Index: chrome/browser/instant/instant_client.cc |
diff --git a/chrome/browser/instant/instant_client.cc b/chrome/browser/instant/instant_client.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..09b2f98e8db4067405c91eef4e06318bb32cadb2 |
--- /dev/null |
+++ b/chrome/browser/instant/instant_client.cc |
@@ -0,0 +1,88 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/instant/instant_client.h" |
+ |
+#include "chrome/browser/instant/instant_controller.h" |
+#include "chrome/common/render_messages.h" |
+#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+InstantClient::InstantClient(InstantController* controller, |
+ content::WebContents* contents) |
+ : content::WebContentsObserver(contents), |
+ controller_(controller), |
+ supports_instant_(false) { |
+} |
+ |
+InstantClient::~InstantClient() { |
+} |
+ |
+void InstantClient::Update(const string16& user_text, bool verbatim) { |
+ // TODO: Support real cursor position. |
+ Send(new ChromeViewMsg_SearchBoxChange(routing_id(), user_text, verbatim, |
+ user_text.size(), user_text.size())); |
+} |
+ |
+void InstantClient::Submit(const string16& text) { |
+ Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); |
+} |
+ |
+void InstantClient::SendAutocompleteResults( |
+ const std::vector<InstantAutocompleteResult>& results) { |
+ Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); |
+} |
+ |
+void InstantClient::UpOrDownKeyPressed(int count) { |
+ Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); |
+} |
+ |
+void InstantClient::DetermineIfPageSupportsInstant() { |
+ Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
+} |
+ |
+bool InstantClient::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(InstantClient, message) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
+ OnInstantSupportDetermined) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void InstantClient::NotifyInstantSupportDetermined(bool supports_instant) { |
sky
2012/11/27 01:07:51
I would name this SetInstantSupportDetermined.
sreeram
2012/11/29 07:33:19
Done. Now it's just "InstantSupportDetermined".
|
+ // If we already determined that the page supports Instant, nothing to do. |
+ if (!supports_instant_) { |
+ supports_instant_ = supports_instant; |
+ controller_->InstantSupportDetermined(this, supports_instant); |
+ } |
+} |
+ |
+void InstantClient::DidFinishLoad(int64 frame_id, |
+ const GURL& validated_url, |
+ bool is_main_frame, |
+ content::RenderViewHost* render_view_host) { |
+ if (is_main_frame && !supports_instant_) |
+ DetermineIfPageSupportsInstant(); |
+} |
+ |
+void InstantClient::OnSetSuggestions( |
+ int page_id, |
+ const std::vector<InstantSuggestion>& suggestions) { |
+ content::NavigationEntry* entry = |
+ contents()->GetController().GetActiveEntry(); |
+ if (entry && page_id == entry->GetPageID()) { |
+ NotifyInstantSupportDetermined(true); |
+ controller_->SetSuggestions(this, suggestions); |
+ } |
+} |
+ |
+void InstantClient::OnInstantSupportDetermined(int page_id, bool result) { |
+ content::NavigationEntry* entry = |
+ contents()->GetController().GetActiveEntry(); |
+ if (entry && page_id == entry->GetPageID()) |
+ NotifyInstantSupportDetermined(result); |
+} |