| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/extensions/extension_browser_event_router.h" | 22 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 23 #include "chrome/browser/extensions/extension_data_deleter.h" | 23 #include "chrome/browser/extensions/extension_data_deleter.h" |
| 24 #include "chrome/browser/extensions/extension_dom_ui.h" | 24 #include "chrome/browser/extensions/extension_dom_ui.h" |
| 25 #include "chrome/browser/extensions/extension_error_reporter.h" | 25 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 26 #include "chrome/browser/extensions/extension_history_api.h" | 26 #include "chrome/browser/extensions/extension_history_api.h" |
| 27 #include "chrome/browser/extensions/extension_host.h" | 27 #include "chrome/browser/extensions/extension_host.h" |
| 28 #include "chrome/browser/extensions/extension_process_manager.h" | 28 #include "chrome/browser/extensions/extension_process_manager.h" |
| 29 #include "chrome/browser/extensions/extension_updater.h" | 29 #include "chrome/browser/extensions/extension_updater.h" |
| 30 #include "chrome/browser/extensions/external_extension_provider.h" | 30 #include "chrome/browser/extensions/external_extension_provider.h" |
| 31 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 31 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
| 32 #include "chrome/browser/net/chrome_url_request_context.h" |
| 32 #include "chrome/browser/pref_service.h" | 33 #include "chrome/browser/pref_service.h" |
| 33 #include "chrome/browser/profile.h" | 34 #include "chrome/browser/profile.h" |
| 34 #include "chrome/browser/net/chrome_url_request_context.h" | 35 #include "chrome/browser/search_engines/template_url_model.h" |
| 35 #include "chrome/common/child_process_logging.h" | 36 #include "chrome/common/child_process_logging.h" |
| 36 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/extensions/extension.h" | 38 #include "chrome/common/extensions/extension.h" |
| 38 #include "chrome/common/extensions/extension_constants.h" | 39 #include "chrome/common/extensions/extension_constants.h" |
| 39 #include "chrome/common/extensions/extension_file_util.h" | 40 #include "chrome/common/extensions/extension_file_util.h" |
| 40 #include "chrome/common/extensions/extension_l10n_util.h" | 41 #include "chrome/common/extensions/extension_l10n_util.h" |
| 41 #include "chrome/common/notification_service.h" | 42 #include "chrome/common/notification_service.h" |
| 42 #include "chrome/common/notification_type.h" | 43 #include "chrome/common/notification_type.h" |
| 43 #include "chrome/common/json_value_serializer.h" | 44 #include "chrome/common/json_value_serializer.h" |
| 44 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 318 |
| 318 // Get hold of information we need after unloading, since the extension | 319 // Get hold of information we need after unloading, since the extension |
| 319 // pointer will be invalid then. | 320 // pointer will be invalid then. |
| 320 GURL extension_url(extension->url()); | 321 GURL extension_url(extension->url()); |
| 321 Extension::Location location(extension->location()); | 322 Extension::Location location(extension->location()); |
| 322 | 323 |
| 323 // Also copy the extension identifier since the reference might have been | 324 // Also copy the extension identifier since the reference might have been |
| 324 // obtained via Extension::id(). | 325 // obtained via Extension::id(). |
| 325 std::string extension_id_copy(extension_id); | 326 std::string extension_id_copy(extension_id); |
| 326 | 327 |
| 328 if (profile_->GetTemplateURLModel()) |
| 329 profile_->GetTemplateURLModel()->UnregisterExtensionKeyword(extension); |
| 330 |
| 327 // Unload before doing more cleanup to ensure that nothing is hanging on to | 331 // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 328 // any of these resources. | 332 // any of these resources. |
| 329 UnloadExtension(extension_id); | 333 UnloadExtension(extension_id); |
| 330 | 334 |
| 331 extension_prefs_->OnExtensionUninstalled(extension_id_copy, location, | 335 extension_prefs_->OnExtensionUninstalled(extension_id_copy, location, |
| 332 external_uninstall); | 336 external_uninstall); |
| 333 | 337 |
| 334 // Tell the backend to start deleting installed extensions on the file thread. | 338 // Tell the backend to start deleting installed extensions on the file thread. |
| 335 if (Extension::LOAD != location) { | 339 if (Extension::LOAD != location) { |
| 336 ChromeThread::PostTask( | 340 ChromeThread::PostTask( |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 ready_ = true; | 760 ready_ = true; |
| 757 if (updater_.get()) { | 761 if (updater_.get()) { |
| 758 updater_->Start(); | 762 updater_->Start(); |
| 759 } | 763 } |
| 760 NotificationService::current()->Notify( | 764 NotificationService::current()->Notify( |
| 761 NotificationType::EXTENSIONS_READY, | 765 NotificationType::EXTENSIONS_READY, |
| 762 Source<Profile>(profile_), | 766 Source<Profile>(profile_), |
| 763 NotificationService::NoDetails()); | 767 NotificationService::NoDetails()); |
| 764 } | 768 } |
| 765 | 769 |
| 766 void ExtensionsService::OnExtensionLoaded(Extension* extension, | 770 bool ExtensionsService::OnExtensionLoaded(Extension* extension, |
| 767 bool allow_privilege_increase) { | 771 bool allow_privilege_increase) { |
| 768 // Ensure extension is deleted unless we transfer ownership. | 772 // Ensure extension is deleted unless we transfer ownership. |
| 769 scoped_ptr<Extension> scoped_extension(extension); | 773 scoped_ptr<Extension> scoped_extension(extension); |
| 770 | 774 |
| 771 // The extension is now loaded, remove its data from unloaded extension map. | 775 // The extension is now loaded, remove its data from unloaded extension map. |
| 772 unloaded_extension_paths_.erase(extension->id()); | 776 unloaded_extension_paths_.erase(extension->id()); |
| 773 | 777 |
| 774 // TODO(aa): Need to re-evaluate this branch. Does this still make sense now | 778 // TODO(aa): Need to re-evaluate this branch. Does this still make sense now |
| 775 // that extensions are enabled by default? | 779 // that extensions are enabled by default? |
| 776 if (extensions_enabled() || | 780 if (extensions_enabled() || |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 break; | 828 break; |
| 825 default: | 829 default: |
| 826 NOTREACHED(); | 830 NOTREACHED(); |
| 827 break; | 831 break; |
| 828 } | 832 } |
| 829 } | 833 } |
| 830 | 834 |
| 831 extension->set_being_upgraded(false); | 835 extension->set_being_upgraded(false); |
| 832 | 836 |
| 833 UpdateActiveExtensionsInCrashReporter(); | 837 UpdateActiveExtensionsInCrashReporter(); |
| 838 return true; |
| 834 } | 839 } |
| 835 | 840 |
| 836 void ExtensionsService::UpdateActiveExtensionsInCrashReporter() { | 841 void ExtensionsService::UpdateActiveExtensionsInCrashReporter() { |
| 837 std::set<std::string> extension_ids; | 842 std::set<std::string> extension_ids; |
| 838 for (size_t i = 0; i < extensions_.size(); ++i) { | 843 for (size_t i = 0; i < extensions_.size(); ++i) { |
| 839 if (!extensions_[i]->IsTheme()) | 844 if (!extensions_[i]->IsTheme()) |
| 840 extension_ids.insert(extensions_[i]->id()); | 845 extension_ids.insert(extensions_[i]->id()); |
| 841 } | 846 } |
| 842 | 847 |
| 843 child_process_logging::SetActiveExtensions(extension_ids); | 848 child_process_logging::SetActiveExtensions(extension_ids); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 871 Source<Profile>(profile_), | 876 Source<Profile>(profile_), |
| 872 Details<Extension>(extension)); | 877 Details<Extension>(extension)); |
| 873 } else { | 878 } else { |
| 874 NotificationService::current()->Notify( | 879 NotificationService::current()->Notify( |
| 875 NotificationType::EXTENSION_INSTALLED, | 880 NotificationType::EXTENSION_INSTALLED, |
| 876 Source<Profile>(profile_), | 881 Source<Profile>(profile_), |
| 877 Details<Extension>(extension)); | 882 Details<Extension>(extension)); |
| 878 } | 883 } |
| 879 | 884 |
| 880 // Also load the extension. | 885 // Also load the extension. |
| 881 OnExtensionLoaded(extension, allow_privilege_increase); | 886 bool success = OnExtensionLoaded(extension, allow_privilege_increase); |
| 887 if (!success) |
| 888 extension = NULL; // extension is deleted on failure. |
| 882 | 889 |
| 883 // Erase any pending extension. | 890 // Erase any pending extension. |
| 884 if (it != pending_extensions_.end()) { | 891 if (it != pending_extensions_.end()) { |
| 885 pending_extensions_.erase(it); | 892 pending_extensions_.erase(it); |
| 886 } | 893 } |
| 894 |
| 895 if (success && profile_->GetTemplateURLModel()) |
| 896 profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); |
| 887 } | 897 } |
| 888 | 898 |
| 889 Extension* ExtensionsService::GetExtensionByIdInternal(const std::string& id, | 899 Extension* ExtensionsService::GetExtensionByIdInternal(const std::string& id, |
| 890 bool include_enabled, | 900 bool include_enabled, |
| 891 bool include_disabled) { | 901 bool include_disabled) { |
| 892 std::string lowercase_id = StringToLowerASCII(id); | 902 std::string lowercase_id = StringToLowerASCII(id); |
| 893 if (include_enabled) { | 903 if (include_enabled) { |
| 894 for (ExtensionList::const_iterator iter = extensions_.begin(); | 904 for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 895 iter != extensions_.end(); ++iter) { | 905 iter != extensions_.end(); ++iter) { |
| 896 if ((*iter)->id() == lowercase_id) | 906 if ((*iter)->id() == lowercase_id) |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 // Finish installing on UI thread. | 1208 // Finish installing on UI thread. |
| 1199 ChromeThread::PostTask( | 1209 ChromeThread::PostTask( |
| 1200 ChromeThread::UI, FROM_HERE, | 1210 ChromeThread::UI, FROM_HERE, |
| 1201 NewRunnableMethod( | 1211 NewRunnableMethod( |
| 1202 frontend_, | 1212 frontend_, |
| 1203 &ExtensionsService::ContinueLoadAllExtensions, | 1213 &ExtensionsService::ContinueLoadAllExtensions, |
| 1204 extensions_to_reload, | 1214 extensions_to_reload, |
| 1205 start_time, | 1215 start_time, |
| 1206 true)); | 1216 true)); |
| 1207 } | 1217 } |
| OLD | NEW |