Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 1598553003: Implement the Windows desktop search redirection feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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();
407 DCHECK(browser);
Alexei Svitkine (slow) 2016/01/18 16:08:51 What guarantees this is true? I see an |in_synchro
fdoray 2016/01/18 18:51:45 I changed the code to handle cases where |browser|
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 }
417 #endif // defined(OS_WIN)
394 } else { 418 } else {
395 in_synchronous_profile_launch_ = false; 419 in_synchronous_profile_launch_ = false;
396 } 420 }
397 421
398 profile_launch_observer.Get().AddLaunched(profile); 422 profile_launch_observer.Get().AddLaunched(profile);
399 423
400 #if defined(OS_CHROMEOS) 424 #if defined(OS_CHROMEOS)
401 chromeos::ProfileHelper::Get()->ProfileStartup(profile, process_startup); 425 chromeos::ProfileHelper::Get()->ProfileStartup(profile, process_startup);
402 #endif 426 #endif
403 return true; 427 return true;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // static 546 // static
523 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() { 547 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() {
524 return kSetDefaultBrowserHelpUrl; 548 return kSetDefaultBrowserHelpUrl;
525 } 549 }
526 #endif // defined(OS_WIN) 550 #endif // defined(OS_WIN)
527 551
528 // static 552 // static
529 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 553 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
530 const base::CommandLine& command_line, 554 const base::CommandLine& command_line,
531 const base::FilePath& cur_dir, 555 const base::FilePath& cur_dir,
532 Profile* profile) { 556 Profile* profile,
557 bool* should_show_desktop_search_infobar) {
558 DCHECK(profile);
559 DCHECK(should_show_desktop_search_infobar);
560
533 std::vector<GURL> urls; 561 std::vector<GURL> urls;
534 562
535 const base::CommandLine::StringVector& params = command_line.GetArgs(); 563 const base::CommandLine::StringVector& params = command_line.GetArgs();
536 for (size_t i = 0; i < params.size(); ++i) { 564 for (size_t i = 0; i < params.size(); ++i) {
537 base::FilePath param = base::FilePath(params[i]); 565 base::FilePath param = base::FilePath(params[i]);
538 // Handle Vista way of searching - "? <search-term>" 566 // Handle Vista way of searching - "? <search-term>"
539 if ((param.value().size() > 2) && (param.value()[0] == '?') && 567 if ((param.value().size() > 2) && (param.value()[0] == '?') &&
540 (param.value()[1] == ' ')) { 568 (param.value()[1] == ' ')) {
541 GURL url(GetDefaultSearchURLForSearchTerms( 569 GURL url(GetDefaultSearchURLForSearchTerms(
542 TemplateURLServiceFactory::GetForProfile(profile), 570 TemplateURLServiceFactory::GetForProfile(profile),
543 param.LossyDisplayName().substr(2))); 571 param.LossyDisplayName().substr(2)));
544 if (url.is_valid()) { 572 if (url.is_valid()) {
545 urls.push_back(url); 573 urls.push_back(url);
546 continue; 574 continue;
547 } 575 }
548 } 576 }
549 577
550 // Otherwise, fall through to treating it as a URL. 578 // Otherwise, fall through to treating it as a URL.
551 579
552 // This will create a file URL or a regular URL. 580 // This will create a file URL or a regular URL.
553 // This call can (in rare circumstances) block the UI thread. 581 // This call can (in rare circumstances) block the UI thread.
554 // Allow it until this bug is fixed. 582 // Allow it until this bug is fixed.
555 // http://code.google.com/p/chromium/issues/detail?id=60641 583 // http://code.google.com/p/chromium/issues/detail?id=60641
556 GURL url = GURL(param.MaybeAsASCII()); 584 GURL url = GURL(param.MaybeAsASCII());
557 585
558 #if defined(OS_WIN) 586 #if defined(OS_WIN)
559 if (ShouldRedirectWindowsDesktopSearchToDefaultSearchEngine( 587 // Replace desktop search URL by a default search engine URL if needed.
560 profile->GetPrefs())) { 588 // Ignore cases where there is multiple command line arguments, because
561 TemplateURLService* template_url_service = 589 // desktop search never passes multiple URLs to the browser.
562 TemplateURLServiceFactory::GetForProfile(profile); 590 if (params.size() == 1) {
563 DCHECK(template_url_service); 591 ReplaceWindowsDesktopSearchURLWithDefaultSearchURLIfNeeded(
564 base::string16 search_terms; 592 profile->GetPrefs(),
565 if (DetectWindowsDesktopSearch( 593 TemplateURLServiceFactory::GetForProfile(profile), &url,
566 url, template_url_service->search_terms_data(), &search_terms)) { 594 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 } 595 }
575 #endif // defined(OS_WIN) 596 #endif // defined(OS_WIN)
576 597
577 // http://crbug.com/371030: Only use URLFixerUpper if we don't have a valid 598 // 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 599 // 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. 600 // 'about' if the browser was started with a about:foo argument.
580 if (!url.is_valid()) { 601 if (!url.is_valid()) {
581 base::ThreadRestrictions::ScopedAllowIO allow_io; 602 base::ThreadRestrictions::ScopedAllowIO allow_io;
582 url = url_formatter::FixupRelativeFile(cur_dir, param); 603 url = url_formatter::FixupRelativeFile(cur_dir, param);
583 } 604 }
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 // If we are showing the app list then chrome isn't shown so load the app 953 // If we are showing the app list then chrome isn't shown so load the app
933 // list's profile rather than chrome's. 954 // list's profile rather than chrome's.
934 if (command_line.HasSwitch(switches::kShowAppList)) { 955 if (command_line.HasSwitch(switches::kShowAppList)) {
935 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 956 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
936 GetProfilePath(user_data_dir); 957 GetProfilePath(user_data_dir);
937 } 958 }
938 959
939 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 960 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
940 user_data_dir); 961 user_data_dir);
941 } 962 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698