Title: [158764] trunk/Source/WebKit2
Revision
158764
Author
[email protected]
Date
2013-11-06 11:42:09 -0800 (Wed, 06 Nov 2013)

Log Message

Add WKBrowsingContextPolicyDelegate
https://bugs.webkit.org/show_bug.cgi?id=123904

Reviewed by Anders Carlsson.

* UIProcess/API/mac/WKBrowsingContextController.h:
* UIProcess/API/mac/WKBrowsingContextController.mm:
Implement a WKPagePolicyClient in terms of the new WKBrowsingContextPolicyDelegate protocol.
        
* UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h: 
Added.

* UIProcess/API/mac/WebKit2.h:
Add new #include of WKBrowsingContextPolicyDelegate.h

* WebKit2.xcodeproj/project.pbxproj:
Add new file.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (158763 => 158764)


--- trunk/Source/WebKit2/ChangeLog	2013-11-06 19:23:20 UTC (rev 158763)
+++ trunk/Source/WebKit2/ChangeLog	2013-11-06 19:42:09 UTC (rev 158764)
@@ -1,3 +1,23 @@
+2013-11-06  Sam Weinig  <[email protected]>
+
+        Add WKBrowsingContextPolicyDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=123904
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/mac/WKBrowsingContextController.h:
+        * UIProcess/API/mac/WKBrowsingContextController.mm:
+        Implement a WKPagePolicyClient in terms of the new WKBrowsingContextPolicyDelegate protocol.
+        
+        * UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h: 
+        Added.
+
+        * UIProcess/API/mac/WebKit2.h:
+        Add new #include of WKBrowsingContextPolicyDelegate.h
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add new file.
+
 2013-11-06  Anders Carlsson  <[email protected]>
 
         WKRemoteObjectInterface should keep track of allowed decodable classes

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h (158763 => 158764)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h	2013-11-06 19:23:20 UTC (rev 158763)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h	2013-11-06 19:42:09 UTC (rev 158764)
@@ -32,6 +32,7 @@
 @class WKBackForwardListItem;
 @protocol WKBrowsingContextHistoryDelegate;
 @protocol WKBrowsingContextLoadDelegate;
+@protocol WKBrowsingContextPolicyDelegate;
 
 WK_EXPORT
 @interface WKBrowsingContextController : NSObject {
@@ -41,7 +42,8 @@
 
 #pragma mark Delegates
 
-@property(assign) id<WKBrowsingContextLoadDelegate> loadDelegate;
+@property (assign) id <WKBrowsingContextLoadDelegate> loadDelegate;
+@property (assign) id <WKBrowsingContextPolicyDelegate> policyDelegate;
 
 #if WK_API_ENABLED
 @property (assign) id <WKBrowsingContextHistoryDelegate> historyDelegate;

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm (158763 => 158764)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm	2013-11-06 19:23:20 UTC (rev 158763)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm	2013-11-06 19:42:09 UTC (rev 158764)
@@ -33,6 +33,7 @@
 #import "WKBackForwardListItemInternal.h"
 #import "WKErrorCF.h"
 #import "WKFrame.h"
+#import "WKFramePolicyListener.h"
 #import "WKNSArray.h"
 #import "WKPagePrivate.h"
 #import "WKRetainPtr.h"
@@ -40,6 +41,8 @@
 #import "WKURLCF.h"
 #import "WKURLRequest.h"
 #import "WKURLRequestNS.h"
+#import "WKURLResponse.h"
+#import "WKURLResponseNS.h"
 #import "WebContext.h"
 #import "WebData.h"
 #import "WebPageProxy.h"
@@ -47,6 +50,7 @@
 #import <wtf/RetainPtr.h>
 
 #import "WKBrowsingContextLoadDelegate.h"
+#import "WKBrowsingContextPolicyDelegate.h"
 
 using namespace WebKit;
 
@@ -60,6 +64,24 @@
     return url ? CFBridgingRelease(WKURLCopyCFURL(kCFAllocatorDefault, adoptWK(url).get())) : nil;
 }
 
+static inline NSURLRequest *autoreleased(WKURLRequestRef urlRequest)
+{
+    return urlRequest ? CFBridgingRelease(WKURLRequestCopyNSURLRequest(adoptWK(urlRequest).get())) : nil;
+}
+
+static inline NSURLResponse *autoreleased(WKURLResponseRef urlResponse)
+{
+    return urlResponse ? CFBridgingRelease(WKURLResponseCopyNSURLResponse(adoptWK(urlResponse).get())) : nil;
+}
+
+NSString *WKActionIsMainFrameKey = @"WKActionIsMainFrameKey";
+NSString *WKActionNavigationTypeKey = @"WKActionNavigationTypeKey";
+NSString *WKActionMouseButtonKey = @"WKActionMouseButtonKey";
+NSString *WKActionModifierFlagsKey = @"WKActionModifierFlagsKey";
+NSString *WKActionURLRequestKey = @"WKActionURLRequestKey";
+NSString *WKActionURLResponseKey = @"WKActionURLResponseKey";
+NSString *WKActionFrameNameKey = @"WKActionFrameNameKey";
+
 @interface WKBrowsingContextControllerData : NSObject {
 @public
     // Underlying WKPageRef.
@@ -67,6 +89,9 @@
     
     // Delegate for load callbacks.
     id<WKBrowsingContextLoadDelegate> _loadDelegate;
+
+    // Delegate for policy callbacks.
+    id<WKBrowsingContextPolicyDelegate> _policyDelegate;
 }
 @end
 
@@ -78,7 +103,8 @@
 
 - (void)dealloc
 {
-    WKPageSetPageLoaderClient(_data->_pageRef.get(), 0);
+    WKPageSetPageLoaderClient(_data->_pageRef.get(), nullptr);
+    WKPageSetPagePolicyClient(_data->_pageRef.get(), nullptr);
 
     [_data release];
     [super dealloc];
@@ -101,6 +127,16 @@
     _data->_loadDelegate = loadDelegate;
 }
 
+- (id<WKBrowsingContextPolicyDelegate>)policyDelegate
+{
+    return _data->_policyDelegate;
+}
+
+- (void)setPolicyDelegate:(id<WKBrowsingContextPolicyDelegate>)policyDelegate
+{
+    _data->_policyDelegate = policyDelegate;
+}
+
 #pragma mark Loading
 
 + (void)registerSchemeForCustomProtocol:(NSString *)scheme
@@ -533,7 +569,88 @@
     WKPageSetPageLoaderClient(pageRef, &loaderClient);
 }
 
+static WKPolicyDecisionHandler makePolicyDecisionBlock(WKFramePolicyListenerRef listener)
+{
+    WKRetain(listener); // Released in the decision handler below.
 
+    return [[^(WKPolicyDecision decision) {
+        switch (decision) {
+        case WKPolicyDecisionCancel:
+            WKFramePolicyListenerIgnore(listener);                    
+            break;
+        
+        case WKPolicyDecisionAllow:
+            WKFramePolicyListenerUse(listener);
+            break;
+        
+        case WKPolicyDecisionBecomeDownload:
+            WKFramePolicyListenerDownload(listener);
+            break;
+        };
+
+        WKRelease(listener); // Retained in the context above.
+    } copy] autorelease];
+}
+
+static void setUpPagePolicyClient(WKBrowsingContextController *browsingContext, WKPageRef pageRef)
+{
+    WKPagePolicyClient policyClient;
+    memset(&policyClient, 0, sizeof(policyClient));
+
+    policyClient.version = kWKPagePolicyClientCurrentVersion;
+    policyClient.clientInfo = browsingContext;
+
+    policyClient.decidePolicyForNavigationAction = [](WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
+    {
+        WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo;
+        if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNavigationAction:decisionHandler:)]) {
+            NSDictionary *actionDictionary = @{
+                WKActionIsMainFrameKey: @(WKFrameIsMainFrame(frame)),
+                WKActionNavigationTypeKey: @(navigationType),
+                WKActionModifierFlagsKey: @(modifiers),
+                WKActionMouseButtonKey: @(mouseButton),
+                WKActionURLRequestKey: autoreleased(request)
+            };
+            
+            [browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForNavigationAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];
+        }
+    };
+
+    policyClient.decidePolicyForNewWindowAction = [](WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
+    {
+        WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo;
+        if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNewWindowAction:decisionHandler:)]) {
+            NSDictionary *actionDictionary = @{
+                WKActionIsMainFrameKey: @(WKFrameIsMainFrame(frame)),
+                WKActionNavigationTypeKey: @(navigationType),
+                WKActionModifierFlagsKey: @(modifiers),
+                WKActionMouseButtonKey: @(mouseButton),
+                WKActionURLRequestKey: autoreleased(request),
+                WKActionFrameNameKey: toImpl(frameName)->wrapper()
+            };
+            
+            [browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForNewWindowAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];
+        }
+
+    };
+
+    policyClient.decidePolicyForResponse = [](WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
+    {
+        WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo;
+        if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForResponseAction:decisionHandler:)]) {
+            NSDictionary *actionDictionary = @{
+                WKActionIsMainFrameKey: @(WKFrameIsMainFrame(frame)),
+                WKActionURLRequestKey: autoreleased(request),
+                WKActionURLResponseKey: autoreleased(response)
+            };
+
+            [browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForResponseAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];
+        }
+    };
+
+    WKPageSetPagePolicyClient(pageRef, &policyClient);
+}
+
 /* This should only be called from associate view. */
 
 - (id)_initWithPageRef:(WKPageRef)pageRef
@@ -546,6 +663,7 @@
     _data->_pageRef = pageRef;
 
     setUpPageLoaderClient(self, pageRef);
+    setUpPagePolicyClient(self, pageRef);
 
     return self;
 }

Added: trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h (0 => 158764)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h	2013-11-06 19:42:09 UTC (rev 158764)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+@class WKBrowsingContextController;
+
+/* Constants for policy action dictionaries */
+extern NSString *WKActionIsMainFrameKey;    // NSNumber (BOOL)
+extern NSString *WKActionNavigationTypeKey; // NSNumber (WKNavigationType)
+extern NSString *WKActionMouseButtonKey;    // NSNumber (0 for left button, 1 for middle button, 2 for right button)
+extern NSString *WKActionModifierFlagsKey;  // NSNumber (unsigned)
+extern NSString *WKActionURLRequestKey;     // NSURLRequest
+extern NSString *WKActionURLResponseKey;    // NSURLResponse
+extern NSString *WKActionFrameNameKey;      // NSString
+
+typedef NS_ENUM(NSUInteger, WKNavigationType) {
+    WKNavigationTypeLinkClicked,
+    WKNavigationTypeFormSubmitted,
+    WKNavigationTypeBackForward,
+    WKNavigationTypeReload,
+    WKNavigationTypeFormResubmitted,
+    WKNavigationTypeOther
+};
+
+typedef NS_ENUM(NSUInteger, WKPolicyDecision) {
+    WKPolicyDecisionCancel,
+    WKPolicyDecisionAllow,
+    WKPolicyDecisionBecomeDownload
+};
+
+typedef void (^WKPolicyDecisionHandler)(WKPolicyDecision);
+
+@protocol WKBrowsingContextPolicyDelegate <NSObject>
+@optional
+
+- (void)browsingContextController:(WKBrowsingContextController *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler;
+- (void)browsingContextController:(WKBrowsingContextController *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler;
+- (void)browsingContextController:(WKBrowsingContextController *)sender decidePolicyForResponseAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler;
+
+@end

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WebKit2.h (158763 => 158764)


--- trunk/Source/WebKit2/UIProcess/API/mac/WebKit2.h	2013-11-06 19:23:20 UTC (rev 158763)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WebKit2.h	2013-11-06 19:42:09 UTC (rev 158764)
@@ -26,6 +26,7 @@
 #import <WebKit2/WKBrowsingContextController.h>
 #import <WebKit2/WKBrowsingContextGroup.h>
 #import <WebKit2/WKBrowsingContextLoadDelegate.h>
+#import <WebKit2/WKBrowsingContextPolicyDelegate.h>
 #import <WebKit2/WKConnection.h>
 #import <WebKit2/WKFoundation.h>
 #import <WebKit2/WKProcessGroup.h>

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (158763 => 158764)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-11-06 19:23:20 UTC (rev 158763)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-11-06 19:42:09 UTC (rev 158764)
@@ -665,6 +665,7 @@
 		7C3F8C90173AF52D007B7F39 /* PluginInformation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3F8C8E173AF52D007B7F39 /* PluginInformation.cpp */; };
 		7C3F8C91173AF52D007B7F39 /* PluginInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3F8C8F173AF52D007B7F39 /* PluginInformation.h */; };
 		7C6D37FC172F555F009D2847 /* PageBannerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C6D37FA172F555F009D2847 /* PageBannerMac.mm */; };
+		7CA254EB182993CE00FC8A41 /* WKBrowsingContextPolicyDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CA254EA182993CE00FC8A41 /* WKBrowsingContextPolicyDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		7CB16FEF1724BA23007A0A95 /* com.apple.ist.ds.appleconnect.webplugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 7CB16FE21724B9B5007A0A95 /* com.apple.ist.ds.appleconnect.webplugin.sb */; };
 		7CB16FF01724BA24007A0A95 /* com.apple.QuickTime Plugin.plugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 7CB16FE31724B9B5007A0A95 /* com.apple.QuickTime Plugin.plugin.sb */; };
 		7CB16FF11724BA26007A0A95 /* com.apple.WebKit.plugin-common.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 7CB16FE41724B9B5007A0A95 /* com.apple.WebKit.plugin-common.sb */; };
@@ -2195,6 +2196,7 @@
 		7C3F8C8E173AF52D007B7F39 /* PluginInformation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginInformation.cpp; sourceTree = "<group>"; };
 		7C3F8C8F173AF52D007B7F39 /* PluginInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInformation.h; sourceTree = "<group>"; };
 		7C6D37FA172F555F009D2847 /* PageBannerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageBannerMac.mm; sourceTree = "<group>"; };
+		7CA254EA182993CE00FC8A41 /* WKBrowsingContextPolicyDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBrowsingContextPolicyDelegate.h; sourceTree = "<group>"; };
 		7CB16FE21724B9B5007A0A95 /* com.apple.ist.ds.appleconnect.webplugin.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.ist.ds.appleconnect.webplugin.sb; sourceTree = "<group>"; };
 		7CB16FE31724B9B5007A0A95 /* com.apple.QuickTime Plugin.plugin.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "com.apple.QuickTime Plugin.plugin.sb"; sourceTree = "<group>"; };
 		7CB16FE41724B9B5007A0A95 /* com.apple.WebKit.plugin-common.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "com.apple.WebKit.plugin-common.sb"; sourceTree = "<group>"; };
@@ -4577,6 +4579,7 @@
 				BCBAACEF145232440053F82F /* WKBrowsingContextGroup.mm */,
 				BCBAACF0145232480053F82F /* WKBrowsingContextGroupPrivate.h */,
 				BCBAAD0A14560A430053F82F /* WKBrowsingContextLoadDelegate.h */,
+				7CA254EA182993CE00FC8A41 /* WKBrowsingContextPolicyDelegate.h */,
 				BCA284D51492F2C7001F9042 /* WKConnection.h */,
 				BCA284D41492F2C7001F9042 /* WKConnection.mm */,
 				BC5C75C614954DA600BC4775 /* WKConnectionInternal.h */,
@@ -5510,6 +5513,7 @@
 				93FC67C012D3CCF200A60610 /* EncoderAdapter.h in Headers */,
 				51B15A8513843A3900321AD8 /* EnvironmentUtilities.h in Headers */,
 				1A7C6CDB1378950800B9C04D /* EnvironmentVariables.h in Headers */,
+				7CA254EB182993CE00FC8A41 /* WKBrowsingContextPolicyDelegate.h in Headers */,
 				1AA575FB1496B52600A4EE06 /* EventDispatcher.h in Headers */,
 				1A90C1F41264FD71003E44D4 /* FindController.h in Headers */,
 				1A910071126675C4001842F5 /* FindIndicator.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to