[blam] ItemView: Don't open iframes on the browser



commit c8bfed32fdb0678d6d92b493153f68119b28220d
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Mon Feb 7 23:27:12 2011 +0100

    ItemView: Don't open iframes on the browser
    
    Only open a navigation request on the browser if the user was hovering
    on the link.
    
    I.e. don't open the facebook iframe on the browser if a post has it.

 src/ItemView.cs |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/src/ItemView.cs b/src/ItemView.cs
index 204ba01..1407a62 100644
--- a/src/ItemView.cs
+++ b/src/ItemView.cs
@@ -27,7 +27,7 @@ namespace Imendio.Blam {
 #endif
 	private Imendio.Blam.Item currentItem;
     private string baseDir = null;
-
+	private string last_link = null;
 	public bool PageLoaded;
 
         public event StringUpdatedHandler OnUrl;
@@ -69,24 +69,27 @@ namespace Imendio.Blam {
 
 		webView.NavigationRequested += delegate (object sender, NavigationRequestedArgs args) {
         try {
-            /* Allow our local files to be downloaded. Needed to load the theme */
-            if(args.Request.Uri.StartsWith(baseDir)){
-                    args.RetVal = NavigationResponse.Accept;
-                    return;
-            }
-            Gnome.Url.Show(args.Request.Uri);
-                    args.RetVal = NavigationResponse.Ignore;
+			/*
+			 * If last_link is the same as args.Request.Uri, the user clicked on a link
+			 * (as we know he was hovering). Thus, try to open it on the browser
+			 */
+			if(args.Request.Uri.Equals(last_link)){
+				Gnome.Url.Show(args.Request.Uri);
+				args.RetVal = NavigationResponse.Ignore;
+			} else {
+				/* Otherwise, it's part of the post, so accept it (like the facebook iframe) */
+				args.RetVal = NavigationResponse.Accept;
+			}
         }
         catch (Exception e) {
             Console.Error.WriteLine("Couldn't show URL: " + args.Request.Uri + e.Message);
         }
-
-				args.RetVal = NavigationResponse.Ignore;
 		};
 
             webView.HoveringOverLink += delegate (object sender, HoveringOverLinkArgs args) {
                 if (OnUrl != null)
                   OnUrl (args.Link);
+				  last_link = args.Link;
             };
 
             webView.Show ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]