[Sugar-devel] [PATCH Browse] Handle new windows request and instead open links in new tabs #3507

Manuel Quiñones manuq at laptop.org
Wed Apr 25 14:55:28 EDT 2012


Browse being a Sugar activity only has one full screen window.  This
patchs adds a callback to the new window policy decision requested
signal and handles new links in new tabs.

If in need, we can also take the decision to not open the link, using:

reason = navigation_action.get_reason()

I have not come to a reason to do that yet.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 browser.py |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/browser.py b/browser.py
index f35ded3..259d888 100644
--- a/browser.py
+++ b/browser.py
@@ -490,6 +490,8 @@ class Browser(WebKit.WebView):
         self.connect('download-requested', self.__download_requested_cb)
         self.connect('mime-type-policy-decision-requested',
                      self.__mime_type_policy_cb)
+        self.connect('new-window-policy-decision-requested',
+                     self.__new_window_policy_cb)
 
     def get_history(self):
         """Return the browsing history of this browser."""
@@ -591,6 +593,21 @@ class Browser(WebKit.WebView):
             policy_decision.download()
         return True
 
+    def __new_window_policy_cb(self, webview, webframe, request,
+                               navigation_action, policy_decision):
+        """Open new tab instead of a new window.
+
+        Browse doesn't support many windows, as any Sugar activity.
+        So we will handle the request, ignoring it and returning True
+        to inform WebKit that a decision was made.  And we will open a
+        new tab instead.
+
+        """
+        policy_decision.ignore()
+        uri = request.get_uri()
+        self.open_new_tab(uri)
+        return True
+
     def __download_requested_cb(self, browser, download):
         downloadmanager.add_download(download, browser)
         return True
-- 
1.7.7.6



More information about the Sugar-devel mailing list