Commit 9ae7396d authored by amistry@chromium.org's avatar amistry@chromium.org

Make runtime.reload() work with component extensions.

This eliminates the ENABLED_COMPONENT state, and fixes the path CHECK failure.

BUG=402377

Review URL: https://codereview.chromium.org/462533002

Cr-Commit-Position: refs/heads/master@{#289616}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289616 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d35ccf9
......@@ -1051,6 +1051,36 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) {
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
ComponentExtensionRuntimeReload) {
// Ensure that we wait until the background page is run (to register the
// OnLaunched listener) before trying to open the application. This is similar
// to LoadAndLaunchPlatformApp, but we want to load as a component extension.
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
const Extension* extension = LoadExtensionAsComponent(
test_data_dir_.AppendASCII("platform_apps").AppendASCII("component"));
ASSERT_TRUE(extension);
app_loaded_observer.Wait();
{
ExtensionTestMessageListener launched_listener("Launched", false);
OpenApplication(AppLaunchParams(
browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW));
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
}
{
ASSERT_TRUE(ExecuteScriptInBackgroundPageNoWait(
extension->id(), "chrome.runtime.reload();"));
ExtensionTestMessageListener launched_listener("Launched", false);
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
}
}
// Fails on Win7. http://crbug.com/171450
#if defined(OS_WIN)
#define MAYBE_Messaging DISABLED_Messaging
......
......@@ -1461,7 +1461,7 @@ void ExtensionService::AddComponentExtension(const Extension* extension) {
<< old_version_string << "' to " << extension->version()->GetString();
AddNewOrUpdatedExtension(extension,
Extension::ENABLED_COMPONENT,
Extension::ENABLED,
extensions::kInstallFlagNone,
syncer::StringOrdinal(),
std::string());
......
......@@ -300,9 +300,6 @@ class VoiceSearchDomHandler : public WebUIMessageHandler {
case extensions::Extension::EXTERNAL_EXTENSION_UNINSTALLED:
state = "EXTERNAL_EXTENSION_UNINSTALLED";
break;
case extensions::Extension::ENABLED_COMPONENT:
state = "ENABLED_COMPONENT";
break;
default:
state = "undefined";
}
......
......@@ -1337,23 +1337,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper(
if (!extension->GetInteger(kPrefLocation, &location_value))
return scoped_ptr<ExtensionInfo>();
base::FilePath::StringType path;
if (!extension->GetString(kPrefPath, &path))
return scoped_ptr<ExtensionInfo>();
// Make path absolute. Unpacked extensions will already have absolute paths,
// otherwise make it so.
Manifest::Location location = static_cast<Manifest::Location>(location_value);
#if !defined(OS_CHROMEOS)
if (!Manifest::IsUnpackedLocation(location)) {
DCHECK(location == Manifest::COMPONENT ||
!base::FilePath(path).IsAbsolute());
#else
// On Chrome OS some extensions can be installed to shared location and
// thus use absolute paths in prefs.
if (!base::FilePath(path).IsAbsolute()) {
#endif // !defined(OS_CHROMEOS)
path = install_directory_.Append(path).value();
if (location == Manifest::COMPONENT) {
// Component extensions are ignored. Component extensions may have data
// saved in preferences, but they are already loaded at this point (by
// ComponentLoader) and shouldn't be populated into the result of
// GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to
// load them.
return scoped_ptr<ExtensionInfo>();
}
// Only the following extension types have data saved in the preferences.
......@@ -1371,6 +1362,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper(
// Just a warning for now.
}
base::FilePath::StringType path;
if (!extension->GetString(kPrefPath, &path))
return scoped_ptr<ExtensionInfo>();
// Make path absolute. Most (but not all) extension types have relative paths.
if (!base::FilePath(path).IsAbsolute())
path = install_directory_.Append(path).value();
return scoped_ptr<ExtensionInfo>(new ExtensionInfo(
manifest, extension_id, base::FilePath(path), location));
}
......@@ -1384,13 +1383,8 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
!extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
return scoped_ptr<ExtensionInfo>();
int state_value;
if (!ext->GetInteger(kPrefState, &state_value) ||
state_value == Extension::ENABLED_COMPONENT) {
// Old preferences files may not have kPrefState for component extensions.
return scoped_ptr<ExtensionInfo>();
}
if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
if (ext->GetInteger(kPrefState, &state_value) &&
state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
LOG(WARNING) << "External extension with id " << extension_id
<< " has been uninstalled by the user";
return scoped_ptr<ExtensionInfo>();
......@@ -2047,12 +2041,7 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs(
int install_flags,
const std::string& install_parameter,
base::DictionaryValue* extension_dict) {
// Leave the state blank for component extensions so that old chrome versions
// loading new profiles do not fail in GetInstalledExtensionInfo. Older
// Chrome versions would only check for an omitted state.
if (initial_state != Extension::ENABLED_COMPONENT)
extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
extension_dict->Set(kPrefLocation,
new base::FundamentalValue(extension->location()));
extension_dict->Set(kPrefCreationFlags,
......
......@@ -62,9 +62,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// An external extension that the user uninstalled. We should not reinstall
// such extensions on startup.
EXTERNAL_EXTENSION_UNINSTALLED,
// Special state for component extensions, since they are always loaded by
// the component loader, and should never be auto-installed on startup.
ENABLED_COMPONENT,
// DEPRECATED: Special state for component extensions.
// Maintained as a placeholder since states may be stored to disk.
ENABLED_COMPONENT_DEPRECATED,
NUM_STATES
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment