Merge lp:~abreu-alexandre/unity-webapps-qml/rtm-backport-oa-api-requestaccount into lp:unity-webapps-qml/rtm-14.09

Proposed by Alexandre Abreu on 2015-03-09
Status: Merged
Approved by: Alexandre Abreu on 2015-03-09
Approved revision: 138
Merged at revision: 138
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/rtm-backport-oa-api-requestaccount
Merge into: lp:unity-webapps-qml/rtm-14.09
Diff against target: 237 lines (+152/-4)
7 files modified
debian/control (+2/-1)
examples/api-bindings/online-accounts/www/js/app.js (+11/-1)
src/Ubuntu/UnityWebApps/UnityWebApps.pro (+3/-1)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+1/-0)
src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js (+87/-0)
src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js (+2/-0)
src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js (+46/-1)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/rtm-backport-oa-api-requestaccount
Reviewer Review Type Date Requested Status
WebApps 2015-03-09 Pending
Review via email: mp+252319@code.launchpad.net

Commit message

BAckport additional OA HTML5 API to request account access

Description of the change

BAckport additional OA HTML5 API to request account access

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
1=== modified file 'debian/control'
2--- debian/control 2015-01-16 16:12:44 +0000
3+++ debian/control 2015-03-09 16:03:01 +0000
4@@ -36,7 +36,8 @@
5 qtdeclarative5-accounts-plugin,
6 ${misc:Depends},
7 ${shlibs:Depends},
8-Suggests: qtdeclarative5-ubuntu-content1,
9+Suggests: qtdeclarative5-online-accounts-client0.1 (>= 0.3+14.10.20140530),
10+ qtdeclarative5-ubuntu-content1,
11 qtdeclarative5-ubuntu-download-manager0.1
12 Description: Unity Webapps QML component
13 Unity Webapps QML is a QML component that binds to a QML WebView and allows
14
15=== modified file 'examples/api-bindings/online-accounts/www/js/app.js'
16--- examples/api-bindings/online-accounts/www/js/app.js 2014-05-09 13:17:09 +0000
17+++ examples/api-bindings/online-accounts/www/js/app.js 2015-03-09 16:03:01 +0000
18@@ -4,13 +4,23 @@
19 var api = external.getUnityObject('1.0');
20 var oa = api.OnlineAccounts;
21
22- oa.api.getProviders({"applicationId": "webbrowser-app"}, function(providers) {
23+ var appId = "shotwell";
24+
25+ oa.api.getProviders({"applicationId": appId}, function(providers) {
26 var ul = document.querySelector('#providers ul');
27
28 for (var i = 0; i < providers.length; ++i) {
29 var li = document.createElement('li');
30+ var button = document.createElement('input');
31+ button.type = 'button';
32+ button.providerId = providers[i].providerId;
33+ button.value = 'Request account';
34+ button.addEventListener('click', function() {
35+ oa.api.requestAccount(appId, this.providerId, function() {});
36+ });
37 li.innerHTML = 'displayName: ' + providers[i].displayName
38 + ', providerId: ' + providers[i].providerId;
39+ li.appendChild(button);
40 ul.appendChild(li);
41 }
42 });
43
44=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.pro'
45--- src/Ubuntu/UnityWebApps/UnityWebApps.pro 2014-07-11 17:13:18 +0000
46+++ src/Ubuntu/UnityWebApps/UnityWebApps.pro 2015-03-09 16:03:01 +0000
47@@ -60,7 +60,9 @@
48 alarm_binding_backend_js_files.files = ./bindings/alarm-api/backend/alarm-api.js
49
50 online_accounts_binding_backend_js_files.path = $$installPath/bindings/online-accounts/backend/
51-online_accounts_binding_backend_js_files.files = ./bindings/online-accounts/backend/online-accounts.js
52+online_accounts_binding_backend_js_files.files = \
53+ ./bindings/online-accounts/backend/online-accounts.js \
54+ ./bindings/online-accounts/backend/online-accounts-client.js
55
56 runtime_api_binding_backend_js_files.path = $$installPath/bindings/runtime-api/backend/
57 runtime_api_binding_backend_js_files.files = ./bindings/runtime-api/backend/runtime-api.js
58
59=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
60--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-01-16 16:12:44 +0000
61+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-09 16:03:01 +0000
62@@ -26,6 +26,7 @@
63 import "./bindings/alarm-api/backend/alarm-api.js" as AlarmApiBackend
64 import "./bindings/content-hub/backend/content-hub.js" as ContentHubApiBackend
65 import "./bindings/online-accounts/backend/online-accounts.js" as OnlineAccountsApiBackend
66+import "./bindings/online-accounts/backend/online-accounts-client.js" as OnlineAccountsClientApiBackend
67 import "./bindings/download-manager/backend/download-api.js" as DownloadApiBackend
68
69 /*!
70
71=== added file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js'
72--- src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js 1970-01-01 00:00:00 +0000
73+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js 2015-03-09 16:03:01 +0000
74@@ -0,0 +1,87 @@
75+/*
76+ * Copyright 2014 Canonical Ltd.
77+ *
78+ * This file is part of unity-webapps-qml.
79+ *
80+ * unity-webapps-qml is free software; you can redistribute it and/or modify
81+ * it under the terms of the GNU General Public License as published by
82+ * the Free Software Foundation; version 3.
83+ *
84+ * unity-webapps-qml is distributed in the hope that it will be useful,
85+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
86+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87+ * GNU General Public License for more details.
88+ *
89+ * You should have received a copy of the GNU General Public License
90+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
91+ */
92+
93+/**
94+ *
95+ * Online Accounts client API backend binding
96+ *
97+ */
98+function createOnlineAccountsClientApi(backendDelegate) {
99+ var PLUGIN_URI = 'Ubuntu.OnlineAccounts.Client';
100+ var VERSION = 0.1;
101+
102+ function Setup(params) {
103+ var result = backendDelegate.createQmlObject(
104+ PLUGIN_URI, VERSION, 'Setup', params);
105+ this._id = result.id;
106+ this._object = result.object;
107+ };
108+ Setup.prototype = {
109+ _validate: function() {
110+ if (! this._object)
111+ throw new TypeError("Invalid object null");
112+ },
113+
114+ destroy: function() {
115+ if (! this._object)
116+ return;
117+ this._object.destroy();
118+ backendDelegate.deleteId(this._id);
119+ },
120+
121+ // object methods
122+ serialize: function() {
123+ this._validate();
124+ return {
125+ type: 'object-proxy',
126+ apiid: 'OnlineAccounts.Client',
127+ objecttype: 'Setup',
128+ objectid: this._id,
129+ }
130+ },
131+
132+ // methods
133+ exec: function(callback) {
134+ this._validate();
135+
136+ var self = this;
137+
138+ var onFinished = function() {
139+ self._object.onFinished.disconnect(onFinished);
140+ callback();
141+ }
142+
143+ this._object.onFinished.connect(onFinished);
144+ this._object.exec();
145+ }
146+ };
147+
148+ return {
149+ requestAccount: function(applicationId, providerId, callback) {
150+ var setup = new Setup({
151+ 'applicationId': applicationId,
152+ 'providerId': providerId,
153+ });
154+ var onFinished = function() {
155+ setup.destroy();
156+ callback();
157+ };
158+ setup.exec(onFinished);
159+ },
160+ };
161+}
162
163=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js'
164--- src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2014-05-22 08:54:56 +0000
165+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2015-03-09 16:03:01 +0000
166@@ -673,6 +673,8 @@
167 }
168 },
169
170+ Client: OnlineAccountsClientApiBackend.createOnlineAccountsClientApi(backendDelegate),
171+
172 // Internal
173
174 dispatchToObject: function(infos) {
175
176=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js'
177--- src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js 2014-05-09 13:17:09 +0000
178+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js 2015-03-09 16:03:01 +0000
179@@ -161,7 +161,7 @@
180 *
181 * @method api.getAccounts
182 * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
183- * - application: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
184+ * - applicationId: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
185 * - provider: the ID of a provider (see /usr/share/accounts/providers/ or ~/.local/share/accounts/providers/ for a list of the available providers)
186 * - service: the ID of a service (see /usr/share/accounts/services/ or ~/.local/share/accounts/services/ for a list of the available services)
187 *
188@@ -215,6 +215,51 @@
189 , [filters]
190 , callback);
191 },
192+ /**
193+ * Requests access to an account.
194+ *
195+ * Applications must invoke this method in order to obtain access
196+ * to an account. The user will be prompted to grant access to
197+ * either an existing account, to create a new one or to decline
198+ * the request.
199+ *
200+ * @method api.requestAccount
201+ * @param applicationId {String} The ID of the application
202+ * requesting the account (see /usr/share/accounts/applications/ or
203+ * ~/.local/share/accounts/applications/ for a list of the
204+ * available applications)
205+ * @param providerId {String} The ID of the provider of the desired
206+ * account (see /usr/share/accounts/providers/ or
207+ * ~/.local/share/accounts/providers/ for a list of the available
208+ * providers)
209+ * @param callback {Function()} Callback which will be invoked
210+ * after the access request has been decided (either with the
211+ * access to an account being granted, or with a refusal).
212+ *
213+ * @example
214+ var api = external.getUnityObject(1.0);
215+ var oa = api.OnlineAccounts;
216+
217+ var appId = 'com.ubuntu.developer.me.MyPackage_MyApp';
218+ oa.api.requestAccount(appId,
219+ 'facebook',
220+ function() {
221+ oa.api.getAccounts({ 'application': appId }, function(result) {
222+ for (var i = 0; i < result.length; ++i) {
223+ console.log("name: " + result[i].displayName()
224+ + ', id: ' + result[i].accountId()
225+ + ', providerName: ' + result[i].provider().displayName
226+ + ', enabled: ' + (result[i].enabled() ? "true" : "false")
227+ );
228+ }
229+ });
230+ });
231+ */
232+ requestAccount: function(applicationId, providerId, callback) {
233+ backendBridge.call('OnlineAccounts.Client.requestAccount',
234+ [ applicationId, providerId],
235+ callback);
236+ },
237 },
238
239

Subscribers

People subscribed via source and target branches

to all changes: