Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1906)

Side by Side Diff: services/view_manager/view_manager_service_impl.cc

Issue 858103002: Remove [Client=] annotation from ServiceProvider (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/view_manager/view_manager_service_impl.h" 5 #include "services/view_manager/view_manager_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "mojo/converters/geometry/geometry_type_converters.h" 9 #include "mojo/converters/geometry/geometry_type_converters.h"
10 #include "mojo/converters/input_events/input_events_type_converters.h" 10 #include "mojo/converters/input_events/input_events_type_converters.h"
11 #include "mojo/converters/surfaces/surfaces_type_converters.h" 11 #include "mojo/converters/surfaces/surfaces_type_converters.h"
12 #include "mojo/services/window_manager/public/interfaces/window_manager_internal .mojom.h" 12 #include "mojo/services/window_manager/public/interfaces/window_manager_internal .mojom.h"
13 #include "services/view_manager/connection_manager.h" 13 #include "services/view_manager/connection_manager.h"
14 #include "services/view_manager/default_access_policy.h" 14 #include "services/view_manager/default_access_policy.h"
15 #include "services/view_manager/display_manager.h" 15 #include "services/view_manager/display_manager.h"
16 #include "services/view_manager/server_view.h" 16 #include "services/view_manager/server_view.h"
17 #include "services/view_manager/window_manager_access_policy.h" 17 #include "services/view_manager/window_manager_access_policy.h"
18 18
19 using mojo::Array; 19 using mojo::Array;
20 using mojo::Callback; 20 using mojo::Callback;
21 using mojo::Id; 21 using mojo::Id;
22 using mojo::InterfaceRequest; 22 using mojo::InterfaceRequest;
23 using mojo::OrderDirection; 23 using mojo::OrderDirection;
24 using mojo::Rect; 24 using mojo::Rect;
25 using mojo::ServiceProvider; 25 using mojo::ServiceProvider;
26 using mojo::ServiceProviderPtr;
26 using mojo::String; 27 using mojo::String;
27 using mojo::ViewDataPtr; 28 using mojo::ViewDataPtr;
28 29
29 namespace view_manager { 30 namespace view_manager {
30 31
31 ViewManagerServiceImpl::ViewManagerServiceImpl( 32 ViewManagerServiceImpl::ViewManagerServiceImpl(
32 ConnectionManager* connection_manager, 33 ConnectionManager* connection_manager,
33 mojo::ConnectionSpecificId creator_id, 34 mojo::ConnectionSpecificId creator_id,
34 const std::string& creator_url, 35 const std::string& creator_url,
35 const std::string& url, 36 const std::string& url,
36 const ViewId& root_id) 37 const ViewId& root_id)
37 : connection_manager_(connection_manager), 38 : connection_manager_(connection_manager),
38 id_(connection_manager_->GetAndAdvanceNextConnectionId()), 39 id_(connection_manager_->GetAndAdvanceNextConnectionId()),
39 url_(url), 40 url_(url),
40 creator_id_(creator_id), 41 creator_id_(creator_id),
41 creator_url_(creator_url), 42 creator_url_(creator_url),
42 client_(nullptr) { 43 client_(nullptr) {
43 CHECK(GetView(root_id)); 44 CHECK(GetView(root_id));
44 root_.reset(new ViewId(root_id)); 45 root_.reset(new ViewId(root_id));
45 if (root_id == RootViewId()) 46 if (root_id == RootViewId())
46 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); 47 access_policy_.reset(new WindowManagerAccessPolicy(id_, this));
47 else 48 else
48 access_policy_.reset(new DefaultAccessPolicy(id_, this)); 49 access_policy_.reset(new DefaultAccessPolicy(id_, this));
49 } 50 }
50 51
51 ViewManagerServiceImpl::~ViewManagerServiceImpl() { 52 ViewManagerServiceImpl::~ViewManagerServiceImpl() {
52 DestroyViews(); 53 DestroyViews();
53 } 54 }
54 55
55 void ViewManagerServiceImpl::Init( 56 void ViewManagerServiceImpl::Init(mojo::ViewManagerClient* client,
56 mojo::ViewManagerClient* client, 57 InterfaceRequest<ServiceProvider> services,
57 InterfaceRequest<ServiceProvider> service_provider) { 58 ServiceProviderPtr exposed_services) {
58 DCHECK(!client_); 59 DCHECK(!client_);
59 client_ = client; 60 client_ = client;
60 std::vector<const ServerView*> to_send; 61 std::vector<const ServerView*> to_send;
61 if (root_.get()) 62 if (root_.get())
62 GetUnknownViewsFrom(GetView(*root_), &to_send); 63 GetUnknownViewsFrom(GetView(*root_), &to_send);
63 64
64 mojo::MessagePipe pipe; 65 mojo::MessagePipe pipe;
65 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient( 66 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient(
66 id_, pipe.handle1.Pass()); 67 id_, pipe.handle1.Pass());
67 client->OnEmbed(id_, creator_url_, ViewToViewData(to_send.front()), 68 client->OnEmbed(id_, creator_url_, ViewToViewData(to_send.front()),
68 service_provider.Pass(), pipe.handle0.Pass()); 69 services.Pass(), exposed_services.Pass(),
70 pipe.handle0.Pass());
69 } 71 }
70 72
71 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { 73 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const {
72 if (id_ == id.connection_id) { 74 if (id_ == id.connection_id) {
73 ViewMap::const_iterator i = view_map_.find(id.view_id); 75 ViewMap::const_iterator i = view_map_.find(id.view_id);
74 return i == view_map_.end() ? NULL : i->second; 76 return i == view_map_.end() ? NULL : i->second;
75 } 77 }
76 return connection_manager_->GetView(id); 78 return connection_manager_->GetView(id);
77 } 79 }
78 80
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 ServerView* view = GetView(view_id); 132 ServerView* view = GetView(view_id);
131 if (!view || view->visible() == visible || 133 if (!view || view->visible() == visible ||
132 !access_policy_->CanChangeViewVisibility(view)) { 134 !access_policy_->CanChangeViewVisibility(view)) {
133 return false; 135 return false;
134 } 136 }
135 ConnectionManager::ScopedChange change(this, connection_manager_, false); 137 ConnectionManager::ScopedChange change(this, connection_manager_, false);
136 view->SetVisible(visible); 138 view->SetVisible(visible);
137 return true; 139 return true;
138 } 140 }
139 141
140 bool ViewManagerServiceImpl::Embed( 142 bool ViewManagerServiceImpl::Embed(const std::string& url,
141 const std::string& url, 143 const ViewId& view_id,
142 const ViewId& view_id, 144 InterfaceRequest<ServiceProvider> services,
143 InterfaceRequest<ServiceProvider> service_provider) { 145 ServiceProviderPtr exposed_services) {
144 const ServerView* view = GetView(view_id); 146 const ServerView* view = GetView(view_id);
145 if (!view || !access_policy_->CanEmbed(view)) 147 if (!view || !access_policy_->CanEmbed(view))
146 return false; 148 return false;
147 149
148 // Only allow a node to be the root for one connection. 150 // Only allow a node to be the root for one connection.
149 ViewManagerServiceImpl* existing_owner = 151 ViewManagerServiceImpl* existing_owner =
150 connection_manager_->GetConnectionWithRoot(view_id); 152 connection_manager_->GetConnectionWithRoot(view_id);
151 153
152 ConnectionManager::ScopedChange change(this, connection_manager_, true); 154 ConnectionManager::ScopedChange change(this, connection_manager_, true);
153 RemoveChildrenAsPartOfEmbed(view_id); 155 RemoveChildrenAsPartOfEmbed(view_id);
154 if (existing_owner) { 156 if (existing_owner) {
155 // Never message the originating connection. 157 // Never message the originating connection.
156 connection_manager_->OnConnectionMessagedClient(id_); 158 connection_manager_->OnConnectionMessagedClient(id_);
157 existing_owner->RemoveRoot(); 159 existing_owner->RemoveRoot();
158 } 160 }
159 connection_manager_->EmbedAtView(id_, url, view_id, service_provider.Pass()); 161 connection_manager_->EmbedAtView(id_, url, view_id, services.Pass(),
162 exposed_services.Pass());
160 return true; 163 return true;
161 } 164 }
162 165
163 void ViewManagerServiceImpl::ProcessViewBoundsChanged( 166 void ViewManagerServiceImpl::ProcessViewBoundsChanged(
164 const ServerView* view, 167 const ServerView* view,
165 const gfx::Rect& old_bounds, 168 const gfx::Rect& old_bounds,
166 const gfx::Rect& new_bounds, 169 const gfx::Rect& new_bounds,
167 bool originated_change) { 170 bool originated_change) {
168 if (originated_change || !IsViewKnown(view)) 171 if (originated_change || !IsViewKnown(view))
169 return; 172 return;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (value.is_null()) { 579 if (value.is_null()) {
577 view->SetProperty(name, nullptr); 580 view->SetProperty(name, nullptr);
578 } else { 581 } else {
579 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); 582 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>();
580 view->SetProperty(name, &data); 583 view->SetProperty(name, &data);
581 } 584 }
582 } 585 }
583 callback.Run(success); 586 callback.Run(success);
584 } 587 }
585 588
586 void ViewManagerServiceImpl::Embed( 589 void ViewManagerServiceImpl::Embed(const String& url,
587 const String& url, 590 Id transport_view_id,
588 Id transport_view_id, 591 InterfaceRequest<ServiceProvider> services,
589 InterfaceRequest<ServiceProvider> service_provider, 592 ServiceProviderPtr exposed_services,
590 const Callback<void(bool)>& callback) { 593 const Callback<void(bool)>& callback) {
591 callback.Run(Embed(url.To<std::string>(), 594 callback.Run(Embed(url.To<std::string>(),
592 ViewIdFromTransportId(transport_view_id), 595 ViewIdFromTransportId(transport_view_id), services.Pass(),
593 service_provider.Pass())); 596 exposed_services.Pass()));
594 } 597 }
595 598
596 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId& id) const { 599 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId& id) const {
597 return IsRoot(id); 600 return IsRoot(id);
598 } 601 }
599 602
600 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( 603 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy(
601 const ServerView* view) const { 604 const ServerView* view) const {
602 return IsViewKnown(view); 605 return IsViewKnown(view);
603 } 606 }
604 607
605 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( 608 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy(
606 const ServerView* view) const { 609 const ServerView* view) const {
607 ViewManagerServiceImpl* connection = 610 ViewManagerServiceImpl* connection =
608 connection_manager_->GetConnectionWithRoot(view->id()); 611 connection_manager_->GetConnectionWithRoot(view->id());
609 return connection && connection != this; 612 return connection && connection != this;
610 } 613 }
611 614
612 } // namespace view_manager 615 } // namespace view_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698