Merge lp:~osomon/webbrowser-app/hyperlinks-blank-target into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Ugo Riboni
Approved revision: 89
Merged at revision: 98
Proposed branch: lp:~osomon/webbrowser-app/hyperlinks-blank-target
Merge into: lp:webbrowser-app
Diff against target: 57 lines (+41/-1)
2 files modified
src/Ubuntu/Browser/Browser.qml (+2/-1)
src/Ubuntu/Browser/hyperlinks.js (+39/-0)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/hyperlinks-blank-target
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+155216@code.launchpad.net

Commit message

Use javascript event delegation to work around the lack of support for handling hyperlinks with a target attribute set to '_blank' in QtWebKit.

Description of the change

Note to the reviewer: bug #1129281 was originally reported against the twitter web app. Unfortunately, this MR doesn’t fix the original issue because the twitter web app does additional event handling that conflicts with my solution (see https://bugs.launchpad.net/manhattan/+bug/1129281/comments/7 for details).

However this patch does fix the handling of "normal" hyperlinks with target="_blank" (hopefully the majority of them out there), so I think it’s still valuable on its own. It can be tested against http://news.google.com (all links have target="_blank" on this page).

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

A different approach would be to wait for the document to finish loading, then do document.getElementsByTagName("a") and add your click listener on those of them that have target = "_blank"

The advantage of that is that you don't have to walk up the tree for each click anywhere on the document (which probably happens often). The tradeoff is bviously of some more initial setup at page load, but it shouldn't be too bad.

Revision history for this message
Olivier Tilloy (osomon) wrote :

As discussed on IRC, the approach suggested by Ugo would probably consume more memory (for each onclick handler), as opposed to more CPU consumption for the patch I’m proposing. We’d need numbers to back this hypothesis though.

Regardless, this is a temporary solution, the proper way of fixing this issue is to patch QtWebKit to implement decidePolicyForNewWindowAction(…).

This patch improves user experience by enabling something that doesn’t work without it, so let’s get it in as is, and work on a proper fix asap.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Ubuntu/Browser/Browser.qml'
--- src/Ubuntu/Browser/Browser.qml 2013-03-20 18:28:04 +0000
+++ src/Ubuntu/Browser/Browser.qml 2013-03-25 12:57:10 +0000
@@ -130,7 +130,8 @@
130 experimental.devicePixelRatio: browser.qtwebkitdpr130 experimental.devicePixelRatio: browser.qtwebkitdpr
131 experimental.preferences.developerExtrasEnabled: browser.developerExtrasEnabled131 experimental.preferences.developerExtrasEnabled: browser.developerExtrasEnabled
132 experimental.preferences.navigatorQtObjectEnabled: true132 experimental.preferences.navigatorQtObjectEnabled: true
133 experimental.userScripts: [Qt.resolvedUrl("selection.js")]133 experimental.userScripts: [Qt.resolvedUrl("hyperlinks.js"),
134 Qt.resolvedUrl("selection.js")]
134 experimental.onMessageReceived: {135 experimental.onMessageReceived: {
135 var data = null136 var data = null
136 try {137 try {
137138
=== added file 'src/Ubuntu/Browser/hyperlinks.js'
--- src/Ubuntu/Browser/hyperlinks.js 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/Browser/hyperlinks.js 2013-03-25 12:57:10 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This file is part of ubuntu-browser.
5 *
6 * ubuntu-browser is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-browser is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19var doc = document.documentElement;
20
21doc.addEventListener('click', function(event) {
22 var node = event.target;
23 while (node) {
24 if (node.nodeName.toLowerCase() == 'a') {
25 // Using event delegation to work around the lack of support for
26 // handling hyperlinks with a target attribute set to '_blank' in
27 // QtWebKit. See related upstream bug reports:
28 // https://bugs.webkit.org/show_bug.cgi?id=76416
29 // https://bugs.webkit.org/show_bug.cgi?id=91779
30 if (node.hasAttribute('target')) {
31 if (node.getAttribute('target').toLowerCase() == '_blank') {
32 window.location = node.getAttribute('href');
33 }
34 }
35 break;
36 }
37 node = node.parentNode;
38 }
39});

Subscribers

People subscribed via source and target branches

to status/vote changes: