PDFPlugin should take advantage of threaded scrolling
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / WebFrame.cpp
index fc4ec02..250b42b 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "APIArray.h"
 #include "DownloadManager.h"
+#include "InjectedBundleFileHandle.h"
 #include "InjectedBundleHitTestResult.h"
 #include "InjectedBundleNodeHandle.h"
 #include "InjectedBundleRangeHandle.h"
@@ -49,6 +50,7 @@
 #include <WebCore/Chrome.h>
 #include <WebCore/DocumentLoader.h>
 #include <WebCore/EventHandler.h>
+#include <WebCore/File.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameSnapshotting.h>
 #include <WebCore/FrameView.h>
@@ -60,6 +62,7 @@
 #include <WebCore/ImageBuffer.h>
 #include <WebCore/JSCSSStyleDeclaration.h>
 #include <WebCore/JSElement.h>
+#include <WebCore/JSFile.h>
 #include <WebCore/JSRange.h>
 #include <WebCore/MainFrame.h>
 #include <WebCore/NetworkingContext.h>
@@ -67,9 +70,9 @@
 #include <WebCore/Page.h>
 #include <WebCore/PluginDocument.h>
 #include <WebCore/RenderTreeAsText.h>
-#include <WebCore/ResourceLoader.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>
@@ -152,9 +155,12 @@ WebFrame::WebFrame(std::unique_ptr<WebFrameLoaderClient> frameLoaderClient)
     , m_frameLoaderClient(WTF::move(frameLoaderClient))
     , m_loadListener(0)
     , m_frameID(generateFrameID())
+#if PLATFORM(IOS)
+    , m_firstLayerTreeTransactionIDAfterDidCommitLoad(0)
+#endif
 {
     m_frameLoaderClient->setWebFrame(this);
-    WebProcess::shared().addWebFrame(m_frameID, this);
+    WebProcess::singleton().addWebFrame(m_frameID, this);
 
 #ifndef NDEBUG
     webFrameCounter.increment();
@@ -192,7 +198,7 @@ WebFrame* WebFrame::fromCoreFrame(Frame& frame)
 
 void WebFrame::invalidate()
 {
-    WebProcess::shared().removeWebFrame(m_frameID);
+    WebProcess::singleton().removeWebFrame(m_frameID);
     m_coreFrame = 0;
 }
 
@@ -250,14 +256,15 @@ void WebFrame::startDownload(const WebCore::ResourceRequest& request)
     uint64_t policyDownloadID = m_policyDownloadID;
     m_policyDownloadID = 0;
 
+    auto& webProcess = WebProcess::singleton();
 #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
 
-    WebProcess::shared().downloadManager().startDownload(policyDownloadID, request);
+    webProcess.downloadManager().startDownload(policyDownloadID, request);
 }
 
 void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
@@ -267,30 +274,32 @@ void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader,
     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 (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;
 
-        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.
-        WebProcess::shared().downloadManager().startDownload(policyDownloadID, request);
+        webProcess.downloadManager().startDownload(policyDownloadID, request);
         return;
     }
 
-    WebProcess::shared().downloadManager().convertHandleToDownload(policyDownloadID, documentLoader->mainResourceLoader()->handle(), request, response);
+    webProcess.downloadManager().convertHandleToDownload(policyDownloadID, documentLoader->mainResourceLoader()->handle(), request, response);
 }
 
 String WebFrame::source() const 
@@ -440,7 +449,7 @@ WebFrame* WebFrame::parentFrame() const
     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();
@@ -505,6 +514,35 @@ bool WebFrame::handlesPageScaleGesture() const
     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)
@@ -613,7 +651,7 @@ bool WebFrame::containsAnyFormElements() const
     if (!document)
         return false;
 
-    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) {
+    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(*node)) {
         if (!is<Element>(*node))
             continue;
         if (is<HTMLFormElement>(*node))
@@ -631,7 +669,7 @@ bool WebFrame::containsAnyFormControls() const
     if (!document)
         return false;
 
-    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) {
+    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(*node)) {
         if (!is<Element>(*node))
             continue;
         if (is<HTMLInputElement>(*node) || is<HTMLSelectElement>(*node) || is<HTMLTextAreaElement>(*node))
@@ -655,7 +693,7 @@ WebFrame* WebFrame::frameForContext(JSContextRef context)
     if (strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell") != 0)
         return 0;
 
-    Frame* frame = static_cast<JSDOMWindowShell*>(globalObjectObj)->window()->impl().frame();
+    Frame* frame = static_cast<JSDOMWindowShell*>(globalObjectObj)->window()->wrapped().frame();
     return WebFrame::fromCoreFrame(*frame);
 }
 
@@ -683,12 +721,24 @@ JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleRangeHandle* rangeHandle, I
     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();
 
-    return counterValueForElement(&jsCast<JSElement*>(toJS(element))->impl());
+    return counterValueForElement(&jsCast<JSElement*>(toJS(element))->wrapped());
 }
 
 String WebFrame::provisionalURL() const
@@ -798,7 +848,7 @@ PassRefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const
     auto graphicsContext = sharedSnapshot->createGraphicsContext();
     float deviceScaleFactor = coreFrame()->page()->deviceScaleFactor();
     graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
-    graphicsContext->drawImageBuffer(snapshot.get(), ColorSpaceDeviceRGB, FloatPoint());
+    graphicsContext->drawImageBuffer(*snapshot, ColorSpaceDeviceRGB, FloatPoint());
 
     return sharedSnapshot.release();
 }