summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-23 16:43:43 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-23 16:43:43 +0000
commit6f9bc6eaec4053da0dc2727b297a4f9c9b897580 (patch)
tree3fe51d4d2e2f11833936c49a18da70440ed4231b
parentee544e1ac2f6aeae2213661169eed15c016d5b0a (diff)
downloadchromium_src-6f9bc6eaec4053da0dc2727b297a4f9c9b897580.zip
chromium_src-6f9bc6eaec4053da0dc2727b297a4f9c9b897580.tar.gz
chromium_src-6f9bc6eaec4053da0dc2727b297a4f9c9b897580.tar.bz2
Add EmbedRoot to ViewManagerService.
This means if you have an existing ViewManager connection you can just use that to ask the WM to embed a new node for you. Also fix the issue where only one call to EmbedRoot() could be made to the init service prior to the window tree host being ready. R=sky@chromium.org BUG=none Review URL: https://codereview.chromium.org/405163002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284952 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/examples/aura_demo/view_manager_init.cc6
-rw-r--r--mojo/examples/demo_launcher/demo_launcher.cc6
-rw-r--r--mojo/examples/window_manager/window_manager.cc2
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc4
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h2
-rw-r--r--mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc2
-rw-r--r--mojo/services/public/cpp/view_manager/window_manager_delegate.h2
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom8
-rw-r--r--mojo/services/view_manager/root_node_manager.cc2
-rw-r--r--mojo/services/view_manager/test_change_tracker.cc8
-rw-r--r--mojo/services/view_manager/test_change_tracker.h4
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.cc28
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.h13
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.cc5
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.h4
-rw-r--r--mojo/services/view_manager/view_manager_unittest.cc42
-rw-r--r--mojo/services/window_manager/window_manager_api_unittest.cc12
17 files changed, 87 insertions, 63 deletions
diff --git a/mojo/examples/aura_demo/view_manager_init.cc b/mojo/examples/aura_demo/view_manager_init.cc
index 4130193..d6414cb 100644
--- a/mojo/examples/aura_demo/view_manager_init.cc
+++ b/mojo/examples/aura_demo/view_manager_init.cc
@@ -20,9 +20,9 @@ class ViewManagerInit : public ApplicationDelegate {
virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
app->ConnectToService("mojo:mojo_view_manager", &view_manager_init_);
- view_manager_init_->EmbedRoot("mojo:mojo_aura_demo",
- base::Bind(&ViewManagerInit::DidConnect,
- base::Unretained(this)));
+ view_manager_init_->Embed("mojo:mojo_aura_demo",
+ base::Bind(&ViewManagerInit::DidConnect,
+ base::Unretained(this)));
}
private:
diff --git a/mojo/examples/demo_launcher/demo_launcher.cc b/mojo/examples/demo_launcher/demo_launcher.cc
index d6a3712..273e5ac 100644
--- a/mojo/examples/demo_launcher/demo_launcher.cc
+++ b/mojo/examples/demo_launcher/demo_launcher.cc
@@ -25,9 +25,9 @@ class DemoLauncher : public ApplicationDelegate {
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
MOJO_OVERRIDE {
- view_manager_init_->EmbedRoot("mojo:mojo_window_manager",
- base::Bind(&DemoLauncher::OnConnect,
- base::Unretained(this)));
+ view_manager_init_->Embed("mojo:mojo_window_manager",
+ base::Bind(&DemoLauncher::OnConnect,
+ base::Unretained(this)));
return true;
}
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 057c101..0b08a52 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -367,7 +367,7 @@ class WindowManager : public ApplicationDelegate,
}
// Overridden from WindowManagerDelegate:
- virtual void EmbedRoot(const String& url) OVERRIDE {
+ virtual void Embed(const String& url) OVERRIDE {
CreateWindow(url,
navigation::NavigationDetailsPtr().Pass(),
navigation::ResponseDetailsPtr().Pass());
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
index b881e6a..dbb5a5c 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
@@ -824,8 +824,8 @@ void ViewManagerClientImpl::OnFocusChanged(Id gained_focus_id,
}
}
-void ViewManagerClientImpl::EmbedRoot(const String& url) {
- window_manager_delegate_->EmbedRoot(url);
+void ViewManagerClientImpl::Embed(const String& url) {
+ window_manager_delegate_->Embed(url);
}
void ViewManagerClientImpl::DispatchOnViewInputEvent(Id view_id,
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
index 734f77f..6c14553 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
@@ -123,7 +123,7 @@ class ViewManagerClientImpl : public ViewManager,
EventPtr event,
const Callback<void()>& callback) OVERRIDE;
virtual void OnFocusChanged(Id gained_focus_id, Id lost_focus_id) OVERRIDE;
- virtual void EmbedRoot(const String& url) OVERRIDE;
+ virtual void Embed(const String& url) OVERRIDE;
virtual void DispatchOnViewInputEvent(Id view_id, EventPtr event) OVERRIDE;
// Sync the client model with the service by enumerating the pending
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 31d5618..1992239 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
@@ -376,7 +376,7 @@ class ViewManagerTest : public testing::Test {
bool EmbedRoot(ViewManagerInitService* view_manager_init,
const std::string& url) {
bool result = false;
- view_manager_init->EmbedRoot(
+ view_manager_init->Embed(
url,
base::Bind(&ViewManagerTest::EmbedRootCallback, base::Unretained(this),
&result));
diff --git a/mojo/services/public/cpp/view_manager/window_manager_delegate.h b/mojo/services/public/cpp/view_manager/window_manager_delegate.h
index e543280..bbf8feb 100644
--- a/mojo/services/public/cpp/view_manager/window_manager_delegate.h
+++ b/mojo/services/public/cpp/view_manager/window_manager_delegate.h
@@ -17,7 +17,7 @@ class View;
class WindowManagerDelegate {
public:
// Create an appropriate node to embed |url|.
- virtual void EmbedRoot(const String& url) = 0;
+ virtual void Embed(const String& url) = 0;
// Dispatch the supplied input event to the appropriate view (taking into
// account focus, activation, modality, etc.).
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 5edd9ce..a5d2739 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -33,7 +33,7 @@ interface ViewManagerInitService {
// application embedded at the service root Node. This application is
// typically referred to as the "window manager", and will have a specific
// definition of where within its Node hierarchy to embed an unparented URL.
- EmbedRoot(string url) => (bool success);
+ Embed(string url) => (bool success);
};
// Nodes and Views are identified by a uint32. The upper 16 bits are the
@@ -134,6 +134,10 @@ interface ViewManagerService {
// current connection. The current connection is told this by way of
// OnNodeDeleted().
//
+ // If |node_id| is 0, the View Manager delegates determination of what node to
+ // embed |url| at to the app embedded at the service root node (i.e. the
+ // window manager).
+ //
// This advances the server change id.
Embed(string url, uint32 node_id) => (bool success);
@@ -207,7 +211,7 @@ interface ViewManagerClient {
// once support for derived FIFOs is landed.
// Requests the window manager create a "top level" node embedding |url|.
- EmbedRoot(string url);
+ Embed(string url);
// Requests the view manager dispatch the event targeted at |view|.
DispatchOnViewInputEvent(uint32 view, mojo.Event event);
diff --git a/mojo/services/view_manager/root_node_manager.cc b/mojo/services/view_manager/root_node_manager.cc
index 317dad2..e25ae27 100644
--- a/mojo/services/view_manager/root_node_manager.cc
+++ b/mojo/services/view_manager/root_node_manager.cc
@@ -93,7 +93,7 @@ void RootNodeManager::EmbedRoot(const std::string& url) {
return;
}
ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection);
- connection->client()->EmbedRoot(url);
+ connection->client()->Embed(url);
}
void RootNodeManager::Embed(ConnectionSpecificId creator_id,
diff --git a/mojo/services/view_manager/test_change_tracker.cc b/mojo/services/view_manager/test_change_tracker.cc
index eba216b..baf4236 100644
--- a/mojo/services/view_manager/test_change_tracker.cc
+++ b/mojo/services/view_manager/test_change_tracker.cc
@@ -80,8 +80,8 @@ std::string ChangeToDescription1(const Change& change) {
"InputEvent view=%s event_action=%d",
NodeIdToString(change.view_id).c_str(),
change.event_action);
- case CHANGE_TYPE_EMBED_ROOT:
- return base::StringPrintf("EmbedRoot url=%s", change.embed_url.data());
+ case CHANGE_TYPE_EMBED:
+ return base::StringPrintf("Embed url=%s", change.embed_url.data());
}
return std::string();
}
@@ -225,9 +225,9 @@ void TestChangeTracker::OnViewInputEvent(Id view_id, EventPtr event) {
AddChange(change);
}
-void TestChangeTracker::OnEmbedRoot(const String& url) {
+void TestChangeTracker::OnEmbed(const String& url) {
Change change;
- change.type = CHANGE_TYPE_EMBED_ROOT;
+ change.type = CHANGE_TYPE_EMBED;
change.embed_url = url;
AddChange(change);
}
diff --git a/mojo/services/view_manager/test_change_tracker.h b/mojo/services/view_manager/test_change_tracker.h
index a1d5010..b122315 100644
--- a/mojo/services/view_manager/test_change_tracker.h
+++ b/mojo/services/view_manager/test_change_tracker.h
@@ -27,7 +27,7 @@ enum ChangeType {
CHANGE_TYPE_VIEW_DELETED,
CHANGE_TYPE_VIEW_REPLACED,
CHANGE_TYPE_INPUT_EVENT,
- CHANGE_TYPE_EMBED_ROOT,
+ CHANGE_TYPE_EMBED,
};
// TODO(sky): consider nuking and converting directly to NodeData.
@@ -113,7 +113,7 @@ class TestChangeTracker {
void OnViewDeleted(Id view_id);
void OnNodeViewReplaced(Id node_id, Id new_view_id, Id old_view_id);
void OnViewInputEvent(Id view_id, EventPtr event);
- void OnEmbedRoot(const String& url);
+ void OnEmbed(const String& url);
private:
void AddChange(const Change& change);
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 0a1c024..79cc6c4 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_init_service_impl.cc
@@ -31,32 +31,32 @@ ViewManagerInitServiceImpl::ViewManagerInitServiceImpl(
ViewManagerInitServiceImpl::~ViewManagerInitServiceImpl() {
}
-void ViewManagerInitServiceImpl::MaybeEmbedRoot(
- const std::string& url,
- const Callback<void(bool)>& callback) {
+void ViewManagerInitServiceImpl::MaybeEmbed() {
if (!is_tree_host_ready_)
return;
- root_node_manager_.EmbedRoot(url);
- callback.Run(true);
+ ScopedVector<ConnectParams>::const_iterator it = connect_params_.begin();
+ for (; it != connect_params_.end(); ++it) {
+ root_node_manager_.EmbedRoot((*it)->url);
+ (*it)->callback.Run(true);
+ }
+ connect_params_.clear();
}
-void ViewManagerInitServiceImpl::EmbedRoot(
+void ViewManagerInitServiceImpl::Embed(
const String& url,
const Callback<void(bool)>& callback) {
- // TODO(beng): This means you can only have one EmbedRoot in flight at a time.
- // Keep a vector of these around instead.
- connect_params_.reset(new ConnectParams);
- connect_params_->url = url.To<std::string>();
- connect_params_->callback = callback;
- MaybeEmbedRoot(url.To<std::string>(), callback);
+ ConnectParams* params = new ConnectParams;
+ params->url = url.To<std::string>();
+ params->callback = callback;
+ connect_params_.push_back(params);
+ MaybeEmbed();
}
void ViewManagerInitServiceImpl::OnRootViewManagerWindowTreeHostCreated() {
DCHECK(!is_tree_host_ready_);
is_tree_host_ready_ = true;
- if (connect_params_)
- MaybeEmbedRoot(connect_params_->url, connect_params_->callback);
+ MaybeEmbed();
}
void ViewManagerInitServiceImpl::OnNativeViewportDeleted() {
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 b9b5b3b..f659df9 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.h
+++ b/mojo/services/view_manager/view_manager_init_service_impl.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#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"
@@ -47,12 +48,11 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceImpl
Callback<void(bool)> callback;
};
- void MaybeEmbedRoot(const std::string& url,
- const Callback<void(bool)>& callback);
+ void MaybeEmbed();
// ViewManagerInitService overrides:
- virtual void EmbedRoot(const String& url,
- const Callback<void(bool)>& callback) OVERRIDE;
+ virtual void Embed(const String& url,
+ const Callback<void(bool)>& callback) OVERRIDE;
// RootViewManagerDelegate overrides:
virtual void OnRootViewManagerWindowTreeHostCreated() OVERRIDE;
@@ -63,8 +63,9 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceImpl
RootNodeManager root_node_manager_;
- // Parameters passed to Connect(). If non-null Connect() has been invoked.
- scoped_ptr<ConnectParams> connect_params_;
+ // Stores information about inbound calls to Embed() pending execution on
+ // the window tree host being ready to use.
+ ScopedVector<ConnectParams> connect_params_;
bool is_tree_host_ready_;
diff --git a/mojo/services/view_manager/view_manager_service_impl.cc b/mojo/services/view_manager/view_manager_service_impl.cc
index ee2c795..96cf102 100644
--- a/mojo/services/view_manager/view_manager_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_service_impl.cc
@@ -726,6 +726,11 @@ void ViewManagerServiceImpl::SetNodeVisibility(
void ViewManagerServiceImpl::Embed(const String& url,
Id transport_node_id,
const Callback<void(bool)>& callback) {
+ if (NodeIdFromTransportId(transport_node_id) == InvalidNodeId()) {
+ root_node_manager_->EmbedRoot(url);
+ callback.Run(true);
+ return;
+ }
bool success = CanEmbed(transport_node_id);
if (success) {
// Only allow a node to be the root for one connection.
diff --git a/mojo/services/view_manager/view_manager_service_impl.h b/mojo/services/view_manager/view_manager_service_impl.h
index 00b61cb..3c0eb71 100644
--- a/mojo/services/view_manager/view_manager_service_impl.h
+++ b/mojo/services/view_manager/view_manager_service_impl.h
@@ -205,9 +205,9 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
virtual void SetNodeVisibility(Id transport_node_id,
bool visible,
const Callback<void(bool)>& callback) OVERRIDE;
- virtual void Embed(const mojo::String& url,
+ virtual void Embed(const String& url,
Id transport_node_id,
- const mojo::Callback<void(bool)>& callback) OVERRIDE;
+ const Callback<void(bool)>& callback) OVERRIDE;
virtual void DispatchOnViewInputEvent(Id transport_view_id,
EventPtr event) OVERRIDE;
diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc
index 2590796..f0aa211 100644
--- a/mojo/services/view_manager/view_manager_unittest.cc
+++ b/mojo/services/view_manager/view_manager_unittest.cc
@@ -363,8 +363,8 @@ class TestViewManagerClientConnection
}
virtual void OnFocusChanged(Id gained_focus_id,
Id lost_focus_id) OVERRIDE {}
- virtual void EmbedRoot(const String& url) OVERRIDE {
- tracker_.OnEmbedRoot(url);
+ virtual void Embed(const String& url) OVERRIDE {
+ tracker_.OnEmbed(url);
}
virtual void DispatchOnViewInputEvent(Id view_id,
mojo::EventPtr event) OVERRIDE {
@@ -421,23 +421,24 @@ Id BuildViewId(ConnectionSpecificId connection_id,
return (connection_id << 16) | view_id;
}
-// Callback from EmbedRoot(). |result| is the result of the
+// Callback from Embed(). |result| is the result of the
// Embed() call and |run_loop| the nested RunLoop.
-void EmbedRootCallback(bool* result_cache,
- base::RunLoop* run_loop,
- bool result) {
+void EmbedCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
*result_cache = result;
run_loop->Quit();
}
-// Responsible for establishing the initial ViewManagerService connection.
+// Embed from an application that does not yet have a view manager connection.
// Blocks until result is determined.
-bool EmbedRoot(ViewManagerInitService* view_manager_init,
- const std::string& url) {
+bool InitEmbed(ViewManagerInitService* view_manager_init,
+ const std::string& url,
+ size_t number_of_calls) {
bool result = false;
base::RunLoop run_loop;
- view_manager_init->EmbedRoot(url, base::Bind(&EmbedRootCallback,
- &result, &run_loop));
+ for (size_t i = 0; i < number_of_calls; ++i) {
+ view_manager_init->Embed(url, base::Bind(&EmbedCallback,
+ &result, &run_loop));
+ }
run_loop.Run();
return result;
}
@@ -464,7 +465,7 @@ class ViewManagerTest : public testing::Test {
test_helper_.service_manager()->ConnectToService(
GURL("mojo:mojo_view_manager"),
&view_manager_init_);
- ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL));
+ ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
connection_ = ViewManagerProxy::WaitForInstance();
ASSERT_TRUE(connection_ != NULL);
@@ -520,12 +521,25 @@ class ViewManagerTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
};
-TEST_F(ViewManagerTest, SecondEmbedRoot) {
- ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL));
+TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) {
+ ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
+ connection_->DoRunLoopUntilChangesCount(1);
+ EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
+}
+
+TEST_F(ViewManagerTest, SecondEmbedRoot_Service) {
+ ASSERT_TRUE(connection_->Embed(BuildNodeId(0, 0), kTestServiceURL));
connection_->DoRunLoopUntilChangesCount(1);
EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
}
+TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) {
+ ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 2));
+ connection_->DoRunLoopUntilChangesCount(2);
+ EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
+ EXPECT_EQ(kTestServiceURL, connection_->changes()[1].embed_url);
+}
+
// Verifies client gets a valid id.
TEST_F(ViewManagerTest, ValidId) {
// TODO(beng): this should really have the URL of the application that
diff --git a/mojo/services/window_manager/window_manager_api_unittest.cc b/mojo/services/window_manager/window_manager_api_unittest.cc
index 387b8af..7f81819b 100644
--- a/mojo/services/window_manager/window_manager_api_unittest.cc
+++ b/mojo/services/window_manager/window_manager_api_unittest.cc
@@ -23,8 +23,8 @@ const char kTestServiceURL[] = "mojo:test_url";
void EmptyResultCallback(bool result) {}
-// Callback from EmbedRoot(). |result| is the result of the
-// Embed() call and |run_loop| the nested RunLoop.
+// Callback from Embed(). |result| is the result of the Embed() call and
+// |run_loop| the nested RunLoop.
void ResultCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
*result_cache = result;
run_loop->Quit();
@@ -32,12 +32,12 @@ void ResultCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
// Responsible for establishing the initial ViewManagerService connection.
// Blocks until result is determined.
-bool EmbedRoot(view_manager::ViewManagerInitService* view_manager_init,
+bool InitEmbed(view_manager::ViewManagerInitService* view_manager_init,
const std::string& url) {
bool result = false;
base::RunLoop run_loop;
- view_manager_init->EmbedRoot(url,
- base::Bind(&ResultCallback, &result, &run_loop));
+ view_manager_init->Embed(url,
+ base::Bind(&ResultCallback, &result, &run_loop));
run_loop.Run();
return result;
}
@@ -217,7 +217,7 @@ class WindowManagerApiTest : public testing::Test {
test_helper_.service_manager()->ConnectToService(
GURL("mojo:mojo_view_manager"),
&view_manager_init_);
- ASSERT_TRUE(EmbedRoot(view_manager_init_.get(),
+ ASSERT_TRUE(InitEmbed(view_manager_init_.get(),
"mojo:mojo_core_window_manager"));
ConnectToWindowManager();
}