Home | History | Annotate | Download | only in WebCoreSupport
      1 /*
      2  * Copyright (C) 2006 Zack Rusin <zack (at) 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 Girish Ramakrishnan <girish (at) forwardbias.in>
      8  *
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     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.
     19  *
     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.
     31  */
     32 
     33 #include "config.h"
     34 #include "CSSComputedStyleDeclaration.h"
     35 #include "CSSPropertyNames.h"
     36 #include "FormState.h"
     37 #include "FrameLoaderClientQt.h"
     38 #include "FrameTree.h"
     39 #include "FrameView.h"
     40 #include "DocumentLoader.h"
     41 #include "MIMETypeRegistry.h"
     42 #include "ResourceResponse.h"
     43 #include "Page.h"
     44 #include "PluginData.h"
     45 #include "PluginDatabase.h"
     46 #include "ProgressTracker.h"
     47 #include "RenderPart.h"
     48 #include "ResourceRequest.h"
     49 #include "HistoryItem.h"
     50 #include "HTMLAppletElement.h"
     51 #include "HTMLFormElement.h"
     52 #include "HTMLPlugInElement.h"
     53 #include "NotImplemented.h"
     54 #include "QNetworkReplyHandler.h"
     55 #include "ResourceHandleInternal.h"
     56 #include "ResourceHandle.h"
     57 #include "ScriptController.h"
     58 #include "ScriptString.h"
     59 #include "Settings.h"
     60 #include "QWebPageClient.h"
     61 
     62 #include "qwebpage.h"
     63 #include "qwebpage_p.h"
     64 #include "qwebframe.h"
     65 #include "qwebframe_p.h"
     66 #include "qwebhistoryinterface.h"
     67 #include "qwebpluginfactory.h"
     68 
     69 #include <qfileinfo.h>
     70 
     71 #include <QCoreApplication>
     72 #include <QDebug>
     73 #include <QGraphicsScene>
     74 #include <QGraphicsWidget>
     75 #include <QNetworkRequest>
     76 #include <QNetworkReply>
     77 #include "qwebhistory_p.h"
     78 
     79 static bool dumpFrameLoaderCallbacks = false;
     80 static bool dumpResourceLoadCallbacks = false;
     81 
     82 static QMap<unsigned long, QString> dumpAssignedUrls;
     83 
     84 void QWEBKIT_EXPORT qt_dump_frame_loader(bool b)
     85 {
     86     dumpFrameLoaderCallbacks = b;
     87 }
     88 
     89 void QWEBKIT_EXPORT qt_dump_resource_load_callbacks(bool b)
     90 {
     91     dumpResourceLoadCallbacks = b;
     92 }
     93 
     94 // Compare with WebKitTools/DumpRenderTree/mac/FrameLoadDelegate.mm
     95 static QString drtDescriptionSuitableForTestResult(WebCore::Frame* _frame)
     96 {
     97     QWebFrame* frame = QWebFramePrivate::kit(_frame);
     98     QString name = frame->frameName();
     99 
    100     bool isMainFrame = frame == frame->page()->mainFrame();
    101     if (isMainFrame) {
    102         if (!name.isEmpty())
    103             return QString::fromLatin1("main frame \"%1\"").arg(name);
    104         return QLatin1String("main frame");
    105     } else {
    106         if (!name.isEmpty())
    107             return QString::fromLatin1("frame \"%1\"").arg(name);
    108         return QLatin1String("frame (anonymous)");
    109     }
    110 }
    111 
    112 static QString drtDescriptionSuitableForTestResult(const WebCore::KURL& _url)
    113 {
    114     QUrl url = _url;
    115     return url.toString();
    116 }
    117 
    118 static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceError& error)
    119 {
    120     QString failingURL = error.failingURL();
    121     return QString::fromLatin1("<NSError domain NSURLErrorDomain, code %1, failing URL \"%2\">").arg(error.errorCode()).arg(failingURL);
    122 }
    123 
    124 static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceRequest& request)
    125 {
    126     QString url = request.url().string();
    127     return QString::fromLatin1("<NSURLRequest %1>").arg(url);
    128 }
    129 
    130 static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceResponse& response)
    131 {
    132     QString text = response.httpStatusText();
    133     if (text.isEmpty())
    134         return QLatin1String("(null)");
    135 
    136     return text;
    137 }
    138 
    139 
    140 namespace WebCore
    141 {
    142 
    143 FrameLoaderClientQt::FrameLoaderClientQt()
    144     : m_frame(0)
    145     , m_webFrame(0)
    146     , m_firstData(false)
    147     , m_pluginView(0)
    148     , m_hasSentResponseToPlugin(false)
    149     , m_loadError (ResourceError())
    150 {
    151 }
    152 
    153 
    154 FrameLoaderClientQt::~FrameLoaderClientQt()
    155 {
    156 }
    157 
    158 void FrameLoaderClientQt::setFrame(QWebFrame* webFrame, Frame* frame)
    159 {
    160     m_webFrame = webFrame;
    161     m_frame = frame;
    162     if (!m_webFrame || !m_webFrame->page()) {
    163         qWarning("FrameLoaderClientQt::setFrame frame without Page!");
    164         return;
    165     }
    166 
    167     connect(this, SIGNAL(loadStarted()),
    168             m_webFrame->page(), SIGNAL(loadStarted()));
    169     connect(this, SIGNAL(loadStarted()),
    170             m_webFrame, SIGNAL(loadStarted()));
    171     connect(this, SIGNAL(loadProgress(int)),
    172             m_webFrame->page(), SIGNAL(loadProgress(int)));
    173     connect(this, SIGNAL(loadFinished(bool)),
    174             m_webFrame->page(), SIGNAL(loadFinished(bool)));
    175     connect(this, SIGNAL(loadFinished(bool)),
    176             m_webFrame, SIGNAL(loadFinished(bool)));
    177     connect(this, SIGNAL(titleChanged(QString)),
    178             m_webFrame, SIGNAL(titleChanged(QString)));
    179 }
    180 
    181 QWebFrame* FrameLoaderClientQt::webFrame() const
    182 {
    183     return m_webFrame;
    184 }
    185 
    186 void FrameLoaderClientQt::callPolicyFunction(FramePolicyFunction function, PolicyAction action)
    187 {
    188     (m_frame->loader()->policyChecker()->*function)(action);
    189 }
    190 
    191 bool FrameLoaderClientQt::hasWebView() const
    192 {
    193     //notImplemented();
    194     return true;
    195 }
    196 
    197 void FrameLoaderClientQt::savePlatformDataToCachedFrame(CachedFrame*)
    198 {
    199     notImplemented();
    200 }
    201 
    202 void FrameLoaderClientQt::transitionToCommittedFromCachedFrame(CachedFrame*)
    203 {
    204 }
    205 
    206 void FrameLoaderClientQt::transitionToCommittedForNewPage()
    207 {
    208     ASSERT(m_frame);
    209     ASSERT(m_webFrame);
    210 
    211     QBrush brush = m_webFrame->page()->palette().brush(QPalette::Base);
    212     QColor backgroundColor = brush.style() == Qt::SolidPattern ? brush.color() : QColor();
    213 
    214     QWebPage* page = m_webFrame->page();
    215     const QSize preferredLayoutSize = page->preferredContentsSize();
    216 
    217     m_frame->createView(m_webFrame->page()->viewportSize(),
    218                         backgroundColor, !backgroundColor.alpha(),
    219                         preferredLayoutSize.isValid() ? IntSize(preferredLayoutSize) : IntSize(),
    220                         preferredLayoutSize.isValid(),
    221                         (ScrollbarMode)m_webFrame->scrollBarPolicy(Qt::Horizontal),
    222                         (ScrollbarMode)m_webFrame->scrollBarPolicy(Qt::Vertical));
    223 }
    224 
    225 
    226 void FrameLoaderClientQt::makeRepresentation(DocumentLoader*)
    227 {
    228     // don't need this for now I think.
    229 }
    230 
    231 
    232 void FrameLoaderClientQt::forceLayout()
    233 {
    234     FrameView* view = m_frame->view();
    235     if (view)
    236         view->forceLayout(true);
    237 }
    238 
    239 
    240 void FrameLoaderClientQt::forceLayoutForNonHTML()
    241 {
    242 }
    243 
    244 
    245 void FrameLoaderClientQt::setCopiesOnScroll()
    246 {
    247     // apparently mac specific
    248 }
    249 
    250 
    251 void FrameLoaderClientQt::detachedFromParent2()
    252 {
    253 }
    254 
    255 
    256 void FrameLoaderClientQt::detachedFromParent3()
    257 {
    258 }
    259 
    260 void FrameLoaderClientQt::dispatchDidHandleOnloadEvents()
    261 {
    262     // don't need this one
    263     if (dumpFrameLoaderCallbacks)
    264         printf("%s - didHandleOnloadEventsForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    265 
    266 }
    267 
    268 
    269 void FrameLoaderClientQt::dispatchDidReceiveServerRedirectForProvisionalLoad()
    270 {
    271     if (dumpFrameLoaderCallbacks)
    272         printf("%s - didReceiveServerRedirectForProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    273 
    274     notImplemented();
    275 }
    276 
    277 
    278 void FrameLoaderClientQt::dispatchDidCancelClientRedirect()
    279 {
    280     if (dumpFrameLoaderCallbacks)
    281         printf("%s - didCancelClientRedirectForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    282 
    283     notImplemented();
    284 }
    285 
    286 
    287 void FrameLoaderClientQt::dispatchWillPerformClientRedirect(const KURL& url, double, double)
    288 {
    289     if (dumpFrameLoaderCallbacks)
    290         printf("%s - willPerformClientRedirectToURL: %s \n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(drtDescriptionSuitableForTestResult(url)));
    291 
    292     notImplemented();
    293 }
    294 
    295 
    296 void FrameLoaderClientQt::dispatchDidChangeLocationWithinPage()
    297 {
    298     if (dumpFrameLoaderCallbacks)
    299         printf("%s - didChangeLocationWithinPageForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    300 
    301     if (!m_webFrame)
    302         return;
    303 
    304     emit m_webFrame->urlChanged(m_webFrame->url());
    305     m_webFrame->page()->d->updateNavigationActions();
    306 }
    307 
    308 void FrameLoaderClientQt::dispatchDidPushStateWithinPage()
    309 {
    310     if (dumpFrameLoaderCallbacks)
    311         printf("%s - dispatchDidPushStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    312 
    313     notImplemented();
    314 }
    315 
    316 void FrameLoaderClientQt::dispatchDidReplaceStateWithinPage()
    317 {
    318     if (dumpFrameLoaderCallbacks)
    319         printf("%s - dispatchDidReplaceStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    320 
    321     notImplemented();
    322 }
    323 
    324 void FrameLoaderClientQt::dispatchDidPopStateWithinPage()
    325 {
    326     if (dumpFrameLoaderCallbacks)
    327         printf("%s - dispatchDidPopStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    328 
    329     notImplemented();
    330 }
    331 
    332 void FrameLoaderClientQt::dispatchWillClose()
    333 {
    334 }
    335 
    336 
    337 void FrameLoaderClientQt::dispatchDidStartProvisionalLoad()
    338 {
    339     if (dumpFrameLoaderCallbacks)
    340         printf("%s - didStartProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    341 
    342     if (m_webFrame)
    343         emit m_webFrame->provisionalLoad();
    344 }
    345 
    346 
    347 void FrameLoaderClientQt::dispatchDidReceiveTitle(const String& title)
    348 {
    349     if (dumpFrameLoaderCallbacks)
    350         printf("%s - didReceiveTitle: %s\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(QString(title)));
    351 
    352     if (!m_webFrame)
    353         return;
    354 
    355     emit titleChanged(title);
    356 }
    357 
    358 
    359 void FrameLoaderClientQt::dispatchDidCommitLoad()
    360 {
    361     if (dumpFrameLoaderCallbacks)
    362         printf("%s - didCommitLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    363 
    364     if (m_frame->tree()->parent() || !m_webFrame)
    365         return;
    366 
    367     emit m_webFrame->urlChanged(m_webFrame->url());
    368     m_webFrame->page()->d->updateNavigationActions();
    369 
    370     // We should assume first the frame has no title. If it has, then the above dispatchDidReceiveTitle()
    371     // will be called very soon with the correct title.
    372     // This properly resets the title when we navigate to a URI without a title.
    373     emit titleChanged(String());
    374 }
    375 
    376 
    377 void FrameLoaderClientQt::dispatchDidFinishDocumentLoad()
    378 {
    379     if (dumpFrameLoaderCallbacks)
    380         printf("%s - didFinishDocumentLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    381 
    382     if (QWebPagePrivate::drtRun) {
    383         int unloadEventCount = m_frame->domWindow()->pendingUnloadEventListeners();
    384         if (unloadEventCount)
    385             printf("%s - has %u onunload handler(s)\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), unloadEventCount);
    386     }
    387 
    388     if (m_frame->tree()->parent() || !m_webFrame)
    389         return;
    390 
    391     m_webFrame->page()->d->updateNavigationActions();
    392 }
    393 
    394 
    395 void FrameLoaderClientQt::dispatchDidFinishLoad()
    396 {
    397     if (dumpFrameLoaderCallbacks)
    398         printf("%s - didFinishLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    399 
    400     // Clears the previous error.
    401     m_loadError = ResourceError();
    402 
    403     if (!m_webFrame)
    404         return;
    405     m_webFrame->page()->d->updateNavigationActions();
    406 }
    407 
    408 
    409 void FrameLoaderClientQt::dispatchDidFirstLayout()
    410 {
    411     if (m_webFrame)
    412         emit m_webFrame->initialLayoutCompleted();
    413 }
    414 
    415 void FrameLoaderClientQt::dispatchDidFirstVisuallyNonEmptyLayout()
    416 {
    417     notImplemented();
    418 }
    419 
    420 void FrameLoaderClientQt::dispatchShow()
    421 {
    422     notImplemented();
    423 }
    424 
    425 
    426 void FrameLoaderClientQt::cancelPolicyCheck()
    427 {
    428 //    qDebug() << "FrameLoaderClientQt::cancelPolicyCheck";
    429 }
    430 
    431 
    432 void FrameLoaderClientQt::dispatchWillSubmitForm(FramePolicyFunction function,
    433                                                  PassRefPtr<FormState>)
    434 {
    435     notImplemented();
    436     // FIXME: This is surely too simple
    437     callPolicyFunction(function, PolicyUse);
    438 }
    439 
    440 
    441 void FrameLoaderClientQt::dispatchDidLoadMainResource(DocumentLoader*)
    442 {
    443 }
    444 
    445 
    446 void FrameLoaderClientQt::revertToProvisionalState(DocumentLoader*)
    447 {
    448     notImplemented();
    449 }
    450 
    451 
    452 void FrameLoaderClientQt::postProgressStartedNotification()
    453 {
    454     if (m_webFrame && m_frame->page()) {
    455         // A new load starts, so lets clear the previous error.
    456         m_loadError = ResourceError();
    457         emit loadStarted();
    458         postProgressEstimateChangedNotification();
    459     }
    460     if (m_frame->tree()->parent() || !m_webFrame)
    461         return;
    462     m_webFrame->page()->d->updateNavigationActions();
    463 }
    464 
    465 void FrameLoaderClientQt::postProgressEstimateChangedNotification()
    466 {
    467     if (m_webFrame && m_frame->page())
    468         emit loadProgress(qRound(m_frame->page()->progress()->estimatedProgress() * 100));
    469 }
    470 
    471 void FrameLoaderClientQt::postProgressFinishedNotification()
    472 {
    473     // send a mousemove event to
    474     // (1) update the cursor to change according to whatever is underneath the mouse cursor right now
    475     // (2) display the tool tip if the mouse hovers a node which has a tool tip
    476     if (m_frame && m_frame->eventHandler() && m_webFrame->page()) {
    477         QWidget* view = m_webFrame->page()->view();
    478         if (view && view->hasFocus()) {
    479             QPoint localPos = view->mapFromGlobal(QCursor::pos());
    480             if (view->rect().contains(localPos)) {
    481                 QMouseEvent event(QEvent::MouseMove, localPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
    482                 m_frame->eventHandler()->mouseMoved(PlatformMouseEvent(&event, 0));
    483             }
    484         }
    485     }
    486 
    487     if (m_webFrame && m_frame->page())
    488         emit loadFinished(m_loadError.isNull());
    489 }
    490 
    491 void FrameLoaderClientQt::setMainFrameDocumentReady(bool)
    492 {
    493     // this is only interesting once we provide an external API for the DOM
    494 }
    495 
    496 
    497 void FrameLoaderClientQt::willChangeTitle(DocumentLoader*)
    498 {
    499     // no need for, dispatchDidReceiveTitle is the right callback
    500 }
    501 
    502 
    503 void FrameLoaderClientQt::didChangeTitle(DocumentLoader *)
    504 {
    505     // no need for, dispatchDidReceiveTitle is the right callback
    506 }
    507 
    508 
    509 void FrameLoaderClientQt::finishedLoading(DocumentLoader* loader)
    510 {
    511     if (!m_pluginView) {
    512         if(m_firstData) {
    513             FrameLoader *fl = loader->frameLoader();
    514             fl->setEncoding(m_response.textEncodingName(), false);
    515             m_firstData = false;
    516         }
    517     }
    518     else {
    519         m_pluginView->didFinishLoading();
    520         m_pluginView = 0;
    521         m_hasSentResponseToPlugin = false;
    522     }
    523 }
    524 
    525 
    526 bool FrameLoaderClientQt::canShowMIMEType(const String& MIMEType) const
    527 {
    528     if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType))
    529         return true;
    530 
    531     if (MIMETypeRegistry::isSupportedNonImageMIMEType(MIMEType))
    532         return true;
    533 
    534     if (m_frame && m_frame->settings()  && m_frame->settings()->arePluginsEnabled()
    535         && PluginDatabase::installedPlugins()->isMIMETypeRegistered(MIMEType))
    536         return true;
    537 
    538     return false;
    539 }
    540 
    541 bool FrameLoaderClientQt::representationExistsForURLScheme(const String&) const
    542 {
    543     return false;
    544 }
    545 
    546 
    547 String FrameLoaderClientQt::generatedMIMETypeForURLScheme(const String&) const
    548 {
    549     notImplemented();
    550     return String();
    551 }
    552 
    553 
    554 void FrameLoaderClientQt::frameLoadCompleted()
    555 {
    556     // Note: Can be called multiple times.
    557 }
    558 
    559 
    560 void FrameLoaderClientQt::restoreViewState()
    561 {
    562     if (!m_webFrame)
    563         return;
    564     emit m_webFrame->page()->restoreFrameStateRequested(m_webFrame);
    565 }
    566 
    567 
    568 void FrameLoaderClientQt::provisionalLoadStarted()
    569 {
    570     // don't need to do anything here
    571 }
    572 
    573 
    574 void FrameLoaderClientQt::didFinishLoad()
    575 {
    576 //     notImplemented();
    577 }
    578 
    579 
    580 void FrameLoaderClientQt::prepareForDataSourceReplacement()
    581 {
    582 }
    583 
    584 void FrameLoaderClientQt::setTitle(const String&, const KURL&)
    585 {
    586     // no need for, dispatchDidReceiveTitle is the right callback
    587 }
    588 
    589 
    590 String FrameLoaderClientQt::userAgent(const KURL& url)
    591 {
    592     if (m_webFrame) {
    593         return m_webFrame->page()->userAgentForUrl(url);
    594     }
    595     return String();
    596 }
    597 
    598 void FrameLoaderClientQt::dispatchDidReceiveIcon()
    599 {
    600     if (m_webFrame) {
    601         emit m_webFrame->iconChanged();
    602     }
    603 }
    604 
    605 void FrameLoaderClientQt::frameLoaderDestroyed()
    606 {
    607     delete m_webFrame;
    608     m_frame = 0;
    609     m_webFrame = 0;
    610 
    611     delete this;
    612 }
    613 
    614 bool FrameLoaderClientQt::canHandleRequest(const WebCore::ResourceRequest&) const
    615 {
    616     return true;
    617 }
    618 
    619 void FrameLoaderClientQt::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
    620 {
    621     if (world != mainThreadNormalWorld())
    622         return;
    623 
    624     if (m_webFrame)
    625         emit m_webFrame->javaScriptWindowObjectCleared();
    626 }
    627 
    628 void FrameLoaderClientQt::documentElementAvailable()
    629 {
    630     return;
    631 }
    632 
    633 void FrameLoaderClientQt::didPerformFirstNavigation() const
    634 {
    635     if (m_frame->tree()->parent() || !m_webFrame)
    636         return;
    637     m_webFrame->page()->d->updateNavigationActions();
    638 }
    639 
    640 void FrameLoaderClientQt::registerForIconNotification(bool)
    641 {
    642     notImplemented();
    643 }
    644 
    645 void FrameLoaderClientQt::updateGlobalHistory()
    646 {
    647     QWebHistoryInterface *history = QWebHistoryInterface::defaultInterface();
    648     if (history)
    649         history->addHistoryEntry(m_frame->loader()->documentLoader()->urlForHistory().prettyURL());
    650 }
    651 
    652 void FrameLoaderClientQt::updateGlobalHistoryRedirectLinks()
    653 {
    654 }
    655 
    656 bool FrameLoaderClientQt::shouldGoToHistoryItem(WebCore::HistoryItem *) const
    657 {
    658     return true;
    659 }
    660 
    661 void FrameLoaderClientQt::dispatchDidAddBackForwardItem(WebCore::HistoryItem*) const
    662 {
    663 }
    664 
    665 void FrameLoaderClientQt::dispatchDidRemoveBackForwardItem(WebCore::HistoryItem*) const
    666 {
    667 }
    668 
    669 void FrameLoaderClientQt::dispatchDidChangeBackForwardIndex() const
    670 {
    671 }
    672 
    673 void FrameLoaderClientQt::didDisplayInsecureContent()
    674 {
    675     if (dumpFrameLoaderCallbacks)
    676         printf("didDisplayInsecureContent\n");
    677 
    678     notImplemented();
    679 }
    680 
    681 void FrameLoaderClientQt::didRunInsecureContent(WebCore::SecurityOrigin*)
    682 {
    683     if (dumpFrameLoaderCallbacks)
    684         printf("didRunInsecureContent\n");
    685 
    686     notImplemented();
    687 }
    688 
    689 void FrameLoaderClientQt::saveViewStateToItem(WebCore::HistoryItem* item)
    690 {
    691     QWebHistoryItem historyItem(new QWebHistoryItemPrivate(item));
    692     emit m_webFrame->page()->saveFrameStateRequested(m_webFrame, &historyItem);
    693 }
    694 
    695 bool FrameLoaderClientQt::canCachePage() const
    696 {
    697     return true;
    698 }
    699 
    700 void FrameLoaderClientQt::setMainDocumentError(WebCore::DocumentLoader* loader, const WebCore::ResourceError& error)
    701 {
    702     if (!m_pluginView) {
    703         if (m_firstData) {
    704             loader->frameLoader()->setEncoding(m_response.textEncodingName(), false);
    705             m_firstData = false;
    706         }
    707     } else {
    708         m_pluginView->didFail(error);
    709         m_pluginView = 0;
    710         m_hasSentResponseToPlugin = false;
    711     }
    712 }
    713 
    714 void FrameLoaderClientQt::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length)
    715 {
    716     if (!m_pluginView) {
    717         if (!m_frame)
    718             return;
    719         FrameLoader *fl = loader->frameLoader();
    720         if (m_firstData) {
    721             fl->setEncoding(m_response.textEncodingName(), false);
    722             m_firstData = false;
    723         }
    724         fl->addData(data, length);
    725     }
    726 
    727     // We re-check here as the plugin can have been created
    728     if (m_pluginView) {
    729         if (!m_hasSentResponseToPlugin) {
    730             m_pluginView->didReceiveResponse(loader->response());
    731             // didReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
    732             // setting up this stream can cause the main document load to be cancelled, setting m_pluginView
    733             // to null
    734             if (!m_pluginView)
    735                 return;
    736             m_hasSentResponseToPlugin = true;
    737         }
    738         m_pluginView->didReceiveData(data, length);
    739     }
    740 }
    741 
    742 WebCore::ResourceError FrameLoaderClientQt::cancelledError(const WebCore::ResourceRequest& request)
    743 {
    744     ResourceError error = ResourceError("QtNetwork", QNetworkReply::OperationCanceledError, request.url().prettyURL(),
    745             QCoreApplication::translate("QWebFrame", "Request cancelled", 0, QCoreApplication::UnicodeUTF8));
    746     error.setIsCancellation(true);
    747     return error;
    748 }
    749 
    750 // copied from WebKit/Misc/WebKitErrors[Private].h
    751 enum {
    752     WebKitErrorCannotShowMIMEType =                             100,
    753     WebKitErrorCannotShowURL =                                  101,
    754     WebKitErrorFrameLoadInterruptedByPolicyChange =             102,
    755     WebKitErrorCannotUseRestrictedPort = 103,
    756     WebKitErrorCannotFindPlugIn =                               200,
    757     WebKitErrorCannotLoadPlugIn =                               201,
    758     WebKitErrorJavaUnavailable =                                202,
    759 };
    760 
    761 WebCore::ResourceError FrameLoaderClientQt::blockedError(const WebCore::ResourceRequest& request)
    762 {
    763     return ResourceError("WebKit", WebKitErrorCannotUseRestrictedPort, request.url().prettyURL(),
    764             QCoreApplication::translate("QWebFrame", "Request blocked", 0, QCoreApplication::UnicodeUTF8));
    765 }
    766 
    767 
    768 WebCore::ResourceError FrameLoaderClientQt::cannotShowURLError(const WebCore::ResourceRequest& request)
    769 {
    770     return ResourceError("WebKit", WebKitErrorCannotShowURL, request.url().string(),
    771             QCoreApplication::translate("QWebFrame", "Cannot show URL", 0, QCoreApplication::UnicodeUTF8));
    772 }
    773 
    774 WebCore::ResourceError FrameLoaderClientQt::interruptForPolicyChangeError(const WebCore::ResourceRequest& request)
    775 {
    776     return ResourceError("WebKit", WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(),
    777             QCoreApplication::translate("QWebFrame", "Frame load interrupted by policy change", 0, QCoreApplication::UnicodeUTF8));
    778 }
    779 
    780 WebCore::ResourceError FrameLoaderClientQt::cannotShowMIMETypeError(const WebCore::ResourceResponse& response)
    781 {
    782     return ResourceError("WebKit", WebKitErrorCannotShowMIMEType, response.url().string(),
    783             QCoreApplication::translate("QWebFrame", "Cannot show mimetype", 0, QCoreApplication::UnicodeUTF8));
    784 }
    785 
    786 WebCore::ResourceError FrameLoaderClientQt::fileDoesNotExistError(const WebCore::ResourceResponse& response)
    787 {
    788     return ResourceError("QtNetwork", QNetworkReply::ContentNotFoundError, response.url().string(),
    789             QCoreApplication::translate("QWebFrame", "File does not exist", 0, QCoreApplication::UnicodeUTF8));
    790 }
    791 
    792 WebCore::ResourceError FrameLoaderClientQt::pluginWillHandleLoadError(const WebCore::ResourceResponse&)
    793 {
    794     notImplemented();
    795     return ResourceError();
    796 }
    797 
    798 bool FrameLoaderClientQt::shouldFallBack(const WebCore::ResourceError&)
    799 {
    800     notImplemented();
    801     return false;
    802 }
    803 
    804 WTF::PassRefPtr<WebCore::DocumentLoader> FrameLoaderClientQt::createDocumentLoader(const WebCore::ResourceRequest& request, const SubstituteData& substituteData)
    805 {
    806     RefPtr<DocumentLoader> loader = DocumentLoader::create(request, substituteData);
    807     if (substituteData.isValid())
    808         loader->setDeferMainResourceDataLoad(false);
    809     return loader.release();
    810 }
    811 
    812 void FrameLoaderClientQt::download(WebCore::ResourceHandle* handle, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
    813 {
    814     if (!m_webFrame)
    815         return;
    816 
    817     QNetworkReplyHandler* handler = handle->getInternal()->m_job;
    818     QNetworkReply* reply = handler->release();
    819     if (reply) {
    820         QWebPage *page = m_webFrame->page();
    821         if (page->forwardUnsupportedContent())
    822             emit m_webFrame->page()->unsupportedContent(reply);
    823         else
    824             reply->abort();
    825     }
    826 }
    827 
    828 void FrameLoaderClientQt::assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest& request)
    829 {
    830     if (dumpResourceLoadCallbacks)
    831         dumpAssignedUrls[identifier] = drtDescriptionSuitableForTestResult(request.url());
    832 }
    833 
    834 void FrameLoaderClientQt::dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest& newRequest, const WebCore::ResourceResponse& redirectResponse)
    835 {
    836     if (dumpResourceLoadCallbacks)
    837         printf("%s - willSendRequest %s redirectResponse %s\n",
    838                qPrintable(dumpAssignedUrls[identifier]),
    839                qPrintable(drtDescriptionSuitableForTestResult(newRequest)),
    840                qPrintable(drtDescriptionSuitableForTestResult(redirectResponse)));
    841 
    842     // seems like the Mac code doesn't do anything here by default neither
    843     //qDebug() << "FrameLoaderClientQt::dispatchWillSendRequest" << request.isNull() << request.url().string`();
    844 }
    845 
    846 bool
    847 FrameLoaderClientQt::shouldUseCredentialStorage(DocumentLoader*, unsigned long)
    848 {
    849     notImplemented();
    850     return false;
    851 }
    852 
    853 void FrameLoaderClientQt::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
    854 {
    855     notImplemented();
    856 }
    857 
    858 void FrameLoaderClientQt::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&)
    859 {
    860     notImplemented();
    861 }
    862 
    863 void FrameLoaderClientQt::dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceResponse& response)
    864 {
    865 
    866     m_response = response;
    867     m_firstData = true;
    868     //qDebug() << "    got response from" << response.url().string();
    869 }
    870 
    871 void FrameLoaderClientQt::dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long, int)
    872 {
    873 }
    874 
    875 void FrameLoaderClientQt::dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long)
    876 {
    877 }
    878 
    879 void FrameLoaderClientQt::dispatchDidFailLoading(WebCore::DocumentLoader* loader, unsigned long identifier, const WebCore::ResourceError& error)
    880 {
    881     if (dumpResourceLoadCallbacks)
    882         printf("%s - didFailLoadingWithError: %s\n", qPrintable(dumpAssignedUrls[identifier]), qPrintable(drtDescriptionSuitableForTestResult(error)));
    883 
    884     if (m_firstData) {
    885         FrameLoader *fl = loader->frameLoader();
    886         fl->setEncoding(m_response.textEncodingName(), false);
    887         m_firstData = false;
    888     }
    889 }
    890 
    891 bool FrameLoaderClientQt::dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int)
    892 {
    893     notImplemented();
    894     return false;
    895 }
    896 
    897 void FrameLoaderClientQt::dispatchDidLoadResourceByXMLHttpRequest(unsigned long, const WebCore::ScriptString&)
    898 {
    899     notImplemented();
    900 }
    901 
    902 void FrameLoaderClientQt::callErrorPageExtension(const WebCore::ResourceError& error)
    903 {
    904     QWebPage* page = m_webFrame->page();
    905     if (page->supportsExtension(QWebPage::ErrorPageExtension)) {
    906         QWebPage::ErrorPageExtensionOption option;
    907 
    908         if (error.domain() == "QtNetwork")
    909             option.domain = QWebPage::QtNetwork;
    910         else if (error.domain() == "HTTP")
    911             option.domain = QWebPage::Http;
    912         else if (error.domain() == "WebKit")
    913             option.domain = QWebPage::WebKit;
    914         else
    915             return;
    916 
    917         option.url = QUrl(error.failingURL());
    918         option.frame = m_webFrame;
    919         option.error = error.errorCode();
    920         option.errorString = error.localizedDescription();
    921 
    922         QWebPage::ErrorPageExtensionReturn output;
    923         if (!page->extension(QWebPage::ErrorPageExtension, &option, &output))
    924             return;
    925 
    926         KURL baseUrl(output.baseUrl);
    927         KURL failingUrl(option.url);
    928 
    929         WebCore::ResourceRequest request(baseUrl);
    930         WTF::RefPtr<WebCore::SharedBuffer> buffer = WebCore::SharedBuffer::create(output.content.constData(), output.content.length());
    931         WebCore::SubstituteData substituteData(buffer, output.contentType, output.encoding, failingUrl);
    932         m_frame->loader()->load(request, substituteData, false);
    933     }
    934 }
    935 
    936 void FrameLoaderClientQt::dispatchDidFailProvisionalLoad(const WebCore::ResourceError& error)
    937 {
    938     if (dumpFrameLoaderCallbacks)
    939         printf("%s - didFailProvisionalLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    940 
    941     m_loadError = error;
    942     if (!error.isNull() && !error.isCancellation())
    943         callErrorPageExtension(error);
    944 }
    945 
    946 void FrameLoaderClientQt::dispatchDidFailLoad(const WebCore::ResourceError& error)
    947 {
    948     if (dumpFrameLoaderCallbacks)
    949         printf("%s - didFailLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));
    950 
    951     m_loadError = error;
    952     if (!error.isNull() && !error.isCancellation())
    953         callErrorPageExtension(error);
    954 }
    955 
    956 WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage()
    957 {
    958     if (!m_webFrame)
    959         return 0;
    960     QWebPage *newPage = m_webFrame->page()->createWindow(QWebPage::WebBrowserWindow);
    961     if (!newPage)
    962         return 0;
    963     return newPage->mainFrame()->d->frame;
    964 }
    965 
    966 void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String& MIMEType, const WebCore::ResourceRequest&)
    967 {
    968     // we need to call directly here
    969     if (canShowMIMEType(MIMEType))
    970         callPolicyFunction(function, PolicyUse);
    971     else
    972         callPolicyFunction(function, PolicyDownload);
    973 }
    974 
    975 void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>, const WebCore::String&)
    976 {
    977     Q_ASSERT(m_webFrame);
    978     QNetworkRequest r(request.toNetworkRequest(m_webFrame));
    979     QWebPage* page = m_webFrame->page();
    980 
    981     if (!page->d->acceptNavigationRequest(0, r, QWebPage::NavigationType(action.type()))) {
    982         if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted)
    983             m_frame->loader()->resetMultipleFormSubmissionProtection();
    984 
    985         if (action.type() == NavigationTypeLinkClicked && r.url().hasFragment()) {
    986             ResourceRequest emptyRequest;
    987             m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest);
    988         }
    989 
    990         callPolicyFunction(function, PolicyIgnore);
    991         return;
    992     }
    993     callPolicyFunction(function, PolicyUse);
    994 }
    995 
    996 void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>)
    997 {
    998     Q_ASSERT(m_webFrame);
    999     QNetworkRequest r(request.toNetworkRequest(m_webFrame));
   1000     QWebPage*page = m_webFrame->page();
   1001 
   1002     if (!page->d->acceptNavigationRequest(m_webFrame, r, QWebPage::NavigationType(action.type()))) {
   1003         if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted)
   1004             m_frame->loader()->resetMultipleFormSubmissionProtection();
   1005 
   1006         if (action.type() == NavigationTypeLinkClicked && r.url().hasFragment()) {
   1007             ResourceRequest emptyRequest;
   1008             m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest);
   1009         }
   1010 
   1011         callPolicyFunction(function, PolicyIgnore);
   1012         return;
   1013     }
   1014     callPolicyFunction(function, PolicyUse);
   1015 }
   1016 
   1017 void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::ResourceError&)
   1018 {
   1019     notImplemented();
   1020 }
   1021 
   1022 void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request)
   1023 {
   1024     if (!m_webFrame)
   1025         return;
   1026 
   1027     emit m_webFrame->page()->downloadRequested(request.toNetworkRequest(m_webFrame));
   1028 }
   1029 
   1030 PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
   1031                                         const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight)
   1032 {
   1033     if (!m_webFrame)
   1034         return 0;
   1035 
   1036     QWebFrameData frameData(m_frame->page(), m_frame, ownerElement, name);
   1037 
   1038     if (url.isEmpty())
   1039         frameData.url = blankURL();
   1040     else
   1041         frameData.url = url;
   1042 
   1043     frameData.referrer = referrer;
   1044     frameData.allowsScrolling = allowsScrolling;
   1045     frameData.marginWidth = marginWidth;
   1046     frameData.marginHeight = marginHeight;
   1047 
   1048     QPointer<QWebFrame> webFrame = new QWebFrame(m_webFrame, &frameData);
   1049     // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
   1050     if (!webFrame->d->frame->page()) {
   1051         frameData.frame.release();
   1052         ASSERT(webFrame.isNull());
   1053         return 0;
   1054     }
   1055 
   1056     emit m_webFrame->page()->frameCreated(webFrame);
   1057 
   1058     // ### set override encoding if we have one
   1059 
   1060     frameData.frame->loader()->loadURLIntoChildFrame(frameData.url, frameData.referrer, frameData.frame.get());
   1061 
   1062     // The frame's onload handler may have removed it from the document.
   1063     if (!frameData.frame->tree()->parent())
   1064         return 0;
   1065 
   1066     return frameData.frame.release();
   1067 }
   1068 
   1069 ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& _mimeType)
   1070 {
   1071 //    qDebug()<<" ++++++++++++++++ url is "<<url.prettyURL()<<", mime = "<<_mimeType;
   1072     if (_mimeType == "application/x-qt-plugin" || _mimeType == "application/x-qt-styled-widget")
   1073         return ObjectContentOtherPlugin;
   1074 
   1075     if (url.isEmpty() && !_mimeType.length())
   1076         return ObjectContentNone;
   1077 
   1078     String mimeType = _mimeType;
   1079     if (!mimeType.length()) {
   1080         QFileInfo fi(url.path());
   1081         mimeType = MIMETypeRegistry::getMIMETypeForExtension(fi.suffix());
   1082     }
   1083 
   1084     if (!mimeType.length())
   1085         return ObjectContentFrame;
   1086 
   1087     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
   1088         return ObjectContentImage;
   1089 
   1090     if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))
   1091         return ObjectContentNetscapePlugin;
   1092 
   1093     if (m_frame->page() && m_frame->page()->pluginData() && m_frame->page()->pluginData()->supportsMimeType(mimeType))
   1094         return ObjectContentOtherPlugin;
   1095 
   1096     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
   1097         return ObjectContentFrame;
   1098 
   1099     if (url.protocol() == "about")
   1100         return ObjectContentFrame;
   1101 
   1102     return ObjectContentNone;
   1103 }
   1104 
   1105 static const CSSPropertyID qstyleSheetProperties[] = {
   1106     CSSPropertyColor,
   1107     CSSPropertyFontFamily,
   1108     CSSPropertyFontSize,
   1109     CSSPropertyFontStyle,
   1110     CSSPropertyFontWeight
   1111 };
   1112 
   1113 const unsigned numqStyleSheetProperties = sizeof(qstyleSheetProperties) / sizeof(qstyleSheetProperties[0]);
   1114 
   1115 class QtPluginWidget: public Widget
   1116 {
   1117 public:
   1118     QtPluginWidget(QWidget* w = 0): Widget(w) {}
   1119     ~QtPluginWidget()
   1120     {
   1121         if (platformWidget())
   1122             platformWidget()->deleteLater();
   1123     }
   1124     virtual void invalidateRect(const IntRect& r)
   1125     {
   1126         if (platformWidget())
   1127             platformWidget()->update(r);
   1128     }
   1129     virtual void frameRectsChanged()
   1130     {
   1131         if (!platformWidget())
   1132             return;
   1133 
   1134         IntRect windowRect = convertToContainingWindow(IntRect(0, 0, frameRect().width(), frameRect().height()));
   1135         platformWidget()->setGeometry(windowRect);
   1136 
   1137         ScrollView* parentScrollView = parent();
   1138         if (!parentScrollView)
   1139             return;
   1140 
   1141         ASSERT(parentScrollView->isFrameView());
   1142         IntRect clipRect(static_cast<FrameView*>(parentScrollView)->windowClipRect());
   1143         clipRect.move(-windowRect.x(), -windowRect.y());
   1144         clipRect.intersect(platformWidget()->rect());
   1145 
   1146         QRegion clipRegion = QRegion(clipRect);
   1147         platformWidget()->setMask(clipRegion);
   1148 
   1149         handleVisibility();
   1150     }
   1151 
   1152     virtual void show()
   1153     {
   1154         Widget::show();
   1155         handleVisibility();
   1156     }
   1157 
   1158 private:
   1159     void handleVisibility()
   1160     {
   1161         if (!isVisible())
   1162             return;
   1163 
   1164         // if setMask is set with an empty QRegion, no clipping will
   1165         // be performed, so in that case we hide the platformWidget
   1166         QRegion mask = platformWidget()->mask();
   1167         platformWidget()->setVisible(!mask.isEmpty());
   1168     }
   1169 };
   1170 
   1171 #if QT_VERSION >= 0x040600
   1172 class QtPluginGraphicsWidget: public Widget
   1173 {
   1174 public:
   1175     static RefPtr<QtPluginGraphicsWidget> create(QGraphicsWidget* w = 0)
   1176     {
   1177         return adoptRef(new QtPluginGraphicsWidget(w));
   1178     }
   1179 
   1180     ~QtPluginGraphicsWidget()
   1181     {
   1182         if (graphicsWidget)
   1183             graphicsWidget->deleteLater();
   1184     }
   1185     virtual void invalidateRect(const IntRect& r)
   1186     {
   1187         QGraphicsScene* scene = graphicsWidget ? graphicsWidget->scene() : 0;
   1188         if (scene)
   1189             scene->update(QRect(r));
   1190     }
   1191     virtual void frameRectsChanged()
   1192     {
   1193         if (!graphicsWidget)
   1194             return;
   1195 
   1196         IntRect windowRect = convertToContainingWindow(IntRect(0, 0, frameRect().width(), frameRect().height()));
   1197         graphicsWidget->setGeometry(QRect(windowRect));
   1198 
   1199         // FIXME: clipping of graphics widgets
   1200     }
   1201     virtual void show()
   1202     {
   1203         if (graphicsWidget)
   1204             graphicsWidget->show();
   1205     }
   1206     virtual void hide()
   1207     {
   1208         if (graphicsWidget)
   1209             graphicsWidget->hide();
   1210     }
   1211 private:
   1212     QtPluginGraphicsWidget(QGraphicsWidget* w = 0): Widget(0), graphicsWidget(w) {}
   1213 
   1214     QGraphicsWidget* graphicsWidget;
   1215 };
   1216 #endif
   1217 
   1218 PassRefPtr<Widget> FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames,
   1219                                           const Vector<String>& paramValues, const String& mimeType, bool loadManually)
   1220 {
   1221 //     qDebug()<<"------ Creating plugin in FrameLoaderClientQt::createPlugin for "<<url.prettyURL() << mimeType;
   1222 //     qDebug()<<"------\t url = "<<url.prettyURL();
   1223 
   1224     if (!m_webFrame)
   1225         return 0;
   1226 
   1227     QStringList params;
   1228     QStringList values;
   1229     QString classid(element->getAttribute("classid"));
   1230 
   1231     for (unsigned i = 0; i < paramNames.size(); ++i) {
   1232         params.append(paramNames[i]);
   1233         if (paramNames[i] == "classid")
   1234             classid = paramValues[i];
   1235     }
   1236     for (unsigned i = 0; i < paramValues.size(); ++i)
   1237         values.append(paramValues[i]);
   1238 
   1239     QString urlStr(url.string());
   1240     QUrl qurl = urlStr;
   1241 
   1242     QObject* object = 0;
   1243 
   1244     if (mimeType == "application/x-qt-plugin" || mimeType == "application/x-qt-styled-widget") {
   1245         object = m_webFrame->page()->createPlugin(classid, qurl, params, values);
   1246 #ifndef QT_NO_STYLE_STYLESHEET
   1247         QWidget* widget = qobject_cast<QWidget*>(object);
   1248         if (widget && mimeType == "application/x-qt-styled-widget") {
   1249 
   1250             QString styleSheet = element->getAttribute("style");
   1251             if (!styleSheet.isEmpty())
   1252                 styleSheet += QLatin1Char(';');
   1253 
   1254             for (unsigned i = 0; i < numqStyleSheetProperties; ++i) {
   1255                 CSSPropertyID property = qstyleSheetProperties[i];
   1256 
   1257                 styleSheet += QString::fromLatin1(::getPropertyName(property));
   1258                 styleSheet += QLatin1Char(':');
   1259                 styleSheet += computedStyle(element)->getPropertyValue(property);
   1260                 styleSheet += QLatin1Char(';');
   1261             }
   1262 
   1263             widget->setStyleSheet(styleSheet);
   1264         }
   1265 #endif // QT_NO_STYLE_STYLESHEET
   1266     }
   1267 
   1268         if (!object) {
   1269             QWebPluginFactory* factory = m_webFrame->page()->pluginFactory();
   1270             if (factory)
   1271                 object = factory->create(mimeType, qurl, params, values);
   1272         }
   1273 
   1274         if (object) {
   1275             QWidget* widget = qobject_cast<QWidget*>(object);
   1276             if (widget) {
   1277                 QWidget* parentWidget = 0;
   1278                 if (m_webFrame->page()->d->client)
   1279                     parentWidget = qobject_cast<QWidget*>(m_webFrame->page()->d->client->pluginParent());
   1280                 if (parentWidget) // don't reparent to nothing (i.e. keep whatever parent QWebPage::createPlugin() chose.
   1281                     widget->setParent(parentWidget);
   1282                 widget->hide();
   1283                 RefPtr<QtPluginWidget> w = adoptRef(new QtPluginWidget());
   1284                 w->setPlatformWidget(widget);
   1285                 // Make sure it's invisible until properly placed into the layout
   1286                 w->setFrameRect(IntRect(0, 0, 0, 0));
   1287                 return w;
   1288             }
   1289 #if QT_VERSION >= 0x040600
   1290             QGraphicsWidget* graphicsWidget = qobject_cast<QGraphicsWidget*>(object);
   1291             if (graphicsWidget) {
   1292                 QGraphicsObject* parentWidget = 0;
   1293                 if (m_webFrame->page()->d->client)
   1294                     parentWidget = qobject_cast<QGraphicsObject*>(m_webFrame->page()->d->client->pluginParent());
   1295                 graphicsWidget->hide();
   1296                 if (parentWidget) // don't reparent to nothing (i.e. keep whatever parent QWebPage::createPlugin() chose.
   1297                     graphicsWidget->setParentItem(parentWidget);
   1298                 RefPtr<QtPluginGraphicsWidget> w = QtPluginGraphicsWidget::create(graphicsWidget);
   1299                 // Make sure it's invisible until properly placed into the layout
   1300                 w->setFrameRect(IntRect(0, 0, 0, 0));
   1301                 return w;
   1302             }
   1303 #endif
   1304             // FIXME: make things work for widgetless plugins as well
   1305             delete object;
   1306     } else { // NPAPI Plugins
   1307         Vector<String> params = paramNames;
   1308         Vector<String> values = paramValues;
   1309         if (mimeType == "application/x-shockwave-flash") {
   1310             QWebPageClient* client = m_webFrame->page()->d->client;
   1311             if (!client || !qobject_cast<QWidget*>(client->pluginParent())) {
   1312                 // inject wmode=opaque when there is no client or the client is not a QWebView
   1313                 size_t wmodeIndex = params.find("wmode");
   1314                 if (wmodeIndex == -1) {
   1315                     params.append("wmode");
   1316                     values.append("opaque");
   1317                 } else
   1318                     values[wmodeIndex] = "opaque";
   1319             }
   1320         }
   1321 
   1322         RefPtr<PluginView> pluginView = PluginView::create(m_frame, pluginSize, element, url,
   1323             params, values, mimeType, loadManually);
   1324         return pluginView;
   1325     }
   1326 
   1327     return 0;
   1328 }
   1329 
   1330 void FrameLoaderClientQt::redirectDataToPlugin(Widget* pluginWidget)
   1331 {
   1332     ASSERT(!m_pluginView);
   1333     m_pluginView = static_cast<PluginView*>(pluginWidget);
   1334     m_hasSentResponseToPlugin = false;
   1335 }
   1336 
   1337 PassRefPtr<Widget> FrameLoaderClientQt::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL&,
   1338                                                     const Vector<String>&, const Vector<String>&)
   1339 {
   1340     notImplemented();
   1341     return 0;
   1342 }
   1343 
   1344 String FrameLoaderClientQt::overrideMediaType() const
   1345 {
   1346     return String();
   1347 }
   1348 
   1349 QString FrameLoaderClientQt::chooseFile(const QString& oldFile)
   1350 {
   1351     return webFrame()->page()->chooseFile(webFrame(), oldFile);
   1352 }
   1353 
   1354 }
   1355 
   1356 #include "moc_FrameLoaderClientQt.cpp"
   1357