8000 Cleanup #if NETFX guarded code and remove XBAP related types by vatsan-madhavan · Pull Request #1009 · dotnet/wpf · GitHub
[go: up one dir, main page]

Skip to content

Cleanup #if NETFX guarded code and remove XBAP related types #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove #if NETFX from NavigationService
  • Loading branch information
vatsan-madhavan committed Jun 18, 2019
commit e4f265e853b0bc571b12bc018478cc619f699c57
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,7 @@ private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
}
else
{
#if NETFX
if (Application.InBrowserHostedApp())
{
LaunchResult launched = LaunchResult.NotLaunched;

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

launched = AppSecurityManager.SafeLaunchBrowserOnlyIfPossible(CurrentSource, bpu, target, true /*IsTopLevelContainer*/);

if (launched == LaunchResult.NotLaunched)
{
throw new System.Exception(SR.Get(SRID.FailToNavigateUsingHyperlinkTarget));
}
}
else
#endif
{
throw new System.ArgumentException(SR.Get(SRID.HyperLinkTargetNotFound));
}
throw new System.Argumen 8000 tException(SR.Get(SRID.HyperLinkTargetNotFound));
}
}

Expand Down Expand Up @@ -451,35 +430,6 @@ private JournalNavigationScope EnsureJournal()
return _journalScope;
}

private bool IsParentedByBrowserWindow()
{
// We want to update browser related state only if
//
// 1. There's no window associated with this NavigationService (meaning that this NavigationService)
// was created by Application) and if we're hosted in the Browser i.e BCBS is not null
//
// or
//
// 2. The window associated with this NavigationService is a RootBrowserWindow (meaning that we're
// hosted in the browser and RBW is navigated
// and
// we are not in a Frame with its own Journal.
//
#if NETFX
if (this.Application != null &&
this.Application.CheckAccess())
{
if ((JournalScope != null && JournalScope.NavigatorHost is RootBrowserWindow) ||
(JournalScope == null &&
this.Application.BrowserCallbackServices != null))
{
return true;
}
}
#endif
return false;
}

bool IsConsistent(NavigateInfo navInfo)
{
return navInfo == null
Expand Down Expand Up @@ -523,76 +473,6 @@ private bool RestoreRootViewerState(CustomJournalStateInternal rvs)
return true;
}

#if NETFX
/// <summary>
/// When it is top level navigation away from loose XAML (not the intial navigation to the loose xaml,
/// nor a refresh), we want to delegate to the browser right away. There is no need to go through our
/// navigation process, because no matter what content type (xaml, html...) it is trying to navigate to,
/// we always let the browser handle it when it is top-level navigation from inside XamlViewer.
///
/// V3 SP1 Optimization:
/// We can avoid the cost of recycling the host process when:
/// 1) The new content is from the same site-of-origin. This way there is no danger of cross-domain
/// attacks made possible by poor cleanup. See SecurityNote below.
/// 2) We can update the address bar with the new URL, or there is no address bar, which is when
/// XamlViewer is hosted in an HTML frame.
/// </summary>
/// <remarks>
/// This function may return false and we still end up delegating to the browser. This will be the
/// case when the top-level navigation is to something other than XAML. GetObjectFromResponse()
/// handles this case.
/// </remarks>
/// <SecurityNote>
/// There is no check for same site-of-origin here. A call to SecurityHelper.CallerHasWebPermission(
/// resolvedUri) could be added, but that would create an additional, redundant code path in
/// navigation. Here's what happens when the new URI is outside the site-of-origin:
/// - For `http://, CreateWebRequest() gets a SecurityException and delegates to the browser.
/// - For file://, HandleGetResponse() gets a SecurityException from
/// (File)WebRequest.EndGetResponse() and similarly delegates to the browser.
/// </SecurityNote>
private bool ShouldDelegateXamlViewerNavigationToBrowser(NavigateInfo navigateInfo, Uri resolvedUri)
{
bool shouldDelegate = false;
if (BrowserInteropHelper.IsViewer)
{
Invariant.Assert(resolvedUri != null && resolvedUri.IsAbsoluteUri);
shouldDelegate = !BrowserInteropHelper.IsInitialViewerNavigation &&
(navigateInfo == null || navigateInfo.NavigationMode != NavigationMode.Refresh) &&
IsTopLevelContainer &&
// except when we can update the address bar or we are in a frame:
!(!BrowserInteropHelper.IsAvalonTopLevel || HasTravelLogIntegration);
}
return shouldDelegate;
}


/// <SecurityNote>
/// Critical: Calls IBCS.UpdateAddressBar(), which can be used for URL spoofing.
/// Safe: The browser's address bar is updated only when XamlViewer navigates to another loose XAML
/// file, with the URL of that file. (Also when doing fragment navigation within a document.)
/// To prevent spoofing of _currentSource with a URL outside the site of origin, a web permission
/// Demand is made. (It's okay for a site to show one page while the address bar is pointing to
/// another from the same site. This is equivalent to using a frame that occupies the entire
/// content area...)
/// </SecurityNote>
[SecurityCritical, SecurityTreatAsSafe]
void UpdateAddressBarForLooseXaml()
{
if (BrowserInteropHelper.IsViewer && !BrowserInteropHelper.IsInitialViewerNavigation &&
IsTopLevelContainer)
{
Uri source = _currentSource;
if (PackUriHelper.IsPackUri(source))
{
source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
}
Invariant.Assert(_navigatorHost != null && _navigatorHost == Application.MainWindow &&
source.IsAbsoluteUri && !PackUriHelper.IsPackUri(source));
SecurityHelper.DemandWebPermission(source);
this.Application.BrowserCallbackServices.UpdateAddressBar(source.ToString());
}
}
#endif

#endregion Private Methods

Expand Down Expand Up @@ -1150,22 +1030,6 @@ private bool OnBeforeSwitchContent(Object newBP, NavigateInfo navInfo, Uri newUr

Debug.Assert(_navigateQueueItem == null);

#if NETFX
// Workaround for the reentrance problem from browser (bug 128689).
// Call into browser before we update journal. If there is another navigation waiting, e.g,
// user starts a new navigation using the browser back/forward button, it will
// re-enter with this call. We can detect whether a new navigation has started by checking
// _navigateQueueItem. The goal is to check for reentrance before we update journal. It should
// be safe to cancel the current navigation at this point (before any journal changes).
if (HasTravelLogIntegration)
{
DispatchPendingCallFromBrowser();
if (_navigateQueueItem != null)
{
return false;
}
}
#endif

if (navInfo == null)
{
Expand All @@ -1176,8 +1040,6 @@ private bool OnBeforeSwitchContent(Object newBP, NavigateInfo navInfo, Uri newUr
UpdateJournal(navInfo.NavigationMode, JournalReason.NewContentNavigation, navInfo.JournalEntry);
}

// Check for reentrance again before we proceed. UpdateJournal calls CallUpdateTravelLog which calls
// into browser that can cause a new navigation to reenter.
// Future:
// The journal entry of the new page that is navigated to might be lost because the navigation is
// cancelled after the current page being added to jounral. E.g, The journal looks like:
Expand Down Expand Up @@ -1217,19 +1079,6 @@ private bool OnBeforeSwitchContent(Object newBP, NavigateInfo navInfo, Uri newUr
return true;
}

#if NETFX
// Allow new navigations from browser to re-enter with this call.
///<SecurityNote>
/// Critical - calls back to browser to get the browser top.
/// TreatAsSafe - this value isn't returned or stored.
///</SecurityNote>
[SecurityCritical, SecurityTreatAsSafe]
private void DispatchPendingCallFromBrowser()
{
BrowserInteropHelper.HostBrowser.GetTop();
}
#endif

/// <summary>
/// Called when style is actually applied.
/// </summary>
Expand Down Expand Up @@ -1771,24 +1620,8 @@ internal bool Navigate(Uri source, Object navigationState, bool sandboxExternalC
return true;
}

#if NETFX
if (ShouldDelegateXamlViewerNavigationToBrowser(navInfo, resolvedSource))
{
try
{
DelegateToBrowser(newRequest is PackWebRequest, resolvedSource);
}
finally
{
ResetPendingNavigationState(NavigationStatus.Idle);
}
}
else
#endif
{
// Post the navigate Dispatcher operation
_navigateQueueItem.PostNavigation();
}
// Post the navigate Dispatcher operation
_navigateQueueItem.PostNavigation();

return true;
}
Expand Down Expand Up @@ -2440,9 +2273,6 @@ private void FireNavigated(object navState)
private void HandleNavigated(object navState, bool navigatedToNewContent)
{
Debug.Assert(_navStatus == NavigationStatus.Navigated);
#if NETFX
UpdateAddressBarForLooseXaml();
#endif
BrowserInteropHelper.IsInitialViewerNavigation = false;

NavigateInfo navInfo = navState as NavigateInfo;
Expand Down Expand Up @@ -3122,13 +2952,6 @@ private void HandleWebResponse(IAsyncResult ar)
}
}

private bool CanUseTopLevelBrowserForHTMLRendering()
{
return (IsTopLevelContainer
&& IsParentedByBrowserWindow()
);
}

// Create Object from the return of WebResponse stream
private void GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
{
Expand Down Expand Up @@ -3166,14 +2989,12 @@ private void GetObjectFromResponse(WebRequest request, WebResponse response, Uri
_webResponse = response;
_asyncObjectConverter = null;

#if NETFX
Invariant.Assert(!ShouldDelegateXamlViewerNavigationToBrowser(navigateInfo, destinationUri),
"TopLevel navigation away from loose xaml is already delageted to browser. It should never reach here.");
#endif

// CanUseTopLevelBrowserForHTMLRendering() will be true for TopLevel navigation away from browser hosted app. If that is the case
// canUseTopLevelBrowserForHTMLRendering will be true for TopLevel navigation away from browser hosted app. If that is the case
// o will be null.
Object o = MimeObjectFactory.GetObjectAndCloseStream(bindStream, contentType, destinationUri, CanUseTopLevelBrowserForHTMLRendering(), sandBoxContent, true /*allowAsync*/, IsJournalNavigation(navigateInfo), out _asyncObjectConverter);
// We don't support browser hosting since .NET Core 3.0, so therefore canUseTopLevelBrowserForHTMLRendering = false
bool canUseTopLevelBrowserForHTMLRendering = false;
Object o = MimeObjectFactory.GetObjectAndCloseStream(bindStream, contentType, destinationUri, canUseTopLevelBrowserForHTMLRendering, sandBoxContent, true /*allowAsync*/, IsJournalNavigation(navigateInfo), out _asyncObjectConverter);

if (o != null)
{
Expand Down Expand Up @@ -3403,10 +3224,6 @@ private JournalEntry UpdateJournal(

journalScope.Journal.UpdateCurrentEntry(journalEntry);

if (journalEntry.IsNavigable())
{
CallUpdateTravelLog(navigationMode == NavigationMode.New);
}

if (navigationMode == NavigationMode.New)
{
Expand Down Expand Up @@ -3638,31 +3455,6 @@ internal void RequestCustomContentStateOnAppShutdown()
FireNavigating(null, null, null, null); // sets _customContentStateToSave
}

/// <SecurityNote>
/// Critical - elevates permissions to call UpdateTravellog by calling a SUC'ed PInvoke
/// TreatAsSafe - we're callling to update the travellog.
/// information passed back is whether we're a top-level container, and whether to add a new entry.
///
/// Net effect is creation of a new journal entry. Considered safe as the information stored in the journal is derived from what's been navigated to.
/// We could have the same effect via programmatically allowing a navigate OR calling NavigationWindow.GoBack().
/// </SecurityNote>
[SecurityCritical, SecurityTreatAsSafe]
internal void CallUpdateTravelLog(bool addNewEntry)
{
#if NETFX
// Not explicitly checking IsSerializable here because we will be called back
// immediately via SaveHistory which will throw the serialization exception which
// will give us the same effect and without the overhead of an explicit
// GetType + type.IsSerializable check. But if the subclass has data members
// that are not serializable we will still throw an exception inspite of
// IsSerializable == true for the subclass.

if (HasTravelLogIntegration)
{
this.Application.BrowserCallbackServices.UpdateTravelLog(addNewEntry);
}
#endif
}

/// <summary>
/// Returns the current Application
Expand Down Expand Up @@ -3749,23 +3541,6 @@ private FinishEventHandler FinishHandler
}
}

#if NETFX
/// <SecurityNote>
/// Critical: Uses ApplicationProxyInternal.Current, which is Critical.
/// Safe: Only ApplicationProxyInternal.HasTravelLogIntegration is accessed, which is okay to give out.
/// </SecurityNote>
private bool HasTravelLogIntegration
{
[SecurityCritical, SecurityTreatAsSafe]
get
{
return IsParentedByBrowserWindow() &&
ApplicationProxyInternal.Current.RootBrowserWindow.HasTravelLogIntegration;
return false;
}
}
#endif

private bool IsTopLevelContainer
{
get
Expand Down
0