예제 #1
0
 /// <summary>
 /// Event is fired by webview when the content is not a webpage, such as a file download
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     appendLog(String.Format("Content for \"{0}\" cannot be loaded into webview. Invoking the default launcher instead.\n", args.Uri.ToString()));
     // We turn around and hand the Uri to the system launcher to launch the default handler for it
     Windows.Foundation.IAsyncOperation <bool> b = Windows.System.Launcher.LaunchUriAsync(args.Uri);
     pageIsLoading = false;
 }
예제 #2
0
 void web_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     if (UnviewableContentIdentified != null)
     {
         UnviewableContentIdentified(sender, args);
     }
 }
예제 #3
0
        /// <summary>
        /// Event is fired by webview when the content is not a webpage, such as a file download
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        async void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            // We turn around and hand the Uri to the system launcher to launch the default handler for it
            await Windows.System.Launcher.LaunchUriAsync(args.Uri);

            pageIsLoading = false;
        }
예제 #4
0
        private async void web_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            this.FindName("_ucDownloadUI");
            _ucDownloadUI.btDownload.Click   += btStartDownload;
            _ucDownloadUI.tsDownload.Toggled += TsDownload_Toggled;
            if (_ucDownloadUI.tsDownload.IsOn)
            {
                ContentDialog cntExisitingDownload = new ContentDialog
                {
                    Content             = "A File is Downloading Currently, let it finish and then try again",
                    Title               = "Another file is Downloading",
                    PrimaryButtonText   = "Ok",
                    SecondaryButtonText = "Check Download"
                };
                cntExisitingDownload.SecondaryButtonClick += (s, a) =>
                {
                    cntExisitingDownload.Hide();
                    _ucDownloadUI.Visibility = Visibility.Visible;
                };
                await cntExisitingDownload.ShowAsync();

                return;
            }
            else
            {
                _ucDownloadUI.txbDownloadLink.Text = args.Uri.ToString();
                _ucDownloadUI.txbFileName.Text     = await UtilityClass.GetFileName(args.Uri);

                _ucDownloadUI.Visibility = Visibility.Visible;
            }
        }
 /// <summary>
 /// Handle the event that indicates that the WebView content is not a web page.
 /// For example, it may be a file download.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void WebViewControl_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     AppendLog($"Content for \"{UriToString(args.Uri)}\" cannot be loaded into webview.");
     // We throw away the request. See the "Unviewable content" scenario for other
     // ways of handling the event.
     pageIsLoading = false;
 }
예제 #6
0
        // 在 WebView 尝试下载不受支持的文件时发生
        void webView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            // 引用页
            // args.Referrer

            // args.Uri
        }
예제 #7
0
 private void MenuWebView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     Debug.WriteLine("Web View Unviewable Content Error... Result: " + args.Uri.ToString());
     networkStatus.Text       = "W.V. Error 102";
     streamStatus.Text        = "Restart the App and notify the Developer";
     networkStatus.Foreground = new SolidColorBrush(Colors.Red);
     streamStatus.Foreground  = new SolidColorBrush(Colors.Red);
 }
        /// <summary>
        /// Event is fired by webview when the content is not a webpage, such as a file download
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        async void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            rootPage.NotifyUser(String.Format("Content for \"{0}\" cannot be loaded into webview. Invoking the default launcher instead.\n", args.Uri.ToString()), NotifyType.ErrorMessage);
            // We turn around and hand the Uri to the system launcher to launch the default handler for it
            await Windows.System.Launcher.LaunchUriAsync(args.Uri);

            pageIsLoading = false;
        }
예제 #9
0
 public void webView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     /*  WebViewPage.InfoDialog.IsOpen = true;
      * WebViewPage.InfoDialog.Title = "Unviewable content";
      * WebViewPage.InfoDialog.IsLightDismissEnabled = false;
      * WebViewPage.InfoDialog.ActionButtonContent = "Launch content";
      * WebViewPage.InfoDialog.ActionButtonClick += LaunchUnviewable;*/
 }
예제 #10
0
        private void WebBrowser_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            Frame root = Window.Current.Content as Frame;

            //这里参数自动装箱
            root.Navigate(typeof(HistoryPage));
            Messenger.Default.Send(new NotificationMessageAction <Uri>(args.Uri, null, item =>
            {
            }), "down");
            //_downLoadFileAsync(args.Uri);
        }
예제 #11
0
    private async void webView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
    {
        if (DataContext is not ViewModels.BrowserControlViewModel dataContext)
        {
            return;
        }

        if (UnviewableContentIdentifiedOverride != null)
        {
            UnviewableContentIdentifiedOverride.Invoke(sender, args, dataContext);
            return;
        }

        try
        {
            var namebody = Path.GetFileNameWithoutExtension(args.Uri.AbsoluteUri);
            namebody = namebody.Length > 32 ? namebody.Substring(0, 32) : namebody;
            var extension = Path.GetExtension(args.Uri.AbsoluteUri);
            extension = string.IsNullOrEmpty(extension) ? MimeTypes.MimeTypeMap.GetExtension(args.MediaType) : extension;

            var item = await(await dataContext.FolderProvider?.Invoke())?.CreateFileAsync(
                namebody + extension
                , Windows.Storage.CreationCollisionOption.GenerateUniqueName);
            if (item is null)
            {
                return;
            }
            var downloader = new BackgroundDownloader();
            var download   = downloader.CreateDownload(args.Uri, item);

            var dlitem = new ViewModels.DownloadItemViewModel(item);
            dataContext?.Downloads.Add(dlitem);

            await download.StartAsync().AsTask(new Progress <DownloadOperation>((t) =>
            {
                try
                {
                    //https://stackoverflow.com/questions/38939720/backgrounddownloader-progress-doesnt-update-in-uwp-c-sharp
                    if (t.Progress.TotalBytesToReceive > 0)
                    {
                        double br             = t.Progress.TotalBytesToReceive;
                        dlitem.DownloadedRate = br / t.Progress.TotalBytesToReceive;
                    }
                }
                catch { }
            }));

            dlitem.DownloadedRate = 1.0;
            OpenFile(item);
        }
        catch { }
    }
  private async void WebViewControl_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     if (args.Uri.AbsolutePath.EndsWith(".pdf"))
     {
         if (await Windows.System.Launcher.LaunchUriAsync(args.Uri))
         {
             rootPage.NotifyUser($"Launched {args.Uri} with system launcher", NotifyType.StatusMessage);
         }
         else
         {
             rootPage.NotifyUser($"Failed to launch {args.Uri}", NotifyType.ErrorMessage);
         }
     } else
     {
         rootPage.NotifyUser($"Blocked unknown file type of {args.Uri}", NotifyType.ErrorMessage);
     }
 }
예제 #13
0
        private async void WebView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            BackgroundDownloader downloader = new BackgroundDownloader();
            Uri          source             = args.Uri;
            FolderPicker picker             = new FolderPicker {
                SuggestedStartLocation = PickerLocationId.Downloads
            };

            picker.FileTypeFilter.Add("*");
            StorageFolder folder = await picker.PickSingleFolderAsync();

            if (folder != null)
            {
                StorageFile testfile = await folder.CreateFileAsync("Help.pdf", CreationCollisionOption.ReplaceExisting);

                DownloadOperation download = downloader.CreateDownload(source, testfile);
                await download.StartAsync();
            }
        }
예제 #14
0
        // 在尝试导航至 WebView 不支持的类型的文件时触发的事件
        private async void WebView3_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            // 文件类型,本例中此值为 "application/pdf"
            string mediaType = args.MediaType;

            // 尝试导航至的 uri(本例中此值为 https://www.apple.com/cn/iphone/business/docs/iOS_Security_Guide.pdf)
            Uri uri = args.Uri;

            // uri 的 referrer(本例中此值为 https://www.apple.com/cn/iphone/business/docs/iOS_Security_Guide.pdf 并不是 uri 的 referrer,为啥?)
            Uri referrer = args.Referrer;

            if (args.Uri.AbsolutePath.EndsWith(".pdf"))
            {
                // 通过 launcher 打开 pdf 文件
                if (await Launcher.LaunchUriAsync(args.Uri))
                {
                }
                else
                {
                }
            }
        }
 /// <summary>
 /// Event is fired by webview when the content is not a webpage, such as a file download
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void FavoriteBrowser_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     IsNavigationCompleted = true;
     Windows.Foundation.IAsyncOperation <bool> b = Windows.System.Launcher.LaunchUriAsync(args.Uri);
     //pageIsLoading = false;
 }
예제 #16
0
 private void wvMain_UnviewableContentIdentified(Windows.UI.Xaml.Controls.WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     SendMessage?.Invoke(null, new ContentViewEventArgs()
     {
         Type = "UnviewableContentIdentified"
     });
 }
예제 #17
0
 /// <summary> 
 /// Event is fired by webview when the content is not a webpage, such as a file download 
 /// </summary> 
 async void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     // We turn around and hand the Uri to the system launcher to launch the default handler for it 
     await Windows.System.Launcher.LaunchUriAsync(args.Uri);
     pageIsLoading = false;
     progress_ring_Main.IsActive = false;
 }
 private void MainWeb_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     this.Frame.Navigate(typeof(DownloadsTab), args.Uri);
 }
 /// <summary>
 /// Handle the event that indicates that the WebView content is not a web page.
 /// For example, it may be a file download.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void WebViewControl_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     AppendLog($"Content for \"{UriToString(args.Uri)}\" cannot be loaded into webview.");
     // We throw away the request. See the "Unviewable content" scenario for other
     // ways of handling the event.
     pageIsLoading = false;
 }
예제 #20
0
 private void wvMain_UnviewableContentIdentified(Windows.UI.Xaml.Controls.WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "UnviewableContentIdentified" });
 }
예제 #21
0
 private void Download(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     new DownloadScript().Download(Site.Source, this);
 }
예제 #22
0
 /// <summary>
 /// Gets the Uniform Resource Identifier (URI) of the page that contains the link to the unviewable content.
 /// </summary>
 /// <param name="e">The requested <see cref="WebViewUnviewableContentIdentifiedEventArgs"/>.</param>
 /// <returns>The URI of the referring page.</returns>
 public static Uri Referrer(this WebViewUnviewableContentIdentifiedEventArgs e) => Resolver.Referrer(e);
		void wbMain_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
		{
		}
예제 #24
0
        private async void WebView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
        {
            await Model.MainModel.Current.DownloadFile(args.Uri.OriginalString);

            await new Windows.UI.Popups.MessageDialog("下载完成").ShowAsync();
        }
예제 #25
0
 void Web_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     ProgressText.Text = text1;
 }
예제 #26
0
 private void webView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     Debug.WriteLine(args.Uri.ToString());
     //Display error message?
 }
예제 #27
0
 void wbMain_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
 }
 private void MenuWebView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     Debug.WriteLine("Web View Unviewable Content Error... Result: " + args.Uri.ToString());
     networkStatus.Text = "W.V. Error 102";
     streamStatus.Text = "Restart the App and notify the Developer";
     networkStatus.Foreground = new SolidColorBrush(Colors.Red);
     streamStatus.Foreground = new SolidColorBrush(Colors.Red);
 }
예제 #29
0
 /// <summary>
 /// Gets the media type of content that can't be viewed.
 /// </summary>
 /// <param name="e">The requested <see cref="WebViewUnviewableContentIdentifiedEventArgs"/>.</param>
 /// <returns>The media type of content that can't be viewed.</returns>
 public static string MediaType(this WebViewUnviewableContentIdentifiedEventArgs e) => Resolver.MediaType(e);
예제 #30
0
 /// <summary>
 /// Event is fired by webview when the content is not a webpage, such as a file download
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 async void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     rootPage.NotifyUser(String.Format("Content for \"{0}\" cannot be loaded into webview. Invoking the default launcher instead.\n", args.Uri.ToString()), NotifyType.ErrorMessage);
     // We turn around and hand the Uri to the system launcher to launch the default handler for it
     await Windows.System.Launcher.LaunchUriAsync(args.Uri);
     pageIsLoading = false;
 }
예제 #31
0
 Uri IWebViewUnviewableContentIdentifiedEventArgsResolver.Uri(WebViewUnviewableContentIdentifiedEventArgs e) => e.Uri;
예제 #32
0
 /// <summary>
 /// Gets the Uniform Resource Identifier (URI) of the content the <see cref="WebView"/> attempted to load.
 /// </summary>
 /// <param name="e">The requested <see cref="WebViewUnviewableContentIdentifiedEventArgs"/>.</param>
 /// <returns>The URI of the content.</returns>
 public static Uri Uri(this WebViewUnviewableContentIdentifiedEventArgs e) => Resolver.Uri(e);
예제 #33
0
 void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     // We turn around and hand the Uri to the system launcher to launch the default handler for it
     Windows.Foundation.IAsyncOperation<bool> b = Windows.System.Launcher.LaunchUriAsync(args.Uri);
     pageIsLoading = false;
 }
예제 #34
0
 Uri IWebViewUnviewableContentIdentifiedEventArgsResolver.Referrer(WebViewUnviewableContentIdentifiedEventArgs e) => e.Referrer;
예제 #35
0
 private void webView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     Windows.Foundation.IAsyncOperation<bool> b = Windows.System.Launcher.LaunchUriAsync(args.Uri);
 }
예제 #36
0
 string IWebViewUnviewableContentIdentifiedEventArgsResolver.MediaType(WebViewUnviewableContentIdentifiedEventArgs e) => e.MediaType;
예제 #37
0
 private void MyWebView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     Windows.Foundation.IAsyncOperation <bool> b =
         Windows.System.Launcher.LaunchUriAsync(args.Uri);
 }
예제 #38
0
 private async void WebViewControl_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     if (args.Uri.AbsolutePath.EndsWith(".pdf"))
     {
         if (await Windows.System.Launcher.LaunchUriAsync(args.Uri))
         {
             rootPage.NotifyUser($"Launched {args.Uri} with system launcher", NotifyType.StatusMessage);
         }
         else
         {
             rootPage.NotifyUser($"Failed to launch {args.Uri}", NotifyType.ErrorMessage);
         }
     }
     else
     {
         rootPage.NotifyUser($"Blocked unknown file type of {args.Uri}", NotifyType.ErrorMessage);
     }
 }
 private void webView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     Debug.WriteLine(args.Uri.ToString());
     //Display error message?
 }
예제 #40
0
 /// <summary>
 /// Event is fired by webview when the content is not a webpage, such as a file download
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void webView1_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     appendLog(String.Format("Content for \"{0}\" cannot be loaded into webview. Invoking the default launcher instead.\n", args.Uri.ToString()));
     // We turn around and hand the Uri to the system launcher to launch the default handler for it
     Windows.Foundation.IAsyncOperation<bool> b = Windows.System.Launcher.LaunchUriAsync(args.Uri);
     pageIsLoading = false;
 }
예제 #41
0
 private async void View_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
 {
     await downloader.Download(args.Uri);
 }