Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: chrome/browser/ui/extensions/extension_install_ui_default.cc

Issue 634313004: Display dialog when app install succeeds / fails on Athena (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ui/extensions/extension_install_ui_default.h" 5 #include "chrome/browser/ui/extensions/extension_install_ui_default.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/extension_install_prompt.h"
11 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" 10 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h"
12 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/prefs/incognito_mode_prefs.h" 12 #include "chrome/browser/prefs/incognito_mode_prefs.h"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/themes/theme_service.h" 14 #include "chrome/browser/themes/theme_service.h"
16 #include "chrome/browser/themes/theme_service_factory.h" 15 #include "chrome/browser/themes/theme_service_factory.h"
17 #include "chrome/browser/ui/app_list/app_list_service.h" 16 #include "chrome/browser/ui/app_list/app_list_service.h"
18 #include "chrome/browser/ui/app_list/app_list_util.h" 17 #include "chrome/browser/ui/app_list/app_list_util.h"
19 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_dialogs.h" 19 #include "chrome/browser/ui/browser_dialogs.h"
21 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
23 #include "chrome/browser/ui/browser_tabstrip.h" 22 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/host_desktop.h" 24 #include "chrome/browser/ui/host_desktop.h"
26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 25 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
27 #include "chrome/browser/ui/simple_message_box.h" 26 #include "chrome/browser/ui/simple_message_box.h"
28 #include "chrome/browser/ui/singleton_tabs.h" 27 #include "chrome/browser/ui/singleton_tabs.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
31 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
32 #include "components/infobars/core/confirm_infobar_delegate.h" 31 #include "components/infobars/core/confirm_infobar_delegate.h"
33 #include "components/infobars/core/infobar.h" 32 #include "components/infobars/core/infobar.h"
34 #include "components/search/search.h" 33 #include "components/search/search.h"
35 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
37 #include "extensions/browser/install/crx_installer_error.h"
38 #include "extensions/common/extension.h" 38 #include "extensions/common/extension.h"
39 #include "grit/components_strings.h" 39 #include "grit/components_strings.h"
40 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 41
42 #if defined(USE_ASH) 42 #if defined(USE_ASH)
43 #include "ash/shell.h" 43 #include "ash/shell.h"
44 #endif 44 #endif
45 45
46 using content::BrowserThread; 46 using content::BrowserThread;
47 using content::WebContents; 47 using content::WebContents;
48 using extensions::Extension; 48 using extensions::Extension;
49 49
50 namespace { 50 namespace {
51 51
52 // Helpers --------------------------------------------------------------------
53
54 Browser* FindOrCreateVisibleBrowser(Profile* profile) { 52 Browser* FindOrCreateVisibleBrowser(Profile* profile) {
55 // TODO(mpcomplete): remove this workaround for http://crbug.com/244246 53 // TODO(mpcomplete): remove this workaround for http://crbug.com/244246
56 // after fixing http://crbug.com/38676. 54 // after fixing http://crbug.com/38676.
57 if (!IncognitoModePrefs::CanOpenBrowser(profile)) 55 if (!IncognitoModePrefs::CanOpenBrowser(profile))
58 return NULL; 56 return NULL;
59 chrome::ScopedTabbedBrowserDisplayer displayer( 57 chrome::ScopedTabbedBrowserDisplayer displayer(
60 profile, chrome::GetActiveDesktop()); 58 profile, chrome::GetActiveDesktop());
61 Browser* browser = displayer.browser(); 59 Browser* browser = displayer.browser();
62 if (browser->tab_strip_model()->count() == 0) 60 if (browser->tab_strip_model()->count() == 0)
63 chrome::AddTabAt(browser, GURL(), -1, true); 61 chrome::AddTabAt(browser, GURL(), -1, true);
64 return browser; 62 return browser;
65 } 63 }
66 64
67 void ShowExtensionInstalledBubble(const extensions::Extension* extension, 65 void ShowExtensionInstalledBubble(const extensions::Extension* extension,
68 Profile* profile, 66 Profile* profile,
69 const SkBitmap& icon) { 67 const SkBitmap& icon) {
70 Browser* browser = FindOrCreateVisibleBrowser(profile); 68 Browser* browser = FindOrCreateVisibleBrowser(profile);
71 if (browser) 69 if (browser)
72 chrome::ShowExtensionInstalledBubble(extension, browser, icon); 70 chrome::ShowExtensionInstalledBubble(extension, browser, icon);
73 } 71 }
74 72
75
76 // ErrorInfoBarDelegate -------------------------------------------------------
77
78 // Helper class to put up an infobar when installation fails. 73 // Helper class to put up an infobar when installation fails.
79 class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { 74 class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate {
80 public: 75 public:
81 // Creates an error infobar and delegate and adds the infobar to 76 // Creates an error infobar and delegate and adds the infobar to
82 // |infobar_service|. 77 // |infobar_service|.
83 static void Create(InfoBarService* infobar_service, 78 static void Create(InfoBarService* infobar_service,
84 const extensions::CrxInstallerError& error); 79 const extensions::CrxInstallerError& error);
85 80
86 private: 81 private:
87 explicit ErrorInfoBarDelegate(const extensions::CrxInstallerError& error); 82 explicit ErrorInfoBarDelegate(const extensions::CrxInstallerError& error);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 content::OpenURLParams( 127 content::OpenURLParams(
133 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), 128 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"),
134 content::Referrer(), 129 content::Referrer(),
135 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 130 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
136 ui::PAGE_TRANSITION_LINK, false)); 131 ui::PAGE_TRANSITION_LINK, false));
137 return false; 132 return false;
138 } 133 }
139 134
140 } // namespace 135 } // namespace
141 136
142 137 ExtensionInstallUIDefault::ExtensionInstallUIDefault(
143 // ExtensionInstallUI --------------------------------------------------------- 138 content::BrowserContext* context)
144 139 : profile_(Profile::FromBrowserContext(context)),
145 // static
146 ExtensionInstallUI* ExtensionInstallUI::Create(Profile* profile) {
147 return new ExtensionInstallUIDefault(profile);
148 }
149
150 // static
151 void ExtensionInstallUI::OpenAppInstalledUI(Profile* profile,
152 const std::string& app_id) {
153 #if defined(OS_CHROMEOS)
154 // App Launcher always enabled on ChromeOS, so always handled in
155 // OnInstallSuccess.
156 NOTREACHED();
157 #else
158 Browser* browser = FindOrCreateVisibleBrowser(profile);
159 if (browser) {
160 GURL url(chrome::IsInstantExtendedAPIEnabled() ?
161 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
162 chrome::NavigateParams params(
163 chrome::GetSingletonTabNavigateParams(browser, url));
164 chrome::Navigate(&params);
165
166 content::NotificationService::current()->Notify(
167 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
168 content::Source<WebContents>(params.target_contents),
169 content::Details<const std::string>(&app_id));
170 }
171 #endif
172 }
173
174 // static
175 ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithBrowser(
176 Browser* browser) {
177 content::WebContents* web_contents = NULL;
178 if (browser)
179 web_contents = browser->tab_strip_model()->GetActiveWebContents();
180 return new ExtensionInstallPrompt(web_contents);
181 }
182
183 // static
184 ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithProfile(
185 Profile* profile) {
186 Browser* browser = chrome::FindLastActiveWithProfile(profile,
187 chrome::GetActiveDesktop());
188 if (browser)
189 return CreateInstallPromptWithBrowser(browser);
190 // No browser window is open yet. Create a free-standing dialog associated
191 // with |profile|.
192 return new ExtensionInstallPrompt(profile, NULL, NULL);
193 }
194
195
196 // ExtensionInstallUIDefault --------------------------------------------------
197
198 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile)
199 : ExtensionInstallUI(profile),
200 previous_using_system_theme_(false), 140 previous_using_system_theme_(false),
201 use_app_installed_bubble_(false) { 141 use_app_installed_bubble_(false) {
202 // |profile| can be NULL during tests. 142 // |profile| can be NULL during tests.
203 if (profile) { 143 if (profile_) {
204 // Remember the current theme in case the user presses undo. 144 // Remember the current theme in case the user presses undo.
205 const Extension* previous_theme = 145 const Extension* previous_theme =
206 ThemeServiceFactory::GetThemeForProfile(profile); 146 ThemeServiceFactory::GetThemeForProfile(profile_);
207 if (previous_theme) 147 if (previous_theme)
208 previous_theme_id_ = previous_theme->id(); 148 previous_theme_id_ = previous_theme->id();
209 previous_using_system_theme_ = 149 previous_using_system_theme_ =
210 ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme(); 150 ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme();
211 } 151 }
212 } 152 }
213 153
214 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {} 154 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {}
215 155
216 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension, 156 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension,
217 const SkBitmap* icon) { 157 const SkBitmap* icon) {
218 if (skip_post_install_ui()) 158 if (skip_post_install_ui_)
219 return; 159 return;
220 160
221 if (!profile()) { 161 if (!profile_) {
222 // TODO(zelidrag): Figure out what exact conditions cause crash 162 // TODO(zelidrag): Figure out what exact conditions cause crash
223 // http://crbug.com/159437 and write browser test to cover it. 163 // http://crbug.com/159437 and write browser test to cover it.
224 NOTREACHED(); 164 NOTREACHED();
225 return; 165 return;
226 } 166 }
227 167
228 if (extension->is_theme()) { 168 if (extension->is_theme()) {
229 ThemeInstalledInfoBarDelegate::Create( 169 ThemeInstalledInfoBarDelegate::Create(
230 extension, profile(), previous_theme_id_, previous_using_system_theme_); 170 extension, profile_, previous_theme_id_, previous_using_system_theme_);
231 return; 171 return;
232 } 172 }
233 173
234 // Extensions aren't enabled by default in incognito so we confirm 174 // Extensions aren't enabled by default in incognito so we confirm
235 // the install in a normal window. 175 // the install in a normal window.
236 Profile* current_profile = profile()->GetOriginalProfile(); 176 Profile* current_profile = profile_->GetOriginalProfile();
237 if (extension->is_app()) { 177 if (extension->is_app()) {
238 bool use_bubble = false; 178 bool use_bubble = false;
239 179
240 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 180 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
241 use_bubble = use_app_installed_bubble_; 181 use_bubble = use_app_installed_bubble_;
242 #endif 182 #endif
243 183
244 if (IsAppLauncherEnabled()) { 184 if (IsAppLauncherEnabled()) {
245 // TODO(tapted): ExtensionInstallUI should retain the desktop type from 185 // TODO(tapted): ExtensionInstallUI should retain the desktop type from
246 // the browser used to initiate the flow. http://crbug.com/308360. 186 // the browser used to initiate the flow. http://crbug.com/308360.
247 AppListService::Get(chrome::GetActiveDesktop()) 187 AppListService::Get(chrome::GetActiveDesktop())
248 ->ShowForAppInstall(current_profile, extension->id(), false); 188 ->ShowForAppInstall(current_profile, extension->id(), false);
249 return; 189 return;
250 } 190 }
251 191
252 if (use_bubble) { 192 if (use_bubble) {
253 ShowExtensionInstalledBubble(extension, current_profile, *icon); 193 ShowExtensionInstalledBubble(extension, current_profile, *icon);
254 return; 194 return;
255 } 195 }
256 196
257 ExtensionInstallUI::OpenAppInstalledUI(current_profile, extension->id()); 197 OpenAppInstalledUI(extension->id());
258 return; 198 return;
259 } 199 }
260 200
261 ShowExtensionInstalledBubble(extension, current_profile, *icon); 201 ShowExtensionInstalledBubble(extension, current_profile, *icon);
262 } 202 }
263 203
264 void ExtensionInstallUIDefault::OnInstallFailure( 204 void ExtensionInstallUIDefault::OnInstallFailure(
265 const extensions::CrxInstallerError& error) { 205 const extensions::CrxInstallerError& error) {
266 DCHECK_CURRENTLY_ON(BrowserThread::UI); 206 DCHECK_CURRENTLY_ON(BrowserThread::UI);
267 if (disable_failure_ui_for_tests() || skip_post_install_ui()) 207 if (disable_failure_ui_for_tests() || skip_post_install_ui_)
268 return; 208 return;
269 209
270 Browser* browser = 210 Browser* browser =
271 chrome::FindLastActiveWithProfile(profile(), chrome::GetActiveDesktop()); 211 chrome::FindLastActiveWithProfile(profile_, chrome::GetActiveDesktop());
272 if (!browser) // Can be NULL in unittests. 212 if (!browser) // Can be NULL in unittests.
273 return; 213 return;
274 WebContents* web_contents = 214 WebContents* web_contents =
275 browser->tab_strip_model()->GetActiveWebContents(); 215 browser->tab_strip_model()->GetActiveWebContents();
276 if (!web_contents) 216 if (!web_contents)
277 return; 217 return;
278 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents), 218 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents),
279 error); 219 error);
280 } 220 }
281 221
222 void ExtensionInstallUIDefault::OpenAppInstalledUI(const std::string& app_id) {
223 #if defined(OS_CHROMEOS)
224 // App Launcher always enabled on ChromeOS, so always handled in
225 // OnInstallSuccess.
226 NOTREACHED();
227 #else
228 Profile* current_profile = profile_->GetOriginalProfile();
229 Browser* browser = FindOrCreateVisibleBrowser(current_profile);
230 if (browser) {
231 GURL url(chrome::IsInstantExtendedAPIEnabled() ?
232 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
233 chrome::NavigateParams params(
234 chrome::GetSingletonTabNavigateParams(browser, url));
235 chrome::Navigate(&params);
236
237 content::NotificationService::current()->Notify(
238 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
239 content::Source<WebContents>(params.target_contents),
240 content::Details<const std::string>(&app_id));
241 }
242 #endif
243 }
244
282 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { 245 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) {
283 use_app_installed_bubble_ = use_bubble; 246 use_app_installed_bubble_ = use_bubble;
284 } 247 }
248
249 void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) {
250 skip_post_install_ui_ = skip_ui;
251 }
252
253 gfx::NativeWindow ExtensionInstallUIDefault::GetDefaultInstallDialogParent() {
254 Browser* browser = chrome::FindLastActiveWithProfile(profile_,
255 chrome::GetActiveDesktop());
256 if (browser) {
257 content::WebContents* contents =
258 browser->tab_strip_model()->GetActiveWebContents();
259 return contents->GetTopLevelNativeWindow();
260 }
261 return NULL;
262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698