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