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

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;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 content::OpenURLParams( 132 content::OpenURLParams(
133 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), 133 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"),
134 content::Referrer(), 134 content::Referrer(),
135 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 135 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
136 ui::PAGE_TRANSITION_LINK, false)); 136 ui::PAGE_TRANSITION_LINK, false));
137 return false; 137 return false;
138 } 138 }
139 139
140 } // namespace 140 } // namespace
141 141
142
143 // ExtensionInstallUI ---------------------------------------------------------
144
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 -------------------------------------------------- 142 // ExtensionInstallUIDefault --------------------------------------------------
Ken Rockot(use gerrit already) 2014/10/14 22:18:58 totally optional nit: Could you remove this and ot
197 143
198 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile) 144 ExtensionInstallUIDefault::ExtensionInstallUIDefault(
199 : ExtensionInstallUI(profile), 145 content::BrowserContext* context)
146 : profile_(Profile::FromBrowserContext(context)),
200 previous_using_system_theme_(false), 147 previous_using_system_theme_(false),
201 use_app_installed_bubble_(false) { 148 use_app_installed_bubble_(false) {
202 // |profile| can be NULL during tests. 149 // |profile| can be NULL during tests.
203 if (profile) { 150 if (profile_) {
204 // Remember the current theme in case the user presses undo. 151 // Remember the current theme in case the user presses undo.
205 const Extension* previous_theme = 152 const Extension* previous_theme =
206 ThemeServiceFactory::GetThemeForProfile(profile); 153 ThemeServiceFactory::GetThemeForProfile(profile_);
207 if (previous_theme) 154 if (previous_theme)
208 previous_theme_id_ = previous_theme->id(); 155 previous_theme_id_ = previous_theme->id();
209 previous_using_system_theme_ = 156 previous_using_system_theme_ =
210 ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme(); 157 ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme();
211 } 158 }
212 } 159 }
213 160
214 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {} 161 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {}
215 162
216 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension, 163 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension,
217 const SkBitmap* icon) { 164 const SkBitmap* icon) {
218 if (skip_post_install_ui()) 165 if (skip_post_install_ui_)
219 return; 166 return;
220 167
221 if (!profile()) { 168 if (!profile_) {
222 // TODO(zelidrag): Figure out what exact conditions cause crash 169 // TODO(zelidrag): Figure out what exact conditions cause crash
223 // http://crbug.com/159437 and write browser test to cover it. 170 // http://crbug.com/159437 and write browser test to cover it.
224 NOTREACHED(); 171 NOTREACHED();
225 return; 172 return;
226 } 173 }
227 174
228 if (extension->is_theme()) { 175 if (extension->is_theme()) {
229 ThemeInstalledInfoBarDelegate::Create( 176 ThemeInstalledInfoBarDelegate::Create(
230 extension, profile(), previous_theme_id_, previous_using_system_theme_); 177 extension, profile_, previous_theme_id_, previous_using_system_theme_);
231 return; 178 return;
232 } 179 }
233 180
234 // Extensions aren't enabled by default in incognito so we confirm 181 // Extensions aren't enabled by default in incognito so we confirm
235 // the install in a normal window. 182 // the install in a normal window.
236 Profile* current_profile = profile()->GetOriginalProfile(); 183 Profile* current_profile = profile_->GetOriginalProfile();
237 if (extension->is_app()) { 184 if (extension->is_app()) {
238 bool use_bubble = false; 185 bool use_bubble = false;
239 186
240 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 187 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
241 use_bubble = use_app_installed_bubble_; 188 use_bubble = use_app_installed_bubble_;
242 #endif 189 #endif
243 190
244 if (IsAppLauncherEnabled()) { 191 if (IsAppLauncherEnabled()) {
245 // TODO(tapted): ExtensionInstallUI should retain the desktop type from 192 // TODO(tapted): ExtensionInstallUI should retain the desktop type from
246 // the browser used to initiate the flow. http://crbug.com/308360. 193 // the browser used to initiate the flow. http://crbug.com/308360.
247 AppListService::Get(chrome::GetActiveDesktop()) 194 AppListService::Get(chrome::GetActiveDesktop())
248 ->ShowForAppInstall(current_profile, extension->id(), false); 195 ->ShowForAppInstall(current_profile, extension->id(), false);
249 return; 196 return;
250 } 197 }
251 198
252 if (use_bubble) { 199 if (use_bubble) {
253 ShowExtensionInstalledBubble(extension, current_profile, *icon); 200 ShowExtensionInstalledBubble(extension, current_profile, *icon);
254 return; 201 return;
255 } 202 }
256 203
257 ExtensionInstallUI::OpenAppInstalledUI(current_profile, extension->id()); 204 OpenAppInstalledUI(extension->id());
258 return; 205 return;
259 } 206 }
260 207
261 ShowExtensionInstalledBubble(extension, current_profile, *icon); 208 ShowExtensionInstalledBubble(extension, current_profile, *icon);
262 } 209 }
263 210
264 void ExtensionInstallUIDefault::OnInstallFailure( 211 void ExtensionInstallUIDefault::OnInstallFailure(
265 const extensions::CrxInstallerError& error) { 212 const extensions::CrxInstallerError& error) {
266 DCHECK_CURRENTLY_ON(BrowserThread::UI); 213 DCHECK_CURRENTLY_ON(BrowserThread::UI);
267 if (disable_failure_ui_for_tests() || skip_post_install_ui()) 214 if (disable_failure_ui_for_tests() || skip_post_install_ui_)
268 return; 215 return;
269 216
270 Browser* browser = 217 Browser* browser =
271 chrome::FindLastActiveWithProfile(profile(), chrome::GetActiveDesktop()); 218 chrome::FindLastActiveWithProfile(profile_, chrome::GetActiveDesktop());
272 if (!browser) // Can be NULL in unittests. 219 if (!browser) // Can be NULL in unittests.
273 return; 220 return;
274 WebContents* web_contents = 221 WebContents* web_contents =
275 browser->tab_strip_model()->GetActiveWebContents(); 222 browser->tab_strip_model()->GetActiveWebContents();
276 if (!web_contents) 223 if (!web_contents)
277 return; 224 return;
278 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents), 225 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents),
279 error); 226 error);
280 } 227 }
281 228
229 void ExtensionInstallUIDefault::OpenAppInstalledUI(const std::string& app_id) {
230 #if defined(OS_CHROMEOS)
231 // App Launcher always enabled on ChromeOS, so always handled in
232 // OnInstallSuccess.
233 NOTREACHED();
234 #else
235 Profile* current_profile = profile_->GetOriginalProfile();
236 Browser* browser = FindOrCreateVisibleBrowser(current_profile);
237 if (browser) {
238 GURL url(chrome::IsInstantExtendedAPIEnabled() ?
239 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
240 chrome::NavigateParams params(
241 chrome::GetSingletonTabNavigateParams(browser, url));
242 chrome::Navigate(&params);
243
244 content::NotificationService::current()->Notify(
245 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
246 content::Source<WebContents>(params.target_contents),
247 content::Details<const std::string>(&app_id));
248 }
249 #endif
250 }
251
282 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { 252 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) {
283 use_app_installed_bubble_ = use_bubble; 253 use_app_installed_bubble_ = use_bubble;
284 } 254 }
255
256 void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) {
257 skip_post_install_ui_ = skip_ui;
258 }
259
260 gfx::NativeWindow ExtensionInstallUIDefault::GetDefaultInstallDialogParent() {
261 Browser* browser = chrome::FindLastActiveWithProfile(profile_,
262 chrome::GetActiveDesktop());
263 if (browser) {
264 content::WebContents* contents =
265 browser->tab_strip_model()->GetActiveWebContents();
266 return contents->GetTopLevelNativeWindow();
267 }
268 return NULL;
269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698