Expose security origin to BundleFrame
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Nov 2012 22:26:02 +0000 (22:26 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Nov 2012 22:26:02 +0000 (22:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=101139
<rdar://problem/12629900>

Reviewed by Darin Adler.

Create a WebSecurityOrigin instance, sharing the security origin instance
that comes directly from the frame's document. We can do this because the
WK2 API only retrieves information about the origin, and because those
results are returned as copies. The security origin holds no references
that could lead to a retain cycle, avoiding the possibility that the
injected bundle accidentally keeps something alive.

* Shared/API/c/WKSharedAPICast.h:
(WebKit::toCopiedAPI): Create copied API for WebCore::SecurityOrigin
instances.
* Shared/WebSecurityOrigin.h:
(WebKit::WebSecurityOrigin::create): Add a new create() function that
takes a PassRefPtr to a WebCore SecurityOrigin instance.
(WebKit::WebSecurityOrigin::createFromString): Refactor to use new create()
function.
(WebKit::WebSecurityOrigin::createFromDatabaseIdentifier): Refactor to
use new create() function.
(WebKit::WebSecurityOrigin::create): Refactor to use new create()
function.
* WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
(WKBundleFrameCopySecurityOrigin): Add function to retrieve the security
origin as a WK2 API object.
* WebProcess/InjectedBundle/API/c/WKBundleFrame.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/c/WKSharedAPICast.h
Source/WebKit2/Shared/WebSecurityOrigin.h
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h

index ac72343..d1aaa96 100644 (file)
@@ -1,3 +1,35 @@
+2012-11-04  Jon Lee  <jonlee@apple.com>
+
+        Expose security origin to BundleFrame
+        https://bugs.webkit.org/show_bug.cgi?id=101139
+        <rdar://problem/12629900>
+
+        Reviewed by Darin Adler.
+
+        Create a WebSecurityOrigin instance, sharing the security origin instance
+        that comes directly from the frame's document. We can do this because the
+        WK2 API only retrieves information about the origin, and because those
+        results are returned as copies. The security origin holds no references
+        that could lead to a retain cycle, avoiding the possibility that the
+        injected bundle accidentally keeps something alive.
+
+        * Shared/API/c/WKSharedAPICast.h:
+        (WebKit::toCopiedAPI): Create copied API for WebCore::SecurityOrigin
+        instances.
+        * Shared/WebSecurityOrigin.h:
+        (WebKit::WebSecurityOrigin::create): Add a new create() function that
+        takes a PassRefPtr to a WebCore SecurityOrigin instance.
+        (WebKit::WebSecurityOrigin::createFromString): Refactor to use new create()
+        function.
+        (WebKit::WebSecurityOrigin::createFromDatabaseIdentifier): Refactor to
+        use new create() function.
+        (WebKit::WebSecurityOrigin::create): Refactor to use new create()
+        function.
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
+        (WKBundleFrameCopySecurityOrigin): Add function to retrieve the security
+        origin as a WK2 API object.
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
+
 2012-11-02  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         [EFL] Unify transforms in WK2
index ff9a50f..380cd25 100644 (file)
@@ -39,6 +39,7 @@
 #include "WebEvent.h"
 #include "WebFindOptions.h"
 #include "WebNumber.h"
+#include "WebSecurityOrigin.h"
 #include "WebString.h"
 #include "WebURL.h"
 #include "WebURLRequest.h"
@@ -48,6 +49,7 @@
 #include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/LayoutMilestones.h>
+#include <WebCore/SecurityOrigin.h>
 #include <WebCore/UserContentTypes.h>
 #include <WebCore/UserScriptTypes.h>
 #include <wtf/TypeTraits.h>
@@ -197,6 +199,13 @@ inline ProxyingRefPtr<WebURLResponse> toAPI(const WebCore::ResourceResponse& res
     return ProxyingRefPtr<WebURLResponse>(WebURLResponse::create(response));
 }
 
+inline WKSecurityOriginRef toCopiedAPI(WebCore::SecurityOrigin* origin)
+{
+    if (!origin)
+        return 0;
+    return toAPI(WebSecurityOrigin::create(origin).leakRef());
+}
+
 /* Geometry conversions */
 
 inline WebCore::FloatRect toFloatRect(const WKRect& wkRect)
index 66074c5..b6ec1c9 100644 (file)
@@ -38,26 +38,24 @@ public:
 
     static PassRefPtr<WebSecurityOrigin> createFromString(const String& string)
     {
-        RefPtr<WebCore::SecurityOrigin> securityOrigin = WebCore::SecurityOrigin::createFromString(string);
-        if (!securityOrigin)
-            return 0;
-        return adoptRef(new WebSecurityOrigin(securityOrigin.release()));
+        return create(WebCore::SecurityOrigin::createFromString(string));
     }
 
     static PassRefPtr<WebSecurityOrigin> createFromDatabaseIdentifier(const String& identifier)
     {
-        RefPtr<WebCore::SecurityOrigin> securityOrigin = WebCore::SecurityOrigin::createFromDatabaseIdentifier(identifier);
-        if (!securityOrigin)
-            return 0;
-        return adoptRef(new WebSecurityOrigin(securityOrigin.release()));
+        return create(WebCore::SecurityOrigin::createFromDatabaseIdentifier(identifier));
     }
 
     static PassRefPtr<WebSecurityOrigin> create(const String& protocol, const String& host, int port)
     {
-        RefPtr<WebCore::SecurityOrigin> securityOrigin = WebCore::SecurityOrigin::create(protocol, host, port);
+        return create(WebCore::SecurityOrigin::create(protocol, host, port));
+    }
+
+    static PassRefPtr<WebSecurityOrigin> create(PassRefPtr<WebCore::SecurityOrigin> securityOrigin)
+    {
         if (!securityOrigin)
             return 0;
-        return adoptRef(new WebSecurityOrigin(securityOrigin.release()));
+        return adoptRef(new WebSecurityOrigin(securityOrigin));
     }
 
     const String protocol() const { return m_securityOrigin->protocol(); }
index 24188ff..f00e035 100644 (file)
@@ -32,6 +32,7 @@
 #include "WKBundleAPICast.h"
 #include "WKData.h"
 #include "WebFrame.h"
+#include "WebSecurityOrigin.h"
 #include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
 
@@ -286,3 +287,12 @@ WKBundleHitTestResultRef WKBundleFrameCreateHitTestResult(WKBundleFrameRef frame
 {
     return toAPI(toImpl(frameRef)->hitTest(toIntPoint(point)).leakRef());
 }
+
+WKSecurityOriginRef WKBundleFrameCopySecurityOrigin(WKBundleFrameRef frameRef)
+{
+    Frame* coreFrame = toImpl(frameRef)->coreFrame();
+    if (!coreFrame)
+        return 0;
+
+    return toCopiedAPI(coreFrame->document()->securityOrigin());
+}
index 021aec0..8c2b875 100644 (file)
@@ -44,6 +44,7 @@ WK_EXPORT WKArrayRef WKBundleFrameCopyChildFrames(WKBundleFrameRef frame);
 WK_EXPORT WKStringRef WKBundleFrameCopyName(WKBundleFrameRef frame);
 WK_EXPORT WKURLRef WKBundleFrameCopyURL(WKBundleFrameRef frame);
 WK_EXPORT WKURLRef WKBundleFrameCopyProvisionalURL(WKBundleFrameRef frame);
+WK_EXPORT WKSecurityOriginRef WKBundleFrameCopySecurityOrigin(WKBundleFrameRef frame);
 
 WK_EXPORT WKFrameLoadState WKBundleFrameGetFrameLoadState(WKBundleFrameRef frame);