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

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

Issue 10879043: Centralize logic around Instant modes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a few more style nits Created 8 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/instant/instant_loader.h" 5 #include "chrome/browser/instant/instant_loader.h"
6 6
7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
8 #include "chrome/browser/history/history_types.h" 8 #include "chrome/browser/history/history_types.h"
9 #include "chrome/browser/instant/instant_loader_delegate.h" 9 #include "chrome/browser/instant/instant_loader_delegate.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return handled; 195 return handled;
196 } 196 }
197 197
198 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( 198 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions(
199 int page_id, 199 int page_id,
200 const std::vector<InstantSuggestion>& suggestions) { 200 const std::vector<InstantSuggestion>& suggestions) {
201 DCHECK(loader_->preview_contents() && 201 DCHECK(loader_->preview_contents() &&
202 loader_->preview_contents_->web_contents()); 202 loader_->preview_contents_->web_contents());
203 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. 203 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed.
204 if (!loader_->preview_contents() || 204 if (!loader_->preview_contents() ||
205 !loader_->preview_contents_->web_contents()) { 205 !loader_->preview_contents_->web_contents())
206 return; 206 return;
207 }
208 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> 207 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()->
209 GetController().GetActiveEntry(); 208 GetController().GetActiveEntry();
210 if (entry && page_id == entry->GetPageID()) { 209 if (entry && page_id == entry->GetPageID()) {
211 MaybeSetAndNotifyInstantSupportDetermined(true); 210 MaybeSetAndNotifyInstantSupportDetermined(true);
212 loader_->loader_delegate_->SetSuggestions(loader_, suggestions); 211 loader_->loader_delegate_->SetSuggestions(loader_, suggestions);
213 } 212 }
214 } 213 }
215 214
216 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( 215 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined(
217 int page_id, 216 int page_id,
218 bool result) { 217 bool result) {
219 DCHECK(loader_->preview_contents() && 218 DCHECK(loader_->preview_contents() &&
220 loader_->preview_contents_->web_contents()); 219 loader_->preview_contents_->web_contents());
221 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. 220 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed.
222 if (!loader_->preview_contents() || 221 if (!loader_->preview_contents() ||
223 !loader_->preview_contents_->web_contents()) { 222 !loader_->preview_contents_->web_contents())
224 return; 223 return;
225 }
226 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> 224 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()->
227 GetController().GetActiveEntry(); 225 GetController().GetActiveEntry();
228 if (entry && page_id == entry->GetPageID()) 226 if (entry && page_id == entry->GetPageID())
229 MaybeSetAndNotifyInstantSupportDetermined(result); 227 MaybeSetAndNotifyInstantSupportDetermined(result);
230 } 228 }
231 229
232 230
233 void InstantLoader::WebContentsDelegateImpl 231 void InstantLoader::WebContentsDelegateImpl
234 ::CommitFromPointerReleaseIfNecessary() { 232 ::CommitFromPointerReleaseIfNecessary() {
235 if (is_pointer_down_from_activate_) { 233 if (is_pointer_down_from_activate_) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 content::RenderViewHost* rvh = 306 content::RenderViewHost* rvh =
309 preview_contents_->web_contents()->GetRenderViewHost(); 307 preview_contents_->web_contents()->GetRenderViewHost();
310 rvh->Send(new ChromeViewMsg_SearchBoxAutocompleteResults(rvh->GetRoutingID(), 308 rvh->Send(new ChromeViewMsg_SearchBoxAutocompleteResults(rvh->GetRoutingID(),
311 results)); 309 results));
312 } 310 }
313 311
314 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type, 312 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type,
315 const string16& text) { 313 const string16& text) {
316 content::RenderViewHost* rvh = 314 content::RenderViewHost* rvh =
317 preview_contents_->web_contents()->GetRenderViewHost(); 315 preview_contents_->web_contents()->GetRenderViewHost();
318 if (type == INSTANT_COMMIT_PRESSED_ENTER) { 316 if (type == INSTANT_COMMIT_PRESSED_ENTER)
319 rvh->Send(new ChromeViewMsg_SearchBoxSubmit(rvh->GetRoutingID(), text)); 317 rvh->Send(new ChromeViewMsg_SearchBoxSubmit(rvh->GetRoutingID(), text));
320 } else { 318 else
321 rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text)); 319 rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text));
322 }
323 CleanupPreviewContents(); 320 CleanupPreviewContents();
324 return preview_contents_.release(); 321 return preview_contents_.release();
325 } 322 }
326 323
327 bool InstantLoader::IsPointerDownFromActivate() const { 324 bool InstantLoader::IsPointerDownFromActivate() const {
328 return preview_delegate_->is_pointer_down_from_activate(); 325 return preview_delegate_->is_pointer_down_from_activate();
329 } 326 }
330 327
331 void InstantLoader::Observe(int type, 328 void InstantLoader::Observe(int type,
332 const content::NotificationSource& source, 329 const content::NotificationSource& source,
333 const content::NotificationDetails& details) { 330 const content::NotificationDetails& details) {
334 #if defined(OS_MACOSX) 331 #if defined(OS_MACOSX)
335 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { 332 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) {
336 if (content::RenderWidgetHostView* rwhv = 333 if (content::RenderWidgetHostView* rwhv =
337 preview_contents_->web_contents()->GetRenderWidgetHostView()) { 334 preview_contents_->web_contents()->GetRenderWidgetHostView())
338 rwhv->SetTakesFocusOnlyOnMouseDown(true); 335 rwhv->SetTakesFocusOnlyOnMouseDown(true);
339 }
340 return; 336 return;
341 } 337 }
342 NOTREACHED(); 338 NOTREACHED();
343 #endif 339 #endif
344 } 340 }
345 341
346 void InstantLoader::SetupPreviewContents() { 342 void InstantLoader::SetupPreviewContents() {
347 content::WebContents* new_contents = preview_contents_->web_contents(); 343 content::WebContents* new_contents = preview_contents_->web_contents();
348 preview_delegate_.reset(new WebContentsDelegateImpl(this)); 344 preview_delegate_.reset(new WebContentsDelegateImpl(this));
349 WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); 345 WebContentsDelegateImpl* new_delegate = preview_delegate_.get();
350 new_contents->SetDelegate(new_delegate); 346 new_contents->SetDelegate(new_delegate);
351 347
352 // Disable popups and such (mainly to avoid losing focus and reverting the 348 // Disable popups and such (mainly to avoid losing focus and reverting the
353 // preview prematurely). 349 // preview prematurely).
354 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); 350 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true);
355 preview_contents_->constrained_window_tab_helper()->set_delegate( 351 preview_contents_->constrained_window_tab_helper()->set_delegate(
356 new_delegate); 352 new_delegate);
357 preview_contents_->content_settings()->SetPopupsBlocked(true); 353 preview_contents_->content_settings()->SetPopupsBlocked(true);
358 preview_contents_->core_tab_helper()->set_delegate(new_delegate); 354 preview_contents_->core_tab_helper()->set_delegate(new_delegate);
359 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) 355 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator())
360 tg->set_enabled(false); 356 tg->set_enabled(false);
361 357
362 #if defined(OS_MACOSX) 358 #if defined(OS_MACOSX)
363 // If |preview_contents_| does not currently have a RWHV, we will call 359 // If |preview_contents_| does not currently have a RWHV, we will call
364 // SetTakesFocusOnlyOnMouseDown() as a result of the RENDER_VIEW_HOST_CHANGED 360 // SetTakesFocusOnlyOnMouseDown() as a result of the RENDER_VIEW_HOST_CHANGED
365 // notification. 361 // notification.
366 if (content::RenderWidgetHostView* rwhv = 362 if (content::RenderWidgetHostView* rwhv =
367 new_contents->GetRenderWidgetHostView()) { 363 new_contents->GetRenderWidgetHostView())
368 rwhv->SetTakesFocusOnlyOnMouseDown(true); 364 rwhv->SetTakesFocusOnlyOnMouseDown(true);
369 }
370 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 365 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
371 content::Source<content::NavigationController>( 366 content::Source<content::NavigationController>(
372 &new_contents->GetController())); 367 &new_contents->GetController()));
373 #endif 368 #endif
374 } 369 }
375 370
376 void InstantLoader::CleanupPreviewContents() { 371 void InstantLoader::CleanupPreviewContents() {
377 content::WebContents* old_contents = preview_contents_->web_contents(); 372 content::WebContents* old_contents = preview_contents_->web_contents();
378 old_contents->SetDelegate(NULL); 373 old_contents->SetDelegate(NULL);
379 preview_delegate_.reset(); 374 preview_delegate_.reset();
380 375
381 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false); 376 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false);
382 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL); 377 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL);
383 preview_contents_->content_settings()->SetPopupsBlocked(false); 378 preview_contents_->content_settings()->SetPopupsBlocked(false);
384 preview_contents_->core_tab_helper()->set_delegate(NULL); 379 preview_contents_->core_tab_helper()->set_delegate(NULL);
385 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) 380 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator())
386 tg->set_enabled(true); 381 tg->set_enabled(true);
387 382
388 #if defined(OS_MACOSX) 383 #if defined(OS_MACOSX)
389 if (content::RenderWidgetHostView* rwhv = 384 if (content::RenderWidgetHostView* rwhv =
390 old_contents->GetRenderWidgetHostView()) { 385 old_contents->GetRenderWidgetHostView())
391 rwhv->SetTakesFocusOnlyOnMouseDown(false); 386 rwhv->SetTakesFocusOnlyOnMouseDown(false);
392 }
393 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 387 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
394 content::Source<content::NavigationController>( 388 content::Source<content::NavigationController>(
395 &old_contents->GetController())); 389 &old_contents->GetController()));
396 #endif 390 #endif
397 } 391 }
398 392
399 void InstantLoader::ReplacePreviewContents(TabContents* old_tc, 393 void InstantLoader::ReplacePreviewContents(TabContents* old_tc,
400 TabContents* new_tc) { 394 TabContents* new_tc) {
401 DCHECK(old_tc == preview_contents_); 395 DCHECK(old_tc == preview_contents_);
402 CleanupPreviewContents(); 396 CleanupPreviewContents();
403 // We release here without deleting so that the caller still has the 397 // We release here without deleting so that the caller still has the
404 // responsibility for deleting the TabContents. 398 // responsibility for deleting the TabContents.
405 ignore_result(preview_contents_.release()); 399 ignore_result(preview_contents_.release());
406 preview_contents_.reset(new_tc); 400 preview_contents_.reset(new_tc);
407 SetupPreviewContents(); 401 SetupPreviewContents();
408 loader_delegate_->SwappedTabContents(this); 402 loader_delegate_->SwappedTabContents(this);
409 } 403 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.cc ('k') | chrome/browser/search_engines/search_terms_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698