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

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

Patch that handles 'create-web-view'

  • browser.py

    From 755b91e96b5d78e0fc4e588539b3feabba0f6973 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.
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     browser.py | 34 ++++++++++++++++++++++++++++++++++
     1 file changed, 34 insertions(+)
    
    diff --git a/browser.py b/browser.py
    index 8af7a4a..2c29d1d 100644
    a b class TabbedView(BrowserNotebook): 
    195195        new_browser.load_uri(url)
    196196        new_browser.grab_focus()
    197197
     198    def __new_window_cb(self, browser, new_browser):
     199        """
     200        Handle new window requested and open it in a new tab.
     201
     202        This callback is called when the WebKit.WebView request for a
     203        new window to open (for example a call to the Javascript
     204        function 'window.open()')
     205
     206        browser -- the browser where window.open() was called
     207
     208        new_browser -- the new browser there the url of the
     209                       window.open() call will be loaded.
     210
     211                       This object is created in the signal callback
     212                       'create-web-view'.
     213        """
     214        new_browser.connect('new-tab', self.__new_tab_cb)
     215        new_browser.connect('new-window', self.__new_window_cb)
     216        new_browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
     217        new_browser.grab_focus()
     218
     219        self._insert_tab_next(new_browser)
     220
    198221    def __open_pdf_in_new_tab_cb(self, browser, url):
    199222        tab_page = PDFTabPage()
    200223        tab_page.browser.connect('new-tab', self.__new_tab_cb)
    class TabbedView(BrowserNotebook): 
    226249    def add_tab(self, next_to_current=False):
    227250        browser = Browser()
    228251        browser.connect('new-tab', self.__new_tab_cb)
     252        browser.connect('new-window', self.__new_window_cb)
    229253        browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
    230254
    231255        if next_to_current:
    class TabbedView(BrowserNotebook): 
    351375            else:
    352376                browser = Browser()
    353377                browser.connect('new-tab', self.__new_tab_cb)
     378                browser.connect('new-window', self.__new_window_cb)
    354379                browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb)
    355380                self._append_tab(browser)
    356381                browser.set_history(tab_history)
    class Browser(WebKit.WebView): 
    462487        'new-tab': (GObject.SignalFlags.RUN_FIRST,
    463488                    None,
    464489                    ([str])),
     490        'new-window': (GObject.SignalFlags.RUN_FIRST,
     491                       None,
     492                       ([object])),
    465493        'open-pdf': (GObject.SignalFlags.RUN_FIRST,
    466494                     None,
    467495                     ([str])),
    class Browser(WebKit.WebView): 
    507535        self.connect('new-window-policy-decision-requested',
    508536                     self.__new_window_policy_cb)
    509537        self.connect('load-error', self.__load_error_cb)
     538        self.connect('create-web-view', self.__create_web_view_cb)
    510539
    511540        ContentInvoker(self)
    512541
    class Browser(WebKit.WebView): 
    677706
    678707        return True
    679708
     709    def __create_web_view_cb(self, web_view, frame):
     710        new_web_view = Browser()
     711        self.emit('new-window', new_web_view)
     712        return new_web_view
     713
    680714
    681715class PopupDialog(Gtk.Window):
    682716    def __init__(self):