| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 ExtensionService* service_; | 111 ExtensionService* service_; |
| 112 Profile* profile_; | 112 Profile* profile_; |
| 113 chrome::HostDesktopType desktop_type_; | 113 chrome::HostDesktopType desktop_type_; |
| 114 std::string extension_id_; | 114 std::string extension_id_; |
| 115 base::Closure callback_; | 115 base::Closure callback_; |
| 116 scoped_ptr<ExtensionEnableFlow> flow_; | 116 scoped_ptr<ExtensionEnableFlow> flow_; |
| 117 | 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(EnableViaAppListFlow); | 118 DISALLOW_COPY_AND_ASSIGN(EnableViaAppListFlow); |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 const Extension* GetExtension(const AppLaunchParams& params) { |
| 122 if (params.extension_id.empty()) |
| 123 return NULL; |
| 124 ExtensionService* service = |
| 125 extensions::ExtensionSystem::Get(params.profile)->extension_service(); |
| 126 const Extension* extension = service->GetExtensionById( |
| 127 params.extension_id, |
| 128 ExtensionService::INCLUDE_ENABLED | ExtensionService::INCLUDE_DISABLED | |
| 129 ExtensionService::INCLUDE_TERMINATED); |
| 130 if (!extension) |
| 131 extension = service->GetTerminatedExtension(params.extension_id); |
| 132 return extension; |
| 133 } |
| 134 |
| 121 // Get the launch URL for a given extension, with optional override/fallback. | 135 // Get the launch URL for a given extension, with optional override/fallback. |
| 122 // |override_url|, if non-empty, will be preferred over the extension's | 136 // |override_url|, if non-empty, will be preferred over the extension's |
| 123 // launch url. | 137 // launch url. |
| 124 GURL UrlForExtension(const Extension* extension, | 138 GURL UrlForExtension(const Extension* extension, |
| 125 const GURL& override_url) { | 139 const GURL& override_url) { |
| 126 if (!extension) | 140 if (!extension) |
| 127 return override_url; | 141 return override_url; |
| 128 | 142 |
| 129 GURL url; | 143 GURL url; |
| 130 if (!override_url.is_empty()) { | 144 if (!override_url.is_empty()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return ui::SHOW_STATE_MAXIMIZED; | 180 return ui::SHOW_STATE_MAXIMIZED; |
| 167 else if (launch_type == extensions::LAUNCH_TYPE_WINDOW) | 181 else if (launch_type == extensions::LAUNCH_TYPE_WINDOW) |
| 168 return ui::SHOW_STATE_NORMAL; | 182 return ui::SHOW_STATE_NORMAL; |
| 169 #endif | 183 #endif |
| 170 | 184 |
| 171 return ui::SHOW_STATE_DEFAULT; | 185 return ui::SHOW_STATE_DEFAULT; |
| 172 } | 186 } |
| 173 | 187 |
| 174 WebContents* OpenApplicationWindow(const AppLaunchParams& params) { | 188 WebContents* OpenApplicationWindow(const AppLaunchParams& params) { |
| 175 Profile* const profile = params.profile; | 189 Profile* const profile = params.profile; |
| 176 const extensions::Extension* const extension = params.extension; | 190 const Extension* const extension = GetExtension(params); |
| 177 const GURL url_input = params.override_url; | 191 const GURL url_input = params.override_url; |
| 178 | 192 |
| 179 DCHECK(!url_input.is_empty() || extension); | 193 DCHECK(!url_input.is_empty() || extension); |
| 180 GURL url = UrlForExtension(extension, url_input); | 194 GURL url = UrlForExtension(extension, url_input); |
| 181 Browser::CreateParams browser_params( | 195 Browser::CreateParams browser_params( |
| 182 Browser::TYPE_POPUP, profile, params.desktop_type); | 196 Browser::TYPE_POPUP, profile, params.desktop_type); |
| 183 | 197 |
| 184 browser_params.app_name = extension ? | 198 browser_params.app_name = extension ? |
| 185 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : | 199 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : |
| 186 web_app::GenerateApplicationNameFromURL(url); | 200 web_app::GenerateApplicationNameFromURL(url); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 217 | 231 |
| 218 browser->window()->Show(); | 232 browser->window()->Show(); |
| 219 | 233 |
| 220 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 234 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 221 // focus explicitly. | 235 // focus explicitly. |
| 222 web_contents->GetView()->SetInitialFocus(); | 236 web_contents->GetView()->SetInitialFocus(); |
| 223 return web_contents; | 237 return web_contents; |
| 224 } | 238 } |
| 225 | 239 |
| 226 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) { | 240 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) { |
| 241 const Extension* extension = GetExtension(launch_params); |
| 242 CHECK(extension); |
| 227 Profile* const profile = launch_params.profile; | 243 Profile* const profile = launch_params.profile; |
| 228 const extensions::Extension* extension = launch_params.extension; | |
| 229 WindowOpenDisposition disposition = launch_params.disposition; | 244 WindowOpenDisposition disposition = launch_params.disposition; |
| 230 | 245 |
| 231 Browser* browser = chrome::FindTabbedBrowser(profile, | 246 Browser* browser = chrome::FindTabbedBrowser(profile, |
| 232 false, | 247 false, |
| 233 launch_params.desktop_type); | 248 launch_params.desktop_type); |
| 234 WebContents* contents = NULL; | 249 WebContents* contents = NULL; |
| 235 if (!browser) { | 250 if (!browser) { |
| 236 // No browser for this profile, need to open a new one. | 251 // No browser for this profile, need to open a new one. |
| 237 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, | 252 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, |
| 238 profile, | 253 profile, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 chrome::ToggleFullscreenWithChromeOrFallback(browser); | 325 chrome::ToggleFullscreenWithChromeOrFallback(browser); |
| 311 #else | 326 #else |
| 312 chrome::ToggleFullscreenMode(browser); | 327 chrome::ToggleFullscreenMode(browser); |
| 313 #endif | 328 #endif |
| 314 } | 329 } |
| 315 } | 330 } |
| 316 return contents; | 331 return contents; |
| 317 } | 332 } |
| 318 | 333 |
| 319 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { | 334 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { |
| 335 const Extension* extension = GetExtension(params); |
| 336 if (!extension) |
| 337 return NULL; |
| 320 Profile* profile = params.profile; | 338 Profile* profile = params.profile; |
| 321 const extensions::Extension* extension = params.extension; | |
| 322 | 339 |
| 323 WebContents* tab = NULL; | 340 WebContents* tab = NULL; |
| 324 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile)-> | 341 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile)-> |
| 325 extension_service()->extension_prefs(); | 342 extension_service()->extension_prefs(); |
| 326 prefs->SetActiveBit(extension->id(), true); | 343 prefs->SetActiveBit(extension->id(), true); |
| 327 | 344 |
| 328 UMA_HISTOGRAM_ENUMERATION( | 345 UMA_HISTOGRAM_ENUMERATION( |
| 329 "Extensions.AppLaunchContainer", params.container, 100); | 346 "Extensions.AppLaunchContainer", params.container, 100); |
| 330 | 347 |
| 331 if (extension->is_platform_app()) { | 348 if (extension->is_platform_app()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 return tab; | 397 return tab; |
| 381 } | 398 } |
| 382 | 399 |
| 383 } // namespace | 400 } // namespace |
| 384 | 401 |
| 385 AppLaunchParams::AppLaunchParams(Profile* profile, | 402 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 386 const extensions::Extension* extension, | 403 const extensions::Extension* extension, |
| 387 extensions::LaunchContainer container, | 404 extensions::LaunchContainer container, |
| 388 WindowOpenDisposition disposition) | 405 WindowOpenDisposition disposition) |
| 389 : profile(profile), | 406 : profile(profile), |
| 390 extension(extension), | 407 extension_id(extension ? extension->id() : std::string()), |
| 391 container(container), | 408 container(container), |
| 392 disposition(disposition), | 409 disposition(disposition), |
| 393 desktop_type(chrome::GetActiveDesktop()), | 410 desktop_type(chrome::GetActiveDesktop()), |
| 394 override_url(), | 411 override_url(), |
| 395 override_bounds(), | 412 override_bounds(), |
| 396 command_line(NULL) {} | 413 command_line(CommandLine::NO_PROGRAM) {} |
| 397 | 414 |
| 398 AppLaunchParams::AppLaunchParams(Profile* profile, | 415 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 399 const extensions::Extension* extension, | 416 const extensions::Extension* extension, |
| 400 WindowOpenDisposition disposition) | 417 WindowOpenDisposition disposition) |
| 401 : profile(profile), | 418 : profile(profile), |
| 402 extension(extension), | 419 extension_id(extension ? extension->id() : std::string()), |
| 403 container(extensions::LAUNCH_CONTAINER_NONE), | 420 container(extensions::LAUNCH_CONTAINER_NONE), |
| 404 disposition(disposition), | 421 disposition(disposition), |
| 405 desktop_type(chrome::GetActiveDesktop()), | 422 desktop_type(chrome::GetActiveDesktop()), |
| 406 override_url(), | 423 override_url(), |
| 407 override_bounds(), | 424 override_bounds(), |
| 408 command_line(NULL) { | 425 command_line(CommandLine::NO_PROGRAM) { |
| 409 ExtensionService* service = | 426 ExtensionService* service = |
| 410 extensions::ExtensionSystem::Get(profile)->extension_service(); | 427 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 411 DCHECK(service); | 428 DCHECK(service); |
| 412 | 429 |
| 413 // Look up the app preference to find out the right launch container. Default | 430 // Look up the app preference to find out the right launch container. Default |
| 414 // is to launch as a regular tab. | 431 // is to launch as a regular tab. |
| 415 container = extensions::GetLaunchContainer( | 432 container = extensions::GetLaunchContainer( |
| 416 service->extension_prefs(), extension); | 433 service->extension_prefs(), extension); |
| 417 } | 434 } |
| 418 | 435 |
| 419 AppLaunchParams::AppLaunchParams(Profile* profile, | 436 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 420 const extensions::Extension* extension, | 437 const extensions::Extension* extension, |
| 421 int event_flags, | 438 int event_flags, |
| 422 chrome::HostDesktopType desktop_type) | 439 chrome::HostDesktopType desktop_type) |
| 423 : profile(profile), | 440 : profile(profile), |
| 424 extension(extension), | 441 extension_id(extension ? extension->id() : std::string()), |
| 425 container(extensions::LAUNCH_CONTAINER_NONE), | 442 container(extensions::LAUNCH_CONTAINER_NONE), |
| 426 disposition(ui::DispositionFromEventFlags(event_flags)), | 443 disposition(ui::DispositionFromEventFlags(event_flags)), |
| 427 desktop_type(desktop_type), | 444 desktop_type(desktop_type), |
| 428 override_url(), | 445 override_url(), |
| 429 override_bounds(), | 446 override_bounds(), |
| 430 command_line(NULL) { | 447 command_line(CommandLine::NO_PROGRAM) { |
| 431 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 448 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 432 container = extensions::LAUNCH_CONTAINER_TAB; | 449 container = extensions::LAUNCH_CONTAINER_TAB; |
| 433 } else if (disposition == NEW_WINDOW) { | 450 } else if (disposition == NEW_WINDOW) { |
| 434 container = extensions::LAUNCH_CONTAINER_WINDOW; | 451 container = extensions::LAUNCH_CONTAINER_WINDOW; |
| 435 } else { | 452 } else { |
| 436 ExtensionService* service = | 453 ExtensionService* service = |
| 437 extensions::ExtensionSystem::Get(profile)->extension_service(); | 454 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 438 DCHECK(service); | 455 DCHECK(service); |
| 439 | 456 |
| 440 // Look at preference to find the right launch container. If no preference | 457 // Look at preference to find the right launch container. If no preference |
| 441 // is set, launch as a regular tab. | 458 // is set, launch as a regular tab. |
| 442 container = extensions::GetLaunchContainer( | 459 container = extensions::GetLaunchContainer( |
| 443 service->extension_prefs(), extension); | 460 service->extension_prefs(), extension); |
| 444 disposition = NEW_FOREGROUND_TAB; | 461 disposition = NEW_FOREGROUND_TAB; |
| 445 } | 462 } |
| 446 } | 463 } |
| 447 | 464 |
| 465 AppLaunchParams::~AppLaunchParams() { |
| 466 } |
| 467 |
| 448 WebContents* OpenApplication(const AppLaunchParams& params) { | 468 WebContents* OpenApplication(const AppLaunchParams& params) { |
| 449 return OpenEnabledApplication(params); | 469 return OpenEnabledApplication(params); |
| 450 } | 470 } |
| 451 | 471 |
| 452 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { | 472 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { |
| 473 const Extension* extension = GetExtension(params); |
| 474 if (!extension) |
| 475 return; |
| 453 Profile* profile = params.profile; | 476 Profile* profile = params.profile; |
| 454 const extensions::Extension* extension = params.extension; | |
| 455 | 477 |
| 456 ExtensionService* service = | 478 ExtensionService* service = |
| 457 extensions::ExtensionSystem::Get(profile)->extension_service(); | 479 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 458 if (!service->IsExtensionEnabled(extension->id())) { | 480 if (!service->IsExtensionEnabled(extension->id())) { |
| 459 (new EnableViaAppListFlow( | 481 (new EnableViaAppListFlow( |
| 460 service, profile, params.desktop_type, extension->id(), | 482 service, profile, params.desktop_type, extension->id(), |
| 461 base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run(); | 483 base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run(); |
| 462 return; | 484 return; |
| 463 } | 485 } |
| 464 | 486 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 485 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 507 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 486 // the web app info is available, extensions::TabHelper notifies Browser via | 508 // the web app info is available, extensions::TabHelper notifies Browser via |
| 487 // OnDidGetApplicationInfo, which calls | 509 // OnDidGetApplicationInfo, which calls |
| 488 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 510 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 489 // pending web app action. | 511 // pending web app action. |
| 490 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( | 512 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( |
| 491 extensions::TabHelper::UPDATE_SHORTCUT); | 513 extensions::TabHelper::UPDATE_SHORTCUT); |
| 492 | 514 |
| 493 return tab; | 515 return tab; |
| 494 } | 516 } |
| OLD | NEW |