diff options
author | reillyg <reillyg@chromium.org> | 2014-09-29 14:10:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-29 21:14:41 +0000 |
commit | c64d3dd16d71e8f18c05b7d48d74722c8c922dfc (patch) | |
tree | 30031a7ffe777c795129cc7ad85fba9fe4d53369 /chrome/browser/extensions | |
parent | 18a2ed23ddf0967ed4569d0eccd71ee2f0a56e91 (diff) | |
download | chromium_src-c64d3dd16d71e8f18c05b7d48d74722c8c922dfc.zip chromium_src-c64d3dd16d71e8f18c05b7d48d74722c8c922dfc.tar.gz chromium_src-c64d3dd16d71e8f18c05b7d48d74722c8c922dfc.tar.bz2 |
Update app info and install prompt UI to show retained devices.
This patch updates the app info dialog and the extensions install prompt
dialog user interfaces to show, for each extension, the devices that are
recorded in the SavedDevicesService. Along with retained files, access
to these devices can be revoked by clicking a button in these dialog
boxes. Devices not written to ExtensionPrefs (devices that are ephemeral
because the do not have a serial number) are not shown here. Permission
to access them is dropped when they are disconnected or Chrome exits.
BUG=346953
Review URL: https://codereview.chromium.org/580363002
Cr-Commit-Position: refs/heads/master@{#297262}
Diffstat (limited to 'chrome/browser/extensions')
3 files changed, 85 insertions, 13 deletions
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 e341787..ad94981 100644 --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc @@ -46,6 +46,7 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" +#include "extensions/browser/api/device_permissions_manager.h" #include "extensions/browser/app_window/app_window.h" #include "extensions/browser/app_window/app_window_registry.h" #include "extensions/browser/extension_error.h" @@ -758,7 +759,14 @@ bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { retained_file_paths.push_back(retained_file_entries[i].path); } } - prompt_->ReviewPermissions(this, extension, retained_file_paths); + std::vector<base::string16> retained_device_messages; + if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) { + retained_device_messages = + extensions::DevicePermissionsManager::Get(GetProfile()) + ->GetPermissionMessageStrings(extension_id_); + } + prompt_->ReviewPermissions( + this, extension, retained_file_paths, retained_device_messages); return true; } diff --git a/chrome/browser/extensions/extension_install_prompt.cc b/chrome/browser/extensions/extension_install_prompt.cc index 6edea03..b646252 100644 --- a/chrome/browser/extensions/extension_install_prompt.cc +++ b/chrome/browser/extensions/extension_install_prompt.cc @@ -101,7 +101,7 @@ static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, 0, // External installs use different strings for extensions/apps. - IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON, + 0, // Different strings depending on the files and devices retained. IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, IDS_EXTENSION_PROMPT_REPAIR_BUTTON, @@ -229,6 +229,7 @@ std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { ExtensionInstallPrompt::Prompt::Prompt(PromptType type) : type_(type), is_showing_details_for_retained_files_(false), + is_showing_details_for_retained_devices_(false), extension_(NULL), bundle_(NULL), average_rating_(0.0), @@ -272,6 +273,9 @@ void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( case RETAINED_FILES_DETAILS: is_showing_details_for_retained_files_ = is_showing_details; break; + case RETAINED_DEVICES_DETAILS: + is_showing_details_for_retained_devices_ = is_showing_details; + break; } } @@ -337,8 +341,7 @@ base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const { } int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { - if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && - ShouldDisplayRevokeFilesButton()) { + if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && ShouldDisplayRevokeButton()) { return kButtons[type_] | ui::DIALOG_BUTTON_OK; } @@ -351,12 +354,12 @@ bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { } bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { + if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) + return ShouldDisplayRevokeButton(); + if (kAcceptButtonIds[type_] == 0) return false; - if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) - return ShouldDisplayRevokeFilesButton(); - return true; } @@ -370,6 +373,18 @@ base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { else id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; return l10n_util::GetStringUTF16(id); + } else if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) { + int id = -1; + if (GetRetainedFileCount() && GetRetainedDeviceCount()) { + id = + IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_AND_DEVICES_BUTTON; + } else if (GetRetainedFileCount()) { + id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON; + } else { + DCHECK_LT(0U, GetRetainedDeviceCount()); + id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_DEVICES_BUTTON; + } + return l10n_util::GetStringUTF16(id); } if (ShouldShowExplanationText()) return experiment_->GetOkButtonText(); @@ -412,13 +427,31 @@ base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, }; - std::vector<int> message_ids; - for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { - message_ids.push_back(kRetainedFilesMessageIDs[i]); - } + std::vector<int> message_ids( + kRetainedFilesMessageIDs, + kRetainedFilesMessageIDs + arraysize(kRetainedFilesMessageIDs)); + return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); } +base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDevicesHeading() + const { + const int kRetainedDevicesMessageIDs[6] = { + IDS_EXTENSION_PROMPT_RETAINED_DEVICES_DEFAULT, + IDS_EXTENSION_PROMPT_RETAINED_DEVICE_SINGULAR, + IDS_EXTENSION_PROMPT_RETAINED_DEVICES_ZERO, + IDS_EXTENSION_PROMPT_RETAINED_DEVICES_TWO, + IDS_EXTENSION_PROMPT_RETAINED_DEVICES_FEW, + IDS_EXTENSION_PROMPT_RETAINED_DEVICES_MANY, + }; + std::vector<int> message_ids( + kRetainedDevicesMessageIDs, + kRetainedDevicesMessageIDs + arraysize(kRetainedDevicesMessageIDs)); + + return l10n_util::GetPluralStringFUTF16(message_ids, + GetRetainedDeviceCount()); +} + bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { return GetPermissionCount(ALL_PERMISSIONS) > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; @@ -530,6 +563,8 @@ bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( return withheld_prompt_permissions_.is_showing_details[index]; case RETAINED_FILES_DETAILS: return is_showing_details_for_retained_files_; + case RETAINED_DEVICES_DETAILS: + return is_showing_details_for_retained_devices_; } return false; } @@ -544,6 +579,20 @@ base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) return retained_files_[index].AsUTF16Unsafe(); } +size_t ExtensionInstallPrompt::Prompt::GetRetainedDeviceCount() const { + return retained_device_messages_.size(); +} + +base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDeviceMessageString( + size_t index) const { + CHECK_LT(index, retained_device_messages_.size()); + return retained_device_messages_[index]; +} + +bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeButton() const { + return !retained_files_.empty() || !retained_device_messages_.empty(); +} + ExtensionInstallPrompt::Prompt::InstallPromptPermissions& ExtensionInstallPrompt::Prompt::GetPermissionsForType( PermissionsType permissions_type) { @@ -753,11 +802,13 @@ void ExtensionInstallPrompt::ConfirmPermissions( void ExtensionInstallPrompt::ReviewPermissions( Delegate* delegate, const Extension* extension, - const std::vector<base::FilePath>& retained_file_paths) { + const std::vector<base::FilePath>& retained_file_paths, + const std::vector<base::string16>& retained_device_messages) { DCHECK(ui_loop_ == base::MessageLoop::current()); extension_ = extension; prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); prompt_->set_retained_files(retained_file_paths); + prompt_->set_retained_device_messages(retained_device_messages); delegate_ = delegate; LoadImageIfNeeded(); diff --git a/chrome/browser/extensions/extension_install_prompt.h b/chrome/browser/extensions/extension_install_prompt.h index 0ba6e44..bb85e49 100644 --- a/chrome/browser/extensions/extension_install_prompt.h +++ b/chrome/browser/extensions/extension_install_prompt.h @@ -84,6 +84,7 @@ class ExtensionInstallPrompt PERMISSIONS_DETAILS = 0, WITHHELD_PERMISSIONS_DETAILS, RETAINED_FILES_DETAILS, + RETAINED_DEVICES_DETAILS, }; // This enum is used to differentiate regular and withheld permissions for @@ -135,6 +136,7 @@ class ExtensionInstallPrompt base::string16 GetPermissionsHeading( PermissionsType permissions_type) const; base::string16 GetRetainedFilesHeading() const; + base::string16 GetRetainedDevicesHeading() const; bool ShouldShowPermissions() const; bool ShouldShowExplanationText() const; @@ -160,6 +162,8 @@ class ExtensionInstallPrompt bool GetIsShowingDetails(DetailsType type, size_t index) const; size_t GetRetainedFileCount() const; base::string16 GetRetainedFile(size_t index) const; + size_t GetRetainedDeviceCount() const; + base::string16 GetRetainedDeviceMessageString(size_t index) const; // Populated for BUNDLE_INSTALL_PROMPT. const extensions::BundleInstaller* bundle() const { return bundle_; } @@ -177,6 +181,10 @@ class ExtensionInstallPrompt void set_retained_files(const std::vector<base::FilePath>& retained_files) { retained_files_ = retained_files; } + void set_retained_device_messages( + const std::vector<base::string16>& retained_device_messages) { + retained_device_messages_ = retained_device_messages; + } const gfx::Image& icon() const { return icon_; } void set_icon(const gfx::Image& icon) { icon_ = icon; } @@ -204,6 +212,8 @@ class ExtensionInstallPrompt virtual ~Prompt(); + bool ShouldDisplayRevokeButton() const; + // Returns the InstallPromptPermissions corresponding to // |permissions_type|. InstallPromptPermissions& GetPermissionsForType( @@ -222,6 +232,7 @@ class ExtensionInstallPrompt InstallPromptPermissions withheld_prompt_permissions_; bool is_showing_details_for_retained_files_; + bool is_showing_details_for_retained_devices_; // The extension or bundle being installed. const extensions::Extension* extension_; @@ -247,6 +258,7 @@ class ExtensionInstallPrompt bool has_webstore_data_; std::vector<base::FilePath> retained_files_; + std::vector<base::string16> retained_device_messages_; scoped_refptr<ExtensionInstallPromptExperiment> experiment_; @@ -389,7 +401,8 @@ class ExtensionInstallPrompt virtual void ReviewPermissions( Delegate* delegate, const extensions::Extension* extension, - const std::vector<base::FilePath>& retained_file_paths); + const std::vector<base::FilePath>& retained_file_paths, + const std::vector<base::string16>& retained_device_messages); // Installation was successful. This is declared virtual for testing. virtual void OnInstallSuccess(const extensions::Extension* extension, |