2 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2008 Collabora Ltd. All rights reserved.
6 * Coypright (C) 2008 Holger Hans Peter Freyther
7 * Coypright (C) 2009, 2010 Girish Ramakrishnan <girish@forwardbias.in>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "CSSComputedStyleDeclaration.h"
35 #include "CSSPropertyNames.h"
36 #include "FormState.h"
37 #include "FrameLoaderClientQt.h"
38 #include "FrameNetworkingContextQt.h"
39 #include "FrameTree.h"
40 #include "FrameView.h"
41 #include "DocumentLoader.h"
42 #include "HitTestResult.h"
44 #include "JSDOMWindowBase.h"
46 #include "V8DOMWindow.h"
48 #include "MIMETypeRegistry.h"
49 #include "MouseEvent.h"
50 #include "ResourceResponse.h"
52 #include "PluginData.h"
53 #include "PluginDatabase.h"
54 #include "ProgressTracker.h"
55 #include "RenderPart.h"
56 #include "ResourceRequest.h"
57 #include "HistoryItem.h"
58 #include "HTMLAppletElement.h"
59 #include "HTMLFormElement.h"
60 #include "HTMLPlugInElement.h"
61 #include "HTTPParsers.h"
62 #include "QtNAMThreadSafeProxy.h"
63 #include "NotImplemented.h"
64 #include "QNetworkReplyHandler.h"
65 #include "ResourceHandleInternal.h"
66 #include "ResourceHandle.h"
67 #include "ScriptController.h"
69 #include "QWebPageClient.h"
70 #include "ViewportArguments.h"
73 #include "qwebpage_p.h"
74 #include "qwebframe.h"
75 #include "qwebframe_p.h"
76 #include "qwebhistoryinterface.h"
77 #include "qwebpluginfactory.h"
79 #include <qfileinfo.h>
81 #include <QCoreApplication>
83 #include <QGraphicsScene>
84 #include <QGraphicsWidget>
85 #include <QNetworkRequest>
86 #include <QNetworkReply>
87 #include <QStringList>
88 #include "qwebhistory_p.h"
89 #include <wtf/OwnPtr.h>
91 static QMap<unsigned long, QString> dumpAssignedUrls;
93 // Compare with WebKitTools/DumpRenderTree/mac/FrameLoadDelegate.mm
94 static QString drtDescriptionSuitableForTestResult(WebCore::Frame* _frame)
96 QWebFrame* frame = QWebFramePrivate::kit(_frame);
97 QString name = frame->frameName();
99 bool isMainFrame = frame == frame->page()->mainFrame();
102 return QString::fromLatin1("main frame \"%1\"").arg(name);
103 return QLatin1String("main frame");
106 return QString::fromLatin1("frame \"%1\"").arg(name);
107 return QLatin1String("frame (anonymous)");
111 static QString drtPrintFrameUserGestureStatus(WebCore::Frame* frame)
113 if (frame->loader()->isProcessingUserGesture())
114 return QString::fromLatin1("Frame with user gesture \"%1\"").arg(QLatin1String("true"));
115 return QString::fromLatin1("Frame with user gesture \"%1\"").arg(QLatin1String("false"));
118 static QString drtDescriptionSuitableForTestResult(const WebCore::KURL& _url)
120 if (_url.isEmpty() || !_url.isLocalFile())
121 return _url.string();
122 // Remove the leading path from file urls
123 return QString(_url.string()).replace(WebCore::FrameLoaderClientQt::dumpResourceLoadCallbacksPath, "").mid(1);
126 static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceError& error)
128 QString failingURL = error.failingURL();
129 return QString::fromLatin1("<NSError domain NSURLErrorDomain, code %1, failing URL \"%2\">").arg(error.errorCode()).arg(failingURL);
132 static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceRequest& request)
134 QString url = drtDescriptionSuitableForTestResult(request.url());
135 QString httpMethod = request.httpMethod();
136 QString mainDocumentUrl = drtDescriptionSuitableForTestResult(request.firstPartyForCookies());
137 return QString::fromLatin1("<NSURLRequest URL %1, main document URL %2, http method %3>").arg(url).arg(mainDocumentUrl).arg(httpMethod);
140 static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceResponse& response)
142 QString url = drtDescriptionSuitableForTestResult(response.url());
143 int httpStatusCode = response.httpStatusCode();
144 return QString::fromLatin1("<NSURLResponse %1, http status code %2>").arg(url).arg(httpStatusCode);
147 static QString drtDescriptionSuitableForTestResult(const RefPtr<WebCore::Node> node, int exception)
151 result.append("ERROR");
155 result.append("NULL");
158 result.append(node->nodeName());
159 RefPtr<WebCore::Node> parent = node->parentNode();
161 result.append(" > ");
162 result.append(drtDescriptionSuitableForTestResult(parent, 0));
170 bool FrameLoaderClientQt::dumpFrameLoaderCallbacks = false;
171 bool FrameLoaderClientQt::dumpUserGestureInFrameLoaderCallbacks = false;
172 bool FrameLoaderClientQt::dumpResourceLoadCallbacks = false;
173 bool FrameLoaderClientQt::sendRequestReturnsNullOnRedirect = false;
174 bool FrameLoaderClientQt::sendRequestReturnsNull = false;
175 bool FrameLoaderClientQt::dumpResourceResponseMIMETypes = false;
176 bool FrameLoaderClientQt::deferMainResourceDataLoad = true;
177 bool FrameLoaderClientQt::dumpHistoryCallbacks = false;
179 QStringList FrameLoaderClientQt::sendRequestClearHeaders;
180 QString FrameLoaderClientQt::dumpResourceLoadCallbacksPath;
181 bool FrameLoaderClientQt::policyDelegateEnabled = false;
182 bool FrameLoaderClientQt::policyDelegatePermissive = false;
183 QMap<QString, QString> FrameLoaderClientQt::URLsToRedirect = QMap<QString, QString>();
185 // Taken from DumpRenderTree/chromium/WebViewHost.cpp
186 static const char* navigationTypeToString(NavigationType type)
189 case NavigationTypeLinkClicked:
190 return "link clicked";
191 case NavigationTypeFormSubmitted:
192 return "form submitted";
193 case NavigationTypeBackForward:
194 return "back/forward";
195 case NavigationTypeReload:
197 case NavigationTypeFormResubmitted:
198 return "form resubmitted";
199 case NavigationTypeOther:
202 return "illegal value";
205 FrameLoaderClientQt::FrameLoaderClientQt()
209 , m_hasSentResponseToPlugin(false)
210 , m_hasRepresentation(false)
211 , m_loadError(ResourceError())
216 FrameLoaderClientQt::~FrameLoaderClientQt()
220 void FrameLoaderClientQt::setFrame(QWebFrame* webFrame, Frame* frame)
222 m_webFrame = webFrame;
225 if (!m_webFrame || !m_webFrame->page()) {
226 qWarning("FrameLoaderClientQt::setFrame frame without Page!");
230 connect(this, SIGNAL(loadStarted()),
231 m_webFrame->page(), SIGNAL(loadStarted()));
232 connect(this, SIGNAL(loadStarted()),
233 m_webFrame, SIGNAL(loadStarted()));
234 connect(this, SIGNAL(loadProgress(int)),
235 m_webFrame->page(), SIGNAL(loadProgress(int)));
236 connect(this, SIGNAL(loadFinished(bool)),
237 m_webFrame->page(), SIGNAL(loadFinished(bool)));
238 connect(this, SIGNAL(loadFinished(bool)),
239 m_webFrame, SIGNAL(loadFinished(bool)));
240 connect(this, SIGNAL(titleChanged(QString)),
241 m_webFrame, SIGNAL(titleChanged(QString)));
244 void FrameLoaderClientQt::callPolicyFunction(FramePolicyFunction function, PolicyAction action)
246 (m_frame->loader()->policyChecker()->*function)(action);
249 bool FrameLoaderClientQt::hasWebView() const
255 void FrameLoaderClientQt::savePlatformDataToCachedFrame(CachedFrame*)
260 void FrameLoaderClientQt::transitionToCommittedFromCachedFrame(CachedFrame*)
264 void FrameLoaderClientQt::transitionToCommittedForNewPage()
269 QBrush brush = m_webFrame->page()->palette().brush(QPalette::Base);
270 QColor backgroundColor = brush.style() == Qt::SolidPattern ? brush.color() : QColor();
272 QWebPage* page = m_webFrame->page();
273 const QSize preferredLayoutSize = page->preferredContentsSize();
275 ScrollbarMode hScrollbar = (ScrollbarMode) m_webFrame->scrollBarPolicy(Qt::Horizontal);
276 ScrollbarMode vScrollbar = (ScrollbarMode) m_webFrame->scrollBarPolicy(Qt::Vertical);
277 bool hLock = hScrollbar != ScrollbarAuto;
278 bool vLock = vScrollbar != ScrollbarAuto;
280 IntSize currentVisibleContentSize = m_frame->view() ? m_frame->view()->actualVisibleContentRect().size() : IntSize();
282 m_frame->createView(m_webFrame->page()->viewportSize(),
283 backgroundColor, !backgroundColor.alpha(),
284 preferredLayoutSize.isValid() ? IntSize(preferredLayoutSize) : IntSize(),
285 preferredLayoutSize.isValid(),
289 bool isMainFrame = m_frame == m_frame->page()->mainFrame();
290 if (isMainFrame && page->d->client) {
291 m_frame->view()->setPaintsEntireContents(page->d->client->viewResizesToContentsEnabled());
292 m_frame->view()->setDelegatesScrolling(page->d->client->viewResizesToContentsEnabled());
295 // The HistoryController will update the scroll position later if needed.
296 m_frame->view()->setActualVisibleContentRect(IntRect(IntPoint::zero(), currentVisibleContentSize));
299 void FrameLoaderClientQt::didSaveToPageCache()
303 void FrameLoaderClientQt::didRestoreFromPageCache()
307 void FrameLoaderClientQt::dispatchDidBecomeFrameset(bool)
311 void FrameLoaderClientQt::makeRepresentation(DocumentLoader*)
313 m_hasRepresentation = true;
317 void FrameLoaderClientQt::forceLayout()
319 FrameView* view = m_frame->view();
325 void FrameLoaderClientQt::forceLayoutForNonHTML()
330 void FrameLoaderClientQt::setCopiesOnScroll()
332 // apparently mac specific
336 void FrameLoaderClientQt::detachedFromParent2()
341 void FrameLoaderClientQt::detachedFromParent3()
345 void FrameLoaderClientQt::dispatchDidHandleOnloadEvents()
347 // don't need this one
348 if (dumpFrameLoaderCallbacks)
349 printf("%s - didHandleOnloadEventsForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
353 void FrameLoaderClientQt::dispatchDidReceiveServerRedirectForProvisionalLoad()
355 if (dumpFrameLoaderCallbacks)
356 printf("%s - didReceiveServerRedirectForProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
362 void FrameLoaderClientQt::dispatchDidCancelClientRedirect()
364 if (dumpFrameLoaderCallbacks)
365 printf("%s - didCancelClientRedirectForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
371 void FrameLoaderClientQt::dispatchWillPerformClientRedirect(const KURL& url, double, double)
373 if (dumpFrameLoaderCallbacks)
374 printf("%s - willPerformClientRedirectToURL: %s \n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(drtDescriptionSuitableForTestResult(url)));
380 void FrameLoaderClientQt::dispatchDidChangeLocationWithinPage()
382 if (dumpFrameLoaderCallbacks)
383 printf("%s - didChangeLocationWithinPageForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
388 emit m_webFrame->urlChanged(m_webFrame->url());
389 m_webFrame->page()->d->updateNavigationActions();
393 void FrameLoaderClientQt::didCreateScriptContextForFrame()
396 void FrameLoaderClientQt::didDestroyScriptContextForFrame()
399 void FrameLoaderClientQt::didCreateIsolatedScriptContext()
404 void FrameLoaderClientQt::dispatchDidPushStateWithinPage()
406 if (dumpFrameLoaderCallbacks)
407 printf("%s - dispatchDidPushStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
412 void FrameLoaderClientQt::dispatchDidReplaceStateWithinPage()
414 if (dumpFrameLoaderCallbacks)
415 printf("%s - dispatchDidReplaceStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
420 void FrameLoaderClientQt::dispatchDidPopStateWithinPage()
422 if (dumpFrameLoaderCallbacks)
423 printf("%s - dispatchDidPopStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
428 void FrameLoaderClientQt::dispatchWillClose()
433 void FrameLoaderClientQt::dispatchDidStartProvisionalLoad()
435 if (dumpFrameLoaderCallbacks)
436 printf("%s - didStartProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
438 if (dumpUserGestureInFrameLoaderCallbacks)
439 printf("%s - in didStartProvisionalLoadForFrame\n", qPrintable(drtPrintFrameUserGestureStatus(m_frame)));
442 emit m_webFrame->provisionalLoad();
446 void FrameLoaderClientQt::dispatchDidReceiveTitle(const String& title)
448 if (dumpFrameLoaderCallbacks)
449 printf("%s - didReceiveTitle: %s\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(QString(title)));
454 emit titleChanged(title);
458 void FrameLoaderClientQt::dispatchDidChangeIcons()
460 if (dumpFrameLoaderCallbacks)
461 printf("%s - didChangeIcons\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
466 // FIXME: To be notified of changing icon URLS add notification
467 // emit iconsChanged();
471 void FrameLoaderClientQt::dispatchDidCommitLoad()
473 if (dumpFrameLoaderCallbacks)
474 printf("%s - didCommitLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
476 if (m_frame->tree()->parent() || !m_webFrame)
479 emit m_webFrame->urlChanged(m_webFrame->url());
480 m_webFrame->page()->d->updateNavigationActions();
482 // We should assume first the frame has no title. If it has, then the above dispatchDidReceiveTitle()
483 // will be called very soon with the correct title.
484 // This properly resets the title when we navigate to a URI without a title.
485 emit titleChanged(String());
487 bool isMainFrame = (m_frame == m_frame->page()->mainFrame());
491 emit m_webFrame->page()->viewportChangeRequested();
495 void FrameLoaderClientQt::dispatchDidFinishDocumentLoad()
497 if (dumpFrameLoaderCallbacks)
498 printf("%s - didFinishDocumentLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
500 if (QWebPagePrivate::drtRun) {
501 int unloadEventCount = m_frame->domWindow()->pendingUnloadEventListeners();
502 if (unloadEventCount)
503 printf("%s - has %u onunload handler(s)\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), unloadEventCount);
506 if (m_frame->tree()->parent() || !m_webFrame)
509 m_webFrame->page()->d->updateNavigationActions();
513 void FrameLoaderClientQt::dispatchDidFinishLoad()
515 if (dumpFrameLoaderCallbacks)
516 printf("%s - didFinishLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
518 // Clears the previous error.
519 m_loadError = ResourceError();
523 m_webFrame->page()->d->updateNavigationActions();
527 void FrameLoaderClientQt::dispatchDidFirstLayout()
531 void FrameLoaderClientQt::dispatchDidFirstVisuallyNonEmptyLayout()
534 emit m_webFrame->initialLayoutCompleted();
537 void FrameLoaderClientQt::dispatchShow()
543 void FrameLoaderClientQt::cancelPolicyCheck()
545 // qDebug() << "FrameLoaderClientQt::cancelPolicyCheck";
549 void FrameLoaderClientQt::dispatchWillSubmitForm(FramePolicyFunction function,
550 PassRefPtr<FormState>)
553 // FIXME: This is surely too simple
554 callPolicyFunction(function, PolicyUse);
558 void FrameLoaderClientQt::dispatchDidLoadMainResource(DocumentLoader*)
563 void FrameLoaderClientQt::revertToProvisionalState(DocumentLoader*)
565 m_hasRepresentation = true;
569 void FrameLoaderClientQt::postProgressStartedNotification()
571 if (m_webFrame && m_frame->page()) {
572 // A new load starts, so lets clear the previous error.
573 m_loadError = ResourceError();
575 postProgressEstimateChangedNotification();
577 if (m_frame->tree()->parent() || !m_webFrame)
579 m_webFrame->page()->d->updateNavigationActions();
582 void FrameLoaderClientQt::postProgressEstimateChangedNotification()
584 if (m_webFrame && m_frame->page())
585 emit loadProgress(qRound(m_frame->page()->progress()->estimatedProgress() * 100));
588 void FrameLoaderClientQt::postProgressFinishedNotification()
590 // send a mousemove event to
591 // (1) update the cursor to change according to whatever is underneath the mouse cursor right now
592 // (2) display the tool tip if the mouse hovers a node which has a tool tip
593 if (m_frame && m_frame->eventHandler() && m_webFrame->page()) {
594 QWidget* view = m_webFrame->page()->view();
595 if (view && view->hasFocus()) {
596 QPoint localPos = view->mapFromGlobal(QCursor::pos());
597 if (view->rect().contains(localPos)) {
598 QMouseEvent event(QEvent::MouseMove, localPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
599 m_frame->eventHandler()->mouseMoved(PlatformMouseEvent(&event, 0));
604 if (m_webFrame && m_frame->page())
605 emit loadFinished(m_loadError.isNull());
608 void FrameLoaderClientQt::setMainFrameDocumentReady(bool)
610 // this is only interesting once we provide an external API for the DOM
614 void FrameLoaderClientQt::willChangeTitle(DocumentLoader*)
616 // no need for, dispatchDidReceiveTitle is the right callback
620 void FrameLoaderClientQt::didChangeTitle(DocumentLoader*)
622 // no need for, dispatchDidReceiveTitle is the right callback
626 void FrameLoaderClientQt::finishedLoading(DocumentLoader* loader)
629 // This is necessary to create an empty document. See bug 634004.
630 // However, we only want to do this if makeRepresentation has been called, to
631 // match the behavior on the Mac.
632 if (m_hasRepresentation)
633 loader->writer()->setEncoding("", false);
636 if (m_pluginView->isPluginView())
637 m_pluginView->didFinishLoading();
639 m_hasSentResponseToPlugin = false;
642 bool FrameLoaderClientQt::canShowMIMETypeAsHTML(const String& MIMEType) const
648 bool FrameLoaderClientQt::canShowMIMEType(const String& MIMEType) const
650 String type = MIMEType;
652 if (MIMETypeRegistry::isSupportedImageMIMEType(type))
655 if (MIMETypeRegistry::isSupportedNonImageMIMEType(type))
658 if (m_frame && m_frame->settings() && m_frame->settings()->arePluginsEnabled()
659 && PluginDatabase::installedPlugins()->isMIMETypeRegistered(type))
665 bool FrameLoaderClientQt::representationExistsForURLScheme(const String&) const
671 String FrameLoaderClientQt::generatedMIMETypeForURLScheme(const String&) const
678 void FrameLoaderClientQt::frameLoadCompleted()
680 // Note: Can be called multiple times.
684 void FrameLoaderClientQt::restoreViewState()
688 emit m_webFrame->page()->restoreFrameStateRequested(m_webFrame);
692 void FrameLoaderClientQt::provisionalLoadStarted()
694 // don't need to do anything here
698 void FrameLoaderClientQt::didFinishLoad()
704 void FrameLoaderClientQt::prepareForDataSourceReplacement()
708 void FrameLoaderClientQt::setTitle(const String& title, const KURL& url)
710 // Used by Apple WebKit to update the title of an existing history item.
711 // QtWebKit doesn't accomodate this on history items. If it ever does,
712 // it should be privateBrowsing-aware.For now, we are just passing
713 // globalhistory layout tests.
714 if (dumpHistoryCallbacks) {
715 printf("WebView updated the title for history URL \"%s\" to \"%s\".\n",
716 qPrintable(drtDescriptionSuitableForTestResult(url)),
717 qPrintable(QString(title)));
722 String FrameLoaderClientQt::userAgent(const KURL& url)
725 return m_webFrame->page()->userAgentForUrl(url);
730 void FrameLoaderClientQt::dispatchDidReceiveIcon()
733 emit m_webFrame->iconChanged();
737 void FrameLoaderClientQt::frameLoaderDestroyed()
746 bool FrameLoaderClientQt::canHandleRequest(const WebCore::ResourceRequest&) const
751 void FrameLoaderClientQt::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
753 if (world != mainThreadNormalWorld())
757 emit m_webFrame->javaScriptWindowObjectCleared();
761 void FrameLoaderClientQt::documentElementAvailable()
766 void FrameLoaderClientQt::didPerformFirstNavigation() const
768 if (m_frame->tree()->parent() || !m_webFrame)
770 m_webFrame->page()->d->updateNavigationActions();
773 void FrameLoaderClientQt::registerForIconNotification(bool)
778 void FrameLoaderClientQt::updateGlobalHistory()
780 QWebHistoryInterface *history = QWebHistoryInterface::defaultInterface();
781 WebCore::DocumentLoader* loader = m_frame->loader()->documentLoader();
783 history->addHistoryEntry(loader->urlForHistory().prettyURL());
785 if (dumpHistoryCallbacks) {
786 printf("WebView navigated to url \"%s\" with title \"%s\" with HTTP equivalent method \"%s\". The navigation was %s and was %s%s.\n",
787 qPrintable(drtDescriptionSuitableForTestResult(loader->urlForHistory())),
788 qPrintable(QString(loader->title())),
789 qPrintable(QString(loader->request().httpMethod())),
790 ((loader->substituteData().isValid() || (loader->response().httpStatusCode() >= 400)) ? "a failure" : "successful"),
791 ((!loader->clientRedirectSourceForHistory().isEmpty()) ? "a client redirect from " : "not a client redirect"),
792 (!loader->clientRedirectSourceForHistory().isEmpty()) ? qPrintable(drtDescriptionSuitableForTestResult(loader->clientRedirectSourceForHistory())) : "");
796 void FrameLoaderClientQt::updateGlobalHistoryRedirectLinks()
798 // Apple WebKit is the only port that makes use of this callback. It calls
799 // WebCore::HistoryItem::addRedirectURL() with the contents of
800 // loader->[server|client]RedirectDestinationForHistory().
801 // WebCore can associate a bunch of redirect URLs with a particular
802 // item in the history, presumably this allows Safari to skip the redirections
803 // when navigating to that history item. That might be a feature Qt wants to
804 // offer through QWebHistoryInterface in the future. For now, we're just
805 // passing tests in LayoutTests/http/tests/globalhistory.
806 WebCore::DocumentLoader* loader = m_frame->loader()->documentLoader();
808 if (!loader->clientRedirectSourceForHistory().isNull()) {
809 if (dumpHistoryCallbacks) {
810 printf("WebView performed a client redirect from \"%s\" to \"%s\".\n",
811 qPrintable(QString(loader->clientRedirectSourceForHistory())),
812 qPrintable(QString(loader->clientRedirectDestinationForHistory())));
816 if (!loader->serverRedirectSourceForHistory().isNull()) {
817 if (dumpHistoryCallbacks) {
818 printf("WebView performed a server redirect from \"%s\" to \"%s\".\n",
819 qPrintable(QString(loader->serverRedirectSourceForHistory())),
820 qPrintable(QString(loader->serverRedirectDestinationForHistory())));
825 bool FrameLoaderClientQt::shouldGoToHistoryItem(WebCore::HistoryItem *) const
830 void FrameLoaderClientQt::dispatchDidAddBackForwardItem(WebCore::HistoryItem*) const
834 void FrameLoaderClientQt::dispatchDidRemoveBackForwardItem(WebCore::HistoryItem*) const
838 void FrameLoaderClientQt::dispatchDidChangeBackForwardIndex() const
842 void FrameLoaderClientQt::didDisplayInsecureContent()
844 if (dumpFrameLoaderCallbacks)
845 printf("didDisplayInsecureContent\n");
850 void FrameLoaderClientQt::didRunInsecureContent(WebCore::SecurityOrigin*, const KURL&)
852 if (dumpFrameLoaderCallbacks)
853 printf("didRunInsecureContent\n");
858 void FrameLoaderClientQt::saveViewStateToItem(WebCore::HistoryItem* item)
860 QWebHistoryItem historyItem(new QWebHistoryItemPrivate(item));
861 emit m_webFrame->page()->saveFrameStateRequested(m_webFrame, &historyItem);
864 bool FrameLoaderClientQt::canCachePage() const
869 void FrameLoaderClientQt::setMainDocumentError(WebCore::DocumentLoader* loader, const WebCore::ResourceError& error)
873 if (m_pluginView->isPluginView())
874 m_pluginView->didFail(error);
876 m_hasSentResponseToPlugin = false;
879 // FIXME: This function should be moved into WebCore.
880 void FrameLoaderClientQt::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
883 loader->commitData(data, length);
885 // We re-check here as the plugin can have been created
886 if (m_pluginView && m_pluginView->isPluginView()) {
887 if (!m_hasSentResponseToPlugin) {
888 m_pluginView->didReceiveResponse(loader->response());
889 // didReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
890 // setting up this stream can cause the main document load to be cancelled, setting m_pluginView
894 m_hasSentResponseToPlugin = true;
896 m_pluginView->didReceiveData(data, length);
900 WebCore::ResourceError FrameLoaderClientQt::cancelledError(const WebCore::ResourceRequest& request)
902 ResourceError error = ResourceError("QtNetwork", QNetworkReply::OperationCanceledError, request.url().prettyURL(),
903 QCoreApplication::translate("QWebFrame", "Request cancelled", 0, QCoreApplication::UnicodeUTF8));
904 error.setIsCancellation(true);
908 // copied from WebKit/Misc/WebKitErrors[Private].h
910 WebKitErrorCannotShowMIMEType = 100,
911 WebKitErrorCannotShowURL = 101,
912 WebKitErrorFrameLoadInterruptedByPolicyChange = 102,
913 WebKitErrorCannotUseRestrictedPort = 103,
914 WebKitErrorCannotFindPlugIn = 200,
915 WebKitErrorCannotLoadPlugIn = 201,
916 WebKitErrorJavaUnavailable = 202,
917 WebKitErrorPluginWillHandleLoad = 203
920 WebCore::ResourceError FrameLoaderClientQt::blockedError(const WebCore::ResourceRequest& request)
922 return ResourceError("WebKitErrorDomain", WebKitErrorCannotUseRestrictedPort, request.url().prettyURL(),
923 QCoreApplication::translate("QWebFrame", "Request blocked", 0, QCoreApplication::UnicodeUTF8));
927 WebCore::ResourceError FrameLoaderClientQt::cannotShowURLError(const WebCore::ResourceRequest& request)
929 return ResourceError("WebKitErrorDomain", WebKitErrorCannotShowURL, request.url().string(),
930 QCoreApplication::translate("QWebFrame", "Cannot show URL", 0, QCoreApplication::UnicodeUTF8));
933 WebCore::ResourceError FrameLoaderClientQt::interruptForPolicyChangeError(const WebCore::ResourceRequest& request)
935 return ResourceError("WebKitErrorDomain", WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(),
936 QCoreApplication::translate("QWebFrame", "Frame load interrupted by policy change", 0, QCoreApplication::UnicodeUTF8));
939 WebCore::ResourceError FrameLoaderClientQt::cannotShowMIMETypeError(const WebCore::ResourceResponse& response)
941 return ResourceError("WebKitErrorDomain", WebKitErrorCannotShowMIMEType, response.url().string(),
942 QCoreApplication::translate("QWebFrame", "Cannot show mimetype", 0, QCoreApplication::UnicodeUTF8));
945 WebCore::ResourceError FrameLoaderClientQt::fileDoesNotExistError(const WebCore::ResourceResponse& response)
947 return ResourceError("QtNetwork", QNetworkReply::ContentNotFoundError, response.url().string(),
948 QCoreApplication::translate("QWebFrame", "File does not exist", 0, QCoreApplication::UnicodeUTF8));
951 WebCore::ResourceError FrameLoaderClientQt::pluginWillHandleLoadError(const WebCore::ResourceResponse& response)
953 return ResourceError("WebKit", WebKitErrorPluginWillHandleLoad, response.url().string(),
954 QCoreApplication::translate("QWebFrame", "Loading is handled by the media engine", 0, QCoreApplication::UnicodeUTF8));
957 bool FrameLoaderClientQt::shouldFallBack(const WebCore::ResourceError&)
963 WTF::PassRefPtr<WebCore::DocumentLoader> FrameLoaderClientQt::createDocumentLoader(const WebCore::ResourceRequest& request, const SubstituteData& substituteData)
965 RefPtr<DocumentLoader> loader = DocumentLoader::create(request, substituteData);
966 if (!deferMainResourceDataLoad || substituteData.isValid()) {
967 loader->setDeferMainResourceDataLoad(false);
968 // Use the default timeout interval for JS as the HTML tokenizer delay. This ensures
969 // that long-running JavaScript will still allow setHtml() to be synchronous, while
970 // still giving a reasonable timeout to prevent deadlock.
972 double delay = JSDOMWindowBase::commonJSGlobalData()->timeoutChecker.timeoutInterval() / 1000.0f;
974 // FIXME: Hard coded for now.
975 double delay = 10000 / 1000.0f;
977 m_frame->page()->setCustomHTMLTokenizerTimeDelay(delay);
979 m_frame->page()->setCustomHTMLTokenizerTimeDelay(-1);
980 return loader.release();
983 void FrameLoaderClientQt::download(WebCore::ResourceHandle* handle, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
988 QNetworkReplyHandler* handler = handle->getInternal()->m_job;
989 QtNetworkReplyThreadSafeProxy* replyProxy = handler->release();
991 QWebPage *page = m_webFrame->page();
992 if (page->forwardUnsupportedContent())
993 emit page->unsupportedContent(replyProxy->reply());
999 void FrameLoaderClientQt::assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest& request)
1001 if (dumpResourceLoadCallbacks)
1002 dumpAssignedUrls[identifier] = drtDescriptionSuitableForTestResult(request.url());
1005 void FrameLoaderClientQt::dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest& newRequest, const WebCore::ResourceResponse& redirectResponse)
1008 if (dumpResourceLoadCallbacks)
1009 printf("%s - willSendRequest %s redirectResponse %s\n",
1010 qPrintable(dumpAssignedUrls[identifier]),
1011 qPrintable(drtDescriptionSuitableForTestResult(newRequest)),
1012 (redirectResponse.isNull()) ? "(null)" : qPrintable(drtDescriptionSuitableForTestResult(redirectResponse)));
1014 if (sendRequestReturnsNull)
1015 newRequest.setURL(QUrl());
1017 if (sendRequestReturnsNullOnRedirect && !redirectResponse.isNull()) {
1018 printf("Returning null for this redirect\n");
1019 newRequest.setURL(QUrl());
1022 for (int i = 0; i < sendRequestClearHeaders.size(); ++i)
1023 newRequest.setHTTPHeaderField(sendRequestClearHeaders.at(i).toLocal8Bit().constData(), QString());
1025 if (QWebPagePrivate::drtRun) {
1026 QString url = newRequest.url().string();
1027 if (URLsToRedirect.contains(url))
1028 newRequest.setURL(QUrl(URLsToRedirect[url]));
1030 // seems like the Mac code doesn't do anything here by default neither
1031 //qDebug() << "FrameLoaderClientQt::dispatchWillSendRequest" << request.isNull() << request.url().string`();
1035 FrameLoaderClientQt::shouldUseCredentialStorage(DocumentLoader*, unsigned long)
1041 void FrameLoaderClientQt::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
1046 void FrameLoaderClientQt::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
1051 void FrameLoaderClientQt::dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse& response)
1054 m_response = response;
1055 if (dumpResourceLoadCallbacks)
1056 printf("%s - didReceiveResponse %s\n",
1057 qPrintable(dumpAssignedUrls[identifier]),
1058 qPrintable(drtDescriptionSuitableForTestResult(response)));
1060 if (dumpResourceResponseMIMETypes) {
1061 printf("%s has MIME type %s\n",
1062 qPrintable(QFileInfo(drtDescriptionSuitableForTestResult(response.url())).fileName()),
1063 qPrintable(QString(response.mimeType())));
1067 void FrameLoaderClientQt::dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long, int)
1071 void FrameLoaderClientQt::dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier)
1073 if (dumpResourceLoadCallbacks)
1074 printf("%s - didFinishLoading\n",
1075 (dumpAssignedUrls.contains(identifier) ? qPrintable(dumpAssignedUrls[identifier]) : "<unknown>"));
1078 void FrameLoaderClientQt::dispatchDidFailLoading(WebCore::DocumentLoader* loader, unsigned long identifier, const WebCore::ResourceError& error)
1080 if (dumpResourceLoadCallbacks)
1081 printf("%s - didFailLoadingWithError: %s\n",
1082 (dumpAssignedUrls.contains(identifier) ? qPrintable(dumpAssignedUrls[identifier]) : "<unknown>"),
1083 qPrintable(drtDescriptionSuitableForTestResult(error)));
1086 bool FrameLoaderClientQt::dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int)
1092 void FrameLoaderClientQt::callErrorPageExtension(const WebCore::ResourceError& error)
1094 QWebPage* page = m_webFrame->page();
1095 if (page->supportsExtension(QWebPage::ErrorPageExtension)) {
1096 QWebPage::ErrorPageExtensionOption option;
1098 if (error.domain() == "QtNetwork")
1099 option.domain = QWebPage::QtNetwork;
1100 else if (error.domain() == "HTTP")
1101 option.domain = QWebPage::Http;
1102 else if (error.domain() == "WebKit")
1103 option.domain = QWebPage::WebKit;
1107 option.url = QUrl(error.failingURL());
1108 option.frame = m_webFrame;
1109 option.error = error.errorCode();
1110 option.errorString = error.localizedDescription();
1112 QWebPage::ErrorPageExtensionReturn output;
1113 if (!page->extension(QWebPage::ErrorPageExtension, &option, &output))
1116 KURL baseUrl(output.baseUrl);
1117 KURL failingUrl(option.url);
1119 WebCore::ResourceRequest request(baseUrl);
1120 WTF::RefPtr<WebCore::SharedBuffer> buffer = WebCore::SharedBuffer::create(output.content.constData(), output.content.length());
1121 WebCore::SubstituteData substituteData(buffer, output.contentType, output.encoding, failingUrl);
1122 m_frame->loader()->load(request, substituteData, false);
1126 void FrameLoaderClientQt::dispatchDidFailProvisionalLoad(const WebCore::ResourceError& error)
1128 if (dumpFrameLoaderCallbacks)
1129 printf("%s - didFailProvisionalLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
1131 m_loadError = error;
1132 if (!error.isNull() && !error.isCancellation())
1133 callErrorPageExtension(error);
1136 void FrameLoaderClientQt::dispatchDidFailLoad(const WebCore::ResourceError& error)
1138 if (dumpFrameLoaderCallbacks)
1139 printf("%s - didFailLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
1141 m_loadError = error;
1142 if (!error.isNull() && !error.isCancellation())
1143 callErrorPageExtension(error);
1146 WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage(const WebCore::NavigationAction&)
1150 QWebPage *newPage = m_webFrame->page()->createWindow(QWebPage::WebBrowserWindow);
1153 return newPage->mainFrame()->d->frame;
1156 void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WTF::String& MIMEType, const WebCore::ResourceRequest&)
1158 // we need to call directly here
1159 const ResourceResponse& response = m_frame->loader()->activeDocumentLoader()->response();
1160 if (WebCore::contentDispositionType(response.httpHeaderField("Content-Disposition")) == WebCore::ContentDispositionAttachment)
1161 callPolicyFunction(function, PolicyDownload);
1162 else if (canShowMIMEType(MIMEType))
1163 callPolicyFunction(function, PolicyUse);
1165 callPolicyFunction(function, PolicyDownload);
1168 void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>, const WTF::String&)
1170 Q_ASSERT(m_webFrame);
1171 QNetworkRequest r(request.toNetworkRequest(m_webFrame));
1172 QWebPage* page = m_webFrame->page();
1174 if (!page->d->acceptNavigationRequest(0, r, QWebPage::NavigationType(action.type()))) {
1175 if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted)
1176 m_frame->loader()->resetMultipleFormSubmissionProtection();
1178 if (action.type() == NavigationTypeLinkClicked && r.url().hasFragment()) {
1179 ResourceRequest emptyRequest;
1180 m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest);
1183 callPolicyFunction(function, PolicyIgnore);
1186 callPolicyFunction(function, PolicyUse);
1189 void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>)
1191 Q_ASSERT(m_webFrame);
1192 QNetworkRequest r(request.toNetworkRequest(m_webFrame));
1193 QWebPage*page = m_webFrame->page();
1194 PolicyAction result;
1196 // Currently, this is only enabled by DRT
1197 if (policyDelegateEnabled) {
1199 for (const Event* event = action.event(); event; event = event->underlyingEvent()) {
1200 if (event->isMouseEvent()) {
1201 const MouseEvent* mouseEvent = static_cast<const MouseEvent*>(event);
1202 node = QWebFramePrivate::core(m_webFrame)->eventHandler()->hitTestResultAtPoint(
1203 mouseEvent->absoluteLocation(), false).innerNonSharedNode();
1208 printf("Policy delegate: attempt to load %s with navigation type '%s'%s\n",
1209 qPrintable(drtDescriptionSuitableForTestResult(request.url())), navigationTypeToString(action.type()),
1210 (node) ? qPrintable(QString(" originating from " + drtDescriptionSuitableForTestResult(node, 0))) : "");
1212 if (policyDelegatePermissive)
1215 result = PolicyIgnore;
1217 callPolicyFunction(function, result);
1221 if (!page->d->acceptNavigationRequest(m_webFrame, r, QWebPage::NavigationType(action.type()))) {
1222 if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted)
1223 m_frame->loader()->resetMultipleFormSubmissionProtection();
1225 if (action.type() == NavigationTypeLinkClicked && r.url().hasFragment()) {
1226 ResourceRequest emptyRequest;
1227 m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest);
1230 callPolicyFunction(function, PolicyIgnore);
1233 callPolicyFunction(function, PolicyUse);
1236 void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::ResourceError&)
1241 void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request)
1246 emit m_webFrame->page()->downloadRequested(request.toNetworkRequest(m_webFrame));
1249 PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
1250 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
1255 QWebFrameData frameData(m_frame->page(), m_frame, ownerElement, name);
1258 frameData.url = blankURL();
1260 frameData.url = url;
1262 frameData.referrer = referrer;
1263 frameData.allowsScrolling = allowsScrolling;
1264 frameData.marginWidth = marginWidth;
1265 frameData.marginHeight = marginHeight;
1267 QPointer<QWebFrame> webFrame = new QWebFrame(m_webFrame, &frameData);
1268 // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
1269 if (!webFrame->d->frame->page()) {
1270 frameData.frame.release();
1271 ASSERT(webFrame.isNull());
1275 emit m_webFrame->page()->frameCreated(webFrame);
1277 // ### set override encoding if we have one
1279 m_frame->loader()->loadURLIntoChildFrame(frameData.url, frameData.referrer, frameData.frame.get());
1281 // The frame's onload handler may have removed it from the document.
1282 if (!frameData.frame->tree()->parent())
1285 return frameData.frame.release();
1288 void FrameLoaderClientQt::didTransferChildFrameToNewDocument(Page*)
1290 ASSERT(m_frame->ownerElement());
1295 Frame* parentFrame = m_webFrame->d->frame->tree()->parent();
1296 ASSERT(parentFrame);
1298 if (QWebFrame* parent = QWebFramePrivate::kit(parentFrame)) {
1299 m_webFrame->d->setPage(parent->page());
1301 if (m_webFrame->parent() != qobject_cast<QObject*>(parent))
1302 m_webFrame->setParent(parent);
1306 void FrameLoaderClientQt::transferLoadingResourceFromPage(unsigned long, DocumentLoader*, const ResourceRequest&, Page*)
1310 ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& _mimeType)
1312 // qDebug()<<" ++++++++++++++++ url is "<<url.prettyURL()<<", mime = "<<_mimeType;
1313 QFileInfo fi(url.path());
1314 String extension = fi.suffix();
1315 if (_mimeType == "application/x-qt-plugin" || _mimeType == "application/x-qt-styled-widget")
1316 return ObjectContentOtherPlugin;
1318 if (url.isEmpty() && !_mimeType.length())
1319 return ObjectContentNone;
1321 String mimeType = _mimeType;
1322 if (!mimeType.length())
1323 mimeType = MIMETypeRegistry::getMIMETypeForExtension(extension);
1325 if (!mimeType.length())
1326 mimeType = PluginDatabase::installedPlugins()->MIMETypeForExtension(extension);
1328 if (!mimeType.length())
1329 return ObjectContentFrame;
1331 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
1332 return ObjectContentImage;
1334 if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))
1335 return ObjectContentNetscapePlugin;
1337 if (m_frame->page() && m_frame->page()->pluginData() && m_frame->page()->pluginData()->supportsMimeType(mimeType))
1338 return ObjectContentOtherPlugin;
1340 if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
1341 return ObjectContentFrame;
1343 if (url.protocol() == "about")
1344 return ObjectContentFrame;
1346 return ObjectContentNone;
1349 static const CSSPropertyID qstyleSheetProperties[] = {
1351 CSSPropertyFontFamily,
1352 CSSPropertyFontSize,
1353 CSSPropertyFontStyle,
1354 CSSPropertyFontWeight
1357 const unsigned numqStyleSheetProperties = sizeof(qstyleSheetProperties) / sizeof(qstyleSheetProperties[0]);
1359 class QtPluginWidget: public Widget
1362 QtPluginWidget(QWidget* w = 0): Widget(w) {}
1365 if (platformWidget())
1366 platformWidget()->deleteLater();
1368 virtual void invalidateRect(const IntRect& r)
1370 if (platformWidget())
1371 platformWidget()->update(r);
1373 virtual void frameRectsChanged()
1375 if (!platformWidget())
1378 IntRect windowRect = convertToContainingWindow(IntRect(0, 0, frameRect().width(), frameRect().height()));
1379 platformWidget()->setGeometry(windowRect);
1381 ScrollView* parentScrollView = parent();
1382 if (!parentScrollView)
1385 ASSERT(parentScrollView->isFrameView());
1386 IntRect clipRect(static_cast<FrameView*>(parentScrollView)->windowClipRect());
1387 clipRect.move(-windowRect.x(), -windowRect.y());
1388 clipRect.intersect(platformWidget()->rect());
1390 QRegion clipRegion = QRegion(clipRect);
1391 platformWidget()->setMask(clipRegion);
1395 platformWidget()->update();
1405 void handleVisibility()
1410 // if setMask is set with an empty QRegion, no clipping will
1411 // be performed, so in that case we hide the platformWidget
1412 QRegion mask = platformWidget()->mask();
1413 platformWidget()->setVisible(!mask.isEmpty());
1417 #if !defined(QT_NO_GRAPHICSVIEW)
1418 class QtPluginGraphicsWidget: public Widget
1421 static RefPtr<QtPluginGraphicsWidget> create(QGraphicsWidget* w = 0)
1423 return adoptRef(new QtPluginGraphicsWidget(w));
1426 ~QtPluginGraphicsWidget()
1429 graphicsWidget->deleteLater();
1431 virtual void invalidateRect(const IntRect& r)
1433 QGraphicsScene* scene = graphicsWidget ? graphicsWidget->scene() : 0;
1435 scene->update(QRect(r));
1437 virtual void frameRectsChanged()
1439 if (!graphicsWidget)
1442 IntRect windowRect = convertToContainingWindow(IntRect(0, 0, frameRect().width(), frameRect().height()));
1443 graphicsWidget->setGeometry(QRect(windowRect));
1445 // FIXME: clipping of graphics widgets
1450 graphicsWidget->show();
1455 graphicsWidget->hide();
1458 QtPluginGraphicsWidget(QGraphicsWidget* w = 0)
1462 setBindingObject(graphicsWidget);
1465 QGraphicsWidget* graphicsWidget;
1467 #endif // QT_NO_GRAPHICSVIEW
1469 PassRefPtr<Widget> FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames,
1470 const Vector<String>& paramValues, const String& mimeType, bool loadManually)
1472 // qDebug()<<"------ Creating plugin in FrameLoaderClientQt::createPlugin for "<<url.prettyURL() << mimeType;
1473 // qDebug()<<"------\t url = "<<url.prettyURL();
1480 QString classid(element->getAttribute("classid"));
1482 for (unsigned i = 0; i < paramNames.size(); ++i) {
1483 params.append(paramNames[i]);
1484 if (paramNames[i] == "classid")
1485 classid = paramValues[i];
1487 for (unsigned i = 0; i < paramValues.size(); ++i)
1488 values.append(paramValues[i]);
1490 QString urlStr(url.string());
1493 QObject* object = 0;
1495 if (mimeType == "application/x-qt-plugin" || mimeType == "application/x-qt-styled-widget") {
1496 object = m_webFrame->page()->createPlugin(classid, qurl, params, values);
1497 #ifndef QT_NO_STYLE_STYLESHEET
1498 QWidget* widget = qobject_cast<QWidget*>(object);
1499 if (widget && mimeType == "application/x-qt-styled-widget") {
1501 QString styleSheet = element->getAttribute("style");
1502 if (!styleSheet.isEmpty())
1503 styleSheet += QLatin1Char(';');
1505 for (unsigned i = 0; i < numqStyleSheetProperties; ++i) {
1506 CSSPropertyID property = qstyleSheetProperties[i];
1508 styleSheet += QString::fromLatin1(getPropertyName(property));
1509 styleSheet += QLatin1Char(':');
1510 styleSheet += computedStyle(element)->getPropertyValue(property);
1511 styleSheet += QLatin1Char(';');
1514 widget->setStyleSheet(styleSheet);
1516 #endif // QT_NO_STYLE_STYLESHEET
1520 QWebPluginFactory* factory = m_webFrame->page()->pluginFactory();
1522 object = factory->create(mimeType, qurl, params, values);
1526 QWidget* widget = qobject_cast<QWidget*>(object);
1528 QWidget* parentWidget = 0;
1529 if (m_webFrame->page()->d->client)
1530 parentWidget = qobject_cast<QWidget*>(m_webFrame->page()->d->client->pluginParent());
1531 if (parentWidget) // don't reparent to nothing (i.e. keep whatever parent QWebPage::createPlugin() chose.
1532 widget->setParent(parentWidget);
1534 RefPtr<QtPluginWidget> w = adoptRef(new QtPluginWidget());
1535 w->setPlatformWidget(widget);
1536 // Make sure it's invisible until properly placed into the layout
1537 w->setFrameRect(IntRect(0, 0, 0, 0));
1541 #if !defined(QT_NO_GRAPHICSVIEW)
1542 QGraphicsWidget* graphicsWidget = qobject_cast<QGraphicsWidget*>(object);
1543 if (graphicsWidget) {
1544 QGraphicsObject* parentWidget = 0;
1545 if (m_webFrame->page()->d->client)
1546 parentWidget = qobject_cast<QGraphicsObject*>(m_webFrame->page()->d->client->pluginParent());
1547 graphicsWidget->hide();
1548 if (parentWidget) // don't reparent to nothing (i.e. keep whatever parent QWebPage::createPlugin() chose.
1549 graphicsWidget->setParentItem(parentWidget);
1550 RefPtr<QtPluginGraphicsWidget> w = QtPluginGraphicsWidget::create(graphicsWidget);
1551 // Make sure it's invisible until properly placed into the layout
1552 w->setFrameRect(IntRect(0, 0, 0, 0));
1555 #endif // QT_NO_GRAPHICSVIEW
1557 // FIXME: make things work for widgetless plugins as well
1560 #if ENABLE(NETSCAPE_PLUGIN_API)
1561 else { // NPAPI Plugins
1562 Vector<String> params = paramNames;
1563 Vector<String> values = paramValues;
1564 if (mimeType == "application/x-shockwave-flash") {
1565 QWebPageClient* client = m_webFrame->page()->d->client.get();
1566 const bool isQWebView = client && qobject_cast<QWidget*>(client->pluginParent());
1567 #if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO >= 5)
1568 size_t wmodeIndex = params.find("wmode");
1569 if (wmodeIndex == -1) {
1570 // Disable XEmbed mode and force it to opaque mode
1571 params.append("wmode");
1572 values.append("opaque");
1573 } else if (!isQWebView) {
1574 // Disable transparency if client is not a QWebView
1575 values[wmodeIndex] = "opaque";
1579 // inject wmode=opaque when there is no client or the client is not a QWebView
1580 size_t wmodeIndex = params.find("wmode");
1581 if (wmodeIndex == -1) {
1582 params.append("wmode");
1583 values.append("opaque");
1584 } else if (equalIgnoringCase(values[wmodeIndex], "window"))
1585 values[wmodeIndex] = "opaque";
1590 RefPtr<PluginView> pluginView = PluginView::create(m_frame, pluginSize, element, url,
1591 params, values, mimeType, loadManually);
1594 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1599 void FrameLoaderClientQt::redirectDataToPlugin(Widget* pluginWidget)
1601 ASSERT(!m_pluginView);
1602 m_pluginView = static_cast<PluginView*>(pluginWidget);
1603 m_hasSentResponseToPlugin = false;
1606 PassRefPtr<Widget> FrameLoaderClientQt::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* element, const KURL& url,
1607 const Vector<String>& paramNames, const Vector<String>& paramValues)
1609 return createPlugin(pluginSize, element, url, paramNames, paramValues, "application/x-java-applet", true);
1612 String FrameLoaderClientQt::overrideMediaType() const
1617 QString FrameLoaderClientQt::chooseFile(const QString& oldFile)
1619 return m_webFrame->page()->chooseFile(m_webFrame, oldFile);
1622 PassRefPtr<FrameNetworkingContext> FrameLoaderClientQt::createNetworkingContext()
1624 return FrameNetworkingContextQt::create(m_frame, m_webFrame, m_webFrame->page()->networkAccessManager());
1629 #include "moc_FrameLoaderClientQt.cpp"