Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 1f69dc2

Browse files
committed
Merge pull request #317 from macie/linux-OpenLiveBrowser
Support for chromium browser in linux
2 parents 71a85aa + df482fd commit 1f69dc2

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed

appshell/appshell_extensions_gtk.cpp

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdio.h>
3232
#include <stdlib.h>
3333
#include <sys/stat.h>
34+
#include <unistd.h>
3435
#include <X11/Xlib.h>
3536

3637
GtkWidget* _menuWidget;
@@ -40,48 +41,16 @@ int ConvertGnomeErrorCode(GError* gerror, bool isReading = true);
4041

4142
extern bool isReallyClosing;
4243

43-
static const char* GetPathToLiveBrowser()
44-
{
45-
//#TODO Use execlp and be done with it! No need to reinvent the wheel; so badly that too!
46-
char *envPath = getenv( "PATH" ), *path, *dir, *currentPath;
47-
48-
//# copy PATH and not modify the original
49-
path=(char *)malloc(strlen(envPath)+1);
50-
strcpy(path, envPath);
51-
52-
// Prepend a forward-slash. For convenience
53-
const char* executable="/google-chrome";
54-
struct stat buf;
55-
int len;
56-
57-
for ( dir = strtok( path, ":" ); dir; dir = strtok( NULL, ":" ) )
58-
{
59-
len=strlen(dir)+strlen(executable);
60-
// if((strrchr(dir,'/')-dir)==strlen(dir))
61-
// {
62-
// currentPath = (char*)malloc(len);
63-
// strcpy(currentPath,dir);
64-
// } else
65-
// {
66-
// stat handles consecutive forward slashes automatically. No need for above
67-
currentPath = (char *)malloc(len+1);
68-
strncpy(currentPath,dir,len);
69-
//}
70-
strcat(currentPath,executable);
71-
72-
if(stat(currentPath,&buf)==0 && S_ISREG(buf.st_mode))
73-
return currentPath;
74-
}
75-
76-
return "";
77-
}
7844

7945
int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
8046
{
81-
//# COnsider using execlp and avoid all this path mess!
82-
const char *appPath = GetPathToLiveBrowser(),
83-
*arg1 = "--allow-file-access-from-files";
84-
std::string arg2(" ");
47+
// Supported browsers (order matters):
48+
// - google-chorme
49+
// - chromium-browser - chromium executable name (in ubuntu)
50+
// - chromium - other chromium executable name (in arch linux)
51+
std::string browsers[3] = {"google-chrome", "chromium-browser", "chromium"},
52+
arg1("--allow-file-access-from-files"),
53+
arg2(" ");
8554

8655
if(enableRemoteDebugging)
8756
arg2.assign("--remote-debugging-port=9222");
@@ -95,10 +64,16 @@ int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
9564
case -1: //# Something went wrong
9665
return ConvertLinuxErrorCode(errno);
9766
case 0: //# I'm the child. When I successfully exec, parent is resumed. Or when I _exec()
98-
execl(appPath, arg1, argURL.c_str(), arg2.c_str(),(char *)0);
99-
67+
// check for supported browsers (in PATH directories)
68+
for (size_t i = 0; i < sizeof(browsers) / sizeof(browsers[0]); i++) {
69+
if (execlp(browsers[i].c_str(), browsers[i].c_str(), arg1.c_str(), argURL.c_str(), arg2.c_str(), NULL) != -1) {
70+
// browser is found in os; stop iterating
71+
break;
72+
}
73+
}
10074
error=errno;
10175
_exit(0);
76+
10277
default:
10378
if(error!=0)
10479
{

0 commit comments

Comments
 (0)