ContentView.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #import "ContentView.h"
  2. #import "WebViewDelegate.h"
  3. #import "AppDelegate.h"
  4. #import "JSEventHelper.h"
  5. @interface WebPreferences (WebPreferencesPrivate)
  6. - (void)_setLocalStorageDatabasePath:(NSString *)path;
  7. - (void) setLocalStorageEnabled: (BOOL) localStorageEnabled;
  8. - (void) setDatabasesEnabled:(BOOL)databasesEnabled;
  9. - (void) setDeveloperExtrasEnabled:(BOOL)developerExtrasEnabled;
  10. - (void) setWebGLEnabled:(BOOL)webGLEnabled;
  11. - (void) setOfflineWebApplicationCacheEnabled:(BOOL)offlineWebApplicationCacheEnabled;
  12. @end
  13. @implementation ContentView
  14. @synthesize webView, delegate, mainMenu;
  15. - (void) awakeFromNib
  16. {
  17. WebPreferences *webPrefs = [WebPreferences standardPreferences];
  18. NSString *cappBundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
  19. NSString *applicationSupportFile = [@"~/Library/Application Support/" stringByExpandingTildeInPath];
  20. NSString *savePath = [NSString pathWithComponents:[NSArray arrayWithObjects:applicationSupportFile, cappBundleName, @"LocalStorage", nil]];
  21. [webPrefs _setLocalStorageDatabasePath:savePath];
  22. [webPrefs setLocalStorageEnabled:YES];
  23. [webPrefs setDatabasesEnabled:YES];
  24. [webPrefs setDeveloperExtrasEnabled:[[NSUserDefaults standardUserDefaults] boolForKey: @"developer"]];
  25. [webPrefs setOfflineWebApplicationCacheEnabled:YES];
  26. [webPrefs setWebGLEnabled:YES];
  27. [self.webView setPreferences:webPrefs];
  28. NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage
  29. sharedHTTPCookieStorage];
  30. [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
  31. [self.webView setApplicationNameForUserAgent: @"MacGap"];
  32. self.delegate = [[WebViewDelegate alloc] initWithMenu:[NSApp mainMenu]];
  33. [self.webView setFrameLoadDelegate:self.delegate];
  34. [self.webView setUIDelegate:self.delegate];
  35. [self.webView setResourceLoadDelegate:self.delegate];
  36. [self.webView setDownloadDelegate:self.delegate];
  37. [self.webView setPolicyDelegate:self.delegate];
  38. [self.webView setDrawsBackground:NO];
  39. [self.webView setShouldCloseWithWindow:NO];
  40. [self.webView setGroupName:@"MacGap"];
  41. }
  42. - (void) windowResized:(NSNotification*)notification;
  43. {
  44. NSWindow* window = (NSWindow*)notification.object;
  45. NSSize size = [window frame].size;
  46. DebugNSLog(@"window width = %f, window height = %f", size.width, size.height);
  47. bool isFullScreen = (window.styleMask & NSFullScreenWindowMask) == NSFullScreenWindowMask;
  48. int titleBarHeight = isFullScreen ? 0 : [[Utils sharedInstance] titleBarHeight:window];
  49. [self.webView setFrame:NSMakeRect(0, 0, size.width, size.height - titleBarHeight)];
  50. [JSEventHelper triggerEvent:@"orientationchange" forWebView:self.webView];
  51. }
  52. @end