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