Commit 94489a86 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Add basic web::Frame implementation in webrunner

Now webrunner::FrameImpl creates WebContents and a WindowTreeHost.

Also moved FrameImpl and ContextImpl classes to //webrunner/browser
(because they run in the browser process).

Bug: 852145
Change-Id: Ic1f3e453342f182e28bbf971fae011a671bee105
Reviewed-on: https://chromium-review.googlesource.com/1135836Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575394}
parent f350010a
......@@ -70,6 +70,11 @@ executable("service_exe") {
]
}
fuchsia_package_runner("service_runner") {
package = ":service_pkg"
package_name_override = "web_service"
}
component("service_lib") {
deps = [
":service_pak",
......@@ -82,7 +87,9 @@ component("service_lib") {
"//content/public/renderer",
"//services/network/public/cpp",
"//services/service_manager/embedder:embedder_switches",
"//ui/aura",
"//ui/display",
"//ui/platform_window",
]
data_deps = [
......@@ -97,6 +104,10 @@ component("service_lib") {
configs += [ ":webrunner_implementation" ]
sources = [
"browser/context_impl.cc",
"browser/context_impl.h",
"browser/frame_impl.cc",
"browser/frame_impl.h",
"browser/webrunner_browser_context.cc",
"browser/webrunner_browser_context.h",
"browser/webrunner_browser_main.cc",
......@@ -116,14 +127,10 @@ component("service_lib") {
"common/webrunner_export.h",
"service/common.cc",
"service/common.h",
"service/context_impl.cc",
"service/context_impl.h",
"service/context_provider_impl.cc",
"service/context_provider_impl.h",
"service/context_provider_main.cc",
"service/context_provider_main.h",
"service/frame_impl.cc",
"service/frame_impl.h",
"service/webrunner_main_delegate.cc",
"service/webrunner_main_delegate.h",
]
......
......@@ -2,4 +2,5 @@ include_rules = [
"+content/public/browser",
"+ui/aura",
"+ui/display",
"+ui/platform_window",
]
\ No newline at end of file
......@@ -2,25 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/service/context_impl.h"
#include "webrunner/browser/context_impl.h"
#include <memory>
#include <utility>
#include "webrunner/service/frame_impl.h"
#include "content/public/browser/web_contents.h"
#include "webrunner/browser/frame_impl.h"
namespace webrunner {
ContextImpl::ContextImpl() = default;
ContextImpl::ContextImpl(content::BrowserContext* browser_context)
: browser_context_(browser_context) {}
ContextImpl::~ContextImpl() = default;
void ContextImpl::CreateFrame(
::fidl::InterfaceHandle<chromium::web::FrameObserver> observer,
::fidl::InterfaceRequest<chromium::web::Frame> frame_request) {
std::unique_ptr<chromium::web::Frame> frame =
std::make_unique<FrameImpl>(observer.Bind());
frame_bindings_.AddBinding(std::move(frame), std::move(frame_request));
fidl::InterfaceHandle<chromium::web::FrameObserver> observer,
fidl::InterfaceRequest<chromium::web::Frame> frame_request) {
auto web_contents = content::WebContents::Create(
content::WebContents::CreateParams(browser_context_, nullptr));
frame_bindings_.AddBinding(
std::make_unique<FrameImpl>(std::move(web_contents), observer.Bind()),
std::move(frame_request));
}
} // namespace webrunner
......@@ -2,15 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBRUNNER_SERVICE_CONTEXT_IMPL_H_
#define WEBRUNNER_SERVICE_CONTEXT_IMPL_H_
#ifndef WEBRUNNER_BROWSER_CONTEXT_IMPL_H_
#define WEBRUNNER_BROWSER_CONTEXT_IMPL_H_
#include <lib/fidl/cpp/binding_set.h>
#include <memory>
#include "base/macros.h"
#include "chromium/web/cpp/fidl.h"
#include "webrunner/common/webrunner_export.h"
#include "webrunner/fidl/chromium/web/cpp/fidl.h"
namespace content {
class BrowserContext;
} // namespace content
namespace webrunner {
......@@ -19,17 +23,18 @@ namespace webrunner {
// All created Frames are owned by this object.
class WEBRUNNER_EXPORT ContextImpl : public chromium::web::Context {
public:
ContextImpl();
// |browser_context| must outlive ContextImpl.
explicit ContextImpl(content::BrowserContext* browser_context);
// Tears down the Context, destroying any active Frames in the process.
~ContextImpl() override;
// chromium::web::Context implementation.
void CreateFrame(
::fidl::InterfaceHandle<chromium::web::FrameObserver> observer,
::fidl::InterfaceRequest<chromium::web::Frame> frame) override;
void CreateFrame(fidl::InterfaceHandle<chromium::web::FrameObserver> observer,
fidl::InterfaceRequest<chromium::web::Frame> frame) override;
private:
content::BrowserContext* browser_context_;
fidl::BindingSet<chromium::web::Frame, std::unique_ptr<chromium::web::Frame>>
frame_bindings_;
......@@ -38,4 +43,4 @@ class WEBRUNNER_EXPORT ContextImpl : public chromium::web::Context {
} // namespace webrunner
#endif // WEBRUNNER_SERVICE_CONTEXT_IMPL_H_
#endif // WEBRUNNER_BROWSER_CONTEXT_IMPL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/browser/frame_impl.h"
#include "base/logging.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host_platform.h"
#include "ui/platform_window/platform_window_init_properties.h"
#include "url/gurl.h"
namespace webrunner {
namespace {
// Layout manager that allows only one child window and stretches it to fill the
// parent.
class LayoutManagerImpl : public aura::LayoutManager {
public:
LayoutManagerImpl() = default;
~LayoutManagerImpl() override = default;
// aura::LayoutManager.
void OnWindowResized() override {
// Resize the child to match the size of the parent
if (child_) {
SetChildBoundsDirect(child_,
gfx::Rect(child_->parent()->bounds().size()));
}
}
void OnWindowAddedToLayout(aura::Window* child) override {
DCHECK(!child_);
child_ = child;
SetChildBoundsDirect(child_, gfx::Rect(child_->parent()->bounds().size()));
}
void OnWillRemoveWindowFromLayout(aura::Window* child) override {
DCHECK_EQ(child, child_);
child_ = nullptr;
}
void OnWindowRemovedFromLayout(aura::Window* child) override {}
void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) override {}
void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) override {}
private:
aura::Window* child_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl);
};
} // namespace
FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents,
chromium::web::FrameObserverPtr observer)
: web_contents_(std::move(web_contents)), observer_(std::move(observer)) {
Observe(web_contents.get());
}
FrameImpl::~FrameImpl() {
window_tree_host_->Hide();
window_tree_host_->compositor()->SetVisible(false);
}
void FrameImpl::CreateView(
fidl::InterfaceRequest<fuchsia::ui::views_v1_token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) {
ui::PlatformWindowInitProperties properties;
properties.view_owner_request = std::move(view_owner);
window_tree_host_ =
std::make_unique<aura::WindowTreeHostPlatform>(std::move(properties));
window_tree_host_->InitHost();
window_tree_host_->window()->SetLayoutManager(new LayoutManagerImpl());
window_tree_host_->window()->AddChild(web_contents_->GetNativeView());
window_tree_host_->window()->Show();
window_tree_host_->Show();
web_contents_->GetNativeView()->Show();
}
void FrameImpl::GetNavigationController(
fidl::InterfaceRequest<chromium::web::NavigationController> controller) {
controller_bindings_.AddBinding(this, std::move(controller));
}
void FrameImpl::LoadUrl(fidl::StringPtr url,
std::unique_ptr<chromium::web::LoadUrlParams> params) {
GURL validated_url(*url);
if (!validated_url.is_valid()) {
DLOG(WARNING) << "Invalid URL: " << *url;
return;
}
content::NavigationController::LoadURLParams params_converted(validated_url);
params_converted.transition_type = ui::PageTransitionFromInt(
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
web_contents_->GetController().LoadURLWithParams(params_converted);
}
void FrameImpl::GoBack() {
NOTIMPLEMENTED();
}
void FrameImpl::GoForward() {
NOTIMPLEMENTED();
}
void FrameImpl::Stop() {
NOTIMPLEMENTED();
}
void FrameImpl::Reload() {
NOTIMPLEMENTED();
}
void FrameImpl::GetVisibleEntry(GetVisibleEntryCallback callback) {
NOTIMPLEMENTED();
callback(nullptr);
}
} // namespace webrunner
......@@ -2,39 +2,53 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBRUNNER_SERVICE_FRAME_IMPL_H_
#define WEBRUNNER_SERVICE_FRAME_IMPL_H_
#ifndef WEBRUNNER_BROWSER_FRAME_IMPL_H_
#define WEBRUNNER_BROWSER_FRAME_IMPL_H_
#include <lib/fidl/cpp/binding_set.h>
#include <memory>
#include <utility>
#include "base/macros.h"
#include "chromium/web/cpp/fidl.h"
#include "content/public/browser/web_contents_observer.h"
#include "url/gurl.h"
#include "webrunner/fidl/chromium/web/cpp/fidl.h"
namespace aura {
class WindowTreeHost;
} // namespace aura
namespace content {
class BrowserContext;
class WebContents;
} // namespace content
namespace webrunner {
// Implementation of Frame from //webrunner/fidl/frame.fidl.
// Implements a Frame service, which is a wrapper for a WebContents instance.
class FrameImpl : public chromium::web::Frame,
public chromium::web::NavigationController {
public chromium::web::NavigationController,
public content::WebContentsObserver {
public:
explicit FrameImpl(chromium::web::FrameObserverPtr observer);
FrameImpl(std::unique_ptr<content::WebContents> web_contents,
chromium::web::FrameObserverPtr observer);
~FrameImpl() override;
// content::WebContentsObserver implementation.
void Init(content::BrowserContext* browser_context, const GURL& url);
// chromium::web::Frame implementation.
void CreateView(
::fidl::InterfaceRequest<fuchsia::ui::views_v1_token::ViewOwner>
view_owner,
::fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services)
override;
fidl::InterfaceRequest<fuchsia::ui::views_v1_token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) override;
void GetNavigationController(
::fidl::InterfaceRequest<chromium::web::NavigationController> controller)
fidl::InterfaceRequest<chromium::web::NavigationController> controller)
override;
// chromium::web::NavigationController implementation.
void LoadUrl(::fidl::StringPtr url,
::std::unique_ptr<chromium::web::LoadUrlParams> params) override;
void LoadUrl(fidl::StringPtr url,
std::unique_ptr<chromium::web::LoadUrlParams> params) override;
void GoBack() override;
void GoForward() override;
void Stop() override;
......@@ -42,6 +56,9 @@ class FrameImpl : public chromium::web::Frame,
void GetVisibleEntry(GetVisibleEntryCallback callback) override;
private:
std::unique_ptr<aura::WindowTreeHost> window_tree_host_;
std::unique_ptr<content::WebContents> web_contents_;
chromium::web::FrameObserverPtr observer_;
fidl::BindingSet<chromium::web::NavigationController> controller_bindings_;
......@@ -50,4 +67,4 @@ class FrameImpl : public chromium::web::Frame,
} // namespace webrunner
#endif // WEBRUNNER_SERVICE_FRAME_IMPL_H_
#endif // WEBRUNNER_BROWSER_FRAME_IMPL_H_
......@@ -4,10 +4,10 @@
#include "webrunner/browser/webrunner_browser_main_parts.h"
#include "webrunner/browser/context_impl.h"
#include "webrunner/browser/webrunner_browser_context.h"
#include "webrunner/browser/webrunner_screen.h"
#include "webrunner/service/common.h"
#include "webrunner/service/context_impl.h"
namespace webrunner {
......@@ -29,7 +29,7 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
fidl::InterfaceRequest<chromium::web::Context> context_request(
std::move(context_handle));
context_impl_ = std::make_unique<ContextImpl>();
context_impl_ = std::make_unique<ContextImpl>(browser_context_.get());
context_binding_ = std::make_unique<fidl::Binding<chromium::web::Context>>(
context_impl_.get(), std::move(context_request));
......
......@@ -12,7 +12,7 @@ interface Frame {
// |view_owner|: Request for the Frame's ViewOwner.
// |services|: Request for the Frame's View-related services.
1: CreateView(request<fuchsia.ui.views_v1_token.ViewOwner> view_owner,
request<fuchsia.sys.ServiceProvider> services);
request<fuchsia.sys.ServiceProvider>? services);
// Returns an interface through which the frame may be navigated to
// a desired URL, reloaded, etc.
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/service/frame_impl.h"
#include "base/logging.h"
namespace webrunner {
FrameImpl::FrameImpl(chromium::web::FrameObserverPtr observer)
: observer_(std::move(observer)) {}
FrameImpl::~FrameImpl() = default;
void FrameImpl::CreateView(
::fidl::InterfaceRequest<fuchsia::ui::views_v1_token::ViewOwner> view_owner,
::fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) {
NOTIMPLEMENTED();
}
void FrameImpl::GetNavigationController(
::fidl::InterfaceRequest<chromium::web::NavigationController> controller) {
controller_bindings_.AddBinding(this, std::move(controller));
}
void FrameImpl::LoadUrl(
::fidl::StringPtr url,
::std::unique_ptr<chromium::web::LoadUrlParams> params) {
NOTIMPLEMENTED() << "Loading URL " << *url;
}
void FrameImpl::GoBack() {
NOTIMPLEMENTED();
}
void FrameImpl::GoForward() {
NOTIMPLEMENTED();
}
void FrameImpl::Stop() {
NOTIMPLEMENTED();
}
void FrameImpl::Reload() {
NOTIMPLEMENTED();
}
void FrameImpl::GetVisibleEntry(GetVisibleEntryCallback callback) {
NOTIMPLEMENTED();
callback(nullptr);
}
} // namespace webrunner
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