2012-08-22 02:14:50 +04:00
|
|
|
#import "include/cef_application_mac.h"
|
2012-08-30 02:31:06 +04:00
|
|
|
#include "include/cef_client.h"
|
2012-08-28 00:21:59 +04:00
|
|
|
#import "native/atom_cef_client.h"
|
|
|
|
#import "native/atom_window_controller.h"
|
2012-08-22 02:14:50 +04:00
|
|
|
|
2012-08-26 01:06:00 +04:00
|
|
|
@implementation AtomWindowController
|
2012-08-22 02:14:50 +04:00
|
|
|
|
2012-08-30 02:31:06 +04:00
|
|
|
@synthesize splitView=_splitView;
|
2012-08-22 02:14:50 +04:00
|
|
|
@synthesize webView=_webView;
|
2012-08-30 02:31:06 +04:00
|
|
|
@synthesize devToolsView=_devToolsView;
|
2012-08-22 02:14:50 +04:00
|
|
|
|
|
|
|
- (void)dealloc {
|
2012-08-30 02:31:06 +04:00
|
|
|
_cefClient = NULL;
|
|
|
|
_cefDevToolsClient = NULL;
|
2012-08-28 20:58:24 +04:00
|
|
|
[_webView release];
|
|
|
|
[_bootstrapScript release];
|
2012-08-22 04:22:43 +04:00
|
|
|
[_pathToOpen release];
|
2012-08-28 20:58:24 +04:00
|
|
|
[super dealloc];
|
2012-08-22 02:14:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-28 21:33:34 +04:00
|
|
|
- (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)background {
|
2012-08-28 20:58:24 +04:00
|
|
|
self = [super initWithWindowNibName:@"AtomWindow"];
|
|
|
|
_bootstrapScript = [bootstrapScript retain];
|
2012-08-22 04:22:43 +04:00
|
|
|
|
2012-08-28 21:33:34 +04:00
|
|
|
if (!background) {
|
2012-08-28 21:51:36 +04:00
|
|
|
[self showWindow:self];
|
2012-08-28 21:33:34 +04:00
|
|
|
}
|
2012-08-29 21:59:45 +04:00
|
|
|
|
2012-08-28 21:33:34 +04:00
|
|
|
return self;
|
2012-08-22 04:22:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-24 00:47:06 +04:00
|
|
|
- (id)initWithPath:(NSString *)path {
|
2012-08-22 04:22:43 +04:00
|
|
|
_pathToOpen = [path retain];
|
2012-08-28 21:33:34 +04:00
|
|
|
return [self initWithBootstrapScript:@"window-bootstrap" background:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initInBackground {
|
|
|
|
[self initWithBootstrapScript:@"window-bootstrap" background:YES];
|
|
|
|
[self.window setFrame:NSMakeRect(0, 0, 0, 0) display:NO];
|
|
|
|
return self;
|
2012-08-22 04:22:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-31 04:10:05 +04:00
|
|
|
- (id)initSpecsThenExit:(BOOL)exitWhenDone {
|
2012-08-22 04:22:43 +04:00
|
|
|
_runningSpecs = true;
|
2012-08-31 04:10:05 +04:00
|
|
|
_exitWhenDone = exitWhenDone;
|
2012-08-28 21:33:34 +04:00
|
|
|
return [self initWithBootstrapScript:@"spec-bootstrap" background:NO];
|
2012-08-22 04:22:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-31 04:10:05 +04:00
|
|
|
- (id)initBenchmarksThenExit:(BOOL)exitWhenDone {
|
|
|
|
_runningSpecs = true;
|
|
|
|
_exitWhenDone = exitWhenDone;
|
2012-08-28 21:33:34 +04:00
|
|
|
return [self initWithBootstrapScript:@"benchmark-bootstrap" background:NO];
|
2012-08-22 04:22:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-30 01:37:17 +04:00
|
|
|
- (void)addBrowserToView:(NSView *)view url:(const char *)url cefHandler:(CefRefPtr<AtomCefClient>)cefClient {
|
2012-08-25 03:20:07 +04:00
|
|
|
CefBrowserSettings settings;
|
2012-08-22 02:14:50 +04:00
|
|
|
[self populateBrowserSettings:settings];
|
2012-08-28 20:58:24 +04:00
|
|
|
CefWindowInfo window_info;
|
2012-08-30 01:37:17 +04:00
|
|
|
window_info.SetAsChild(view, 0, 0, view.bounds.size.width, view.bounds.size.height);
|
|
|
|
CefBrowserHost::CreateBrowser(window_info, cefClient.get(), url, settings);
|
|
|
|
}
|
2012-08-28 20:58:24 +04:00
|
|
|
|
2012-08-30 01:37:17 +04:00
|
|
|
- (void)windowDidLoad {
|
|
|
|
[self.window setDelegate:self];
|
2012-08-30 02:31:06 +04:00
|
|
|
|
2012-08-27 01:10:11 +04:00
|
|
|
NSURL *url = [[NSBundle mainBundle] resourceURL];
|
2012-08-29 03:46:44 +04:00
|
|
|
NSMutableString *urlString = [NSMutableString string];
|
2012-08-30 02:31:06 +04:00
|
|
|
[urlString appendString:[[url URLByAppendingPathComponent:@"static/index.html"] absoluteString]];
|
2012-08-29 21:59:45 +04:00
|
|
|
[urlString appendFormat:@"?bootstrapScript=%@", [_bootstrapScript stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
2012-08-31 04:10:05 +04:00
|
|
|
if (_exitWhenDone)
|
|
|
|
[urlString appendString:@"&exitWhenDone=1"];
|
|
|
|
if (_pathToOpen)
|
|
|
|
[urlString appendFormat:@"&pathToOpen=%@", [_pathToOpen stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
2012-08-30 02:31:06 +04:00
|
|
|
|
2012-08-30 01:37:17 +04:00
|
|
|
_cefClient = new AtomCefClient();
|
|
|
|
[self addBrowserToView:self.webView url:[urlString UTF8String] cefHandler:_cefClient];
|
2012-08-22 04:22:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-30 02:31:06 +04:00
|
|
|
- (void)toggleDevTools {
|
|
|
|
if (_devToolsView) {
|
2012-08-30 19:47:21 +04:00
|
|
|
[self hideDevTools];
|
2012-08-30 02:31:06 +04:00
|
|
|
}
|
2012-08-30 19:47:21 +04:00
|
|
|
else {
|
|
|
|
[self showDevTools];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showDevTools {
|
2012-08-30 21:24:01 +04:00
|
|
|
if (_devToolsView) return;
|
|
|
|
|
2012-08-30 19:47:21 +04:00
|
|
|
if (_cefClient && _cefClient->GetBrowser()) {
|
|
|
|
_devToolsView = [[NSView alloc] initWithFrame:_splitView.bounds];
|
2012-08-30 02:31:06 +04:00
|
|
|
[_splitView addSubview:_devToolsView];
|
|
|
|
[_splitView adjustSubviews];
|
2012-08-30 19:47:21 +04:00
|
|
|
|
2012-08-30 02:31:06 +04:00
|
|
|
_cefDevToolsClient = new AtomCefClient();
|
2012-08-30 19:47:21 +04:00
|
|
|
std::string devtools_url = _cefClient->GetBrowser()->GetHost()->GetDevToolsURL(true);
|
2012-08-30 02:31:06 +04:00
|
|
|
[self addBrowserToView:_devToolsView url:devtools_url.c_str() cefHandler:_cefDevToolsClient];
|
2012-08-30 19:47:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)hideDevTools {
|
|
|
|
[_devToolsView removeFromSuperview];
|
|
|
|
[_splitView adjustSubviews];
|
|
|
|
[_devToolsView release];
|
|
|
|
_devToolsView = nil;
|
|
|
|
_cefDevToolsClient = NULL;
|
|
|
|
_cefClient->GetBrowser()->GetHost()->SetFocus(true);
|
2012-08-30 02:31:06 +04:00
|
|
|
}
|
2012-08-30 01:37:17 +04:00
|
|
|
|
2012-08-22 02:14:50 +04:00
|
|
|
# pragma mark NSWindowDelegate
|
|
|
|
|
2012-08-22 04:22:43 +04:00
|
|
|
- (void)windowDidResignMain:(NSNotification *)notification {
|
2012-08-25 21:17:47 +04:00
|
|
|
if (_cefClient && _cefClient->GetBrowser() && !_runningSpecs) {
|
2012-08-28 20:58:24 +04:00
|
|
|
_cefClient->GetBrowser()->GetHost()->SetFocus(false);
|
2012-08-22 04:22:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeMain:(NSNotification *)notification {
|
2012-08-25 21:17:47 +04:00
|
|
|
if (_cefClient && _cefClient->GetBrowser()) {
|
2012-08-28 20:58:24 +04:00
|
|
|
_cefClient->GetBrowser()->GetHost()->SetFocus(true);
|
2012-08-22 02:14:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)window {
|
2012-08-25 03:05:41 +04:00
|
|
|
[self autorelease];
|
2012-08-22 02:14:50 +04:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)populateBrowserSettings:(CefBrowserSettings &)settings {
|
|
|
|
CefString(&settings.default_encoding) = "UTF-8";
|
|
|
|
settings.remote_fonts_disabled = true;
|
|
|
|
settings.encoding_detector_enabled = false;
|
|
|
|
settings.javascript_disabled = false;
|
2012-08-23 02:29:39 +04:00
|
|
|
settings.javascript_open_windows_disallowed = false;
|
2012-08-22 02:14:50 +04:00
|
|
|
settings.javascript_close_windows_disallowed = false;
|
|
|
|
settings.javascript_access_clipboard_disallowed = false;
|
|
|
|
settings.dom_paste_disabled = true;
|
|
|
|
settings.caret_browsing_enabled = false;
|
|
|
|
settings.java_disabled = true;
|
|
|
|
settings.plugins_disabled = true;
|
|
|
|
settings.universal_access_from_file_urls_allowed = false;
|
|
|
|
settings.file_access_from_file_urls_allowed = false;
|
|
|
|
settings.web_security_disabled = false;
|
|
|
|
settings.xss_auditor_enabled = true;
|
|
|
|
settings.image_load_disabled = false;
|
|
|
|
settings.shrink_standalone_images_to_fit = false;
|
|
|
|
settings.site_specific_quirks_disabled = false;
|
|
|
|
settings.text_area_resize_disabled = false;
|
|
|
|
settings.page_cache_disabled = true;
|
|
|
|
settings.tab_to_links_disabled = true;
|
|
|
|
settings.hyperlink_auditing_disabled = true;
|
|
|
|
settings.user_style_sheet_enabled = false;
|
|
|
|
settings.author_and_user_styles_disabled = false;
|
|
|
|
settings.local_storage_disabled = false;
|
|
|
|
settings.databases_disabled = false;
|
|
|
|
settings.application_cache_disabled = false;
|
|
|
|
settings.webgl_disabled = false;
|
|
|
|
settings.accelerated_compositing_disabled = false;
|
|
|
|
settings.accelerated_layers_disabled = false;
|
|
|
|
settings.accelerated_video_disabled = false;
|
|
|
|
settings.accelerated_2d_canvas_disabled = false;
|
|
|
|
settings.accelerated_painting_enabled = true;
|
|
|
|
settings.accelerated_filters_enabled = true;
|
|
|
|
settings.accelerated_plugins_disabled = false;
|
|
|
|
settings.developer_tools_disabled = false;
|
|
|
|
settings.fullscreen_enabled = true;
|
|
|
|
}
|
|
|
|
|
2012-08-29 21:59:45 +04:00
|
|
|
@end
|