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

Proposed by Alexandre Abreu on 2015-03-16
Status: Needs review
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/14.10-backport-oa-api-requestaccount
Merge into: lp:unity-webapps-qml/14.10
Diff against target: 318 lines (+164/-10)
10 files modified
debian/control (+2/-1)
examples/api-bindings/online-accounts/www/js/app.js (+11/-1)
src/Ubuntu/UnityWebApps/UnityWebApps.js (+1/-2)
src/Ubuntu/UnityWebApps/UnityWebApps.pro (+3/-1)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+9/-1)
src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js (+2/-2)
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)
src/Ubuntu/UnityWebApps/common/js/unity-backend-messaging-proxy.js (+1/-1)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/14.10-backport-oa-api-requestaccount
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) 2015-03-16 Approve on 2015-03-19
Review via email: mp+253057@code.launchpad.net

Commit message

Backport requestAccount() new OA API to 14.10

Description of the change

Backport requestAccount() new OA API to 14.10

To post a comment you must log in.
135. By Alexandre Abreu on 2015-03-16

fixes

Alberto Mardegan (mardy) wrote :

Yes, looks familiar :-)

review: Approve

Unmerged revisions

135. By Alexandre Abreu on 2015-03-16

fixes

134. By Alexandre Abreu on 2015-03-06

backport requestAccount() for OA API

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 2014-10-14 10:02:49 +0000
3+++ debian/control 2015-03-16 20:19:48 +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-16 20:19:48 +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.js'
45--- src/Ubuntu/UnityWebApps/UnityWebApps.js 2014-07-18 13:43:55 +0000
46+++ src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-03-16 20:19:48 +0000
47@@ -75,8 +75,7 @@
48 var cb = this._onMessageReceivedCallback.bind(self);
49 self._bindeeProxies.messageReceivedConnect(cb);
50
51- cb = this._onLoadingStartedCallback.bind(self);
52- self._bindeeProxies.loadingStartedConnect(cb);
53+ this._onLoadingStartedCallback();
54 },
55
56 /**
57
58=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.pro'
59--- src/Ubuntu/UnityWebApps/UnityWebApps.pro 2014-07-11 17:13:18 +0000
60+++ src/Ubuntu/UnityWebApps/UnityWebApps.pro 2015-03-16 20:19:48 +0000
61@@ -60,7 +60,9 @@
62 alarm_binding_backend_js_files.files = ./bindings/alarm-api/backend/alarm-api.js
63
64 online_accounts_binding_backend_js_files.path = $$installPath/bindings/online-accounts/backend/
65-online_accounts_binding_backend_js_files.files = ./bindings/online-accounts/backend/online-accounts.js
66+online_accounts_binding_backend_js_files.files = \
67+ ./bindings/online-accounts/backend/online-accounts.js \
68+ ./bindings/online-accounts/backend/online-accounts-client.js
69
70 runtime_api_binding_backend_js_files.path = $$installPath/bindings/runtime-api/backend/
71 runtime_api_binding_backend_js_files.files = ./bindings/runtime-api/backend/runtime-api.js
72
73=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
74--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-07-18 21:46:57 +0000
75+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-16 20:19:48 +0000
76@@ -26,6 +26,7 @@
77 import "./bindings/alarm-api/backend/alarm-api.js" as AlarmApiBackend
78 import "./bindings/content-hub/backend/content-hub.js" as ContentHubApiBackend
79 import "./bindings/online-accounts/backend/online-accounts.js" as OnlineAccountsApiBackend
80+import "./bindings/online-accounts/backend/online-accounts-client.js" as OnlineAccountsClientApiBackend
81 import "./bindings/download-manager/backend/download-api.js" as DownloadApiBackend
82
83 /*!
84@@ -167,6 +168,7 @@
85 */
86 property string _opt_homepage: ""
87
88+ signal userScriptsInjected()
89
90 Settings {
91 id: settings
92@@ -237,6 +239,8 @@
93
94 if (internal.backends)
95 internal.instance.setBackends(internal.backends)
96+
97+ userScriptsInjected();
98 }
99
100 /*!
101@@ -392,7 +396,11 @@
102 \internal
103
104 */
105- onModelChanged: model.modelContentChanged.connect(__setupNamedWebappEnvironment)
106+ onModelChanged: {
107+ if (model) {
108+ model.modelContentChanged.connect(__setupNamedWebappEnvironment)
109+ }
110+ }
111
112 /*!
113 \internal
114
115=== modified file 'src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js'
116--- src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js 2014-07-18 13:43:55 +0000
117+++ src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js 2015-03-16 20:19:48 +0000
118@@ -64,7 +64,7 @@
119 this.disposer = disposer;
120 this.makeSignalDisconnecter = makeSignalDisconnecter;
121 this._userScriptInjected = false;
122- this._WEBAPPS_USER_SCRIPT_CONTEXT = "oxide://UnityWebappsApi";
123+ this._WEBAPPS_USER_SCRIPT_CONTEXT = "oxide://main-world";
124 }
125 OxideWebviewAdapter.prototype = {
126 injectUserScripts: function(userScriptUrls) {
127@@ -82,7 +82,7 @@
128 var scriptEnd = "}";
129 var statement = scriptStart +
130 '"' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '"' +
131- '; matchAllFrames: false; url: "' + userScriptUrls[i] + '";' + scriptEnd;
132+ '; matchAllFrames: false; emulateGreasemonkey: true; url: "' + userScriptUrls[i] + '";' + scriptEnd;
133 context.addUserScript(Qt.createQmlObject(statement, this.webview));
134 }
135 this._userScriptInjected = true;
136
137=== added file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js'
138--- src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js 1970-01-01 00:00:00 +0000
139+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts-client.js 2015-03-16 20:19:48 +0000
140@@ -0,0 +1,87 @@
141+/*
142+ * Copyright 2014 Canonical Ltd.
143+ *
144+ * This file is part of unity-webapps-qml.
145+ *
146+ * unity-webapps-qml is free software; you can redistribute it and/or modify
147+ * it under the terms of the GNU General Public License as published by
148+ * the Free Software Foundation; version 3.
149+ *
150+ * unity-webapps-qml is distributed in the hope that it will be useful,
151+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
152+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153+ * GNU General Public License for more details.
154+ *
155+ * You should have received a copy of the GNU General Public License
156+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
157+ */
158+
159+/**
160+ *
161+ * Online Accounts client API backend binding
162+ *
163+ */
164+function createOnlineAccountsClientApi(backendDelegate) {
165+ var PLUGIN_URI = 'Ubuntu.OnlineAccounts.Client';
166+ var VERSION = 0.1;
167+
168+ function Setup(params) {
169+ var result = backendDelegate.createQmlObject(
170+ PLUGIN_URI, VERSION, 'Setup', params);
171+ this._id = result.id;
172+ this._object = result.object;
173+ };
174+ Setup.prototype = {
175+ _validate: function() {
176+ if (! this._object)
177+ throw new TypeError("Invalid object null");
178+ },
179+
180+ destroy: function() {
181+ if (! this._object)
182+ return;
183+ this._object.destroy();
184+ backendDelegate.deleteId(this._id);
185+ },
186+
187+ // object methods
188+ serialize: function() {
189+ this._validate();
190+ return {
191+ type: 'object-proxy',
192+ apiid: 'OnlineAccounts.Client',
193+ objecttype: 'Setup',
194+ objectid: this._id,
195+ }
196+ },
197+
198+ // methods
199+ exec: function(callback) {
200+ this._validate();
201+
202+ var self = this;
203+
204+ var onFinished = function() {
205+ self._object.onFinished.disconnect(onFinished);
206+ callback();
207+ }
208+
209+ this._object.onFinished.connect(onFinished);
210+ this._object.exec();
211+ }
212+ };
213+
214+ return {
215+ requestAccount: function(applicationId, providerId, callback) {
216+ var setup = new Setup({
217+ 'applicationId': applicationId,
218+ 'providerId': providerId,
219+ });
220+ var onFinished = function() {
221+ setup.destroy();
222+ callback();
223+ };
224+ setup.exec(onFinished);
225+ },
226+ };
227+}
228
229=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js'
230--- src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2014-05-22 08:54:56 +0000
231+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/backend/online-accounts.js 2015-03-16 20:19:48 +0000
232@@ -673,6 +673,8 @@
233 }
234 },
235
236+ Client: OnlineAccountsClientApiBackend.createOnlineAccountsClientApi(backendDelegate),
237+
238 // Internal
239
240 dispatchToObject: function(infos) {
241
242=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js'
243--- src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js 2014-05-09 13:17:09 +0000
244+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js 2015-03-16 20:19:48 +0000
245@@ -161,7 +161,7 @@
246 *
247 * @method api.getAccounts
248 * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
249- * - application: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
250+ * - applicationId: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
251 * - provider: the ID of a provider (see /usr/share/accounts/providers/ or ~/.local/share/accounts/providers/ for a list of the available providers)
252 * - service: the ID of a service (see /usr/share/accounts/services/ or ~/.local/share/accounts/services/ for a list of the available services)
253 *
254@@ -215,6 +215,51 @@
255 , [filters]
256 , callback);
257 },
258+ /**
259+ * Requests access to an account.
260+ *
261+ * Applications must invoke this method in order to obtain access
262+ * to an account. The user will be prompted to grant access to
263+ * either an existing account, to create a new one or to decline
264+ * the request.
265+ *
266+ * @method api.requestAccount
267+ * @param applicationId {String} The ID of the application
268+ * requesting the account (see /usr/share/accounts/applications/ or
269+ * ~/.local/share/accounts/applications/ for a list of the
270+ * available applications)
271+ * @param providerId {String} The ID of the provider of the desired
272+ * account (see /usr/share/accounts/providers/ or
273+ * ~/.local/share/accounts/providers/ for a list of the available
274+ * providers)
275+ * @param callback {Function()} Callback which will be invoked
276+ * after the access request has been decided (either with the
277+ * access to an account being granted, or with a refusal).
278+ *
279+ * @example
280+ var api = external.getUnityObject(1.0);
281+ var oa = api.OnlineAccounts;
282+
283+ var appId = 'com.ubuntu.developer.me.MyPackage_MyApp';
284+ oa.api.requestAccount(appId,
285+ 'facebook',
286+ function() {
287+ oa.api.getAccounts({ 'application': appId }, function(result) {
288+ for (var i = 0; i < result.length; ++i) {
289+ console.log("name: " + result[i].displayName()
290+ + ', id: ' + result[i].accountId()
291+ + ', providerName: ' + result[i].provider().displayName
292+ + ', enabled: ' + (result[i].enabled() ? "true" : "false")
293+ );
294+ }
295+ });
296+ });
297+ */
298+ requestAccount: function(applicationId, providerId, callback) {
299+ backendBridge.call('OnlineAccounts.Client.requestAccount',
300+ [ applicationId, providerId],
301+ callback);
302+ },
303 },
304
305
306
307=== modified file 'src/Ubuntu/UnityWebApps/common/js/unity-backend-messaging-proxy.js'
308--- src/Ubuntu/UnityWebApps/common/js/unity-backend-messaging-proxy.js 2014-03-28 13:21:47 +0000
309+++ src/Ubuntu/UnityWebApps/common/js/unity-backend-messaging-proxy.js 2015-03-16 20:19:48 +0000
310@@ -4,7 +4,7 @@
311 navigator.qt.postMessage) {
312 return new UnityQtWebkitBackendMessagingProxy();
313 }
314- else if (window.oxide) {
315+ else if (oxide) {
316 return new UnityOxideBackendMessagingProxy();
317 }
318 return null;

Subscribers

People subscribed via source and target branches

to all changes: