| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 SearchBox::SearchBox(content::RenderView* render_view) | 231 SearchBox::SearchBox(content::RenderView* render_view) |
| 232 : content::RenderViewObserver(render_view), | 232 : content::RenderViewObserver(render_view), |
| 233 content::RenderViewObserverTracker<SearchBox>(render_view), | 233 content::RenderViewObserverTracker<SearchBox>(render_view), |
| 234 page_seq_no_(0), | 234 page_seq_no_(0), |
| 235 app_launcher_enabled_(false), | 235 app_launcher_enabled_(false), |
| 236 is_focused_(false), | 236 is_focused_(false), |
| 237 is_input_in_progress_(false), | 237 is_input_in_progress_(false), |
| 238 is_key_capture_enabled_(false), | 238 is_key_capture_enabled_(false), |
| 239 display_instant_results_(false), | 239 display_instant_results_(false), |
| 240 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize), | 240 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize), |
| 241 query_(), | 241 query_() { |
| 242 start_margin_(0) { | |
| 243 } | 242 } |
| 244 | 243 |
| 245 SearchBox::~SearchBox() { | 244 SearchBox::~SearchBox() { |
| 246 } | 245 } |
| 247 | 246 |
| 248 void SearchBox::LogEvent(NTPLoggingEventType event) { | 247 void SearchBox::LogEvent(NTPLoggingEventType event) { |
| 249 // The main frame for the current RenderView may be out-of-process, in which | 248 // The main frame for the current RenderView may be out-of-process, in which |
| 250 // case it won't have performance(). Use the default delta of 0 in this | 249 // case it won't have performance(). Use the default delta of 0 in this |
| 251 // case. | 250 // case. |
| 252 base::TimeDelta delta; | 251 base::TimeDelta delta; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) | 365 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) |
| 367 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetPageSequenceNumber, | 366 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetPageSequenceNumber, |
| 368 OnSetPageSequenceNumber) | 367 OnSetPageSequenceNumber) |
| 369 IPC_MESSAGE_HANDLER(ChromeViewMsg_ChromeIdentityCheckResult, | 368 IPC_MESSAGE_HANDLER(ChromeViewMsg_ChromeIdentityCheckResult, |
| 370 OnChromeIdentityCheckResult) | 369 OnChromeIdentityCheckResult) |
| 371 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 370 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
| 372 OnDetermineIfPageSupportsInstant) | 371 OnDetermineIfPageSupportsInstant) |
| 373 IPC_MESSAGE_HANDLER(ChromeViewMsg_HistorySyncCheckResult, | 372 IPC_MESSAGE_HANDLER(ChromeViewMsg_HistorySyncCheckResult, |
| 374 OnHistorySyncCheckResult) | 373 OnHistorySyncCheckResult) |
| 375 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged, OnFocusChanged) | 374 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged, OnFocusChanged) |
| 376 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange) | |
| 377 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, | 375 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, |
| 378 OnMostVisitedChanged) | 376 OnMostVisitedChanged) |
| 379 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPromoInformation, | 377 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPromoInformation, |
| 380 OnPromoInformationReceived) | 378 OnPromoInformationReceived) |
| 381 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, | 379 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, |
| 382 OnSetDisplayInstantResults) | 380 OnSetDisplayInstantResults) |
| 383 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetInputInProgress, | 381 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetInputInProgress, |
| 384 OnSetInputInProgress) | 382 OnSetInputInProgress) |
| 385 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetSuggestionToPrefetch, | 383 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetSuggestionToPrefetch, |
| 386 OnSetSuggestionToPrefetch) | 384 OnSetSuggestionToPrefetch) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 445 } |
| 448 } | 446 } |
| 449 | 447 |
| 450 void SearchBox::OnHistorySyncCheckResult(bool sync_history) { | 448 void SearchBox::OnHistorySyncCheckResult(bool sync_history) { |
| 451 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 449 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 452 extensions_v8::SearchBoxExtension::DispatchHistorySyncCheckResult( | 450 extensions_v8::SearchBoxExtension::DispatchHistorySyncCheckResult( |
| 453 render_view()->GetWebView()->mainFrame(), sync_history); | 451 render_view()->GetWebView()->mainFrame(), sync_history); |
| 454 } | 452 } |
| 455 } | 453 } |
| 456 | 454 |
| 457 void SearchBox::OnMarginChange(int margin) { | |
| 458 start_margin_ = margin; | |
| 459 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | |
| 460 extensions_v8::SearchBoxExtension::DispatchMarginChange( | |
| 461 render_view()->GetWebView()->mainFrame()); | |
| 462 } | |
| 463 } | |
| 464 | |
| 465 void SearchBox::OnMostVisitedChanged( | 455 void SearchBox::OnMostVisitedChanged( |
| 466 const std::vector<InstantMostVisitedItem>& items) { | 456 const std::vector<InstantMostVisitedItem>& items) { |
| 467 std::vector<InstantMostVisitedItemIDPair> last_known_items; | 457 std::vector<InstantMostVisitedItemIDPair> last_known_items; |
| 468 GetMostVisitedItems(&last_known_items); | 458 GetMostVisitedItems(&last_known_items); |
| 469 | 459 |
| 470 if (AreMostVisitedItemsEqual(last_known_items, items)) | 460 if (AreMostVisitedItemsEqual(last_known_items, items)) |
| 471 return; // Do not send duplicate onmostvisitedchange events. | 461 return; // Do not send duplicate onmostvisitedchange events. |
| 472 | 462 |
| 473 most_visited_items_cache_.AddItems(items); | 463 most_visited_items_cache_.AddItems(items); |
| 474 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 464 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 528 |
| 539 GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const { | 529 GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const { |
| 540 InstantMostVisitedItem item; | 530 InstantMostVisitedItem item; |
| 541 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); | 531 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); |
| 542 } | 532 } |
| 543 | 533 |
| 544 void SearchBox::Reset() { | 534 void SearchBox::Reset() { |
| 545 query_.clear(); | 535 query_.clear(); |
| 546 embedded_search_request_params_ = EmbeddedSearchRequestParams(); | 536 embedded_search_request_params_ = EmbeddedSearchRequestParams(); |
| 547 suggestion_ = InstantSuggestion(); | 537 suggestion_ = InstantSuggestion(); |
| 548 start_margin_ = 0; | |
| 549 is_focused_ = false; | 538 is_focused_ = false; |
| 550 is_key_capture_enabled_ = false; | 539 is_key_capture_enabled_ = false; |
| 551 theme_info_ = ThemeBackgroundInfo(); | 540 theme_info_ = ThemeBackgroundInfo(); |
| 552 } | 541 } |
| OLD | NEW |