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) { ...@@ -1051,6 +1051,36 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) {
ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 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 // Fails on Win7. http://crbug.com/171450
#if defined(OS_WIN) #if defined(OS_WIN)
#define MAYBE_Messaging DISABLED_Messaging #define MAYBE_Messaging DISABLED_Messaging
......
...@@ -1461,7 +1461,7 @@ void ExtensionService::AddComponentExtension(const Extension* extension) { ...@@ -1461,7 +1461,7 @@ void ExtensionService::AddComponentExtension(const Extension* extension) {
<< old_version_string << "' to " << extension->version()->GetString(); << old_version_string << "' to " << extension->version()->GetString();
AddNewOrUpdatedExtension(extension, AddNewOrUpdatedExtension(extension,
Extension::ENABLED_COMPONENT, Extension::ENABLED,
extensions::kInstallFlagNone, extensions::kInstallFlagNone,
syncer::StringOrdinal(), syncer::StringOrdinal(),
std::string()); std::string());
......
...@@ -300,9 +300,6 @@ class VoiceSearchDomHandler : public WebUIMessageHandler { ...@@ -300,9 +300,6 @@ class VoiceSearchDomHandler : public WebUIMessageHandler {
case extensions::Extension::EXTERNAL_EXTENSION_UNINSTALLED: case extensions::Extension::EXTERNAL_EXTENSION_UNINSTALLED:
state = "EXTERNAL_EXTENSION_UNINSTALLED"; state = "EXTERNAL_EXTENSION_UNINSTALLED";
break; break;
case extensions::Extension::ENABLED_COMPONENT:
state = "ENABLED_COMPONENT";
break;
default: default:
state = "undefined"; state = "undefined";
} }
......
...@@ -1337,23 +1337,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper( ...@@ -1337,23 +1337,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper(
if (!extension->GetInteger(kPrefLocation, &location_value)) if (!extension->GetInteger(kPrefLocation, &location_value))
return scoped_ptr<ExtensionInfo>(); 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); Manifest::Location location = static_cast<Manifest::Location>(location_value);
#if !defined(OS_CHROMEOS) if (location == Manifest::COMPONENT) {
if (!Manifest::IsUnpackedLocation(location)) { // Component extensions are ignored. Component extensions may have data
DCHECK(location == Manifest::COMPONENT || // saved in preferences, but they are already loaded at this point (by
!base::FilePath(path).IsAbsolute()); // ComponentLoader) and shouldn't be populated into the result of
#else // GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to
// On Chrome OS some extensions can be installed to shared location and // load them.
// thus use absolute paths in prefs. return scoped_ptr<ExtensionInfo>();
if (!base::FilePath(path).IsAbsolute()) {
#endif // !defined(OS_CHROMEOS)
path = install_directory_.Append(path).value();
} }
// Only the following extension types have data saved in the preferences. // Only the following extension types have data saved in the preferences.
...@@ -1371,6 +1362,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper( ...@@ -1371,6 +1362,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper(
// Just a warning for now. // 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( return scoped_ptr<ExtensionInfo>(new ExtensionInfo(
manifest, extension_id, base::FilePath(path), location)); manifest, extension_id, base::FilePath(path), location));
} }
...@@ -1384,13 +1383,8 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( ...@@ -1384,13 +1383,8 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
!extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
return scoped_ptr<ExtensionInfo>(); return scoped_ptr<ExtensionInfo>();
int state_value; int state_value;
if (!ext->GetInteger(kPrefState, &state_value) || if (ext->GetInteger(kPrefState, &state_value) &&
state_value == Extension::ENABLED_COMPONENT) { state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
// Old preferences files may not have kPrefState for component extensions.
return scoped_ptr<ExtensionInfo>();
}
if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
LOG(WARNING) << "External extension with id " << extension_id LOG(WARNING) << "External extension with id " << extension_id
<< " has been uninstalled by the user"; << " has been uninstalled by the user";
return scoped_ptr<ExtensionInfo>(); return scoped_ptr<ExtensionInfo>();
...@@ -2047,12 +2041,7 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs( ...@@ -2047,12 +2041,7 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs(
int install_flags, int install_flags,
const std::string& install_parameter, const std::string& install_parameter,
base::DictionaryValue* extension_dict) { base::DictionaryValue* extension_dict) {
// Leave the state blank for component extensions so that old chrome versions extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
// 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(kPrefLocation, extension_dict->Set(kPrefLocation,
new base::FundamentalValue(extension->location())); new base::FundamentalValue(extension->location()));
extension_dict->Set(kPrefCreationFlags, extension_dict->Set(kPrefCreationFlags,
......
...@@ -62,9 +62,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> { ...@@ -62,9 +62,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// An external extension that the user uninstalled. We should not reinstall // An external extension that the user uninstalled. We should not reinstall
// such extensions on startup. // such extensions on startup.
EXTERNAL_EXTENSION_UNINSTALLED, EXTERNAL_EXTENSION_UNINSTALLED,
// Special state for component extensions, since they are always loaded by // DEPRECATED: Special state for component extensions.
// the component loader, and should never be auto-installed on startup. // Maintained as a placeholder since states may be stored to disk.
ENABLED_COMPONENT, ENABLED_COMPONENT_DEPRECATED,
NUM_STATES 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