summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-29 04:11:39 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-29 04:11:39 +0000
commit2992d10e5d9b13cf4a275b6eb9f1fddc71c383f5 (patch)
tree7967d540b3b61f94396f7c9c5f7d340fe0ecbc49
parent645c474490f7069300e935e5bc7fecca67049465 (diff)
downloadchromium_src-2992d10e5d9b13cf4a275b6eb9f1fddc71c383f5.zip
chromium_src-2992d10e5d9b13cf4a275b6eb9f1fddc71c383f5.tar.gz
chromium_src-2992d10e5d9b13cf4a275b6eb9f1fddc71c383f5.tar.bz2
Replace OnViewManagerConnectionEstablished and OnRootAdded with a single OnEmbed call
R=sky@chromium.org BUG= Review URL: https://codereview.chromium.org/418223011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286080 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/examples/aura_demo/aura_demo.cc2
-rw-r--r--mojo/examples/browser/browser.cc4
-rw-r--r--mojo/examples/embedded_app/embedded_app.cc2
-rw-r--r--mojo/examples/keyboard/keyboard.cc4
-rw-r--r--mojo/examples/media_viewer/media_viewer.cc2
-rw-r--r--mojo/examples/nesting_app/nesting_app.cc2
-rw-r--r--mojo/examples/png_viewer/png_viewer.cc2
-rw-r--r--mojo/examples/window_manager/window_manager.cc2
-rw-r--r--mojo/examples/wm_flow/app/app.cc4
-rw-r--r--mojo/examples/wm_flow/wm/wm.cc5
-rw-r--r--mojo/services/html_viewer/html_viewer.cc4
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc27
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h8
-rw-r--r--mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc3
-rw-r--r--mojo/services/public/cpp/view_manager/view_manager.h4
-rw-r--r--mojo/services/public/cpp/view_manager/view_manager_delegate.h14
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom14
-rw-r--r--mojo/services/view_manager/test_change_tracker.cc53
-rw-r--r--mojo/services/view_manager/test_change_tracker.h14
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.cc47
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.h7
-rw-r--r--mojo/services/view_manager/view_manager_unittest.cc30
-rw-r--r--mojo/services/window_manager/window_manager_api_unittest.cc3
-rw-r--r--mojo/services/window_manager/window_manager_app.cc5
-rw-r--r--mojo/services/window_manager/window_manager_app.h3
25 files changed, 127 insertions, 138 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
index c4c9b93..636b78a 100644
--- a/mojo/examples/aura_demo/aura_demo.cc
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -119,7 +119,7 @@ class AuraDemo : public ApplicationDelegate,
private:
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
// TODO(beng): this function could be called multiple times!
view_ = View::Create(view_manager);
root->SetActiveView(view_);
diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc
index 719f8f2..fb2a308 100644
--- a/mojo/examples/browser/browser.cc
+++ b/mojo/examples/browser/browser.cc
@@ -203,8 +203,8 @@ class Browser : public ApplicationDelegate,
}
// ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
- // TODO: deal with OnRootAdded() being invoked multiple times.
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
+ // TODO: deal with OnEmbed() being invoked multiple times.
view_manager_ = view_manager;
root_ = root;
root_->AddObserver(this);
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
index 8e0afb6..8a71171 100644
--- a/mojo/examples/embedded_app/embedded_app.cc
+++ b/mojo/examples/embedded_app/embedded_app.cc
@@ -79,7 +79,7 @@ class EmbeddedApp
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
View* view = View::Create(view_manager);
view->AddObserver(this);
root->SetActiveView(view);
diff --git a/mojo/examples/keyboard/keyboard.cc b/mojo/examples/keyboard/keyboard.cc
index 13eb4c7..990e2b2 100644
--- a/mojo/examples/keyboard/keyboard.cc
+++ b/mojo/examples/keyboard/keyboard.cc
@@ -93,8 +93,8 @@ class Keyboard
}
// ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
- // TODO: deal with OnRootAdded() being invoked multiple times.
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
+ // TODO: deal with OnEmbed() being invoked multiple times.
view_manager_ = view_manager;
root->SetActiveView(View::Create(view_manager));
CreateWidget(root);
diff --git a/mojo/examples/media_viewer/media_viewer.cc b/mojo/examples/media_viewer/media_viewer.cc
index 706275f..908c444 100644
--- a/mojo/examples/media_viewer/media_viewer.cc
+++ b/mojo/examples/media_viewer/media_viewer.cc
@@ -292,7 +292,7 @@ class MediaViewer
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
root_node_ = root;
view_manager_ = view_manager;
diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
index 3b8c324..0d22d62 100644
--- a/mojo/examples/nesting_app/nesting_app.cc
+++ b/mojo/examples/nesting_app/nesting_app.cc
@@ -88,7 +88,7 @@ class NestingApp
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
root->AddObserver(this);
View* view = View::Create(view_manager);
diff --git a/mojo/examples/png_viewer/png_viewer.cc b/mojo/examples/png_viewer/png_viewer.cc
index 2d16aeb..e461b4b 100644
--- a/mojo/examples/png_viewer/png_viewer.cc
+++ b/mojo/examples/png_viewer/png_viewer.cc
@@ -173,7 +173,7 @@ class PNGViewer
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
root_ = root;
root_->AddObserver(this);
content_view_ = View::Create(view_manager);
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index e89f2b8..1f0a4e0 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -341,7 +341,7 @@ class WindowManager
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
DCHECK(!view_manager_);
view_manager_ = view_manager;
view_manager_->SetWindowManagerDelegate(this);
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc
index 13fac63..075f98a 100644
--- a/mojo/examples/wm_flow/app/app.cc
+++ b/mojo/examples/wm_flow/app/app.cc
@@ -49,8 +49,8 @@ class WMFlowApp : public mojo::ApplicationDelegate,
void OnConnect(bool success) {}
// Overridden from mojo::ViewManagerDelegate:
- virtual void OnRootAdded(mojo::ViewManager* view_manager,
- mojo::Node* root) MOJO_OVERRIDE {
+ virtual void OnEmbed(mojo::ViewManager* view_manager,
+ mojo::Node* root) MOJO_OVERRIDE {
mojo::View* view =
mojo::View::Create(view_manager);
root->SetActiveView(view);
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
index 6d98b6d..eb2708a 100644
--- a/mojo/examples/wm_flow/wm/wm.cc
+++ b/mojo/examples/wm_flow/wm/wm.cc
@@ -34,9 +34,8 @@ class SimpleWM : public mojo::ApplicationDelegate,
}
// Overridden from mojo::ViewManagerDelegate:
- virtual void OnRootAdded(
- mojo::ViewManager* view_manager,
- mojo::Node* root) MOJO_OVERRIDE {
+ virtual void OnEmbed(mojo::ViewManager* view_manager,
+ mojo::Node* root) MOJO_OVERRIDE {
view_manager_ = view_manager;
root_ = root;
view_manager_->SetWindowManagerDelegate(this);
diff --git a/mojo/services/html_viewer/html_viewer.cc b/mojo/services/html_viewer/html_viewer.cc
index 005f73c..7f9390f 100644
--- a/mojo/services/html_viewer/html_viewer.cc
+++ b/mojo/services/html_viewer/html_viewer.cc
@@ -54,7 +54,7 @@ class HTMLViewer
}
void Load(URLResponsePtr response) {
- // Need to wait for OnRootAdded.
+ // Need to wait for OnEmbed.
response_ = response.Pass();
MaybeLoad();
}
@@ -75,7 +75,7 @@ class HTMLViewer
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
document_view_ = new HTMLDocumentView(
application_impl_->ConnectToApplication("mojo://mojo_window_manager/")->
GetServiceProvider(),
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 879dc3a..f76b0be 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
@@ -330,18 +330,19 @@ void ViewManagerClientImpl::OnConnectionEstablished() {
////////////////////////////////////////////////////////////////////////////////
// ViewManagerClientImpl, ViewManagerClient implementation:
-void ViewManagerClientImpl::OnViewManagerConnectionEstablished(
- ConnectionSpecificId connection_id,
- const String& creator_url,
- Array<NodeDataPtr> nodes) {
- connected_ = true;
- connection_id_ = connection_id;
- creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url);
- AddRoot(BuildNodeTree(this, nodes, NULL));
-}
-
-void ViewManagerClientImpl::OnRootAdded(Array<NodeDataPtr> nodes) {
- AddRoot(BuildNodeTree(this, nodes, NULL));
+void ViewManagerClientImpl::OnEmbed(ConnectionSpecificId connection_id,
+ const String& creator_url,
+ NodeDataPtr root) {
+ if (!connected_) {
+ connected_ = true;
+ connection_id_ = connection_id;
+ creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url);
+ } else {
+ DCHECK_EQ(connection_id_, connection_id);
+ DCHECK_EQ(creator_url_, creator_url);
+ }
+ AddRoot(AddNodeToViewManager(this, NULL, root->node_id, root->view_id,
+ root->bounds.To<gfx::Rect>()));
}
void ViewManagerClientImpl::OnNodeBoundsChanged(Id node_id,
@@ -462,7 +463,7 @@ void ViewManagerClientImpl::AddRoot(Node* root) {
}
roots_.push_back(root);
root->AddObserver(new RootObserver(root));
- delegate_->OnRootAdded(this, root);
+ delegate_->OnEmbed(this, root);
}
void ViewManagerClientImpl::RemoveRoot(Node* root) {
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 51aec4c..c9d81d5 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
@@ -95,11 +95,9 @@ class ViewManagerClientImpl : public ViewManager,
virtual void OnConnectionEstablished() OVERRIDE;
// Overridden from ViewManagerClient:
- virtual void OnViewManagerConnectionEstablished(
- ConnectionSpecificId connection_id,
- const String& creator_url,
- Array<NodeDataPtr> nodes) OVERRIDE;
- virtual void OnRootAdded(Array<NodeDataPtr> nodes) OVERRIDE;
+ virtual void OnEmbed(ConnectionSpecificId connection_id,
+ const String& creator_url,
+ NodeDataPtr root) OVERRIDE;
virtual void OnNodeBoundsChanged(Id node_id,
RectPtr old_bounds,
RectPtr new_bounds) OVERRIDE;
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 86b7f68..5351b0e 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
@@ -72,8 +72,7 @@ class ConnectServiceLoader : public ServiceLoader,
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager,
- Node* root) OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE {
callback_.Run(view_manager, root);
}
virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {}
diff --git a/mojo/services/public/cpp/view_manager/view_manager.h b/mojo/services/public/cpp/view_manager/view_manager.h
index b520d07..163f5fe 100644
--- a/mojo/services/public/cpp/view_manager/view_manager.h
+++ b/mojo/services/public/cpp/view_manager/view_manager.h
@@ -18,6 +18,10 @@ class View;
class ViewManagerDelegate;
class WindowManagerDelegate;
+// Encapsulates a connection to the view manager service.
+// A unique connection is made for every unique embed path for an app. e.g. for
+// app B embed by the following paths: A->B, A->C->B - there are two connections
+// and thus two instances of this class.
class ViewManager {
public:
// Sets the window manager delegate. Can only be called by the app embedded at
diff --git a/mojo/services/public/cpp/view_manager/view_manager_delegate.h b/mojo/services/public/cpp/view_manager/view_manager_delegate.h
index c05c24c..3b9d073 100644
--- a/mojo/services/public/cpp/view_manager/view_manager_delegate.h
+++ b/mojo/services/public/cpp/view_manager/view_manager_delegate.h
@@ -10,9 +10,21 @@ namespace mojo {
class Node;
class ViewManager;
+// Interface implemented by an application using the view manager.
class ViewManagerDelegate {
public:
- virtual void OnRootAdded(ViewManager* view_manager, Node* root) = 0;
+ // Called when the application implementing this interface is embedded at
+ // |root|. |view_manager| is an implementation of an object bound to a
+ // connection to the view manager service. The object is valid until
+ // OnViewManagerDisconnected() is called with the same object.
+ // This function is called for every embed, but there will be a unique
+ // instance of |view_manager| only for every unique connection. See
+ // the class description of ViewManager for some rules about when a new
+ // connection is made.
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) = 0;
+
+ // Called when a connection to the view manager service is closed.
+ // |view_manager| is not valid after this function returns.
virtual void OnViewManagerDisconnected(ViewManager* view_manager) = 0;
protected:
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 19e8820..81bb028 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -127,7 +127,7 @@ interface ViewManagerService {
//
// If a particular client invokes Embed() multiple times with the same url,
// the connection is reused. When this happens the ViewManagerClient is
- // notified of the additional roots by way of OnRootAdded().
+ // notified of the additional roots by way of OnEmbed().
//
// A node may only be a root of one connection at a time. Subsequent calls to
// Embed() for the same node result in the node being removed from the
@@ -155,16 +155,8 @@ interface ViewManagerService {
// connection 1 does not receive OnNodeViewReplaced().
[Client=ViewManagerService]
interface ViewManagerClient {
- // Invoked once the connection has been established. |connection_id| is the id
- // that uniquely identifies this connection. |nodes| are the nodes parented to
- // the root.
- OnViewManagerConnectionEstablished(uint16 connection_id,
- string creator_url,
- NodeData[] nodes);
-
- // See description of ViewManagerService::Embed() for details as to when
- // this is invoked.
- OnRootAdded(NodeData[] nodes);
+ // Invoked when the client application has been embedded at |root|.
+ OnEmbed(uint16 connection_id, string embedder_url, NodeData root);
// Invoked when a node's bounds have changed.
OnNodeBoundsChanged(uint32 node, mojo.Rect old_bounds, mojo.Rect new_bounds);
diff --git a/mojo/services/view_manager/test_change_tracker.cc b/mojo/services/view_manager/test_change_tracker.cc
index 6bba79c..9c8ee42 100644
--- a/mojo/services/view_manager/test_change_tracker.cc
+++ b/mojo/services/view_manager/test_change_tracker.cc
@@ -31,13 +31,10 @@ std::string DirectionToString(OrderDirection direction) {
std::string ChangeToDescription1(const Change& change) {
switch (change.type) {
- case CHANGE_TYPE_CONNECTION_ESTABLISHED:
- return base::StringPrintf("OnConnectionEstablished creator=%s",
+ case CHANGE_TYPE_EMBED:
+ return base::StringPrintf("OnEmbed creator=%s",
change.creator_url.data());
- case CHANGE_TYPE_ROOTS_ADDED:
- return "OnRootAdded";
-
case CHANGE_TYPE_NODE_BOUNDS_CHANGED:
return base::StringPrintf(
"BoundsChanged node=%s old_bounds=%s new_bounds=%s",
@@ -79,8 +76,9 @@ 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:
- return base::StringPrintf("Embed url=%s", change.embed_url.data());
+ case CHANGE_TYPE_DELEGATE_EMBED:
+ return base::StringPrintf("DelegateEmbed url=%s",
+ change.embed_url.data());
}
return std::string();
}
@@ -104,19 +102,22 @@ std::string ChangeNodeDescription(const std::vector<Change>& changes) {
return JoinString(node_strings, ',');
}
+TestNode NodeDataToTestNode(const NodeDataPtr& data) {
+ TestNode node;
+ node.parent_id = data->parent_id;
+ node.node_id = data->node_id;
+ node.view_id = data->view_id;
+ return node;
+}
+
void NodeDatasToTestNodes(const Array<NodeDataPtr>& data,
std::vector<TestNode>* test_nodes) {
- for (size_t i = 0; i < data.size(); ++i) {
- TestNode node;
- node.parent_id = data[i]->parent_id;
- node.node_id = data[i]->node_id;
- node.view_id = data[i]->view_id;
- test_nodes->push_back(node);
- }
+ for (size_t i = 0; i < data.size(); ++i)
+ test_nodes->push_back(NodeDataToTestNode(data[i]));
}
Change::Change()
- : type(CHANGE_TYPE_CONNECTION_ESTABLISHED),
+ : type(CHANGE_TYPE_EMBED),
connection_id(0),
node_id(0),
node_id2(0),
@@ -137,22 +138,14 @@ TestChangeTracker::TestChangeTracker()
TestChangeTracker::~TestChangeTracker() {
}
-void TestChangeTracker::OnViewManagerConnectionEstablished(
- ConnectionSpecificId connection_id,
- const String& creator_url,
- Array<NodeDataPtr> nodes) {
+void TestChangeTracker::OnEmbed(ConnectionSpecificId connection_id,
+ const String& creator_url,
+ NodeDataPtr root) {
Change change;
- change.type = CHANGE_TYPE_CONNECTION_ESTABLISHED;
+ change.type = CHANGE_TYPE_EMBED;
change.connection_id = connection_id;
change.creator_url = creator_url;
- NodeDatasToTestNodes(nodes, &change.nodes);
- AddChange(change);
-}
-
-void TestChangeTracker::OnRootAdded(Array<NodeDataPtr> nodes) {
- Change change;
- change.type = CHANGE_TYPE_ROOTS_ADDED;
- NodeDatasToTestNodes(nodes, &change.nodes);
+ change.nodes.push_back(NodeDataToTestNode(root));
AddChange(change);
}
@@ -224,9 +217,9 @@ void TestChangeTracker::OnViewInputEvent(Id view_id, EventPtr event) {
AddChange(change);
}
-void TestChangeTracker::OnEmbed(const String& url) {
+void TestChangeTracker::DelegateEmbed(const String& url) {
Change change;
- change.type = CHANGE_TYPE_EMBED;
+ change.type = CHANGE_TYPE_DELEGATE_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 01a8572..3454dcc 100644
--- a/mojo/services/view_manager/test_change_tracker.h
+++ b/mojo/services/view_manager/test_change_tracker.h
@@ -17,8 +17,7 @@ namespace mojo {
namespace service {
enum ChangeType {
- CHANGE_TYPE_CONNECTION_ESTABLISHED,
- CHANGE_TYPE_ROOTS_ADDED,
+ CHANGE_TYPE_EMBED,
CHANGE_TYPE_NODE_BOUNDS_CHANGED,
CHANGE_TYPE_NODE_HIERARCHY_CHANGED,
CHANGE_TYPE_NODE_REORDERED,
@@ -26,7 +25,7 @@ enum ChangeType {
CHANGE_TYPE_VIEW_DELETED,
CHANGE_TYPE_VIEW_REPLACED,
CHANGE_TYPE_INPUT_EVENT,
- CHANGE_TYPE_EMBED,
+ CHANGE_TYPE_DELEGATE_EMBED,
};
// TODO(sky): consider nuking and converting directly to NodeData.
@@ -96,10 +95,9 @@ class TestChangeTracker {
// Each of these functions generate a Change. There is one per
// ViewManagerClient function.
- void OnViewManagerConnectionEstablished(ConnectionSpecificId connection_id,
- const String& creator_url,
- Array<NodeDataPtr> nodes);
- void OnRootAdded(Array<NodeDataPtr> nodes);
+ void OnEmbed(ConnectionSpecificId connection_id,
+ const String& creator_url,
+ NodeDataPtr root);
void OnNodeBoundsChanged(Id node_id, RectPtr old_bounds, RectPtr new_bounds);
void OnNodeHierarchyChanged(Id node_id,
Id new_parent_id,
@@ -112,7 +110,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 OnEmbed(const String& url);
+ void DelegateEmbed(const String& url);
private:
void AddChange(const Change& change);
diff --git a/mojo/services/view_manager/view_manager_service_impl.cc b/mojo/services/view_manager/view_manager_service_impl.cc
index 5ef7e09..e2de0b01 100644
--- a/mojo/services/view_manager/view_manager_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_service_impl.cc
@@ -293,11 +293,11 @@ void ViewManagerServiceImpl::AddRoot(const NodeId& node_id) {
const Id transport_node_id(NodeIdToTransportId(node_id));
CHECK(roots_.count(transport_node_id) == 0);
- std::vector<const Node*> to_send;
CHECK_EQ(creator_id_, node_id.connection_id);
roots_.insert(transport_node_id);
- Node* node = GetNode(node_id);
+ const Node* node = GetNode(node_id);
CHECK(node);
+ std::vector<const Node*> to_send;
if (!IsNodeKnown(node)) {
GetUnknownNodesFrom(node, &to_send);
} else {
@@ -306,7 +306,7 @@ void ViewManagerServiceImpl::AddRoot(const NodeId& node_id) {
to_send.push_back(node);
}
- client()->OnRootAdded(NodesToNodeDatas(to_send));
+ client()->OnEmbed(id_, creator_url_, NodeToNodeData(to_send.front()));
root_node_manager_->OnConnectionMessagedClient(id_);
}
@@ -344,26 +344,28 @@ void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed(
Array<NodeDataPtr> ViewManagerServiceImpl::NodesToNodeDatas(
const std::vector<const Node*>& nodes) {
Array<NodeDataPtr> array(nodes.size());
- for (size_t i = 0; i < nodes.size(); ++i) {
- const Node* node = nodes[i];
- DCHECK(IsNodeKnown(node));
- const Node* parent = node->GetParent();
- // If the parent isn't known, it means the parent is not visible to us (not
- // in roots), and should not be sent over.
- if (parent && !IsNodeKnown(parent))
- parent = NULL;
- NodeDataPtr inode(NodeData::New());
- inode->parent_id = NodeIdToTransportId(parent ? parent->id() : NodeId());
- inode->node_id = NodeIdToTransportId(node->id());
- // TODO(sky): should the id only be sent if known?
- inode->view_id =
- ViewIdToTransportId(node->view() ? node->view()->id() : ViewId());
- inode->bounds = Rect::From(node->bounds());
- array[i] = inode.Pass();
- }
+ for (size_t i = 0; i < nodes.size(); ++i)
+ array[i] = NodeToNodeData(nodes[i]).Pass();
return array.Pass();
}
+NodeDataPtr ViewManagerServiceImpl::NodeToNodeData(const Node* node) {
+ DCHECK(IsNodeKnown(node));
+ const Node* parent = node->GetParent();
+ // If the parent isn't known, it means the parent is not visible to us (not
+ // in roots), and should not be sent over.
+ if (parent && !IsNodeKnown(parent))
+ parent = NULL;
+ NodeDataPtr node_data(NodeData::New());
+ node_data->parent_id = NodeIdToTransportId(parent ? parent->id() : NodeId());
+ node_data->node_id = NodeIdToTransportId(node->id());
+ // TODO(sky): should the id only be sent if known?
+ node_data->view_id =
+ ViewIdToTransportId(node->view() ? node->view()->id() : ViewId());
+ node_data->bounds = Rect::From(node->bounds());
+ return node_data.Pass();
+}
+
void ViewManagerServiceImpl::GetNodeTreeImpl(
const Node* node,
std::vector<const Node*>* nodes) const {
@@ -631,10 +633,7 @@ void ViewManagerServiceImpl::OnConnectionEstablished() {
for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i)
GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send);
- client()->OnViewManagerConnectionEstablished(
- id_,
- creator_url_,
- NodesToNodeDatas(to_send));
+ client()->OnEmbed(id_, creator_url_, NodeToNodeData(to_send.front()));
}
const base::hash_set<Id>&
diff --git a/mojo/services/view_manager/view_manager_service_impl.h b/mojo/services/view_manager/view_manager_service_impl.h
index 4ea21a9..9806fbf 100644
--- a/mojo/services/view_manager/view_manager_service_impl.h
+++ b/mojo/services/view_manager/view_manager_service_impl.h
@@ -149,10 +149,11 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
void RemoveChildrenAsPartOfEmbed(const NodeId& node_id);
- // Converts an array of Nodes to NodeDatas. This assumes all the nodes are
- // valid for the client. The parent of nodes the client is not allowed to see
- // are set to NULL (in the returned NodeDatas).
+ // Converts Node(s) to NodeData(s) for transport. This assumes all the nodes
+ // are valid for the client. The parent of nodes the client is not allowed to
+ // see are set to NULL (in the returned NodeData(s)).
Array<NodeDataPtr> NodesToNodeDatas(const std::vector<const Node*>& nodes);
+ NodeDataPtr NodeToNodeData(const Node* node);
// Implementation of GetNodeTree(). Adds |node| to |nodes| and recurses if
// CanDescendIntoNodeForNodeTree() returns true.
diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc
index 8c0a0c4..3b4968d 100644
--- a/mojo/services/view_manager/view_manager_unittest.cc
+++ b/mojo/services/view_manager/view_manager_unittest.cc
@@ -310,22 +310,17 @@ class TestViewManagerClientConnection
tracker_.set_delegate(&connection_);
}
- // InterfaceImp:
+ // InterfaceImpl:
virtual void OnConnectionEstablished() OVERRIDE {
connection_.set_router(internal_state()->router());
connection_.set_view_manager(client());
}
// ViewManagerClient:
- virtual void OnViewManagerConnectionEstablished(
- ConnectionSpecificId connection_id,
- const String& creator_url,
- Array<NodeDataPtr> nodes) OVERRIDE {
- tracker_.OnViewManagerConnectionEstablished(
- connection_id, creator_url, nodes.Pass());
- }
- virtual void OnRootAdded(Array<NodeDataPtr> nodes) OVERRIDE {
- tracker_.OnRootAdded(nodes.Pass());
+ virtual void OnEmbed(ConnectionSpecificId connection_id,
+ const String& creator_url,
+ NodeDataPtr root) OVERRIDE {
+ tracker_.OnEmbed(connection_id, creator_url, root.Pass());
}
virtual void OnNodeBoundsChanged(Id node_id,
RectPtr old_bounds,
@@ -362,7 +357,7 @@ class TestViewManagerClientConnection
virtual void OnFocusChanged(Id gained_focus_id,
Id lost_focus_id) OVERRIDE {}
virtual void Embed(const String& url) OVERRIDE {
- tracker_.OnEmbed(url);
+ tracker_.DelegateEmbed(url);
}
virtual void DispatchOnViewInputEvent(Id view_id,
mojo::EventPtr event) OVERRIDE {
@@ -507,7 +502,7 @@ class ViewManagerTest : public testing::Test {
EstablishSecondConnectionWithRoot(BuildNodeId(1, 1)));
const std::vector<Change>& changes(connection2_->changes());
ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url",
+ EXPECT_EQ("OnEmbed creator=mojo:test_url",
ChangesToDescription1(changes)[0]);
if (create_initial_node) {
EXPECT_EQ("[node=1,1 parent=null view=null]",
@@ -522,7 +517,7 @@ class ViewManagerTest : public testing::Test {
ASSERT_TRUE(connection3_ != NULL);
connection3_->DoRunLoopUntilChangesCount(1);
ASSERT_EQ(1u, connection3_->changes().size());
- EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url",
+ EXPECT_EQ("OnEmbed creator=mojo:test_url",
ChangesToDescription1(connection3_->changes())[0]);
}
@@ -568,7 +563,7 @@ TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) {
TEST_F(ViewManagerTest, ValidId) {
// TODO(beng): this should really have the URL of the application that
// connected to ViewManagerInit.
- EXPECT_EQ("OnConnectionEstablished creator=",
+ EXPECT_EQ("OnEmbed creator=",
ChangesToDescription1(connection_->changes())[0]);
// All these tests assume 1 for the client id. The only real assertion here is
@@ -579,7 +574,7 @@ TEST_F(ViewManagerTest, ValidId) {
// Verifies two clients/connections get different ids.
TEST_F(ViewManagerTest, TwoClientsGetDifferentConnectionIds) {
ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
- EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url",
+ EXPECT_EQ("OnEmbed creator=mojo:test_url",
ChangesToDescription1(connection2_->changes())[0]);
// It isn't strictly necessary that the second connection gets 2, but these
@@ -1340,7 +1335,7 @@ TEST_F(ViewManagerTest, ConnectTwice) {
connection2_->DoRunLoopUntilChangesCount(1);
const Changes changes(ChangesToDescription1(connection2_->changes()));
ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("OnRootAdded", changes[0]);
+ EXPECT_EQ("OnEmbed creator=mojo:test_url", changes[0]);
EXPECT_EQ("[node=1,2 parent=null view=null]",
ChangeNodeDescription(connection2_->changes()));
}
@@ -1419,7 +1414,8 @@ TEST_F(ViewManagerTest, EmbedWithSameNodeId2) {
connection2_->DoRunLoopUntilChangesCount(1);
const std::vector<Change>& changes(connection2_->changes());
ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("OnRootAdded", ChangesToDescription1(changes)[0]);
+ EXPECT_EQ("OnEmbed creator=mojo:test_url",
+ ChangesToDescription1(changes)[0]);
EXPECT_EQ("[node=1,1 parent=null view=null]",
ChangeNodeDescription(changes));
diff --git a/mojo/services/window_manager/window_manager_api_unittest.cc b/mojo/services/window_manager/window_manager_api_unittest.cc
index 9f31fe9..b6048b9 100644
--- a/mojo/services/window_manager/window_manager_api_unittest.cc
+++ b/mojo/services/window_manager/window_manager_api_unittest.cc
@@ -147,8 +147,7 @@ class TestServiceLoader : public ServiceLoader,
}
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager,
- Node* root) MOJO_OVERRIDE {
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) MOJO_OVERRIDE {
root_added_callback_.Run(root);
}
virtual void OnViewManagerDisconnected(
diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc
index cddc33f..6afe720 100644
--- a/mojo/services/window_manager/window_manager_app.cc
+++ b/mojo/services/window_manager/window_manager_app.cc
@@ -150,8 +150,7 @@ bool WindowManagerApp::ConfigureIncomingConnection(
////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, ViewManagerDelegate implementation:
-void WindowManagerApp::OnRootAdded(ViewManager* view_manager,
- Node* root) {
+void WindowManagerApp::OnEmbed(ViewManager* view_manager, Node* root) {
DCHECK(!view_manager_ && !root_);
view_manager_ = view_manager;
root_ = root;
@@ -172,7 +171,7 @@ void WindowManagerApp::OnRootAdded(ViewManager* view_manager,
activation_client_->AddObserver(this);
if (wrapped_delegate_)
- wrapped_delegate_->OnRootAdded(view_manager, root);
+ wrapped_delegate_->OnEmbed(view_manager, root);
for (Connections::const_iterator it = connections_.begin();
it != connections_.end(); ++it) {
diff --git a/mojo/services/window_manager/window_manager_app.h b/mojo/services/window_manager/window_manager_app.h
index 1664393..f4815ee 100644
--- a/mojo/services/window_manager/window_manager_app.h
+++ b/mojo/services/window_manager/window_manager_app.h
@@ -72,8 +72,7 @@ class WindowManagerApp
typedef std::map<Id, aura::Window*> NodeIdToWindowMap;
// Overridden from ViewManagerDelegate:
- virtual void OnRootAdded(ViewManager* view_manager,
- Node* root) MOJO_OVERRIDE;
+ virtual void OnEmbed(ViewManager* view_manager, Node* root) MOJO_OVERRIDE;
virtual void OnViewManagerDisconnected(
ViewManager* view_manager) MOJO_OVERRIDE;