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 #include "chrome/browser/extensions/extension_reenabler.h" | 5 #include "chrome/browser/extensions/extension_reenabler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/webstore_data_fetcher.h" | 10 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
10 #include "chrome/browser/extensions/webstore_inline_installer.h" | 11 #include "chrome/browser/extensions/webstore_inline_installer.h" |
11 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
14 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
15 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
20 ExtensionReenabler::~ExtensionReenabler() { | 21 ExtensionReenabler::~ExtensionReenabler() { |
21 if (!finished_) | 22 if (!finished_) |
22 Finish(ABORTED); | 23 Finish(ABORTED); |
23 } | 24 } |
24 | 25 |
25 // static | 26 // static |
26 scoped_ptr<ExtensionReenabler> ExtensionReenabler::PromptForReenable( | 27 std::unique_ptr<ExtensionReenabler> ExtensionReenabler::PromptForReenable( |
27 const scoped_refptr<const Extension>& extension, | 28 const scoped_refptr<const Extension>& extension, |
28 content::BrowserContext* browser_context, | 29 content::BrowserContext* browser_context, |
29 content::WebContents* web_contents, | 30 content::WebContents* web_contents, |
30 const GURL& referrer_url, | 31 const GURL& referrer_url, |
31 const Callback& callback) { | 32 const Callback& callback) { |
32 #if DCHECK_IS_ON() | 33 #if DCHECK_IS_ON() |
33 // We should only try to reenable an extension that is, in fact, disabled. | 34 // We should only try to reenable an extension that is, in fact, disabled. |
34 DCHECK(ExtensionRegistry::Get(browser_context)->disabled_extensions(). | 35 DCHECK(ExtensionRegistry::Get(browser_context)->disabled_extensions(). |
35 Contains(extension->id())); | 36 Contains(extension->id())); |
36 // Currently, this should only be used for extensions that are disabled due | 37 // Currently, this should only be used for extensions that are disabled due |
37 // to a permissions increase. | 38 // to a permissions increase. |
38 int disable_reasons = | 39 int disable_reasons = |
39 ExtensionPrefs::Get(browser_context)->GetDisableReasons(extension->id()); | 40 ExtensionPrefs::Get(browser_context)->GetDisableReasons(extension->id()); |
40 DCHECK_NE(0, disable_reasons & Extension::DISABLE_PERMISSIONS_INCREASE); | 41 DCHECK_NE(0, disable_reasons & Extension::DISABLE_PERMISSIONS_INCREASE); |
41 #endif // DCHECK_IS_ON() | 42 #endif // DCHECK_IS_ON() |
42 | 43 |
43 return make_scoped_ptr(new ExtensionReenabler( | 44 return base::WrapUnique(new ExtensionReenabler( |
44 extension, browser_context, referrer_url, callback, web_contents, | 45 extension, browser_context, referrer_url, callback, web_contents, |
45 ExtensionInstallPrompt::GetDefaultShowDialogCallback())); | 46 ExtensionInstallPrompt::GetDefaultShowDialogCallback())); |
46 } | 47 } |
47 | 48 |
48 // static | 49 // static |
49 scoped_ptr<ExtensionReenabler> | 50 std::unique_ptr<ExtensionReenabler> |
50 ExtensionReenabler::PromptForReenableWithCallbackForTest( | 51 ExtensionReenabler::PromptForReenableWithCallbackForTest( |
51 const scoped_refptr<const Extension>& extension, | 52 const scoped_refptr<const Extension>& extension, |
52 content::BrowserContext* browser_context, | 53 content::BrowserContext* browser_context, |
53 const Callback& callback, | 54 const Callback& callback, |
54 const ExtensionInstallPrompt::ShowDialogCallback& show_dialog_callback) { | 55 const ExtensionInstallPrompt::ShowDialogCallback& show_dialog_callback) { |
55 return make_scoped_ptr(new ExtensionReenabler(extension, browser_context, | 56 return base::WrapUnique(new ExtensionReenabler(extension, browser_context, |
56 GURL(), callback, nullptr, | 57 GURL(), callback, nullptr, |
57 show_dialog_callback)); | 58 show_dialog_callback)); |
58 } | 59 } |
59 | 60 |
60 ExtensionReenabler::ExtensionReenabler( | 61 ExtensionReenabler::ExtensionReenabler( |
61 const scoped_refptr<const Extension>& extension, | 62 const scoped_refptr<const Extension>& extension, |
62 content::BrowserContext* browser_context, | 63 content::BrowserContext* browser_context, |
63 const GURL& referrer_url, | 64 const GURL& referrer_url, |
64 const Callback& callback, | 65 const Callback& callback, |
65 content::WebContents* web_contents, | 66 content::WebContents* web_contents, |
66 const ExtensionInstallPrompt::ShowDialogCallback& show_dialog_callback) | 67 const ExtensionInstallPrompt::ShowDialogCallback& show_dialog_callback) |
67 : extension_(extension), | 68 : extension_(extension), |
(...skipping 19 matching lines...) Expand all Loading... |
87 extension->id())); | 88 extension->id())); |
88 webstore_data_fetcher_->Start(); | 89 webstore_data_fetcher_->Start(); |
89 } else { | 90 } else { |
90 ExtensionInstallPrompt::PromptType type = | 91 ExtensionInstallPrompt::PromptType type = |
91 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( | 92 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( |
92 browser_context, extension.get()); | 93 browser_context, extension.get()); |
93 install_prompt_->ShowDialog( | 94 install_prompt_->ShowDialog( |
94 base::Bind(&ExtensionReenabler::OnInstallPromptDone, | 95 base::Bind(&ExtensionReenabler::OnInstallPromptDone, |
95 weak_factory_.GetWeakPtr()), | 96 weak_factory_.GetWeakPtr()), |
96 extension.get(), nullptr, | 97 extension.get(), nullptr, |
97 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), | 98 base::WrapUnique(new ExtensionInstallPrompt::Prompt(type)), |
98 show_dialog_callback_); | 99 show_dialog_callback_); |
99 } | 100 } |
100 } | 101 } |
101 | 102 |
102 void ExtensionReenabler::OnInstallPromptDone( | 103 void ExtensionReenabler::OnInstallPromptDone( |
103 ExtensionInstallPrompt::Result install_result) { | 104 ExtensionInstallPrompt::Result install_result) { |
104 ReenableResult result = ABORTED; | 105 ReenableResult result = ABORTED; |
105 switch (install_result) { | 106 switch (install_result) { |
106 case ExtensionInstallPrompt::Result::ACCEPTED: { | 107 case ExtensionInstallPrompt::Result::ACCEPTED: { |
107 // Stop observing - we don't want to see our own enablement. | 108 // Stop observing - we don't want to see our own enablement. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 UninstallReason reason) { | 149 UninstallReason reason) { |
149 if (extension == extension_.get()) | 150 if (extension == extension_.get()) |
150 Finish(USER_CANCELED); | 151 Finish(USER_CANCELED); |
151 } | 152 } |
152 | 153 |
153 void ExtensionReenabler::OnWebstoreRequestFailure() { | 154 void ExtensionReenabler::OnWebstoreRequestFailure() { |
154 Finish(ABORTED); | 155 Finish(ABORTED); |
155 } | 156 } |
156 | 157 |
157 void ExtensionReenabler::OnWebstoreResponseParseSuccess( | 158 void ExtensionReenabler::OnWebstoreResponseParseSuccess( |
158 scoped_ptr<base::DictionaryValue> webstore_data) { | 159 std::unique_ptr<base::DictionaryValue> webstore_data) { |
159 DCHECK(!referrer_url_.is_empty()); | 160 DCHECK(!referrer_url_.is_empty()); |
160 std::string error; | 161 std::string error; |
161 if (!WebstoreInlineInstaller::IsRequestorPermitted(*webstore_data, | 162 if (!WebstoreInlineInstaller::IsRequestorPermitted(*webstore_data, |
162 referrer_url_, | 163 referrer_url_, |
163 &error)) { | 164 &error)) { |
164 Finish(NOT_ALLOWED); | 165 Finish(NOT_ALLOWED); |
165 } else { | 166 } else { |
166 ExtensionInstallPrompt::PromptType type = | 167 ExtensionInstallPrompt::PromptType type = |
167 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( | 168 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( |
168 browser_context_, extension_.get()); | 169 browser_context_, extension_.get()); |
169 install_prompt_->ShowDialog( | 170 install_prompt_->ShowDialog( |
170 base::Bind(&ExtensionReenabler::OnInstallPromptDone, | 171 base::Bind(&ExtensionReenabler::OnInstallPromptDone, |
171 weak_factory_.GetWeakPtr()), | 172 weak_factory_.GetWeakPtr()), |
172 extension_.get(), nullptr, | 173 extension_.get(), nullptr, |
173 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), | 174 base::WrapUnique(new ExtensionInstallPrompt::Prompt(type)), |
174 show_dialog_callback_); | 175 show_dialog_callback_); |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 void ExtensionReenabler::OnWebstoreResponseParseFailure( | 179 void ExtensionReenabler::OnWebstoreResponseParseFailure( |
179 const std::string& error) { | 180 const std::string& error) { |
180 Finish(ABORTED); | 181 Finish(ABORTED); |
181 } | 182 } |
182 | 183 |
183 void ExtensionReenabler::Finish(ReenableResult result) { | 184 void ExtensionReenabler::Finish(ReenableResult result) { |
184 DCHECK(!finished_); | 185 DCHECK(!finished_); |
185 finished_ = true; | 186 finished_ = true; |
186 registry_observer_.RemoveAll(); | 187 registry_observer_.RemoveAll(); |
187 callback_.Run(result); | 188 callback_.Run(result); |
188 } | 189 } |
189 | 190 |
190 } // namespace extensions | 191 } // namespace extensions |
OLD | NEW |