| OLD | NEW |
| (Empty) |
| 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 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 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 ExtensionInstallUI; | |
| 17 class GlobalError; | |
| 18 class GlobalErrorService; | |
| 19 | |
| 20 namespace content { | |
| 21 class BrowserContext; | |
| 22 } | |
| 23 | |
| 24 namespace extensions { | |
| 25 class Extension; | |
| 26 class ExternalInstallManager; | |
| 27 class WebstoreDataFetcher; | |
| 28 | |
| 29 // An error to show the user an extension has been externally installed. The | |
| 30 // error will automatically fetch data about the extension from the webstore (if | |
| 31 // possible) and will handle adding itself to the GlobalErrorService when | |
| 32 // initialized and removing itself from the GlobalErrorService upon | |
| 33 // destruction. | |
| 34 class ExternalInstallError : public ExtensionInstallPrompt::Delegate, | |
| 35 public WebstoreDataFetcherDelegate { | |
| 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 | |
| 46 ExternalInstallError(content::BrowserContext* browser_context, | |
| 47 const std::string& extension_id, | |
| 48 AlertType error_type, | |
| 49 ExternalInstallManager* manager); | |
| 50 virtual ~ExternalInstallError(); | |
| 51 | |
| 52 // ExtensionInstallPrompt::Delegate implementation. | |
| 53 virtual void InstallUIProceed() OVERRIDE; | |
| 54 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | |
| 55 | |
| 56 // Acknowledge the associated external extension. | |
| 57 void AcknowledgeExtension(); | |
| 58 | |
| 59 // Show the associated dialog. This should only be called once the dialog is | |
| 60 // ready. | |
| 61 void ShowDialog(); | |
| 62 | |
| 63 // Return the associated extension, or NULL. | |
| 64 const Extension* GetExtension() const; | |
| 65 | |
| 66 const std::string& extension_id() const { return extension_id_; } | |
| 67 AlertType alert_type() const { return alert_type_; } | |
| 68 | |
| 69 private: | |
| 70 // WebstoreDataFetcherDelegate implementation. | |
| 71 virtual void OnWebstoreRequestFailure() OVERRIDE; | |
| 72 virtual void OnWebstoreResponseParseSuccess( | |
| 73 scoped_ptr<base::DictionaryValue> webstore_data) OVERRIDE; | |
| 74 virtual void OnWebstoreResponseParseFailure( | |
| 75 const std::string& error) OVERRIDE; | |
| 76 | |
| 77 // Called when data fetching has completed (either successfully or not). | |
| 78 void OnFetchComplete(); | |
| 79 | |
| 80 // Called when the dialog has been successfully populated, and is ready to be | |
| 81 // shown. | |
| 82 void OnDialogReady(const ExtensionInstallPrompt::ShowParams& show_params, | |
| 83 ExtensionInstallPrompt::Delegate* prompt_delegate, | |
| 84 const ExtensionInstallPrompt::Prompt& prompt); | |
| 85 | |
| 86 // The associated BrowserContext. | |
| 87 content::BrowserContext* browser_context_; | |
| 88 | |
| 89 // The id of the external extension. | |
| 90 std::string extension_id_; | |
| 91 | |
| 92 // The type of alert to show the user. | |
| 93 AlertType alert_type_; | |
| 94 | |
| 95 // The owning ExternalInstallManager. | |
| 96 ExternalInstallManager* manager_; | |
| 97 | |
| 98 // The associated GlobalErrorService. | |
| 99 GlobalErrorService* error_service_; | |
| 100 | |
| 101 // The UI for showing the error. | |
| 102 scoped_ptr<ExtensionInstallPrompt> install_ui_; | |
| 103 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt_; | |
| 104 scoped_ptr<ExtensionInstallPrompt::ShowParams> show_params_; | |
| 105 | |
| 106 // The UI for the given error, which will take the form of either a menu | |
| 107 // alert or a bubble alert (depending on the |alert_type_|. | |
| 108 scoped_ptr<GlobalError> global_error_; | |
| 109 | |
| 110 // The associated browser. Can be NULL. | |
| 111 Browser* browser_; | |
| 112 | |
| 113 // The WebstoreDataFetcher to use in order to populate the error with webstore | |
| 114 // information of the extension. | |
| 115 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_; | |
| 116 | |
| 117 base::WeakPtrFactory<ExternalInstallError> weak_factory_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(ExternalInstallError); | |
| 120 }; | |
| 121 | |
| 122 } // namespace extensions | |
| 123 | |
| 124 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_ | |
| OLD | NEW |