Wrap NSURLRequest in bundle API
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jun 2014 15:36:58 +0000 (15:36 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jun 2014 15:36:58 +0000 (15:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133732
<rdar://problem/17267217>

Reviewed by Andreas Kling.

Patch by Dan Bernstein.

We don't want to construct actual NSURLRequests in the web process side unless really needed as it is slow.

* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):
* Shared/Cocoa/WKNSURLRequest.h: Added.
(WebKit::wrapper):
* Shared/Cocoa/WKNSURLRequest.mm: Added.

    Add a wrapper object that initializes the underlying NSURLRequest on-demand.

(-[WKNSURLRequest _web_createTarget]):
(-[WKNSURLRequest URL]):
(-[WKNSURLRequest copyWithZone:]):
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(willSendRequestForFrame):
(didInitiateLoadForResource):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169807 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/Cocoa/APIObject.mm
Source/WebKit2/Shared/Cocoa/WKNSURLRequest.h [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WKNSURLRequest.mm [new file with mode: 0644]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm

index 4e6896f..b0254bc 100644 (file)
@@ -1,3 +1,31 @@
+2014-06-11  Antti Koivisto  <antti@apple.com>
+
+        Wrap NSURLRequest in bundle API
+        https://bugs.webkit.org/show_bug.cgi?id=133732
+        <rdar://problem/17267217>
+
+        Reviewed by Andreas Kling.
+        
+        Patch by Dan Bernstein.
+
+        We don't want to construct actual NSURLRequests in the web process side unless really needed as it is slow.
+
+        * Shared/Cocoa/APIObject.mm:
+        (API::Object::newObject):
+        * Shared/Cocoa/WKNSURLRequest.h: Added.
+        (WebKit::wrapper):
+        * Shared/Cocoa/WKNSURLRequest.mm: Added.
+        
+            Add a wrapper object that initializes the underlying NSURLRequest on-demand.
+
+        (-[WKNSURLRequest _web_createTarget]):
+        (-[WKNSURLRequest URL]):
+        (-[WKNSURLRequest copyWithZone:]):
+        * WebKit2.xcodeproj/project.pbxproj:
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        (willSendRequestForFrame):
+        (didInitiateLoadForResource):
+
 2014-06-11  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/17218629> [Cocoa] WKWebView’s canGoBack and canGoForward properties are not KVO-compliant
index 31ad24a..771e034 100644 (file)
@@ -41,6 +41,7 @@
 #import "WKNSURL.h"
 #import "WKNSURLAuthenticationChallenge.h"
 #import "WKNSURLProtectionSpace.h"
+#import "WKNSURLRequest.h"
 #import "WKNavigationDataInternal.h"
 #import "WKProcessPoolInternal.h"
 #import "WKWebProcessPlugInBrowserContextControllerInternal.h"
@@ -151,6 +152,10 @@ void* Object::newObject(size_t size, Type type)
         wrapper = NSAllocateObject([WKNSURL class], size, nullptr);
         break;
 
+    case Type::URLRequest:
+        wrapper = NSAllocateObject([WKNSURLRequest class], size, nullptr);
+        break;
+
     case Type::BundleFrame:
         wrapper = [WKWebProcessPlugInFrame alloc];
         break;
diff --git a/Source/WebKit2/Shared/Cocoa/WKNSURLRequest.h b/Source/WebKit2/Shared/Cocoa/WKNSURLRequest.h
new file mode 100644 (file)
index 0000000..883da16
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2014 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 "WKFoundation.h"
+
+#if WK_API_ENABLED
+
+#import "APIURLRequest.h"
+#import "WKObject.h"
+
+namespace WebKit {
+
+inline NSURLRequest *wrapper(API::URLRequest& request)
+{
+    return (NSURLRequest *)request.wrapper();
+}
+
+}
+
+@interface WKNSURLRequest : WKObject <NSCopying>
+@end
+
+#endif // WK_API_ENABLED
diff --git a/Source/WebKit2/Shared/Cocoa/WKNSURLRequest.mm b/Source/WebKit2/Shared/Cocoa/WKNSURLRequest.mm
new file mode 100644 (file)
index 0000000..30ebdb7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 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 "config.h"
+#import "WKNSURLRequest.h"
+
+#if WK_API_ENABLED
+
+#import "WKNSURLExtras.h"
+
+@implementation WKNSURLRequest
+
+- (NSObject *)_web_createTarget
+{
+    return [static_cast<API::URLRequest*>(&self._apiObject)->resourceRequest().nsURLRequest(WebCore::DoNotUpdateHTTPBody) copy];
+}
+
+- (NSURL *)URL
+{
+    return [NSURL _web_URLWithWTFString:static_cast<API::URLRequest*>(&self._apiObject)->resourceRequest().url().string()];
+}
+
+#pragma mark NSCopying protocol implementation
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+@end
+
+#endif // WK_API_ENABLED
index fcd2a4e..08e96b7 100644 (file)
                37A5E01418BBF93F000A081E /* _WKActivatedElementInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 37A5E01218BBF937000A081E /* _WKActivatedElementInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                37A64E5518F38E3C00EB30F1 /* _WKFormDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 37A64E5418F38E3C00EB30F1 /* _WKFormDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                37A64E5718F38F4600EB30F1 /* _WKFormInputSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 37A64E5618F38F4600EB30F1 /* _WKFormInputSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               37BF2F061947DEB400723C48 /* WKNSURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 37BF2F041947DEB400723C48 /* WKNSURLRequest.h */; };
+               37BF2F071947DEB400723C48 /* WKNSURLRequest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37BF2F051947DEB400723C48 /* WKNSURLRequest.mm */; };
                37C4C08618149C5B003688B9 /* WKBackForwardListItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C4C08418149C5B003688B9 /* WKBackForwardListItem.mm */; };
                37C4C08718149C5B003688B9 /* WKBackForwardListItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08518149C5B003688B9 /* WKBackForwardListItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
                37C4C08918149F23003688B9 /* WKBackForwardListItemInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */; };
                37A5E01218BBF937000A081E /* _WKActivatedElementInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKActivatedElementInfo.h; sourceTree = "<group>"; };
                37A64E5418F38E3C00EB30F1 /* _WKFormDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKFormDelegate.h; sourceTree = "<group>"; };
                37A64E5618F38F4600EB30F1 /* _WKFormInputSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKFormInputSession.h; sourceTree = "<group>"; };
+               37BF2F041947DEB400723C48 /* WKNSURLRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSURLRequest.h; sourceTree = "<group>"; };
+               37BF2F051947DEB400723C48 /* WKNSURLRequest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSURLRequest.mm; sourceTree = "<group>"; };
                37C4C08418149C5B003688B9 /* WKBackForwardListItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKBackForwardListItem.mm; sourceTree = "<group>"; };
                37C4C08518149C5B003688B9 /* WKBackForwardListItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListItem.h; sourceTree = "<group>"; };
                37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListItemInternal.h; sourceTree = "<group>"; };
                                37183D54182F4E700080C811 /* WKNSURLExtras.mm */,
                                371B32DC184D67490013E2B2 /* WKNSURLProtectionSpace.h */,
                                371B32DB184D67480013E2B2 /* WKNSURLProtectionSpace.mm */,
+                               37BF2F041947DEB400723C48 /* WKNSURLRequest.h */,
+                               37BF2F051947DEB400723C48 /* WKNSURLRequest.mm */,
                                378E1A3F181EDA010031007A /* WKObject.h */,
                                374436871820E7240049579F /* WKObject.mm */,
                        );
                                CEDA12E3152CD1B300D9E08D /* WebAlternativeTextClient.h in Headers */,
                                512E352F130B55AF00ABD19A /* WebApplicationCacheManager.h in Headers */,
                                1A256E3A18A1A7DF006FB922 /* WKNavigationActionInternal.h in Headers */,
+                               37BF2F061947DEB400723C48 /* WKNSURLRequest.h in Headers */,
                                512E356B130B57F000ABD19A /* WebApplicationCacheManagerMessages.h in Headers */,
                                512E3525130B550600ABD19A /* WebApplicationCacheManagerProxy.h in Headers */,
                                512E35F9130B642E00ABD19A /* WebApplicationCacheManagerProxyMessages.h in Headers */,
                                BC646C1A11DD399F006455B0 /* WKBackForwardListRef.cpp in Sources */,
                                BC646C1C11DD399F006455B0 /* WKBackForwardListItemRef.cpp in Sources */,
                                1A256E3718A1A788006FB922 /* WKNavigationAction.mm in Sources */,
+                               37BF2F071947DEB400723C48 /* WKNSURLRequest.mm in Sources */,
                                BCBAAC72144E61990053F82F /* WKBrowsingContextController.mm in Sources */,
                                BCBAACF51452324F0053F82F /* WKBrowsingContextGroup.mm in Sources */,
                                51290992183ACEAF005522A6 /* WebIDBServerConnection.cpp in Sources */,
index 4e732b0..1dd6b98 100644 (file)
@@ -38,6 +38,7 @@
 #import "WKDOMInternals.h"
 #import "WKNSDictionary.h"
 #import "WKNSError.h"
+#import "WKNSURLRequest.h"
 #import "WKRenderingProgressEventsInternal.h"
 #import "WKRetainPtr.h"
 #import "WKURLRequestNS.h"
@@ -205,7 +206,7 @@ static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef
     auto loadDelegate = pluginContextController->_loadDelegate.get();
 
     if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequest:redirectResponse:)]) {
-        NSURLRequest *originalRequest = toImpl(request)->resourceRequest().nsURLRequest(DoNotUpdateHTTPBody);
+        NSURLRequest *originalRequest = wrapper(*toImpl(request));
         RetainPtr<NSURLRequest> substituteRequest = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*toImpl(frame)) willSendRequest:originalRequest
             redirectResponse:toImpl(redirectResponse)->resourceResponse().nsURLResponse()];
 
@@ -226,7 +227,7 @@ static void didInitiateLoadForResource(WKBundlePageRef, WKBundleFrameRef frame,
         [loadDelegate webProcessPlugInBrowserContextController:pluginContextController
                                                          frame:wrapper(*toImpl(frame))
                                     didInitiateLoadForResource:resourceIdentifier
-                                                       request:toImpl(request)->resourceRequest().nsURLRequest(DoNotUpdateHTTPBody)];
+                                                       request:wrapper(*toImpl(request))];
     }
 }