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/extension_install_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
17 #include "chrome/browser/extensions/extension_install_dialog.h" | |
18 #include "chrome/browser/extensions/extension_install_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/signin/token_service.h" | 20 #include "chrome/browser/signin/token_service.h" |
22 #include "chrome/browser/signin/token_service_factory.h" | 21 #include "chrome/browser/signin/token_service_factory.h" |
23 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 std::vector<ui::ScaleFactor> supported_scale_factors = | 112 std::vector<ui::ScaleFactor> supported_scale_factors = |
114 ui::GetSupportedScaleFactors(); | 113 ui::GetSupportedScaleFactors(); |
115 // Scale factors are in ascending order, so the last one is the one we need. | 114 // Scale factors are in ascending order, so the last one is the one we need. |
116 ui::ScaleFactor max_scale_factor = | 115 ui::ScaleFactor max_scale_factor = |
117 supported_scale_factors[supported_scale_factors.size() - 1]; | 116 supported_scale_factors[supported_scale_factors.size() - 1]; |
118 | 117 |
119 return Extension::GetDefaultIcon(is_app). | 118 return Extension::GetDefaultIcon(is_app). |
120 GetRepresentation(max_scale_factor).sk_bitmap(); | 119 GetRepresentation(max_scale_factor).sk_bitmap(); |
121 } | 120 } |
122 | 121 |
122 // If auto confirm is enabled then posts a task to proceed with or cancel the in stall | |
123 // and returns true. Otherwise returns false. | |
124 bool DoAutoConfirm(ExtensionInstallPrompt::Delegate* delegate) { | |
125 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
126 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | |
127 return false; | |
128 std::string value = cmdline->GetSwitchValueASCII( | |
129 switches::kAppsGalleryInstallAutoConfirmForTests); | |
130 | |
131 // We use PostTask instead of calling the delegate directly here, because in | |
132 // the real implementations it's highly likely the message loop will be | |
133 // pumping a few times before the user clicks accept or cancel. | |
134 if (value == "accept") { | |
135 MessageLoop::current()->PostTask( | |
136 FROM_HERE, base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProc eed, | |
Aaron Boodman
2012/10/11 21:44:47
Weird indent.
Aaron Boodman
2012/10/11 21:44:47
80 cols
sail
2012/10/11 21:49:38
Done.
sail
2012/10/11 21:49:38
Done.
| |
137 base::Unretained(delegate))); | |
138 return true; | |
139 } | |
140 | |
141 if (value == "cancel") { | |
142 MessageLoop::current()->PostTask( | |
Aaron Boodman
2012/10/11 21:44:47
ditto
sail
2012/10/11 21:49:38
Done.
| |
143 FROM_HERE, base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbor t, | |
144 base::Unretained(delegate), | |
145 true)); | |
146 return true; | |
147 } | |
148 | |
149 NOTREACHED(); | |
150 return false; | |
151 } | |
152 | |
123 } // namespace | 153 } // namespace |
124 | 154 |
125 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) | 155 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) |
126 : type_(type), | 156 : type_(type), |
127 extension_(NULL), | 157 extension_(NULL), |
128 bundle_(NULL), | 158 bundle_(NULL), |
129 average_rating_(0.0), | 159 average_rating_(0.0), |
130 rating_count_(0), | 160 rating_count_(0), |
131 profile_(profile) { | 161 profile_(profile) { |
132 } | 162 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 extension_ = extension; | 371 extension_ = extension; |
342 permissions_ = extension->GetActivePermissions(); | 372 permissions_ = extension->GetActivePermissions(); |
343 delegate_ = delegate; | 373 delegate_ = delegate; |
344 prompt_ = prompt; | 374 prompt_ = prompt; |
345 prompt_type_ = prompt.type(); | 375 prompt_type_ = prompt.type(); |
346 | 376 |
347 SetIcon(icon); | 377 SetIcon(icon); |
348 FetchOAuthIssueAdviceIfNeeded(); | 378 FetchOAuthIssueAdviceIfNeeded(); |
349 } | 379 } |
350 | 380 |
351 void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate, | 381 void ExtensionInstallPrompt::ConfirmWebstoreInstall( |
352 const Extension* extension, | 382 Delegate* delegate, |
353 const SkBitmap* icon) { | 383 const Extension* extension, |
384 const SkBitmap* icon, | |
385 const ShowDialogCallback& show_dialog_callback) { | |
354 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the | 386 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
355 // remaining fields. | 387 // remaining fields. |
356 extension_ = extension; | 388 extension_ = extension; |
357 SetIcon(icon); | 389 SetIcon(icon); |
358 ConfirmInstall(delegate, extension); | 390 ConfirmInstall(delegate, extension, show_dialog_callback); |
359 } | 391 } |
360 | 392 |
361 void ExtensionInstallPrompt::ConfirmInstall(Delegate* delegate, | 393 void ExtensionInstallPrompt::ConfirmInstall( |
362 const Extension* extension) { | 394 Delegate* delegate, |
395 const Extension* extension, | |
396 const ShowDialogCallback& show_dialog_callback) { | |
363 DCHECK(ui_loop_ == MessageLoop::current()); | 397 DCHECK(ui_loop_ == MessageLoop::current()); |
364 extension_ = extension; | 398 extension_ = extension; |
365 permissions_ = extension->GetActivePermissions(); | 399 permissions_ = extension->GetActivePermissions(); |
366 delegate_ = delegate; | 400 delegate_ = delegate; |
367 prompt_type_ = INSTALL_PROMPT; | 401 prompt_type_ = INSTALL_PROMPT; |
402 show_dialog_callback_ = show_dialog_callback; | |
403 DCHECK(!show_dialog_callback_.is_null()); | |
368 | 404 |
369 // We special-case themes to not show any confirm UI. Instead they are | 405 // We special-case themes to not show any confirm UI. Instead they are |
370 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 406 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
371 // to allow the user to revert if they don't like it. | 407 // to allow the user to revert if they don't like it. |
372 // | 408 // |
373 // We don't do this in the case where off-store extension installs are | 409 // We don't do this in the case where off-store extension installs are |
374 // disabled because in that case, we don't show the dangerous download UI, so | 410 // disabled because in that case, we don't show the dangerous download UI, so |
375 // we need the UI confirmation. | 411 // we need the UI confirmation. |
376 if (extension->is_theme()) { | 412 if (extension->is_theme()) { |
377 if (extension->from_webstore() || | 413 if (extension->from_webstore() || |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); | 566 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); |
531 } | 567 } |
532 | 568 |
533 switch (prompt_type_) { | 569 switch (prompt_type_) { |
534 case PERMISSIONS_PROMPT: | 570 case PERMISSIONS_PROMPT: |
535 case RE_ENABLE_PROMPT: | 571 case RE_ENABLE_PROMPT: |
536 case INLINE_INSTALL_PROMPT: | 572 case INLINE_INSTALL_PROMPT: |
537 case INSTALL_PROMPT: { | 573 case INSTALL_PROMPT: { |
538 prompt_.set_extension(extension_); | 574 prompt_.set_extension(extension_); |
539 prompt_.set_icon(gfx::Image(icon_)); | 575 prompt_.set_icon(gfx::Image(icon_)); |
540 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_); | |
541 break; | 576 break; |
542 } | 577 } |
543 case BUNDLE_INSTALL_PROMPT: { | 578 case BUNDLE_INSTALL_PROMPT: { |
544 prompt_.set_bundle(bundle_); | 579 prompt_.set_bundle(bundle_); |
545 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_); | |
546 break; | 580 break; |
547 } | 581 } |
548 default: | 582 default: |
549 NOTREACHED() << "Unknown message"; | 583 NOTREACHED() << "Unknown message"; |
550 break; | 584 return; |
551 } | 585 } |
586 | |
Aaron Boodman
2012/10/11 21:44:47
naming: if (AutoConfirmPrompt()) ?
sail
2012/10/11 21:49:55
Done.
| |
587 if (DoAutoConfirm(delegate_)) | |
588 return; | |
589 | |
590 DCHECK(!show_dialog_callback_.is_null()); | |
591 show_dialog_callback_.Run(parent_, navigator_, delegate_, prompt_); | |
552 } | 592 } |
553 | 593 |
554 namespace chrome { | 594 namespace chrome { |
555 | 595 |
556 ExtensionInstallPrompt* CreateExtensionInstallPromptWithBrowser( | 596 ExtensionInstallPrompt* CreateExtensionInstallPromptWithBrowser( |
557 Browser* browser) { | 597 Browser* browser) { |
558 // |browser| can be NULL in unit tests. | 598 // |browser| can be NULL in unit tests. |
559 if (!browser) | 599 if (!browser) |
560 return new ExtensionInstallPrompt(NULL, NULL, NULL); | 600 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
561 gfx::NativeWindow parent = | 601 gfx::NativeWindow parent = |
562 browser->window() ? browser->window()->GetNativeWindow() : NULL; | 602 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
563 return new ExtensionInstallPrompt(parent, browser, browser->profile()); | 603 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
564 } | 604 } |
565 | 605 |
566 } // namespace chrome | 606 } // namespace chrome |
OLD | NEW |