Merge lp:~abreu-alexandre/unity-webapps-qml/rtm-fix-local-script-handling into lp:unity-webapps-qml/rtm-14.09

Proposed by Alexandre Abreu on 2015-01-16
Status: Merged
Approved by: Alexandre Abreu on 2015-02-16
Approved revision: 134
Merged at revision: 136
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/rtm-fix-local-script-handling
Merge into: lp:unity-webapps-qml/rtm-14.09
Diff against target: 219 lines (+58/-41)
5 files modified
debian/control (+1/-1)
src/Ubuntu/UnityWebApps/UnityWebApps.js (+14/-16)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+2/-2)
src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js (+41/-20)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp (+0/-2)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/rtm-fix-local-script-handling
Reviewer Review Type Date Requested Status
WebApps 2015-01-16 Pending
Review via email: mp+246734@code.launchpad.net

Commit message

When using a webapp-properties file for an unamed webapp the user script does not get injected.

Description of the change

When using a webapp-properties file for an unamed webapp the user script does not get injected.

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 2014-10-14 10:02:49 +0000
3+++ debian/control 2015-01-16 16:14:22 +0000
4@@ -29,7 +29,7 @@
5 Package: unity-webapps-qml
6 Architecture: any
7 Depends: qml-module-qtwebkit,
8- liboxideqt-qmlplugin (>= 1.0),
9+ liboxideqt-qmlplugin (>= 1.3.0),
10 qtdeclarative5-qtquick2-plugin,
11 qtdeclarative5-unity-action-plugin,
12 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,
13
14=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.js'
15--- src/Ubuntu/UnityWebApps/UnityWebApps.js 2014-07-18 13:43:55 +0000
16+++ src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-01-16 16:14:22 +0000
17@@ -40,7 +40,6 @@
18 this._injected_unity_api_path = injected_api_path;
19 this._bindeeProxies = bindeeProxies;
20 this._backends = null;
21- this._userscripts = [];
22 this._accessPolicy = accessPolicy;
23 this._callbackManager = UnityWebAppsUtils.makeCallbackManager();
24
25@@ -50,16 +49,22 @@
26 _UnityWebApps.prototype = {
27
28 cleanup: function() {
29- if (this._bindeeProxies.cleanup && typeof(this._bindeeProxies.cleanup) == 'function')
30+ if (this._bindeeProxies.cleanup
31+ && typeof(this._bindeeProxies.cleanup) == 'function') {
32 this._bindeeProxies.cleanup();
33+ }
34 },
35
36 proxies: function() {
37 return this._bindeeProxies;
38 },
39
40- setUserScriptsToInject: function(userscripts) {
41- this._userscripts = userscripts;
42+ injectWebappUserScripts: function(userscripts) {
43+ if (this._bindeeProxies) {
44+ this._bindeeProxies.injectUserScripts(
45+ userscripts.map(function(script) {
46+ return Qt.resolvedUrl(script); }));
47+ }
48 },
49
50 setBackends: function(backends) {
51@@ -75,25 +80,18 @@
52 var cb = this._onMessageReceivedCallback.bind(self);
53 self._bindeeProxies.messageReceivedConnect(cb);
54
55- cb = this._onLoadingStartedCallback.bind(self);
56- self._bindeeProxies.loadingStartedConnect(cb);
57+ this._injectCoreBindingUserScripts();
58 },
59
60 /**
61 * \internal
62 *
63 */
64- _onLoadingStartedCallback: function () {
65- var scripts = [this._injected_unity_api_path];
66- for(var i = 0; i < this._userscripts.length; ++i) {
67- scripts.push(Qt.resolvedUrl(this._userscripts[i]));
68+ _injectCoreBindingUserScripts: function () {
69+ if (this._bindeeProxies) {
70+ this._bindeeProxies.injectUserScripts(
71+ [Qt.resolvedUrl(this._injected_unity_api_path)]);
72 }
73-
74- for (i = 0; i < scripts.length; ++i)
75- console.debug('Injecting webapps script[' + i + '] : '
76- + scripts[i]);
77-
78- this._bindeeProxies.injectUserScripts(scripts);
79 },
80
81 /**
82
83=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
84--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-07-18 21:46:57 +0000
85+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-01-16 16:14:22 +0000
86@@ -231,7 +231,7 @@
87 __getPolicyForContent(settings),
88 customClientApiFileUrl && customClientApiFileUrl.length !== 0
89 ? customClientApiFileUrl
90- : Qt.resolvedUrl('unity-webapps-api.js'));
91+ : 'unity-webapps-api.js');
92
93 internal.instance = instance;
94
95@@ -369,7 +369,7 @@
96 if (__isValidWebAppForModel(name)) {
97 if (internal.instance) {
98 var userScripts = __gatherWebAppUserscriptsIfAny(name);
99- internal.instance.setUserScriptsToInject(userScripts);
100+ internal.instance.injectWebappUserScripts(userScripts);
101 }
102 __navigateToWebappHomepageInBindee(name);
103 }
104
105=== modified file 'src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js'
106--- src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js 2014-07-18 13:43:55 +0000
107+++ src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js 2015-01-16 16:14:22 +0000
108@@ -63,14 +63,12 @@
109 this.webview = webview;
110 this.disposer = disposer;
111 this.makeSignalDisconnecter = makeSignalDisconnecter;
112- this._userScriptInjected = false;
113 this._WEBAPPS_USER_SCRIPT_CONTEXT = "oxide://UnityWebappsApi";
114+ this._injectedUserScripts = [];
115+ this._scriptMessageReceivedHandler = null;
116 }
117 OxideWebviewAdapter.prototype = {
118 injectUserScripts: function(userScriptUrls) {
119- if (this._userScriptInjected)
120- return;
121-
122 var context = this.webview.context;
123 if (!context) {
124 console.error('No context found for the current Oxide webview. Cannot inject user scripts.');
125@@ -78,18 +76,31 @@
126 }
127
128 for (var i = 0; i < userScriptUrls.length; ++i) {
129- var scriptStart = "import com.canonical.Oxide 1.0 as Oxide; Oxide.UserScript { context:";
130+ var script = userScriptUrls[i];
131+ if (this._injectedUserScripts.some(
132+ function(e) { return e === script; })) {
133+ console.log('Skipping already injected script: ' + script)
134+ continue;
135+ }
136+
137+ var scriptStart = "import com.canonical.Oxide 1.0 as Oxide; Oxide.UserScript { ";
138 var scriptEnd = "}";
139- var statement = scriptStart +
140- '"' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '"' +
141- '; matchAllFrames: false; url: "' + userScriptUrls[i] + '";' + scriptEnd;
142- context.addUserScript(Qt.createQmlObject(statement, this.webview));
143+ var statement = scriptStart
144+ + 'context: "' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '";'
145+ + 'matchAllFrames: false;'
146+ + 'emulateGreasemonkey: true;'
147+ + 'url: "' + script + '";'
148+ + scriptEnd;
149+ context.addUserScript(
150+ Qt.createQmlObject(statement, this.webview));
151 }
152- this._userScriptInjected = true;
153+ this._injectedUserScripts.push(script);
154 },
155 sendToPage: function (message) {
156 this.webview.rootFrame.sendMessageNoReply(
157- this._WEBAPPS_USER_SCRIPT_CONTEXT, "UnityWebappApi-Host-Message", JSON.parse(message));
158+ this._WEBAPPS_USER_SCRIPT_CONTEXT,
159+ "UnityWebappApi-Host-Message",
160+ JSON.parse(message));
161 },
162 loadingStartedConnect: function (onLoadingStarted) {
163 function handler(loadEvent) {
164@@ -102,17 +113,22 @@
165 this.disposer.addDisposer(this.makeSignalDisconnecter(this.webview.loadingChanged, handler));
166 },
167 messageReceivedConnect: function (onMessageReceived) {
168- function handler(msg, frame) {
169+ function _handler(msg, frame) {
170 onMessageReceived(msg.args);
171 }
172-
173- var script = 'import com.canonical.Oxide 1.0 as Oxide; ' +
174- ' Oxide.ScriptMessageHandler { msgId: "UnityWebappApi-Message"; contexts: ["' +
175- this._WEBAPPS_USER_SCRIPT_CONTEXT +
176- '"]; ' +
177- '}';
178- var messageHandler = Qt.createQmlObject(script, this.webview);
179- messageHandler.callback = handler;
180+ if ( ! this._scriptMessageReceivedHandler) {
181+ var script = 'import com.canonical.Oxide 1.0 as Oxide; ' +
182+ ' Oxide.ScriptMessageHandler { '
183+ + 'msgId: "UnityWebappApi-Message"; '
184+ + 'contexts: ["' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '"]; ' +
185+ '}';
186+ this._scriptMessageReceivedHandler =
187+ Qt.createQmlObject(script, this.webview);
188+ }
189+ this._scriptMessageReceivedHandler.callback = _handler;
190+ },
191+ cleanupAdapterInternals: function() {
192+ this._scriptMessageReceivedHandler.callback = function() {};
193 }
194 }
195
196@@ -194,6 +210,11 @@
197 // called from the UnityWebApps side
198 proxy.cleanup = function() {
199 disposer.disposeAndCleanupAll();
200+
201+ if (this.cleanupAdapterInternals
202+ && typeof(this.cleanupAdapterInternals) === "function") {
203+ this.cleanupAdapterInternals();
204+ }
205 };
206
207 return proxy;
208
209=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp'
210--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2014-07-17 13:41:45 +0000
211+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2015-01-16 16:14:22 +0000
212@@ -191,8 +191,6 @@
213 QFileInfo manifestFileInfo =
214 installationDir.absolutePath() + QDir::separator() + manifestFileName;
215 if ( ! manifestFileInfo.isFile()) {
216- qDebug() << "Skipping" << manifestFileName << "as a webapp definition search: "
217- << manifestFileInfo.absoluteFilePath();
218 continue;
219 }
220

Subscribers

People subscribed via source and target branches

to all changes: