Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: chrome/renderer/searchbox/searchbox.cc

Issue 14805004: InstantExtended: Prevent spurious themechanged/mostvisitedchanged events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed last set of comments Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/instant_types.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 IsThemeInfoEqual(const ThemeBackgroundInfo& new_theme_info,
28 const ThemeBackgroundInfo& old_theme_info) {
29 return old_theme_info.color_r == new_theme_info.color_r &&
30 old_theme_info.color_g == new_theme_info.color_g &&
31 old_theme_info.color_b == new_theme_info.color_b &&
32 old_theme_info.color_a == new_theme_info.color_a &&
33 old_theme_info.theme_id == new_theme_info.theme_id &&
34 old_theme_info.image_horizontal_alignment ==
35 new_theme_info.image_horizontal_alignment &&
36 old_theme_info.image_vertical_alignment ==
37 new_theme_info.image_vertical_alignment &&
38 old_theme_info.image_tiling == new_theme_info.image_tiling &&
39 old_theme_info.image_height == new_theme_info.image_height &&
40 old_theme_info.has_attribution == new_theme_info.has_attribution;
41 }
42
43 bool AreMostVisitedItemsEqual(
44 const std::vector<InstantMostVisitedItemIDPair>& new_tems,
sreeram 2013/05/06 14:31:56 Typo: new_tems -> new_items
Anuj 2013/05/06 17:44:45 Done.
45 const std::vector<InstantMostVisitedItemIDPair>& old_items) {
46 if (old_items.size() != new_tems.size())
47 return false;
48 for (size_t i = 0; i < new_tems.size(); i++) {
49 InstantMostVisitedItem old_item = old_items[i].second;
sreeram 2013/05/06 14:31:56 const InstantMostVisitedItem&
Anuj 2013/05/06 17:44:45 Done.
50 InstantMostVisitedItem new_item = new_tems[i].second;
sreeram 2013/05/06 14:31:56 const InstantMostVisitedItem&
Anuj 2013/05/06 17:44:45 Done.
51 if (new_item.url != old_item.url || new_item.title != old_item.title)
52 return false;
53 }
54 return true;
55 }
56
27 } // namespace 57 } // namespace
28 58
29 SearchBox::SearchBox(content::RenderView* render_view) 59 SearchBox::SearchBox(content::RenderView* render_view)
30 : content::RenderViewObserver(render_view), 60 : content::RenderViewObserver(render_view),
31 content::RenderViewObserverTracker<SearchBox>(render_view), 61 content::RenderViewObserverTracker<SearchBox>(render_view),
32 verbatim_(false), 62 verbatim_(false),
33 query_is_restricted_(false), 63 query_is_restricted_(false),
34 selection_start_(0), 64 selection_start_(0),
35 selection_end_(0), 65 selection_end_(0),
36 start_margin_(0), 66 start_margin_(0),
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( 352 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange(
323 render_view()->GetWebView()->mainFrame()); 353 render_view()->GetWebView()->mainFrame());
324 } 354 }
325 } 355 }
326 356
327 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { 357 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) {
328 display_instant_results_ = display_instant_results; 358 display_instant_results_ = display_instant_results;
329 } 359 }
330 360
331 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { 361 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
362 if (IsThemeInfoEqual(theme_info, theme_info_))
363 return;
332 theme_info_ = theme_info; 364 theme_info_ = theme_info;
333 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 365 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
334 extensions_v8::SearchBoxExtension::DispatchThemeChange( 366 extensions_v8::SearchBoxExtension::DispatchThemeChange(
335 render_view()->GetWebView()->mainFrame()); 367 render_view()->GetWebView()->mainFrame());
336 } 368 }
337 } 369 }
338 370
339 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, 371 void SearchBox::OnFontInformationReceived(const string16& omnibox_font,
340 size_t omnibox_font_size) { 372 size_t omnibox_font_size) {
341 omnibox_font_ = omnibox_font; 373 omnibox_font_ = omnibox_font;
(...skipping 28 matching lines...) Expand all
370 } 402 }
371 403
372 void SearchBox::SetQuery(const string16& query, bool verbatim) { 404 void SearchBox::SetQuery(const string16& query, bool verbatim) {
373 query_ = query; 405 query_ = query;
374 verbatim_ = verbatim; 406 verbatim_ = verbatim;
375 query_is_restricted_ = false; 407 query_is_restricted_ = false;
376 } 408 }
377 409
378 void SearchBox::OnMostVisitedChanged( 410 void SearchBox::OnMostVisitedChanged(
379 const std::vector<InstantMostVisitedItemIDPair>& items) { 411 const std::vector<InstantMostVisitedItemIDPair>& items) {
412 std::vector<InstantMostVisitedItemIDPair> old_items;
413 most_visited_items_cache_.GetCurrentItems(&old_items);
414 if (AreMostVisitedItemsEqual(items, old_items))
415 return;
416
380 most_visited_items_cache_.AddItemsWithRestrictedID(items); 417 most_visited_items_cache_.AddItemsWithRestrictedID(items);
381 418
382 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 419 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
383 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( 420 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
384 render_view()->GetWebView()->mainFrame()); 421 render_view()->GetWebView()->mainFrame());
385 } 422 }
386 } 423 }
387 424
388 void SearchBox::GetMostVisitedItems( 425 void SearchBox::GetMostVisitedItems(
389 std::vector<InstantMostVisitedItemIDPair>* items) const { 426 std::vector<InstantMostVisitedItemIDPair>* items) const {
390 return most_visited_items_cache_.GetCurrentItems(items); 427 return most_visited_items_cache_.GetCurrentItems(items);
391 } 428 }
392 429
393 bool SearchBox::GetMostVisitedItemWithID( 430 bool SearchBox::GetMostVisitedItemWithID(
394 InstantRestrictedID most_visited_item_id, 431 InstantRestrictedID most_visited_item_id,
395 InstantMostVisitedItem* item) const { 432 InstantMostVisitedItem* item) const {
396 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, 433 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id,
397 item); 434 item);
398 } 435 }
OLDNEW
« no previous file with comments | « chrome/common/instant_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698