Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 52983004: Convert ExtensionProcessManager to BrowserContext, part 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, add browser test Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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";
miket_OOO 2013/10/31 23:04:53 OK to keep, but did you mean this?
James Cook 2013/11/01 00:08:32 Yeah, I need these DVLOG lines to keep working on
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
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.
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.
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 } 263 }
264 } 264 }
265 265
266 ExtensionHost* ExtensionProcessManager::CreateViewHost( 266 ExtensionHost* ExtensionProcessManager::CreateViewHost(
267 const Extension* extension, 267 const Extension* extension,
268 const GURL& url, 268 const GURL& url,
269 Browser* browser, 269 Browser* browser,
270 extensions::ViewType view_type) { 270 extensions::ViewType view_type) {
271 DVLOG(1) << "CreateViewHost";
miket_OOO 2013/10/31 23:04:53 same
271 DCHECK(extension); 272 DCHECK(extension);
272 EnsureBrowserWhenRequired(browser, view_type); 273 EnsureBrowserWhenRequired(browser, view_type);
273 ExtensionHost* host = 274 ExtensionHost* host =
274 #if defined(OS_MACOSX) 275 #if defined(OS_MACOSX)
275 new extensions::ExtensionHostMac( 276 new extensions::ExtensionHostMac(
276 extension, GetSiteInstanceForURL(url), url, view_type); 277 extension, GetSiteInstanceForURL(url), url, view_type);
277 #else 278 #else
278 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); 279 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type);
279 #endif 280 #endif
280 host->CreateView(browser); 281 host->CreateView(browser);
281 OnExtensionHostCreated(host, false); 282 OnExtensionHostCreated(host, false);
282 return host; 283 return host;
283 } 284 }
284 285
285 ExtensionHost* ExtensionProcessManager::CreateViewHost( 286 ExtensionHost* ExtensionProcessManager::CreateViewHost(
286 const GURL& url, Browser* browser, extensions::ViewType view_type) { 287 const GURL& url, Browser* browser, extensions::ViewType view_type) {
287 EnsureBrowserWhenRequired(browser, view_type); 288 EnsureBrowserWhenRequired(browser, view_type);
288 ExtensionService* service = GetProfile()->GetExtensionService(); 289 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
290 GetBrowserContext())->extension_service();
289 if (service) { 291 if (service) {
290 std::string extension_id = url.host(); 292 std::string extension_id = url.host();
291 if (url.SchemeIs(chrome::kChromeUIScheme) && 293 if (url.SchemeIs(chrome::kChromeUIScheme) &&
292 url.host() == chrome::kChromeUIExtensionInfoHost) 294 url.host() == chrome::kChromeUIExtensionInfoHost)
293 extension_id = url.path().substr(1); 295 extension_id = url.path().substr(1);
294 const Extension* extension = 296 const Extension* extension =
295 service->extensions()->GetByID(extension_id); 297 service->extensions()->GetByID(extension_id);
296 if (extension) 298 if (extension)
297 return CreateViewHost(extension, url, browser, view_type); 299 return CreateViewHost(extension, url, browser, view_type);
298 } 300 }
(...skipping 21 matching lines...) Expand all
320 extension, url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR); 322 extension, url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR);
321 } 323 }
322 324
323 ExtensionHost* ExtensionProcessManager::CreateInfobarHost( 325 ExtensionHost* ExtensionProcessManager::CreateInfobarHost(
324 const GURL& url, Browser* browser) { 326 const GURL& url, Browser* browser) {
325 return CreateViewHost(url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR); 327 return CreateViewHost(url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR);
326 } 328 }
327 329
328 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( 330 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost(
329 const Extension* extension, const GURL& url) { 331 const Extension* extension, const GURL& url) {
332 DVLOG(1) << "CreateBackgroundHost " << url.spec();
330 // Hosted apps are taken care of from BackgroundContentsService. Ignore them 333 // Hosted apps are taken care of from BackgroundContentsService. Ignore them
331 // here. 334 // here.
332 if (extension->is_hosted_app()) 335 if (extension->is_hosted_app())
333 return NULL; 336 return NULL;
334 337
335 // Don't create multiple background hosts for an extension. 338 // Don't create multiple background hosts for an extension.
336 if (ExtensionHost* host = GetBackgroundHostForExtension(extension->id())) 339 if (ExtensionHost* host = GetBackgroundHostForExtension(extension->id()))
337 return host; // TODO(kalman): return NULL here? It might break things... 340 return host; // TODO(kalman): return NULL here? It might break things...
338 341
339 ExtensionHost* host = 342 ExtensionHost* host =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 383 }
381 384
382 return result; 385 return result;
383 } 386 }
384 387
385 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( 388 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost(
386 RenderViewHost* render_view_host) { 389 RenderViewHost* render_view_host) {
387 if (!render_view_host->GetSiteInstance()) 390 if (!render_view_host->GetSiteInstance())
388 return NULL; 391 return NULL;
389 392
390 ExtensionService* service = 393 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
391 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); 394 GetBrowserContext())->extension_service();
392 if (!service) 395 if (!service)
393 return NULL; 396 return NULL;
394 397
395 return service->extensions()->GetByID(GetExtensionID(render_view_host)); 398 return service->extensions()->GetByID(GetExtensionID(render_view_host));
396 } 399 }
397 400
398 void ExtensionProcessManager::UnregisterRenderViewHost( 401 void ExtensionProcessManager::UnregisterRenderViewHost(
399 RenderViewHost* render_view_host) { 402 RenderViewHost* render_view_host) {
400 ExtensionRenderViews::iterator view = 403 ExtensionRenderViews::iterator view =
401 all_extension_views_.find(render_view_host); 404 all_extension_views_.find(render_view_host);
402 if (view == all_extension_views_.end()) 405 if (view == all_extension_views_.end())
403 return; 406 return;
404 407
405 OnRenderViewHostUnregistered(GetProfile(), render_view_host); 408 OnRenderViewHostUnregistered(GetBrowserContext(), render_view_host);
406 extensions::ViewType view_type = view->second; 409 extensions::ViewType view_type = view->second;
407 all_extension_views_.erase(view); 410 all_extension_views_.erase(view);
408 411
409 // Keepalive count, balanced in RegisterRenderViewHost. 412 // Keepalive count, balanced in RegisterRenderViewHost.
410 if (view_type != extensions::VIEW_TYPE_INVALID && 413 if (view_type != extensions::VIEW_TYPE_INVALID &&
411 view_type != extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 414 view_type != extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
412 const Extension* extension = GetExtensionForRenderViewHost( 415 const Extension* extension = GetExtensionForRenderViewHost(
413 render_view_host); 416 render_view_host);
414 if (extension) 417 if (extension)
415 DecrementLazyKeepaliveCount(extension); 418 DecrementLazyKeepaliveCount(extension);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { 609 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
607 // If a window for this profile, or this profile's incognito profile, 610 // If a window for this profile, or this profile's incognito profile,
608 // has been opened, make sure this profile's background hosts have 611 // has been opened, make sure this profile's background hosts have
609 // been loaded. 612 // been loaded.
610 Browser* browser = content::Source<Browser>(source).ptr(); 613 Browser* browser = content::Source<Browser>(source).ptr();
611 if (browser->profile() != GetProfile() && 614 if (browser->profile() != GetProfile() &&
612 !(GetProfile()->HasOffTheRecordProfile() && 615 !(GetProfile()->HasOffTheRecordProfile() &&
613 browser->profile() == GetProfile()->GetOffTheRecordProfile())) 616 browser->profile() == GetProfile()->GetOffTheRecordProfile()))
614 break; 617 break;
615 618
616 ExtensionService* service = GetProfile()->GetExtensionService(); 619 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
620 GetBrowserContext())->extension_service();
617 if (!service || !service->is_ready()) 621 if (!service || !service->is_ready())
618 break; 622 break;
619 623
620 CreateBackgroundHostsForProfileStartup(); 624 CreateBackgroundHostsForProfileStartup();
621 break; 625 break;
622 } 626 }
623 case chrome::NOTIFICATION_EXTENSIONS_READY: 627 case chrome::NOTIFICATION_EXTENSIONS_READY:
624 case chrome::NOTIFICATION_PROFILE_CREATED: { 628 case chrome::NOTIFICATION_PROFILE_CREATED: {
625 CreateBackgroundHostsForProfileStartup(); 629 CreateBackgroundHostsForProfileStartup();
626 break; 630 break;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 break; 677 break;
674 } 678 }
675 679
676 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { 680 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: {
677 // We get this notification both for new WebContents and when one 681 // 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 682 // 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 683 // 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 684 // unregister the old RVH so it doesn't count as an active view that would
681 // keep the event page alive. 685 // keep the event page alive.
682 WebContents* contents = content::Source<WebContents>(source).ptr(); 686 WebContents* contents = content::Source<WebContents>(source).ptr();
683 if (contents->GetBrowserContext() != GetProfile()) 687 if (contents->GetBrowserContext() != GetBrowserContext())
684 break; 688 break;
685 689
686 typedef std::pair<RenderViewHost*, RenderViewHost*> RVHPair; 690 typedef std::pair<RenderViewHost*, RenderViewHost*> RVHPair;
687 RVHPair* switched_details = content::Details<RVHPair>(details).ptr(); 691 RVHPair* switched_details = content::Details<RVHPair>(details).ptr();
688 if (switched_details->first) 692 if (switched_details->first)
689 UnregisterRenderViewHost(switched_details->first); 693 UnregisterRenderViewHost(switched_details->first);
690 694
691 // The above will unregister a RVH when it gets swapped out with a new 695 // 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 696 // one. However we need to watch the WebContents to know when a RVH is
693 // deleted because the WebContents has gone away. 697 // deleted because the WebContents has gone away.
694 RenderViewHostDestructionObserver::CreateForWebContents(contents); 698 RenderViewHostDestructionObserver::CreateForWebContents(contents);
695 RegisterRenderViewHost(switched_details->second); 699 RegisterRenderViewHost(switched_details->second);
696 break; 700 break;
697 } 701 }
698 702
699 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { 703 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: {
700 WebContents* contents = content::Source<WebContents>(source).ptr(); 704 WebContents* contents = content::Source<WebContents>(source).ptr();
701 if (contents->GetBrowserContext() != GetProfile()) 705 if (contents->GetBrowserContext() != GetBrowserContext())
702 break; 706 break;
703 const Extension* extension = GetExtensionForRenderViewHost( 707 const Extension* extension = GetExtensionForRenderViewHost(
704 contents->GetRenderViewHost()); 708 contents->GetRenderViewHost());
705 if (!extension) 709 if (!extension)
706 return; 710 return;
707 711
708 // RegisterRenderViewHost is called too early (before the process is 712 // RegisterRenderViewHost is called too early (before the process is
709 // available), so we need to wait until now to notify. 713 // available), so we need to wait until now to notify.
710 content::NotificationService::current()->Notify( 714 content::NotificationService::current()->Notify(
711 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, 715 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED,
712 content::Source<Profile>(GetProfile()), 716 content::Source<BrowserContext>(GetBrowserContext()),
713 content::Details<RenderViewHost>(contents->GetRenderViewHost())); 717 content::Details<RenderViewHost>(contents->GetRenderViewHost()));
714 break; 718 break;
715 } 719 }
716 720
717 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 721 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
718 // Close background hosts when the last browser is closed so that they 722 // Close background hosts when the last browser is closed so that they
719 // have time to shutdown various objects on different threads. Our 723 // have time to shutdown various objects on different threads. Our
720 // destructor is called too late in the shutdown sequence. 724 // destructor is called too late in the shutdown sequence.
721 CloseBackgroundHosts(); 725 CloseBackgroundHosts();
722 break; 726 break;
723 } 727 }
724 728
725 default: 729 default:
726 NOTREACHED(); 730 NOTREACHED();
727 } 731 }
728 } 732 }
729 733
730 void ExtensionProcessManager::OnDevToolsStateChanged( 734 void ExtensionProcessManager::OnDevToolsStateChanged(
731 content::DevToolsAgentHost* agent_host, bool attached) { 735 content::DevToolsAgentHost* agent_host, bool attached) {
732 RenderViewHost* rvh = agent_host->GetRenderViewHost(); 736 RenderViewHost* rvh = agent_host->GetRenderViewHost();
733 // Ignore unrelated notifications. 737 // Ignore unrelated notifications.
734 if (!rvh || 738 if (!rvh ||
735 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != GetProfile()) 739 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() !=
740 GetBrowserContext())
736 return; 741 return;
737 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != 742 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) !=
738 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) 743 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE)
739 return; 744 return;
740 const Extension* extension = GetExtensionForRenderViewHost(rvh); 745 const Extension* extension = GetExtensionForRenderViewHost(rvh);
741 if (!extension) 746 if (!extension)
742 return; 747 return;
743 if (attached) { 748 if (attached) {
744 // Keep the lazy background page alive while it's being inspected. 749 // Keep the lazy background page alive while it's being inspected.
745 CancelSuspend(extension); 750 CancelSuspend(extension);
746 IncrementLazyKeepaliveCount(extension); 751 IncrementLazyKeepaliveCount(extension);
747 } else { 752 } else {
748 DecrementLazyKeepaliveCount(extension); 753 DecrementLazyKeepaliveCount(extension);
749 } 754 }
750 } 755 }
751 756
752 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() { 757 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() {
758 DVLOG(1) << "CreateBackgroundHostsForProfileStartup";
753 // Don't load background hosts now if the loading should be deferred. 759 // 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 760 // Instead they will be loaded when a browser window for this profile
755 // (or an incognito profile from this profile) is ready, or when 761 // (or an incognito profile from this profile) is ready, or when
756 // DeferBackgroundHostCreation is called with false. 762 // DeferBackgroundHostCreation is called with false.
757 if (DeferLoadingBackgroundHosts()) 763 if (DeferLoadingBackgroundHosts())
758 return; 764 return;
759 765
760 ExtensionService* service = GetProfile()->GetExtensionService(); 766 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
767 GetBrowserContext())->extension_service();
768 DCHECK(service);
761 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); 769 for (ExtensionSet::const_iterator extension = service->extensions()->begin();
762 extension != service->extensions()->end(); ++extension) { 770 extension != service->extensions()->end(); ++extension) {
763 CreateBackgroundHostForExtensionLoad(this, extension->get()); 771 CreateBackgroundHostForExtensionLoad(this, extension->get());
764 772
765 extensions::RuntimeEventRouter::DispatchOnStartupEvent( 773 extensions::RuntimeEventRouter::DispatchOnStartupEvent(
766 GetProfile(), (*extension)->id()); 774 GetBrowserContext(), (*extension)->id());
767 } 775 }
768 776
769 // Background pages should only be loaded once. To prevent any further loads 777 // Background pages should only be loaded once. To prevent any further loads
770 // occurring, we remove the notification listeners. 778 // occurring, we remove the notification listeners.
771 Profile* original_profile = GetProfile()->GetOriginalProfile(); 779 BrowserContext* original_context =
780 ExtensionsBrowserClient::Get()->GetOriginalContext(GetBrowserContext());
772 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 781 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
773 content::NotificationService::AllSources()); 782 content::NotificationService::AllSources());
774 if (registrar_.IsRegistered(this, chrome::NOTIFICATION_PROFILE_CREATED, 783 if (registrar_.IsRegistered(
775 content::Source<Profile>(original_profile))) 784 this,
776 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, 785 chrome::NOTIFICATION_PROFILE_CREATED,
777 content::Source<Profile>(original_profile)); 786 content::Source<BrowserContext>(original_context))) {
778 if (registrar_.IsRegistered(this, chrome::NOTIFICATION_EXTENSIONS_READY, 787 registrar_.Remove(this,
779 content::Source<Profile>(original_profile))) 788 chrome::NOTIFICATION_PROFILE_CREATED,
780 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, 789 content::Source<BrowserContext>(original_context));
781 content::Source<Profile>(original_profile)); 790 }
791 if (registrar_.IsRegistered(
792 this,
793 chrome::NOTIFICATION_EXTENSIONS_READY,
794 content::Source<BrowserContext>(original_context))) {
795 registrar_.Remove(this,
796 chrome::NOTIFICATION_EXTENSIONS_READY,
797 content::Source<BrowserContext>(original_context));
798 }
782 } 799 }
783 800
784 Profile* ExtensionProcessManager::GetProfile() const { 801 Profile* ExtensionProcessManager::GetProfile() const {
785 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); 802 return Profile::FromBrowserContext(site_instance_->GetBrowserContext());
786 } 803 }
787 804
805 content::BrowserContext* ExtensionProcessManager::GetBrowserContext() const {
806 return site_instance_->GetBrowserContext();
807 }
808
788 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 809 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
789 bool is_background) { 810 bool is_background) {
790 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); 811 DCHECK_EQ(site_instance_->GetBrowserContext(), host->browser_context());
791 if (is_background) { 812 if (is_background) {
792 background_hosts_.insert(host); 813 background_hosts_.insert(host);
793 814
794 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) { 815 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) {
795 linked_ptr<base::ElapsedTimer> since_suspended( 816 linked_ptr<base::ElapsedTimer> since_suspended(
796 background_page_data_[host->extension()->id()]. 817 background_page_data_[host->extension()->id()].
797 since_suspended.release()); 818 since_suspended.release());
798 if (since_suspended.get()) { 819 if (since_suspended.get()) {
799 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime", 820 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime",
800 since_suspended->Elapsed()); 821 since_suspended->Elapsed());
(...skipping 18 matching lines...) Expand all
819 } 840 }
820 } 841 }
821 842
822 void ExtensionProcessManager::UnregisterExtension( 843 void ExtensionProcessManager::UnregisterExtension(
823 const std::string& extension_id) { 844 const std::string& extension_id) {
824 // The lazy_keepalive_count may be greater than zero at this point because 845 // The lazy_keepalive_count may be greater than zero at this point because
825 // RenderViewHosts are still alive. During extension reloading, they will 846 // RenderViewHosts are still alive. During extension reloading, they will
826 // decrement the lazy_keepalive_count to negative for the new extension 847 // decrement the lazy_keepalive_count to negative for the new extension
827 // instance when they are destroyed. Since we are erasing the background page 848 // instance when they are destroyed. Since we are erasing the background page
828 // data for the unloaded extension, unregister the RenderViewHosts too. 849 // data for the unloaded extension, unregister the RenderViewHosts too.
829 Profile* profile = GetProfile(); 850 BrowserContext* context = GetBrowserContext();
830 for (ExtensionRenderViews::iterator it = all_extension_views_.begin(); 851 for (ExtensionRenderViews::iterator it = all_extension_views_.begin();
831 it != all_extension_views_.end(); ) { 852 it != all_extension_views_.end(); ) {
832 if (GetExtensionID(it->first) == extension_id) { 853 if (GetExtensionID(it->first) == extension_id) {
833 OnRenderViewHostUnregistered(profile, it->first); 854 OnRenderViewHostUnregistered(context, it->first);
834 all_extension_views_.erase(it++); 855 all_extension_views_.erase(it++);
835 } else { 856 } else {
836 ++it; 857 ++it;
837 } 858 }
838 } 859 }
839 860
840 background_page_data_.erase(extension_id); 861 background_page_data_.erase(extension_id);
841 } 862 }
842 863
843 void ExtensionProcessManager::ClearBackgroundPageData( 864 void ExtensionProcessManager::ClearBackgroundPageData(
844 const std::string& extension_id) { 865 const std::string& extension_id) {
845 background_page_data_.erase(extension_id); 866 background_page_data_.erase(extension_id);
846 867
847 // Re-register all RenderViews for this extension. We do this to restore 868 // 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 869 // the lazy_keepalive_count (if any) to properly reflect the number of open
849 // views. 870 // views.
850 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); 871 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin();
851 it != all_extension_views_.end(); ++it) { 872 it != all_extension_views_.end(); ++it) {
852 if (GetExtensionID(it->first) == extension_id) 873 if (GetExtensionID(it->first) == extension_id)
853 IncrementLazyKeepaliveCountForView(it->first); 874 IncrementLazyKeepaliveCountForView(it->first);
854 } 875 }
855 } 876 }
856 877
857 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { 878 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const {
858 // Don't load background hosts now if the loading should be deferred. 879 // Don't load background hosts now if the loading should be deferred.
859 if (defer_background_host_creation_) 880 if (defer_background_host_creation_)
860 return true; 881 return true;
861 882
862 // The profile may not be valid yet if it is still being initialized. 883 // The extensions embedder may have special rules about background hosts.
863 // In that case, defer loading, since it depends on an initialized profile. 884 return ExtensionsBrowserClient::Get()->DeferLoadingBackgroundHosts(
864 // http://crbug.com/222473 885 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 } 886 }
875 887
876 // 888 //
877 // IncognitoExtensionProcessManager 889 // IncognitoExtensionProcessManager
878 // 890 //
879 891
880 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( 892 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager(
881 Profile* profile) 893 BrowserContext* incognito_context,
882 : ExtensionProcessManager(profile), 894 BrowserContext* original_context)
883 original_manager_(extensions::ExtensionSystem::Get( 895 : ExtensionProcessManager(incognito_context, original_context),
884 profile->GetOriginalProfile())->process_manager()) { 896 original_manager_(extensions::ExtensionSystem::GetForBrowserContext(
885 DCHECK(profile->IsOffTheRecord()); 897 original_context)->process_manager()) {
898 DCHECK(incognito_context->IsOffTheRecord());
886 899
887 // The original profile will have its own ExtensionProcessManager to 900 // The original profile will have its own ExtensionProcessManager to
888 // load the background pages of the spanning extensions. This process 901 // load the background pages of the spanning extensions. This process
889 // manager need only worry about the split mode extensions, which is handled 902 // manager need only worry about the split mode extensions, which is handled
890 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler. 903 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler.
891 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, 904 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY,
892 content::Source<Profile>(profile->GetOriginalProfile())); 905 content::Source<BrowserContext>(original_context));
893 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, 906 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED,
894 content::Source<Profile>(profile->GetOriginalProfile())); 907 content::Source<BrowserContext>(original_context));
895 } 908 }
896 909
897 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { 910 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() {
898 // TODO(yoz): This cleanup code belongs in the MenuManager. 911 // TODO(yoz): This cleanup code belongs in the MenuManager.
899 // Remove "incognito" "split" mode context menu items. 912 // Remove "incognito" "split" mode context menu items.
900 ExtensionService* service = 913 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
901 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); 914 GetBrowserContext())->extension_service();
902 if (service) 915 if (service)
903 service->menu_manager()->RemoveAllIncognitoContextItems(); 916 service->menu_manager()->RemoveAllIncognitoContextItems();
904 } 917 }
905 918
906 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( 919 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost(
907 const Extension* extension, 920 const Extension* extension,
908 const GURL& url, 921 const GURL& url,
909 Browser* browser, 922 Browser* browser,
910 extensions::ViewType view_type) { 923 extensions::ViewType view_type) {
911 if (extensions::IncognitoInfo::IsSplitMode(extension)) { 924 if (extensions::IncognitoInfo::IsSplitMode(extension)) {
(...skipping 19 matching lines...) Expand all
931 return ExtensionProcessManager::CreateBackgroundHost(extension, url); 944 return ExtensionProcessManager::CreateBackgroundHost(extension, url);
932 } else { 945 } else {
933 // Do nothing. If an extension is spanning, then its original-profile 946 // Do nothing. If an extension is spanning, then its original-profile
934 // background page is shared with incognito, so we don't create another. 947 // background page is shared with incognito, so we don't create another.
935 } 948 }
936 return NULL; 949 return NULL;
937 } 950 }
938 951
939 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL( 952 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL(
940 const GURL& url) { 953 const GURL& url) {
941 ExtensionService* service = GetProfile()->GetExtensionService(); 954 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
955 GetBrowserContext())->extension_service();
942 if (service) { 956 if (service) {
943 const Extension* extension = 957 const Extension* extension =
944 service->extensions()->GetExtensionOrAppByURL(url); 958 service->extensions()->GetExtensionOrAppByURL(url);
945 if (extension && 959 if (extension &&
946 !extensions::IncognitoInfo::IsSplitMode(extension)) { 960 !extensions::IncognitoInfo::IsSplitMode(extension)) {
947 return original_manager_->GetSiteInstanceForURL(url); 961 return original_manager_->GetSiteInstanceForURL(url);
948 } 962 }
949 } 963 }
950 return ExtensionProcessManager::GetSiteInstanceForURL(url); 964 return ExtensionProcessManager::GetSiteInstanceForURL(url);
951 } 965 }
952 966
953 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( 967 bool IncognitoExtensionProcessManager::IsIncognitoEnabled(
954 const Extension* extension) { 968 const Extension* extension) {
955 // Keep in sync with duplicate in extension_info_map.cc. 969 // Keep in sync with duplicate in extension_info_map.cc.
956 ExtensionService* service = GetProfile()->GetExtensionService(); 970 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
971 GetBrowserContext())->extension_service();
957 return extension_util::IsIncognitoEnabled(extension->id(), service); 972 return extension_util::IsIncognitoEnabled(extension->id(), service);
958 } 973 }
959 974
960 void IncognitoExtensionProcessManager::Observe( 975 void IncognitoExtensionProcessManager::Observe(
961 int type, 976 int type,
962 const content::NotificationSource& source, 977 const content::NotificationSource& source,
963 const content::NotificationDetails& details) { 978 const content::NotificationDetails& details) {
964 switch (type) { 979 switch (type) {
965 // Do not use ExtensionProcessManager's handler for 980 // Do not use ExtensionProcessManager's handler for
966 // NOTIFICATION_BROWSER_WINDOW_READY. 981 // NOTIFICATION_BROWSER_WINDOW_READY.
967 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { 982 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
968 // We want to spawn our background hosts as soon as the user opens an 983 // 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 984 // incognito window. Watch for new browsers and create the hosts if
970 // it matches our profile. 985 // it matches our profile.
971 Browser* browser = content::Source<Browser>(source).ptr(); 986 Browser* browser = content::Source<Browser>(source).ptr();
972 if (browser->profile() == site_instance_->GetBrowserContext()) { 987 if (browser->profile() == site_instance_->GetBrowserContext()) {
973 // On Chrome OS, a login screen is implemented as a browser. 988 // On Chrome OS, a login screen is implemented as a browser.
974 // This browser has no extension service. In this case, 989 // This browser has no extension service. In this case,
975 // service will be NULL. 990 // service will be NULL.
976 ExtensionService* service = GetProfile()->GetExtensionService(); 991 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
992 GetBrowserContext())->extension_service();
977 if (service && service->is_ready()) 993 if (service && service->is_ready())
978 CreateBackgroundHostsForProfileStartup(); 994 CreateBackgroundHostsForProfileStartup();
979 } 995 }
980 break; 996 break;
981 } 997 }
982 default: 998 default:
983 ExtensionProcessManager::Observe(type, source, details); 999 ExtensionProcessManager::Observe(type, source, details);
984 break; 1000 break;
985 } 1001 }
986 } 1002 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698