OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/bundle_installer.h" | 5 #include "chrome/browser/extensions/bundle_installer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/extensions/crx_installer.h" | 17 #include "chrome/browser/extensions/crx_installer.h" |
17 #include "chrome/browser/extensions/permissions_updater.h" | 18 #include "chrome/browser/extensions/permissions_updater.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return; | 169 return; |
169 } | 170 } |
170 | 171 |
171 // Start each WebstoreInstaller. | 172 // Start each WebstoreInstaller. |
172 for (const std::pair<std::string, Item>& entry : items_) { | 173 for (const std::pair<std::string, Item>& entry : items_) { |
173 if (entry.second.state != Item::STATE_PENDING) | 174 if (entry.second.state != Item::STATE_PENDING) |
174 continue; | 175 continue; |
175 | 176 |
176 // Since we've already confirmed the permissions, create an approval that | 177 // Since we've already confirmed the permissions, create an approval that |
177 // lets CrxInstaller bypass the prompt. | 178 // lets CrxInstaller bypass the prompt. |
178 scoped_ptr<WebstoreInstaller::Approval> approval( | 179 std::unique_ptr<WebstoreInstaller::Approval> approval( |
179 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 180 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
180 profile_, | 181 profile_, entry.first, |
181 entry.first, | 182 base::WrapUnique(parsed_manifests_[entry.first]->DeepCopy()), |
182 make_scoped_ptr(parsed_manifests_[entry.first]->DeepCopy()), | |
183 true)); | 183 true)); |
184 approval->use_app_installed_bubble = false; | 184 approval->use_app_installed_bubble = false; |
185 approval->skip_post_install_ui = true; | 185 approval->skip_post_install_ui = true; |
186 approval->authuser = authuser_; | 186 approval->authuser = authuser_; |
187 approval->installing_icon = | 187 approval->installing_icon = |
188 gfx::ImageSkia::CreateFrom1xBitmap(entry.second.icon); | 188 gfx::ImageSkia::CreateFrom1xBitmap(entry.second.icon); |
189 | 189 |
190 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 190 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
191 profile_, this, web_contents, entry.first, std::move(approval), | 191 profile_, this, web_contents, entry.first, std::move(approval), |
192 WebstoreInstaller::INSTALL_SOURCE_OTHER); | 192 WebstoreInstaller::INSTALL_SOURCE_OTHER); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 ShowPrompt(); | 254 ShowPrompt(); |
255 } | 255 } |
256 | 256 |
257 void BundleInstaller::ShowPrompt() { | 257 void BundleInstaller::ShowPrompt() { |
258 // Abort if we couldn't create any Extensions out of the manifests. | 258 // Abort if we couldn't create any Extensions out of the manifests. |
259 if (dummy_extensions_.empty()) { | 259 if (dummy_extensions_.empty()) { |
260 approval_callback_.Run(APPROVAL_ERROR); | 260 approval_callback_.Run(APPROVAL_ERROR); |
261 return; | 261 return; |
262 } | 262 } |
263 | 263 |
264 scoped_ptr<const PermissionSet> permissions; | 264 std::unique_ptr<const PermissionSet> permissions; |
265 PermissionSet empty; | 265 PermissionSet empty; |
266 for (size_t i = 0; i < dummy_extensions_.size(); ++i) { | 266 for (size_t i = 0; i < dummy_extensions_.size(); ++i) { |
267 // Using "permissions ? *permissions : PermissionSet()" tries to do a copy, | 267 // Using "permissions ? *permissions : PermissionSet()" tries to do a copy, |
268 // and doesn't compile. Use a more verbose, but compilable, workaround. | 268 // and doesn't compile. Use a more verbose, but compilable, workaround. |
269 permissions = PermissionSet::CreateUnion( | 269 permissions = PermissionSet::CreateUnion( |
270 permissions ? *permissions : empty, | 270 permissions ? *permissions : empty, |
271 dummy_extensions_[i]->permissions_data()->active_permissions()); | 271 dummy_extensions_[i]->permissions_data()->active_permissions()); |
272 } | 272 } |
273 | 273 |
274 if (g_auto_approve_for_test == PROCEED) { | 274 if (g_auto_approve_for_test == PROCEED) { |
275 OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED); | 275 OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED); |
276 } else if (g_auto_approve_for_test == ABORT) { | 276 } else if (g_auto_approve_for_test == ABORT) { |
277 OnInstallPromptDone(ExtensionInstallPrompt::Result::USER_CANCELED); | 277 OnInstallPromptDone(ExtensionInstallPrompt::Result::USER_CANCELED); |
278 } else { | 278 } else { |
279 Browser* browser = browser_; | 279 Browser* browser = browser_; |
280 if (!browser) { | 280 if (!browser) { |
281 // The browser that we got initially could have gone away during our | 281 // The browser that we got initially could have gone away during our |
282 // thread hopping. | 282 // thread hopping. |
283 browser = chrome::FindLastActiveWithProfile(profile_); | 283 browser = chrome::FindLastActiveWithProfile(profile_); |
284 } | 284 } |
285 content::WebContents* web_contents = NULL; | 285 content::WebContents* web_contents = NULL; |
286 if (browser) | 286 if (browser) |
287 web_contents = browser->tab_strip_model()->GetActiveWebContents(); | 287 web_contents = browser->tab_strip_model()->GetActiveWebContents(); |
288 install_ui_.reset(new ExtensionInstallPrompt(web_contents)); | 288 install_ui_.reset(new ExtensionInstallPrompt(web_contents)); |
289 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt; | 289 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt; |
290 if (delegated_username_.empty()) { | 290 if (delegated_username_.empty()) { |
291 prompt.reset(new ExtensionInstallPrompt::Prompt( | 291 prompt.reset(new ExtensionInstallPrompt::Prompt( |
292 ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT)); | 292 ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT)); |
293 } else { | 293 } else { |
294 prompt.reset(new ExtensionInstallPrompt::Prompt( | 294 prompt.reset(new ExtensionInstallPrompt::Prompt( |
295 ExtensionInstallPrompt::DELEGATED_BUNDLE_PERMISSIONS_PROMPT)); | 295 ExtensionInstallPrompt::DELEGATED_BUNDLE_PERMISSIONS_PROMPT)); |
296 prompt->set_delegated_username(delegated_username_); | 296 prompt->set_delegated_username(delegated_username_); |
297 } | 297 } |
298 prompt->set_bundle(this); | 298 prompt->set_bundle(this); |
299 install_ui_->ShowDialog( | 299 install_ui_->ShowDialog( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 375 |
376 ShowInstalledBubbleIfDone(); | 376 ShowInstalledBubbleIfDone(); |
377 } | 377 } |
378 | 378 |
379 void BundleInstaller::OnBrowserRemoved(Browser* browser) { | 379 void BundleInstaller::OnBrowserRemoved(Browser* browser) { |
380 if (browser_ == browser) | 380 if (browser_ == browser) |
381 browser_ = nullptr; | 381 browser_ = nullptr; |
382 } | 382 } |
383 | 383 |
384 } // namespace extensions | 384 } // namespace extensions |
OLD | NEW |