changeset 32:9490bb2373db

Fixed TODOs; window.reload() works now.
author Atul Varma <avarma@mozilla.com>
date Mon, 12 Apr 2010 19:56:24 -0700
parents 6b0b9b04057e
children c3e5b6b3bb4b
files JavaScriptQuasimode.m Quasimode.m
diffstat 2 files changed, 46 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/JavaScriptQuasimode.m	Mon Apr 12 11:49:46 2010 -0700
+++ b/JavaScriptQuasimode.m	Mon Apr 12 19:56:24 2010 -0700
@@ -139,14 +139,23 @@
   }
 }
 
+static void finalize(JSObjectRef object)
+{
+  Quasimode *quasimode = (Quasimode *) JSObjectGetPrivate(object);
+  [quasimode release];
+}
+
 void JSQuasimodeInit(Quasimode *quasimode)
 {
   WebFrame *frame = [[quasimode view] mainFrame];
   JSGlobalContextRef ctx = [frame globalContext];
   JSClassDefinition classDef = kJSClassDefinitionEmpty;
   classDef.initialize = initialize;
+  classDef.finalize = finalize;
   classDef.className = "Quasimode";
 
+  [quasimode retain];
+
   JSClassRef class = JSClassCreate(&classDef);
   JSObjectRef jsQuasimode = JSObjectMake(ctx, class, quasimode);
   JSObjectRef global = JSContextGetGlobalObject(ctx);
--- a/Quasimode.m	Mon Apr 12 11:49:46 2010 -0700
+++ b/Quasimode.m	Mon Apr 12 19:56:24 2010 -0700
@@ -12,16 +12,27 @@
 #import "JavaScriptQuasimode.h"
 #import "QuasimodalEventTap.h"
 
-// TODO: Consider calling this on WebFrameLoadDelegate's
-// webView:willCloseFrame: instead.
-@interface QuasimodeWindowDelegate : NSObject {
+@interface QuasimodeFrameLoadDelegate : NSObject {
+  Quasimode *quasimode;
 }
-- windowWillClose:(NSNotification *)notification;
+- (id)initWithQuasimode:(Quasimode *)qm;
+- (void)webView:(WebView *)sender
+  didClearWindowObject:(WebScriptObject *)windowObject
+  forFrame:(WebFrame *)frame;
 @end
 
-@implementation QuasimodeWindowDelegate
-- windowWillClose:(NSNotification *)notification {
-  [NSApp terminate: self];
+@implementation QuasimodeFrameLoadDelegate
+- (id)initWithQuasimode:(Quasimode *)qm {
+  if (self = [super init]) {
+    quasimode = qm;
+  }
+  return self;
+}
+
+- (void)webView:(WebView *)sender
+  didClearWindowObject:(WebScriptObject *)windowObject
+  forFrame:(WebFrame *)frame {
+  JSQuasimodeInit(quasimode);
 }
 @end
 
@@ -64,12 +75,16 @@
                                backing: NSBackingStoreBuffered
                                defer: YES];
 
-    [window setDelegate: [[QuasimodeWindowDelegate alloc] init]];
-
     view = [[WebView alloc] initWithFrame: rect
                             frameName: nil
                             groupName: nil];
 
+    QuasimodeFrameLoadDelegate
+      *frameLoadDelegate = [[QuasimodeFrameLoadDelegate alloc]
+                             initWithQuasimode: self];
+
+    [view setFrameLoadDelegate: frameLoadDelegate];
+
     NSURLRequest *req = [
       NSURLRequest requestWithURL: url
       cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
@@ -80,11 +95,6 @@
     [[[view mainFrame] frameView] setAllowsScrolling: NO];
     [[view mainFrame] loadRequest: req];
 
-    // TODO: Consider calling this on WebFrameLoadDelegate's
-    // webView:didClearWindowObject:forFrame: instead, so it
-    // gets called after window.location.reload().
-    JSQuasimodeInit(self);
-
     [window setOpaque: NO];
     [window setBackgroundColor: [NSColor colorWithCalibratedRed: 0.0
                                          green: 0.0
@@ -106,6 +116,17 @@
 }
 @end
 
+@interface QuasimodeWindowDelegate : NSObject {
+}
+- windowWillClose:(NSNotification *)notification;
+@end
+
+@implementation QuasimodeWindowDelegate
+- windowWillClose:(NSNotification *)notification {
+  [NSApp terminate: self];
+}
+@end
+
 int main(int argc, const char *argv[])
 {
   if (argc < 2) {
@@ -146,6 +167,8 @@
     Quasimode *app = [[Quasimode alloc] initWithEventSource: @"keyboard"
                                         url: url];
 
+    [[app window] setDelegate: [[QuasimodeWindowDelegate alloc] init]];
+
     [NSApp run];
   }