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:55 UTC

[1/2] cordova-plugin-inappbrowser git commit: ubuntu: port to oxide

Repository: cordova-plugin-inappbrowser
Updated Branches:
  refs/heads/master a40a10f1e -> e5d6d6f69


ubuntu: port to oxide


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/88b71b3a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/88b71b3a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/88b71b3a

Branch: refs/heads/master
Commit: 88b71b3a579b0052dae1eff2a8e00d842c31991e
Parents: a40a10f
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Fri Oct 17 01:45:03 2014 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Mon Dec 15 16:38:22 2014 +0300

----------------------------------------------------------------------
 src/ubuntu/InAppBrowser.qml |  9 ++++-----
 src/ubuntu/inappbrowser.cpp | 12 ++++--------
 src/ubuntu/inappbrowser.h   |  2 +-
 3 files changed, 9 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/88b71b3a/src/ubuntu/InAppBrowser.qml
----------------------------------------------------------------------
diff --git a/src/ubuntu/InAppBrowser.qml b/src/ubuntu/InAppBrowser.qml
index 03448f6..2d1af51 100644
--- a/src/ubuntu/InAppBrowser.qml
+++ b/src/ubuntu/InAppBrowser.qml
@@ -21,9 +21,9 @@
  *
 */
 import QtQuick 2.0
-import QtWebKit 3.0
 import Ubuntu.Components.Popups 0.1
 import Ubuntu.Components 0.1
+import com.canonical.Oxide 1.0
 
 Rectangle {
     anchors.fill: parent
@@ -60,10 +60,9 @@ Rectangle {
         y: urlEntry.height
         height: parent.height - y
         url: url1
-        onLoadingChanged: {
-            if (loadRequest.status) {
-                root.exec("InAppBrowser", "loadFinished", [loadRequest.status])
-            }
+        id: _view
+        onLoadingStateChanged: {
+            root.exec("InAppBrowser", "loadFinished", [_view.loading])
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/88b71b3a/src/ubuntu/inappbrowser.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/inappbrowser.cpp b/src/ubuntu/inappbrowser.cpp
index 7a0538f..97be212 100644
--- a/src/ubuntu/inappbrowser.cpp
+++ b/src/ubuntu/inappbrowser.cpp
@@ -91,14 +91,10 @@ void Inappbrowser::injectScriptCode(int, int, const QString&, bool) {
     qCritical() << "unimplemented " << __PRETTY_FUNCTION__;
 }
 
-void Inappbrowser::loadFinished(int status) {
-    if (status == 2) {
-        this->callbackWithoutRemove(_eventCb, LOADERROR_EVENT);
-    }
-    if (status == 0) {
-        this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
-    }
-    if (status == 3) {
+void Inappbrowser::loadFinished(bool status) {
+    if (status) {
         this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT);
+    } else {
+        this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/88b71b3a/src/ubuntu/inappbrowser.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/inappbrowser.h b/src/ubuntu/inappbrowser.h
index 7a4a68a..1da4e03 100644
--- a/src/ubuntu/inappbrowser.h
+++ b/src/ubuntu/inappbrowser.h
@@ -52,7 +52,7 @@ public slots:
     void injectScriptFile(int cb, int, const QString&, bool);
     void injectScriptCode(int cb, int, const QString&, bool);
 
-    void loadFinished(int status);
+    void loadFinished(bool status);
 
 private:
     int _eventCb;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[2/2] cordova-plugin-inappbrowser git commit: ubuntu: implement inject* functions

Posted by za...@apache.org.
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