Add a DownloadURL method on WebContents.

This commit is contained in:
Charlie Hess 2015-12-02 13:49:30 -08:00
parent 85b7aa6933
commit c311c6cf1b
2 changed files with 11 additions and 0 deletions

View file

@ -634,6 +634,15 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
web_contents()->GetController().LoadURLWithParams(params); 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 { GURL WebContents::GetURL() const {
return web_contents()->GetURL(); return web_contents()->GetURL();
} }
@ -996,6 +1005,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("getId", &WebContents::GetID) .SetMethod("getId", &WebContents::GetID)
.SetMethod("equal", &WebContents::Equal) .SetMethod("equal", &WebContents::Equal)
.SetMethod("_loadURL", &WebContents::LoadURL) .SetMethod("_loadURL", &WebContents::LoadURL)
.SetMethod("downloadURL", &WebContents::DownloadURL)
.SetMethod("_getURL", &WebContents::GetURL) .SetMethod("_getURL", &WebContents::GetURL)
.SetMethod("getTitle", &WebContents::GetTitle) .SetMethod("getTitle", &WebContents::GetTitle)
.SetMethod("isLoading", &WebContents::IsLoading) .SetMethod("isLoading", &WebContents::IsLoading)

View file

@ -60,6 +60,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
int GetID() const; int GetID() const;
bool Equal(const WebContents* web_contents) const; bool Equal(const WebContents* web_contents) const;
void LoadURL(const GURL& url, const mate::Dictionary& options); void LoadURL(const GURL& url, const mate::Dictionary& options);
void DownloadURL(const GURL& url);
GURL GetURL() const; GURL GetURL() const;
base::string16 GetTitle() const; base::string16 GetTitle() const;
bool IsLoading() const; bool IsLoading() const;