示例#1
0
        /// <summary>
        ///     This is called when the Title dependency property changes in the Window.
        /// </summary>
        internal override void UpdateTitle(string titleStr)
        {
            IBrowserCallbackServices ibcs = Browser;

            if (ibcs != null) // null on shutdown
            {
                string title = PruneTitleString(titleStr);

                // It's not the end of the world if this fails.
                // VS's browser in particular returns RPC_E_CALL_REJECTED.
                // Not sure of other exceptions that might be thrown here,
                // so keeping this scoped to what's been reported.
                const int RPC_E_CALL_REJECTED = unchecked ((int)0x80010001);
                try
                {
                    // SHOULD NOT CALL BASE; BASE IMPLEMENTS TEXT PROPERTY ON WINDOW
                    BrowserInteropHelper.HostBrowser.SetTitle(title);
                }
                catch (COMException e)
                {
                    if (e.ErrorCode != RPC_E_CALL_REJECTED)
                    {
                        throw;
                    }
                }
            }
        }
        internal static LaunchResult SafeLaunchBrowserOnlyIfPossible(Uri originatingUri, Uri destinationUri, string targetName, bool fIsTopLevel)
        {
            LaunchResult launchResult = LaunchResult.NotLaunched;
            bool         flag         = destinationUri.Scheme == Uri.UriSchemeHttp || destinationUri.Scheme == Uri.UriSchemeHttps || destinationUri.IsFile;
            bool         flag2        = string.Compare(destinationUri.Scheme, Uri.UriSchemeMailto, StringComparison.OrdinalIgnoreCase) == 0;

            if (!BrowserInteropHelper.IsInitialViewerNavigation && SecurityHelper.CallerHasUserInitiatedNavigationPermission() && ((fIsTopLevel && flag) || flag2))
            {
                if (flag)
                {
                    IBrowserCallbackServices browserCallbackServices = (Application.Current != null) ? Application.Current.BrowserCallbackServices : null;
                    if (browserCallbackServices != null)
                    {
                        launchResult = AppSecurityManager.CanNavigateToUrlWithZoneCheck(originatingUri, destinationUri);
                        if (launchResult == LaunchResult.Launched)
                        {
                            browserCallbackServices.DelegateNavigation(BindUriHelper.UriToString(destinationUri), targetName, AppSecurityManager.GetHeaders(destinationUri));
                            launchResult = LaunchResult.Launched;
                        }
                    }
                }
                else if (flag2)
                {
                    UnsafeNativeMethods.ShellExecute(new HandleRef(null, IntPtr.Zero), null, BindUriHelper.UriToString(destinationUri), null, null, 0);
                    launchResult = LaunchResult.Launched;
                }
            }
            return(launchResult);
        }
 internal static void UnsafeLaunchBrowser(Uri uri, string targetFrame = null)
 {
     if (Application.Current != null && Application.Current.CheckAccess())
     {
         IBrowserCallbackServices browserCallbackServices = Application.Current.BrowserCallbackServices;
         if (browserCallbackServices != null)
         {
             browserCallbackServices.DelegateNavigation(BindUriHelper.UriToString(uri), targetFrame, AppSecurityManager.GetHeaders(uri));
             return;
         }
     }
     AppSecurityManager.ShellExecuteDefaultBrowser(uri);
 }
示例#4
0
        private void HandleBackForwardStateChange(object sender, EventArgs args)
        {
            if (!this.HasTravelLogIntegration)
            {
                return;
            }
            IBrowserCallbackServices browser = RootBrowserWindow.Browser;

            if (browser != null)
            {
                browser.UpdateBackForwardState();
            }
        }
示例#5
0
        /// <summary>
        /// We are not using the CanGoBack/CanGoForward property change since that is fired only
        /// if the value changes eg. if we had 3 entries in the backstack, then a back navigation
        /// won't fire this since the value is still 'true' and has not changed.
        /// What we need is the UpdateView() notification or the BackForwardState change
        /// notification which is fired from UpdateView() of the Journal.
        /// Trying to hook the event will create the journal even if there was no navigation
        /// so just using an virtual override to do the work.
        /// </summary>
        private void HandleBackForwardStateChange(object sender, EventArgs args)
        {
            //Nothing to do for downlevel platform
            if (!HasTravelLogIntegration)
            {
                return;
            }

            IBrowserCallbackServices ibcs = Browser;

            if (ibcs != null)
            {
                ibcs.UpdateBackForwardState();
            }
        }
示例#6
0
 internal XappLauncherApp(Uri deploymentManifest, string applicationId, IBrowserCallbackServices browser, DocObjHost.ApplicationRunnerCallback applicationRunner, INativeProgressPage nativeProgressPage, string progressPageAssembly, string progressPageClass, string errorPageAssembly, string errorPageClass)
 {
     this._deploymentManifest        = deploymentManifest;
     this._applicationId             = applicationId;
     this._browser                   = browser;
     this._applicationRunnerCallback = applicationRunner;
     this._fwlinkUri                 = null;
     this._requiredCLRVersion        = null;
     base.Startup              += this.XappLauncherApp_Startup;
     base.Exit                 += this.XappLauncherApp_Exit;
     base.Navigated            += this.XappLauncherApp_Navigated;
     this._nativeProgressPage   = nativeProgressPage;
     this._progressPageAssembly = progressPageAssembly;
     this._progressPageClass    = progressPageClass;
     this._errorPageAssembly    = errorPageAssembly;
     this._errorPageClass       = errorPageClass;
 }
示例#7
0
        internal static void UnsafeLaunchBrowser(Uri uri, string targetFrame = null)
        {
            // This'll likely go into SafeLaunchBrowser() function.
            if (Application.Current != null && Application.Current.CheckAccess())
            {
                IBrowserCallbackServices ibcs = Application.Current.BrowserCallbackServices;
                if (ibcs != null)
                {
                    // Browser app.
                    //

                    ibcs.DelegateNavigation(BindUriHelper.UriToString(uri), targetFrame, GetHeaders(uri));
                    return;
                }
            }

            ShellExecuteDefaultBrowser(uri);
        }
示例#8
0
        // This invokes the browser unsafely.
        // Whoever is calling this function should do the right demands.
        internal static void UnsafeLaunchBrowser(Uri uri, string targetFrame = null)
        {
#if NETFX
            // This'll likely go into SafeLaunchBrowser() function.
            if (Application.Current != null && Application.Current.CheckAccess())
            {
                IBrowserCallbackServices ibcs = Application.Current.BrowserCallbackServices;
                if (ibcs != null)
                {
                    // Browser app.
                    // TODO: See if this is the right behavior when clicking on a link in
                    // a secondary window in a multi-window browser app - PS # 840726
                    ibcs.DelegateNavigation(BindUriHelper.UriToString(uri), targetFrame, GetHeaders(uri));
                    return;
                }
            }
#endif

            ShellExecuteDefaultBrowser(uri);
        }
示例#9
0
        internal XappLauncherApp(Uri deploymentManifest, string applicationId,
            IBrowserCallbackServices browser, DocObjHost.ApplicationRunnerCallback applicationRunner,
            INativeProgressPage nativeProgressPage,
            string progressPageAssembly, string progressPageClass, string errorPageAssembly, string errorPageClass) 
        {
            _deploymentManifest = deploymentManifest; 
            _applicationId = applicationId; 
            _browser = browser;
            _applicationRunnerCallback = applicationRunner; 
            _fwlinkUri = null;
            this.Startup += new StartupEventHandler(XappLauncherApp_Startup);
            this.Exit += new ExitEventHandler(XappLauncherApp_Exit);
            this.Navigated += new NavigatedEventHandler(XappLauncherApp_Navigated); 

            _nativeProgressPage = nativeProgressPage; 
            _progressPageAssembly = progressPageAssembly; 
            _progressPageClass = progressPageClass;
            _errorPageAssembly = errorPageAssembly; 
            _errorPageClass = errorPageClass;
        }
示例#10
0
        internal override void UpdateTitle(string titleStr)
        {
            IBrowserCallbackServices browser = RootBrowserWindow.Browser;

            if (browser != null)
            {
                string title = this.PruneTitleString(titleStr);
                try
                {
                    BrowserInteropHelper.HostBrowser.SetTitle(title);
                }
                catch (COMException ex)
                {
                    if (ex.ErrorCode != -2147418111)
                    {
                        throw;
                    }
                }
            }
        }
 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);
     }
 }
示例#12
0
        internal static LaunchResult SafeLaunchBrowserOnlyIfPossible(Uri originatingUri, Uri destinationUri, string targetName, bool fIsTopLevel)
        {
            LaunchResult launched = LaunchResult.NotLaunched;

            bool isKnownScheme = (Object.ReferenceEquals(destinationUri.Scheme, Uri.UriSchemeHttp)) ||
                                 (Object.ReferenceEquals(destinationUri.Scheme, Uri.UriSchemeHttps)) ||
                                 destinationUri.IsFile;

            bool fIsMailTo = String.Compare(destinationUri.Scheme, Uri.UriSchemeMailto, StringComparison.OrdinalIgnoreCase) == 0;

            // We elevate to navigate the browser iff:
            //  We are user initiated AND
            //      Scheme == http/https & topLevel OR scheme == mailto.
            //
            // For all other cases ( evil protocols etc).
            // We will demand.
            //
            // The check of IsInitialViewerNavigation is necessary because viewer applications will probably
            // need to call Navigate on the URI they receive, but we want them to be able to do it in partial trust.
            if ((!BrowserInteropHelper.IsInitialViewerNavigation &&
                 MS.Internal.PresentationFramework.SecurityHelper.CallerHasUserInitiatedNavigationPermission()) &&
                ((fIsTopLevel && isKnownScheme) || fIsMailTo))
            {
                if (isKnownScheme)
                {
                    IBrowserCallbackServices ibcs = (Application.Current != null) ? Application.Current.BrowserCallbackServices : null;
                    if (ibcs != null)
                    {
                        launched = CanNavigateToUrlWithZoneCheck(originatingUri, destinationUri);
                        if (launched == LaunchResult.Launched)
                        {
                            // resetting launched to NotLaunched here; if the assert succeeds
                            // and ibcs.DelegateNavigation does not throw then we will set it to Launched.
                            launched = LaunchResult.NotLaunched;
                            // Browser app.
                            //

                            ibcs.DelegateNavigation(BindUriHelper.UriToString(destinationUri), targetName, GetHeaders(destinationUri));

                            launched = LaunchResult.Launched;
                        }
                    }
                }
                else if (fIsMailTo)   // unnecessary if - but being paranoid.
                {
                    // Shell-Exec the browser to the mailto url.
                    // assumed safe - because we're only allowing this for mailto urls.
                    //

                    UnsafeNativeMethods.ShellExecute(new HandleRef(null, IntPtr.Zero),          /*hwnd*/
                                                     null,                                      /*operation*/
                                                     BindUriHelper.UriToString(destinationUri), /*file*/
                                                     null,                                      /*parameters*/
                                                     null,                                      /*directory*/
                                                     0);                                        /*nShowCmd*/
                    launched = LaunchResult.Launched;
                }
            }

            return(launched);
        }
示例#13
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);
            }
        }
示例#14
0
 void IBrowserHostServices.SetBrowserCallback(object browserCallbackServices)
 { 
     Invariant.Assert(browserCallbackServices != null, "Browser interop interface passed in should not be null");
     _browserCallbackServices = (IBrowserCallbackServices)browserCallbackServices; 
 } 
示例#15
0
        private void Cleanup(int exitCode)
        { 
            //No error => don't cleanup 
            if (exitCode == 0)
                return; 

            // You need to explicitly release the COM object.  The RCW doesn't
            // seem to get garbage collected automatically.
            // 
            // We don't want to call release multiple times.  So call either
            // on the App or on the Docobj since the ServiceProvider setter 
            // release the  _browserCallbackServices com object 
            if (_appProxyInternal != null)
            { 
                _appProxyInternal.Cleanup();
            }
            else if (_browserCallbackServices != null)
            { 
                Marshal.ReleaseComObject(_browserCallbackServices);
                _browserCallbackServices = null; 
            } 
        }