pulsar/atom/atom_window_controller.mm

117 lines
3.8 KiB
Plaintext
Raw Normal View History

2012-08-22 02:14:50 +04:00
#import "include/cef_application_mac.h"
#import "atom/atom_cef_client.h"
#import "atom/atom_window_controller.h"
2012-08-22 02:14:50 +04:00
@implementation AtomWindowController
2012-08-22 02:14:50 +04:00
@synthesize webView=_webView;
- (void)dealloc {
[_webView release];
2012-08-22 04:22:43 +04:00
[_bootstrapScript release];
[_pathToOpen release];
2012-08-22 02:14:50 +04:00
[super dealloc];
}
2012-08-24 00:47:06 +04:00
- (id)initWithBootstrapScript:(NSString *)bootstrapScript {
2012-08-22 02:14:50 +04:00
self = [super initWithWindowNibName:@"AtomWindow"];
2012-08-22 04:22:43 +04:00
_bootstrapScript = [bootstrapScript retain];
[self showWindow: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-24 00:47:06 +04:00
return [self initWithBootstrapScript:@"window-bootstrap"];
2012-08-22 04:22:43 +04:00
}
2012-08-24 00:47:06 +04:00
- (id)initSpecs {
2012-08-22 04:22:43 +04:00
_runningSpecs = true;
2012-08-24 00:47:06 +04:00
return [self initWithBootstrapScript:@"spec-bootstrap"];
2012-08-22 04:22:43 +04:00
}
2012-08-24 00:47:06 +04:00
- (id)initBenchmarks {
return [self initWithBootstrapScript:@"benchmark-bootstrap"];
2012-08-22 04:22:43 +04:00
}
- (void)windowDidLoad {
[self.window setDelegate:self];
2012-08-22 02:14:50 +04:00
_cefClient = new AtomCefClient();
2012-08-22 02:14:50 +04:00
CefBrowserSettings settings;
2012-08-22 02:14:50 +04:00
[self populateBrowserSettings:settings];
CefWindowInfo window_info;
window_info.SetAsChild(self.webView, 0, 0, self.webView.bounds.size.width, self.webView.bounds.size.height);
NSURL *url = [[NSBundle mainBundle] resourceURL];
NSString *urlString = [[url URLByAppendingPathComponent:@"static/index.html"] absoluteString];
urlString = [urlString stringByAppendingFormat:@"?bootstrapScript=%@&pathToOpen=%@", [_bootstrapScript stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [_pathToOpen stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"%@", urlString);
CefBrowserHost::CreateBrowser(window_info, _cefClient.get(), [urlString UTF8String], settings);
2012-08-22 04:22:43 +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 {
if (_cefClient && _cefClient->GetBrowser() && !_runningSpecs) {
_cefClient->GetBrowser()->GetHost()->SetFocus(false);
2012-08-22 04:22:43 +04:00
}
}
- (void)windowDidBecomeMain:(NSNotification *)notification {
if (_cefClient && _cefClient->GetBrowser()) {
_cefClient->GetBrowser()->GetHost()->SetFocus(true);
2012-08-22 02:14:50 +04:00
}
}
- (BOOL)windowShouldClose:(id)window {
[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;
}
@end