Beispiel #1
0
        internal static object XamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
        {
            asyncObjectConverter = null;
            if (sandboxExternalContent)
            {
                if (SecurityHelper.AreStringTypesEqual(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme))
                {
                    baseUri = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(baseUri);
                }
                stream.Close();
                return(new WebBrowser
                {
                    Source = baseUri
                });
            }
            ParserContext parserContext = new ParserContext();

            parserContext.BaseUri = baseUri;
            parserContext.SkipJournaledProperties = isJournalNavigation;
            if (allowAsync)
            {
                XamlReader xamlReader = new XamlReader();
                asyncObjectConverter      = xamlReader;
                xamlReader.LoadCompleted += AppModelKnownContentFactory.OnParserComplete;
                return(xamlReader.LoadAsync(stream, parserContext));
            }
            return(XamlReader.Load(stream, parserContext));
        }
Beispiel #2
0
        /// <summary>
        /// Open Media
        /// </summary>
        private void OpenMedia(Uri source)
        {
            string toOpen = null;

            if (source != null && source.IsAbsoluteUri && source.Scheme == PackUriHelper.UriSchemePack)
            {
                try
                {
                    source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
                }
                catch (InvalidOperationException)
                {
                    source = null;
                    _mediaEventsHelper.RaiseMediaFailed(new System.NotSupportedException(SR.Get(SRID.Media_PackURIsAreNotSupported, null)));
                }
            }

            // Setting a null source effectively disconects the MediaElement.
            if (source != null)
            {
                // get the base directory of the application; never expose this
                Uri appBase = SecurityHelper.GetBaseDirectory(AppDomain.CurrentDomain);
                // this extracts the URI to open
                Uri uriToOpen = ResolveUri(source, appBase);
                toOpen = DemandPermissions(uriToOpen);
            }
            else
            {
                toOpen = null;
            }

            // We pass in exact same URI for which we demanded permissions so that we can be sure
            // there is no discrepancy between the two.
            HRESULT.Check(MILMedia.Open(_nativeMedia, toOpen));
        }
Beispiel #3
0
        private void DoNavigate(Uri source, ref object targetFrameName, ref object postData, ref object headers, bool ignoreEscaping = false)
        {
            base.VerifyAccess();
            NativeMethods.IOleCommandTarget oleCommandTarget = (NativeMethods.IOleCommandTarget) this.AxIWebBrowser2;
            object obj = false;

            oleCommandTarget.Exec(null, 23, 0, new object[]
            {
                obj
            }, 0);
            this.LastNavigation = Guid.NewGuid();
            if (source == null)
            {
                this.NavigatingToAboutBlank = true;
                source = new Uri("about:blank");
            }
            else
            {
                this.CleanInternalState();
            }
            if (!source.IsAbsoluteUri)
            {
                throw new ArgumentException(SR.Get("AbsoluteUriOnly"), "source");
            }
            if (PackUriHelper.IsPackUri(source))
            {
                source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
            }
            if (!string.IsNullOrEmpty((string)targetFrameName))
            {
                new WebPermission(PermissionState.Unrestricted).Demand();
            }
            else if (!this.NavigatingToAboutBlank)
            {
                SecurityHelper.DemandWebPermission(source);
            }
            object obj2 = null;
            object obj3 = ignoreEscaping ? source.AbsoluteUri : BindUriHelper.UriToString(source);

            try
            {
                this.AxIWebBrowser2.Navigate2(ref obj3, ref obj2, ref targetFrameName, ref postData, ref headers);
            }
            catch (COMException ex)
            {
                this.CleanInternalState();
                if (ex.ErrorCode != -2147023673)
                {
                    throw;
                }
            }
        }
Beispiel #4
0
 // Token: 0x06007A66 RID: 31334 RVA: 0x0022AE28 File Offset: 0x00229028
 internal static object HtmlXappConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
 {
     asyncObjectConverter = null;
     if (canUseTopLevelBrowser)
     {
         return(null);
     }
     if (SecurityHelper.AreStringTypesEqual(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme))
     {
         baseUri = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(baseUri);
     }
     stream.Close();
     return(new WebBrowser
     {
         Source = baseUri
     });
 }
Beispiel #5
0
        // <summary>
        // Creates an object instance from a Xaml stream and it's Uri
        // </summary>
        internal static object XamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
        {
            asyncObjectConverter = null;

            if (sandboxExternalContent)
            {
                if (SecurityHelper.AreStringTypesEqual(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme))
                {
                    baseUri = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(baseUri);
                }

                stream.Close();

                WebBrowser webBrowser = new WebBrowser();
                webBrowser.Source = baseUri;
                return(webBrowser);
            }
            else
            {
                ParserContext pc = new ParserContext();

                pc.BaseUri = baseUri;
                pc.SkipJournaledProperties = isJournalNavigation;

                if (allowAsync)
                {
                    XamlReader xr = new XamlReader();
                    asyncObjectConverter = xr;
                    xr.LoadCompleted    += new AsyncCompletedEventHandler(OnParserComplete);
                    // XamlReader.Load will close the stream.
                    return(xr.LoadAsync(stream, pc));
                }
                else
                {
                    // XamlReader.Load will close the stream.
                    return(XamlReader.Load(stream, pc));
                }
            }
        }
Beispiel #6
0
        private void DoNavigate(Uri source, ref object targetFrameName, ref object postData, ref object headers, bool ignoreEscaping = false)
        {
            VerifyAccess();

            // TFS  - Calling Navigate and NavigateToStream subsequently causes internal state
            // of the WebBrowser control to become invalid. By cancelling outstanding navigations in the
            // browser, we make sure not to get a NavigationCompleted2 event for the original request while
            // we've already overwritten internal state (more specifically the NavigatingToAboutBlank and
            // DocumentStream properties), therefore avoiding the Invariant.Assert over there to fail.
            // Notice we're passing showCancelPage = false as the input parameter. This keeps the browser
            // from navigating to res://ieframe.dll/navcancl.htm because of the cancellation (which would
            // by itself cause navigation events to occur). See inetcore/ieframe/shdocvw/shvocx.cpp.
            NativeMethods.IOleCommandTarget cmdTarget = (NativeMethods.IOleCommandTarget)AxIWebBrowser2;
            object showCancelPage = false;

            cmdTarget.Exec(
                null /* default command group */,
                (int)UnsafeNativeMethods.OLECMDID.OLECMDID_STOP,
                (int)UnsafeNativeMethods.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT,
                new object[] { showCancelPage }, /* don't navigate to res://ieframe.dll/navcancl.htm */
                0
                );

            // TFS  - Launching a navigation from the Navigating event handler causes reentrancy.
            // For more info, see WebBrowser.LastNavigation. Here we generate a new navigation identifier which
            // is used to detect reentrant calls during handling of the Navigating event.
            LastNavigation = Guid.NewGuid();

            // When source set to null or navigating to stream/string, we navigate to "about:blank" internally.
            if (source == null)
            {
                NavigatingToAboutBlank = true;
                source = new Uri(AboutBlankUriString);
            }
            else
            {
                CleanInternalState();
            }

            if (!source.IsAbsoluteUri)
            {
                throw new ArgumentException(SR.Get(SRID.AbsoluteUriOnly), "source");
            }

            // Resolve Pack://siteoforigin.
            if (PackUriHelper.IsPackUri(source))
            {
                source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
            }

            // figure out why BrowserNavConstants.NewWindowsManaged does not work.
            object flags = (object)null; // UnsafeNativeMethods.BrowserNavConstants.NewWindowsManaged;

            // Fix for inability to navigate to a URI containing invalid UTF-8 sequences
            // BindUriHelper.UriToString does use Uri.GetComponents with the UriFormat.SafeUnescaped flag passed in,
            // causing invalid UTF-8 sequences to get dropped, resulting in a strictly speaking valid URI but for
            // some websites this causes breakage. Therefore we allow ignoring this treatment by means of string-
            // based overloads for the public Navigate methods, creating a Uri internally and using AbsoluteUri
            // to get back the URI string to feed in to the WebOC in its original form. WinForms has a similar
            // set of overloads to enable this scenario.
            object sourceString = ignoreEscaping ? source.AbsoluteUri : BindUriHelper.UriToString(source);

            try
            {
                AxIWebBrowser2.Navigate2(ref sourceString, ref flags, ref targetFrameName, ref postData, ref headers);
            }
            catch (COMException ce)
            {
                // Clear internal state if Navigation fails.
                CleanInternalState();

                // "the operation was canceled by the user" - navigation failed
                // ignore this error, IE has already alerted the user.
                if ((uint)unchecked (ce.ErrorCode) != (uint)unchecked (0x800704c7))
                {
                    throw;
                }
            }
        }
Beispiel #7
0
        private void OpenMedia(Uri source)
        {
            string toOpen = null;

            if (source != null && source.IsAbsoluteUri && source.Scheme == PackUriHelper.UriSchemePack)
            {
                try
                {
                    source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
                }
                catch (InvalidOperationException)
                {
                    source = null;
                    _mediaEventsHelper.RaiseMediaFailed(new System.NotSupportedException(SR.Get(SRID.Media_PackURIsAreNotSupported, null)));
                }
            }

            // Setting a null source effectively disconects the MediaElement.
            if (source != null)
            {
                // keep whether we asserted permissions or not
                bool elevated = false;

                // get the base directory of the application; never expose this
                Uri appBase = SecurityHelper.GetBaseDirectory(AppDomain.CurrentDomain);

                // this extracts the URI to open
                Uri uriToOpen = ResolveUri(source, appBase);

                // access is allowed in the following cases (only 1 & 2 require elevation):
                // 1) to any HTTPS media if app is NOT coming from HTTPS
                // 2) to URI in the current directory of the fusion cache
                // 3) to site of origin media
                if (SecurityHelper.AreStringTypesEqual(uriToOpen.Scheme, Uri.UriSchemeHttps))
                {
                    // target is HTTPS. Then, elevate ONLY if we are NOT coming from HTTPS (=XDomain HTTPS app to HTTPS media disallowed)
                    Uri appDeploymentUri = SecurityHelper.ExtractUriForClickOnceDeployedApp();
                    if (!SecurityHelper.AreStringTypesEqual(appDeploymentUri.Scheme, Uri.UriSchemeHttps))
                    {
                        new WebPermission(NetworkAccess.Connect, BindUriHelper.UriToString(uriToOpen)).Assert();
                        elevated = true;
                    }
                }
                else
                {
                    // elevate to allow access to media in the app's directory in the fusion cache.
                    new FileIOPermission(FileIOPermissionAccess.Read, appBase.LocalPath).Assert();// BlessedAssert
                    elevated = true;
                }

                // demand permissions. if demands succeds, it means we are in one of the cases above.
                try
                {
                    toOpen = DemandPermissions(uriToOpen);
                }
                finally
                {
                    if (elevated)
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            else
            {
                toOpen = null;
            }

            // We pass in exact same URI for which we demanded permissions so that we can be sure
            // there is no discrepancy between the two.
            HRESULT.Check(MILMedia.Open(_nativeMedia, toOpen));
        }