blob: cfe9bbe06f3342c3fb43d34a0ed9514786924283 [file] [log] [blame]
[email protected]764bc252013-01-08 03:19:031// 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]50736a12013-09-26 08:58:3411#include "base/callback.h"
[email protected]764bc252013-01-08 03:19:0312#include "base/compiler_specific.h"
[email protected]a97883a882014-05-13 11:49:2513#include "base/scoped_observer.h"
[email protected]764bc252013-01-08 03:19:0314#include "chrome/browser/extensions/extension_install_prompt.h"
[email protected]7b1e364a2013-08-09 15:36:1215#include "content/public/browser/notification_observer.h"
16#include "content/public/browser/notification_registrar.h"
[email protected]e2377032013-01-18 17:53:2217#include "content/public/browser/page_navigator.h"
[email protected]a97883a882014-05-13 11:49:2518#include "extensions/browser/extension_registry_observer.h"
[email protected]764bc252013-01-08 03:19:0319
20class ExtensionEnableFlowDelegate;
21
[email protected]e2377032013-01-18 17:53:2222namespace content {
23class PageNavigator;
24class WebContents;
25}
26
[email protected]a97883a882014-05-13 11:49:2527namespace extensions {
28class ExtensionRegistry;
29}
30
[email protected]764bc252013-01-08 03:19:0331// ExtensionEnableFlow performs an UI flow to enable a disabled/terminated
32// extension. It calls its delegate when enabling is done or is aborted.
33// Callback on the delegate might be called synchronously if there is no
34// permission change while the extension is disabled/terminated (or the
35// extension is enabled already). Otherwise, a re-enable install prompt is
36// shown to user. The extension is enabled when user acknowledges it or the
37// flow is aborted when user declines it.
[email protected]e2377032013-01-18 17:53:2238class ExtensionEnableFlow : public ExtensionInstallPrompt::Delegate,
[email protected]7b1e364a2013-08-09 15:36:1239 public content::PageNavigator,
[email protected]a97883a882014-05-13 11:49:2540 public content::NotificationObserver,
41 public extensions::ExtensionRegistryObserver {
[email protected]764bc252013-01-08 03:19:0342 public:
43 ExtensionEnableFlow(Profile* profile,
44 const std::string& extension_id,
45 ExtensionEnableFlowDelegate* delegate);
dcheng5dd5ff62014-10-21 12:42:3846 ~ExtensionEnableFlow() override;
[email protected]764bc252013-01-08 03:19:0347
48 // Starts the flow and the logic continues on |delegate_| after enabling is
[email protected]e2377032013-01-18 17:53:2249 // finished or aborted. Note that |delegate_| could be called synchronously
50 // before this call returns when there is no need to show UI to finish the
[email protected]50736a12013-09-26 08:58:3451 // enabling flow. Three variations of the flow are supported:
52 // - one with a parent WebContents
53 // - one with a native parent window
54 // - one with a callback for creating a parent window
[email protected]e2377032013-01-18 17:53:2255 void StartForWebContents(content::WebContents* parent_contents);
56 void StartForNativeWindow(gfx::NativeWindow parent_window);
[email protected]50736a12013-09-26 08:58:3457 void StartForCurrentlyNonexistentWindow(
58 base::Callback<gfx::NativeWindow(void)> window_getter);
[email protected]764bc252013-01-08 03:19:0359
60 const std::string& extension_id() const { return extension_id_; }
61
62 private:
[email protected]7b1e364a2013-08-09 15:36:1263 // Runs the enable flow. It starts by checking if the extension is loaded.
64 // If not, it tries to reload it. If the load is asynchronous, wait for the
65 // load to finish before continuing the flow. Otherwise, calls
66 // CheckPermissionAndMaybePromptUser finish the flow.
[email protected]e2377032013-01-18 17:53:2267 void Run();
68
[email protected]7b1e364a2013-08-09 15:36:1269 // Checks if there is permission escalation while the extension is
70 // disabled/terminated. If no, enables the extension and notify |delegate_|
71 // synchronously. Otherwise, creates an ExtensionInstallPrompt and asks user
72 // to confirm.
73 void CheckPermissionAndMaybePromptUser();
74
[email protected]e2377032013-01-18 17:53:2275 // Creates an ExtensionInstallPrompt in |prompt_|.
76 void CreatePrompt();
77
[email protected]7b1e364a2013-08-09 15:36:1278 // Starts/stops observing extension load notifications.
79 void StartObserving();
80 void StopObserving();
81
82 // content::NotificationObserver overrides:
dcheng5dd5ff62014-10-21 12:42:3883 void Observe(int type,
84 const content::NotificationSource& source,
85 const content::NotificationDetails& details) override;
[email protected]7b1e364a2013-08-09 15:36:1286
[email protected]a97883a882014-05-13 11:49:2587 // extensions::ExtensionRegistryObserver overrides:
dcheng5dd5ff62014-10-21 12:42:3888 void OnExtensionLoaded(content::BrowserContext* browser_context,
89 const extensions::Extension* extension) override;
90 void OnExtensionUninstalled(content::BrowserContext* browser_context,
91 const extensions::Extension* extension,
92 extensions::UninstallReason reason) override;
[email protected]a97883a882014-05-13 11:49:2593
[email protected]764bc252013-01-08 03:19:0394 // ExtensionInstallPrompt::Delegate overrides:
dcheng5dd5ff62014-10-21 12:42:3895 void InstallUIProceed() override;
96 void InstallUIAbort(bool user_initiated) override;
[email protected]764bc252013-01-08 03:19:0397
[email protected]e2377032013-01-18 17:53:2298 // content::PageNavigator overrides:
dcheng5dd5ff62014-10-21 12:42:3899 content::WebContents* OpenURL(const content::OpenURLParams& params) override;
[email protected]e2377032013-01-18 17:53:22100
[email protected]764bc252013-01-08 03:19:03101 Profile* const profile_;
102 const std::string extension_id_;
103 ExtensionEnableFlowDelegate* const delegate_; // Not owned.
104
[email protected]e2377032013-01-18 17:53:22105 // Parent web contents for ExtensionInstallPrompt that may be created during
106 // the flow. Note this is mutually exclusive with |parent_window_| below.
107 content::WebContents* parent_contents_;
108
109 // Parent native window for ExtensionInstallPrompt. Note this is mutually
110 // exclusive with |parent_contents_| above.
111 gfx::NativeWindow parent_window_;
112
[email protected]50736a12013-09-26 08:58:34113 // Called to acquire a parent window for the prompt. This is used for clients
114 // who only want to create a window if it is required.
115 base::Callback<gfx::NativeWindow(void)> window_getter_;
116
[email protected]764bc252013-01-08 03:19:03117 scoped_ptr<ExtensionInstallPrompt> prompt_;
[email protected]7b1e364a2013-08-09 15:36:12118 content::NotificationRegistrar registrar_;
[email protected]764bc252013-01-08 03:19:03119
[email protected]a97883a882014-05-13 11:49:25120 // Listen to extension load notification.
121 ScopedObserver<extensions::ExtensionRegistry,
122 extensions::ExtensionRegistryObserver>
123 extension_registry_observer_;
124
[email protected]764bc252013-01-08 03:19:03125 DISALLOW_COPY_AND_ASSIGN(ExtensionEnableFlow);
126};
127
128#endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ENABLE_FLOW_H_