| 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/renderer/searchbox/searchbox.h" | 5 #include "chrome/renderer/searchbox/searchbox.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 path = path.substr(1); | 136 path = path.substr(1); |
| 137 | 137 |
| 138 return GetInstantRestrictedIDFromPath(render_view_id, path, id); | 138 return GetInstantRestrictedIDFromPath(render_view_id, path, id); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace internal | 141 } // namespace internal |
| 142 | 142 |
| 143 SearchBox::SearchBox(content::RenderView* render_view) | 143 SearchBox::SearchBox(content::RenderView* render_view) |
| 144 : content::RenderViewObserver(render_view), | 144 : content::RenderViewObserver(render_view), |
| 145 content::RenderViewObserverTracker<SearchBox>(render_view), | 145 content::RenderViewObserverTracker<SearchBox>(render_view), |
| 146 page_seq_no_(0), |
| 146 app_launcher_enabled_(false), | 147 app_launcher_enabled_(false), |
| 147 is_focused_(false), | 148 is_focused_(false), |
| 148 is_input_in_progress_(false), | 149 is_input_in_progress_(false), |
| 149 is_key_capture_enabled_(false), | 150 is_key_capture_enabled_(false), |
| 150 display_instant_results_(false), | 151 display_instant_results_(false), |
| 151 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize), | 152 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize), |
| 152 query_(), | 153 query_(), |
| 153 start_margin_(0) { | 154 start_margin_(0) { |
| 154 } | 155 } |
| 155 | 156 |
| 156 SearchBox::~SearchBox() { | 157 SearchBox::~SearchBox() { |
| 157 } | 158 } |
| 158 | 159 |
| 159 void SearchBox::LogEvent(NTPLoggingEventType event) { | 160 void SearchBox::LogEvent(NTPLoggingEventType event) { |
| 160 render_view()->Send(new ChromeViewHostMsg_LogEvent( | 161 render_view()->Send(new ChromeViewHostMsg_LogEvent( |
| 161 render_view()->GetRoutingID(), render_view()->GetPageId(), event)); | 162 render_view()->GetRoutingID(), page_seq_no_, event)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void SearchBox::LogMostVisitedImpression(int position, | 165 void SearchBox::LogMostVisitedImpression(int position, |
| 165 const base::string16& provider) { | 166 const base::string16& provider) { |
| 166 render_view()->Send(new ChromeViewHostMsg_LogMostVisitedImpression( | 167 render_view()->Send(new ChromeViewHostMsg_LogMostVisitedImpression( |
| 167 render_view()->GetRoutingID(), render_view()->GetPageId(), position, | 168 render_view()->GetRoutingID(), page_seq_no_, position, provider)); |
| 168 provider)); | |
| 169 } | 169 } |
| 170 | 170 |
| 171 void SearchBox::LogMostVisitedNavigation(int position, | 171 void SearchBox::LogMostVisitedNavigation(int position, |
| 172 const base::string16& provider) { | 172 const base::string16& provider) { |
| 173 render_view()->Send(new ChromeViewHostMsg_LogMostVisitedNavigation( | 173 render_view()->Send(new ChromeViewHostMsg_LogMostVisitedNavigation( |
| 174 render_view()->GetRoutingID(), render_view()->GetPageId(), position, | 174 render_view()->GetRoutingID(), page_seq_no_, position, provider)); |
| 175 provider)); | |
| 176 } | 175 } |
| 177 | 176 |
| 178 void SearchBox::CheckIsUserSignedInToChromeAs(const base::string16& identity) { | 177 void SearchBox::CheckIsUserSignedInToChromeAs(const base::string16& identity) { |
| 179 render_view()->Send(new ChromeViewHostMsg_ChromeIdentityCheck( | 178 render_view()->Send(new ChromeViewHostMsg_ChromeIdentityCheck( |
| 180 render_view()->GetRoutingID(), render_view()->GetPageId(), identity)); | 179 render_view()->GetRoutingID(), page_seq_no_, identity)); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void SearchBox::DeleteMostVisitedItem( | 182 void SearchBox::DeleteMostVisitedItem( |
| 184 InstantRestrictedID most_visited_item_id) { | 183 InstantRestrictedID most_visited_item_id) { |
| 185 render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( | 184 render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( |
| 186 render_view()->GetRoutingID(), render_view()->GetPageId(), | 185 render_view()->GetRoutingID(), |
| 186 page_seq_no_, |
| 187 GetURLForMostVisitedItem(most_visited_item_id))); | 187 GetURLForMostVisitedItem(most_visited_item_id))); |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url, | 190 bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url, |
| 191 GURL* url) const { | 191 GURL* url) const { |
| 192 std::string favicon_params; | 192 std::string favicon_params; |
| 193 InstantRestrictedID rid = -1; | 193 InstantRestrictedID rid = -1; |
| 194 bool success = internal::GetRestrictedIDFromFaviconUrl( | 194 bool success = internal::GetRestrictedIDFromFaviconUrl( |
| 195 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid); | 195 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid); |
| 196 if (!success) | 196 if (!success) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, | 234 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, |
| 235 item); | 235 item); |
| 236 } | 236 } |
| 237 | 237 |
| 238 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { | 238 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { |
| 239 return theme_info_; | 239 return theme_info_; |
| 240 } | 240 } |
| 241 | 241 |
| 242 void SearchBox::Focus() { | 242 void SearchBox::Focus() { |
| 243 render_view()->Send(new ChromeViewHostMsg_FocusOmnibox( | 243 render_view()->Send(new ChromeViewHostMsg_FocusOmnibox( |
| 244 render_view()->GetRoutingID(), render_view()->GetPageId(), | 244 render_view()->GetRoutingID(), page_seq_no_, OMNIBOX_FOCUS_VISIBLE)); |
| 245 OMNIBOX_FOCUS_VISIBLE)); | |
| 246 } | 245 } |
| 247 | 246 |
| 248 void SearchBox::NavigateToURL(const GURL& url, | 247 void SearchBox::NavigateToURL(const GURL& url, |
| 249 WindowOpenDisposition disposition, | 248 WindowOpenDisposition disposition, |
| 250 bool is_most_visited_item_url) { | 249 bool is_most_visited_item_url) { |
| 251 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( | 250 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( |
| 252 render_view()->GetRoutingID(), render_view()->GetPageId(), url, | 251 render_view()->GetRoutingID(), page_seq_no_, url, |
| 253 disposition, is_most_visited_item_url)); | 252 disposition, is_most_visited_item_url)); |
| 254 } | 253 } |
| 255 | 254 |
| 256 void SearchBox::Paste(const base::string16& text) { | 255 void SearchBox::Paste(const base::string16& text) { |
| 257 render_view()->Send(new ChromeViewHostMsg_PasteAndOpenDropdown( | 256 render_view()->Send(new ChromeViewHostMsg_PasteAndOpenDropdown( |
| 258 render_view()->GetRoutingID(), render_view()->GetPageId(), text)); | 257 render_view()->GetRoutingID(), page_seq_no_, text)); |
| 259 } | 258 } |
| 260 | 259 |
| 261 void SearchBox::SetVoiceSearchSupported(bool supported) { | 260 void SearchBox::SetVoiceSearchSupported(bool supported) { |
| 262 render_view()->Send(new ChromeViewHostMsg_SetVoiceSearchSupported( | 261 render_view()->Send(new ChromeViewHostMsg_SetVoiceSearchSupported( |
| 263 render_view()->GetRoutingID(), render_view()->GetPageId(), supported)); | 262 render_view()->GetRoutingID(), page_seq_no_, supported)); |
| 264 } | 263 } |
| 265 | 264 |
| 266 void SearchBox::StartCapturingKeyStrokes() { | 265 void SearchBox::StartCapturingKeyStrokes() { |
| 267 render_view()->Send(new ChromeViewHostMsg_FocusOmnibox( | 266 render_view()->Send(new ChromeViewHostMsg_FocusOmnibox( |
| 268 render_view()->GetRoutingID(), render_view()->GetPageId(), | 267 render_view()->GetRoutingID(), page_seq_no_, OMNIBOX_FOCUS_INVISIBLE)); |
| 269 OMNIBOX_FOCUS_INVISIBLE)); | |
| 270 } | 268 } |
| 271 | 269 |
| 272 void SearchBox::StopCapturingKeyStrokes() { | 270 void SearchBox::StopCapturingKeyStrokes() { |
| 273 render_view()->Send(new ChromeViewHostMsg_FocusOmnibox( | 271 render_view()->Send(new ChromeViewHostMsg_FocusOmnibox( |
| 274 render_view()->GetRoutingID(), render_view()->GetPageId(), | 272 render_view()->GetRoutingID(), page_seq_no_, OMNIBOX_FOCUS_NONE)); |
| 275 OMNIBOX_FOCUS_NONE)); | |
| 276 } | 273 } |
| 277 | 274 |
| 278 void SearchBox::UndoAllMostVisitedDeletions() { | 275 void SearchBox::UndoAllMostVisitedDeletions() { |
| 279 render_view()->Send( | 276 render_view()->Send( |
| 280 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( | 277 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( |
| 281 render_view()->GetRoutingID(), render_view()->GetPageId())); | 278 page_seq_no_, render_view()->GetRoutingID())); |
| 282 } | 279 } |
| 283 | 280 |
| 284 void SearchBox::UndoMostVisitedDeletion( | 281 void SearchBox::UndoMostVisitedDeletion( |
| 285 InstantRestrictedID most_visited_item_id) { | 282 InstantRestrictedID most_visited_item_id) { |
| 286 render_view()->Send(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( | 283 render_view()->Send(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( |
| 287 render_view()->GetRoutingID(), render_view()->GetPageId(), | 284 render_view()->GetRoutingID(), page_seq_no_, |
| 288 GetURLForMostVisitedItem(most_visited_item_id))); | 285 GetURLForMostVisitedItem(most_visited_item_id))); |
| 289 } | 286 } |
| 290 | 287 |
| 291 bool SearchBox::OnMessageReceived(const IPC::Message& message) { | 288 bool SearchBox::OnMessageReceived(const IPC::Message& message) { |
| 292 bool handled = true; | 289 bool handled = true; |
| 293 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) | 290 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) |
| 291 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetPageSequenceNumber, |
| 292 OnSetPageSequenceNumber) |
| 294 IPC_MESSAGE_HANDLER(ChromeViewMsg_ChromeIdentityCheckResult, | 293 IPC_MESSAGE_HANDLER(ChromeViewMsg_ChromeIdentityCheckResult, |
| 295 OnChromeIdentityCheckResult) | 294 OnChromeIdentityCheckResult) |
| 296 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 295 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
| 297 OnDetermineIfPageSupportsInstant) | 296 OnDetermineIfPageSupportsInstant) |
| 298 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged, OnFocusChanged) | 297 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged, OnFocusChanged) |
| 299 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange) | 298 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange) |
| 300 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, | 299 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, |
| 301 OnMostVisitedChanged) | 300 OnMostVisitedChanged) |
| 302 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPromoInformation, | 301 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPromoInformation, |
| 303 OnPromoInformationReceived) | 302 OnPromoInformationReceived) |
| 304 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, | 303 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, |
| 305 OnSetDisplayInstantResults) | 304 OnSetDisplayInstantResults) |
| 306 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetInputInProgress, | 305 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetInputInProgress, |
| 307 OnSetInputInProgress) | 306 OnSetInputInProgress) |
| 308 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetSuggestionToPrefetch, | 307 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetSuggestionToPrefetch, |
| 309 OnSetSuggestionToPrefetch) | 308 OnSetSuggestionToPrefetch) |
| 310 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) | 309 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) |
| 311 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, | 310 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, |
| 312 OnThemeChanged) | 311 OnThemeChanged) |
| 313 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxToggleVoiceSearch, | 312 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxToggleVoiceSearch, |
| 314 OnToggleVoiceSearch) | 313 OnToggleVoiceSearch) |
| 315 IPC_MESSAGE_UNHANDLED(handled = false) | 314 IPC_MESSAGE_UNHANDLED(handled = false) |
| 316 IPC_END_MESSAGE_MAP() | 315 IPC_END_MESSAGE_MAP() |
| 317 return handled; | 316 return handled; |
| 318 } | 317 } |
| 319 | 318 |
| 319 void SearchBox::OnSetPageSequenceNumber(int page_seq_no) { |
| 320 page_seq_no_ = page_seq_no; |
| 321 } |
| 322 |
| 320 void SearchBox::OnChromeIdentityCheckResult(const base::string16& identity, | 323 void SearchBox::OnChromeIdentityCheckResult(const base::string16& identity, |
| 321 bool identity_match) { | 324 bool identity_match) { |
| 322 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 325 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 323 extensions_v8::SearchBoxExtension::DispatchChromeIdentityCheckResult( | 326 extensions_v8::SearchBoxExtension::DispatchChromeIdentityCheckResult( |
| 324 render_view()->GetWebView()->mainFrame(), identity, identity_match); | 327 render_view()->GetWebView()->mainFrame(), identity, identity_match); |
| 325 } | 328 } |
| 326 } | 329 } |
| 327 | 330 |
| 328 void SearchBox::OnDetermineIfPageSupportsInstant() { | 331 void SearchBox::OnDetermineIfPageSupportsInstant() { |
| 329 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 332 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 330 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( | 333 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
| 331 render_view()->GetWebView()->mainFrame()); | 334 render_view()->GetWebView()->mainFrame()); |
| 332 DVLOG(1) << render_view() << " PageSupportsInstant: " << result; | 335 DVLOG(1) << render_view() << " PageSupportsInstant: " << result; |
| 333 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( | 336 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( |
| 334 render_view()->GetRoutingID(), render_view()->GetPageId(), result)); | 337 render_view()->GetRoutingID(), page_seq_no_, result)); |
| 335 } | 338 } |
| 336 } | 339 } |
| 337 | 340 |
| 338 void SearchBox::OnFocusChanged(OmniboxFocusState new_focus_state, | 341 void SearchBox::OnFocusChanged(OmniboxFocusState new_focus_state, |
| 339 OmniboxFocusChangeReason reason) { | 342 OmniboxFocusChangeReason reason) { |
| 340 bool key_capture_enabled = new_focus_state == OMNIBOX_FOCUS_INVISIBLE; | 343 bool key_capture_enabled = new_focus_state == OMNIBOX_FOCUS_INVISIBLE; |
| 341 if (key_capture_enabled != is_key_capture_enabled_) { | 344 if (key_capture_enabled != is_key_capture_enabled_) { |
| 342 // Tell the page if the key capture mode changed unless the focus state | 345 // Tell the page if the key capture mode changed unless the focus state |
| 343 // changed because of TYPING. This is because in that case, the browser | 346 // changed because of TYPING. This is because in that case, the browser |
| 344 // hasn't really stopped capturing key strokes. | 347 // hasn't really stopped capturing key strokes. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 464 } |
| 462 | 465 |
| 463 void SearchBox::Reset() { | 466 void SearchBox::Reset() { |
| 464 query_.clear(); | 467 query_.clear(); |
| 465 suggestion_ = InstantSuggestion(); | 468 suggestion_ = InstantSuggestion(); |
| 466 start_margin_ = 0; | 469 start_margin_ = 0; |
| 467 is_focused_ = false; | 470 is_focused_ = false; |
| 468 is_key_capture_enabled_ = false; | 471 is_key_capture_enabled_ = false; |
| 469 theme_info_ = ThemeBackgroundInfo(); | 472 theme_info_ = ThemeBackgroundInfo(); |
| 470 } | 473 } |
| OLD | NEW |