[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_ |
| 7 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "base/macros.h" |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
| 13 | #include "chrome/browser/extensions/extension_install_prompt.h" |
| 14 | #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" |
| 15 | |
| 16 | class Browser; |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 17 | class ExtensionInstallPromptShowParams; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 18 | class GlobalError; |
| 19 | class GlobalErrorService; |
| 20 | |
| 21 | namespace content { |
| 22 | class BrowserContext; |
| 23 | } |
| 24 | |
| 25 | namespace extensions { |
| 26 | class Extension; |
| 27 | class ExternalInstallManager; |
| 28 | class WebstoreDataFetcher; |
| 29 | |
| 30 | // An error to show the user an extension has been externally installed. The |
| 31 | // error will automatically fetch data about the extension from the webstore (if |
| 32 | // possible) and will handle adding itself to the GlobalErrorService when |
| 33 | // initialized and removing itself from the GlobalErrorService upon |
| 34 | // destruction. |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 35 | class ExternalInstallError : public WebstoreDataFetcherDelegate { |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 36 | public: |
| 37 | // The possible types of errors to show. A menu alert adds a menu item to the |
| 38 | // wrench, which spawns an extension install dialog when clicked. The bubble |
| 39 | // alert also adds an item, but spawns a bubble instead (less invasive and |
| 40 | // easier to dismiss). |
| 41 | enum AlertType { |
| 42 | BUBBLE_ALERT, |
| 43 | MENU_ALERT |
| 44 | }; |
| 45 | |
proberge | bc529d6 | 2018-04-24 14:48:26 | [diff] [blame] | 46 | // The possible dialog button configurations to use in the error bubble. |
| 47 | enum DefaultDialogButtonSetting { |
| 48 | NOT_SPECIFIED, |
| 49 | DIALOG_BUTTON_OK, |
| 50 | DIALOG_BUTTON_CANCEL, |
| 51 | NO_DEFAULT_DIALOG_BUTTON |
| 52 | }; |
| 53 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 54 | ExternalInstallError(content::BrowserContext* browser_context, |
| 55 | const std::string& extension_id, |
| 56 | AlertType error_type, |
| 57 | ExternalInstallManager* manager); |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 58 | ~ExternalInstallError() override; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 59 | |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 60 | void OnInstallPromptDone(ExtensionInstallPrompt::Result result); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 61 | |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 62 | void DidOpenBubbleView(); |
| 63 | void DidCloseBubbleView(); |
| 64 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 65 | // Show the associated dialog. This should only be called once the dialog is |
| 66 | // ready. |
| 67 | void ShowDialog(Browser* browser); |
| 68 | |
| 69 | // Return the associated extension, or NULL. |
| 70 | const Extension* GetExtension() const; |
| 71 | |
| 72 | const std::string& extension_id() const { return extension_id_; } |
| 73 | AlertType alert_type() const { return alert_type_; } |
| 74 | |
proberge | bc529d6 | 2018-04-24 14:48:26 | [diff] [blame] | 75 | // Returns the setting specified by the following optional sources, by order |
| 76 | // of priority: |
| 77 | // 1. The webstore response's |kExternalInstallDefaultButtonKey| parameter. |
| 78 | // 2. The |kExternalExtensionDefaultButtonControl| field trial parameter's |
| 79 | // |kExternalInstallDefaultButtonKey| value. |
| 80 | // If not specified by either optional source, returns |NOT_SPECIFIED|. |
| 81 | static DefaultDialogButtonSetting GetDefaultDialogButton( |
| 82 | const base::Value& webstore_response); |
| 83 | |
| 84 | DefaultDialogButtonSetting default_dialog_button_setting() const { |
| 85 | return default_dialog_button_setting_; |
| 86 | } |
| 87 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 88 | private: |
| 89 | // WebstoreDataFetcherDelegate implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 90 | void OnWebstoreRequestFailure() override; |
| 91 | void OnWebstoreResponseParseSuccess( |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 92 | std::unique_ptr<base::DictionaryValue> webstore_data) override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 93 | void OnWebstoreResponseParseFailure(const std::string& error) override; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 94 | |
| 95 | // Called when data fetching has completed (either successfully or not). |
| 96 | void OnFetchComplete(); |
| 97 | |
| 98 | // Called when the dialog has been successfully populated, and is ready to be |
| 99 | // shown. |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 100 | void OnDialogReady(ExtensionInstallPromptShowParams* show_params, |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 101 | const ExtensionInstallPrompt::DoneCallback& done_callback, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 102 | std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 103 | |
rdevlin.cronin | b2daf2e4 | 2016-01-14 20:00:54 | [diff] [blame] | 104 | // Removes the error. |
| 105 | void RemoveError(); |
| 106 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 107 | // The associated BrowserContext. |
| 108 | content::BrowserContext* browser_context_; |
| 109 | |
| 110 | // The id of the external extension. |
| 111 | std::string extension_id_; |
| 112 | |
| 113 | // The type of alert to show the user. |
| 114 | AlertType alert_type_; |
| 115 | |
proberge | bc529d6 | 2018-04-24 14:48:26 | [diff] [blame] | 116 | // The dialog button configuration to use in the error bubble. |
| 117 | DefaultDialogButtonSetting default_dialog_button_setting_ = NOT_SPECIFIED; |
| 118 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 119 | // The owning ExternalInstallManager. |
| 120 | ExternalInstallManager* manager_; |
| 121 | |
| 122 | // The associated GlobalErrorService. |
| 123 | GlobalErrorService* error_service_; |
| 124 | |
| 125 | // The UI for showing the error. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 126 | std::unique_ptr<ExtensionInstallPrompt> install_ui_; |
| 127 | std::unique_ptr<ExtensionInstallPromptShowParams> install_ui_show_params_; |
| 128 | std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt_; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 129 | |
| 130 | // The UI for the given error, which will take the form of either a menu |
| 131 | // alert or a bubble alert (depending on the |alert_type_|. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 132 | std::unique_ptr<GlobalError> global_error_; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 133 | |
| 134 | // The WebstoreDataFetcher to use in order to populate the error with webstore |
| 135 | // information of the extension. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 136 | std::unique_ptr<WebstoreDataFetcher> webstore_data_fetcher_; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 137 | |
Jeremy Roman | 495db68 | 2019-07-12 16:03:24 | [diff] [blame] | 138 | base::WeakPtrFactory<ExternalInstallError> weak_factory_{this}; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 139 | |
| 140 | DISALLOW_COPY_AND_ASSIGN(ExternalInstallError); |
| 141 | }; |
| 142 | |
| 143 | } // namespace extensions |
| 144 | |
| 145 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_ |