blob: cfd1672eb721056459329e273fe52e93b9bf2ce0 [file] [log] [blame]
[email protected]2894a512014-06-26 19:03:561// 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
dchengc963c7142016-04-08 03:55:228#include <memory>
[email protected]2894a512014-06-26 19:03:569#include <string>
10
11#include "base/macros.h"
[email protected]2894a512014-06-26 19:03:5612#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
16class Browser;
pkotwicz2f181782014-10-29 17:33:4517class ExtensionInstallPromptShowParams;
[email protected]2894a512014-06-26 19:03:5618class GlobalError;
19class GlobalErrorService;
20
21namespace content {
22class BrowserContext;
23}
24
25namespace extensions {
26class Extension;
27class ExternalInstallManager;
28class 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.cronin41593052016-01-08 01:40:1235class ExternalInstallError : public WebstoreDataFetcherDelegate {
[email protected]2894a512014-06-26 19:03:5636 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
probergebc529d62018-04-24 14:48:2646 // 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]2894a512014-06-26 19:03:5654 ExternalInstallError(content::BrowserContext* browser_context,
55 const std::string& extension_id,
56 AlertType error_type,
57 ExternalInstallManager* manager);
dchengae36a4a2014-10-21 12:36:3658 ~ExternalInstallError() override;
[email protected]2894a512014-06-26 19:03:5659
rdevlin.cronin41593052016-01-08 01:40:1260 void OnInstallPromptDone(ExtensionInstallPrompt::Result result);
[email protected]2894a512014-06-26 19:03:5661
lazyboy1899eec42016-03-08 19:00:5062 void DidOpenBubbleView();
63 void DidCloseBubbleView();
64
[email protected]2894a512014-06-26 19:03:5665 // 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
probergebc529d62018-04-24 14:48:2675 // 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]2894a512014-06-26 19:03:5688 private:
89 // WebstoreDataFetcherDelegate implementation.
dchengae36a4a2014-10-21 12:36:3690 void OnWebstoreRequestFailure() override;
91 void OnWebstoreResponseParseSuccess(
dchengc963c7142016-04-08 03:55:2292 std::unique_ptr<base::DictionaryValue> webstore_data) override;
dchengae36a4a2014-10-21 12:36:3693 void OnWebstoreResponseParseFailure(const std::string& error) override;
[email protected]2894a512014-06-26 19:03:5694
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.
pkotwicz2f181782014-10-29 17:33:45100 void OnDialogReady(ExtensionInstallPromptShowParams* show_params,
rdevlin.cronin41593052016-01-08 01:40:12101 const ExtensionInstallPrompt::DoneCallback& done_callback,
dchengc963c7142016-04-08 03:55:22102 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt);
[email protected]2894a512014-06-26 19:03:56103
rdevlin.croninb2daf2e42016-01-14 20:00:54104 // Removes the error.
105 void RemoveError();
106
[email protected]2894a512014-06-26 19:03:56107 // 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
probergebc529d62018-04-24 14:48:26116 // The dialog button configuration to use in the error bubble.
117 DefaultDialogButtonSetting default_dialog_button_setting_ = NOT_SPECIFIED;
118
[email protected]2894a512014-06-26 19:03:56119 // The owning ExternalInstallManager.
120 ExternalInstallManager* manager_;
121
122 // The associated GlobalErrorService.
123 GlobalErrorService* error_service_;
124
125 // The UI for showing the error.
dchengc963c7142016-04-08 03:55:22126 std::unique_ptr<ExtensionInstallPrompt> install_ui_;
127 std::unique_ptr<ExtensionInstallPromptShowParams> install_ui_show_params_;
128 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt_;
[email protected]2894a512014-06-26 19:03:56129
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_|.
dchengc963c7142016-04-08 03:55:22132 std::unique_ptr<GlobalError> global_error_;
[email protected]2894a512014-06-26 19:03:56133
134 // The WebstoreDataFetcher to use in order to populate the error with webstore
135 // information of the extension.
dchengc963c7142016-04-08 03:55:22136 std::unique_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
[email protected]2894a512014-06-26 19:03:56137
Jeremy Roman495db682019-07-12 16:03:24138 base::WeakPtrFactory<ExternalInstallError> weak_factory_{this};
[email protected]2894a512014-06-26 19:03:56139
140 DISALLOW_COPY_AND_ASSIGN(ExternalInstallError);
141};
142
143} // namespace extensions
144
145#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_