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& 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_items, | |
45 const std::vector<InstantMostVisitedItemIDPair>& old_items) { | |
46 if (old_items.size() != new_items.size()) | |
47 return false; | |
48 for (size_t i = 0; i < new_items.size(); i++) { | |
49 const InstantMostVisitedItem& old_item = old_items[i].second; | |
50 const InstantMostVisitedItem& new_item = new_items[i].second; | |
51 if (new_item.url != old_item.url || new_item.title != old_item.title) | |
52 return false; | |
53 } | |
54 return true; | |
55 } | |
56 | |
57 } // namespace | 27 } // namespace |
58 | 28 |
59 SearchBox::SearchBox(content::RenderView* render_view) | 29 SearchBox::SearchBox(content::RenderView* render_view) |
60 : content::RenderViewObserver(render_view), | 30 : content::RenderViewObserver(render_view), |
61 content::RenderViewObserverTracker<SearchBox>(render_view), | 31 content::RenderViewObserverTracker<SearchBox>(render_view), |
62 verbatim_(false), | 32 verbatim_(false), |
63 query_is_restricted_(false), | 33 query_is_restricted_(false), |
64 selection_start_(0), | 34 selection_start_(0), |
65 selection_end_(0), | 35 selection_end_(0), |
66 start_margin_(0), | 36 start_margin_(0), |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( | 332 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( |
363 render_view()->GetWebView()->mainFrame()); | 333 render_view()->GetWebView()->mainFrame()); |
364 } | 334 } |
365 } | 335 } |
366 | 336 |
367 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 337 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
368 display_instant_results_ = display_instant_results; | 338 display_instant_results_ = display_instant_results; |
369 } | 339 } |
370 | 340 |
371 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { | 341 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
372 if (IsThemeInfoEqual(theme_info, theme_info_)) | |
373 return; | |
374 theme_info_ = theme_info; | 342 theme_info_ = theme_info; |
375 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 343 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
376 extensions_v8::SearchBoxExtension::DispatchThemeChange( | 344 extensions_v8::SearchBoxExtension::DispatchThemeChange( |
377 render_view()->GetWebView()->mainFrame()); | 345 render_view()->GetWebView()->mainFrame()); |
378 } | 346 } |
379 } | 347 } |
380 | 348 |
381 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, | 349 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, |
382 size_t omnibox_font_size) { | 350 size_t omnibox_font_size) { |
383 omnibox_font_ = omnibox_font; | 351 omnibox_font_ = omnibox_font; |
(...skipping 28 matching lines...) Expand all Loading... |
412 } | 380 } |
413 | 381 |
414 void SearchBox::SetQuery(const string16& query, bool verbatim) { | 382 void SearchBox::SetQuery(const string16& query, bool verbatim) { |
415 query_ = query; | 383 query_ = query; |
416 verbatim_ = verbatim; | 384 verbatim_ = verbatim; |
417 query_is_restricted_ = false; | 385 query_is_restricted_ = false; |
418 } | 386 } |
419 | 387 |
420 void SearchBox::OnMostVisitedChanged( | 388 void SearchBox::OnMostVisitedChanged( |
421 const std::vector<InstantMostVisitedItemIDPair>& items) { | 389 const std::vector<InstantMostVisitedItemIDPair>& items) { |
422 std::vector<InstantMostVisitedItemIDPair> old_items; | |
423 most_visited_items_cache_.GetCurrentItems(&old_items); | |
424 if (AreMostVisitedItemsEqual(items, old_items)) | |
425 return; | |
426 | |
427 most_visited_items_cache_.AddItemsWithRestrictedID(items); | 390 most_visited_items_cache_.AddItemsWithRestrictedID(items); |
428 | 391 |
429 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 392 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
430 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( | 393 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |
431 render_view()->GetWebView()->mainFrame()); | 394 render_view()->GetWebView()->mainFrame()); |
432 } | 395 } |
433 } | 396 } |
434 | 397 |
435 void SearchBox::GetMostVisitedItems( | 398 void SearchBox::GetMostVisitedItems( |
436 std::vector<InstantMostVisitedItemIDPair>* items) const { | 399 std::vector<InstantMostVisitedItemIDPair>* items) const { |
437 return most_visited_items_cache_.GetCurrentItems(items); | 400 return most_visited_items_cache_.GetCurrentItems(items); |
438 } | 401 } |
439 | 402 |
440 bool SearchBox::GetMostVisitedItemWithID( | 403 bool SearchBox::GetMostVisitedItemWithID( |
441 InstantRestrictedID most_visited_item_id, | 404 InstantRestrictedID most_visited_item_id, |
442 InstantMostVisitedItem* item) const { | 405 InstantMostVisitedItem* item) const { |
443 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, | 406 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, |
444 item); | 407 item); |
445 } | 408 } |
OLD | NEW |