Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Internal / AppModel / AppModelKnownContentFactory.cs / 1 / 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; 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(); return new WebBrowser(baseUri);; } else { ParserContext pc = new ParserContext(); pc.BaseUri = baseUri; pc.SkipJournaledProperties = isJournalNavigation; pc.XamlTypeMapper = XmlParserDefaults.DefaultMapper; 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(); return new WebBrowser(baseUri); } } } // 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
- ByteArrayHelperWithString.cs
- SecurityPolicySection.cs
- SqlUDTStorage.cs
- CanExecuteRoutedEventArgs.cs
- X509WindowsSecurityToken.cs
- CompilationUnit.cs
- VisualCollection.cs
- MostlySingletonList.cs
- PlainXmlWriter.cs
- SharedPerformanceCounter.cs
- SystemColors.cs
- DataGridColumnStyleMappingNameEditor.cs
- ModelTypeConverter.cs
- EngineSiteSapi.cs
- AutomationPatternInfo.cs
- MessageProtectionOrder.cs
- AggregatePushdown.cs
- SamlAssertion.cs
- JsonWriterDelegator.cs
- EventManager.cs
- RequiredFieldValidator.cs
- AuthenticatedStream.cs
- HttpCacheVaryByContentEncodings.cs
- SoundPlayer.cs
- BookmarkScopeHandle.cs
- CustomAttributeBuilder.cs
- Formatter.cs
- TableLayoutStyleCollection.cs
- GetCryptoTransformRequest.cs
- SqlHelper.cs
- UnauthorizedAccessException.cs
- brushes.cs
- TextTreeRootTextBlock.cs
- FunctionDetailsReader.cs
- SparseMemoryStream.cs
- FocusTracker.cs
- SelectionEditor.cs
- Positioning.cs
- RootProfilePropertySettingsCollection.cs
- RequestNavigateEventArgs.cs
- NamespaceInfo.cs
- ScrollItemPattern.cs
- DbConnectionStringBuilder.cs
- ComponentSerializationService.cs
- TryCatchDesigner.xaml.cs
- OperatingSystem.cs
- EntityDataSourceChangedEventArgs.cs
- sqlser.cs
- WindowsGraphicsWrapper.cs
- SizeAnimation.cs
- XmlAnyAttributeAttribute.cs
- AccessKeyManager.cs
- DesignerView.cs
- FlowLayoutPanel.cs
- NullExtension.cs
- CancelEventArgs.cs
- PerformanceCounterPermission.cs
- TreeViewDesigner.cs
- ObjectConverter.cs
- PreviewKeyDownEventArgs.cs
- iisPickupDirectory.cs
- Calendar.cs
- ValidatorCompatibilityHelper.cs
- IssuanceLicense.cs
- MouseActionConverter.cs
- ItemContainerProviderWrapper.cs
- ScopedKnownTypes.cs
- StrongNameKeyPair.cs
- EntityDataSourceUtil.cs
- InternalConfigEventArgs.cs
- UnknownBitmapDecoder.cs
- Accessible.cs
- ProfileServiceManager.cs
- TableLayoutSettings.cs
- SourceChangedEventArgs.cs
- Camera.cs
- _Connection.cs
- DependencyPropertyKind.cs
- BooleanStorage.cs
- RequestTimeoutManager.cs
- XPathNodeIterator.cs
- SmtpFailedRecipientsException.cs
- ToolBarOverflowPanel.cs
- TextPenaltyModule.cs
- PrimaryKeyTypeConverter.cs
- VisualBrush.cs
- UserControl.cs
- dsa.cs
- ChannelManager.cs
- Brushes.cs
- TrackPoint.cs
- configsystem.cs
- OperationContractAttribute.cs
- CriticalFinalizerObject.cs
- QilReference.cs
- EdmMember.cs
- EmptyReadOnlyDictionaryInternal.cs
- MenuItemAutomationPeer.cs
- MonthCalendar.cs
- ScheduleChanges.cs