| 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" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const Extension* extension) { | 165 const Extension* extension) { |
| 166 if (!extension || container != extensions::LAUNCH_CONTAINER_WINDOW) | 166 if (!extension || container != extensions::LAUNCH_CONTAINER_WINDOW) |
| 167 return ui::SHOW_STATE_DEFAULT; | 167 return ui::SHOW_STATE_DEFAULT; |
| 168 | 168 |
| 169 if (chrome::IsRunningInForcedAppMode()) | 169 if (chrome::IsRunningInForcedAppMode()) |
| 170 return ui::SHOW_STATE_FULLSCREEN; | 170 return ui::SHOW_STATE_FULLSCREEN; |
| 171 | 171 |
| 172 #if defined(USE_ASH) | 172 #if defined(USE_ASH) |
| 173 // In ash, LAUNCH_TYPE_FULLSCREEN launches in a maximized app window and | 173 // In ash, LAUNCH_TYPE_FULLSCREEN launches in a maximized app window and |
| 174 // LAUNCH_TYPE_WINDOW launches in a normal app window. | 174 // LAUNCH_TYPE_WINDOW launches in a normal app window. |
| 175 ExtensionService* service = | |
| 176 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 177 extensions::LaunchType launch_type = extensions::GetLaunchType( | 175 extensions::LaunchType launch_type = extensions::GetLaunchType( |
| 178 service->extension_prefs(), extension); | 176 ExtensionPrefs::Get(profile), extension); |
| 179 if (launch_type == extensions::LAUNCH_TYPE_FULLSCREEN) | 177 if (launch_type == extensions::LAUNCH_TYPE_FULLSCREEN) |
| 180 return ui::SHOW_STATE_MAXIMIZED; | 178 return ui::SHOW_STATE_MAXIMIZED; |
| 181 else if (launch_type == extensions::LAUNCH_TYPE_WINDOW) | 179 else if (launch_type == extensions::LAUNCH_TYPE_WINDOW) |
| 182 return ui::SHOW_STATE_NORMAL; | 180 return ui::SHOW_STATE_NORMAL; |
| 183 #endif | 181 #endif |
| 184 | 182 |
| 185 return ui::SHOW_STATE_DEFAULT; | 183 return ui::SHOW_STATE_DEFAULT; |
| 186 } | 184 } |
| 187 | 185 |
| 188 WebContents* OpenApplicationWindow(const AppLaunchParams& params) { | 186 WebContents* OpenApplicationWindow(const AppLaunchParams& params) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 launch_params.desktop_type)); | 252 launch_params.desktop_type)); |
| 255 browser->window()->Show(); | 253 browser->window()->Show(); |
| 256 // There's no current tab in this browser window, so add a new one. | 254 // There's no current tab in this browser window, so add a new one. |
| 257 disposition = NEW_FOREGROUND_TAB; | 255 disposition = NEW_FOREGROUND_TAB; |
| 258 } else { | 256 } else { |
| 259 // For existing browser, ensure its window is shown and activated. | 257 // For existing browser, ensure its window is shown and activated. |
| 260 browser->window()->Show(); | 258 browser->window()->Show(); |
| 261 browser->window()->Activate(); | 259 browser->window()->Activate(); |
| 262 } | 260 } |
| 263 | 261 |
| 264 // Check the prefs for overridden mode. | |
| 265 ExtensionService* extension_service = | |
| 266 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 267 DCHECK(extension_service); | |
| 268 | |
| 269 extensions::LaunchType launch_type = extensions::GetLaunchType( | 262 extensions::LaunchType launch_type = extensions::GetLaunchType( |
| 270 extension_service->extension_prefs(), extension); | 263 ExtensionPrefs::Get(profile), extension); |
| 271 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); | 264 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
| 272 | 265 |
| 273 int add_type = TabStripModel::ADD_ACTIVE; | 266 int add_type = TabStripModel::ADD_ACTIVE; |
| 274 if (launch_type == extensions::LAUNCH_TYPE_PINNED) | 267 if (launch_type == extensions::LAUNCH_TYPE_PINNED) |
| 275 add_type |= TabStripModel::ADD_PINNED; | 268 add_type |= TabStripModel::ADD_PINNED; |
| 276 | 269 |
| 277 GURL extension_url = UrlForExtension(extension, launch_params.override_url); | 270 GURL extension_url = UrlForExtension(extension, launch_params.override_url); |
| 278 chrome::NavigateParams params(browser, extension_url, | 271 chrome::NavigateParams params(browser, extension_url, |
| 279 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 272 content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 280 params.tabstrip_add_types = add_type; | 273 params.tabstrip_add_types = add_type; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 return contents; | 324 return contents; |
| 332 } | 325 } |
| 333 | 326 |
| 334 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { | 327 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { |
| 335 const Extension* extension = GetExtension(params); | 328 const Extension* extension = GetExtension(params); |
| 336 if (!extension) | 329 if (!extension) |
| 337 return NULL; | 330 return NULL; |
| 338 Profile* profile = params.profile; | 331 Profile* profile = params.profile; |
| 339 | 332 |
| 340 WebContents* tab = NULL; | 333 WebContents* tab = NULL; |
| 341 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile)-> | 334 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); |
| 342 extension_service()->extension_prefs(); | |
| 343 prefs->SetActiveBit(extension->id(), true); | 335 prefs->SetActiveBit(extension->id(), true); |
| 344 | 336 |
| 345 UMA_HISTOGRAM_ENUMERATION( | 337 UMA_HISTOGRAM_ENUMERATION( |
| 346 "Extensions.AppLaunchContainer", params.container, 100); | 338 "Extensions.AppLaunchContainer", params.container, 100); |
| 347 | 339 |
| 348 if (extension->is_platform_app()) { | 340 if (extension->is_platform_app()) { |
| 349 // Remember what desktop the launch happened on so that when the app opens a | 341 // Remember what desktop the launch happened on so that when the app opens a |
| 350 // window we can open them on the right desktop. | 342 // window we can open them on the right desktop. |
| 351 PerAppSettingsServiceFactory::GetForBrowserContext(profile)-> | 343 PerAppSettingsServiceFactory::GetForBrowserContext(profile)-> |
| 352 SetDesktopLastLaunchedFrom(extension->id(), params.desktop_type); | 344 SetDesktopLastLaunchedFrom(extension->id(), params.desktop_type); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 const extensions::Extension* extension, | 413 const extensions::Extension* extension, |
| 422 WindowOpenDisposition disposition) | 414 WindowOpenDisposition disposition) |
| 423 : profile(profile), | 415 : profile(profile), |
| 424 extension_id(extension ? extension->id() : std::string()), | 416 extension_id(extension ? extension->id() : std::string()), |
| 425 container(extensions::LAUNCH_CONTAINER_NONE), | 417 container(extensions::LAUNCH_CONTAINER_NONE), |
| 426 disposition(disposition), | 418 disposition(disposition), |
| 427 desktop_type(chrome::GetActiveDesktop()), | 419 desktop_type(chrome::GetActiveDesktop()), |
| 428 override_url(), | 420 override_url(), |
| 429 override_bounds(), | 421 override_bounds(), |
| 430 command_line(CommandLine::NO_PROGRAM) { | 422 command_line(CommandLine::NO_PROGRAM) { |
| 431 ExtensionService* service = | |
| 432 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 433 DCHECK(service); | |
| 434 | |
| 435 // Look up the app preference to find out the right launch container. Default | 423 // Look up the app preference to find out the right launch container. Default |
| 436 // is to launch as a regular tab. | 424 // is to launch as a regular tab. |
| 437 container = extensions::GetLaunchContainer( | 425 container = extensions::GetLaunchContainer( |
| 438 service->extension_prefs(), extension); | 426 ExtensionPrefs::Get(profile), extension); |
| 439 } | 427 } |
| 440 | 428 |
| 441 AppLaunchParams::AppLaunchParams(Profile* profile, | 429 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 442 const extensions::Extension* extension, | 430 const extensions::Extension* extension, |
| 443 int event_flags, | 431 int event_flags, |
| 444 chrome::HostDesktopType desktop_type) | 432 chrome::HostDesktopType desktop_type) |
| 445 : profile(profile), | 433 : profile(profile), |
| 446 extension_id(extension ? extension->id() : std::string()), | 434 extension_id(extension ? extension->id() : std::string()), |
| 447 container(extensions::LAUNCH_CONTAINER_NONE), | 435 container(extensions::LAUNCH_CONTAINER_NONE), |
| 448 disposition(ui::DispositionFromEventFlags(event_flags)), | 436 disposition(ui::DispositionFromEventFlags(event_flags)), |
| 449 desktop_type(desktop_type), | 437 desktop_type(desktop_type), |
| 450 override_url(), | 438 override_url(), |
| 451 override_bounds(), | 439 override_bounds(), |
| 452 command_line(CommandLine::NO_PROGRAM) { | 440 command_line(CommandLine::NO_PROGRAM) { |
| 453 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 441 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 454 container = extensions::LAUNCH_CONTAINER_TAB; | 442 container = extensions::LAUNCH_CONTAINER_TAB; |
| 455 } else if (disposition == NEW_WINDOW) { | 443 } else if (disposition == NEW_WINDOW) { |
| 456 container = extensions::LAUNCH_CONTAINER_WINDOW; | 444 container = extensions::LAUNCH_CONTAINER_WINDOW; |
| 457 } else { | 445 } else { |
| 458 ExtensionService* service = | |
| 459 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 460 DCHECK(service); | |
| 461 | |
| 462 // Look at preference to find the right launch container. If no preference | 446 // Look at preference to find the right launch container. If no preference |
| 463 // is set, launch as a regular tab. | 447 // is set, launch as a regular tab. |
| 464 container = extensions::GetLaunchContainer( | 448 container = extensions::GetLaunchContainer( |
| 465 service->extension_prefs(), extension); | 449 ExtensionPrefs::Get(profile), extension); |
| 466 disposition = NEW_FOREGROUND_TAB; | 450 disposition = NEW_FOREGROUND_TAB; |
| 467 } | 451 } |
| 468 } | 452 } |
| 469 | 453 |
| 470 AppLaunchParams::~AppLaunchParams() { | 454 AppLaunchParams::~AppLaunchParams() { |
| 471 } | 455 } |
| 472 | 456 |
| 473 WebContents* OpenApplication(const AppLaunchParams& params) { | 457 WebContents* OpenApplication(const AppLaunchParams& params) { |
| 474 return OpenEnabledApplication(params); | 458 return OpenEnabledApplication(params); |
| 475 } | 459 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 496 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 513 // the web app info is available, extensions::TabHelper notifies Browser via | 497 // the web app info is available, extensions::TabHelper notifies Browser via |
| 514 // OnDidGetApplicationInfo, which calls | 498 // OnDidGetApplicationInfo, which calls |
| 515 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 499 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 516 // pending web app action. | 500 // pending web app action. |
| 517 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( | 501 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( |
| 518 extensions::TabHelper::UPDATE_SHORTCUT); | 502 extensions::TabHelper::UPDATE_SHORTCUT); |
| 519 | 503 |
| 520 return tab; | 504 return tab; |
| 521 } | 505 } |
| OLD | NEW |