Example #1
0
 static BaseUriHelper()
 {
     _baseUri = new SecurityCriticalDataForSet <Uri>(_packAppBaseUri);
     // Add an instance of the ResourceContainer to PreloadedPackages so that PackWebRequestFactory can find it
     // and mark it as thread-safe so PackWebResponse won't protect returned streams with a synchronizing wrapper
     PreloadedPackages.AddPackage(PackUriHelper.GetPackageUri(SiteOfOriginBaseUri), new SiteOfOriginContainer(), true);
 }
        private static Uri GetStructureUriFromRelationship(Uri contentUri, string relationshipName)
        {
            Uri result = null;

            if (contentUri != null && relationshipName != null)
            {
                Uri partUri = PackUriHelper.GetPartUri(contentUri);
                if (partUri != null)
                {
                    Uri     packageUri = PackUriHelper.GetPackageUri(contentUri);
                    Package package    = PreloadedPackages.GetPackage(packageUri);
                    if (package == null && SecurityHelper.CheckEnvironmentPermission())
                    {
                        package = PackageStore.GetPackage(packageUri);
                    }
                    if (package != null)
                    {
                        PackagePart part = package.GetPart(partUri);
                        PackageRelationshipCollection relationshipsByType = part.GetRelationshipsByType(relationshipName);
                        Uri uri = null;
                        foreach (PackageRelationship packageRelationship in relationshipsByType)
                        {
                            uri = PackUriHelper.ResolvePartUri(partUri, packageRelationship.TargetUri);
                        }
                        if (uri != null)
                        {
                            result = PackUriHelper.Create(packageUri, uri);
                        }
                    }
                }
            }
            return(result);
        }
        static int _wpfPayloadCount;     // used to disambiguate between all acts of loading from different WPF payloads.


        internal static object LoadElement(Stream stream)
        {
            Package    package    = Package.Open(stream, FileMode.Open, FileAccess.Read);
            WpfPayload wpfPayload = new WpfPayload(package);

            PackagePart xamlEntryPart = wpfPayload.GetWpfEntryPart();


            int newWpfPayoutCount = _wpfPayloadCount++;
            Uri payloadUri        = new Uri("payload://wpf" + newWpfPayoutCount, UriKind.Absolute);
            Uri entryPartUri      = PackUriHelper.Create(payloadUri, xamlEntryPart.Uri); // gives an absolute uri of the entry part
            Uri packageUri        = PackUriHelper.GetPackageUri(entryPartUri);           // extracts package uri from combined package+part uri

            PackageStore.AddPackage(packageUri, wpfPayload.Package);                     // Register the package
            ParserContext parserContext = new ParserContext();

            parserContext.BaseUri = entryPartUri;

            object xamlObject = XamlReader.Load(xamlEntryPart.GetStream(), parserContext);

            // Remove the temporary uri from the PackageStore
            PackageStore.RemovePackage(packageUri);

            return(xamlObject);
        }
Example #4
0
        /// <summary>
        /// Loads xaml content from a WPF package.
        /// </summary>
        /// <param name="stream">
        /// Stream that must be accessible for reading and structured as
        /// a WPF container: part XamlEntryPart is expected as one of
        /// its entry parts.
        /// </param>
        /// <returns>
        /// Returns a xaml element loaded from the entry part of the package.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Throws parsing exception when the xaml content does not comply with the xaml schema.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Throws validation exception when the package is not well structured.
        /// </exception>
        /// <exception cref="Exception">
        /// Throws uri exception when the pachageBaseUri is not correct absolute uri.
        /// </exception>
        /// <remarks>
        /// USED IN LEXICON VIA REFLECTION
        /// </remarks>
        internal static object LoadElement(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            object xamlObject;

            try
            {
                WpfPayload wpfPayload = WpfPayload.OpenWpfPayload(stream);

                // Now load the package
                using (wpfPayload.Package)
                {
                    // Validate WPF paypoad and get its entry part
                    PackagePart xamlEntryPart = wpfPayload.ValidatePayload();

                    // Define a unique uri for this instance of PWF payload.
                    // Uniqueness is required to make sure that cached images are not mixed up.
                    int newWpfPayoutCount = Interlocked.Increment(ref _wpfPayloadCount);
                    Uri payloadUri        = new Uri("payload://wpf" + newWpfPayoutCount, UriKind.Absolute);
                    Uri entryPartUri      = PackUriHelper.Create(payloadUri, xamlEntryPart.Uri); // gives an absolute uri of the entry part
                    Uri packageUri        = PackUriHelper.GetPackageUri(entryPartUri);           // extracts package uri from combined package+part uri
                    PackageStore.AddPackage(packageUri, wpfPayload.Package);                     // Register the package

                    // Set this temporary uri as a base uri for xaml parser
                    ParserContext parserContext = new ParserContext();
                    parserContext.BaseUri = entryPartUri;

                    // Call xaml parser
                    xamlObject = XamlReader.Load(xamlEntryPart.GetStream(), parserContext);

                    // Remove the temporary uri from the PackageStore
                    PackageStore.RemovePackage(packageUri);
                }
            }
            catch (XamlParseException e)
            {
                // Incase of xaml parsing or package structure failure
                // we return null.
                Invariant.Assert(e != null); //to make compiler happy about not using a variable e. This variable is useful in debugging process though - to see a reason of a parsing failure
                xamlObject = null;
            }
            catch (System.IO.FileFormatException)
            {
                xamlObject = null;
            }
            catch (System.IO.FileLoadException)
            {
                xamlObject = null;
            }
            catch (System.OutOfMemoryException)
            {
                xamlObject = null;
            }

            return(xamlObject);
        }
        ///<summary>
        /// <see cref="XmlUrlResolver.GetEntity"/>
        ///</summary>
        public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
        {
            ofObjectToReturn.DbC_Assure(value => value == typeof(Stream));

            switch (absoluteUri.Scheme)
            {
            case "resource":
                return(Resources.GetStream(absoluteUri.AbsolutePath));

            case "dynamic":
                string ResourceName = absoluteUri.Host;
                if (this.dynamicContent.ContainsKey(ResourceName))
                {
                    return(new MemoryStream(Encoding.Unicode.GetBytes(this.dynamicContent[ResourceName])));
                }
                else
                {
                    throw new ArgumentException($"Dynamic content not found: {ResourceName}");
                }

            case "pack":
                return(Package
                       .Open((Stream)this.GetEntity(PackUriHelper.GetPackageUri(absoluteUri), null, typeof(Stream)))
                       .GetPart(PackUriHelper.GetPartUri(absoluteUri)).GetStream());

            default:
                return(base.GetEntity(absoluteUri, role, ofObjectToReturn));
            }
        }
Example #6
0
 internal static bool IsPackApplicationUri(Uri uri)
 {
     if (uri.IsAbsoluteUri && SecurityHelper.AreStringTypesEqual(uri.Scheme, PackUriHelper.UriSchemePack))
     {
         return(SecurityHelper.AreStringTypesEqual(PackUriHelper.GetPackageUri(uri).GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped), "application:///"));
     }
     return(false);
 }
Example #7
0
 static BaseUriHelper()
 {
     _siteOfOriginBaseUri = PackUriHelper.Create(new Uri("SiteOfOrigin://"));
     _packAppBaseUri      = PackUriHelper.Create(new Uri("application://"));
     BaseUriProperty      = DependencyProperty.RegisterAttached("BaseUri", typeof(Uri), typeof(BaseUriHelper), new PropertyMetadata((object)null));
     _baseUri             = new MS.Internal.SecurityCriticalDataForSet <Uri>(_packAppBaseUri);
     PreloadedPackages.AddPackage(PackUriHelper.GetPackageUri(SiteOfOriginBaseUri), new SiteOfOriginContainer(), true);
 }
Example #8
0
        /// <summary>
        /// Checks whether the input uri is in the "pack://application:,,," form
        /// </summary>
        internal static bool IsPackApplicationUri(Uri uri)
        {
            return
                // Is the "outer" URI absolute?
                (uri.IsAbsoluteUri &&

                 // Does the "outer" URI have the pack: scheme?
                 SecurityHelper.AreStringTypesEqual(uri.Scheme, PackUriHelper.UriSchemePack) &&

                 // Does the "inner" URI have the application: scheme
                 SecurityHelper.AreStringTypesEqual(
                     PackUriHelper.GetPackageUri(uri).GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped),
                     _packageApplicationBaseUriEscaped));
        }
        internal static bool IsPackApplicationUri(Uri uri)
        {
            return
                (uri != null &&

                 // Is the "outer" URI absolute?
                 uri.IsAbsoluteUri &&

                 // Does the "outer" URI have the pack: scheme?
                 string.Equals(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase) &&

                 // Does the "inner" URI have the application: scheme?
                 string.Equals(
                     PackUriHelper.GetPackageUri(uri).GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped),
                     PackageApplicationBaseUriEscaped,
                     StringComparison.OrdinalIgnoreCase));
        }
Example #10
0
        // Token: 0x06003F20 RID: 16160 RVA: 0x0012075C File Offset: 0x0011E95C
        internal static object LoadElement(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            object result;

            try
            {
                WpfPayload wpfPayload = WpfPayload.OpenWpfPayload(stream);
                using (wpfPayload.Package)
                {
                    PackagePart packagePart = wpfPayload.ValidatePayload();
                    int         num         = Interlocked.Increment(ref WpfPayload._wpfPayloadCount);
                    Uri         packageUri  = new Uri("payload://wpf" + num, UriKind.Absolute);
                    Uri         uri         = PackUriHelper.Create(packageUri, packagePart.Uri);
                    Uri         packageUri2 = PackUriHelper.GetPackageUri(uri);
                    PackageStore.AddPackage(packageUri2, wpfPayload.Package);
                    ParserContext parserContext = new ParserContext();
                    parserContext.BaseUri = uri;
                    bool useRestrictiveXamlReader = !Clipboard.UseLegacyDangerousClipboardDeserializationMode();
                    result = XamlReader.Load(packagePart.GetStream(), parserContext, useRestrictiveXamlReader);
                    PackageStore.RemovePackage(packageUri2);
                }
            }
            catch (XamlParseException ex)
            {
                Invariant.Assert(ex != null);
                result = null;
            }
            catch (FileFormatException)
            {
                result = null;
            }
            catch (FileLoadException)
            {
                result = null;
            }
            catch (OutOfMemoryException)
            {
                result = null;
            }
            return(result);
        }
 internal void Cleanup()
 {
     if (Application.Current != null)
     {
         IBrowserCallbackServices browserCallbackServices = Application.Current.BrowserCallbackServices;
         if (browserCallbackServices != null)
         {
             Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(this.ReleaseBrowserCallback), browserCallbackServices);
         }
     }
     this.ServiceProvider = null;
     this.ClearRootBrowserWindow();
     if (this._storageRoot != null && this._storageRoot.Value != null)
     {
         this._storageRoot.Value.Close();
     }
     if (this._document.Value is PackageDocument)
     {
         PreloadedPackages.RemovePackage(PackUriHelper.GetPackageUri(PackUriHelper.Create(this.Uri)));
         ((PackageDocument)this._document.Value).Dispose();
         this._document.Value = null;
     }
     if (this._mimeType.Value == MimeType.Document)
     {
         DocumentManager.CleanUp();
     }
     if (this._packageStream.Value != null)
     {
         this._packageStream.Value.Close();
     }
     if (this._unmanagedStream.Value != null)
     {
         Marshal.ReleaseComObject(this._unmanagedStream.Value);
         this._unmanagedStream = new SecurityCriticalData <object>(null);
     }
 }
Example #12
0
 public void GetPackageUri3()
 {
     PackUriHelper.GetPackageUri(part1);
 }
Example #13
0
        private void documentViewer_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
        {
            try
            {
                string url         = e.Uri.AbsoluteUri;
                string lower_url   = url.ToLower();
                string package_url = "";
                LogFile.Debug("Requested URI: " + url);
                try
                {
                    if (url.ToLower().StartsWith("pack://"))  //sonst exception bei exec:// z.B.
                    {
                        package_url = PackUriHelper.GetPackageUri(e.Uri).AbsoluteUri;
                    }
                }
                catch (Exception ex)
                {
                    LogFile.Error("exception in RequestNavigate() while analyzing uri:", ex);
                }

                if (document_uri.Equals(package_url) && document_uri != "" && package_url != "")
                {
                    string fragment_to_find = e.Uri.Fragment.Replace("#", "");
                    if (index.Contains(fragment_to_find))
                    {
                        BringIntoView_ByURI(fragment_to_find, (int)index[fragment_to_find]);
                    }
                }
                else if (url.ToLower().StartsWith("exec://"))
                {
                    string cmd = url.Remove(0, "exec://".Length);
                    if (cmd.EndsWith("/"))
                    {
                        cmd = cmd.Substring(0, cmd.Length - 1);
                    }
                    if (cmd.StartsWith("/"))
                    {
                        cmd = cmd.Substring(1, cmd.Length - 1);
                    }
                    cmd = cmd.Replace("/", @"\");
                    string param = Program.ExecParam.Replace("$1", "\"" + cmd + "\"");
                    if (Program.ExecProgram != "")
                    {
                        System.Diagnostics.Process.Start(Program.ExecProgram, param);
                    }
                }
                else if (url.ToLower().StartsWith("execx://"))
                {
                    string cmd = url.Remove(0, "execx://".Length);
                    if (cmd.EndsWith("/"))
                    {
                        cmd = cmd.Substring(0, cmd.Length - 1);
                    }
                    if (cmd.StartsWith("/"))
                    {
                        cmd = cmd.Substring(1, cmd.Length - 1);
                    }
                    cmd = cmd.Replace("/", @"\");
                    string param = Program.ExecParam.Replace("$1", "\"" + cmd + "\"");
                    if (Program.ExecProgram != "")
                    {
                        System.Diagnostics.Process.Start(Program.ExecProgram, param);
                    }
                    Program.Quit();
                }
                else if (url.ToLower().Equals("document://thumbnails/"))
                {
                    this.documentViewer.ViewThumbnails();
                }
                else if (url.ToLower().Equals("document://last-page/"))
                {
                    this.documentViewer.LastPage();
                }
                else if (url.ToLower().Equals("document://first-page/"))
                {
                    this.documentViewer.FirstPage();
                }
                else if (url.ToLower().Equals("document://next-page/"))
                {
                    this.GotoNextPage();
                }
                else if (url.ToLower().Equals("document://prev-page/"))
                {
                    this.GotoPrevPage();
                }
                else if (url.ToLower().Equals("document://close/"))
                {
                    Program.Quit();
                }
                else if (url.ToLower().StartsWith("document://page-"))
                {
                    string page = url.Remove(0, "document://page-".Length);
                    if (page.EndsWith("/"))
                    {
                        page = page.Substring(0, page.Length - 1);
                    }
                    if (page.StartsWith("/"))
                    {
                        page = page.Substring(1, page.Length - 1);
                    }

                    int pageIdx = Convert.ToInt32(page);
                    if (pageIdx >= 1)
                    {
                        if (documentViewer.CanGoToPage(pageIdx))
                        {
                            documentViewer.GoToPage(pageIdx);
                        }
                    }
                }
                else
                {
                    //All protocol, exe, and similar
                    System.Diagnostics.Process.Start(url);  //Can raise exception!
                }
                //URL is always handled
                e.Handled = true;
            }
            catch (Exception ex)
            {
                LogFile.Error("exception in RequestNavigate:", ex);
            }
        }
Example #14
0
 public void GetPackageUri2()
 {
     PackUriHelper.GetPackageUri(null);
 }
Example #15
0
 public void GetPackageUriTest()
 {
     Assert.AreEqual(a, PackUriHelper.GetPackageUri(PackUriHelper.Create(a, new Uri("/test.html", UriKind.Relative))));
 }
Example #16
0
        private object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType, string rootElement)
        {
            object      result    = null;
            List <Type> safeTypes = new List <Type>
            {
                typeof(ResourceDictionary)
            };

            if (!XpsValidatingLoader.DocumentMode)
            {
                if (rootElement == null)
                {
                    XmlReader reader = XmlReader.Create(stream, null, pc);
                    result = XamlReader.Load(reader, pc, XamlParseMode.Synchronous, FrameworkCompatibilityPreferences.DisableLegacyDangerousXamlDeserializationMode, safeTypes);
                    stream.Close();
                }
            }
            else
            {
                XpsSchema schema  = XpsSchema.GetSchema(mimeType);
                Uri       baseUri = pc.BaseUri;
                Uri       uri;
                Uri       uri2;
                PackUriHelper.ValidateAndGetPackUriComponents(baseUri, out uri, out uri2);
                Package package = PreloadedPackages.GetPackage(uri);
                if (parentUri != null)
                {
                    Uri packageUri = PackUriHelper.GetPackageUri(parentUri);
                    if (!packageUri.Equals(uri))
                    {
                        throw new FileFormatException(SR.Get("XpsValidatingLoaderUriNotInSamePackage"));
                    }
                }
                schema.ValidateRelationships(new SecurityCriticalData <Package>(package), uri, uri2, mimeType);
                if (schema.AllowsMultipleReferencesToSameUri(mimeType))
                {
                    this._uniqueUriRef = null;
                }
                else
                {
                    this._uniqueUriRef = new Hashtable(11);
                }
                Hashtable hashtable = (XpsValidatingLoader._validResources.Count > 0) ? XpsValidatingLoader._validResources.Peek() : null;
                if (schema.HasRequiredResources(mimeType))
                {
                    hashtable = new Hashtable(11);
                    PackagePart part = package.GetPart(uri2);
                    PackageRelationshipCollection relationshipsByType = part.GetRelationshipsByType(XpsValidatingLoader._requiredResourceRel);
                    foreach (PackageRelationship packageRelationship in relationshipsByType)
                    {
                        Uri         partUri = PackUriHelper.ResolvePartUri(uri2, packageRelationship.TargetUri);
                        Uri         key     = PackUriHelper.Create(uri, partUri);
                        PackagePart part2   = package.GetPart(partUri);
                        if (schema.IsValidRequiredResourceMimeType(part2.ValidatedContentType))
                        {
                            if (!hashtable.ContainsKey(key))
                            {
                                hashtable.Add(key, true);
                            }
                        }
                        else if (!hashtable.ContainsKey(key))
                        {
                            hashtable.Add(key, false);
                        }
                    }
                }
                XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType, stream, uri, uri2);
                XpsValidatingLoader._validResources.Push(hashtable);
                if (rootElement != null)
                {
                    xpsSchemaValidator.XmlReader.MoveToContent();
                    if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name))
                    {
                        throw new FileFormatException(SR.Get("XpsValidatingLoaderUnsupportedMimeType"));
                    }
                    while (xpsSchemaValidator.XmlReader.Read())
                    {
                    }
                }
                else
                {
                    result = XamlReader.Load(xpsSchemaValidator.XmlReader, pc, XamlParseMode.Synchronous, FrameworkCompatibilityPreferences.DisableLegacyDangerousXamlDeserializationMode, safeTypes);
                }
                XpsValidatingLoader._validResources.Pop();
            }
            return(result);
        }
Example #17
0
        internal void Cleanup()
        {
            if (Application.Current != null)
            {
                IBrowserCallbackServices bcs = Application.Current.BrowserCallbackServices;
                if (bcs != null)
                {
                    Debug.Assert(!Application.IsApplicationObjectShuttingDown);
                    // Marshal.ReleaseComObject(bcs) has to be called so that the refcount of the
                    // native objects goes to zero for clean shutdown. But it should not be called
                    // right away, because there may still be DispatcherOperations in the queue
                    // that will attempt to use IBCS, especially during downloading/activation.
                    // Last, it can't be called with prioroty lower than Normal, because that's
                    // the priority of Applicatoin.ShudownCallback(), which shuts down the
                    // Dispatcher.
                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Normal, new DispatcherOperationCallback(ReleaseBrowserCallback), bcs);
                }
            }

            ServiceProvider = null;
            ClearRootBrowserWindow();

            if (_storageRoot != null && _storageRoot.Value != null)
            {
                _storageRoot.Value.Close();
            }

            // Due to the dependecies the following objects have to be released
            // in the following order: _document, DocumentManager,
            // _packageStream, _unmanagedStream.

            if (_document.Value is PackageDocument)
            {
                // We are about to close the package ad remove it from the Preloaded Packages Store.
                // Let's make sure that the data structures are consistent. The package that we hold is
                // actually in the store under the URI that we think it should be using
                Debug.Assert(((PackageDocument)_document.Value).Package ==
                             PreloadedPackages.GetPackage(PackUriHelper.GetPackageUri(PackUriHelper.Create(Uri))));

                // We need to remove the Package from the PreloadedPackage storage,
                // so that potential future requests would fail in a way of returning a null (resource not found)
                // rather then return a Package or stream that is already Closed
                PreloadedPackages.RemovePackage(PackUriHelper.GetPackageUri(PackUriHelper.Create(Uri)));

                ((PackageDocument)_document.Value).Dispose();
                _document.Value = null;
            }

            if (_mimeType.Value == MimeType.Document)
            {
                DocumentManager.CleanUp();
            }

            if (_packageStream.Value != null)
            {
                _packageStream.Value.Close();
            }

            if (_unmanagedStream.Value != null)
            {
                Marshal.ReleaseComObject(_unmanagedStream.Value);
                _unmanagedStream = new SecurityCriticalData <object>(null);
            }
        }
Example #18
0
        private object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType, string rootElement)
        {
            object obj = null;

            if (!DocumentMode)
            {                       // Loose XAML, just check against schema, don't check content type
                if (rootElement == null)
                {
                    obj = XamlReader.Load(stream, pc);
                }
            }
            else
            {                       // inside an XPS Document. Perform maximum validation
                XpsSchema schema = XpsSchema.GetSchema(mimeType);
                Uri       uri    = pc.BaseUri;

                // Using PackUriHelper.ValidateAndGetPackUriComponents internal method
                // to get Package and Part Uri in one step
                Uri packageUri;
                Uri partUri;
                PackUriHelper.ValidateAndGetPackUriComponents(uri, out packageUri, out partUri);

                Package package = PreloadedPackages.GetPackage(packageUri);

                Uri parentPackageUri = null;

                if (parentUri != null)
                {
                    parentPackageUri = PackUriHelper.GetPackageUri(parentUri);
                    if (!parentPackageUri.Equals(packageUri))
                    {
                        throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUriNotInSamePackage));
                    }
                }

                schema.ValidateRelationships(new SecurityCriticalData <Package>(package), packageUri, partUri, mimeType);

                if (schema.AllowsMultipleReferencesToSameUri(mimeType))
                {
                    _uniqueUriRef = null;
                }
                else
                {
                    _uniqueUriRef = new Hashtable(11);
                }

                Hashtable validResources = (_validResources.Count > 0 ? _validResources.Peek() : null);
                if (schema.HasRequiredResources(mimeType))
                {
                    validResources = new Hashtable(11);

                    PackagePart part = package.GetPart(partUri);
                    PackageRelationshipCollection requiredResources = part.GetRelationshipsByType(_requiredResourceRel);

                    foreach (PackageRelationship relationShip in requiredResources)
                    {
                        Uri targetUri    = PackUriHelper.ResolvePartUri(partUri, relationShip.TargetUri);
                        Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);

                        PackagePart targetPart = package.GetPart(targetUri);

                        if (schema.IsValidRequiredResourceMimeType(targetPart.ValidatedContentType))
                        {
                            if (!validResources.ContainsKey(absTargetUri))
                            {
                                validResources.Add(absTargetUri, true);
                            }
                        }
                        else
                        {
                            if (!validResources.ContainsKey(absTargetUri))
                            {
                                validResources.Add(absTargetUri, false);
                            }
                        }
                    }
                }

                XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType,
                                                                               stream, packageUri, partUri);
                _validResources.Push(validResources);
                if (rootElement != null)
                {
                    xpsSchemaValidator.XmlReader.MoveToContent();

                    if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name))
                    {
                        throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUnsupportedMimeType));
                    }

                    while (xpsSchemaValidator.XmlReader.Read())
                    {
                        ;
                    }
                }
                else
                {
                    obj = XamlReader.Load(xpsSchemaValidator.XmlReader,
                                          pc,
                                          XamlParseMode.Synchronous);
                }
                _validResources.Pop();
            }

            return(obj);
        }