Merge lp:~abreu-alexandre/unity-webapps-qml/content-hub-share into lp:unity-webapps-qml

Proposed by Alexandre Abreu
Status: Work in progress
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/content-hub-share
Merge into: lp:unity-webapps-qml
Diff against target: 965 lines (+763/-9)
20 files modified
examples/facebook-share/bla.qml (+13/-0)
examples/facebook-share/content-hub/content-hub-exporter.json (+5/-0)
examples/facebook-share/facebook-webapp.service (+6/-0)
examples/facebook-share/manifest.json (+19/-0)
examples/facebook-share/unity-webapps-facebook/HubSharer.qml (+80/-0)
examples/facebook-share/unity-webapps-facebook/Share.qml (+303/-0)
examples/facebook-share/unity-webapps-facebook/facebook.user.js (+72/-0)
examples/facebook-share/unity-webapps-facebook/manifest.json (+7/-0)
examples/facebook-share/unity-webapps-facebook/uploader.html (+15/-0)
examples/facebook-share/unity-webapps-facebook/uploader.js (+34/-0)
examples/facebook-share/webapp-facebook.application (+11/-0)
examples/facebook-share/webapp-facebook.desktop (+9/-0)
examples/facebook-share/webapp-facebook.json (+13/-0)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+76/-6)
src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js (+15/-1)
src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js (+52/-0)
src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js (+1/-1)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp (+19/-0)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h (+7/-1)
src/Ubuntu/UnityWebApps/unity-webapps-api.js.in (+6/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/content-hub-share
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+222640@code.launchpad.net

Commit message

Add share cpability

Description of the change

Add share cpability

To post a comment you must log in.

Unmerged revisions

122. By Alexandre Abreu

expand

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'examples/facebook-share'
=== added file 'examples/facebook-share/bla.qml'
--- examples/facebook-share/bla.qml 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/bla.qml 2014-06-10 12:45:47 +0000
@@ -0,0 +1,13 @@
1import QtQuick 2.0;
2
3//import "/home/ken/work/phablet/content-hub/14.10/content-hub-share/examples/facebook-share/unity-webapps-facebook" as Sharer
4import "unity-webapps-facebook" as Sharer
5
6Sharer.HubSharer {
7 width: 800
8 height: 500
9
10 fileToShare: 'file:///home/ken/.cache/com.ubuntu.developer.webapps.webapp-facebook/HubIncoming/14/ubuntu-varsity-red-1920x1200.png';
11 visible: true;
12}
13
014
=== added directory 'examples/facebook-share/content-hub'
=== added file 'examples/facebook-share/content-hub/content-hub-exporter.json'
--- examples/facebook-share/content-hub/content-hub-exporter.json 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/content-hub/content-hub-exporter.json 2014-06-10 12:45:47 +0000
@@ -0,0 +1,5 @@
1{
2 "source": [
3 "pictures"
4 ]
5}
06
=== added file 'examples/facebook-share/facebook-webapp.service'
--- examples/facebook-share/facebook-webapp.service 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/facebook-webapp.service 2014-06-10 12:45:47 +0000
@@ -0,0 +1,6 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<service id="com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook">
3 <type>webapps</type>
4 <name>Facebook Webapp</name>
5 <provider>facebook</provider>
6</service>
07
=== added file 'examples/facebook-share/facebook.png'
1Binary files examples/facebook-share/facebook.png 1970-01-01 00:00:00 +0000 and examples/facebook-share/facebook.png 2014-06-10 12:45:47 +0000 differ8Binary files examples/facebook-share/facebook.png 1970-01-01 00:00:00 +0000 and examples/facebook-share/facebook.png 2014-06-10 12:45:47 +0000 differ
=== added file 'examples/facebook-share/manifest.json'
--- examples/facebook-share/manifest.json 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/manifest.json 2014-06-10 12:45:47 +0000
@@ -0,0 +1,19 @@
1{
2 "description": "Facebook (webapp version)",
3 "framework": "ubuntu-sdk-14.04-dev1",
4 "architecture": "all",
5 "hooks": {
6 "webapp-facebook": {
7 "account-application": "webapp-facebook.application",
8 "content-hub": "content-hub/content-hub-exporter.json",
9 "account-service": "facebook-webapp.service",
10 "apparmor": "webapp-facebook.json",
11 "desktop": "webapp-facebook.desktop"
12 }
13 },
14 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
15 "name": "com.ubuntu.developer.webapps.webapp-facebook",
16 "title": "webapp-facebook",
17 "version": "1.0.13"
18}
19
020
=== added directory 'examples/facebook-share/unity-webapps-facebook'
=== added file 'examples/facebook-share/unity-webapps-facebook/HubSharer.qml'
--- examples/facebook-share/unity-webapps-facebook/HubSharer.qml 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/unity-webapps-facebook/HubSharer.qml 2014-06-10 12:45:47 +0000
@@ -0,0 +1,80 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem
4import Ubuntu.Components.Popups 0.1
5import Ubuntu.Components.Extras.Browser 0.1
6
7
8/*!
9 \brief MainView with a Label and Button elements.
10*/
11
12Item {
13 id: main
14 // objectName for functional testing purposes (autopilot-qt5)
15 //objectName: "mainView"
16
17 // Note! applicationName needs to match the "name" field of the click manifest
18 //applicationName: "com.ubuntu.developer.ken-vandine.hub-sharer"
19
20 /*
21 This property enables the application to change orientation
22 when the device is rotated. The default is false.
23 */
24 //automaticOrientation: true
25
26 width: parent.width
27 height: parent.height
28 anchors.fill: parent
29
30 signal completed(string result)
31
32 property string fileToShare: "/home/ken/Pictures/Ubuntu_TV.png"
33
34 function _callback(accessToken, fileToShare, message, cb) {
35 print ("_callback: " + accessToken);
36 print ("_callback: " + fileToShare);
37 print ("_callback: " + message);
38 webview.experimental.postMessage(JSON.stringify({file: fileToShare, token: accessToken}));
39 }
40
41 UbuntuWebView {
42 id: webview
43
44 url: Qt.resolvedUrl("uploader.html")
45
46 experimental.onMessageReceived: {
47 completed("[]");
48 }
49
50 experimental.preferences.offlineWebApplicationCacheEnabled: true
51 experimental.preferences.universalAccessFromFileURLsAllowed: true
52 experimental.preferences.navigatorQtObjectEnabled: true
53
54 // port in QTWEBKIT_INSPECTOR_SERVER enviroment variable
55 experimental.preferences.developerExtrasEnabled: true
56 }
57
58 //PageStack {
59 // id: pageStack
60 // Component.onCompleted: push(sharePage)
61
62 //Page {
63 // id: sharePage
64 // anchors.fill: parent
65 // visible: true
66 // title: i18n.tr("Hub Share")
67
68 Share {
69 anchors.fill: parent
70 visible: true
71 fileToShare: main.fileToShare
72 callback: _callback
73 provider: "facebook"
74 onCanceled: print ("canceled")
75 onUploadCompleted: print (success)
76 Component.onCompleted: print ("Page completed " + height + " : " + width)
77 }
78 //}
79 //}
80}
081
=== added file 'examples/facebook-share/unity-webapps-facebook/Share.qml'
--- examples/facebook-share/unity-webapps-facebook/Share.qml 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/unity-webapps-facebook/Share.qml 2014-06-10 12:45:47 +0000
@@ -0,0 +1,303 @@
1/*
2 * Copyright (C) 2012-2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.0
18import QtQuick.Window 2.0
19import Ubuntu.Components 0.1
20import Ubuntu.Components.ListItems 0.1 as ListItem
21import Ubuntu.OnlineAccounts 0.1
22
23Rectangle {
24 id: root
25 anchors.fill: parent
26 color: Theme.palette.normal.background
27 property string fileToShare
28 property var callback
29 property string serviceType: "sharing"
30 property string provider: "facebook"
31 property string userAccountId
32 property string accessToken
33 property var account
34 signal accountSelected
35 signal canceled()
36 signal uploadCompleted(bool success)
37
38 onUploadCompleted: {
39 activitySpinner.visible = false;
40 if (success)
41 print ("Successfully posted");
42 else
43 print ("Failed to post");
44 }
45
46 Component.onCompleted: print ("Root completed " + height + " : " + width)
47
48 AccountServiceModel {
49 id: accounts
50 serviceType: root.serviceType
51 provider: root.provider
52 }
53
54 Rectangle {
55 id: shareComponent
56 objectName: "shareComponent"
57 anchors.fill: parent
58 color: Theme.palette.normal.background
59 visible: false
60
61 Component.onCompleted: print ("shareComponent completed " + height + " : " + width)
62
63 Column {
64 anchors.fill: parent
65 spacing: units.gu(1)
66
67 Item {
68 id: serviceHeader
69 y: 0
70 anchors.left: parent.left
71 anchors.right: parent.right
72 anchors.topMargin: units.gu(1)
73 anchors.leftMargin: units.gu(1)
74 anchors.rightMargin: units.gu(1)
75 height: childrenRect.height
76
77 ListItem.Subtitled {
78 anchors {
79 left: parent.left
80 right: parent.right
81 }
82 iconName: root.account.provider.iconName
83 text: root.account.provider.displayName
84 subText: root.account.displayName
85 showDivider: false
86 }
87 }
88
89 ListItem.ThinDivider {}
90
91 UbuntuShape {
92 id: messageArea
93 objectName: "messageArea"
94 anchors.left: parent.left
95 anchors.right: parent.right
96 anchors.topMargin: units.gu(1)
97 anchors.leftMargin: units.gu(1)
98 anchors.rightMargin: units.gu(1)
99
100 height: units.gu(20)
101 color: "#f2f2f2"
102
103 TextEdit {
104 id: message
105 color: "#333333"
106 anchors.top: parent.top
107 anchors.left: snapshot.right
108 anchors.bottom: parent.bottom
109 anchors.margins: units.gu(1)
110 wrapMode: Text.Wrap
111 width: parent.width - snapshot.width -
112 snapshot.anchors.margins * 2 -
113 message.anchors.leftMargin - message.anchors.rightMargin
114 clip: true
115 font.pixelSize: FontUtils.sizeToPixels("medium")
116 font.weight: Font.Light
117 focus: true
118 }
119
120 ActivityIndicator {
121 id: activitySpinner
122 anchors.centerIn: message
123 visible: false
124 running: visible
125 }
126
127 UbuntuShape {
128 id: snapshot
129 anchors.top: parent.top
130 anchors.left: parent.left
131 anchors.margins: units.gu(1)
132 width: units.gu(10)
133 height: units.gu(10)
134
135 image: Image {
136 source: fileToShare
137 sourceSize.height: snapshot.height
138 sourceSize.width: snapshot.width
139 fillMode: Image.PreserveAspectCrop
140 }
141 }
142 }
143
144 Item {
145 id: actionsBar
146 anchors.left: parent.left
147 anchors.right: parent.right
148 anchors.topMargin: units.gu(2)
149 anchors.leftMargin: units.gu(1)
150 anchors.rightMargin: units.gu(1)
151 height: childrenRect.height
152
153 Button {
154 objectName: "cancelButton"
155 anchors.left: parent.left
156 text: i18n.dtr("ubuntu-ui-extras", "Cancel")
157 color: "#cccccc"
158 width: units.gu(10)
159 height: units.gu(4)
160 onClicked: canceled()
161 }
162
163 Button {
164 objectName: "postButton"
165 anchors.right: parent.right
166 anchors.top: parent.top
167 text: i18n.dtr("ubuntu-ui-extras", "Post")
168 color: "#dd4814"
169 width: units.gu(10)
170 height: units.gu(4)
171 enabled: !activitySpinner.visible
172 onClicked: {
173 activitySpinner.visible = true;
174 callback(accessToken, fileToShare, message.text, uploadCompleted);
175 }
176 }
177 }
178
179 UbuntuShape {
180 id: useLocation
181 anchors {
182 left: parent.left
183 leftMargin: units.gu(1)
184 topMargin: units.gu(1)
185 }
186 color: selected ? "#cccccc" : "transparent"
187 property bool selected: false
188 width: units.gu(4.5)
189 height: units.gu(4)
190
191 AbstractButton {
192 anchors.fill: parent
193 onClicked: parent.selected = !parent.selected
194 Image {
195 source: "assets/icon_location.png"
196 anchors.centerIn: parent
197 height: parent.height * 0.75
198 fillMode: Image.PreserveAspectFit
199 smooth: true
200 }
201 }
202 }
203
204 Label {
205 anchors.left: useLocation.right
206 anchors.baseline: useLocation.top
207 anchors.baselineOffset: units.gu(3)
208 anchors.leftMargin: units.gu(1)
209 text: i18n.dtr("ubuntu-ui-extras", "Include location")
210 fontSize: "small"
211 }
212
213 }
214
215 states: [
216 State {
217 name: "landscape-with-keyborad"
218 PropertyChanges {
219 target: serviceHeader
220 y: - serviceHeader.height
221 }
222 PropertyChanges {
223 target: messageArea
224 height: units.gu(12)
225 }
226 }
227 ]
228
229 state: ((Screen.orientation === Qt.LandscapeOrientation) ||
230 (Screen.orientation === Qt.InvertedLandscapeOrientation)) &&
231 Qt.inputMethod.visible ? "landscape-with-keyborad" : ""
232 }
233
234 /* Menu listing online accounts */
235 Item {
236 id: sharemenu
237 anchors.fill: parent
238 visible: true
239
240 signal selected(string accountId, string token)
241
242 Component.onCompleted: {
243 visible = true;
244 print ("sharemenu completed " + height + " : " + width);
245 }
246 onSelected: {
247 root.userAccountId = accountId;
248 root.accessToken = token;
249 shareComponent.visible = true;
250 sharemenu.visible = false;
251 }
252
253 Component {
254 id: acctDelegate
255 Item {
256 anchors {
257 left: parent.left
258 right: parent.right
259 }
260 AccountService {
261 id: service
262 objectHandle: accountServiceHandle
263 onAuthenticated: {
264 sharemenu.selected(accountId, reply.AccessToken);
265 }
266 }
267
268 height: childrenRect.height
269
270 ListItem.Subtitled {
271 anchors {
272 left: parent.left
273 right: parent.right
274 }
275 text: service.provider.displayName
276 subText: displayName
277 iconName: service.provider.iconName
278 __iconHeight: units.gu(5)
279 __iconWidth: units.gu(5)
280
281 onClicked: {
282 root.account = service;
283 root.account.authenticate(null);
284 }
285 Component.onCompleted: print ("KEN: " + service.provider.displayName + " height: " + height + " y: " + y + " visible: " + visible)
286 }
287 }
288 }
289
290 ListView {
291 anchors {
292 top: parent.top
293 left: parent.left
294 right: parent.right
295 }
296 height: childrenRect.height
297 interactive: false
298 model: accounts
299 delegate: acctDelegate
300 Component.onCompleted: print ("listview completed " + height + " : " + width)
301 }
302 }
303}
0304
=== added file 'examples/facebook-share/unity-webapps-facebook/facebook.user.js'
--- examples/facebook-share/unity-webapps-facebook/facebook.user.js 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/unity-webapps-facebook/facebook.user.js 2014-06-10 12:45:47 +0000
@@ -0,0 +1,72 @@
1var api = external.getUnityObject('1.0');
2
3var oa = api.OnlineAccounts;
4var hub = api.ContentHub;
5
6function _shareRequested(transfer) {
7 transfer.items(function(items) {
8 api.launchEmbeddedUI("HubSharer", upload, {"fileToShare": items[0]});
9 });
10};
11hub.onShareRequested(_shareRequested);
12
13function upload(res) {
14 var results = JSON.parse(res);
15 //console.log (results);
16 console.log (results.accessToken);
17 var xhr = new XMLHttpRequest();
18 xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + results.accessToken, true );
19 xhr.onload = xhr.onerror = function() {
20 console.log( xhr.responseText );
21 };
22
23 //var xhrr = new XMLHttpRequest();
24 //var re = /file:\/\//gi;
25 //var file = results.fileToShare.replace(re, '');
26 //console.log ("FILE: " + results.fileToShare);
27 console.log('file to share lenght: ' + [].slice.call(results.fileToShare).length)
28
29 console.log(results.fileToShare)
30
31 console.log("After atob: " + atob(results.fileToShare))
32
33 var bin = atob(results.fileToShare);
34 var a = new Uint8Array(results.contentlength);
35
36 console.log('results.length: ' + results.size)
37
38 for (var i = 0; i < results.size; ++i) {
39 a[i] = bin.charCodeAt(i);
40 }
41
42 console.log("array buffer content: " + btoa(a.buffer))
43
44 var div = document.createElement('div');
45 div.innerHTML = '<form enctype="multipart/form-data" method="post" id="uploadForm"><textarea id="message" name="message"></textarea></form>';
46 document.getElementsByTagName('body')[0].appendChild(div);
47
48 var blob = new Blob([a], {type: "image/png"});
49
50 console.log('blob size: ' + blob.size)
51 console.log(blob.type)
52
53 var uploadForm = document.forms.namedItem("uploadForm");
54 var formData = new FormData(uploadForm);
55 formData.append('source', blob);
56 xhr.send(formData);
57
58 /*
59 xhrr.open("GET", results.fileToShare, true);
60 xhrr.responseType = "blob";
61 xhrr.onload = function (e) {
62 var blob = new Blob([xhrr.response], {type: "image/png"});
63 var formData = new FormData();
64 formData.append('source', blob);
65 formData.append('message', results.message);
66 xhr.send(formData);
67 }
68 xhrr.send();
69 */
70}
71
72
073
=== added file 'examples/facebook-share/unity-webapps-facebook/manifest.json'
--- examples/facebook-share/unity-webapps-facebook/manifest.json 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/unity-webapps-facebook/manifest.json 2014-06-10 12:45:47 +0000
@@ -0,0 +1,7 @@
1{
2 "name": "facebook",
3 "includes": ["https://*.facebook.com/*"],
4 "homepage": "https://m.facebook.com/",
5 "domain": "facebook.com",
6 "scripts": ["facebook.user.js"]
7}
08
=== added file 'examples/facebook-share/unity-webapps-facebook/uploader.html'
--- examples/facebook-share/unity-webapps-facebook/uploader.html 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/unity-webapps-facebook/uploader.html 2014-06-10 12:45:47 +0000
@@ -0,0 +1,15 @@
1<html>
2<head>
3<script src="./uploader.js"></script>
4</head>
5<body>
6
7 <div>
8 <form enctype="multipart/form-data" method="post" id="uploadForm">
9 <textarea id="message" name="message" rows="5" style="height: auto; width: 600px;" placeholder="What's on your mind?">
10 </textarea>
11 </form>
12 </div>
13
14<body>
15</html>
016
=== added file 'examples/facebook-share/unity-webapps-facebook/uploader.js'
--- examples/facebook-share/unity-webapps-facebook/uploader.js 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/unity-webapps-facebook/uploader.js 2014-06-10 12:45:47 +0000
@@ -0,0 +1,34 @@
1/**
2 * Wait before the DOM has been loaded before initializing the Ubuntu UI layer
3 */
4navigator.qt.onmessage = function(message) {
5 var data = null;
6 try {
7 data = JSON.parse(message.data);
8 } catch (error) {
9 return;
10 }
11 upload(data.file, data.token);
12}
13
14function upload(file, token) {
15 // FIXME: we should submit multiples if we can
16 var xhr = new XMLHttpRequest();
17 xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + token, true );
18 xhr.onload = xhr.onerror = function() {
19 navigator.qt.postMessage(JSON.stringify({}));
20 };
21
22 var xhrr = new XMLHttpRequest();
23 xhrr.open("GET", file, true);
24 xhrr.responseType = "blob";
25 xhrr.onload = function (e) {
26 var blob = new Blob([xhrr.response], {type: "image/png"});
27 var uploadForm = document.forms.namedItem("uploadForm");
28 var formData = new FormData(uploadForm);
29 formData.append('source', blob);
30 xhr.send(formData);
31 }
32 xhrr.send();
33}
34
035
=== added file 'examples/facebook-share/webapp-facebook.application'
--- examples/facebook-share/webapp-facebook.application 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/webapp-facebook.application 2014-06-10 12:45:47 +0000
@@ -0,0 +1,11 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2<application id="com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook">
3 <description>Facebook webapp</description>
4
5 <services>
6 <service id="com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook">
7 <description>Use the service in a webapp</description>
8 </service>
9 </services>
10
11</application>
012
=== added file 'examples/facebook-share/webapp-facebook.desktop'
--- examples/facebook-share/webapp-facebook.desktop 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/webapp-facebook.desktop 2014-06-10 12:45:47 +0000
@@ -0,0 +1,9 @@
1[Desktop Entry]
2Type=Application
3Terminal=false
4Exec=webapp-container --enable-back-forward --webappModelSearchPath=. --webappUrlPatterns=https?://*.facebook.com/*
5Name=Facebook
6Icon=./facebook.png
7X-Ubuntu-Touch=true
8X-Ubuntu-StageHint=SideStage
9X-Ubuntu-Single-Instance=true
010
=== added file 'examples/facebook-share/webapp-facebook.json'
--- examples/facebook-share/webapp-facebook.json 1970-01-01 00:00:00 +0000
+++ examples/facebook-share/webapp-facebook.json 2014-06-10 12:45:47 +0000
@@ -0,0 +1,13 @@
1{
2 "template": "ubuntu-webapp",
3 "policy_groups": [
4 "networking",
5 "audio",
6 "video",
7 "webview",
8 "location",
9 "content_exchange",
10 "content_exchange_source"
11 ],
12 "policy_version": 1.1
13}
014
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-05-16 16:29:35 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-06-10 12:45:47 +0000
@@ -413,6 +413,27 @@
413 return null;413 return null;
414 }414 }
415415
416 /*!
417 \internal
418
419 */
420 function __getPolicyForContent(settings) {
421 // TODO: review this
422 function PassthroughPolicy() {};
423 PassthroughPolicy.prototype.allowed = function(signature) {
424 return true;
425 };
426 function RestrictedPolicy(restrictions) {
427 this.restrictions = restrictions || [];
428 };
429 RestrictedPolicy.prototype.allowed = function(signature) {
430 return this.restrictions.some(function(e) { return e == signature; });
431 };
432
433 if (injectExtraUbuntuApis)
434 return new PassthroughPolicy();
435 return new RestrictedPolicy(["ContentHub.onShareRequested"])
436 }
416437
417 /*!438 /*!
418 \internal439 \internal
@@ -524,6 +545,59 @@
524 UnityBackends.get("hud").clearActions();545 UnityBackends.get("hud").clearActions();
525 },546 },
526547
548 launchEmbeddedUI: function(name, callback, params) {
549 if ( ! model) {
550 print ("No model");
551 return;
552 }
553
554 // TODO validate
555 var path = model.path(webapps.name);
556 console.debug ("PATH: " + path);
557 if (! path || path.length == 0)
558 return;
559
560 var backendDelegate = UnityBackends.backendDelegate;
561
562 var parentItem = backendDelegate.parentView();
563 if ( ! parentItem || ! parentItem.visible || ! parentItem.height || ! parentItem.width) {
564 console.debug("Cannot launch the content peer picker UI, invalid parent item: " + parentItem);
565 callback({result: "cancelled"});
566 return;
567 }
568
569 var p = parentItem.parent ? parentItem.parent : parentItem
570
571 var c;
572 function oncreated() {
573 //if (p) {
574 // p.visible = false;
575 //}
576
577 var ui = c.createObject(p, {"fileToShare": params.fileToShare.url, "visible": true});
578
579 if ( ! ui.onCompleted) {
580 ui.destroy();
581 return;
582 }
583
584 function _onCompleted(data) {
585 ui.visible = false;
586 p.visible = true;
587 ui.onCompleted.disconnect(_onCompleted);
588 ui.destroy();
589 callback(data);
590 }
591 ui.onCompleted.connect(_onCompleted);
592 };
593
594 c = Qt.createComponent(path + "/" + name + ".qml");
595 if (c.status == Component.Ready)
596 oncreated()
597 else
598 c.statusChanged.connect(oncreated)
599 },
600
527 Notification: {601 Notification: {
528 showNotification: function (summary, body, iconUrl) {602 showNotification: function (summary, body, iconUrl) {
529 if (!initialized)603 if (!initialized)
@@ -641,17 +715,13 @@
641 }715 }
642 },716 },
643717
644 OnlineAccounts: __injectResourceIfExtraApisAreEnabled(function() {718 OnlineAccounts: OnlineAccountsApiBackend.createOnlineAccountsApi(UnityBackends.backendDelegate),
645 return OnlineAccountsApiBackend.createOnlineAccountsApi(UnityBackends.backendDelegate)
646 }),
647719
648 Alarm: __injectResourceIfExtraApisAreEnabled(function() {720 Alarm: __injectResourceIfExtraApisAreEnabled(function() {
649 return AlarmApiBackend.createAlarmApi(UnityBackends.backendDelegate)721 return AlarmApiBackend.createAlarmApi(UnityBackends.backendDelegate)
650 }),722 }),
651723
652 ContentHub: __injectResourceIfExtraApisAreEnabled(function() {724 ContentHub: ContentHubApiBackend.createContentHubApi(UnityBackends.backendDelegate),
653 return ContentHubApiBackend.createContentHubApi(UnityBackends.backendDelegate)
654 }),
655725
656 RuntimeApi: __injectResourceIfExtraApisAreEnabled(function() {726 RuntimeApi: __injectResourceIfExtraApisAreEnabled(function() {
657 return RuntimeApiBackend.createRuntimeApi(UnityBackends.backendDelegate)727 return RuntimeApiBackend.createRuntimeApi(UnityBackends.backendDelegate)
658728
=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js'
--- src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-05-08 13:01:07 +0000
+++ src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-06-10 12:45:47 +0000
@@ -24,7 +24,7 @@
24 *24 *
25 */25 */
2626
27function createContentHubApi(backendDelegate) {27function createContentHubApi(backendDelegate, accessPolicy) {
28 var PLUGIN_URI = 'Ubuntu.Content';28 var PLUGIN_URI = 'Ubuntu.Content';
29 var VERSION = 0.1;29 var VERSION = 0.1;
3030
@@ -769,6 +769,20 @@
769 });769 });
770 },770 },
771771
772 onImportRequested: function(callback) {
773 _contenthub.onImportRequested.connect(function(importTransfer) {
774 var wrapped = new ContentTransfer(importTransfer);
775 callback(wrapped.serialize());
776 });
777 },
778
779 onShareRequested: function(callback) {
780 _contenthub.shareRequested.connect(function(shareTransfer) {
781 var wrapped = new ContentTransfer(shareTransfer);
782 callback(wrapped.serialize());
783 });
784 },
785
772 // Internal786 // Internal
773787
774 dispatchToObject: function(infos) {788 dispatchToObject: function(infos) {
775789
=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js'
--- src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-03-18 13:59:36 +0000
+++ src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-06-10 12:45:47 +0000
@@ -836,6 +836,58 @@
836 [callback]);836 [callback]);
837 },837 },
838838
839 /**
840 * Sets a handler that is to be called when the current application is the
841 * target of an share request.
842 *
843 * @method onExportRequested
844 * @param callback {Function(ContentTransfer)} Function when one requests a resource to be shared.
845 * The corresponding ContentTransfer is provided as a parameter.
846 *
847 * @example
848
849 var api = external.getUnityObject(1.0);
850 var hub = api.ContentHub;
851
852 var transferState = hub.ContentTransfer.State;
853
854 function _shareRequested(transfer) {
855 };
856
857 hub.onShareRequested(_shareRequested);
858
859 */
860 onShareRequested: function(callback) {
861 backendBridge.call('ContentHub.onShareRequested',
862 [callback]);
863 },
864
865 /**
866 * Sets a handler that is to be called when the current application is the
867 * target of an import request.
868 *
869 * @method onImportRequested
870 * @param callback {Function(ContentTransfer)} Function when one requests a resource to be imported.
871 * The corresponding ContentTransfer is provided as a parameter.
872 *
873 * @example
874
875 var api = external.getUnityObject(1.0);
876 var hub = api.ContentHub;
877
878 var transferState = hub.ContentTransfer.State;
879
880 function _importRequested(transfer) {
881 };
882
883 hub.onImportRequested(_importRequested);
884
885 */
886 onImportRequested: function(callback) {
887 backendBridge.call('ContentHub.onImportRequested',
888 [callback]);
889 },
890
839 api: {891 api: {
840892
841 /**893 /**
842894
=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js'
--- src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2014-05-09 13:17:09 +0000
+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2014-06-10 12:45:47 +0000
@@ -21,7 +21,7 @@
21 * Online Accounts API backend binding21 * Online Accounts API backend binding
22 *22 *
23 */23 */
24function createOnlineAccountsApi(backendDelegate) {24function createOnlineAccountsApi(backendDelegate, accessPolicy) {
25 var PLUGIN_URI = 'Ubuntu.OnlineAccounts';25 var PLUGIN_URI = 'Ubuntu.OnlineAccounts';
26 var VERSION = 0.1;26 var VERSION = 0.1;
2727
2828
=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp'
--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2014-05-14 01:41:14 +0000
+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2014-06-10 12:45:47 +0000
@@ -156,6 +156,7 @@
156 roles[Scripts] = "scripts";156 roles[Scripts] = "scripts";
157 roles[Chrome] = "chrome";157 roles[Chrome] = "chrome";
158 roles[UserAgentOverride] = "useragent";158 roles[UserAgentOverride] = "useragent";
159 roles[Path] = "path";
159 }160 }
160 return roles;161 return roles;
161}162}
@@ -337,6 +338,21 @@
337}338}
338339
339QString340QString
341UnityWebappsAppModel::path(const QString & webappName) const {
342 if (!exists(webappName))
343 return QString();
344
345 int idx = getWebappIndex(webappName);
346 if (Q_UNLIKELY(idx == -1))
347 {
348 qDebug() << "Invalid index for a supposedly existing webapp: " << webappName;
349 return QString();
350 }
351
352 return data(idx, Path).toString();
353}
354
355QString
340UnityWebappsAppModel::userAgentOverrideFor(const QString & webappName) const356UnityWebappsAppModel::userAgentOverrideFor(const QString & webappName) const
341{357{
342 if (!exists(webappName))358 if (!exists(webappName))
@@ -543,6 +559,9 @@
543559
544 case UserAgentOverride:560 case UserAgentOverride:
545 return webapp.data.manifest.userAgentOverride;561 return webapp.data.manifest.userAgentOverride;
562
563 case Path:
564 return webapp.userscriptLocation;
546 }565 }
547566
548 return QVariant();567 return QVariant();
549568
=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h'
--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h 2014-05-08 15:20:47 +0000
+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h 2014-06-10 12:45:47 +0000
@@ -58,7 +58,8 @@
58 Scripts,58 Scripts,
59 ScriptsContent,59 ScriptsContent,
60 Chrome,60 Chrome,
61 UserAgentOverride61 UserAgentOverride,
62 Path
62 };63 };
6364
64 // QAbstractListModel implementation65 // QAbstractListModel implementation
@@ -108,6 +109,11 @@
108 */109 */
109 Q_INVOKABLE QString userAgentOverrideFor(const QString & webappName) const;110 Q_INVOKABLE QString userAgentOverrideFor(const QString & webappName) const;
110111
112 /*!
113 * \brief
114 */
115 Q_INVOKABLE QString path(const QString & webappName) const;
116
111117
112 /*!118 /*!
113 * \brief119 * \brief
114120
=== modified file 'src/Ubuntu/UnityWebApps/unity-webapps-api.js.in'
--- src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2014-05-13 17:48:43 +0000
+++ src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2014-06-10 12:45:47 +0000
@@ -98,6 +98,12 @@
98 clearActions: createArgumentsSanitizer (backend, [], 'clearActions'),98 clearActions: createArgumentsSanitizer (backend, [], 'clearActions'),
9999
100 /**100 /**
101 */
102 launchEmbeddedUI: function(name, callback, params) {
103 backend.call('launchEmbeddedUI', [name, callback, params]);
104 },
105
106 /**
101 *107 *
102 * MediaPlayer API108 * MediaPlayer API
103 *109 *

Subscribers

People subscribed via source and target branches

to all changes: