From 56b904947bf4be0b3ca80cd65c137a84595f83be Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 24 Jul 2013 07:56:55 -0400 Subject: [PATCH] Avoid a crash when starting a download by disallowing downloads Chromium crashes when starting a download if a content::DownloadManagerDelegate is not provided. We now provide a default implementation of content::DownloadManagerDelegate which disallows all downloads. --- brightray/brightray.gyp | 2 ++ brightray/browser/browser_context.cc | 5 ++++- brightray/browser/browser_context.h | 2 ++ .../browser/download_manager_delegate.cc | 11 +++++++++++ brightray/browser/download_manager_delegate.h | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 brightray/browser/download_manager_delegate.cc create mode 100644 brightray/browser/download_manager_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b91e1d9aed1..d6ba7960b8b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -36,6 +36,8 @@ 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_delegate.cc', 'browser/devtools_delegate.h', + 'browser/download_manager_delegate.cc', + 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', 'browser/inspectable_web_contents_impl.cc', diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 42074e74ce3..494f08f6403 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,6 +4,7 @@ #include "browser_context.h" +#include "browser/download_manager_delegate.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" #include "common/application_info.h" @@ -116,7 +117,9 @@ content::ResourceContext* BrowserContext::GetResourceContext() { } content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() { - return nullptr; + if (!download_manager_delegate_) + download_manager_delegate_.reset(new DownloadManagerDelegate); + return download_manager_delegate_.get(); } content::GeolocationPermissionContext* BrowserContext::GetGeolocationPermissionContext() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 4307df0aa3b..85f00148c9c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -13,6 +13,7 @@ class PrefService; namespace brightray { +class DownloadManagerDelegate; class NetworkDelegate; class URLRequestContextGetter; @@ -55,6 +56,7 @@ private: scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; + scoped_ptr download_manager_delegate_; DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; diff --git a/brightray/browser/download_manager_delegate.cc b/brightray/browser/download_manager_delegate.cc new file mode 100644 index 00000000000..f241f8441bc --- /dev/null +++ b/brightray/browser/download_manager_delegate.cc @@ -0,0 +1,11 @@ +#include "browser/download_manager_delegate.h" + +namespace brightray { + +DownloadManagerDelegate::DownloadManagerDelegate() { +} + +DownloadManagerDelegate::~DownloadManagerDelegate() { +} + +} diff --git a/brightray/browser/download_manager_delegate.h b/brightray/browser/download_manager_delegate.h new file mode 100644 index 00000000000..c25d2e7a16a --- /dev/null +++ b/brightray/browser/download_manager_delegate.h @@ -0,0 +1,19 @@ +#ifndef BRIGHTRAY_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ + +#include "content/public/browser/download_manager_delegate.h" + +namespace brightray { + +class DownloadManagerDelegate : public content::DownloadManagerDelegate { + public: + DownloadManagerDelegate(); + ~DownloadManagerDelegate(); + + private: + DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegate); +}; + +} + +#endif