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( | |
|
benwells
2013/12/13 06:31:58
Nit: There is a GetExtensionById variant that take
koz (OOO until 15th September)
2013/12/16 00:21:45
I didn't - that would be clearer. Done.
| |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
| 175 Profile* const profile = params.profile; | 185 Profile* const profile = params.profile; |
| 176 const extensions::Extension* const extension = params.extension; | 186 const Extension* const extension = GetExtension(params); |
| 177 const GURL url_input = params.override_url; | 187 const GURL url_input = params.override_url; |
| 178 | 188 |
| 179 DCHECK(!url_input.is_empty() || extension); | 189 DCHECK(!url_input.is_empty() || extension); |
| 180 GURL url = UrlForExtension(extension, url_input); | 190 GURL url = UrlForExtension(extension, url_input); |
| 181 Browser::CreateParams browser_params( | 191 Browser::CreateParams browser_params( |
| 182 Browser::TYPE_POPUP, profile, params.desktop_type); | 192 Browser::TYPE_POPUP, profile, params.desktop_type); |
| 183 | 193 |
| 184 browser_params.app_name = extension ? | 194 browser_params.app_name = extension ? |
| 185 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : | 195 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : |
| 186 web_app::GenerateApplicationNameFromURL(url); | 196 web_app::GenerateApplicationNameFromURL(url); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 217 | 227 |
| 218 browser->window()->Show(); | 228 browser->window()->Show(); |
| 219 | 229 |
| 220 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 230 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 221 // focus explicitly. | 231 // focus explicitly. |
| 222 web_contents->GetView()->SetInitialFocus(); | 232 web_contents->GetView()->SetInitialFocus(); |
| 223 return web_contents; | 233 return web_contents; |
| 224 } | 234 } |
| 225 | 235 |
| 226 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) { | 236 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) { |
| 237 const Extension* extension = GetExtension(launch_params); | |
| 238 CHECK(extension); | |
| 227 Profile* const profile = launch_params.profile; | 239 Profile* const profile = launch_params.profile; |
| 228 const extensions::Extension* extension = launch_params.extension; | |
| 229 WindowOpenDisposition disposition = launch_params.disposition; | 240 WindowOpenDisposition disposition = launch_params.disposition; |
| 230 | 241 |
| 231 Browser* browser = chrome::FindTabbedBrowser(profile, | 242 Browser* browser = chrome::FindTabbedBrowser(profile, |
| 232 false, | 243 false, |
| 233 launch_params.desktop_type); | 244 launch_params.desktop_type); |
| 234 WebContents* contents = NULL; | 245 WebContents* contents = NULL; |
| 235 if (!browser) { | 246 if (!browser) { |
| 236 // No browser for this profile, need to open a new one. | 247 // No browser for this profile, need to open a new one. |
| 237 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, | 248 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, |
| 238 profile, | 249 profile, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 chrome::ToggleFullscreenWithChromeOrFallback(browser); | 321 chrome::ToggleFullscreenWithChromeOrFallback(browser); |
| 311 #else | 322 #else |
| 312 chrome::ToggleFullscreenMode(browser); | 323 chrome::ToggleFullscreenMode(browser); |
| 313 #endif | 324 #endif |
| 314 } | 325 } |
| 315 } | 326 } |
| 316 return contents; | 327 return contents; |
| 317 } | 328 } |
| 318 | 329 |
| 319 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { | 330 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { |
| 331 const Extension* extension = GetExtension(params); | |
| 332 if (!extension) | |
| 333 return NULL; | |
| 320 Profile* profile = params.profile; | 334 Profile* profile = params.profile; |
| 321 const extensions::Extension* extension = params.extension; | |
| 322 | 335 |
| 323 WebContents* tab = NULL; | 336 WebContents* tab = NULL; |
| 324 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile)-> | 337 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile)-> |
| 325 extension_service()->extension_prefs(); | 338 extension_service()->extension_prefs(); |
| 326 prefs->SetActiveBit(extension->id(), true); | 339 prefs->SetActiveBit(extension->id(), true); |
| 327 | 340 |
| 328 UMA_HISTOGRAM_ENUMERATION( | 341 UMA_HISTOGRAM_ENUMERATION( |
| 329 "Extensions.AppLaunchContainer", params.container, 100); | 342 "Extensions.AppLaunchContainer", params.container, 100); |
| 330 | 343 |
| 331 if (extension->is_platform_app()) { | 344 if (extension->is_platform_app()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 return tab; | 393 return tab; |
| 381 } | 394 } |
| 382 | 395 |
| 383 } // namespace | 396 } // namespace |
| 384 | 397 |
| 385 AppLaunchParams::AppLaunchParams(Profile* profile, | 398 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 386 const extensions::Extension* extension, | 399 const extensions::Extension* extension, |
| 387 extensions::LaunchContainer container, | 400 extensions::LaunchContainer container, |
| 388 WindowOpenDisposition disposition) | 401 WindowOpenDisposition disposition) |
| 389 : profile(profile), | 402 : profile(profile), |
| 390 extension(extension), | 403 extension_id(extension ? extension->id() : ""), |
|
tapted
2013/12/13 05:16:47
nit: "" -> std::string() [it's much faster, since
koz (OOO until 15th September)
2013/12/16 00:21:45
Done.
| |
| 391 container(container), | 404 container(container), |
| 392 disposition(disposition), | 405 disposition(disposition), |
| 393 desktop_type(chrome::GetActiveDesktop()), | 406 desktop_type(chrome::GetActiveDesktop()), |
| 394 override_url(), | 407 override_url(), |
| 395 override_bounds(), | 408 override_bounds(), |
| 396 command_line(NULL) {} | 409 command_line(CommandLine::NO_PROGRAM) {} |
| 397 | 410 |
| 398 AppLaunchParams::AppLaunchParams(Profile* profile, | 411 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 399 const extensions::Extension* extension, | 412 const extensions::Extension* extension, |
| 400 WindowOpenDisposition disposition) | 413 WindowOpenDisposition disposition) |
| 401 : profile(profile), | 414 : profile(profile), |
| 402 extension(extension), | 415 extension_id(extension ? extension->id() : ""), |
|
tapted
2013/12/13 05:16:47
I think this overload, and the next, actually can'
koz (OOO until 15th September)
2013/12/16 00:21:45
I think it's simpler if we just have extension_id.
| |
| 403 container(extensions::LAUNCH_CONTAINER_NONE), | 416 container(extensions::LAUNCH_CONTAINER_NONE), |
| 404 disposition(disposition), | 417 disposition(disposition), |
| 405 desktop_type(chrome::GetActiveDesktop()), | 418 desktop_type(chrome::GetActiveDesktop()), |
| 406 override_url(), | 419 override_url(), |
| 407 override_bounds(), | 420 override_bounds(), |
| 408 command_line(NULL) { | 421 command_line(CommandLine::NO_PROGRAM) { |
| 409 ExtensionService* service = | 422 ExtensionService* service = |
| 410 extensions::ExtensionSystem::Get(profile)->extension_service(); | 423 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 411 DCHECK(service); | 424 DCHECK(service); |
| 412 | 425 |
| 413 // Look up the app preference to find out the right launch container. Default | 426 // Look up the app preference to find out the right launch container. Default |
| 414 // is to launch as a regular tab. | 427 // is to launch as a regular tab. |
| 415 container = extensions::GetLaunchContainer( | 428 container = extensions::GetLaunchContainer( |
| 416 service->extension_prefs(), extension); | 429 service->extension_prefs(), extension); |
| 417 } | 430 } |
| 418 | 431 |
| 419 AppLaunchParams::AppLaunchParams(Profile* profile, | 432 AppLaunchParams::AppLaunchParams(Profile* profile, |
| 420 const extensions::Extension* extension, | 433 const extensions::Extension* extension, |
| 421 int event_flags, | 434 int event_flags, |
| 422 chrome::HostDesktopType desktop_type) | 435 chrome::HostDesktopType desktop_type) |
| 423 : profile(profile), | 436 : profile(profile), |
| 424 extension(extension), | 437 extension_id(extension ? extension->id() : ""), |
| 425 container(extensions::LAUNCH_CONTAINER_NONE), | 438 container(extensions::LAUNCH_CONTAINER_NONE), |
| 426 disposition(ui::DispositionFromEventFlags(event_flags)), | 439 disposition(ui::DispositionFromEventFlags(event_flags)), |
| 427 desktop_type(desktop_type), | 440 desktop_type(desktop_type), |
| 428 override_url(), | 441 override_url(), |
| 429 override_bounds(), | 442 override_bounds(), |
| 430 command_line(NULL) { | 443 command_line(CommandLine::NO_PROGRAM) { |
| 431 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 444 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 432 container = extensions::LAUNCH_CONTAINER_TAB; | 445 container = extensions::LAUNCH_CONTAINER_TAB; |
| 433 } else if (disposition == NEW_WINDOW) { | 446 } else if (disposition == NEW_WINDOW) { |
| 434 container = extensions::LAUNCH_CONTAINER_WINDOW; | 447 container = extensions::LAUNCH_CONTAINER_WINDOW; |
| 435 } else { | 448 } else { |
| 436 ExtensionService* service = | 449 ExtensionService* service = |
| 437 extensions::ExtensionSystem::Get(profile)->extension_service(); | 450 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 438 DCHECK(service); | 451 DCHECK(service); |
| 439 | 452 |
| 440 // Look at preference to find the right launch container. If no preference | 453 // Look at preference to find the right launch container. If no preference |
| 441 // is set, launch as a regular tab. | 454 // is set, launch as a regular tab. |
| 442 container = extensions::GetLaunchContainer( | 455 container = extensions::GetLaunchContainer( |
| 443 service->extension_prefs(), extension); | 456 service->extension_prefs(), extension); |
| 444 disposition = NEW_FOREGROUND_TAB; | 457 disposition = NEW_FOREGROUND_TAB; |
| 445 } | 458 } |
| 446 } | 459 } |
| 447 | 460 |
| 448 WebContents* OpenApplication(const AppLaunchParams& params) { | 461 WebContents* OpenApplication(const AppLaunchParams& params) { |
| 449 return OpenEnabledApplication(params); | 462 return OpenEnabledApplication(params); |
| 450 } | 463 } |
| 451 | 464 |
| 452 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { | 465 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { |
| 466 const Extension* extension = GetExtension(params); | |
| 467 if (!extension) | |
| 468 return; | |
| 453 Profile* profile = params.profile; | 469 Profile* profile = params.profile; |
| 454 const extensions::Extension* extension = params.extension; | |
| 455 | 470 |
| 456 ExtensionService* service = | 471 ExtensionService* service = |
| 457 extensions::ExtensionSystem::Get(profile)->extension_service(); | 472 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 458 if (!service->IsExtensionEnabled(extension->id())) { | 473 if (!service->IsExtensionEnabled(extension->id())) { |
| 459 (new EnableViaAppListFlow( | 474 (new EnableViaAppListFlow( |
| 460 service, profile, params.desktop_type, extension->id(), | 475 service, profile, params.desktop_type, extension->id(), |
| 461 base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run(); | 476 base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run(); |
| 462 return; | 477 return; |
| 463 } | 478 } |
| 464 | 479 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 485 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 500 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 486 // the web app info is available, extensions::TabHelper notifies Browser via | 501 // the web app info is available, extensions::TabHelper notifies Browser via |
| 487 // OnDidGetApplicationInfo, which calls | 502 // OnDidGetApplicationInfo, which calls |
| 488 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 503 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 489 // pending web app action. | 504 // pending web app action. |
| 490 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( | 505 extensions::TabHelper::FromWebContents(tab)->set_pending_web_app_action( |
| 491 extensions::TabHelper::UPDATE_SHORTCUT); | 506 extensions::TabHelper::UPDATE_SHORTCUT); |
| 492 | 507 |
| 493 return tab; | 508 return tab; |
| 494 } | 509 } |
| OLD | NEW |