// <summary> // Creates an object instance from a Baml stream and it's Uri // </summary> 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)); }
// Return uri's extension or null if no extension. private string GetPartExtension(Uri partUri) { // partUri is the part's path as exposed by its part uri, so it cannot be null. Invariant.Assert(partUri != null); string path = InternalPackUriHelper.GetStringForPartUri(partUri); string extension = Path.GetExtension(path); if (extension == string.Empty) { return(null); } return(extension); }
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; } } }