cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zasp...@apache.org
Subject [09/37] cordova-ubuntu git commit: port to oxide
Date Mon, 15 Dec 2014 13:32:58 GMT
port to oxide


Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/ed47b556
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/ed47b556
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/ed47b556

Branch: refs/heads/master
Commit: ed47b556cb34de78fb8e0c1fc25bceec925c25ed
Parents: 9669f2c
Author: Maxim Ermilov <maxim.ermilov@canonical.com>
Authored: Fri Oct 17 05:25:15 2014 +0400
Committer: Maxim Ermilov <maxim.ermilov@canonical.com>
Committed: Fri Oct 17 05:25:15 2014 +0400

----------------------------------------------------------------------
 Cordovaqt/CordovaViewInternal.qml | 105 ++++++++++++++++++---------------
 Cordovaqt/cordova_wrapper.js      |   4 +-
 Cordovaqt/escape.js               |   1 +
 src/qmlplugin.h                   |   4 ++
 www/cordova.js                    |  14 ++++-
 5 files changed, 75 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/ed47b556/Cordovaqt/CordovaViewInternal.qml
----------------------------------------------------------------------
diff --git a/Cordovaqt/CordovaViewInternal.qml b/Cordovaqt/CordovaViewInternal.qml
index b0b986d..4c7009a 100644
--- a/Cordovaqt/CordovaViewInternal.qml
+++ b/Cordovaqt/CordovaViewInternal.qml
@@ -17,8 +17,7 @@
  *
 */
 import QtQuick 2.0
-import QtWebKit 3.0
-import QtWebKit.experimental 1.0
+import com.canonical.Oxide 1.0
 import "cordova_wrapper.js" as CordovaWrapper
 import Ubuntu.Components 0.1
 import Ubuntu.Components.Popups 0.1
@@ -41,20 +40,7 @@ Item {
     function plugin(plugin) {
         return CordovaWrapper.pluginObjects[plugin];
     }
-
-    function overrideScheme(schemeName, pluginName) {
-        var handler = Qt.createQmlObject("import QtWebKit.experimental 1.0;"
-            + "UrlSchemeDelegate { scheme: '" + schemeName + "';"
-            + "onReceivedRequest: { var data = plugin('" + pluginName + "').handleUri(request.url);
reply.data = data; reply.contentType = 'application/octet-stream'; reply.send(); } } ", webView);
-
-        var handlers = [];
-        // QQmlListProperty (qt 5.2) does not support appending items from qml
-        for (var i in webView.experimental.urlSchemeDelegates)
-            handlers.push(webView.experimental.urlSchemeDelegates[i])
-
-        handlers.push(handler);
-        webView.experimental.urlSchemeDelegates = handlers;
-    }
+    property string usContext: "oxide://main-world"
 
     Rectangle {
         id: webViewContainer
@@ -66,44 +52,69 @@ Item {
 
             onNavigationRequested: {
                 if (cordova.isUrlWhiteListed(request.url))
-                    request.action = WebView.AcceptRequest;
+                    request.action = NavigationRequest.ActionAccept;
                 else
-                    request.action = WebView.IgnoreRequest;
+                    request.action = NavigationRequest.ActionReject;
             }
 
-            boundsBehavior: disallowOverscroll ? Flickable.StopAtBounds : Flickable.DragAndOvershootBounds
+            preferences.remoteFontsEnabled: true
+            preferences.javascriptCanAccessClipboard: true
+            preferences.canDisplayInsecureContent: true
+            preferences.canRunInsecureContent: true
+
+            preferences.allowUniversalAccessFromFileUrls: true
+            preferences.allowFileAccessFromFileUrls: true
+
+            preferences.localStorageEnabled: true
+            preferences.appCacheEnabled: true
+
+//            boundsBehavior: disallowOverscroll ? Flickable.StopAtBounds : Flickable.DragAndOvershootBounds
             property string scheme: "file"
-            experimental.preferences.navigatorQtObjectEnabled: true
-            experimental.preferences.localStorageEnabled: true
-            experimental.preferences.offlineWebApplicationCacheEnabled: true
-            experimental.preferences.universalAccessFromFileURLsAllowed: true
-            experimental.preferences.webGLEnabled: true
-            experimental.databaseQuotaDialog: Item {
-                Timer {
-                    interval: 1
-                    running: true
-                    onTriggered: {
-                        model.accept(model.expectedUsage)
-                    }
-                }
-            }
-            // port in QTWEBKIT_INSPECTOR_SERVER enviroment variable
-            experimental.preferences.developerExtrasEnabled: true
 
-            function evalInPageUnsafe(expr) {
-                experimental.evaluateJavaScript('(function() { ' + expr + ' })();');
+            property var currentDialog: null
+
+            // FIXME: remove code from geolocation plugin
+            onGeolocationPermissionRequested: {
+                request.accept();
             }
 
-            experimental.onMessageReceived: {
-                if (message.data.length > 1000) {
-                    console.debug("WebView received Message: " + message.data.substr(0, 900)
+ "...");
-                } else {
-                    console.debug("WebView received Message: " + message.data);
-                }
+            context: WebContext {
+                id: webcontext
+
+                devtoolsEnabled: true
+                devtoolsPort: 9222
 
-                CordovaWrapper.messageHandler(message)
+                userScripts: [
+                    UserScript {
+                        context: usContext
+                        emulateGreasemonkey: true
+                        url: "escape.js"
+                    }
+                ]
+                sessionCookieMode: {
+                    if (typeof webContextSessionCookieMode !== 'undefined') {
+                        if (webContextSessionCookieMode === "persistent") {
+                            return WebContext.SessionCookieModePersistent
+                        } else if (webContextSessionCookieMode === "restored") {
+                            return WebContext.SessionCookieModeRestored
+                        }
+                    }
+                    return WebContext.SessionCookieModeEphemeral
+                }
+                dataPath: cordova.getDataLocation()
             }
 
+            messageHandlers: [
+                ScriptMessageHandler {
+                    msgId: "from-cordova"
+                    contexts: [usContext]
+                    callback: function(msg, frame) {
+                        CordovaWrapper.messageHandler(msg.args)
+                        console.log(JSON.stringify(msg.args))
+                    }
+                }
+            ]
+
             Component.onCompleted: {
                 root.mainWebview = webView;
                 cordova.appLoaded();
@@ -115,17 +126,15 @@ Item {
             }
 
             onLoadingChanged: {
-                if (loadRequest.status) {
+                if (!webView.loading) {
                     root.completed()
                     cordova.loadFinished(true)
                 }
-                //TODO: check here for errors
             }
-
             Connections {
                 target: cordova
                 onJavaScriptExecNeeded: {
-                    webView.experimental.evaluateJavaScript(js);
+                      webView.rootFrame.sendMessage(usContext, "EXECUTE", {code: js});
                 }
                 onQmlExecNeeded: {
                     eval(src);

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/ed47b556/Cordovaqt/cordova_wrapper.js
----------------------------------------------------------------------
diff --git a/Cordovaqt/cordova_wrapper.js b/Cordovaqt/cordova_wrapper.js
index 3a4cddc..006614c 100644
--- a/Cordovaqt/cordova_wrapper.js
+++ b/Cordovaqt/cordova_wrapper.js
@@ -29,8 +29,7 @@ function addPlugin(pluginName, pluginObject) {
     pluginObjects[pluginName] = pluginObject
 }
 
-function messageHandler(message) {
-    var received = eval(message.data); // TODO: qt 5.2 have buggy JSON.parse. JSON.parse
fails on FileApi tests
+function messageHandler(received) {
     if (typeof received === 'undefined')
         return false;
     if (typeof received.messageType === 'undefined')
@@ -46,6 +45,7 @@ function messageHandler(message) {
 function execMethod(pluginName, functionName, params) {
     if (typeof pluginObjects[pluginName][functionName] != "function")
         return false;
+
     pluginObjects[pluginName][functionName].apply(this, params);
     return true;
 }

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/ed47b556/Cordovaqt/escape.js
----------------------------------------------------------------------
diff --git a/Cordovaqt/escape.js b/Cordovaqt/escape.js
new file mode 100644
index 0000000..48243ad
--- /dev/null
+++ b/Cordovaqt/escape.js
@@ -0,0 +1 @@
+window.oxide = oxide;

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/ed47b556/src/qmlplugin.h
----------------------------------------------------------------------
diff --git a/src/qmlplugin.h b/src/qmlplugin.h
index ebe9adc..4492bb2 100644
--- a/src/qmlplugin.h
+++ b/src/qmlplugin.h
@@ -63,6 +63,10 @@ public:
         return QSharedPointer<Cordova>(new Cordova(QDir(www), "index.html", parent))->getSplashscreenPath();
     }
 
+    Q_INVOKABLE static QString getDataLocation() {
+        return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+    }
+
     QString mainUrl() {
         if (!_cordova.data()) {
             return "";

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/ed47b556/www/cordova.js
----------------------------------------------------------------------
diff --git a/www/cordova.js b/www/cordova.js
index e40cd9a..18e9d6a 100644
--- a/www/cordova.js
+++ b/www/cordova.js
@@ -278,7 +278,7 @@ var cordova = {
         try {
             cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
         } catch (e) {
-            console.log("Error in error callback: " + callbackId + " = "+e);
+            console.log("Error in success callback: " + callbackId + " = "+e);
         }
     },
 
@@ -846,6 +846,7 @@ cordova.callbackWithoutRemove = function() {
     if (typeof(callbackRef) == "function") callbackRef.apply(this, parameters);
 };
 
+var _initialized = false;
 function ubuntuExec(success, fail, service, action, args) {
     if (callbackId % 2) {
         callbackId++;
@@ -859,7 +860,14 @@ function ubuntuExec(success, fail, service, action, args) {
     args.unshift(ecId);
     args.unshift(scId);
 
-    navigator.qt.postMessage(JSON.stringify({messageType: "callPluginFunction", plugin: service,
func: action, params: args}));
+    if (!_initialized) {
+        _initialized = true;
+        window.oxide.addMessageHandler("EXECUTE", function (msg) {
+            eval(msg.args.code);
+        });
+    }
+
+    oxide.sendMessage("from-cordova", {messageType: "callPluginFunction", plugin: service,
func: action, params: args});
 }
 module.exports = ubuntuExec;
 
@@ -1541,4 +1549,4 @@ window.cordova = require('cordova');
 
 require('cordova/init');
 
-})();
\ No newline at end of file
+})();


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


Mime
View raw message