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/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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 88 |
| 89 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) | 89 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) |
| 90 #include "ui/events/devices/x11/touch_factory_x11.h" | 90 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 #if defined(OS_MACOSX) | 93 #if defined(OS_MACOSX) |
| 94 #include "chrome/browser/web_applications/web_app_mac.h" | 94 #include "chrome/browser/web_applications/web_app_mac.h" |
| 95 #endif | 95 #endif |
| 96 | 96 |
| 97 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
| 98 #include "chrome/browser/infobars/infobar_service.h" | |
| 98 #include "chrome/browser/metrics/jumplist_metrics_win.h" | 99 #include "chrome/browser/metrics/jumplist_metrics_win.h" |
| 99 #include "components/search_engines/desktop_search_win.h" | 100 #include "chrome/browser/ui/browser_list.h" |
| 101 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 102 #include "components/search_engines/desktop_search_infobar_delegate_win.h" | |
| 103 #include "components/search_engines/desktop_search_utils_win.h" | |
| 104 #include "components/search_engines/template_url.h" | |
| 100 #endif | 105 #endif |
| 101 | 106 |
| 102 #if defined(ENABLE_PRINT_PREVIEW) | 107 #if defined(ENABLE_PRINT_PREVIEW) |
| 103 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 108 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 104 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" | 109 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" |
| 105 #include "chrome/browser/printing/print_dialog_cloud.h" | 110 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 106 #endif | 111 #endif |
| 107 | 112 |
| 108 using content::BrowserThread; | 113 using content::BrowserThread; |
| 109 using content::ChildProcessSecurityPolicy; | 114 using content::ChildProcessSecurityPolicy; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 367 } |
| 363 | 368 |
| 364 // Note: This check should have been done in ProcessCmdLineImpl() | 369 // Note: This check should have been done in ProcessCmdLineImpl() |
| 365 // before calling this function. However chromeos/login/login_utils.cc | 370 // before calling this function. However chromeos/login/login_utils.cc |
| 366 // calls this function directly (see comments there) so it has to be checked | 371 // calls this function directly (see comments there) so it has to be checked |
| 367 // again. | 372 // again. |
| 368 const bool silent_launch = command_line.HasSwitch(switches::kSilentLaunch); | 373 const bool silent_launch = command_line.HasSwitch(switches::kSilentLaunch); |
| 369 | 374 |
| 370 if (!silent_launch) { | 375 if (!silent_launch) { |
| 371 StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); | 376 StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); |
| 372 const std::vector<GURL> urls_to_launch = | 377 bool should_show_desktop_search_infobar = false; |
| 373 GetURLsFromCommandLine(command_line, cur_dir, profile); | 378 const std::vector<GURL> urls_to_launch = GetURLsFromCommandLine( |
| 379 command_line, cur_dir, profile, &should_show_desktop_search_infobar); | |
| 374 chrome::HostDesktopType host_desktop_type = | 380 chrome::HostDesktopType host_desktop_type = |
| 375 chrome::HOST_DESKTOP_TYPE_NATIVE; | 381 chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 376 | 382 |
| 377 #if defined(USE_ASH) && !defined(OS_CHROMEOS) | 383 #if defined(USE_ASH) && !defined(OS_CHROMEOS) |
| 378 // We want to maintain only one type of instance for now, either ASH | 384 // We want to maintain only one type of instance for now, either ASH |
| 379 // or desktop. | 385 // or desktop. |
| 380 // TODO(shrikant): Remove this code once we decide on running both desktop | 386 // TODO(shrikant): Remove this code once we decide on running both desktop |
| 381 // and ASH instances side by side. | 387 // and ASH instances side by side. |
| 382 if (ash::Shell::HasInstance()) | 388 if (ash::Shell::HasInstance()) |
| 383 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | 389 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| 384 #endif | 390 #endif |
| 385 | 391 |
| 386 const bool launched = lwp.Launch(profile, urls_to_launch, | 392 const bool launched = lwp.Launch(profile, urls_to_launch, |
| 387 in_synchronous_profile_launch_, | 393 in_synchronous_profile_launch_, |
| 388 host_desktop_type); | 394 host_desktop_type); |
| 389 in_synchronous_profile_launch_ = false; | 395 in_synchronous_profile_launch_ = false; |
| 390 if (!launched) { | 396 if (!launched) { |
| 391 LOG(ERROR) << "launch error"; | 397 LOG(ERROR) << "launch error"; |
| 392 return false; | 398 return false; |
| 393 } | 399 } |
| 400 | |
| 401 #if defined(OS_WIN) | |
| 402 if (should_show_desktop_search_infobar) { | |
| 403 // Show an infobar informing the user that a desktop search has been | |
| 404 // redirected to the default search engine. | |
| 405 Browser* browser = | |
| 406 BrowserList::GetInstance(host_desktop_type)->GetLastActive(); | |
|
Peter Kasting
2016/01/20 03:03:01
We ultimately only need this in order to get the a
fdoray
2016/01/21 21:02:33
Done. I moved this code to StartupBrowserCreatorIm
| |
| 407 if (browser) { | |
|
Peter Kasting
2016/01/20 03:03:01
When can this be null?
fdoray
2016/01/21 21:02:33
chrome.exe --no-startup-window
| |
| 408 WindowsDesktopSearchInfobarDelegate::Show( | |
| 409 InfoBarService::FromWebContents( | |
| 410 browser->tab_strip_model()->GetActiveWebContents()), | |
| 411 TemplateURLServiceFactory::GetForProfile(profile) | |
| 412 ->GetDefaultSearchProvider() | |
| 413 ->AdjustedShortNameForLocaleDirection(), | |
| 414 GURL(std::string(chrome::kChromeUISettingsURL) + | |
| 415 chrome::kSearchEnginesSubPage), | |
| 416 profile->GetPrefs()); | |
| 417 } | |
| 418 } | |
| 419 #endif // defined(OS_WIN) | |
| 394 } else { | 420 } else { |
| 395 in_synchronous_profile_launch_ = false; | 421 in_synchronous_profile_launch_ = false; |
| 396 } | 422 } |
| 397 | 423 |
| 398 profile_launch_observer.Get().AddLaunched(profile); | 424 profile_launch_observer.Get().AddLaunched(profile); |
| 399 | 425 |
| 400 #if defined(OS_CHROMEOS) | 426 #if defined(OS_CHROMEOS) |
| 401 chromeos::ProfileHelper::Get()->ProfileStartup(profile, process_startup); | 427 chromeos::ProfileHelper::Get()->ProfileStartup(profile, process_startup); |
| 402 #endif | 428 #endif |
| 403 return true; | 429 return true; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 // static | 548 // static |
| 523 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() { | 549 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() { |
| 524 return kSetDefaultBrowserHelpUrl; | 550 return kSetDefaultBrowserHelpUrl; |
| 525 } | 551 } |
| 526 #endif // defined(OS_WIN) | 552 #endif // defined(OS_WIN) |
| 527 | 553 |
| 528 // static | 554 // static |
| 529 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( | 555 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( |
| 530 const base::CommandLine& command_line, | 556 const base::CommandLine& command_line, |
| 531 const base::FilePath& cur_dir, | 557 const base::FilePath& cur_dir, |
| 532 Profile* profile) { | 558 Profile* profile, |
| 559 bool* should_show_desktop_search_infobar) { | |
| 560 DCHECK(profile); | |
| 561 DCHECK(should_show_desktop_search_infobar); | |
| 562 | |
| 533 std::vector<GURL> urls; | 563 std::vector<GURL> urls; |
| 534 | 564 |
| 535 const base::CommandLine::StringVector& params = command_line.GetArgs(); | 565 const base::CommandLine::StringVector& params = command_line.GetArgs(); |
| 536 for (size_t i = 0; i < params.size(); ++i) { | 566 for (size_t i = 0; i < params.size(); ++i) { |
| 537 base::FilePath param = base::FilePath(params[i]); | 567 base::FilePath param = base::FilePath(params[i]); |
| 538 // Handle Vista way of searching - "? <search-term>" | 568 // Handle Vista way of searching - "? <search-term>" |
| 539 if ((param.value().size() > 2) && (param.value()[0] == '?') && | 569 if ((param.value().size() > 2) && (param.value()[0] == '?') && |
| 540 (param.value()[1] == ' ')) { | 570 (param.value()[1] == ' ')) { |
| 541 GURL url(GetDefaultSearchURLForSearchTerms( | 571 GURL url(GetDefaultSearchURLForSearchTerms( |
| 542 TemplateURLServiceFactory::GetForProfile(profile), | 572 TemplateURLServiceFactory::GetForProfile(profile), |
| 543 param.LossyDisplayName().substr(2))); | 573 param.LossyDisplayName().substr(2))); |
| 544 if (url.is_valid()) { | 574 if (url.is_valid()) { |
| 545 urls.push_back(url); | 575 urls.push_back(url); |
| 546 continue; | 576 continue; |
| 547 } | 577 } |
| 548 } | 578 } |
| 549 | 579 |
| 550 // Otherwise, fall through to treating it as a URL. | 580 // Otherwise, fall through to treating it as a URL. |
| 551 | 581 |
| 552 // This will create a file URL or a regular URL. | 582 // This will create a file URL or a regular URL. |
| 553 // This call can (in rare circumstances) block the UI thread. | 583 // This call can (in rare circumstances) block the UI thread. |
| 554 // Allow it until this bug is fixed. | 584 // Allow it until this bug is fixed. |
| 555 // http://code.google.com/p/chromium/issues/detail?id=60641 | 585 // http://code.google.com/p/chromium/issues/detail?id=60641 |
| 556 GURL url = GURL(param.MaybeAsASCII()); | 586 GURL url = GURL(param.MaybeAsASCII()); |
| 557 | 587 |
| 558 #if defined(OS_WIN) | 588 #if defined(OS_WIN) |
| 559 if (ShouldRedirectWindowsDesktopSearchToDefaultSearchEngine( | 589 // Replace desktop search URL by a default search engine URL if needed. |
| 560 profile->GetPrefs())) { | 590 // Ignore cases where there is multiple command line arguments, because |
|
Peter Kasting
2016/01/20 03:03:01
Nit: is -> are
fdoray
2016/01/21 21:02:33
Done.
| |
| 561 TemplateURLService* template_url_service = | 591 // desktop search never passes multiple URLs to the browser. |
| 562 TemplateURLServiceFactory::GetForProfile(profile); | 592 if (params.size() == 1) { |
| 563 DCHECK(template_url_service); | 593 ReplaceWindowsDesktopSearchURLWithDefaultSearchURLIfNeeded( |
| 564 base::string16 search_terms; | 594 profile->GetPrefs(), |
| 565 if (DetectWindowsDesktopSearch( | 595 TemplateURLServiceFactory::GetForProfile(profile), &url, |
| 566 url, template_url_service->search_terms_data(), &search_terms)) { | 596 should_show_desktop_search_infobar); |
| 567 const GURL search_url(GetDefaultSearchURLForSearchTerms( | |
| 568 template_url_service, search_terms)); | |
| 569 if (search_url.is_valid()) { | |
| 570 urls.push_back(search_url); | |
| 571 continue; | |
| 572 } | |
| 573 } | |
| 574 } | 597 } |
| 575 #endif // defined(OS_WIN) | 598 #endif // defined(OS_WIN) |
| 576 | 599 |
| 577 // http://crbug.com/371030: Only use URLFixerUpper if we don't have a valid | 600 // http://crbug.com/371030: Only use URLFixerUpper if we don't have a valid |
| 578 // URL, otherwise we will look in the current directory for a file named | 601 // URL, otherwise we will look in the current directory for a file named |
| 579 // 'about' if the browser was started with a about:foo argument. | 602 // 'about' if the browser was started with a about:foo argument. |
| 580 if (!url.is_valid()) { | 603 if (!url.is_valid()) { |
| 581 base::ThreadRestrictions::ScopedAllowIO allow_io; | 604 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 582 url = url_formatter::FixupRelativeFile(cur_dir, param); | 605 url = url_formatter::FixupRelativeFile(cur_dir, param); |
| 583 } | 606 } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 // If we are showing the app list then chrome isn't shown so load the app | 955 // If we are showing the app list then chrome isn't shown so load the app |
| 933 // list's profile rather than chrome's. | 956 // list's profile rather than chrome's. |
| 934 if (command_line.HasSwitch(switches::kShowAppList)) { | 957 if (command_line.HasSwitch(switches::kShowAppList)) { |
| 935 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 958 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
| 936 GetProfilePath(user_data_dir); | 959 GetProfilePath(user_data_dir); |
| 937 } | 960 } |
| 938 | 961 |
| 939 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 962 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 940 user_data_dir); | 963 user_data_dir); |
| 941 } | 964 } |
| OLD | NEW |