Nukes ViewTree::SetAccessPolicy
[chromium-blink-merge.git] / components / mus / view_manager_app.cc
blobd83894ddcf1f0ab80d9d7795f5cb3275d170c062
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/mus/view_manager_app.h"
7 #include "base/command_line.h"
8 #include "base/stl_util.h"
9 #include "components/mus/client_connection.h"
10 #include "components/mus/connection_manager.h"
11 #include "components/mus/gles2/gpu_impl.h"
12 #include "components/mus/public/cpp/args.h"
13 #include "components/mus/surfaces/surfaces_scheduler.h"
14 #include "components/mus/view_tree_host_connection.h"
15 #include "components/mus/view_tree_host_impl.h"
16 #include "components/mus/view_tree_impl.h"
17 #include "mojo/application/public/cpp/application_connection.h"
18 #include "mojo/application/public/cpp/application_impl.h"
19 #include "mojo/application/public/cpp/application_runner.h"
20 #include "mojo/common/tracing_impl.h"
21 #include "third_party/mojo/src/mojo/public/c/system/main.h"
22 #include "ui/events/event_switches.h"
23 #include "ui/events/platform/platform_event_source.h"
24 #include "ui/gl/gl_surface.h"
25 #include "ui/gl/test/gl_surface_test_support.h"
27 #if defined(USE_X11)
28 #include <X11/Xlib.h>
29 #include "ui/platform_window/x11/x11_window.h"
30 #endif
32 using mojo::ApplicationConnection;
33 using mojo::ApplicationImpl;
34 using mojo::Gpu;
35 using mojo::InterfaceRequest;
36 using mojo::ViewTreeHostFactory;
38 namespace view_manager {
40 ViewManagerApp::ViewManagerApp() : app_impl_(nullptr), is_headless_(false) {}
42 ViewManagerApp::~ViewManagerApp() {
43 if (gpu_state_)
44 gpu_state_->StopControlThread();
45 // Destroy |connection_manager_| first, since it depends on |event_source_|.
46 connection_manager_.reset();
49 void ViewManagerApp::Initialize(ApplicationImpl* app) {
50 app_impl_ = app;
51 tracing_.Initialize(app);
52 surfaces_state_ = new surfaces::SurfacesState;
54 #if !defined(OS_ANDROID)
55 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
56 is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig);
57 if (!is_headless_) {
58 #if defined(USE_X11)
59 if (command_line->HasSwitch(mojo::kUseX11TestConfig)) {
60 XInitThreads();
61 ui::test::SetUseOverrideRedirectWindowByDefault(true);
63 #endif
64 gfx::GLSurface::InitializeOneOff();
65 event_source_ = ui::PlatformEventSource::CreateDefault();
67 #endif
69 if (!gpu_state_.get())
70 gpu_state_ = new gles2::GpuState;
71 connection_manager_.reset(new ConnectionManager(this, surfaces_state_));
74 bool ViewManagerApp::ConfigureIncomingConnection(
75 ApplicationConnection* connection) {
76 // ViewManager
77 connection->AddService<ViewTreeHostFactory>(this);
78 // GPU
79 connection->AddService<Gpu>(this);
80 return true;
83 void ViewManagerApp::OnNoMoreRootConnections() {
84 app_impl_->Quit();
87 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView(
88 ConnectionManager* connection_manager,
89 mojo::InterfaceRequest<mojo::ViewTree> tree_request,
90 mojo::ConnectionSpecificId creator_id,
91 mojo::URLRequestPtr request,
92 const ViewId& root_id,
93 uint32_t policy_bitmask) {
94 mojo::ViewTreeClientPtr client;
95 app_impl_->ConnectToService(request.Pass(), &client);
97 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl(
98 connection_manager, creator_id, root_id, policy_bitmask));
99 return new DefaultClientConnection(service.Pass(), connection_manager,
100 tree_request.Pass(), client.Pass());
103 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView(
104 ConnectionManager* connection_manager,
105 mojo::InterfaceRequest<mojo::ViewTree> tree_request,
106 mojo::ConnectionSpecificId creator_id,
107 const ViewId& root_id,
108 uint32_t policy_bitmask,
109 mojo::ViewTreeClientPtr client) {
110 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl(
111 connection_manager, creator_id, root_id, policy_bitmask));
112 return new DefaultClientConnection(service.Pass(), connection_manager,
113 tree_request.Pass(), client.Pass());
116 void ViewManagerApp::Create(ApplicationConnection* connection,
117 InterfaceRequest<ViewTreeHostFactory> request) {
118 factory_bindings_.AddBinding(this, request.Pass());
121 void ViewManagerApp::Create(mojo::ApplicationConnection* connection,
122 mojo::InterfaceRequest<Gpu> request) {
123 if (!gpu_state_.get())
124 gpu_state_ = new gles2::GpuState;
125 new gles2::GpuImpl(request.Pass(), gpu_state_);
128 void ViewManagerApp::CreateViewTreeHost(
129 mojo::InterfaceRequest<mojo::ViewTreeHost> host,
130 mojo::ViewTreeHostClientPtr host_client,
131 mojo::ViewTreeClientPtr tree_client) {
132 DCHECK(connection_manager_.get());
134 // TODO(fsamuel): We need to make sure that only the window manager can create
135 // new roots.
136 ViewTreeHostImpl* host_impl = new ViewTreeHostImpl(
137 host_client.Pass(), connection_manager_.get(), is_headless_, app_impl_,
138 gpu_state_, surfaces_state_);
140 // ViewTreeHostConnection manages its own lifetime.
141 host_impl->Init(new ViewTreeHostConnectionImpl(
142 host.Pass(), make_scoped_ptr(host_impl), tree_client.Pass(),
143 connection_manager_.get()));
146 } // namespace view_manager