forked from chromiumembedded/cef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions_1947.patch
186 lines (170 loc) · 7.93 KB
/
extensions_1947.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
diff --git chrome/browser/extensions/api/streams_private/streams_private_api.cc chrome/browser/extensions/api/streams_private/streams_private_api.cc
index 5c903a13a14ed..d385c6c0c95c4 100644
--- chrome/browser/extensions/api/streams_private/streams_private_api.cc
+++ chrome/browser/extensions/api/streams_private/streams_private_api.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "cef/libcef/features/runtime.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#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"
@@ -42,6 +43,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
if (!web_contents)
return;
+ if (!cef::IsAlloyRuntimeEnabled()) {
// If the request was for NoStatePrefetch, abort the prefetcher and do not
// continue. This is because plugins cancel NoStatePrefetch, see
// http://crbug.com/343590.
@@ -52,6 +54,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
no_state_prefetch_contents->Destroy(prerender::FINAL_STATUS_DOWNLOAD);
return;
}
+ }
auto* browser_context = web_contents->GetBrowserContext();
diff --git extensions/browser/extension_host.cc extensions/browser/extension_host.cc
index 231a3b6c8ce1d..14776d981f506 100644
--- extensions/browser/extension_host.cc
+++ extensions/browser/extension_host.cc
@@ -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);
- host_contents_ = WebContents::Create(
+ host_contents_owned_ = WebContents::Create(
WebContents::CreateParams(browser_context_, site_instance)),
- content::WebContentsObserver::Observe(host_contents_.get());
+ 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);
main_frame_host_ = host_contents_->GetMainFrame();
// Listen for when an extension is unloaded from the same profile, as it may
@@ -81,6 +82,44 @@ ExtensionHost::ExtensionHost(const Extension* extension,
dispatcher()->set_delegate(this);
}
+ExtensionHost::ExtensionHost(ExtensionHostDelegate* delegate,
+ const Extension* extension,
+ content::BrowserContext* browser_context,
+ content::WebContents* host_contents,
+ const GURL& url,
+ mojom::ViewType host_type)
+ : 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.
+ DCHECK(host_type == mojom::ViewType::kExtensionBackgroundPage ||
+ host_type == mojom::ViewType::kExtensionDialog ||
+ host_type == mojom::ViewType::kExtensionPopup);
+
+ content::WebContentsObserver::Observe(host_contents_);
+ SetViewType(host_contents_, host_type);
+
+ main_frame_host_ = host_contents_->GetMainFrame();
+
+ // 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
index 305726557f2ea..caa4b798a013e 100644
--- extensions/browser/extension_host.h
+++ extensions/browser/extension_host.h
@@ -53,13 +53,19 @@ class ExtensionHost : public DeferredStartRenderHost,
content::SiteInstance* site_instance,
const GURL& url,
mojom::ViewType host_type);
+ ExtensionHost(ExtensionHostDelegate* delegate,
+ const Extension* extension,
+ content::BrowserContext* browser_context,
+ content::WebContents* host_contents,
+ const GURL& url,
+ mojom::ViewType host_type);
~ExtensionHost() override;
// This may be null if the extension has been or is being unloaded.
const Extension* extension() const { return extension_; }
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::RenderFrameHost* main_frame_host() const { return main_frame_host_; }
content::RenderProcessHost* render_process_host() const;
bool has_loaded_once() const { return has_loaded_once_; }
@@ -182,7 +188,8 @@ class ExtensionHost : public DeferredStartRenderHost,
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 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
diff --git extensions/browser/extensions_browser_client.h extensions/browser/extensions_browser_client.h
index 7eb3d073c7b79..3844a9c6033a5 100644
--- extensions/browser/extensions_browser_client.h
+++ extensions/browser/extensions_browser_client.h
@@ -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;
class Extension;
class ExtensionCache;
class ExtensionError;
+class ExtensionHost;
class ExtensionHostDelegate;
class ExtensionSet;
class ExtensionSystem;
@@ -204,6 +206,14 @@ class ExtensionsBrowserClient {
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
index 26bff09c646be..830ff12c5fc9c 100644
--- extensions/browser/process_manager.cc
+++ extensions/browser/process_manager.cc
@@ -392,9 +392,17 @@ bool ProcessManager::CreateBackgroundHost(const Extension* extension,
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) {
+ host =
new ExtensionHost(extension, GetSiteInstanceForURL(url).get(), url,
mojom::ViewType::kExtensionBackgroundPage);
+ }
host->CreateRendererSoon();
OnBackgroundHostCreated(host);
return true;