Commit 8be1b63b authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Use WebView in EmbeddedBrowser

Bug: 983397
Test: ash_ui_perftests passes without dcheck
Change-Id: I8dd2bb38f010d340f9be520f9e208267622559a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1700567Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677124}
parent 16166859
...@@ -1535,6 +1535,7 @@ static_library("ash_shell_lib_with_content") { ...@@ -1535,6 +1535,7 @@ static_library("ash_shell_lib_with_content") {
"//ui/events/devices", "//ui/events/devices",
"//ui/message_center", "//ui/message_center",
"//ui/views:test_support", "//ui/views:test_support",
"//ui/views/controls/webview",
"//ui/views/examples:views_examples_with_content_lib", "//ui/views/examples:views_examples_with_content_lib",
"//ui/wm", "//ui/wm",
] ]
......
...@@ -5,15 +5,8 @@ ...@@ -5,15 +5,8 @@
#include "ash/shell/content/embedded_browser.h" #include "ash/shell/content/embedded_browser.h"
#include "ash/public/cpp/app_types.h" #include "ash/public/cpp/app_types.h"
#include "ash/shell.h"
#include "base/bind_helpers.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -24,36 +17,16 @@ namespace shell { ...@@ -24,36 +17,16 @@ namespace shell {
namespace { namespace {
// Simulate a widget created on Window Service side to host a native window. class BrowserWidgetDelegateView : public views::WidgetDelegateView {
// For classic, it is done by NativeViewHost. For single process mash,
// it uses ServerRemoteViewHost. To implement for mash, the code should be
// moved to ash process somehow and invoked over mojo.
class HostWidget : public views::WidgetDelegateView {
public: public:
// Creates HostWidget that hosts |native_window| directly for classic. BrowserWidgetDelegateView(content::BrowserContext* context, const GURL& url) {
static void CreateFromNativeWindow(gfx::NativeWindow native_window) {
// HostWidget deletes itself when underlying widget closes.
new HostWidget(native_window);
}
private:
HostWidget(gfx::NativeWindow native_window) {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
auto* webview = new views::WebView(context);
auto* widget = new views::Widget; AddChildView(webview);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.context = Shell::GetPrimaryRootWindow();
params.bounds = gfx::Rect(20, 0, 800, 600);
params.delegate = this;
widget->Init(params);
widget->Show();
auto* host = new views::NativeViewHost();
AddChildView(host);
host->Attach(native_window);
Layout(); Layout();
webview->LoadInitialURL(url);
} }
~BrowserWidgetDelegateView() override = default;
// views::WidgetDelegateView: // views::WidgetDelegateView:
base::string16 GetWindowTitle() const override { base::string16 GetWindowTitle() const override {
...@@ -62,34 +35,32 @@ class HostWidget : public views::WidgetDelegateView { ...@@ -62,34 +35,32 @@ class HostWidget : public views::WidgetDelegateView {
return title; return title;
} }
DISALLOW_COPY_AND_ASSIGN(HostWidget); private:
DISALLOW_COPY_AND_ASSIGN(BrowserWidgetDelegateView);
}; };
} // namespace } // namespace
EmbeddedBrowser::EmbeddedBrowser(content::BrowserContext* context, EmbeddedBrowser::EmbeddedBrowser(content::BrowserContext* context,
const GURL& url) { const GURL& url)
contents_ = : widget_(new views::Widget) {
content::WebContents::Create(content::WebContents::CreateParams(context)); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
contents_->GetController().LoadURLWithParams( params.bounds = gfx::Rect(20, 0, 800, 600);
content::NavigationController::LoadURLParams(url)); params.delegate = new BrowserWidgetDelegateView(context, url);
contents_->GetNativeView()->Show(); widget_->Init(params);
widget_->Show();
HostWidget::CreateFromNativeWindow(contents_->GetNativeView());
} }
EmbeddedBrowser::~EmbeddedBrowser() = default; EmbeddedBrowser::~EmbeddedBrowser() = default;
aura::Window* EmbeddedBrowser::GetWindow() { aura::Window* EmbeddedBrowser::GetWindow() {
return contents_->GetNativeView()->GetToplevelWindow(); return widget_->GetNativeView();
} }
// static // static
aura::Window* EmbeddedBrowser::Create(content::BrowserContext* context, aura::Window* EmbeddedBrowser::Create(content::BrowserContext* context,
const GURL& url) { const GURL& url) {
// EmbeddedBrowser deletes itself when the hosting widget is closed. // EmbeddedBrowser deletes itself when the widget is closed.
// TODO(oshima): This leaks site process map for some reason. Fix it.
// crbug.com/983397.
aura::Window* browser_window = aura::Window* browser_window =
(new EmbeddedBrowser(context, url))->GetWindow(); (new EmbeddedBrowser(context, url))->GetWindow();
browser_window->SetProperty(aura::client::kAppType, browser_window->SetProperty(aura::client::kAppType,
......
...@@ -17,8 +17,11 @@ class Window; ...@@ -17,8 +17,11 @@ class Window;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class WebContents; }
} // namespace content
namespace views {
class Widget;
}
namespace ash { namespace ash {
namespace shell { namespace shell {
...@@ -39,7 +42,7 @@ class EmbeddedBrowser { ...@@ -39,7 +42,7 @@ class EmbeddedBrowser {
// Callback invoked when the embedding is broken. // Callback invoked when the embedding is broken.
void OnUnembed(); void OnUnembed();
std::unique_ptr<content::WebContents> contents_; views::Widget* widget_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(EmbeddedBrowser); DISALLOW_COPY_AND_ASSIGN(EmbeddedBrowser);
}; };
......
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