Merge lp:~osomon/webbrowser-app/userAgentOverrides into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 1144
Merged at revision: 1179
Proposed branch: lp:~osomon/webbrowser-app/userAgentOverrides
Merge into: lp:webbrowser-app
Diff against target: 151 lines (+19/-78)
3 files modified
debian/control (+2/-2)
src/Ubuntu/Web/UbuntuWebContext.qml (+17/-22)
src/Ubuntu/Web/ua-override-worker.js (+0/-54)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/userAgentOverrides
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Alexandre Abreu (community) Approve
Review via email: mp+268210@code.launchpad.net

Commit message

Use the new WebContext.userAgentOverrides API (new in Oxide 1.9).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Needs Information
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

> temp.overrides being left unchecked type wise, could it cause an issue
> with userAgentOverrides if it is not of the expected type (or null) ?

It won’t cause issues because strict checks are implemented in oxide. I verified that by messing with the contents of ua-overrides-desktop.js on my desktop machine.
If I set overrides to be a string instead of an array, I get the following error message:

  UbuntuWebContext.qml:88: Error: Cannot assign QString to QVariantList

If I keep overrides an array but mess with its contents, I get the following error message from oxide:

  OxideQQuickWebContext::userAgentOverride: Each entry must be a list of size 2, with the first item being a valid regular expression for URL matching and the second item being the user agent string

1143. By Olivier Tilloy

Bump build dependency on oxide to 1.9.

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1144. By Olivier Tilloy

Merge the latest changes from trunk and resolve a minor conflict.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-08-25 13:56:58 +0000
+++ debian/control 2015-09-01 07:22:19 +0000
@@ -6,7 +6,7 @@
6 debhelper (>= 9),6 debhelper (>= 9),
7 dh-translations,7 dh-translations,
8 hardening-wrapper,8 hardening-wrapper,
9 liboxideqt-qmlplugin (>= 1.8),9 liboxideqt-qmlplugin (>= 1.9),
10 libqt5sql5-sqlite,10 libqt5sql5-sqlite,
11 python3-all,11 python3-all,
12 python3-flake8,12 python3-flake8,
@@ -97,7 +97,7 @@
97Pre-Depends: ${misc:Pre-Depends}97Pre-Depends: ${misc:Pre-Depends}
98Depends: ${misc:Depends},98Depends: ${misc:Depends},
99 ${shlibs:Depends},99 ${shlibs:Depends},
100 liboxideqt-qmlplugin (>= 1.8),100 liboxideqt-qmlplugin (>= 1.9),
101 qml-module-qtquick2 (>= 5.4),101 qml-module-qtquick2 (>= 5.4),
102 qml-module-qtquick-window2 (>= 5.3),102 qml-module-qtquick-window2 (>= 5.3),
103 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3),103 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3),
104104
=== removed symlink 'src/Ubuntu/Components/Extras/Browser/ua-override-worker.js'
=== target was u'../../../Web/ua-override-worker.js'
=== modified file 'src/Ubuntu/Web/UbuntuWebContext.qml'
--- src/Ubuntu/Web/UbuntuWebContext.qml 2015-08-10 15:22:00 +0000
+++ src/Ubuntu/Web/UbuntuWebContext.qml 2015-09-01 07:22:19 +0000
@@ -17,7 +17,7 @@
17 */17 */
1818
19import QtQuick 2.419import QtQuick 2.4
20import com.canonical.Oxide 1.6 as Oxide20import com.canonical.Oxide 1.9 as Oxide
2121
22Oxide.WebContext {22Oxide.WebContext {
23 readonly property string defaultUserAgent: __ua.defaultUA23 readonly property string defaultUserAgent: __ua.defaultUA
@@ -29,27 +29,6 @@
2929
30 userAgent: defaultUserAgent30 userAgent: defaultUserAgent
3131
32 networkRequestDelegate: Oxide.WebContextDelegateWorker {
33 source: Qt.resolvedUrl("ua-override-worker.js")
34 // Disable this log message since it outputs sensitive content when
35 // in private mode. (See http://pad.lv/1457925)
36 //onMessage: console.log("Overriden UA for", message.url, ":", message.override)
37 Component.onCompleted: {
38 var script = "ua-overrides-%1.js".arg(formFactor)
39 var temp = null
40 try {
41 temp = Qt.createQmlObject('import QtQml 2.0; import "%1" as Overrides; QtObject { readonly property var overrides: Overrides.overrides }'.arg(script), this)
42 } catch (e) {
43 console.error("No overrides found for", formFactor)
44 }
45 if (temp !== null) {
46 console.log("Loaded %1 UA override(s) from %2".arg(temp.overrides.length).arg(Qt.resolvedUrl(script)))
47 sendMessage({overrides: temp.overrides})
48 temp.destroy()
49 }
50 }
51 }
52 userAgentOverrideDelegate: networkRequestDelegate
53 sessionCookieMode: {32 sessionCookieMode: {
54 if (typeof webContextSessionCookieMode !== 'undefined') {33 if (typeof webContextSessionCookieMode !== 'undefined') {
55 if (webContextSessionCookieMode === "persistent") {34 if (webContextSessionCookieMode === "persistent") {
@@ -60,6 +39,7 @@
60 }39 }
61 return Oxide.WebContext.SessionCookieModeEphemeral40 return Oxide.WebContext.SessionCookieModeEphemeral
62 }41 }
42
63 userScripts: [43 userScripts: [
64 Oxide.UserScript {44 Oxide.UserScript {
65 context: "oxide://smartbanners/"45 context: "oxide://smartbanners/"
@@ -94,4 +74,19 @@
94 devtoolsIp: webviewDevtoolsDebugHost74 devtoolsIp: webviewDevtoolsDebugHost
9575
96 hostMappingRules: webviewHostMappingRules76 hostMappingRules: webviewHostMappingRules
77
78 Component.onCompleted: {
79 var script = "ua-overrides-%1.js".arg(formFactor)
80 var temp = null
81 try {
82 temp = Qt.createQmlObject('import QtQml 2.0; import "%1" as Overrides; QtObject { readonly property var overrides: Overrides.overrides }'.arg(script), this)
83 } catch (e) {
84 console.error("No overrides found for", formFactor)
85 }
86 if (temp !== null) {
87 console.log("Loaded %1 UA override(s) from %2".arg(temp.overrides.length).arg(Qt.resolvedUrl(script)))
88 userAgentOverrides = temp.overrides
89 temp.destroy()
90 }
91 }
97}92}
9893
=== removed file 'src/Ubuntu/Web/ua-override-worker.js'
--- src/Ubuntu/Web/ua-override-worker.js 2015-05-25 21:22:58 +0000
+++ src/Ubuntu/Web/ua-override-worker.js 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
1/*
2 * Copyright 2014-2015 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app 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 * webbrowser-app 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 overrides = [];
20
21oxide.onMessage = function(msg) {
22 if ("overrides" in msg) {
23 var o = msg["overrides"];
24 for (var i in o) {
25 var r = o[i];
26 overrides.push([new RegExp(r[0]), r[1]]);
27 }
28 }
29}
30
31function getUAoverride(url) {
32 for (var i = 0; i < overrides.length; i++) {
33 var override = overrides[i];
34 if (override[0].test(url)) {
35 return override[1];
36 }
37 }
38 return null;
39}
40
41exports.onBeforeSendHeaders = function(event) {
42 var override = getUAoverride(event.url);
43 if (override !== null) {
44 event.setHeader("User-Agent", override);
45 oxide.sendMessage({url: event.url, override: override});
46 }
47}
48
49exports.onGetUserAgentOverride = function(event) {
50 var override = getUAoverride(event.url);
51 if (override !== null) {
52 event.userAgentOverride = override;
53 }
54}

Subscribers

People subscribed via source and target branches

to status/vote changes: