| 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/startup/startup_browser_creator_impl.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 8 #include <vector> |
| 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 11 #include "base/environment.h" | 14 #include "base/environment.h" |
| 12 #include "base/event_recorder.h" | 15 #include "base/event_recorder.h" |
| 13 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 14 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 16 #include "base/metrics/statistics_recorder.h" | 19 #include "base/metrics/statistics_recorder.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 #include "content/public/browser/child_process_security_policy.h" | 81 #include "content/public/browser/child_process_security_policy.h" |
| 79 #include "content/public/browser/dom_storage_context.h" | 82 #include "content/public/browser/dom_storage_context.h" |
| 80 #include "content/public/browser/notification_observer.h" | 83 #include "content/public/browser/notification_observer.h" |
| 81 #include "content/public/browser/notification_registrar.h" | 84 #include "content/public/browser/notification_registrar.h" |
| 82 #include "content/public/browser/storage_partition.h" | 85 #include "content/public/browser/storage_partition.h" |
| 83 #include "content/public/browser/web_contents.h" | 86 #include "content/public/browser/web_contents.h" |
| 84 #include "content/public/browser/web_contents_view.h" | 87 #include "content/public/browser/web_contents_view.h" |
| 85 #include "grit/locale_settings.h" | 88 #include "grit/locale_settings.h" |
| 86 #include "ui/base/l10n/l10n_util.h" | 89 #include "ui/base/l10n/l10n_util.h" |
| 87 #include "ui/base/resource/resource_bundle.h" | 90 #include "ui/base/resource/resource_bundle.h" |
| 91 #include "ui/gfx/rect.h" |
| 92 #include "ui/gfx/screen.h" |
| 93 |
| 94 #if defined(USE_ASH) |
| 95 #include "ash/launcher/launcher_types.h" |
| 96 #endif |
| 88 | 97 |
| 89 #if defined(OS_MACOSX) | 98 #if defined(OS_MACOSX) |
| 90 #include "base/mac/mac_util.h" | 99 #include "base/mac/mac_util.h" |
| 91 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" | 100 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" |
| 92 #endif | 101 #endif |
| 93 | 102 |
| 94 #if defined(TOOLKIT_GTK) | 103 #if defined(TOOLKIT_GTK) |
| 95 #include "chrome/browser/ui/gtk/gtk_util.h" | 104 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 96 #endif | 105 #endif |
| 97 | 106 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // preference is set, launch as a window. | 211 // preference is set, launch as a window. |
| 203 extension_misc::LaunchContainer launch_container = | 212 extension_misc::LaunchContainer launch_container = |
| 204 extensions_service->extension_prefs()->GetLaunchContainer( | 213 extensions_service->extension_prefs()->GetLaunchContainer( |
| 205 extension, extensions::ExtensionPrefs::LAUNCH_WINDOW); | 214 extension, extensions::ExtensionPrefs::LAUNCH_WINDOW); |
| 206 | 215 |
| 207 *out_extension = extension; | 216 *out_extension = extension; |
| 208 *out_launch_container = launch_container; | 217 *out_launch_container = launch_container; |
| 209 return true; | 218 return true; |
| 210 } | 219 } |
| 211 | 220 |
| 221 // Parse two comma-separated integers from string. Return true on success. |
| 222 bool ParseCommaSeparatedIntegers(const std::string& str, |
| 223 int* ret_num1, |
| 224 int* ret_num2) { |
| 225 std::vector<std::string> dimensions; |
| 226 base::SplitString(str, ',', &dimensions); |
| 227 if (dimensions.size() != 2) |
| 228 return false; |
| 229 |
| 230 int num1, num2; |
| 231 if (!base::StringToInt(dimensions[0], &num1) || |
| 232 !base::StringToInt(dimensions[1], &num2)) |
| 233 return false; |
| 234 |
| 235 *ret_num1 = num1; |
| 236 *ret_num2 = num2; |
| 237 return true; |
| 238 } |
| 239 |
| 212 void RecordCmdLineAppHistogram() { | 240 void RecordCmdLineAppHistogram() { |
| 213 AppLauncherHandler::RecordAppLaunchType( | 241 AppLauncherHandler::RecordAppLaunchType( |
| 214 extension_misc::APP_LAUNCH_CMD_LINE_APP); | 242 extension_misc::APP_LAUNCH_CMD_LINE_APP); |
| 215 } | 243 } |
| 216 | 244 |
| 217 void RecordAppLaunches(Profile* profile, | 245 void RecordAppLaunches(Profile* profile, |
| 218 const std::vector<GURL>& cmd_line_urls, | 246 const std::vector<GURL>& cmd_line_urls, |
| 219 StartupTabs& autolaunch_tabs) { | 247 StartupTabs& autolaunch_tabs) { |
| 220 ExtensionService* extension_service = profile->GetExtensionService(); | 248 ExtensionService* extension_service = profile->GetExtensionService(); |
| 221 DCHECK(extension_service); | 249 DCHECK(extension_service); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 424 } |
| 397 | 425 |
| 398 #if defined(OS_WIN) | 426 #if defined(OS_WIN) |
| 399 if (process_startup) | 427 if (process_startup) |
| 400 ShellIntegration::MigrateChromiumShortcuts(); | 428 ShellIntegration::MigrateChromiumShortcuts(); |
| 401 #endif // defined(OS_WIN) | 429 #endif // defined(OS_WIN) |
| 402 | 430 |
| 403 return true; | 431 return true; |
| 404 } | 432 } |
| 405 | 433 |
| 434 void StartupBrowserCreatorImpl::ExtractOptionalAppWindowSize( |
| 435 gfx::Rect* bounds) { |
| 436 if (command_line_.HasSwitch(switches::kAppWindowSize)) { |
| 437 int width, height; |
| 438 width = height = 0; |
| 439 std::string switch_value = |
| 440 command_line_.GetSwitchValueASCII(switches::kAppWindowSize); |
| 441 if (ParseCommaSeparatedIntegers(switch_value, &width, &height)) { |
| 442 const gfx::Rect work_area = gfx::Screen::GetPrimaryDisplay().work_area(); |
| 443 width = std::min(width, work_area.width()); |
| 444 height = std::min(height, work_area.height()); |
| 445 bounds->set_size(gfx::Size(width, height)); |
| 446 bounds->set_x((work_area.width() - bounds->width()) / 2); |
| 447 // TODO(nkostylev): work_area does include launcher but should not. |
| 448 // Launcher auto hide pref is synced and is most likely not applied here. |
| 449 bounds->set_y((work_area.height() - bounds->height()) / 2); |
| 450 } |
| 451 } |
| 452 } |
| 453 |
| 406 bool StartupBrowserCreatorImpl::IsAppLaunch(std::string* app_url, | 454 bool StartupBrowserCreatorImpl::IsAppLaunch(std::string* app_url, |
| 407 std::string* app_id) { | 455 std::string* app_id) { |
| 408 if (command_line_.HasSwitch(switches::kApp)) { | 456 if (command_line_.HasSwitch(switches::kApp)) { |
| 409 if (app_url) | 457 if (app_url) |
| 410 *app_url = command_line_.GetSwitchValueASCII(switches::kApp); | 458 *app_url = command_line_.GetSwitchValueASCII(switches::kApp); |
| 411 return true; | 459 return true; |
| 412 } | 460 } |
| 413 if (command_line_.HasSwitch(switches::kAppId)) { | 461 if (command_line_.HasSwitch(switches::kAppId)) { |
| 414 if (app_id) | 462 if (app_id) |
| 415 *app_id = command_line_.GetSwitchValueASCII(switches::kAppId); | 463 *app_id = command_line_.GetSwitchValueASCII(switches::kAppId); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 ChildProcessSecurityPolicy::GetInstance(); | 550 ChildProcessSecurityPolicy::GetInstance(); |
| 503 if (policy->IsWebSafeScheme(url.scheme()) || | 551 if (policy->IsWebSafeScheme(url.scheme()) || |
| 504 url.SchemeIs(chrome::kFileScheme)) { | 552 url.SchemeIs(chrome::kFileScheme)) { |
| 505 if (profile->GetExtensionService()->IsInstalledApp(url)) { | 553 if (profile->GetExtensionService()->IsInstalledApp(url)) { |
| 506 RecordCmdLineAppHistogram(); | 554 RecordCmdLineAppHistogram(); |
| 507 } else { | 555 } else { |
| 508 AppLauncherHandler::RecordAppLaunchType( | 556 AppLauncherHandler::RecordAppLaunchType( |
| 509 extension_misc::APP_LAUNCH_CMD_LINE_APP_LEGACY); | 557 extension_misc::APP_LAUNCH_CMD_LINE_APP_LEGACY); |
| 510 } | 558 } |
| 511 | 559 |
| 560 gfx::Rect override_bounds; |
| 561 ExtractOptionalAppWindowSize(&override_bounds); |
| 562 |
| 512 WebContents* app_tab = application_launch::OpenAppShortcutWindow( | 563 WebContents* app_tab = application_launch::OpenAppShortcutWindow( |
| 513 profile, | 564 profile, |
| 514 url); | 565 url, |
| 566 override_bounds); |
| 515 | 567 |
| 516 if (out_app_contents) | 568 if (out_app_contents) |
| 517 *out_app_contents = app_tab; | 569 *out_app_contents = app_tab; |
| 518 | 570 |
| 519 return (app_tab != NULL); | 571 return (app_tab != NULL); |
| 520 } | 572 } |
| 521 } | 573 } |
| 522 return false; | 574 return false; |
| 523 } | 575 } |
| 524 | 576 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 // New: | 994 // New: |
| 943 prefs->GetString(prefs::kHomePage), | 995 prefs->GetString(prefs::kHomePage), |
| 944 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), | 996 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), |
| 945 prefs->GetBoolean(prefs::kShowHomeButton), | 997 prefs->GetBoolean(prefs::kShowHomeButton), |
| 946 // Backup: | 998 // Backup: |
| 947 backup_homepage, | 999 backup_homepage, |
| 948 backup_homepage_is_ntp, | 1000 backup_homepage_is_ntp, |
| 949 backup_show_home_button)); | 1001 backup_show_home_button)); |
| 950 } | 1002 } |
| 951 } | 1003 } |
| OLD | NEW |