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") { ...@@ -70,6 +70,11 @@ executable("service_exe") {
] ]
} }
fuchsia_package_runner("service_runner") {
package = ":service_pkg"
package_name_override = "web_service"
}
component("service_lib") { component("service_lib") {
deps = [ deps = [
":service_pak", ":service_pak",
...@@ -82,7 +87,9 @@ component("service_lib") { ...@@ -82,7 +87,9 @@ component("service_lib") {
"//content/public/renderer", "//content/public/renderer",
"//services/network/public/cpp", "//services/network/public/cpp",
"//services/service_manager/embedder:embedder_switches", "//services/service_manager/embedder:embedder_switches",
"//ui/aura",
"//ui/display", "//ui/display",
"//ui/platform_window",
] ]
data_deps = [ data_deps = [
...@@ -97,6 +104,10 @@ component("service_lib") { ...@@ -97,6 +104,10 @@ component("service_lib") {
configs += [ ":webrunner_implementation" ] configs += [ ":webrunner_implementation" ]
sources = [ 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.cc",
"browser/webrunner_browser_context.h", "browser/webrunner_browser_context.h",
"browser/webrunner_browser_main.cc", "browser/webrunner_browser_main.cc",
...@@ -116,14 +127,10 @@ component("service_lib") { ...@@ -116,14 +127,10 @@ component("service_lib") {
"common/webrunner_export.h", "common/webrunner_export.h",
"service/common.cc", "service/common.cc",
"service/common.h", "service/common.h",
"service/context_impl.cc",
"service/context_impl.h",
"service/context_provider_impl.cc", "service/context_provider_impl.cc",
"service/context_provider_impl.h", "service/context_provider_impl.h",
"service/context_provider_main.cc", "service/context_provider_main.cc",
"service/context_provider_main.h", "service/context_provider_main.h",
"service/frame_impl.cc",
"service/frame_impl.h",
"service/webrunner_main_delegate.cc", "service/webrunner_main_delegate.cc",
"service/webrunner_main_delegate.h", "service/webrunner_main_delegate.h",
] ]
......
...@@ -2,4 +2,5 @@ include_rules = [ ...@@ -2,4 +2,5 @@ include_rules = [
"+content/public/browser", "+content/public/browser",
"+ui/aura", "+ui/aura",
"+ui/display", "+ui/display",
"+ui/platform_window",
] ]
\ No newline at end of file
...@@ -2,25 +2,29 @@ ...@@ -2,25 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "webrunner/service/context_impl.h" #include "webrunner/browser/context_impl.h"
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "webrunner/service/frame_impl.h" #include "content/public/browser/web_contents.h"
#include "webrunner/browser/frame_impl.h"
namespace webrunner { namespace webrunner {
ContextImpl::ContextImpl() = default; ContextImpl::ContextImpl(content::BrowserContext* browser_context)
: browser_context_(browser_context) {}
ContextImpl::~ContextImpl() = default; ContextImpl::~ContextImpl() = default;
void ContextImpl::CreateFrame( void ContextImpl::CreateFrame(
::fidl::InterfaceHandle<chromium::web::FrameObserver> observer, fidl::InterfaceHandle<chromium::web::FrameObserver> observer,
::fidl::InterfaceRequest<chromium::web::Frame> frame_request) { fidl::InterfaceRequest<chromium::web::Frame> frame_request) {
std::unique_ptr<chromium::web::Frame> frame = auto web_contents = content::WebContents::Create(
std::make_unique<FrameImpl>(observer.Bind()); content::WebContents::CreateParams(browser_context_, nullptr));
frame_bindings_.AddBinding(std::move(frame), std::move(frame_request)); frame_bindings_.AddBinding(
std::make_unique<FrameImpl>(std::move(web_contents), observer.Bind()),
std::move(frame_request));
} }
} // namespace webrunner } // namespace webrunner
...@@ -2,15 +2,19 @@ ...@@ -2,15 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBRUNNER_SERVICE_CONTEXT_IMPL_H_ #ifndef WEBRUNNER_BROWSER_CONTEXT_IMPL_H_
#define WEBRUNNER_SERVICE_CONTEXT_IMPL_H_ #define WEBRUNNER_BROWSER_CONTEXT_IMPL_H_
#include <lib/fidl/cpp/binding_set.h> #include <lib/fidl/cpp/binding_set.h>
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "chromium/web/cpp/fidl.h"
#include "webrunner/common/webrunner_export.h" #include "webrunner/common/webrunner_export.h"
#include "webrunner/fidl/chromium/web/cpp/fidl.h"
namespace content {
class BrowserContext;
} // namespace content
namespace webrunner { namespace webrunner {
...@@ -19,17 +23,18 @@ namespace webrunner { ...@@ -19,17 +23,18 @@ namespace webrunner {
// All created Frames are owned by this object. // All created Frames are owned by this object.
class WEBRUNNER_EXPORT ContextImpl : public chromium::web::Context { class WEBRUNNER_EXPORT ContextImpl : public chromium::web::Context {
public: public:
ContextImpl(); // |browser_context| must outlive ContextImpl.
explicit ContextImpl(content::BrowserContext* browser_context);
// Tears down the Context, destroying any active Frames in the process. // Tears down the Context, destroying any active Frames in the process.
~ContextImpl() override; ~ContextImpl() override;
// chromium::web::Context implementation. // chromium::web::Context implementation.
void CreateFrame( void CreateFrame(fidl::InterfaceHandle<chromium::web::FrameObserver> observer,
::fidl::InterfaceHandle<chromium::web::FrameObserver> observer, fidl::InterfaceRequest<chromium::web::Frame> frame) override;
::fidl::InterfaceRequest<chromium::web::Frame> frame) override;
private: private:
content::BrowserContext* browser_context_;
fidl::BindingSet<chromium::web::Frame, std::unique_ptr<chromium::web::Frame>> fidl::BindingSet<chromium::web::Frame, std::unique_ptr<chromium::web::Frame>>
frame_bindings_; frame_bindings_;
...@@ -38,4 +43,4 @@ class WEBRUNNER_EXPORT ContextImpl : public chromium::web::Context { ...@@ -38,4 +43,4 @@ class WEBRUNNER_EXPORT ContextImpl : public chromium::web::Context {
} // namespace webrunner } // 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 @@ ...@@ -2,39 +2,53 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBRUNNER_SERVICE_FRAME_IMPL_H_ #ifndef WEBRUNNER_BROWSER_FRAME_IMPL_H_
#define WEBRUNNER_SERVICE_FRAME_IMPL_H_ #define WEBRUNNER_BROWSER_FRAME_IMPL_H_
#include <lib/fidl/cpp/binding_set.h> #include <lib/fidl/cpp/binding_set.h>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/macros.h" #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 { namespace webrunner {
// Implementation of Frame from //webrunner/fidl/frame.fidl. // Implementation of Frame from //webrunner/fidl/frame.fidl.
// Implements a Frame service, which is a wrapper for a WebContents instance. // Implements a Frame service, which is a wrapper for a WebContents instance.
class FrameImpl : public chromium::web::Frame, class FrameImpl : public chromium::web::Frame,
public chromium::web::NavigationController { public chromium::web::NavigationController,
public content::WebContentsObserver {
public: public:
explicit FrameImpl(chromium::web::FrameObserverPtr observer); FrameImpl(std::unique_ptr<content::WebContents> web_contents,
chromium::web::FrameObserverPtr observer);
~FrameImpl() override; ~FrameImpl() override;
// content::WebContentsObserver implementation.
void Init(content::BrowserContext* browser_context, const GURL& url);
// chromium::web::Frame implementation. // chromium::web::Frame implementation.
void CreateView( void CreateView(
::fidl::InterfaceRequest<fuchsia::ui::views_v1_token::ViewOwner> fidl::InterfaceRequest<fuchsia::ui::views_v1_token::ViewOwner> view_owner,
view_owner, fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) override;
::fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services)
override;
void GetNavigationController( void GetNavigationController(
::fidl::InterfaceRequest<chromium::web::NavigationController> controller) fidl::InterfaceRequest<chromium::web::NavigationController> controller)
override; override;
// chromium::web::NavigationController implementation. // chromium::web::NavigationController implementation.
void LoadUrl(::fidl::StringPtr url, void LoadUrl(fidl::StringPtr url,
::std::unique_ptr<chromium::web::LoadUrlParams> params) override; std::unique_ptr<chromium::web::LoadUrlParams> params) override;
void GoBack() override; void GoBack() override;
void GoForward() override; void GoForward() override;
void Stop() override; void Stop() override;
...@@ -42,6 +56,9 @@ class FrameImpl : public chromium::web::Frame, ...@@ -42,6 +56,9 @@ class FrameImpl : public chromium::web::Frame,
void GetVisibleEntry(GetVisibleEntryCallback callback) override; void GetVisibleEntry(GetVisibleEntryCallback callback) override;
private: private:
std::unique_ptr<aura::WindowTreeHost> window_tree_host_;
std::unique_ptr<content::WebContents> web_contents_;
chromium::web::FrameObserverPtr observer_; chromium::web::FrameObserverPtr observer_;
fidl::BindingSet<chromium::web::NavigationController> controller_bindings_; fidl::BindingSet<chromium::web::NavigationController> controller_bindings_;
...@@ -50,4 +67,4 @@ class FrameImpl : public chromium::web::Frame, ...@@ -50,4 +67,4 @@ class FrameImpl : public chromium::web::Frame,
} // namespace webrunner } // namespace webrunner
#endif // WEBRUNNER_SERVICE_FRAME_IMPL_H_ #endif // WEBRUNNER_BROWSER_FRAME_IMPL_H_
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
#include "webrunner/browser/webrunner_browser_main_parts.h" #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_browser_context.h"
#include "webrunner/browser/webrunner_screen.h" #include "webrunner/browser/webrunner_screen.h"
#include "webrunner/service/common.h" #include "webrunner/service/common.h"
#include "webrunner/service/context_impl.h"
namespace webrunner { namespace webrunner {
...@@ -29,7 +29,7 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() { ...@@ -29,7 +29,7 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
fidl::InterfaceRequest<chromium::web::Context> context_request( fidl::InterfaceRequest<chromium::web::Context> context_request(
std::move(context_handle)); 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_binding_ = std::make_unique<fidl::Binding<chromium::web::Context>>(
context_impl_.get(), std::move(context_request)); context_impl_.get(), std::move(context_request));
......
...@@ -12,7 +12,7 @@ interface Frame { ...@@ -12,7 +12,7 @@ interface Frame {
// |view_owner|: Request for the Frame's ViewOwner. // |view_owner|: Request for the Frame's ViewOwner.
// |services|: Request for the Frame's View-related services. // |services|: Request for the Frame's View-related services.
1: CreateView(request<fuchsia.ui.views_v1_token.ViewOwner> view_owner, 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 // Returns an interface through which the frame may be navigated to
// a desired URL, reloaded, etc. // 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