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_ui_default.h" | 5 #include "chrome/browser/extensions/extension_install_ui_default.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_install_prompt.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
9 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" | 10 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" |
10 #include "chrome/browser/infobars/infobar_tab_helper.h" | 11 #include "chrome/browser/infobars/infobar_tab_helper.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
12 #include "chrome/browser/themes/theme_service.h" | 14 #include "chrome/browser/themes/theme_service.h" |
13 #include "chrome/browser/themes/theme_service_factory.h" | 15 #include "chrome/browser/themes/theme_service_factory.h" |
14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 17 #include "chrome/browser/ui/browser_dialogs.h" |
16 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
17 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
18 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/simple_message_box.h" | 21 #include "chrome/browser/ui/simple_message_box.h" |
20 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
21 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 23 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
(...skipping 13 matching lines...) Expand all Loading... |
35 #endif | 37 #endif |
36 | 38 |
37 using content::BrowserThread; | 39 using content::BrowserThread; |
38 using content::WebContents; | 40 using content::WebContents; |
39 using extensions::Extension; | 41 using extensions::Extension; |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
43 bool disable_failure_ui_for_tests = false; | 45 bool disable_failure_ui_for_tests = false; |
44 | 46 |
| 47 // Helper class to put up an infobar when installation fails. |
| 48 class ErrorInfobarDelegate : public ConfirmInfoBarDelegate { |
| 49 public: |
| 50 ErrorInfobarDelegate(InfoBarTabHelper* infobar_helper, |
| 51 Browser* browser, |
| 52 const CrxInstallerError& error) |
| 53 : ConfirmInfoBarDelegate(infobar_helper), |
| 54 browser_(browser), |
| 55 error_(error) { |
| 56 } |
| 57 |
| 58 private: |
| 59 virtual string16 GetMessageText() const OVERRIDE { |
| 60 return error_.message(); |
| 61 } |
| 62 |
| 63 virtual int GetButtons() const OVERRIDE { |
| 64 return BUTTON_OK; |
| 65 } |
| 66 |
| 67 virtual string16 GetLinkText() const OVERRIDE { |
| 68 // TODO(aa): Return the learn more link once we have the help article |
| 69 // posted. |
| 70 // return error_.type() == CrxInstallerError::ERROR_OFF_STORE ? |
| 71 // l10n_util::GetStringUTF16(IDS_LEARN_MORE) : ASCIIToUTF16(""); |
| 72 return ASCIIToUTF16(""); |
| 73 } |
| 74 |
| 75 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE { |
| 76 browser::NavigateParams params(browser_, |
| 77 GURL("http://www.google.com/"), |
| 78 content::PAGE_TRANSITION_LINK); |
| 79 params.disposition = NEW_FOREGROUND_TAB; |
| 80 browser::Navigate(¶ms); |
| 81 return false; |
| 82 } |
| 83 |
| 84 Browser* browser_; |
| 85 CrxInstallerError error_; |
| 86 }; |
| 87 |
45 } // namespace | 88 } // namespace |
46 | 89 |
47 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Browser* browser) | 90 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Browser* browser) |
48 : browser_(browser), | 91 : browser_(browser), |
49 skip_post_install_ui_(false), | 92 skip_post_install_ui_(false), |
50 previous_using_native_theme_(false), | 93 previous_using_native_theme_(false), |
51 use_app_installed_bubble_(false) { | 94 use_app_installed_bubble_(false) { |
52 // Remember the current theme in case the user presses undo. | 95 // Remember the current theme in case the user presses undo. |
53 if (browser) { | 96 if (browser) { |
54 Profile* profile = browser->profile(); | 97 Profile* profile = browser->profile(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 136 |
94 if (extension->is_app() && !use_bubble_for_apps) { | 137 if (extension->is_app() && !use_bubble_for_apps) { |
95 ExtensionInstallUI::OpenAppInstalledUI(browser, extension->id()); | 138 ExtensionInstallUI::OpenAppInstalledUI(browser, extension->id()); |
96 return; | 139 return; |
97 } | 140 } |
98 | 141 |
99 browser::ShowExtensionInstalledBubble(extension, browser, *icon, | 142 browser::ShowExtensionInstalledBubble(extension, browser, *icon, |
100 current_profile); | 143 current_profile); |
101 } | 144 } |
102 | 145 |
103 void ExtensionInstallUIDefault::OnInstallFailure(const string16& error) { | 146 void ExtensionInstallUIDefault::OnInstallFailure( |
| 147 const CrxInstallerError& error) { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
105 if (disable_failure_ui_for_tests || skip_post_install_ui_) | 149 if (disable_failure_ui_for_tests || skip_post_install_ui_) |
106 return; | 150 return; |
107 | 151 |
108 Browser* browser = browser::FindLastActiveWithProfile(browser_->profile()); | 152 Browser* browser = browser::FindLastActiveWithProfile(browser_->profile()); |
109 browser::ShowMessageBox(browser ? browser->window()->GetNativeWindow() : NULL, | 153 TabContents* tab_contents = browser->GetActiveTabContents(); |
110 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_FAILURE_TITLE), error, | 154 if (!tab_contents) |
111 browser::MESSAGE_BOX_TYPE_WARNING); | 155 return; |
| 156 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
| 157 infobar_helper->AddInfoBar( |
| 158 new ErrorInfobarDelegate(infobar_helper, browser, error)); |
112 } | 159 } |
113 | 160 |
114 void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) { | 161 void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) { |
115 skip_post_install_ui_ = skip_ui; | 162 skip_post_install_ui_ = skip_ui; |
116 } | 163 } |
117 | 164 |
118 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { | 165 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { |
119 use_app_installed_bubble_ = use_bubble; | 166 use_app_installed_bubble_ = use_bubble; |
120 } | 167 } |
121 | 168 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 #else | 253 #else |
207 NOTREACHED(); | 254 NOTREACHED(); |
208 #endif | 255 #endif |
209 } | 256 } |
210 } | 257 } |
211 | 258 |
212 // static | 259 // static |
213 void ExtensionInstallUI::DisableFailureUIForTests() { | 260 void ExtensionInstallUI::DisableFailureUIForTests() { |
214 disable_failure_ui_for_tests = true; | 261 disable_failure_ui_for_tests = true; |
215 } | 262 } |
OLD | NEW |