From anonymous, 1 Year ago, written in Diff-output.
Embed
  1. diff --git a/src/core/browser_context_adapter_client.h b/src/core/browser_context_adapter_client.h
  2. index 02bee8ed..eb4e3849 100644
  3. --- a/src/core/browser_context_adapter_client.h
  4. +++ b/src/core/browser_context_adapter_client.h
  5. @@ -45,6 +45,7 @@
  6.  #include <QUrl>
  7.  
  8.  namespace QtWebEngineCore {
  9. +class WebContentsAdapter;
  10.  
  11.  class QWEBENGINE_EXPORT BrowserContextAdapterClient
  12.  {
  13. @@ -122,6 +123,7 @@ public:
  14.          bool done;
  15.          int downloadType;
  16.          int downloadInterruptReason;
  17. +        void *page;
  18.      };
  19.  
  20.      virtual ~BrowserContextAdapterClient() { }
  21. diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
  22. index 5eb97c5e..7f3d5774 100644
  23. --- a/src/core/download_manager_delegate_qt.cpp
  24. +++ b/src/core/download_manager_delegate_qt.cpp
  25. @@ -159,51 +159,56 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
  26.      }
  27.  
  28.      item->AddObserver(this);
  29. -    QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
  30. -    if (!clients.isEmpty()) {
  31. -        BrowserContextAdapterClient::DownloadItemInfo info = {
  32. -            item->GetId(),
  33. -            toQt(item->GetURL()),
  34. -            item->GetState(),
  35. -            item->GetTotalBytes(),
  36. -            item->GetReceivedBytes(),
  37. -            mimeTypeString,
  38. -            suggestedFilePath,
  39. -            BrowserContextAdapterClient::UnknownSavePageFormat,
  40. -            false /* accepted */,
  41. -            false /* paused */,
  42. -            false /* done */,
  43. -            m_downloadType,
  44. -            item->GetLastReason()
  45. -        };
  46. +    Q_ASSERT(item->GetBrowserContext() == m_contextAdapter->browserContext());
  47. +    BrowserContextAdapterClient::DownloadItemInfo info = {
  48. +        item->GetId(),
  49. +        toQt(item->GetURL()),
  50. +        item->GetState(),
  51. +        item->GetTotalBytes(),
  52. +        item->GetReceivedBytes(),
  53. +        mimeTypeString,
  54. +        suggestedFilePath,
  55. +        BrowserContextAdapterClient::UnknownSavePageFormat,
  56. +        false /* accepted */,
  57. +        false /* paused */,
  58. +        false /* done */,
  59. +        m_downloadType,
  60. +        item->GetLastReason(),
  61. +        nullptr
  62. +    };
  63.  
  64. -        Q_FOREACH (BrowserContextAdapterClient *client, clients) {
  65. +    content::WebContents *webContents = item->GetWebContents();
  66. +    WebContentsAdapterClient *adapterClient = nullptr;
  67. +    if (webContents) {
  68. +        adapterClient = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate())->adapterClient();
  69. +        adapterClient->downloadRequested(info);
  70. +    }
  71. +    if (!info.accepted) {
  72. +        Q_FOREACH (BrowserContextAdapterClient *client, m_contextAdapter->clients()) {
  73.              client->downloadRequested(info);
  74.              if (info.accepted)
  75.                  break;
  76.          }
  77. +    }
  78.  
  79. -        suggestedFile.setFile(info.path);
  80. -
  81. -        if (info.accepted && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) {
  82. -            qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data());
  83. -            info.accepted = false;
  84. -        }
  85. +    suggestedFile.setFile(info.path);
  86.  
  87. -        if (!info.accepted) {
  88. -            cancelDownload(callback);
  89. -            return true;
  90. -        }
  91. +    if (info.accepted && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) {
  92. +        qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data());
  93. +        info.accepted = false;
  94. +    }
  95.  
  96. -        base::FilePath filePathForCallback(toFilePathString(suggestedFile.absoluteFilePath()));
  97. -        callback.Run(filePathForCallback,
  98. -                     content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
  99. -                     content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
  100. -                     filePathForCallback.AddExtension(toFilePathString("download")),
  101. -                     content::DOWNLOAD_INTERRUPT_REASON_NONE);
  102. -    } else
  103. +    if (!info.accepted) {
  104.          cancelDownload(callback);
  105. +        return true;
  106. +    }
  107.  
  108. +    base::FilePath filePathForCallback(toFilePathString(suggestedFile.absoluteFilePath()));
  109. +    callback.Run(filePathForCallback,
  110. +                 content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
  111. +                 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
  112. +                 filePathForCallback.AddExtension(toFilePathString("download")),
  113. +                 content::DOWNLOAD_INTERRUPT_REASON_NONE);
  114.      return true;
  115.  }
  116.  
  117. @@ -269,7 +274,8 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
  118.          false, /* paused */
  119.          false, /* done */
  120.          BrowserContextAdapterClient::SavePage,
  121. -        BrowserContextAdapterClient::NoReason
  122. +        BrowserContextAdapterClient::NoReason,
  123. +        nullptr
  124.      };
  125.  
  126.      Q_FOREACH (BrowserContextAdapterClient *client, clients) {
  127. @@ -309,7 +315,8 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
  128.              download->IsPaused(),
  129.              download->IsDone(),
  130.              m_downloadType,
  131. -            download->GetLastReason()
  132. +            download->GetLastReason(),
  133. +            nullptr
  134.          };
  135.  
  136.          Q_FOREACH (BrowserContextAdapterClient *client, clients) {
  137. diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
  138. index 8b736534..28fd62b3 100644
  139. --- a/src/core/web_contents_adapter_client.h
  140. +++ b/src/core/web_contents_adapter_client.h
  141. @@ -41,6 +41,7 @@
  142.  #define WEB_CONTENTS_ADAPTER_CLIENT_H
  143.  
  144.  #include "qtwebenginecoreglobal.h"
  145. +#include "browser_context_adapter_client.h"
  146.  
  147.  #include <QFlags>
  148.  #include <QRect>
  149. @@ -382,6 +383,7 @@ public:
  150.      virtual bool isEnabled() const = 0;
  151.      virtual const QObject *holdingQObject() const = 0;
  152.      virtual void setToolTip(const QString& toolTipText) = 0;
  153. +    virtual void downloadRequested(BrowserContextAdapterClient::DownloadItemInfo &info) = 0;
  154.  
  155.      virtual QSharedPointer<BrowserContextAdapter> browserContextAdapter() = 0;
  156.      virtual WebContentsAdapter* webContentsAdapter() = 0;
  157. diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h
  158. index 2e37c498..6f249472 100644
  159. --- a/src/core/web_contents_delegate_qt.h
  160. +++ b/src/core/web_contents_delegate_qt.h
  161. @@ -149,6 +149,7 @@ public:
  162.      const SavePageInfo &savePageInfo() { return m_savePageInfo; }
  163.  
  164.      WebEngineSettings *webEngineSettings() const;
  165. +    WebContentsAdapterClient *adapterClient() const { return m_viewClient; }
  166.  
  167.  private:
  168.      QWeakPointer<WebContentsAdapter> createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture);
  169. diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
  170. index 123acb20..f0aac9ac 100644
  171. --- a/src/webengine/api/qquickwebengineview.cpp
  172. +++ b/src/webengine/api/qquickwebengineview.cpp
  173. @@ -1195,6 +1195,12 @@ void QQuickWebEngineViewPrivate::setToolTip(const QString &toolTipText)
  174.      ui()->showToolTip(toolTipText);
  175.  }
  176.  
  177. +void QQuickWebEngineViewPrivate::downloadRequested(QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info)
  178. +{
  179. +    info.page = q_ptr;
  180. +    m_profile->d_func()->downloadRequested(info);
  181. +}
  182. +
  183.  bool QQuickWebEngineView::isLoading() const
  184.  {
  185.      Q_D(const QQuickWebEngineView);
  186. diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
  187. index 19ecf5e1..e130a79a 100644
  188. --- a/src/webengine/api/qquickwebengineview_p_p.h
  189. +++ b/src/webengine/api/qquickwebengineview_p_p.h
  190. @@ -145,6 +145,7 @@ public:
  191.                         const QPixmap &pixmap, const QPoint &offset) Q_DECL_OVERRIDE;
  192.      virtual bool isEnabled() const Q_DECL_OVERRIDE;
  193.      virtual void setToolTip(const QString &toolTipText) Q_DECL_OVERRIDE;
  194. +    virtual void downloadRequested(QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info) Q_DECL_OVERRIDE;
  195.      const QObject *holdingQObject() const Q_DECL_OVERRIDE;
  196.  
  197.      virtual QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextAdapter() Q_DECL_OVERRIDE;
  198. diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
  199. index a5569e40..a2f55aa0 100644
  200. --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp
  201. +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
  202. @@ -121,6 +121,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr
  203.      , downloadPaused(false)
  204.      , totalBytes(-1)
  205.      , receivedBytes(0)
  206. +    , page(0)
  207.  {
  208.  }
  209.  
  210. @@ -547,6 +548,12 @@ QString QWebEngineDownloadItem::interruptReasonString() const
  211.                static_cast<BrowserContextAdapterClient::DownloadInterruptReason>(interruptReason()));
  212.  }
  213.  
  214. +QWebEnginePage *QWebEngineDownloadItem::page() const
  215. +{
  216. +    Q_D(const QWebEngineDownloadItem);
  217. +    return d->page;
  218. +}
  219. +
  220.  QWebEngineDownloadItem::QWebEngineDownloadItem(QWebEngineDownloadItemPrivate *p, QObject *parent)
  221.      : QObject(parent)
  222.      , d_ptr(p)
  223. diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h
  224. index 2aca2bb2..24bf6ad8 100644
  225. --- a/src/webenginewidgets/api/qwebenginedownloaditem.h
  226. +++ b/src/webenginewidgets/api/qwebenginedownloaditem.h
  227. @@ -46,6 +46,7 @@
  228.  
  229.  QT_BEGIN_NAMESPACE
  230.  
  231. +class QWebEnginePage;
  232.  class QWebEngineDownloadItemPrivate;
  233.  class QWebEngineProfilePrivate;
  234.  
  235. @@ -127,6 +128,8 @@ public:
  236.      DownloadInterruptReason interruptReason() const;
  237.      QString interruptReasonString() const;
  238.  
  239. +    QWebEnginePage *page() const;
  240. +
  241.  public Q_SLOTS:
  242.      void accept();
  243.      void cancel();
  244. diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
  245. index 178f6ec9..4a63d571 100644
  246. --- a/src/webenginewidgets/api/qwebenginepage.cpp
  247. +++ b/src/webenginewidgets/api/qwebenginepage.cpp
  248. @@ -1627,6 +1627,12 @@ void QWebEnginePagePrivate::setToolTip(const QString &toolTipText)
  249.      }
  250.  }
  251.  
  252. +void QWebEnginePagePrivate::downloadRequested(BrowserContextAdapterClient::DownloadItemInfo &info)
  253. +{
  254. +    info.page = q_func();
  255. +    profile->d_func()->downloadRequested(info);
  256. +}
  257. +
  258.  QMenu *QWebEnginePage::createStandardContextMenu()
  259.  {
  260.      Q_D(QWebEnginePage);
  261. diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
  262. index ec84f05e..005a8dfd 100644
  263. --- a/src/webenginewidgets/api/qwebenginepage_p.h
  264. +++ b/src/webenginewidgets/api/qwebenginepage_p.h
  265. @@ -141,6 +141,7 @@ public:
  266.                         const QPixmap &pixmap, const QPoint &offset) Q_DECL_OVERRIDE;
  267.      virtual bool isEnabled() const Q_DECL_OVERRIDE;
  268.      virtual void setToolTip(const QString &toolTipText) Q_DECL_OVERRIDE;
  269. +    virtual void downloadRequested(QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info) Q_DECL_OVERRIDE;
  270.      const QObject *holdingQObject() const Q_DECL_OVERRIDE;
  271.  
  272.      virtual QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextAdapter() Q_DECL_OVERRIDE;
  273. diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
  274. index 18b9cb48..165e8ead 100644
  275. --- a/src/webenginewidgets/api/qwebengineprofile.cpp
  276. +++ b/src/webenginewidgets/api/qwebengineprofile.cpp
  277. @@ -190,6 +190,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
  278.      itemPrivate->mimeType = info.mimeType;
  279.      itemPrivate->savePageFormat = static_cast<QWebEngineDownloadItem::SavePageFormat>(info.savePageFormat);
  280.      itemPrivate->type = static_cast<QWebEngineDownloadItem::DownloadType>(info.downloadType);
  281. +    itemPrivate->page = static_cast<QWebEnginePage *>(info.page);
  282.  
  283.      QWebEngineDownloadItem *download = new QWebEngineDownloadItem(itemPrivate, q);