Move all extension C and JavaScript code into native/v8_extensions

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-27 14:02:05 -07:00
parent c4639b894e
commit 5141aba658
7 changed files with 22 additions and 23 deletions

View File

@@ -63,15 +63,16 @@ task :"copy-files-to-bundle" => :"verify-prerequisites" do
dest = File.join(built_dir, contents_dir, "Resources")
mkdir_p "#{dest}/v8_extensions"
cp Dir.glob("#{project_dir}/native/v8_extensions/*.js"), "#{dest}/v8_extensions/"
if resource_path = ENV['RESOURCE_PATH']
sh "coffee -c -o #{dest}/src/stdlib #{resource_path}/src/stdlib/require.coffee"
sh "coffee -c -o '#{dest}/src/stdlib' '#{resource_path}/src/stdlib/require.coffee'"
cp_r "#{resource_path}/static", dest
cp "#{resource_path}/src/stdlib/onig-reg-exp-extension.js", "#{dest}/src/stdlib"
cp "#{resource_path}/src/stdlib/native-handler.js", "#{dest}/src/stdlib"
else
# TODO: Restore this list when we add in all of atoms source
#%w(src static vendor spec benchmark bundles themes).each do |dir|
%w(src static vendor).each do |dir|
%w(src static vendor bundles themes).each do |dir|
dest_path = File.join(dest, dir)
rm_rf dest_path
cp_r dir, dest_path

View File

@@ -66,8 +66,8 @@
'native/util.h',
'native/path_watcher.mm',
'native/path_watcher.h',
'native/v8_extensions/native_handler.mm',
'native/v8_extensions/native_handler.h',
'native/v8_extensions/native.mm',
'native/v8_extensions/native.h',
],
'mac_bundle_resources': [
'native/mac/atom.icns',
@@ -279,8 +279,8 @@
'native/util.h',
'native/path_watcher.mm',
'native/path_watcher.h',
'native/v8_extensions/native_handler.mm',
'native/v8_extensions/native_handler.h',
'native/v8_extensions/native.mm',
'native/v8_extensions/native.h',
],
# TODO(mark): For now, don't put any resources into this app. Its
# resources directory will be a symbolic link to the browser app's
@@ -307,6 +307,14 @@
'${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}'
],
},
{
'postbuild_name': 'Copy and Compile Static Files',
'action': [
'rake',
'--trace',
'copy-files-to-bundle',
],
},
],
}, # target cefclient_helper_app
],

View File

@@ -1,7 +1,7 @@
#include "atom_cef_app.h"
#import <Cocoa/Cocoa.h>
#import "native/v8_extensions/native_handler.h"
#import "native/v8_extensions/native.h"
void AtomCefApp::OnWebKitInitialized() {

View File

@@ -3,7 +3,7 @@
#import <CommonCrypto/CommonDigest.h>
#import "atom_application.h"
#import "native_handler.h"
#import "native.h"
#import "include/cef_base.h"
#import "path_watcher.h"
@@ -25,19 +25,9 @@ void throwException(const CefRefPtr<CefV8Value>& global, CefRefPtr<CefV8Exceptio
}
NativeHandler::NativeHandler() : CefV8Handler() {
std::string extensionCode = "var $native = {}; (function() {";
const char *functionNames[] = {"exists", "alert", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "toggleDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory", "move", "moveToTrash", "reload", "lastModified", "md5ForPath", "exec", "getPlatform"};
NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *);
for (NSUInteger i = 0; i < arrayLength; i++) {
std::string functionName = std::string(functionNames[i]);
extensionCode += "native function " + functionName + "(); $native." + functionName + " = " + functionName + ";";
}
extensionCode += "})();";
// Register the extension.
CefRegisterExtension("v8/test", extensionCode, this);
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"v8_extensions/native.js"];
NSString *extensionCode = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
CefRegisterExtension("v8/native", [extensionCode UTF8String], this);
}
bool NativeHandler::Execute(const CefString& name,