Merge lp:~ken-vandine/signon-ui/lp1235259 into lp:signon-ui

Proposed by Ken VanDine
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 110
Merged at revision: 111
Proposed branch: lp:~ken-vandine/signon-ui/lp1235259
Merge into: lp:signon-ui
Diff against target: 382 lines (+272/-74)
5 files modified
src/browser-process/UserAgent.qml (+90/-0)
src/browser-process/browser-process.pro (+3/-1)
src/browser-process/qml.qrc (+8/-7)
src/browser-process/ua-overrides.js (+99/-0)
src/browser-process/webview.qml (+72/-66)
To merge this branch: bzr merge lp:~ken-vandine/signon-ui/lp1235259
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Mardegan (community) Approve
Review via email: mp+189614@code.launchpad.net

Commit message

Use a MainView and pull in the UserAgent logic used in the Browser
component. Using the correct useragent fixes things like facebook
suggesting users should install the facebook app for iphone (LP: #1235259)

Description of the change

Use a MainView and pull in the UserAgent logic used in the Browser
component. Using the correct useragent fixes things like facebook
suggesting users should install the facebook app for iphone (LP: #1235259)

To post a comment you must log in.
Revision history for this message
Alberto Mardegan (mardy) wrote :

Excellent! :-)

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/browser-process/UserAgent.qml'
2--- src/browser-process/UserAgent.qml 1970-01-01 00:00:00 +0000
3+++ src/browser-process/UserAgent.qml 2013-10-07 14:11:32 +0000
4@@ -0,0 +1,90 @@
5+/*
6+ * Copyright 2013 Canonical Ltd.
7+ *
8+ * This file is part of webbrowser-app.
9+ *
10+ * webbrowser-app is free software; you can redistribute it and/or modify
11+ * it under the terms of the GNU General Public License as published by
12+ * the Free Software Foundation; version 3.
13+ *
14+ * webbrowser-app is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU General Public License
20+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21+ */
22+
23+import QtQuick 2.0
24+import QtQuick.Window 2.0
25+import Ubuntu.Components 0.1
26+import "ua-overrides.js" as Overrides
27+
28+/*
29+ * Useful documentation:
30+ * http://en.wikipedia.org/wiki/User_agent#Format
31+ * https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
32+ * https://wiki.mozilla.org/B2G/User_Agent
33+ * https://github.com/mozilla-b2g/gaia/blob/master/build/ua-override-prefs.js
34+ * https://developers.google.com/chrome/mobile/docs/user-agent
35+ */
36+
37+// This is an Item, not a QtObject, because it needs information about the Screen.
38+Item {
39+ // %1: form factor (Mobile, Tablet, Desktop)
40+ // %2: WebKit version
41+ readonly property string _template: "Mozilla/5.0 (Ubuntu; %1) WebKit/%2"
42+
43+ // See Source/WebCore/Configurations/Version.xcconfig in QtWebKit’s source tree
44+ // TODO: determine this value at runtime
45+ readonly property string _webkitVersion: "537.21"
46+
47+ // FIXME: this is a quick hack that will become increasingly unreliable
48+ // as we support more devices, so we need a better solution for this
49+ // FIXME: only handling phone and tablet for now, need to handle desktop too
50+ readonly property string _formFactor: (Screen.width >= units.gu(60)) ? "Tablet" : "Mobile"
51+
52+ property string defaultUA: _template.arg(_formFactor).arg(_webkitVersion)
53+
54+ property var overrides: Overrides.overrides
55+
56+ function getDomain(url) {
57+ var domain = url.toString()
58+ var indexOfScheme = domain.indexOf("://")
59+ if (indexOfScheme !== -1) {
60+ domain = domain.slice(indexOfScheme + 3)
61+ }
62+ var indexOfPath = domain.indexOf("/")
63+ if (indexOfPath !== -1) {
64+ domain = domain.slice(0, indexOfPath)
65+ }
66+ return domain
67+ }
68+
69+ function getDomains(domain) {
70+ var components = domain.split(".")
71+ var domains = []
72+ for (var i = 0; i < components.length; i++) {
73+ domains.push(components.slice(i).join("."))
74+ }
75+ return domains
76+ }
77+
78+ function getUAString(url) {
79+ var ua = defaultUA
80+ var domains = getDomains(getDomain(url))
81+ for (var i = 0; i < domains.length; i++) {
82+ var domain = domains[i]
83+ if (domain in overrides) {
84+ var form = overrides[domain]
85+ if (typeof form == "string") {
86+ return form
87+ } else if (typeof form == "object") {
88+ return ua.replace(form[0], form[1])
89+ }
90+ }
91+ }
92+ return ua
93+ }
94+}
95
96=== modified file 'src/browser-process/browser-process.pro'
97--- src/browser-process/browser-process.pro 2013-10-04 17:15:49 +0000
98+++ src/browser-process/browser-process.pro 2013-10-07 14:11:32 +0000
99@@ -47,7 +47,9 @@
100 OTHER_FILES += \
101 webview.qml \
102 KeyboardRectangle.qml \
103- StandardAnimation.qml
104+ StandardAnimation.qml \
105+ UserAgent.qml \
106+ ua-overrides.js
107
108 RESOURCES += \
109 qml.qrc
110
111=== modified file 'src/browser-process/qml.qrc'
112--- src/browser-process/qml.qrc 2013-04-19 11:13:03 +0000
113+++ src/browser-process/qml.qrc 2013-10-07 14:11:32 +0000
114@@ -1,8 +1,9 @@
115-<!DOCTYPE RCC><RCC version="1.0">
116-<qresource>
117- <file>webview.qml</file>
118- <file>KeyboardRectangle.qml</file>
119- <file>StandardAnimation.qml</file>
120-</qresource>
121+<RCC>
122+ <qresource prefix="/">
123+ <file>webview.qml</file>
124+ <file>KeyboardRectangle.qml</file>
125+ <file>StandardAnimation.qml</file>
126+ <file>UserAgent.qml</file>
127+ <file>ua-overrides.js</file>
128+ </qresource>
129 </RCC>
130-
131
132=== added file 'src/browser-process/ua-overrides.js'
133--- src/browser-process/ua-overrides.js 1970-01-01 00:00:00 +0000
134+++ src/browser-process/ua-overrides.js 2013-10-07 14:11:32 +0000
135@@ -0,0 +1,99 @@
136+/*
137+ * Copyright 2013 Canonical Ltd.
138+ *
139+ * This file is part of webbrowser-app.
140+ *
141+ * webbrowser-app is free software; you can redistribute it and/or modify
142+ * it under the terms of the GNU General Public License as published by
143+ * the Free Software Foundation; version 3.
144+ *
145+ * webbrowser-app is distributed in the hope that it will be useful,
146+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
147+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148+ * GNU General Public License for more details.
149+ *
150+ * You should have received a copy of the GNU General Public License
151+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
152+ */
153+
154+.pragma library
155+
156+// B2G’s list of overrides: https://github.com/mozilla-b2g/gaia/blob/master/build/ua-override-prefs.js
157+
158+// List of user agent string overrides in the form of an object.
159+// Each key is a domain name for which the default user agent string doesn’t
160+// work well enough. Values can either be a string (full override) or an array
161+// containing two values that are passed to the String.replace method (the
162+// first value may be either a string or a regular expression, the second value
163+// must be a string).
164+
165+// Examples of valid entries:
166+// "example.org": "full override"
167+// "example.com": ["Ubuntu", "Ubuntu Edge"]
168+// "google.com": [/mobi/i, "b"]
169+
170+// The original list was initially built from the top 100 entries
171+// at http://www.alexa.com/topsites (2013-08-16), using Chrome on
172+// Android as a reference.
173+
174+var overrides = {
175+ "mail.google.com": [/Mobile\) WebKit\/[.0-9]*/, "Android 4.3) AppleWebKit Mobile Safari"],
176+ "google.com": ["Mobile", "Android; Mobile"],
177+ "youtube.com": ["Mobile", "Android; Mobile"],
178+ "yahoo.com": ["Mobile", "Android; Mobile"],
179+ "baidu.com": ["Mobile", "Android; Mobile"],
180+ "qq.com": [/WebKit\/[.0-9]*/, "Apple$& Mobile"],
181+ "amazon.com": ["Mobile", "Android; Mobile"],
182+ "linkedin.com": ["Mobile", "Android; Mobile"],
183+ "blogspot.com": ["Mobile", "Android; Mobile"],
184+ "taobao.com": ["Mobile", "Android; Mobile"],
185+ "google.co.in": ["Mobile", "Android; Mobile"],
186+ "bing.com": ["Mobile", "Android; Mobile"],
187+ "yahoo.co.jp": ["Ubuntu", "Linux; Android 4; Galaxy Build/"],
188+ "yandex.ru": ["Mobile", "Android; Mobile"],
189+ "sina.com.cn": ["Mobile", "Android; Mobile"],
190+ "ebay.com": ["Mobile", "Android; Mobile"],
191+ "google.de": ["Mobile", "Android; Mobile"],
192+ "tumblr.com": ["Mobile", "Android; Mobile"],
193+ "google.co.uk": ["Mobile", "Android; Mobile"],
194+ "msn.com": ["Mobile", "Android; Mobile"],
195+ "google.fr": ["Mobile", "Android; Mobile"],
196+ "mail.ru": ["Ubuntu", "Linux; Android 4; Galaxy Build/"],
197+ "google.com.br": ["Mobile", "Android; Mobile"],
198+ "google.co.jp": ["Mobile", "Android; Mobile"],
199+ "hao123.com": ["Mobile", "Android; Mobile"],
200+ "ask.com": ["Mobile", "Android; Mobile"],
201+ "google.com.hk": ["Mobile", "Android; Mobile"],
202+ "google.ru": ["Mobile", "Android; Mobile"],
203+ "blogger.com": ["Mobile", "Android; Mobile"],
204+ "imdb.com": ["Mobile", "Android; Mobile"],
205+ "google.it": ["Mobile", "Android; Mobile"],
206+ "google.es": ["Mobile", "Android; Mobile"],
207+ "amazon.co.jp": ["Mobile", "Android; Mobile"],
208+ "tmall.com": ["Mobile", "Android; Mobile"],
209+ "fc2.com": ["Mobile", "Android; Mobile"],
210+ "google.com.mx": ["Mobile", "Android; Mobile"],
211+ "google.ca": ["Mobile", "Android; Mobile"],
212+ "soso.com": ["Mobile", "Android; Mobile"],
213+ "delta-search.com": ["Mobile", "Android; Mobile"],
214+ "odnoklassniki.ru": ["Mobile", "Android; Mobile"],
215+ "alibaba.com": ["Mobile", "Android; Mobile"],
216+ "flickr.com": ["Mobile", "Android; Mobile"],
217+ "amazon.de": ["Mobile", "Android; Mobile"],
218+ "blogspot.in": ["Mobile", "Android; Mobile"],
219+ "ifeng.com": ["Mobile", "Android; Mobile"],
220+ "360.cn": ["Mobile", "Android; Mobile"],
221+ "google.com.tr": ["Mobile", "Android; Mobile"],
222+ "google.com.au": ["Mobile", "Android; Mobile"],
223+ "youku.com": ["Mobile", "Android; Mobile"],
224+ "ebay.de": ["Mobile", "Android; Mobile"],
225+ "uol.com.br": ["Mobile", "Android; Mobile"],
226+ "aol.com": ["Mobile", "Android; Mobile"],
227+ "google.pl": ["Mobile", "Android; Mobile"],
228+ "alipay.com": ["Mobile", "Android; Mobile"],
229+ "dailymotion.com": ["Mobile", "Android; Mobile Safari"],
230+ "amazon.co.uk": ["Mobile", "Android; Mobile"],
231+ "ebay.co.uk": ["Mobile", "Android; Mobile"],
232+ "facebook.com": [/WebKit\/[.0-9]*/, "Apple$& Firefox/18"],
233+ "nytimes.com": ["Mobile", "Android; Mobile Safari"],
234+};
235
236=== modified file 'src/browser-process/webview.qml'
237--- src/browser-process/webview.qml 2013-10-01 11:03:28 +0000
238+++ src/browser-process/webview.qml 2013-10-07 14:11:32 +0000
239@@ -3,71 +3,77 @@
240 import QtWebKit 3.0
241 import QtWebKit.experimental 1.0
242 import Ubuntu.Components 0.1
243-
244-FocusScope {
245- id: browser
246- width: 400
247- height: 300
248- focus: true
249- property string qtwebkitdpr: "1.0"
250-
251- QtObject {
252- // clumsy way of defining an enum in QML
253- id: formFactor
254- readonly property int desktop: 0
255- readonly property int phone: 1
256- readonly property int tablet: 2
257- }
258- // FIXME: this is a quick hack that will become increasingly unreliable
259- // as we support more devices, so we need a better solution for this
260- // FIXME: only handling phone and tablet for now
261- property int formFactor: (Screen.width >= units.gu(60)) ? formFactor.tablet : formFactor.phone
262-
263- onQtwebkitdprChanged: {
264- // Do not make this patch to QtWebKit a hard requirement.
265- if (webview.experimental.hasOwnProperty('devicePixelRatio')) {
266- webview.experimental.devicePixelRatio = qtwebkitdpr
267- }
268- }
269-
270- WebView {
271- id: webView
272- anchors {
273- top: parent.top
274- left: parent.left
275- right: parent.right
276- bottom: osk.top
277- }
278- focus: true
279- experimental.userAgent: {
280- // FIXME: using iOS 5.0's iPhone/iPad user-agent strings
281- // (source: http://stackoverflow.com/questions/7825873/what-is-the-ios-5-0-user-agent-string),
282- // this should be changed to a more neutral user-agent in the
283- // future as we don't want websites to recommend installing
284- // their iPhone/iPad apps.
285- if (browser.formFactor === formFactor.phone) {
286- return "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
287- } else if (browser.formFactor === formFactor.tablet) {
288- return "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
289- }
290- }
291-
292- experimental.preferences.developerExtrasEnabled: false
293- experimental.preferences.navigatorQtObjectEnabled: true
294-
295-
296- Component.onCompleted: url = request.startUrl
297-
298- onLoadingChanged: {
299- console.log("Loading changed")
300- if (loadRequest.status === WebView.LoadSucceededStatus) {
301- request.onLoadFinished(true)
302- }
303- }
304- onUrlChanged: request.currentUrl = url
305- }
306-
307- KeyboardRectangle {
308- id: osk
309+import Ubuntu.Unity.Action 1.0 as UnityActions
310+
311+import "ua-overrides.js" as Overrides
312+
313+MainView {
314+ id: root
315+ width: units.gu(60)
316+ height: units.gu(90)
317+
318+ Page {
319+
320+ FocusScope {
321+ id: browser
322+ anchors.fill: parent
323+ focus: true
324+ property string qtwebkitdpr: "1.0"
325+
326+ QtObject {
327+ // clumsy way of defining an enum in QML
328+ id: formFactor
329+ readonly property int desktop: 0
330+ readonly property int phone: 1
331+ readonly property int tablet: 2
332+ }
333+ // FIXME: this is a quick hack that will become increasingly unreliable
334+ // as we support more devices, so we need a better solution for this
335+ // FIXME: only handling phone and tablet for now
336+ property int formFactor: (Screen.width >= units.gu(60)) ? formFactor.tablet : formFactor.phone
337+
338+ onQtwebkitdprChanged: {
339+ // Do not make this patch to QtWebKit a hard requirement.
340+ if (webview.experimental.hasOwnProperty('devicePixelRatio')) {
341+ webview.experimental.devicePixelRatio = qtwebkitdpr
342+ }
343+ }
344+
345+ WebView {
346+ id: webView
347+ anchors {
348+ top: parent.top
349+ left: parent.left
350+ right: parent.right
351+ bottom: osk.top
352+ }
353+ focus: true
354+ UserAgent {
355+ id: userAgent
356+ }
357+
358+ experimental.userAgent: userAgent.defaultUA
359+
360+ experimental.preferences.developerExtrasEnabled: false
361+ experimental.preferences.navigatorQtObjectEnabled: true
362+
363+ Component.onCompleted: url = request.startUrl
364+
365+ onLoadingChanged: {
366+ console.log("Loading changed")
367+ if (loadRequest.status === WebView.LoadSucceededStatus) {
368+ request.onLoadFinished(true)
369+ }
370+ else if (loadRequest.status === WebView.LoadFailedStatus) {
371+ request.cancel();
372+ }
373+ }
374+ onUrlChanged: request.currentUrl = url
375+ }
376+
377+ KeyboardRectangle {
378+ id: osk
379+ }
380+ }
381 }
382 }

Subscribers

People subscribed via source and target branches

to all changes: