1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// 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 "base/utf_string_conversions.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
InstantClient::Delegate::~Delegate() {
}
InstantClient::InstantClient(Delegate* delegate) : delegate_(delegate) {
}
InstantClient::~InstantClient() {
}
void InstantClient::SetContents(content::WebContents* contents) {
Observe(contents);
}
void InstantClient::Update(const string16& text,
size_t selection_start,
size_t selection_end,
bool verbatim) {
Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim,
selection_start, selection_end));
}
void InstantClient::Submit(const string16& text) {
Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
}
void InstantClient::Cancel(const string16& text) {
Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text));
}
void InstantClient::SetPopupBounds(const gfx::Rect& bounds) {
Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds));
}
void InstantClient::SetMarginSize(const int start, const int end) {
Send(new ChromeViewMsg_SearchBoxMarginChange(routing_id(), start, end));
}
void InstantClient::InitializeFonts() {
const gfx::Font& omnibox_font =
ui::ResourceBundle::GetSharedInstance().GetFont(
ui::ResourceBundle::MediumFont);
string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
size_t omnibox_font_size = omnibox_font.GetFontSize();
Send(new ChromeViewMsg_SearchBoxFontInformation(
routing_id(), omnibox_font_name, omnibox_font_size));
}
void InstantClient::DetermineIfPageSupportsInstant() {
Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
}
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::SearchModeChanged(const chrome::search::Mode& mode) {
Send(new ChromeViewMsg_SearchBoxModeChanged(routing_id(), mode));
}
void InstantClient::SendThemeBackgroundInfo(
const ThemeBackgroundInfo& theme_info) {
Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
}
void InstantClient::SendThemeAreaHeight(int height) {
Send(new ChromeViewMsg_SearchBoxThemeAreaHeightChanged(routing_id(), height));
}
void InstantClient::SetDisplayInstantResults(bool display_instant_results) {
Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(routing_id(),
display_instant_results));
}
void InstantClient::KeyCaptureChanged(bool is_key_capture_enabled) {
Send(new ChromeViewMsg_SearchBoxKeyCaptureChanged(routing_id(),
is_key_capture_enabled));
}
void InstantClient::RenderViewCreated(
content::RenderViewHost* render_view_host) {
delegate_->RenderViewCreated();
}
void InstantClient::DidFinishLoad(
int64 /* frame_id */,
const GURL& /* validated_url */,
bool is_main_frame,
content::RenderViewHost* /* render_view_host */) {
if (is_main_frame)
DetermineIfPageSupportsInstant();
}
bool InstantClient::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(InstantClient, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, SetSuggestions)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
InstantSupportDetermined)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview,
ShowInstantPreview)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes,
StartCapturingKeyStrokes);
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes,
StopCapturingKeyStrokes);
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
SearchBoxNavigate);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void InstantClient::RenderViewGone(base::TerminationStatus status) {
delegate_->RenderViewGone();
}
void InstantClient::DidCommitProvisionalLoadForFrame(
int64 frame_id,
bool is_main_frame,
const GURL& url,
content::PageTransition transition_type,
content::RenderViewHost* render_view_host) {
if (!is_main_frame)
return;
delegate_->AboutToNavigateMainFrame(url);
}
void InstantClient::SetSuggestions(
int page_id,
const std::vector<InstantSuggestion>& suggestions) {
if (web_contents()->IsActiveEntry(page_id))
delegate_->SetSuggestions(suggestions);
}
void InstantClient::InstantSupportDetermined(int page_id, bool result) {
if (web_contents()->IsActiveEntry(page_id))
delegate_->InstantSupportDetermined(result);
}
void InstantClient::ShowInstantPreview(int page_id,
InstantShownReason reason,
int height,
InstantSizeUnits units) {
if (web_contents()->IsActiveEntry(page_id))
delegate_->ShowInstantPreview(reason, height, units);
}
void InstantClient::StartCapturingKeyStrokes(int page_id) {
if (web_contents()->IsActiveEntry(page_id))
delegate_->StartCapturingKeyStrokes();
}
void InstantClient::StopCapturingKeyStrokes(int page_id) {
if (web_contents()->IsActiveEntry(page_id))
delegate_->StopCapturingKeyStrokes();
}
void InstantClient::SearchBoxNavigate(int page_id,
const GURL& url,
content::PageTransition transition) {
if (web_contents()->IsActiveEntry(page_id))
delegate_->NavigateToURL(url, transition);
}
|