Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / AppModel / AppModelKnownContentFactory.cs / 1305600 / AppModelKnownContentFactory.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Provides a method to turn a baml stream into an object. // // // History: // 11/22/04: [....]: Initial Creation // // //--------------------------------------------------------------------------- using System; using System.IO; using System.Net; // WebPermission. using System.Security; using System.Security.Permissions; using System.Windows; using System.Windows.Markup; using System.Windows.Navigation; using MS.Internal.Controls; using MS.Internal.Navigation; using MS.Internal.Utility; using MS.Internal.Resources; using System.IO.Packaging; using MS.Internal.PresentationFramework; using System.ComponentModel; using System.Windows.Controls; namespace MS.Internal.AppModel { // !!!! Note: Those methods are registered as MimeObjectFactory.StreamToObjectFactoryDelegate. The caller expects the // delgate to close stream. internal static class AppModelKnownContentFactory { //// Creates an object instance from a Baml stream and it's Uri // internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter) { asyncObjectConverter = null; // If this stream comes from outside the application throw // if (!BaseUriHelper.IsPackApplicationUri(baseUri)) { throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources)); } // If this stream comes from a content file also throw Uri partUri = PackUriHelper.GetPartUri(baseUri); string partName, assemblyName, assemblyVersion, assemblyKey; BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey); if (ContentFileHelper.IsContentFile(partName)) { throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources)); } ParserContext pc = new ParserContext(); pc.BaseUri = baseUri; pc.SkipJournaledProperties = isJournalNavigation; return Application.LoadBamlStreamWithSyncInfo(stream, pc); } //// Creates an object instance from a Xaml stream and it's Uri // ////// Critical - Keep track of this, as sandboxing is meant to be a way for an application to /// isolate xaml content from the hosting application. /// TreatAsSafe - the act of putting this content in a new webbrowser control (and by extention, a new PresentationHost) /// isolates the xaml content from the rest of the application. /// [SecurityCritical, SecurityTreatAsSafe] 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); } } } private static void OnParserComplete(object sender, AsyncCompletedEventArgs args) { // We can get this event from cancellation. We do not care about the error if there is any // that happened as a result of cancellation. if ((! args.Cancelled) && (args.Error != null)) { throw args.Error; } } 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(); WebBrowser webBrowser = new WebBrowser(); webBrowser.Source = baseUri; return webBrowser; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Provides a method to turn a baml stream into an object. // // // History: // 11/22/04: [....]: Initial Creation // // //--------------------------------------------------------------------------- using System; using System.IO; using System.Net; // WebPermission. using System.Security; using System.Security.Permissions; using System.Windows; using System.Windows.Markup; using System.Windows.Navigation; using MS.Internal.Controls; using MS.Internal.Navigation; using MS.Internal.Utility; using MS.Internal.Resources; using System.IO.Packaging; using MS.Internal.PresentationFramework; using System.ComponentModel; using System.Windows.Controls; namespace MS.Internal.AppModel { // !!!! Note: Those methods are registered as MimeObjectFactory.StreamToObjectFactoryDelegate. The caller expects the // delgate to close stream. internal static class AppModelKnownContentFactory { //// Creates an object instance from a Baml stream and it's Uri // internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter) { asyncObjectConverter = null; // If this stream comes from outside the application throw // if (!BaseUriHelper.IsPackApplicationUri(baseUri)) { throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources)); } // If this stream comes from a content file also throw Uri partUri = PackUriHelper.GetPartUri(baseUri); string partName, assemblyName, assemblyVersion, assemblyKey; BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey); if (ContentFileHelper.IsContentFile(partName)) { throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources)); } ParserContext pc = new ParserContext(); pc.BaseUri = baseUri; pc.SkipJournaledProperties = isJournalNavigation; return Application.LoadBamlStreamWithSyncInfo(stream, pc); } //// Creates an object instance from a Xaml stream and it's Uri // ////// Critical - Keep track of this, as sandboxing is meant to be a way for an application to /// isolate xaml content from the hosting application. /// TreatAsSafe - the act of putting this content in a new webbrowser control (and by extention, a new PresentationHost) /// isolates the xaml content from the rest of the application. /// [SecurityCritical, SecurityTreatAsSafe] 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); } } } private static void OnParserComplete(object sender, AsyncCompletedEventArgs args) { // We can get this event from cancellation. We do not care about the error if there is any // that happened as a result of cancellation. if ((! args.Cancelled) && (args.Error != null)) { throw args.Error; } } 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(); WebBrowser webBrowser = new WebBrowser(); webBrowser.Source = baseUri; return webBrowser; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataListItemCollection.cs
- HighlightOverlayGlyph.cs
- XmlSchemaDocumentation.cs
- HtmlControlDesigner.cs
- CatalogPartCollection.cs
- ExpressionConverter.cs
- UntrustedRecipientException.cs
- KeyValuePairs.cs
- Qualifier.cs
- CustomErrorCollection.cs
- MergeLocalizationDirectives.cs
- LoginView.cs
- sqlmetadatafactory.cs
- HwndSourceParameters.cs
- TypeForwardedToAttribute.cs
- MaterialGroup.cs
- UnicodeEncoding.cs
- SR.Designer.cs
- VirtualPathProvider.cs
- TypedTableBaseExtensions.cs
- EntryPointNotFoundException.cs
- DecoderExceptionFallback.cs
- EventLogPermissionEntryCollection.cs
- IntegerValidator.cs
- ThrowHelper.cs
- __Filters.cs
- MimeTypeAttribute.cs
- Point3DValueSerializer.cs
- BaseValidatorDesigner.cs
- CacheSection.cs
- OpenTypeLayoutCache.cs
- PolygonHotSpot.cs
- DataGrid.cs
- TextSelectionHelper.cs
- SmiGettersStream.cs
- ContainerUIElement3D.cs
- LifetimeServices.cs
- LinkUtilities.cs
- RegexWriter.cs
- LineGeometry.cs
- HttpListenerRequestTraceRecord.cs
- WebPartVerb.cs
- AnimatedTypeHelpers.cs
- Registry.cs
- ListViewItem.cs
- ProxyAttribute.cs
- PropertyTabAttribute.cs
- ThreadStartException.cs
- TypeCollectionDesigner.xaml.cs
- ChannelTracker.cs
- HtmlElementCollection.cs
- Splitter.cs
- COM2PropertyDescriptor.cs
- Frame.cs
- CommunicationObjectFaultedException.cs
- util.cs
- SqlParameter.cs
- BufferedGraphicsContext.cs
- PagesChangedEventArgs.cs
- DataRowExtensions.cs
- BitmapEffectvisualstate.cs
- FileChangesMonitor.cs
- SynchronizationLockException.cs
- NativeMethods.cs
- SessionStateSection.cs
- BaseResourcesBuildProvider.cs
- WinEventHandler.cs
- ValidationErrorCollection.cs
- UInt32Storage.cs
- PropertyBuilder.cs
- SharedUtils.cs
- DataGridViewBand.cs
- PersonalizationStateInfo.cs
- MethodToken.cs
- documentsequencetextcontainer.cs
- SystemWebCachingSectionGroup.cs
- ComplexBindingPropertiesAttribute.cs
- basecomparevalidator.cs
- WebBrowserNavigatingEventHandler.cs
- PersonalizationStateInfoCollection.cs
- TextFormatterContext.cs
- TimelineGroup.cs
- SystemIPInterfaceStatistics.cs
- MetadataWorkspace.cs
- ZipIORawDataFileBlock.cs
- MutexSecurity.cs
- FormsAuthentication.cs
- XmlSchemaAny.cs
- ValueSerializerAttribute.cs
- DrawingVisualDrawingContext.cs
- validationstate.cs
- NumberSubstitution.cs
- DetailsViewUpdatedEventArgs.cs
- FrameworkPropertyMetadata.cs
- ScriptBehaviorDescriptor.cs
- UnsafeNativeMethods.cs
- ImageDesigner.cs
- MemberJoinTreeNode.cs
- _WebProxyDataBuilder.cs
- CodeStatementCollection.cs