PDFPlugin should take advantage of threaded scrolling
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / WebFrame.cpp
index c49a41c..250b42b 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "APIArray.h"
 #include "DownloadManager.h"
 
 #include "APIArray.h"
 #include "DownloadManager.h"
+#include "InjectedBundleFileHandle.h"
 #include "InjectedBundleHitTestResult.h"
 #include "InjectedBundleNodeHandle.h"
 #include "InjectedBundleRangeHandle.h"
 #include "InjectedBundleHitTestResult.h"
 #include "InjectedBundleNodeHandle.h"
 #include "InjectedBundleRangeHandle.h"
@@ -36,6 +37,7 @@
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
 #include "WebChromeClient.h"
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
 #include "WebChromeClient.h"
+#include "WebDocumentLoader.h"
 #include "WebPage.h"
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
 #include "WebPage.h"
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
 #include <JavaScriptCore/JSLock.h>
 #include <JavaScriptCore/JSValueRef.h>
 #include <WebCore/ArchiveResource.h>
 #include <JavaScriptCore/JSLock.h>
 #include <JavaScriptCore/JSValueRef.h>
 #include <WebCore/ArchiveResource.h>
+#include <WebCore/CertificateInfo.h>
 #include <WebCore/Chrome.h>
 #include <WebCore/DocumentLoader.h>
 #include <WebCore/EventHandler.h>
 #include <WebCore/Chrome.h>
 #include <WebCore/DocumentLoader.h>
 #include <WebCore/EventHandler.h>
+#include <WebCore/File.h>
 #include <WebCore/Frame.h>
 #include <WebCore/Frame.h>
+#include <WebCore/FrameSnapshotting.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/HTMLFormElement.h>
 #include <WebCore/HTMLFrameOwnerElement.h>
 #include <WebCore/HTMLInputElement.h>
 #include <WebCore/HTMLNames.h>
 #include <WebCore/HTMLTextAreaElement.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/HTMLFormElement.h>
 #include <WebCore/HTMLFrameOwnerElement.h>
 #include <WebCore/HTMLInputElement.h>
 #include <WebCore/HTMLNames.h>
 #include <WebCore/HTMLTextAreaElement.h>
+#include <WebCore/ImageBuffer.h>
 #include <WebCore/JSCSSStyleDeclaration.h>
 #include <WebCore/JSElement.h>
 #include <WebCore/JSCSSStyleDeclaration.h>
 #include <WebCore/JSElement.h>
+#include <WebCore/JSFile.h>
 #include <WebCore/JSRange.h>
 #include <WebCore/JSRange.h>
+#include <WebCore/MainFrame.h>
 #include <WebCore/NetworkingContext.h>
 #include <WebCore/NodeTraversal.h>
 #include <WebCore/Page.h>
 #include <WebCore/PluginDocument.h>
 #include <WebCore/RenderTreeAsText.h>
 #include <WebCore/NetworkingContext.h>
 #include <WebCore/NodeTraversal.h>
 #include <WebCore/Page.h>
 #include <WebCore/PluginDocument.h>
 #include <WebCore/RenderTreeAsText.h>
-#include <WebCore/ResourceBuffer.h>
-#include <WebCore/ResourceLoader.h>
 #include <WebCore/ScriptController.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/ScriptController.h>
 #include <WebCore/SecurityOrigin.h>
+#include <WebCore/SubresourceLoader.h>
 #include <WebCore/TextIterator.h>
 #include <WebCore/TextResourceDecoder.h>
 #include <wtf/text/StringBuilder.h>
 
 #include <WebCore/TextIterator.h>
 #include <WebCore/TextResourceDecoder.h>
 #include <wtf/text/StringBuilder.h>
 
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
 #include <WebCore/LegacyWebArchive.h>
 #endif
 
 #include <WebCore/LegacyWebArchive.h>
 #endif
 
@@ -106,7 +113,7 @@ static uint64_t generateListenerID()
 PassRefPtr<WebFrame> WebFrame::createWithCoreMainFrame(WebPage* page, WebCore::Frame* coreFrame)
 {
     RefPtr<WebFrame> frame = create(std::unique_ptr<WebFrameLoaderClient>(static_cast<WebFrameLoaderClient*>(&coreFrame->loader().client())));
 PassRefPtr<WebFrame> WebFrame::createWithCoreMainFrame(WebPage* page, WebCore::Frame* coreFrame)
 {
     RefPtr<WebFrame> frame = create(std::unique_ptr<WebFrameLoaderClient>(static_cast<WebFrameLoaderClient*>(&coreFrame->loader().client())));
-    page->send(Messages::WebPageProxy::DidCreateMainFrame(frame->frameID()));
+    page->send(Messages::WebPageProxy::DidCreateMainFrame(frame->frameID()), page->pageID(), IPC::DispatchMessageEvenWhenWaitingForSyncReply);
 
     frame->m_coreFrame = coreFrame;
     frame->m_coreFrame->tree().setName(String());
 
     frame->m_coreFrame = coreFrame;
     frame->m_coreFrame->tree().setName(String());
@@ -117,14 +124,14 @@ PassRefPtr<WebFrame> WebFrame::createWithCoreMainFrame(WebPage* page, WebCore::F
 PassRefPtr<WebFrame> WebFrame::createSubframe(WebPage* page, const String& frameName, HTMLFrameOwnerElement* ownerElement)
 {
     RefPtr<WebFrame> frame = create(std::make_unique<WebFrameLoaderClient>());
 PassRefPtr<WebFrame> WebFrame::createSubframe(WebPage* page, const String& frameName, HTMLFrameOwnerElement* ownerElement)
 {
     RefPtr<WebFrame> frame = create(std::make_unique<WebFrameLoaderClient>());
-    page->send(Messages::WebPageProxy::DidCreateSubframe(frame->frameID()));
+    page->send(Messages::WebPageProxy::DidCreateSubframe(frame->frameID()), page->pageID(), IPC::DispatchMessageEvenWhenWaitingForSyncReply);
 
 
-    RefPtr<Frame> coreFrame = Frame::create(page->corePage(), ownerElement, frame->m_frameLoaderClient.get());
-    frame->m_coreFrame = coreFrame.get();
+    Ref<WebCore::Frame> coreFrame = Frame::create(page->corePage(), ownerElement, frame->m_frameLoaderClient.get());
+    frame->m_coreFrame = coreFrame.ptr();
     frame->m_coreFrame->tree().setName(frameName);
     if (ownerElement) {
         ASSERT(ownerElement->document().frame());
     frame->m_coreFrame->tree().setName(frameName);
     if (ownerElement) {
         ASSERT(ownerElement->document().frame());
-        ownerElement->document().frame()->tree().appendChild(coreFrame.release());
+        ownerElement->document().frame()->tree().appendChild(WTF::move(coreFrame));
     }
     frame->m_coreFrame->init();
     return frame.release();
     }
     frame->m_coreFrame->init();
     return frame.release();
@@ -132,7 +139,7 @@ PassRefPtr<WebFrame> WebFrame::createSubframe(WebPage* page, const String& frame
 
 PassRefPtr<WebFrame> WebFrame::create(std::unique_ptr<WebFrameLoaderClient> frameLoaderClient)
 {
 
 PassRefPtr<WebFrame> WebFrame::create(std::unique_ptr<WebFrameLoaderClient> frameLoaderClient)
 {
-    RefPtr<WebFrame> frame = adoptRef(new WebFrame(std::move(frameLoaderClient)));
+    RefPtr<WebFrame> frame = adoptRef(new WebFrame(WTF::move(frameLoaderClient)));
 
     // Add explict ref() that will be balanced in WebFrameLoaderClient::frameLoaderDestroyed().
     frame->ref();
 
     // Add explict ref() that will be balanced in WebFrameLoaderClient::frameLoaderDestroyed().
     frame->ref();
@@ -145,12 +152,15 @@ WebFrame::WebFrame(std::unique_ptr<WebFrameLoaderClient> frameLoaderClient)
     , m_policyListenerID(0)
     , m_policyFunction(0)
     , m_policyDownloadID(0)
     , m_policyListenerID(0)
     , m_policyFunction(0)
     , m_policyDownloadID(0)
-    , m_frameLoaderClient(std::move(frameLoaderClient))
+    , m_frameLoaderClient(WTF::move(frameLoaderClient))
     , m_loadListener(0)
     , m_frameID(generateFrameID())
     , m_loadListener(0)
     , m_frameID(generateFrameID())
+#if PLATFORM(IOS)
+    , m_firstLayerTreeTransactionIDAfterDidCommitLoad(0)
+#endif
 {
     m_frameLoaderClient->setWebFrame(this);
 {
     m_frameLoaderClient->setWebFrame(this);
-    WebProcess::shared().addWebFrame(m_frameID, this);
+    WebProcess::singleton().addWebFrame(m_frameID, this);
 
 #ifndef NDEBUG
     webFrameCounter.increment();
 
 #ifndef NDEBUG
     webFrameCounter.increment();
@@ -177,9 +187,18 @@ WebPage* WebFrame::page() const
     return 0;
 }
 
     return 0;
 }
 
+WebFrame* WebFrame::fromCoreFrame(Frame& frame)
+{
+    auto* webFrameLoaderClient = toWebFrameLoaderClient(frame.loader().client());
+    if (!webFrameLoaderClient)
+        return nullptr;
+
+    return webFrameLoaderClient->webFrame();
+}
+
 void WebFrame::invalidate()
 {
 void WebFrame::invalidate()
 {
-    WebProcess::shared().removeWebFrame(m_frameID);
+    WebProcess::singleton().removeWebFrame(m_frameID);
     m_coreFrame = 0;
 }
 
     m_coreFrame = 0;
 }
 
@@ -204,7 +223,7 @@ void WebFrame::invalidatePolicyListener()
     m_policyFunction = 0;
 }
 
     m_policyFunction = 0;
 }
 
-void WebFrame::didReceivePolicyDecision(uint64_t listenerID, PolicyAction action, uint64_t downloadID)
+void WebFrame::didReceivePolicyDecision(uint64_t listenerID, PolicyAction action, uint64_t navigationID, uint64_t downloadID)
 {
     if (!m_coreFrame)
         return;
 {
     if (!m_coreFrame)
         return;
@@ -217,11 +236,16 @@ void WebFrame::didReceivePolicyDecision(uint64_t listenerID, PolicyAction action
 
     ASSERT(m_policyFunction);
 
 
     ASSERT(m_policyFunction);
 
-    FramePolicyFunction function = std::move(m_policyFunction);
+    FramePolicyFunction function = WTF::move(m_policyFunction);
 
     invalidatePolicyListener();
 
     m_policyDownloadID = downloadID;
 
     invalidatePolicyListener();
 
     m_policyDownloadID = downloadID;
+    if (navigationID) {
+        if (WebDocumentLoader* documentLoader = static_cast<WebDocumentLoader*>(m_coreFrame->loader().policyDocumentLoader()))
+            documentLoader->setNavigationID(navigationID);
+    }
+
     function(action);
 }
 
     function(action);
 }
 
@@ -232,14 +256,15 @@ void WebFrame::startDownload(const WebCore::ResourceRequest& request)
     uint64_t policyDownloadID = m_policyDownloadID;
     m_policyDownloadID = 0;
 
     uint64_t policyDownloadID = m_policyDownloadID;
     m_policyDownloadID = 0;
 
+    auto& webProcess = WebProcess::singleton();
 #if ENABLE(NETWORK_PROCESS)
 #if ENABLE(NETWORK_PROCESS)
-    if (WebProcess::shared().usesNetworkProcess()) {
-        WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::StartDownload(page()->sessionID(), policyDownloadID, request), 0);
+    if (webProcess.usesNetworkProcess()) {
+        webProcess.networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::StartDownload(page()->sessionID(), policyDownloadID, request), 0);
         return;
     }
 #endif
 
         return;
     }
 #endif
 
-    WebProcess::shared().downloadManager().startDownload(policyDownloadID, request);
+    webProcess.downloadManager().startDownload(policyDownloadID, request);
 }
 
 void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
 }
 
 void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
@@ -249,30 +274,32 @@ void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader,
     uint64_t policyDownloadID = m_policyDownloadID;
     m_policyDownloadID = 0;
 
     uint64_t policyDownloadID = m_policyDownloadID;
     m_policyDownloadID = 0;
 
-    ResourceLoader* mainResourceLoader = documentLoader->mainResourceLoader();
+    SubresourceLoader* mainResourceLoader = documentLoader->mainResourceLoader();
 
 
+    auto& webProcess = WebProcess::singleton();
 #if ENABLE(NETWORK_PROCESS)
 #if ENABLE(NETWORK_PROCESS)
-    if (WebProcess::shared().usesNetworkProcess()) {
-        // Use 0 to indicate that there is no main resource loader.
-        // This can happen if the main resource is in the WebCore memory cache.
+    if (webProcess.usesNetworkProcess()) {
+        // Use 0 to indicate that the resource load can't be converted and a new download must be started.
+        // This can happen if there is no loader because the main resource is in the WebCore memory cache,
+        // or because the conversion was attempted when not calling SubresourceLoader::didReceiveResponse().
         uint64_t mainResourceLoadIdentifier;
         if (mainResourceLoader)
             mainResourceLoadIdentifier = mainResourceLoader->identifier();
         else
             mainResourceLoadIdentifier = 0;
 
         uint64_t mainResourceLoadIdentifier;
         if (mainResourceLoader)
             mainResourceLoadIdentifier = mainResourceLoader->identifier();
         else
             mainResourceLoadIdentifier = 0;
 
-        WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::ConvertMainResourceLoadToDownload(mainResourceLoadIdentifier, policyDownloadID, request, response), 0);
+        webProcess.networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::ConvertMainResourceLoadToDownload(mainResourceLoadIdentifier, policyDownloadID, request, response), 0);
         return;
     }
 #endif
 
     if (!mainResourceLoader) {
         // The main resource has already been loaded. Start a new download instead.
         return;
     }
 #endif
 
     if (!mainResourceLoader) {
         // The main resource has already been loaded. Start a new download instead.
-        WebProcess::shared().downloadManager().startDownload(policyDownloadID, request);
+        webProcess.downloadManager().startDownload(policyDownloadID, request);
         return;
     }
 
         return;
     }
 
-    WebProcess::shared().downloadManager().convertHandleToDownload(policyDownloadID, documentLoader->mainResourceLoader()->handle(), request, response);
+    webProcess.downloadManager().convertHandleToDownload(policyDownloadID, documentLoader->mainResourceLoader()->handle(), request, response);
 }
 
 String WebFrame::source() const 
 }
 
 String WebFrame::source() const 
@@ -288,7 +315,7 @@ String WebFrame::source() const
     DocumentLoader* documentLoader = m_coreFrame->loader().activeDocumentLoader();
     if (!documentLoader)
         return String();
     DocumentLoader* documentLoader = m_coreFrame->loader().activeDocumentLoader();
     if (!documentLoader)
         return String();
-    RefPtr<ResourceBuffer> mainResourceData = documentLoader->mainResourceData();
+    RefPtr<SharedBuffer> mainResourceData = documentLoader->mainResourceData();
     if (!mainResourceData)
         return String();
     return decoder->encoding().decode(mainResourceData->data(), mainResourceData->size());
     if (!mainResourceData)
         return String();
     return decoder->encoding().decode(mainResourceData->data(), mainResourceData->size());
@@ -305,8 +332,7 @@ String WebFrame::contentsAsString() const
             if (!builder.isEmpty())
                 builder.append(' ');
 
             if (!builder.isEmpty())
                 builder.append(' ');
 
-            WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(child->loader().client());
-            WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+            WebFrame* webFrame = WebFrame::fromCoreFrame(*child);
             ASSERT(webFrame);
 
             builder.append(webFrame->contentsAsString());
             ASSERT(webFrame);
 
             builder.append(webFrame->contentsAsString());
@@ -366,10 +392,10 @@ bool WebFrame::isFrameSet() const
 
 bool WebFrame::isMainFrame() const
 {
 
 bool WebFrame::isMainFrame() const
 {
-    if (WebPage* p = page())
-        return p->mainWebFrame() == this;
+    if (!m_coreFrame)
+        return false;
 
 
-    return false;
+    return m_coreFrame->isMainFrame();
 }
 
 String WebFrame::name() const
 }
 
 String WebFrame::name() const
@@ -392,6 +418,18 @@ String WebFrame::url() const
     return documentLoader->url().string();
 }
 
     return documentLoader->url().string();
 }
 
+WebCore::CertificateInfo WebFrame::certificateInfo() const
+{
+    if (!m_coreFrame)
+        return CertificateInfo();
+
+    DocumentLoader* documentLoader = m_coreFrame->loader().documentLoader();
+    if (!documentLoader)
+        return CertificateInfo();
+
+    return documentLoader->response().certificateInfo();
+}
+
 String WebFrame::innerText() const
 {
     if (!m_coreFrame)
 String WebFrame::innerText() const
 {
     if (!m_coreFrame)
@@ -408,11 +446,10 @@ WebFrame* WebFrame::parentFrame() const
     if (!m_coreFrame || !m_coreFrame->ownerElement())
         return 0;
 
     if (!m_coreFrame || !m_coreFrame->ownerElement())
         return 0;
 
-    WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(m_coreFrame->ownerElement()->document().frame()->loader().client());
-    return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+    return WebFrame::fromCoreFrame(*m_coreFrame->ownerElement()->document().frame());
 }
 
 }
 
-PassRefPtr<API::Array> WebFrame::childFrames()
+Ref<API::Array> WebFrame::childFrames()
 {
     if (!m_coreFrame)
         return API::Array::create();
 {
     if (!m_coreFrame)
         return API::Array::create();
@@ -425,13 +462,12 @@ PassRefPtr<API::Array> WebFrame::childFrames()
     vector.reserveInitialCapacity(size);
 
     for (Frame* child = m_coreFrame->tree().firstChild(); child; child = child->tree().nextSibling()) {
     vector.reserveInitialCapacity(size);
 
     for (Frame* child = m_coreFrame->tree().firstChild(); child; child = child->tree().nextSibling()) {
-        WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(child->loader().client());
-        WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+        WebFrame* webFrame = WebFrame::fromCoreFrame(*child);
         ASSERT(webFrame);
         vector.uncheckedAppend(webFrame);
     }
 
         ASSERT(webFrame);
         vector.uncheckedAppend(webFrame);
     }
 
-    return API::Array::create(std::move(vector));
+    return API::Array::create(WTF::move(vector));
 }
 
 String WebFrame::layerTreeAsText() const
 }
 
 String WebFrame::layerTreeAsText() const
@@ -478,6 +514,35 @@ bool WebFrame::handlesPageScaleGesture() const
     return pluginView && pluginView->handlesPageScaleFactor();
 }
 
     return pluginView && pluginView->handlesPageScaleFactor();
 }
 
+bool WebFrame::requiresUnifiedScaleFactor() const
+{
+    if (!m_coreFrame->document()->isPluginDocument())
+        return 0;
+
+    PluginDocument* pluginDocument = static_cast<PluginDocument*>(m_coreFrame->document());
+    PluginView* pluginView = static_cast<PluginView*>(pluginDocument->pluginWidget());
+    return pluginView && pluginView->requiresUnifiedScaleFactor();
+}
+
+void WebFrame::setAccessibleName(const String& accessibleName)
+{
+    if (!AXObjectCache::accessibilityEnabled())
+        return;
+    
+    if (!m_coreFrame)
+        return;
+
+    auto* document = m_coreFrame->document();
+    if (!document)
+        return;
+    
+    auto* rootObject = document->axObjectCache()->rootObject();
+    if (!rootObject)
+        return;
+
+    rootObject->setAccessibleName(accessibleName);
+}
+
 IntRect WebFrame::contentBounds() const
 {    
     if (!m_coreFrame)
 IntRect WebFrame::contentBounds() const
 {    
     if (!m_coreFrame)
@@ -499,7 +564,7 @@ IntRect WebFrame::visibleContentBounds() const
     if (!view)
         return IntRect();
     
     if (!view)
         return IntRect();
     
-    IntRect contentRect = view->visibleContentRect(ScrollableArea::IncludeScrollbars);
+    IntRect contentRect = view->visibleContentRectIncludingScrollbars();
     return IntRect(0, 0, contentRect.width(), contentRect.height());
 }
 
     return IntRect(0, 0, contentRect.width(), contentRect.height());
 }
 
@@ -586,10 +651,10 @@ bool WebFrame::containsAnyFormElements() const
     if (!document)
         return false;
 
     if (!document)
         return false;
 
-    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) {
-        if (!node->isElementNode())
+    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(*node)) {
+        if (!is<Element>(*node))
             continue;
             continue;
-        if (isHTMLFormElement(node))
+        if (is<HTMLFormElement>(*node))
             return true;
     }
     return false;
             return true;
     }
     return false;
@@ -604,10 +669,10 @@ bool WebFrame::containsAnyFormControls() const
     if (!document)
         return false;
 
     if (!document)
         return false;
 
-    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) {
-        if (!node->isElementNode())
+    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(*node)) {
+        if (!is<Element>(*node))
             continue;
             continue;
-        if (isHTMLInputElement(node) || isHTMLSelectElement(node) || isHTMLTextAreaElement(node))
+        if (is<HTMLInputElement>(*node) || is<HTMLSelectElement>(*node) || is<HTMLTextAreaElement>(*node))
             return true;
     }
     return false;
             return true;
     }
     return false;
@@ -628,10 +693,8 @@ WebFrame* WebFrame::frameForContext(JSContextRef context)
     if (strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell") != 0)
         return 0;
 
     if (strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell") != 0)
         return 0;
 
-    Frame* coreFrame = static_cast<JSDOMWindowShell*>(globalObjectObj)->window()->impl().frame();
-
-    WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(coreFrame->loader().client());
-    return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+    Frame* frame = static_cast<JSDOMWindowShell*>(globalObjectObj)->window()->wrapped().frame();
+    return WebFrame::fromCoreFrame(*frame);
 }
 
 JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleNodeHandle* nodeHandle, InjectedBundleScriptWorld* world)
 }
 
 JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleNodeHandle* nodeHandle, InjectedBundleScriptWorld* world)
@@ -658,12 +721,24 @@ JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleRangeHandle* rangeHandle, I
     return toRef(exec, toJS(exec, globalObject, rangeHandle->coreRange()));
 }
 
     return toRef(exec, toJS(exec, globalObject, rangeHandle->coreRange()));
 }
 
+JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleFileHandle* fileHandle, InjectedBundleScriptWorld* world)
+{
+    if (!m_coreFrame)
+        return nullptr;
+
+    JSDOMWindow* globalObject = m_coreFrame->script().globalObject(world->coreWorld());
+    ExecState* exec = globalObject->globalExec();
+
+    JSLockHolder lock(exec);
+    return toRef(exec, toJS(exec, globalObject, fileHandle->coreFile()));
+}
+
 String WebFrame::counterValue(JSObjectRef element)
 {
     if (!toJS(element)->inherits(JSElement::info()))
         return String();
 
 String WebFrame::counterValue(JSObjectRef element)
 {
     if (!toJS(element)->inherits(JSElement::info()))
         return String();
 
-    return counterValueForElement(&jsCast<JSElement*>(toJS(element))->impl());
+    return counterValueForElement(&jsCast<JSElement*>(toJS(element))->wrapped());
 }
 
 String WebFrame::provisionalURL() const
 }
 
 String WebFrame::provisionalURL() const
@@ -733,15 +808,19 @@ void WebFrame::setTextDirection(const String& direction)
         m_coreFrame->editor().setBaseWritingDirection(RightToLeftWritingDirection);
 }
 
         m_coreFrame->editor().setBaseWritingDirection(RightToLeftWritingDirection);
 }
 
-#if PLATFORM(MAC)
+void WebFrame::documentLoaderDetached(uint64_t navigationID)
+{
+    page()->send(Messages::WebPageProxy::DidDestroyNavigation(navigationID));
+}
+
+#if PLATFORM(COCOA)
 RetainPtr<CFDataRef> WebFrame::webArchiveData(FrameFilterFunction callback, void* context)
 {
     RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(coreFrame()->document(), [this, callback, context](Frame& frame) -> bool {
         if (!callback)
             return true;
 
 RetainPtr<CFDataRef> WebFrame::webArchiveData(FrameFilterFunction callback, void* context)
 {
     RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(coreFrame()->document(), [this, callback, context](Frame& frame) -> bool {
         if (!callback)
             return true;
 
-        WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame.loader().client());
-        WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+        WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
         ASSERT(webFrame);
 
         return callback(toAPI(this), toAPI(webFrame), context);
         ASSERT(webFrame);
 
         return callback(toAPI(this), toAPI(webFrame), context);
@@ -753,5 +832,25 @@ RetainPtr<CFDataRef> WebFrame::webArchiveData(FrameFilterFunction callback, void
     return archive->rawDataRepresentation();
 }
 #endif
     return archive->rawDataRepresentation();
 }
 #endif
+
+PassRefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const
+{
+    std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(*coreFrame(), WebCore::SnapshotOptionsForceBlackText);
+    if (!snapshot)
+        return nullptr;
+
+    RefPtr<ShareableBitmap> sharedSnapshot = ShareableBitmap::createShareable(snapshot->internalSize(), ShareableBitmap::SupportsAlpha);
+    if (!sharedSnapshot)
+        return nullptr;
+
+    // FIXME: We should consider providing a way to use subpixel antialiasing for the snapshot
+    // if we're compositing this image onto a solid color (e.g. the modern find indicator style).
+    auto graphicsContext = sharedSnapshot->createGraphicsContext();
+    float deviceScaleFactor = coreFrame()->page()->deviceScaleFactor();
+    graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
+    graphicsContext->drawImageBuffer(*snapshot, ColorSpaceDeviceRGB, FloatPoint());
+
+    return sharedSnapshot.release();
+}
     
 } // namespace WebKit
     
 } // namespace WebKit