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
1=== modified file 'debian/control'
2--- debian/control 2015-08-25 13:56:58 +0000
3+++ debian/control 2015-09-01 07:22:19 +0000
4@@ -6,7 +6,7 @@
5 debhelper (>= 9),
6 dh-translations,
7 hardening-wrapper,
8- liboxideqt-qmlplugin (>= 1.8),
9+ liboxideqt-qmlplugin (>= 1.9),
10 libqt5sql5-sqlite,
11 python3-all,
12 python3-flake8,
13@@ -97,7 +97,7 @@
14 Pre-Depends: ${misc:Pre-Depends}
15 Depends: ${misc:Depends},
16 ${shlibs:Depends},
17- liboxideqt-qmlplugin (>= 1.8),
18+ liboxideqt-qmlplugin (>= 1.9),
19 qml-module-qtquick2 (>= 5.4),
20 qml-module-qtquick-window2 (>= 5.3),
21 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3),
22
23=== removed symlink 'src/Ubuntu/Components/Extras/Browser/ua-override-worker.js'
24=== target was u'../../../Web/ua-override-worker.js'
25=== modified file 'src/Ubuntu/Web/UbuntuWebContext.qml'
26--- src/Ubuntu/Web/UbuntuWebContext.qml 2015-08-10 15:22:00 +0000
27+++ src/Ubuntu/Web/UbuntuWebContext.qml 2015-09-01 07:22:19 +0000
28@@ -17,7 +17,7 @@
29 */
30
31 import QtQuick 2.4
32-import com.canonical.Oxide 1.6 as Oxide
33+import com.canonical.Oxide 1.9 as Oxide
34
35 Oxide.WebContext {
36 readonly property string defaultUserAgent: __ua.defaultUA
37@@ -29,27 +29,6 @@
38
39 userAgent: defaultUserAgent
40
41- networkRequestDelegate: Oxide.WebContextDelegateWorker {
42- source: Qt.resolvedUrl("ua-override-worker.js")
43- // Disable this log message since it outputs sensitive content when
44- // in private mode. (See http://pad.lv/1457925)
45- //onMessage: console.log("Overriden UA for", message.url, ":", message.override)
46- Component.onCompleted: {
47- var script = "ua-overrides-%1.js".arg(formFactor)
48- var temp = null
49- try {
50- temp = Qt.createQmlObject('import QtQml 2.0; import "%1" as Overrides; QtObject { readonly property var overrides: Overrides.overrides }'.arg(script), this)
51- } catch (e) {
52- console.error("No overrides found for", formFactor)
53- }
54- if (temp !== null) {
55- console.log("Loaded %1 UA override(s) from %2".arg(temp.overrides.length).arg(Qt.resolvedUrl(script)))
56- sendMessage({overrides: temp.overrides})
57- temp.destroy()
58- }
59- }
60- }
61- userAgentOverrideDelegate: networkRequestDelegate
62 sessionCookieMode: {
63 if (typeof webContextSessionCookieMode !== 'undefined') {
64 if (webContextSessionCookieMode === "persistent") {
65@@ -60,6 +39,7 @@
66 }
67 return Oxide.WebContext.SessionCookieModeEphemeral
68 }
69+
70 userScripts: [
71 Oxide.UserScript {
72 context: "oxide://smartbanners/"
73@@ -94,4 +74,19 @@
74 devtoolsIp: webviewDevtoolsDebugHost
75
76 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+ }
92 }
93
94=== removed file 'src/Ubuntu/Web/ua-override-worker.js'
95--- src/Ubuntu/Web/ua-override-worker.js 2015-05-25 21:22:58 +0000
96+++ src/Ubuntu/Web/ua-override-worker.js 1970-01-01 00:00:00 +0000
97@@ -1,54 +0,0 @@
98-/*
99- * Copyright 2014-2015 Canonical Ltd.
100- *
101- * This file is part of webbrowser-app.
102- *
103- * webbrowser-app is free software; you can redistribute it and/or modify
104- * it under the terms of the GNU General Public License as published by
105- * the Free Software Foundation; version 3.
106- *
107- * webbrowser-app is distributed in the hope that it will be useful,
108- * but WITHOUT ANY WARRANTY; without even the implied warranty of
109- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110- * GNU General Public License for more details.
111- *
112- * You should have received a copy of the GNU General Public License
113- * along with this program. If not, see <http://www.gnu.org/licenses/>.
114- */
115-
116-var overrides = [];
117-
118-oxide.onMessage = function(msg) {
119- if ("overrides" in msg) {
120- var o = msg["overrides"];
121- for (var i in o) {
122- var r = o[i];
123- overrides.push([new RegExp(r[0]), r[1]]);
124- }
125- }
126-}
127-
128-function getUAoverride(url) {
129- for (var i = 0; i < overrides.length; i++) {
130- var override = overrides[i];
131- if (override[0].test(url)) {
132- return override[1];
133- }
134- }
135- return null;
136-}
137-
138-exports.onBeforeSendHeaders = function(event) {
139- var override = getUAoverride(event.url);
140- if (override !== null) {
141- event.setHeader("User-Agent", override);
142- oxide.sendMessage({url: event.url, override: override});
143- }
144-}
145-
146-exports.onGetUserAgentOverride = function(event) {
147- var override = getUAoverride(event.url);
148- if (override !== null) {
149- event.userAgentOverride = override;
150- }
151-}

Subscribers

People subscribed via source and target branches

to status/vote changes: