Merge lp:~ken-vandine/webapps-core/facebook-userscript into lp:webapps-core

Proposed by Ken VanDine
Status: Merged
Merged at revision: 52
Proposed branch: lp:~ken-vandine/webapps-core/facebook-userscript
Merge into: lp:webapps-core
Diff against target: 604 lines (+518/-6)
8 files modified
webapp-facebook/content-hub/webapp-facebook.json (+5/-0)
webapp-facebook/manifest.json (+4/-4)
webapp-facebook/unity-webapps-facebook/HubSharer.qml (+65/-0)
webapp-facebook/unity-webapps-facebook/Share.qml (+383/-0)
webapp-facebook/unity-webapps-facebook/facebook.user.js (+51/-0)
webapp-facebook/unity-webapps-facebook/manifest.json (+7/-0)
webapp-facebook/webapp-facebook.desktop (+1/-1)
webapp-facebook/webapp-facebook.json (+2/-1)
To merge this branch: bzr merge lp:~ken-vandine/webapps-core/facebook-userscript
Reviewer Review Type Date Requested Status
David Barth Pending
Review via email: mp+223991@code.launchpad.net

Commit message

Implements a share handler in the facebook webapp.

Description of the change

Implements a share handler in the facebook webapp. This requires updates[1] to unity-webapps-qml to be fully functional.

[1] https://code.launchpad.net/~abreu-alexandre/unity-webapps-qml/add-content-hub-share

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'webapp-facebook/content-hub'
=== added file 'webapp-facebook/content-hub/webapp-facebook.json'
--- webapp-facebook/content-hub/webapp-facebook.json 1970-01-01 00:00:00 +0000
+++ webapp-facebook/content-hub/webapp-facebook.json 2014-06-20 21:39:29 +0000
@@ -0,0 +1,5 @@
1{
2 "share": [
3 "pictures"
4 ]
5}
06
=== modified file 'webapp-facebook/manifest.json'
--- webapp-facebook/manifest.json 2014-06-20 13:54:52 +0000
+++ webapp-facebook/manifest.json 2014-06-20 21:39:29 +0000
@@ -1,11 +1,12 @@
1{1{
2 "description": "Facebook (webapp version)",2 "description": "Facebook (webapp version)",
3 "framework": "ubuntu-sdk-14.04-dev1",3 "framework": "ubuntu-sdk-14.10-dev1",
4 "architecture": "all",4 "architecture": "all",
5 "hooks": {5 "hooks": {
6 "webapp-facebook": {6 "webapp-facebook": {
7 "account-application": "webapp-facebook.application",7 "account-application": "webapp-facebook.application",
8 "account-service": "facebook-webapp.service",8 "content-hub": "content-hub/webapp-facebook.json",
9 "account-service": "webapp-facebook.service",
9 "apparmor": "webapp-facebook.json",10 "apparmor": "webapp-facebook.json",
10 "desktop": "webapp-facebook.desktop"11 "desktop": "webapp-facebook.desktop"
11 }12 }
@@ -13,6 +14,5 @@
13 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",14 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
14 "name": "com.ubuntu.developer.webapps.webapp-facebook",15 "name": "com.ubuntu.developer.webapps.webapp-facebook",
15 "title": "webapp-facebook",16 "title": "webapp-facebook",
16 "version": "1.0.13"17 "version": "1.0.13.2"
17}18}
18
1919
=== added directory 'webapp-facebook/unity-webapps-facebook'
=== added file 'webapp-facebook/unity-webapps-facebook/HubSharer.qml'
--- webapp-facebook/unity-webapps-facebook/HubSharer.qml 1970-01-01 00:00:00 +0000
+++ webapp-facebook/unity-webapps-facebook/HubSharer.qml 2014-06-20 21:39:29 +0000
@@ -0,0 +1,65 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import Ubuntu.Content 0.1
4
5Item {
6 id: main
7 anchors.fill: parent
8
9 signal completed(string result, var uploadCompletedCallback)
10
11 property string fileToShare
12
13 function _callback(accessToken, fileToShare, message, uploadCompletedCallback) {
14
15 itemComp.url = fileToShare;
16 var dataUri = itemComp.toDataURI();
17 var result = {accessToken: accessToken,
18 fileToShare: dataUri.toString(),
19 message: message};
20
21 completed(JSON.stringify(result), uploadCompletedCallback);
22 }
23
24 ContentItem {
25 id: itemComp
26 }
27
28 Rectangle {
29 anchors.fill: parent
30 color: UbuntuColors.lightGrey
31
32 Image {
33 id: background
34 anchors {
35 left: parent.left
36 right: parent.right
37 bottom: parent.bottom
38 }
39 source: Qt.resolvedUrl("assets/background_full.png")
40 }
41 }
42
43 Share {
44 id: share
45 anchors.fill: parent
46 visible: true
47 fileToShare: main.fileToShare
48 callback: _callback
49 provider: "facebook"
50 onCanceled: {
51 completed(JSON.stringify({status: "cancelled"}), uploadCompleted);
52 parent.destroy();
53 }
54 onUploadCompleted: {
55 console.log (success);
56 /* if the upload was successful, we need to destroy the parent */
57 if (success) {
58 parent.destroy();
59 } else {
60 console.error ("Upload failed");
61 /* FIXME: Display a message to the user */
62 }
63 }
64 }
65}
066
=== added file 'webapp-facebook/unity-webapps-facebook/Share.qml'
--- webapp-facebook/unity-webapps-facebook/Share.qml 1970-01-01 00:00:00 +0000
+++ webapp-facebook/unity-webapps-facebook/Share.qml 2014-06-20 21:39:29 +0000
@@ -0,0 +1,383 @@
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
22import Ubuntu.OnlineAccounts.Client 0.1
23
24Item {
25 id: root
26 anchors.fill: parent
27 property string fileToShare
28 property var callback
29 property string serviceType: "webapps"
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 AccountServiceModel {
47 id: accounts
48 serviceType: root.serviceType
49 provider: root.provider
50 Component.onCompleted: {
51 if (count == 1) {
52 srv.objectHandle = get(0, "accountServiceHandle");
53 }
54 }
55 }
56
57 AccountService {
58 id: srv
59 onObjectHandleChanged: {
60 root.account = srv;
61 root.account.authenticate(null);
62 }
63 onAuthenticated: {
64 root.userAccountId = accountId;
65 root.accessToken = reply.AccessToken;
66 shareComponent.visible = true;
67 sharemenu.visible = false;
68 }
69 }
70
71 Item {
72 id: shareComponent
73 objectName: "shareComponent"
74 anchors {
75 left: parent.left
76 right: parent.right
77 }
78 visible: false
79
80 Column {
81 anchors.fill: parent
82 spacing: units.gu(1)
83
84 Item {
85 id: serviceHeader
86 y: 0
87 anchors.left: parent.left
88 anchors.right: parent.right
89 anchors.topMargin: units.gu(1)
90 anchors.leftMargin: units.gu(1)
91 anchors.rightMargin: units.gu(1)
92 height: childrenRect.height
93
94 ListItem.Subtitled {
95 anchors {
96 left: parent.left
97 right: parent.right
98 }
99 iconName: root.account.provider.iconName
100 text: root.account.provider.displayName
101 subText: root.account.displayName
102 showDivider: false
103 }
104 }
105
106 ListItem.ThinDivider {}
107
108 UbuntuShape {
109 id: messageArea
110 objectName: "messageArea"
111 anchors.left: parent.left
112 anchors.right: parent.right
113 anchors.topMargin: units.gu(1)
114 anchors.leftMargin: units.gu(1)
115 anchors.rightMargin: units.gu(1)
116 height: units.gu(20)
117 color: "#f2f2f2"
118
119 TextArea {
120 id: message
121 //color: "#333333"
122 anchors.top: parent.top
123 anchors.left: snapshot.right
124 anchors.bottom: parent.bottom
125 anchors.margins: units.gu(1)
126 wrapMode: Text.Wrap
127 width: parent.width - snapshot.width -
128 snapshot.anchors.margins * 2 -
129 message.anchors.leftMargin - message.anchors.rightMargin
130 clip: true
131 font.pixelSize: FontUtils.sizeToPixels("medium")
132 font.weight: Font.Light
133 focus: true
134 }
135
136 ActivityIndicator {
137 id: activitySpinner
138 anchors.centerIn: message
139 visible: false
140 running: visible
141 }
142
143 UbuntuShape {
144 id: snapshot
145 anchors.top: parent.top
146 anchors.left: parent.left
147 anchors.margins: units.gu(1)
148 width: units.gu(10)
149 height: units.gu(10)
150
151 image: Image {
152 source: fileToShare
153 sourceSize.height: snapshot.height
154 sourceSize.width: snapshot.width
155 fillMode: Image.PreserveAspectCrop
156 }
157 }
158 }
159
160 Item {
161 id: actionsBar
162 anchors.left: parent.left
163 anchors.right: parent.right
164 anchors.topMargin: units.gu(2)
165 anchors.leftMargin: units.gu(1)
166 anchors.rightMargin: units.gu(1)
167 height: childrenRect.height
168
169 Button {
170 objectName: "cancelButton"
171 anchors.left: parent.left
172 text: i18n.dtr("ubuntu-ui-extras", "Cancel")
173 color: "#cccccc"
174 width: units.gu(10)
175 height: units.gu(4)
176 onClicked: canceled()
177 }
178
179 Button {
180 objectName: "postButton"
181 anchors.right: parent.right
182 anchors.top: parent.top
183 text: i18n.dtr("ubuntu-ui-extras", "Post")
184 color: "#dd4814"
185 width: units.gu(10)
186 height: units.gu(4)
187 enabled: !activitySpinner.visible
188 onClicked: {
189 activitySpinner.visible = true;
190 callback(accessToken, fileToShare, message.text, uploadCompleted);
191 }
192 }
193 }
194
195 // toggle to enable including location - Not implemented yet
196 /*
197 UbuntuShape {
198 id: useLocation
199 anchors {
200 left: parent.left
201 leftMargin: units.gu(1)
202 topMargin: units.gu(1)
203 }
204 color: selected ? "#cccccc" : "transparent"
205 property bool selected: false
206 width: units.gu(4.5)
207 height: units.gu(4)
208
209 AbstractButton {
210 anchors.fill: parent
211 onClicked: parent.selected = !parent.selected
212 Image {
213 source: "assets/icon_location.png"
214 anchors.centerIn: parent
215 height: parent.height * 0.75
216 fillMode: Image.PreserveAspectFit
217 smooth: true
218 }
219 }
220 }
221
222 Label {
223 anchors.left: useLocation.right
224 anchors.baseline: useLocation.top
225 anchors.baselineOffset: units.gu(3)
226 anchors.leftMargin: units.gu(1)
227 text: i18n.dtr("ubuntu-ui-extras", "Include location")
228 fontSize: "small"
229 }
230 */
231 // End location toggle
232
233 }
234
235 states: [
236 State {
237 name: "landscape-with-keyborad"
238 PropertyChanges {
239 target: serviceHeader
240 y: - serviceHeader.height
241 }
242 PropertyChanges {
243 target: messageArea
244 height: units.gu(12)
245 }
246 }
247 ]
248
249 state: ((Screen.orientation === Qt.LandscapeOrientation) ||
250 (Screen.orientation === Qt.InvertedLandscapeOrientation)) &&
251 Qt.inputMethod.visible ? "landscape-with-keyborad" : ""
252 }
253
254 /* Menu listing online accounts */
255 Item {
256 id: sharemenu
257 anchors.fill: parent
258 visible: true
259
260 signal selected(string accountId, string token)
261
262 Component.onCompleted: {
263 visible = true;
264 }
265 onSelected: {
266 root.userAccountId = accountId;
267 root.accessToken = token;
268 shareComponent.visible = true;
269 sharemenu.visible = false;
270 }
271
272 Component {
273 id: acctDelegate
274 Item {
275 anchors {
276 left: parent.left
277 right: parent.right
278 }
279 AccountService {
280 id: service
281 objectHandle: accountServiceHandle
282 onAuthenticated: {
283 sharemenu.selected(accountId, reply.AccessToken);
284 }
285 }
286
287 height: childrenRect.height
288
289 ListItem.Subtitled {
290 anchors {
291 left: parent.left
292 right: parent.right
293 }
294 text: service.provider.displayName
295 subText: displayName
296 iconName: service.provider.iconName
297 __iconHeight: units.gu(5)
298 __iconWidth: units.gu(5)
299
300 onClicked: {
301 root.account = service;
302 root.account.authenticate(null);
303 }
304 }
305 }
306 }
307
308 ListView {
309 anchors {
310 top: parent.top
311 left: parent.left
312 right: parent.right
313 }
314 height: childrenRect.height
315 interactive: false
316 visible: !listView.visible
317 model: accounts
318 header: ListItem.Header {
319 anchors {
320 left: parent.left
321 right: parent.right
322 }
323 text: i18n.tr("Select account")
324 }
325 delegate: acctDelegate
326 }
327
328 ListView {
329 id: listView
330 anchors {
331 top: parent.top
332 left: parent.left
333 right: parent.right
334 }
335 height: childrenRect.height
336 header: headerComponent
337 model: providerModel
338 visible: accounts.count === 0
339 delegate: providerDelegate
340
341 Component {
342 id: headerComponent
343 ListItem.Header {
344 anchors {
345 left: parent.left
346 right: parent.right
347 }
348 text: i18n.tr("No online accounts configured")
349 }
350 }
351
352 Component {
353 id: providerDelegate
354 Item {
355 anchors {
356 left: parent.left
357 right: parent.right
358 }
359 height: childrenRect.height
360 ListItem.Standard {
361 text: model.displayName
362 iconName: model.iconName
363 onClicked: {
364 setup.providerId = providerId
365 setup.exec()
366 }
367 }
368 }
369 }
370
371
372 ProviderModel {
373 id: providerModel
374 applicationId: "com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook"
375 }
376
377 Setup {
378 id: setup
379 applicationId: "com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook"
380 }
381 }
382 }
383}
0384
=== added directory 'webapp-facebook/unity-webapps-facebook/assets'
=== added file 'webapp-facebook/unity-webapps-facebook/assets/avatar_image.jpg'
1Binary files webapp-facebook/unity-webapps-facebook/assets/avatar_image.jpg 1970-01-01 00:00:00 +0000 and webapp-facebook/unity-webapps-facebook/assets/avatar_image.jpg 2014-06-20 21:39:29 +0000 differ385Binary files webapp-facebook/unity-webapps-facebook/assets/avatar_image.jpg 1970-01-01 00:00:00 +0000 and webapp-facebook/unity-webapps-facebook/assets/avatar_image.jpg 2014-06-20 21:39:29 +0000 differ
=== added file 'webapp-facebook/unity-webapps-facebook/assets/background_full@27.png'
2Binary files webapp-facebook/unity-webapps-facebook/assets/background_full@27.png 1970-01-01 00:00:00 +0000 and webapp-facebook/unity-webapps-facebook/assets/background_full@27.png 2014-06-20 21:39:29 +0000 differ386Binary files webapp-facebook/unity-webapps-facebook/assets/background_full@27.png 1970-01-01 00:00:00 +0000 and webapp-facebook/unity-webapps-facebook/assets/background_full@27.png 2014-06-20 21:39:29 +0000 differ
=== added file 'webapp-facebook/unity-webapps-facebook/assets/icon_location.png'
3Binary files webapp-facebook/unity-webapps-facebook/assets/icon_location.png 1970-01-01 00:00:00 +0000 and webapp-facebook/unity-webapps-facebook/assets/icon_location.png 2014-06-20 21:39:29 +0000 differ387Binary files webapp-facebook/unity-webapps-facebook/assets/icon_location.png 1970-01-01 00:00:00 +0000 and webapp-facebook/unity-webapps-facebook/assets/icon_location.png 2014-06-20 21:39:29 +0000 differ
=== added file 'webapp-facebook/unity-webapps-facebook/facebook.user.js'
--- webapp-facebook/unity-webapps-facebook/facebook.user.js 1970-01-01 00:00:00 +0000
+++ webapp-facebook/unity-webapps-facebook/facebook.user.js 2014-06-20 21:39:29 +0000
@@ -0,0 +1,51 @@
1var api = external.getUnityObject('1.0');
2var hub = api.ContentHub;
3var activeTransfer;
4
5function _shareRequested(transfer) {
6 activeTransfer = transfer;
7 transfer.items(function(items) {
8 api.launchEmbeddedUI("HubSharer", upload, {"fileToShare": items[0]});
9 });
10};
11
12hub.onShareRequested(_shareRequested);
13
14function upload(res, uploadCompletedCallback) {
15 var results = JSON.parse(res);
16 if (results.status == "cancelled")
17 activeTransfer.setState(hub.ContentTransfer.State.Aborted);
18
19 var xhr = new XMLHttpRequest();
20 xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + results.accessToken, true );
21 xhr.onload = xhr.onerror = function() {
22 if ( xhr.status == 200 ) {
23 uploadCompletedCallback(true);
24 window.location.reload();
25 } else {
26 uploadCompletedCallback(false);
27 }
28 };
29
30 var contentType = results.fileToShare.split(',')[0].split(':')[1];
31 var b64data = results.fileToShare.split(',')[1];
32
33 var byteCharacters = atob(b64data);
34 var byteNumbers = new Array(byteCharacters.length);
35 for (var i = 0; i < byteCharacters.length; i++) {
36 byteNumbers[i] = byteCharacters.charCodeAt(i);
37 }
38 var byteArray = new Uint8Array(byteNumbers);
39
40 var div = document.createElement('div');
41 div.innerHTML = '<form enctype="multipart/form-data" method="post" id="uploadForm"><textarea id="message" name="message"></textarea></form>';
42 document.getElementsByTagName('body')[0].appendChild(div);
43
44 var blob = new Blob([byteArray], {type: contentType});
45
46 var uploadForm = document.forms.namedItem("uploadForm");
47 var formData = new FormData(uploadForm);
48 formData.append('source', blob);
49 formData.append('message', results.message);
50 xhr.send(formData);
51}
052
=== added file 'webapp-facebook/unity-webapps-facebook/manifest.json'
--- webapp-facebook/unity-webapps-facebook/manifest.json 1970-01-01 00:00:00 +0000
+++ webapp-facebook/unity-webapps-facebook/manifest.json 2014-06-20 21:39:29 +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
=== modified file 'webapp-facebook/webapp-facebook.desktop'
--- webapp-facebook/webapp-facebook.desktop 2014-06-20 13:54:52 +0000
+++ webapp-facebook/webapp-facebook.desktop 2014-06-20 21:39:29 +0000
@@ -1,7 +1,7 @@
1[Desktop Entry]1[Desktop Entry]
2Type=Application2Type=Application
3Terminal=false3Terminal=false
4Exec=webapp-container --enable-back-forward --popup-redirection-url-prefix=http://lm.facebook.com/l.php?u= --webappUrlPatterns=https?://*.facebook.com/* https://m.facebook.com/4Exec=webapp-container --enable-back-forward --popup-redirection-url-prefix=http://lm.facebook.com/l.php?u= --webapp='ZmFjZWJvb2s=' --webappModelSearchPath=. --webappUrlPatterns=https?://*.facebook.com/* https://m.facebook.com/
5Name=Facebook5Name=Facebook
6Icon=./facebook.png6Icon=./facebook.png
7X-Ubuntu-Touch=true7X-Ubuntu-Touch=true
88
=== modified file 'webapp-facebook/webapp-facebook.json'
--- webapp-facebook/webapp-facebook.json 2014-04-10 21:52:56 +0000
+++ webapp-facebook/webapp-facebook.json 2014-06-20 21:39:29 +0000
@@ -2,11 +2,12 @@
2 "template": "ubuntu-webapp",2 "template": "ubuntu-webapp",
3 "policy_groups": [ 3 "policy_groups": [
4 "networking",4 "networking",
5 "accounts",
5 "audio",6 "audio",
6 "video",7 "video",
7 "webview",8 "webview",
8 "location",9 "location",
9 "content_exchange"10 "content_exchange"
10 ],11 ],
11 "policy_version": 1.112 "policy_version": 1.2
12}13}
1314
=== renamed file 'webapp-facebook/facebook-webapp.service' => 'webapp-facebook/webapp-facebook.service'

Subscribers

People subscribed via source and target branches

to all changes: