Chromium Code Reviews| 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 "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/omnibox_focus_state.h" | 10 #include "chrome/common/omnibox_focus_state.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "chrome/renderer/searchbox/searchbox_extension.h" | 13 #include "chrome/renderer/searchbox/searchbox_extension.h" |
| 14 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
| 15 #include "grit/renderer_resources.h" | 15 #include "grit/renderer_resources.h" |
| 16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Size of the results cache. | 24 // Size of the results cache. |
| 25 const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; | 25 const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; |
| 26 | 26 |
| 27 bool DidThemeInfoChange(const ThemeBackgroundInfo& theme_info, | |
| 28 const ThemeBackgroundInfo& old_theme_info) { | |
| 29 return old_theme_info.color_r != theme_info.color_r || | |
| 30 old_theme_info.color_g != theme_info.color_g || | |
| 31 old_theme_info.color_b != theme_info.color_b || | |
| 32 old_theme_info.color_a != theme_info.color_a || | |
| 33 old_theme_info.theme_id != theme_info.theme_id || | |
| 34 old_theme_info.image_horizontal_alignment != | |
| 35 theme_info.image_horizontal_alignment || | |
| 36 old_theme_info.image_vertical_alignment != | |
| 37 theme_info.image_vertical_alignment || | |
| 38 old_theme_info.image_tiling != theme_info.image_tiling || | |
| 39 old_theme_info.image_height != theme_info.image_height || | |
| 40 old_theme_info.has_attribution != theme_info.has_attribution; | |
| 41 } | |
| 42 | |
| 43 bool DidMostVisitedItemsChange( | |
|
samarth
2013/05/04 00:41:54
Sorry for the back and forth, but one more change:
Anuj
2013/05/04 01:00:01
Done.
| |
| 44 const std::vector<InstantMostVisitedItemIDPair>& items, | |
| 45 const std::vector<InstantMostVisitedItemIDPair>& old_items) { | |
| 46 bool most_visited_changed = old_items.size() != items.size(); | |
| 47 if (!most_visited_changed) { | |
| 48 for (size_t i = 0; i < items.size(); i++) { | |
| 49 InstantMostVisitedItem old_item = old_items[i].second; | |
| 50 InstantMostVisitedItem new_item = items[i].second; | |
| 51 if (new_item.url != old_item.url || new_item.title != old_item.title) { | |
| 52 most_visited_changed = true; | |
| 53 break; | |
| 54 } | |
| 55 } | |
| 56 } | |
| 57 return most_visited_changed; | |
| 58 } | |
| 59 | |
| 27 } // namespace | 60 } // namespace |
| 28 | 61 |
| 29 SearchBox::SearchBox(content::RenderView* render_view) | 62 SearchBox::SearchBox(content::RenderView* render_view) |
| 30 : content::RenderViewObserver(render_view), | 63 : content::RenderViewObserver(render_view), |
| 31 content::RenderViewObserverTracker<SearchBox>(render_view), | 64 content::RenderViewObserverTracker<SearchBox>(render_view), |
| 32 verbatim_(false), | 65 verbatim_(false), |
| 33 query_is_restricted_(false), | 66 query_is_restricted_(false), |
| 34 selection_start_(0), | 67 selection_start_(0), |
| 35 selection_end_(0), | 68 selection_end_(0), |
| 36 start_margin_(0), | 69 start_margin_(0), |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( | 355 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( |
| 323 render_view()->GetWebView()->mainFrame()); | 356 render_view()->GetWebView()->mainFrame()); |
| 324 } | 357 } |
| 325 } | 358 } |
| 326 | 359 |
| 327 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 360 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
| 328 display_instant_results_ = display_instant_results; | 361 display_instant_results_ = display_instant_results; |
| 329 } | 362 } |
| 330 | 363 |
| 331 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { | 364 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| 365 if (!DidThemeInfoChange(theme_info, theme_info_)) | |
| 366 return; | |
| 332 theme_info_ = theme_info; | 367 theme_info_ = theme_info; |
| 333 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 368 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 334 extensions_v8::SearchBoxExtension::DispatchThemeChange( | 369 extensions_v8::SearchBoxExtension::DispatchThemeChange( |
| 335 render_view()->GetWebView()->mainFrame()); | 370 render_view()->GetWebView()->mainFrame()); |
| 336 } | 371 } |
| 337 } | 372 } |
| 338 | 373 |
| 339 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, | 374 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, |
| 340 size_t omnibox_font_size) { | 375 size_t omnibox_font_size) { |
| 341 omnibox_font_ = omnibox_font; | 376 omnibox_font_ = omnibox_font; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 370 } | 405 } |
| 371 | 406 |
| 372 void SearchBox::SetQuery(const string16& query, bool verbatim) { | 407 void SearchBox::SetQuery(const string16& query, bool verbatim) { |
| 373 query_ = query; | 408 query_ = query; |
| 374 verbatim_ = verbatim; | 409 verbatim_ = verbatim; |
| 375 query_is_restricted_ = false; | 410 query_is_restricted_ = false; |
| 376 } | 411 } |
| 377 | 412 |
| 378 void SearchBox::OnMostVisitedChanged( | 413 void SearchBox::OnMostVisitedChanged( |
| 379 const std::vector<InstantMostVisitedItemIDPair>& items) { | 414 const std::vector<InstantMostVisitedItemIDPair>& items) { |
| 415 std::vector<InstantMostVisitedItemIDPair> old_items; | |
| 416 most_visited_items_cache_.GetCurrentItems(&old_items); | |
| 417 if (!DidMostVisitedItemsChange(items, old_items)) | |
| 418 return; | |
| 419 | |
| 380 most_visited_items_cache_.AddItemsWithRestrictedID(items); | 420 most_visited_items_cache_.AddItemsWithRestrictedID(items); |
| 381 | 421 |
| 382 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 422 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 383 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( | 423 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |
| 384 render_view()->GetWebView()->mainFrame()); | 424 render_view()->GetWebView()->mainFrame()); |
| 385 } | 425 } |
| 386 } | 426 } |
| 387 | 427 |
| 388 void SearchBox::GetMostVisitedItems( | 428 void SearchBox::GetMostVisitedItems( |
| 389 std::vector<InstantMostVisitedItemIDPair>* items) const { | 429 std::vector<InstantMostVisitedItemIDPair>* items) const { |
| 390 return most_visited_items_cache_.GetCurrentItems(items); | 430 return most_visited_items_cache_.GetCurrentItems(items); |
| 391 } | 431 } |
| 392 | 432 |
| 393 bool SearchBox::GetMostVisitedItemWithID( | 433 bool SearchBox::GetMostVisitedItemWithID( |
| 394 InstantRestrictedID most_visited_item_id, | 434 InstantRestrictedID most_visited_item_id, |
| 395 InstantMostVisitedItem* item) const { | 435 InstantMostVisitedItem* item) const { |
| 396 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, | 436 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, |
| 397 item); | 437 item); |
| 398 } | 438 } |
| OLD | NEW |