| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_thread.h" | 14 #include "chrome/browser/chrome_thread.h" |
| 15 #include "chrome/browser/debugger/devtools_manager.h" | 15 #include "chrome/browser/debugger/devtools_manager.h" |
| 16 #include "chrome/browser/extensions/crx_installer.h" | 16 #include "chrome/browser/extensions/crx_installer.h" |
| 17 #include "chrome/browser/extensions/extension_bookmarks_module.h" | 17 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
| 18 #include "chrome/browser/extensions/extension_browser_event_router.h" | 18 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 19 #include "chrome/browser/extensions/extension_dom_ui.h" | 19 #include "chrome/browser/extensions/extension_dom_ui.h" |
| 20 #include "chrome/browser/extensions/extension_file_util.h" | 20 #include "chrome/browser/extensions/extension_file_util.h" |
| 21 #include "chrome/browser/extensions/extension_history_api.h" | 21 #include "chrome/browser/extensions/extension_history_api.h" |
| 22 #include "chrome/browser/extensions/extension_host.h" | 22 #include "chrome/browser/extensions/extension_host.h" |
| 23 #include "chrome/browser/extensions/extension_process_manager.h" | 23 #include "chrome/browser/extensions/extension_process_manager.h" |
| 24 #include "chrome/browser/extensions/extension_updater.h" | 24 #include "chrome/browser/extensions/extension_updater.h" |
| 25 #include "chrome/browser/extensions/external_extension_provider.h" | 25 #include "chrome/browser/extensions/external_extension_provider.h" |
| 26 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 26 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
| 27 #include "chrome/browser/profile.h" | 27 #include "chrome/browser/profile.h" |
| 28 #include "chrome/browser/net/chrome_url_request_context.h" | 28 #include "chrome/browser/net/chrome_url_request_context.h" |
| 29 #include "chrome/common/child_process_logging.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
| 31 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
| 32 #include "chrome/common/extensions/extension_error_reporter.h" | 33 #include "chrome/common/extensions/extension_error_reporter.h" |
| 33 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
| 34 #include "chrome/common/notification_type.h" | 35 #include "chrome/common/notification_type.h" |
| 35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/common/pref_service.h" | 37 #include "chrome/common/pref_service.h" |
| 37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 38 | 39 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 extensions_.push_back(extension); | 251 extensions_.push_back(extension); |
| 251 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), | 252 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 252 disabled_extensions_.end(), | 253 disabled_extensions_.end(), |
| 253 extension); | 254 extension); |
| 254 disabled_extensions_.erase(iter); | 255 disabled_extensions_.erase(iter); |
| 255 | 256 |
| 256 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, | 257 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, |
| 257 extension->GetChromeURLOverrides()); | 258 extension->GetChromeURLOverrides()); |
| 258 | 259 |
| 259 NotifyExtensionLoaded(extension); | 260 NotifyExtensionLoaded(extension); |
| 261 UpdateActiveExtensionsInCrashReporter(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 void ExtensionsService::DisableExtension(const std::string& extension_id) { | 264 void ExtensionsService::DisableExtension(const std::string& extension_id) { |
| 263 Extension* extension = GetExtensionByIdInternal(extension_id, true, false); | 265 Extension* extension = GetExtensionByIdInternal(extension_id, true, false); |
| 264 if (!extension) { | 266 if (!extension) { |
| 265 NOTREACHED() << "Trying to disable an extension that isn't enabled."; | 267 NOTREACHED() << "Trying to disable an extension that isn't enabled."; |
| 266 return; | 268 return; |
| 267 } | 269 } |
| 268 | 270 |
| 269 // Remember that we disabled it, unless it's temporary. | 271 // Remember that we disabled it, unless it's temporary. |
| 270 if (extension->location() != Extension::LOAD) | 272 if (extension->location() != Extension::LOAD) |
| 271 extension_prefs_->SetExtensionState(extension, Extension::DISABLED); | 273 extension_prefs_->SetExtensionState(extension, Extension::DISABLED); |
| 272 | 274 |
| 273 // Move it over to the disabled list. | 275 // Move it over to the disabled list. |
| 274 disabled_extensions_.push_back(extension); | 276 disabled_extensions_.push_back(extension); |
| 275 ExtensionList::iterator iter = std::find(extensions_.begin(), | 277 ExtensionList::iterator iter = std::find(extensions_.begin(), |
| 276 extensions_.end(), | 278 extensions_.end(), |
| 277 extension); | 279 extension); |
| 278 extensions_.erase(iter); | 280 extensions_.erase(iter); |
| 279 | 281 |
| 280 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, | 282 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, |
| 281 extension->GetChromeURLOverrides()); | 283 extension->GetChromeURLOverrides()); |
| 282 | 284 |
| 283 NotifyExtensionUnloaded(extension); | 285 NotifyExtensionUnloaded(extension); |
| 286 UpdateActiveExtensionsInCrashReporter(); |
| 284 } | 287 } |
| 285 | 288 |
| 286 void ExtensionsService::LoadExtension(const FilePath& extension_path) { | 289 void ExtensionsService::LoadExtension(const FilePath& extension_path) { |
| 287 ChromeThread::PostTask( | 290 ChromeThread::PostTask( |
| 288 ChromeThread::FILE, FROM_HERE, | 291 ChromeThread::FILE, FROM_HERE, |
| 289 NewRunnableMethod( | 292 NewRunnableMethod( |
| 290 backend_.get(), | 293 backend_.get(), |
| 291 &ExtensionsServiceBackend::LoadSingleExtension, | 294 &ExtensionsServiceBackend::LoadSingleExtension, |
| 292 extension_path, scoped_refptr<ExtensionsService>(this))); | 295 extension_path, scoped_refptr<ExtensionsService>(this))); |
| 293 } | 296 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 Details<Extension>(extension.get())); | 495 Details<Extension>(extension.get())); |
| 493 return; | 496 return; |
| 494 } | 497 } |
| 495 | 498 |
| 496 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); | 499 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
| 497 | 500 |
| 498 // Remove the extension from our list. | 501 // Remove the extension from our list. |
| 499 extensions_.erase(iter); | 502 extensions_.erase(iter); |
| 500 | 503 |
| 501 NotifyExtensionUnloaded(extension.get()); | 504 NotifyExtensionUnloaded(extension.get()); |
| 505 UpdateActiveExtensionsInCrashReporter(); |
| 502 } | 506 } |
| 503 | 507 |
| 504 void ExtensionsService::UnloadAllExtensions() { | 508 void ExtensionsService::UnloadAllExtensions() { |
| 505 ExtensionList::iterator iter; | 509 ExtensionList::iterator iter; |
| 506 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) | 510 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) |
| 507 delete *iter; | 511 delete *iter; |
| 508 extensions_.clear(); | 512 extensions_.clear(); |
| 509 | 513 |
| 510 // TODO(erikkay) should there be a notification for this? We can't use | 514 // TODO(erikkay) should there be a notification for this? We can't use |
| 511 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 515 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 NotificationType::EXTENSION_UPDATE_DISABLED, | 619 NotificationType::EXTENSION_UPDATE_DISABLED, |
| 616 Source<Profile>(profile_), | 620 Source<Profile>(profile_), |
| 617 Details<Extension>(extension)); | 621 Details<Extension>(extension)); |
| 618 disabled_extensions_.push_back(scoped_extension.release()); | 622 disabled_extensions_.push_back(scoped_extension.release()); |
| 619 break; | 623 break; |
| 620 default: | 624 default: |
| 621 NOTREACHED(); | 625 NOTREACHED(); |
| 622 break; | 626 break; |
| 623 } | 627 } |
| 624 } | 628 } |
| 629 |
| 630 UpdateActiveExtensionsInCrashReporter(); |
| 631 } |
| 632 |
| 633 void ExtensionsService::UpdateActiveExtensionsInCrashReporter() { |
| 634 std::vector<std::string> extension_ids; |
| 635 for (size_t i = 0; i < extensions_.size(); ++i) { |
| 636 if (!extensions_[i]->IsTheme()) |
| 637 extension_ids.push_back(extensions_[i]->id()); |
| 638 } |
| 639 |
| 640 child_process_logging::SetActiveExtensions(extension_ids); |
| 625 } | 641 } |
| 626 | 642 |
| 627 void ExtensionsService::OnExtensionInstalled(Extension* extension, | 643 void ExtensionsService::OnExtensionInstalled(Extension* extension, |
| 628 bool allow_privilege_increase) { | 644 bool allow_privilege_increase) { |
| 629 extension_prefs_->OnExtensionInstalled(extension); | 645 extension_prefs_->OnExtensionInstalled(extension); |
| 630 | 646 |
| 631 // If the extension is a theme, tell the profile (and therefore ThemeProvider) | 647 // If the extension is a theme, tell the profile (and therefore ThemeProvider) |
| 632 // to apply it. | 648 // to apply it. |
| 633 if (extension->IsTheme()) { | 649 if (extension->IsTheme()) { |
| 634 NotificationService::current()->Notify( | 650 NotificationService::current()->Notify( |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 | 981 |
| 966 void ExtensionsServiceBackend::OnExternalExtensionFound( | 982 void ExtensionsServiceBackend::OnExternalExtensionFound( |
| 967 const std::string& id, const Version* version, const FilePath& path, | 983 const std::string& id, const Version* version, const FilePath& path, |
| 968 Extension::Location location) { | 984 Extension::Location location) { |
| 969 ChromeThread::PostTask( | 985 ChromeThread::PostTask( |
| 970 ChromeThread::UI, FROM_HERE, | 986 ChromeThread::UI, FROM_HERE, |
| 971 NewRunnableMethod( | 987 NewRunnableMethod( |
| 972 frontend_, &ExtensionsService::OnExternalExtensionFound, id, | 988 frontend_, &ExtensionsService::OnExternalExtensionFound, id, |
| 973 version->GetString(), path, location)); | 989 version->GetString(), path, location)); |
| 974 } | 990 } |
| OLD | NEW |