1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0
import Ubuntu.Components 0.1
FocusScope {
id: browser
width: 400
height: 300
focus: true
property string qtwebkitdpr: "1.0"
QtObject {
// clumsy way of defining an enum in QML
id: formFactor
readonly property int desktop: 0
readonly property int phone: 1
readonly property int tablet: 2
}
// FIXME: this is a quick hack that will become increasingly unreliable
// as we support more devices, so we need a better solution for this
// FIXME: only handling phone and tablet for now
property int formFactor: (Screen.width >= units.gu(60)) ? formFactor.tablet : formFactor.phone
onQtwebkitdprChanged: {
// Do not make this patch to QtWebKit a hard requirement.
if (webview.experimental.hasOwnProperty('devicePixelRatio')) {
webview.experimental.devicePixelRatio = qtwebkitdpr
}
}
WebView {
id: webView
anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: osk.top
}
focus: true
experimental.userAgent: {
// FIXME: using iOS 5.0's iPhone/iPad user-agent strings
// (source: http://stackoverflow.com/questions/7825873/what-is-the-ios-5-0-user-agent-string),
// this should be changed to a more neutral user-agent in the
// future as we don't want websites to recommend installing
// their iPhone/iPad apps.
if (browser.formFactor === formFactor.phone) {
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"
} else if (browser.formFactor === formFactor.tablet) {
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"
}
}
experimental.preferences.developerExtrasEnabled: false
experimental.preferences.navigatorQtObjectEnabled: true
Component.onCompleted: url = request.startUrl
onLoadingChanged: {
console.log("Loading changed")
if (loadRequest.status === WebView.LoadSucceededStatus) {
request.onLoadFinished(true)
}
}
onUrlChanged: request.currentUrl = url
}
KeyboardRectangle {
id: osk
}
}
|