[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 1 | // Copyright (c) 2012 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_UI_EXTENSIONS_EXTENSION_ENABLE_FLOW_H_ |
| 6 | #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ENABLE_FLOW_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame^] | 11 | #include "base/callback.h" |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
| 13 | #include "chrome/browser/extensions/extension_install_prompt.h" |
[email protected] | 7b1e364a | 2013-08-09 15:36:12 | [diff] [blame] | 14 | #include "content/public/browser/notification_observer.h" |
| 15 | #include "content/public/browser/notification_registrar.h" |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 16 | #include "content/public/browser/page_navigator.h" |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 17 | |
| 18 | class ExtensionEnableFlowDelegate; |
| 19 | |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 20 | namespace content { |
| 21 | class PageNavigator; |
| 22 | class WebContents; |
| 23 | } |
| 24 | |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 25 | // ExtensionEnableFlow performs an UI flow to enable a disabled/terminated |
| 26 | // extension. It calls its delegate when enabling is done or is aborted. |
| 27 | // Callback on the delegate might be called synchronously if there is no |
| 28 | // permission change while the extension is disabled/terminated (or the |
| 29 | // extension is enabled already). Otherwise, a re-enable install prompt is |
| 30 | // shown to user. The extension is enabled when user acknowledges it or the |
| 31 | // flow is aborted when user declines it. |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 32 | class ExtensionEnableFlow : public ExtensionInstallPrompt::Delegate, |
[email protected] | 7b1e364a | 2013-08-09 15:36:12 | [diff] [blame] | 33 | public content::PageNavigator, |
| 34 | public content::NotificationObserver { |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 35 | public: |
| 36 | ExtensionEnableFlow(Profile* profile, |
| 37 | const std::string& extension_id, |
| 38 | ExtensionEnableFlowDelegate* delegate); |
| 39 | virtual ~ExtensionEnableFlow(); |
| 40 | |
| 41 | // Starts the flow and the logic continues on |delegate_| after enabling is |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 42 | // finished or aborted. Note that |delegate_| could be called synchronously |
| 43 | // before this call returns when there is no need to show UI to finish the |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame^] | 44 | // enabling flow. Three variations of the flow are supported: |
| 45 | // - one with a parent WebContents |
| 46 | // - one with a native parent window |
| 47 | // - one with a callback for creating a parent window |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 48 | void StartForWebContents(content::WebContents* parent_contents); |
| 49 | void StartForNativeWindow(gfx::NativeWindow parent_window); |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame^] | 50 | void StartForCurrentlyNonexistentWindow( |
| 51 | base::Callback<gfx::NativeWindow(void)> window_getter); |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 52 | |
| 53 | const std::string& extension_id() const { return extension_id_; } |
| 54 | |
| 55 | private: |
[email protected] | 7b1e364a | 2013-08-09 15:36:12 | [diff] [blame] | 56 | // Runs the enable flow. It starts by checking if the extension is loaded. |
| 57 | // If not, it tries to reload it. If the load is asynchronous, wait for the |
| 58 | // load to finish before continuing the flow. Otherwise, calls |
| 59 | // CheckPermissionAndMaybePromptUser finish the flow. |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 60 | void Run(); |
| 61 | |
[email protected] | 7b1e364a | 2013-08-09 15:36:12 | [diff] [blame] | 62 | // Checks if there is permission escalation while the extension is |
| 63 | // disabled/terminated. If no, enables the extension and notify |delegate_| |
| 64 | // synchronously. Otherwise, creates an ExtensionInstallPrompt and asks user |
| 65 | // to confirm. |
| 66 | void CheckPermissionAndMaybePromptUser(); |
| 67 | |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 68 | // Creates an ExtensionInstallPrompt in |prompt_|. |
| 69 | void CreatePrompt(); |
| 70 | |
[email protected] | 7b1e364a | 2013-08-09 15:36:12 | [diff] [blame] | 71 | // Starts/stops observing extension load notifications. |
| 72 | void StartObserving(); |
| 73 | void StopObserving(); |
| 74 | |
| 75 | // content::NotificationObserver overrides: |
| 76 | virtual void Observe(int type, |
| 77 | const content::NotificationSource& source, |
| 78 | const content::NotificationDetails& details) OVERRIDE; |
| 79 | |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 80 | // ExtensionInstallPrompt::Delegate overrides: |
| 81 | virtual void InstallUIProceed() OVERRIDE; |
| 82 | virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| 83 | |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 84 | // content::PageNavigator overrides: |
| 85 | virtual content::WebContents* OpenURL( |
| 86 | const content::OpenURLParams& params) OVERRIDE; |
| 87 | |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 88 | Profile* const profile_; |
| 89 | const std::string extension_id_; |
| 90 | ExtensionEnableFlowDelegate* const delegate_; // Not owned. |
| 91 | |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 92 | // Parent web contents for ExtensionInstallPrompt that may be created during |
| 93 | // the flow. Note this is mutually exclusive with |parent_window_| below. |
| 94 | content::WebContents* parent_contents_; |
| 95 | |
| 96 | // Parent native window for ExtensionInstallPrompt. Note this is mutually |
| 97 | // exclusive with |parent_contents_| above. |
| 98 | gfx::NativeWindow parent_window_; |
| 99 | |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame^] | 100 | // Called to acquire a parent window for the prompt. This is used for clients |
| 101 | // who only want to create a window if it is required. |
| 102 | base::Callback<gfx::NativeWindow(void)> window_getter_; |
| 103 | |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 104 | scoped_ptr<ExtensionInstallPrompt> prompt_; |
[email protected] | 7b1e364a | 2013-08-09 15:36:12 | [diff] [blame] | 105 | content::NotificationRegistrar registrar_; |
[email protected] | 764bc25 | 2013-01-08 03:19:03 | [diff] [blame] | 106 | |
| 107 | DISALLOW_COPY_AND_ASSIGN(ExtensionEnableFlow); |
| 108 | }; |
| 109 | |
| 110 | #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ENABLE_FLOW_H_ |