| 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.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> // For max(). | 9 #include <algorithm> // For max(). |
| 10 #include <set> | 10 #include <set> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) | 91 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) |
| 92 #include "ui/events/devices/x11/touch_factory_x11.h" | 92 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 93 #endif | 93 #endif |
| 94 | 94 |
| 95 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) |
| 96 #include "chrome/browser/web_applications/web_app_mac.h" | 96 #include "chrome/browser/web_applications/web_app_mac.h" |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
| 100 #include "chrome/browser/metrics/jumplist_metrics_win.h" | 100 #include "chrome/browser/metrics/jumplist_metrics_win.h" |
| 101 #include "components/search_engines/desktop_search_win.h" | 101 #include "components/search_engines/desktop_search_utils.h" |
| 102 #endif | 102 #endif |
| 103 | 103 |
| 104 #if defined(ENABLE_PRINT_PREVIEW) | 104 #if defined(ENABLE_PRINT_PREVIEW) |
| 105 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 105 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 106 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | 106 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" |
| 107 #include "chrome/browser/printing/print_dialog_cloud.h" | 107 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 108 #endif | 108 #endif |
| 109 | 109 |
| 110 using content::BrowserThread; | 110 using content::BrowserThread; |
| 111 using content::ChildProcessSecurityPolicy; | 111 using content::ChildProcessSecurityPolicy; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 UserManager::Show( | 300 UserManager::Show( |
| 301 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); | 301 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); |
| 302 return true; | 302 return true; |
| 303 #endif | 303 #endif |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace | 306 } // namespace |
| 307 | 307 |
| 308 StartupBrowserCreator::StartupBrowserCreator() | 308 StartupBrowserCreator::StartupBrowserCreator() |
| 309 : is_default_browser_dialog_suppressed_(false), | 309 : is_default_browser_dialog_suppressed_(false), |
| 310 show_main_browser_window_(true) { | 310 show_main_browser_window_(true), |
| 311 } | 311 show_desktop_search_redirection_infobar_(false) {} |
| 312 | 312 |
| 313 StartupBrowserCreator::~StartupBrowserCreator() {} | 313 StartupBrowserCreator::~StartupBrowserCreator() {} |
| 314 | 314 |
| 315 // static | 315 // static |
| 316 bool StartupBrowserCreator::was_restarted_read_ = false; | 316 bool StartupBrowserCreator::was_restarted_read_ = false; |
| 317 | 317 |
| 318 // static | 318 // static |
| 319 bool StartupBrowserCreator::in_synchronous_profile_launch_ = false; | 319 bool StartupBrowserCreator::in_synchronous_profile_launch_ = false; |
| 320 | 320 |
| 321 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) { | 321 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 // Note: This check should have been done in ProcessCmdLineImpl() | 366 // Note: This check should have been done in ProcessCmdLineImpl() |
| 367 // before calling this function. However chromeos/login/login_utils.cc | 367 // before calling this function. However chromeos/login/login_utils.cc |
| 368 // calls this function directly (see comments there) so it has to be checked | 368 // calls this function directly (see comments there) so it has to be checked |
| 369 // again. | 369 // again. |
| 370 const bool silent_launch = command_line.HasSwitch(switches::kSilentLaunch); | 370 const bool silent_launch = command_line.HasSwitch(switches::kSilentLaunch); |
| 371 | 371 |
| 372 if (!silent_launch) { | 372 if (!silent_launch) { |
| 373 StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); | 373 StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); |
| 374 const std::vector<GURL> urls_to_launch = | 374 const std::vector<GURL> urls_to_launch = |
| 375 GetURLsFromCommandLine(command_line, cur_dir, profile); | 375 GetURLsFromCommandLine(command_line, cur_dir, profile, |
| 376 &show_desktop_search_redirection_infobar_); |
| 376 chrome::HostDesktopType host_desktop_type = | 377 chrome::HostDesktopType host_desktop_type = |
| 377 chrome::HOST_DESKTOP_TYPE_NATIVE; | 378 chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 378 | 379 |
| 379 #if defined(USE_ASH) && !defined(OS_CHROMEOS) | 380 #if defined(USE_ASH) && !defined(OS_CHROMEOS) |
| 380 // We want to maintain only one type of instance for now, either ASH | 381 // We want to maintain only one type of instance for now, either ASH |
| 381 // or desktop. | 382 // or desktop. |
| 382 // TODO(shrikant): Remove this code once we decide on running both desktop | 383 // TODO(shrikant): Remove this code once we decide on running both desktop |
| 383 // and ASH instances side by side. | 384 // and ASH instances side by side. |
| 384 if (ash::Shell::HasInstance()) | 385 if (ash::Shell::HasInstance()) |
| 385 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | 386 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // static | 525 // static |
| 525 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() { | 526 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() { |
| 526 return kSetDefaultBrowserHelpUrl; | 527 return kSetDefaultBrowserHelpUrl; |
| 527 } | 528 } |
| 528 #endif // defined(OS_WIN) | 529 #endif // defined(OS_WIN) |
| 529 | 530 |
| 530 // static | 531 // static |
| 531 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( | 532 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( |
| 532 const base::CommandLine& command_line, | 533 const base::CommandLine& command_line, |
| 533 const base::FilePath& cur_dir, | 534 const base::FilePath& cur_dir, |
| 534 Profile* profile) { | 535 Profile* profile, |
| 536 bool* show_desktop_search_redirection_infobar) { |
| 537 DCHECK(profile); |
| 538 DCHECK(show_desktop_search_redirection_infobar); |
| 539 |
| 535 std::vector<GURL> urls; | 540 std::vector<GURL> urls; |
| 536 | 541 |
| 537 const base::CommandLine::StringVector& params = command_line.GetArgs(); | 542 const base::CommandLine::StringVector& params = command_line.GetArgs(); |
| 538 for (size_t i = 0; i < params.size(); ++i) { | 543 for (size_t i = 0; i < params.size(); ++i) { |
| 539 base::FilePath param = base::FilePath(params[i]); | 544 base::FilePath param = base::FilePath(params[i]); |
| 540 // Handle Vista way of searching - "? <search-term>" | 545 // Handle Vista way of searching - "? <search-term>" |
| 541 if ((param.value().size() > 2) && (param.value()[0] == '?') && | 546 if ((param.value().size() > 2) && (param.value()[0] == '?') && |
| 542 (param.value()[1] == ' ')) { | 547 (param.value()[1] == ' ')) { |
| 543 GURL url(GetDefaultSearchURLForSearchTerms( | 548 GURL url(GetDefaultSearchURLForSearchTerms( |
| 544 TemplateURLServiceFactory::GetForProfile(profile), | 549 TemplateURLServiceFactory::GetForProfile(profile), |
| 545 param.LossyDisplayName().substr(2))); | 550 param.LossyDisplayName().substr(2))); |
| 546 if (url.is_valid()) { | 551 if (url.is_valid()) { |
| 547 urls.push_back(url); | 552 urls.push_back(url); |
| 548 continue; | 553 continue; |
| 549 } | 554 } |
| 550 } | 555 } |
| 551 | 556 |
| 552 // Otherwise, fall through to treating it as a URL. | 557 // Otherwise, fall through to treating it as a URL. |
| 553 | 558 |
| 554 // This will create a file URL or a regular URL. | 559 // This will create a file URL or a regular URL. |
| 555 // This call can (in rare circumstances) block the UI thread. | 560 // This call can (in rare circumstances) block the UI thread. |
| 556 // Allow it until this bug is fixed. | 561 // Allow it until this bug is fixed. |
| 557 // http://code.google.com/p/chromium/issues/detail?id=60641 | 562 // http://code.google.com/p/chromium/issues/detail?id=60641 |
| 558 GURL url = GURL(param.MaybeAsASCII()); | 563 GURL url = GURL(param.MaybeAsASCII()); |
| 559 | 564 |
| 560 #if defined(OS_WIN) | 565 #if defined(OS_WIN) |
| 561 TemplateURLService* template_url_service = | 566 // Replace desktop search URL by a default search engine URL if needed. |
| 562 TemplateURLServiceFactory::GetForProfile(profile); | 567 // Ignore cases where there are multiple command line arguments, because |
| 563 DCHECK(template_url_service); | 568 // desktop search never passes multiple URLs to the browser. |
| 564 base::string16 search_terms; | 569 if (params.size() == 1) { |
| 565 if (DetectWindowsDesktopSearch( | 570 *show_desktop_search_redirection_infobar = |
| 566 url, template_url_service->search_terms_data(), &search_terms)) { | 571 ReplaceDesktopSearchURLWithDefaultSearchURLIfNeeded( |
| 567 base::RecordAction(base::UserMetricsAction("DesktopSearch")); | 572 profile->GetPrefs(), |
| 568 | 573 TemplateURLServiceFactory::GetForProfile(profile), &url); |
| 569 if (ShouldRedirectWindowsDesktopSearchToDefaultSearchEngine( | |
| 570 profile->GetPrefs())) { | |
| 571 const GURL search_url(GetDefaultSearchURLForSearchTerms( | |
| 572 template_url_service, search_terms)); | |
| 573 if (search_url.is_valid()) { | |
| 574 urls.push_back(search_url); | |
| 575 continue; | |
| 576 } | |
| 577 } | |
| 578 } | 574 } |
| 579 #endif // defined(OS_WIN) | 575 #endif // defined(OS_WIN) |
| 580 | 576 |
| 581 // http://crbug.com/371030: Only use URLFixerUpper if we don't have a valid | 577 // http://crbug.com/371030: Only use URLFixerUpper if we don't have a valid |
| 582 // URL, otherwise we will look in the current directory for a file named | 578 // URL, otherwise we will look in the current directory for a file named |
| 583 // 'about' if the browser was started with a about:foo argument. | 579 // 'about' if the browser was started with a about:foo argument. |
| 584 if (!url.is_valid()) { | 580 if (!url.is_valid()) { |
| 585 base::ThreadRestrictions::ScopedAllowIO allow_io; | 581 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 586 url = url_formatter::FixupRelativeFile(cur_dir, param); | 582 url = url_formatter::FixupRelativeFile(cur_dir, param); |
| 587 } | 583 } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 // If we are showing the app list then chrome isn't shown so load the app | 932 // If we are showing the app list then chrome isn't shown so load the app |
| 937 // list's profile rather than chrome's. | 933 // list's profile rather than chrome's. |
| 938 if (command_line.HasSwitch(switches::kShowAppList)) { | 934 if (command_line.HasSwitch(switches::kShowAppList)) { |
| 939 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 935 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
| 940 GetProfilePath(user_data_dir); | 936 GetProfilePath(user_data_dir); |
| 941 } | 937 } |
| 942 | 938 |
| 943 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 939 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 944 user_data_dir); | 940 user_data_dir); |
| 945 } | 941 } |
| OLD | NEW |