Index: chrome/browser/ui/startup/startup_browser_creator.cc |
diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc |
index 72487b014c39a1440800051a943cef9114e7ccd1..b4f29ac05d104ea34e5069fe31774eed707dd0b4 100644 |
--- a/chrome/browser/ui/startup/startup_browser_creator.cc |
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc |
@@ -95,8 +95,13 @@ |
#endif |
#if defined(OS_WIN) |
+#include "chrome/browser/infobars/infobar_service.h" |
#include "chrome/browser/metrics/jumplist_metrics_win.h" |
-#include "components/search_engines/desktop_search_win.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "components/search_engines/desktop_search_infobar_delegate_win.h" |
+#include "components/search_engines/desktop_search_utils_win.h" |
+#include "components/search_engines/template_url.h" |
#endif |
#if defined(ENABLE_PRINT_PREVIEW) |
@@ -369,8 +374,9 @@ bool StartupBrowserCreator::LaunchBrowser( |
if (!silent_launch) { |
StartupBrowserCreatorImpl lwp(cur_dir, command_line, this, is_first_run); |
- const std::vector<GURL> urls_to_launch = |
- GetURLsFromCommandLine(command_line, cur_dir, profile); |
+ bool should_show_desktop_search_infobar = false; |
+ const std::vector<GURL> urls_to_launch = GetURLsFromCommandLine( |
+ command_line, cur_dir, profile, &should_show_desktop_search_infobar); |
chrome::HostDesktopType host_desktop_type = |
chrome::HOST_DESKTOP_TYPE_NATIVE; |
@@ -391,6 +397,24 @@ bool StartupBrowserCreator::LaunchBrowser( |
LOG(ERROR) << "launch error"; |
return false; |
} |
+ |
+#if defined(OS_WIN) |
+ if (should_show_desktop_search_infobar) { |
+ // Show an infobar informing the user that a desktop search has been |
+ // redirected to the default search engine. |
+ Browser* browser = |
+ BrowserList::GetInstance(host_desktop_type)->GetLastActive(); |
+ 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|
|
+ WindowsDesktopSearchInfobarDelegate::Show( |
+ InfoBarService::FromWebContents( |
+ browser->tab_strip_model()->GetActiveWebContents()), |
+ TemplateURLServiceFactory::GetForProfile(profile) |
+ ->GetDefaultSearchProvider() |
+ ->AdjustedShortNameForLocaleDirection(), |
+ GURL(std::string(chrome::kChromeUISettingsURL) + |
+ chrome::kSearchEnginesSubPage)); |
+ } |
+#endif // defined(OS_WIN) |
} else { |
in_synchronous_profile_launch_ = false; |
} |
@@ -529,7 +553,11 @@ const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() { |
std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( |
const base::CommandLine& command_line, |
const base::FilePath& cur_dir, |
- Profile* profile) { |
+ Profile* profile, |
+ bool* should_show_desktop_search_infobar) { |
+ DCHECK(profile); |
+ DCHECK(should_show_desktop_search_infobar); |
+ |
std::vector<GURL> urls; |
const base::CommandLine::StringVector& params = command_line.GetArgs(); |
@@ -556,21 +584,14 @@ std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( |
GURL url = GURL(param.MaybeAsASCII()); |
#if defined(OS_WIN) |
- if (ShouldRedirectWindowsDesktopSearchToDefaultSearchEngine( |
- profile->GetPrefs())) { |
- TemplateURLService* template_url_service = |
- TemplateURLServiceFactory::GetForProfile(profile); |
- DCHECK(template_url_service); |
- base::string16 search_terms; |
- if (DetectWindowsDesktopSearch( |
- url, template_url_service->search_terms_data(), &search_terms)) { |
- const GURL search_url(GetDefaultSearchURLForSearchTerms( |
- template_url_service, search_terms)); |
- if (search_url.is_valid()) { |
- urls.push_back(search_url); |
- continue; |
- } |
- } |
+ // Replace desktop search URL by a default search engine URL if needed. |
+ // Ignore cases where there is multiple command line arguments, because |
+ // desktop search never passes multiple URLs to the browser. |
+ if (params.size() == 1) { |
+ ReplaceWindowsDesktopSearchURLWithDefaultSearchURLIfNeeded( |
+ profile->GetPrefs(), |
+ TemplateURLServiceFactory::GetForProfile(profile), &url, |
+ should_show_desktop_search_infobar); |
} |
#endif // defined(OS_WIN) |