Title: [106139] trunk
Revision
106139
Author
adac...@apple.com
Date
2012-01-27 11:40:22 -0800 (Fri, 27 Jan 2012)

Log Message

Source/WebKit2: Add API to get the parent frame in WKBundleFrameRef
https://bugs.webkit.org/show_bug.cgi?id=77161

Reviewed by Anders Carlsson.

* WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
(WKBundleFrameGetParentFrame): Get the parent frame by calling WebFrame::parentFrame().
* WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::parentFrame): Return null if the frame does not have an owner element.
Otherwise, return the owner element's frame.
* WebProcess/WebPage/WebFrame.h:

Tools: Add test for WKBundleFrameGetParentFrame().
https://bugs.webkit.org/show_bug.cgi?id=77161

Reviewed by Anders Carlsson.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add ParentFrame.cpp and ParentFrame_Bundle.cpp.
* TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp: Added.
(TestWebKitAPI):
(TestWebKitAPI::didReceiveMessageFromInjectedBundle): Get the check result from the injected bundle.
(TestWebKitAPI::setInjectedBundleClient):
(TestWebKitAPI::TEST): Load simple-iframe.html and then wait for the injected bundle to post result.
Make sure the check is successful.
* TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp: Added.
(TestWebKitAPI):
(ParentFrameTest):
(TestWebKitAPI::ParentFrameTest::ParentFrameTest):
(TestWebKitAPI::didFinishLoadForFrame): If the frame is a subframe, store it off for checking later.
If the frame is the main frame, check whether it's indeed the subframe's parent frame and post the result
to the test controller.
(TestWebKitAPI::ParentFrameTest::didCreatePage): Set the page loader client on this page.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (106138 => 106139)


--- trunk/Source/WebKit2/ChangeLog	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Source/WebKit2/ChangeLog	2012-01-27 19:40:22 UTC (rev 106139)
@@ -1,3 +1,18 @@
+2012-01-27  Ada Chan  <adac...@apple.com>
+
+        Add API to get the parent frame in WKBundleFrameRef
+        https://bugs.webkit.org/show_bug.cgi?id=77161
+
+        Reviewed by Anders Carlsson.
+
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
+        (WKBundleFrameGetParentFrame): Get the parent frame by calling WebFrame::parentFrame().
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::parentFrame): Return null if the frame does not have an owner element.
+        Otherwise, return the owner element's frame.
+        * WebProcess/WebPage/WebFrame.h:
+
 2012-01-27  Gustavo Noronha Silva  <g...@gnome.org>
 
         [GTK] Sometimes fails to build when using make -j

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp (106138 => 106139)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp	2012-01-27 19:40:22 UTC (rev 106139)
@@ -47,6 +47,11 @@
     return toImpl(frameRef)->isMainFrame();
 }
 
+WKBundleFrameRef WKBundleFrameGetParentFrame(WKBundleFrameRef frameRef)
+{
+    return toAPI(toImpl(frameRef)->parentFrame());
+}
+
 WKURLRef WKBundleFrameCopyURL(WKBundleFrameRef frameRef)
 {
     return toCopiedURLAPI(toImpl(frameRef)->url());

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h (106138 => 106139)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h	2012-01-27 19:40:22 UTC (rev 106139)
@@ -38,6 +38,7 @@
 WK_EXPORT WKTypeID WKBundleFrameGetTypeID();
 
 WK_EXPORT bool WKBundleFrameIsMainFrame(WKBundleFrameRef frame);
+WK_EXPORT WKBundleFrameRef WKBundleFrameGetParentFrame(WKBundleFrameRef frame);
 WK_EXPORT WKArrayRef WKBundleFrameCopyChildFrames(WKBundleFrameRef frame);
 
 WK_EXPORT WKStringRef WKBundleFrameCopyName(WKBundleFrameRef frame);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp (106138 => 106139)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp	2012-01-27 19:40:22 UTC (rev 106139)
@@ -357,6 +357,14 @@
     return m_coreFrame->document()->documentElement()->innerText();
 }
 
+WebFrame* WebFrame::parentFrame() const
+{
+    if (!m_coreFrame || !m_coreFrame->ownerElement() || !m_coreFrame->ownerElement()->document())
+        return 0;
+
+    return static_cast<WebFrameLoaderClient*>(m_coreFrame->ownerElement()->document()->frame()->loader()->client())->webFrame();
+}
+
 PassRefPtr<ImmutableArray> WebFrame::childFrames()
 {
     if (!m_coreFrame)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h (106138 => 106139)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h	2012-01-27 19:40:22 UTC (rev 106139)
@@ -86,6 +86,7 @@
     String url() const;
     String innerText() const;
     bool isFrameSet() const;
+    WebFrame* parentFrame() const;
     PassRefPtr<ImmutableArray> childFrames();
     JSValueRef computedStyleIncludingVisitedInfo(JSObjectRef element);
     JSGlobalContextRef jsContext();

Modified: trunk/Tools/ChangeLog (106138 => 106139)


--- trunk/Tools/ChangeLog	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Tools/ChangeLog	2012-01-27 19:40:22 UTC (rev 106139)
@@ -1,3 +1,26 @@
+2012-01-27  Ada Chan  <adac...@apple.com>
+
+        Add test for WKBundleFrameGetParentFrame().
+        https://bugs.webkit.org/show_bug.cgi?id=77161
+
+        Reviewed by Anders Carlsson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add ParentFrame.cpp and ParentFrame_Bundle.cpp.
+        * TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp: Added.
+        (TestWebKitAPI):
+        (TestWebKitAPI::didReceiveMessageFromInjectedBundle): Get the check result from the injected bundle.
+        (TestWebKitAPI::setInjectedBundleClient):
+        (TestWebKitAPI::TEST): Load simple-iframe.html and then wait for the injected bundle to post result.
+        Make sure the check is successful.
+        * TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp: Added.
+        (TestWebKitAPI):
+        (ParentFrameTest):
+        (TestWebKitAPI::ParentFrameTest::ParentFrameTest):
+        (TestWebKitAPI::didFinishLoadForFrame): If the frame is a subframe, store it off for checking later.
+        If the frame is the main frame, check whether it's indeed the subframe's parent frame and post the result
+        to the test controller.
+        (TestWebKitAPI::ParentFrameTest::didCreatePage): Set the page loader client on this page.
+
 2012-01-27  Zan Dobersek  <zandober...@gmail.com>
 
         [Gtk] DumpRenderTree lacks --no-timeout command line option

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (106138 => 106139)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2012-01-27 19:32:43 UTC (rev 106138)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2012-01-27 19:40:22 UTC (rev 106139)
@@ -38,6 +38,8 @@
 		520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; };
 		520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */; };
 		52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */; };
+		52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */; };
+		52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */; };
 		81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; };
 		939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */; };
 		A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
@@ -190,6 +192,8 @@
 		520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive_Bundle.cpp; sourceTree = "<group>"; };
 		520BCF4B141EB09E00937EA8 /* WebArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive.cpp; sourceTree = "<group>"; };
 		52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; };
+		52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame.cpp; sourceTree = "<group>"; };
+		52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame_Bundle.cpp; sourceTree = "<group>"; };
 		81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringBuilder.cpp; path = WTF/StringBuilder.cpp; sourceTree = "<group>"; };
 		8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; };
 		939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; };
@@ -437,6 +441,8 @@
 				33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */,
 				BC909779125571AB00083756 /* PageLoadBasic.cpp */,
 				BC2D004812A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp */,
+				52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */,
+				52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */,
 				333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */,
 				F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */,
 				C0BD669C131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp */,
@@ -729,6 +735,7 @@
 				BC55F5F914AD78EE00484BE1 /* Vector.cpp in Sources */,
 				440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */,
 				C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */,
+				52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -751,6 +758,7 @@
 				520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */,
 				C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */,
 				BC901E331492AF390074A667 /* WKConnection_Bundle.cpp in Sources */,
+				52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp (0 => 106139)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp	2012-01-27 19:40:22 UTC (rev 106139)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include <WebKit2/WKContextPrivate.h>
+
+namespace TestWebKitAPI {
+
+static bool didReceiveMessage;
+static bool isParentFrameCheckSuccessful;
+
+static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*)
+{
+    didReceiveMessage = true;
+
+    EXPECT_WK_STREQ("DidCheckParentFrame", messageName);
+    EXPECT_EQ(WKBooleanGetTypeID(), WKGetTypeID(body));
+    
+    isParentFrameCheckSuccessful = WKBooleanGetValue(static_cast<WKBooleanRef>(body));
+}
+
+static void setInjectedBundleClient(WKContextRef context)
+{
+    WKContextInjectedBundleClient injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+
+    WKContextSetInjectedBundleClient(context, &injectedBundleClient);
+}
+
+TEST(WebKit2, ParentFrame)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("ParentFrameTest"));
+    setInjectedBundleClient(context.get());
+
+    PlatformWebView webView(context.get());
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-iframe", "html")).get());
+
+    Util::run(&didReceiveMessage);
+    EXPECT_TRUE(isParentFrameCheckSuccessful);
+}
+
+} // namespace TestWebKitAPI

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp (0 => 106139)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp	2012-01-27 19:40:22 UTC (rev 106139)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include "config.h"
+#include "InjectedBundleTest.h"
+
+#include "PlatformUtilities.h"
+#include <WebKit2/WKBundlePage.h>
+#include <WebKit2/WKBundleFrame.h>
+#include <WebKit2/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static WKRetainPtr<WKBundleRef> testBundle;
+static WKRetainPtr<WKBundleFrameRef> childFrame;
+
+class ParentFrameTest : public InjectedBundleTest {
+public:
+    ParentFrameTest(const std::string& identifier);
+
+private:
+    virtual void didCreatePage(WKBundleRef, WKBundlePageRef);
+    
+};
+
+static InjectedBundleTest::Register<ParentFrameTest> registrar("ParentFrameTest");
+
+ParentFrameTest::ParentFrameTest(const std::string& identifier)
+    : InjectedBundleTest(identifier)
+{
+}
+
+static void didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+{
+    if (!WKBundleFrameIsMainFrame(frame)) {
+        childFrame = frame;
+        return;
+    }
+    
+    bool isParentFrameCheckSuccessful = childFrame ? WKBundleFrameGetParentFrame(childFrame.get()) == frame : false;
+    WKBundlePostMessage(testBundle.get(), Util::toWK("DidCheckParentFrame").get(), adoptWK(WKBooleanCreate(isParentFrameCheckSuccessful)).get());
+}
+
+void ParentFrameTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page)
+{
+    testBundle = bundle;
+    
+    WKBundlePageLoaderClient pageLoaderClient;
+    memset(&pageLoaderClient, 0, sizeof(pageLoaderClient));
+    
+    pageLoaderClient.version = 1;
+    pageLoaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    
+    WKBundlePageSetPageLoaderClient(page, &pageLoaderClient);
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to