| OLD | NEW |
| 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/string16.h" | |
| 21 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
| 22 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 23 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 24 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| 25 #include "base/time.h" | 24 #include "base/time.h" |
| 26 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
| 27 #include "base/values.h" | 26 #include "base/values.h" |
| 28 #include "base/version.h" | 27 #include "base/version.h" |
| 29 #include "chrome/browser/accessibility/accessibility_extension_api.h" | 28 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 30 #include "chrome/browser/bookmarks/bookmark_extension_api.h" | 29 #include "chrome/browser/bookmarks/bookmark_extension_api.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 #include "chrome/common/url_constants.h" | 97 #include "chrome/common/url_constants.h" |
| 99 #include "content/public/browser/browser_thread.h" | 98 #include "content/public/browser/browser_thread.h" |
| 100 #include "content/public/browser/devtools_agent_host_registry.h" | 99 #include "content/public/browser/devtools_agent_host_registry.h" |
| 101 #include "content/public/browser/devtools_manager.h" | 100 #include "content/public/browser/devtools_manager.h" |
| 102 #include "content/public/browser/notification_service.h" | 101 #include "content/public/browser/notification_service.h" |
| 103 #include "content/public/browser/notification_types.h" | 102 #include "content/public/browser/notification_types.h" |
| 104 #include "content/public/browser/plugin_service.h" | 103 #include "content/public/browser/plugin_service.h" |
| 105 #include "content/public/browser/render_process_host.h" | 104 #include "content/public/browser/render_process_host.h" |
| 106 #include "content/public/common/pepper_plugin_info.h" | 105 #include "content/public/common/pepper_plugin_info.h" |
| 107 #include "googleurl/src/gurl.h" | 106 #include "googleurl/src/gurl.h" |
| 107 #include "grit/generated_resources.h" |
| 108 #include "net/base/registry_controlled_domain.h" | 108 #include "net/base/registry_controlled_domain.h" |
| 109 #include "sync/api/sync_change.h" | 109 #include "sync/api/sync_change.h" |
| 110 #include "sync/api/sync_error_factory.h" | 110 #include "sync/api/sync_error_factory.h" |
| 111 #include "ui/base/l10n/l10n_util.h" |
| 111 #include "webkit/database/database_tracker.h" | 112 #include "webkit/database/database_tracker.h" |
| 112 #include "webkit/database/database_util.h" | 113 #include "webkit/database/database_util.h" |
| 113 | 114 |
| 114 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
| 115 #include "chrome/browser/chromeos/cros/cros_library.h" | 116 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 116 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | 117 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" |
| 117 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 118 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 118 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 119 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| 119 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" | 120 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
| 120 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 121 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 298 |
| 298 // We can't call UninstallExtension with an invalid extension ID. | 299 // We can't call UninstallExtension with an invalid extension ID. |
| 299 if (!extension) { | 300 if (!extension) { |
| 300 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " | 301 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
| 301 << "id: " << extension_id; | 302 << "id: " << extension_id; |
| 302 return false; | 303 return false; |
| 303 } | 304 } |
| 304 | 305 |
| 305 // The following call to UninstallExtension will not allow an uninstall of a | 306 // The following call to UninstallExtension will not allow an uninstall of a |
| 306 // policy-controlled extension. | 307 // policy-controlled extension. |
| 307 std::string error; | 308 string16 error; |
| 308 if (!extensions_service->UninstallExtension(extension_id, false, &error)) { | 309 if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 309 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id | 310 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 310 << ": " << error; | 311 << ": " << error; |
| 311 return false; | 312 return false; |
| 312 } | 313 } |
| 313 | 314 |
| 314 return true; | 315 return true; |
| 315 } | 316 } |
| 316 | 317 |
| 317 ExtensionService::ExtensionService(Profile* profile, | 318 ExtensionService::ExtensionService(Profile* profile, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 // We should always be able to remember the extension's path. If it's not in | 672 // We should always be able to remember the extension's path. If it's not in |
| 672 // the map, someone failed to update |unloaded_extension_paths_|. | 673 // the map, someone failed to update |unloaded_extension_paths_|. |
| 673 CHECK(!path.empty()); | 674 CHECK(!path.empty()); |
| 674 extensions::UnpackedInstaller::Create(this)->Load(path); | 675 extensions::UnpackedInstaller::Create(this)->Load(path); |
| 675 } | 676 } |
| 676 } | 677 } |
| 677 | 678 |
| 678 bool ExtensionService::UninstallExtension( | 679 bool ExtensionService::UninstallExtension( |
| 679 std::string extension_id, | 680 std::string extension_id, |
| 680 bool external_uninstall, | 681 bool external_uninstall, |
| 681 std::string* error) { | 682 string16* error) { |
| 682 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 683 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 683 | 684 |
| 684 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); | 685 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); |
| 685 | 686 |
| 686 // Callers should not send us nonexistent extensions. | 687 // Callers should not send us nonexistent extensions. |
| 687 CHECK(extension); | 688 CHECK(extension); |
| 688 | 689 |
| 689 // Policy change which triggers an uninstall will always set | 690 // Policy change which triggers an uninstall will always set |
| 690 // |external_uninstall| to true so this is the only way to uninstall | 691 // |external_uninstall| to true so this is the only way to uninstall |
| 691 // managed extensions. | 692 // managed extensions. |
| 692 if (!Extension::UserMayDisable(extension->location()) && | 693 if (!external_uninstall && |
| 693 !external_uninstall) { | 694 !system_->management_policy()->UserMayModifySettings( |
| 695 extension.get(), error)) { |
| 694 content::NotificationService::current()->Notify( | 696 content::NotificationService::current()->Notify( |
| 695 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 697 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 696 content::Source<Profile>(profile_), | 698 content::Source<Profile>(profile_), |
| 697 content::Details<const Extension>(extension)); | 699 content::Details<const Extension>(extension)); |
| 698 if (error != NULL) { | |
| 699 *error = errors::kCannotUninstallManagedExtension; | |
| 700 } | |
| 701 return false; | 700 return false; |
| 702 } | 701 } |
| 703 | 702 |
| 704 // Extract the data we need for sync now, but don't actually sync until we've | 703 // Extract the data we need for sync now, but don't actually sync until we've |
| 705 // completed the uninstallation. | 704 // completed the uninstallation. |
| 706 SyncChange sync_change; | 705 SyncChange sync_change; |
| 707 if (app_sync_bundle_.HandlesApp(*extension)) { | 706 if (app_sync_bundle_.HandlesApp(*extension)) { |
| 708 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension); | 707 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension); |
| 709 } else if (extension_sync_bundle_.HandlesExtension(*extension)) { | 708 } else if (extension_sync_bundle_.HandlesExtension(*extension)) { |
| 710 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension); | 709 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 Extension::DisableReason disable_reason) { | 840 Extension::DisableReason disable_reason) { |
| 842 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 841 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 843 | 842 |
| 844 // The extension may have been disabled already. | 843 // The extension may have been disabled already. |
| 845 if (!IsExtensionEnabled(extension_id)) | 844 if (!IsExtensionEnabled(extension_id)) |
| 846 return; | 845 return; |
| 847 | 846 |
| 848 const Extension* extension = GetInstalledExtension(extension_id); | 847 const Extension* extension = GetInstalledExtension(extension_id); |
| 849 // |extension| can be NULL if sync disables an extension that is not | 848 // |extension| can be NULL if sync disables an extension that is not |
| 850 // installed yet. | 849 // installed yet. |
| 851 if (extension && !Extension::UserMayDisable(extension->location())) | 850 if (extension && |
| 851 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
| 852 return; | 852 return; |
| 853 } |
| 853 | 854 |
| 854 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 855 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
| 855 extension_prefs_->SetDisableReason(extension_id, disable_reason); | 856 extension_prefs_->SetDisableReason(extension_id, disable_reason); |
| 856 | 857 |
| 857 extension = GetExtensionByIdInternal(extension_id, true, false, true); | 858 extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 858 if (!extension) | 859 if (!extension) |
| 859 return; | 860 return; |
| 860 | 861 |
| 861 // Move it over to the disabled list. | 862 // Move it over to the disabled list. |
| 862 disabled_extensions_.Insert(make_scoped_refptr(extension)); | 863 disabled_extensions_.Insert(make_scoped_refptr(extension)); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 extensions::ExtensionUpdater* ExtensionService::updater() { | 1148 extensions::ExtensionUpdater* ExtensionService::updater() { |
| 1148 return updater_.get(); | 1149 return updater_.get(); |
| 1149 } | 1150 } |
| 1150 | 1151 |
| 1151 void ExtensionService::CheckAdminBlacklist() { | 1152 void ExtensionService::CheckAdminBlacklist() { |
| 1152 std::vector<std::string> to_be_removed; | 1153 std::vector<std::string> to_be_removed; |
| 1153 // Loop through extensions list, unload installed extensions. | 1154 // Loop through extensions list, unload installed extensions. |
| 1154 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 1155 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 1155 iter != extensions_.end(); ++iter) { | 1156 iter != extensions_.end(); ++iter) { |
| 1156 const Extension* extension = (*iter); | 1157 const Extension* extension = (*iter); |
| 1157 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(), | 1158 if (!system_->management_policy()->UserMayLoad(extension, NULL)) { |
| 1158 extension->location())) { | |
| 1159 to_be_removed.push_back(extension->id()); | 1159 to_be_removed.push_back(extension->id()); |
| 1160 } | 1160 } |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 // UnloadExtension will change the extensions_ list. So, we should | 1163 // UnloadExtension will change the extensions_ list. So, we should |
| 1164 // call it outside the iterator loop. | 1164 // call it outside the iterator loop. |
| 1165 for (unsigned int i = 0; i < to_be_removed.size(); ++i) | 1165 for (unsigned int i = 0; i < to_be_removed.size(); ++i) |
| 1166 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); | 1166 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
| 1167 } | 1167 } |
| 1168 | 1168 |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2090 const StringOrdinal& page_ordinal) { | 2090 const StringOrdinal& page_ordinal) { |
| 2091 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2091 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2092 | 2092 |
| 2093 // Ensure extension is deleted unless we transfer ownership. | 2093 // Ensure extension is deleted unless we transfer ownership. |
| 2094 scoped_refptr<const Extension> scoped_extension(extension); | 2094 scoped_refptr<const Extension> scoped_extension(extension); |
| 2095 const std::string& id = extension->id(); | 2095 const std::string& id = extension->id(); |
| 2096 // Extensions installed by policy can't be disabled. So even if a previous | 2096 // Extensions installed by policy can't be disabled. So even if a previous |
| 2097 // installation disabled the extension, make sure it is now enabled. | 2097 // installation disabled the extension, make sure it is now enabled. |
| 2098 bool initial_enable = | 2098 bool initial_enable = |
| 2099 !extension_prefs_->IsExtensionDisabled(id) || | 2099 !extension_prefs_->IsExtensionDisabled(id) || |
| 2100 !Extension::UserMayDisable(extension->location()); | 2100 system_->management_policy()->MustRemainEnabled(extension, NULL); |
| 2101 PendingExtensionInfo pending_extension_info; | 2101 PendingExtensionInfo pending_extension_info; |
| 2102 if (pending_extension_manager()->GetById(id, &pending_extension_info)) { | 2102 if (pending_extension_manager()->GetById(id, &pending_extension_info)) { |
| 2103 pending_extension_manager()->Remove(id); | 2103 pending_extension_manager()->Remove(id); |
| 2104 | 2104 |
| 2105 if (!pending_extension_info.ShouldAllowInstall(*extension)) { | 2105 if (!pending_extension_info.ShouldAllowInstall(*extension)) { |
| 2106 LOG(WARNING) | 2106 LOG(WARNING) |
| 2107 << "ShouldAllowInstall() returned false for " | 2107 << "ShouldAllowInstall() returned false for " |
| 2108 << id << " of type " << extension->GetType() | 2108 << id << " of type " << extension->GetType() |
| 2109 << " and update URL " << extension->update_url().spec() | 2109 << " and update URL " << extension->update_url().spec() |
| 2110 << "; not installing"; | 2110 << "; not installing"; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2547 | 2547 |
| 2548 // To coexist with certain unit tests that don't have a work-thread message | 2548 // To coexist with certain unit tests that don't have a work-thread message |
| 2549 // loop available at ExtensionService shutdown, we lazy-initialize this | 2549 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2550 // object so that those cases neither create nor destroy an | 2550 // object so that those cases neither create nor destroy an |
| 2551 // APIResourceController. | 2551 // APIResourceController. |
| 2552 if (!api_resource_controller_.get()) { | 2552 if (!api_resource_controller_.get()) { |
| 2553 api_resource_controller_.reset(new extensions::APIResourceController()); | 2553 api_resource_controller_.reset(new extensions::APIResourceController()); |
| 2554 } | 2554 } |
| 2555 return api_resource_controller_.get(); | 2555 return api_resource_controller_.get(); |
| 2556 } | 2556 } |
| OLD | NEW |