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

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: Address comments. 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
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::DetermineIfPageSupportsInstant() {
44 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
45 }
46
47 void InstantPage::SendAutocompleteResults(
48 const std::vector<InstantAutocompleteResult>& results) {
49 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
50 }
51
52 void InstantPage::UpOrDownKeyPressed(int count) {
53 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
54 }
55
56 void InstantPage::SearchModeChanged(const chrome::search::Mode& mode) {
57 Send(new ChromeViewMsg_SearchBoxModeChanged(routing_id(), mode));
58 }
59
60 void InstantPage::SendThemeBackgroundInfo(
61 const ThemeBackgroundInfo& theme_info) {
62 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
63 }
64
65 void InstantPage::SendThemeAreaHeight(int height) {
66 Send(new ChromeViewMsg_SearchBoxThemeAreaHeightChanged(routing_id(), height));
67 }
68
69 void InstantPage::SetDisplayInstantResults(bool display_instant_results) {
70 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(
71 routing_id(), display_instant_results));
72 }
73
74 void InstantPage::KeyCaptureChanged(bool is_key_capture_enabled) {
75 Send(new ChromeViewMsg_SearchBoxKeyCaptureChanged(
76 routing_id(), is_key_capture_enabled));
77 }
78
79 InstantPage::InstantPage(Delegate* delegate)
80 : delegate_(delegate),
81 contents_(NULL),
82 supports_instant_(false) {
83 }
84
85 void InstantPage::SetContents(content::WebContents* contents) {
86 Observe(contents);
87 contents_ = contents;
88 }
89
90 bool InstantPage::ShouldProcessRenderViewGone() const {
91 return true;
92 }
93
94 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() const {
95 return true;
96 }
97
98 bool InstantPage::ShouldProcessSetSuggestions() const {
99 return true;
100 }
101
102 bool InstantPage::ShouldProcessShowInstantPreview() const {
103 return true;
104 }
105
106 bool InstantPage::ShouldProcessStartCapturingKeyStrokes() const {
107 return true;
108 }
109
110 bool InstantPage::ShouldProcessStopCapturingKeyStrokes() const {
111 return true;
112 }
113
114 bool InstantPage::ShouldProcessNavigateToURL() const {
115 return true;
116 }
117
118 void InstantPage::DidFinishLoad(
119 int64 /* frame_id */,
120 const GURL& /* validated_url */,
121 bool is_main_frame,
122 content::RenderViewHost* /* render_view_host */) {
123 if (is_main_frame && !supports_instant_)
124 DetermineIfPageSupportsInstant();
125 }
126
127 bool InstantPage::OnMessageReceived(const IPC::Message& message) {
128 bool handled = true;
129 IPC_BEGIN_MESSAGE_MAP(InstantPage, message)
130 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions)
131 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
132 OnInstantSupportDetermined)
133 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview,
134 OnShowInstantPreview)
135 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes,
136 OnStartCapturingKeyStrokes);
137 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes,
138 OnStopCapturingKeyStrokes);
139 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
140 OnSearchBoxNavigate);
141 IPC_MESSAGE_UNHANDLED(handled = false)
142 IPC_END_MESSAGE_MAP()
143 return handled;
144 }
145
146 void InstantPage::RenderViewGone(base::TerminationStatus status) {
sreeram 2013/01/29 13:35:42 /* status */
samarth 2013/01/31 16:24:57 Done.
147 if (ShouldProcessRenderViewGone())
148 delegate_->InstantPageRenderViewGone(contents_);
149 }
150
151 void InstantPage::DidCommitProvisionalLoadForFrame(
152 int64 frame_id,
153 bool is_main_frame,
154 const GURL& url,
155 content::PageTransition transition_type,
156 content::RenderViewHost* render_view_host) {
sreeram 2013/01/29 13:35:42 Comment out names that are unused.
samarth 2013/01/31 16:24:57 Done.
157 if (is_main_frame && ShouldProcessAboutToNavigateMainFrame())
158 delegate_->InstantPageAboutToNavigateMainFrame(contents_, url);
159 }
160
161 void InstantPage::OnSetSuggestions(
162 int page_id,
163 const std::vector<InstantSuggestion>& suggestions) {
164 if (contents_ && contents_->IsActiveEntry(page_id)) {
165 OnInstantSupportDetermined(page_id, true);
166 if (ShouldProcessSetSuggestions())
167 delegate_->SetSuggestions(contents_, suggestions);
168 }
169 }
170
171 void InstantPage::OnInstantSupportDetermined(int page_id,
172 bool supports_instant) {
173 if (!contents_ || !contents_->IsActiveEntry(page_id) || supports_instant_) {
174 // Nothing to do if the page already supports instant.
175 return;
176 }
177
178 supports_instant_ = supports_instant;
179 delegate_->InstantSupportDetermined(contents_, supports_instant);
180
181 if (supports_instant) {
182 // Inform the renderer process of the Omnibox's font information.
183 // TODO(samarth): this logic doesn't really belong here. Move this to
184 // InstantController.
185 const gfx::Font& omnibox_font =
186 ui::ResourceBundle::GetSharedInstance().GetFont(
187 ui::ResourceBundle::MediumFont);
188 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
189 size_t omnibox_font_size = omnibox_font.GetFontSize();
sreeram 2013/01/29 13:35:42 Note: Shishir is fixing this in https://codereview
samarth 2013/01/31 16:24:57 Noted.
190
191 Send(new ChromeViewMsg_SearchBoxFontInformation(
192 routing_id(), omnibox_font_name, omnibox_font_size));
193 } else {
194 // If the page doesn't support Instant, stop listening to it.
195 Observe(NULL);
196 }
197 }
198
199 void InstantPage::OnShowInstantPreview(int page_id,
200 InstantShownReason reason,
201 int height,
202 InstantSizeUnits units) {
203 if (contents_ && contents_->IsActiveEntry(page_id)) {
204 OnInstantSupportDetermined(page_id, true);
205 if (ShouldProcessShowInstantPreview())
206 delegate_->ShowInstantPreview(contents_, reason, height, units);
207 }
208 }
209
210 void InstantPage::OnStartCapturingKeyStrokes(int page_id) {
211 if (contents_ && contents_->IsActiveEntry(page_id)) {
212 OnInstantSupportDetermined(page_id, true);
213 if (ShouldProcessStartCapturingKeyStrokes())
214 delegate_->StartCapturingKeyStrokes(contents_);
215 }
216 }
217
218 void InstantPage::OnStopCapturingKeyStrokes(int page_id) {
219 if (contents_ && contents_->IsActiveEntry(page_id)) {
220 OnInstantSupportDetermined(page_id, true);
221 if (ShouldProcessStopCapturingKeyStrokes())
222 delegate_->StopCapturingKeyStrokes(contents_);
223 }
224 }
225
226 void InstantPage::OnSearchBoxNavigate(int page_id,
227 const GURL& url,
228 content::PageTransition transition) {
229 if (contents_ && contents_->IsActiveEntry(page_id)) {
230 OnInstantSupportDetermined(page_id, true);
231 if (ShouldProcessNavigateToURL())
232 delegate_->NavigateToURL(contents_, url, transition);
233 }
234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698