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): |
195 | 195 | new_browser.load_uri(url) |
196 | 196 | new_browser.grab_focus() |
197 | 197 | |
| 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 | |
198 | 221 | def __open_pdf_in_new_tab_cb(self, browser, url): |
199 | 222 | tab_page = PDFTabPage() |
200 | 223 | tab_page.browser.connect('new-tab', self.__new_tab_cb) |
… |
… |
class TabbedView(BrowserNotebook): |
226 | 249 | def add_tab(self, next_to_current=False): |
227 | 250 | browser = Browser() |
228 | 251 | browser.connect('new-tab', self.__new_tab_cb) |
| 252 | browser.connect('new-window', self.__new_window_cb) |
229 | 253 | browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) |
230 | 254 | |
231 | 255 | if next_to_current: |
… |
… |
class TabbedView(BrowserNotebook): |
351 | 375 | else: |
352 | 376 | browser = Browser() |
353 | 377 | browser.connect('new-tab', self.__new_tab_cb) |
| 378 | browser.connect('new-window', self.__new_window_cb) |
354 | 379 | browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) |
355 | 380 | self._append_tab(browser) |
356 | 381 | browser.set_history(tab_history) |
… |
… |
class Browser(WebKit.WebView): |
462 | 487 | 'new-tab': (GObject.SignalFlags.RUN_FIRST, |
463 | 488 | None, |
464 | 489 | ([str])), |
| 490 | 'new-window': (GObject.SignalFlags.RUN_FIRST, |
| 491 | None, |
| 492 | ([object])), |
465 | 493 | 'open-pdf': (GObject.SignalFlags.RUN_FIRST, |
466 | 494 | None, |
467 | 495 | ([str])), |
… |
… |
class Browser(WebKit.WebView): |
507 | 535 | self.connect('new-window-policy-decision-requested', |
508 | 536 | self.__new_window_policy_cb) |
509 | 537 | self.connect('load-error', self.__load_error_cb) |
| 538 | self.connect('create-web-view', self.__create_web_view_cb) |
510 | 539 | |
511 | 540 | ContentInvoker(self) |
512 | 541 | |
… |
… |
class Browser(WebKit.WebView): |
677 | 706 | |
678 | 707 | return True |
679 | 708 | |
| 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 | |
680 | 714 | |
681 | 715 | class PopupDialog(Gtk.Window): |
682 | 716 | def __init__(self): |