| 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/utf_string_conversions.h" |    7 #include "base/utf_string_conversions.h" | 
|    8 #include "chrome/common/render_messages.h" |    8 #include "chrome/common/render_messages.h" | 
|    9 #include "chrome/common/url_constants.h" |    9 #include "chrome/common/url_constants.h" | 
|   10 #include "chrome/renderer/searchbox/searchbox_extension.h" |   10 #include "chrome/renderer/searchbox/searchbox_extension.h" | 
|   11 #include "content/public/renderer/render_view.h" |   11 #include "content/public/renderer/render_view.h" | 
|   12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |   12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 
|   13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |   13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 
|   14  |   14  | 
|   15 namespace { |  | 
|   16  |  | 
|   17 // Prefix for a thumbnail URL. |  | 
|   18 const char kThumbnailUrlPrefix[] = "chrome-search://thumb/"; |  | 
|   19  |  | 
|   20 // Prefix for a thumbnail URL. |  | 
|   21 const char kFaviconUrlPrefix[] = "chrome-search://favicon/"; |  | 
|   22  |  | 
|   23 } |  | 
|   24  |  | 
|   25 SearchBox::SearchBox(content::RenderView* render_view) |   15 SearchBox::SearchBox(content::RenderView* render_view) | 
|   26     : content::RenderViewObserver(render_view), |   16     : content::RenderViewObserver(render_view), | 
|   27       content::RenderViewObserverTracker<SearchBox>(render_view), |   17       content::RenderViewObserverTracker<SearchBox>(render_view), | 
|   28       verbatim_(false), |   18       verbatim_(false), | 
|   29       selection_start_(0), |   19       selection_start_(0), | 
|   30       selection_end_(0), |   20       selection_end_(0), | 
|   31       results_base_(0), |   21       results_base_(0), | 
|   32       start_margin_(0), |   22       start_margin_(0), | 
|   33       last_results_base_(0), |   23       last_results_base_(0), | 
|   34       is_key_capture_enabled_(false), |   24       is_key_capture_enabled_(false), | 
|   35       display_instant_results_(false), |   25       display_instant_results_(false), | 
|   36       omnibox_font_size_(0), |   26       omnibox_font_size_(0) { | 
|   37       last_most_visited_item_id_(0) { |  | 
|   38 } |   27 } | 
|   39  |   28  | 
|   40 SearchBox::~SearchBox() { |   29 SearchBox::~SearchBox() { | 
|   41 } |   30 } | 
|   42  |   31  | 
|   43 void SearchBox::SetSuggestions( |   32 void SearchBox::SetSuggestions( | 
|   44     const std::vector<InstantSuggestion>& suggestions) { |   33     const std::vector<InstantSuggestion>& suggestions) { | 
|   45   if (!suggestions.empty() && |   34   if (!suggestions.empty() && | 
|   46       suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { |   35       suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { | 
|   47     query_ = suggestions[0].text; |   36     query_ = suggestions[0].text; | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|   77 } |   66 } | 
|   78  |   67  | 
|   79 void SearchBox::NavigateToURL(const GURL& url, |   68 void SearchBox::NavigateToURL(const GURL& url, | 
|   80                               content::PageTransition transition, |   69                               content::PageTransition transition, | 
|   81                               WindowOpenDisposition disposition) { |   70                               WindowOpenDisposition disposition) { | 
|   82   render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( |   71   render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( | 
|   83       render_view()->GetRoutingID(), render_view()->GetPageId(), |   72       render_view()->GetRoutingID(), render_view()->GetPageId(), | 
|   84       url, transition, disposition)); |   73       url, transition, disposition)); | 
|   85 } |   74 } | 
|   86  |   75  | 
|   87 void SearchBox::DeleteMostVisitedItem(int most_visited_item_id) { |   76 void SearchBox::DeleteMostVisitedItem(uint64 most_visited_item_id) { | 
|   88   string16 url = MostVisitedItemIDToURL(most_visited_item_id); |   77   render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( | 
|   89   render_view()->Send(new ChromeViewHostMsg_InstantDeleteMostVisitedItem( |   78       render_view()->GetRoutingID(), most_visited_item_id)); | 
|   90       render_view()->GetRoutingID(), GURL(url))); |  | 
|   91 } |   79 } | 
|   92  |   80  | 
|   93 void SearchBox::UndoMostVisitedDeletion(int most_visited_item_id) { |   81 void SearchBox::UndoMostVisitedDeletion(uint64 most_visited_item_id) { | 
|   94   string16 url = MostVisitedItemIDToURL(most_visited_item_id); |   82   render_view()->Send(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( | 
|   95   render_view()->Send(new ChromeViewHostMsg_InstantUndoMostVisitedDeletion( |   83       render_view()->GetRoutingID(), most_visited_item_id)); | 
|   96       render_view()->GetRoutingID(), GURL(url))); |  | 
|   97 } |   84 } | 
|   98  |   85  | 
|   99 void SearchBox::UndoAllMostVisitedDeletions() { |   86 void SearchBox::UndoAllMostVisitedDeletions() { | 
|  100   render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions( |   87   render_view()->Send( | 
 |   88       new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( | 
|  101       render_view()->GetRoutingID())); |   89       render_view()->GetRoutingID())); | 
|  102 } |   90 } | 
|  103  |   91  | 
|  104 int SearchBox::GetStartMargin() const { |   92 int SearchBox::GetStartMargin() const { | 
|  105   return static_cast<int>(start_margin_ / GetZoom()); |   93   return static_cast<int>(start_margin_ / GetZoom()); | 
|  106 } |   94 } | 
|  107  |   95  | 
|  108 gfx::Rect SearchBox::GetPopupBounds() const { |   96 gfx::Rect SearchBox::GetPopupBounds() const { | 
|  109   double zoom = GetZoom(); |   97   double zoom = GetZoom(); | 
|  110   return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), |   98   return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  157                         OnSetDisplayInstantResults) |  145                         OnSetDisplayInstantResults) | 
|  158     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged, |  146     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged, | 
|  159                         OnKeyCaptureChange) |  147                         OnKeyCaptureChange) | 
|  160     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, |  148     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, | 
|  161                         OnThemeChanged) |  149                         OnThemeChanged) | 
|  162     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, |  150     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, | 
|  163                         OnFontInformationReceived) |  151                         OnFontInformationReceived) | 
|  164     IPC_MESSAGE_HANDLER( |  152     IPC_MESSAGE_HANDLER( | 
|  165         ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin, |  153         ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin, | 
|  166         OnGrantChromeSearchAccessFromOrigin) |  154         OnGrantChromeSearchAccessFromOrigin) | 
|  167     IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged, |  155     IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, | 
|  168                         OnMostVisitedChanged) |  156                         OnMostVisitedChanged) | 
|  169     IPC_MESSAGE_UNHANDLED(handled = false) |  157     IPC_MESSAGE_UNHANDLED(handled = false) | 
|  170   IPC_END_MESSAGE_MAP() |  158   IPC_END_MESSAGE_MAP() | 
|  171   return handled; |  159   return handled; | 
|  172 } |  160 } | 
|  173  |  161  | 
|  174 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { |  162 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { | 
|  175   extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame); |  163   extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame); | 
|  176 } |  164 } | 
|  177  |  165  | 
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  345   is_key_capture_enabled_ = false; |  333   is_key_capture_enabled_ = false; | 
|  346   theme_info_ = ThemeBackgroundInfo(); |  334   theme_info_ = ThemeBackgroundInfo(); | 
|  347   // Don't reset display_instant_results_ to prevent clearing it on committed |  335   // Don't reset display_instant_results_ to prevent clearing it on committed | 
|  348   // results pages in extended mode. Otherwise resetting it is a no-op because |  336   // results pages in extended mode. Otherwise resetting it is a no-op because | 
|  349   // a new loader is created when it changes; see crbug.com/164662. |  337   // a new loader is created when it changes; see crbug.com/164662. | 
|  350   // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |  338   // Also don't reset omnibox_font_ or omnibox_font_size_ since it never | 
|  351   // changes. |  339   // changes. | 
|  352 } |  340 } | 
|  353  |  341  | 
|  354 void SearchBox::OnMostVisitedChanged( |  342 void SearchBox::OnMostVisitedChanged( | 
|  355     const std::vector<MostVisitedItem>& items) { |  343     const std::vector<InstantMostVisitedItem>& items) { | 
|  356   most_visited_items_ = items; |  344   most_visited_items_ = items; | 
|  357  |  345  | 
|  358   if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |  346   if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 
|  359     extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |  347     extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( | 
|  360         render_view()->GetWebView()->mainFrame()); |  348         render_view()->GetWebView()->mainFrame()); | 
|  361   } |  349   } | 
|  362 } |  350 } | 
|  363  |  351  | 
|  364 const std::vector<MostVisitedItem>& SearchBox::GetMostVisitedItems() { |  352 const std::vector<InstantMostVisitedItem>& | 
 |  353 SearchBox::GetMostVisitedItems() const { | 
|  365   return most_visited_items_; |  354   return most_visited_items_; | 
|  366 } |  355 } | 
|  367  |  | 
|  368 int SearchBox::URLToMostVisitedItemID(string16 url) { |  | 
|  369   if (url_to_most_visited_item_id_map_[url]) |  | 
|  370     return url_to_most_visited_item_id_map_[url]; |  | 
|  371  |  | 
|  372   last_most_visited_item_id_++; |  | 
|  373   url_to_most_visited_item_id_map_[url] = last_most_visited_item_id_; |  | 
|  374   most_visited_item_id_to_url_map_[last_most_visited_item_id_] = url; |  | 
|  375  |  | 
|  376   return last_most_visited_item_id_; |  | 
|  377 } |  | 
|  378  |  | 
|  379 string16 SearchBox::MostVisitedItemIDToURL(int most_visited_item_id) { |  | 
|  380   return most_visited_item_id_to_url_map_[most_visited_item_id]; |  | 
|  381 } |  | 
|  382  |  | 
|  383 string16 SearchBox::GenerateThumbnailUrl(int most_visited_item_id) { |  | 
|  384   std::ostringstream ostr; |  | 
|  385   ostr << kThumbnailUrlPrefix << most_visited_item_id; |  | 
|  386   GURL url = GURL(ostr.str()); |  | 
|  387   return UTF8ToUTF16(url.spec()); |  | 
|  388 } |  | 
|  389  |  | 
|  390 string16 SearchBox::GenerateFaviconUrl(int most_visited_item_id) { |  | 
|  391   std::ostringstream ostr; |  | 
|  392   ostr << kFaviconUrlPrefix << most_visited_item_id; |  | 
|  393   GURL url = GURL(ostr.str()); |  | 
|  394   return UTF8ToUTF16(url.spec()); |  | 
|  395 } |  | 
| OLD | NEW |