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/common/render_messages.h" |
| 8 #include "content/public/browser/web_contents.h" |
| 9 |
| 10 InstantClient::InstantClient(Delegate* delegate) : delegate_(delegate) { |
| 11 } |
| 12 |
| 13 InstantClient::~InstantClient() { |
| 14 } |
| 15 |
| 16 void InstantClient::SetContents(content::WebContents* contents) { |
| 17 Observe(contents); |
| 18 } |
| 19 |
| 20 void InstantClient::Update(const string16& text, bool verbatim) { |
| 21 // TODO: Support real cursor position. |
| 22 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim, |
| 23 text.size(), text.size())); |
| 24 } |
| 25 |
| 26 void InstantClient::Submit(const string16& text) { |
| 27 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); |
| 28 } |
| 29 |
| 30 void InstantClient::Cancel(const string16& text) { |
| 31 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); |
| 32 } |
| 33 |
| 34 void InstantClient::SetOmniboxBounds(const gfx::Rect& bounds) { |
| 35 Send(new ChromeViewMsg_SearchBoxResize(routing_id(), bounds)); |
| 36 } |
| 37 |
| 38 void InstantClient::DetermineIfPageSupportsInstant() { |
| 39 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| 40 } |
| 41 |
| 42 void InstantClient::SendAutocompleteResults( |
| 43 const std::vector<InstantAutocompleteResult>& results) { |
| 44 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); |
| 45 } |
| 46 |
| 47 void InstantClient::UpOrDownKeyPressed(int count) { |
| 48 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); |
| 49 } |
| 50 |
| 51 void InstantClient::SearchModeChanged(const chrome::search::Mode& mode) { |
| 52 Send(new ChromeViewMsg_SearchBoxModeChanged(routing_id(), mode)); |
| 53 } |
| 54 |
| 55 void InstantClient::SendThemeBackgroundInfo( |
| 56 const ThemeBackgroundInfo& theme_info) { |
| 57 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); |
| 58 } |
| 59 |
| 60 void InstantClient::SendThemeAreaHeight(int height) { |
| 61 Send(new ChromeViewMsg_SearchBoxThemeAreaHeightChanged(routing_id(), height)); |
| 62 } |
| 63 |
| 64 void InstantClient::DidFinishLoad( |
| 65 int64 /* frame_id */, |
| 66 const GURL& /* validated_url */, |
| 67 bool is_main_frame, |
| 68 content::RenderViewHost* /* render_view_host */) { |
| 69 if (is_main_frame) |
| 70 DetermineIfPageSupportsInstant(); |
| 71 } |
| 72 |
| 73 bool InstantClient::OnMessageReceived(const IPC::Message& message) { |
| 74 bool handled = true; |
| 75 IPC_BEGIN_MESSAGE_MAP(InstantClient, message) |
| 76 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, SetSuggestions) |
| 77 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| 78 InstantSupportDetermined) |
| 79 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview, |
| 80 ShowInstantPreview) |
| 81 IPC_MESSAGE_UNHANDLED(handled = false) |
| 82 IPC_END_MESSAGE_MAP() |
| 83 return handled; |
| 84 } |
| 85 |
| 86 void InstantClient::SetSuggestions( |
| 87 int page_id, |
| 88 const std::vector<InstantSuggestion>& suggestions) { |
| 89 if (web_contents()->IsActiveEntry(page_id)) |
| 90 delegate_->SetSuggestions(suggestions); |
| 91 } |
| 92 |
| 93 void InstantClient::InstantSupportDetermined(int page_id, bool result) { |
| 94 if (web_contents()->IsActiveEntry(page_id)) |
| 95 delegate_->InstantSupportDetermined(result); |
| 96 } |
| 97 |
| 98 void InstantClient::ShowInstantPreview(int page_id, |
| 99 InstantShownReason reason, |
| 100 int height, |
| 101 InstantSizeUnits units) { |
| 102 if (web_contents()->IsActiveEntry(page_id)) |
| 103 delegate_->ShowInstantPreview(reason, height, units); |
| 104 } |
OLD | NEW |