Skip to content

Commit

Permalink
mus: Use a barebone mus client-lib in chrome-renderer.
Browse files Browse the repository at this point in the history
Notable changes:
. Add RendererWindowTreeClient that implements ui.mojom.WindowTreeClient
  interface for chrome-renderer. It currently supports the most basic
  functionalities. For example, it does not receive events (the events
  instead are routed through chrome-browser), it does not support more
  than one window, window state changes (e.g. bounds, visibility etc.)
  are ignored (the corresponding messages from chrome-browser are used
  instead) etc. Over time however, this implementation will grow.
. When chrome-renderer is running as a mus-client, it immediately creates
  a RendererWindowTreeClient instance for a RenderWidget, instead of
  waiting for a creation request from chrome-browser.
. Remove RenderWidgetMusConnection, since it's no longer needed.

BUG=672913

Review-Url: https://codereview.chromium.org/2648213002
Cr-Commit-Position: refs/heads/master@{#446257}
  • Loading branch information
sadrulhc authored and Commit bot committed Jan 26, 2017
1 parent 2718915 commit 602ce13
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 141 deletions.
4 changes: 2 additions & 2 deletions content/renderer/mus/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ static_library("mus") {
visibility = [ "//content/renderer/*" ]

sources = [
"render_widget_mus_connection.cc",
"render_widget_mus_connection.h",
"render_widget_window_tree_client_factory.cc",
"render_widget_window_tree_client_factory.h",
"renderer_window_tree_client.cc",
"renderer_window_tree_client.h",
]

configs += [ "//content:content_implementation" ]
Expand Down
65 changes: 0 additions & 65 deletions content/renderer/mus/render_widget_mus_connection.cc

This file was deleted.

60 changes: 0 additions & 60 deletions content/renderer/mus/render_widget_mus_connection.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "content/common/render_widget_window_tree_client_factory.mojom.h"
#include "content/public/common/connection_filter.h"
#include "content/public/common/service_manager_connection.h"
#include "content/renderer/mus/render_widget_mus_connection.h"
#include "content/renderer/mus/renderer_window_tree_client.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/service_manager/public/cpp/interface_registry.h"
Expand All @@ -31,9 +31,7 @@ namespace {
void BindMusConnectionOnMainThread(
uint32_t routing_id,
ui::mojom::WindowTreeClientRequest request) {
RenderWidgetMusConnection* connection =
RenderWidgetMusConnection::GetOrCreate(routing_id);
connection->Bind(std::move(request));
RendererWindowTreeClient::Get(routing_id)->Bind(std::move(request));
}

// This object's lifetime is managed by ServiceManagerConnection because it's a
Expand Down
225 changes: 225 additions & 0 deletions content/renderer/mus/renderer_window_tree_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
// Copyright 2017 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 "content/renderer/mus/renderer_window_tree_client.h"

#include <map>

#include "base/lazy_instance.h"
#include "services/ui/public/cpp/window_compositor_frame_sink.h"

namespace content {

namespace {
typedef std::map<int, RendererWindowTreeClient*> ConnectionMap;
base::LazyInstance<ConnectionMap>::Leaky g_connections =
LAZY_INSTANCE_INITIALIZER;
} // namespace

// static
RendererWindowTreeClient* RendererWindowTreeClient::Get(int routing_id) {
auto it = g_connections.Get().find(routing_id);
if (it != g_connections.Get().end())
return it->second;
return nullptr;
}

// static
void RendererWindowTreeClient::Create(int routing_id) {
DCHECK(g_connections.Get().find(routing_id) == g_connections.Get().end());
RendererWindowTreeClient* connection =
new RendererWindowTreeClient(routing_id);
g_connections.Get().insert(std::make_pair(routing_id, connection));
}

RendererWindowTreeClient::RendererWindowTreeClient(int routing_id)
: routing_id_(routing_id), binding_(this) {}

RendererWindowTreeClient::~RendererWindowTreeClient() {
g_connections.Get().erase(routing_id_);
}

void RendererWindowTreeClient::Bind(
ui::mojom::WindowTreeClientRequest request) {
binding_.Bind(std::move(request));
}

std::unique_ptr<cc::CompositorFrameSink>
RendererWindowTreeClient::CreateCompositorFrameSink(
const cc::FrameSinkId& frame_sink_id,
scoped_refptr<cc::ContextProvider> context_provider,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
std::unique_ptr<ui::WindowCompositorFrameSinkBinding> frame_sink_binding;
auto frame_sink = ui::WindowCompositorFrameSink::Create(
frame_sink_id, std::move(context_provider), gpu_memory_buffer_manager,
&frame_sink_binding);
if (tree_) {
tree_->AttachCompositorFrameSink(
root_window_id_, frame_sink_binding->TakeFrameSinkRequest(),
mojo::MakeProxy(frame_sink_binding->TakeFrameSinkClient()));
} else {
pending_frame_sink_ = std::move(frame_sink_binding);
}
return std::move(frame_sink);
}

void RendererWindowTreeClient::DestroySelf() {
delete this;
}

void RendererWindowTreeClient::OnEmbed(ui::ClientSpecificId client_id,
ui::mojom::WindowDataPtr root,
ui::mojom::WindowTreePtr tree,
int64_t display_id,
ui::Id focused_window_id,
bool drawn) {
root_window_id_ = root->window_id;
tree_ = std::move(tree);
if (pending_frame_sink_) {
tree_->AttachCompositorFrameSink(
root_window_id_, pending_frame_sink_->TakeFrameSinkRequest(),
mojo::MakeProxy(pending_frame_sink_->TakeFrameSinkClient()));
pending_frame_sink_ = nullptr;
}
}

void RendererWindowTreeClient::OnEmbeddedAppDisconnected(ui::Id window_id) {
// TODO(sad): Embedded mus-client (oopif) is gone. Figure out what to do.
}

void RendererWindowTreeClient::OnUnembed(ui::Id window_id) {
CHECK_EQ(window_id, root_window_id_);
DestroySelf();
}

void RendererWindowTreeClient::OnCaptureChanged(ui::Id new_capture_window_id,
ui::Id old_capture_window_id) {}

void RendererWindowTreeClient::OnTopLevelCreated(uint32_t change_id,
ui::mojom::WindowDataPtr data,
int64_t display_id,
bool drawn) {
NOTREACHED();
}

void RendererWindowTreeClient::OnWindowBoundsChanged(
ui::Id window_id,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {}

void RendererWindowTreeClient::OnClientAreaChanged(
uint32_t window_id,
const gfx::Insets& new_client_area,
const std::vector<gfx::Rect>& new_additional_client_areas) {}

void RendererWindowTreeClient::OnTransientWindowAdded(
uint32_t window_id,
uint32_t transient_window_id) {}

void RendererWindowTreeClient::OnTransientWindowRemoved(
uint32_t window_id,
uint32_t transient_window_id) {}

void RendererWindowTreeClient::OnWindowHierarchyChanged(
ui::Id window_id,
ui::Id old_parent_id,
ui::Id new_parent_id,
std::vector<ui::mojom::WindowDataPtr> windows) {}

void RendererWindowTreeClient::OnWindowReordered(
ui::Id window_id,
ui::Id relative_window_id,
ui::mojom::OrderDirection direction) {}

void RendererWindowTreeClient::OnWindowDeleted(ui::Id window_id) {
// TODO(sad): With OOPIF, |window_id| may not be |root_window_id_|. We need to
// make sure that works correctly.
CHECK_EQ(window_id, root_window_id_);
DestroySelf();
}

void RendererWindowTreeClient::OnWindowVisibilityChanged(ui::Id window_id,
bool visible) {}

void RendererWindowTreeClient::OnWindowOpacityChanged(ui::Id window_id,
float old_opacity,
float new_opacity) {}

void RendererWindowTreeClient::OnWindowParentDrawnStateChanged(ui::Id window_id,
bool drawn) {}

void RendererWindowTreeClient::OnWindowSharedPropertyChanged(
ui::Id window_id,
const std::string& name,
const base::Optional<std::vector<uint8_t>>& new_data) {}

void RendererWindowTreeClient::OnWindowInputEvent(
uint32_t event_id,
ui::Id window_id,
std::unique_ptr<ui::Event> event,
bool matches_pointer_watcher) {
NOTREACHED();
}

void RendererWindowTreeClient::OnPointerEventObserved(
std::unique_ptr<ui::Event> event,
uint32_t window_id) {
NOTREACHED();
}

void RendererWindowTreeClient::OnWindowFocused(ui::Id focused_window_id) {}

void RendererWindowTreeClient::OnWindowPredefinedCursorChanged(
ui::Id window_id,
ui::mojom::Cursor cursor) {}

void RendererWindowTreeClient::OnWindowSurfaceChanged(
ui::Id window_id,
const cc::SurfaceInfo& surface_info) {
NOTIMPLEMENTED();
}

void RendererWindowTreeClient::OnDragDropStart(
const std::unordered_map<std::string, std::vector<uint8_t>>& mime_data) {}

void RendererWindowTreeClient::OnDragEnter(
ui::Id window_id,
uint32_t event_flags,
const gfx::Point& position,
uint32_t effect_bitmask,
const OnDragEnterCallback& callback) {}

void RendererWindowTreeClient::OnDragOver(ui::Id window_id,
uint32_t event_flags,
const gfx::Point& position,
uint32_t effect_bitmask,
const OnDragOverCallback& callback) {}

void RendererWindowTreeClient::OnDragLeave(ui::Id window_id) {}

void RendererWindowTreeClient::OnCompleteDrop(
ui::Id window_id,
uint32_t event_flags,
const gfx::Point& position,
uint32_t effect_bitmask,
const OnCompleteDropCallback& callback) {}

void RendererWindowTreeClient::OnPerformDragDropCompleted(
uint32_t window,
bool success,
uint32_t action_taken) {}

void RendererWindowTreeClient::OnDragDropDone() {}

void RendererWindowTreeClient::OnChangeCompleted(uint32_t change_id,
bool success) {}

void RendererWindowTreeClient::RequestClose(uint32_t window_id) {}

void RendererWindowTreeClient::GetWindowManager(
mojo::AssociatedInterfaceRequest<ui::mojom::WindowManager> internal) {
NOTREACHED();
}

} // namespace content
Loading

0 comments on commit 602ce13

Please sign in to comment.