From 85c37fd652f0e11b59bce5f9ffb6e4f67430a4f0 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 5 Sep 2012 12:52:11 -0700 Subject: [PATCH] Move atom.resourcePath to window.resourcePath The resourcePath is now set using a url param. Because resourcePath is needed by require.js, it needs to be on `window` rather than `atom`. --- native/atom_application.h | 1 - native/atom_application.mm | 9 +------- native/atom_cef_render_process_handler.mm | 9 -------- native/atom_window_controller.h | 1 + native/atom_window_controller.mm | 19 +++++++++++++++-- spec/spec-suite.coffee | 2 +- src/atom-bootstrap.coffee | 2 +- src/stdlib/require.coffee | 22 ++++++++++---------- static/index.html | 25 ++++++++++++++--------- 9 files changed, 47 insertions(+), 43 deletions(-) diff --git a/native/atom_application.h b/native/atom_application.h index 6236de158..8f176a63f 100644 --- a/native/atom_application.h +++ b/native/atom_application.h @@ -10,7 +10,6 @@ class AtomCefClient; + (id)applicationWithArguments:(char **)argv count:(int)argc; + (CefSettings)createCefSettings; -- (const char *)resourcePath; - (void)open:(NSString *)path; - (IBAction)runSpecs:(id)sender; - (IBAction)runBenchmarks:(id)sender; diff --git a/native/atom_application.mm b/native/atom_application.mm index 7a7b3dd6f..8e46406f2 100644 --- a/native/atom_application.mm +++ b/native/atom_application.mm @@ -70,7 +70,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification { _backgroundWindowController = [[AtomWindowController alloc] initInBackground]; - + NSArray *processArguments = [[NSProcessInfo processInfo] arguments]; if ([processArguments containsObject:@"--benchmark"]) { [self runBenchmarksThenExit:true]; @@ -78,13 +78,6 @@ else if ([processArguments containsObject:@"--test"]) { [self runSpecsThenExit:true]; } - else { - #ifdef RESOURCE_PATH - [self open:[NSString stringWithUTF8String:RESOURCE_PATH]]; - #else - [self open:nil]; - #endif - } } - (void)applicationWillTerminate:(NSNotification *)notification { diff --git a/native/atom_cef_render_process_handler.mm b/native/atom_cef_render_process_handler.mm index 5f2ae5c4b..03ba62708 100644 --- a/native/atom_cef_render_process_handler.mm +++ b/native/atom_cef_render_process_handler.mm @@ -14,15 +14,6 @@ void AtomCefRenderProcessHandler::OnWebKitInitialized() { void AtomCefRenderProcessHandler::OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { -#ifdef RESOURCE_PATH - CefRefPtr resourcePath = CefV8Value::CreateString(RESOURCE_PATH); -#else - CefRefPtr resourcePath = CefV8Value::CreateString([[[NSBundle mainBundle] resourcePath] UTF8String]); -#endif - - CefRefPtr global = context->GetGlobal(); - CefRefPtr atom = global->GetValue("atom"); - atom->SetValue("resourcePath", resourcePath, V8_PROPERTY_ATTRIBUTE_NONE); } bool AtomCefRenderProcessHandler::OnProcessMessageReceived(CefRefPtr browser, diff --git a/native/atom_window_controller.h b/native/atom_window_controller.h index e5343a0f5..1921ec066 100644 --- a/native/atom_window_controller.h +++ b/native/atom_window_controller.h @@ -7,6 +7,7 @@ class AtomCefClient; NSView *_devToolsView; NSView *_webView; NSString *_bootstrapScript; + NSString *_resourcePath; NSString *_pathToOpen; CefRefPtr _cefClient; diff --git a/native/atom_window_controller.mm b/native/atom_window_controller.mm index b229a6a60..15ab5da84 100644 --- a/native/atom_window_controller.mm +++ b/native/atom_window_controller.mm @@ -14,6 +14,7 @@ _cefDevToolsClient = NULL; [_webView release]; [_bootstrapScript release]; + [_resourcePath release]; [_pathToOpen release]; [super dealloc]; } @@ -22,6 +23,13 @@ self = [super initWithWindowNibName:@"AtomWindow"]; _bootstrapScript = [bootstrapScript retain]; +#ifdef RESOURCE_PATH + _resourcePath = [[NSString alloc] initWithUTF8String:RESOURCE_PATH]; +#else + _resourcePath = [[[NSBundle mainBundle] resourcePath] retain]; +#endif + + if (!background) { [self showWindow:self]; } @@ -60,17 +68,24 @@ CefBrowserHost::CreateBrowser(window_info, cefClient.get(), url, settings); } +- (NSString *)encodeUrlParam:(NSString *)param { + param = [param stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; + param = [param stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + return param; +} + - (void)windowDidLoad { [self.window setDelegate:self]; NSURL *url = [[NSBundle mainBundle] resourceURL]; NSMutableString *urlString = [NSMutableString string]; [urlString appendString:[[url URLByAppendingPathComponent:@"static/index.html"] absoluteString]]; - [urlString appendFormat:@"?bootstrapScript=%@", [_bootstrapScript stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + [urlString appendFormat:@"?bootstrapScript=%@", [self encodeUrlParam:_bootstrapScript]]; + [urlString appendFormat:@"&resourcePath=%@", [self encodeUrlParam:_resourcePath]]; if (_exitWhenDone) [urlString appendString:@"&exitWhenDone=1"]; if (_pathToOpen) - [urlString appendFormat:@"&pathToOpen=%@", [_pathToOpen stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + [urlString appendFormat:@"&pathToOpen=%@", [self encodeUrlParam:_pathToOpen]]; _cefClient = new AtomCefClient(); [self addBrowserToView:self.webView url:[urlString UTF8String] cefHandler:_cefClient]; diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee index 400144695..26d0e02b3 100644 --- a/spec/spec-suite.coffee +++ b/spec/spec-suite.coffee @@ -1,4 +1,4 @@ fs = require 'fs' require 'spec-helper' -require path for path in fs.listTree(atom.resourcePath + "/spec") when /-spec\.coffee$/.test path +require path for path in fs.listTree(window.resourcePath + "/spec") when /-spec\.coffee$/.test path diff --git a/src/atom-bootstrap.coffee b/src/atom-bootstrap.coffee index 4522e7689..0f4657442 100644 --- a/src/atom-bootstrap.coffee +++ b/src/atom-bootstrap.coffee @@ -1,2 +1,2 @@ Atom = require 'atom' -window.atom = new Atom(atom.resourcePath, $native) +window.atom = new Atom(window.resourcePath, $native) diff --git a/src/stdlib/require.coffee b/src/stdlib/require.coffee index be7be3929..0774c594c 100644 --- a/src/stdlib/require.coffee +++ b/src/stdlib/require.coffee @@ -1,15 +1,15 @@ paths = [ - "#{atom.resourcePath}/spec" - "#{atom.resourcePath}/benchmark" - "#{atom.resourcePath}/src/stdlib" - "#{atom.resourcePath}/src/app" - "#{atom.resourcePath}/src/extensions" - "#{atom.resourcePath}/src" - "#{atom.resourcePath}/vendor" - "#{atom.resourcePath}/static" - "#{atom.resourcePath}/bundles" - "#{atom.resourcePath}/themes" - "#{atom.resourcePath}" + "#{window.resourcePath}/spec" + "#{window.resourcePath}/benchmark" + "#{window.resourcePath}/src/stdlib" + "#{window.resourcePath}/src/app" + "#{window.resourcePath}/src/extensions" + "#{window.resourcePath}/src" + "#{window.resourcePath}/vendor" + "#{window.resourcePath}/static" + "#{window.resourcePath}/bundles" + "#{window.resourcePath}/themes" + "#{window.resourcePath}" ] window.__filename = null diff --git a/static/index.html b/static/index.html index a25e57367..e55a9502e 100644 --- a/static/index.html +++ b/static/index.html @@ -1,26 +1,31 @@ + - + + +