| 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 "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 UpdateMode(false); | 85 UpdateMode(false); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void SearchTabHelper::NavigationEntryUpdated() { | 88 void SearchTabHelper::NavigationEntryUpdated() { |
| 89 if (!is_search_enabled_) | 89 if (!is_search_enabled_) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 UpdateMode(false); | 92 UpdateMode(false); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool SearchTabHelper::UpdateLastKnownMostVisitedItems( | |
| 96 const std::vector<InstantMostVisitedItem>& items) { | |
| 97 if (chrome::AreMostVisitedItemsEqual(items, last_known_most_visited_items_)) | |
| 98 return false; | |
| 99 | |
| 100 last_known_most_visited_items_ = items; | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 void SearchTabHelper::InstantSupportChanged(bool instant_support) { | 95 void SearchTabHelper::InstantSupportChanged(bool instant_support) { |
| 105 if (!is_search_enabled_) | 96 if (!is_search_enabled_) |
| 106 return; | 97 return; |
| 107 | 98 |
| 108 model_.SetInstantSupportState(instant_support ? INSTANT_SUPPORT_YES : | 99 model_.SetInstantSupportState(instant_support ? INSTANT_SUPPORT_YES : |
| 109 INSTANT_SUPPORT_NO); | 100 INSTANT_SUPPORT_NO); |
| 110 } | 101 } |
| 111 | 102 |
| 112 bool SearchTabHelper::SupportsInstant() const { | 103 bool SearchTabHelper::SupportsInstant() const { |
| 113 return model_.instant_support() == INSTANT_SUPPORT_YES; | 104 return model_.instant_support() == INSTANT_SUPPORT_YES; |
| 114 } | 105 } |
| 115 | 106 |
| 116 void SearchTabHelper::Observe( | 107 void SearchTabHelper::Observe( |
| 117 int type, | 108 int type, |
| 118 const content::NotificationSource& source, | 109 const content::NotificationSource& source, |
| 119 const content::NotificationDetails& details) { | 110 const content::NotificationDetails& details) { |
| 120 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | 111 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
| 121 content::LoadCommittedDetails* load_details = | 112 content::LoadCommittedDetails* load_details = |
| 122 content::Details<content::LoadCommittedDetails>(details).ptr(); | 113 content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 123 if (!load_details->is_main_frame) | 114 if (!load_details->is_main_frame) |
| 124 return; | 115 return; |
| 125 | 116 |
| 126 UpdateMode(true); | 117 UpdateMode(true); |
| 127 last_known_most_visited_items_.clear(); | |
| 128 | 118 |
| 129 // Already determined the instant support state for this page, do not reset | 119 // Already determined the instant support state for this page, do not reset |
| 130 // the instant support state. | 120 // the instant support state. |
| 131 // | 121 // |
| 132 // When we get a navigation entry committed event, there seem to be two ways | 122 // When we get a navigation entry committed event, there seem to be two ways |
| 133 // to tell whether the navigation was "in-page". Ideally, when | 123 // to tell whether the navigation was "in-page". Ideally, when |
| 134 // LoadCommittedDetails::is_in_page is true, we should have | 124 // LoadCommittedDetails::is_in_page is true, we should have |
| 135 // LoadCommittedDetails::type to be NAVIGATION_TYPE_IN_PAGE. Unfortunately, | 125 // LoadCommittedDetails::type to be NAVIGATION_TYPE_IN_PAGE. Unfortunately, |
| 136 // they are different in some cases. To workaround this bug, we are checking | 126 // they are different in some cases. To workaround this bug, we are checking |
| 137 // (is_in_page || type == NAVIGATION_TYPE_IN_PAGE). Please refer to | 127 // (is_in_page || type == NAVIGATION_TYPE_IN_PAGE). Please refer to |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (web_contents()->IsActiveEntry(page_id)) { | 249 if (web_contents()->IsActiveEntry(page_id)) { |
| 260 model_.SetTopBarsVisible(false); | 250 model_.SetTopBarsVisible(false); |
| 261 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); | 251 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); |
| 262 } | 252 } |
| 263 } | 253 } |
| 264 | 254 |
| 265 void SearchTabHelper::OnSetVoiceSearchSupported(int page_id, bool supported) { | 255 void SearchTabHelper::OnSetVoiceSearchSupported(int page_id, bool supported) { |
| 266 if (web_contents()->IsActiveEntry(page_id)) | 256 if (web_contents()->IsActiveEntry(page_id)) |
| 267 model_.SetVoiceSearchSupported(supported); | 257 model_.SetVoiceSearchSupported(supported); |
| 268 } | 258 } |
| OLD | NEW |