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

Side by Side Diff: chrome/browser/background/background_contents_service.cc

Issue 425303002: Move extension notifications to extensions/browser/notification_types.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (extension-notifications) rebase Created 6 years, 4 months 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/background/background_contents_service.h" 5 #include "chrome/browser/background/background_contents_service.h"
6 6
7 #include "apps/app_load_service.h" 7 #include "apps/app_load_service.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 21 matching lines...) Expand all
32 #include "chrome/browser/ui/host_desktop.h" 32 #include "chrome/browser/ui/host_desktop.h"
33 #include "chrome/common/extensions/extension_constants.h" 33 #include "chrome/common/extensions/extension_constants.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/site_instance.h" 36 #include "content/public/browser/site_instance.h"
37 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
38 #include "extensions/browser/extension_host.h" 38 #include "extensions/browser/extension_host.h"
39 #include "extensions/browser/extension_registry.h" 39 #include "extensions/browser/extension_registry.h"
40 #include "extensions/browser/extension_system.h" 40 #include "extensions/browser/extension_system.h"
41 #include "extensions/browser/image_loader.h" 41 #include "extensions/browser/image_loader.h"
42 #include "extensions/browser/notification_types.h"
42 #include "extensions/common/constants.h" 43 #include "extensions/common/constants.h"
43 #include "extensions/common/extension.h" 44 #include "extensions/common/extension.h"
44 #include "extensions/common/extension_icon_set.h" 45 #include "extensions/common/extension_icon_set.h"
45 #include "extensions/common/extension_set.h" 46 #include "extensions/common/extension_set.h"
46 #include "extensions/common/manifest_handlers/background_info.h" 47 #include "extensions/common/manifest_handlers/background_info.h"
47 #include "extensions/common/manifest_handlers/icons_handler.h" 48 #include "extensions/common/manifest_handlers/icons_handler.h"
48 #include "grit/generated_resources.h" 49 #include "grit/generated_resources.h"
49 #include "grit/theme_resources.h" 50 #include "grit/theme_resources.h"
50 #include "ipc/ipc_message.h" 51 #include "ipc/ipc_message.h"
51 #include "ui/base/l10n/l10n_util.h" 52 #include "ui/base/l10n/l10n_util.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 { 303 {
303 std::vector<BackgroundContents*> contents; 304 std::vector<BackgroundContents*> contents;
304 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); 305 for (BackgroundContentsMap::const_iterator it = contents_map_.begin();
305 it != contents_map_.end(); ++it) 306 it != contents_map_.end(); ++it)
306 contents.push_back(it->second.contents); 307 contents.push_back(it->second.contents);
307 return contents; 308 return contents;
308 } 309 }
309 310
310 void BackgroundContentsService::StartObserving(Profile* profile) { 311 void BackgroundContentsService::StartObserving(Profile* profile) {
311 // On startup, load our background pages after extension-apps have loaded. 312 // On startup, load our background pages after extension-apps have loaded.
312 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 313 registrar_.Add(this,
314 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
313 content::Source<Profile>(profile)); 315 content::Source<Profile>(profile));
314 316
315 // Track the lifecycle of all BackgroundContents in the system to allow us 317 // Track the lifecycle of all BackgroundContents in the system to allow us
316 // to store an up-to-date list of the urls. Start tracking contents when they 318 // to store an up-to-date list of the urls. Start tracking contents when they
317 // have been opened via CreateBackgroundContents(), and stop tracking them 319 // have been opened via CreateBackgroundContents(), and stop tracking them
318 // when they are closed by script. 320 // when they are closed by script.
319 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, 321 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED,
320 content::Source<Profile>(profile)); 322 content::Source<Profile>(profile));
321 323
322 // Stop tracking BackgroundContents when they have been deleted (happens 324 // Stop tracking BackgroundContents when they have been deleted (happens
323 // during shutdown or if the render process dies). 325 // during shutdown or if the render process dies).
324 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 326 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
325 content::Source<Profile>(profile)); 327 content::Source<Profile>(profile));
326 328
327 // Track when the BackgroundContents navigates to a new URL so we can update 329 // Track when the BackgroundContents navigates to a new URL so we can update
328 // our persisted information as appropriate. 330 // our persisted information as appropriate.
329 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 331 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
330 content::Source<Profile>(profile)); 332 content::Source<Profile>(profile));
331 333
332 // Track when the extensions crash so that the user can be notified 334 // Track when the extensions crash so that the user can be notified
333 // about it, and the crashed contents can be restarted. 335 // about it, and the crashed contents can be restarted.
334 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 336 registrar_.Add(this,
337 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
335 content::Source<Profile>(profile)); 338 content::Source<Profile>(profile));
336 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, 339 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED,
337 content::Source<Profile>(profile)); 340 content::Source<Profile>(profile));
338 341
339 // Listen for extension uninstall, load, unloaded notification. 342 // Listen for extension uninstall, load, unloaded notification.
340 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); 343 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
341 } 344 }
342 345
343 void BackgroundContentsService::Observe( 346 void BackgroundContentsService::Observe(
344 int type, 347 int type,
345 const content::NotificationSource& source, 348 const content::NotificationSource& source,
346 const content::NotificationDetails& details) { 349 const content::NotificationDetails& details) {
347 switch (type) { 350 switch (type) {
348 case chrome::NOTIFICATION_EXTENSIONS_READY: { 351 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: {
349 Profile* profile = content::Source<Profile>(source).ptr(); 352 Profile* profile = content::Source<Profile>(source).ptr();
350 LoadBackgroundContentsFromManifests(profile); 353 LoadBackgroundContentsFromManifests(profile);
351 LoadBackgroundContentsFromPrefs(profile); 354 LoadBackgroundContentsFromPrefs(profile);
352 SendChangeNotification(profile); 355 SendChangeNotification(profile);
353 break; 356 break;
354 } 357 }
355 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: 358 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED:
356 BackgroundContentsShutdown( 359 BackgroundContentsShutdown(
357 content::Details<BackgroundContents>(details).ptr()); 360 content::Details<BackgroundContents>(details).ptr());
358 SendChangeNotification(content::Source<Profile>(source).ptr()); 361 SendChangeNotification(content::Source<Profile>(source).ptr());
(...skipping 19 matching lines...) Expand all
378 // extension_service can be NULL when running tests. 381 // extension_service can be NULL when running tests.
379 if (extension_service) { 382 if (extension_service) {
380 const Extension* extension = extension_service->GetExtensionById( 383 const Extension* extension = extension_service->GetExtensionById(
381 base::UTF16ToUTF8(appid), false); 384 base::UTF16ToUTF8(appid), false);
382 if (extension && BackgroundInfo::HasBackgroundPage(extension)) 385 if (extension && BackgroundInfo::HasBackgroundPage(extension))
383 break; 386 break;
384 } 387 }
385 RegisterBackgroundContents(bgcontents); 388 RegisterBackgroundContents(bgcontents);
386 break; 389 break;
387 } 390 }
388 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: 391 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED:
389 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { 392 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: {
390 Profile* profile = content::Source<Profile>(source).ptr(); 393 Profile* profile = content::Source<Profile>(source).ptr();
391 const Extension* extension = NULL; 394 const Extension* extension = NULL;
392 if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED) { 395 if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED) {
393 BackgroundContents* bg = 396 BackgroundContents* bg =
394 content::Details<BackgroundContents>(details).ptr(); 397 content::Details<BackgroundContents>(details).ptr();
395 std::string extension_id = base::UTF16ToASCII( 398 std::string extension_id = base::UTF16ToASCII(
396 BackgroundContentsServiceFactory::GetForProfile(profile)-> 399 BackgroundContentsServiceFactory::GetForProfile(profile)->
397 GetParentApplicationId(bg)); 400 GetParentApplicationId(bg));
398 extension = 401 extension =
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 bool user_gesture, 774 bool user_gesture,
772 bool* was_blocked) { 775 bool* was_blocked) {
773 Browser* browser = chrome::FindLastActiveWithProfile( 776 Browser* browser = chrome::FindLastActiveWithProfile(
774 Profile::FromBrowserContext(new_contents->GetBrowserContext()), 777 Profile::FromBrowserContext(new_contents->GetBrowserContext()),
775 chrome::GetActiveDesktop()); 778 chrome::GetActiveDesktop());
776 if (browser) { 779 if (browser) {
777 chrome::AddWebContents(browser, NULL, new_contents, disposition, 780 chrome::AddWebContents(browser, NULL, new_contents, disposition,
778 initial_pos, user_gesture, was_blocked); 781 initial_pos, user_gesture, was_blocked);
779 } 782 }
780 } 783 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_application_list_model.cc ('k') | chrome/browser/background/background_mode_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698