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

Side by Side Diff: chrome/browser/ui/panels/panel.cc

Issue 1132163004: Remove NOTIFICATION_RENDER_VIEW_HOST_CHANGED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed explicitly invoking default WebContentsObserver ctor Created 5 years, 7 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
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/ui/panels/panel.h" 5 #include "chrome/browser/ui/panels/panel.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 default: 430 default:
431 LOG(WARNING) << "Received unimplemented command: " << id; 431 LOG(WARNING) << "Received unimplemented command: " << id;
432 break; 432 break;
433 } 433 }
434 } 434 }
435 435
436 void Panel::Observe(int type, 436 void Panel::Observe(int type,
437 const content::NotificationSource& source, 437 const content::NotificationSource& source,
438 const content::NotificationDetails& details) { 438 const content::NotificationDetails& details) {
439 switch (type) { 439 switch (type) {
440 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED:
441 ConfigureAutoResize(content::Source<content::WebContents>(source).ptr());
442 break;
443 case chrome::NOTIFICATION_APP_TERMINATING: 440 case chrome::NOTIFICATION_APP_TERMINATING:
444 Close(); 441 Close();
445 break; 442 break;
446 default: 443 default:
447 NOTREACHED() << "Received unexpected notification " << type; 444 NOTREACHED() << "Received unexpected notification " << type;
448 } 445 }
449 } 446 }
450 447
448 void Panel::RenderViewHostChanged(content::RenderViewHost* old_host,
449 content::RenderViewHost* new_host) {
450 ConfigureAutoResize(web_contents());
451 }
452
451 void Panel::OnExtensionUnloaded( 453 void Panel::OnExtensionUnloaded(
452 content::BrowserContext* browser_context, 454 content::BrowserContext* browser_context,
453 const extensions::Extension* extension, 455 const extensions::Extension* extension,
454 extensions::UnloadedExtensionInfo::Reason reason) { 456 extensions::UnloadedExtensionInfo::Reason reason) {
455 if (extension->id() == extension_id()) 457 if (extension->id() == extension_id())
456 Close(); 458 Close();
457 } 459 }
458 void Panel::OnTitlebarClicked(panel::ClickModifier modifier) { 460 void Panel::OnTitlebarClicked(panel::ClickModifier modifier) {
459 if (collection_) 461 if (collection_)
460 collection_->OnPanelTitlebarClicked(this, modifier); 462 collection_->OnPanelTitlebarClicked(this, modifier);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (auto_resizable_ == resizable) 588 if (auto_resizable_ == resizable)
587 return; 589 return;
588 590
589 auto_resizable_ = resizable; 591 auto_resizable_ = resizable;
590 content::WebContents* web_contents = GetWebContents(); 592 content::WebContents* web_contents = GetWebContents();
591 if (auto_resizable_) { 593 if (auto_resizable_) {
592 if (web_contents) 594 if (web_contents)
593 EnableWebContentsAutoResize(web_contents); 595 EnableWebContentsAutoResize(web_contents);
594 } else { 596 } else {
595 if (web_contents) { 597 if (web_contents) {
596 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 598 content::WebContentsObserver::Observe(nullptr);
597 content::Source<content::WebContents>(web_contents));
598 599
599 // NULL might be returned if the tab has not been added. 600 // NULL might be returned if the tab has not been added.
600 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); 601 RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
601 if (render_view_host) 602 if (render_view_host)
602 render_view_host->DisableAutoResize(full_size_); 603 render_view_host->DisableAutoResize(full_size_);
603 } 604 }
604 } 605 }
605 } 606 }
606 607
607 void Panel::EnableWebContentsAutoResize(content::WebContents* web_contents) { 608 void Panel::EnableWebContentsAutoResize(content::WebContents* web_contents) {
608 DCHECK(web_contents); 609 DCHECK(web_contents);
609 ConfigureAutoResize(web_contents); 610 ConfigureAutoResize(web_contents);
610 611
611 // We also need to know when the render view host changes in order 612 // We also need to know when the render view host changes in order
612 // to turn on auto-resize notifications in the new render view host. 613 // to turn on auto-resize notifications in the new render view host.
613 if (!registrar_.IsRegistered( 614 content::WebContentsObserver::Observe(web_contents);
614 this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
615 content::Source<content::WebContents>(web_contents))) {
616 registrar_.Add(
617 this,
618 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
619 content::Source<content::WebContents>(web_contents));
620 }
621 } 615 }
622 616
623 void Panel::OnContentsAutoResized(const gfx::Size& new_content_size) { 617 void Panel::OnContentsAutoResized(const gfx::Size& new_content_size) {
624 DCHECK(auto_resizable_); 618 DCHECK(auto_resizable_);
625 if (!collection_) 619 if (!collection_)
626 return; 620 return;
627 621
628 gfx::Size new_window_size = 622 gfx::Size new_window_size =
629 native_panel_->WindowSizeFromContentSize(new_content_size); 623 native_panel_->WindowSizeFromContentSize(new_content_size);
630 624
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 // static 890 // static
897 void Panel::FormatTitleForDisplay(base::string16* title) { 891 void Panel::FormatTitleForDisplay(base::string16* title) {
898 size_t current_index = 0; 892 size_t current_index = 0;
899 size_t match_index; 893 size_t match_index;
900 while ((match_index = title->find(L'\n', current_index)) != 894 while ((match_index = title->find(L'\n', current_index)) !=
901 base::string16::npos) { 895 base::string16::npos) {
902 title->replace(match_index, 1, base::string16()); 896 title->replace(match_index, 1, base::string16());
903 current_index = match_index; 897 current_index = match_index;
904 } 898 }
905 } 899 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698