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

Side by Side Diff: chrome/browser/ui/search/search_ipc_router.cc

Issue 292123015: Remove WebContents::IsActiveEntry from Instant Extended and from WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/search_ipc_router.h" 5 #include "chrome/browser/ui/search/search_ipc_router.h"
6 6
7 #include "chrome/browser/search/search.h" 7 #include "chrome/browser/search/search.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
10 11
11 namespace { 12 namespace {
12 13
13 bool IsProviderValid(const base::string16& provider) { 14 bool IsProviderValid(const base::string16& provider) {
14 // Only allow string of 8 alphanumeric characters or less as providers. 15 // Only allow string of 8 alphanumeric characters or less as providers.
15 // The empty string is considered valid and should be treated as if no 16 // The empty string is considered valid and should be treated as if no
16 // provider were specified. 17 // provider were specified.
17 if (provider.length() > 8) 18 if (provider.length() > 8)
18 return false; 19 return false;
19 for (base::string16::const_iterator it = provider.begin(); 20 for (base::string16::const_iterator it = provider.begin();
20 it != provider.end(); ++it) { 21 it != provider.end(); ++it) {
21 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it)) 22 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it))
22 return false; 23 return false;
23 } 24 }
24 return true; 25 return true;
25 } 26 }
26 27
27 } // namespace 28 } // namespace
28 29
29 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, 30 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents,
30 Delegate* delegate, scoped_ptr<Policy> policy) 31 Delegate* delegate, scoped_ptr<Policy> policy)
31 : WebContentsObserver(web_contents), 32 : WebContentsObserver(web_contents),
32 delegate_(delegate), 33 delegate_(delegate),
33 policy_(policy.Pass()), 34 policy_(policy.Pass()),
35 commit_counter_(0),
34 is_active_tab_(false) { 36 is_active_tab_(false) {
35 DCHECK(web_contents); 37 DCHECK(web_contents);
36 DCHECK(delegate); 38 DCHECK(delegate);
37 DCHECK(policy_.get()); 39 DCHECK(policy_.get());
38 } 40 }
39 41
40 SearchIPCRouter::~SearchIPCRouter() {} 42 SearchIPCRouter::~SearchIPCRouter() {}
41 43
44 void SearchIPCRouter::OnNavigationEntryCommitted() {
45 ++commit_counter_;
46 Send(new ChromeViewMsg_SetPageSequenceNumber(routing_id(), commit_counter_));
47 }
48
42 void SearchIPCRouter::DetermineIfPageSupportsInstant() { 49 void SearchIPCRouter::DetermineIfPageSupportsInstant() {
43 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); 50 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
44 } 51 }
45 52
46 void SearchIPCRouter::SendChromeIdentityCheckResult( 53 void SearchIPCRouter::SendChromeIdentityCheckResult(
47 const base::string16& identity, 54 const base::string16& identity,
48 bool identity_match) { 55 bool identity_match) {
49 if (!policy_->ShouldProcessChromeIdentityCheck()) 56 if (!policy_->ShouldProcessChromeIdentityCheck())
50 return; 57 return;
51 58
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 OnLogMostVisitedNavigation); 172 OnLogMostVisitedNavigation);
166 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, 173 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown,
167 OnPasteAndOpenDropDown); 174 OnPasteAndOpenDropDown);
168 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck, 175 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck,
169 OnChromeIdentityCheck); 176 OnChromeIdentityCheck);
170 IPC_MESSAGE_UNHANDLED(handled = false) 177 IPC_MESSAGE_UNHANDLED(handled = false)
171 IPC_END_MESSAGE_MAP() 178 IPC_END_MESSAGE_MAP()
172 return handled; 179 return handled;
173 } 180 }
174 181
175 void SearchIPCRouter::OnInstantSupportDetermined(int page_id, 182 void SearchIPCRouter::OnInstantSupportDetermined(int page_seq_no,
176 bool instant_support) const { 183 bool instant_support) const {
177 if (!web_contents()->IsActiveEntry(page_id)) 184 if (page_seq_no != commit_counter_)
178 return; 185 return;
179 186
180 delegate_->OnInstantSupportDetermined(instant_support); 187 delegate_->OnInstantSupportDetermined(instant_support);
181 } 188 }
182 189
183 void SearchIPCRouter::OnVoiceSearchSupportDetermined( 190 void SearchIPCRouter::OnVoiceSearchSupportDetermined(
184 int page_id, 191 int page_seq_no,
185 bool supports_voice_search) const { 192 bool supports_voice_search) const {
186 if (!web_contents()->IsActiveEntry(page_id)) 193 if (page_seq_no != commit_counter_)
187 return; 194 return;
188 195
189 delegate_->OnInstantSupportDetermined(true); 196 delegate_->OnInstantSupportDetermined(true);
190 if (!policy_->ShouldProcessSetVoiceSearchSupport()) 197 if (!policy_->ShouldProcessSetVoiceSearchSupport())
191 return; 198 return;
192 199
193 delegate_->OnSetVoiceSearchSupport(supports_voice_search); 200 delegate_->OnSetVoiceSearchSupport(supports_voice_search);
194 } 201 }
195 202
196 void SearchIPCRouter::OnFocusOmnibox(int page_id, 203 void SearchIPCRouter::OnFocusOmnibox(int page_seq_no,
197 OmniboxFocusState state) const { 204 OmniboxFocusState state) const {
198 if (!web_contents()->IsActiveEntry(page_id)) 205 if (page_seq_no != commit_counter_)
199 return; 206 return;
200 207
201 delegate_->OnInstantSupportDetermined(true); 208 delegate_->OnInstantSupportDetermined(true);
202 if (!policy_->ShouldProcessFocusOmnibox(is_active_tab_)) 209 if (!policy_->ShouldProcessFocusOmnibox(is_active_tab_))
203 return; 210 return;
204 211
205 delegate_->FocusOmnibox(state); 212 delegate_->FocusOmnibox(state);
206 } 213 }
207 214
208 void SearchIPCRouter::OnSearchBoxNavigate( 215 void SearchIPCRouter::OnSearchBoxNavigate(
209 int page_id, 216 int page_seq_no,
210 const GURL& url, 217 const GURL& url,
211 WindowOpenDisposition disposition, 218 WindowOpenDisposition disposition,
212 bool is_most_visited_item_url) const { 219 bool is_most_visited_item_url) const {
213 if (!web_contents()->IsActiveEntry(page_id)) 220 if (page_seq_no != commit_counter_)
214 return; 221 return;
215 222
216 delegate_->OnInstantSupportDetermined(true); 223 delegate_->OnInstantSupportDetermined(true);
217 if (!policy_->ShouldProcessNavigateToURL(is_active_tab_)) 224 if (!policy_->ShouldProcessNavigateToURL(is_active_tab_))
218 return; 225 return;
219 226
220 delegate_->NavigateToURL(url, disposition, is_most_visited_item_url); 227 delegate_->NavigateToURL(url, disposition, is_most_visited_item_url);
221 } 228 }
222 229
223 void SearchIPCRouter::OnDeleteMostVisitedItem(int page_id, 230 void SearchIPCRouter::OnDeleteMostVisitedItem(int page_seq_no,
224 const GURL& url) const { 231 const GURL& url) const {
225 if (!web_contents()->IsActiveEntry(page_id)) 232 if (page_seq_no != commit_counter_)
226 return; 233 return;
227 234
228 delegate_->OnInstantSupportDetermined(true); 235 delegate_->OnInstantSupportDetermined(true);
229 if (!policy_->ShouldProcessDeleteMostVisitedItem()) 236 if (!policy_->ShouldProcessDeleteMostVisitedItem())
230 return; 237 return;
231 238
232 delegate_->OnDeleteMostVisitedItem(url); 239 delegate_->OnDeleteMostVisitedItem(url);
233 } 240 }
234 241
235 void SearchIPCRouter::OnUndoMostVisitedDeletion(int page_id, 242 void SearchIPCRouter::OnUndoMostVisitedDeletion(int page_seq_no,
236 const GURL& url) const { 243 const GURL& url) const {
237 if (!web_contents()->IsActiveEntry(page_id)) 244 if (page_seq_no != commit_counter_)
238 return; 245 return;
239 246
240 delegate_->OnInstantSupportDetermined(true); 247 delegate_->OnInstantSupportDetermined(true);
241 if (!policy_->ShouldProcessUndoMostVisitedDeletion()) 248 if (!policy_->ShouldProcessUndoMostVisitedDeletion())
242 return; 249 return;
243 250
244 delegate_->OnUndoMostVisitedDeletion(url); 251 delegate_->OnUndoMostVisitedDeletion(url);
245 } 252 }
246 253
247 void SearchIPCRouter::OnUndoAllMostVisitedDeletions(int page_id) const { 254 void SearchIPCRouter::OnUndoAllMostVisitedDeletions(int page_seq_no) const {
248 if (!web_contents()->IsActiveEntry(page_id)) 255 if (page_seq_no != commit_counter_)
249 return; 256 return;
250 257
251 delegate_->OnInstantSupportDetermined(true); 258 delegate_->OnInstantSupportDetermined(true);
252 if (!policy_->ShouldProcessUndoAllMostVisitedDeletions()) 259 if (!policy_->ShouldProcessUndoAllMostVisitedDeletions())
253 return; 260 return;
254 261
255 delegate_->OnUndoAllMostVisitedDeletions(); 262 delegate_->OnUndoAllMostVisitedDeletions();
256 } 263 }
257 264
258 void SearchIPCRouter::OnLogEvent(int page_id, NTPLoggingEventType event) const { 265 void SearchIPCRouter::OnLogEvent(int page_seq_no,
259 if (!web_contents()->IsActiveEntry(page_id)) 266 NTPLoggingEventType event) const {
267 if (page_seq_no != commit_counter_)
260 return; 268 return;
261 269
262 delegate_->OnInstantSupportDetermined(true); 270 delegate_->OnInstantSupportDetermined(true);
263 if (!policy_->ShouldProcessLogEvent()) 271 if (!policy_->ShouldProcessLogEvent())
264 return; 272 return;
265 273
266 delegate_->OnLogEvent(event); 274 delegate_->OnLogEvent(event);
267 } 275 }
268 276
269 void SearchIPCRouter::OnLogMostVisitedImpression( 277 void SearchIPCRouter::OnLogMostVisitedImpression(
270 int page_id, int position, const base::string16& provider) const { 278 int page_seq_no, int position, const base::string16& provider) const {
271 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider)) 279 if (page_seq_no != commit_counter_ || !IsProviderValid(provider))
272 return; 280 return;
273 281
274 delegate_->OnInstantSupportDetermined(true); 282 delegate_->OnInstantSupportDetermined(true);
275 // Logging impressions is controlled by the same policy as logging events. 283 // Logging impressions is controlled by the same policy as logging events.
276 if (!policy_->ShouldProcessLogEvent()) 284 if (!policy_->ShouldProcessLogEvent())
277 return; 285 return;
278 286
279 delegate_->OnLogMostVisitedImpression(position, provider); 287 delegate_->OnLogMostVisitedImpression(position, provider);
280 } 288 }
281 289
282 void SearchIPCRouter::OnLogMostVisitedNavigation( 290 void SearchIPCRouter::OnLogMostVisitedNavigation(
283 int page_id, int position, const base::string16& provider) const { 291 int page_seq_no, int position, const base::string16& provider) const {
284 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider)) 292 if (page_seq_no != commit_counter_ || !IsProviderValid(provider))
285 return; 293 return;
286 294
287 delegate_->OnInstantSupportDetermined(true); 295 delegate_->OnInstantSupportDetermined(true);
288 // Logging navigations is controlled by the same policy as logging events. 296 // Logging navigations is controlled by the same policy as logging events.
289 if (!policy_->ShouldProcessLogEvent()) 297 if (!policy_->ShouldProcessLogEvent())
290 return; 298 return;
291 299
292 delegate_->OnLogMostVisitedNavigation(position, provider); 300 delegate_->OnLogMostVisitedNavigation(position, provider);
293 } 301 }
294 302
295 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_id, 303 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_seq_no,
296 const base::string16& text) const { 304 const base::string16& text) const {
297 if (!web_contents()->IsActiveEntry(page_id)) 305 if (page_seq_no != commit_counter_)
298 return; 306 return;
299 307
300 delegate_->OnInstantSupportDetermined(true); 308 delegate_->OnInstantSupportDetermined(true);
301 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_)) 309 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_))
302 return; 310 return;
303 311
304 delegate_->PasteIntoOmnibox(text); 312 delegate_->PasteIntoOmnibox(text);
305 } 313 }
306 314
307 void SearchIPCRouter::OnChromeIdentityCheck( 315 void SearchIPCRouter::OnChromeIdentityCheck(
308 int page_id, 316 int page_seq_no,
309 const base::string16& identity) const { 317 const base::string16& identity) const {
310 if (!web_contents()->IsActiveEntry(page_id)) 318 if (page_seq_no != commit_counter_)
311 return; 319 return;
312 320
313 delegate_->OnInstantSupportDetermined(true); 321 delegate_->OnInstantSupportDetermined(true);
314 if (!policy_->ShouldProcessChromeIdentityCheck()) 322 if (!policy_->ShouldProcessChromeIdentityCheck())
315 return; 323 return;
316 324
317 delegate_->OnChromeIdentityCheck(identity); 325 delegate_->OnChromeIdentityCheck(identity);
318 } 326 }
319 327
320 void SearchIPCRouter::set_delegate(Delegate* delegate) { 328 void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) {
321 DCHECK(delegate); 329 DCHECK(delegate);
322 delegate_ = delegate; 330 delegate_ = delegate;
323 } 331 }
324 332
325 void SearchIPCRouter::set_policy(scoped_ptr<Policy> policy) { 333 void SearchIPCRouter::set_policy_for_testing(scoped_ptr<Policy> policy) {
326 DCHECK(policy.get()); 334 DCHECK(policy.get());
327 policy_.reset(policy.release()); 335 policy_.reset(policy.release());
328 } 336 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router.h ('k') | chrome/browser/ui/search/search_ipc_router_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698