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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/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_prompt_show_params.h" |
17 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
18 #include "chrome/browser/extensions/permissions_updater.h" | 19 #include "chrome/browser/extensions/permissions_updater.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" | 21 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "extensions/browser/extension_prefs.h" | 27 #include "extensions/browser/extension_prefs.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 NOTREACHED(); | 170 NOTREACHED(); |
170 return false; | 171 return false; |
171 } | 172 } |
172 | 173 |
173 Profile* ProfileForWebContents(content::WebContents* web_contents) { | 174 Profile* ProfileForWebContents(content::WebContents* web_contents) { |
174 if (!web_contents) | 175 if (!web_contents) |
175 return NULL; | 176 return NULL; |
176 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 177 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
177 } | 178 } |
178 | 179 |
179 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { | |
180 if (!contents) | |
181 return NULL; | |
182 | |
183 return contents->GetTopLevelNativeWindow(); | |
184 } | |
185 | |
186 } // namespace | 180 } // namespace |
187 | 181 |
188 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: | 182 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
189 InstallPromptPermissions() { | 183 InstallPromptPermissions() { |
190 } | 184 } |
191 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: | 185 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
192 ~InstallPromptPermissions() { | 186 ~InstallPromptPermissions() { |
193 } | 187 } |
194 | 188 |
195 // static | 189 // static |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 PermissionsType permissions_type) const { | 600 PermissionsType permissions_type) const { |
607 DCHECK_NE(ALL_PERMISSIONS, permissions_type); | 601 DCHECK_NE(ALL_PERMISSIONS, permissions_type); |
608 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ | 602 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ |
609 : withheld_prompt_permissions_; | 603 : withheld_prompt_permissions_; |
610 } | 604 } |
611 | 605 |
612 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { | 606 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { |
613 return !retained_files_.empty(); | 607 return !retained_files_.empty(); |
614 } | 608 } |
615 | 609 |
616 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) | |
617 : profile(ProfileForWebContents(contents)), | |
618 parent_web_contents(contents), | |
619 parent_window(NativeWindowForWebContents(contents)) { | |
620 } | |
621 | |
622 ExtensionInstallPrompt::ShowParams::ShowParams(Profile* profile, | |
623 gfx::NativeWindow window) | |
624 : profile(profile), | |
625 parent_web_contents(NULL), | |
626 parent_window(window) { | |
627 } | |
628 | |
629 // static | 610 // static |
630 scoped_refptr<Extension> | 611 scoped_refptr<Extension> |
631 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( | 612 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
632 const base::DictionaryValue* manifest, | 613 const base::DictionaryValue* manifest, |
633 int flags, | 614 int flags, |
634 const std::string& id, | 615 const std::string& id, |
635 const std::string& localized_name, | 616 const std::string& localized_name, |
636 const std::string& localized_description, | 617 const std::string& localized_description, |
637 std::string* error) { | 618 std::string* error) { |
638 scoped_ptr<base::DictionaryValue> localized_manifest; | 619 scoped_ptr<base::DictionaryValue> localized_manifest; |
(...skipping 18 matching lines...) Expand all Loading... |
657 error); | 638 error); |
658 } | 639 } |
659 | 640 |
660 ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) | 641 ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) |
661 : profile_(ProfileForWebContents(contents)), | 642 : profile_(ProfileForWebContents(contents)), |
662 ui_loop_(base::MessageLoop::current()), | 643 ui_loop_(base::MessageLoop::current()), |
663 extension_(NULL), | 644 extension_(NULL), |
664 bundle_(NULL), | 645 bundle_(NULL), |
665 install_ui_(extensions::CreateExtensionInstallUI( | 646 install_ui_(extensions::CreateExtensionInstallUI( |
666 ProfileForWebContents(contents))), | 647 ProfileForWebContents(contents))), |
667 show_params_(contents), | 648 show_params_(new ExtensionInstallPromptShowParams(contents)), |
668 delegate_(NULL) { | 649 delegate_(NULL) { |
669 } | 650 } |
670 | 651 |
671 ExtensionInstallPrompt::ExtensionInstallPrompt(Profile* profile, | 652 ExtensionInstallPrompt::ExtensionInstallPrompt(Profile* profile, |
672 gfx::NativeWindow native_window) | 653 gfx::NativeWindow native_window) |
673 : profile_(profile), | 654 : profile_(profile), |
674 ui_loop_(base::MessageLoop::current()), | 655 ui_loop_(base::MessageLoop::current()), |
675 extension_(NULL), | 656 extension_(NULL), |
676 bundle_(NULL), | 657 bundle_(NULL), |
677 install_ui_(extensions::CreateExtensionInstallUI(profile)), | 658 install_ui_(extensions::CreateExtensionInstallUI(profile)), |
678 show_params_(profile, native_window), | 659 show_params_( |
| 660 new ExtensionInstallPromptShowParams(profile, native_window)), |
679 delegate_(NULL) { | 661 delegate_(NULL) { |
680 } | 662 } |
681 | 663 |
682 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 664 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
683 } | 665 } |
684 | 666 |
685 void ExtensionInstallPrompt::ConfirmBundleInstall( | 667 void ExtensionInstallPrompt::ConfirmBundleInstall( |
686 extensions::BundleInstaller* bundle, | 668 extensions::BundleInstaller* bundle, |
687 const PermissionSet* permissions) { | 669 const PermissionSet* permissions) { |
688 DCHECK(ui_loop_ == base::MessageLoop::current()); | 670 DCHECK(ui_loop_ == base::MessageLoop::current()); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 break; | 920 break; |
939 } | 921 } |
940 default: | 922 default: |
941 NOTREACHED() << "Unknown message"; | 923 NOTREACHED() << "Unknown message"; |
942 return; | 924 return; |
943 } | 925 } |
944 | 926 |
945 if (AutoConfirmPrompt(delegate_)) | 927 if (AutoConfirmPrompt(delegate_)) |
946 return; | 928 return; |
947 | 929 |
| 930 if (show_params_->WasParentDestroyed()) { |
| 931 delegate_->InstallUIAbort(false); |
| 932 return; |
| 933 } |
| 934 |
948 if (show_dialog_callback_.is_null()) | 935 if (show_dialog_callback_.is_null()) |
949 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 936 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); |
950 else | 937 else |
951 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 938 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); |
952 } | 939 } |
OLD | NEW |