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 IsThemeInfoEqual(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 AreMostVisitedItemsEqual( | |
44 const std::vector<InstantMostVisitedItemIDPair>& items, | |
45 const std::vector<InstantMostVisitedItemIDPair>& old_items) { | |
46 if (old_items.size() != items.size()) | |
47 return false; | |
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; | |
sreeram
2013/05/05 02:19:12
"const InstantMostVisitedItem&" in both lines abov
sreeram
2013/05/05 02:19:12
It's mildly inconsistent to have "items" and "old_
Anuj
2013/05/06 17:44:44
Done.
Anuj
2013/05/06 17:44:44
Done.
| |
51 if (new_item.url != old_item.url || new_item.title != old_item.title) { | |
52 return false; | |
sreeram
2013/05/05 02:19:12
Nit: No braces.
Anuj
2013/05/06 17:44:44
Done.
| |
53 } | |
54 } | |
55 return true; | |
56 } | |
57 | |
27 } // namespace | 58 } // namespace |
28 | 59 |
29 SearchBox::SearchBox(content::RenderView* render_view) | 60 SearchBox::SearchBox(content::RenderView* render_view) |
30 : content::RenderViewObserver(render_view), | 61 : content::RenderViewObserver(render_view), |
31 content::RenderViewObserverTracker<SearchBox>(render_view), | 62 content::RenderViewObserverTracker<SearchBox>(render_view), |
32 verbatim_(false), | 63 verbatim_(false), |
33 query_is_restricted_(false), | 64 query_is_restricted_(false), |
34 selection_start_(0), | 65 selection_start_(0), |
35 selection_end_(0), | 66 selection_end_(0), |
36 start_margin_(0), | 67 start_margin_(0), |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( | 353 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( |
323 render_view()->GetWebView()->mainFrame()); | 354 render_view()->GetWebView()->mainFrame()); |
324 } | 355 } |
325 } | 356 } |
326 | 357 |
327 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 358 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
328 display_instant_results_ = display_instant_results; | 359 display_instant_results_ = display_instant_results; |
329 } | 360 } |
330 | 361 |
331 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { | 362 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
363 if (IsThemeInfoEqual(theme_info, theme_info_)) | |
364 return; | |
332 theme_info_ = theme_info; | 365 theme_info_ = theme_info; |
333 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 366 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
334 extensions_v8::SearchBoxExtension::DispatchThemeChange( | 367 extensions_v8::SearchBoxExtension::DispatchThemeChange( |
335 render_view()->GetWebView()->mainFrame()); | 368 render_view()->GetWebView()->mainFrame()); |
336 } | 369 } |
337 } | 370 } |
338 | 371 |
339 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, | 372 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, |
340 size_t omnibox_font_size) { | 373 size_t omnibox_font_size) { |
341 omnibox_font_ = omnibox_font; | 374 omnibox_font_ = omnibox_font; |
(...skipping 28 matching lines...) Expand all Loading... | |
370 } | 403 } |
371 | 404 |
372 void SearchBox::SetQuery(const string16& query, bool verbatim) { | 405 void SearchBox::SetQuery(const string16& query, bool verbatim) { |
373 query_ = query; | 406 query_ = query; |
374 verbatim_ = verbatim; | 407 verbatim_ = verbatim; |
375 query_is_restricted_ = false; | 408 query_is_restricted_ = false; |
376 } | 409 } |
377 | 410 |
378 void SearchBox::OnMostVisitedChanged( | 411 void SearchBox::OnMostVisitedChanged( |
379 const std::vector<InstantMostVisitedItemIDPair>& items) { | 412 const std::vector<InstantMostVisitedItemIDPair>& items) { |
413 std::vector<InstantMostVisitedItemIDPair> old_items; | |
414 most_visited_items_cache_.GetCurrentItems(&old_items); | |
415 if (AreMostVisitedItemsEqual(items, old_items)) | |
416 return; | |
417 | |
380 most_visited_items_cache_.AddItemsWithRestrictedID(items); | 418 most_visited_items_cache_.AddItemsWithRestrictedID(items); |
381 | 419 |
382 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 420 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
383 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( | 421 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |
384 render_view()->GetWebView()->mainFrame()); | 422 render_view()->GetWebView()->mainFrame()); |
385 } | 423 } |
386 } | 424 } |
387 | 425 |
388 void SearchBox::GetMostVisitedItems( | 426 void SearchBox::GetMostVisitedItems( |
389 std::vector<InstantMostVisitedItemIDPair>* items) const { | 427 std::vector<InstantMostVisitedItemIDPair>* items) const { |
390 return most_visited_items_cache_.GetCurrentItems(items); | 428 return most_visited_items_cache_.GetCurrentItems(items); |
391 } | 429 } |
392 | 430 |
393 bool SearchBox::GetMostVisitedItemWithID( | 431 bool SearchBox::GetMostVisitedItemWithID( |
394 InstantRestrictedID most_visited_item_id, | 432 InstantRestrictedID most_visited_item_id, |
395 InstantMostVisitedItem* item) const { | 433 InstantMostVisitedItem* item) const { |
396 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, | 434 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, |
397 item); | 435 item); |
398 } | 436 } |
OLD | NEW |