summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-02 20:51:53 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-02 20:51:53 +0000
commit607460b9f19be650a5f25c1726fee62a33418118 (patch)
tree21e917d9f5cdad62f9fc13baae46998a12f2aab6 /mojo
parent7278052a5e91d3b4b92ecda86d3f50bf44eb5958 (diff)
downloadchromium_src-607460b9f19be650a5f25c1726fee62a33418118.zip
chromium_src-607460b9f19be650a5f25c1726fee62a33418118.tar.gz
chromium_src-607460b9f19be650a5f25c1726fee62a33418118.tar.bz2
Implement a demo that shows one app embedding rendering in another.
launcher inits the view manager, running the "window manager" app @ root. window manager embeds another app. R=sky@chromium.org TEST=mojo_shell --origin=http://127.0.0.1:4444 --disable-cache mojo:mojo_demo_launcher http://crbug.com/365012 Review URL: https://codereview.chromium.org/303163005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/examples/demo_launcher/demo_launcher.cc43
-rw-r--r--mojo/examples/embedded_app/embedded_app.cc40
-rw-r--r--mojo/examples/sample_view_manager_app/sample_view_manager_app.cc5
-rw-r--r--mojo/examples/window_manager/window_manager.cc51
-rw-r--r--mojo/mojo.gyp4
-rw-r--r--mojo/mojo_examples.gypi49
-rw-r--r--mojo/services/public/cpp/view_manager/DEPS1
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view.cc7
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager.cc19
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_private.h6
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc98
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h21
-rw-r--r--mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc14
-rw-r--r--mojo/services/public/cpp/view_manager/view.h3
-rw-r--r--mojo/services/public/cpp/view_manager/view_manager.h19
15 files changed, 300 insertions, 80 deletions
diff --git a/mojo/examples/demo_launcher/demo_launcher.cc b/mojo/examples/demo_launcher/demo_launcher.cc
new file mode 100644
index 0000000..def2e4d
--- /dev/null
+++ b/mojo/examples/demo_launcher/demo_launcher.cc
@@ -0,0 +1,43 @@
+// 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/basictypes.h"
+#include "base/bind.h"
+#include "base/run_loop.h"
+#include "mojo/public/cpp/application/application.h"
+#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
+
+namespace mojo {
+namespace examples {
+
+class DemoLauncher : public Application {
+ public:
+ DemoLauncher() {}
+ virtual ~DemoLauncher() {}
+
+ private:
+ // Overridden from Application:
+ virtual void Initialize() MOJO_OVERRIDE {
+ ConnectTo<view_manager::IViewManagerInit>("mojo:mojo_view_manager",
+ &view_manager_init_);
+ view_manager_init_->Connect("mojo:mojo_window_manager",
+ base::Bind(&DemoLauncher::OnConnect,
+ base::Unretained(this)));
+ }
+
+ void OnConnect(bool success) {}
+
+ view_manager::IViewManagerInitPtr view_manager_init_;
+
+ DISALLOW_COPY_AND_ASSIGN(DemoLauncher);
+};
+
+} // namespace examples
+
+// static
+Application* Application::Create() {
+ return new examples::DemoLauncher;
+}
+
+} // namespace mojo
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
new file mode 100644
index 0000000..139e313
--- /dev/null
+++ b/mojo/examples/embedded_app/embedded_app.cc
@@ -0,0 +1,40 @@
+// 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/basictypes.h"
+#include "mojo/public/cpp/application/application.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_tree_node.h"
+
+namespace mojo {
+namespace examples {
+
+class EmbeddedApp : public Application {
+ public:
+ EmbeddedApp() {}
+ virtual ~EmbeddedApp() {}
+
+ private:
+ // Overridden from Application:
+ virtual void Initialize() MOJO_OVERRIDE {
+ view_manager_ = new view_manager::ViewManager(this);
+ view_manager::View* view = view_manager::View::Create(view_manager_);
+ view_manager_->tree()->SetActiveView(view);
+ view->SetColor(SK_ColorYELLOW);
+ }
+
+ view_manager::ViewManager* view_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
+};
+
+} // namespace examples
+
+// static
+Application* Application::Create() {
+ return new examples::EmbeddedApp;
+}
+
+} // namespace mojo \ No newline at end of file
diff --git a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
index 1ae5b90..15113bb 100644
--- a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
+++ b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
@@ -36,10 +36,7 @@ class SampleApp : public Application {
view_manager_->tree()->AddChild(node1);
node1->AddChild(node11);
- gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
- canvas.DrawColor(SK_ColorRED);
- view11->SetContents(
- skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
+ view11->SetColor(SK_ColorRED);
}
private:
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
new file mode 100644
index 0000000..8aa52a3
--- /dev/null
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -0,0 +1,51 @@
+// 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/basictypes.h"
+#include "mojo/public/cpp/application/application.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_tree_node.h"
+
+namespace mojo {
+namespace examples {
+
+class WindowManager : public Application {
+ public:
+ WindowManager() {}
+ virtual ~WindowManager() {}
+
+ private:
+ // Overridden from Application:
+ virtual void Initialize() MOJO_OVERRIDE {
+ view_manager_ = new view_manager::ViewManager(this);
+ view_manager::ViewTreeNode* node =
+ view_manager::ViewTreeNode::Create(view_manager_);
+ view_manager_->tree()->AddChild(node);
+ node->SetBounds(gfx::Rect(800, 600));
+
+ view_manager::View* view = view_manager::View::Create(view_manager_);
+ node->SetActiveView(view);
+ view->SetColor(SK_ColorBLUE);
+
+ view_manager::ViewTreeNode* embedded =
+ view_manager::ViewTreeNode::Create(view_manager_);
+ node->AddChild(embedded);
+ embedded->SetBounds(gfx::Rect(50, 50, 200, 200));
+ view_manager_->Embed("mojo:mojo_embedded_app", embedded);
+ }
+
+ view_manager::ViewManager* view_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowManager);
+};
+
+} // namespace examples
+
+// static
+Application* Application::Create() {
+ return new examples::WindowManager;
+}
+
+} // namespace mojo \ No newline at end of file
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index bc71705..c7ae097 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -63,7 +63,9 @@
'dependencies': [
'mojo_aura_demo',
'mojo_launcher',
- 'mojo_sample_view_manager_app',
+ 'mojo_demo_launcher',
+ 'mojo_embedded_app',
+ 'mojo_window_manager',
'mojo_view_manager',
'mojo_view_manager_unittests',
],
diff --git a/mojo/mojo_examples.gypi b/mojo/mojo_examples.gypi
index d99bf5a..e62740e 100644
--- a/mojo/mojo_examples.gypi
+++ b/mojo/mojo_examples.gypi
@@ -246,7 +246,7 @@
'includes': [ 'build/package_app.gypi' ],
},
{
- 'target_name': 'mojo_sample_view_manager_app',
+ 'target_name': 'mojo_demo_launcher',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
@@ -254,17 +254,60 @@
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gl/gl.gyp:gl',
+ 'mojo_application',
+ 'mojo_cpp_bindings',
+ 'mojo_environment_chromium',
+ 'mojo_geometry_bindings',
+ 'mojo_gles2',
+ 'mojo_view_manager_bindings',
+ 'mojo_system_impl',
+ 'mojo_utility',
+ ],
+ 'sources': [
+ 'examples/demo_launcher/demo_launcher.cc',
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ ],
+ },
+ {
+ 'target_name': 'mojo_window_manager',
+ 'type': 'shared_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../ui/gfx/gfx.gyp:gfx_geometry',
+ '../ui/gl/gl.gyp:gl',
+ 'mojo_application',
+ 'mojo_cpp_bindings',
+ 'mojo_environment_chromium',
+ 'mojo_geometry_bindings',
+ 'mojo_gles2',
+ 'mojo_view_manager_lib',
+ 'mojo_system_impl',
+ 'mojo_utility',
+ ],
+ 'sources': [
+ 'examples/window_manager/window_manager.cc',
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ ],
+ },
+ {
+ 'target_name': 'mojo_embedded_app',
+ 'type': 'shared_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../ui/gfx/gfx.gyp:gfx_geometry',
+ '../ui/gl/gl.gyp:gl',
+ 'mojo_application',
'mojo_cpp_bindings',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_gles2',
- 'mojo_main_chromium',
'mojo_view_manager_lib',
'mojo_system_impl',
'mojo_utility',
],
'sources': [
- 'examples/sample_view_manager_app/sample_view_manager_app.cc',
+ 'examples/embedded_app/embedded_app.cc',
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
],
diff --git a/mojo/services/public/cpp/view_manager/DEPS b/mojo/services/public/cpp/view_manager/DEPS
index 8ce1d20..4460c19 100644
--- a/mojo/services/public/cpp/view_manager/DEPS
+++ b/mojo/services/public/cpp/view_manager/DEPS
@@ -1,3 +1,4 @@
include_rules = [
+ "+third_party/skia/include/core",
"+ui/gfx/geometry"
]
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index b11929c..be4397b 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -7,6 +7,7 @@
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_private.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
+#include "ui/gfx/canvas.h"
namespace mojo {
namespace view_manager {
@@ -61,6 +62,12 @@ void View::SetContents(const SkBitmap& contents) {
ViewManagerPrivate(manager_).synchronizer()->SetViewContents(id_, contents);
}
+void View::SetColor(SkColor color) {
+ gfx::Canvas canvas(node_->bounds().size(), 1.0f, true);
+ canvas.DrawColor(color);
+ SetContents(skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
+}
+
View::View(ViewManager* manager)
: id_(ViewManagerPrivate(manager).synchronizer()->CreateView()),
node_(NULL),
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager.cc b/mojo/services/public/cpp/view_manager/lib/view_manager.cc
index 93d99e8..74fa699 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager.cc
@@ -4,6 +4,8 @@
#include "mojo/services/public/cpp/view_manager/view_manager.h"
+#include "base/message_loop/message_loop.h"
+#include "mojo/public/cpp/application/application.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -11,8 +13,13 @@
namespace mojo {
namespace view_manager {
-ViewManager::ViewManager(ServiceProvider* service_provider)
- : service_provider_(service_provider) {}
+ViewManager::ViewManager(Application* application)
+ : synchronizer_(NULL),
+ tree_(NULL) {
+ application->AddService<ViewManagerSynchronizer>(this);
+ // Block in a nested message loop until the ViewManagerSynchronizer is set up.
+ base::MessageLoop::current()->Run();
+}
ViewManager::~ViewManager() {
while (!nodes_.empty()) {
@@ -31,10 +38,6 @@ ViewManager::~ViewManager() {
}
}
-void ViewManager::Init() {
- synchronizer_.reset(new ViewManagerSynchronizer(this));
-}
-
ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) {
IdToNodeMap::const_iterator it = nodes_.find(id);
return it != nodes_.end() ? it->second : NULL;
@@ -45,5 +48,9 @@ View* ViewManager::GetViewById(TransportViewId id) {
return it != views_.end() ? it->second : NULL;
}
+void ViewManager::Embed(const String& url, ViewTreeNode* node) {
+ synchronizer_->Embed(url, node->id());
+}
+
} // namespace view_manager
} // namespace mojo
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_private.h b/mojo/services/public/cpp/view_manager/lib/view_manager_private.h
index edd55cc..a2b2aab 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_private.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_private.h
@@ -20,9 +20,11 @@ class ViewManagerPrivate {
~ViewManagerPrivate();
ViewManagerSynchronizer* synchronizer() {
- return manager_->synchronizer_.get();
+ return manager_->synchronizer_;
+ }
+ void set_synchronizer(ViewManagerSynchronizer* synchronizer) {
+ manager_->synchronizer_ = synchronizer;
}
- ServiceProvider* service_provider() { return manager_->service_provider_; }
void set_root(ViewTreeNode* root) { manager_->tree_ = root; }
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
index 2ae1378..7d1d489 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
@@ -5,7 +5,7 @@
#include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
#include "base/bind.h"
-#include "base/run_loop.h"
+#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
@@ -108,7 +108,9 @@ class ViewManagerTransaction {
// Node bounds.
TYPE_SET_BOUNDS,
// View contents
- TYPE_SET_VIEW_CONTENTS
+ TYPE_SET_VIEW_CONTENTS,
+ // Embed.
+ TYPE_EMBED
};
ViewManagerTransaction(TransactionType transaction_type,
@@ -125,7 +127,7 @@ class ViewManagerTransaction {
// service.
virtual void DoActionCompleted(bool success) = 0;
- IViewManager* service() { return synchronizer_->service_.get(); }
+ IViewManager* service() { return synchronizer_->service_; }
TransportChangeId GetAndAdvanceNextServerChangeId() {
return synchronizer_->next_server_change_id_++;
@@ -405,26 +407,42 @@ class SetViewContentsTransaction : public ViewManagerTransaction {
DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction);
};
+class EmbedTransaction : public ViewManagerTransaction {
+ public:
+ EmbedTransaction(const String& url,
+ TransportNodeId node_id,
+ ViewManagerSynchronizer* synchronizer)
+ : ViewManagerTransaction(TYPE_EMBED, synchronizer),
+ url_(url),
+ node_id_(node_id) {}
+ virtual ~EmbedTransaction() {}
+
+ private:
+ // Overridden from ViewManagerTransaction:
+ virtual void DoCommit() OVERRIDE {
+ std::vector<TransportNodeId> ids;
+ ids.push_back(node_id_);
+ service()->Connect(url_, Array<TransportNodeId>::From(ids),
+ ActionCompletedCallback());
+ }
+ virtual void DoActionCompleted(bool success) OVERRIDE {
+ // TODO(beng): recovery?
+ }
+
+ const String url_;
+ const TransportNodeId node_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(EmbedTransaction);
+};
+
ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager)
: view_manager_(view_manager),
connected_(false),
connection_id_(0),
next_id_(1),
next_server_change_id_(0),
- sync_factory_(this),
- init_loop_(NULL) {
- ConnectToService(
- ViewManagerPrivate(view_manager_).service_provider(),
- "mojo:mojo_view_manager",
- &service_);
- service_.set_client(this);
-
- // Start a runloop. This loop is quit when the server tells us about the
- // connection (OnConnectionEstablished()).
- base::RunLoop loop;
- init_loop_ = &loop;
- init_loop_->Run();
- init_loop_ = NULL;
+ sync_factory_(this) {
+ ViewManagerPrivate(view_manager).set_synchronizer(this);
}
ViewManagerSynchronizer::~ViewManagerSynchronizer() {
@@ -517,6 +535,20 @@ void ViewManagerSynchronizer::SetViewContents(TransportViewId view_id,
Sync();
}
+void ViewManagerSynchronizer::Embed(const String& url,
+ TransportNodeId node_id) {
+ DCHECK(connected_);
+ pending_transactions_.push_back(new EmbedTransaction(url, node_id, this));
+ Sync();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ViewManagerSynchronizer, InterfaceImpl overrides:
+
+void ViewManagerSynchronizer::OnConnectionEstablished() {
+ service_ = client();
+}
+
////////////////////////////////////////////////////////////////////////////////
// ViewManagerSynchronizer, IViewManagerClient implementation:
@@ -528,12 +560,12 @@ void ViewManagerSynchronizer::OnViewManagerConnectionEstablished(
connection_id_ = connection_id;
next_server_change_id_ = next_server_change_id;
- ViewManagerPrivate(view_manager_).set_root(
- BuildNodeTree(view_manager_, nodes));
- if (init_loop_)
- init_loop_->Quit();
+ ViewManagerPrivate(view_manager()).set_root(
+ BuildNodeTree(view_manager(), nodes));
Sync();
+
+ base::MessageLoop::current()->Quit();
}
void ViewManagerSynchronizer::OnServerChangeIdAdvanced(
@@ -544,7 +576,7 @@ void ViewManagerSynchronizer::OnServerChangeIdAdvanced(
void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id,
RectPtr old_bounds,
RectPtr new_bounds) {
- ViewTreeNode* node = view_manager_->GetNodeById(node_id);
+ ViewTreeNode* node = view_manager()->GetNodeById(node_id);
ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(),
new_bounds.To<gfx::Rect>());
}
@@ -558,11 +590,11 @@ void ViewManagerSynchronizer::OnNodeHierarchyChanged(
// TODO: deal with |nodes|.
next_server_change_id_ = server_change_id + 1;
- BuildNodeTree(view_manager_, nodes);
+ BuildNodeTree(view_manager(), nodes);
- ViewTreeNode* new_parent = view_manager_->GetNodeById(new_parent_id);
- ViewTreeNode* old_parent = view_manager_->GetNodeById(old_parent_id);
- ViewTreeNode* node = view_manager_->GetNodeById(node_id);
+ ViewTreeNode* new_parent = view_manager()->GetNodeById(new_parent_id);
+ ViewTreeNode* old_parent = view_manager()->GetNodeById(old_parent_id);
+ ViewTreeNode* node = view_manager()->GetNodeById(node_id);
if (new_parent)
ViewTreeNodePrivate(new_parent).LocalAddChild(node);
else
@@ -573,7 +605,7 @@ void ViewManagerSynchronizer::OnNodeDeleted(uint32_t node_id,
uint32_t server_change_id) {
next_server_change_id_ = server_change_id + 1;
- ViewTreeNode* node = view_manager_->GetNodeById(node_id);
+ ViewTreeNode* node = view_manager()->GetNodeById(node_id);
if (node)
ViewTreeNodePrivate(node).LocalDestroy();
}
@@ -581,24 +613,24 @@ void ViewManagerSynchronizer::OnNodeDeleted(uint32_t node_id,
void ViewManagerSynchronizer::OnNodeViewReplaced(uint32_t node_id,
uint32_t new_view_id,
uint32_t old_view_id) {
- ViewTreeNode* node = view_manager_->GetNodeById(node_id);
- View* new_view = view_manager_->GetViewById(new_view_id);
+ ViewTreeNode* node = view_manager()->GetNodeById(node_id);
+ View* new_view = view_manager()->GetViewById(new_view_id);
if (!new_view && new_view_id != 0) {
// This client wasn't aware of this View until now.
new_view = ViewPrivate::LocalCreate();
ViewPrivate private_view(new_view);
- private_view.set_view_manager(view_manager_);
+ private_view.set_view_manager(view_manager());
private_view.set_id(new_view_id);
private_view.set_node(node);
- ViewManagerPrivate(view_manager_).AddView(new_view->id(), new_view);
+ ViewManagerPrivate(view_manager()).AddView(new_view->id(), new_view);
}
- View* old_view = view_manager_->GetViewById(old_view_id);
+ View* old_view = view_manager()->GetViewById(old_view_id);
DCHECK_EQ(old_view, node->active_view());
ViewTreeNodePrivate(node).LocalSetActiveView(new_view);
}
void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id) {
- View* view = view_manager_->GetViewById(view_id);
+ View* view = view_manager()->GetViewById(view_id);
if (view)
ViewPrivate(view).LocalDestroy();
}
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
index 8e286b1..887fef4 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
@@ -15,10 +15,6 @@
class SkBitmap;
-namespace base {
-class RunLoop;
-}
-
namespace mojo {
namespace view_manager {
@@ -26,7 +22,7 @@ class ViewManager;
class ViewManagerTransaction;
// Manages the connection with the View Manager service.
-class ViewManagerSynchronizer : public IViewManagerClient {
+class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
public:
explicit ViewManagerSynchronizer(ViewManager* view_manager);
virtual ~ViewManagerSynchronizer();
@@ -54,6 +50,8 @@ class ViewManagerSynchronizer : public IViewManagerClient {
void SetBounds(TransportNodeId node_id, const gfx::Rect& bounds);
void SetViewContents(TransportViewId view_id, const SkBitmap& contents);
+ void Embed(const String& url, TransportNodeId node_id);
+
void set_changes_acked_callback(const base::Callback<void(void)>& callback) {
changes_acked_callback_ = callback;
}
@@ -65,6 +63,9 @@ class ViewManagerSynchronizer : public IViewManagerClient {
friend class ViewManagerTransaction;
typedef ScopedVector<ViewManagerTransaction> Transactions;
+ // Overridden from InterfaceImpl:
+ virtual void OnConnectionEstablished() OVERRIDE;
+
// Overridden from IViewManagerClient:
virtual void OnViewManagerConnectionEstablished(
TransportConnectionId connection_id,
@@ -96,7 +97,9 @@ class ViewManagerSynchronizer : public IViewManagerClient {
// front of the queue.
void RemoveFromPendingQueue(ViewManagerTransaction* transaction);
- ViewManager* view_manager_;
+ ViewManager* view_manager() { return view_manager_.get(); }
+
+ scoped_ptr<ViewManager> view_manager_;
bool connected_;
TransportConnectionId connection_id_;
uint16_t next_id_;
@@ -106,13 +109,9 @@ class ViewManagerSynchronizer : public IViewManagerClient {
base::WeakPtrFactory<ViewManagerSynchronizer> sync_factory_;
- // Non-NULL while blocking on the connection to |service_| during
- // construction.
- base::RunLoop* init_loop_;
-
base::Callback<void(void)> changes_acked_callback_;
- IViewManagerPtr service_;
+ IViewManager* service_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer);
};
diff --git a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
index f4430c9..90bbb6c 100644
--- a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
+++ b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
@@ -258,8 +258,8 @@ class ViewManagerTest : public testing::Test {
ViewManagerTest() : commit_count_(0) {}
protected:
- ViewManager* view_manager_1() { return view_manager_1_.get(); }
- ViewManager* view_manager_2() { return view_manager_2_.get(); }
+ ViewManager* view_manager_1() { return view_manager_1_; }
+ ViewManager* view_manager_2() { return view_manager_2_; }
ViewTreeNode* CreateNodeInParent(ViewTreeNode* parent) {
ViewManager* parent_manager = ViewTreeNodePrivate(parent).view_manager();
@@ -269,23 +269,19 @@ class ViewManagerTest : public testing::Test {
}
void DestroyViewManager1() {
- view_manager_1_.reset();
+ // view_manager_1_.reset();
}
private:
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
test_helper_.Init();
- view_manager_1_.reset(new ViewManager(test_helper_.service_provider()));
- view_manager_2_.reset(new ViewManager(test_helper_.service_provider()));
- view_manager_1_->Init();
- view_manager_2_->Init();
}
base::MessageLoop loop_;
shell::ShellTestHelper test_helper_;
- scoped_ptr<ViewManager> view_manager_1_;
- scoped_ptr<ViewManager> view_manager_2_;
+ ViewManager* view_manager_1_;
+ ViewManager* view_manager_2_;
int commit_count_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
diff --git a/mojo/services/public/cpp/view_manager/view.h b/mojo/services/public/cpp/view_manager/view.h
index c4e61b8..c6724d4 100644
--- a/mojo/services/public/cpp/view_manager/view.h
+++ b/mojo/services/public/cpp/view_manager/view.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/observer_list.h"
#include "mojo/services/public/cpp/view_manager/view_manager_types.h"
+#include "third_party/skia/include/core/SkColor.h"
class SkBitmap;
@@ -31,7 +32,9 @@ class View {
void AddObserver(ViewObserver* observer);
void RemoveObserver(ViewObserver* observer);
+ // TODO(beng): temporary only.
void SetContents(const SkBitmap& contents);
+ void SetColor(SkColor color);
private:
friend class ViewPrivate;
diff --git a/mojo/services/public/cpp/view_manager/view_manager.h b/mojo/services/public/cpp/view_manager/view_manager.h
index 8380581..edfe2c1 100644
--- a/mojo/services/public/cpp/view_manager/view_manager.h
+++ b/mojo/services/public/cpp/view_manager/view_manager.h
@@ -13,7 +13,7 @@
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
namespace mojo {
-class ServiceProvider;
+class Application;
namespace view_manager {
class View;
@@ -21,17 +21,12 @@ class ViewManagerSynchronizer;
class ViewTreeNode;
// Approximately encapsulates the View Manager service.
-// Owns a synchronizer that keeps a client model in sync with the service.
-// Owned by the creator.
+// Has a synchronizer that keeps a client model in sync with the service.
+// Owned by the connection.
//
// TODO: displays
class ViewManager {
public:
- explicit ViewManager(ServiceProvider* service_provider);
- ~ViewManager();
-
- // Connects to the View Manager service. This method must be called before
- // using any other View Manager lib class or function.
// Blocks on establishing the connection and subsequently receiving a node
// tree from the service.
// TODO(beng): blocking is currently achieved by running a nested runloop,
@@ -39,20 +34,22 @@ class ViewManager {
// we should instead wait on the client pipe receiving a
// connection established message.
// TODO(beng): this method could optionally not block if supplied a callback.
- void Init();
+ explicit ViewManager(Application* application);
+ ~ViewManager();
ViewTreeNode* tree() { return tree_; }
ViewTreeNode* GetNodeById(TransportNodeId id);
View* GetViewById(TransportViewId id);
+ void Embed(const String& url, ViewTreeNode* node);
+
private:
friend class ViewManagerPrivate;
typedef std::map<TransportNodeId, ViewTreeNode*> IdToNodeMap;
typedef std::map<TransportViewId, View*> IdToViewMap;
- ServiceProvider* service_provider_;
- scoped_ptr<ViewManagerSynchronizer> synchronizer_;
+ ViewManagerSynchronizer* synchronizer_;
ViewTreeNode* tree_;
IdToNodeMap nodes_;