Chromium Code Reviews| Index: chrome/browser/ui/webui/options/extension_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/extension_settings_handler.cc b/chrome/browser/ui/webui/options/extension_settings_handler.cc |
| index 6a088ea32617d4a3a8ecbb123993454355f7453b..27a64bcccdd3fffc88ac36e02419e4f758bffb43 100644 |
| --- a/chrome/browser/ui/webui/options/extension_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/options/extension_settings_handler.cc |
| @@ -109,6 +109,178 @@ void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { |
| PrefService::SYNCABLE_PREF); |
| } |
| +// Static |
| +DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| + ExtensionService* service, const Extension* extension, |
| + const std::vector<ExtensionPage>& pages, |
| + const ExtensionWarningSet* warnings_set, |
| + bool enabled, bool terminated) { |
| + DictionaryValue* extension_data = new DictionaryValue(); |
| + GURL icon = |
| + ExtensionIconSource::GetIconURL(extension, |
| + ExtensionIconSet::EXTENSION_ICON_MEDIUM, |
| + ExtensionIconSet::MATCH_BIGGER, |
| + !enabled, NULL); |
| + extension_data->SetString("id", extension->id()); |
| + extension_data->SetString("name", extension->name()); |
| + extension_data->SetString("description", extension->description()); |
| + if (extension->location() == Extension::LOAD) |
| + extension_data->SetString("path", extension->path().value()); |
| + extension_data->SetString("version", extension->version()->GetString()); |
| + extension_data->SetString("icon", icon.spec()); |
| + extension_data->SetBoolean("isUnpacked", |
| + extension->location() == Extension::LOAD); |
| + extension_data->SetBoolean("mayDisable", |
| + Extension::UserMayDisable(extension->location())); |
| + extension_data->SetBoolean("enabled", enabled); |
| + extension_data->SetBoolean("terminated", terminated); |
| + extension_data->SetBoolean("enabledIncognito", |
| + service ? service->IsIncognitoEnabled(extension->id()) : false); |
| + extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); |
| + extension_data->SetBoolean("allowFileAccess", |
| + service ? service->AllowFileAccess(extension) : false); |
| + extension_data->SetBoolean("allow_activity", |
| + enabled && CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableExtensionActivityUI)); |
| + extension_data->SetBoolean("allow_reload", |
| + extension->location() == Extension::LOAD); |
| + extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); |
| + |
| + // Determine the sort order: Extensions loaded through --load-extensions show |
| + // up at the top. Disabled extensions show up at the bottom. |
| + if (extension->location() == Extension::LOAD) |
| + extension_data->SetInteger("order", 1); |
| + else |
| + extension_data->SetInteger("order", 2); |
| + |
| + if (!extension->options_url().is_empty() && enabled) |
| + extension_data->SetString("options_url", extension->options_url().spec()); |
| + |
| + if (service && !service->GetBrowserActionVisibility(extension)) |
| + extension_data->SetBoolean("enable_show_button", true); |
| + |
| + // Add views |
| + ListValue* views = new ListValue; |
| + for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); |
| + iter != pages.end(); ++iter) { |
| + DictionaryValue* view_value = new DictionaryValue; |
| + if (iter->url.scheme() == chrome::kExtensionScheme) { |
| + // No leading slash. |
| + view_value->SetString("path", iter->url.path().substr(1)); |
| + } else { |
| + // For live pages, use the full URL. |
| + view_value->SetString("path", iter->url.spec()); |
| + } |
| + view_value->SetInteger("renderViewId", iter->render_view_id); |
| + view_value->SetInteger("renderProcessId", iter->render_process_id); |
| + view_value->SetBoolean("incognito", iter->incognito); |
| + views->Append(view_value); |
| + } |
| + extension_data->Set("views", views); |
| + extension_data->SetBoolean("hasPopupAction", |
| + extension->browser_action() || extension->page_action()); |
| + extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); |
| + |
| + // Add warnings. |
| + ListValue* warnings_list = new ListValue; |
| + if (warnings_set) { |
| + std::set<ExtensionWarningSet::WarningType> warnings; |
| + warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); |
| + |
| + for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = |
| + warnings.begin(); |
| + iter != warnings.end(); |
| + ++iter) { |
| + string16 warning_string(ExtensionWarningSet::GetLocalizedWarning(*iter)); |
| + warnings_list->Append(Value::CreateStringValue(warning_string)); |
| + } |
| + } |
| + extension_data->Set("warnings", warnings_list); |
| + |
| + return extension_data; |
| +} |
| + |
| +void ExtensionSettingsHandler::GetLocalizedValues( |
| + DictionaryValue* localized_strings) { |
| + RegisterTitle(localized_strings, "extensionSettings", |
| + IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
| + |
| + localized_strings->SetString("extensionSettingsVisitWebsite", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); |
| + |
| + localized_strings->SetString("extensionSettingsDeveloperMode", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); |
| + localized_strings->SetString("extensionSettingsNoExtensions", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); |
| + localized_strings->SetString("extensionSettingsSuggestGallery", |
| + l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, |
| + ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| + GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); |
| + localized_strings->SetString("extensionSettingsGetMoreExtensionsDeprecated", |
| + l10n_util::GetStringFUTF16(IDS_GET_MORE_EXTENSIONS_DEPRECATED, |
| + ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| + GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); |
| + localized_strings->SetString("extensionSettingsGetMoreExtensions", |
| + l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS)); |
| + localized_strings->SetString("extensionSettingsGetMoreExtensionsUrl", |
| + ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| + GURL(extension_urls::GetWebstoreLaunchURL())).spec())); |
| + localized_strings->SetString("extensionSettingsExtensionId", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); |
| + localized_strings->SetString("extensionSettingsExtensionPath", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH)); |
| + localized_strings->SetString("extensionSettingsInspectViews", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); |
| + localized_strings->SetString("viewIncognito", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); |
| + localized_strings->SetString("extensionSettingsEnable", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); |
| + localized_strings->SetString("extensionSettingsEnabled", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED)); |
| + localized_strings->SetString("extensionSettingsRemove", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE)); |
| + localized_strings->SetString("extensionSettingsEnableIncognito", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); |
| + localized_strings->SetString("extensionSettingsAllowFileAccess", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); |
| + localized_strings->SetString("extensionSettingsIncognitoWarning", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING)); |
| + localized_strings->SetString("extensionSettingsReload", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); |
| + localized_strings->SetString("extensionSettingsOptions", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); |
| + localized_strings->SetString("extensionSettingsActivity", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); |
| + localized_strings->SetString("extensionSettingsPolicyControlled", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); |
| + localized_strings->SetString("extensionSettingsShowButton", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); |
| + localized_strings->SetString("extensionSettingsLoadUnpackedButton", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); |
| + localized_strings->SetString("extensionSettingsPackButton", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); |
| + localized_strings->SetString("extensionSettingsUpdateButton", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); |
| + localized_strings->SetString("extensionSettingsCrashMessage", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); |
| + localized_strings->SetString("extensionSettingsInDevelopment", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); |
| + localized_strings->SetString("extensionSettingsWarningsTitle", |
| + l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE)); |
| + localized_strings->SetString("extensionSettingsShowDetails", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| + localized_strings->SetString("extensionSettingsHideDetails", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); |
| + |
| + // TODO(estade): comb through the above strings to find ones no longer used in |
| + // uber extensions. |
| + localized_strings->SetString("extensionUninstall", |
| + l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| +} |
| + |
| +void ExtensionSettingsHandler::Initialize() { |
| +} |
| + |
| void ExtensionSettingsHandler::RegisterMessages() { |
| extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()-> |
| GetExtensionService(); |
| @@ -143,17 +315,106 @@ void ExtensionSettingsHandler::RegisterMessages() { |
| web_ui()->RegisterMessageCallback("extensionSettingsShowButton", |
| base::Bind(&ExtensionSettingsHandler::HandleShowButtonMessage, |
| base::Unretained(this))); |
| - web_ui()->RegisterMessageCallback("extensionSettingsLoad", |
| - base::Bind(&ExtensionSettingsHandler::HandleLoadMessage, |
| - base::Unretained(this))); |
| web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", |
| base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, |
| base::Unretained(this))); |
| - web_ui()->RegisterMessageCallback("extensionSettingsSelectFilePath", |
|
Evan Stade
2012/03/14 23:13:45
this is still used in the pack extension overlay
James Hawkins
2012/03/15 00:24:13
Done.
|
| - base::Bind(&ExtensionSettingsHandler::HandleSelectFilePathMessage, |
| + web_ui()->RegisterMessageCallback("extensionSettingsLoadUnpackedExtension", |
| + base::Bind(&ExtensionSettingsHandler::HandleLoadUnpackedExtensionMessage, |
| base::Unretained(this))); |
| } |
| +void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, |
| + void* params) { |
| + extensions::UnpackedInstaller::Create(extension_service_)->Load(path); |
| +} |
| + |
| +void ExtensionSettingsHandler::MultiFilesSelected( |
| + const std::vector<FilePath>& files, void* params) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ExtensionSettingsHandler::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + Profile* source_profile = NULL; |
| + switch (type) { |
| + // We listen for notifications that will result in the page being |
| + // repopulated with data twice for the same event in certain cases. |
| + // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because |
| + // we don't know about the views for an extension at EXTENSION_LOADED, but |
| + // if we only listen to EXTENSION_HOST_CREATED, we'll miss extensions |
| + // that don't have a process at startup. |
| + // |
| + // Doing it this way gets everything but causes the page to be rendered |
| + // more than we need. It doesn't seem to result in any noticeable flicker. |
| + case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
| + deleting_rvh_ = content::Source<RenderViewHost>(source).ptr(); |
| + // Fall through. |
| + case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
| + source_profile = Profile::FromBrowserContext( |
| + content::Source<RenderViewHost>(source)->GetSiteInstance()-> |
| + GetBrowserContext()); |
| + if (!profile->IsSameProfile(source_profile)) |
| + return; |
| + MaybeUpdateAfterNotification(); |
| + break; |
| + case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| + deleting_rvh_ = content::Details<BackgroundContents>(details)-> |
| + web_contents()->GetRenderViewHost(); |
| + // Fall through. |
| + case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
| + case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: |
| + source_profile = content::Source<Profile>(source).ptr(); |
| + if (!profile->IsSameProfile(source_profile)) |
| + return; |
| + MaybeUpdateAfterNotification(); |
| + break; |
| + case chrome::NOTIFICATION_EXTENSION_LOADED: |
| + case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| + case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| + case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| + case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| + MaybeUpdateAfterNotification(); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| + DCHECK(!extension_id_prompting_.empty()); |
| + |
| + bool was_terminated = false; |
| + |
| + // The extension can be uninstalled in another window while the UI was |
| + // showing. Do nothing in that case. |
| + const Extension* extension = |
| + extension_service_->GetExtensionById(extension_id_prompting_, true); |
| + if (!extension) { |
| + extension = extension_service_->GetTerminatedExtension( |
| + extension_id_prompting_); |
| + was_terminated = true; |
| + } |
| + if (!extension) |
| + return; |
| + |
| + extension_service_->UninstallExtension(extension_id_prompting_, |
| + false, // External uninstall. |
| + NULL); // Error. |
| + extension_id_prompting_ = ""; |
| + |
| + // There will be no EXTENSION_UNLOADED notification for terminated |
| + // extensions as they were already unloaded. |
| + if (was_terminated) |
| + HandleRequestExtensionsData(NULL); |
| +} |
| + |
| +void ExtensionSettingsHandler::ExtensionUninstallCanceled() { |
| + extension_id_prompting_ = ""; |
| +} |
| + |
| void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| const ListValue* args) { |
| DictionaryValue results; |
| @@ -199,64 +460,18 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| warnings, |
| false, true)); // enabled, terminated |
| } |
| - } |
| - results.Set("extensions", extensions_list); |
| - |
| - Profile* profile = Profile::FromWebUI(web_ui()); |
| - bool developer_mode = |
| - profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| - results.SetBoolean("developerMode", developer_mode); |
| - |
| - web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
| - results); |
| - |
| - MaybeRegisterForNotifications(); |
| -} |
| - |
| -void ExtensionSettingsHandler::MaybeRegisterForNotifications() { |
| - if (registered_for_notifications_) |
| - return; |
| + } |
| + results.Set("extensions", extensions_list); |
| - registered_for_notifications_ = true; |
| Profile* profile = Profile::FromWebUI(web_ui()); |
| + bool developer_mode = |
| + profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| + results.SetBoolean("developerMode", developer_mode); |
| - // Register for notifications that we need to reload the page. |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| - content::Source<Profile>(profile)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| - content::Source<Profile>(profile)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| - content::Source<Profile>(profile)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, |
| - content::Source<Profile>(profile)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| - content::NotificationService::AllBrowserContextsAndSources()); |
| - registrar_.Add(this, |
| - content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| - content::NotificationService::AllBrowserContextsAndSources()); |
| - registrar_.Add(this, |
| - content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| - content::NotificationService::AllBrowserContextsAndSources()); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| - content::NotificationService::AllBrowserContextsAndSources()); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| - content::NotificationService::AllBrowserContextsAndSources()); |
| - registrar_.Add( |
| - this, |
| - chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| - content::Source<ExtensionPrefs>(profile->GetExtensionService()-> |
| - extension_prefs())); |
| -} |
| + web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
| + results); |
| -ExtensionUninstallDialog* |
| -ExtensionSettingsHandler::GetExtensionUninstallDialog() { |
| - if (!extension_uninstall_dialog_.get()) { |
| - extension_uninstall_dialog_.reset( |
| - ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); |
| - } |
| - return extension_uninstall_dialog_.get(); |
| + MaybeRegisterForNotifications(); |
| } |
| void ExtensionSettingsHandler::HandleToggleDeveloperMode( |
| @@ -342,306 +557,107 @@ void ExtensionSettingsHandler::HandleEnableIncognitoMessage( |
| // window, when toggling this, the browser action will flicker because it gets |
| // unloaded, then reloaded. It would be better to have a dedicated |
| // notification for this case. |
| - // |
| - // Bug: http://crbug.com/41384 |
| - AutoReset<bool> auto_reset_ignore_notifications(&ignore_notifications_, true); |
| - extension_service_->SetIsIncognitoEnabled(extension->id(), |
| - enable_str == "true"); |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleAllowFileAccessMessage( |
| - const ListValue* args) { |
| - CHECK_EQ(2U, args->GetSize()); |
| - std::string extension_id, allow_str; |
| - CHECK(args->GetString(0, &extension_id)); |
| - CHECK(args->GetString(1, &allow_str)); |
| - const Extension* extension = |
| - extension_service_->GetExtensionById(extension_id, true); |
| - DCHECK(extension); |
| - |
| - if (!Extension::UserMayDisable(extension->location())) { |
| - LOG(ERROR) << "Attempt to change allow file access of an extension that is " |
| - << "non-usermanagable was made. Extension id : " |
| - << extension->id(); |
| - return; |
| - } |
| - |
| - extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
| - std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| - CHECK(!extension_id.empty()); |
| - const Extension* extension = |
| - extension_service_->GetExtensionById(extension_id, true); |
| - if (!extension) |
| - extension = extension_service_->GetTerminatedExtension(extension_id); |
| - if (!extension) |
| - return; |
| - |
| - if (!Extension::UserMayDisable(extension->location())) { |
| - LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| - << "was made. Extension id : " << extension->id(); |
| - return; |
| - } |
| - |
| - if (!extension_id_prompting_.empty()) |
| - return; // Only one prompt at a time. |
| - |
| - extension_id_prompting_ = extension_id; |
| - |
| - GetExtensionUninstallDialog()->ConfirmUninstall(extension); |
| -} |
| - |
| -void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| - DCHECK(!extension_id_prompting_.empty()); |
| - |
| - bool was_terminated = false; |
| - |
| - // The extension can be uninstalled in another window while the UI was |
| - // showing. Do nothing in that case. |
| - const Extension* extension = |
| - extension_service_->GetExtensionById(extension_id_prompting_, true); |
| - if (!extension) { |
| - extension = extension_service_->GetTerminatedExtension( |
| - extension_id_prompting_); |
| - was_terminated = true; |
| - } |
| - if (!extension) |
| - return; |
| - |
| - extension_service_->UninstallExtension(extension_id_prompting_, |
| - false, // External uninstall. |
| - NULL); // Error. |
| - extension_id_prompting_ = ""; |
| - |
| - // There will be no EXTENSION_UNLOADED notification for terminated |
| - // extensions as they were already unloaded. |
| - if (was_terminated) |
| - HandleRequestExtensionsData(NULL); |
| -} |
| - |
| -void ExtensionSettingsHandler::ExtensionUninstallCanceled() { |
| - extension_id_prompting_ = ""; |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) { |
| - const Extension* extension = GetExtension(args); |
| - if (!extension || extension->options_url().is_empty()) |
| - return; |
| - Profile::FromWebUI(web_ui())->GetExtensionProcessManager()->OpenOptionsPage( |
| - extension, NULL); |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) { |
| - const Extension* extension = GetExtension(args); |
| - extension_service_->SetBrowserActionVisibility(extension, true); |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleLoadMessage(const ListValue* args) { |
| - FilePath::StringType string_path; |
| - CHECK_EQ(1U, args->GetSize()) << args->GetSize(); |
| - CHECK(args->GetString(0, &string_path)); |
| - extensions::UnpackedInstaller::Create(extension_service_)-> |
| - Load(FilePath(string_path)); |
| -} |
| - |
| -void ExtensionSettingsHandler::ShowAlert(const std::string& message) { |
| - ListValue arguments; |
| - arguments.Append(Value::CreateStringValue(message)); |
| - web_ui()->CallJavascriptFunction("alert", arguments); |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleAutoUpdateMessage(const ListValue* args) { |
| - ExtensionUpdater* updater = extension_service_->updater(); |
| - if (updater) |
| - updater->CheckNow(); |
| -} |
| - |
| -void ExtensionSettingsHandler::HandleSelectFilePathMessage( |
| - const ListValue* args) { |
| - std::string select_type; |
| - std::string operation; |
| - CHECK_EQ(2U, args->GetSize()); |
| - CHECK(args->GetString(0, &select_type)); |
| - CHECK(args->GetString(1, &operation)); |
| - |
| - SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; |
| - SelectFileDialog::FileTypeInfo info; |
| - int file_type_index = 0; |
| - if (select_type == "file") |
| - type = SelectFileDialog::SELECT_OPEN_FILE; |
| - |
| - string16 select_title; |
| - if (operation == "load") { |
| - select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
| - } else if (operation == "packRoot") { |
| - select_title = l10n_util::GetStringUTF16( |
| - IDS_EXTENSION_PACK_DIALOG_SELECT_ROOT); |
| - } else if (operation == "pem") { |
| - select_title = l10n_util::GetStringUTF16( |
| - IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); |
| - info.extensions.push_back(std::vector<FilePath::StringType>()); |
| - info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); |
| - info.extension_description_overrides.push_back( |
| - l10n_util::GetStringUTF16( |
| - IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); |
| - info.include_all_files = true; |
| - file_type_index = 1; |
| - } else { |
| - NOTREACHED(); |
| - return; |
| - } |
| - |
| - load_extension_dialog_ = SelectFileDialog::Create(this); |
| - load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, |
| - file_type_index, FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), |
| - web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| -} |
| - |
| - |
| -void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, |
| - void* params) { |
| - // Add the extensions to the results structure. |
| - ListValue results; |
| - results.Append(Value::CreateStringValue(path.value())); |
| - web_ui()->CallJavascriptFunction("window.handleFilePathSelected", results); |
| -} |
| - |
| -void ExtensionSettingsHandler::MultiFilesSelected( |
| - const std::vector<FilePath>& files, void* params) { |
| - NOTREACHED(); |
| -} |
| - |
| -void ExtensionSettingsHandler::GetLocalizedValues( |
| - DictionaryValue* localized_strings) { |
| - RegisterTitle(localized_strings, "extensionSettings", |
| - IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
| - |
| - localized_strings->SetString("extensionSettingsVisitWebsite", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); |
| - |
| - localized_strings->SetString("extensionSettingsDeveloperMode", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); |
| - localized_strings->SetString("extensionSettingsNoExtensions", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); |
| - localized_strings->SetString("extensionSettingsSuggestGallery", |
| - l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, |
| - ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| - GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); |
| - localized_strings->SetString("extensionSettingsGetMoreExtensionsDeprecated", |
| - l10n_util::GetStringFUTF16(IDS_GET_MORE_EXTENSIONS_DEPRECATED, |
| - ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| - GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); |
| - localized_strings->SetString("extensionSettingsGetMoreExtensions", |
| - l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS)); |
| - localized_strings->SetString("extensionSettingsGetMoreExtensionsUrl", |
| - ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| - GURL(extension_urls::GetWebstoreLaunchURL())).spec())); |
| - localized_strings->SetString("extensionSettingsExtensionId", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); |
| - localized_strings->SetString("extensionSettingsExtensionPath", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH)); |
| - localized_strings->SetString("extensionSettingsInspectViews", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); |
| - localized_strings->SetString("viewIncognito", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); |
| - localized_strings->SetString("extensionSettingsEnable", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); |
| - localized_strings->SetString("extensionSettingsEnabled", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED)); |
| - localized_strings->SetString("extensionSettingsRemove", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE)); |
| - localized_strings->SetString("extensionSettingsEnableIncognito", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); |
| - localized_strings->SetString("extensionSettingsAllowFileAccess", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); |
| - localized_strings->SetString("extensionSettingsIncognitoWarning", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING)); |
| - localized_strings->SetString("extensionSettingsReload", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); |
| - localized_strings->SetString("extensionSettingsOptions", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); |
| - localized_strings->SetString("extensionSettingsActivity", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); |
| - localized_strings->SetString("extensionSettingsPolicyControlled", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); |
| - localized_strings->SetString("extensionSettingsShowButton", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); |
| - localized_strings->SetString("extensionSettingsLoadUnpackedButton", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); |
| - localized_strings->SetString("extensionSettingsPackButton", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); |
| - localized_strings->SetString("extensionSettingsUpdateButton", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); |
| - localized_strings->SetString("extensionSettingsCrashMessage", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); |
| - localized_strings->SetString("extensionSettingsInDevelopment", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); |
| - localized_strings->SetString("extensionSettingsWarningsTitle", |
| - l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE)); |
| - localized_strings->SetString("extensionSettingsShowDetails", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| - localized_strings->SetString("extensionSettingsHideDetails", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); |
| - |
| - // TODO(estade): comb through the above strings to find ones no longer used in |
| - // uber extensions. |
| - localized_strings->SetString("extensionUninstall", |
| - l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| + // |
| + // Bug: http://crbug.com/41384 |
| + AutoReset<bool> auto_reset_ignore_notifications(&ignore_notifications_, true); |
| + extension_service_->SetIsIncognitoEnabled(extension->id(), |
| + enable_str == "true"); |
| } |
| -void ExtensionSettingsHandler::Initialize() { |
| +void ExtensionSettingsHandler::HandleAllowFileAccessMessage( |
| + const ListValue* args) { |
| + CHECK_EQ(2U, args->GetSize()); |
| + std::string extension_id, allow_str; |
| + CHECK(args->GetString(0, &extension_id)); |
| + CHECK(args->GetString(1, &allow_str)); |
| + const Extension* extension = |
| + extension_service_->GetExtensionById(extension_id, true); |
| + DCHECK(extension); |
| + |
| + if (!Extension::UserMayDisable(extension->location())) { |
| + LOG(ERROR) << "Attempt to change allow file access of an extension that is " |
| + << "non-usermanagable was made. Extension id : " |
| + << extension->id(); |
| + return; |
| + } |
| + |
| + extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
| } |
| -void ExtensionSettingsHandler::Observe( |
| - int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| - Profile* profile = Profile::FromWebUI(web_ui()); |
| - Profile* source_profile = NULL; |
| - switch (type) { |
| - // We listen for notifications that will result in the page being |
| - // repopulated with data twice for the same event in certain cases. |
| - // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because |
| - // we don't know about the views for an extension at EXTENSION_LOADED, but |
| - // if we only listen to EXTENSION_HOST_CREATED, we'll miss extensions |
| - // that don't have a process at startup. |
| - // |
| - // Doing it this way gets everything but causes the page to be rendered |
| - // more than we need. It doesn't seem to result in any noticeable flicker. |
| - case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
| - deleting_rvh_ = content::Source<RenderViewHost>(source).ptr(); |
| - // Fall through. |
| - case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
| - source_profile = Profile::FromBrowserContext( |
| - content::Source<RenderViewHost>(source)->GetSiteInstance()-> |
| - GetBrowserContext()); |
| - if (!profile->IsSameProfile(source_profile)) |
| - return; |
| - MaybeUpdateAfterNotification(); |
| - break; |
| - case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| - deleting_rvh_ = content::Details<BackgroundContents>(details)-> |
| - web_contents()->GetRenderViewHost(); |
| - // Fall through. |
| - case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
| - case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: |
| - source_profile = content::Source<Profile>(source).ptr(); |
| - if (!profile->IsSameProfile(source_profile)) |
| - return; |
| - MaybeUpdateAfterNotification(); |
| - break; |
| - case chrome::NOTIFICATION_EXTENSION_LOADED: |
| - case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| - case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| - case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| - case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| - MaybeUpdateAfterNotification(); |
| - break; |
| - default: |
| - NOTREACHED(); |
| +void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
| + std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| + CHECK(!extension_id.empty()); |
| + const Extension* extension = |
| + extension_service_->GetExtensionById(extension_id, true); |
| + if (!extension) |
| + extension = extension_service_->GetTerminatedExtension(extension_id); |
| + if (!extension) |
| + return; |
| + |
| + if (!Extension::UserMayDisable(extension->location())) { |
| + LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| + << "was made. Extension id : " << extension->id(); |
| + return; |
| } |
| + |
| + if (!extension_id_prompting_.empty()) |
| + return; // Only one prompt at a time. |
| + |
| + extension_id_prompting_ = extension_id; |
| + |
| + GetExtensionUninstallDialog()->ConfirmUninstall(extension); |
| +} |
| + |
| +void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) { |
| + const Extension* extension = GetExtension(args); |
| + if (!extension || extension->options_url().is_empty()) |
| + return; |
| + Profile::FromWebUI(web_ui())->GetExtensionProcessManager()->OpenOptionsPage( |
| + extension, NULL); |
| +} |
| + |
| +void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) { |
| + const Extension* extension = GetExtension(args); |
| + extension_service_->SetBrowserActionVisibility(extension, true); |
| +} |
| + |
| +void ExtensionSettingsHandler::HandleAutoUpdateMessage(const ListValue* args) { |
|
Evan Stade
2012/03/14 23:13:45
moving all this code around makes it difficult to
|
| + ExtensionUpdater* updater = extension_service_->updater(); |
| + if (updater) |
| + updater->CheckNow(); |
| +} |
| + |
| +void ExtensionSettingsHandler::HandleLoadUnpackedExtensionMessage( |
| + const ListValue* args) { |
| + DCHECK(args->empty()); |
| + |
| + SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; |
| + int file_type_index = 0; |
|
csilv
2012/03/14 23:20:19
You can remove file_type_index, it isn't being use
James Hawkins
2012/03/15 00:24:13
Done.
|
| + |
| + SelectFileDialog::FileTypeInfo info; |
| + info.extensions.push_back(std::vector<FilePath::StringType>()); |
| + info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); |
| + info.extension_description_overrides.push_back( |
| + l10n_util::GetStringUTF16( |
| + IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); |
| + info.include_all_files = true; |
| + file_type_index = 1; |
| + |
| + string16 select_title = |
| + l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); |
| + |
| + const int kFileTypeIndex = 1; // Index into |info.extensions|. |
| + load_extension_dialog_ = SelectFileDialog::Create(this); |
| + load_extension_dialog_->SelectFile( |
| + type, select_title, FilePath(), &info, kFileTypeIndex, |
| + FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), |
| + web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| +} |
| + |
| +void ExtensionSettingsHandler::ShowAlert(const std::string& message) { |
| + ListValue arguments; |
| + arguments.Append(Value::CreateStringValue(message)); |
| + web_ui()->CallJavascriptFunction("alert", arguments); |
| } |
| const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
| @@ -657,95 +673,41 @@ void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| deleting_rvh_ = NULL; |
| } |
| -// Static |
| -DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| - ExtensionService* service, const Extension* extension, |
| - const std::vector<ExtensionPage>& pages, |
| - const ExtensionWarningSet* warnings_set, |
| - bool enabled, bool terminated) { |
| - DictionaryValue* extension_data = new DictionaryValue(); |
| - GURL icon = |
| - ExtensionIconSource::GetIconURL(extension, |
| - ExtensionIconSet::EXTENSION_ICON_MEDIUM, |
| - ExtensionIconSet::MATCH_BIGGER, |
| - !enabled, NULL); |
| - extension_data->SetString("id", extension->id()); |
| - extension_data->SetString("name", extension->name()); |
| - extension_data->SetString("description", extension->description()); |
| - if (extension->location() == Extension::LOAD) |
| - extension_data->SetString("path", extension->path().value()); |
| - extension_data->SetString("version", extension->version()->GetString()); |
| - extension_data->SetString("icon", icon.spec()); |
| - extension_data->SetBoolean("isUnpacked", |
| - extension->location() == Extension::LOAD); |
| - extension_data->SetBoolean("mayDisable", |
| - Extension::UserMayDisable(extension->location())); |
| - extension_data->SetBoolean("enabled", enabled); |
| - extension_data->SetBoolean("terminated", terminated); |
| - extension_data->SetBoolean("enabledIncognito", |
| - service ? service->IsIncognitoEnabled(extension->id()) : false); |
| - extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); |
| - extension_data->SetBoolean("allowFileAccess", |
| - service ? service->AllowFileAccess(extension) : false); |
| - extension_data->SetBoolean("allow_activity", |
| - enabled && CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kEnableExtensionActivityUI)); |
| - extension_data->SetBoolean("allow_reload", |
| - extension->location() == Extension::LOAD); |
| - extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); |
| - |
| - // Determine the sort order: Extensions loaded through --load-extensions show |
| - // up at the top. Disabled extensions show up at the bottom. |
| - if (extension->location() == Extension::LOAD) |
| - extension_data->SetInteger("order", 1); |
| - else |
| - extension_data->SetInteger("order", 2); |
| - |
| - if (!extension->options_url().is_empty() && enabled) |
| - extension_data->SetString("options_url", extension->options_url().spec()); |
| - |
| - if (service && !service->GetBrowserActionVisibility(extension)) |
| - extension_data->SetBoolean("enable_show_button", true); |
| - |
| - // Add views |
| - ListValue* views = new ListValue; |
| - for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); |
| - iter != pages.end(); ++iter) { |
| - DictionaryValue* view_value = new DictionaryValue; |
| - if (iter->url.scheme() == chrome::kExtensionScheme) { |
| - // No leading slash. |
| - view_value->SetString("path", iter->url.path().substr(1)); |
| - } else { |
| - // For live pages, use the full URL. |
| - view_value->SetString("path", iter->url.spec()); |
| - } |
| - view_value->SetInteger("renderViewId", iter->render_view_id); |
| - view_value->SetInteger("renderProcessId", iter->render_process_id); |
| - view_value->SetBoolean("incognito", iter->incognito); |
| - views->Append(view_value); |
| - } |
| - extension_data->Set("views", views); |
| - extension_data->SetBoolean("hasPopupAction", |
| - extension->browser_action() || extension->page_action()); |
| - extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); |
| - |
| - // Add warnings. |
| - ListValue* warnings_list = new ListValue; |
| - if (warnings_set) { |
| - std::set<ExtensionWarningSet::WarningType> warnings; |
| - warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); |
| +void ExtensionSettingsHandler::MaybeRegisterForNotifications() { |
| + if (registered_for_notifications_) |
| + return; |
| - for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = |
| - warnings.begin(); |
| - iter != warnings.end(); |
| - ++iter) { |
| - string16 warning_string(ExtensionWarningSet::GetLocalizedWarning(*iter)); |
| - warnings_list->Append(Value::CreateStringValue(warning_string)); |
| - } |
| - } |
| - extension_data->Set("warnings", warnings_list); |
| + registered_for_notifications_ = true; |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| - return extension_data; |
| + // Register for notifications that we need to reload the page. |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| + content::Source<Profile>(profile)); |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| + content::Source<Profile>(profile)); |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| + content::Source<Profile>(profile)); |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, |
| + content::Source<Profile>(profile)); |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| + registrar_.Add(this, |
| + content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| + registrar_.Add(this, |
| + content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| + registrar_.Add( |
| + this, |
| + chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| + content::Source<ExtensionPrefs>(profile->GetExtensionService()-> |
| + extension_prefs())); |
| } |
| std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( |
| @@ -792,3 +754,12 @@ void ExtensionSettingsHandler::GetActivePagesForExtensionProcess( |
| process->GetBrowserContext()->IsOffTheRecord())); |
| } |
| } |
| + |
| +ExtensionUninstallDialog* |
| +ExtensionSettingsHandler::GetExtensionUninstallDialog() { |
| + if (!extension_uninstall_dialog_.get()) { |
| + extension_uninstall_dialog_.reset( |
| + ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); |
| + } |
| + return extension_uninstall_dialog_.get(); |
| +} |