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

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

Issue 5073002: Modifies the Instant loader to listen for RENDER_VIEW_HOST_CHANGED notificati... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « chrome/browser/instant/instant_loader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/search_engines/template_url.h" 23 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/tab_contents/navigation_controller.h" 24 #include "chrome/browser/tab_contents/navigation_controller.h"
25 #include "chrome/browser/tab_contents/navigation_entry.h" 25 #include "chrome/browser/tab_contents/navigation_entry.h"
26 #include "chrome/browser/tab_contents/tab_contents.h" 26 #include "chrome/browser/tab_contents/tab_contents.h"
27 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 27 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
28 #include "chrome/browser/tab_contents/tab_contents_view.h" 28 #include "chrome/browser/tab_contents/tab_contents_view.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/notification_observer.h" 30 #include "chrome/common/notification_observer.h"
31 #include "chrome/common/notification_registrar.h" 31 #include "chrome/common/notification_registrar.h"
32 #include "chrome/common/notification_service.h" 32 #include "chrome/common/notification_service.h"
33 #include "chrome/common/notification_type.h"
33 #include "chrome/common/page_transition_types.h" 34 #include "chrome/common/page_transition_types.h"
34 #include "chrome/common/render_messages.h" 35 #include "chrome/common/render_messages.h"
35 #include "chrome/common/renderer_preferences.h" 36 #include "chrome/common/renderer_preferences.h"
36 #include "gfx/codec/png_codec.h" 37 #include "gfx/codec/png_codec.h"
37 #include "ipc/ipc_message.h" 38 #include "ipc/ipc_message.h"
38 39
39 namespace { 40 namespace {
40 // Number of ms to delay before updating the omnibox bounds. This is a bit long 41 // Number of ms to delay before updating the omnibox bounds. This is a bit long
41 // as updating the bounds ends up being quite expensive. 42 // as updating the bounds ends up being quite expensive.
42 const int kUpdateBoundsDelayMS = 500; 43 const int kUpdateBoundsDelayMS = 500;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 384
384 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) 385 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id)
385 : delegate_(delegate), 386 : delegate_(delegate),
386 template_url_id_(id), 387 template_url_id_(id),
387 ready_(false), 388 ready_(false),
388 last_transition_type_(PageTransition::LINK) { 389 last_transition_type_(PageTransition::LINK) {
389 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); 390 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this));
390 } 391 }
391 392
392 InstantLoader::~InstantLoader() { 393 InstantLoader::~InstantLoader() {
394 registrar_.RemoveAll();
395
393 // Delete the TabContents before the delegate as the TabContents holds a 396 // Delete the TabContents before the delegate as the TabContents holds a
394 // reference to the delegate. 397 // reference to the delegate.
395 preview_contents_.reset(NULL); 398 preview_contents_.reset(NULL);
396 } 399 }
397 400
398 void InstantLoader::Update(TabContents* tab_contents, 401 void InstantLoader::Update(TabContents* tab_contents,
399 const TemplateURL* template_url, 402 const TemplateURL* template_url,
400 const GURL& url, 403 const GURL& url,
401 PageTransition::Type transition_type, 404 PageTransition::Type transition_type,
402 const string16& user_text, 405 const string16& user_text,
(...skipping 19 matching lines...) Expand all
422 int32 max_page_id = tab_contents->GetMaxPageID(); 425 int32 max_page_id = tab_contents->GetMaxPageID();
423 if (max_page_id != -1) 426 if (max_page_id != -1)
424 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); 427 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1);
425 428
426 preview_contents_->set_delegate(preview_tab_contents_delegate_.get()); 429 preview_contents_->set_delegate(preview_tab_contents_delegate_.get());
427 430
428 gfx::Rect tab_bounds; 431 gfx::Rect tab_bounds;
429 tab_contents->view()->GetContainerBounds(&tab_bounds); 432 tab_contents->view()->GetContainerBounds(&tab_bounds);
430 preview_contents_->view()->SizeContents(tab_bounds.size()); 433 preview_contents_->view()->SizeContents(tab_bounds.size());
431 434
435 #if defined(OS_MACOSX)
436 // If |preview_contents_| does not currently have a RWHV, we will call
437 // SetTakesFocusOnlyOnMouseDown() as a result of the
438 // RENDER_VIEW_HOST_CHANGED notification.
439 if (preview_contents_->GetRenderWidgetHostView()) {
440 preview_contents_->GetRenderWidgetHostView()->
441 SetTakesFocusOnlyOnMouseDown(true);
442 }
443 registrar_.Add(
444 this,
445 NotificationType::RENDER_VIEW_HOST_CHANGED,
446 Source<NavigationController>(&preview_contents_->controller()));
447 #endif
448
432 preview_contents_->ShowContents(); 449 preview_contents_->ShowContents();
433 created_preview_contents = true; 450 created_preview_contents = true;
434 } else { 451 } else {
435 created_preview_contents = false; 452 created_preview_contents = false;
436 } 453 }
437 preview_tab_contents_delegate_->PrepareForNewLoad(); 454 preview_tab_contents_delegate_->PrepareForNewLoad();
438 455
439 if (template_url) { 456 if (template_url) {
440 DCHECK(template_url_id_ == template_url->id()); 457 DCHECK(template_url_id_ == template_url->id());
441 if (!created_preview_contents) { 458 if (!created_preview_contents) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if (type != INSTANT_COMMIT_DESTROY) 547 if (type != INSTANT_COMMIT_DESTROY)
531 preview_tab_contents_delegate_->CommitHistory(); 548 preview_tab_contents_delegate_->CommitHistory();
532 // Destroy the paint observer. 549 // Destroy the paint observer.
533 // RenderWidgetHostView may be null during shutdown. 550 // RenderWidgetHostView may be null during shutdown.
534 if (preview_contents_->GetRenderWidgetHostView()) { 551 if (preview_contents_->GetRenderWidgetHostView()) {
535 preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()-> 552 preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->
536 set_paint_observer(NULL); 553 set_paint_observer(NULL);
537 #if defined(OS_MACOSX) 554 #if defined(OS_MACOSX)
538 preview_contents_->GetRenderWidgetHostView()-> 555 preview_contents_->GetRenderWidgetHostView()->
539 SetTakesFocusOnlyOnMouseDown(false); 556 SetTakesFocusOnlyOnMouseDown(false);
557 registrar_.Remove(
558 this,
559 NotificationType::RENDER_VIEW_HOST_CHANGED,
560 Source<NavigationController>(&preview_contents_->controller()));
540 #endif 561 #endif
541 } 562 }
542 preview_contents_->set_delegate(NULL); 563 preview_contents_->set_delegate(NULL);
543 preview_tab_contents_delegate_->Reset(); 564 preview_tab_contents_delegate_->Reset();
544 ready_ = false; 565 ready_ = false;
545 } 566 }
546 update_bounds_timer_.Stop(); 567 update_bounds_timer_.Stop();
547 return preview_contents_.release(); 568 return preview_contents_.release();
548 } 569 }
549 570
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 void InstantLoader::PreviewPainted() { 618 void InstantLoader::PreviewPainted() {
598 // If instant is supported then we wait for the first suggest result before 619 // If instant is supported then we wait for the first suggest result before
599 // showing the page. 620 // showing the page.
600 if (!template_url_id_) 621 if (!template_url_id_)
601 ShowPreview(); 622 ShowPreview();
602 } 623 }
603 624
604 void InstantLoader::ShowPreview() { 625 void InstantLoader::ShowPreview() {
605 if (!ready_) { 626 if (!ready_) {
606 ready_ = true; 627 ready_ = true;
607 #if defined(OS_MACOSX)
608 if (preview_contents_->GetRenderWidgetHostView()) {
609 preview_contents_->GetRenderWidgetHostView()->
610 SetTakesFocusOnlyOnMouseDown(true);
611 }
612 #endif
613 delegate_->ShowInstantLoader(this); 628 delegate_->ShowInstantLoader(this);
614 } 629 }
615 } 630 }
616 631
632 void InstantLoader::Observe(NotificationType type,
633 const NotificationSource& source,
634 const NotificationDetails& details) {
635 #if defined(OS_MACOSX)
636 if (type.value == NotificationType::RENDER_VIEW_HOST_CHANGED) {
637 if (preview_contents_->GetRenderWidgetHostView()) {
638 preview_contents_->GetRenderWidgetHostView()->
639 SetTakesFocusOnlyOnMouseDown(true);
640 }
641 return;
642 }
643 #endif
644
645 NOTREACHED() << "Got a notification we didn't register for.";
646 }
647
617 void InstantLoader::PageFinishedLoading() { 648 void InstantLoader::PageFinishedLoading() {
618 frame_load_observer_.reset(); 649 frame_load_observer_.reset();
619 // Wait for the user input before showing, this way the page should be up to 650 // Wait for the user input before showing, this way the page should be up to
620 // date by the time we show it. 651 // date by the time we show it.
621 } 652 }
622 653
623 // TODO(tonyg): This method only fires when the omnibox bounds change. It also 654 // TODO(tonyg): This method only fires when the omnibox bounds change. It also
624 // needs to fire when the preview bounds change (e.g. open/close info bar). 655 // needs to fire when the preview bounds change (e.g. open/close info bar).
625 gfx::Rect InstantLoader::GetOmniboxBoundsInTermsOfPreview() { 656 gfx::Rect InstantLoader::GetOmniboxBoundsInTermsOfPreview() {
626 gfx::Rect preview_bounds(delegate_->GetInstantBounds()); 657 gfx::Rect preview_bounds(delegate_->GetInstantBounds());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 if (last_omnibox_bounds_ == omnibox_bounds_) 690 if (last_omnibox_bounds_ == omnibox_bounds_)
660 return; 691 return;
661 692
662 last_omnibox_bounds_ = omnibox_bounds_; 693 last_omnibox_bounds_ = omnibox_bounds_;
663 if (preview_contents_.get() && is_showing_instant() && 694 if (preview_contents_.get() && is_showing_instant() &&
664 !is_waiting_for_load()) { 695 !is_waiting_for_load()) {
665 preview_contents_->render_view_host()->SearchBoxResize( 696 preview_contents_->render_view_host()->SearchBoxResize(
666 GetOmniboxBoundsInTermsOfPreview()); 697 GetOmniboxBoundsInTermsOfPreview());
667 } 698 }
668 } 699 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698