コード例 #1
0
ファイル: MediaPermission.cs プロジェクト: yk2012985/wpf
        ///<summary>
        ///     Return the intersection with the target
        ///</summary>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            MediaPermission operand = target as MediaPermission;

            if (operand != null)
            {
                //
                // Construct a permission that is the aggregate of the
                // least priveleged level of the 3 enums.
                //
                MediaPermissionAudio audioIntersectLevel = _mediaPermissionAudio < operand._mediaPermissionAudio
                                                                ? _mediaPermissionAudio : operand._mediaPermissionAudio;

                MediaPermissionVideo videoIntersectLevel = _mediaPermissionVideo < operand._mediaPermissionVideo
                                                                ? _mediaPermissionVideo : operand._mediaPermissionVideo;

                MediaPermissionImage imageIntersectLevel = _mediaPermissionImage < operand._mediaPermissionImage
                                                                ? _mediaPermissionImage : operand._mediaPermissionImage;

                if ((audioIntersectLevel == MediaPermissionAudio.NoAudio) &&
                    (videoIntersectLevel == MediaPermissionVideo.NoVideo) &&
                    (imageIntersectLevel == MediaPermissionImage.NoImage))

                {
                    return(null);
                }
                else
                {
                    return(new MediaPermission(audioIntersectLevel, videoIntersectLevel, imageIntersectLevel));
                }
            }
            else
            {
                throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel));
            }
        }
コード例 #2
0
ファイル: MediaPermission.cs プロジェクト: yk2012985/wpf
        //
        // CodeAccessPermission implementation
        //


        ///<summary>
        ///     Is this a subsetOf the target ?
        ///</summary>
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(EqualsLevel(MediaPermissionAudio.NoAudio,
                                   MediaPermissionVideo.NoVideo,
                                   MediaPermissionImage.NoImage));
            }

            MediaPermission operand = target as MediaPermission;

            if (operand != null)
            {
                return((this._mediaPermissionAudio <= operand._mediaPermissionAudio) &&
                       (this._mediaPermissionVideo <= operand._mediaPermissionVideo) &&
                       (this._mediaPermissionImage <= operand._mediaPermissionImage));
            }
            else
            {
                throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel));
            }
        }
コード例 #3
0
        CreateMediaAccessPermission(String uri)
        {
            CodeAccessPermission codeAccessPermission = null;
            if (uri != null)
            {
                // do a Case invariant dotnet culture specific string compare
                if (String.Compare(SafeSecurityHelper.IMAGE, uri, true/*Ignore case*/, TypeConverterHelper.InvariantEnglishUS ) == 0)
                {
                    codeAccessPermission = new MediaPermission(MediaPermissionAudio.NoAudio,
                                                               MediaPermissionVideo.NoVideo,
                                                               MediaPermissionImage.AllImage);
                }
                else
                {
                    // we allow access to pack: bits so assuming scheme is not pack: we demand
                    if (String.Compare((System.Windows.Navigation.BaseUriHelper.GetResolvedUri(System.Windows.Navigation.BaseUriHelper.BaseUri, new Uri(uri, UriKind.RelativeOrAbsolute))).Scheme,
                                       PackUriHelper.UriSchemePack, true /* ignore case */,
                                       TypeConverterHelper.InvariantEnglishUS) != 0)
                    {
                        // Creating a URI is fine it is going the other way that is risky
                        if(!SecurityHelper.CallerHasWebPermission(new Uri(uri,UriKind.RelativeOrAbsolute)))
                        {
                            codeAccessPermission = new MediaPermission(MediaPermissionAudio.NoAudio,
                                                                       MediaPermissionVideo.NoVideo,
                                                                       MediaPermissionImage.AllImage);
                        }

                    }
                }
            }
            else
            {
                codeAccessPermission = new MediaPermission(MediaPermissionAudio.NoAudio,
                                                           MediaPermissionVideo.NoVideo,
                                                           MediaPermissionImage.AllImage);
            }
            return codeAccessPermission;
        }