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

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();
sky 2010/11/16 17:41:05 Is this needed?
rohitrao (ping after 24h) 2010/11/16 18:33:59 General paranoia, because we delete preview_conten
sky 2010/11/16 18:42:29 You're right, we should keep the explicit remove.
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if (type != INSTANT_COMMIT_DESTROY) 533 if (type != INSTANT_COMMIT_DESTROY)
531 preview_tab_contents_delegate_->CommitHistory(); 534 preview_tab_contents_delegate_->CommitHistory();
532 // Destroy the paint observer. 535 // Destroy the paint observer.
533 // RenderWidgetHostView may be null during shutdown. 536 // RenderWidgetHostView may be null during shutdown.
534 if (preview_contents_->GetRenderWidgetHostView()) { 537 if (preview_contents_->GetRenderWidgetHostView()) {
535 preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()-> 538 preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->
536 set_paint_observer(NULL); 539 set_paint_observer(NULL);
537 #if defined(OS_MACOSX) 540 #if defined(OS_MACOSX)
538 preview_contents_->GetRenderWidgetHostView()-> 541 preview_contents_->GetRenderWidgetHostView()->
539 SetTakesFocusOnlyOnMouseDown(false); 542 SetTakesFocusOnlyOnMouseDown(false);
543 registrar_.Remove(
544 this,
545 NotificationType::RENDER_VIEW_HOST_CHANGED,
546 Source<NavigationController>(&preview_contents_->controller()));
540 #endif 547 #endif
541 } 548 }
542 preview_contents_->set_delegate(NULL); 549 preview_contents_->set_delegate(NULL);
543 preview_tab_contents_delegate_->Reset(); 550 preview_tab_contents_delegate_->Reset();
544 ready_ = false; 551 ready_ = false;
545 } 552 }
546 update_bounds_timer_.Stop(); 553 update_bounds_timer_.Stop();
547 return preview_contents_.release(); 554 return preview_contents_.release();
548 } 555 }
549 556
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 } 609 }
603 610
604 void InstantLoader::ShowPreview() { 611 void InstantLoader::ShowPreview() {
605 if (!ready_) { 612 if (!ready_) {
606 ready_ = true; 613 ready_ = true;
607 #if defined(OS_MACOSX) 614 #if defined(OS_MACOSX)
608 if (preview_contents_->GetRenderWidgetHostView()) { 615 if (preview_contents_->GetRenderWidgetHostView()) {
609 preview_contents_->GetRenderWidgetHostView()-> 616 preview_contents_->GetRenderWidgetHostView()->
610 SetTakesFocusOnlyOnMouseDown(true); 617 SetTakesFocusOnlyOnMouseDown(true);
611 } 618 }
619 registrar_.Add(
sky 2010/11/16 17:41:05 Any reason you put this here instead of when the p
rohitrao (ping after 24h) 2010/11/16 18:33:59 Mostly because the notification is so closely asso
620 this,
621 NotificationType::RENDER_VIEW_HOST_CHANGED,
622 Source<NavigationController>(&preview_contents_->controller()));
612 #endif 623 #endif
613 delegate_->ShowInstantLoader(this); 624 delegate_->ShowInstantLoader(this);
614 } 625 }
615 } 626 }
616 627
628 void InstantLoader::Observe(NotificationType type,
629 const NotificationSource& source,
630 const NotificationDetails& details) {
631 switch (type.value) {
632 #if defined(OS_MACOSX)
633 case NotificationType::RENDER_VIEW_HOST_CHANGED:
634 LOG(ERROR) << "New RWHV";
sky 2010/11/16 17:41:05 Did you really want the LOG(ERROR)?
rohitrao (ping after 24h) 2010/11/16 18:33:59 No, no I don't =)
635 if (preview_contents_->GetRenderWidgetHostView()) {
636 preview_contents_->GetRenderWidgetHostView()->
637 SetTakesFocusOnlyOnMouseDown(true);
638 }
639 break;
640 #endif
641 default:
642 NOTREACHED() << "Got a notification we didn't register for.";
643 }
644 }
645
617 void InstantLoader::PageFinishedLoading() { 646 void InstantLoader::PageFinishedLoading() {
618 frame_load_observer_.reset(); 647 frame_load_observer_.reset();
619 // Wait for the user input before showing, this way the page should be up to 648 // Wait for the user input before showing, this way the page should be up to
620 // date by the time we show it. 649 // date by the time we show it.
621 } 650 }
622 651
623 // TODO(tonyg): This method only fires when the omnibox bounds change. It also 652 // 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). 653 // needs to fire when the preview bounds change (e.g. open/close info bar).
625 gfx::Rect InstantLoader::GetOmniboxBoundsInTermsOfPreview() { 654 gfx::Rect InstantLoader::GetOmniboxBoundsInTermsOfPreview() {
626 gfx::Rect preview_bounds(delegate_->GetInstantBounds()); 655 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_) 688 if (last_omnibox_bounds_ == omnibox_bounds_)
660 return; 689 return;
661 690
662 last_omnibox_bounds_ = omnibox_bounds_; 691 last_omnibox_bounds_ = omnibox_bounds_;
663 if (preview_contents_.get() && is_showing_instant() && 692 if (preview_contents_.get() && is_showing_instant() &&
664 !is_waiting_for_load()) { 693 !is_waiting_for_load()) {
665 preview_contents_->render_view_host()->SearchBoxResize( 694 preview_contents_->render_view_host()->SearchBoxResize(
666 GetOmniboxBoundsInTermsOfPreview()); 695 GetOmniboxBoundsInTermsOfPreview());
667 } 696 }
668 } 697 }
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