Commit 20680b9a authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Lots of non-functional cleanup to ExtensionView{Host,Views} and related.

* DISALLOW_COPY_AND_ASSIGN() -> explicit deletions
* Remove using declarations
* Use =default
* Use in-declaration initializers
* NULL -> nullptr
* Combine ExtensionViewHost::CreateView() with constructor
* Use const and auto more
* Use make_unique instead of bare new
* Shorten code
* Move most of ExtensionDialog::Show() into the constructor
* Combine ExtensionDialog::InitWindow() with constructor
* Replace GetExtensionView() functions with |extension_view_| members,
  since the return value is constant (and its source will change in an
  upcoming CL)
* Remove always-true condition from ExtensionDialog::CanResize()
  (size was always set)
* Consistently use |host_|, not host(), in ExtensionPopup
* Have ExtensionViewViews obtain the relevant profile from the |host|
  instead of having it explicitly passed in
* For clarity, make ExtensionViewViews::minimum_size_ an Optional
  instead of treating Size() as a magic value that means "not set"
* Eliminate unnecessary friend declaration

Bug: none
Change-Id: I2733f7460b09c07ada3fcae819d71bee960886ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209593
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770603}
parent c4d72938
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
class Browser; class Browser;
class Profile;
namespace content { namespace content {
class SiteInstance; class SiteInstance;
...@@ -36,21 +35,17 @@ class ExtensionViewHost ...@@ -36,21 +35,17 @@ class ExtensionViewHost
public web_modal::WebContentsModalDialogHost, public web_modal::WebContentsModalDialogHost,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
// |browser| may be null, since extension views may be bound to TabContents
// hosted in ExternalTabContainer objects, which do not instantiate Browsers.
ExtensionViewHost(const Extension* extension, ExtensionViewHost(const Extension* extension,
content::SiteInstance* site_instance, content::SiteInstance* site_instance,
const GURL& url, const GURL& url,
ViewType host_type); ViewType host_type,
Browser* browser);
~ExtensionViewHost() override; ~ExtensionViewHost() override;
Browser* browser() { return browser_; } Browser* browser() { return browser_; }
ExtensionView* view() { return view_.get(); } ExtensionView* view() { return view_.get(); }
const ExtensionView* view() const { return view_.get(); }
// Create an ExtensionView and tie it to this host and |browser|. Note NULL
// is a valid argument for |browser|. Extension views may be bound to
// tab-contents hosted in ExternalTabContainer objects, which do not
// instantiate Browser objects.
void CreateView(Browser* browser);
void SetAssociatedWebContents(content::WebContents* web_contents); void SetAssociatedWebContents(content::WebContents* web_contents);
...@@ -118,13 +113,16 @@ class ExtensionViewHost ...@@ -118,13 +113,16 @@ class ExtensionViewHost
private: private:
// Implemented per-platform. Create the platform-specific ExtensionView. // Implemented per-platform. Create the platform-specific ExtensionView.
static std::unique_ptr<ExtensionView> CreateExtensionView( static std::unique_ptr<ExtensionView> CreateExtensionView(
ExtensionViewHost* host, ExtensionViewHost* host);
Profile* profile);
// Returns whether the provided event is a raw escape keypress in a
// VIEW_TYPE_EXTENSION_POPUP.
bool IsEscapeInPopup(const content::NativeWebKeyboardEvent& event) const;
// The browser associated with the ExtensionView, if any. // The browser associated with the ExtensionView, if any.
Browser* browser_ = nullptr; Browser* browser_;
// Optional view that shows the rendered content in the UI. // View that shows the rendered content in the UI.
std::unique_ptr<ExtensionView> view_; std::unique_ptr<ExtensionView> view_;
// The relevant WebContents associated with this ExtensionViewHost, if any. // The relevant WebContents associated with this ExtensionViewHost, if any.
......
...@@ -34,10 +34,8 @@ std::unique_ptr<ExtensionViewHost> CreateViewHostForExtension( ...@@ -34,10 +34,8 @@ std::unique_ptr<ExtensionViewHost> CreateViewHostForExtension(
DCHECK(browser || view_type == VIEW_TYPE_EXTENSION_DIALOG); DCHECK(browser || view_type == VIEW_TYPE_EXTENSION_DIALOG);
scoped_refptr<content::SiteInstance> site_instance = scoped_refptr<content::SiteInstance> site_instance =
ProcessManager::Get(profile)->GetSiteInstanceForURL(url); ProcessManager::Get(profile)->GetSiteInstanceForURL(url);
auto host = std::make_unique<ExtensionViewHost>( return std::make_unique<ExtensionViewHost>(extension, site_instance.get(),
extension, site_instance.get(), url, view_type); url, view_type, browser);
host->CreateView(browser);
return host;
} }
// Creates a view host for an extension in an incognito window. Returns NULL // Creates a view host for an extension in an incognito window. Returns NULL
......
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#endif #endif
using content::BrowserContext;
using content::WebContents;
ExtensionDialog::InitParams::InitParams(gfx::Size size) ExtensionDialog::InitParams::InitParams(gfx::Size size)
: size(std::move(size)) {} : size(std::move(size)) {}
ExtensionDialog::InitParams::InitParams(const InitParams& other) = default; ExtensionDialog::InitParams::InitParams(const InitParams& other) = default;
...@@ -46,43 +43,28 @@ ExtensionDialog::InitParams::~InitParams() = default; ...@@ -46,43 +43,28 @@ ExtensionDialog::InitParams::~InitParams() = default;
ExtensionDialog* ExtensionDialog::Show(const GURL& url, ExtensionDialog* ExtensionDialog::Show(const GURL& url,
gfx::NativeWindow parent_window, gfx::NativeWindow parent_window,
Profile* profile, Profile* profile,
WebContents* web_contents, content::WebContents* web_contents,
ExtensionDialogObserver* observer, ExtensionDialogObserver* observer,
const InitParams& init_params) { const InitParams& init_params) {
DCHECK(parent_window);
std::unique_ptr<extensions::ExtensionViewHost> host = std::unique_ptr<extensions::ExtensionViewHost> host =
extensions::ExtensionViewHostFactory::CreateDialogHost(url, profile); extensions::ExtensionViewHostFactory::CreateDialogHost(url, profile);
if (!host) if (!host)
return nullptr; return nullptr;
// Preferred size must be set before views::Widget::CreateWindowWithParent()
// is called because CreateWindowWithParent() references CanResize().
ExtensionViewViews* view = GetExtensionView(host.get());
view->SetPreferredSize(init_params.size);
view->set_minimum_size(init_params.min_size);
host->SetAssociatedWebContents(web_contents); host->SetAssociatedWebContents(web_contents);
DCHECK(parent_window); return new ExtensionDialog(std::move(host), observer, parent_window,
extensions::ExtensionViewHost* host_ptr = host.get(); init_params);
ExtensionDialog* dialog = new ExtensionDialog(std::move(host), observer);
dialog->set_title(init_params.title);
dialog->InitWindow(parent_window, init_params);
// Show a white background while the extension loads. This is prettier than
// flashing a black unfilled window frame.
view->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
view->SetVisible(true);
// Ensure the DOM JavaScript can respond immediately to keyboard shortcuts.
host_ptr->host_contents()->Focus();
return dialog;
} }
void ExtensionDialog::ObserverDestroyed() { void ExtensionDialog::ObserverDestroyed() {
observer_ = NULL; observer_ = nullptr;
} }
void ExtensionDialog::MaybeFocusRenderView() { void ExtensionDialog::MaybeFocusRenderView() {
views::FocusManager* focus_manager = GetWidget()->GetFocusManager(); views::FocusManager* focus_manager = GetWidget()->GetFocusManager();
DCHECK(focus_manager != NULL); DCHECK(focus_manager);
// Already there's a focused view, so no need to switch the focus. // Already there's a focused view, so no need to switch the focus.
if (focus_manager->GetFocusedView()) if (focus_manager->GetFocusedView())
...@@ -97,7 +79,7 @@ void ExtensionDialog::MaybeFocusRenderView() { ...@@ -97,7 +79,7 @@ void ExtensionDialog::MaybeFocusRenderView() {
} }
void ExtensionDialog::SetMinimumContentsSize(int width, int height) { void ExtensionDialog::SetMinimumContentsSize(int width, int height) {
GetExtensionView()->SetPreferredSize(gfx::Size(width, height)); extension_view_->SetPreferredSize(gfx::Size(width, height));
} }
bool ExtensionDialog::CanResize() const { bool ExtensionDialog::CanResize() const {
...@@ -106,8 +88,7 @@ bool ExtensionDialog::CanResize() const { ...@@ -106,8 +88,7 @@ bool ExtensionDialog::CanResize() const {
if (ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode()) if (ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode())
return false; return false;
#endif #endif
// Can resize only if minimum contents size set. return true;
return GetExtensionView()->GetPreferredSize() != gfx::Size();
} }
ui::ModalType ExtensionDialog::GetModalType() const { ui::ModalType ExtensionDialog::GetModalType() const {
...@@ -133,15 +114,23 @@ void ExtensionDialog::DeleteDelegate() { ...@@ -133,15 +114,23 @@ void ExtensionDialog::DeleteDelegate() {
} }
views::Widget* ExtensionDialog::GetWidget() { views::Widget* ExtensionDialog::GetWidget() {
return GetExtensionView()->GetWidget(); return extension_view_->GetWidget();
} }
const views::Widget* ExtensionDialog::GetWidget() const { const views::Widget* ExtensionDialog::GetWidget() const {
return GetExtensionView()->GetWidget(); return extension_view_->GetWidget();
} }
views::View* ExtensionDialog::GetContentsView() { views::View* ExtensionDialog::GetContentsView() {
return GetExtensionView(); if (!extension_view_) {
extension_view_ = static_cast<ExtensionViewViews*>(host_->view());
// Show a white background while the extension loads. This is prettier than
// flashing a black unfilled window frame.
extension_view_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
}
return extension_view_;
} }
void ExtensionDialog::Observe(int type, void ExtensionDialog::Observe(int type,
...@@ -151,7 +140,7 @@ void ExtensionDialog::Observe(int type, ...@@ -151,7 +140,7 @@ void ExtensionDialog::Observe(int type,
case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD: case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD:
// Avoid potential overdraw by removing the temporary background after // Avoid potential overdraw by removing the temporary background after
// the extension finishes loading. // the extension finishes loading.
GetExtensionView()->SetBackground(nullptr); extension_view_->SetBackground(nullptr);
// The render view is created during the LoadURL(), so we should // The render view is created during the LoadURL(), so we should
// set the focus to the view if nobody else takes the focus. // set the focus to the view if nobody else takes the focus.
if (content::Details<extensions::ExtensionHost>(host()) == details) if (content::Details<extensions::ExtensionHost>(host()) == details)
...@@ -179,40 +168,44 @@ ExtensionDialog::~ExtensionDialog() = default; ...@@ -179,40 +168,44 @@ ExtensionDialog::~ExtensionDialog() = default;
ExtensionDialog::ExtensionDialog( ExtensionDialog::ExtensionDialog(
std::unique_ptr<extensions::ExtensionViewHost> host, std::unique_ptr<extensions::ExtensionViewHost> host,
ExtensionDialogObserver* observer) ExtensionDialogObserver* observer,
gfx::NativeWindow parent_window,
const InitParams& init_params)
: host_(std::move(host)), observer_(observer) { : host_(std::move(host)), observer_(observer) {
SetButtons(ui::DIALOG_BUTTON_NONE); SetButtons(ui::DIALOG_BUTTON_NONE);
set_use_custom_frame(false); set_use_custom_frame(false);
AddRef(); // Balanced in DeleteDelegate(); AddRef(); // Balanced in DeleteDelegate();
const content::Source<content::BrowserContext> source =
host_->browser_context();
registrar_.Add(this, registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD,
content::Source<BrowserContext>(host_->browser_context())); source);
// Listen for the containing view calling window.close(); // Listen for the containing view calling window.close();
registrar_.Add(this, registrar_.Add(
extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, this, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, source);
content::Source<BrowserContext>(host_->browser_context()));
// Listen for a crash or other termination of the extension process. // Listen for a crash or other termination of the extension process.
registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
content::Source<BrowserContext>(host_->browser_context())); source);
chrome::RecordDialogCreation(chrome::DialogIdentifier::EXTENSION); chrome::RecordDialogCreation(chrome::DialogIdentifier::EXTENSION);
}
void ExtensionDialog::InitWindow(gfx::NativeWindow parent, set_title(init_params.title);
const InitParams& init_params) {
views::Widget* window = views::Widget* window =
init_params.is_modal init_params.is_modal
? constrained_window::CreateBrowserModalDialogViews(this, parent) ? constrained_window::CreateBrowserModalDialogViews(this,
: views::DialogDelegate::CreateDialogWidget( parent_window)
this, nullptr /* context */, nullptr /* parent */); : views::DialogDelegate::CreateDialogWidget(this, nullptr, nullptr);
// Center the window over the parent browser window or the screen. // Center the window over the parent browser window or the screen.
gfx::Rect screen_rect = gfx::Rect screen_rect = display::Screen::GetScreen()
display::Screen::GetScreen()->GetDisplayNearestWindow(parent).work_area(); ->GetDisplayNearestWindow(parent_window)
gfx::Rect bounds = parent ? views::Widget::GetWidgetForNativeWindow(parent) .work_area();
->GetWindowBoundsInScreen() gfx::Rect bounds =
: screen_rect; parent_window ? views::Widget::GetWidgetForNativeWindow(parent_window)
->GetWindowBoundsInScreen()
: screen_rect;
bounds.ClampToCenteredSize(init_params.size); bounds.ClampToCenteredSize(init_params.size);
// Make sure bounds is larger than {min_size}. // Make sure bounds is larger than {min_size}.
...@@ -248,13 +241,14 @@ void ExtensionDialog::InitWindow(gfx::NativeWindow parent, ...@@ -248,13 +241,14 @@ void ExtensionDialog::InitWindow(gfx::NativeWindow parent,
window->Show(); window->Show();
// TODO(jamescook): Remove redundant call to Activate()? // TODO(jamescook): Remove redundant call to Activate()?
window->Activate(); window->Activate();
}
ExtensionViewViews* ExtensionDialog::GetExtensionView() const { // Creating the Widget should have called GetContentsView() and created
return GetExtensionView(host_.get()); // |extension_view_|.
} DCHECK(extension_view_);
extension_view_->SetPreferredSize(init_params.size);
extension_view_->set_minimum_size(init_params.min_size);
extension_view_->SetVisible(true);
ExtensionViewViews* ExtensionDialog::GetExtensionView( // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts.
extensions::ExtensionViewHost* host) { host_->host_contents()->Focus();
return static_cast<ExtensionViewViews*>(host->view());
} }
...@@ -114,21 +114,18 @@ class ExtensionDialog : public views::DialogDelegate, ...@@ -114,21 +114,18 @@ class ExtensionDialog : public views::DialogDelegate,
// Use Show() to create instances. // Use Show() to create instances.
ExtensionDialog(std::unique_ptr<extensions::ExtensionViewHost> host, ExtensionDialog(std::unique_ptr<extensions::ExtensionViewHost> host,
ExtensionDialogObserver* observer); ExtensionDialogObserver* observer,
gfx::NativeWindow parent_window,
void InitWindow(gfx::NativeWindow parent_window,
const InitParams& init_params); const InitParams& init_params);
ExtensionViewViews* GetExtensionView() const;
static ExtensionViewViews* GetExtensionView(
extensions::ExtensionViewHost* host);
// Window Title // Window Title
base::string16 window_title_; base::string16 window_title_;
// The contained host for the view. // The contained host for the view.
std::unique_ptr<extensions::ExtensionViewHost> host_; std::unique_ptr<extensions::ExtensionViewHost> host_;
ExtensionViewViews* extension_view_ = nullptr;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
// The observer of this popup. // The observer of this popup.
......
...@@ -69,7 +69,7 @@ void ExtensionPopup::AddedToWidget() { ...@@ -69,7 +69,7 @@ void ExtensionPopup::AddedToWidget() {
BubbleDialogDelegateView::AddedToWidget(); BubbleDialogDelegateView::AddedToWidget();
const int radius = GetBubbleFrameView()->corner_radius(); const int radius = GetBubbleFrameView()->corner_radius();
const bool contents_has_rounded_corners = const bool contents_has_rounded_corners =
GetExtensionView()->holder()->SetCornerRadius(radius); extension_view_->holder()->SetCornerRadius(radius);
SetBorder(views::CreateEmptyBorder( SetBorder(views::CreateEmptyBorder(
gfx::Insets(contents_has_rounded_corners ? 0 : radius, 0))); gfx::Insets(contents_has_rounded_corners ? 0 : radius, 0)));
} }
...@@ -128,7 +128,7 @@ void ExtensionPopup::OnExtensionUnloaded( ...@@ -128,7 +128,7 @@ void ExtensionPopup::OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) { extensions::UnloadedExtensionReason reason) {
if (extension->id() == host()->extension_id()) { if (extension->id() == host_->extension_id()) {
host_.reset(); host_.reset();
GetWidget()->Close(); GetWidget()->Close();
} }
...@@ -138,7 +138,7 @@ void ExtensionPopup::Observe(int type, ...@@ -138,7 +138,7 @@ void ExtensionPopup::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME) { if (type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME) {
DCHECK_EQ(host()->host_contents(), DCHECK_EQ(host_->host_contents(),
content::Source<content::WebContents>(source).ptr()); content::Source<content::WebContents>(source).ptr());
// Show when the content finishes loading and its width is computed. // Show when the content finishes loading and its width is computed.
ShowBubble(); ShowBubble();
...@@ -147,7 +147,7 @@ void ExtensionPopup::Observe(int type, ...@@ -147,7 +147,7 @@ void ExtensionPopup::Observe(int type,
DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, type); DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, type);
// If we aren't the host of the popup, then disregard the notification. // If we aren't the host of the popup, then disregard the notification.
if (content::Details<extensions::ExtensionHost>(host()) == details) if (content::Details<extensions::ExtensionHost>(host_.get()) == details)
GetWidget()->Close(); GetWidget()->Close();
} }
...@@ -161,7 +161,7 @@ void ExtensionPopup::OnTabStripModelChanged( ...@@ -161,7 +161,7 @@ void ExtensionPopup::OnTabStripModelChanged(
void ExtensionPopup::DevToolsAgentHostAttached( void ExtensionPopup::DevToolsAgentHostAttached(
content::DevToolsAgentHost* agent_host) { content::DevToolsAgentHost* agent_host) {
if (host()->host_contents() == agent_host->GetWebContents()) if (host_->host_contents() == agent_host->GetWebContents())
show_action_ = SHOW_AND_INSPECT; show_action_ = SHOW_AND_INSPECT;
} }
...@@ -171,9 +171,9 @@ void ExtensionPopup::DevToolsAgentHostDetached( ...@@ -171,9 +171,9 @@ void ExtensionPopup::DevToolsAgentHostDetached(
// is uninstalled, and if DevTools are attached, we will be notified here. // is uninstalled, and if DevTools are attached, we will be notified here.
// But because OnExtensionUnloaded was already called, |host_| is // But because OnExtensionUnloaded was already called, |host_| is
// no longer valid. // no longer valid.
if (!host()) if (!host_)
return; return;
if (host()->host_contents() == agent_host->GetWebContents()) if (host_->host_contents() == agent_host->GetWebContents())
show_action_ = SHOW; show_action_ = SHOW;
} }
...@@ -193,8 +193,10 @@ ExtensionPopup::ExtensionPopup( ...@@ -193,8 +193,10 @@ ExtensionPopup::ExtensionPopup(
set_margins(gfx::Insets()); set_margins(gfx::Insets());
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
AddChildView(GetExtensionView());
GetExtensionView()->set_container(this); extension_view_ =
AddChildView(static_cast<ExtensionViewViews*>(host_.get()->view()));
extension_view_->set_container(this);
// See comments in OnWidgetActivationChanged(). // See comments in OnWidgetActivationChanged().
set_close_on_deactivate(false); set_close_on_deactivate(false);
...@@ -225,11 +227,11 @@ void ExtensionPopup::ShowBubble() { ...@@ -225,11 +227,11 @@ void ExtensionPopup::ShowBubble() {
GetWidget()->Show(); GetWidget()->Show();
// Focus on the host contents when the bubble is first shown. // Focus on the host contents when the bubble is first shown.
host()->host_contents()->Focus(); host_->host_contents()->Focus();
if (show_action_ == SHOW_AND_INSPECT) { if (show_action_ == SHOW_AND_INSPECT) {
DevToolsWindow::OpenDevToolsWindow( DevToolsWindow::OpenDevToolsWindow(
host()->host_contents(), DevToolsToggleAction::ShowConsolePanel()); host_->host_contents(), DevToolsToggleAction::ShowConsolePanel());
} }
} }
...@@ -237,7 +239,3 @@ void ExtensionPopup::CloseUnlessUnderInspection() { ...@@ -237,7 +239,3 @@ void ExtensionPopup::CloseUnlessUnderInspection() {
if (show_action_ != SHOW_AND_INSPECT) if (show_action_ != SHOW_AND_INSPECT)
GetWidget()->CloseWithReason(views::Widget::ClosedReason::kLostFocus); GetWidget()->CloseWithReason(views::Widget::ClosedReason::kLostFocus);
} }
ExtensionViewViews* ExtensionPopup::GetExtensionView() {
return static_cast<ExtensionViewViews*>(host_.get()->view());
}
...@@ -128,11 +128,11 @@ class ExtensionPopup : public views::BubbleDialogDelegateView, ...@@ -128,11 +128,11 @@ class ExtensionPopup : public views::BubbleDialogDelegateView,
// Closes the bubble if the devtools window is not attached. // Closes the bubble if the devtools window is not attached.
void CloseUnlessUnderInspection(); void CloseUnlessUnderInspection();
ExtensionViewViews* GetExtensionView();
// The contained host for the view. // The contained host for the view.
std::unique_ptr<extensions::ExtensionViewHost> host_; std::unique_ptr<extensions::ExtensionViewHost> host_;
ExtensionViewViews* extension_view_;
ScopedObserver<extensions::ExtensionRegistry, ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver> extensions::ExtensionRegistryObserver>
extension_registry_observer_; extension_registry_observer_;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_host.h"
#include "extensions/common/view_type.h" #include "extensions/common/view_type.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
...@@ -26,9 +25,9 @@ ...@@ -26,9 +25,9 @@
#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor.h"
#endif #endif
ExtensionViewViews::ExtensionViewViews(extensions::ExtensionHost* host, ExtensionViewViews::ExtensionViewViews(extensions::ExtensionViewHost* host)
Profile* profile) : views::WebView(host->browser() ? host->browser()->profile() : nullptr),
: views::WebView(profile), host_(host), container_(nullptr) { host_(host) {
SetWebContents(host_->web_contents()); SetWebContents(host_->web_contents());
if (host->extension_host_type() == extensions::VIEW_TYPE_EXTENSION_POPUP) { if (host->extension_host_type() == extensions::VIEW_TYPE_EXTENSION_POPUP) {
EnableSizingFromWebContents( EnableSizingFromWebContents(
...@@ -107,9 +106,7 @@ gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) { ...@@ -107,9 +106,7 @@ gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) {
} }
gfx::Size ExtensionViewViews::GetMinimumSize() const { gfx::Size ExtensionViewViews::GetMinimumSize() const {
// If the minimum size has never been set, returns the preferred size (same return minimum_size_.value_or(GetPreferredSize());
// behavior as views::View).
return (minimum_size_ == gfx::Size()) ? GetPreferredSize() : minimum_size_;
} }
void ExtensionViewViews::PreferredSizeChanged() { void ExtensionViewViews::PreferredSizeChanged() {
...@@ -127,9 +124,8 @@ namespace extensions { ...@@ -127,9 +124,8 @@ namespace extensions {
// static // static
std::unique_ptr<ExtensionView> ExtensionViewHost::CreateExtensionView( std::unique_ptr<ExtensionView> ExtensionViewHost::CreateExtensionView(
ExtensionViewHost* host, ExtensionViewHost* host) {
Profile* profile) { auto view = std::make_unique<ExtensionViewViews>(host);
auto view = std::make_unique<ExtensionViewViews>(host, profile);
// We own |view_|, so don't auto delete when it's removed from the view // We own |view_|, so don't auto delete when it's removed from the view
// hierarchy. // hierarchy.
view->set_owned_by_client(); view->set_owned_by_client();
......
...@@ -6,20 +6,18 @@ ...@@ -6,20 +6,18 @@
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_ #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/optional.h"
#include "chrome/browser/extensions/extension_view.h" #include "chrome/browser/extensions/extension_view.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
class Profile;
namespace content { namespace content {
class RenderViewHost; class RenderViewHost;
} }
namespace extensions { namespace extensions {
class ExtensionHost; class ExtensionViewHost;
} }
// This handles the display portion of an ExtensionHost. // This handles the display portion of an ExtensionHost.
...@@ -30,12 +28,14 @@ class ExtensionViewViews : public views::WebView, ...@@ -30,12 +28,14 @@ class ExtensionViewViews : public views::WebView,
// (bottom shelf, side bar, etc.) // (bottom shelf, side bar, etc.)
class Container { class Container {
public: public:
virtual ~Container() {} virtual ~Container() = default;
virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {} virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {}
}; };
ExtensionViewViews(extensions::ExtensionHost* host, Profile* profile); explicit ExtensionViewViews(extensions::ExtensionViewHost* host);
ExtensionViewViews(const ExtensionViewViews&) = delete;
ExtensionViewViews& operator=(const ExtensionViewViews&) = delete;
~ExtensionViewViews() override; ~ExtensionViewViews() override;
// views::WebView: // views::WebView:
...@@ -47,8 +47,6 @@ class ExtensionViewViews : public views::WebView, ...@@ -47,8 +47,6 @@ class ExtensionViewViews : public views::WebView,
void set_container(Container* container) { container_ = container; } void set_container(Container* container) { container_ = container; }
private: private:
friend class extensions::ExtensionHost;
// extensions::ExtensionView: // extensions::ExtensionView:
gfx::NativeView GetNativeView() override; gfx::NativeView GetNativeView() override;
void ResizeDueToAutoResize(content::WebContents* web_contents, void ResizeDueToAutoResize(content::WebContents* web_contents,
...@@ -66,22 +64,21 @@ class ExtensionViewViews : public views::WebView, ...@@ -66,22 +64,21 @@ class ExtensionViewViews : public views::WebView,
void OnWebContentsAttached() override; void OnWebContentsAttached() override;
// Note that host_ owns view // Note that host_ owns view
extensions::ExtensionHost* host_; extensions::ExtensionViewHost* host_;
// What we should set the preferred width to once the ExtensionViewViews has // What we should set the preferred width to once the ExtensionViewViews has
// loaded. // loaded.
gfx::Size pending_preferred_size_; gfx::Size pending_preferred_size_;
gfx::Size minimum_size_;
base::Optional<gfx::Size> minimum_size_;
// The container this view is in (not necessarily its direct superview). // The container this view is in (not necessarily its direct superview).
// Note: the view does not own its container. // Note: the view does not own its container.
Container* container_; Container* container_ = nullptr;
// A handler to handle unhandled keyboard messages coming back from the // A handler to handle unhandled keyboard messages coming back from the
// renderer process. // renderer process.
views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
DISALLOW_COPY_AND_ASSIGN(ExtensionViewViews);
}; };
#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_ #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment