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") {
"//ui/events/devices",
"//ui/message_center",
"//ui/views:test_support",
"//ui/views/controls/webview",
"//ui/views/examples:views_examples_with_content_lib",
"//ui/wm",
]
......
......@@ -5,15 +5,8 @@
#include "ash/shell/content/embedded_browser.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/views/controls/label.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
......@@ -24,36 +17,16 @@ namespace shell {
namespace {
// Simulate a widget created on Window Service side to host a native window.
// 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 {
class BrowserWidgetDelegateView : public views::WidgetDelegateView {
public:
// Creates HostWidget that hosts |native_window| directly for classic.
static void CreateFromNativeWindow(gfx::NativeWindow native_window) {
// HostWidget deletes itself when underlying widget closes.
new HostWidget(native_window);
}
private:
HostWidget(gfx::NativeWindow native_window) {
BrowserWidgetDelegateView(content::BrowserContext* context, const GURL& url) {
SetLayoutManager(std::make_unique<views::FillLayout>());
auto* widget = new views::Widget;
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);
auto* webview = new views::WebView(context);
AddChildView(webview);
Layout();
webview->LoadInitialURL(url);
}
~BrowserWidgetDelegateView() override = default;
// views::WidgetDelegateView:
base::string16 GetWindowTitle() const override {
......@@ -62,34 +35,32 @@ class HostWidget : public views::WidgetDelegateView {
return title;
}
DISALLOW_COPY_AND_ASSIGN(HostWidget);
private:
DISALLOW_COPY_AND_ASSIGN(BrowserWidgetDelegateView);
};
} // namespace
EmbeddedBrowser::EmbeddedBrowser(content::BrowserContext* context,
const GURL& url) {
contents_ =
content::WebContents::Create(content::WebContents::CreateParams(context));
contents_->GetController().LoadURLWithParams(
content::NavigationController::LoadURLParams(url));
contents_->GetNativeView()->Show();
HostWidget::CreateFromNativeWindow(contents_->GetNativeView());
const GURL& url)
: widget_(new views::Widget) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(20, 0, 800, 600);
params.delegate = new BrowserWidgetDelegateView(context, url);
widget_->Init(params);
widget_->Show();
}
EmbeddedBrowser::~EmbeddedBrowser() = default;
aura::Window* EmbeddedBrowser::GetWindow() {
return contents_->GetNativeView()->GetToplevelWindow();
return widget_->GetNativeView();
}
// static
aura::Window* EmbeddedBrowser::Create(content::BrowserContext* context,
const GURL& url) {
// EmbeddedBrowser deletes itself when the hosting widget is closed.
// TODO(oshima): This leaks site process map for some reason. Fix it.
// crbug.com/983397.
// EmbeddedBrowser deletes itself when the widget is closed.
aura::Window* browser_window =
(new EmbeddedBrowser(context, url))->GetWindow();
browser_window->SetProperty(aura::client::kAppType,
......
......@@ -17,8 +17,11 @@ class Window;
namespace content {
class BrowserContext;
class WebContents;
} // namespace content
}
namespace views {
class Widget;
}
namespace ash {
namespace shell {
......@@ -39,7 +42,7 @@ class EmbeddedBrowser {
// Callback invoked when the embedding is broken.
void OnUnembed();
std::unique_ptr<content::WebContents> contents_;
views::Widget* widget_ = nullptr;
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