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

Side by Side Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 10941003: Reset registered events and dispatch runtime.onInstalled to all extensions when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ? Created 8 years, 3 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/extensions/api/runtime/runtime_api.h" 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/event_router.h" 8 #include "chrome/browser/extensions/event_router.h"
9 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_process_manager.h" 10 #include "chrome/browser/extensions/extension_process_manager.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 12 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/extensions/lazy_background_task_queue.h" 13 #include "chrome/browser/extensions/lazy_background_task_queue.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 namespace { 21 namespace {
22 22
23 const char kOnStartupEvent[] = "runtime.onStartup"; 23 const char kOnStartupEvent[] = "runtime.onStartup";
24 const char kOnInstalledEvent[] = "runtime.onInstalled"; 24 const char kOnInstalledEvent[] = "runtime.onInstalled";
25 const char kNoBackgroundPageError[] = "You do not have a background page."; 25 const char kNoBackgroundPageError[] = "You do not have a background page.";
26 const char kPageLoadError[] = "Background page failed to load."; 26 const char kPageLoadError[] = "Background page failed to load.";
27 const char kInstallReason[] = "reason"; 27 const char kInstallReason[] = "reason";
28 const char kInstallReasonChromeUpdate[] = "chrome_update";
28 const char kInstallReasonUpdate[] = "update"; 29 const char kInstallReasonUpdate[] = "update";
29 const char kInstallReasonInstall[] = "install"; 30 const char kInstallReasonInstall[] = "install";
30 const char kInstallPreviousVersion[] = "previousVersion"; 31 const char kInstallPreviousVersion[] = "previousVersion";
31 32
32 static void DispatchOnStartupEventImpl( 33 static void DispatchOnStartupEventImpl(
33 Profile* profile, 34 Profile* profile,
34 const std::string& extension_id, 35 const std::string& extension_id,
35 bool first_call, 36 bool first_call,
36 ExtensionHost* host) { 37 ExtensionHost* host) {
37 // A NULL host from the LazyBackgroundTaskQueue means the page failed to 38 // A NULL host from the LazyBackgroundTaskQueue means the page failed to
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // static 72 // static
72 void RuntimeEventRouter::DispatchOnStartupEvent( 73 void RuntimeEventRouter::DispatchOnStartupEvent(
73 Profile* profile, const std::string& extension_id) { 74 Profile* profile, const std::string& extension_id) {
74 DispatchOnStartupEventImpl(profile, extension_id, true, NULL); 75 DispatchOnStartupEventImpl(profile, extension_id, true, NULL);
75 } 76 }
76 77
77 // static 78 // static
78 void RuntimeEventRouter::DispatchOnInstalledEvent( 79 void RuntimeEventRouter::DispatchOnInstalledEvent(
79 Profile* profile, 80 Profile* profile,
80 const std::string& extension_id, 81 const std::string& extension_id,
81 const Version& old_version) { 82 const Version& old_version,
83 bool chrome_updated) {
82 ExtensionSystem* system = ExtensionSystem::Get(profile); 84 ExtensionSystem* system = ExtensionSystem::Get(profile);
83 if (!system) 85 if (!system)
84 return; 86 return;
85 87
86 // Special case: normally, extensions add their own lazy event listeners. 88 // Special case: normally, extensions add their own lazy event listeners.
87 // However, since the extension has just been installed, it hasn't had a 89 // However, since the extension has just been installed, it hasn't had a
88 // chance to register for events. So we register on its behalf. If the 90 // chance to register for events. So we register on its behalf. If the
89 // extension does not actually have a listener, the event will just be 91 // extension does not actually have a listener, the event will just be
90 // ignored. 92 // ignored.
91 scoped_ptr<base::ListValue> event_args(new ListValue()); 93 scoped_ptr<base::ListValue> event_args(new ListValue());
92 base::DictionaryValue* info = new base::DictionaryValue(); 94 base::DictionaryValue* info = new base::DictionaryValue();
93 event_args->Append(info); 95 event_args->Append(info);
94 info->SetString(kInstallReason, 96 if (old_version.IsValid()) {
95 old_version.IsValid() ? kInstallReasonUpdate : kInstallReasonInstall); 97 info->SetString(kInstallReason, kInstallReasonUpdate);
96 if (old_version.IsValid())
97 info->SetString(kInstallPreviousVersion, old_version.GetString()); 98 info->SetString(kInstallPreviousVersion, old_version.GetString());
99 } else if (chrome_updated) {
100 info->SetString(kInstallReason, kInstallReasonChromeUpdate);
101 } else {
102 info->SetString(kInstallReason, kInstallReasonInstall);
103 }
98 system->event_router()->AddLazyEventListener(kOnInstalledEvent, extension_id); 104 system->event_router()->AddLazyEventListener(kOnInstalledEvent, extension_id);
99 system->event_router()->DispatchEventToExtension( 105 system->event_router()->DispatchEventToExtension(
100 extension_id, kOnInstalledEvent, event_args.Pass(), NULL, GURL()); 106 extension_id, kOnInstalledEvent, event_args.Pass(), NULL, GURL());
101 system->event_router()->RemoveLazyEventListener(kOnInstalledEvent, 107 system->event_router()->RemoveLazyEventListener(kOnInstalledEvent,
102 extension_id); 108 extension_id);
103 } 109 }
104 110
105 bool RuntimeGetBackgroundPageFunction::RunImpl() { 111 bool RuntimeGetBackgroundPageFunction::RunImpl() {
106 ExtensionHost* host = 112 ExtensionHost* host =
107 ExtensionSystem::Get(profile())->process_manager()-> 113 ExtensionSystem::Get(profile())->process_manager()->
(...skipping 17 matching lines...) Expand all
125 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { 131 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) {
126 if (host) { 132 if (host) {
127 SendResponse(true); 133 SendResponse(true);
128 } else { 134 } else {
129 error_ = kPageLoadError; 135 error_ = kPageLoadError;
130 SendResponse(false); 136 SendResponse(false);
131 } 137 }
132 } 138 }
133 139
134 } // namespace extensions 140 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698