]> khamidou — GitHub mirrors - electron.git/commitdiff
Add a DownloadURL method on WebContents.
authorCharlie Hess <charlie@slack-corp.com>
Wed, 2 Dec 2015 21:49:30 +0000 (13:49 -0800)
committerCharlie Hess <charlie@slack-corp.com>
Wed, 2 Dec 2015 21:49:30 +0000 (13:49 -0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h

index f377e8fda9e8990a48ac7a0ef3a5bbeb1b5e65a6..116bf03b1d4ca061ee717af860a3fdf4339aa21a 100644 (file)
@@ -634,6 +634,15 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
   web_contents()->GetController().LoadURLWithParams(params);
 }
 
+void WebContents::DownloadURL(const GURL& url) {
+  auto browser_context = web_contents()->GetBrowserContext();
+  auto download_manager =
+    content::BrowserContext::GetDownloadManager(browser_context);
+
+  download_manager->DownloadUrl(
+    content::DownloadUrlParameters::FromWebContents(web_contents(), url));
+}
+
 GURL WebContents::GetURL() const {
   return web_contents()->GetURL();
 }
@@ -996,6 +1005,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
         .SetMethod("getId", &WebContents::GetID)
         .SetMethod("equal", &WebContents::Equal)
         .SetMethod("_loadURL", &WebContents::LoadURL)
+        .SetMethod("downloadURL", &WebContents::DownloadURL)
         .SetMethod("_getURL", &WebContents::GetURL)
         .SetMethod("getTitle", &WebContents::GetTitle)
         .SetMethod("isLoading", &WebContents::IsLoading)
index 568a563e2c84e29042fcf02e3e9f62583fa3b134..07cb79dfab9ca07ed54c19d02e205cb890516c75 100644 (file)
@@ -60,6 +60,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
   int GetID() const;
   bool Equal(const WebContents* web_contents) const;
   void LoadURL(const GURL& url, const mate::Dictionary& options);
+  void DownloadURL(const GURL& url);
   GURL GetURL() const;
   base::string16 GetTitle() const;
   bool IsLoading() const;