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
|
2022-09-26 21:30:45 +02:00
|
|
|
index cead7cfa14bae..24142c2e4896f 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"
|
2022-07-25 19:49:32 +02:00
|
|
|
#include "chrome/browser/preloading/prefetch/no_state_prefetch/chrome_no_state_prefetch_contents_delegate.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "components/no_state_prefetch/browser/no_state_prefetch_contents.h"
|
2021-06-16 21:54:26 +02:00
|
|
|
@@ -18,6 +19,10 @@
|
|
|
|
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
|
|
|
|
#include "extensions/common/manifest_handlers/mime_types_handler.h"
|
|
|
|
|
|
|
|
+#if BUILDFLAG(ENABLE_CEF)
|
|
|
|
+#include "cef/libcef/browser/extensions/alloy_extensions_util.h"
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
2022-04-21 20:58:48 +02:00
|
|
|
@@ -34,6 +39,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.
|
2022-04-21 20:58:48 +02:00
|
|
|
@@ -44,6 +50,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
2021-03-04 23:36:57 +01:00
|
|
|
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
|
|
|
|
2022-04-21 20:58:48 +02:00
|
|
|
@@ -70,9 +77,18 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
2021-06-16 21:54:26 +02:00
|
|
|
// forms of zooming won't work).
|
|
|
|
// TODO(1042323): Present a coherent representation of a tab id for portal
|
|
|
|
// contents.
|
|
|
|
- int tab_id = web_contents->GetOuterWebContents()
|
|
|
|
- ? SessionID::InvalidValue().id()
|
|
|
|
- : ExtensionTabUtil::GetTabId(web_contents);
|
|
|
|
+ int tab_id;
|
|
|
|
+ if (web_contents->GetOuterWebContents()) {
|
|
|
|
+ tab_id = SessionID::InvalidValue().id();
|
|
|
|
+ } else
|
|
|
|
+#if BUILDFLAG(ENABLE_CEF)
|
|
|
|
+ if (cef::IsAlloyRuntimeEnabled()) {
|
|
|
|
+ tab_id = alloy::GetTabIdForWebContents(web_contents);
|
|
|
|
+ } else
|
|
|
|
+#endif // BUILDFLAG(ENABLE_CEF)
|
|
|
|
+ {
|
|
|
|
+ tab_id = ExtensionTabUtil::GetTabId(web_contents);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
std::unique_ptr<StreamContainer> stream_container(
|
|
|
|
new StreamContainer(tab_id, embedded, handler_url, extension_id,
|
2017-08-04 00:55:19 +02:00
|
|
|
diff --git extensions/browser/extension_host.cc extensions/browser/extension_host.cc
|
2023-02-27 19:52:38 +01:00
|
|
|
index 91928c8b7811e..a9c5913f4f5d0 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.cc
|
|
|
|
+++ extensions/browser/extension_host.cc
|
2023-01-03 00:34:43 +01:00
|
|
|
@@ -62,11 +62,12 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
2021-04-21 00:52:34 +02:00
|
|
|
host_type == mojom::ViewType::kExtensionDialog ||
|
2023-01-03 00:34:43 +01:00
|
|
|
host_type == mojom::ViewType::kExtensionPopup ||
|
|
|
|
host_type == mojom::ViewType::kExtensionSidePanel);
|
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);
|
2022-06-17 15:28:55 +02:00
|
|
|
main_frame_host_ = host_contents_->GetPrimaryMainFrame();
|
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
|
2023-01-03 00:34:43 +01:00
|
|
|
@@ -81,6 +82,44 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
2021-10-19 00:17:16 +02:00
|
|
|
ExtensionHostRegistry::Get(browser_context_)->ExtensionHostCreated(this);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+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);
|
|
|
|
+
|
2022-07-21 19:26:10 +02:00
|
|
|
+ main_frame_host_ = host_contents_->GetPrimaryMainFrame();
|
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
|
2023-01-30 18:43:54 +01:00
|
|
|
index 9ba85048d1fcf..f3a5b8bc9bda0 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.h
|
|
|
|
+++ extensions/browser/extension_host.h
|
2023-01-03 00:34:43 +01:00
|
|
|
@@ -59,6 +59,12 @@ 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
|
|
|
|
2021-10-19 00:17:16 +02:00
|
|
|
ExtensionHost(const ExtensionHost&) = delete;
|
|
|
|
ExtensionHost& operator=(const ExtensionHost&) = delete;
|
2023-01-03 00:34:43 +01:00
|
|
|
@@ -69,7 +75,7 @@ class ExtensionHost : public DeferredStartRenderHost,
|
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_; }
|
2023-01-03 00:34:43 +01:00
|
|
|
@@ -205,7 +211,8 @@ class ExtensionHost : public DeferredStartRenderHost,
|
2021-12-16 23:35:54 +01:00
|
|
|
raw_ptr<content::BrowserContext> browser_context_;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// 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
|
2023-01-05 19:55:00 +01:00
|
|
|
diff --git extensions/browser/extension_registry.cc extensions/browser/extension_registry.cc
|
2023-04-04 20:00:13 +02:00
|
|
|
index c3197eb4790fa..1e7ae767b0582 100644
|
2023-01-05 19:55:00 +01:00
|
|
|
--- extensions/browser/extension_registry.cc
|
|
|
|
+++ extensions/browser/extension_registry.cc
|
|
|
|
@@ -6,9 +6,14 @@
|
|
|
|
|
|
|
|
#include "base/observer_list.h"
|
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
+#include "cef/libcef/features/runtime.h"
|
|
|
|
#include "extensions/browser/extension_registry_factory.h"
|
|
|
|
#include "extensions/browser/extension_registry_observer.h"
|
|
|
|
|
|
|
|
+#if BUILDFLAG(ENABLE_CEF)
|
|
|
|
+#include "cef/libcef/common/extensions/extensions_util.h"
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
ExtensionRegistry::ExtensionRegistry(content::BrowserContext* browser_context)
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -17,6 +22,11 @@ ExtensionRegistry::~ExtensionRegistry() = default;
|
2023-01-05 19:55:00 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) {
|
|
|
|
+#if BUILDFLAG(ENABLE_CEF)
|
|
|
|
+ if (cef::IsAlloyRuntimeEnabled() && !extensions::ExtensionsEnabled()) {
|
|
|
|
+ return nullptr;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
return ExtensionRegistryFactory::GetForBrowserContext(context);
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
diff --git extensions/browser/extensions_browser_client.h extensions/browser/extensions_browser_client.h
|
2023-02-27 19:52:38 +01:00
|
|
|
index 2b0287529078a..e4144e0755e4b 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extensions_browser_client.h
|
|
|
|
+++ extensions/browser/extensions_browser_client.h
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -30,6 +30,7 @@
|
2022-03-26 02:12:30 +01:00
|
|
|
#include "url/gurl.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
|
|
|
|
class ExtensionFunctionRegistry;
|
|
|
|
+class GURL;
|
|
|
|
class PrefService;
|
|
|
|
|
|
|
|
namespace base {
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -74,6 +75,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;
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -249,6 +251,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
|
2023-02-27 19:52:38 +01:00
|
|
|
index 115f31f9ce46d..914b2564d5a21 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/process_manager.cc
|
|
|
|
+++ extensions/browser/process_manager.cc
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -379,9 +379,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
|
|
|
+ }
|
2022-07-21 19:26:10 +02:00
|
|
|
host->SetCloseHandler(
|
|
|
|
base::BindOnce(&ProcessManager::HandleCloseExtensionHost,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2023-01-05 19:55:00 +01:00
|
|
|
diff --git extensions/common/extensions_client.cc extensions/common/extensions_client.cc
|
2023-04-04 20:00:13 +02:00
|
|
|
index a8108350ddde2..7ae49e78b4327 100644
|
2023-01-05 19:55:00 +01:00
|
|
|
--- extensions/common/extensions_client.cc
|
|
|
|
+++ extensions/common/extensions_client.cc
|
|
|
|
@@ -23,7 +23,7 @@ ExtensionsClient* g_client = nullptr;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ExtensionsClient* ExtensionsClient::Get() {
|
|
|
|
- DCHECK(g_client);
|
|
|
|
+ // May be nullptr if using CEF Alloy with extensions disabled.
|
|
|
|
return g_client;
|
|
|
|
}
|
|
|
|
|