Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: chrome/browser/instant/instant_page.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo to fix blacklisting. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/instant/instant_page.h ('k') | chrome/browser/instant/instant_tab.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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_page.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/render_messages.h"
9 #include "content/public/browser/web_contents.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/font.h"
12
13 InstantPage::Delegate::~Delegate() {
14 }
15
16 InstantPage::~InstantPage() {
17 }
18
19 void InstantPage::Update(const string16& text,
20 size_t selection_start,
21 size_t selection_end,
22 bool verbatim) {
23 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim,
24 selection_start, selection_end));
25 }
26
27 void InstantPage::Submit(const string16& text) {
28 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
29 }
30
31 void InstantPage::Cancel(const string16& text) {
32 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text));
33 }
34
35 void InstantPage::SetPopupBounds(const gfx::Rect& bounds) {
36 Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds));
37 }
38
39 void InstantPage::SetMarginSize(const int start, const int end) {
40 Send(new ChromeViewMsg_SearchBoxMarginChange(routing_id(), start, end));
41 }
42
43 void InstantPage::InitializeFonts() {
44 const gfx::Font& omnibox_font =
45 ui::ResourceBundle::GetSharedInstance().GetFont(
46 ui::ResourceBundle::MediumFont);
47 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
48 size_t omnibox_font_size = omnibox_font.GetFontSize();
49 Send(new ChromeViewMsg_SearchBoxFontInformation(
50 routing_id(), omnibox_font_name, omnibox_font_size));
51 }
52
53 void InstantPage::DetermineIfPageSupportsInstant() {
54 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
55 }
56
57 void InstantPage::SendAutocompleteResults(
58 const std::vector<InstantAutocompleteResult>& results) {
59 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
60 }
61
62 void InstantPage::UpOrDownKeyPressed(int count) {
63 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
64 }
65
66 void InstantPage::SearchModeChanged(const chrome::search::Mode& mode) {
67 Send(new ChromeViewMsg_SearchBoxModeChanged(routing_id(), mode));
68 }
69
70 void InstantPage::SendThemeBackgroundInfo(
71 const ThemeBackgroundInfo& theme_info) {
72 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
73 }
74
75 void InstantPage::SendThemeAreaHeight(int height) {
76 Send(new ChromeViewMsg_SearchBoxThemeAreaHeightChanged(routing_id(), height));
77 }
78
79 void InstantPage::SetDisplayInstantResults(bool display_instant_results) {
80 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(
81 routing_id(), display_instant_results));
82 }
83
84 void InstantPage::KeyCaptureChanged(bool is_key_capture_enabled) {
85 Send(new ChromeViewMsg_SearchBoxKeyCaptureChanged(
86 routing_id(), is_key_capture_enabled));
87 }
88
89 InstantPage::InstantPage(Delegate* delegate)
90 : delegate_(delegate),
91 supports_instant_(false) {
92 }
93
94 void InstantPage::SetContents(content::WebContents* contents) {
95 Observe(contents);
96 }
97
98 bool InstantPage::ShouldProcessRenderViewCreated() {
99 return false;
100 }
101
102 bool InstantPage::ShouldProcessRenderViewGone() {
103 return false;
104 }
105
106 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() {
107 return false;
108 }
109
110 bool InstantPage::ShouldProcessSetSuggestions() {
111 return false;
112 }
113
114 bool InstantPage::ShouldProcessShowInstantPreview() {
115 return false;
116 }
117
118 bool InstantPage::ShouldProcessStartCapturingKeyStrokes() {
119 return false;
120 }
121
122 bool InstantPage::ShouldProcessStopCapturingKeyStrokes() {
123 return false;
124 }
125
126 bool InstantPage::ShouldProcessNavigateToURL() {
127 return false;
128 }
129
130 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) {
131 if (ShouldProcessRenderViewCreated())
132 delegate_->InstantPageRenderViewCreated(contents());
133 }
134
135 void InstantPage::DidFinishLoad(
136 int64 /* frame_id */,
137 const GURL& /* validated_url */,
138 bool is_main_frame,
139 content::RenderViewHost* /* render_view_host */) {
140 if (is_main_frame && !supports_instant_)
141 DetermineIfPageSupportsInstant();
142 }
143
144 bool InstantPage::OnMessageReceived(const IPC::Message& message) {
145 bool handled = true;
146 IPC_BEGIN_MESSAGE_MAP(InstantPage, message)
147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions)
148 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
149 OnInstantSupportDetermined)
150 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview,
151 OnShowInstantPreview)
152 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes,
153 OnStartCapturingKeyStrokes);
154 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes,
155 OnStopCapturingKeyStrokes);
156 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
157 OnSearchBoxNavigate);
158 IPC_MESSAGE_UNHANDLED(handled = false)
159 IPC_END_MESSAGE_MAP()
160 return handled;
161 }
162
163 void InstantPage::RenderViewGone(base::TerminationStatus /* status */) {
164 if (ShouldProcessRenderViewGone())
165 delegate_->InstantPageRenderViewGone(contents());
166 }
167
168 void InstantPage::DidCommitProvisionalLoadForFrame(
169 int64 /* frame_id */,
170 bool is_main_frame,
171 const GURL& url,
172 content::PageTransition /* transition_type */,
173 content::RenderViewHost* /* render_view_host */) {
174 if (is_main_frame && ShouldProcessAboutToNavigateMainFrame())
175 delegate_->InstantPageAboutToNavigateMainFrame(contents(), url);
176 }
177
178 void InstantPage::OnSetSuggestions(
179 int page_id,
180 const std::vector<InstantSuggestion>& suggestions) {
181 if (contents()->IsActiveEntry(page_id)) {
182 OnInstantSupportDetermined(page_id, true);
183 if (ShouldProcessSetSuggestions())
184 delegate_->SetSuggestions(contents(), suggestions);
185 }
186 }
187
188 void InstantPage::OnInstantSupportDetermined(int page_id,
189 bool supports_instant) {
190 if (!contents()->IsActiveEntry(page_id) || supports_instant_) {
191 // Nothing to do if the page already supports Instant.
192 return;
193 }
194
195 supports_instant_ = supports_instant;
196 delegate_->InstantSupportDetermined(contents(), supports_instant);
197
198 // If the page doesn't support Instant, stop listening to it.
199 if (!supports_instant)
200 Observe(NULL);
201 }
202
203 void InstantPage::OnShowInstantPreview(int page_id,
204 InstantShownReason reason,
205 int height,
206 InstantSizeUnits units) {
207 if (contents()->IsActiveEntry(page_id)) {
208 OnInstantSupportDetermined(page_id, true);
209 if (ShouldProcessShowInstantPreview())
210 delegate_->ShowInstantPreview(contents(), reason, height, units);
211 }
212 }
213
214 void InstantPage::OnStartCapturingKeyStrokes(int page_id) {
215 if (contents()->IsActiveEntry(page_id)) {
216 OnInstantSupportDetermined(page_id, true);
217 if (ShouldProcessStartCapturingKeyStrokes())
218 delegate_->StartCapturingKeyStrokes(contents());
219 }
220 }
221
222 void InstantPage::OnStopCapturingKeyStrokes(int page_id) {
223 if (contents()->IsActiveEntry(page_id)) {
224 OnInstantSupportDetermined(page_id, true);
225 if (ShouldProcessStopCapturingKeyStrokes())
226 delegate_->StopCapturingKeyStrokes(contents());
227 }
228 }
229
230 void InstantPage::OnSearchBoxNavigate(int page_id,
231 const GURL& url,
232 content::PageTransition transition) {
233 if (contents()->IsActiveEntry(page_id)) {
234 OnInstantSupportDetermined(page_id, true);
235 if (ShouldProcessNavigateToURL())
236 delegate_->NavigateToURL(contents(), url, transition);
237 }
238 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_page.h ('k') | chrome/browser/instant/instant_tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698