コード例 #1
0
        public override ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordHosting, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DetermineApplicationTrustStart);
            Uri  uriFromActivationData = this.GetUriFromActivationData(0);
            bool flag = PresentationAppDomainManager.IsDebug || this.GetBoolFromActivationData(1);

            BrowserInteropHelper.SetBrowserHosted(true);
            ApplicationTrust applicationTrust;

            if (flag)
            {
                context.IgnorePersistedDecision = true;
                context.Persist   = false;
                context.KeepAlive = false;
                context.NoPrompt  = true;
                applicationTrust  = base.DetermineApplicationTrust(applicationEvidence, activatorEvidence, context);
            }
            else
            {
                Zone hostEvidence = applicationEvidence.GetHostEvidence <Zone>();
                context.NoPrompt = (hostEvidence.SecurityZone != SecurityZone.Intranet && hostEvidence.SecurityZone != SecurityZone.Trusted);
                bool flag2 = !context.NoPrompt && PresentationHostSecurityManager.ElevationPromptOwnerWindow != IntPtr.Zero;
                if (flag2)
                {
                    IntPtr ancestor = UnsafeNativeMethods.GetAncestor(new HandleRef(null, PresentationHostSecurityManager.ElevationPromptOwnerWindow), 2);
                    PresentationHostSecurityManager.SetFakeActiveWindow(ancestor);
                    PresentationHostSecurityManager.ElevationPromptOwnerWindow = IntPtr.Zero;
                }
                try
                {
                    applicationTrust = base.DetermineApplicationTrust(applicationEvidence, activatorEvidence, context);
                }
                finally
                {
                    if (flag2)
                    {
                        PresentationHostSecurityManager.SetFakeActiveWindow((IntPtr)0);
                    }
                }
            }
            if (applicationTrust != null)
            {
                PermissionSet permissionSet = applicationTrust.DefaultGrantSet.PermissionSet;
                if (flag)
                {
                    Uri uriFromActivationData2 = this.GetUriFromActivationData(2);
                    if (uriFromActivationData2 != null)
                    {
                        permissionSet = PresentationHostSecurityManager.AddPermissionForUri(permissionSet, uriFromActivationData2);
                    }
                }
                if (permissionSet is ReadOnlyPermissionSet)
                {
                    permissionSet = new PermissionSet(permissionSet);
                }
                applicationTrust.DefaultGrantSet.PermissionSet = permissionSet;
            }
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordHosting, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DetermineApplicationTrustEnd);
            return(applicationTrust);
        }
コード例 #2
0
        private ApplicationProxyInternal CreateAppDomainForLooseXaml(Uri uri)
        {
            PermissionSet permissionSet = new PermissionSet(null);

            permissionSet.AddPermission(new FileDialogPermission(FileDialogPermissionAccess.Open));
            permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            permissionSet.AddPermission(new UIPermission(UIPermissionWindow.SafeTopLevelWindows));
            permissionSet.AddPermission(new UIPermission(UIPermissionClipboard.OwnClipboard));
            permissionSet.AddPermission(SystemDrawingHelper.NewSafePrintingPermission());
            permissionSet.AddPermission(new MediaPermission(MediaPermissionAudio.SafeAudio, MediaPermissionVideo.SafeVideo, MediaPermissionImage.SafeImage));
            permissionSet.AddPermission(new WebBrowserPermission(WebBrowserPermissionLevel.Safe));
            permissionSet = PresentationHostSecurityManager.AddPermissionForUri(permissionSet, uri);
            string text           = "XamlViewer";
            string moduleFileName = UnsafeNativeMethods.GetModuleFileName(new HandleRef(null, UnsafeNativeMethods.GetModuleHandle("PresentationHost_v0400.dll")));
            string appBasePath    = Path.GetDirectoryName(moduleFileName) + "\\" + text;

            return(this.CreateAppDomainAndAppProxy(text, appBasePath, permissionSet));
        }