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/ui/extensions/application_launch.h" | 5 #include "chrome/browser/ui/extensions/application_launch.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "apps/launcher.h" | 9 #include "apps/launcher.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 15 #include "chrome/browser/extensions/extension_prefs.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
| 18 #include "chrome/browser/extensions/launch_util.h" |
18 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/signin/signin_manager.h" | 21 #include "chrome/browser/signin/signin_manager.h" |
21 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
22 #include "chrome/browser/ui/app_list/app_list_service.h" | 23 #include "chrome/browser/ui/app_list/app_list_service.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
26 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 154 } |
154 | 155 |
155 if (chrome::IsRunningInForcedAppMode()) | 156 if (chrome::IsRunningInForcedAppMode()) |
156 return ui::SHOW_STATE_FULLSCREEN; | 157 return ui::SHOW_STATE_FULLSCREEN; |
157 | 158 |
158 #if defined(USE_ASH) | 159 #if defined(USE_ASH) |
159 // In ash, LAUNCH_FULLSCREEN launches in a maximized app window and | 160 // In ash, LAUNCH_FULLSCREEN launches in a maximized app window and |
160 // LAUNCH_WINDOW launches in a normal app window. | 161 // LAUNCH_WINDOW launches in a normal app window. |
161 ExtensionService* service = | 162 ExtensionService* service = |
162 extensions::ExtensionSystem::Get(profile)->extension_service(); | 163 extensions::ExtensionSystem::Get(profile)->extension_service(); |
163 ExtensionPrefs::LaunchType launch_type = | 164 extensions::LaunchType launch_type = extensions::GetLaunchType( |
164 service->extension_prefs()->GetLaunchType(extension); | 165 service->extension_prefs(), extension); |
165 if (launch_type == ExtensionPrefs::LAUNCH_TYPE_FULLSCREEN) | 166 if (launch_type == extensions::LAUNCH_TYPE_FULLSCREEN) |
166 return ui::SHOW_STATE_MAXIMIZED; | 167 return ui::SHOW_STATE_MAXIMIZED; |
167 else if (launch_type == ExtensionPrefs::LAUNCH_TYPE_WINDOW) | 168 else if (launch_type == extensions::LAUNCH_TYPE_WINDOW) |
168 return ui::SHOW_STATE_NORMAL; | 169 return ui::SHOW_STATE_NORMAL; |
169 #endif | 170 #endif |
170 | 171 |
171 return ui::SHOW_STATE_DEFAULT; | 172 return ui::SHOW_STATE_DEFAULT; |
172 } | 173 } |
173 | 174 |
174 WebContents* OpenApplicationWindow(const AppLaunchParams& params) { | 175 WebContents* OpenApplicationWindow(const AppLaunchParams& params) { |
175 Profile* const profile = params.profile; | 176 Profile* const profile = params.profile; |
176 const extensions::Extension* const extension = params.extension; | 177 const extensions::Extension* const extension = params.extension; |
177 const GURL url_input = params.override_url; | 178 const GURL url_input = params.override_url; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // For existing browser, ensure its window is shown and activated. | 245 // For existing browser, ensure its window is shown and activated. |
245 browser->window()->Show(); | 246 browser->window()->Show(); |
246 browser->window()->Activate(); | 247 browser->window()->Activate(); |
247 } | 248 } |
248 | 249 |
249 // Check the prefs for overridden mode. | 250 // Check the prefs for overridden mode. |
250 ExtensionService* extension_service = | 251 ExtensionService* extension_service = |
251 extensions::ExtensionSystem::Get(profile)->extension_service(); | 252 extensions::ExtensionSystem::Get(profile)->extension_service(); |
252 DCHECK(extension_service); | 253 DCHECK(extension_service); |
253 | 254 |
254 ExtensionPrefs::LaunchType launch_type = | 255 extensions::LaunchType launch_type = extensions::GetLaunchType( |
255 extension_service->extension_prefs()->GetLaunchType(extension); | 256 extension_service->extension_prefs(), extension); |
256 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); | 257 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
257 | 258 |
258 int add_type = TabStripModel::ADD_ACTIVE; | 259 int add_type = TabStripModel::ADD_ACTIVE; |
259 if (launch_type == ExtensionPrefs::LAUNCH_TYPE_PINNED) | 260 if (launch_type == extensions::LAUNCH_TYPE_PINNED) |
260 add_type |= TabStripModel::ADD_PINNED; | 261 add_type |= TabStripModel::ADD_PINNED; |
261 | 262 |
262 GURL extension_url = UrlForExtension(extension, launch_params.override_url); | 263 GURL extension_url = UrlForExtension(extension, launch_params.override_url); |
263 chrome::NavigateParams params(browser, extension_url, | 264 chrome::NavigateParams params(browser, extension_url, |
264 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 265 content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
265 params.tabstrip_add_types = add_type; | 266 params.tabstrip_add_types = add_type; |
266 params.disposition = disposition; | 267 params.disposition = disposition; |
267 | 268 |
268 if (disposition == CURRENT_TAB) { | 269 if (disposition == CURRENT_TAB) { |
269 WebContents* existing_tab = | 270 WebContents* existing_tab = |
(...skipping 21 matching lines...) Expand all Loading... |
291 chrome::Navigate(¶ms); | 292 chrome::Navigate(¶ms); |
292 contents = params.target_contents; | 293 contents = params.target_contents; |
293 } | 294 } |
294 | 295 |
295 // On Chrome OS the host desktop type for a browser window is always set to | 296 // On Chrome OS the host desktop type for a browser window is always set to |
296 // HOST_DESKTOP_TYPE_ASH. On Windows 8 it is only the case for Chrome ASH | 297 // HOST_DESKTOP_TYPE_ASH. On Windows 8 it is only the case for Chrome ASH |
297 // in metro mode. | 298 // in metro mode. |
298 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) { | 299 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) { |
299 // In ash, LAUNCH_FULLSCREEN launches in the OpenApplicationWindow function | 300 // In ash, LAUNCH_FULLSCREEN launches in the OpenApplicationWindow function |
300 // i.e. it should not reach here. | 301 // i.e. it should not reach here. |
301 DCHECK(launch_type != ExtensionPrefs::LAUNCH_TYPE_FULLSCREEN); | 302 DCHECK(launch_type != extensions::LAUNCH_TYPE_FULLSCREEN); |
302 } else { | 303 } else { |
303 // TODO(skerner): If we are already in full screen mode, and the user | 304 // TODO(skerner): If we are already in full screen mode, and the user |
304 // set the app to open as a regular or pinned tab, what should happen? | 305 // set the app to open as a regular or pinned tab, what should happen? |
305 // Today we open the tab, but stay in full screen mode. Should we leave | 306 // Today we open the tab, but stay in full screen mode. Should we leave |
306 // full screen mode in this case? | 307 // full screen mode in this case? |
307 if (launch_type == ExtensionPrefs::LAUNCH_TYPE_FULLSCREEN && | 308 if (launch_type == extensions::LAUNCH_TYPE_FULLSCREEN && |
308 !browser->window()->IsFullscreen()) { | 309 !browser->window()->IsFullscreen()) { |
309 #if defined(OS_MACOSX) | 310 #if defined(OS_MACOSX) |
310 chrome::ToggleFullscreenWithChromeOrFallback(browser); | 311 chrome::ToggleFullscreenWithChromeOrFallback(browser); |
311 #else | 312 #else |
312 chrome::ToggleFullscreenMode(browser); | 313 chrome::ToggleFullscreenMode(browser); |
313 #endif | 314 #endif |
314 } | 315 } |
315 } | 316 } |
316 return contents; | 317 return contents; |
317 } | 318 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 desktop_type(chrome::GetActiveDesktop()), | 406 desktop_type(chrome::GetActiveDesktop()), |
406 override_url(), | 407 override_url(), |
407 override_bounds(), | 408 override_bounds(), |
408 command_line(NULL) { | 409 command_line(NULL) { |
409 ExtensionService* service = | 410 ExtensionService* service = |
410 extensions::ExtensionSystem::Get(profile)->extension_service(); | 411 extensions::ExtensionSystem::Get(profile)->extension_service(); |
411 DCHECK(service); | 412 DCHECK(service); |
412 | 413 |
413 // Look up the app preference to find out the right launch container. Default | 414 // Look up the app preference to find out the right launch container. Default |
414 // is to launch as a regular tab. | 415 // is to launch as a regular tab. |
415 container = service->extension_prefs()->GetLaunchContainer(extension); | 416 container = extensions::GetLaunchContainer( |
| 417 service->extension_prefs(), extension); |
416 } | 418 } |
417 | 419 |
418 AppLaunchParams::AppLaunchParams(Profile* profile, | 420 AppLaunchParams::AppLaunchParams(Profile* profile, |
419 const extensions::Extension* extension, | 421 const extensions::Extension* extension, |
420 int event_flags, | 422 int event_flags, |
421 chrome::HostDesktopType desktop_type) | 423 chrome::HostDesktopType desktop_type) |
422 : profile(profile), | 424 : profile(profile), |
423 extension(extension), | 425 extension(extension), |
424 container(extensions::LAUNCH_NONE), | 426 container(extensions::LAUNCH_NONE), |
425 disposition(ui::DispositionFromEventFlags(event_flags)), | 427 disposition(ui::DispositionFromEventFlags(event_flags)), |
426 desktop_type(desktop_type), | 428 desktop_type(desktop_type), |
427 override_url(), | 429 override_url(), |
428 override_bounds(), | 430 override_bounds(), |
429 command_line(NULL) { | 431 command_line(NULL) { |
430 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 432 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
431 container = extensions::LAUNCH_TAB; | 433 container = extensions::LAUNCH_TAB; |
432 } else if (disposition == NEW_WINDOW) { | 434 } else if (disposition == NEW_WINDOW) { |
433 container = extensions::LAUNCH_WINDOW; | 435 container = extensions::LAUNCH_WINDOW; |
434 } else { | 436 } else { |
435 ExtensionService* service = | 437 ExtensionService* service = |
436 extensions::ExtensionSystem::Get(profile)->extension_service(); | 438 extensions::ExtensionSystem::Get(profile)->extension_service(); |
437 DCHECK(service); | 439 DCHECK(service); |
438 | 440 |
439 // Look at preference to find the right launch container. If no preference | 441 // Look at preference to find the right launch container. If no preference |
440 // is set, launch as a regular tab. | 442 // is set, launch as a regular tab. |
441 container = service->extension_prefs()->GetLaunchContainer(extension); | 443 container = extensions::GetLaunchContainer( |
| 444 service->extension_prefs(), extension); |
442 disposition = NEW_FOREGROUND_TAB; | 445 disposition = NEW_FOREGROUND_TAB; |
443 } | 446 } |
444 } | 447 } |
445 | 448 |
446 WebContents* OpenApplication(const AppLaunchParams& params) { | 449 WebContents* OpenApplication(const AppLaunchParams& params) { |
447 return OpenEnabledApplication(params); | 450 return OpenEnabledApplication(params); |
448 } | 451 } |
449 | 452 |
450 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { | 453 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { |
451 Profile* profile = params.profile; | 454 Profile* profile = params.profile; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 486 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
484 // the web app info is available, extensions::TabHelper notifies Browser via | 487 // the web app info is available, extensions::TabHelper notifies Browser via |
485 // OnDidGetApplicationInfo, which calls | 488 // OnDidGetApplicationInfo, which calls |
486 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 489 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
487 // pending web app action. | 490 // pending web app action. |
488 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( | 491 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( |
489 extensions::TabHelper::UPDATE_SHORTCUT); | 492 extensions::TabHelper::UPDATE_SHORTCUT); |
490 | 493 |
491 return tab; | 494 return tab; |
492 } | 495 } |
OLD | NEW |