2018-04-19 17:44:42 +02:00
|
|
|
diff --git chrome/browser/extensions/api/streams_private/streams_private_api.cc chrome/browser/extensions/api/streams_private/streams_private_api.cc
|
2018-10-24 22:37:39 +02:00
|
|
|
index 9e81f0a33ede..b796e79ae7ef 100644
|
2018-04-19 17:44:42 +02:00
|
|
|
--- chrome/browser/extensions/api/streams_private/streams_private_api.cc
|
|
|
|
+++ chrome/browser/extensions/api/streams_private/streams_private_api.cc
|
2018-10-24 22:37:39 +02:00
|
|
|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
|
|
#include <utility>
|
2018-05-14 13:24:05 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
+#include "cef/libcef/features/features.h"
|
|
|
|
#include "chrome/browser/extensions/extension_tab_util.h"
|
|
|
|
#include "chrome/browser/prerender/prerender_contents.h"
|
2018-10-24 22:37:39 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
@@ -42,6 +43,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
2018-04-19 17:44:42 +02:00
|
|
|
if (!web_contents)
|
|
|
|
return;
|
2018-05-14 13:24:05 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
// If the request was for a prerender, abort the prerender and do not
|
|
|
|
// continue. This is because plugins cancel prerender, see
|
|
|
|
// http://crbug.com/343590.
|
2018-10-24 22:37:39 +02:00
|
|
|
@@ -51,6 +53,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
2018-04-19 17:44:42 +02:00
|
|
|
prerender_contents->Destroy(prerender::FINAL_STATUS_DOWNLOAD);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
+#endif // !BUILDFLAG(ENABLE_CEF)
|
2018-05-14 13:24:05 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
auto* browser_context = web_contents->GetBrowserContext();
|
2018-10-24 22:37:39 +02:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
diff --git extensions/browser/extension_host.cc extensions/browser/extension_host.cc
|
2019-04-16 16:38:48 +02:00
|
|
|
index 8cc9503fc131..b74c385b40a2 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.cc
|
|
|
|
+++ extensions/browser/extension_host.cc
|
2018-07-02 19:11:49 +02:00
|
|
|
@@ -67,11 +67,12 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
2017-08-04 00:55:19 +02:00
|
|
|
DCHECK(host_type == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
|
|
|
|
host_type == VIEW_TYPE_EXTENSION_DIALOG ||
|
|
|
|
host_type == VIEW_TYPE_EXTENSION_POPUP);
|
2018-05-18 12:45:18 +02:00
|
|
|
- host_contents_ = WebContents::Create(
|
|
|
|
- WebContents::CreateParams(browser_context_, site_instance)),
|
2017-08-04 00:55:19 +02:00
|
|
|
- content::WebContentsObserver::Observe(host_contents_.get());
|
2018-05-18 12:45:18 +02:00
|
|
|
+ host_contents_owned_ = WebContents::Create(
|
|
|
|
+ WebContents::CreateParams(browser_context_, site_instance));
|
2017-08-04 00:55:19 +02:00
|
|
|
+ host_contents_ = host_contents_owned_.get();
|
|
|
|
+ content::WebContentsObserver::Observe(host_contents_);
|
|
|
|
host_contents_->SetDelegate(this);
|
|
|
|
- SetViewType(host_contents_.get(), host_type);
|
|
|
|
+ SetViewType(host_contents_, host_type);
|
|
|
|
|
|
|
|
render_view_host_ = host_contents_->GetRenderViewHost();
|
|
|
|
|
2018-07-02 19:11:49 +02:00
|
|
|
@@ -86,6 +87,48 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
2017-08-04 00:55:19 +02:00
|
|
|
dispatcher()->set_delegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ExtensionHost::ExtensionHost(ExtensionHostDelegate* delegate,
|
|
|
|
+ const Extension* extension,
|
|
|
|
+ content::BrowserContext* browser_context,
|
|
|
|
+ content::WebContents* host_contents,
|
|
|
|
+ const GURL& url,
|
|
|
|
+ ViewType host_type)
|
|
|
|
+ : delegate_(delegate),
|
|
|
|
+ extension_(extension),
|
|
|
|
+ extension_id_(extension->id()),
|
|
|
|
+ browser_context_(browser_context),
|
|
|
|
+ host_contents_(host_contents),
|
|
|
|
+ render_view_host_(nullptr),
|
|
|
|
+ is_render_view_creation_pending_(false),
|
|
|
|
+ has_loaded_once_(false),
|
|
|
|
+ document_element_available_(false),
|
|
|
|
+ initial_url_(url),
|
|
|
|
+ extension_host_type_(host_type) {
|
|
|
|
+ DCHECK(delegate);
|
|
|
|
+ DCHECK(browser_context);
|
|
|
|
+ DCHECK(host_contents);
|
|
|
|
+
|
|
|
|
+ // Not used for panels, see PanelHost.
|
|
|
|
+ DCHECK(host_type == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
|
|
|
|
+ host_type == VIEW_TYPE_EXTENSION_DIALOG ||
|
|
|
|
+ host_type == VIEW_TYPE_EXTENSION_POPUP);
|
|
|
|
+
|
|
|
|
+ content::WebContentsObserver::Observe(host_contents_);
|
|
|
|
+ SetViewType(host_contents_, host_type);
|
|
|
|
+
|
|
|
|
+ render_view_host_ = host_contents_->GetRenderViewHost();
|
|
|
|
+
|
|
|
|
+ // Listen for when an extension is unloaded from the same profile, as it may
|
|
|
|
+ // be the same extension that this points to.
|
|
|
|
+ ExtensionRegistry::Get(browser_context_)->AddObserver(this);
|
|
|
|
+
|
|
|
|
+ // Set up web contents observers and pref observers.
|
|
|
|
+ delegate_->OnExtensionHostCreated(host_contents_);
|
|
|
|
+
|
|
|
|
+ ExtensionWebContentsObserver::GetForWebContents(host_contents_)->
|
|
|
|
+ dispatcher()->set_delegate(this);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
ExtensionHost::~ExtensionHost() {
|
|
|
|
ExtensionRegistry::Get(browser_context_)->RemoveObserver(this);
|
|
|
|
|
|
|
|
diff --git extensions/browser/extension_host.h extensions/browser/extension_host.h
|
2019-02-01 17:42:40 +01:00
|
|
|
index 4027505469b8..de8258562bb2 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.h
|
|
|
|
+++ extensions/browser/extension_host.h
|
2019-02-01 17:42:40 +01:00
|
|
|
@@ -52,13 +52,19 @@ class ExtensionHost : public DeferredStartRenderHost,
|
2017-08-04 00:55:19 +02:00
|
|
|
ExtensionHost(const Extension* extension,
|
|
|
|
content::SiteInstance* site_instance,
|
|
|
|
const GURL& url, ViewType host_type);
|
|
|
|
+ ExtensionHost(ExtensionHostDelegate* delegate,
|
|
|
|
+ const Extension* extension,
|
|
|
|
+ content::BrowserContext* browser_context,
|
|
|
|
+ content::WebContents* host_contents,
|
|
|
|
+ const GURL& url,
|
|
|
|
+ ViewType host_type);
|
|
|
|
~ExtensionHost() override;
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
// This may be null if the extension has been or is being unloaded.
|
2017-08-04 00:55:19 +02:00
|
|
|
const Extension* extension() const { return extension_; }
|
2017-12-07 22:44:24 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
const std::string& extension_id() const { return extension_id_; }
|
|
|
|
- content::WebContents* host_contents() const { return host_contents_.get(); }
|
|
|
|
+ content::WebContents* host_contents() const { return host_contents_; }
|
|
|
|
content::RenderViewHost* render_view_host() const;
|
|
|
|
content::RenderProcessHost* render_process_host() const;
|
|
|
|
bool has_loaded_once() const { return has_loaded_once_; }
|
2019-02-01 17:42:40 +01:00
|
|
|
@@ -180,7 +186,8 @@ class ExtensionHost : public DeferredStartRenderHost,
|
2017-08-04 00:55:19 +02:00
|
|
|
content::BrowserContext* browser_context_;
|
|
|
|
|
|
|
|
// The host for our HTML content.
|
|
|
|
- std::unique_ptr<content::WebContents> host_contents_;
|
|
|
|
+ std::unique_ptr<content::WebContents> host_contents_owned_;
|
|
|
|
+ content::WebContents* host_contents_;
|
|
|
|
|
|
|
|
// A weak pointer to the current or pending RenderViewHost. We don't access
|
|
|
|
// this through the host_contents because we want to deal with the pending
|
|
|
|
diff --git extensions/browser/extensions_browser_client.h extensions/browser/extensions_browser_client.h
|
2019-03-24 01:39:54 +01:00
|
|
|
index 93dce1cad08c..1eef00b03063 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extensions_browser_client.h
|
|
|
|
+++ extensions/browser/extensions_browser_client.h
|
2019-02-21 01:42:36 +01:00
|
|
|
@@ -62,6 +62,7 @@ class ComponentExtensionResourceManager;
|
2017-08-04 00:55:19 +02:00
|
|
|
class Extension;
|
|
|
|
class ExtensionCache;
|
|
|
|
class ExtensionError;
|
|
|
|
+class ExtensionHost;
|
|
|
|
class ExtensionHostDelegate;
|
|
|
|
class ExtensionPrefsObserver;
|
|
|
|
class ExtensionApiFrameIdMap;
|
2019-03-24 01:39:54 +01:00
|
|
|
@@ -216,6 +217,14 @@ class ExtensionsBrowserClient {
|
2017-08-04 00:55:19 +02:00
|
|
|
virtual std::unique_ptr<ExtensionHostDelegate>
|
|
|
|
CreateExtensionHostDelegate() = 0;
|
|
|
|
|
|
|
|
+ // CEF creates a custom ExtensionHost for background pages. If the return
|
|
|
|
+ // value is true and |host| is NULL then fail the background host creation.
|
|
|
|
+ virtual bool CreateBackgroundExtensionHost(
|
|
|
|
+ const Extension* extension,
|
|
|
|
+ content::BrowserContext* browser_context,
|
|
|
|
+ const GURL& url,
|
|
|
|
+ ExtensionHost** host) { return false; }
|
|
|
|
+
|
|
|
|
// Returns true if the client version has updated since the last run. Called
|
|
|
|
// once each time the extensions system is loaded per browser_context. The
|
|
|
|
// implementation may wish to use the BrowserContext to record the current
|
|
|
|
diff --git extensions/browser/process_manager.cc extensions/browser/process_manager.cc
|
2019-06-05 16:15:45 +02:00
|
|
|
index b203c136597a..4967c176f9b8 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/process_manager.cc
|
|
|
|
+++ extensions/browser/process_manager.cc
|
2019-03-13 22:27:37 +01:00
|
|
|
@@ -383,9 +383,16 @@ bool ProcessManager::CreateBackgroundHost(const Extension* extension,
|
2017-08-04 00:55:19 +02:00
|
|
|
return true; // TODO(kalman): return false here? It might break things...
|
|
|
|
|
|
|
|
DVLOG(1) << "CreateBackgroundHost " << extension->id();
|
|
|
|
- ExtensionHost* host =
|
|
|
|
- new ExtensionHost(extension, GetSiteInstanceForURL(url).get(), url,
|
|
|
|
- VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
|
|
|
|
+ ExtensionHost* host = nullptr;
|
|
|
|
+ if (ExtensionsBrowserClient::Get()->CreateBackgroundExtensionHost(
|
|
|
|
+ extension, browser_context_, url, &host) && !host) {
|
|
|
|
+ // Explicitly fail if the client can't create the host.
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (!host) {
|
|
|
|
+ host = new ExtensionHost(extension, GetSiteInstanceForURL(url).get(), url,
|
|
|
|
+ VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
|
|
|
|
+ }
|
|
|
|
host->CreateRenderViewSoon();
|
|
|
|
OnBackgroundHostCreated(host);
|
|
|
|
return true;
|