Index: chrome/renderer/searchbox.cc |
diff --git a/chrome/renderer/searchbox.cc b/chrome/renderer/searchbox.cc |
index fc9ee55fc5289d61af8bc23993b92feb40a73711..2540fa24d48b3bad66355019484709818ffb5701 100644 |
--- a/chrome/renderer/searchbox.cc |
+++ b/chrome/renderer/searchbox.cc |
@@ -4,6 +4,7 @@ |
#include "chrome/renderer/searchbox.h" |
+#include "base/utf_string_conversions.h" |
#include "chrome/common/render_messages.h" |
#include "chrome/renderer/searchbox_extension.h" |
#include "content/public/renderer/render_view.h" |
@@ -16,18 +17,32 @@ SearchBox::SearchBox(content::RenderView* render_view) |
content::RenderViewObserverTracker<SearchBox>(render_view), |
verbatim_(false), |
selection_start_(0), |
- selection_end_(0) { |
+ selection_end_(0), |
+ rid_base_(0), |
+ key_code_(0), |
+ is_focused_(false) { |
} |
SearchBox::~SearchBox() { |
} |
-void SearchBox::SetSuggestions(const std::vector<std::string>& suggestions, |
- InstantCompleteBehavior behavior) { |
+void SearchBox::SetSuggestions( |
+ const std::vector<InstantSuggestion>& suggestions) { |
+ if (!suggestions.empty() && |
+ suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { |
+ value_ = UTF8ToUTF16(suggestions[0].text); |
+ verbatim_ = true; |
+ selection_start_ = selection_end_ = value_.size(); |
+ } |
// Explicitly allow empty vector to be sent to the browser. |
render_view()->Send(new ChromeViewHostMsg_SetSuggestions( |
- render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions, |
- behavior)); |
+ render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions)); |
+} |
+ |
+void SearchBox::SetInstantPreviewHeight(int height, InstantSizeUnits units) { |
+ render_view()->Send(new ChromeViewHostMsg_SetInstantPreviewHeight( |
+ render_view()->GetRoutingID(), render_view()->GetPageId(), height, |
+ units)); |
} |
gfx::Rect SearchBox::GetRect() { |
@@ -55,6 +70,13 @@ bool SearchBox::OnMessageReceived(const IPC::Message& message) { |
IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) |
IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
OnDetermineIfPageSupportsInstant) |
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxNativeSuggestions, |
+ OnNativeSuggestions) |
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyPress, OnKeyPress) |
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxLastQuery, OnLastQuery) |
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCurrentURL, OnCurrentURL) |
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocused, OnFocused) |
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBlurred, OnBlurred) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -68,10 +90,10 @@ void SearchBox::OnChange(const string16& value, |
verbatim_ = verbatim; |
selection_start_ = selection_start; |
selection_end_ = selection_end; |
- if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) |
- return; |
- extensions_v8::SearchBoxExtension::DispatchChange( |
- render_view()->GetWebView()->mainFrame()); |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ extensions_v8::SearchBoxExtension::DispatchChange( |
+ render_view()->GetWebView()->mainFrame()); |
+ } |
} |
void SearchBox::OnSubmit(const string16& value, bool verbatim) { |
@@ -95,29 +117,75 @@ void SearchBox::OnCancel() { |
void SearchBox::OnResize(const gfx::Rect& bounds) { |
rect_ = bounds; |
- if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) |
- return; |
- extensions_v8::SearchBoxExtension::DispatchResize( |
- render_view()->GetWebView()->mainFrame()); |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ extensions_v8::SearchBoxExtension::DispatchResize( |
+ render_view()->GetWebView()->mainFrame()); |
+ } |
} |
void SearchBox::OnDetermineIfPageSupportsInstant(const string16& value, |
bool verbatim, |
int selection_start, |
int selection_end) { |
- value_ = value; |
- verbatim_ = verbatim; |
- selection_start_ = selection_start; |
- selection_end_ = selection_end; |
- bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
- render_view()->GetWebView()->mainFrame()); |
- render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( |
- render_view()->GetRoutingID(), render_view()->GetPageId(), result)); |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
+ render_view()->GetWebView()->mainFrame()); |
+ render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( |
+ render_view()->GetRoutingID(), render_view()->GetPageId(), result)); |
+ } |
+} |
+ |
+void SearchBox::OnNativeSuggestions( |
+ const std::vector<InstantNativeSuggestionsParts>& native_suggestions) { |
+ rid_base_ += native_suggestions_.size(); |
+ native_suggestions_ = native_suggestions; |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ extensions_v8::SearchBoxExtension::DispatchNativeSuggestions( |
+ render_view()->GetWebView()->mainFrame()); |
+ } |
+} |
+ |
+void SearchBox::OnKeyPress(int key_code) { |
+ key_code_ = key_code; |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ extensions_v8::SearchBoxExtension::DispatchKeyPress( |
+ render_view()->GetWebView()->mainFrame()); |
+ } |
+} |
+ |
+void SearchBox::OnLastQuery(const std::string& last_query) { |
+ last_query_ = last_query; |
+} |
+ |
+void SearchBox::OnCurrentURL(const std::string& current_url) { |
+ current_url_ = current_url; |
+} |
+ |
+void SearchBox::OnFocused() { |
+ is_focused_ = true; |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ extensions_v8::SearchBoxExtension::DispatchFocus( |
+ render_view()->GetWebView()->mainFrame()); |
+ } |
+} |
+ |
+void SearchBox::OnBlurred() { |
+ is_focused_ = false; |
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
+ extensions_v8::SearchBoxExtension::DispatchBlur( |
+ render_view()->GetWebView()->mainFrame()); |
+ } |
} |
void SearchBox::Reset() { |
+ value_.clear(); |
verbatim_ = false; |
- value_ = string16(); |
selection_start_ = selection_end_ = 0; |
+ rid_base_ = 0; |
rect_ = gfx::Rect(); |
+ native_suggestions_.clear(); |
+ key_code_ = 0; |
+ last_query_.clear(); |
+ current_url_.clear(); |
+ is_focused_ = false; |
} |