You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by za...@apache.org on 2014/12/15 14:40:56 UTC
[2/2] cordova-plugin-inappbrowser git commit: ubuntu: implement
inject* functions
ubuntu: implement inject* functions
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/e5d6d6f6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/e5d6d6f6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/e5d6d6f6
Branch: refs/heads/master
Commit: e5d6d6f69aad5ebedb12af207986ace623daff75
Parents: 88b71b3
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Sat Oct 18 02:36:31 2014 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Mon Dec 15 16:38:26 2014 +0300
----------------------------------------------------------------------
plugin.xml | 1 +
src/ubuntu/InAppBrowser.qml | 24 +++++++++++++++++
src/ubuntu/InAppBrowser_escapeScript.js | 8 ++++++
src/ubuntu/inappbrowser.cpp | 39 ++++++++++++++++------------
4 files changed, 55 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/e5d6d6f6/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8d27ab5..cf32c7c 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -106,6 +106,7 @@
<header-file src="src/ubuntu/inappbrowser.h" />
<source-file src="src/ubuntu/inappbrowser.cpp" />
<resource-file src="src/ubuntu/InAppBrowser.qml" />
+ <resource-file src="src/ubuntu/InAppBrowser_escapeScript.js" />
<resource-file src="src/ubuntu/close.png" />
</platform>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/e5d6d6f6/src/ubuntu/InAppBrowser.qml
----------------------------------------------------------------------
diff --git a/src/ubuntu/InAppBrowser.qml b/src/ubuntu/InAppBrowser.qml
index 2d1af51..781e8a6 100644
--- a/src/ubuntu/InAppBrowser.qml
+++ b/src/ubuntu/InAppBrowser.qml
@@ -55,6 +55,19 @@ Rectangle {
}
}
+ property string usContext: "oxide://main-world/2"
+
+ function executeJS(scId, code) {
+ var req = _view.rootFrame.sendMessage(usContext, "EXECUTE", {code: code});
+
+ req.onreply = function(response) {
+ var code = 'cordova.callback(' + scId + ', JSON.parse(\'' + JSON.stringify(response.result) + '\'))';
+ console.warn(code);
+ cordova.javaScriptExecNeeded(code);
+ console.warn("RESP:" + JSON.stringify(response));
+ };
+ }
+
WebView {
width: parent.width
y: urlEntry.height
@@ -64,5 +77,16 @@ Rectangle {
onLoadingStateChanged: {
root.exec("InAppBrowser", "loadFinished", [_view.loading])
}
+ context: WebContext {
+ id: webcontext
+
+ userScripts: [
+ UserScript {
+ context: usContext
+ emulateGreasemonkey: true
+ url: "InAppBrowser_escapeScript.js"
+ }
+ ]
+ }
}
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/e5d6d6f6/src/ubuntu/InAppBrowser_escapeScript.js
----------------------------------------------------------------------
diff --git a/src/ubuntu/InAppBrowser_escapeScript.js b/src/ubuntu/InAppBrowser_escapeScript.js
new file mode 100644
index 0000000..e1c0c6c
--- /dev/null
+++ b/src/ubuntu/InAppBrowser_escapeScript.js
@@ -0,0 +1,8 @@
+oxide.addMessageHandler("EXECUTE", function(msg) {
+ var code = msg.args.code;
+ try {
+ msg.reply({result: eval(code)});
+ } catch(e) {
+ msg.error("Code threw exception: \"" + e + "\"");
+ }
+});
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/e5d6d6f6/src/ubuntu/inappbrowser.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/inappbrowser.cpp b/src/ubuntu/inappbrowser.cpp
index 97be212..c5a9e64 100644
--- a/src/ubuntu/inappbrowser.cpp
+++ b/src/ubuntu/inappbrowser.cpp
@@ -45,10 +45,10 @@ function finishCreation() { \
} \
createObject()";
-const char EXIT_EVENT[] = "'exit'";
-const char LOADSTART_EVENT[] = "'loadstart'";
-const char LOADSTOP_EVENT[] = "'loadstop'";
-const char LOADERROR_EVENT[] = "'loaderror'";
+const char EXIT_EVENT[] = "{type: 'exit'}";
+const char LOADSTART_EVENT[] = "{type: 'loadstart'}";
+const char LOADSTOP_EVENT[] = "{type: 'loadstop'}";
+const char LOADERROR_EVENT[] = "{type: 'loaderror'}";
void Inappbrowser::open(int cb, int, const QString &url, const QString &, const QString &) {
assert(_eventCb == 0);
@@ -71,28 +71,33 @@ void Inappbrowser::close(int, int) {
_eventCb = 0;
}
-void Inappbrowser::injectStyleFile(int, int, const QString&, bool) {
- // TODO:
- qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+void Inappbrowser::injectStyleFile(int scId, int ecId, const QString& src, bool b) {
+ QString code("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %1; d.head.appendChild(c);})(document)");
+ code = code.arg(CordovaInternal::format(src));
+
+ injectScriptCode(scId, ecId, code, b);
}
-void Inappbrowser::injectStyleCode(int, int, const QString&, bool) {
- // TODO:
- qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+void Inappbrowser::injectStyleCode(int scId, int ecId, const QString& src, bool b) {
+ QString code("(function(d) { var c = d.createElement('style'); c.innerHTML = %1; d.body.appendChild(c); })(document)");
+ code = code.arg(CordovaInternal::format(src));
+
+ injectScriptCode(scId, ecId, code, b);
}
-void Inappbrowser::injectScriptFile(int, int, const QString&, bool) {
- // TODO:
- qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+void Inappbrowser::injectScriptFile(int scId, int ecId, const QString& src, bool b) {
+ QString code("(function(d) { var c = d.createElement('script'); c.src = %1; d.body.appendChild(c);})(document)");
+ code = code.arg(CordovaInternal::format(src));
+
+ injectScriptCode(scId, ecId, code, b);
}
-void Inappbrowser::injectScriptCode(int, int, const QString&, bool) {
- // TODO:
- qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
+void Inappbrowser::injectScriptCode(int scId, int, const QString& code, bool) {
+ m_cordova->execQML(QString("CordovaWrapper.global.inappbrowser.executeJS(%2, %1)").arg(CordovaInternal::format(code)).arg(scId));
}
void Inappbrowser::loadFinished(bool status) {
- if (status) {
+ if (!status) {
this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT);
} else {
this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org