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