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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106139
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-01-27 Ada Chan <adachan@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 <gns@gnome.org>
[GTK] Sometimes fails to build when using make -j
return toImpl(frameRef)->isMainFrame();
}
+WKBundleFrameRef WKBundleFrameGetParentFrame(WKBundleFrameRef frameRef)
+{
+ return toAPI(toImpl(frameRef)->parentFrame());
+}
+
WKURLRef WKBundleFrameCopyURL(WKBundleFrameRef frameRef)
{
return toCopiedURLAPI(toImpl(frameRef)->url());
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);
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)
String url() const;
String innerText() const;
bool isFrameSet() const;
+ WebFrame* parentFrame() const;
PassRefPtr<ImmutableArray> childFrames();
JSValueRef computedStyleIncludingVisitedInfo(JSObjectRef element);
JSGlobalContextRef jsContext();
+2012-01-27 Ada Chan <adachan@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 <zandobersek@gmail.com>
[Gtk] DumpRenderTree lacks --no-timeout command line option
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 */; };
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>"; };
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 */,
BC55F5F914AD78EE00484BE1 /* Vector.cpp in Sources */,
440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */,
C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */,
+ 52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
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;
};
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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