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
1=== added directory 'examples/facebook-share'
2=== added file 'examples/facebook-share/bla.qml'
3--- examples/facebook-share/bla.qml 1970-01-01 00:00:00 +0000
4+++ examples/facebook-share/bla.qml 2014-06-10 12:45:47 +0000
5@@ -0,0 +1,13 @@
6+import QtQuick 2.0;
7+
8+//import "/home/ken/work/phablet/content-hub/14.10/content-hub-share/examples/facebook-share/unity-webapps-facebook" as Sharer
9+import "unity-webapps-facebook" as Sharer
10+
11+Sharer.HubSharer {
12+ width: 800
13+ height: 500
14+
15+ fileToShare: 'file:///home/ken/.cache/com.ubuntu.developer.webapps.webapp-facebook/HubIncoming/14/ubuntu-varsity-red-1920x1200.png';
16+ visible: true;
17+}
18+
19
20=== added directory 'examples/facebook-share/content-hub'
21=== added file 'examples/facebook-share/content-hub/content-hub-exporter.json'
22--- examples/facebook-share/content-hub/content-hub-exporter.json 1970-01-01 00:00:00 +0000
23+++ examples/facebook-share/content-hub/content-hub-exporter.json 2014-06-10 12:45:47 +0000
24@@ -0,0 +1,5 @@
25+{
26+ "source": [
27+ "pictures"
28+ ]
29+}
30
31=== added file 'examples/facebook-share/facebook-webapp.service'
32--- examples/facebook-share/facebook-webapp.service 1970-01-01 00:00:00 +0000
33+++ examples/facebook-share/facebook-webapp.service 2014-06-10 12:45:47 +0000
34@@ -0,0 +1,6 @@
35+<?xml version="1.0" encoding="UTF-8"?>
36+<service id="com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook">
37+ <type>webapps</type>
38+ <name>Facebook Webapp</name>
39+ <provider>facebook</provider>
40+</service>
41
42=== added file 'examples/facebook-share/facebook.png'
43Binary 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
44=== added file 'examples/facebook-share/manifest.json'
45--- examples/facebook-share/manifest.json 1970-01-01 00:00:00 +0000
46+++ examples/facebook-share/manifest.json 2014-06-10 12:45:47 +0000
47@@ -0,0 +1,19 @@
48+{
49+ "description": "Facebook (webapp version)",
50+ "framework": "ubuntu-sdk-14.04-dev1",
51+ "architecture": "all",
52+ "hooks": {
53+ "webapp-facebook": {
54+ "account-application": "webapp-facebook.application",
55+ "content-hub": "content-hub/content-hub-exporter.json",
56+ "account-service": "facebook-webapp.service",
57+ "apparmor": "webapp-facebook.json",
58+ "desktop": "webapp-facebook.desktop"
59+ }
60+ },
61+ "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
62+ "name": "com.ubuntu.developer.webapps.webapp-facebook",
63+ "title": "webapp-facebook",
64+ "version": "1.0.13"
65+}
66+
67
68=== added directory 'examples/facebook-share/unity-webapps-facebook'
69=== added file 'examples/facebook-share/unity-webapps-facebook/HubSharer.qml'
70--- examples/facebook-share/unity-webapps-facebook/HubSharer.qml 1970-01-01 00:00:00 +0000
71+++ examples/facebook-share/unity-webapps-facebook/HubSharer.qml 2014-06-10 12:45:47 +0000
72@@ -0,0 +1,80 @@
73+import QtQuick 2.0
74+import Ubuntu.Components 0.1
75+import Ubuntu.Components.ListItems 0.1 as ListItem
76+import Ubuntu.Components.Popups 0.1
77+import Ubuntu.Components.Extras.Browser 0.1
78+
79+
80+/*!
81+ \brief MainView with a Label and Button elements.
82+*/
83+
84+Item {
85+ id: main
86+ // objectName for functional testing purposes (autopilot-qt5)
87+ //objectName: "mainView"
88+
89+ // Note! applicationName needs to match the "name" field of the click manifest
90+ //applicationName: "com.ubuntu.developer.ken-vandine.hub-sharer"
91+
92+ /*
93+ This property enables the application to change orientation
94+ when the device is rotated. The default is false.
95+ */
96+ //automaticOrientation: true
97+
98+ width: parent.width
99+ height: parent.height
100+ anchors.fill: parent
101+
102+ signal completed(string result)
103+
104+ property string fileToShare: "/home/ken/Pictures/Ubuntu_TV.png"
105+
106+ function _callback(accessToken, fileToShare, message, cb) {
107+ print ("_callback: " + accessToken);
108+ print ("_callback: " + fileToShare);
109+ print ("_callback: " + message);
110+ webview.experimental.postMessage(JSON.stringify({file: fileToShare, token: accessToken}));
111+ }
112+
113+ UbuntuWebView {
114+ id: webview
115+
116+ url: Qt.resolvedUrl("uploader.html")
117+
118+ experimental.onMessageReceived: {
119+ completed("[]");
120+ }
121+
122+ experimental.preferences.offlineWebApplicationCacheEnabled: true
123+ experimental.preferences.universalAccessFromFileURLsAllowed: true
124+ experimental.preferences.navigatorQtObjectEnabled: true
125+
126+ // port in QTWEBKIT_INSPECTOR_SERVER enviroment variable
127+ experimental.preferences.developerExtrasEnabled: true
128+ }
129+
130+ //PageStack {
131+ // id: pageStack
132+ // Component.onCompleted: push(sharePage)
133+
134+ //Page {
135+ // id: sharePage
136+ // anchors.fill: parent
137+ // visible: true
138+ // title: i18n.tr("Hub Share")
139+
140+ Share {
141+ anchors.fill: parent
142+ visible: true
143+ fileToShare: main.fileToShare
144+ callback: _callback
145+ provider: "facebook"
146+ onCanceled: print ("canceled")
147+ onUploadCompleted: print (success)
148+ Component.onCompleted: print ("Page completed " + height + " : " + width)
149+ }
150+ //}
151+ //}
152+}
153
154=== added file 'examples/facebook-share/unity-webapps-facebook/Share.qml'
155--- examples/facebook-share/unity-webapps-facebook/Share.qml 1970-01-01 00:00:00 +0000
156+++ examples/facebook-share/unity-webapps-facebook/Share.qml 2014-06-10 12:45:47 +0000
157@@ -0,0 +1,303 @@
158+/*
159+ * Copyright (C) 2012-2013 Canonical, Ltd.
160+ *
161+ * This program is free software; you can redistribute it and/or modify
162+ * it under the terms of the GNU General Public License as published by
163+ * the Free Software Foundation; version 3.
164+ *
165+ * This program is distributed in the hope that it will be useful,
166+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
167+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168+ * GNU General Public License for more details.
169+ *
170+ * You should have received a copy of the GNU General Public License
171+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
172+ */
173+
174+import QtQuick 2.0
175+import QtQuick.Window 2.0
176+import Ubuntu.Components 0.1
177+import Ubuntu.Components.ListItems 0.1 as ListItem
178+import Ubuntu.OnlineAccounts 0.1
179+
180+Rectangle {
181+ id: root
182+ anchors.fill: parent
183+ color: Theme.palette.normal.background
184+ property string fileToShare
185+ property var callback
186+ property string serviceType: "sharing"
187+ property string provider: "facebook"
188+ property string userAccountId
189+ property string accessToken
190+ property var account
191+ signal accountSelected
192+ signal canceled()
193+ signal uploadCompleted(bool success)
194+
195+ onUploadCompleted: {
196+ activitySpinner.visible = false;
197+ if (success)
198+ print ("Successfully posted");
199+ else
200+ print ("Failed to post");
201+ }
202+
203+ Component.onCompleted: print ("Root completed " + height + " : " + width)
204+
205+ AccountServiceModel {
206+ id: accounts
207+ serviceType: root.serviceType
208+ provider: root.provider
209+ }
210+
211+ Rectangle {
212+ id: shareComponent
213+ objectName: "shareComponent"
214+ anchors.fill: parent
215+ color: Theme.palette.normal.background
216+ visible: false
217+
218+ Component.onCompleted: print ("shareComponent completed " + height + " : " + width)
219+
220+ Column {
221+ anchors.fill: parent
222+ spacing: units.gu(1)
223+
224+ Item {
225+ id: serviceHeader
226+ y: 0
227+ anchors.left: parent.left
228+ anchors.right: parent.right
229+ anchors.topMargin: units.gu(1)
230+ anchors.leftMargin: units.gu(1)
231+ anchors.rightMargin: units.gu(1)
232+ height: childrenRect.height
233+
234+ ListItem.Subtitled {
235+ anchors {
236+ left: parent.left
237+ right: parent.right
238+ }
239+ iconName: root.account.provider.iconName
240+ text: root.account.provider.displayName
241+ subText: root.account.displayName
242+ showDivider: false
243+ }
244+ }
245+
246+ ListItem.ThinDivider {}
247+
248+ UbuntuShape {
249+ id: messageArea
250+ objectName: "messageArea"
251+ anchors.left: parent.left
252+ anchors.right: parent.right
253+ anchors.topMargin: units.gu(1)
254+ anchors.leftMargin: units.gu(1)
255+ anchors.rightMargin: units.gu(1)
256+
257+ height: units.gu(20)
258+ color: "#f2f2f2"
259+
260+ TextEdit {
261+ id: message
262+ color: "#333333"
263+ anchors.top: parent.top
264+ anchors.left: snapshot.right
265+ anchors.bottom: parent.bottom
266+ anchors.margins: units.gu(1)
267+ wrapMode: Text.Wrap
268+ width: parent.width - snapshot.width -
269+ snapshot.anchors.margins * 2 -
270+ message.anchors.leftMargin - message.anchors.rightMargin
271+ clip: true
272+ font.pixelSize: FontUtils.sizeToPixels("medium")
273+ font.weight: Font.Light
274+ focus: true
275+ }
276+
277+ ActivityIndicator {
278+ id: activitySpinner
279+ anchors.centerIn: message
280+ visible: false
281+ running: visible
282+ }
283+
284+ UbuntuShape {
285+ id: snapshot
286+ anchors.top: parent.top
287+ anchors.left: parent.left
288+ anchors.margins: units.gu(1)
289+ width: units.gu(10)
290+ height: units.gu(10)
291+
292+ image: Image {
293+ source: fileToShare
294+ sourceSize.height: snapshot.height
295+ sourceSize.width: snapshot.width
296+ fillMode: Image.PreserveAspectCrop
297+ }
298+ }
299+ }
300+
301+ Item {
302+ id: actionsBar
303+ anchors.left: parent.left
304+ anchors.right: parent.right
305+ anchors.topMargin: units.gu(2)
306+ anchors.leftMargin: units.gu(1)
307+ anchors.rightMargin: units.gu(1)
308+ height: childrenRect.height
309+
310+ Button {
311+ objectName: "cancelButton"
312+ anchors.left: parent.left
313+ text: i18n.dtr("ubuntu-ui-extras", "Cancel")
314+ color: "#cccccc"
315+ width: units.gu(10)
316+ height: units.gu(4)
317+ onClicked: canceled()
318+ }
319+
320+ Button {
321+ objectName: "postButton"
322+ anchors.right: parent.right
323+ anchors.top: parent.top
324+ text: i18n.dtr("ubuntu-ui-extras", "Post")
325+ color: "#dd4814"
326+ width: units.gu(10)
327+ height: units.gu(4)
328+ enabled: !activitySpinner.visible
329+ onClicked: {
330+ activitySpinner.visible = true;
331+ callback(accessToken, fileToShare, message.text, uploadCompleted);
332+ }
333+ }
334+ }
335+
336+ UbuntuShape {
337+ id: useLocation
338+ anchors {
339+ left: parent.left
340+ leftMargin: units.gu(1)
341+ topMargin: units.gu(1)
342+ }
343+ color: selected ? "#cccccc" : "transparent"
344+ property bool selected: false
345+ width: units.gu(4.5)
346+ height: units.gu(4)
347+
348+ AbstractButton {
349+ anchors.fill: parent
350+ onClicked: parent.selected = !parent.selected
351+ Image {
352+ source: "assets/icon_location.png"
353+ anchors.centerIn: parent
354+ height: parent.height * 0.75
355+ fillMode: Image.PreserveAspectFit
356+ smooth: true
357+ }
358+ }
359+ }
360+
361+ Label {
362+ anchors.left: useLocation.right
363+ anchors.baseline: useLocation.top
364+ anchors.baselineOffset: units.gu(3)
365+ anchors.leftMargin: units.gu(1)
366+ text: i18n.dtr("ubuntu-ui-extras", "Include location")
367+ fontSize: "small"
368+ }
369+
370+ }
371+
372+ states: [
373+ State {
374+ name: "landscape-with-keyborad"
375+ PropertyChanges {
376+ target: serviceHeader
377+ y: - serviceHeader.height
378+ }
379+ PropertyChanges {
380+ target: messageArea
381+ height: units.gu(12)
382+ }
383+ }
384+ ]
385+
386+ state: ((Screen.orientation === Qt.LandscapeOrientation) ||
387+ (Screen.orientation === Qt.InvertedLandscapeOrientation)) &&
388+ Qt.inputMethod.visible ? "landscape-with-keyborad" : ""
389+ }
390+
391+ /* Menu listing online accounts */
392+ Item {
393+ id: sharemenu
394+ anchors.fill: parent
395+ visible: true
396+
397+ signal selected(string accountId, string token)
398+
399+ Component.onCompleted: {
400+ visible = true;
401+ print ("sharemenu completed " + height + " : " + width);
402+ }
403+ onSelected: {
404+ root.userAccountId = accountId;
405+ root.accessToken = token;
406+ shareComponent.visible = true;
407+ sharemenu.visible = false;
408+ }
409+
410+ Component {
411+ id: acctDelegate
412+ Item {
413+ anchors {
414+ left: parent.left
415+ right: parent.right
416+ }
417+ AccountService {
418+ id: service
419+ objectHandle: accountServiceHandle
420+ onAuthenticated: {
421+ sharemenu.selected(accountId, reply.AccessToken);
422+ }
423+ }
424+
425+ height: childrenRect.height
426+
427+ ListItem.Subtitled {
428+ anchors {
429+ left: parent.left
430+ right: parent.right
431+ }
432+ text: service.provider.displayName
433+ subText: displayName
434+ iconName: service.provider.iconName
435+ __iconHeight: units.gu(5)
436+ __iconWidth: units.gu(5)
437+
438+ onClicked: {
439+ root.account = service;
440+ root.account.authenticate(null);
441+ }
442+ Component.onCompleted: print ("KEN: " + service.provider.displayName + " height: " + height + " y: " + y + " visible: " + visible)
443+ }
444+ }
445+ }
446+
447+ ListView {
448+ anchors {
449+ top: parent.top
450+ left: parent.left
451+ right: parent.right
452+ }
453+ height: childrenRect.height
454+ interactive: false
455+ model: accounts
456+ delegate: acctDelegate
457+ Component.onCompleted: print ("listview completed " + height + " : " + width)
458+ }
459+ }
460+}
461
462=== added file 'examples/facebook-share/unity-webapps-facebook/facebook.user.js'
463--- examples/facebook-share/unity-webapps-facebook/facebook.user.js 1970-01-01 00:00:00 +0000
464+++ examples/facebook-share/unity-webapps-facebook/facebook.user.js 2014-06-10 12:45:47 +0000
465@@ -0,0 +1,72 @@
466+var api = external.getUnityObject('1.0');
467+
468+var oa = api.OnlineAccounts;
469+var hub = api.ContentHub;
470+
471+function _shareRequested(transfer) {
472+ transfer.items(function(items) {
473+ api.launchEmbeddedUI("HubSharer", upload, {"fileToShare": items[0]});
474+ });
475+};
476+hub.onShareRequested(_shareRequested);
477+
478+function upload(res) {
479+ var results = JSON.parse(res);
480+ //console.log (results);
481+ console.log (results.accessToken);
482+ var xhr = new XMLHttpRequest();
483+ xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + results.accessToken, true );
484+ xhr.onload = xhr.onerror = function() {
485+ console.log( xhr.responseText );
486+ };
487+
488+ //var xhrr = new XMLHttpRequest();
489+ //var re = /file:\/\//gi;
490+ //var file = results.fileToShare.replace(re, '');
491+ //console.log ("FILE: " + results.fileToShare);
492+ console.log('file to share lenght: ' + [].slice.call(results.fileToShare).length)
493+
494+ console.log(results.fileToShare)
495+
496+ console.log("After atob: " + atob(results.fileToShare))
497+
498+ var bin = atob(results.fileToShare);
499+ var a = new Uint8Array(results.contentlength);
500+
501+ console.log('results.length: ' + results.size)
502+
503+ for (var i = 0; i < results.size; ++i) {
504+ a[i] = bin.charCodeAt(i);
505+ }
506+
507+ console.log("array buffer content: " + btoa(a.buffer))
508+
509+ var div = document.createElement('div');
510+ div.innerHTML = '<form enctype="multipart/form-data" method="post" id="uploadForm"><textarea id="message" name="message"></textarea></form>';
511+ document.getElementsByTagName('body')[0].appendChild(div);
512+
513+ var blob = new Blob([a], {type: "image/png"});
514+
515+ console.log('blob size: ' + blob.size)
516+ console.log(blob.type)
517+
518+ var uploadForm = document.forms.namedItem("uploadForm");
519+ var formData = new FormData(uploadForm);
520+ formData.append('source', blob);
521+ xhr.send(formData);
522+
523+ /*
524+ xhrr.open("GET", results.fileToShare, true);
525+ xhrr.responseType = "blob";
526+ xhrr.onload = function (e) {
527+ var blob = new Blob([xhrr.response], {type: "image/png"});
528+ var formData = new FormData();
529+ formData.append('source', blob);
530+ formData.append('message', results.message);
531+ xhr.send(formData);
532+ }
533+ xhrr.send();
534+ */
535+}
536+
537+
538
539=== added file 'examples/facebook-share/unity-webapps-facebook/manifest.json'
540--- examples/facebook-share/unity-webapps-facebook/manifest.json 1970-01-01 00:00:00 +0000
541+++ examples/facebook-share/unity-webapps-facebook/manifest.json 2014-06-10 12:45:47 +0000
542@@ -0,0 +1,7 @@
543+{
544+ "name": "facebook",
545+ "includes": ["https://*.facebook.com/*"],
546+ "homepage": "https://m.facebook.com/",
547+ "domain": "facebook.com",
548+ "scripts": ["facebook.user.js"]
549+}
550
551=== added file 'examples/facebook-share/unity-webapps-facebook/uploader.html'
552--- examples/facebook-share/unity-webapps-facebook/uploader.html 1970-01-01 00:00:00 +0000
553+++ examples/facebook-share/unity-webapps-facebook/uploader.html 2014-06-10 12:45:47 +0000
554@@ -0,0 +1,15 @@
555+<html>
556+<head>
557+<script src="./uploader.js"></script>
558+</head>
559+<body>
560+
561+ <div>
562+ <form enctype="multipart/form-data" method="post" id="uploadForm">
563+ <textarea id="message" name="message" rows="5" style="height: auto; width: 600px;" placeholder="What's on your mind?">
564+ </textarea>
565+ </form>
566+ </div>
567+
568+<body>
569+</html>
570
571=== added file 'examples/facebook-share/unity-webapps-facebook/uploader.js'
572--- examples/facebook-share/unity-webapps-facebook/uploader.js 1970-01-01 00:00:00 +0000
573+++ examples/facebook-share/unity-webapps-facebook/uploader.js 2014-06-10 12:45:47 +0000
574@@ -0,0 +1,34 @@
575+/**
576+ * Wait before the DOM has been loaded before initializing the Ubuntu UI layer
577+ */
578+navigator.qt.onmessage = function(message) {
579+ var data = null;
580+ try {
581+ data = JSON.parse(message.data);
582+ } catch (error) {
583+ return;
584+ }
585+ upload(data.file, data.token);
586+}
587+
588+function upload(file, token) {
589+ // FIXME: we should submit multiples if we can
590+ var xhr = new XMLHttpRequest();
591+ xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + token, true );
592+ xhr.onload = xhr.onerror = function() {
593+ navigator.qt.postMessage(JSON.stringify({}));
594+ };
595+
596+ var xhrr = new XMLHttpRequest();
597+ xhrr.open("GET", file, true);
598+ xhrr.responseType = "blob";
599+ xhrr.onload = function (e) {
600+ var blob = new Blob([xhrr.response], {type: "image/png"});
601+ var uploadForm = document.forms.namedItem("uploadForm");
602+ var formData = new FormData(uploadForm);
603+ formData.append('source', blob);
604+ xhr.send(formData);
605+ }
606+ xhrr.send();
607+}
608+
609
610=== added file 'examples/facebook-share/webapp-facebook.application'
611--- examples/facebook-share/webapp-facebook.application 1970-01-01 00:00:00 +0000
612+++ examples/facebook-share/webapp-facebook.application 2014-06-10 12:45:47 +0000
613@@ -0,0 +1,11 @@
614+<?xml version="1.0" encoding="UTF-8" ?>
615+<application id="com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook">
616+ <description>Facebook webapp</description>
617+
618+ <services>
619+ <service id="com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook">
620+ <description>Use the service in a webapp</description>
621+ </service>
622+ </services>
623+
624+</application>
625
626=== added file 'examples/facebook-share/webapp-facebook.desktop'
627--- examples/facebook-share/webapp-facebook.desktop 1970-01-01 00:00:00 +0000
628+++ examples/facebook-share/webapp-facebook.desktop 2014-06-10 12:45:47 +0000
629@@ -0,0 +1,9 @@
630+[Desktop Entry]
631+Type=Application
632+Terminal=false
633+Exec=webapp-container --enable-back-forward --webappModelSearchPath=. --webappUrlPatterns=https?://*.facebook.com/*
634+Name=Facebook
635+Icon=./facebook.png
636+X-Ubuntu-Touch=true
637+X-Ubuntu-StageHint=SideStage
638+X-Ubuntu-Single-Instance=true
639
640=== added file 'examples/facebook-share/webapp-facebook.json'
641--- examples/facebook-share/webapp-facebook.json 1970-01-01 00:00:00 +0000
642+++ examples/facebook-share/webapp-facebook.json 2014-06-10 12:45:47 +0000
643@@ -0,0 +1,13 @@
644+{
645+ "template": "ubuntu-webapp",
646+ "policy_groups": [
647+ "networking",
648+ "audio",
649+ "video",
650+ "webview",
651+ "location",
652+ "content_exchange",
653+ "content_exchange_source"
654+ ],
655+ "policy_version": 1.1
656+}
657
658=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
659--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-05-16 16:29:35 +0000
660+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-06-10 12:45:47 +0000
661@@ -413,6 +413,27 @@
662 return null;
663 }
664
665+ /*!
666+ \internal
667+
668+ */
669+ function __getPolicyForContent(settings) {
670+ // TODO: review this
671+ function PassthroughPolicy() {};
672+ PassthroughPolicy.prototype.allowed = function(signature) {
673+ return true;
674+ };
675+ function RestrictedPolicy(restrictions) {
676+ this.restrictions = restrictions || [];
677+ };
678+ RestrictedPolicy.prototype.allowed = function(signature) {
679+ return this.restrictions.some(function(e) { return e == signature; });
680+ };
681+
682+ if (injectExtraUbuntuApis)
683+ return new PassthroughPolicy();
684+ return new RestrictedPolicy(["ContentHub.onShareRequested"])
685+ }
686
687 /*!
688 \internal
689@@ -524,6 +545,59 @@
690 UnityBackends.get("hud").clearActions();
691 },
692
693+ launchEmbeddedUI: function(name, callback, params) {
694+ if ( ! model) {
695+ print ("No model");
696+ return;
697+ }
698+
699+ // TODO validate
700+ var path = model.path(webapps.name);
701+ console.debug ("PATH: " + path);
702+ if (! path || path.length == 0)
703+ return;
704+
705+ var backendDelegate = UnityBackends.backendDelegate;
706+
707+ var parentItem = backendDelegate.parentView();
708+ if ( ! parentItem || ! parentItem.visible || ! parentItem.height || ! parentItem.width) {
709+ console.debug("Cannot launch the content peer picker UI, invalid parent item: " + parentItem);
710+ callback({result: "cancelled"});
711+ return;
712+ }
713+
714+ var p = parentItem.parent ? parentItem.parent : parentItem
715+
716+ var c;
717+ function oncreated() {
718+ //if (p) {
719+ // p.visible = false;
720+ //}
721+
722+ var ui = c.createObject(p, {"fileToShare": params.fileToShare.url, "visible": true});
723+
724+ if ( ! ui.onCompleted) {
725+ ui.destroy();
726+ return;
727+ }
728+
729+ function _onCompleted(data) {
730+ ui.visible = false;
731+ p.visible = true;
732+ ui.onCompleted.disconnect(_onCompleted);
733+ ui.destroy();
734+ callback(data);
735+ }
736+ ui.onCompleted.connect(_onCompleted);
737+ };
738+
739+ c = Qt.createComponent(path + "/" + name + ".qml");
740+ if (c.status == Component.Ready)
741+ oncreated()
742+ else
743+ c.statusChanged.connect(oncreated)
744+ },
745+
746 Notification: {
747 showNotification: function (summary, body, iconUrl) {
748 if (!initialized)
749@@ -641,17 +715,13 @@
750 }
751 },
752
753- OnlineAccounts: __injectResourceIfExtraApisAreEnabled(function() {
754- return OnlineAccountsApiBackend.createOnlineAccountsApi(UnityBackends.backendDelegate)
755- }),
756+ OnlineAccounts: OnlineAccountsApiBackend.createOnlineAccountsApi(UnityBackends.backendDelegate),
757
758 Alarm: __injectResourceIfExtraApisAreEnabled(function() {
759 return AlarmApiBackend.createAlarmApi(UnityBackends.backendDelegate)
760 }),
761
762- ContentHub: __injectResourceIfExtraApisAreEnabled(function() {
763- return ContentHubApiBackend.createContentHubApi(UnityBackends.backendDelegate)
764- }),
765+ ContentHub: ContentHubApiBackend.createContentHubApi(UnityBackends.backendDelegate),
766
767 RuntimeApi: __injectResourceIfExtraApisAreEnabled(function() {
768 return RuntimeApiBackend.createRuntimeApi(UnityBackends.backendDelegate)
769
770=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js'
771--- src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-05-08 13:01:07 +0000
772+++ src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-06-10 12:45:47 +0000
773@@ -24,7 +24,7 @@
774 *
775 */
776
777-function createContentHubApi(backendDelegate) {
778+function createContentHubApi(backendDelegate, accessPolicy) {
779 var PLUGIN_URI = 'Ubuntu.Content';
780 var VERSION = 0.1;
781
782@@ -769,6 +769,20 @@
783 });
784 },
785
786+ onImportRequested: function(callback) {
787+ _contenthub.onImportRequested.connect(function(importTransfer) {
788+ var wrapped = new ContentTransfer(importTransfer);
789+ callback(wrapped.serialize());
790+ });
791+ },
792+
793+ onShareRequested: function(callback) {
794+ _contenthub.shareRequested.connect(function(shareTransfer) {
795+ var wrapped = new ContentTransfer(shareTransfer);
796+ callback(wrapped.serialize());
797+ });
798+ },
799+
800 // Internal
801
802 dispatchToObject: function(infos) {
803
804=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js'
805--- src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-03-18 13:59:36 +0000
806+++ src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-06-10 12:45:47 +0000
807@@ -836,6 +836,58 @@
808 [callback]);
809 },
810
811+ /**
812+ * Sets a handler that is to be called when the current application is the
813+ * target of an share request.
814+ *
815+ * @method onExportRequested
816+ * @param callback {Function(ContentTransfer)} Function when one requests a resource to be shared.
817+ * The corresponding ContentTransfer is provided as a parameter.
818+ *
819+ * @example
820+
821+ var api = external.getUnityObject(1.0);
822+ var hub = api.ContentHub;
823+
824+ var transferState = hub.ContentTransfer.State;
825+
826+ function _shareRequested(transfer) {
827+ };
828+
829+ hub.onShareRequested(_shareRequested);
830+
831+ */
832+ onShareRequested: function(callback) {
833+ backendBridge.call('ContentHub.onShareRequested',
834+ [callback]);
835+ },
836+
837+ /**
838+ * Sets a handler that is to be called when the current application is the
839+ * target of an import request.
840+ *
841+ * @method onImportRequested
842+ * @param callback {Function(ContentTransfer)} Function when one requests a resource to be imported.
843+ * The corresponding ContentTransfer is provided as a parameter.
844+ *
845+ * @example
846+
847+ var api = external.getUnityObject(1.0);
848+ var hub = api.ContentHub;
849+
850+ var transferState = hub.ContentTransfer.State;
851+
852+ function _importRequested(transfer) {
853+ };
854+
855+ hub.onImportRequested(_importRequested);
856+
857+ */
858+ onImportRequested: function(callback) {
859+ backendBridge.call('ContentHub.onImportRequested',
860+ [callback]);
861+ },
862+
863 api: {
864
865 /**
866
867=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js'
868--- src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2014-05-09 13:17:09 +0000
869+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2014-06-10 12:45:47 +0000
870@@ -21,7 +21,7 @@
871 * Online Accounts API backend binding
872 *
873 */
874-function createOnlineAccountsApi(backendDelegate) {
875+function createOnlineAccountsApi(backendDelegate, accessPolicy) {
876 var PLUGIN_URI = 'Ubuntu.OnlineAccounts';
877 var VERSION = 0.1;
878
879
880=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp'
881--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2014-05-14 01:41:14 +0000
882+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2014-06-10 12:45:47 +0000
883@@ -156,6 +156,7 @@
884 roles[Scripts] = "scripts";
885 roles[Chrome] = "chrome";
886 roles[UserAgentOverride] = "useragent";
887+ roles[Path] = "path";
888 }
889 return roles;
890 }
891@@ -337,6 +338,21 @@
892 }
893
894 QString
895+UnityWebappsAppModel::path(const QString & webappName) const {
896+ if (!exists(webappName))
897+ return QString();
898+
899+ int idx = getWebappIndex(webappName);
900+ if (Q_UNLIKELY(idx == -1))
901+ {
902+ qDebug() << "Invalid index for a supposedly existing webapp: " << webappName;
903+ return QString();
904+ }
905+
906+ return data(idx, Path).toString();
907+}
908+
909+QString
910 UnityWebappsAppModel::userAgentOverrideFor(const QString & webappName) const
911 {
912 if (!exists(webappName))
913@@ -543,6 +559,9 @@
914
915 case UserAgentOverride:
916 return webapp.data.manifest.userAgentOverride;
917+
918+ case Path:
919+ return webapp.userscriptLocation;
920 }
921
922 return QVariant();
923
924=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h'
925--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h 2014-05-08 15:20:47 +0000
926+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.h 2014-06-10 12:45:47 +0000
927@@ -58,7 +58,8 @@
928 Scripts,
929 ScriptsContent,
930 Chrome,
931- UserAgentOverride
932+ UserAgentOverride,
933+ Path
934 };
935
936 // QAbstractListModel implementation
937@@ -108,6 +109,11 @@
938 */
939 Q_INVOKABLE QString userAgentOverrideFor(const QString & webappName) const;
940
941+ /*!
942+ * \brief
943+ */
944+ Q_INVOKABLE QString path(const QString & webappName) const;
945+
946
947 /*!
948 * \brief
949
950=== modified file 'src/Ubuntu/UnityWebApps/unity-webapps-api.js.in'
951--- src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2014-05-13 17:48:43 +0000
952+++ src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2014-06-10 12:45:47 +0000
953@@ -98,6 +98,12 @@
954 clearActions: createArgumentsSanitizer (backend, [], 'clearActions'),
955
956 /**
957+ */
958+ launchEmbeddedUI: function(name, callback, params) {
959+ backend.call('launchEmbeddedUI', [name, callback, params]);
960+ },
961+
962+ /**
963 *
964 * MediaPlayer API
965 *

Subscribers

People subscribed via source and target branches

to all changes: