Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / extensions / extension_reenabler.h
blobe8ed4f8529b2d6be9b98dc817a28728e1bf2e150
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
15 #include "extensions/browser/extension_registry_observer.h"
17 namespace content {
18 class BrowserContext;
21 namespace extensions {
23 class Extension;
24 class ExtensionRegistry;
25 class WebstoreDataFetcher;
27 // A class to handle reenabling an extension disabled due to a permissions
28 // increase.
29 // TODO(devlin): Once we get the UI figured out, we should also have this handle
30 // other disable reasons.
31 class ExtensionReenabler : public ExtensionInstallPrompt::Delegate,
32 public ExtensionRegistryObserver,
33 public WebstoreDataFetcherDelegate {
34 public:
35 enum ReenableResult {
36 REENABLE_SUCCESS, // The extension has been successfully re-enabled.
37 USER_CANCELED, // The user chose to not re-enable the extension.
38 NOT_ALLOWED, // The re-enable is not allowed.
39 ABORTED, // The re-enable process was aborted due to, e.g.,
40 // shutdown or a bad webstore response.
43 using Callback = base::Callback<void(ReenableResult)>;
45 ~ExtensionReenabler() override;
47 // Prompts the user to reenable the given |extension|, and calls |callback|
48 // upon completion.
49 // If |referrer_url| is non-empty, then this will also check to make sure
50 // that the referrer_url is listed as a trusted url by the extension.
51 static scoped_ptr<ExtensionReenabler> PromptForReenable(
52 const scoped_refptr<const Extension>& extension,
53 content::BrowserContext* browser_context,
54 content::WebContents* web_contents,
55 const GURL& referrer_url,
56 const Callback& callback);
58 // Like PromptForReenable, but allows tests to inject the
59 // ExtensionInstallPrompt.
60 static scoped_ptr<ExtensionReenabler> PromptForReenableWithPromptForTest(
61 const scoped_refptr<const Extension>& extension,
62 content::BrowserContext* browser_context,
63 const Callback& callback,
64 scoped_ptr<ExtensionInstallPrompt> install_prompt);
66 private:
67 ExtensionReenabler(const scoped_refptr<const Extension>& extension,
68 content::BrowserContext* browser_context,
69 const GURL& referrer_url,
70 const Callback& callback,
71 scoped_ptr<ExtensionInstallPrompt> install_prompt);
73 // ExtensionInstallPrompt::Delegate:
74 void InstallUIProceed() override;
75 void InstallUIAbort(bool user_initiated) override;
77 // ExtensionRegistryObserver:
78 void OnExtensionLoaded(content::BrowserContext* browser_context,
79 const Extension* extension) override;
80 void OnExtensionUninstalled(content::BrowserContext* browser_context,
81 const Extension* extension,
82 UninstallReason reason) override;
84 // WebstoreDataFetcherDelegate:
85 void OnWebstoreRequestFailure() override;
86 void OnWebstoreResponseParseSuccess(
87 scoped_ptr<base::DictionaryValue> webstore_data) override;
88 void OnWebstoreResponseParseFailure(const std::string& error) override;
90 // Sets the |finished_| bit and runs |callback_| with the given |result|.
91 void Finish(ReenableResult result);
93 // The extension to be re-enabled.
94 scoped_refptr<const Extension> extension_;
96 // The associated browser context.
97 content::BrowserContext* browser_context_;
99 // The url of the referrer, if any. If this is non-empty, it means we have
100 // to check that the url is trusted by the extension.
101 GURL referrer_url_;
103 // The callback to run upon completion.
104 Callback callback_;
106 // The re-enable prompt.
107 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
109 // Indicates whether the re-enable process finished.
110 bool finished_;
112 // The data fetcher for retrieving webstore data.
113 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
115 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
116 registry_observer_;
118 DISALLOW_COPY_AND_ASSIGN(ExtensionReenabler);
121 } // namespace extensions
123 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_