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
=== modified file 'debian/control'
--- debian/control 2014-10-14 10:02:49 +0000
+++ debian/control 2015-01-16 16:14:22 +0000
@@ -29,7 +29,7 @@
29Package: unity-webapps-qml29Package: unity-webapps-qml
30Architecture: any30Architecture: any
31Depends: qml-module-qtwebkit,31Depends: qml-module-qtwebkit,
32 liboxideqt-qmlplugin (>= 1.0),32 liboxideqt-qmlplugin (>= 1.3.0),
33 qtdeclarative5-qtquick2-plugin,33 qtdeclarative5-qtquick2-plugin,
34 qtdeclarative5-unity-action-plugin,34 qtdeclarative5-unity-action-plugin,
35 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,35 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,
3636
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.js'
--- src/Ubuntu/UnityWebApps/UnityWebApps.js 2014-07-18 13:43:55 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-01-16 16:14:22 +0000
@@ -40,7 +40,6 @@
40 this._injected_unity_api_path = injected_api_path;40 this._injected_unity_api_path = injected_api_path;
41 this._bindeeProxies = bindeeProxies;41 this._bindeeProxies = bindeeProxies;
42 this._backends = null;42 this._backends = null;
43 this._userscripts = [];
44 this._accessPolicy = accessPolicy;43 this._accessPolicy = accessPolicy;
45 this._callbackManager = UnityWebAppsUtils.makeCallbackManager();44 this._callbackManager = UnityWebAppsUtils.makeCallbackManager();
4645
@@ -50,16 +49,22 @@
50 _UnityWebApps.prototype = {49 _UnityWebApps.prototype = {
5150
52 cleanup: function() {51 cleanup: function() {
53 if (this._bindeeProxies.cleanup && typeof(this._bindeeProxies.cleanup) == 'function')52 if (this._bindeeProxies.cleanup
53 && typeof(this._bindeeProxies.cleanup) == 'function') {
54 this._bindeeProxies.cleanup();54 this._bindeeProxies.cleanup();
55 }
55 },56 },
5657
57 proxies: function() {58 proxies: function() {
58 return this._bindeeProxies;59 return this._bindeeProxies;
59 },60 },
6061
61 setUserScriptsToInject: function(userscripts) {62 injectWebappUserScripts: function(userscripts) {
62 this._userscripts = userscripts;63 if (this._bindeeProxies) {
64 this._bindeeProxies.injectUserScripts(
65 userscripts.map(function(script) {
66 return Qt.resolvedUrl(script); }));
67 }
63 },68 },
6469
65 setBackends: function(backends) {70 setBackends: function(backends) {
@@ -75,25 +80,18 @@
75 var cb = this._onMessageReceivedCallback.bind(self);80 var cb = this._onMessageReceivedCallback.bind(self);
76 self._bindeeProxies.messageReceivedConnect(cb);81 self._bindeeProxies.messageReceivedConnect(cb);
7782
78 cb = this._onLoadingStartedCallback.bind(self);83 this._injectCoreBindingUserScripts();
79 self._bindeeProxies.loadingStartedConnect(cb);
80 },84 },
8185
82 /**86 /**
83 * \internal87 * \internal
84 *88 *
85 */89 */
86 _onLoadingStartedCallback: function () {90 _injectCoreBindingUserScripts: function () {
87 var scripts = [this._injected_unity_api_path];91 if (this._bindeeProxies) {
88 for(var i = 0; i < this._userscripts.length; ++i) {92 this._bindeeProxies.injectUserScripts(
89 scripts.push(Qt.resolvedUrl(this._userscripts[i]));93 [Qt.resolvedUrl(this._injected_unity_api_path)]);
90 }94 }
91
92 for (i = 0; i < scripts.length; ++i)
93 console.debug('Injecting webapps script[' + i + '] : '
94 + scripts[i]);
95
96 this._bindeeProxies.injectUserScripts(scripts);
97 },95 },
9896
99 /**97 /**
10098
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-07-18 21:46:57 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-01-16 16:14:22 +0000
@@ -231,7 +231,7 @@
231 __getPolicyForContent(settings),231 __getPolicyForContent(settings),
232 customClientApiFileUrl && customClientApiFileUrl.length !== 0232 customClientApiFileUrl && customClientApiFileUrl.length !== 0
233 ? customClientApiFileUrl233 ? customClientApiFileUrl
234 : Qt.resolvedUrl('unity-webapps-api.js'));234 : 'unity-webapps-api.js');
235235
236 internal.instance = instance;236 internal.instance = instance;
237237
@@ -369,7 +369,7 @@
369 if (__isValidWebAppForModel(name)) {369 if (__isValidWebAppForModel(name)) {
370 if (internal.instance) {370 if (internal.instance) {
371 var userScripts = __gatherWebAppUserscriptsIfAny(name);371 var userScripts = __gatherWebAppUserscriptsIfAny(name);
372 internal.instance.setUserScriptsToInject(userScripts);372 internal.instance.injectWebappUserScripts(userScripts);
373 }373 }
374 __navigateToWebappHomepageInBindee(name);374 __navigateToWebappHomepageInBindee(name);
375 }375 }
376376
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js'
--- src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js 2014-07-18 13:43:55 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebAppsUtils.js 2015-01-16 16:14:22 +0000
@@ -63,14 +63,12 @@
63 this.webview = webview;63 this.webview = webview;
64 this.disposer = disposer;64 this.disposer = disposer;
65 this.makeSignalDisconnecter = makeSignalDisconnecter;65 this.makeSignalDisconnecter = makeSignalDisconnecter;
66 this._userScriptInjected = false;
67 this._WEBAPPS_USER_SCRIPT_CONTEXT = "oxide://UnityWebappsApi";66 this._WEBAPPS_USER_SCRIPT_CONTEXT = "oxide://UnityWebappsApi";
67 this._injectedUserScripts = [];
68 this._scriptMessageReceivedHandler = null;
68}69}
69OxideWebviewAdapter.prototype = {70OxideWebviewAdapter.prototype = {
70 injectUserScripts: function(userScriptUrls) {71 injectUserScripts: function(userScriptUrls) {
71 if (this._userScriptInjected)
72 return;
73
74 var context = this.webview.context;72 var context = this.webview.context;
75 if (!context) {73 if (!context) {
76 console.error('No context found for the current Oxide webview. Cannot inject user scripts.');74 console.error('No context found for the current Oxide webview. Cannot inject user scripts.');
@@ -78,18 +76,31 @@
78 }76 }
7977
80 for (var i = 0; i < userScriptUrls.length; ++i) {78 for (var i = 0; i < userScriptUrls.length; ++i) {
81 var scriptStart = "import com.canonical.Oxide 1.0 as Oxide; Oxide.UserScript { context:";79 var script = userScriptUrls[i];
80 if (this._injectedUserScripts.some(
81 function(e) { return e === script; })) {
82 console.log('Skipping already injected script: ' + script)
83 continue;
84 }
85
86 var scriptStart = "import com.canonical.Oxide 1.0 as Oxide; Oxide.UserScript { ";
82 var scriptEnd = "}";87 var scriptEnd = "}";
83 var statement = scriptStart +88 var statement = scriptStart
84 '"' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '"' +89 + 'context: "' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '";'
85 '; matchAllFrames: false; url: "' + userScriptUrls[i] + '";' + scriptEnd;90 + 'matchAllFrames: false;'
86 context.addUserScript(Qt.createQmlObject(statement, this.webview));91 + 'emulateGreasemonkey: true;'
92 + 'url: "' + script + '";'
93 + scriptEnd;
94 context.addUserScript(
95 Qt.createQmlObject(statement, this.webview));
87 }96 }
88 this._userScriptInjected = true;97 this._injectedUserScripts.push(script);
89 },98 },
90 sendToPage: function (message) {99 sendToPage: function (message) {
91 this.webview.rootFrame.sendMessageNoReply(100 this.webview.rootFrame.sendMessageNoReply(
92 this._WEBAPPS_USER_SCRIPT_CONTEXT, "UnityWebappApi-Host-Message", JSON.parse(message));101 this._WEBAPPS_USER_SCRIPT_CONTEXT,
102 "UnityWebappApi-Host-Message",
103 JSON.parse(message));
93 },104 },
94 loadingStartedConnect: function (onLoadingStarted) {105 loadingStartedConnect: function (onLoadingStarted) {
95 function handler(loadEvent) {106 function handler(loadEvent) {
@@ -102,17 +113,22 @@
102 this.disposer.addDisposer(this.makeSignalDisconnecter(this.webview.loadingChanged, handler));113 this.disposer.addDisposer(this.makeSignalDisconnecter(this.webview.loadingChanged, handler));
103 },114 },
104 messageReceivedConnect: function (onMessageReceived) {115 messageReceivedConnect: function (onMessageReceived) {
105 function handler(msg, frame) {116 function _handler(msg, frame) {
106 onMessageReceived(msg.args);117 onMessageReceived(msg.args);
107 }118 }
108119 if ( ! this._scriptMessageReceivedHandler) {
109 var script = 'import com.canonical.Oxide 1.0 as Oxide; ' +120 var script = 'import com.canonical.Oxide 1.0 as Oxide; ' +
110 ' Oxide.ScriptMessageHandler { msgId: "UnityWebappApi-Message"; contexts: ["' +121 ' Oxide.ScriptMessageHandler { '
111 this._WEBAPPS_USER_SCRIPT_CONTEXT +122 + 'msgId: "UnityWebappApi-Message"; '
112 '"]; ' +123 + 'contexts: ["' + this._WEBAPPS_USER_SCRIPT_CONTEXT + '"]; ' +
113 '}';124 '}';
114 var messageHandler = Qt.createQmlObject(script, this.webview);125 this._scriptMessageReceivedHandler =
115 messageHandler.callback = handler;126 Qt.createQmlObject(script, this.webview);
127 }
128 this._scriptMessageReceivedHandler.callback = _handler;
129 },
130 cleanupAdapterInternals: function() {
131 this._scriptMessageReceivedHandler.callback = function() {};
116 }132 }
117}133}
118134
@@ -194,6 +210,11 @@
194 // called from the UnityWebApps side210 // called from the UnityWebApps side
195 proxy.cleanup = function() {211 proxy.cleanup = function() {
196 disposer.disposeAndCleanupAll();212 disposer.disposeAndCleanupAll();
213
214 if (this.cleanupAdapterInternals
215 && typeof(this.cleanupAdapterInternals) === "function") {
216 this.cleanupAdapterInternals();
217 }
197 };218 };
198219
199 return proxy;220 return proxy;
200221
=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp'
--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2014-07-17 13:41:45 +0000
+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2015-01-16 16:14:22 +0000
@@ -191,8 +191,6 @@
191 QFileInfo manifestFileInfo =191 QFileInfo manifestFileInfo =
192 installationDir.absolutePath() + QDir::separator() + manifestFileName;192 installationDir.absolutePath() + QDir::separator() + manifestFileName;
193 if ( ! manifestFileInfo.isFile()) {193 if ( ! manifestFileInfo.isFile()) {
194 qDebug() << "Skipping" << manifestFileName << "as a webapp definition search: "
195 << manifestFileInfo.absoluteFilePath();
196 continue;194 continue;
197 }195 }
198196

Subscribers

People subscribed via source and target branches

to all changes: