OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" | 5 #include "extensions/browser/api/runtime/runtime_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 130 |
131 static base::LazyInstance<BrowserContextKeyedAPIFactory<RuntimeAPI> > | 131 static base::LazyInstance<BrowserContextKeyedAPIFactory<RuntimeAPI> > |
132 g_factory = LAZY_INSTANCE_INITIALIZER; | 132 g_factory = LAZY_INSTANCE_INITIALIZER; |
133 | 133 |
134 // static | 134 // static |
135 BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() { | 135 BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() { |
136 return g_factory.Pointer(); | 136 return g_factory.Pointer(); |
137 } | 137 } |
138 | 138 |
139 RuntimeAPI::RuntimeAPI(content::BrowserContext* context) | 139 RuntimeAPI::RuntimeAPI(content::BrowserContext* context) |
140 : browser_context_(context), dispatch_chrome_updated_event_(false) { | 140 : browser_context_(context), |
141 extension_registry_observer_(this), | |
142 dispatch_chrome_updated_event_(false) { | |
141 registrar_.Add(this, | 143 registrar_.Add(this, |
142 chrome::NOTIFICATION_EXTENSIONS_READY, | 144 chrome::NOTIFICATION_EXTENSIONS_READY, |
143 content::Source<BrowserContext>(context)); | 145 content::Source<BrowserContext>(context)); |
144 registrar_.Add(this, | 146 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
145 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
146 content::Source<BrowserContext>(context)); | |
147 registrar_.Add(this, | |
148 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | |
149 content::Source<BrowserContext>(context)); | |
150 registrar_.Add(this, | |
151 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | |
152 content::Source<BrowserContext>(context)); | |
153 | 147 |
154 delegate_ = ExtensionsBrowserClient::Get()->CreateRuntimeAPIDelegate( | 148 delegate_ = ExtensionsBrowserClient::Get()->CreateRuntimeAPIDelegate( |
155 browser_context_); | 149 browser_context_); |
156 | 150 |
157 // Check if registered events are up-to-date. We can only do this once | 151 // Check if registered events are up-to-date. We can only do this once |
158 // per browser context, since it updates internal state when called. | 152 // per browser context, since it updates internal state when called. |
159 dispatch_chrome_updated_event_ = | 153 dispatch_chrome_updated_event_ = |
160 ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_); | 154 ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_); |
161 } | 155 } |
162 | 156 |
163 RuntimeAPI::~RuntimeAPI() { | 157 RuntimeAPI::~RuntimeAPI() { |
164 delegate_->RemoveUpdateObserver(this); | 158 delegate_->RemoveUpdateObserver(this); |
165 } | 159 } |
166 | 160 |
167 void RuntimeAPI::Observe(int type, | 161 void RuntimeAPI::Observe(int type, |
168 const content::NotificationSource& source, | 162 const content::NotificationSource& source, |
169 const content::NotificationDetails& details) { | 163 const content::NotificationDetails& details) { |
170 switch (type) { | 164 switch (type) { |
Devlin
2014/07/22 00:26:58
Let's make this DCHECK_EQ(chrome::NOTIFICATION_EXT
rpaquay
2014/07/22 16:34:21
Done.
Devlin
2014/07/22 22:21:12
Sorry, what I meant by this was to do:
DCHECK_EQ(.
rpaquay
2014/07/23 00:03:59
Done.
| |
171 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 165 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
172 OnExtensionsReady(); | 166 OnExtensionsReady(); |
173 break; | 167 break; |
174 } | 168 } |
175 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | |
176 const Extension* extension = | |
177 content::Details<const Extension>(details).ptr(); | |
178 OnExtensionLoaded(extension); | |
179 break; | |
180 } | |
181 case chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { | |
182 const Extension* extension = | |
183 content::Details<const InstalledExtensionInfo>(details)->extension; | |
184 OnExtensionInstalled(extension); | |
185 break; | |
186 } | |
187 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { | |
188 const Extension* extension = | |
189 content::Details<const Extension>(details).ptr(); | |
190 OnExtensionUninstalled(extension); | |
191 break; | |
192 } | |
193 default: | 169 default: |
194 NOTREACHED(); | 170 NOTREACHED(); |
195 break; | 171 break; |
196 } | 172 } |
197 } | 173 } |
198 | 174 |
175 void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, | |
176 const Extension* extension) { | |
177 OnExtensionLoaded(extension); | |
Devlin
2014/07/22 00:26:59
Let's put the OnExtensionLoaded method body in her
rpaquay
2014/07/22 16:34:21
Done.
| |
178 } | |
179 | |
180 void RuntimeAPI::OnExtensionWillBeInstalled( | |
181 content::BrowserContext* browser_context, | |
182 const Extension* extension, | |
183 bool is_update, | |
184 bool from_ephemeral, | |
185 const std::string& old_name) { | |
186 OnExtensionInstalled(extension); | |
187 } | |
188 | |
189 void RuntimeAPI::OnExtensionUninstalled( | |
190 content::BrowserContext* browser_context, | |
191 const Extension* extension, | |
192 UninstallReason reason) { | |
193 OnExtensionUninstalled(extension, reason); | |
194 } | |
195 | |
199 void RuntimeAPI::OnExtensionsReady() { | 196 void RuntimeAPI::OnExtensionsReady() { |
200 // We're done restarting Chrome after an update. | 197 // We're done restarting Chrome after an update. |
201 dispatch_chrome_updated_event_ = false; | 198 dispatch_chrome_updated_event_ = false; |
202 | 199 |
203 delegate_->AddUpdateObserver(this); | 200 delegate_->AddUpdateObserver(this); |
204 | 201 |
205 // RuntimeAPI is redirected in incognito, so |browser_context_| is never | 202 // RuntimeAPI is redirected in incognito, so |browser_context_| is never |
206 // incognito. We don't observe incognito ProcessManagers but that is OK | 203 // incognito. We don't observe incognito ProcessManagers but that is OK |
207 // because we don't send onStartup events to incognito browser contexts. | 204 // because we don't send onStartup events to incognito browser contexts. |
208 DCHECK(!browser_context_->IsOffTheRecord()); | 205 DCHECK(!browser_context_->IsOffTheRecord()); |
(...skipping 28 matching lines...) Expand all Loading... | |
237 // Dispatch the onInstalled event. | 234 // Dispatch the onInstalled event. |
238 base::MessageLoop::current()->PostTask( | 235 base::MessageLoop::current()->PostTask( |
239 FROM_HERE, | 236 FROM_HERE, |
240 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 237 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
241 browser_context_, | 238 browser_context_, |
242 extension->id(), | 239 extension->id(), |
243 old_version, | 240 old_version, |
244 false)); | 241 false)); |
245 } | 242 } |
246 | 243 |
247 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { | 244 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension, |
245 UninstallReason reason) { | |
248 // Ephemeral apps are not considered to be installed, so the uninstall URL | 246 // Ephemeral apps are not considered to be installed, so the uninstall URL |
249 // is not invoked when they are removed. | 247 // is not invoked when they are removed. |
250 if (util::IsEphemeralApp(extension->id(), browser_context_)) | 248 if (util::IsEphemeralApp(extension->id(), browser_context_)) |
251 return; | 249 return; |
252 | 250 |
253 RuntimeEventRouter::OnExtensionUninstalled(browser_context_, extension->id()); | 251 RuntimeEventRouter::OnExtensionUninstalled( |
252 browser_context_, extension->id(), reason); | |
254 } | 253 } |
255 | 254 |
256 void RuntimeAPI::Shutdown() { | 255 void RuntimeAPI::Shutdown() { |
257 // ExtensionSystem deletes its ProcessManager during the Shutdown() phase, so | 256 // ExtensionSystem deletes its ProcessManager during the Shutdown() phase, so |
258 // the observer must be removed here and not in the RuntimeAPI destructor. | 257 // the observer must be removed here and not in the RuntimeAPI destructor. |
259 ProcessManager* process_manager = | 258 ProcessManager* process_manager = |
260 ExtensionSystem::Get(browser_context_)->process_manager(); | 259 ExtensionSystem::Get(browser_context_)->process_manager(); |
261 // Some tests use partially constructed Profiles without a process manager. | 260 // Some tests use partially constructed Profiles without a process manager. |
262 if (process_manager) | 261 if (process_manager) |
263 process_manager->RemoveObserver(this); | 262 process_manager->RemoveObserver(this); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 new Event(runtime::OnRestartRequired::kEventName, | 404 new Event(runtime::OnRestartRequired::kEventName, |
406 core_api::runtime::OnRestartRequired::Create(reason))); | 405 core_api::runtime::OnRestartRequired::Create(reason))); |
407 | 406 |
408 DCHECK(system->event_router()); | 407 DCHECK(system->event_router()); |
409 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); | 408 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); |
410 } | 409 } |
411 | 410 |
412 // static | 411 // static |
413 void RuntimeEventRouter::OnExtensionUninstalled( | 412 void RuntimeEventRouter::OnExtensionUninstalled( |
414 content::BrowserContext* context, | 413 content::BrowserContext* context, |
415 const std::string& extension_id) { | 414 const std::string& extension_id, |
415 UninstallReason reason) { | |
416 bool open_uninstall_url = (reason == UNINSTALL_REASON_USER_INITIATED) || | |
417 (reason == UNINSTALL_REASON_MANAGEMENT_API); | |
Devlin
2014/07/22 00:26:59
I think it's readable enough to inline this in the
rpaquay
2014/07/22 16:34:21
Done.
| |
418 if (!open_uninstall_url) | |
419 return; | |
420 | |
416 GURL uninstall_url( | 421 GURL uninstall_url( |
417 GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); | 422 GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); |
418 | 423 |
419 if (uninstall_url.is_empty()) | 424 if (uninstall_url.is_empty()) |
420 return; | 425 return; |
421 | 426 |
422 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); | 427 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); |
423 } | 428 } |
424 | 429 |
425 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { | 430 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 content::ChildProcessSecurityPolicy* policy = | 535 content::ChildProcessSecurityPolicy* policy = |
531 content::ChildProcessSecurityPolicy::GetInstance(); | 536 content::ChildProcessSecurityPolicy::GetInstance(); |
532 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 537 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
533 base::DictionaryValue* dict = new base::DictionaryValue(); | 538 base::DictionaryValue* dict = new base::DictionaryValue(); |
534 dict->SetString("fileSystemId", filesystem_id); | 539 dict->SetString("fileSystemId", filesystem_id); |
535 dict->SetString("baseName", relative_path); | 540 dict->SetString("baseName", relative_path); |
536 return RespondNow(OneArgument(dict)); | 541 return RespondNow(OneArgument(dict)); |
537 } | 542 } |
538 | 543 |
539 } // namespace extensions | 544 } // namespace extensions |
OLD | NEW |