Home | History | Annotate | Download | only in view_manager
      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
      3 // found in the LICENSE file.
      4 
      5 #include "mojo/services/view_manager/window_manager_access_policy.h"
      6 
      7 #include "mojo/services/view_manager/access_policy_delegate.h"
      8 #include "mojo/services/view_manager/server_view.h"
      9 
     10 namespace mojo {
     11 namespace service {
     12 
     13 // TODO(sky): document why this differs from default for each case. Maybe want
     14 // to subclass DefaultAccessPolicy.
     15 
     16 WindowManagerAccessPolicy::WindowManagerAccessPolicy(
     17     ConnectionSpecificId connection_id,
     18     AccessPolicyDelegate* delegate)
     19     : connection_id_(connection_id),
     20       delegate_(delegate) {
     21 }
     22 
     23 WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {
     24 }
     25 
     26 bool WindowManagerAccessPolicy::CanRemoveViewFromParent(
     27     const ServerView* view) const {
     28   return true;
     29 }
     30 
     31 bool WindowManagerAccessPolicy::CanAddView(const ServerView* parent,
     32                                            const ServerView* child) const {
     33   return true;
     34 }
     35 
     36 bool WindowManagerAccessPolicy::CanReorderView(const ServerView* view,
     37                                                const ServerView* relative_view,
     38                                                OrderDirection direction) const {
     39   return true;
     40 }
     41 
     42 bool WindowManagerAccessPolicy::CanDeleteView(const ServerView* view) const {
     43   return view->id().connection_id == connection_id_;
     44 }
     45 
     46 bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView* view) const {
     47   return true;
     48 }
     49 
     50 bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
     51     const ServerView* view) const {
     52   return true;
     53 }
     54 
     55 bool WindowManagerAccessPolicy::CanEmbed(const ServerView* view) const {
     56   return view->id().connection_id == connection_id_;
     57 }
     58 
     59 bool WindowManagerAccessPolicy::CanChangeViewVisibility(
     60     const ServerView* view) const {
     61   return view->id().connection_id == connection_id_;
     62 }
     63 
     64 bool WindowManagerAccessPolicy::CanSetViewSurfaceId(
     65     const ServerView* view) const {
     66   if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
     67     return false;
     68   return view->id().connection_id == connection_id_ ||
     69          (delegate_->GetRootsForAccessPolicy().count(
     70               ViewIdToTransportId(view->id())) > 0);
     71 }
     72 
     73 bool WindowManagerAccessPolicy::CanSetViewBounds(const ServerView* view) const {
     74   return view->id().connection_id == connection_id_;
     75 }
     76 
     77 bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
     78     const ServerView* view,
     79     const ServerView** new_parent,
     80     const ServerView** old_parent) const {
     81   // Notify if we've already told the window manager about the view, or if we've
     82   // already told the window manager about the parent. The later handles the
     83   // case of a view that wasn't parented to the root getting added to the root.
     84   return IsViewKnown(view) || (*new_parent && IsViewKnown(*new_parent));
     85 }
     86 
     87 bool WindowManagerAccessPolicy::IsViewKnown(const ServerView* view) const {
     88   return delegate_->IsViewKnownForAccessPolicy(view);
     89 }
     90 
     91 }  // namespace service
     92 }  // namespace mojo
     93