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
|
2021-04-21 00:52:34 +02:00
|
|
|
index 5c903a13a14ed..d385c6c0c95c4 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
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
+#include "cef/libcef/features/runtime.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "chrome/browser/extensions/extension_tab_util.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "chrome/browser/prefetch/no_state_prefetch/chrome_no_state_prefetch_contents_delegate.h"
|
|
|
|
#include "components/no_state_prefetch/browser/no_state_prefetch_contents.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
@@ -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
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
+ if (!cef::IsAlloyRuntimeEnabled()) {
|
|
|
|
// If the request was for NoStatePrefetch, abort the prefetcher and do not
|
|
|
|
// continue. This is because plugins cancel NoStatePrefetch, see
|
2018-04-19 17:44:42 +02:00
|
|
|
// http://crbug.com/343590.
|
2021-03-04 23:36:57 +01:00
|
|
|
@@ -52,6 +54,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
|
|
|
no_state_prefetch_contents->Destroy(prerender::FINAL_STATUS_DOWNLOAD);
|
2018-04-19 17:44:42 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-03-04 23:36:57 +01:00
|
|
|
+ }
|
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
|
2021-06-04 03:34:56 +02:00
|
|
|
index 7e38155c3b695..78768b28d8c99 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.cc
|
|
|
|
+++ extensions/browser/extension_host.cc
|
2021-04-21 00:52:34 +02:00
|
|
|
@@ -63,11 +63,12 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
|
|
|
DCHECK(host_type == mojom::ViewType::kExtensionBackgroundPage ||
|
|
|
|
host_type == mojom::ViewType::kExtensionDialog ||
|
|
|
|
host_type == mojom::ViewType::kExtensionPopup);
|
2018-05-18 12:45:18 +02:00
|
|
|
- host_contents_ = WebContents::Create(
|
|
|
|
+ host_contents_owned_ = WebContents::Create(
|
2021-03-04 23:36:57 +01:00
|
|
|
WebContents::CreateParams(browser_context_, site_instance)),
|
|
|
|
- content::WebContentsObserver::Observe(host_contents_.get());
|
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);
|
2021-03-04 23:36:57 +01:00
|
|
|
main_frame_host_ = host_contents_->GetMainFrame();
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
// Listen for when an extension is unloaded from the same profile, as it may
|
2021-04-21 00:52:34 +02:00
|
|
|
@@ -81,6 +82,44 @@ 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,
|
2021-04-21 00:52:34 +02:00
|
|
|
+ mojom::ViewType host_type)
|
2017-08-04 00:55:19 +02:00
|
|
|
+ : delegate_(delegate),
|
|
|
|
+ extension_(extension),
|
|
|
|
+ extension_id_(extension->id()),
|
|
|
|
+ browser_context_(browser_context),
|
|
|
|
+ host_contents_(host_contents),
|
|
|
|
+ initial_url_(url),
|
|
|
|
+ extension_host_type_(host_type) {
|
|
|
|
+ DCHECK(delegate);
|
|
|
|
+ DCHECK(browser_context);
|
|
|
|
+ DCHECK(host_contents);
|
|
|
|
+
|
|
|
|
+ // Not used for panels, see PanelHost.
|
2021-04-21 00:52:34 +02:00
|
|
|
+ DCHECK(host_type == mojom::ViewType::kExtensionBackgroundPage ||
|
|
|
|
+ host_type == mojom::ViewType::kExtensionDialog ||
|
|
|
|
+ host_type == mojom::ViewType::kExtensionPopup);
|
2017-08-04 00:55:19 +02:00
|
|
|
+
|
|
|
|
+ content::WebContentsObserver::Observe(host_contents_);
|
|
|
|
+ SetViewType(host_contents_, host_type);
|
|
|
|
+
|
2021-03-04 23:36:57 +01:00
|
|
|
+ main_frame_host_ = host_contents_->GetMainFrame();
|
2017-08-04 00:55:19 +02:00
|
|
|
+
|
|
|
|
+ // 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
|
2021-04-21 00:52:34 +02:00
|
|
|
index 305726557f2ea..caa4b798a013e 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.h
|
|
|
|
+++ extensions/browser/extension_host.h
|
2021-04-21 00:52:34 +02:00
|
|
|
@@ -53,13 +53,19 @@ class ExtensionHost : public DeferredStartRenderHost,
|
2017-08-04 00:55:19 +02:00
|
|
|
content::SiteInstance* site_instance,
|
2021-04-21 00:52:34 +02:00
|
|
|
const GURL& url,
|
|
|
|
mojom::ViewType host_type);
|
2017-08-04 00:55:19 +02:00
|
|
|
+ ExtensionHost(ExtensionHostDelegate* delegate,
|
|
|
|
+ const Extension* extension,
|
|
|
|
+ content::BrowserContext* browser_context,
|
|
|
|
+ content::WebContents* host_contents,
|
|
|
|
+ const GURL& url,
|
2021-04-21 00:52:34 +02:00
|
|
|
+ mojom::ViewType host_type);
|
2017-08-04 00:55:19 +02:00
|
|
|
~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_; }
|
2021-03-04 23:36:57 +01:00
|
|
|
content::RenderFrameHost* main_frame_host() const { return main_frame_host_; }
|
2017-08-04 00:55:19 +02:00
|
|
|
content::RenderProcessHost* render_process_host() const;
|
|
|
|
bool has_loaded_once() const { return has_loaded_once_; }
|
2021-04-21 00:52:34 +02:00
|
|
|
@@ -182,7 +188,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_;
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
// A pointer to the current or speculative main frame in `host_contents_`. We
|
|
|
|
// can't access this frame through the `host_contents_` directly as it does
|
2017-08-04 00:55:19 +02:00
|
|
|
diff --git extensions/browser/extensions_browser_client.h extensions/browser/extensions_browser_client.h
|
2021-06-04 03:34:56 +02:00
|
|
|
index 216e445c0488b..cd6502cc3f059 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extensions_browser_client.h
|
|
|
|
+++ extensions/browser/extensions_browser_client.h
|
2021-01-28 00:13:12 +01:00
|
|
|
@@ -27,6 +27,7 @@
|
|
|
|
#include "ui/base/page_transition_types.h"
|
|
|
|
|
|
|
|
class ExtensionFunctionRegistry;
|
|
|
|
+class GURL;
|
|
|
|
class PrefService;
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
@@ -62,6 +63,7 @@ class ComponentExtensionResourceManager;
|
2017-08-04 00:55:19 +02:00
|
|
|
class Extension;
|
|
|
|
class ExtensionCache;
|
|
|
|
class ExtensionError;
|
|
|
|
+class ExtensionHost;
|
|
|
|
class ExtensionHostDelegate;
|
2019-10-01 15:55:16 +02:00
|
|
|
class ExtensionSet;
|
|
|
|
class ExtensionSystem;
|
2021-01-28 00:13:12 +01:00
|
|
|
@@ -204,6 +206,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
|
2021-06-04 03:34:56 +02:00
|
|
|
index 0bf4809cb6f60..fccf3478b8669 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/process_manager.cc
|
|
|
|
+++ extensions/browser/process_manager.cc
|
2021-06-04 03:34:56 +02:00
|
|
|
@@ -393,9 +393,17 @@ 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 =
|
|
|
|
+ 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) {
|
2021-04-21 00:52:34 +02:00
|
|
|
+ host =
|
|
|
|
new ExtensionHost(extension, GetSiteInstanceForURL(url).get(), url,
|
|
|
|
mojom::ViewType::kExtensionBackgroundPage);
|
2017-08-04 00:55:19 +02:00
|
|
|
+ }
|
2021-03-04 23:36:57 +01:00
|
|
|
host->CreateRendererSoon();
|
2017-08-04 00:55:19 +02:00
|
|
|
OnBackgroundHostCreated(host);
|
|
|
|
return true;
|