summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-24 19:01:47 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-24 19:01:47 +0000
commitd7c088c65013381ad28743eb825683feab994133 (patch)
treee3cc89476193cd4b90915b3666d38d27911af5fe
parent90e3b587f2001eaffbd13e83ab9d18ed778dbc6e (diff)
downloadchromium_src-d7c088c65013381ad28743eb825683feab994133.zip
chromium_src-d7c088c65013381ad28743eb825683feab994133.tar.gz
chromium_src-d7c088c65013381ad28743eb825683feab994133.tar.bz2
As discussed, a new WM bootstrap flow.
First off, create a new window manager app (wm_flow_wm) which uses the core_window_manager_lib static lib to implement a basic WM. Second, create a new demo launcher (wm_flow_init) that starts the view manager, embeds wm_flow_wm, and starts an additional app (wm_flow_app). Thirdly, creates an additional app (wm_flow_app) that also connects to the view manager init service and asks it to embed it somewhere, thus giving it a connection to the view manager (and a top-level window). I had to change ViewManagerInitService to have some shared state so that it was possible to connect to it > 1 time. R=sky@chromium.org BUG=none Review URL: https://codereview.chromium.org/400113005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285345 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/examples/wm_flow/app/DEPS0
-rw-r--r--mojo/examples/wm_flow/app/app.cc77
-rw-r--r--mojo/examples/wm_flow/init/init.cc48
-rw-r--r--mojo/examples/wm_flow/wm/DEPS0
-rw-r--r--mojo/examples/wm_flow/wm/wm.cc89
-rw-r--r--mojo/mojo.gyp3
-rw-r--r--mojo/mojo_examples.gypi47
-rw-r--r--mojo/mojo_services.gypi20
-rw-r--r--mojo/services/view_manager/main.cc7
-rw-r--r--mojo/services/view_manager/view_manager_init_service_context.cc69
-rw-r--r--mojo/services/view_manager/view_manager_init_service_context.h59
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.cc41
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.h20
-rw-r--r--mojo/services/window_manager/main.cc19
-rw-r--r--mojo/services/window_manager/window_manager_app.cc15
-rw-r--r--mojo/services/window_manager/window_manager_app.h12
-rw-r--r--mojo/shell/view_manager_loader.cc6
-rw-r--r--mojo/shell/view_manager_loader.h2
18 files changed, 480 insertions, 54 deletions
diff --git a/mojo/examples/wm_flow/app/DEPS b/mojo/examples/wm_flow/app/DEPS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mojo/examples/wm_flow/app/DEPS
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc
new file mode 100644
index 0000000..0d6b83f
--- /dev/null
+++ b/mojo/examples/wm_flow/app/app.cc
@@ -0,0 +1,77 @@
+// Copyright 2014 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 "base/bind.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/services/public/cpp/view_manager/node.h"
+#include "mojo/services/public/cpp/view_manager/view.h"
+#include "mojo/services/public/cpp/view_manager/view_manager.h"
+#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
+#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
+#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
+
+namespace examples {
+namespace {
+void ConnectCallback(bool success) {}
+
+const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW };
+
+} // namespace
+
+// This app starts its life via Connect() rather than by being embed, so it does
+// not start with a connection to the ViewManager service. It has to obtain a
+// connection by connecting to the ViewManagerInit service and asking to be
+// embed without a node context.
+class WMFlowApp : public mojo::ApplicationDelegate,
+ public mojo::view_manager::ViewManagerDelegate {
+ public:
+ WMFlowApp() : embed_count_(0), view_manager_client_factory_(this) {}
+ virtual ~WMFlowApp() {}
+
+ private:
+ // Overridden from Application:
+ virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
+ mojo::view_manager::ViewManagerInitServicePtr init_svc;
+ app->ConnectToService("mojo:mojo_view_manager", &init_svc);
+ init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
+ init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
+ init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
+ }
+ virtual bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
+ connection->AddService(&view_manager_client_factory_);
+ return true;
+ }
+
+ void OnConnect(bool success) {}
+
+ // Overridden from mojo::view_manager::ViewManagerDelegate:
+ virtual void OnRootAdded(mojo::view_manager::ViewManager* view_manager,
+ mojo::view_manager::Node* root) MOJO_OVERRIDE {
+ mojo::view_manager::View* view =
+ mojo::view_manager::View::Create(view_manager);
+ root->SetActiveView(view);
+ view->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
+ }
+ virtual void OnViewManagerDisconnected(
+ mojo::view_manager::ViewManager* view_manager) MOJO_OVERRIDE {}
+
+ int embed_count_;
+ mojo::view_manager::ViewManagerClientFactory view_manager_client_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
+};
+
+} // namespace examples
+
+namespace mojo {
+
+// static
+ApplicationDelegate* ApplicationDelegate::Create() {
+ return new examples::WMFlowApp;
+}
+
+} // namespace
diff --git a/mojo/examples/wm_flow/init/init.cc b/mojo/examples/wm_flow/init/init.cc
new file mode 100644
index 0000000..da54305
--- /dev/null
+++ b/mojo/examples/wm_flow/init/init.cc
@@ -0,0 +1,48 @@
+// Copyright 2014 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 "base/bind.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
+
+namespace examples {
+namespace {
+void ConnectCallback(bool success) {}
+} // namespace
+
+// This application starts the view manager, embeds the window manager and then
+// starts another app (wm_flow_app) which also connects to the view manager and
+// asks to be embedded without context.
+class WMFlowInit : public mojo::ApplicationDelegate {
+ public:
+ WMFlowInit() {}
+ virtual ~WMFlowInit() {}
+
+ private:
+ // Overridden from Application:
+ virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_view_manager", &view_manager_init_);
+ view_manager_init_->Embed("mojo:mojo_wm_flow_wm",
+ base::Bind(&ConnectCallback));
+ app->ConnectToApplication("mojo:mojo_wm_flow_app");
+ }
+
+ void OnConnect(bool success) {}
+
+ mojo::view_manager::ViewManagerInitServicePtr view_manager_init_;
+
+ DISALLOW_COPY_AND_ASSIGN(WMFlowInit);
+};
+
+} // namespace examples
+
+namespace mojo {
+
+// static
+ApplicationDelegate* ApplicationDelegate::Create() {
+ return new examples::WMFlowInit;
+}
+
+} // namespace
diff --git a/mojo/examples/wm_flow/wm/DEPS b/mojo/examples/wm_flow/wm/DEPS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mojo/examples/wm_flow/wm/DEPS
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
new file mode 100644
index 0000000..197ad0f
--- /dev/null
+++ b/mojo/examples/wm_flow/wm/wm.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 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 "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/services/public/cpp/view_manager/view_manager.h"
+#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
+#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
+#include "mojo/services/window_manager/window_manager_app.h"
+
+namespace examples {
+
+class SimpleWM : public mojo::ApplicationDelegate,
+ public mojo::view_manager::ViewManagerDelegate,
+ public mojo::view_manager::WindowManagerDelegate {
+ public:
+ SimpleWM()
+ : window_manager_app_(new mojo::WindowManagerApp(this)),
+ view_manager_(NULL),
+ root_(NULL),
+ window_container_(NULL),
+ next_window_origin_(10, 10) {}
+ virtual ~SimpleWM() {}
+
+ private:
+ // Overridden from mojo::ApplicationDelegate:
+ virtual void Initialize(mojo::ApplicationImpl* impl) MOJO_OVERRIDE {
+ window_manager_app_->Initialize(impl);
+ }
+ virtual bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
+ window_manager_app_->ConfigureIncomingConnection(connection);
+ return true;
+ }
+
+ // Overridden from mojo::view_manager::ViewManagerDelegate:
+ virtual void OnRootAdded(
+ mojo::view_manager::ViewManager* view_manager,
+ mojo::view_manager::Node* root) MOJO_OVERRIDE {
+ view_manager_ = view_manager;
+ root_ = root;
+ view_manager_->SetWindowManagerDelegate(this);
+
+ window_container_ = mojo::view_manager::Node::Create(view_manager_);
+ window_container_->SetBounds(root_->bounds());
+ root_->AddChild(window_container_);
+
+ }
+ virtual void OnViewManagerDisconnected(
+ mojo::view_manager::ViewManager* view_manager) MOJO_OVERRIDE {
+ view_manager_ = NULL;
+ root_ = NULL;
+ }
+
+ // Overridden from mojo::view_manager::WindowManagerDelegate:
+ virtual void Embed(const mojo::String& url) MOJO_OVERRIDE {
+ mojo::view_manager::Node* embed_node =
+ mojo::view_manager::Node::Create(view_manager_);
+ embed_node->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
+ window_container_->AddChild(embed_node);
+ embed_node->Embed(url);
+ next_window_origin_.Offset(50, 50);
+ }
+ virtual void DispatchEvent(mojo::view_manager::View* target,
+ mojo::EventPtr event) MOJO_OVERRIDE {
+ view_manager_->DispatchEvent(target, event.Pass());
+ }
+
+ scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
+
+ mojo::view_manager::ViewManager* view_manager_;
+ mojo::view_manager::Node* root_;
+ mojo::view_manager::Node* window_container_;
+
+ gfx::Point next_window_origin_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleWM);
+};
+
+} // namespace examples
+
+namespace mojo {
+
+// static
+ApplicationDelegate* ApplicationDelegate::Create() {
+ return new examples::SimpleWM;
+}
+
+} // namespace
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index 17f8c2d..994893e 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -118,6 +118,9 @@
'mojo_media_viewer',
'mojo_nesting_app',
'mojo_window_manager',
+ 'mojo_wm_flow_app',
+ 'mojo_wm_flow_init',
+ 'mojo_wm_flow_wm',
'mojo_view_manager',
'mojo_view_manager_unittests',
],
diff --git a/mojo/mojo_examples.gypi b/mojo/mojo_examples.gypi
index 44055ee..f51de2d 100644
--- a/mojo/mojo_examples.gypi
+++ b/mojo/mojo_examples.gypi
@@ -594,6 +594,53 @@
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
+ {
+ 'target_name': 'mojo_wm_flow_wm',
+ 'type': 'loadable_module',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'mojo_application',
+ 'mojo_environment_chromium',
+ 'mojo_core_window_manager_lib',
+ 'mojo_view_manager_lib',
+ '<(mojo_system_for_loadable_module)',
+ ],
+ 'sources': [
+ 'examples/wm_flow/wm/wm.cc',
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ ],
+ },
+ {
+ 'target_name': 'mojo_wm_flow_init',
+ 'type': 'loadable_module',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'mojo_application',
+ 'mojo_environment_chromium',
+ 'mojo_view_manager_bindings',
+ '<(mojo_system_for_loadable_module)',
+ ],
+ 'sources': [
+ 'examples/wm_flow/init/init.cc',
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ ],
+ },
+ {
+ 'target_name': 'mojo_wm_flow_app',
+ 'type': 'loadable_module',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'mojo_application',
+ 'mojo_environment_chromium',
+ 'mojo_core_window_manager_bindings',
+ 'mojo_view_manager_lib',
+ '<(mojo_system_for_loadable_module)',
+ ],
+ 'sources': [
+ 'examples/wm_flow/app/app.cc',
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ ],
+ },
],
}],
['OS=="linux"', {
diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi
index 821afcf..58f8ca8 100644
--- a/mojo/mojo_services.gypi
+++ b/mojo/mojo_services.gypi
@@ -724,6 +724,8 @@
'services/view_manager/view.cc',
'services/view_manager/view.h',
'services/view_manager/view_manager_export.h',
+ 'services/view_manager/view_manager_init_service_context.cc',
+ 'services/view_manager/view_manager_init_service_context.h',
'services/view_manager/view_manager_init_service_impl.cc',
'services/view_manager/view_manager_init_service_impl.h',
'services/view_manager/view_manager_service_impl.cc',
@@ -802,8 +804,8 @@
'includes': [ 'build/package_app.gypi' ],
},
{
- 'target_name': 'mojo_core_window_manager',
- 'type': 'loadable_module',
+ 'target_name': 'mojo_core_window_manager_lib',
+ 'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'../ui/base/ui_base.gyp:ui_base',
@@ -816,10 +818,8 @@
'mojo_core_window_manager_bindings',
'mojo_environment_chromium',
'mojo_view_manager_lib',
- '<(mojo_system_for_loadable_module)',
],
'sources': [
- 'public/cpp/application/lib/mojo_main_chromium.cc',
'services/window_manager/window_manager_app.cc',
'services/window_manager/window_manager_app.h',
'services/window_manager/window_manager_service_impl.cc',
@@ -827,6 +827,18 @@
],
},
{
+ 'target_name': 'mojo_core_window_manager',
+ 'type': 'loadable_module',
+ 'dependencies': [
+ 'mojo_core_window_manager_lib',
+ '<(mojo_system_for_loadable_module)',
+ ],
+ 'sources': [
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ 'services/window_manager/main.cc',
+ ],
+ },
+ {
'target_name': 'mojo_core_window_manager_unittests',
'type': 'executable',
'dependencies': [
diff --git a/mojo/services/view_manager/main.cc b/mojo/services/view_manager/main.cc
index 3a80996..2254c76 100644
--- a/mojo/services/view_manager/main.cc
+++ b/mojo/services/view_manager/main.cc
@@ -4,6 +4,7 @@
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/services/view_manager/view_manager_init_service_context.h"
#include "mojo/services/view_manager/view_manager_init_service_impl.h"
namespace mojo {
@@ -18,6 +19,7 @@ class ViewManagerApp : public ApplicationDelegate,
virtual bool ConfigureIncomingConnection(
ApplicationConnection* connection) OVERRIDE {
+ context_.ConfigureIncomingConnection(connection);
// TODO(sky): this needs some sort of authentication as well as making sure
// we only ever have one active at a time.
connection->AddService(this);
@@ -27,10 +29,13 @@ class ViewManagerApp : public ApplicationDelegate,
virtual void Create(
ApplicationConnection* connection,
InterfaceRequest<ViewManagerInitService> request) OVERRIDE {
- BindToRequest(new ViewManagerInitServiceImpl(connection), &request);
+ BindToRequest(new ViewManagerInitServiceImpl(connection, &context_),
+ &request);
}
private:
+ ViewManagerInitServiceContext context_;
+
DISALLOW_COPY_AND_ASSIGN(ViewManagerApp);
};
diff --git a/mojo/services/view_manager/view_manager_init_service_context.cc b/mojo/services/view_manager/view_manager_init_service_context.cc
new file mode 100644
index 0000000..d0a6fdc
--- /dev/null
+++ b/mojo/services/view_manager/view_manager_init_service_context.cc
@@ -0,0 +1,69 @@
+// Copyright 2014 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 "mojo/services/view_manager/view_manager_init_service_context.h"
+
+#include "base/bind.h"
+#include "mojo/services/view_manager/root_node_manager.h"
+#include "mojo/services/view_manager/view_manager_init_service_impl.h"
+
+namespace mojo {
+namespace view_manager {
+namespace service {
+
+ViewManagerInitServiceContext::ViewManagerInitServiceContext()
+ : is_tree_host_ready_(false) {}
+ViewManagerInitServiceContext::~ViewManagerInitServiceContext() {}
+
+void ViewManagerInitServiceContext::AddConnection(
+ ViewManagerInitServiceImpl* connection) {
+ DCHECK(std::find(connections_.begin(), connections_.end(), connection) ==
+ connections_.end());
+ connections_.push_back(connection);
+}
+
+void ViewManagerInitServiceContext::RemoveConnection(
+ ViewManagerInitServiceImpl* connection) {
+ Connections::iterator it =
+ std::find(connections_.begin(), connections_.end(), connection);
+ DCHECK(it != connections_.end());
+ connections_.erase(it);
+
+ // This object is owned by an object that outlives the current thread's
+ // message loop, so we need to destroy the RootNodeManager earlier, as it may
+ // attempt to post tasks during its destruction.
+ if (connections_.empty())
+ root_node_manager_.reset();
+}
+
+void ViewManagerInitServiceContext::ConfigureIncomingConnection(
+ ApplicationConnection* connection) {
+ if (!root_node_manager_.get()) {
+ root_node_manager_.reset(new RootNodeManager(
+ connection,
+ this,
+ base::Bind(&ViewManagerInitServiceContext::OnNativeViewportDeleted,
+ base::Unretained(this))));
+ }
+}
+
+void ViewManagerInitServiceContext::OnNativeViewportDeleted() {
+ for (Connections::const_iterator it = connections_.begin();
+ it != connections_.end(); ++it) {
+ (*it)->OnNativeViewportDeleted();
+ }
+}
+
+void ViewManagerInitServiceContext::OnRootViewManagerWindowTreeHostCreated() {
+ DCHECK(!is_tree_host_ready_);
+ is_tree_host_ready_ = true;
+ for (Connections::const_iterator it = connections_.begin();
+ it != connections_.end(); ++it) {
+ (*it)->OnRootViewManagerWindowTreeHostCreated();
+ }
+}
+
+} // namespace service
+} // namespace view_manager
+} // namespace mojo
diff --git a/mojo/services/view_manager/view_manager_init_service_context.h b/mojo/services/view_manager/view_manager_init_service_context.h
new file mode 100644
index 0000000..3206205
--- /dev/null
+++ b/mojo/services/view_manager/view_manager_init_service_context.h
@@ -0,0 +1,59 @@
+// Copyright 2014 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.
+
+#ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_CONTEXT_H_
+#define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_CONTEXT_H_
+
+#include <set>
+
+#include "base/memory/scoped_ptr.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/services/view_manager/root_view_manager_delegate.h"
+#include "mojo/services/view_manager/view_manager_export.h"
+
+namespace mojo {
+namespace view_manager {
+namespace service {
+
+class RootNodeManager;
+class ViewManagerInitServiceImpl;
+
+// State shared between all ViewManagerInitService impls.
+class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceContext
+ : public RootViewManagerDelegate {
+ public:
+ ViewManagerInitServiceContext();
+ virtual ~ViewManagerInitServiceContext();
+
+ void AddConnection(ViewManagerInitServiceImpl* connection);
+ void RemoveConnection(ViewManagerInitServiceImpl* connection);
+
+ void ConfigureIncomingConnection(ApplicationConnection* connection);
+
+ RootNodeManager* root_node_manager() { return root_node_manager_.get(); }
+
+ bool is_tree_host_ready() const { return is_tree_host_ready_; }
+
+ private:
+ typedef std::vector<ViewManagerInitServiceImpl*> Connections;
+
+ // RootViewManagerDelegate overrides:
+ virtual void OnRootViewManagerWindowTreeHostCreated() OVERRIDE;
+
+ void OnNativeViewportDeleted();
+
+ scoped_ptr<RootNodeManager> root_node_manager_;
+ Connections connections_;
+
+ bool is_tree_host_ready_;
+
+ DISALLOW_COPY_AND_ASSIGN(ViewManagerInitServiceContext);
+};
+
+} // namespace service
+} // namespace view_manager
+} // namespace mojo
+
+#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_CONTEXT_H_
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.cc b/mojo/services/view_manager/view_manager_init_service_impl.cc
index 79cc6c4..e375439 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_init_service_impl.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/view_manager/ids.h"
+#include "mojo/services/view_manager/view_manager_init_service_context.h"
#include "mojo/services/view_manager/view_manager_service_impl.h"
namespace mojo {
@@ -19,25 +20,34 @@ ViewManagerInitServiceImpl::ConnectParams::ConnectParams() {}
ViewManagerInitServiceImpl::ConnectParams::~ConnectParams() {}
ViewManagerInitServiceImpl::ViewManagerInitServiceImpl(
- ApplicationConnection* connection)
- : root_node_manager_(
- connection,
- this,
- base::Bind(&ViewManagerInitServiceImpl::OnNativeViewportDeleted,
- base::Unretained(this))),
- is_tree_host_ready_(false) {
+ ApplicationConnection* connection,
+ ViewManagerInitServiceContext* context)
+ : context_(context) {
+ context_->AddConnection(this);
}
ViewManagerInitServiceImpl::~ViewManagerInitServiceImpl() {
+ context_->RemoveConnection(this);
+}
+
+void ViewManagerInitServiceImpl::OnNativeViewportDeleted() {
+ // TODO(beng): Should not have to rely on implementation detail of
+ // InterfaceImpl to close the connection. Instead should simply
+ // be able to delete this object.
+ internal_state()->router()->CloseMessagePipe();
+}
+
+void ViewManagerInitServiceImpl::OnRootViewManagerWindowTreeHostCreated() {
+ MaybeEmbed();
}
void ViewManagerInitServiceImpl::MaybeEmbed() {
- if (!is_tree_host_ready_)
+ if (!context_->is_tree_host_ready())
return;
ScopedVector<ConnectParams>::const_iterator it = connect_params_.begin();
for (; it != connect_params_.end(); ++it) {
- root_node_manager_.EmbedRoot((*it)->url);
+ context_->root_node_manager()->EmbedRoot((*it)->url);
(*it)->callback.Run(true);
}
connect_params_.clear();
@@ -53,19 +63,6 @@ void ViewManagerInitServiceImpl::Embed(
MaybeEmbed();
}
-void ViewManagerInitServiceImpl::OnRootViewManagerWindowTreeHostCreated() {
- DCHECK(!is_tree_host_ready_);
- is_tree_host_ready_ = true;
- MaybeEmbed();
-}
-
-void ViewManagerInitServiceImpl::OnNativeViewportDeleted() {
- // TODO(beng): Should not have to rely on implementation detail of
- // InterfaceImpl to close the connection. Instead should simply
- // be able to delete this object.
- internal_state()->router()->CloseMessagePipe();
-}
-
} // namespace service
} // namespace view_manager
} // namespace mojo
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.h b/mojo/services/view_manager/view_manager_init_service_impl.h
index f659df9..a10af10 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.h
+++ b/mojo/services/view_manager/view_manager_init_service_impl.h
@@ -12,7 +12,6 @@
#include "base/memory/scoped_vector.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
#include "mojo/services/view_manager/root_node_manager.h"
-#include "mojo/services/view_manager/root_view_manager_delegate.h"
#include "mojo/services/view_manager/view_manager_export.h"
namespace mojo {
@@ -23,6 +22,8 @@ class ServiceProvider;
namespace view_manager {
namespace service {
+class ViewManagerInitServiceContext;
+
#if defined(OS_WIN)
// Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
// below.
@@ -33,12 +34,16 @@ namespace service {
// Used to create the initial ViewManagerClient. Doesn't initiate the Connect()
// until the WindowTreeHost has been created.
class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceImpl
- : public InterfaceImpl<ViewManagerInitService>,
- public RootViewManagerDelegate {
+ : public InterfaceImpl<ViewManagerInitService> {
public:
- explicit ViewManagerInitServiceImpl(ApplicationConnection* connection);
+ ViewManagerInitServiceImpl(ApplicationConnection* connection,
+ ViewManagerInitServiceContext* context);
virtual ~ViewManagerInitServiceImpl();
+ void OnNativeViewportDeleted();
+
+ void OnRootViewManagerWindowTreeHostCreated();
+
private:
struct ConnectParams {
ConnectParams();
@@ -54,15 +59,10 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceImpl
virtual void Embed(const String& url,
const Callback<void(bool)>& callback) OVERRIDE;
- // RootViewManagerDelegate overrides:
- virtual void OnRootViewManagerWindowTreeHostCreated() OVERRIDE;
-
- void OnNativeViewportDeleted();
+ ViewManagerInitServiceContext* context_;
ServiceProvider* service_provider_;
- RootNodeManager root_node_manager_;
-
// Stores information about inbound calls to Embed() pending execution on
// the window tree host being ready to use.
ScopedVector<ConnectParams> connect_params_;
diff --git a/mojo/services/window_manager/main.cc b/mojo/services/window_manager/main.cc
new file mode 100644
index 0000000..b77d388
--- /dev/null
+++ b/mojo/services/window_manager/main.cc
@@ -0,0 +1,19 @@
+// Copyright 2014 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 "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/services/window_manager/window_manager_app.h"
+
+// ApplicationDelegate implementation file for WindowManager users (e.g.
+// core window manager tests) that do not want to provide their own
+// ApplicationDelegate::Create().
+
+namespace mojo {
+
+// static
+ApplicationDelegate* ApplicationDelegate::Create() {
+ return new WindowManagerApp(NULL);
+}
+
+} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc
index 02e5b95..ccc3898 100644
--- a/mojo/services/window_manager/window_manager_app.cc
+++ b/mojo/services/window_manager/window_manager_app.cc
@@ -70,12 +70,14 @@ class WMFocusRules : public wm::FocusRules {
////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, public:
-WindowManagerApp::WindowManagerApp()
+WindowManagerApp::WindowManagerApp(view_manager::ViewManagerDelegate* delegate)
: InterfaceFactoryWithContext(this),
+ wrapped_delegate_(delegate),
view_manager_(NULL),
view_manager_client_factory_(this),
root_(NULL) {
}
+
WindowManagerApp::~WindowManagerApp() {
// TODO(beng): Figure out if this should be done in
// OnViewManagerDisconnected().
@@ -169,7 +171,7 @@ void WindowManagerApp::OnRootAdded(view_manager::ViewManager* view_manager,
focus_client_->AddObserver(this);
activation_client_->AddObserver(this);
- // TODO(beng): Create the universe.
+ wrapped_delegate_->OnRootAdded(view_manager, root);
for (Connections::const_iterator it = connections_.begin();
it != connections_.end(); ++it) {
@@ -180,6 +182,7 @@ void WindowManagerApp::OnRootAdded(view_manager::ViewManager* view_manager,
void WindowManagerApp::OnViewManagerDisconnected(
view_manager::ViewManager* view_manager) {
DCHECK_EQ(view_manager_, view_manager);
+ wrapped_delegate_->OnViewManagerDisconnected(view_manager);
root_->RemoveObserver(this);
root_ = NULL;
view_manager_ = NULL;
@@ -274,12 +277,4 @@ void WindowManagerApp::UnregisterSubtree(view_manager::Id id) {
UnregisterSubtree((*child)->id());
}
-////////////////////////////////////////////////////////////////////////////////
-// ApplicationDelegate, public:
-
-// static
-ApplicationDelegate* ApplicationDelegate::Create() {
- return new WindowManagerApp;
-}
-
} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_app.h b/mojo/services/window_manager/window_manager_app.h
index bcd74db..310dbcc 100644
--- a/mojo/services/window_manager/window_manager_app.h
+++ b/mojo/services/window_manager/window_manager_app.h
@@ -48,7 +48,7 @@ class WindowManagerApp
public InterfaceFactoryWithContext<WindowManagerServiceImpl,
WindowManagerApp> {
public:
- WindowManagerApp();
+ explicit WindowManagerApp(view_manager::ViewManagerDelegate* delegate);
virtual ~WindowManagerApp();
void AddConnection(WindowManagerServiceImpl* connection);
@@ -62,15 +62,15 @@ class WindowManagerApp
bool IsReady() const;
- private:
- typedef std::set<WindowManagerServiceImpl*> Connections;
- typedef std::map<view_manager::Id, aura::Window*> NodeIdToWindowMap;
-
// Overridden from ApplicationDelegate:
virtual void Initialize(ApplicationImpl* impl) MOJO_OVERRIDE;
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
MOJO_OVERRIDE;
+ private:
+ typedef std::set<WindowManagerServiceImpl*> Connections;
+ typedef std::map<view_manager::Id, aura::Window*> NodeIdToWindowMap;
+
// Overridden from view_manager::ViewManagerDelegate:
virtual void OnRootAdded(view_manager::ViewManager* view_manager,
view_manager::Node* root) MOJO_OVERRIDE;
@@ -103,6 +103,8 @@ class WindowManagerApp
// and removes from the registry.
void UnregisterSubtree(view_manager::Id id);
+ view_manager::ViewManagerDelegate* wrapped_delegate_;
+
view_manager::ViewManager* view_manager_;
view_manager::ViewManagerClientFactory view_manager_client_factory_;
view_manager::Node* root_;
diff --git a/mojo/shell/view_manager_loader.cc b/mojo/shell/view_manager_loader.cc
index 6b93eac..9343059 100644
--- a/mojo/shell/view_manager_loader.cc
+++ b/mojo/shell/view_manager_loader.cc
@@ -37,7 +37,8 @@ void ViewManagerLoader::OnServiceError(ServiceManager* manager,
}
bool ViewManagerLoader::ConfigureIncomingConnection(
- ApplicationConnection* connection) {
+ ApplicationConnection* connection) {
+ context_.ConfigureIncomingConnection(connection);
connection->AddService(this);
return true;
}
@@ -45,7 +46,8 @@ bool ViewManagerLoader::ConfigureIncomingConnection(
void ViewManagerLoader::Create(
ApplicationConnection* connection,
InterfaceRequest<ViewManagerInitService> request) {
- BindToRequest(new ViewManagerInitServiceImpl(connection), &request);
+ BindToRequest(new ViewManagerInitServiceImpl(connection, &context_),
+ &request);
}
} // namespace shell
diff --git a/mojo/shell/view_manager_loader.h b/mojo/shell/view_manager_loader.h
index c858a8d..72199f7 100644
--- a/mojo/shell/view_manager_loader.h
+++ b/mojo/shell/view_manager_loader.h
@@ -11,6 +11,7 @@
#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/service_manager/service_loader.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
+#include "mojo/services/view_manager/view_manager_init_service_context.h"
namespace mojo {
@@ -46,6 +47,7 @@ class ViewManagerLoader
InterfaceRequest<view_manager::ViewManagerInitService> request) OVERRIDE;
ScopedVector<Application> apps_;
+ view_manager::service::ViewManagerInitServiceContext context_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerLoader);
};