| 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 <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // We can't use WebContents::GetURL() because that uses the active entry, | 67 // We can't use WebContents::GetURL() because that uses the active entry, |
| 68 // whereas we want the visible entry. | 68 // whereas we want the visible entry. |
| 69 const content::NavigationEntry* entry = | 69 const content::NavigationEntry* entry = |
| 70 contents->GetController().GetVisibleEntry(); | 70 contents->GetController().GetVisibleEntry(); |
| 71 if (entry && entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL)) | 71 if (entry && entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL)) |
| 72 return true; | 72 return true; |
| 73 | 73 |
| 74 return search::IsInstantNTP(contents); | 74 return search::IsInstantNTP(contents); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool IsSearchResults(const content::WebContents* contents) { | |
| 78 return !search::GetSearchTerms(contents).empty(); | |
| 79 } | |
| 80 | |
| 81 bool IsLocal(const content::WebContents* contents) { | 77 bool IsLocal(const content::WebContents* contents) { |
| 82 if (!contents) | 78 if (!contents) |
| 83 return false; | 79 return false; |
| 84 const content::NavigationEntry* entry = | 80 const content::NavigationEntry* entry = |
| 85 contents->GetController().GetVisibleEntry(); | 81 contents->GetController().GetVisibleEntry(); |
| 86 return entry && entry->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); | 82 return entry && entry->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); |
| 87 } | 83 } |
| 88 | 84 |
| 89 // Returns true if |contents| are rendered inside an Instant process. | 85 // Returns true if |contents| are rendered inside an Instant process. |
| 90 bool InInstantProcess(Profile* profile, | 86 bool InInstantProcess(Profile* profile, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 DCHECK(entry); | 286 DCHECK(entry); |
| 291 | 287 |
| 292 // Already determined the instant support state for this page, do not reset | 288 // Already determined the instant support state for this page, do not reset |
| 293 // the instant support state. | 289 // the instant support state. |
| 294 if (load_details.is_in_page) { | 290 if (load_details.is_in_page) { |
| 295 // When an "in-page" navigation happens, we will not receive a | 291 // When an "in-page" navigation happens, we will not receive a |
| 296 // DidFinishLoad() event. Therefore, we will not determine the Instant | 292 // DidFinishLoad() event. Therefore, we will not determine the Instant |
| 297 // support for the navigated page. So, copy over the Instant support from | 293 // support for the navigated page. So, copy over the Instant support from |
| 298 // the previous entry. If the page does not support Instant, update the | 294 // the previous entry. If the page does not support Instant, update the |
| 299 // location bar from here to turn off search terms replacement. | 295 // location bar from here to turn off search terms replacement. |
| 300 search::SetInstantSupportStateInNavigationEntry(model_.instant_support(), | |
| 301 entry); | |
| 302 if (delegate_ && model_.instant_support() == INSTANT_SUPPORT_NO) | 296 if (delegate_ && model_.instant_support() == INSTANT_SUPPORT_NO) |
| 303 delegate_->OnWebContentsInstantSupportDisabled(web_contents_); | 297 delegate_->OnWebContentsInstantSupportDisabled(web_contents_); |
| 304 return; | 298 return; |
| 305 } | 299 } |
| 306 | 300 |
| 307 model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN); | 301 model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN); |
| 308 search::SetInstantSupportStateInNavigationEntry(model_.instant_support(), | |
| 309 entry); | |
| 310 | 302 |
| 311 if (InInstantProcess(profile(), web_contents_)) | 303 if (InInstantProcess(profile(), web_contents_)) |
| 312 ipc_router_.OnNavigationEntryCommitted(); | 304 ipc_router_.OnNavigationEntryCommitted(); |
| 313 } | 305 } |
| 314 | 306 |
| 315 void SearchTabHelper::OnInstantSupportDetermined(bool supports_instant) { | 307 void SearchTabHelper::OnInstantSupportDetermined(bool supports_instant) { |
| 316 InstantSupportChanged(supports_instant); | 308 InstantSupportChanged(supports_instant); |
| 317 } | 309 } |
| 318 | 310 |
| 319 void SearchTabHelper::ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) { | 311 void SearchTabHelper::ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 446 |
| 455 void SearchTabHelper::InstantSupportChanged(bool instant_support) { | 447 void SearchTabHelper::InstantSupportChanged(bool instant_support) { |
| 456 if (!is_search_enabled_) | 448 if (!is_search_enabled_) |
| 457 return; | 449 return; |
| 458 | 450 |
| 459 InstantSupportState new_state = instant_support ? INSTANT_SUPPORT_YES : | 451 InstantSupportState new_state = instant_support ? INSTANT_SUPPORT_YES : |
| 460 INSTANT_SUPPORT_NO; | 452 INSTANT_SUPPORT_NO; |
| 461 | 453 |
| 462 model_.SetInstantSupportState(new_state); | 454 model_.SetInstantSupportState(new_state); |
| 463 | 455 |
| 464 content::NavigationEntry* entry = | 456 if (web_contents_->GetController().GetLastCommittedEntry() && delegate_ && |
| 465 web_contents_->GetController().GetLastCommittedEntry(); | 457 !instant_support) { |
| 466 if (entry) { | 458 delegate_->OnWebContentsInstantSupportDisabled(web_contents_); |
| 467 search::SetInstantSupportStateInNavigationEntry(new_state, entry); | |
| 468 if (delegate_ && !instant_support) | |
| 469 delegate_->OnWebContentsInstantSupportDisabled(web_contents_); | |
| 470 } | 459 } |
| 471 } | 460 } |
| 472 | 461 |
| 473 void SearchTabHelper::UpdateMode(bool update_origin) { | 462 void SearchTabHelper::UpdateMode(bool update_origin) { |
| 474 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 463 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 475 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 464 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 476 if (IsNTP(web_contents_)) { | 465 if (IsNTP(web_contents_)) { |
| 477 type = SearchMode::MODE_NTP; | 466 type = SearchMode::MODE_NTP; |
| 478 origin = SearchMode::ORIGIN_NTP; | 467 origin = SearchMode::ORIGIN_NTP; |
| 479 } else if (IsSearchResults(web_contents_)) { | |
| 480 type = SearchMode::MODE_SEARCH_RESULTS; | |
| 481 origin = SearchMode::ORIGIN_SEARCH; | |
| 482 } | 468 } |
| 483 if (!update_origin) | 469 if (!update_origin) |
| 484 origin = model_.mode().origin; | 470 origin = model_.mode().origin; |
| 485 | 471 |
| 486 OmniboxView* omnibox = GetOmniboxView(); | 472 OmniboxView* omnibox = GetOmniboxView(); |
| 487 if (omnibox && omnibox->model()->user_input_in_progress()) | 473 if (omnibox && omnibox->model()->user_input_in_progress()) |
| 488 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 474 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 489 | 475 |
| 490 SearchMode old_mode(model_.mode()); | 476 SearchMode old_mode(model_.mode()); |
| 491 model_.SetMode(SearchMode(type, origin)); | 477 model_.SetMode(SearchMode(type, origin)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 515 | 501 |
| 516 bool SearchTabHelper::IsInputInProgress() const { | 502 bool SearchTabHelper::IsInputInProgress() const { |
| 517 OmniboxView* omnibox = GetOmniboxView(); | 503 OmniboxView* omnibox = GetOmniboxView(); |
| 518 return !model_.mode().is_ntp() && omnibox && | 504 return !model_.mode().is_ntp() && omnibox && |
| 519 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 505 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
| 520 } | 506 } |
| 521 | 507 |
| 522 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 508 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
| 523 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 509 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
| 524 } | 510 } |
| OLD | NEW |