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/background/background_contents_service.h" | 5 #include "chrome/browser/background/background_contents_service.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/notifications/notification.h" | 21 #include "chrome/browser/notifications/notification.h" |
22 #include "chrome/browser/notifications/notification_ui_manager.h" | 22 #include "chrome/browser/notifications/notification_ui_manager.h" |
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
28 #include "chrome/browser/ui/host_desktop.h" | 28 #include "chrome/browser/ui/host_desktop.h" |
29 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/extensions/background_info.h" |
31 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 33 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chrome/common/extensions/extension_icon_set.h" | 34 #include "chrome/common/extensions/extension_icon_set.h" |
34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
35 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
36 #include "content/public/browser/site_instance.h" | 37 #include "content/public/browser/site_instance.h" |
37 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
38 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
39 #include "ipc/ipc_message.h" | 40 #include "ipc/ipc_message.h" |
40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
41 | 42 |
42 using content::SiteInstance; | 43 using content::SiteInstance; |
43 using content::WebContents; | 44 using content::WebContents; |
| 45 using extensions::BackgroundInfo; |
44 using extensions::Extension; | 46 using extensions::Extension; |
45 using extensions::UnloadedExtensionInfo; | 47 using extensions::UnloadedExtensionInfo; |
46 | 48 |
47 namespace { | 49 namespace { |
48 | 50 |
49 const char kNotificationPrefix[] = "app.background.crashed."; | 51 const char kNotificationPrefix[] = "app.background.crashed."; |
50 | 52 |
51 void CloseBalloon(const std::string id) { | 53 void CloseBalloon(const std::string id) { |
52 g_browser_process->notification_ui_manager()->CancelById(id); | 54 g_browser_process->notification_ui_manager()->CancelById(id); |
53 } | 55 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 BackgroundContents* bgcontents = | 259 BackgroundContents* bgcontents = |
258 content::Details<BackgroundContents>(details).ptr(); | 260 content::Details<BackgroundContents>(details).ptr(); |
259 Profile* profile = content::Source<Profile>(source).ptr(); | 261 Profile* profile = content::Source<Profile>(source).ptr(); |
260 const string16& appid = GetParentApplicationId(bgcontents); | 262 const string16& appid = GetParentApplicationId(bgcontents); |
261 ExtensionService* extension_service = | 263 ExtensionService* extension_service = |
262 extensions::ExtensionSystem::Get(profile)->extension_service(); | 264 extensions::ExtensionSystem::Get(profile)->extension_service(); |
263 // extension_service can be NULL when running tests. | 265 // extension_service can be NULL when running tests. |
264 if (extension_service) { | 266 if (extension_service) { |
265 const Extension* extension = | 267 const Extension* extension = |
266 extension_service->GetExtensionById(UTF16ToUTF8(appid), false); | 268 extension_service->GetExtensionById(UTF16ToUTF8(appid), false); |
267 if (extension && extension->has_background_page()) | 269 if (extension && BackgroundInfo::HasBackgroundPage(extension)) |
268 break; | 270 break; |
269 } | 271 } |
270 RegisterBackgroundContents(bgcontents); | 272 RegisterBackgroundContents(bgcontents); |
271 break; | 273 break; |
272 } | 274 } |
273 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 275 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
274 const Extension* extension = | 276 const Extension* extension = |
275 content::Details<const Extension>(details).ptr(); | 277 content::Details<const Extension>(details).ptr(); |
276 Profile* profile = content::Source<Profile>(source).ptr(); | 278 Profile* profile = content::Source<Profile>(source).ptr(); |
277 if (extension->is_hosted_app() && | 279 if (extension->is_hosted_app() && |
278 extension->has_background_page()) { | 280 BackgroundInfo::HasBackgroundPage(extension)) { |
279 // If there is a background page specified in the manifest for a hosted | 281 // If there is a background page specified in the manifest for a hosted |
280 // app, then blow away registered urls in the pref. | 282 // app, then blow away registered urls in the pref. |
281 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); | 283 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); |
282 | 284 |
283 ExtensionService* service = | 285 ExtensionService* service = |
284 extensions::ExtensionSystem::Get(profile)->extension_service(); | 286 extensions::ExtensionSystem::Get(profile)->extension_service(); |
285 if (service && service->is_ready()) { | 287 if (service && service->is_ready()) { |
286 // Now load the manifest-specified background page. If service isn't | 288 // Now load the manifest-specified background page. If service isn't |
287 // ready, then the background page will be loaded from the | 289 // ready, then the background page will be loaded from the |
288 // EXTENSIONS_READY callback. | 290 // EXTENSIONS_READY callback. |
289 LoadBackgroundContents(profile, extension->GetBackgroundURL(), | 291 LoadBackgroundContents(profile, |
290 ASCIIToUTF16("background"), UTF8ToUTF16(extension->id())); | 292 BackgroundInfo::GetBackgroundURL(extension), |
| 293 ASCIIToUTF16("background"), |
| 294 UTF8ToUTF16(extension->id())); |
291 } | 295 } |
292 } | 296 } |
293 | 297 |
294 // Remove any "This extension has crashed" balloons. | 298 // Remove any "This extension has crashed" balloons. |
295 ScheduleCloseBalloon(extension->id()); | 299 ScheduleCloseBalloon(extension->id()); |
296 SendChangeNotification(profile); | 300 SendChangeNotification(profile); |
297 break; | 301 break; |
298 } | 302 } |
299 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: | 303 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
300 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { | 304 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 break; | 343 break; |
340 case extension_misc::UNLOAD_REASON_UPDATE: { | 344 case extension_misc::UNLOAD_REASON_UPDATE: { |
341 // If there is a manifest specified background page, then shut it down | 345 // If there is a manifest specified background page, then shut it down |
342 // here, since if the updated extension still has the background page, | 346 // here, since if the updated extension still has the background page, |
343 // then it will be loaded from LOADED callback. Otherwise, leave | 347 // then it will be loaded from LOADED callback. Otherwise, leave |
344 // BackgroundContents in place. | 348 // BackgroundContents in place. |
345 // We don't call SendChangeNotification here - it will be generated | 349 // We don't call SendChangeNotification here - it will be generated |
346 // from the LOADED callback. | 350 // from the LOADED callback. |
347 const Extension* extension = | 351 const Extension* extension = |
348 content::Details<UnloadedExtensionInfo>(details)->extension; | 352 content::Details<UnloadedExtensionInfo>(details)->extension; |
349 if (extension->has_background_page()) | 353 if (BackgroundInfo::HasBackgroundPage(extension)) |
350 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); | 354 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); |
351 break; | 355 break; |
352 } | 356 } |
353 default: | 357 default: |
354 NOTREACHED(); | 358 NOTREACHED(); |
355 ShutdownAssociatedBackgroundContents( | 359 ShutdownAssociatedBackgroundContents( |
356 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> | 360 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
357 extension->id())); | 361 extension->id())); |
358 break; | 362 break; |
359 } | 363 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 417 } |
414 | 418 |
415 void BackgroundContentsService::LoadBackgroundContentsForExtension( | 419 void BackgroundContentsService::LoadBackgroundContentsForExtension( |
416 Profile* profile, | 420 Profile* profile, |
417 const std::string& extension_id) { | 421 const std::string& extension_id) { |
418 // First look if the manifest specifies a background page. | 422 // First look if the manifest specifies a background page. |
419 const Extension* extension = | 423 const Extension* extension = |
420 extensions::ExtensionSystem::Get(profile)->extension_service()-> | 424 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
421 GetExtensionById(extension_id, false); | 425 GetExtensionById(extension_id, false); |
422 DCHECK(!extension || extension->is_hosted_app()); | 426 DCHECK(!extension || extension->is_hosted_app()); |
423 if (extension && extension->has_background_page()) { | 427 if (extension && BackgroundInfo::HasBackgroundPage(extension)) { |
424 LoadBackgroundContents(profile, | 428 LoadBackgroundContents(profile, |
425 extension->GetBackgroundURL(), | 429 BackgroundInfo::GetBackgroundURL(extension), |
426 ASCIIToUTF16("background"), | 430 ASCIIToUTF16("background"), |
427 UTF8ToUTF16(extension->id())); | 431 UTF8ToUTF16(extension->id())); |
428 return; | 432 return; |
429 } | 433 } |
430 | 434 |
431 // Now look in the prefs. | 435 // Now look in the prefs. |
432 if (!prefs_) | 436 if (!prefs_) |
433 return; | 437 return; |
434 const DictionaryValue* contents = | 438 const DictionaryValue* contents = |
435 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); | 439 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); |
(...skipping 25 matching lines...) Expand all Loading... |
461 UTF8ToUTF16(extension_id)); | 465 UTF8ToUTF16(extension_id)); |
462 } | 466 } |
463 | 467 |
464 void BackgroundContentsService::LoadBackgroundContentsFromManifests( | 468 void BackgroundContentsService::LoadBackgroundContentsFromManifests( |
465 Profile* profile) { | 469 Profile* profile) { |
466 const ExtensionSet* extensions = extensions::ExtensionSystem::Get(profile)-> | 470 const ExtensionSet* extensions = extensions::ExtensionSystem::Get(profile)-> |
467 extension_service()->extensions(); | 471 extension_service()->extensions(); |
468 ExtensionSet::const_iterator iter = extensions->begin(); | 472 ExtensionSet::const_iterator iter = extensions->begin(); |
469 for (; iter != extensions->end(); ++iter) { | 473 for (; iter != extensions->end(); ++iter) { |
470 const Extension* extension = *iter; | 474 const Extension* extension = *iter; |
471 if (extension->is_hosted_app() && extension->has_background_page()) { | 475 if (extension->is_hosted_app() && |
| 476 BackgroundInfo::HasBackgroundPage(extension)) { |
472 LoadBackgroundContents(profile, | 477 LoadBackgroundContents(profile, |
473 extension->GetBackgroundURL(), | 478 BackgroundInfo::GetBackgroundURL(extension), |
474 ASCIIToUTF16("background"), | 479 ASCIIToUTF16("background"), |
475 UTF8ToUTF16(extension->id())); | 480 UTF8ToUTF16(extension->id())); |
476 } | 481 } |
477 } | 482 } |
478 } | 483 } |
479 | 484 |
480 void BackgroundContentsService::LoadBackgroundContents( | 485 void BackgroundContentsService::LoadBackgroundContents( |
481 Profile* profile, | 486 Profile* profile, |
482 const GURL& url, | 487 const GURL& url, |
483 const string16& frame_name, | 488 const string16& frame_name, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 bool user_gesture, | 635 bool user_gesture, |
631 bool* was_blocked) { | 636 bool* was_blocked) { |
632 Browser* browser = chrome::FindLastActiveWithProfile( | 637 Browser* browser = chrome::FindLastActiveWithProfile( |
633 Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 638 Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
634 chrome::GetActiveDesktop()); | 639 chrome::GetActiveDesktop()); |
635 if (browser) { | 640 if (browser) { |
636 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 641 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
637 initial_pos, user_gesture, was_blocked); | 642 initial_pos, user_gesture, was_blocked); |
638 } | 643 } |
639 } | 644 } |
OLD | NEW |