cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffheif...@apache.org
Subject [22/50] [abbrv] webworks commit: [CB-4563] Migrated blackberry.app parameters to preferences
Date Fri, 27 Sep 2013 14:26:26 GMT
[CB-4563] Migrated blackberry.app parameters to preferences

Reviewed by Bryan Higgins <bhiggins@blackberry.com>


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

Branch: refs/heads/3.1.x
Commit: f60a0cd8d814a2f1143d1262b1a97952c0bdc9a8
Parents: 75b8585
Author: Kristoffer Flores <kflores@blackberry.com>
Authored: Wed Aug 7 13:25:32 2013 -0400
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Mon Aug 26 10:31:22 2013 -0400

----------------------------------------------------------------------
 .../project/cordova/lib/config-parser.js        | 136 +++++++++----------
 blackberry10/bin/test/cordova/unit/config.xml   |  10 +-
 .../test/cordova/unit/spec/lib/config-parser.js |  83 ++++-------
 3 files changed, 94 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/f60a0cd8/blackberry10/bin/templates/project/cordova/lib/config-parser.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/config-parser.js b/blackberry10/bin/templates/project/cordova/lib/config-parser.js
index 65b78a1..7746fd0 100644
--- a/blackberry10/bin/templates/project/cordova/lib/config-parser.js
+++ b/blackberry10/bin/templates/project/cordova/lib/config-parser.js
@@ -26,8 +26,7 @@ var fs = require("fs"),
     utils = require("./packager-utils"),
     i18nMgr = require("./i18n-manager"),
     _self,
-    _predefinedFeatures,
-    _hybridFeatures;
+    _predefinedFeatures;
 
 //This function will convert a wc3 paramObj with a list of
 //<param name="" value=""> elements into a single object
@@ -82,10 +81,6 @@ function processFeatures(featuresArray, widgetConfig, processPredefinedFeatures)
                         _predefinedFeatures[attribs.id](feature, widgetConfig);
                     }
                 } else {
-                    //Handle features that contain both a namespace and custom params
-                    if (_hybridFeatures[attribs.id]) {
-                        _hybridFeatures[attribs.id](feature, widgetConfig);
-                    }
                     features.push(attribs);
                 }
             } else {
@@ -544,9 +539,66 @@ function processNameAndDescription(data, widgetConfig) {
 
 function processCordovaPreferences(data, widgetConfig) {
     if (data.preference) {
-        var preference = processParamObj(data.preference);
-        widgetConfig.packageCordovaJs = preference.packageCordovaJs === "enable";
-        widgetConfig.autoHideSplashScreen = preference.AutoHideSplashScreen !== "false";
+        var preference = JSON.parse(JSON.stringify(processParamObj(data.preference)).toLowerCase());
+        widgetConfig.packageCordovaJs = preference.packagecordovajs === "enable";
+        widgetConfig.autoHideSplashScreen = preference.autohidesplashscreen !== "false";
+
+        // <preference name="backgroundColor" value="hex" />
+        if (preference.backgroundcolor) {
+            widgetConfig.backgroundColor = processBgColor(preference.backgroundcolor);
+        }
+
+        // <preference name="childBrowser" value="enable or disable" />
+        if (preference.childbrowser) {
+            widgetConfig.enableChildWebView = ((preference.childbrowser + '').toLowerCase()
=== 'disable') === false;
+        }
+
+        // <preference name="HideKeyboardFormAccessoryBar" value="enable or disable" />
+        if (preference.hidekeyboardformaccessorybar) {
+            widgetConfig.enableFormControl = ((preference.hidekeyboardformaccessorybar +
'').toLowerCase() === 'enable') === false;
+        }
+
+        // <preference name="popupBlocker" value="enable or disable" />
+        if (preference.popupblocker) {
+            widgetConfig.enablePopupBlocker = ((preference.popupblocker + '').toLowerCase()
=== 'enable') === true;
+        }
+
+        // <preference name="orientation" value="portrait, landscape, north or auto" />
+        if (preference.orientation) {
+            if (preference.orientation ===  "landscape" || preference.orientation === "portrait"
|| preference.orientation === "north") {
+                widgetConfig.autoOrientation = false;
+                widgetConfig.orientation = preference.orientation;
+            } else if (preference.orientation !== "auto") {
+                throw localize.translate("EXCEPTION_INVALID_ORIENTATION_MODE", preference.orientation);
+            }
+        }
+
+        // <preference name="theme" value="bright, dark, inherit or default" />
+        if (preference.theme && (typeof preference.theme === "string")) {
+            preference.theme = preference.theme.toLowerCase();
+            if (preference.theme ===  "bright" || preference.theme === "dark" || preference.theme
=== "inherit" || preference.theme ===  "default") {
+                widgetConfig.theme = preference.theme;
+            }
+        }
+
+        // <preference name="webSecurity" value="enable or disable" />
+        if (preference.websecurity && (typeof preference.websecurity === "string")
&& (preference.websecurity.toLowerCase() === "disable")) {
+            widgetConfig.enableWebSecurity = false;
+            logger.warn(localize.translate("WARNING_WEBSECURITY_DISABLED"));
+        }
+
+    }
+}
+
+function processBgColor(bgColor) {
+    //convert bgColor to a number
+    bgColorNum = parseInt(bgColor, 16);
+
+    if (isNaN(bgColorNum)) {
+        //bgColor is not a number, throw error
+        throw localize.translate("EXCEPTION_BGCOLOR_INVALID", bgColor);
+    } else {
+        return bgColorNum;
     }
 }
 
@@ -604,70 +656,8 @@ function init() {
                 logger.warn(localize.translate("WARNING_ORIENTATION_DEPRECATED"));
             }
         }
-    };
-
-    //Hybrid features are features that have both an API namespace and custom parameters
-    _hybridFeatures = {
-        "blackberry.app": function (feature, widgetConfig) {
-            if (feature) {
-                var params = processParamObj(feature.param),
-                    bgColor = params.backgroundColor,
-                    childBrowser = params.childBrowser,
-                    formControl = params.formControl,
-                    orientation = params.orientation,
-                    theme = params.theme,
-                    popupBlocker = params.popupBlocker,
-                    websecurity = params.websecurity;
-
-                if (bgColor) {
-                    //Convert bgColor to a number
-                    bgColor = parseInt(bgColor, 16);
-
-                    if (isNaN(bgColor)) {
-                        //bgcolor is not a number, throw error
-                        throw localize.translate("EXCEPTION_BGCOLOR_INVALID", params.backgroundColor);
-                    } else {
-                        widgetConfig.backgroundColor = bgColor;
-                    }
-                }
-
-                if (childBrowser) {
-                    widgetConfig.enableChildWebView = ((childBrowser + '').toLowerCase()
=== 'disable') === false;
-                }
-
-                if (formControl) {
-                    widgetConfig.enableFormControl = ((formControl + '').toLowerCase() ===
'disable') === false;
-                }
-
-                if (popupBlocker) {
-                    widgetConfig.enablePopupBlocker = ((popupBlocker + '').toLowerCase()
=== 'enable') === true;
-                }
-
-                if (orientation) {
-                    if (orientation ===  "landscape" || orientation === "portrait" || orientation
=== "north") {
-                        widgetConfig.autoOrientation = false;
-                        widgetConfig.orientation = orientation;
-                    } else if (orientation !== "auto") {
-                        throw localize.translate("EXCEPTION_INVALID_ORIENTATION_MODE", orientation);
-                    }
-                }
-
-                if (theme && (typeof theme === "string")) {
-                    theme = theme.toLowerCase();
-
-                    if (theme ===  "bright" || theme === "dark" || theme === "inherit" ||
theme ===  "default") {
-                        widgetConfig.theme = theme;
-                    }
-                }
-
-                if (websecurity && (typeof websecurity === "string") && (websecurity.toLowerCase()
=== "disable")) {
-                    widgetConfig.enableWebSecurity = false;
-                    logger.warn(localize.translate("WARNING_WEBSECURITY_DISABLED"));
-                }
-            }
-        }
-    };
-}
+    }
+};
 
 _self = {
     parse: function (xmlPath, session, callback) {

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/f60a0cd8/blackberry10/bin/test/cordova/unit/config.xml
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/cordova/unit/config.xml b/blackberry10/bin/test/cordova/unit/config.xml
index 9f42675..f0e76c5 100644
--- a/blackberry10/bin/test/cordova/unit/config.xml
+++ b/blackberry10/bin/test/cordova/unit/config.xml
@@ -22,11 +22,7 @@
         <param name="mode" value="portrait" />
         <param name="other" value="portrait" />
       </feature>
-    <feature id="blackberry.app" required="true" version="1.0.0.0">
-        <param name="childBrowser" value="disable" />
-        <param name="websecurity" value="disable" />
-        <param name="popupBlocker" value="enable" />
-    </feature>
+    <feature id="blackberry.app" required="true" version="1.0.0.0" />
     <feature id="blackberry.system" required="true" version="1.0.0.3"/>
     <access origin="http://www.somedomain1.com" subdomains="true">
         <feature id="blackberry.app" required="true" version="1.0.0.0"/>
@@ -50,4 +46,8 @@
             <property var="exts" value="doc" />
         </filter>
     </rim:invoke-target>
+
+    <preference name="backgroundColor" value="0xffffff" />
+    <preference name="childBrowser" value="disable" />
+    <preference name="HideKeyboardFormAccessoryBar" value="disable" />
 </widget>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/f60a0cd8/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js b/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
index b526b01..d857072 100644
--- a/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
+++ b/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
@@ -50,7 +50,6 @@ describe("config parser", function () {
             expect(configObj.permissions).toContain('read_geolocation');
             expect(configObj.permissions).toContain('use_camera');
             expect(configObj.enableChildWebView).toBe(false);
-            expect(configObj.enableChildWebView).toBe(false);
         });
     });
 
@@ -1106,8 +1105,7 @@ describe("config parser", function () {
 
         it("sets orientation to landscape when specified", function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
-            data['feature'] = { '@': { id: 'blackberry.app', required: true },
-                param: { '@': { name: 'orientation', value: 'landscape' } } };
+            data['preference'] = { '@': { name: 'orientation', value: 'landscape' } };
 
             mockParsing(data);
 
@@ -1119,8 +1117,7 @@ describe("config parser", function () {
 
         it("sets orientation to portrait when specified", function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
-            data['feature'] = { '@': { id: 'blackberry.app', required: true },
-                param: { '@': { name: 'orientation', value: 'portrait' } } };
+            data['preference'] = { '@': { name: 'orientation', value: 'portrait' } };
 
             mockParsing(data);
 
@@ -1132,7 +1129,7 @@ describe("config parser", function () {
 
         it("sets auto orientation to true by default", function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
-            delete data["feature"];//Remove any orientation data
+            delete data['preference'];//Remove any orientation data
 
             mockParsing(data);
 
@@ -1154,21 +1151,18 @@ describe("config parser", function () {
 
         it("throws an error when blackberry.app orientation exists with an invalid mode param",
function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
-            data['feature'] = { '@': { id: 'blackberry.app', required: true },
-                param: { '@': { name: 'orientation', value: 'notAValidMode' } } };
+            data['preference'] = { '@': { name: 'orientation', value: 'notAValidMode' } };
 
             mockParsing(data);
 
-            //Should throw an EXCEPTION_INVALID_ORIENTATION_MODE error
             expect(function () {
                 configParser.parse(configPath, session, function (configObj) {});
-            }).toThrow(localize.translate("EXCEPTION_INVALID_ORIENTATION_MODE", "notAValidMode"));
+            }).toThrow(localize.translate("EXCEPTION_INVALID_ORIENTATION_MODE", "notavalidmode"));
         });
 
-        it("sets backgroundColor when specified via blackberry.app namespace", function ()
{
+        it("sets backgroundColor when specified as a preference", function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
-            data['feature'] = { '@': { id: 'blackberry.app', required: true },
-                param: { '@': { name: 'backgroundColor', value: '0xffffff' } } };
+            data['preference'] = { '@': {name: 'backgroundColor', value: '0xffffff' } };
 
             mockParsing(data);
 
@@ -1177,21 +1171,21 @@ describe("config parser", function () {
             });
         });
 
-        it("throws an error when blackberry.app backgroundColor param is not a number", function
() {
+        it("throws an error backgroundColor preference is not a number", function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
-            data['feature'] = { '@': { id: 'blackberry.app', required: true },
-                param: { '@': { name: 'backgroundColor', value: '$UI*@@$' } } };
+            data['preference'] = { '@': { name: 'backgroundColor', value: '$UI*@@$' } };
 
             mockParsing(data);
 
             //Should throw an EXCEPTION_BGCOLOR_INVALID error
             expect(function () {
                 configParser.parse(configPath, session, {});
-            }).toThrow(localize.translate("EXCEPTION_BGCOLOR_INVALID", "$UI*@@$"));
+            }).toThrow(localize.translate("EXCEPTION_BGCOLOR_INVALID", "$ui*@@$"));
         });
 
         it("can properly parse the custom RIM-Wiget:rim/wiget element", function () {
             var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
             mockParsing(data);
 
             configParser.parse(configPath, session, function (configObj) {
@@ -1235,15 +1229,9 @@ describe("config parser", function () {
         });
 
         describe('disabling childBrowser (childWebView)', function () {
-
-            // { '@': { id: 'blackberry.app', required: true, version: '1.0.0.0' },
-            //   param: { '@': { name: 'childBrowser', value: 'disable' } } }
-
-
             it("sets enableChildWebView to true when childBrowser value is enable", function
() {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data['feature'] = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'childBrowser', value: 'enable' } } };
+                data['preference'] = { '@': { name: 'childBrowser', value: 'enable' } };
 
                 mockParsing(data);
 
@@ -1254,8 +1242,7 @@ describe("config parser", function () {
 
             it("sets enableChildWebView to false when value is disable", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data['feature'] = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'childBrowser', value: 'disable' } } };
+                data['preference'] = { '@': { name: 'childBrowser', value: 'disable' } };
 
                 mockParsing(data);
 
@@ -1266,11 +1253,9 @@ describe("config parser", function () {
         });
 
         describe('disabling formcontrol', function () {
-
-            it("sets enableFormControl to true when formControl value is enable", function
() {
+            it("sets enableFormControl to true when HideKeyboardFormAccessoryBar value is
disable", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data['feature'] = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'formControl', value: 'enable' } } };
+                data['preference'] = { '@': { name: 'HideKeyboardFormAccessoryBar', value:
'disable'  } };
 
                 mockParsing(data);
 
@@ -1279,10 +1264,9 @@ describe("config parser", function () {
                 });
             });
 
-            it("sets enableFormControl to false when value is disable", function () {
+            it("sets enableFormControl to false when value is enable", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data['feature'] = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'formControl', value: 'disable' } } };
+                data['preference'] = { '@': { name: 'HideKeyboardFormAccessoryBar', value:
'enable' } };
 
                 mockParsing(data);
 
@@ -1297,8 +1281,7 @@ describe("config parser", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
 
                 if (themeInConfig) {
-                    data['feature'] = { '@': { id: 'blackberry.app' },
-                        param: { '@': { name: 'theme', value: themeInConfig } } };
+                    data['preference'] = { '@': { name: 'theme', value: themeInConfig } };
 
                     mockParsing(data);
                 }
@@ -1356,15 +1339,9 @@ describe("config parser", function () {
         });
 
         describe('disabling WebSecurity', function () {
-
-            // { '@': { id: 'blackberry.app', required: true, version: '1.0.0.0' },
-            //   param: { '@': { name: 'childBrowser', value: 'disable' } } }
-
-
             it("doesn't set enableWebSecurity to anything when param value is anything but
disable", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data.feature = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'websecurity', value: (new Date()).toString() }
} };
+                data['preference'] = { '@': { name: 'webSecurity', value: (new Date()).toString()
} };
 
                 mockParsing(data);
 
@@ -1376,8 +1353,7 @@ describe("config parser", function () {
 
             it("sets enableWebSecurity to false when value is disable", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data.feature = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'websecurity', value: 'disable' } } };
+                data['preference'] = { '@': { name: 'webSecurity', value: 'disable' } };
 
                 mockParsing(data);
 
@@ -1389,8 +1365,7 @@ describe("config parser", function () {
 
             it("sets enableWebSecurity to false when value is disable case insensitive",
function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data.feature = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'websecurity', value: 'DisAble' } } };
+                data['preference'] = { '@': { name: 'webSecurity', value: 'DisAble' } };
 
                 mockParsing(data);
 
@@ -1402,14 +1377,9 @@ describe("config parser", function () {
         });
 
         describe('enabling popupBlocker', function () {
-
-            // { '@': { id: 'blackberry.app', required: true, version: '1.0.0.0' },
-            //   param: { '@': { name: 'childBrowser', value: 'disable' } } }
-
-            it("sets enableWebSecurity to false when value is disable", function () {
+            it("sets enablePopupBlocker to true when value is enable", function () {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data.feature = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'popupBlocker', value: 'enable' } } };
+                data['preference'] = { '@': { name: 'popupBlocker', value: 'enable' } };
 
                 mockParsing(data);
 
@@ -1418,15 +1388,14 @@ describe("config parser", function () {
                 });
             });
 
-            it("sets enableWebSecurity to false when value is disable case insensitive",
function () {
+            it("sets enablePopBlocker to false when value is disable case insensitive", function
() {
                 var data = testUtilities.cloneObj(testData.xml2jsConfig);
-                data.feature = { '@': { id: 'blackberry.app' },
-                    param: { '@': { name: 'popupBlocker', value: 'EnAbLe' } } };
+                data['preference'] = { '@': { name: 'popupBlocker', value: 'Disable' } };
 
                 mockParsing(data);
 
                 configParser.parse(configPath, session, function (configObj) {
-                    expect(configObj.enablePopupBlocker).toBe(true);
+                    expect(configObj.enablePopupBlocker).toBe(false);
                 });
             });
         });


Mime
View raw message