Merge lp:~abreu-alexandre/webapps-core/share-contenthub-links into lp:webapps-core

Proposed by Alexandre Abreu
Status: Approved
Approved by: Alexandre Abreu
Approved revision: 119
Proposed branch: lp:~abreu-alexandre/webapps-core/share-contenthub-links
Merge into: lp:webapps-core
Diff against target: 413 lines (+173/-45)
11 files modified
webapp-facebook/content-hub/webapp-facebook.json (+2/-1)
webapp-facebook/manifest.json (+1/-1)
webapp-facebook/unity-webapps-facebook/HubSharer.qml (+13/-3)
webapp-facebook/unity-webapps-facebook/Share.qml (+10/-4)
webapp-facebook/unity-webapps-facebook/facebook.user.js (+74/-4)
webapp-googleplus/content-hub/webapp-googleplus.json (+2/-1)
webapp-googleplus/manifest.json (+1/-1)
webapp-googleplus/webview-override.qml (+44/-22)
webapp-twitter/content-hub/webapp-twitter.json (+2/-1)
webapp-twitter/manifest.json (+1/-1)
webapp-twitter/unity-webapps-twitter/share.user.js (+23/-6)
To merge this branch: bzr merge lp:~abreu-alexandre/webapps-core/share-contenthub-links
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+256696@code.launchpad.net

Commit message

Add link sharing

Description of the change

To post a comment you must log in.
113. By Alexandre Abreu

Added an initial selenium + autopilot test for a webapp. It runs locally, on qemu and on the phone.

114. By Alexandre Abreu

fix cookies data path

115. By Alexandre Abreu

bump g+

116. By Alexandre Abreu

Fix gplus

117. By Alexandre Abreu

allow ebay description page pattern

118. By Alexandre Abreu

Fix bad ebay webapp framework

119. By Alexandre Abreu

share content hub links

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'webapp-facebook/content-hub/webapp-facebook.json'
2--- webapp-facebook/content-hub/webapp-facebook.json 2014-06-19 17:20:53 +0000
3+++ webapp-facebook/content-hub/webapp-facebook.json 2015-09-21 14:46:23 +0000
4@@ -1,5 +1,6 @@
5 {
6 "share": [
7- "pictures"
8+ "pictures",
9+ "links"
10 ]
11 }
12
13=== modified file 'webapp-facebook/manifest.json'
14--- webapp-facebook/manifest.json 2014-10-13 17:24:22 +0000
15+++ webapp-facebook/manifest.json 2015-09-21 14:46:23 +0000
16@@ -19,5 +19,5 @@
17 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
18 "name": "com.ubuntu.developer.webapps.webapp-facebook",
19 "title": "Facebook",
20- "version": "1.0.26"
21+ "version": "1.1"
22 }
23
24=== modified file 'webapp-facebook/unity-webapps-facebook/HubSharer.qml'
25--- webapp-facebook/unity-webapps-facebook/HubSharer.qml 2014-07-28 18:35:35 +0000
26+++ webapp-facebook/unity-webapps-facebook/HubSharer.qml 2015-09-21 14:46:23 +0000
27@@ -8,6 +8,7 @@
28
29 signal completed(string result, var resourceUploadCompletedCallback)
30
31+ property string contentType
32 property string fileToShare
33
34 function _callback(accessToken,
35@@ -15,13 +16,18 @@
36 message,
37 resourceUploadCompletedCallback) {
38 itemComp.url = fileToShare;
39+
40 var dataUri = itemComp.toDataURI();
41 var result = {accessToken: accessToken,
42 fileToShare: dataUri.toString(),
43 message: message};
44
45- completed(JSON.stringify(result),
46- function(result) { main.destroy(); resourceUploadCompletedCallback(result); });
47+ completed(
48+ JSON.stringify(result),
49+ function(result) {
50+ main.destroy();
51+ resourceUploadCompletedCallback(result);
52+ });
53 }
54
55 ContentItem {
56@@ -45,16 +51,20 @@
57
58 Share {
59 id: share
60+
61 anchors.fill: parent
62 visible: true
63+
64 fileToShare: main.fileToShare
65+ contentType: main.contentType
66 callback: _callback
67- provider: "facebook"
68+
69 onCanceled: {
70 completed(JSON.stringify({status: "cancelled"}),
71 function(result) { uploadCompleted(result); });
72 main.destroy();
73 }
74+
75 onUploadCompleted: {
76 /* if the upload was successful, we need to destroy the parent */
77 if (success) {
78
79=== modified file 'webapp-facebook/unity-webapps-facebook/Share.qml'
80--- webapp-facebook/unity-webapps-facebook/Share.qml 2014-07-28 14:50:02 +0000
81+++ webapp-facebook/unity-webapps-facebook/Share.qml 2015-09-21 14:46:23 +0000
82@@ -24,13 +24,18 @@
83 Item {
84 id: root
85 anchors.fill: parent
86+
87 property string fileToShare
88+ property string contentType
89 property var callback
90- property string serviceType: "webapps"
91- property string provider: "facebook"
92+
93+ readonly property string serviceType: "webapps"
94+ readonly property string provider: "facebook"
95+
96 property string userAccountId
97 property string accessToken
98 property var account
99+
100 signal accountSelected
101 signal canceled
102 signal uploadCompleted(bool success)
103@@ -142,14 +147,15 @@
104
105 UbuntuShape {
106 id: snapshot
107+
108 anchors.top: parent.top
109 anchors.left: parent.left
110 anchors.margins: units.gu(1)
111 width: units.gu(10)
112 height: units.gu(10)
113-
114+
115 image: Image {
116- source: fileToShare
117+ source: contentType === 'Pictures' ? fileToShare : "language-chooser"
118 sourceSize.height: snapshot.height
119 sourceSize.width: snapshot.width
120 fillMode: Image.PreserveAspectCrop
121
122=== modified file 'webapp-facebook/unity-webapps-facebook/facebook.user.js'
123--- webapp-facebook/unity-webapps-facebook/facebook.user.js 2015-03-12 21:41:16 +0000
124+++ webapp-facebook/unity-webapps-facebook/facebook.user.js 2015-09-21 14:46:23 +0000
125@@ -1,3 +1,20 @@
126+/*
127+ * Copyright 2015 Canonical Ltd.
128+ *
129+ * This file is part of webapps-core.
130+ *
131+ * webbrowser-app is free software; you can redistribute it and/or modify
132+ * it under the terms of the GNU General Public License as published by
133+ * the Free Software Foundation; version 3.
134+ *
135+ * webbrowser-app is distributed in the hope that it will be useful,
136+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
137+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138+ * GNU General Public License for more details.
139+ *
140+ * You should have received a copy of the GNU General Public License
141+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
142+ */
143
144 var api = external.getUnityObject('1.0');
145 var hub = api.ContentHub;
146@@ -5,14 +22,28 @@
147
148 function _shareRequested(transfer) {
149 activeTransfer = transfer;
150- transfer.items(function(items) {
151- api.launchEmbeddedUI("HubSharer", upload, {"fileToShare": items[0]});
152+
153+ transfer.contentType(function(type) {
154+ if (type === hub.ContentType.Pictures) {
155+ transfer.items(function(items) {
156+ api.launchEmbeddedUI(
157+ "HubSharer",
158+ uploadPhoto,
159+ {"fileToShare": items[0], contentType: type});
160+ });
161+ } else if (type === hub.ContentType.Links) {
162+ transfer.items(function(items) {
163+ api.launchEmbeddedUI(
164+ "HubSharer",
165+ uploadLink,
166+ {"fileToShare": items[0], contentType: type});
167+ });
168+ }
169 });
170 };
171-
172 hub.onShareRequested(_shareRequested);
173
174-function upload(res, onResourceUploadedCallback) {
175+function uploadPhoto(res, onResourceUploadedCallback) {
176 var results = JSON.parse(res);
177 if (results.status == "cancelled")
178 activeTransfer.setState(hub.ContentTransfer.State.Aborted);
179@@ -52,3 +83,42 @@
180 xhr.send(formData);
181 }
182
183+function uploadLink(res, onResourceUploadedCallback) {
184+ var results = JSON.parse(res);
185+ if (results.status == "cancelled") {
186+ activeTransfer.setState(hub.ContentTransfer.State.Aborted);
187+ }
188+
189+ var xhr = new XMLHttpRequest();
190+ xhr.open(
191+ 'POST',
192+ 'https://graph.facebook.com/me/feed?'
193+ + 'access_token=' + results.accessToken,
194+ true);
195+ xhr.onload = xhr.onerror = function() {
196+ if (xhr.status === 200) {
197+ window.location.reload();
198+
199+ onResourceUploadedCallback(true);
200+ }
201+ else {
202+ onResourceUploadedCallback(false);
203+ }
204+ };
205+
206+ var div = document.createElement('div');
207+ div.innerHTML =
208+ '<form enctype="multipart/form-data" method="post" id="uploadForm"> \
209+ <textarea id="message" name="message"> \
210+ </textarea> \
211+ </form>';
212+
213+ document.getElementsByTagName('body')[0].appendChild(div);
214+
215+ var uploadForm = document.forms.namedItem("uploadForm");
216+ var formData = new FormData(uploadForm);
217+ formData.append('message', results.message);
218+ formData.append('link', results.fileToShare);
219+ xhr.send(formData);
220+}
221+
222
223=== modified file 'webapp-googleplus/content-hub/webapp-googleplus.json'
224--- webapp-googleplus/content-hub/webapp-googleplus.json 2015-03-18 16:50:37 +0000
225+++ webapp-googleplus/content-hub/webapp-googleplus.json 2015-09-21 14:46:23 +0000
226@@ -1,5 +1,6 @@
227 {
228 "share": [
229- "pictures"
230+ "pictures",
231+ "links"
232 ]
233 }
234
235=== modified file 'webapp-googleplus/manifest.json'
236--- webapp-googleplus/manifest.json 2015-04-30 21:01:24 +0000
237+++ webapp-googleplus/manifest.json 2015-09-21 14:46:23 +0000
238@@ -15,5 +15,5 @@
239 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
240 "name": "com.ubuntu.developer.webapps.googleplus",
241 "title": "Google+",
242- "version": "0.6"
243+ "version": "0.7"
244 }
245
246=== modified file 'webapp-googleplus/webview-override.qml'
247--- webapp-googleplus/webview-override.qml 2015-04-30 21:01:24 +0000
248+++ webapp-googleplus/webview-override.qml 2015-09-21 14:46:23 +0000
249@@ -48,7 +48,7 @@
250 activeTransfer = null
251 }
252
253- function handleShareRequestForFileUris(uris) {
254+ function handleShareRequestForFileUris(uris, contentType) {
255 if ( ! activeTransfer) {
256 return
257 }
258@@ -66,28 +66,50 @@
259 activeFileUrisToShare = uris
260
261 // TODO beware of async
262- defaultFilePicker = webview.filePicker
263- webview.filePicker = contentHubSharePassthroughPickerComponent
264-
265- var request = webview.rootFrame.sendMessage(
266- "oxide://share-request-context/",
267- "EVALUATE-CODE",
268- {
269- code: " var delayCount = 0;
270- var id = window.setInterval(function() {
271- if (document.querySelector('textarea') || delayCount > 10) {
272- window.clearInterval(id);
273- function clickUpload() {
274- document.querySelector('textarea').removeEventListener('focus', clickUpload)
275- document.querySelector('div:nth-child(3) > div > div > div > div > button').click();
276- }
277- if (delayCount <= 10) {
278- document.querySelector('textarea').addEventListener('focus', clickUpload);
279+ if (contentType === ContentType.Pictures) {
280+ defaultFilePicker = webview.filePicker
281+ webview.filePicker = contentHubSharePassthroughPickerComponent
282+ var request = webview.rootFrame.sendMessage(
283+ "oxide://share-request-context/",
284+ "EVALUATE-CODE",
285+ {
286+ code: " var delayCount = 0;
287+ var id = window.setInterval(function() {
288+ if (document.querySelector('textarea') || delayCount > 10) {
289+ window.clearInterval(id);
290+ function clickUpload() {
291+ document.querySelector('textarea').removeEventListener('focus', clickUpload)
292+ document.querySelector('div:nth-child(3) > div > div > div > div > button').click();
293+ }
294+ if (delayCount <= 10) {
295+ document.querySelector('textarea').addEventListener('focus', clickUpload);
296+ }
297 }
298 ++delayCount;
299- }
300- }, 100);"
301- })
302+ }, 100);"
303+ })
304+ } else if (contentType === ContentType.Links) {
305+ var uristext = ''
306+ for (var i = 0; i < uris.length; ++i) {
307+ uristext += uris[i] + " "
308+ }
309+
310+ request = webview.rootFrame.sendMessage(
311+ "oxide://share-request-context/",
312+ "EVALUATE-CODE",
313+ {
314+ code: " var delayCount = 0;
315+ var id = window.setInterval(function() {
316+ if (document.querySelector('textarea') || delayCount > 10) {
317+ window.clearInterval(id);
318+ if (delayCount <= 10) {
319+ document.querySelector('textarea').value = '" + uristext + "';
320+ }
321+ ++delayCount;
322+ }
323+ }, 100);"
324+ })
325+ }
326 }
327
328 }
329@@ -117,7 +139,7 @@
330 for (var i = 0; i < activeTransfer.items.length; ++i) {
331 uris.push(String(activeTransfer.items[i].url).replace("file://", ""))
332 }
333- handleShareRequestForFileUris(uris)
334+ handleShareRequestForFileUris(uris, activeTransfer.contentType)
335 }
336
337 function onLoadProgressChanged() {
338
339=== modified file 'webapp-twitter/content-hub/webapp-twitter.json'
340--- webapp-twitter/content-hub/webapp-twitter.json 2015-02-23 15:58:11 +0000
341+++ webapp-twitter/content-hub/webapp-twitter.json 2015-09-21 14:46:23 +0000
342@@ -1,5 +1,6 @@
343 {
344 "share": [
345- "pictures"
346+ "pictures",
347+ "links"
348 ]
349 }
350
351=== modified file 'webapp-twitter/manifest.json'
352--- webapp-twitter/manifest.json 2015-03-30 14:10:28 +0000
353+++ webapp-twitter/manifest.json 2015-09-21 14:46:23 +0000
354@@ -19,6 +19,6 @@
355 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
356 "name": "com.ubuntu.developer.webapps.webapp-twitter",
357 "title": "webapp-twitter",
358- "version": "1.1"
359+ "version": "1.2"
360 }
361
362
363=== modified file 'webapp-twitter/unity-webapps-twitter/share.user.js'
364--- webapp-twitter/unity-webapps-twitter/share.user.js 2015-03-31 13:27:16 +0000
365+++ webapp-twitter/unity-webapps-twitter/share.user.js 2015-09-21 14:46:23 +0000
366@@ -37,16 +37,33 @@
367 activeTransfer = transfer;
368
369 // Make sure that we have the proper
370- transfer.items(function(items) {
371- api.launchEmbeddedUI(
372- "HubSharer",
373- upload,
374- {"fileToShare": items[0]});
375+ transfer.contentType(function(type) {
376+ if (type === hub.ContentType.Pictures) {
377+ transfer.items(function(items) {
378+ api.launchEmbeddedUI(
379+ "HubSharer",
380+ uploadPhoto,
381+ {"fileToShare": items[0]});
382+ });
383+ } else if (type === hub.ContentType.Links) {
384+ transfer.items(function(items) {
385+ uploadLink(items[0].url)
386+ });
387+ }
388 });
389 };
390 hub.onShareRequested(_shareRequested);
391
392
393+function uploadLink(url) {
394+ window.location.href = 'https://www.twitter.com/share?url=' + url
395+ if (activeTransfer) {
396+ activeTransfer.setState(
397+ hub.ContentTransfer.State.Finalized)
398+ activeTransfer = null
399+ }
400+}
401+
402 function generateNonce() {
403 // base64 encoding 32 bytes of random data, and stripping out all non-word
404 // characters
405@@ -269,7 +286,7 @@
406 )
407 }
408
409-function upload(res, onResourceUploadedCallback) {
410+function uploadPhoto(res, onResourceUploadedCallback) {
411 try {
412 var results = JSON.parse(res);
413 if (results.status == "cancelled") {

Subscribers

People subscribed via source and target branches

to all changes: