From 745314e3a3f9f81a1d8652b9774c40d1fb01ba79 Mon Sep 17 00:00:00 2001 From: Gord Tanner Date: Tue, 8 Jan 2013 01:05:32 -0500 Subject: [PATCH] BlackBerry 10 InAppBrowser support - added common InAppBrowser to qnx platform - created InAppBrowser qnx plugin - updated qnx manager to route to InAppBrowser plugin - exported the original window.open in the common InAppBrowser plugin - updated .jshintrc to know about the webworks global to interface with our custom plugin. --- .jshintrc | 2 +- lib/blackberry/plugin/qnx/InAppBrowser.js | 77 +++++++++++++++++++++++ lib/blackberry/plugin/qnx/manager.js | 1 + lib/blackberry/plugin/qnx/platform.js | 5 ++ lib/common/plugin/InAppBrowser.js | 5 +- 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 lib/blackberry/plugin/qnx/InAppBrowser.js diff --git a/.jshintrc b/.jshintrc index 368b58aa6..076a30eaf 100644 --- a/.jshintrc +++ b/.jshintrc @@ -28,7 +28,7 @@ "dojo": false, // Custom predefined globals. - "predef": ["jasmine", "blackberry", "define", "alert", "prompt", "org", "deviceapis", "Osp", "_cordovaExec", "WinJS", "Windows", "MSApp", "PalmSystem", "PalmServiceBridge", "Acceleration"], + "predef": ["jasmine", "blackberry", "define", "alert", "prompt", "org", "deviceapis", "Osp", "_cordovaExec", "WinJS", "Windows", "MSApp", "PalmSystem", "PalmServiceBridge", "Acceleration", "webworks"], // Development diff --git a/lib/blackberry/plugin/qnx/InAppBrowser.js b/lib/blackberry/plugin/qnx/InAppBrowser.js new file mode 100644 index 000000000..0280fe055 --- /dev/null +++ b/lib/blackberry/plugin/qnx/InAppBrowser.js @@ -0,0 +1,77 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +var cordova = require('cordova'), + core = require('cordova/plugin/InAppBrowser'); + +var navigate = { + "_blank": function (url, whitelisted) { + core._orig.apply(null, [url, "_blank"]); + }, + + "_self": function (url, whitelisted) { + if (whitelisted) { + window.location.href = url; + } + else { + core._orig.apply(null, [url, "_blank"]); + } + }, + + "_system": function (url, whitelisted) { + blackberry.invoke.invoke({ + target: "sys.browser", + uri: url + }, function () {}, function () {}); + } +}; + + +module.exports = { + open: function (args, win, fail) { + var url = args[0], + target = args[1] || '_self', + a = document.createElement('a'); + + //Make all URLs absolute + a.href = url; + url = a.href; + + switch (target) { + case '_self': + case '_system': + case '_blank': + break; + default: + target = '_blank'; + break; + } + + webworks.exec(function (whitelisted) { + navigate[target](url, whitelisted); + }, fail, "org.apache.cordova", "isWhitelisted", [url], true); + + return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "" }; + }, + close: function (args, win, fail) { + return { "status" : cordova.callbackStatus.OK, "message" : "" }; + } +}; diff --git a/lib/blackberry/plugin/qnx/manager.js b/lib/blackberry/plugin/qnx/manager.js index ccbefce87..36244f9ce 100644 --- a/lib/blackberry/plugin/qnx/manager.js +++ b/lib/blackberry/plugin/qnx/manager.js @@ -32,6 +32,7 @@ var cordova = require('cordova'), 'Notification' : require('cordova/plugin/webworks/notification'), 'Media': require('cordova/plugin/webworks/media'), 'File' : require('cordova/plugin/qnx/file'), + 'InAppBrowser' : require('cordova/plugin/qnx/InAppBrowser'), 'FileTransfer': require('cordova/plugin/qnx/fileTransfer') }; diff --git a/lib/blackberry/plugin/qnx/platform.js b/lib/blackberry/plugin/qnx/platform.js index 753e9dc66..50ded05bb 100644 --- a/lib/blackberry/plugin/qnx/platform.js +++ b/lib/blackberry/plugin/qnx/platform.js @@ -41,6 +41,11 @@ module.exports = { }); }); }, + clobbers: { + open: { + path: "cordova/plugin/InAppBrowser" + } + }, merges: { navigator: { children: { diff --git a/lib/common/plugin/InAppBrowser.js b/lib/common/plugin/InAppBrowser.js index 9086b8247..9b8bee1db 100644 --- a/lib/common/plugin/InAppBrowser.js +++ b/lib/common/plugin/InAppBrowser.js @@ -58,4 +58,7 @@ module.exports = function(strUrl, strWindowName, strWindowFeatures) { }; exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); return iab; -}; \ No newline at end of file +}; + +//Export the original open so it can be used if needed +module.exports._orig = window.open;