Merge lp:~osomon/webbrowser-app/open-blank-in-new-tab into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Günter Schwann
Approved revision: 167
Merged at revision: 168
Proposed branch: lp:~osomon/webbrowser-app/open-blank-in-new-tab
Merge into: lp:webbrowser-app
Diff against target: 77 lines (+28/-2)
4 files modified
src/Ubuntu/Browser/Browser.qml (+2/-0)
src/Ubuntu/Browser/UbuntuWebView.qml (+4/-0)
src/Ubuntu/Browser/hyperlinks.js (+4/-2)
tests/autopilot/webbrowser_app/tests/test_tabs.py (+18/-0)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/open-blank-in-new-tab
Reviewer Review Type Date Requested Status
Günter Schwann (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+167910@code.launchpad.net

Commit message

Open links with target="_blank" in a new tab.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
167. By Olivier Tilloy

Be more tolerant with invalid syntaxes:
do the correct thing if the target of the link is defined as "target="_blank"".

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Günter Schwann (schwann) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Browser/Browser.qml'
2--- src/Ubuntu/Browser/Browser.qml 2013-06-06 09:25:48 +0000
3+++ src/Ubuntu/Browser/Browser.qml 2013-06-07 10:56:24 +0000
4@@ -275,6 +275,8 @@
5 historyModel.add(webview.url, webview.title, webview.icon)
6 }
7 }
8+
9+ onNewTabRequested: browser.newTab(url, true)
10 }
11 }
12
13
14=== modified file 'src/Ubuntu/Browser/UbuntuWebView.qml'
15--- src/Ubuntu/Browser/UbuntuWebView.qml 2013-05-28 10:51:25 +0000
16+++ src/Ubuntu/Browser/UbuntuWebView.qml 2013-06-07 10:56:24 +0000
17@@ -26,6 +26,8 @@
18 WebView {
19 id: _webview
20
21+ signal newTabRequested(url url)
22+
23 QtObject {
24 // clumsy way of defining an enum in QML
25 id: formFactor
26@@ -97,6 +99,8 @@
27 }
28 selection.show(data.left * scale, data.top * scale,
29 data.width * scale, data.height * scale)
30+ } else if (data.event === 'newtab') {
31+ newTabRequested(data.url)
32 }
33 }
34 }
35
36=== modified file 'src/Ubuntu/Browser/hyperlinks.js'
37--- src/Ubuntu/Browser/hyperlinks.js 2013-02-22 15:29:02 +0000
38+++ src/Ubuntu/Browser/hyperlinks.js 2013-06-07 10:56:24 +0000
39@@ -28,8 +28,10 @@
40 // https://bugs.webkit.org/show_bug.cgi?id=76416
41 // https://bugs.webkit.org/show_bug.cgi?id=91779
42 if (node.hasAttribute('target')) {
43- if (node.getAttribute('target').toLowerCase() == '_blank') {
44- window.location = node.getAttribute('href');
45+ var target = node.getAttribute('target').toLowerCase();
46+ if ((target == '_blank') || (target == '"_blank"')) {
47+ var link = {'event': 'newtab', 'url': node.getAttribute('href')};
48+ navigator.qt.postMessage(JSON.stringify(link));
49 }
50 }
51 break;
52
53=== modified file 'tests/autopilot/webbrowser_app/tests/test_tabs.py'
54--- tests/autopilot/webbrowser_app/tests/test_tabs.py 2013-06-06 09:25:48 +0000
55+++ tests/autopilot/webbrowser_app/tests/test_tabs.py 2013-06-07 10:56:24 +0000
56@@ -139,3 +139,21 @@
57 self.assert_chrome_eventually_shown()
58 address_bar = self.main_window.get_address_bar()
59 self.assertThat(address_bar.activeFocus, Eventually(Equals(True)))
60+
61+ def test_open_target_blank_in_new_tab(self):
62+ # craft a page that accepts clicks anywhere inside its window
63+ # and that requests opening another page in a new tab
64+ url2 = self.base_url + "/aleaiactaest"
65+ html = '<html><body style="margin: 0">'
66+ html += '<a href="%s" target="_blank">' % url2
67+ html += '<div style="height: 100%"></div></a></body></html>'
68+ url = self.make_raw_html_page(html)
69+ self.go_to_url(url)
70+ self.assert_page_eventually_loaded(url)
71+ webview = self.main_window.get_current_webview()
72+ self.pointing_device.move_to_object(webview)
73+ self.pointing_device.click()
74+ listview = self.main_window.get_tabslist_listview()
75+ self.assertThat(listview.count, Eventually(Equals(2)))
76+ self.assertThat(listview.currentIndex, Eventually(Equals(1)))
77+ self.assert_current_url(url2)

Subscribers

People subscribed via source and target branches

to status/vote changes: