Chromium Code Reviews| 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 dispatch_chrome_updated_event_(false), | |
| 142 extension_registry_observer_(this) { | |
| 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 DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type); |
| 171 case chrome::NOTIFICATION_EXTENSIONS_READY: { | |
| 172 OnExtensionsReady(); | |
| 173 break; | |
| 174 } | |
| 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: | |
| 194 NOTREACHED(); | |
| 195 break; | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 void RuntimeAPI::OnExtensionsReady() { | |
| 200 // We're done restarting Chrome after an update. | 165 // We're done restarting Chrome after an update. |
| 201 dispatch_chrome_updated_event_ = false; | 166 dispatch_chrome_updated_event_ = false; |
| 202 | 167 |
| 203 delegate_->AddUpdateObserver(this); | 168 delegate_->AddUpdateObserver(this); |
| 204 | 169 |
| 205 // RuntimeAPI is redirected in incognito, so |browser_context_| is never | 170 // RuntimeAPI is redirected in incognito, so |browser_context_| is never |
| 206 // incognito. We don't observe incognito ProcessManagers but that is OK | 171 // incognito. We don't observe incognito ProcessManagers but that is OK |
| 207 // because we don't send onStartup events to incognito browser contexts. | 172 // because we don't send onStartup events to incognito browser contexts. |
| 208 DCHECK(!browser_context_->IsOffTheRecord()); | 173 DCHECK(!browser_context_->IsOffTheRecord()); |
| 209 // Some tests use partially constructed Profiles without a process manager. | 174 // Some tests use partially constructed Profiles without a process manager. |
| 210 ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); | 175 ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); |
| 211 if (extension_system->process_manager()) | 176 if (extension_system->process_manager()) |
| 212 extension_system->process_manager()->AddObserver(this); | 177 extension_system->process_manager()->AddObserver(this); |
| 213 } | 178 } |
| 214 | 179 |
| 215 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) { | 180 void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, |
| 181 const Extension* extension) { | |
| 216 if (!dispatch_chrome_updated_event_) | 182 if (!dispatch_chrome_updated_event_) |
| 217 return; | 183 return; |
| 218 | 184 |
| 219 // Dispatch the onInstalled event with reason "chrome_update". | 185 // Dispatch the onInstalled event with reason "chrome_update". |
| 220 base::MessageLoop::current()->PostTask( | 186 base::MessageLoop::current()->PostTask( |
| 221 FROM_HERE, | 187 FROM_HERE, |
| 222 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 188 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
| 223 browser_context_, | 189 browser_context_, |
| 224 extension->id(), | 190 extension->id(), |
| 225 Version(), | 191 Version(), |
| 226 true)); | 192 true)); |
| 227 } | 193 } |
| 228 | 194 |
| 229 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { | 195 void RuntimeAPI::OnExtensionWillBeInstalled( |
| 196 content::BrowserContext* browser_context, | |
| 197 const Extension* extension, | |
| 198 bool is_update, | |
| 199 bool from_ephemeral, | |
| 200 const std::string& old_name) { | |
| 230 // Ephemeral apps are not considered to be installed and do not receive | 201 // Ephemeral apps are not considered to be installed and do not receive |
| 231 // the onInstalled() event. | 202 // the onInstalled() event. |
| 232 if (util::IsEphemeralApp(extension->id(), browser_context_)) | 203 if (util::IsEphemeralApp(extension->id(), browser_context_)) |
| 233 return; | 204 return; |
| 234 | 205 |
| 235 Version old_version = delegate_->GetPreviousExtensionVersion(extension); | 206 Version old_version = delegate_->GetPreviousExtensionVersion(extension); |
| 236 | 207 |
| 237 // Dispatch the onInstalled event. | 208 // Dispatch the onInstalled event. |
| 238 base::MessageLoop::current()->PostTask( | 209 base::MessageLoop::current()->PostTask( |
| 239 FROM_HERE, | 210 FROM_HERE, |
| 240 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 211 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
| 241 browser_context_, | 212 browser_context_, |
| 242 extension->id(), | 213 extension->id(), |
| 243 old_version, | 214 old_version, |
| 244 false)); | 215 false)); |
| 245 } | 216 } |
| 246 | 217 |
| 247 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { | 218 void RuntimeAPI::OnExtensionUninstalled( |
| 219 content::BrowserContext* browser_context, | |
| 220 const Extension* extension, | |
| 221 UninstallReason reason) { | |
| 248 // Ephemeral apps are not considered to be installed, so the uninstall URL | 222 // Ephemeral apps are not considered to be installed, so the uninstall URL |
| 249 // is not invoked when they are removed. | 223 // is not invoked when they are removed. |
| 250 if (util::IsEphemeralApp(extension->id(), browser_context_)) | 224 if (util::IsEphemeralApp(extension->id(), browser_context_)) |
| 251 return; | 225 return; |
| 252 | 226 |
| 253 RuntimeEventRouter::OnExtensionUninstalled(browser_context_, extension->id()); | 227 RuntimeEventRouter::OnExtensionUninstalled( |
| 228 browser_context_, extension->id(), reason); | |
| 254 } | 229 } |
| 255 | 230 |
| 256 void RuntimeAPI::Shutdown() { | 231 void RuntimeAPI::Shutdown() { |
| 257 // ExtensionSystem deletes its ProcessManager during the Shutdown() phase, so | 232 // ExtensionSystem deletes its ProcessManager during the Shutdown() phase, so |
| 258 // the observer must be removed here and not in the RuntimeAPI destructor. | 233 // the observer must be removed here and not in the RuntimeAPI destructor. |
| 259 ProcessManager* process_manager = | 234 ProcessManager* process_manager = |
| 260 ExtensionSystem::Get(browser_context_)->process_manager(); | 235 ExtensionSystem::Get(browser_context_)->process_manager(); |
| 261 // Some tests use partially constructed Profiles without a process manager. | 236 // Some tests use partially constructed Profiles without a process manager. |
| 262 if (process_manager) | 237 if (process_manager) |
| 263 process_manager->RemoveObserver(this); | 238 process_manager->RemoveObserver(this); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 new Event(runtime::OnRestartRequired::kEventName, | 380 new Event(runtime::OnRestartRequired::kEventName, |
| 406 core_api::runtime::OnRestartRequired::Create(reason))); | 381 core_api::runtime::OnRestartRequired::Create(reason))); |
| 407 | 382 |
| 408 DCHECK(system->event_router()); | 383 DCHECK(system->event_router()); |
| 409 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); | 384 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); |
| 410 } | 385 } |
| 411 | 386 |
| 412 // static | 387 // static |
| 413 void RuntimeEventRouter::OnExtensionUninstalled( | 388 void RuntimeEventRouter::OnExtensionUninstalled( |
| 414 content::BrowserContext* context, | 389 content::BrowserContext* context, |
| 415 const std::string& extension_id) { | 390 const std::string& extension_id, |
| 391 UninstallReason reason) { | |
| 392 if (!(reason == UNINSTALL_REASON_USER_INITIATED || | |
| 393 reason == UNINSTALL_REASON_MANAGEMENT_API)) { | |
|
not at google - send to devlin
2014/07/30 02:35:00
I'm reading through the various uninstall reasons
| |
| 394 return; | |
| 395 } | |
| 396 | |
| 416 GURL uninstall_url( | 397 GURL uninstall_url( |
| 417 GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); | 398 GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); |
| 418 | 399 |
| 419 if (uninstall_url.is_empty()) | 400 if (uninstall_url.is_empty()) |
| 420 return; | 401 return; |
| 421 | 402 |
| 422 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); | 403 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); |
| 423 } | 404 } |
| 424 | 405 |
| 425 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { | 406 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 content::ChildProcessSecurityPolicy* policy = | 511 content::ChildProcessSecurityPolicy* policy = |
| 531 content::ChildProcessSecurityPolicy::GetInstance(); | 512 content::ChildProcessSecurityPolicy::GetInstance(); |
| 532 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 513 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 533 base::DictionaryValue* dict = new base::DictionaryValue(); | 514 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 534 dict->SetString("fileSystemId", filesystem_id); | 515 dict->SetString("fileSystemId", filesystem_id); |
| 535 dict->SetString("baseName", relative_path); | 516 dict->SetString("baseName", relative_path); |
| 536 return RespondNow(OneArgument(dict)); | 517 return RespondNow(OneArgument(dict)); |
| 537 } | 518 } |
| 538 | 519 |
| 539 } // namespace extensions | 520 } // namespace extensions |
| OLD | NEW |