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

Commit

Permalink
JS resource compilation, platform independent.
Browse files Browse the repository at this point in the history
  • Loading branch information
pritambaral committed Nov 1, 2012
1 parent 272fb80 commit f5bf46f
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 51 deletions.
59 changes: 56 additions & 3 deletions appshell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'variables': {
'appname': 'Brackets',
'pkg-config': 'pkg-config',
'target_arch%': 'environment',
'chromium_code': 1,
'conditions': [
[ 'OS=="mac"', {
Expand Down Expand Up @@ -165,18 +166,48 @@
],
}],
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
'actions': [
{
'action_name': 'appshell_extensions_js',
'inputs': [
'appshell/appshell_extensions.js',
],
'outputs': [
'appshell_extensions_js.o',
],
'action': [
'objcopy',
'--input',
'binary',
'--output',
'<(output_bfd)',
'--binary-architecture',
'i386',
'<@(_inputs)',
'<@(_outputs)',
],
'message': 'compiling js resource'
},
],
'cflags': [
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
'<(march)',
],
'include_dirs': [
'.',
],
],
'default_configuration': 'Release',
'configurations': {
'Release': {},
'Debug': {},
},
'copies': [
{
'destination': '<(PRODUCT_DIR)/lib',
'files': [
'<@(appshell_bundle_libraries_linux)',
],
},
{
'destination': '<(PRODUCT_DIR)',
'files': [
Expand All @@ -191,10 +222,13 @@
'link_settings': {
'ldflags': [
'<!@(<(pkg-config) --libs-only-other gtk+-2.0 gthread-2.0)',
'$(BUILDTYPE)/lib.target/libcef.so',
'-Wl,-rpath,\$$ORIGIN/lib',
'<(march)'
],
'libraries': [
'<!@(<(pkg-config) --libs-only-l gtk+-2.0 gthread-2.0)',
'$(BUILDTYPE)/lib.target/libcef.so',
'appshell_extensions_js.o',
],
},
}],
Expand Down Expand Up @@ -230,9 +264,10 @@
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
},
'conditions': [
['OS=="linux"', {
['OS=="linux"', {
'cflags': [
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
'<(march)',
],
'default_configuration': 'Release',
'configurations': {
Expand Down Expand Up @@ -310,5 +345,23 @@
}, # target appshell_helper_app
],
}], # OS=="mac"
['target_arch=="ia32"', {
'variables': {
'output_bfd': 'elf32-i386',
'march': '-m32',
},
}],
['target_arch=="x64"', {
'variables': {
'output_bfd': 'elf64-x86-64',
'march': '-m64',
},
}],
['target_arch=="environment"', {
'variables': {
'output_bfd': '<!(uname -m | sed "s/x86_64/elf64-x86-64/;s/i.86/elf32-i386/")',
'march': ' ',
},
}],
],
}
55 changes: 22 additions & 33 deletions appshell/appshell_extensions_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include "appshell_extensions.h"
#include "appshell_extensions_platform.h"
#include "client_handler.h"

#include <errno.h>
Expand Down Expand Up @@ -65,8 +66,8 @@ class LiveBrowserMgrLin
LiveBrowserMgrLin();
virtual ~LiveBrowserMgrLin();

int m_closeLiveBrowserHeartbeatTimerId;
int m_closeLiveBrowserTimeoutTimerId;
int m_closeLiveBrowserHeartbeatTimerId;
int m_closeLiveBrowserTimeoutTimerId;
CefRefPtr<CefProcessMessage> m_closeLiveBrowserCallback;
CefRefPtr<CefBrowser> m_browser;

Expand Down Expand Up @@ -682,18 +683,6 @@ void BringBrowserWindowToFront(CefRefPtr<CefBrowser> browser)
}
}

// void ConvertToNativePath(ExtensionString& filename)
// {
// // Convert '/' to '\'
// replace(filename.begin(), filename.end(), '/', '\\');
// }

// void ConvertToUnixPath(ExtensionString& filename)
// {
// // Convert '\\' to '/'
// replace(filename.begin(), filename.end(), '\\', '/');
// }

// // Maps errors from errno.h to the brackets error codes
// // found in brackets_extensions.js
// int ConvertErrnoCode(int errorCode, bool isReading)
Expand Down Expand Up @@ -767,22 +756,22 @@ int ShowFolderInOSWindow(ExtensionString pathname)

int ConvertLinuxErrorCode(int errorCode, bool isReading)
{
// switch (errorCode) {
// case NO_ERROR:
// return NO_ERROR;
// case ENOENT:
// case ERROR_FILE_NOT_FOUND:
// return ERR_NOT_FOUND;
// case EACCESS:
// return isReading ? ERR_CANT_READ : ERR_CANT_WRITE;
// case ERROR_WRITE_PROTECT:
// return ERR_CANT_WRITE;
// case ERROR_HANDLE_DISK_FULL:
// return ERR_OUT_OF_SPACE;
// case ERROR_ALREADY_EXISTS:
// return ERR_FILE_EXISTS;
// default:
// return ERR_UNKNOWN;
// }
return errorCode;
}
switch (errorCode) {
case NO_ERROR:
return NO_ERROR;
case ENOENT:
return ERR_NOT_FOUND;
case EACCES:
return isReading ? ERR_CANT_READ : ERR_CANT_WRITE;
case ENOTDIR:
return ERR_NOT_DIRECTORY;
// case ERROR_WRITE_PROTECT:
// return ERR_CANT_WRITE;
// case ERROR_HANDLE_DISK_FULL:
// return ERR_OUT_OF_SPACE;
// case ERROR_ALREADY_EXISTS:
// return ERR_FILE_EXISTS;
default:
return ERR_UNKNOWN;
}
}
12 changes: 10 additions & 2 deletions appshell/cefclient_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void TerminationSignalHandler(int signatl) {
destroy();
}

//Callback for File > Exit... menu item.
gboolean ExitActivated(GtkWidget* widget) {
destroy();
}

// // Callback for Debug > Get Source... menu item.
// gboolean GetSourceActivated(GtkWidget* widget) {
// if (g_handler.get() && g_handler->GetBrowserId())
Expand Down Expand Up @@ -204,7 +209,10 @@ GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) {

GtkWidget* CreateMenuBar() {
GtkWidget* menu_bar = gtk_menu_bar_new();
GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests");
GtkWidget* debug_menu = CreateMenu(menu_bar, "File");

AddMenuEntry(debug_menu, "Exit",
G_CALLBACK(ExitActivated));

return menu_bar;
}
Expand Down Expand Up @@ -361,4 +369,4 @@ CefString AppGetCachePath() {
cachePath.append("/cef_data");

return CefString(cachePath);
}
}
30 changes: 17 additions & 13 deletions appshell/client_app_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <string>

extern time_t g_appStartupTime;
extern char _binary_appshell_appshell_extensions_js_start;

CefString ClientApp::GetCurrentLanguage()
{
Expand All @@ -43,22 +44,25 @@ CefString ClientApp::GetCurrentLanguage()

std::string ClientApp::GetExtensionJSSource()
{
//Another bloody TODO here.
std:: string extensionJSPath(AppGetSupportDirectory());
extensionJSPath.append("/appshell_extensions.js");
FILE* file = fopen(extensionJSPath.c_str(),"r");
if(file == NULL)
{
return "";
}
//# We objcopy the appshell/appshell_extensions.js file, and link it directly into the binary.
//# See http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967
const char* p = &_binary_appshell_appshell_extensions_js_start;
std:: string content(p);
// std:: string extensionJSPath(AppGetSupportDirectory());
// extensionJSPath.append("/appshell_extensions.js");
// FILE* file = fopen(extensionJSPath.c_str(),"r");
// if(file == NULL)
// {
// return "";
// }

fseek(file, 0, SEEK_END);
long int size = ftell(file);
rewind(file);
// fseek(file, 0, SEEK_END);
// long int size = ftell(file);
// rewind(file);

char* content = (char*)calloc(size + 1, 1);
// char* content = (char*)calloc(size + 1, 1);

fread(content,1,size,file);
// fread(content,1,size,file);

return content;
}
Expand Down
3 changes: 3 additions & 0 deletions appshell_paths.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,8 @@
'appshell_bundle_resources_linux': [
'$(BUILDTYPE)/locales',
],
'appshell_bundle_libraries_linux': [
'$(BUILDTYPE)/lib.target/libcef.so',
],
},
}

0 comments on commit f5bf46f

Please sign in to comment.