From bf70bc188c5a2773bb6c239e1c377ae81a6d19a0 Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Fri, 14 Aug 2020 18:26:28 -0700 Subject: [PATCH] Do not open new windows for internal _blank links In general, the desktop app should work in a single window. Closes #7 --- src/kolibri_gnome/desktop_launcher/application.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/kolibri_gnome/desktop_launcher/application.py b/src/kolibri_gnome/desktop_launcher/application.py index 0d4cff82..5a4501de 100644 --- a/src/kolibri_gnome/desktop_launcher/application.py +++ b/src/kolibri_gnome/desktop_launcher/application.py @@ -220,6 +220,7 @@ def __init__(self, *args, **kwargs): def show(self): # TODO: Implement this in pyeverywhere + self.gtk_webview.connect('decide-policy', self.__gtk_webview_on_decide_policy) self.gtk_webview.connect("create", self.__gtk_webview_on_create) # Maximize windows on Endless OS @@ -228,6 +229,17 @@ def show(self): super().show() + def __gtk_webview_on_decide_policy(self, webview, decision, decision_type): + if decision_type == WebKit2.PolicyDecisionType.NEW_WINDOW_ACTION: + # Force internal _blank links to open in the same window + target_uri = decision.get_request().get_uri() + frame_name = decision.get_frame_name() + if frame_name == '_blank' and self.delegate.is_kolibri_app_url(target_uri): + decision.ignore() + pew.ui.run_on_main_thread(self.load_url, target_uri) + return True + return False + def __gtk_webview_on_create(self, webview, navigation_action): # TODO: Implement this behaviour in pyeverywhere, and pass the related # webview to the new window so it can use