diff options
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 126 |
1 files changed, 101 insertions, 25 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index bfac6a5b2..6cbfe2867 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -46,9 +46,11 @@ #include "browser_accessibility_qt.h" #include "browser_context_adapter.h" +#include "browser_context_adapter_client.h" #include "browser_context_qt.h" #include "download_manager_delegate_qt.h" #include "media_capture_devices_dispatcher.h" +#include "pdfium_printing_wrapper_qt.h" #include "print_view_manager_qt.h" #include "qwebenginecallback_p.h" #include "render_view_observer_host_qt.h" @@ -90,6 +92,9 @@ #include <QtGui/qaccessible.h> #include <QtGui/qdrag.h> #include <QtGui/qpixmap.h> +#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) +#include <QtPrintSupport/qprinter.h> +#endif // QT_NO_PRINTER #include <QtWebChannel/QWebChannel> namespace QtWebEngineCore { @@ -188,6 +193,17 @@ static void callbackOnPrintingFinished(WebContentsAdapterClient *adapterClient, } } +#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) +static void callbackOnPrintingOnPrinterFinished(WebContentsAdapterClient *adapterClient, int requestId, QPrinter *printer, const std::vector<char> &result) +{ + if (requestId) { + PdfiumPrintingWrapperQt printWrapper(result.data(), result.size()); + bool printerResult = printWrapper.printOnPrinter(*printer); + adapterClient->didPrintPageOnPrinter(requestId, printerResult); + } +} +#endif // QT_NO_PRINTER + static content::WebContents *createBlankWebContents(WebContentsAdapterClient *adapterClient, content::BrowserContext *browserContext) { content::WebContents::CreateParams create_params(browserContext, NULL); @@ -231,7 +247,7 @@ static void serializeNavigationHistory(const content::NavigationController &cont } } -static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, std::vector<scoped_ptr<content::NavigationEntry>> *entries, content::BrowserContext *browserContext) +static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, std::vector<std::unique_ptr<content::NavigationEntry>> *entries, content::BrowserContext *browserContext) { int version; input >> version; @@ -280,7 +296,7 @@ static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, return; } - scoped_ptr<content::NavigationEntry> entry = content::NavigationController::CreateNavigationEntry( + std::unique_ptr<content::NavigationEntry> entry = content::NavigationController::CreateNavigationEntry( toGurl(virtualUrl), content::Referrer(toGurl(referrerUrl), static_cast<blink::WebReferrerPolicy>(referrerPolicy)), // Use a transition type of reload so that we don't incorrectly @@ -351,7 +367,7 @@ WebContentsAdapterPrivate::~WebContentsAdapterPrivate() QSharedPointer<WebContentsAdapter> WebContentsAdapter::createFromSerializedNavigationHistory(QDataStream &input, WebContentsAdapterClient *adapterClient) { int currentIndex; - std::vector<scoped_ptr<content::NavigationEntry>> entries; + std::vector<std::unique_ptr<content::NavigationEntry>> entries; deserializeNavigationHistory(input, ¤tIndex, &entries, adapterClient->browserContextAdapter()->browserContext()); if (currentIndex == -1) @@ -469,21 +485,21 @@ void WebContentsAdapter::stop() controller.RemoveEntryAtIndex(index); d->webContents->Stop(); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::reload() { Q_D(WebContentsAdapter); d->webContents->GetController().Reload(/*checkRepost = */false); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::reloadAndBypassCache() { Q_D(WebContentsAdapter); - d->webContents->GetController().ReloadIgnoringCache(/*checkRepost = */false); - d->webContents->Focus(); + d->webContents->GetController().ReloadBypassingCache(/*checkRepost = */false); + focusIfNecessary(); } void WebContentsAdapter::load(const QUrl &url) @@ -502,11 +518,23 @@ void WebContentsAdapter::load(const QUrl &url) Q_UNUSED(guard); Q_D(WebContentsAdapter); - content::NavigationController::LoadURLParams params(toGurl(url)); + GURL gurl = toGurl(url); + + // Add URL scheme if missing from view-source URL. + if (url.scheme() == content::kViewSourceScheme) { + QUrl pageUrl = QUrl(url.toString().remove(0, strlen(content::kViewSourceScheme) + 1)); + if (pageUrl.scheme().isEmpty()) { + QUrl extendedUrl = QUrl::fromUserInput(pageUrl.toString()); + extendedUrl = QUrl(QString("%1:%2").arg(content::kViewSourceScheme, extendedUrl.toString())); + gurl = toGurl(extendedUrl); + } + } + + content::NavigationController::LoadURLParams params(gurl); params.transition_type = ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; d->webContents->GetController().LoadURLWithParams(params); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) @@ -519,7 +547,7 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT urlString.append(encodedData.constData(), encodedData.length()); GURL dataUrlToLoad(urlString); - if (dataUrlToLoad.spec().size() > content::kMaxURLChars) { + if (dataUrlToLoad.spec().size() > url::kMaxURLChars) { d->adapterClient->loadFinished(false, baseUrl, false, net::ERR_ABORTED); return; } @@ -531,13 +559,14 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT params.transition_type = ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_API); params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; d->webContents->GetController().LoadURLWithParams(params); - d->webContents->Focus(); + focusIfNecessary(); d->webContents->Unselect(); } -void WebContentsAdapter::save() +void WebContentsAdapter::save(const QString &filePath, int savePageFormat) { Q_D(WebContentsAdapter); + d->webContentsDelegate->setSavePageInfo(SavePageInfo(filePath, savePageFormat)); d->webContents->OnSavePage(); } @@ -631,7 +660,7 @@ void WebContentsAdapter::selectAll() void WebContentsAdapter::requestClose() { Q_D(WebContentsAdapter); - d->webContents->DispatchBeforeUnload(false); + d->webContents->DispatchBeforeUnload(); } void WebContentsAdapter::unselect() @@ -644,14 +673,14 @@ void WebContentsAdapter::navigateToIndex(int offset) { Q_D(WebContentsAdapter); d->webContents->GetController().GoToIndex(offset); - d->webContents->Focus(); + focusIfNecessary(); } void WebContentsAdapter::navigateToOffset(int offset) { Q_D(WebContentsAdapter); d->webContents->GetController().GoToOffset(offset); - d->webContents->Focus(); + focusIfNecessary(); } int WebContentsAdapter::navigationEntryCount() @@ -849,13 +878,19 @@ void WebContentsAdapter::updateWebPreferences(const content::WebPreferences & we void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileName) { + Q_D(WebContentsAdapter); content::BrowserContext *bctx = webContents()->GetBrowserContext(); content::DownloadManager *dlm = content::BrowserContext::GetDownloadManager(bctx); + DownloadManagerDelegateQt *dlmd = d->browserContextAdapter->downloadManagerDelegate(); + if (!dlm) return; - scoped_ptr<content::DownloadUrlParameters> params( - content::DownloadUrlParameters::FromWebContents(webContents(), toGurl(url))); + dlmd->setDownloadType(BrowserContextAdapterClient::UserRequested); + dlm->SetDelegate(dlmd); + + std::unique_ptr<content::DownloadUrlParameters> params( + content::DownloadUrlParameters::CreateForWebContentsMainFrame(webContents(), toGurl(url))); params->set_suggested_name(toString16(suggestedFileName)); dlm->DownloadUrl(std::move(params)); } @@ -881,7 +916,7 @@ bool WebContentsAdapter::recentlyAudible() void WebContentsAdapter::copyImageAt(const QPoint &location) { Q_D(WebContentsAdapter); - d->webContents->GetRenderViewHost()->CopyImageAt(location.x(), location.y()); + d->webContents->GetRenderViewHost()->GetMainFrame()->CopyImageAt(location.x(), location.y()); } ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerNoAction, blink::WebMediaPlayerAction::Unknown) @@ -916,13 +951,13 @@ bool WebContentsAdapter::hasInspector() const void WebContentsAdapter::exitFullScreen() { Q_D(WebContentsAdapter); - d->webContents->ExitFullscreen(); + d->webContents->ExitFullscreen(false); } void WebContentsAdapter::changedFullScreen() { Q_D(WebContentsAdapter); - d->webContents->NotifyFullscreenChanged(); + d->webContents->NotifyFullscreenChanged(false); } void WebContentsAdapter::wasShown() @@ -940,7 +975,7 @@ void WebContentsAdapter::wasHidden() void WebContentsAdapter::printToPDF(const QPageLayout &pageLayout, const QString &filePath) { #if defined(ENABLE_BASIC_PRINTING) - PrintViewManagerQt::FromWebContents(webContents())->PrintToPDF(pageLayout, filePath); + PrintViewManagerQt::FromWebContents(webContents())->PrintToPDF(pageLayout, true, filePath); #endif // if defined(ENABLE_BASIC_PRINTING) } @@ -948,13 +983,33 @@ quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayo { #if defined(ENABLE_BASIC_PRINTING) Q_D(WebContentsAdapter); - PrintViewManagerQt::PrintToPDFCallback callback = base::Bind(&callbackOnPrintingFinished, d->adapterClient, d->nextRequestId); - PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(pageLayout, callback); + PrintViewManagerQt::PrintToPDFCallback callback = base::Bind(&callbackOnPrintingFinished + , d->adapterClient + , d->nextRequestId); + PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(pageLayout, true + , callback); + return d->nextRequestId++; +#else + return 0; +#endif // if defined(ENABLE_BASIC_PRINTING) +} + +#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) +quint64 WebContentsAdapter::printOnPrinterCallbackResult(QPrinter *printer) +{ +#if defined(ENABLE_BASIC_PRINTING) + Q_D(WebContentsAdapter); + PrintViewManagerQt::PrintToPDFCallback callback + = base::Bind(&callbackOnPrintingOnPrinterFinished, d->adapterClient + , d->nextRequestId, printer); + PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback( + printer->pageLayout(), printer->colorMode() == QPrinter::Color, callback); return d->nextRequestId++; #else return 0; #endif // if defined(ENABLE_BASIC_PRINTING) } +#endif // QT_NO_PRINTER QPointF WebContentsAdapter::lastScrollOffset() const { @@ -1143,7 +1198,7 @@ void WebContentsAdapter::enterDrag(QDragEnterEvent *e, const QPoint &screenPos) { Q_D(WebContentsAdapter); - scoped_ptr<content::DropData> ownedDropData; + std::unique_ptr<content::DropData> ownedDropData; const content::DropData *rvhDropData = d->currentDropData; if (!rvhDropData) { // The drag originated outside the WebEngineView. @@ -1199,7 +1254,7 @@ void WebContentsAdapter::endDragging(const QPoint &clientPos, const QPoint &scre Q_D(WebContentsAdapter); finishDragUpdate(); content::RenderViewHost *rvh = d->webContents->GetRenderViewHost(); - rvh->DragTargetDrop(toGfx(clientPos), toGfx(screenPos), 0); + rvh->DragTargetDrop(*d->currentDropData, toGfx(clientPos), toGfx(screenPos), 0); } void WebContentsAdapter::leaveDrag() @@ -1238,6 +1293,15 @@ void WebContentsAdapter::replaceMisspelling(const QString &word) #endif } +void WebContentsAdapter::focusIfNecessary() +{ + Q_D(WebContentsAdapter); + const WebEngineSettings *settings = d->adapterClient->webEngineSettings(); + bool focusOnNavigation = settings->testAttribute(WebEngineSettings::FocusOnNavigationEnabled); + if (focusOnNavigation) + d->webContents->Focus(); +} + WebContentsAdapterClient::RenderProcessTerminationStatus WebContentsAdapterClient::renderProcessExitStatus(int terminationStatus) { auto status = WebContentsAdapterClient::RenderProcessTerminationStatus(-1); @@ -1276,4 +1340,16 @@ FaviconManager *WebContentsAdapter::faviconManager() return d->webContentsDelegate->faviconManager(); } +void WebContentsAdapter::viewSource() +{ + Q_D(WebContentsAdapter); + d->webContents->ViewSource(); +} + +bool WebContentsAdapter::canViewSource() +{ + Q_D(WebContentsAdapter); + return d->webContents->GetController().CanViewSource(); +} + } // namespace QtWebEngineCore |