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

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

Issue 1166123005: Removes ServiceProviders from ViewManager::Embed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use is_headless rather than check for browser. Created 5 years, 6 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 "components/view_manager/view_manager_service_impl.h" 5 #include "components/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 "components/view_manager/connection_manager.h" 9 #include "components/view_manager/connection_manager.h"
10 #include "components/view_manager/default_access_policy.h" 10 #include "components/view_manager/default_access_policy.h"
(...skipping 17 matching lines...) Expand all
28 28
29 namespace view_manager { 29 namespace view_manager {
30 30
31 // Contains information needed to complete an Embed(). See description of 31 // Contains information needed to complete an Embed(). See description of
32 // |pending_embeds_| for more details. 32 // |pending_embeds_| for more details.
33 struct ViewManagerServiceImpl::PendingEmbed 33 struct ViewManagerServiceImpl::PendingEmbed
34 : public base::RefCounted<PendingEmbed> { 34 : public base::RefCounted<PendingEmbed> {
35 PendingEmbed() : embed_root(nullptr) {} 35 PendingEmbed() : embed_root(nullptr) {}
36 36
37 ViewManagerServiceImpl* embed_root; 37 ViewManagerServiceImpl* embed_root;
38 mojo::URLRequestPtr url_request;
39 ViewId view_id; 38 ViewId view_id;
40 mojo::Callback<void(bool)> callback; 39 mojo::Callback<void(bool)> callback;
41 40
42 private: 41 private:
43 friend class base::RefCounted<PendingEmbed>; 42 friend class base::RefCounted<PendingEmbed>;
44 43
45 ~PendingEmbed() {} 44 ~PendingEmbed() {}
46 }; 45 };
47 46
48 ViewManagerServiceImpl::ViewManagerServiceImpl( 47 ViewManagerServiceImpl::ViewManagerServiceImpl(
49 ConnectionManager* connection_manager, 48 ConnectionManager* connection_manager,
50 mojo::ConnectionSpecificId creator_id, 49 mojo::ConnectionSpecificId creator_id,
51 const std::string& creator_url,
52 const std::string& url,
53 const ViewId& root_id) 50 const ViewId& root_id)
54 : connection_manager_(connection_manager), 51 : connection_manager_(connection_manager),
55 id_(connection_manager_->GetAndAdvanceNextConnectionId()), 52 id_(connection_manager_->GetAndAdvanceNextConnectionId()),
56 url_(url),
57 creator_id_(creator_id), 53 creator_id_(creator_id),
58 creator_url_(creator_url),
59 client_(nullptr), 54 client_(nullptr),
60 is_embed_root_(false) { 55 is_embed_root_(false) {
61 CHECK(GetView(root_id)); 56 CHECK(GetView(root_id));
62 root_.reset(new ViewId(root_id)); 57 root_.reset(new ViewId(root_id));
63 if (root_id == RootViewId()) 58 if (root_id == RootViewId())
64 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); 59 access_policy_.reset(new WindowManagerAccessPolicy(id_, this));
65 else 60 else
66 access_policy_.reset(new DefaultAccessPolicy(id_, this)); 61 access_policy_.reset(new DefaultAccessPolicy(id_, this));
67 } 62 }
68 63
69 ViewManagerServiceImpl::~ViewManagerServiceImpl() { 64 ViewManagerServiceImpl::~ViewManagerServiceImpl() {
70 DestroyViews(); 65 DestroyViews();
71 } 66 }
72 67
73 void ViewManagerServiceImpl::Init(mojo::ViewManagerClient* client, 68 void ViewManagerServiceImpl::Init(mojo::ViewManagerClient* client,
74 mojo::ViewManagerServicePtr service_ptr, 69 mojo::ViewManagerServicePtr service_ptr) {
75 InterfaceRequest<ServiceProvider> services,
76 ServiceProviderPtr exposed_services) {
77 DCHECK(!client_); 70 DCHECK(!client_);
78 client_ = client; 71 client_ = client;
79 std::vector<const ServerView*> to_send; 72 std::vector<const ServerView*> to_send;
80 if (root_.get()) 73 if (root_.get())
81 GetUnknownViewsFrom(GetView(*root_), &to_send); 74 GetUnknownViewsFrom(GetView(*root_), &to_send);
82 75
83 const ServerView* focused_view = connection_manager_->GetFocusedView(); 76 const ServerView* focused_view = connection_manager_->GetFocusedView();
84 if (focused_view) 77 if (focused_view)
85 focused_view = access_policy_->GetViewForFocusChange(focused_view); 78 focused_view = access_policy_->GetViewForFocusChange(focused_view);
86 const mojo::Id focused_view_transport_id( 79 const mojo::Id focused_view_transport_id(
87 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); 80 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId()));
88 81
89 client->OnEmbed(id_, creator_url_, ViewToViewData(to_send.front()), 82 client->OnEmbed(id_, ViewToViewData(to_send.front()), service_ptr.Pass(),
90 service_ptr.Pass(), services.Pass(), exposed_services.Pass(),
91 focused_view_transport_id); 83 focused_view_transport_id);
92 } 84 }
93 85
94 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { 86 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const {
95 if (id_ == id.connection_id) { 87 if (id_ == id.connection_id) {
96 ViewMap::const_iterator i = view_map_.find(id.view_id); 88 ViewMap::const_iterator i = view_map_.find(id.view_id);
97 return i == view_map_.end() ? NULL : i->second; 89 return i == view_map_.end() ? NULL : i->second;
98 } 90 }
99 return connection_manager_->GetView(id); 91 return connection_manager_->GetView(id);
100 } 92 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ServerView* view = GetView(view_id); 146 ServerView* view = GetView(view_id);
155 if (!view || view->visible() == visible || 147 if (!view || view->visible() == visible ||
156 !access_policy_->CanChangeViewVisibility(view)) { 148 !access_policy_->CanChangeViewVisibility(view)) {
157 return false; 149 return false;
158 } 150 }
159 ConnectionManager::ScopedChange change(this, connection_manager_, false); 151 ConnectionManager::ScopedChange change(this, connection_manager_, false);
160 view->SetVisible(visible); 152 view->SetVisible(visible);
161 return true; 153 return true;
162 } 154 }
163 155
164 void ViewManagerServiceImpl::SetEmbedRoot() { 156 void ViewManagerServiceImpl::EmbedAllowingReembed(
165 is_embed_root_ = true; 157 const ViewId& view_id,
166 } 158 mojo::URLRequestPtr request,
167 159 const mojo::Callback<void(bool)>& callback) {
168 void ViewManagerServiceImpl::Embed(mojo::URLRequestPtr request,
169 const ViewId& view_id,
170 EmbedType type,
171 InterfaceRequest<ServiceProvider> services,
172 ServiceProviderPtr exposed_services,
173 const mojo::Callback<void(bool)>& callback) {
174 if (!CanEmbed(view_id)) { 160 if (!CanEmbed(view_id)) {
175 callback.Run(false); 161 callback.Run(false);
176 return; 162 return;
177 } 163 }
178 164
179 ViewManagerServiceImpl* embed_root = nullptr; 165 ViewManagerServiceImpl* embed_root = nullptr;
180 166
181 // Only the creator is allowed to reset reembed.
182 ServerView* view = GetView(view_id); 167 ServerView* view = GetView(view_id);
183 DCHECK(view); // CanEmbed() returns true only if |view_id| is valid. 168 DCHECK(view); // CanEmbed() returns true only if |view_id| is valid.
184 if (view->id().connection_id == id_) { 169 if (view->id().connection_id == id_) {
185 view->set_allows_reembed(type == EmbedType::ALLOW_REEMBED); 170 view->set_allows_reembed(true);
186 171
187 // Only consult the embed root if the creator is doing the embed. If someone 172 // Only consult the embed root if the creator is doing the embed. If someone
188 // other than the creator is doing the embed they were granted embed access. 173 // other than the creator is doing the embed they were granted embed access.
189 embed_root = connection_manager_->GetEmbedRoot(this); 174 embed_root = connection_manager_->GetEmbedRoot(this);
190 } 175 }
191 176
192 if (!embed_root) { 177 if (!embed_root) {
193 PrepareForEmbed(view_id); 178 PrepareForEmbed(view_id);
194 connection_manager_->EmbedAtView(id_, request.Pass(), view_id, 179 connection_manager_->EmbedAtView(id_, view_id, request.Pass());
195 services.Pass(), exposed_services.Pass());
196 callback.Run(true); 180 callback.Run(true);
197 return; 181 return;
198 } 182 }
199 183
200 // There is an embed root. We have to query it before completing the embed. 184 // There is an embed root. We have to query it before completing the embed.
201 scoped_refptr<PendingEmbed> pending_embed(new PendingEmbed); 185 scoped_refptr<PendingEmbed> pending_embed(new PendingEmbed);
202 pending_embeds_.insert(pending_embed); 186 pending_embeds_.insert(pending_embed);
203 pending_embed->embed_root = embed_root; 187 pending_embed->embed_root = embed_root;
204 pending_embed->view_id = view_id; 188 pending_embed->view_id = view_id;
205 pending_embed->url_request = request.Pass();
206 pending_embed->callback = callback; 189 pending_embed->callback = callback;
207 pending_embeds_.insert(pending_embed); 190 pending_embeds_.insert(pending_embed);
208 embed_root->client()->OnWillEmbed( 191 embed_root->client()->OnEmbedForDescendant(
209 ViewIdToTransportId(view_id), services.Pass(), exposed_services.Pass(), 192 ViewIdToTransportId(view_id), request.Pass(),
210 base::Bind(&ViewManagerServiceImpl::OnWillEmbedDone, 193 base::Bind(&ViewManagerServiceImpl::OnEmbedForDescendantDone,
211 base::Unretained(this), pending_embed)); 194 base::Unretained(this), pending_embed));
212 } 195 }
213 196
214 bool ViewManagerServiceImpl::Embed(const ViewId& view_id, 197 bool ViewManagerServiceImpl::Embed(const ViewId& view_id,
215 mojo::ViewManagerClientPtr client) { 198 mojo::ViewManagerClientPtr client) {
216 // TODO(sky): wire up embed root.
217 if (!client.get() || !CanEmbed(view_id)) 199 if (!client.get() || !CanEmbed(view_id))
218 return false; 200 return false;
219 PrepareForEmbed(view_id); 201 PrepareForEmbed(view_id);
220 connection_manager_->EmbedAtView(id_, view_id, client.Pass()); 202 connection_manager_->EmbedAtView(id_, view_id, client.Pass());
221 return true; 203 return true;
222 } 204 }
223 205
224 void ViewManagerServiceImpl::ProcessViewBoundsChanged( 206 void ViewManagerServiceImpl::ProcessViewBoundsChanged(
225 const ServerView* view, 207 const ServerView* view,
226 const gfx::Rect& old_bounds, 208 const gfx::Rect& old_bounds,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed( 542 void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed(
561 const ViewId& view_id) { 543 const ViewId& view_id) {
562 ServerView* view = GetView(view_id); 544 ServerView* view = GetView(view_id);
563 CHECK(view); 545 CHECK(view);
564 CHECK(view->id().connection_id == view_id.connection_id); 546 CHECK(view->id().connection_id == view_id.connection_id);
565 std::vector<ServerView*> children = view->GetChildren(); 547 std::vector<ServerView*> children = view->GetChildren();
566 for (size_t i = 0; i < children.size(); ++i) 548 for (size_t i = 0; i < children.size(); ++i)
567 view->Remove(children[i]); 549 view->Remove(children[i]);
568 } 550 }
569 551
570 void ViewManagerServiceImpl::OnWillEmbedDone( 552 void ViewManagerServiceImpl::OnEmbedForDescendantDone(
571 scoped_refptr<PendingEmbed> pending_embed, 553 scoped_refptr<PendingEmbed> pending_embed,
572 bool allow_embed, 554 mojo::ViewManagerClientPtr client) {
573 mojo::InterfaceRequest<mojo::ServiceProvider> services,
574 mojo::ServiceProviderPtr exposed_services) {
575 if (!pending_embeds_.count(pending_embed.get())) 555 if (!pending_embeds_.count(pending_embed.get()))
576 return; 556 return;
577 557
578 allow_embed = allow_embed && CanEmbed(pending_embed->view_id); 558 const bool allow_embed = client.get() && CanEmbed(pending_embed->view_id);
579 if (allow_embed) { 559 if (allow_embed) {
580 PrepareForEmbed(pending_embed->view_id); 560 PrepareForEmbed(pending_embed->view_id);
581 connection_manager_->EmbedAtView(id_, pending_embed->url_request.Pass(), 561 connection_manager_->EmbedAtView(id_, pending_embed->view_id,
582 pending_embed->view_id, services.Pass(), 562 client.Pass());
583 exposed_services.Pass());
584 } 563 }
585 RemovePendingEmbedAndNotifyCallback(pending_embed.get(), allow_embed); 564 RemovePendingEmbedAndNotifyCallback(pending_embed.get(), allow_embed);
586 } 565 }
587 566
588 void ViewManagerServiceImpl::InvalidatePendingEmbedForConnection( 567 void ViewManagerServiceImpl::InvalidatePendingEmbedForConnection(
589 ViewManagerServiceImpl* connection) { 568 ViewManagerServiceImpl* connection) {
590 if (pending_embeds_.empty()) 569 if (pending_embeds_.empty())
591 return; 570 return;
592 std::set<scoped_refptr<PendingEmbed>> copy(pending_embeds_); 571 std::set<scoped_refptr<PendingEmbed>> copy(pending_embeds_);
593 for (auto& embed : copy) { 572 for (auto& embed : copy) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 if (value.is_null()) { 705 if (value.is_null()) {
727 view->SetProperty(name, nullptr); 706 view->SetProperty(name, nullptr);
728 } else { 707 } else {
729 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); 708 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>();
730 view->SetProperty(name, &data); 709 view->SetProperty(name, &data);
731 } 710 }
732 } 711 }
733 callback.Run(success); 712 callback.Run(success);
734 } 713 }
735 714
736 void ViewManagerServiceImpl::EmbedRequest( 715 void ViewManagerServiceImpl::SetEmbedRoot() {
737 mojo::URLRequestPtr request, 716 is_embed_root_ = true;
738 Id transport_view_id,
739 InterfaceRequest<ServiceProvider> services,
740 ServiceProviderPtr exposed_services,
741 const Callback<void(bool)>& callback) {
742 Embed(request.Pass(), ViewIdFromTransportId(transport_view_id),
743 EmbedType::NO_REEMBED, services.Pass(), exposed_services.Pass(),
744 callback);
745 }
746
747 void ViewManagerServiceImpl::EmbedAllowingReembed(
748 mojo::URLRequestPtr request,
749 mojo::Id transport_view_id,
750 const mojo::Callback<void(bool)>& callback) {
751 Embed(request.Pass(), ViewIdFromTransportId(transport_view_id),
752 EmbedType::ALLOW_REEMBED, nullptr, nullptr, callback);
753 } 717 }
754 718
755 void ViewManagerServiceImpl::Embed(mojo::Id transport_view_id, 719 void ViewManagerServiceImpl::Embed(mojo::Id transport_view_id,
756 mojo::ViewManagerClientPtr client, 720 mojo::ViewManagerClientPtr client,
757 const mojo::Callback<void(bool)>& callback) { 721 const mojo::Callback<void(bool)>& callback) {
758 callback.Run(Embed(ViewIdFromTransportId(transport_view_id), client.Pass())); 722 callback.Run(Embed(ViewIdFromTransportId(transport_view_id), client.Pass()));
759 } 723 }
760 724
725 void ViewManagerServiceImpl::EmbedAllowingReembed(
726 mojo::Id transport_view_id,
727 mojo::URLRequestPtr request,
728 const mojo::Callback<void(bool)>& callback) {
729 EmbedAllowingReembed(ViewIdFromTransportId(transport_view_id), request.Pass(),
730 callback);
731 }
732
761 void ViewManagerServiceImpl::SetFocus(uint32_t view_id, 733 void ViewManagerServiceImpl::SetFocus(uint32_t view_id,
762 const SetFocusCallback& callback) { 734 const SetFocusCallback& callback) {
763 ServerView* view = GetView(ViewIdFromTransportId(view_id)); 735 ServerView* view = GetView(ViewIdFromTransportId(view_id));
764 bool success = view && view->IsDrawn(connection_manager_->root()) && 736 bool success = view && view->IsDrawn(connection_manager_->root()) &&
765 access_policy_->CanSetFocus(view); 737 access_policy_->CanSetFocus(view);
766 if (success) { 738 if (success) {
767 ConnectionManager::ScopedChange change(this, connection_manager_, false); 739 ConnectionManager::ScopedChange change(this, connection_manager_, false);
768 connection_manager_->SetFocusedView(view); 740 connection_manager_->SetFocusedView(view);
769 } 741 }
770 callback.Run(success); 742 callback.Run(success);
(...skipping 13 matching lines...) Expand all
784 ViewManagerServiceImpl* connection = 756 ViewManagerServiceImpl* connection =
785 connection_manager_->GetConnectionWithRoot(view->id()); 757 connection_manager_->GetConnectionWithRoot(view->id());
786 return connection && connection != this; 758 return connection && connection != this;
787 } 759 }
788 760
789 bool ViewManagerServiceImpl::IsEmbedRootForAccessPolicy() { 761 bool ViewManagerServiceImpl::IsEmbedRootForAccessPolicy() {
790 return is_embed_root_; 762 return is_embed_root_;
791 } 763 }
792 764
793 } // namespace view_manager 765 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/view_manager_service_impl.h ('k') | components/view_manager/view_manager_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698