Title: [159902] trunk/Tools
Revision
159902
Author
[email protected]
Date
2013-12-01 16:50:07 -0800 (Sun, 01 Dec 2013)

Log Message

[Mac] Transition MiniBrowser to the Cocoa API: policy delegate   
https://bugs.webkit.org/show_bug.cgi?id=125046

Reviewed by Sam Weinig.

* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate newWindow:]): Added WK_API_ENABLED guards.
(-[BrowserAppDelegate openDocument:]): Ditto.
* MiniBrowser/mac/WK2BrowserWindowController.h: Ditto. Also moved ivar declarations from the
interface to the implementation.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]): Changed to set the policy delegate instead of
the policy client.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForNavigationAction:decisionHandler:]):
Moved policy client implementation into this delegate method.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForNewWindowAction:decisionHandler:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForResponseAction:decisionHandler:]):
Ditto.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (159901 => 159902)


--- trunk/Tools/ChangeLog	2013-12-01 23:40:27 UTC (rev 159901)
+++ trunk/Tools/ChangeLog	2013-12-02 00:50:07 UTC (rev 159902)
@@ -1,5 +1,27 @@
 2013-12-01  Dan Bernstein  <[email protected]>
 
+        [Mac] Transition MiniBrowser to the Cocoa API: policy delegate   
+        https://bugs.webkit.org/show_bug.cgi?id=125046
+
+        Reviewed by Sam Weinig.
+
+        * MiniBrowser/mac/AppDelegate.m:
+        (-[BrowserAppDelegate newWindow:]): Added WK_API_ENABLED guards.
+        (-[BrowserAppDelegate openDocument:]): Ditto.
+        * MiniBrowser/mac/WK2BrowserWindowController.h: Ditto. Also moved ivar declarations from the
+        interface to the implementation.
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController awakeFromNib]): Changed to set the policy delegate instead of
+        the policy client.
+        (-[WK2BrowserWindowController browsingContextController:decidePolicyForNavigationAction:decisionHandler:]):
+        Moved policy client implementation into this delegate method.
+        (-[WK2BrowserWindowController browsingContextController:decidePolicyForNewWindowAction:decisionHandler:]):
+        Ditto.
+        (-[WK2BrowserWindowController browsingContextController:decidePolicyForResponseAction:decisionHandler:]):
+        Ditto.
+
+2013-12-01  Dan Bernstein  <[email protected]>
+
         [Mac] Remove the MiniBrowser injected bundle
         https://bugs.webkit.org/show_bug.cgi?id=125041
 

Modified: trunk/Tools/MiniBrowser/mac/AppDelegate.m (159901 => 159902)


--- trunk/Tools/MiniBrowser/mac/AppDelegate.m	2013-12-01 23:40:27 UTC (rev 159901)
+++ trunk/Tools/MiniBrowser/mac/AppDelegate.m	2013-12-02 00:50:07 UTC (rev 159902)
@@ -125,8 +125,10 @@
     
     if (![sender respondsToSelector:@selector(tag)] || [sender tag] == WebKit1NewWindowTag)
         controller = [[WK1BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
+#if WK_API_ENABLED
     else if ([sender tag] == WebKit2NewWindowTag)
         controller = [[WK2BrowserWindowController alloc] initWithContext:_processContext pageGroup:_pageGroup];
+#endif
 
     if (!controller)
         return;
@@ -192,6 +194,7 @@
         return;
     }
 
+#if WK_API_ENABLED
     NSOpenPanel *openPanel = [NSOpenPanel openPanel];
     [openPanel beginWithCompletionHandler:^(NSInteger result) {
         if (result != NSOKButton)
@@ -204,6 +207,7 @@
         NSURL *url = "" objectAtIndex:0];
         [newBrowserWindowController loadURLString:[url absoluteString]];
     }];
+#endif // WK_API_ENABLED
 }
 
 @end

Modified: trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.h (159901 => 159902)


--- trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.h	2013-12-01 23:40:27 UTC (rev 159901)
+++ trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.h	2013-12-02 00:50:07 UTC (rev 159902)
@@ -25,12 +25,12 @@
 
 #import "BrowserWindowController.h"
 
-@interface WK2BrowserWindowController : BrowserWindowController<BrowserController> {
-    WKContextRef _context;
-    WKPageGroupRef _pageGroup;
-    WKView *_webView;
-}
+#if WK_API_ENABLED
 
+@interface WK2BrowserWindowController : BrowserWindowController <BrowserController>
+
 - (id)initWithContext:(WKContextRef)context pageGroup:(WKPageGroupRef)pageGroup;
 
 @end
+
+#endif // WK_API_ENABLED

Modified: trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m (159901 => 159902)


--- trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m	2013-12-01 23:40:27 UTC (rev 159901)
+++ trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m	2013-12-02 00:50:07 UTC (rev 159902)
@@ -25,13 +25,17 @@
 
 #import "WK2BrowserWindowController.h"
 
+#if WK_API_ENABLED
+
 #import "AppDelegate.h"
+#import <WebKit2/WKBrowsingContextController.h>
+#import <WebKit2/WKBrowsingContextPolicyDelegate.h>
 #import <WebKit2/WKPagePrivate.h>
 #import <WebKit2/WKStringCF.h>
 #import <WebKit2/WKURLCF.h>
 #import <WebKit2/WKViewPrivate.h>
 
-@interface WK2BrowserWindowController ()
+@interface WK2BrowserWindowController () <WKBrowsingContextPolicyDelegate>
 - (void)didStartProgress;
 - (void)didChangeProgress:(double)value;
 - (void)didFinishProgress;
@@ -44,7 +48,11 @@
 - (BOOL)isPaginated;
 @end
 
-@implementation WK2BrowserWindowController
+@implementation WK2BrowserWindowController {
+    WKContextRef _context;
+    WKPageGroupRef _pageGroup;
+    WKView *_webView;
+}
 
 - (id)initWithContext:(WKContextRef)context pageGroup:(WKPageGroupRef)pageGroup
 {
@@ -61,6 +69,7 @@
 {
     WKRelease(_context);
     WKRelease(_pageGroup);
+    _webView.browsingContextController.policyDelegate = nil;
     [_webView release];
 
     [super dealloc];
@@ -412,25 +421,6 @@
     [(WK2BrowserWindowController *)clientInfo validateToolbar];
 }
 
-// MARK: Policy Client Callbacks
-
-static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
-{
-    LOG(@"decidePolicyForNavigationAction");
-    WKFramePolicyListenerUse(listener);
-}
-
-static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
-{
-    LOG(@"decidePolicyForNewWindowAction");
-    WKFramePolicyListenerUse(listener);
-}
-
-static void decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, bool canShowMIMEType, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
-{
-    WKFramePolicyListenerUse(listener);
-}
-
 // MARK: UI Client Callbacks
 
 static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef request, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton button, const void* clientInfo)
@@ -666,19 +656,9 @@
         0, // pluginLoadPolicy
     };
     WKPageSetPageLoaderClient(_webView.pageRef, &loadClient);
-    
-    WKPagePolicyClient policyClient = {
-        kWKPagePolicyClientCurrentVersion,
-        self,       /* clientInfo */
-        0,          /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */
-        decidePolicyForNewWindowAction,
-        0,          /* decidePolicyForResponse_deprecatedForUseWithV */
-        0,          /* unableToImplementPolicy */
-        decidePolicyForNavigationAction,
-        decidePolicyForResponse,
-    };
-    WKPageSetPagePolicyClient(_webView.pageRef, &policyClient);
 
+    _webView.browsingContextController.policyDelegate = self;
+
     WKPageUIClient uiClient = {
         kWKPageUIClientCurrentVersion,
         self,       /* clientInfo */
@@ -847,4 +827,25 @@
     WKPageFindString(_webView.pageRef, string, kWKFindOptionsCaseInsensitive | kWKFindOptionsWrapAround | kWKFindOptionsShowFindIndicator | kWKFindOptionsShowOverlay, 100);
 }
 
+#pragma mark WKBrowsingContextPolicyDelegate
+
+- (void)browsingContextController:(WKBrowsingContextController *)browsingContext decidePolicyForNavigationAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler
+{
+    LOG(@"decidePolicyForNavigationAction");
+    decisionHandler(WKPolicyDecisionAllow);
+}
+
+- (void)browsingContextController:(WKBrowsingContextController *)browsingContext decidePolicyForNewWindowAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler
+{
+    LOG(@"decidePolicyForNewWindowAction");
+    decisionHandler(WKPolicyDecisionAllow);
+}
+
+- (void)browsingContextController:(WKBrowsingContextController *)browsingContext decidePolicyForResponseAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler
+{
+    decisionHandler(WKPolicyDecisionAllow);
+}
+
 @end
+
+#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to