| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
| 14 #include "chrome/browser/extensions/extension_install_prompt.h" | 15 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 15 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" | 16 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h" |
| 16 #include "extensions/browser/extension_registry_observer.h" | 17 #include "extensions/browser/extension_registry_observer.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class BrowserContext; | 20 class BrowserContext; |
| 20 } | 21 } |
| 21 | 22 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 using Callback = base::Callback<void(ReenableResult)>; | 44 using Callback = base::Callback<void(ReenableResult)>; |
| 44 | 45 |
| 45 ~ExtensionReenabler() override; | 46 ~ExtensionReenabler() override; |
| 46 | 47 |
| 47 // Prompts the user to reenable the given |extension|, and calls |callback| | 48 // Prompts the user to reenable the given |extension|, and calls |callback| |
| 48 // upon completion. | 49 // upon completion. |
| 49 // If |referrer_url| is non-empty, then this will also check to make sure | 50 // 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 // that the referrer_url is listed as a trusted url by the extension. |
| 51 static scoped_ptr<ExtensionReenabler> PromptForReenable( | 52 static std::unique_ptr<ExtensionReenabler> PromptForReenable( |
| 52 const scoped_refptr<const Extension>& extension, | 53 const scoped_refptr<const Extension>& extension, |
| 53 content::BrowserContext* browser_context, | 54 content::BrowserContext* browser_context, |
| 54 content::WebContents* web_contents, | 55 content::WebContents* web_contents, |
| 55 const GURL& referrer_url, | 56 const GURL& referrer_url, |
| 56 const Callback& callback); | 57 const Callback& callback); |
| 57 | 58 |
| 58 // Like PromptForReenable, but allows tests to inject the | 59 // Like PromptForReenable, but allows tests to inject the |
| 59 // ExtensionInstallPrompt. | 60 // ExtensionInstallPrompt. |
| 60 static scoped_ptr<ExtensionReenabler> PromptForReenableWithCallbackForTest( | 61 static std::unique_ptr<ExtensionReenabler> |
| 62 PromptForReenableWithCallbackForTest( |
| 61 const scoped_refptr<const Extension>& extension, | 63 const scoped_refptr<const Extension>& extension, |
| 62 content::BrowserContext* browser_context, | 64 content::BrowserContext* browser_context, |
| 63 const Callback& callback, | 65 const Callback& callback, |
| 64 const ExtensionInstallPrompt::ShowDialogCallback& show_callback); | 66 const ExtensionInstallPrompt::ShowDialogCallback& show_callback); |
| 65 | 67 |
| 66 private: | 68 private: |
| 67 ExtensionReenabler( | 69 ExtensionReenabler( |
| 68 const scoped_refptr<const Extension>& extension, | 70 const scoped_refptr<const Extension>& extension, |
| 69 content::BrowserContext* browser_context, | 71 content::BrowserContext* browser_context, |
| 70 const GURL& referrer_url, | 72 const GURL& referrer_url, |
| 71 const Callback& callback, | 73 const Callback& callback, |
| 72 content::WebContents* web_contents, | 74 content::WebContents* web_contents, |
| 73 const ExtensionInstallPrompt::ShowDialogCallback& show_callback); | 75 const ExtensionInstallPrompt::ShowDialogCallback& show_callback); |
| 74 | 76 |
| 75 void OnInstallPromptDone(ExtensionInstallPrompt::Result result); | 77 void OnInstallPromptDone(ExtensionInstallPrompt::Result result); |
| 76 | 78 |
| 77 // ExtensionRegistryObserver: | 79 // ExtensionRegistryObserver: |
| 78 void OnExtensionLoaded(content::BrowserContext* browser_context, | 80 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 79 const Extension* extension) override; | 81 const Extension* extension) override; |
| 80 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 82 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 81 const Extension* extension, | 83 const Extension* extension, |
| 82 UninstallReason reason) override; | 84 UninstallReason reason) override; |
| 83 | 85 |
| 84 // WebstoreDataFetcherDelegate: | 86 // WebstoreDataFetcherDelegate: |
| 85 void OnWebstoreRequestFailure() override; | 87 void OnWebstoreRequestFailure() override; |
| 86 void OnWebstoreResponseParseSuccess( | 88 void OnWebstoreResponseParseSuccess( |
| 87 scoped_ptr<base::DictionaryValue> webstore_data) override; | 89 std::unique_ptr<base::DictionaryValue> webstore_data) override; |
| 88 void OnWebstoreResponseParseFailure(const std::string& error) override; | 90 void OnWebstoreResponseParseFailure(const std::string& error) override; |
| 89 | 91 |
| 90 // Sets the |finished_| bit and runs |callback_| with the given |result|. | 92 // Sets the |finished_| bit and runs |callback_| with the given |result|. |
| 91 void Finish(ReenableResult result); | 93 void Finish(ReenableResult result); |
| 92 | 94 |
| 93 // The extension to be re-enabled. | 95 // The extension to be re-enabled. |
| 94 scoped_refptr<const Extension> extension_; | 96 scoped_refptr<const Extension> extension_; |
| 95 | 97 |
| 96 // The associated browser context. | 98 // The associated browser context. |
| 97 content::BrowserContext* browser_context_; | 99 content::BrowserContext* browser_context_; |
| 98 | 100 |
| 99 // The url of the referrer, if any. If this is non-empty, it means we have | 101 // 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. | 102 // to check that the url is trusted by the extension. |
| 101 GURL referrer_url_; | 103 GURL referrer_url_; |
| 102 | 104 |
| 103 // The callback to run upon completion. | 105 // The callback to run upon completion. |
| 104 Callback callback_; | 106 Callback callback_; |
| 105 | 107 |
| 106 // The callback to use to show the dialog. | 108 // The callback to use to show the dialog. |
| 107 ExtensionInstallPrompt::ShowDialogCallback show_dialog_callback_; | 109 ExtensionInstallPrompt::ShowDialogCallback show_dialog_callback_; |
| 108 | 110 |
| 109 // The re-enable prompt. | 111 // The re-enable prompt. |
| 110 scoped_ptr<ExtensionInstallPrompt> install_prompt_; | 112 std::unique_ptr<ExtensionInstallPrompt> install_prompt_; |
| 111 | 113 |
| 112 // Indicates whether the re-enable process finished. | 114 // Indicates whether the re-enable process finished. |
| 113 bool finished_; | 115 bool finished_; |
| 114 | 116 |
| 115 // The data fetcher for retrieving webstore data. | 117 // The data fetcher for retrieving webstore data. |
| 116 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_; | 118 std::unique_ptr<WebstoreDataFetcher> webstore_data_fetcher_; |
| 117 | 119 |
| 118 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 120 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 119 registry_observer_; | 121 registry_observer_; |
| 120 | 122 |
| 121 base::WeakPtrFactory<ExtensionReenabler> weak_factory_; | 123 base::WeakPtrFactory<ExtensionReenabler> weak_factory_; |
| 122 | 124 |
| 123 DISALLOW_COPY_AND_ASSIGN(ExtensionReenabler); | 125 DISALLOW_COPY_AND_ASSIGN(ExtensionReenabler); |
| 124 }; | 126 }; |
| 125 | 127 |
| 126 } // namespace extensions | 128 } // namespace extensions |
| 127 | 129 |
| 128 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_ | 130 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_ |
| OLD | NEW |