diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-19 06:19:54 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-19 06:19:54 +0000 |
commit | b567f3d86662dce4bb1c5f0449220253fa6b92a5 (patch) | |
tree | a7f50453b7ec86d29e5ddb31e736104ea1267c43 /mojo | |
parent | 2809e927094c8010513b08fad93a3c606fa40ba2 (diff) | |
download | chromium_src-b567f3d86662dce4bb1c5f0449220253fa6b92a5.zip chromium_src-b567f3d86662dce4bb1c5f0449220253fa6b92a5.tar.gz chromium_src-b567f3d86662dce4bb1c5f0449220253fa6b92a5.tar.bz2 |
Revert 284322 "Allow EmbedRoot to be called multiple times."
> Allow EmbedRoot to be called multiple times.
>
> Subsequent calls to EmbedRoot are now delegated to the window manager. This allows an application that was not created via the embed flow to obtain a connection to the view manager by asking the view manager init service to embed it somewhere. The init service just forwards this to the window manager. This is effectively like asking the window manager to create a toplevel window.
>
> R=sky@chromium.org
> BUG=none
>
> Review URL: https://codereview.chromium.org/403083002
TBR=ben@chromium.org
Review URL: https://codereview.chromium.org/405803002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
12 files changed, 63 insertions, 81 deletions
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc index 057c101..e1cb54d 100644 --- a/mojo/examples/window_manager/window_manager.cc +++ b/mojo/examples/window_manager/window_manager.cc @@ -15,9 +15,9 @@ #include "mojo/services/public/cpp/view_manager/node.h" #include "mojo/services/public/cpp/view_manager/node_observer.h" #include "mojo/services/public/cpp/view_manager/view.h" +#include "mojo/services/public/cpp/view_manager/view_event_dispatcher.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/public/interfaces/input_events/input_events.mojom.h" #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" @@ -34,10 +34,10 @@ using mojo::view_manager::Id; using mojo::view_manager::Node; using mojo::view_manager::NodeObserver; using mojo::view_manager::View; +using mojo::view_manager::ViewEventDispatcher; using mojo::view_manager::ViewManager; using mojo::view_manager::ViewManagerDelegate; using mojo::view_manager::ViewObserver; -using mojo::view_manager::WindowManagerDelegate; namespace mojo { namespace examples { @@ -252,7 +252,7 @@ class RootLayoutManager : public NodeObserver { class WindowManager : public ApplicationDelegate, public DebugPanel::Delegate, public ViewManagerDelegate, - public WindowManagerDelegate { + public ViewEventDispatcher { public: WindowManager() : launcher_ui_(NULL), @@ -339,7 +339,7 @@ class WindowManager : public ApplicationDelegate, virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { DCHECK(!view_manager_); view_manager_ = view_manager; - view_manager_->SetWindowManagerDelegate(this); + view_manager_->SetEventDispatcher(this); Node* node = Node::Create(view_manager_); root->AddChild(node); @@ -366,12 +366,7 @@ class WindowManager : public ApplicationDelegate, base::MessageLoop::current()->Quit(); } - // Overridden from WindowManagerDelegate: - virtual void EmbedRoot(const String& url) OVERRIDE { - CreateWindow(url, - navigation::NavigationDetailsPtr().Pass(), - navigation::ResponseDetailsPtr().Pass()); - } + // Overridden from ViewEventDispatcher: virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { // TODO(beng): More sophisticated focus handling than this is required! if (event->action == ui::ET_MOUSE_PRESSED && diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi index 41a5be1..44e522c 100644 --- a/mojo/mojo_services.gypi +++ b/mojo/mojo_services.gypi @@ -511,10 +511,10 @@ 'services/public/cpp/view_manager/node.h', 'services/public/cpp/view_manager/node_observer.h', 'services/public/cpp/view_manager/view.h', + 'services/public/cpp/view_manager/view_event_dispatcher.h', 'services/public/cpp/view_manager/view_manager.h', 'services/public/cpp/view_manager/view_manager_delegate.h', 'services/public/cpp/view_manager/view_observer.h', - 'services/public/cpp/view_manager/window_manager_delegate.h', ], 'export_dependent_settings': [ 'mojo_view_manager_bindings', 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..de55736 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 @@ -13,9 +13,9 @@ #include "mojo/services/public/cpp/view_manager/lib/view_private.h" #include "mojo/services/public/cpp/view_manager/node_observer.h" #include "mojo/services/public/cpp/view_manager/util.h" +#include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h" #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" #include "mojo/services/public/cpp/view_manager/view_observer.h" -#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/png_codec.h" @@ -529,7 +529,7 @@ ViewManagerClientImpl::ViewManagerClientImpl(ApplicationConnection* connection, connection_id_(0), next_id_(1), delegate_(delegate), - window_manager_delegate_(NULL) {} + dispatcher_(NULL) {} ViewManagerClientImpl::~ViewManagerClientImpl() { while (!nodes_.empty()) { @@ -676,14 +676,14 @@ void ViewManagerClientImpl::RemoveView(Id view_id) { //////////////////////////////////////////////////////////////////////////////// // ViewManagerClientImpl, ViewManager implementation: -void ViewManagerClientImpl::SetWindowManagerDelegate( - WindowManagerDelegate* window_manager_delegate) { +void ViewManagerClientImpl::SetEventDispatcher( + ViewEventDispatcher* dispatcher) { CHECK(NULL != GetNodeById(1)); - window_manager_delegate_ = window_manager_delegate; + dispatcher_ = dispatcher; } void ViewManagerClientImpl::DispatchEvent(View* target, EventPtr event) { - CHECK(window_manager_delegate_); + CHECK(dispatcher_); service_->DispatchOnViewInputEvent(target->id(), event.Pass()); } @@ -824,13 +824,9 @@ void ViewManagerClientImpl::OnFocusChanged(Id gained_focus_id, } } -void ViewManagerClientImpl::EmbedRoot(const String& url) { - window_manager_delegate_->EmbedRoot(url); -} - void ViewManagerClientImpl::DispatchOnViewInputEvent(Id view_id, EventPtr event) { - window_manager_delegate_->DispatchEvent(GetViewById(view_id), event.Pass()); + dispatcher_->DispatchEvent(GetViewById(view_id), event.Pass()); } //////////////////////////////////////////////////////////////////////////////// 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..69715b0 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 @@ -21,6 +21,7 @@ namespace mojo { class ApplicationConnection; namespace view_manager { +class ViewEventDispatcher; class ViewManager; class ViewManagerTransaction; @@ -87,8 +88,7 @@ class ViewManagerClientImpl : public ViewManager, typedef std::map<Id, View*> IdToViewMap; // Overridden from ViewManager: - virtual void SetWindowManagerDelegate( - WindowManagerDelegate* delegate) OVERRIDE; + virtual void SetEventDispatcher(ViewEventDispatcher* dispatcher) OVERRIDE; virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE; virtual const std::string& GetEmbedderURL() const OVERRIDE; virtual const std::vector<Node*>& GetRoots() const OVERRIDE; @@ -123,7 +123,6 @@ 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 DispatchOnViewInputEvent(Id view_id, EventPtr event) OVERRIDE; // Sync the client model with the service by enumerating the pending @@ -148,7 +147,7 @@ class ViewManagerClientImpl : public ViewManager, base::Callback<void(void)> changes_acked_callback_; ViewManagerDelegate* delegate_; - WindowManagerDelegate* window_manager_delegate_; + ViewEventDispatcher* dispatcher_; std::vector<Node*> roots_; diff --git a/mojo/services/public/cpp/view_manager/view_event_dispatcher.h b/mojo/services/public/cpp/view_manager/view_event_dispatcher.h new file mode 100644 index 0000000..bfece61 --- /dev/null +++ b/mojo/services/public/cpp/view_manager/view_event_dispatcher.h @@ -0,0 +1,30 @@ +// 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_PUBLIC_CPP_VIEW_MANAGER_VIEW_EVENT_DISPATCHER_H_ +#define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_EVENT_DISPATCHER_H_ + +#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" + +namespace mojo { +namespace view_manager { + +class View; + +// A ViewEventDispatcher is provided by the application rendering at the root +// of a Node hierarchy. It is responsible for targeting input events to the +// relevant Views. This allows window manager features like focus, activation, +// modality, etc. to be implemented. +class ViewEventDispatcher { + public: + virtual void DispatchEvent(View* target, EventPtr event) = 0; + + protected: + virtual ~ViewEventDispatcher() {} +}; + +} // namespace view_manager +} // namespace mojo + +#endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_EVENT_DISPATCHER_H_ diff --git a/mojo/services/public/cpp/view_manager/view_manager.h b/mojo/services/public/cpp/view_manager/view_manager.h index 83b1199..3c55e307 100644 --- a/mojo/services/public/cpp/view_manager/view_manager.h +++ b/mojo/services/public/cpp/view_manager/view_manager.h @@ -17,8 +17,8 @@ namespace view_manager { class Node; class View; +class ViewEventDispatcher; class ViewManagerDelegate; -class WindowManagerDelegate; class ViewManager { public: @@ -26,13 +26,12 @@ class ViewManager { static void ConfigureIncomingConnection(ApplicationConnection* connection, ViewManagerDelegate* delegate); - // Sets the window manager delegate. Can only be called by the app embedded at - // the service root node. - virtual void SetWindowManagerDelegate( - WindowManagerDelegate* window_manager_delegate) = 0; + // Sets the event dispatcher. Can only be called by the app rendering to the + // root Node of the hierarchy. + virtual void SetEventDispatcher(ViewEventDispatcher* dispatcher) = 0; // Dispatches the supplied event to the specified View. Can be called only - // by the application that called SetWindowManagerDelegate(). + // by the application that called SetEventDispatcher(). virtual void DispatchEvent(View* target, EventPtr event) = 0; // Returns the URL of the application that embedded this application. diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom index 5edd9ce..caf57a9 100644 --- a/mojo/services/public/interfaces/view_manager/view_manager.mojom +++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom @@ -22,17 +22,10 @@ enum ErrorCode { ILLEGAL_ARGUMENT, }; -// ViewManagerInitService is used to grant an application a connection to the -// ViewManager by embedding it at an approriate Node. +// ViewManagerInitService is responsible for launching the client that controls +// the root node. mojo::view_manager returns an instance of this. All other +// connections are established by the client this creates. interface ViewManagerInitService { - // Embed the application @ |url| at an appropriate Node. - // The first time this method is called in the lifetime of a View Manager - // application instance, the "appropriate Node" is defined as being the - // service root Node. - // Subsequent times, implementation of this method is delegated to the - // 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); }; @@ -200,16 +193,8 @@ interface ViewManagerClient { // removed. OnFocusChanged(uint32 gained_focus_id, uint32 lost_focus_id); - // TODO(sky): The following methods represent an interface between the view - // manager and the application embedded at the service root node - // (i.e. the window manager). These methods are not called on - // any other clients. They should be moved to a separate interface - // once support for derived FIFOs is landed. + // TODO(sky): move to separate interface when FIFO sorted out. - // Requests the window manager create a "top level" node embedding |url|. - EmbedRoot(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..fe608e8 100644 --- a/mojo/services/view_manager/root_node_manager.cc +++ b/mojo/services/view_manager/root_node_manager.cc @@ -88,12 +88,8 @@ void RootNodeManager::RemoveConnection(ViewManagerServiceImpl* connection) { } void RootNodeManager::EmbedRoot(const std::string& url) { - if (connection_map_.empty()) { - EmbedImpl(kRootConnection, String::From(url), InvalidNodeId()); - return; - } - ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection); - connection->client()->EmbedRoot(url); + CHECK(connection_map_.empty()); + EmbedImpl(kRootConnection, String::From(url), InvalidNodeId()); } 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..827a77d 100644 --- a/mojo/services/view_manager/test_change_tracker.cc +++ b/mojo/services/view_manager/test_change_tracker.cc @@ -80,8 +80,6 @@ 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()); } return std::string(); } @@ -225,13 +223,6 @@ void TestChangeTracker::OnViewInputEvent(Id view_id, EventPtr event) { AddChange(change); } -void TestChangeTracker::OnEmbedRoot(const String& url) { - Change change; - change.type = CHANGE_TYPE_EMBED_ROOT; - change.embed_url = url; - AddChange(change); -} - void TestChangeTracker::AddChange(const Change& change) { changes_.push_back(change); if (delegate_) diff --git a/mojo/services/view_manager/test_change_tracker.h b/mojo/services/view_manager/test_change_tracker.h index a1d5010..d597c6f 100644 --- a/mojo/services/view_manager/test_change_tracker.h +++ b/mojo/services/view_manager/test_change_tracker.h @@ -27,7 +27,6 @@ enum ChangeType { CHANGE_TYPE_VIEW_DELETED, CHANGE_TYPE_VIEW_REPLACED, CHANGE_TYPE_INPUT_EVENT, - CHANGE_TYPE_EMBED_ROOT, }; // TODO(sky): consider nuking and converting directly to NodeData. @@ -58,7 +57,6 @@ struct Change { gfx::Rect bounds2; int32 event_action; String creator_url; - String embed_url; OrderDirection direction; }; @@ -113,7 +111,6 @@ 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); 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..f7822fc 100644 --- a/mojo/services/view_manager/view_manager_init_service_impl.cc +++ b/mojo/services/view_manager/view_manager_init_service_impl.cc @@ -44,8 +44,11 @@ void ViewManagerInitServiceImpl::MaybeEmbedRoot( void ViewManagerInitServiceImpl::EmbedRoot( 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. + if (connect_params_) { + DVLOG(1) << "Ignoring second connect"; + callback.Run(false); + return; + } connect_params_.reset(new ConnectParams); connect_params_->url = url.To<std::string>(); connect_params_->callback = callback; diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc index 2590796..73153737 100644 --- a/mojo/services/view_manager/view_manager_unittest.cc +++ b/mojo/services/view_manager/view_manager_unittest.cc @@ -318,7 +318,7 @@ class TestViewManagerClientConnection connection_.set_view_manager(client()); } - // ViewManagerClient: + // ViewMangerClient: virtual void OnViewManagerConnectionEstablished( ConnectionSpecificId connection_id, const String& creator_url, @@ -363,9 +363,6 @@ 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 DispatchOnViewInputEvent(Id view_id, mojo::EventPtr event) OVERRIDE { } @@ -520,12 +517,6 @@ class ViewManagerTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); }; -TEST_F(ViewManagerTest, SecondEmbedRoot) { - ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); - connection_->DoRunLoopUntilChangesCount(1); - EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); -} - // Verifies client gets a valid id. TEST_F(ViewManagerTest, ValidId) { // TODO(beng): this should really have the URL of the application that |