OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/browser_process.h" | |
17 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 17 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
19 #include "chrome/browser/extensions/extension_host.h" | 18 #include "chrome/browser/extensions/extension_host.h" |
20 #include "chrome/browser/extensions/extension_info_map.h" | 19 #include "chrome/browser/extensions/extension_info_map.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
23 #include "chrome/browser/extensions/extension_util.h" | 22 #include "chrome/browser/extensions/extension_util.h" |
24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | |
26 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_finder.h" | |
28 #include "chrome/common/chrome_switches.h" | |
29 #include "chrome/common/extensions/background_info.h" | 25 #include "chrome/common/extensions/background_info.h" |
30 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
32 #include "chrome/common/extensions/incognito_handler.h" | 28 #include "chrome/common/extensions/incognito_handler.h" |
33 #include "chrome/common/extensions/manifest_url_handler.h" | 29 #include "chrome/common/extensions/manifest_url_handler.h" |
34 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
35 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/devtools_agent_host.h" | 32 #include "content/public/browser/devtools_agent_host.h" |
37 #include "content/public/browser/devtools_manager.h" | 33 #include "content/public/browser/devtools_manager.h" |
38 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
40 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
41 #include "content/public/browser/site_instance.h" | 37 #include "content/public/browser/site_instance.h" |
42 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
43 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
44 #include "content/public/browser/web_contents_observer.h" | 40 #include "content/public/browser/web_contents_observer.h" |
45 #include "content/public/browser/web_contents_user_data.h" | 41 #include "content/public/browser/web_contents_user_data.h" |
46 #include "content/public/common/renderer_preferences.h" | 42 #include "content/public/common/renderer_preferences.h" |
| 43 #include "extensions/browser/extensions_browser_client.h" |
47 #include "extensions/browser/view_type_utils.h" | 44 #include "extensions/browser/view_type_utils.h" |
| 45 #include "extensions/common/switches.h" |
48 | 46 |
49 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
50 #include "chrome/browser/extensions/extension_host_mac.h" | 48 #include "chrome/browser/extensions/extension_host_mac.h" |
51 #endif | 49 #endif |
52 | 50 |
| 51 using content::BrowserContext; |
53 using content::RenderViewHost; | 52 using content::RenderViewHost; |
54 using content::SiteInstance; | 53 using content::SiteInstance; |
55 using content::WebContents; | 54 using content::WebContents; |
56 using extensions::BackgroundInfo; | 55 using extensions::BackgroundInfo; |
57 using extensions::BackgroundManifestHandler; | 56 using extensions::BackgroundManifestHandler; |
58 using extensions::Extension; | 57 using extensions::Extension; |
59 using extensions::ExtensionHost; | 58 using extensions::ExtensionHost; |
| 59 using extensions::ExtensionsBrowserClient; |
| 60 using extensions::ExtensionSystem; |
60 | 61 |
61 class RenderViewHostDestructionObserver; | 62 class RenderViewHostDestructionObserver; |
62 DEFINE_WEB_CONTENTS_USER_DATA_KEY(RenderViewHostDestructionObserver); | 63 DEFINE_WEB_CONTENTS_USER_DATA_KEY(RenderViewHostDestructionObserver); |
63 | 64 |
64 namespace { | 65 namespace { |
65 | 66 |
66 std::string GetExtensionID(RenderViewHost* render_view_host) { | 67 std::string GetExtensionID(RenderViewHost* render_view_host) { |
67 // This works for both apps and extensions because the site has been | 68 // This works for both apps and extensions because the site has been |
68 // normalized to the extension URL for apps. | 69 // normalized to the extension URL for apps. |
69 if (!render_view_host->GetSiteInstance()) | 70 if (!render_view_host->GetSiteInstance()) |
70 return std::string(); | 71 return std::string(); |
71 | 72 |
72 return render_view_host->GetSiteInstance()->GetSiteURL().host(); | 73 return render_view_host->GetSiteInstance()->GetSiteURL().host(); |
73 } | 74 } |
74 | 75 |
75 void OnRenderViewHostUnregistered(Profile* profile, | 76 void OnRenderViewHostUnregistered(BrowserContext* context, |
76 RenderViewHost* render_view_host) { | 77 RenderViewHost* render_view_host) { |
77 content::NotificationService::current()->Notify( | 78 content::NotificationService::current()->Notify( |
78 chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, | 79 chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, |
79 content::Source<Profile>(profile), | 80 content::Source<BrowserContext>(context), |
80 content::Details<RenderViewHost>(render_view_host)); | 81 content::Details<RenderViewHost>(render_view_host)); |
81 } | 82 } |
82 | 83 |
83 // Incognito profiles use this process manager. It is mostly a shim that decides | 84 // Incognito profiles use this process manager. It is mostly a shim that decides |
84 // whether to fall back on the original profile's ExtensionProcessManager based | 85 // whether to fall back on the original profile's ExtensionProcessManager based |
85 // on whether a given extension uses "split" or "spanning" incognito behavior. | 86 // on whether a given extension uses "split" or "spanning" incognito behavior. |
86 class IncognitoExtensionProcessManager : public ExtensionProcessManager { | 87 class IncognitoExtensionProcessManager : public ExtensionProcessManager { |
87 public: | 88 public: |
88 explicit IncognitoExtensionProcessManager(Profile* profile); | 89 IncognitoExtensionProcessManager(BrowserContext* incognito_context, |
| 90 BrowserContext* original_context); |
89 virtual ~IncognitoExtensionProcessManager(); | 91 virtual ~IncognitoExtensionProcessManager(); |
90 virtual ExtensionHost* CreateViewHost( | 92 virtual ExtensionHost* CreateViewHost( |
91 const Extension* extension, | 93 const Extension* extension, |
92 const GURL& url, | 94 const GURL& url, |
93 Browser* browser, | 95 Browser* browser, |
94 extensions::ViewType view_type) OVERRIDE; | 96 extensions::ViewType view_type) OVERRIDE; |
95 virtual ExtensionHost* CreateBackgroundHost(const Extension* extension, | 97 virtual ExtensionHost* CreateBackgroundHost(const Extension* extension, |
96 const GURL& url) OVERRIDE; | 98 const GURL& url) OVERRIDE; |
97 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url) OVERRIDE; | 99 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url) OVERRIDE; |
98 | 100 |
99 private: | 101 private: |
100 // content::NotificationObserver: | 102 // content::NotificationObserver: |
101 virtual void Observe(int type, | 103 virtual void Observe(int type, |
102 const content::NotificationSource& source, | 104 const content::NotificationSource& source, |
103 const content::NotificationDetails& details) OVERRIDE; | 105 const content::NotificationDetails& details) OVERRIDE; |
104 | 106 |
105 // Returns true if the extension is allowed to run in incognito mode. | 107 // Returns true if the extension is allowed to run in incognito mode. |
106 bool IsIncognitoEnabled(const Extension* extension); | 108 bool IsIncognitoEnabled(const Extension* extension); |
107 | 109 |
108 ExtensionProcessManager* original_manager_; | 110 ExtensionProcessManager* original_manager_; |
109 }; | 111 }; |
110 | 112 |
111 static void CreateBackgroundHostForExtensionLoad( | 113 static void CreateBackgroundHostForExtensionLoad( |
112 ExtensionProcessManager* manager, const Extension* extension) { | 114 ExtensionProcessManager* manager, const Extension* extension) { |
| 115 DVLOG(1) << "CreateBackgroundHostForExtensionLoad"; |
113 if (BackgroundInfo::HasPersistentBackgroundPage(extension)) | 116 if (BackgroundInfo::HasPersistentBackgroundPage(extension)) |
114 manager->CreateBackgroundHost(extension, | 117 manager->CreateBackgroundHost(extension, |
115 BackgroundInfo::GetBackgroundURL(extension)); | 118 BackgroundInfo::GetBackgroundURL(extension)); |
116 } | 119 } |
117 | 120 |
118 } // namespace | 121 } // namespace |
119 | 122 |
120 class RenderViewHostDestructionObserver | 123 class RenderViewHostDestructionObserver |
121 : public content::WebContentsObserver, | 124 : public content::WebContentsObserver, |
122 public content::WebContentsUserData<RenderViewHostDestructionObserver> { | 125 public content::WebContentsUserData<RenderViewHostDestructionObserver> { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 166 |
164 BackgroundPageData() | 167 BackgroundPageData() |
165 : lazy_keepalive_count(0), close_sequence_id(0), is_closing(false) {} | 168 : lazy_keepalive_count(0), close_sequence_id(0), is_closing(false) {} |
166 }; | 169 }; |
167 | 170 |
168 // | 171 // |
169 // ExtensionProcessManager | 172 // ExtensionProcessManager |
170 // | 173 // |
171 | 174 |
172 // static | 175 // static |
173 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { | 176 ExtensionProcessManager* ExtensionProcessManager::Create( |
174 return (profile->IsOffTheRecord()) ? | 177 BrowserContext* context) { |
175 new IncognitoExtensionProcessManager(profile) : | 178 if (context->IsOffTheRecord()) { |
176 new ExtensionProcessManager(profile); | 179 BrowserContext* original_context = |
| 180 ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
| 181 return new IncognitoExtensionProcessManager(context, original_context); |
| 182 } |
| 183 return new ExtensionProcessManager(context, context); |
177 } | 184 } |
178 | 185 |
179 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) | 186 ExtensionProcessManager::ExtensionProcessManager( |
180 : site_instance_(SiteInstance::Create(profile)), | 187 BrowserContext* context, |
| 188 BrowserContext* original_context) |
| 189 : site_instance_(SiteInstance::Create(context)), |
181 defer_background_host_creation_(false), | 190 defer_background_host_creation_(false), |
182 weak_ptr_factory_(this), | |
183 devtools_callback_(base::Bind( | 191 devtools_callback_(base::Bind( |
184 &ExtensionProcessManager::OnDevToolsStateChanged, | 192 &ExtensionProcessManager::OnDevToolsStateChanged, |
185 base::Unretained(this))) { | 193 base::Unretained(this))), |
186 Profile* original_profile = profile->GetOriginalProfile(); | 194 weak_ptr_factory_(this) { |
187 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 195 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
188 content::NotificationService::AllSources()); | 196 content::NotificationService::AllSources()); |
189 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
190 content::Source<Profile>(original_profile)); | 198 content::Source<BrowserContext>(original_context)); |
191 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 199 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
192 content::Source<Profile>(original_profile)); | 200 content::Source<BrowserContext>(original_context)); |
193 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 201 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
194 content::Source<Profile>(original_profile)); | 202 content::Source<BrowserContext>(original_context)); |
195 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 203 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
196 content::Source<Profile>(profile)); | 204 content::Source<BrowserContext>(context)); |
197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
198 content::Source<Profile>(profile)); | 206 content::Source<BrowserContext>(context)); |
199 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 207 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
200 content::NotificationService::AllSources()); | 208 content::NotificationService::AllSources()); |
201 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 209 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
202 content::NotificationService::AllSources()); | 210 content::NotificationService::AllSources()); |
203 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 211 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
204 content::Source<Profile>(original_profile)); | 212 content::Source<BrowserContext>(original_context)); |
205 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 213 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
206 content::Source<Profile>(profile)); | 214 content::Source<BrowserContext>(context)); |
207 if (profile->IsOffTheRecord()) { | 215 if (context->IsOffTheRecord()) { |
208 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 216 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
209 content::Source<Profile>(original_profile)); | 217 content::Source<BrowserContext>(original_context)); |
210 } | 218 } |
211 | 219 |
212 event_page_idle_time_ = base::TimeDelta::FromSeconds(10); | 220 event_page_idle_time_ = base::TimeDelta::FromSeconds(10); |
213 unsigned idle_time_sec = 0; | 221 unsigned idle_time_sec = 0; |
214 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 222 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
215 switches::kEventPageIdleTime), &idle_time_sec)) { | 223 extensions::switches::kEventPageIdleTime), &idle_time_sec)) { |
216 event_page_idle_time_ = base::TimeDelta::FromSeconds(idle_time_sec); | 224 event_page_idle_time_ = base::TimeDelta::FromSeconds(idle_time_sec); |
217 } | 225 } |
218 event_page_suspending_time_ = base::TimeDelta::FromSeconds(5); | 226 event_page_suspending_time_ = base::TimeDelta::FromSeconds(5); |
219 unsigned suspending_time_sec = 0; | 227 unsigned suspending_time_sec = 0; |
220 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 228 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
221 switches::kEventPageSuspendingTime), &suspending_time_sec)) { | 229 extensions::switches::kEventPageSuspendingTime), |
222 event_page_suspending_time_ = base::TimeDelta::FromSeconds( | 230 &suspending_time_sec)) { |
223 suspending_time_sec); | 231 event_page_suspending_time_ = |
| 232 base::TimeDelta::FromSeconds(suspending_time_sec); |
224 } | 233 } |
225 | 234 |
226 content::DevToolsManager::GetInstance()->AddAgentStateCallback( | 235 content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
227 devtools_callback_); | 236 devtools_callback_); |
228 } | 237 } |
229 | 238 |
230 ExtensionProcessManager::~ExtensionProcessManager() { | 239 ExtensionProcessManager::~ExtensionProcessManager() { |
231 CloseBackgroundHosts(); | 240 CloseBackgroundHosts(); |
232 DCHECK(background_hosts_.empty()); | 241 DCHECK(background_hosts_.empty()); |
233 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( | 242 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
234 devtools_callback_); | 243 devtools_callback_); |
235 } | 244 } |
236 | 245 |
237 const ExtensionProcessManager::ViewSet | 246 const ExtensionProcessManager::ViewSet |
238 ExtensionProcessManager::GetAllViews() const { | 247 ExtensionProcessManager::GetAllViews() const { |
239 ViewSet result; | 248 ViewSet result; |
240 for (ExtensionRenderViews::const_iterator iter = | 249 for (ExtensionRenderViews::const_iterator iter = |
241 all_extension_views_.begin(); | 250 all_extension_views_.begin(); |
242 iter != all_extension_views_.end(); ++iter) { | 251 iter != all_extension_views_.end(); ++iter) { |
243 result.insert(iter->first); | 252 result.insert(iter->first); |
244 } | 253 } |
245 return result; | 254 return result; |
246 } | 255 } |
247 | 256 |
248 void ExtensionProcessManager::EnsureBrowserWhenRequired( | 257 void ExtensionProcessManager::EnsureBrowserWhenRequired( |
249 Browser* browser, | 258 Browser* browser, |
250 extensions::ViewType view_type) { | 259 extensions::ViewType view_type) { |
251 if (!browser) { | 260 if (!browser) { |
252 #if defined (OS_CHROMEOS) | 261 // A NULL browser may only be given for pop-up views and dialogs. |
253 // On ChromeOS we'll only use ExtensionView, which | 262 DCHECK(view_type == extensions::VIEW_TYPE_EXTENSION_POPUP || |
254 // does not use the browser parameter. | 263 view_type == extensions::VIEW_TYPE_EXTENSION_DIALOG); |
255 // TODO(rkc): Remove all this once we create a new host for | |
256 // screensaver extensions (crosbug.com/28211). | |
257 DCHECK(view_type == extensions::VIEW_TYPE_EXTENSION_POPUP || | |
258 view_type == extensions::VIEW_TYPE_EXTENSION_DIALOG); | |
259 #else | |
260 // A NULL browser may only be given for pop-up views. | |
261 DCHECK(view_type == extensions::VIEW_TYPE_EXTENSION_POPUP); | |
262 #endif | |
263 } | 264 } |
264 } | 265 } |
265 | 266 |
266 ExtensionHost* ExtensionProcessManager::CreateViewHost( | 267 ExtensionHost* ExtensionProcessManager::CreateViewHost( |
267 const Extension* extension, | 268 const Extension* extension, |
268 const GURL& url, | 269 const GURL& url, |
269 Browser* browser, | 270 Browser* browser, |
270 extensions::ViewType view_type) { | 271 extensions::ViewType view_type) { |
| 272 DVLOG(1) << "CreateViewHost"; |
271 DCHECK(extension); | 273 DCHECK(extension); |
272 EnsureBrowserWhenRequired(browser, view_type); | 274 EnsureBrowserWhenRequired(browser, view_type); |
273 ExtensionHost* host = | 275 ExtensionHost* host = |
274 #if defined(OS_MACOSX) | 276 #if defined(OS_MACOSX) |
275 new extensions::ExtensionHostMac( | 277 new extensions::ExtensionHostMac( |
276 extension, GetSiteInstanceForURL(url), url, view_type); | 278 extension, GetSiteInstanceForURL(url), url, view_type); |
277 #else | 279 #else |
278 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); | 280 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); |
279 #endif | 281 #endif |
280 host->CreateView(browser); | 282 host->CreateView(browser); |
281 OnExtensionHostCreated(host, false); | 283 OnExtensionHostCreated(host, false); |
282 return host; | 284 return host; |
283 } | 285 } |
284 | 286 |
285 ExtensionHost* ExtensionProcessManager::CreateViewHost( | 287 ExtensionHost* ExtensionProcessManager::CreateViewHost( |
286 const GURL& url, Browser* browser, extensions::ViewType view_type) { | 288 const GURL& url, Browser* browser, extensions::ViewType view_type) { |
287 EnsureBrowserWhenRequired(browser, view_type); | 289 EnsureBrowserWhenRequired(browser, view_type); |
288 ExtensionService* service = GetProfile()->GetExtensionService(); | 290 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 291 GetBrowserContext())->extension_service(); |
289 if (service) { | 292 if (service) { |
290 std::string extension_id = url.host(); | 293 std::string extension_id = url.host(); |
291 if (url.SchemeIs(chrome::kChromeUIScheme) && | 294 if (url.SchemeIs(chrome::kChromeUIScheme) && |
292 url.host() == chrome::kChromeUIExtensionInfoHost) | 295 url.host() == chrome::kChromeUIExtensionInfoHost) |
293 extension_id = url.path().substr(1); | 296 extension_id = url.path().substr(1); |
294 const Extension* extension = | 297 const Extension* extension = |
295 service->extensions()->GetByID(extension_id); | 298 service->extensions()->GetByID(extension_id); |
296 if (extension) | 299 if (extension) |
297 return CreateViewHost(extension, url, browser, view_type); | 300 return CreateViewHost(extension, url, browser, view_type); |
298 } | 301 } |
(...skipping 21 matching lines...) Expand all Loading... |
320 extension, url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR); | 323 extension, url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR); |
321 } | 324 } |
322 | 325 |
323 ExtensionHost* ExtensionProcessManager::CreateInfobarHost( | 326 ExtensionHost* ExtensionProcessManager::CreateInfobarHost( |
324 const GURL& url, Browser* browser) { | 327 const GURL& url, Browser* browser) { |
325 return CreateViewHost(url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR); | 328 return CreateViewHost(url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR); |
326 } | 329 } |
327 | 330 |
328 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( | 331 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( |
329 const Extension* extension, const GURL& url) { | 332 const Extension* extension, const GURL& url) { |
| 333 DVLOG(1) << "CreateBackgroundHost " << url.spec(); |
330 // Hosted apps are taken care of from BackgroundContentsService. Ignore them | 334 // Hosted apps are taken care of from BackgroundContentsService. Ignore them |
331 // here. | 335 // here. |
332 if (extension->is_hosted_app()) | 336 if (extension->is_hosted_app()) |
333 return NULL; | 337 return NULL; |
334 | 338 |
335 // Don't create multiple background hosts for an extension. | 339 // Don't create multiple background hosts for an extension. |
336 if (ExtensionHost* host = GetBackgroundHostForExtension(extension->id())) | 340 if (ExtensionHost* host = GetBackgroundHostForExtension(extension->id())) |
337 return host; // TODO(kalman): return NULL here? It might break things... | 341 return host; // TODO(kalman): return NULL here? It might break things... |
338 | 342 |
339 ExtensionHost* host = | 343 ExtensionHost* host = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 384 } |
381 | 385 |
382 return result; | 386 return result; |
383 } | 387 } |
384 | 388 |
385 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( | 389 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( |
386 RenderViewHost* render_view_host) { | 390 RenderViewHost* render_view_host) { |
387 if (!render_view_host->GetSiteInstance()) | 391 if (!render_view_host->GetSiteInstance()) |
388 return NULL; | 392 return NULL; |
389 | 393 |
390 ExtensionService* service = | 394 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
391 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 395 GetBrowserContext())->extension_service(); |
392 if (!service) | 396 if (!service) |
393 return NULL; | 397 return NULL; |
394 | 398 |
395 return service->extensions()->GetByID(GetExtensionID(render_view_host)); | 399 return service->extensions()->GetByID(GetExtensionID(render_view_host)); |
396 } | 400 } |
397 | 401 |
398 void ExtensionProcessManager::UnregisterRenderViewHost( | 402 void ExtensionProcessManager::UnregisterRenderViewHost( |
399 RenderViewHost* render_view_host) { | 403 RenderViewHost* render_view_host) { |
400 ExtensionRenderViews::iterator view = | 404 ExtensionRenderViews::iterator view = |
401 all_extension_views_.find(render_view_host); | 405 all_extension_views_.find(render_view_host); |
402 if (view == all_extension_views_.end()) | 406 if (view == all_extension_views_.end()) |
403 return; | 407 return; |
404 | 408 |
405 OnRenderViewHostUnregistered(GetProfile(), render_view_host); | 409 OnRenderViewHostUnregistered(GetBrowserContext(), render_view_host); |
406 extensions::ViewType view_type = view->second; | 410 extensions::ViewType view_type = view->second; |
407 all_extension_views_.erase(view); | 411 all_extension_views_.erase(view); |
408 | 412 |
409 // Keepalive count, balanced in RegisterRenderViewHost. | 413 // Keepalive count, balanced in RegisterRenderViewHost. |
410 if (view_type != extensions::VIEW_TYPE_INVALID && | 414 if (view_type != extensions::VIEW_TYPE_INVALID && |
411 view_type != extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 415 view_type != extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
412 const Extension* extension = GetExtensionForRenderViewHost( | 416 const Extension* extension = GetExtensionForRenderViewHost( |
413 render_view_host); | 417 render_view_host); |
414 if (extension) | 418 if (extension) |
415 DecrementLazyKeepaliveCount(extension); | 419 DecrementLazyKeepaliveCount(extension); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 610 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
607 // If a window for this profile, or this profile's incognito profile, | 611 // If a window for this profile, or this profile's incognito profile, |
608 // has been opened, make sure this profile's background hosts have | 612 // has been opened, make sure this profile's background hosts have |
609 // been loaded. | 613 // been loaded. |
610 Browser* browser = content::Source<Browser>(source).ptr(); | 614 Browser* browser = content::Source<Browser>(source).ptr(); |
611 if (browser->profile() != GetProfile() && | 615 if (browser->profile() != GetProfile() && |
612 !(GetProfile()->HasOffTheRecordProfile() && | 616 !(GetProfile()->HasOffTheRecordProfile() && |
613 browser->profile() == GetProfile()->GetOffTheRecordProfile())) | 617 browser->profile() == GetProfile()->GetOffTheRecordProfile())) |
614 break; | 618 break; |
615 | 619 |
616 ExtensionService* service = GetProfile()->GetExtensionService(); | 620 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 621 GetBrowserContext())->extension_service(); |
617 if (!service || !service->is_ready()) | 622 if (!service || !service->is_ready()) |
618 break; | 623 break; |
619 | 624 |
620 CreateBackgroundHostsForProfileStartup(); | 625 CreateBackgroundHostsForProfileStartup(); |
621 break; | 626 break; |
622 } | 627 } |
623 case chrome::NOTIFICATION_EXTENSIONS_READY: | 628 case chrome::NOTIFICATION_EXTENSIONS_READY: |
624 case chrome::NOTIFICATION_PROFILE_CREATED: { | 629 case chrome::NOTIFICATION_PROFILE_CREATED: { |
625 CreateBackgroundHostsForProfileStartup(); | 630 CreateBackgroundHostsForProfileStartup(); |
626 break; | 631 break; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 break; | 678 break; |
674 } | 679 } |
675 | 680 |
676 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { | 681 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { |
677 // We get this notification both for new WebContents and when one | 682 // We get this notification both for new WebContents and when one |
678 // has its RenderViewHost replaced (e.g. when a user does a cross-site | 683 // has its RenderViewHost replaced (e.g. when a user does a cross-site |
679 // navigation away from an extension URL). For the replaced case, we must | 684 // navigation away from an extension URL). For the replaced case, we must |
680 // unregister the old RVH so it doesn't count as an active view that would | 685 // unregister the old RVH so it doesn't count as an active view that would |
681 // keep the event page alive. | 686 // keep the event page alive. |
682 WebContents* contents = content::Source<WebContents>(source).ptr(); | 687 WebContents* contents = content::Source<WebContents>(source).ptr(); |
683 if (contents->GetBrowserContext() != GetProfile()) | 688 if (contents->GetBrowserContext() != GetBrowserContext()) |
684 break; | 689 break; |
685 | 690 |
686 typedef std::pair<RenderViewHost*, RenderViewHost*> RVHPair; | 691 typedef std::pair<RenderViewHost*, RenderViewHost*> RVHPair; |
687 RVHPair* switched_details = content::Details<RVHPair>(details).ptr(); | 692 RVHPair* switched_details = content::Details<RVHPair>(details).ptr(); |
688 if (switched_details->first) | 693 if (switched_details->first) |
689 UnregisterRenderViewHost(switched_details->first); | 694 UnregisterRenderViewHost(switched_details->first); |
690 | 695 |
691 // The above will unregister a RVH when it gets swapped out with a new | 696 // The above will unregister a RVH when it gets swapped out with a new |
692 // one. However we need to watch the WebContents to know when a RVH is | 697 // one. However we need to watch the WebContents to know when a RVH is |
693 // deleted because the WebContents has gone away. | 698 // deleted because the WebContents has gone away. |
694 RenderViewHostDestructionObserver::CreateForWebContents(contents); | 699 RenderViewHostDestructionObserver::CreateForWebContents(contents); |
695 RegisterRenderViewHost(switched_details->second); | 700 RegisterRenderViewHost(switched_details->second); |
696 break; | 701 break; |
697 } | 702 } |
698 | 703 |
699 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { | 704 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { |
700 WebContents* contents = content::Source<WebContents>(source).ptr(); | 705 WebContents* contents = content::Source<WebContents>(source).ptr(); |
701 if (contents->GetBrowserContext() != GetProfile()) | 706 if (contents->GetBrowserContext() != GetBrowserContext()) |
702 break; | 707 break; |
703 const Extension* extension = GetExtensionForRenderViewHost( | 708 const Extension* extension = GetExtensionForRenderViewHost( |
704 contents->GetRenderViewHost()); | 709 contents->GetRenderViewHost()); |
705 if (!extension) | 710 if (!extension) |
706 return; | 711 return; |
707 | 712 |
708 // RegisterRenderViewHost is called too early (before the process is | 713 // RegisterRenderViewHost is called too early (before the process is |
709 // available), so we need to wait until now to notify. | 714 // available), so we need to wait until now to notify. |
710 content::NotificationService::current()->Notify( | 715 content::NotificationService::current()->Notify( |
711 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, | 716 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, |
712 content::Source<Profile>(GetProfile()), | 717 content::Source<BrowserContext>(GetBrowserContext()), |
713 content::Details<RenderViewHost>(contents->GetRenderViewHost())); | 718 content::Details<RenderViewHost>(contents->GetRenderViewHost())); |
714 break; | 719 break; |
715 } | 720 } |
716 | 721 |
717 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 722 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
718 // Close background hosts when the last browser is closed so that they | 723 // Close background hosts when the last browser is closed so that they |
719 // have time to shutdown various objects on different threads. Our | 724 // have time to shutdown various objects on different threads. Our |
720 // destructor is called too late in the shutdown sequence. | 725 // destructor is called too late in the shutdown sequence. |
721 CloseBackgroundHosts(); | 726 CloseBackgroundHosts(); |
722 break; | 727 break; |
723 } | 728 } |
724 | 729 |
725 default: | 730 default: |
726 NOTREACHED(); | 731 NOTREACHED(); |
727 } | 732 } |
728 } | 733 } |
729 | 734 |
730 void ExtensionProcessManager::OnDevToolsStateChanged( | 735 void ExtensionProcessManager::OnDevToolsStateChanged( |
731 content::DevToolsAgentHost* agent_host, bool attached) { | 736 content::DevToolsAgentHost* agent_host, bool attached) { |
732 RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 737 RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
733 // Ignore unrelated notifications. | 738 // Ignore unrelated notifications. |
734 if (!rvh || | 739 if (!rvh || |
735 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != GetProfile()) | 740 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != |
| 741 GetBrowserContext()) |
736 return; | 742 return; |
737 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != | 743 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != |
738 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) | 744 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) |
739 return; | 745 return; |
740 const Extension* extension = GetExtensionForRenderViewHost(rvh); | 746 const Extension* extension = GetExtensionForRenderViewHost(rvh); |
741 if (!extension) | 747 if (!extension) |
742 return; | 748 return; |
743 if (attached) { | 749 if (attached) { |
744 // Keep the lazy background page alive while it's being inspected. | 750 // Keep the lazy background page alive while it's being inspected. |
745 CancelSuspend(extension); | 751 CancelSuspend(extension); |
746 IncrementLazyKeepaliveCount(extension); | 752 IncrementLazyKeepaliveCount(extension); |
747 } else { | 753 } else { |
748 DecrementLazyKeepaliveCount(extension); | 754 DecrementLazyKeepaliveCount(extension); |
749 } | 755 } |
750 } | 756 } |
751 | 757 |
752 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() { | 758 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() { |
| 759 DVLOG(1) << "CreateBackgroundHostsForProfileStartup"; |
753 // Don't load background hosts now if the loading should be deferred. | 760 // Don't load background hosts now if the loading should be deferred. |
754 // Instead they will be loaded when a browser window for this profile | 761 // Instead they will be loaded when a browser window for this profile |
755 // (or an incognito profile from this profile) is ready, or when | 762 // (or an incognito profile from this profile) is ready, or when |
756 // DeferBackgroundHostCreation is called with false. | 763 // DeferBackgroundHostCreation is called with false. |
757 if (DeferLoadingBackgroundHosts()) | 764 if (DeferLoadingBackgroundHosts()) |
758 return; | 765 return; |
759 | 766 |
760 ExtensionService* service = GetProfile()->GetExtensionService(); | 767 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 768 GetBrowserContext())->extension_service(); |
| 769 DCHECK(service); |
761 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); | 770 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); |
762 extension != service->extensions()->end(); ++extension) { | 771 extension != service->extensions()->end(); ++extension) { |
763 CreateBackgroundHostForExtensionLoad(this, extension->get()); | 772 CreateBackgroundHostForExtensionLoad(this, extension->get()); |
764 | 773 |
765 extensions::RuntimeEventRouter::DispatchOnStartupEvent( | 774 extensions::RuntimeEventRouter::DispatchOnStartupEvent( |
766 GetProfile(), (*extension)->id()); | 775 GetBrowserContext(), (*extension)->id()); |
767 } | 776 } |
768 | 777 |
769 // Background pages should only be loaded once. To prevent any further loads | 778 // Background pages should only be loaded once. To prevent any further loads |
770 // occurring, we remove the notification listeners. | 779 // occurring, we remove the notification listeners. |
771 Profile* original_profile = GetProfile()->GetOriginalProfile(); | 780 BrowserContext* original_context = |
| 781 ExtensionsBrowserClient::Get()->GetOriginalContext(GetBrowserContext()); |
772 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 782 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
773 content::NotificationService::AllSources()); | 783 content::NotificationService::AllSources()); |
774 if (registrar_.IsRegistered(this, chrome::NOTIFICATION_PROFILE_CREATED, | 784 if (registrar_.IsRegistered( |
775 content::Source<Profile>(original_profile))) | 785 this, |
776 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, | 786 chrome::NOTIFICATION_PROFILE_CREATED, |
777 content::Source<Profile>(original_profile)); | 787 content::Source<BrowserContext>(original_context))) { |
778 if (registrar_.IsRegistered(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 788 registrar_.Remove(this, |
779 content::Source<Profile>(original_profile))) | 789 chrome::NOTIFICATION_PROFILE_CREATED, |
780 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 790 content::Source<BrowserContext>(original_context)); |
781 content::Source<Profile>(original_profile)); | 791 } |
| 792 if (registrar_.IsRegistered( |
| 793 this, |
| 794 chrome::NOTIFICATION_EXTENSIONS_READY, |
| 795 content::Source<BrowserContext>(original_context))) { |
| 796 registrar_.Remove(this, |
| 797 chrome::NOTIFICATION_EXTENSIONS_READY, |
| 798 content::Source<BrowserContext>(original_context)); |
| 799 } |
782 } | 800 } |
783 | 801 |
784 Profile* ExtensionProcessManager::GetProfile() const { | 802 Profile* ExtensionProcessManager::GetProfile() const { |
785 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); | 803 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); |
786 } | 804 } |
787 | 805 |
| 806 content::BrowserContext* ExtensionProcessManager::GetBrowserContext() const { |
| 807 return site_instance_->GetBrowserContext(); |
| 808 } |
| 809 |
788 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 810 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
789 bool is_background) { | 811 bool is_background) { |
790 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); | 812 DCHECK_EQ(site_instance_->GetBrowserContext(), host->browser_context()); |
791 if (is_background) { | 813 if (is_background) { |
792 background_hosts_.insert(host); | 814 background_hosts_.insert(host); |
793 | 815 |
794 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) { | 816 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) { |
795 linked_ptr<base::ElapsedTimer> since_suspended( | 817 linked_ptr<base::ElapsedTimer> since_suspended( |
796 background_page_data_[host->extension()->id()]. | 818 background_page_data_[host->extension()->id()]. |
797 since_suspended.release()); | 819 since_suspended.release()); |
798 if (since_suspended.get()) { | 820 if (since_suspended.get()) { |
799 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime", | 821 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime", |
800 since_suspended->Elapsed()); | 822 since_suspended->Elapsed()); |
(...skipping 18 matching lines...) Expand all Loading... |
819 } | 841 } |
820 } | 842 } |
821 | 843 |
822 void ExtensionProcessManager::UnregisterExtension( | 844 void ExtensionProcessManager::UnregisterExtension( |
823 const std::string& extension_id) { | 845 const std::string& extension_id) { |
824 // The lazy_keepalive_count may be greater than zero at this point because | 846 // The lazy_keepalive_count may be greater than zero at this point because |
825 // RenderViewHosts are still alive. During extension reloading, they will | 847 // RenderViewHosts are still alive. During extension reloading, they will |
826 // decrement the lazy_keepalive_count to negative for the new extension | 848 // decrement the lazy_keepalive_count to negative for the new extension |
827 // instance when they are destroyed. Since we are erasing the background page | 849 // instance when they are destroyed. Since we are erasing the background page |
828 // data for the unloaded extension, unregister the RenderViewHosts too. | 850 // data for the unloaded extension, unregister the RenderViewHosts too. |
829 Profile* profile = GetProfile(); | 851 BrowserContext* context = GetBrowserContext(); |
830 for (ExtensionRenderViews::iterator it = all_extension_views_.begin(); | 852 for (ExtensionRenderViews::iterator it = all_extension_views_.begin(); |
831 it != all_extension_views_.end(); ) { | 853 it != all_extension_views_.end(); ) { |
832 if (GetExtensionID(it->first) == extension_id) { | 854 if (GetExtensionID(it->first) == extension_id) { |
833 OnRenderViewHostUnregistered(profile, it->first); | 855 OnRenderViewHostUnregistered(context, it->first); |
834 all_extension_views_.erase(it++); | 856 all_extension_views_.erase(it++); |
835 } else { | 857 } else { |
836 ++it; | 858 ++it; |
837 } | 859 } |
838 } | 860 } |
839 | 861 |
840 background_page_data_.erase(extension_id); | 862 background_page_data_.erase(extension_id); |
841 } | 863 } |
842 | 864 |
843 void ExtensionProcessManager::ClearBackgroundPageData( | 865 void ExtensionProcessManager::ClearBackgroundPageData( |
844 const std::string& extension_id) { | 866 const std::string& extension_id) { |
845 background_page_data_.erase(extension_id); | 867 background_page_data_.erase(extension_id); |
846 | 868 |
847 // Re-register all RenderViews for this extension. We do this to restore | 869 // Re-register all RenderViews for this extension. We do this to restore |
848 // the lazy_keepalive_count (if any) to properly reflect the number of open | 870 // the lazy_keepalive_count (if any) to properly reflect the number of open |
849 // views. | 871 // views. |
850 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); | 872 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); |
851 it != all_extension_views_.end(); ++it) { | 873 it != all_extension_views_.end(); ++it) { |
852 if (GetExtensionID(it->first) == extension_id) | 874 if (GetExtensionID(it->first) == extension_id) |
853 IncrementLazyKeepaliveCountForView(it->first); | 875 IncrementLazyKeepaliveCountForView(it->first); |
854 } | 876 } |
855 } | 877 } |
856 | 878 |
857 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { | 879 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { |
858 // Don't load background hosts now if the loading should be deferred. | 880 // Don't load background hosts now if the loading should be deferred. |
859 if (defer_background_host_creation_) | 881 if (defer_background_host_creation_) |
860 return true; | 882 return true; |
861 | 883 |
862 // The profile may not be valid yet if it is still being initialized. | 884 // The extensions embedder may have special rules about background hosts. |
863 // In that case, defer loading, since it depends on an initialized profile. | 885 return ExtensionsBrowserClient::Get()->DeferLoadingBackgroundHosts( |
864 // http://crbug.com/222473 | 886 GetBrowserContext()); |
865 if (!g_browser_process->profile_manager()->IsValidProfile(GetProfile())) | |
866 return true; | |
867 | |
868 #if defined(OS_ANDROID) | |
869 return false; | |
870 #else | |
871 return chrome::GetTotalBrowserCountForProfile(GetProfile()) == 0 && | |
872 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList); | |
873 #endif | |
874 } | 887 } |
875 | 888 |
876 // | 889 // |
877 // IncognitoExtensionProcessManager | 890 // IncognitoExtensionProcessManager |
878 // | 891 // |
879 | 892 |
880 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( | 893 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( |
881 Profile* profile) | 894 BrowserContext* incognito_context, |
882 : ExtensionProcessManager(profile), | 895 BrowserContext* original_context) |
883 original_manager_(extensions::ExtensionSystem::Get( | 896 : ExtensionProcessManager(incognito_context, original_context), |
884 profile->GetOriginalProfile())->process_manager()) { | 897 original_manager_(extensions::ExtensionSystem::GetForBrowserContext( |
885 DCHECK(profile->IsOffTheRecord()); | 898 original_context)->process_manager()) { |
| 899 DCHECK(incognito_context->IsOffTheRecord()); |
886 | 900 |
887 // The original profile will have its own ExtensionProcessManager to | 901 // The original profile will have its own ExtensionProcessManager to |
888 // load the background pages of the spanning extensions. This process | 902 // load the background pages of the spanning extensions. This process |
889 // manager need only worry about the split mode extensions, which is handled | 903 // manager need only worry about the split mode extensions, which is handled |
890 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler. | 904 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler. |
891 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 905 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
892 content::Source<Profile>(profile->GetOriginalProfile())); | 906 content::Source<BrowserContext>(original_context)); |
893 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, | 907 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, |
894 content::Source<Profile>(profile->GetOriginalProfile())); | 908 content::Source<BrowserContext>(original_context)); |
895 } | 909 } |
896 | 910 |
897 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { | 911 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { |
898 // TODO(yoz): This cleanup code belongs in the MenuManager. | 912 // TODO(yoz): This cleanup code belongs in the MenuManager. |
899 // Remove "incognito" "split" mode context menu items. | 913 // Remove "incognito" "split" mode context menu items. |
900 ExtensionService* service = | 914 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
901 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 915 GetBrowserContext())->extension_service(); |
902 if (service) | 916 if (service) |
903 service->menu_manager()->RemoveAllIncognitoContextItems(); | 917 service->menu_manager()->RemoveAllIncognitoContextItems(); |
904 } | 918 } |
905 | 919 |
906 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( | 920 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( |
907 const Extension* extension, | 921 const Extension* extension, |
908 const GURL& url, | 922 const GURL& url, |
909 Browser* browser, | 923 Browser* browser, |
910 extensions::ViewType view_type) { | 924 extensions::ViewType view_type) { |
911 if (extensions::IncognitoInfo::IsSplitMode(extension)) { | 925 if (extensions::IncognitoInfo::IsSplitMode(extension)) { |
(...skipping 19 matching lines...) Expand all Loading... |
931 return ExtensionProcessManager::CreateBackgroundHost(extension, url); | 945 return ExtensionProcessManager::CreateBackgroundHost(extension, url); |
932 } else { | 946 } else { |
933 // Do nothing. If an extension is spanning, then its original-profile | 947 // Do nothing. If an extension is spanning, then its original-profile |
934 // background page is shared with incognito, so we don't create another. | 948 // background page is shared with incognito, so we don't create another. |
935 } | 949 } |
936 return NULL; | 950 return NULL; |
937 } | 951 } |
938 | 952 |
939 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL( | 953 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL( |
940 const GURL& url) { | 954 const GURL& url) { |
941 ExtensionService* service = GetProfile()->GetExtensionService(); | 955 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 956 GetBrowserContext())->extension_service(); |
942 if (service) { | 957 if (service) { |
943 const Extension* extension = | 958 const Extension* extension = |
944 service->extensions()->GetExtensionOrAppByURL(url); | 959 service->extensions()->GetExtensionOrAppByURL(url); |
945 if (extension && | 960 if (extension && |
946 !extensions::IncognitoInfo::IsSplitMode(extension)) { | 961 !extensions::IncognitoInfo::IsSplitMode(extension)) { |
947 return original_manager_->GetSiteInstanceForURL(url); | 962 return original_manager_->GetSiteInstanceForURL(url); |
948 } | 963 } |
949 } | 964 } |
950 return ExtensionProcessManager::GetSiteInstanceForURL(url); | 965 return ExtensionProcessManager::GetSiteInstanceForURL(url); |
951 } | 966 } |
952 | 967 |
953 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( | 968 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( |
954 const Extension* extension) { | 969 const Extension* extension) { |
955 // Keep in sync with duplicate in extension_info_map.cc. | 970 // Keep in sync with duplicate in extension_info_map.cc. |
956 ExtensionService* service = GetProfile()->GetExtensionService(); | 971 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 972 GetBrowserContext())->extension_service(); |
957 return extension_util::IsIncognitoEnabled(extension->id(), service); | 973 return extension_util::IsIncognitoEnabled(extension->id(), service); |
958 } | 974 } |
959 | 975 |
960 void IncognitoExtensionProcessManager::Observe( | 976 void IncognitoExtensionProcessManager::Observe( |
961 int type, | 977 int type, |
962 const content::NotificationSource& source, | 978 const content::NotificationSource& source, |
963 const content::NotificationDetails& details) { | 979 const content::NotificationDetails& details) { |
964 switch (type) { | 980 switch (type) { |
965 // Do not use ExtensionProcessManager's handler for | 981 // Do not use ExtensionProcessManager's handler for |
966 // NOTIFICATION_BROWSER_WINDOW_READY. | 982 // NOTIFICATION_BROWSER_WINDOW_READY. |
967 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 983 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
968 // We want to spawn our background hosts as soon as the user opens an | 984 // We want to spawn our background hosts as soon as the user opens an |
969 // incognito window. Watch for new browsers and create the hosts if | 985 // incognito window. Watch for new browsers and create the hosts if |
970 // it matches our profile. | 986 // it matches our profile. |
971 Browser* browser = content::Source<Browser>(source).ptr(); | 987 Browser* browser = content::Source<Browser>(source).ptr(); |
972 if (browser->profile() == site_instance_->GetBrowserContext()) { | 988 if (browser->profile() == site_instance_->GetBrowserContext()) { |
973 // On Chrome OS, a login screen is implemented as a browser. | 989 // On Chrome OS, a login screen is implemented as a browser. |
974 // This browser has no extension service. In this case, | 990 // This browser has no extension service. In this case, |
975 // service will be NULL. | 991 // service will be NULL. |
976 ExtensionService* service = GetProfile()->GetExtensionService(); | 992 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 993 GetBrowserContext())->extension_service(); |
977 if (service && service->is_ready()) | 994 if (service && service->is_ready()) |
978 CreateBackgroundHostsForProfileStartup(); | 995 CreateBackgroundHostsForProfileStartup(); |
979 } | 996 } |
980 break; | 997 break; |
981 } | 998 } |
982 default: | 999 default: |
983 ExtensionProcessManager::Observe(type, source, details); | 1000 ExtensionProcessManager::Observe(type, source, details); |
984 break; | 1001 break; |
985 } | 1002 } |
986 } | 1003 } |
OLD | NEW |