Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/instant/instant_client.h" | |
| 6 | |
| 7 #include "chrome/browser/instant/instant_controller.h" | |
| 8 #include "chrome/common/render_messages.h" | |
| 9 #include "content/public/browser/navigation_entry.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 | |
| 12 InstantClient::InstantClient(InstantController* controller, | |
| 13 content::WebContents* contents) | |
| 14 : content::WebContentsObserver(contents), | |
| 15 controller_(controller), | |
| 16 supports_instant_(false) { | |
| 17 } | |
| 18 | |
| 19 InstantClient::~InstantClient() { | |
| 20 } | |
| 21 | |
| 22 void InstantClient::Update(const string16& user_text, bool verbatim) { | |
| 23 // TODO: Support real cursor position. | |
| 24 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), user_text, verbatim, | |
| 25 user_text.size(), user_text.size())); | |
| 26 } | |
| 27 | |
| 28 void InstantClient::Submit(const string16& text) { | |
| 29 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); | |
| 30 } | |
| 31 | |
| 32 void InstantClient::SendAutocompleteResults( | |
| 33 const std::vector<InstantAutocompleteResult>& results) { | |
| 34 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); | |
| 35 } | |
| 36 | |
| 37 void InstantClient::UpOrDownKeyPressed(int count) { | |
| 38 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); | |
| 39 } | |
| 40 | |
| 41 void InstantClient::DetermineIfPageSupportsInstant() { | |
| 42 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); | |
| 43 } | |
| 44 | |
| 45 bool InstantClient::OnMessageReceived(const IPC::Message& message) { | |
| 46 bool handled = true; | |
| 47 IPC_BEGIN_MESSAGE_MAP(InstantClient, message) | |
| 48 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) | |
| 49 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, | |
| 50 OnInstantSupportDetermined) | |
| 51 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 52 IPC_END_MESSAGE_MAP() | |
| 53 return handled; | |
| 54 } | |
| 55 | |
| 56 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".
| |
| 57 // If we already determined that the page supports Instant, nothing to do. | |
| 58 if (!supports_instant_) { | |
| 59 supports_instant_ = supports_instant; | |
| 60 controller_->InstantSupportDetermined(this, supports_instant); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void InstantClient::DidFinishLoad(int64 frame_id, | |
| 65 const GURL& validated_url, | |
| 66 bool is_main_frame, | |
| 67 content::RenderViewHost* render_view_host) { | |
| 68 if (is_main_frame && !supports_instant_) | |
| 69 DetermineIfPageSupportsInstant(); | |
| 70 } | |
| 71 | |
| 72 void InstantClient::OnSetSuggestions( | |
| 73 int page_id, | |
| 74 const std::vector<InstantSuggestion>& suggestions) { | |
| 75 content::NavigationEntry* entry = | |
| 76 contents()->GetController().GetActiveEntry(); | |
| 77 if (entry && page_id == entry->GetPageID()) { | |
| 78 NotifyInstantSupportDetermined(true); | |
| 79 controller_->SetSuggestions(this, suggestions); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 void InstantClient::OnInstantSupportDetermined(int page_id, bool result) { | |
| 84 content::NavigationEntry* entry = | |
| 85 contents()->GetController().GetActiveEntry(); | |
| 86 if (entry && page_id == entry->GetPageID()) | |
| 87 NotifyInstantSupportDetermined(result); | |
| 88 } | |
| OLD | NEW |