From d441d6f39bb846989d95bcf5caf387b42414718d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 13 Sep 2013 12:51:20 +0200 Subject: Import Qt5x2 branch of QtWebkit for Qt 5.2 Importing a new snapshot of webkit. Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c Reviewed-by: Allan Sandfeld Jensen --- Source/WebKit2/WebProcess/WebPage/WebFrame.cpp | 269 +++++++++---------------- 1 file changed, 99 insertions(+), 170 deletions(-) (limited to 'Source/WebKit2/WebProcess/WebPage/WebFrame.cpp') diff --git a/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp b/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp index c65c5e5bc..ae53d3cdc 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp @@ -42,37 +42,41 @@ #include #include #include -#include #include -#include #include #include +#include #include #include +#include #include +#include #include +#include #include #include #include +#include +#include #include #include #include #include +#include +#include #include #include #include #include -#if ENABLE(WEB_INTENTS) -#include "IntentData.h" -#include -#include -#include -#include +#if PLATFORM(MAC) +#include #endif -#if PLATFORM(MAC) || PLATFORM(WIN) -#include +#if ENABLE(NETWORK_PROCESS) +#include "NetworkConnectionToWebProcessMessages.h" +#include "NetworkProcessConnection.h" +#include "WebCoreArgumentCoders.h" #endif #ifndef NDEBUG @@ -113,8 +117,7 @@ PassRefPtr WebFrame::createSubframe(WebPage* page, const String& frame { RefPtr frame = create(); - WebFrame* parentFrame = static_cast(ownerElement->document()->frame()->loader()->client())->webFrame(); - page->send(Messages::WebPageProxy::DidCreateSubframe(frame->frameID(), parentFrame->frameID())); + page->send(Messages::WebPageProxy::DidCreateSubframe(frame->frameID())); frame->init(page, frameName, ownerElement); @@ -176,8 +179,8 @@ WebPage* WebFrame::page() const if (!m_coreFrame) return 0; - if (WebCore::Page* page = m_coreFrame->page()) - return static_cast(page->chrome()->client())->page(); + if (Page* page = m_coreFrame->page()) + return WebPage::fromCorePage(page); return 0; } @@ -235,57 +238,52 @@ void WebFrame::startDownload(const WebCore::ResourceRequest& request) { ASSERT(m_policyDownloadID); - DownloadManager::shared().startDownload(m_policyDownloadID, page(), request); - + uint64_t policyDownloadID = m_policyDownloadID; m_policyDownloadID = 0; + +#if ENABLE(NETWORK_PROCESS) + if (WebProcess::shared().usesNetworkProcess()) { + bool privateBrowsingEnabled = m_coreFrame->loader()->networkingContext()->storageSession().isPrivateBrowsingSession(); + WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::StartDownload(privateBrowsingEnabled, policyDownloadID, request), 0); + return; + } +#endif + + WebProcess::shared().downloadManager().startDownload(policyDownloadID, request); } -void WebFrame::convertHandleToDownload(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response) +void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response) { ASSERT(m_policyDownloadID); - DownloadManager::shared().convertHandleToDownload(m_policyDownloadID, page(), handle, request, response); + uint64_t policyDownloadID = m_policyDownloadID; m_policyDownloadID = 0; -} -#if ENABLE(WEB_INTENTS) -void WebFrame::deliverIntent(const IntentData& intentData) -{ - OwnPtr dummyClient; - Vector dataCopy = intentData.data; + ResourceLoader* mainResourceLoader = documentLoader->mainResourceLoader(); - OwnPtr channels; - if (!intentData.messagePorts.isEmpty()) { - channels = adoptPtr(new WebCore::MessagePortChannelArray(intentData.messagePorts.size())); - for (size_t i = 0; i < intentData.messagePorts.size(); ++i) - (*channels)[i] = MessagePortChannel::create(WebProcess::shared().messagePortChannel(intentData.messagePorts.at(i))); - } - OwnPtr messagePorts = WebCore::MessagePort::entanglePorts(*m_coreFrame->document()->domWindow()->scriptExecutionContext(), channels.release()); +#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. + uint64_t mainResourceLoadIdentifier; + if (mainResourceLoader) + mainResourceLoadIdentifier = mainResourceLoader->identifier(); + else + mainResourceLoadIdentifier = 0; - RefPtr deliveredIntent = DeliveredIntent::create(m_coreFrame, dummyClient.release(), intentData.action, intentData.type, - SerializedScriptValue::adopt(dataCopy), messagePorts.release(), - intentData.extras); - WebCore::DOMWindowIntents::from(m_coreFrame->document()->domWindow())->deliver(deliveredIntent.release()); -} - -void WebFrame::deliverIntent(WebCore::Intent* intent) -{ - OwnPtr dummyClient; + WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::ConvertMainResourceLoadToDownload(mainResourceLoadIdentifier, policyDownloadID, request, response), 0); + return; + } +#endif - OwnPtr channels; - WebCore::MessagePortChannelArray* origChannels = intent->messagePorts(); - if (origChannels && origChannels->size()) { - channels = adoptPtr(new WebCore::MessagePortChannelArray(origChannels->size())); - for (size_t i = 0; i < origChannels->size(); ++i) - (*channels)[i] = origChannels->at(i).release(); + if (!mainResourceLoader) { + // The main resource has already been loaded. Start a new download instead. + WebProcess::shared().downloadManager().startDownload(policyDownloadID, request); + return; } - OwnPtr messagePorts = WebCore::MessagePort::entanglePorts(*m_coreFrame->document()->domWindow()->scriptExecutionContext(), channels.release()); - RefPtr deliveredIntent = DeliveredIntent::create(m_coreFrame, dummyClient.release(), intent->action(), intent->type(), - intent->data(), messagePorts.release(), intent->extras()); - WebCore::DOMWindowIntents::from(m_coreFrame->document()->domWindow())->deliver(deliveredIntent.release()); + WebProcess::shared().downloadManager().convertHandleToDownload(policyDownloadID, documentLoader->mainResourceLoader()->handle(), request, response); } -#endif String WebFrame::source() const { @@ -316,7 +314,12 @@ String WebFrame::contentsAsString() const for (Frame* child = m_coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling()) { if (!builder.isEmpty()) builder.append(' '); - builder.append(static_cast(child->loader()->client())->webFrame()->contentsAsString()); + + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(child->loader()->client()); + WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; + ASSERT(webFrame); + + builder.append(webFrame->contentsAsString()); } // FIXME: It may make sense to use toStringPreserveCapacity() here. return builder.toString(); @@ -345,7 +348,7 @@ String WebFrame::selectionAsString() const if (!m_coreFrame) return String(); - return m_coreFrame->displayStringModifiedByEncoding(m_coreFrame->editor()->selectedText()); + return m_coreFrame->displayStringModifiedByEncoding(m_coreFrame->editor().selectedText()); } IntSize WebFrame::size() const @@ -415,7 +418,8 @@ WebFrame* WebFrame::parentFrame() const if (!m_coreFrame || !m_coreFrame->ownerElement() || !m_coreFrame->ownerElement()->document()) return 0; - return static_cast(m_coreFrame->ownerElement()->document()->frame()->loader()->client())->webFrame(); + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(m_coreFrame->ownerElement()->document()->frame()->loader()->client()); + return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; } PassRefPtr WebFrame::childFrames() @@ -427,91 +431,19 @@ PassRefPtr WebFrame::childFrames() if (!size) return ImmutableArray::create(); - Vector > vector; + Vector> vector; vector.reserveInitialCapacity(size); for (Frame* child = m_coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling()) { - WebFrame* webFrame = static_cast(child->loader()->client())->webFrame(); + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(child->loader()->client()); + WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; + ASSERT(webFrame); vector.uncheckedAppend(webFrame); } return ImmutableArray::adopt(vector); } -unsigned WebFrame::numberOfActiveAnimations() const -{ - if (!m_coreFrame) - return 0; - - AnimationController* controller = m_coreFrame->animation(); - if (!controller) - return 0; - - return controller->numberOfActiveAnimations(m_coreFrame->document()); -} - -bool WebFrame::pauseAnimationOnElementWithId(const String& animationName, const String& elementID, double time) -{ - if (!m_coreFrame) - return false; - - AnimationController* controller = m_coreFrame->animation(); - if (!controller) - return false; - - if (!m_coreFrame->document()) - return false; - - Node* coreNode = m_coreFrame->document()->getElementById(elementID); - if (!coreNode || !coreNode->renderer()) - return false; - - return controller->pauseAnimationAtTime(coreNode->renderer(), animationName, time); -} - -bool WebFrame::pauseTransitionOnElementWithId(const String& propertyName, const String& elementID, double time) -{ - if (!m_coreFrame) - return false; - - AnimationController* controller = m_coreFrame->animation(); - if (!controller) - return false; - - if (!m_coreFrame->document()) - return false; - - Node* coreNode = m_coreFrame->document()->getElementById(elementID); - if (!coreNode || !coreNode->renderer()) - return false; - - return controller->pauseTransitionAtTime(coreNode->renderer(), propertyName, time); -} - -void WebFrame::suspendAnimations() -{ - if (!m_coreFrame) - return; - - AnimationController* controller = m_coreFrame->animation(); - if (!controller) - return; - - controller->suspendAnimations(); -} - -void WebFrame::resumeAnimations() -{ - if (!m_coreFrame) - return; - - AnimationController* controller = m_coreFrame->animation(); - if (!controller) - return; - - controller->resumeAnimations(); -} - String WebFrame::layerTreeAsText() const { if (!m_coreFrame) @@ -553,8 +485,7 @@ bool WebFrame::handlesPageScaleGesture() const PluginDocument* pluginDocument = static_cast(m_coreFrame->document()); PluginView* pluginView = static_cast(pluginDocument->pluginWidget()); - - return pluginView->handlesPageScaleFactor(); + return pluginView && pluginView->handlesPageScaleFactor(); } IntRect WebFrame::contentBounds() const @@ -578,7 +509,7 @@ IntRect WebFrame::visibleContentBounds() const if (!view) return IntRect(); - IntRect contentRect = view->visibleContentRect(true); + IntRect contentRect = view->visibleContentRect(ScrollableArea::IncludeScrollbars); return IntRect(0, 0, contentRect.width(), contentRect.height()); } @@ -591,7 +522,7 @@ IntRect WebFrame::visibleContentBoundsExcludingScrollbars() const if (!view) return IntRect(); - IntRect contentRect = view->visibleContentRect(false); + IntRect contentRect = view->visibleContentRect(); return IntRect(0, 0, contentRect.width(), contentRect.height()); } @@ -636,7 +567,7 @@ PassRefPtr WebFrame::hitTest(const IntPoint point) if (!m_coreFrame) return 0; - return InjectedBundleHitTestResult::create(m_coreFrame->eventHandler()->hitTestResultAtPoint(point, false, true)); + return InjectedBundleHitTestResult::create(m_coreFrame->eventHandler()->hitTestResultAtPoint(point, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent)); } bool WebFrame::getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha) @@ -665,10 +596,28 @@ bool WebFrame::containsAnyFormElements() const if (!document) return false; - for (Node* node = document->documentElement(); node; node = node->traverseNextNode()) { + for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) { + if (!node->isElementNode()) + continue; + if (isHTMLFormElement(node)) + return true; + } + return false; +} + +bool WebFrame::containsAnyFormControls() const +{ + if (!m_coreFrame) + return false; + + Document* document = m_coreFrame->document(); + if (!document) + return false; + + for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) { if (!node->isElementNode()) continue; - if (static_cast(node)->hasTagName(HTMLNames::formTag)) + if (isHTMLInputElement(node) || toElement(node)->hasTagName(HTMLNames::selectTag) || isHTMLTextAreaElement(node)) return true; } return false; @@ -690,7 +639,9 @@ WebFrame* WebFrame::frameForContext(JSContextRef context) return 0; Frame* coreFrame = static_cast(globalObjectObj)->window()->impl()->frame(); - return static_cast(coreFrame->loader()->client())->webFrame(); + + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(coreFrame->loader()->client()); + return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; } JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleNodeHandle* nodeHandle, InjectedBundleScriptWorld* world) @@ -717,23 +668,6 @@ JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleRangeHandle* rangeHandle, I return toRef(exec, toJS(exec, globalObject, rangeHandle->coreRange())); } -JSValueRef WebFrame::computedStyleIncludingVisitedInfo(JSObjectRef element) -{ - if (!m_coreFrame) - return 0; - - JSDOMWindow* globalObject = m_coreFrame->script()->globalObject(mainThreadNormalWorld()); - ExecState* exec = globalObject->globalExec(); - - if (!toJS(element)->inherits(&JSElement::s_info)) - return JSValueMakeUndefined(toRef(exec)); - - RefPtr style = CSSComputedStyleDeclaration::create(static_cast(toJS(element))->impl(), true); - - JSLockHolder lock(exec); - return toRef(exec, toJS(exec, globalObject, style.get())); -} - String WebFrame::counterValue(JSObjectRef element) { if (!toJS(element)->inherits(&JSElement::s_info)) @@ -742,14 +676,6 @@ String WebFrame::counterValue(JSObjectRef element) return counterValueForElement(static_cast(toJS(element))->impl()); } -String WebFrame::markerText(JSObjectRef element) -{ - if (!toJS(element)->inherits(&JSElement::s_info)) - return String(); - - return markerTextForListItem(static_cast(toJS(element))->impl()); -} - String WebFrame::provisionalURL() const { if (!m_coreFrame) @@ -802,18 +728,18 @@ String WebFrame::mimeTypeForResourceWithURL(const KURL& url) const void WebFrame::setTextDirection(const String& direction) { - if (!m_coreFrame || !m_coreFrame->editor()) + if (!m_coreFrame) return; if (direction == "auto") - m_coreFrame->editor()->setBaseWritingDirection(NaturalWritingDirection); + m_coreFrame->editor().setBaseWritingDirection(NaturalWritingDirection); else if (direction == "ltr") - m_coreFrame->editor()->setBaseWritingDirection(LeftToRightWritingDirection); + m_coreFrame->editor().setBaseWritingDirection(LeftToRightWritingDirection); else if (direction == "rtl") - m_coreFrame->editor()->setBaseWritingDirection(RightToLeftWritingDirection); + m_coreFrame->editor().setBaseWritingDirection(RightToLeftWritingDirection); } -#if PLATFORM(MAC) || PLATFORM(WIN) +#if PLATFORM(MAC) class WebFrameFilter : public FrameFilter { public: @@ -838,8 +764,11 @@ bool WebFrameFilter::shouldIncludeSubframe(Frame* frame) const { if (!m_callback) return true; - - WebFrame* webFrame = static_cast(frame->loader()->client())->webFrame(); + + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader()->client()); + WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; + ASSERT(webFrame); + return m_callback(toAPI(m_topLevelWebFrame), toAPI(webFrame), m_context); } -- cgit v1.2.1