From 022ef0dd9791af51d7b9de38e813096f2ca60948 Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Wed, 25 Apr 2012 18:43:03 +0000 Subject: Handle new windows request and instead open links in new tabs #3507 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 Acked-by: Simon Schampijer --- 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 -- cgit v0.9.1