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
|
2024-02-22 19:36:15 +01:00
|
|
|
index 5ee79cf7fefb1..a84750a496095 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"
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -27,6 +28,10 @@
|
2023-12-06 21:16:15 +01:00
|
|
|
#include "pdf/pdf_features.h"
|
|
|
|
#endif // BUILDFLAG(ENABLE_PDF)
|
2021-06-16 21:54:26 +02:00
|
|
|
|
|
|
|
+#if BUILDFLAG(ENABLE_CEF)
|
|
|
|
+#include "cef/libcef/browser/extensions/alloy_extensions_util.h"
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -44,6 +49,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.
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -54,6 +60,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
|
|
|
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -80,9 +87,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
|
2024-02-22 19:36:15 +01:00
|
|
|
index 0035aedce82f0..861288525b291 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.cc
|
|
|
|
+++ extensions/browser/extension_host.cc
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -104,12 +104,13 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
2023-11-21 20:17:55 +01:00
|
|
|
host_type == mojom::ViewType::kOffscreenDocument ||
|
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(
|
2023-10-19 20:08:48 +02:00
|
|
|
WebContents::CreateParams(browser_context_, site_instance));
|
2017-08-04 00:55:19 +02:00
|
|
|
+ host_contents_ = host_contents_owned_.get();
|
2023-10-19 20:08:48 +02:00
|
|
|
host_contents_->SetOwnerLocationForDebug(FROM_HERE);
|
|
|
|
- content::WebContentsObserver::Observe(host_contents_.get());
|
2017-08-04 00:55:19 +02:00
|
|
|
+ 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
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -125,11 +126,49 @@ ExtensionHost::ExtensionHost(const Extension* extension,
|
2023-04-26 21:55:59 +02:00
|
|
|
// Create password reuse detection manager when new extension web contents are
|
|
|
|
// created.
|
|
|
|
ExtensionsBrowserClient::Get()->CreatePasswordReuseDetectionManager(
|
|
|
|
- host_contents_.get());
|
|
|
|
+ host_contents_);
|
|
|
|
|
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);
|
|
|
|
+
|
2021-04-21 00:52:34 +02:00
|
|
|
+ DCHECK(host_type == mojom::ViewType::kExtensionBackgroundPage ||
|
2023-11-21 20:17:55 +01:00
|
|
|
+ host_type == mojom::ViewType::kOffscreenDocument ||
|
|
|
|
+ host_type == mojom::ViewType::kExtensionPopup ||
|
|
|
|
+ host_type == mojom::ViewType::kExtensionSidePanel);
|
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
|
2024-02-22 19:36:15 +01:00
|
|
|
index 28ba09319b047..2a097a5ae4c16 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extension_host.h
|
|
|
|
+++ extensions/browser/extension_host.h
|
2023-09-15 21:51:43 +02:00
|
|
|
@@ -62,6 +62,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-09-15 21:51:43 +02:00
|
|
|
@@ -72,7 +78,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
|
|
|
|
2023-09-15 21:51:43 +02:00
|
|
|
const ExtensionId& extension_id() const { return extension_id_; }
|
2017-08-04 00:55:19 +02:00
|
|
|
- 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_; }
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -244,7 +250,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
|
2024-02-22 19:36:15 +01:00
|
|
|
index 1be758c66fe70..62f72c7c119d0 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/extensions_browser_client.h
|
|
|
|
+++ extensions/browser/extensions_browser_client.h
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -34,6 +34,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 {
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -82,6 +83,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;
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -272,6 +274,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
|
2024-02-22 19:36:15 +01:00
|
|
|
index 3363f44f7c4fc..3eec0356c0c58 100644
|
2017-08-04 00:55:19 +02:00
|
|
|
--- extensions/browser/process_manager.cc
|
|
|
|
+++ extensions/browser/process_manager.cc
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -353,9 +353,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
|
2024-01-26 03:12:43 +01:00
|
|
|
index 5142f341b8392..d3242aae96ece 100644
|
2023-01-05 19:55:00 +01:00
|
|
|
--- extensions/common/extensions_client.cc
|
|
|
|
+++ extensions/common/extensions_client.cc
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -25,7 +25,7 @@ ExtensionsClient* g_client = nullptr;
|
2023-01-05 19:55:00 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ExtensionsClient* ExtensionsClient::Get() {
|
|
|
|
- DCHECK(g_client);
|
|
|
|
+ // May be nullptr if using CEF Alloy with extensions disabled.
|
|
|
|
return g_client;
|
|
|
|
}
|
|
|
|
|