ubuntu: implement inject* functions
This commit is contained in:
parent
88b71b3a57
commit
e5d6d6f69a
@ -106,6 +106,7 @@
|
|||||||
<header-file src="src/ubuntu/inappbrowser.h" />
|
<header-file src="src/ubuntu/inappbrowser.h" />
|
||||||
<source-file src="src/ubuntu/inappbrowser.cpp" />
|
<source-file src="src/ubuntu/inappbrowser.cpp" />
|
||||||
<resource-file src="src/ubuntu/InAppBrowser.qml" />
|
<resource-file src="src/ubuntu/InAppBrowser.qml" />
|
||||||
|
<resource-file src="src/ubuntu/InAppBrowser_escapeScript.js" />
|
||||||
<resource-file src="src/ubuntu/close.png" />
|
<resource-file src="src/ubuntu/close.png" />
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
|
@ -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 {
|
WebView {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
y: urlEntry.height
|
y: urlEntry.height
|
||||||
@ -64,5 +77,16 @@ Rectangle {
|
|||||||
onLoadingStateChanged: {
|
onLoadingStateChanged: {
|
||||||
root.exec("InAppBrowser", "loadFinished", [_view.loading])
|
root.exec("InAppBrowser", "loadFinished", [_view.loading])
|
||||||
}
|
}
|
||||||
|
context: WebContext {
|
||||||
|
id: webcontext
|
||||||
|
|
||||||
|
userScripts: [
|
||||||
|
UserScript {
|
||||||
|
context: usContext
|
||||||
|
emulateGreasemonkey: true
|
||||||
|
url: "InAppBrowser_escapeScript.js"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
src/ubuntu/InAppBrowser_escapeScript.js
Normal file
8
src/ubuntu/InAppBrowser_escapeScript.js
Normal file
@ -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 + "\"");
|
||||||
|
}
|
||||||
|
});
|
@ -45,10 +45,10 @@ function finishCreation() { \
|
|||||||
} \
|
} \
|
||||||
createObject()";
|
createObject()";
|
||||||
|
|
||||||
const char EXIT_EVENT[] = "'exit'";
|
const char EXIT_EVENT[] = "{type: 'exit'}";
|
||||||
const char LOADSTART_EVENT[] = "'loadstart'";
|
const char LOADSTART_EVENT[] = "{type: 'loadstart'}";
|
||||||
const char LOADSTOP_EVENT[] = "'loadstop'";
|
const char LOADSTOP_EVENT[] = "{type: 'loadstop'}";
|
||||||
const char LOADERROR_EVENT[] = "'loaderror'";
|
const char LOADERROR_EVENT[] = "{type: 'loaderror'}";
|
||||||
|
|
||||||
void Inappbrowser::open(int cb, int, const QString &url, const QString &, const QString &) {
|
void Inappbrowser::open(int cb, int, const QString &url, const QString &, const QString &) {
|
||||||
assert(_eventCb == 0);
|
assert(_eventCb == 0);
|
||||||
@ -71,28 +71,33 @@ void Inappbrowser::close(int, int) {
|
|||||||
_eventCb = 0;
|
_eventCb = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inappbrowser::injectStyleFile(int, int, const QString&, bool) {
|
void Inappbrowser::injectStyleFile(int scId, int ecId, const QString& src, bool b) {
|
||||||
// TODO:
|
QString code("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %1; d.head.appendChild(c);})(document)");
|
||||||
qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
|
code = code.arg(CordovaInternal::format(src));
|
||||||
|
|
||||||
|
injectScriptCode(scId, ecId, code, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inappbrowser::injectStyleCode(int, int, const QString&, bool) {
|
void Inappbrowser::injectStyleCode(int scId, int ecId, const QString& src, bool b) {
|
||||||
// TODO:
|
QString code("(function(d) { var c = d.createElement('style'); c.innerHTML = %1; d.body.appendChild(c); })(document)");
|
||||||
qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
|
code = code.arg(CordovaInternal::format(src));
|
||||||
|
|
||||||
|
injectScriptCode(scId, ecId, code, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inappbrowser::injectScriptFile(int, int, const QString&, bool) {
|
void Inappbrowser::injectScriptFile(int scId, int ecId, const QString& src, bool b) {
|
||||||
// TODO:
|
QString code("(function(d) { var c = d.createElement('script'); c.src = %1; d.body.appendChild(c);})(document)");
|
||||||
qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
|
code = code.arg(CordovaInternal::format(src));
|
||||||
|
|
||||||
|
injectScriptCode(scId, ecId, code, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inappbrowser::injectScriptCode(int, int, const QString&, bool) {
|
void Inappbrowser::injectScriptCode(int scId, int, const QString& code, bool) {
|
||||||
// TODO:
|
m_cordova->execQML(QString("CordovaWrapper.global.inappbrowser.executeJS(%2, %1)").arg(CordovaInternal::format(code)).arg(scId));
|
||||||
qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inappbrowser::loadFinished(bool status) {
|
void Inappbrowser::loadFinished(bool status) {
|
||||||
if (status) {
|
if (!status) {
|
||||||
this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT);
|
this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT);
|
||||||
} else {
|
} else {
|
||||||
this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
|
this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
|
||||||
|
Loading…
Reference in New Issue
Block a user