Change --load-extension flag so the extensions don't persist across restart.
I made --load-extension use a different Location type than other unpacked
extensions, but they are still treated the same in most cases.
BUG=73330
[email protected]
Review URL: https://chromiumcodereview.appspot.com/12345002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184887 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/api/alarms/alarms_api.cc b/chrome/browser/extensions/api/alarms/alarms_api.cc
index 351d1a1e..343175d8 100644
--- a/chrome/browser/extensions/api/alarms/alarms_api.cc
+++ b/chrome/browser/extensions/api/alarms/alarms_api.cc
@@ -54,7 +54,7 @@
if (create_info.delay_in_minutes.get()) {
if (*create_info.delay_in_minutes < kReleaseDelayMinimum) {
COMPILE_ASSERT(kReleaseDelayMinimum == 1, update_warning_message_below);
- if (extension->location() == Manifest::LOAD)
+ if (Manifest::IsUnpackedLocation(extension->location()))
warnings->push_back(ErrorUtils::FormatErrorMessage(
"Alarm delay is less than minimum of 1 minutes."
" In released .crx, alarm \"*\" will fire in approximately"
@@ -70,7 +70,7 @@
if (create_info.period_in_minutes.get()) {
if (*create_info.period_in_minutes < kReleaseDelayMinimum) {
COMPILE_ASSERT(kReleaseDelayMinimum == 1, update_warning_message_below);
- if (extension->location() == Manifest::LOAD)
+ if (Manifest::IsUnpackedLocation(extension->location()))
warnings->push_back(ErrorUtils::FormatErrorMessage(
"Alarm period is less than minimum of 1 minutes."
" In released .crx, alarm \"*\" will fire approximately"
@@ -117,7 +117,7 @@
Alarm alarm(alarm_name,
params->alarm_info,
base::TimeDelta::FromMinutes(
- GetExtension()->location() == Manifest::LOAD ?
+ Manifest::IsUnpackedLocation(GetExtension()->location()) ?
kDevDelayMinimum : kReleaseDelayMinimum),
clock_->Now());
ExtensionSystem::Get(profile())->alarm_manager()->AddAlarm(
diff --git a/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc b/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
index fdb9ffa..fb3d8ed 100644
--- a/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
+++ b/chrome/browser/extensions/api/alarms/alarms_api_unittest.cc
@@ -58,7 +58,7 @@
alarm_manager_->set_delegate(alarm_delegate_);
extension_ = utils::CreateEmptyExtensionWithLocation(
- extensions::Manifest::LOAD);
+ extensions::Manifest::UNPACKED);
// Make sure there's a RenderViewHost for alarms to warn into.
AddTab(browser(), extension_->GetBackgroundURL());
diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
index 48848450..bca5d32 100644
--- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
@@ -157,7 +157,7 @@
NOTREACHED();
}
- if (item.location() == Manifest::LOAD) {
+ if (extensions::Manifest::IsUnpackedLocation(item.location())) {
info->path.reset(
new std::string(UTF16ToUTF8(item.path().LossyDisplayName())));
}
@@ -165,8 +165,9 @@
info->incognito_enabled = service->IsIncognitoEnabled(item.id());
info->wants_file_access = item.wants_file_access();
info->allow_file_access = service->AllowFileAccess(&item);
- info->allow_reload = (item.location() == Manifest::LOAD);
- info->is_unpacked = (item.location() == Manifest::LOAD);
+ info->allow_reload =
+ extensions::Manifest::IsUnpackedLocation(item.location());
+ info->is_unpacked = extensions::Manifest::IsUnpackedLocation(item.location());
info->terminated = service->terminated_extensions()->Contains(item.id());
info->allow_incognito = item.can_be_incognito_enabled();
diff --git a/chrome/browser/extensions/api/discovery/discovery_api_unittest.cc b/chrome/browser/extensions/api/discovery/discovery_api_unittest.cc
index 5550383..223bc16 100644
--- a/chrome/browser/extensions/api/discovery/discovery_api_unittest.cc
+++ b/chrome/browser/extensions/api/discovery/discovery_api_unittest.cc
@@ -71,7 +71,7 @@
public:
virtual void SetUp() {
BrowserWithTestWindowTest::SetUp();
- extension_ = utils::CreateEmptyExtensionWithLocation(Manifest::LOAD);
+ extension_ = utils::CreateEmptyExtensionWithLocation(Manifest::UNPACKED);
}
// Runs a function and returns a pointer to a value, transferring ownership.
diff --git a/chrome/browser/extensions/api/idle/idle_api_unittest.cc b/chrome/browser/extensions/api/idle/idle_api_unittest.cc
index fec96da..a7f2db5 100644
--- a/chrome/browser/extensions/api/idle/idle_api_unittest.cc
+++ b/chrome/browser/extensions/api/idle/idle_api_unittest.cc
@@ -144,7 +144,7 @@
idle_manager_ = IdleManagerFactory::GetForProfile(browser()->profile());
extension_ = utils::CreateEmptyExtensionWithLocation(
- extensions::Manifest::LOAD);
+ extensions::Manifest::UNPACKED);
idle_provider_ = new TestIdleProvider();
idle_manager_->SetIdleTimeProviderForTest(
diff --git a/chrome/browser/extensions/api/management/management_api.cc b/chrome/browser/extensions/api/management/management_api.cc
index 18aa8cd..45ab1cd 100644
--- a/chrome/browser/extensions/api/management/management_api.cc
+++ b/chrome/browser/extensions/api/management/management_api.cc
@@ -177,7 +177,8 @@
case Manifest::INTERNAL:
info->install_type = management::ExtensionInfo::INSTALL_TYPE_NORMAL;
break;
- case Manifest::LOAD:
+ case Manifest::UNPACKED:
+ case Manifest::COMMAND_LINE:
info->install_type = management::ExtensionInfo::INSTALL_TYPE_DEVELOPMENT;
break;
case Manifest::EXTERNAL_PREF:
diff --git a/chrome/browser/extensions/api/socket/socket_api_unittest.cc b/chrome/browser/extensions/api/socket/socket_api_unittest.cc
index d3c7eab8e..9f27f33 100644
--- a/chrome/browser/extensions/api/socket/socket_api_unittest.cc
+++ b/chrome/browser/extensions/api/socket/socket_api_unittest.cc
@@ -27,7 +27,7 @@
system->CreateSocketManager();
extension_ = utils::CreateEmptyExtensionWithLocation(
- extensions::Manifest::LOAD);
+ extensions::Manifest::UNPACKED);
}
base::Value* RunFunctionWithExtension(
diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc
index 61dbfb9..ceb75f6f 100644
--- a/chrome/browser/extensions/app_process_apitest.cc
+++ b/chrome/browser/extensions/app_process_apitest.cc
@@ -287,7 +287,7 @@
std::string error;
scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
test_data_dir_.AppendASCII("app_process"),
- extensions::Manifest::LOAD,
+ extensions::Manifest::UNPACKED,
Extension::FROM_BOOKMARK,
&error));
service->OnExtensionInstalled(extension,
diff --git a/chrome/browser/extensions/extension_nacl_browsertest.cc b/chrome/browser/extensions/extension_nacl_browsertest.cc
index ce134016..03f69305 100644
--- a/chrome/browser/extensions/extension_nacl_browsertest.cc
+++ b/chrome/browser/extensions/extension_nacl_browsertest.cc
@@ -152,7 +152,7 @@
const Extension* extension = InstallExtension(INSTALL_TYPE_UNPACKED);
ASSERT_TRUE(extension);
- ASSERT_EQ(extension->location(), Manifest::LOAD);
+ ASSERT_EQ(extension->location(), Manifest::UNPACKED);
CheckPluginsCreated(extension, true);
}
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 55d9fea..df2d71e 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -441,7 +441,8 @@
continue;
int location_value;
if (extension_dict->GetInteger(kPrefLocation, &location_value) &&
- location_value == Manifest::LOAD) {
+ Manifest::IsUnpackedLocation(
+ static_cast<Manifest::Location>(location_value))) {
// Unpacked extensions can have absolute paths.
continue;
}
@@ -1590,7 +1591,7 @@
}
void ExtensionPrefs::UpdateManifest(const Extension* extension) {
- if (extension->location() != Manifest::LOAD) {
+ if (!Manifest::IsUnpackedLocation(extension->location())) {
const DictionaryValue* extension_dict = GetExtensionPref(extension->id());
if (!extension_dict)
return;
@@ -1680,25 +1681,24 @@
// Make path absolute. Unpacked extensions will already have absolute paths,
// otherwise make it so.
- if (location_value != Manifest::LOAD) {
- DCHECK(location_value == Manifest::COMPONENT ||
+ Manifest::Location location =
+ static_cast<Manifest::Location>(location_value);
+ if (!Manifest::IsUnpackedLocation(location)) {
+ DCHECK(location == Manifest::COMPONENT ||
!base::FilePath(path).IsAbsolute());
path = install_directory_.Append(path).value();
}
- // Only the following extension types can be installed permanently in the
- // preferences.
- Manifest::Location location =
- static_cast<Manifest::Location>(location_value);
+ // Only the following extension types have data saved in the preferences.
if (location != Manifest::INTERNAL &&
- location != Manifest::LOAD &&
+ !Manifest::IsUnpackedLocation(location) &&
!Manifest::IsExternalLocation(location)) {
NOTREACHED();
return scoped_ptr<ExtensionInfo>();
}
const DictionaryValue* manifest = NULL;
- if (location != Manifest::LOAD &&
+ if (!Manifest::IsUnpackedLocation(location) &&
!ext->GetDictionary(kPrefManifest, &manifest)) {
LOG(WARNING) << "Missing manifest for extension " << extension_id;
// Just a warning for now.
@@ -1813,25 +1813,24 @@
// Make path absolute. Unpacked extensions will already have absolute paths,
// otherwise make it so.
- if (location_value != Manifest::LOAD) {
- DCHECK(location_value == Manifest::COMPONENT ||
+ Manifest::Location location =
+ static_cast<Manifest::Location>(location_value);
+ if (!Manifest::IsUnpackedLocation(location)) {
+ DCHECK(location == Manifest::COMPONENT ||
!base::FilePath(path).IsAbsolute());
path = install_directory_.Append(path).value();
}
- // Only the following extension types can be installed permanently in the
- // preferences.
- Manifest::Location location =
- static_cast<Manifest::Location>(location_value);
+ // Only the following extension types have data saved in the preferences.
if (location != Manifest::INTERNAL &&
- location != Manifest::LOAD &&
+ !Manifest::IsUnpackedLocation(location) &&
!Manifest::IsExternalLocation(location)) {
NOTREACHED();
return scoped_ptr<ExtensionInfo>();
}
const DictionaryValue* manifest = NULL;
- if (location != Manifest::LOAD &&
+ if (!Manifest::IsUnpackedLocation(location) &&
!ext->GetDictionary(kPrefManifest, &manifest)) {
LOG(WARNING) << "Missing manifest for extension " << extension_id;
// Just a warning for now.
@@ -2393,7 +2392,7 @@
extension_dict->Set(kPrefPath, Value::CreateStringValue(path));
// We store prefs about LOAD extensions, but don't cache their manifest
// since it may change on disk.
- if (extension->location() != Manifest::LOAD) {
+ if (!Manifest::IsUnpackedLocation(extension->location())) {
extension_dict->Set(kPrefManifest,
extension->manifest()->value()->DeepCopy());
}
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 91d901b..a64dfab4 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -822,7 +822,7 @@
external_uninstall);
// Tell the backend to start deleting installed extensions on the file thread.
- if (Manifest::LOAD != extension->location()) {
+ if (!Manifest::IsUnpackedLocation(extension->location())) {
if (!GetFileTaskRunner()->PostTask(
FROM_HERE,
base::Bind(
@@ -2224,7 +2224,7 @@
if (is_extension_upgrade) {
// Other than for unpacked extensions, CrxInstaller should have guaranteed
// that we aren't downgrading.
- if (extension->location() != Manifest::LOAD)
+ if (!Manifest::IsUnpackedLocation(extension->location()))
CHECK_GE(extension->version()->CompareTo(*(old->version())), 0);
// Extensions get upgraded if the privileges are allowed to increase or
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index f096ffe..fe89f3f 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -2656,7 +2656,7 @@
EXPECT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size());
- EXPECT_EQ(Manifest::LOAD, loaded_[0]->location());
+ EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ("2.0", loaded_[0]->VersionString());
@@ -2670,7 +2670,7 @@
EXPECT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size());
- EXPECT_EQ(Manifest::LOAD, loaded_[0]->location());
+ EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ("1.0", loaded_[0]->VersionString());
}
@@ -3304,11 +3304,11 @@
DictionaryValue manifest;
manifest.SetString(keys::kName, "simple_extension");
manifest.SetString(keys::kVersion, "1");
- // LOAD is for extensions loaded from the command line. We use it here, even
+ // UNPACKED is for extensions loaded from a directory. We use it here, even
// though we're testing loading from prefs, so that we don't need to provide
// an extension key.
extensions::ExtensionInfo extension_info(&manifest, "", path,
- Manifest::LOAD);
+ Manifest::UNPACKED);
// Ensure we can load it with no management policy in place.
management_policy_->UnregisterAllProviders();
@@ -3995,7 +3995,7 @@
loop_.RunUntilIdle();
EXPECT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size());
- EXPECT_EQ(Manifest::LOAD, loaded_[0]->location());
+ EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
EXPECT_EQ(1u, service_->extensions()->size());
ValidatePrefKeyCount(1);
@@ -4032,7 +4032,7 @@
EXPECT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size());
ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
- EXPECT_EQ(loaded_[0]->location(), Manifest::LOAD);
+ EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
ValidatePrefKeyCount(1);
diff --git a/chrome/browser/extensions/extension_ui_unittest.cc b/chrome/browser/extensions/extension_ui_unittest.cc
index 60e7eaa..9571536 100644
--- a/chrome/browser/extensions/extension_ui_unittest.cc
+++ b/chrome/browser/extensions/extension_ui_unittest.cc
@@ -189,7 +189,7 @@
CompareExpectedAndActualOutput(extension_path, pages, expected_output_path);
}
-// Test that using Manifest::LOAD for the extension location triggers the
+// Test that using Manifest::UNPACKED for the extension location triggers the
// correct values in the details, including location, order, and allow_reload.
TEST_F(ExtensionUITest, LocationLoadPropagation) {
base::FilePath data_test_dir_path, extension_path;
@@ -205,7 +205,7 @@
scoped_ptr<DictionaryValue> extension_details(
CreateExtensionDetailViewFromPath(
- extension_path, pages, Manifest::LOAD));
+ extension_path, pages, Manifest::UNPACKED));
bool ui_allow_reload = false;
bool ui_is_unpacked = false;
@@ -221,7 +221,7 @@
// Test that using Manifest::EXTERNAL_PREF for the extension location triggers
// the correct values in the details, including location, order, and
-// allow_reload. Contrast to Manifest::LOAD, which has somewhat different
+// allow_reload. Contrast to Manifest::UNPACKED, which has somewhat different
// values.
TEST_F(ExtensionUITest, LocationExternalPrefPropagation) {
base::FilePath data_test_dir_path, extension_path;
@@ -266,7 +266,7 @@
scoped_ptr<DictionaryValue> extension_details(
CreateExtensionDetailViewFromPath(
- extension_path, pages, Manifest::LOAD));
+ extension_path, pages, Manifest::UNPACKED));
base::FilePath::StringType ui_path;
diff --git a/chrome/browser/extensions/installed_loader.cc b/chrome/browser/extensions/installed_loader.cc
index deb0f857..a12a5477 100644
--- a/chrome/browser/extensions/installed_loader.cc
+++ b/chrome/browser/extensions/installed_loader.cc
@@ -51,7 +51,7 @@
ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) {
// Always reload manifests of unpacked extensions, because they can change
// on disk independent of the manifest in our prefs.
- if (info.extension_location == Manifest::LOAD)
+ if (Manifest::IsUnpackedLocation(info.extension_location))
return UNPACKED_DIR;
// Reload the manifest if it needs to be relocalized.
@@ -106,7 +106,7 @@
// updating the 'key' field in their manifest).
// TODO(jstritar): migrate preferences when unpacked extensions change IDs.
if (extension &&
- extension->location() != Manifest::LOAD &&
+ !Manifest::IsUnpackedLocation(extension->location()) &&
info.extension_id != extension->id()) {
error = errors::kCannotChangeExtensionID;
extension = NULL;
@@ -152,6 +152,11 @@
for (size_t i = 0; i < extensions_info->size(); ++i) {
ExtensionInfo* info = extensions_info->at(i).get();
+ // Skip extensions that were loaded from the command-line because we don't
+ // want those to persist across browser restart.
+ if (info->extension_location == Manifest::COMMAND_LINE)
+ continue;
+
scoped_ptr<ExtensionInfo> pending_update(
extension_prefs_->GetDelayedInstallInfo(info->extension_id));
if (pending_update) {
@@ -271,7 +276,7 @@
// Don't count unpacked extensions, since they're a developer-specific
// feature.
- if (location == Manifest::LOAD)
+ if (Manifest::IsUnpackedLocation(location))
continue;
// Using an enumeration shows us the total installed ratio across all users.
@@ -370,7 +375,7 @@
int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
int flags = extension_prefs_->GetCreationFlags(info->extension_id);
- if (info->extension_location != Manifest::LOAD)
+ if (!Manifest::IsUnpackedLocation(info->extension_location))
flags |= Extension::REQUIRE_KEY;
if (extension_prefs_->AllowFileAccess(info->extension_id))
flags |= Extension::ALLOW_FILE_ACCESS;
diff --git a/chrome/browser/extensions/permissions_updater.cc b/chrome/browser/extensions/permissions_updater.cc
index 8c0e8be..10623ee 100644
--- a/chrome/browser/extensions/permissions_updater.cc
+++ b/chrome/browser/extensions/permissions_updater.cc
@@ -136,7 +136,7 @@
// We only maintain the granted permissions prefs for INTERNAL and LOAD
// extensions.
- if (extension->location() != Manifest::LOAD &&
+ if (!Manifest::IsUnpackedLocation(extension->location()) &&
extension->location() != Manifest::INTERNAL)
return;
diff --git a/chrome/browser/extensions/requirements_checker_browsertest.cc b/chrome/browser/extensions/requirements_checker_browsertest.cc
index 192239d..e7c8e9d9 100644
--- a/chrome/browser/extensions/requirements_checker_browsertest.cc
+++ b/chrome/browser/extensions/requirements_checker_browsertest.cc
@@ -47,7 +47,7 @@
extension_path = extension_path.AppendASCII("requirements_checker")
.AppendASCII(extension_dir_name);
scoped_refptr<const Extension> extension =
- extension_file_util::LoadExtension(extension_path, Manifest::LOAD,
+ extension_file_util::LoadExtension(extension_path, Manifest::UNPACKED,
0, &load_error);
CHECK(load_error.length() == 0u);
return extension;
diff --git a/chrome/browser/extensions/unpacked_installer.cc b/chrome/browser/extensions/unpacked_installer.cc
index ec6739c..c99a5b0e3 100644
--- a/chrome/browser/extensions/unpacked_installer.cc
+++ b/chrome/browser/extensions/unpacked_installer.cc
@@ -138,7 +138,7 @@
std::string error;
extension_ = extension_file_util::LoadExtension(
extension_path_,
- Manifest::LOAD,
+ Manifest::COMMAND_LINE,
GetFlags(),
&error);
@@ -174,7 +174,7 @@
int UnpackedInstaller::GetFlags() {
std::string id = Extension::GenerateIdForPath(extension_path_);
bool allow_file_access =
- Manifest::ShouldAlwaysAllowFileAccess(Manifest::LOAD);
+ Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED);
if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id))
allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id);
@@ -225,7 +225,7 @@
std::string error;
extension_ = extension_file_util::LoadExtension(
extension_path_,
- Manifest::LOAD,
+ Manifest::UNPACKED,
flags,
&error);
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index 8b14a603..0f0f159 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -95,7 +95,7 @@
scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error));
if (!value.get())
return NULL;
- return Extension::Create(path.DirName(), Manifest::LOAD, *value,
+ return Extension::Create(path.DirName(), Manifest::UNPACKED, *value,
Extension::NO_FLAGS, error);
}