| 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" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 InstantRestrictedID autocomplete_result_id, | 148 InstantRestrictedID autocomplete_result_id, |
| 149 InstantAutocompleteResult* result) const { | 149 InstantAutocompleteResult* result) const { |
| 150 return autocomplete_results_cache_.GetItemWithRestrictedID( | 150 return autocomplete_results_cache_.GetItemWithRestrictedID( |
| 151 autocomplete_result_id, result); | 151 autocomplete_result_id, result); |
| 152 } | 152 } |
| 153 | 153 |
| 154 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { | 154 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { |
| 155 return theme_info_; | 155 return theme_info_; |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool SearchBox::GenerateThumbnailURLFromRID(InstantRestrictedID rid, |
| 159 GURL* url) const { |
| 160 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); |
| 161 if (most_visited_item_url.is_empty()) |
| 162 return false; |
| 163 *url = GURL(base::StringPrintf("chrome-search://thumb/%s", |
| 164 most_visited_item_url.spec().c_str())); |
| 165 return true; |
| 166 } |
| 167 |
| 168 bool SearchBox::GenerateFaviconURLFromRID(InstantRestrictedID rid, |
| 169 GURL* url) const { |
| 170 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); |
| 171 if (most_visited_item_url.is_empty()) |
| 172 return false; |
| 173 *url = GURL(base::StringPrintf("chrome-search://favicon/%s", |
| 174 most_visited_item_url.spec().c_str())); |
| 175 return true; |
| 176 } |
| 177 |
| 158 bool SearchBox::OnMessageReceived(const IPC::Message& message) { | 178 bool SearchBox::OnMessageReceived(const IPC::Message& message) { |
| 159 bool handled = true; | 179 bool handled = true; |
| 160 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) | 180 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) |
| 161 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) | 181 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) |
| 162 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) | 182 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) |
| 163 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) | 183 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) |
| 164 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize) | 184 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize) |
| 165 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange) | 185 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange) |
| 166 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBarsHidden, OnBarsHidden) | 186 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBarsHidden, OnBarsHidden) |
| 167 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 187 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // changes. | 418 // changes. |
| 399 } | 419 } |
| 400 | 420 |
| 401 void SearchBox::SetQuery(const string16& query, bool verbatim) { | 421 void SearchBox::SetQuery(const string16& query, bool verbatim) { |
| 402 query_ = query; | 422 query_ = query; |
| 403 verbatim_ = verbatim; | 423 verbatim_ = verbatim; |
| 404 query_is_restricted_ = false; | 424 query_is_restricted_ = false; |
| 405 } | 425 } |
| 406 | 426 |
| 407 void SearchBox::OnMostVisitedChanged( | 427 void SearchBox::OnMostVisitedChanged( |
| 408 const std::vector<InstantMostVisitedItemIDPair>& items) { | 428 const std::vector<InstantMostVisitedItem>& items) { |
| 409 most_visited_items_cache_.AddItemsWithRestrictedID(items); | 429 most_visited_items_cache_.AddItems(items); |
| 410 | |
| 411 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 430 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 412 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( | 431 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |
| 413 render_view()->GetWebView()->mainFrame()); | 432 render_view()->GetWebView()->mainFrame()); |
| 414 } | 433 } |
| 415 } | 434 } |
| 416 | 435 |
| 417 void SearchBox::GetMostVisitedItems( | 436 void SearchBox::GetMostVisitedItems( |
| 418 std::vector<InstantMostVisitedItemIDPair>* items) const { | 437 std::vector<InstantMostVisitedItemIDPair>* items) const { |
| 419 return most_visited_items_cache_.GetCurrentItems(items); | 438 return most_visited_items_cache_.GetCurrentItems(items); |
| 420 } | 439 } |
| 421 | 440 |
| 422 bool SearchBox::GetMostVisitedItemWithID( | 441 bool SearchBox::GetMostVisitedItemWithID( |
| 423 InstantRestrictedID most_visited_item_id, | 442 InstantRestrictedID most_visited_item_id, |
| 424 InstantMostVisitedItem* item) const { | 443 InstantMostVisitedItem* item) const { |
| 425 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, | 444 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, |
| 426 item); | 445 item); |
| 427 } | 446 } |
| 428 | 447 |
| 429 GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const { | 448 GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const { |
| 430 InstantMostVisitedItem item; | 449 InstantMostVisitedItem item; |
| 431 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); | 450 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); |
| 432 } | 451 } |
| OLD | NEW |