Ticket #4236: 0001-Handle-create-web-view-signal-and-open-a-new-tab-SL-.2.patch

File 0001-Handle-create-web-view-signal-and-open-a-new-tab-SL-.2.patch, 4.3 KB (added by humitos, 11 years ago)

v2 - this patch removes the hanlding of the signal 'new-window-policy-decision-requested' and handle 'web-view-ready' to be sure that we can show the WebView

  • browser.py

    From c188e91aa27388e21fb42ceb92d0009e03505c8d Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Thu, 22 Nov 2012 11:41:12 -0300
    Subject: [PATCH Browse] Handle 'create-web-view' signal and open a new tab SL
     #4236
    
    There are some cases that WebKit.WebView needs to create a new
    WebKit.WebView (e.g. to open a pop up window) and it emits this
    signal. Handling this signal we are able to insert a new tab (instead
    of creating a new window) and attach it next to the current one with
    the desired url to be load.
    
    The signal 'new-window-policy-decision-requested' was removed because
    it is not more needed because 'create-web-view' will work for all kind
    of popups.
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     browser.py | 48 +++++++++++++++++++++++++++++++-----------------
     1 file changed, 31 insertions(+), 17 deletions(-)
    
    diff --git a/browser.py b/browser.py
    index 8af7a4a..e6df46f 100644
    a b class TabbedView(BrowserNotebook): 
    195195        new_browser.load_uri(url)
    196196        new_browser.grab_focus()
    197197
     198    def __create_web_view_cb(self, web_view, frame):
     199        new_web_view = Browser()
     200        new_web_view.connect('web-view-ready', self.__web_view_ready_cb)
     201        return new_web_view
     202
     203    def __web_view_ready_cb(self, web_view):
     204        """
     205        Handle new window requested and open it in a new tab.
     206
     207        This callback is called when the WebKit.WebView request for a
     208        new window to open (for example a call to the Javascript
     209        function 'window.open()' or target="_blank")
     210
     211        web_view -- the new browser there the url of the
     212                    window.open() call will be loaded.
     213
     214                    This object is created in the signal callback
     215                    'create-web-view'.
     216        """
     217
     218        web_view.connect('new-tab', self.__new_tab_cb)
     219        web_view.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
     220        web_view.connect('create-web-view', self.__create_web_view_cb)
     221        web_view.grab_focus()
     222
     223        self._insert_tab_next(web_view)
     224
    198225    def __open_pdf_in_new_tab_cb(self, browser, url):
    199226        tab_page = PDFTabPage()
    200227        tab_page.browser.connect('new-tab', self.__new_tab_cb)
    class TabbedView(BrowserNotebook): 
    227254        browser = Browser()
    228255        browser.connect('new-tab', self.__new_tab_cb)
    229256        browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
     257        browser.connect('web-view-ready', self.__web_view_ready_cb)
     258        browser.connect('create-web-view', self.__create_web_view_cb)
    230259
    231260        if next_to_current:
    232261            self._insert_tab_next(browser)
    class TabbedView(BrowserNotebook): 
    352381                browser = Browser()
    353382                browser.connect('new-tab', self.__new_tab_cb)
    354383                browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
     384                browser.connect('web-view-ready', self.__web_view_ready_cb)
     385                browser.connect('create-web-view', self.__create_web_view_cb)
    355386                self._append_tab(browser)
    356387                browser.set_history(tab_history)
    357388
    class Browser(WebKit.WebView): 
    504535        self.connect('download-requested', self.__download_requested_cb)
    505536        self.connect('mime-type-policy-decision-requested',
    506537                     self.__mime_type_policy_cb)
    507         self.connect('new-window-policy-decision-requested',
    508                      self.__new_window_policy_cb)
    509538        self.connect('load-error', self.__load_error_cb)
    510539
    511540        ContentInvoker(self)
    class Browser(WebKit.WebView): 
    631660
    632661        return False
    633662
    634     def __new_window_policy_cb(self, webview, webframe, request,
    635                                navigation_action, policy_decision):
    636         """Open new tab instead of a new window.
    637 
    638         Browse doesn't support many windows, as any Sugar activity.
    639         So we will handle the request, ignoring it and returning True
    640         to inform WebKit that a decision was made.  And we will open a
    641         new tab instead.
    642 
    643         """
    644         policy_decision.ignore()
    645         uri = request.get_uri()
    646         self.open_new_tab(uri)
    647         return True
    648 
    649663    def __download_requested_cb(self, browser, download):
    650664        downloadmanager.add_download(download, browser)
    651665        return True