Chromium Code Reviews| 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/installed_loader.h" | 5 #include "chrome/browser/extensions/installed_loader.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" | |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_file_util.h" | 17 #include "chrome/common/extensions/extension_file_util.h" |
| 17 #include "chrome/common/extensions/extension_l10n_util.h" | 18 #include "chrome/common/extensions/extension_l10n_util.h" |
| 18 #include "chrome/common/extensions/extension_manifest_constants.h" | 19 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 19 #include "chrome/common/extensions/manifest.h" | 20 #include "chrome/common/extensions/manifest.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/user_metrics.h" | 23 #include "content/public/browser/user_metrics.h" |
| 23 | 24 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 : extension_service_(extension_service), | 62 : extension_service_(extension_service), |
| 62 extension_prefs_(extension_service->extension_prefs()) { | 63 extension_prefs_(extension_service->extension_prefs()) { |
| 63 } | 64 } |
| 64 | 65 |
| 65 InstalledLoader::~InstalledLoader() { | 66 InstalledLoader::~InstalledLoader() { |
| 66 } | 67 } |
| 67 | 68 |
| 68 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) { | 69 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) { |
| 69 std::string error; | 70 std::string error; |
| 70 scoped_refptr<const Extension> extension(NULL); | 71 scoped_refptr<const Extension> extension(NULL); |
| 71 // An explicit check against policy is required to behave correctly during | 72 if (info.extension_manifest.get()) { |
| 72 // startup. This is because extensions that were previously OK might have | |
| 73 // been blacklisted in policy while Chrome was not running. | |
| 74 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id, | |
| 75 info.extension_location)) { | |
| 76 error = errors::kDisabledByPolicy; | |
| 77 } else if (info.extension_manifest.get()) { | |
| 78 extension = Extension::Create( | 73 extension = Extension::Create( |
|
Pam (message me for reviews)
2012/05/22 12:51:07
Is it permissible to Create the extension before c
| |
| 79 info.extension_path, | 74 info.extension_path, |
| 80 info.extension_location, | 75 info.extension_location, |
| 81 *info.extension_manifest, | 76 *info.extension_manifest, |
| 82 GetCreationFlags(&info), | 77 GetCreationFlags(&info), |
| 83 &error); | 78 &error); |
| 84 } else { | 79 } else { |
| 85 error = errors::kManifestUnreadable; | 80 error = errors::kManifestUnreadable; |
| 86 } | 81 } |
| 87 | 82 |
| 88 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by | 83 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by |
| 89 // updating the 'key' field in their manifest). | 84 // updating the 'key' field in their manifest). |
| 90 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. | 85 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. |
| 91 if (extension && | 86 if (extension && |
| 92 extension->location() != Extension::LOAD && | 87 extension->location() != Extension::LOAD && |
| 93 info.extension_id != extension->id()) { | 88 info.extension_id != extension->id()) { |
| 94 error = errors::kCannotChangeExtensionID; | 89 error = errors::kCannotChangeExtensionID; |
| 95 extension = NULL; | 90 extension = NULL; |
| 96 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); | 91 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); |
| 97 } | 92 } |
| 98 | 93 |
| 94 // An explicit check against policy is required to behave correctly during | |
| 95 // startup. This is because extensions that were previously OK might have | |
| 96 // been blacklisted in policy while Chrome was not running. | |
| 97 // This isn't a new extension installation, so it's OK if some extension | |
| 98 // management policy delegates aren't yet registered with the | |
| 99 // ExtensionService. Admin policy is handled by the ExtensionPrefs class, | |
| 100 // which is created before the ExtensionService itself, so we have what we | |
| 101 // need here. | |
| 102 if (extension && | |
| 103 !ExtensionSystem::Get(extension_service_->profile())->management_policy() | |
| 104 ->UserMayLoad(extension, info.extension_location, NULL)) { | |
|
Pam (message me for reviews)
2012/05/22 12:51:07
On 2012/05/17 22:41:06, Aaron Boodman wrote:
> May
| |
| 105 // The error message from UserMayInstall() often contain the extension ID | |
| 106 // and is therefore not well suited to this UI. | |
|
Pam (message me for reviews)
2012/05/22 12:51:07
It is typically IDS_EXTENSION_CANT_INSTALL_POLICY_
| |
| 107 error = errors::kDisabledByPolicy; | |
| 108 extension = NULL; | |
| 109 } | |
| 110 | |
| 99 if (!extension) { | 111 if (!extension) { |
| 100 extension_service_-> | 112 extension_service_-> |
| 101 ReportExtensionLoadError(info.extension_path, error, false); | 113 ReportExtensionLoadError(info.extension_path, error, false); |
| 102 return; | 114 return; |
| 103 } | 115 } |
| 104 | 116 |
| 105 if (write_to_prefs) | 117 if (write_to_prefs) |
| 106 extension_prefs_->UpdateManifest(extension); | 118 extension_prefs_->UpdateManifest(extension); |
| 107 | 119 |
| 108 extension_service_->AddExtension(extension); | 120 extension_service_->AddExtension(extension); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 if (extension_prefs_->AllowFileAccess(info->extension_id)) | 309 if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 298 flags |= Extension::ALLOW_FILE_ACCESS; | 310 flags |= Extension::ALLOW_FILE_ACCESS; |
| 299 if (extension_prefs_->IsFromWebStore(info->extension_id)) | 311 if (extension_prefs_->IsFromWebStore(info->extension_id)) |
| 300 flags |= Extension::FROM_WEBSTORE; | 312 flags |= Extension::FROM_WEBSTORE; |
| 301 if (extension_prefs_->IsFromBookmark(info->extension_id)) | 313 if (extension_prefs_->IsFromBookmark(info->extension_id)) |
| 302 flags |= Extension::FROM_BOOKMARK; | 314 flags |= Extension::FROM_BOOKMARK; |
| 303 return flags; | 315 return flags; |
| 304 } | 316 } |
| 305 | 317 |
| 306 } // namespace extensions | 318 } // namespace extensions |
| OLD | NEW |