| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "build/build_config.h" | |
| 14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/history/most_visited_tiles_experiment.h" | 14 #include "chrome/browser/history/most_visited_tiles_experiment.h" |
| 16 #include "chrome/browser/history/top_sites.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/search/instant_service.h" | 16 #include "chrome/browser/search/instant_service.h" |
| 19 #include "chrome/browser/search/instant_service_factory.h" | 17 #include "chrome/browser/search/instant_service_factory.h" |
| 20 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/browser/ui/app_list/app_list_util.h" | 20 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 23 #include "chrome/browser/ui/browser.h" | |
| 24 #include "chrome/browser/ui/browser_finder.h" | |
| 25 #include "chrome/browser/ui/browser_navigator.h" | 21 #include "chrome/browser/ui/browser_navigator.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/omnibox/location_bar.h" | 23 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 28 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 24 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 29 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 25 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 30 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 26 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 31 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" | 27 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" |
| 28 #include "chrome/browser/ui/search/search_tab_helper_delegate.h" |
| 32 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 29 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" | |
| 35 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 30 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
| 36 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 37 #include "components/signin/core/browser/signin_manager.h" | 32 #include "components/signin/core/browser/signin_manager.h" |
| 38 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/navigation_details.h" | 34 #include "content/public/browser/navigation_details.h" |
| 40 #include "content/public/browser/navigation_entry.h" | 35 #include "content/public/browser/navigation_entry.h" |
| 41 #include "content/public/browser/navigation_type.h" | 36 #include "content/public/browser/navigation_type.h" |
| 42 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
| 44 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (!profile || !contents) | 101 if (!profile || !contents) |
| 107 return false; | 102 return false; |
| 108 | 103 |
| 109 InstantService* instant_service = | 104 InstantService* instant_service = |
| 110 InstantServiceFactory::GetForProfile(profile); | 105 InstantServiceFactory::GetForProfile(profile); |
| 111 return instant_service && | 106 return instant_service && |
| 112 instant_service->IsInstantProcess( | 107 instant_service->IsInstantProcess( |
| 113 contents->GetRenderProcessHost()->GetID()); | 108 contents->GetRenderProcessHost()->GetID()); |
| 114 } | 109 } |
| 115 | 110 |
| 116 // Updates the location bar to reflect |contents| Instant support state. | |
| 117 void UpdateLocationBar(content::WebContents* contents) { | |
| 118 // iOS and Android don't use the Instant framework. | |
| 119 #if !defined(OS_IOS) && !defined(OS_ANDROID) | |
| 120 if (!contents) | |
| 121 return; | |
| 122 | |
| 123 Browser* browser = chrome::FindBrowserWithWebContents(contents); | |
| 124 if (!browser) | |
| 125 return; | |
| 126 browser->OnWebContentsInstantSupportDisabled(contents); | |
| 127 #endif | |
| 128 } | |
| 129 | |
| 130 // Called when an NTP finishes loading. If the load start time was noted, | 111 // Called when an NTP finishes loading. If the load start time was noted, |
| 131 // calculates and logs the total load time. | 112 // calculates and logs the total load time. |
| 132 void RecordNewTabLoadTime(content::WebContents* contents) { | 113 void RecordNewTabLoadTime(content::WebContents* contents) { |
| 133 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); | 114 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
| 134 if (core_tab_helper->new_tab_start_time().is_null()) | 115 if (core_tab_helper->new_tab_start_time().is_null()) |
| 135 return; | 116 return; |
| 136 | 117 |
| 137 base::TimeDelta duration = | 118 base::TimeDelta duration = |
| 138 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); | 119 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); |
| 139 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); | 120 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
| 140 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); | 121 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); |
| 141 } | 122 } |
| 142 | 123 |
| 143 // Returns the OmniboxView for |contents| or NULL if not available. | |
| 144 OmniboxView* GetOmniboxView(content::WebContents* contents) { | |
| 145 // iOS and Android don't use the Instant framework. | |
| 146 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 147 return NULL; | |
| 148 #else | |
| 149 if (!contents) | |
| 150 return NULL; | |
| 151 Browser* browser = chrome::FindBrowserWithWebContents(contents); | |
| 152 return browser ? browser->window()->GetLocationBar()->GetOmniboxView() : NULL; | |
| 153 #endif | |
| 154 } | |
| 155 | |
| 156 } // namespace | 124 } // namespace |
| 157 | 125 |
| 158 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) | 126 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) |
| 159 : WebContentsObserver(web_contents), | 127 : WebContentsObserver(web_contents), |
| 160 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), | 128 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), |
| 161 web_contents_(web_contents), | 129 web_contents_(web_contents), |
| 162 ipc_router_(web_contents, this, | 130 ipc_router_(web_contents, this, |
| 163 make_scoped_ptr(new SearchIPCRouterPolicyImpl(web_contents)) | 131 make_scoped_ptr(new SearchIPCRouterPolicyImpl(web_contents)) |
| 164 .PassAs<SearchIPCRouter::Policy>()), | 132 .PassAs<SearchIPCRouter::Policy>()), |
| 165 instant_service_(NULL) { | 133 instant_service_(NULL), |
| 134 delegate_(NULL) { |
| 166 if (!is_search_enabled_) | 135 if (!is_search_enabled_) |
| 167 return; | 136 return; |
| 168 | 137 |
| 169 instant_service_ = | 138 instant_service_ = |
| 170 InstantServiceFactory::GetForProfile( | 139 InstantServiceFactory::GetForProfile( |
| 171 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); | 140 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); |
| 172 if (instant_service_) | 141 if (instant_service_) |
| 173 instant_service_->AddObserver(this); | 142 instant_service_->AddObserver(this); |
| 174 } | 143 } |
| 175 | 144 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 188 |
| 220 InstantSupportState new_state = instant_support ? INSTANT_SUPPORT_YES : | 189 InstantSupportState new_state = instant_support ? INSTANT_SUPPORT_YES : |
| 221 INSTANT_SUPPORT_NO; | 190 INSTANT_SUPPORT_NO; |
| 222 | 191 |
| 223 model_.SetInstantSupportState(new_state); | 192 model_.SetInstantSupportState(new_state); |
| 224 | 193 |
| 225 content::NavigationEntry* entry = | 194 content::NavigationEntry* entry = |
| 226 web_contents_->GetController().GetVisibleEntry(); | 195 web_contents_->GetController().GetVisibleEntry(); |
| 227 if (entry) { | 196 if (entry) { |
| 228 chrome::SetInstantSupportStateInNavigationEntry(new_state, entry); | 197 chrome::SetInstantSupportStateInNavigationEntry(new_state, entry); |
| 229 if (!instant_support) | 198 if (delegate_ && !instant_support) |
| 230 UpdateLocationBar(web_contents_); | 199 delegate_->OnWebContentsInstantSupportDisabled(web_contents_); |
| 231 } | 200 } |
| 232 } | 201 } |
| 233 | 202 |
| 234 bool SearchTabHelper::SupportsInstant() const { | 203 bool SearchTabHelper::SupportsInstant() const { |
| 235 return model_.instant_support() == INSTANT_SUPPORT_YES; | 204 return model_.instant_support() == INSTANT_SUPPORT_YES; |
| 236 } | 205 } |
| 237 | 206 |
| 238 void SearchTabHelper::SetSuggestionToPrefetch( | 207 void SearchTabHelper::SetSuggestionToPrefetch( |
| 239 const InstantSuggestion& suggestion) { | 208 const InstantSuggestion& suggestion) { |
| 240 ipc_router_.SetSuggestionToPrefetch(suggestion); | 209 ipc_router_.SetSuggestionToPrefetch(suggestion); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // crbug.com/251330 for more details. | 344 // crbug.com/251330 for more details. |
| 376 if (load_details.is_in_page || | 345 if (load_details.is_in_page || |
| 377 load_details.type == content::NAVIGATION_TYPE_IN_PAGE) { | 346 load_details.type == content::NAVIGATION_TYPE_IN_PAGE) { |
| 378 // When an "in-page" navigation happens, we will not receive a | 347 // When an "in-page" navigation happens, we will not receive a |
| 379 // DidFinishLoad() event. Therefore, we will not determine the Instant | 348 // DidFinishLoad() event. Therefore, we will not determine the Instant |
| 380 // support for the navigated page. So, copy over the Instant support from | 349 // support for the navigated page. So, copy over the Instant support from |
| 381 // the previous entry. If the page does not support Instant, update the | 350 // the previous entry. If the page does not support Instant, update the |
| 382 // location bar from here to turn off search terms replacement. | 351 // location bar from here to turn off search terms replacement. |
| 383 chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(), | 352 chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(), |
| 384 entry); | 353 entry); |
| 385 if (model_.instant_support() == INSTANT_SUPPORT_NO) | 354 if (delegate_ && model_.instant_support() == INSTANT_SUPPORT_NO) |
| 386 UpdateLocationBar(web_contents_); | 355 delegate_->OnWebContentsInstantSupportDisabled(web_contents_); |
| 387 return; | 356 return; |
| 388 } | 357 } |
| 389 | 358 |
| 390 model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN); | 359 model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN); |
| 391 model_.SetVoiceSearchSupported(false); | 360 model_.SetVoiceSearchSupported(false); |
| 392 chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(), | 361 chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(), |
| 393 entry); | 362 entry); |
| 394 } | 363 } |
| 395 | 364 |
| 396 void SearchTabHelper::OnInstantSupportDetermined(bool supports_instant) { | 365 void SearchTabHelper::OnInstantSupportDetermined(bool supports_instant) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 411 MaybeRemoveMostVisitedItems(&items_copy); | 380 MaybeRemoveMostVisitedItems(&items_copy); |
| 412 ipc_router_.SendMostVisitedItems(items_copy); | 381 ipc_router_.SendMostVisitedItems(items_copy); |
| 413 } | 382 } |
| 414 | 383 |
| 415 void SearchTabHelper::OmniboxStartMarginChanged(int omnibox_start_margin) { | 384 void SearchTabHelper::OmniboxStartMarginChanged(int omnibox_start_margin) { |
| 416 ipc_router_.SetOmniboxStartMargin(omnibox_start_margin); | 385 ipc_router_.SetOmniboxStartMargin(omnibox_start_margin); |
| 417 } | 386 } |
| 418 | 387 |
| 419 void SearchTabHelper::MaybeRemoveMostVisitedItems( | 388 void SearchTabHelper::MaybeRemoveMostVisitedItems( |
| 420 std::vector<InstantMostVisitedItem>* items) { | 389 std::vector<InstantMostVisitedItem>* items) { |
| 421 // The code below uses APIs not available on Android and the experiment should | 390 if (!delegate_) |
| 422 // not run there. | 391 return; |
| 423 #if !defined(OS_ANDROID) | 392 |
| 424 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) | 393 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) |
| 425 return; | 394 return; |
| 426 | 395 |
| 427 Profile* profile = | |
| 428 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 429 if (!profile) | |
| 430 return; | |
| 431 | |
| 432 Browser* browser = chrome::FindBrowserWithProfile(profile, | |
| 433 chrome::GetActiveDesktop()); | |
| 434 if (!browser) | |
| 435 return; | |
| 436 | |
| 437 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
| 438 history::TopSites* top_sites = profile->GetTopSites(); | |
| 439 if (!tab_strip_model || !top_sites) { | |
| 440 NOTREACHED(); | |
| 441 return; | |
| 442 } | |
| 443 | |
| 444 std::set<std::string> open_urls; | 396 std::set<std::string> open_urls; |
| 445 chrome::GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); | 397 delegate_->GetOpenUrls(&open_urls); |
| 446 history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( | 398 history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs(open_urls, |
| 447 open_urls, items); | 399 items); |
| 448 #endif | |
| 449 } | 400 } |
| 450 | 401 |
| 451 void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { | 402 void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { |
| 452 OmniboxView* omnibox = GetOmniboxView(web_contents()); | 403 OmniboxView* omnibox = GetOmniboxView(); |
| 453 if (!omnibox) | 404 if (!omnibox) |
| 454 return; | 405 return; |
| 455 | 406 |
| 456 // Do not add a default case in the switch block for the following reasons: | 407 // Do not add a default case in the switch block for the following reasons: |
| 457 // (1) Explicitly handle the new states. If new states are added in the | 408 // (1) Explicitly handle the new states. If new states are added in the |
| 458 // OmniboxFocusState, the compiler will warn the developer to handle the new | 409 // OmniboxFocusState, the compiler will warn the developer to handle the new |
| 459 // states. | 410 // states. |
| 460 // (2) An attacker may control the renderer and sends the browser process a | 411 // (2) An attacker may control the renderer and sends the browser process a |
| 461 // malformed IPC. This function responds to the invalid |state| values by | 412 // malformed IPC. This function responds to the invalid |state| values by |
| 462 // doing nothing instead of crashing the browser process (intentional no-op). | 413 // doing nothing instead of crashing the browser process (intentional no-op). |
| (...skipping 19 matching lines...) Expand all Loading... |
| 482 // interaction. | 433 // interaction. |
| 483 if (!omnibox->model()->popup_model()->IsOpen()) | 434 if (!omnibox->model()->popup_model()->IsOpen()) |
| 484 web_contents()->GetView()->Focus(); | 435 web_contents()->GetView()->Focus(); |
| 485 break; | 436 break; |
| 486 } | 437 } |
| 487 } | 438 } |
| 488 | 439 |
| 489 void SearchTabHelper::NavigateToURL(const GURL& url, | 440 void SearchTabHelper::NavigateToURL(const GURL& url, |
| 490 WindowOpenDisposition disposition, | 441 WindowOpenDisposition disposition, |
| 491 bool is_most_visited_item_url) { | 442 bool is_most_visited_item_url) { |
| 492 // iOS and Android don't use the Instant framework. | |
| 493 #if !defined(OS_IOS) && !defined(OS_ANDROID) | |
| 494 // TODO(kmadhusu): Remove chrome::FindBrowser...() function call from here. | |
| 495 // Create a SearchTabHelperDelegate interface and have the Browser object | |
| 496 // implement that interface to provide the necessary functionality. | |
| 497 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | |
| 498 Profile* profile = | |
| 499 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 500 if (!browser || !profile) | |
| 501 return; | |
| 502 | |
| 503 if (is_most_visited_item_url) { | 443 if (is_most_visited_item_url) { |
| 504 content::RecordAction( | 444 content::RecordAction( |
| 505 base::UserMetricsAction("InstantExtended.MostVisitedClicked")); | 445 base::UserMetricsAction("InstantExtended.MostVisitedClicked")); |
| 506 } | 446 } |
| 507 | 447 |
| 508 chrome::NavigateParams params(browser, url, | 448 if (delegate_) |
| 509 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 449 delegate_->NavigateToURL(url, disposition, web_contents_); |
| 510 params.referrer = content::Referrer(); | |
| 511 params.source_contents = web_contents_; | |
| 512 params.disposition = disposition; | |
| 513 params.is_renderer_initiated = false; | |
| 514 params.initiating_profile = profile; | |
| 515 chrome::Navigate(¶ms); | |
| 516 #endif | |
| 517 } | 450 } |
| 518 | 451 |
| 519 void SearchTabHelper::OnDeleteMostVisitedItem(const GURL& url) { | 452 void SearchTabHelper::OnDeleteMostVisitedItem(const GURL& url) { |
| 520 DCHECK(!url.is_empty()); | 453 DCHECK(!url.is_empty()); |
| 521 if (instant_service_) | 454 if (instant_service_) |
| 522 instant_service_->DeleteMostVisitedItem(url); | 455 instant_service_->DeleteMostVisitedItem(url); |
| 523 } | 456 } |
| 524 | 457 |
| 525 void SearchTabHelper::OnUndoMostVisitedDeletion(const GURL& url) { | 458 void SearchTabHelper::OnUndoMostVisitedDeletion(const GURL& url) { |
| 526 DCHECK(!url.is_empty()); | 459 DCHECK(!url.is_empty()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 544 web_contents())->LogMostVisitedImpression(position, provider); | 477 web_contents())->LogMostVisitedImpression(position, provider); |
| 545 } | 478 } |
| 546 | 479 |
| 547 void SearchTabHelper::OnLogMostVisitedNavigation( | 480 void SearchTabHelper::OnLogMostVisitedNavigation( |
| 548 int position, const base::string16& provider) { | 481 int position, const base::string16& provider) { |
| 549 NTPUserDataLogger::GetOrCreateFromWebContents( | 482 NTPUserDataLogger::GetOrCreateFromWebContents( |
| 550 web_contents())->LogMostVisitedNavigation(position, provider); | 483 web_contents())->LogMostVisitedNavigation(position, provider); |
| 551 } | 484 } |
| 552 | 485 |
| 553 void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { | 486 void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { |
| 554 OmniboxView* omnibox = GetOmniboxView(web_contents()); | 487 OmniboxView* omnibox = GetOmniboxView(); |
| 555 if (!omnibox) | 488 if (!omnibox) |
| 556 return; | 489 return; |
| 557 | 490 |
| 558 // The first case is for right click to paste, where the text is retrieved | 491 // The first case is for right click to paste, where the text is retrieved |
| 559 // from the clipboard already sanitized. The second case is needed to handle | 492 // from the clipboard already sanitized. The second case is needed to handle |
| 560 // drag-and-drop value and it has to be sanitazed before setting it into the | 493 // drag-and-drop value and it has to be sanitazed before setting it into the |
| 561 // omnibox. | 494 // omnibox. |
| 562 base::string16 text_to_paste = text.empty() ? omnibox->GetClipboardText() : | 495 base::string16 text_to_paste = text.empty() ? omnibox->GetClipboardText() : |
| 563 omnibox->SanitizeTextForPaste(text); | 496 omnibox->SanitizeTextForPaste(text); |
| 564 | 497 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 590 if (IsNTP(web_contents_) || is_preloaded_ntp) { | 523 if (IsNTP(web_contents_) || is_preloaded_ntp) { |
| 591 type = SearchMode::MODE_NTP; | 524 type = SearchMode::MODE_NTP; |
| 592 origin = SearchMode::ORIGIN_NTP; | 525 origin = SearchMode::ORIGIN_NTP; |
| 593 } else if (IsSearchResults(web_contents_)) { | 526 } else if (IsSearchResults(web_contents_)) { |
| 594 type = SearchMode::MODE_SEARCH_RESULTS; | 527 type = SearchMode::MODE_SEARCH_RESULTS; |
| 595 origin = SearchMode::ORIGIN_SEARCH; | 528 origin = SearchMode::ORIGIN_SEARCH; |
| 596 } | 529 } |
| 597 if (!update_origin) | 530 if (!update_origin) |
| 598 origin = model_.mode().origin; | 531 origin = model_.mode().origin; |
| 599 | 532 |
| 600 OmniboxView* omnibox = GetOmniboxView(web_contents()); | 533 OmniboxView* omnibox = GetOmniboxView(); |
| 601 if (omnibox && omnibox->model()->user_input_in_progress()) | 534 if (omnibox && omnibox->model()->user_input_in_progress()) |
| 602 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 535 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 603 | 536 |
| 604 SearchMode old_mode(model_.mode()); | 537 SearchMode old_mode(model_.mode()); |
| 605 model_.SetMode(SearchMode(type, origin)); | 538 model_.SetMode(SearchMode(type, origin)); |
| 606 if (old_mode.is_ntp() != model_.mode().is_ntp()) { | 539 if (old_mode.is_ntp() != model_.mode().is_ntp()) { |
| 607 ipc_router_.SetInputInProgress(IsInputInProgress()); | 540 ipc_router_.SetInputInProgress(IsInputInProgress()); |
| 608 } | 541 } |
| 609 } | 542 } |
| 610 | 543 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 632 content::NavigationController::LoadURLParams load_params( | 565 content::NavigationController::LoadURLParams load_params( |
| 633 (GURL(chrome::kChromeSearchLocalNtpUrl))); | 566 (GURL(chrome::kChromeSearchLocalNtpUrl))); |
| 634 load_params.referrer = content::Referrer(); | 567 load_params.referrer = content::Referrer(); |
| 635 load_params.transition_type = content::PAGE_TRANSITION_SERVER_REDIRECT; | 568 load_params.transition_type = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 636 // Don't push a history entry. | 569 // Don't push a history entry. |
| 637 load_params.should_replace_current_entry = true; | 570 load_params.should_replace_current_entry = true; |
| 638 web_contents_->GetController().LoadURLWithParams(load_params); | 571 web_contents_->GetController().LoadURLWithParams(load_params); |
| 639 } | 572 } |
| 640 | 573 |
| 641 bool SearchTabHelper::IsInputInProgress() const { | 574 bool SearchTabHelper::IsInputInProgress() const { |
| 642 OmniboxView* omnibox = GetOmniboxView(web_contents()); | 575 OmniboxView* omnibox = GetOmniboxView(); |
| 643 return !model_.mode().is_ntp() && omnibox && | 576 return !model_.mode().is_ntp() && omnibox && |
| 644 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 577 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
| 645 } | 578 } |
| 579 |
| 580 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
| 581 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
| 582 } |
| OLD | NEW |