diff options
Diffstat (limited to 'plugins')
262 files changed, 35033 insertions, 0 deletions
diff --git a/plugins/android.json b/plugins/android.json new file mode 100644 index 00000000..d519f004 --- /dev/null +++ b/plugins/android.json @@ -0,0 +1,71 @@ +{ + "prepare_queue": { + "installed": [], + "uninstalled": [] + }, + "config_munge": { + "files": { + "res/xml/config.xml": { + "parents": { + "/*": [ + { + "xml": "<feature name=\"Keyboard\"><param name=\"android-package\" value=\"com.ionic.keyboard.IonicKeyboard\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"Whitelist\"><param name=\"android-package\" value=\"org.apache.cordova.whitelist.WhitelistPlugin\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"Device\"><param name=\"android-package\" value=\"org.apache.cordova.device.Device\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"SplashScreen\"><param name=\"android-package\" value=\"org.apache.cordova.splashscreen.SplashScreen\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"StatusBar\"><param name=\"android-package\" value=\"org.apache.cordova.statusbar.StatusBar\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { + "xml": "<preference name=\"webView\" value=\"org.crosswalk.engine.XWalkWebViewEngine\" />", + "count": 1 + }, + { + "xml": "<feature name=\"InAppBrowser\"><param name=\"android-package\" value=\"org.apache.cordova.inappbrowser.InAppBrowser\" /></feature>", + "count": 1 + } + ] + } + } + } + }, + "installed_plugins": { + "com.ionic.keyboard": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "cordova-plugin-whitelist": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.console": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.device": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.splashscreen": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.statusbar": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "cordova-plugin-crosswalk-webview": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "cordova-plugin-inappbrowser": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + } + }, + "dependent_plugins": {} +}
\ No newline at end of file diff --git a/plugins/com.ionic.keyboard/LICENSE b/plugins/com.ionic.keyboard/LICENSE new file mode 100644 index 00000000..d6f545b8 --- /dev/null +++ b/plugins/com.ionic.keyboard/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014 Drifty Co. + + Licensed 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. diff --git a/plugins/com.ionic.keyboard/README.md b/plugins/com.ionic.keyboard/README.md new file mode 100644 index 00000000..63f70012 --- /dev/null +++ b/plugins/com.ionic.keyboard/README.md @@ -0,0 +1,123 @@ +Keyboard +====== + +The `cordova.plugins.Keyboard` object provides functions to make interacting with the keyboard easier, and fires events to indicate that the keyboard will hide/show. + + cordova plugin add com.ionic.keyboard + +Methods +------- + +- cordova.plugins.Keyboard.hideKeyboardAccessoryBar +- cordova.plugins.Keyboard.close +- cordova.plugins.Keyboard.disableScroll +- cordova.plugins.Keyboard.show + +Properties +-------- + +- cordova.plugins.Keyboard.isVisible + +Events +-------- + +These events are fired on the window. + +- native.keyboardshow + * A number `keyboardHeight` is given on the event object, which is the pixel height of the keyboard. +- native.keyboardhide + +Keyboard.hideKeyboardAccessoryBar +================= + +Hide the keyboard accessory bar with the next, previous and done buttons. + + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false); + +Supported Platforms +------------------- + +- iOS + + +Keyboard.close +================= + +Close the keyboard if it is open. + + cordova.plugins.Keyboard.close(); + +Supported Platforms +------------------- + +- iOS, Android, Blackberry 10 + + +Keyboard.disableScroll +================= + +Disable native scrolling, useful if you are using JavaScript to scroll + + cordova.plugins.Keyboard.disableScroll(true); + cordova.plugins.Keyboard.disableScroll(false); + +Supported Platforms +------------------- + +- iOS + +Keyboard.show +================= + +Force keyboard to be shown on Android. This typically helps if autofocus on a text element does not pop up the keyboard automatically + + cordova.plugins.Keyboard.show(); + +Supported Platforms + +- Android, Blackberry 10 + +native.keyboardshow +================= + +This event fires when the keyboard will be shown + + window.addEventListener('native.keyboardshow', keyboardShowHandler); + + function keyboardShowHandler(e){ + alert('Keyboard height is: ' + e.keyboardHeight); + } + +Properties +----------- + +keyboardHeight: the height of the keyboard in pixels + + +Supported Platforms +------------------- + +- iOS, Android, Blackberry 10 + + +native.keyboardhide +================= + +This event fires when the keyboard will hide + + window.addEventListener('native.keyboardhide', keyboardHideHandler); + + function keyboardHideHandler(e){ + alert('Goodnight, sweet prince'); + } + +Properties +----------- + +None + +Supported Platforms +------------------- + +- iOS, Android, Blackberry 10 diff --git a/plugins/com.ionic.keyboard/package.json b/plugins/com.ionic.keyboard/package.json new file mode 100644 index 00000000..4dd54150 --- /dev/null +++ b/plugins/com.ionic.keyboard/package.json @@ -0,0 +1,19 @@ +{ + "version": "1.0.4", + "name": "com.ionic.keyboard", + "cordova_name": "Keyboard", + "description": "Ionic Keyboard Plugin", + "license": "Apache 2.0", + "repo": "https://github.com/driftyco/ionic-plugins-keyboard.git", + "issue": "https://github.com/driftyco/ionic-plugins-keyboard/issues", + "keywords": [ + "Ionic", + "keyboard" + ], + "platforms": [ + "android", + "ios", + "blackberry10" + ], + "engines": [] +}
\ No newline at end of file diff --git a/plugins/com.ionic.keyboard/plugin.xml b/plugins/com.ionic.keyboard/plugin.xml new file mode 100644 index 00000000..06688915 --- /dev/null +++ b/plugins/com.ionic.keyboard/plugin.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="com.ionic.keyboard" + version="1.0.4"> + <name>Keyboard</name> + <description>Ionic Keyboard Plugin</description> + <license>Apache 2.0</license> + <keywords>Ionic,keyboard</keywords> + <repo>https://github.com/driftyco/ionic-plugins-keyboard.git</repo> + <issue>https://github.com/driftyco/ionic-plugins-keyboard/issues</issue> + + <js-module src="www/keyboard.js" name="keyboard"> + <clobbers target="cordova.plugins.Keyboard" /> + </js-module> + + <!-- android --> + <platform name="android"> + + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="Keyboard"> + <param name="android-package" value="com.ionic.keyboard.IonicKeyboard" /> + <param name="onload" value="true" /> + </feature> + </config-file> + + <source-file src="src/android/IonicKeyboard.java" target-dir="src/com/ionic/keyboard" /> + </platform> + + <!-- ios --> + <platform name="ios"> + <config-file target="config.xml" parent="/*"> + <feature name="Keyboard"> + <param name="ios-package" value="IonicKeyboard" onload="true" /> + </feature> + </config-file> + + <header-file src="src/ios/IonicKeyboard.h" /> + <source-file src="src/ios/IonicKeyboard.m" /> + <header-file src="src/ios/UIWebViewExtension.h" /> + <source-file src="src/ios/UIWebViewExtension.m" /> + </platform> + + <!-- blackberry10 --> + <platform name="blackberry10"> + <source-file src="src/blackberry10/index.js" target-dir='Keyboard' /> + <lib-file src="src/blackberry10/native/device/libKeyboard.so" arch="device"/> + <lib-file src="src/blackberry10/native/simulator/libKeyboard.so" arch="simulator"/> + <config-file target="www/config.xml" parent="/widget"> + <feature name="Keyboard" value="com.ionic.keyboard"/> + + </config-file> + </platform> + +</plugin> diff --git a/plugins/com.ionic.keyboard/src/android/IonicKeyboard.java b/plugins/com.ionic.keyboard/src/android/IonicKeyboard.java new file mode 100644 index 00000000..deb914ab --- /dev/null +++ b/plugins/com.ionic.keyboard/src/android/IonicKeyboard.java @@ -0,0 +1,96 @@ +package com.ionic.keyboard; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaInterface; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.PluginResult.Status; +import org.json.JSONArray; +import org.json.JSONException; + +import android.content.Context; +import android.graphics.Rect; +import android.util.DisplayMetrics; +import android.view.View; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.inputmethod.InputMethodManager; + +public class IonicKeyboard extends CordovaPlugin{ + + public void initialize(CordovaInterface cordova, CordovaWebView webView) { + super.initialize(cordova, webView); + + //calculate density-independent pixels (dp) + //http://developer.android.com/guide/practices/screens_support.html + DisplayMetrics dm = new DisplayMetrics(); + cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + final float density = dm.density; + + final CordovaWebView appView = webView; + + //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing + final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView(); + OnGlobalLayoutListener list = new OnGlobalLayoutListener() { + int previousHeightDiff = 0; + @Override + public void onGlobalLayout() { + Rect r = new Rect(); + //r will be populated with the coordinates of your view that area still visible. + rootView.getWindowVisibleDisplayFrame(r); + + int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top); + int pixelHeightDiff = (int)(heightDiff / density); + if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard... + appView.sendJavascript("cordova.plugins.Keyboard.isVisible = true"); + appView.sendJavascript("cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight':" + Integer.toString(pixelHeightDiff)+"});"); + + //deprecated + appView.sendJavascript("cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight':" + Integer.toString(pixelHeightDiff)+"});"); + } + else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelHeightDiff ) > 100 ){ + appView.sendJavascript("cordova.plugins.Keyboard.isVisible = false"); + appView.sendJavascript("cordova.fireWindowEvent('native.keyboardhide')"); + + //deprecated + appView.sendJavascript("cordova.fireWindowEvent('native.hidekeyboard')"); + } + previousHeightDiff = pixelHeightDiff; + } + }; + + rootView.getViewTreeObserver().addOnGlobalLayoutListener(list); + } + + public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { + if ("close".equals(action)) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + //http://stackoverflow.com/a/7696791/1091751 + InputMethodManager inputManager = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + View v = cordova.getActivity().getCurrentFocus(); + + if (v == null) { + callbackContext.error("No current focus"); + } else { + inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + callbackContext.success(); // Thread-safe. + } + } + }); + return true; + } + if ("show".equals(action)) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + ((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); + callbackContext.success(); // Thread-safe. + } + }); + return true; + } + return false; // Returning false results in a "MethodNotFound" error. + } + + +} + diff --git a/plugins/com.ionic.keyboard/src/blackberry10/index.js b/plugins/com.ionic.keyboard/src/blackberry10/index.js new file mode 100644 index 00000000..40294158 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/index.js @@ -0,0 +1,135 @@ + + +var keyboard, + resultObjs = {}, + threadCallback = null, + _utils = require("../../lib/utils"); + _event = require("../../lib/event"); + _webview = require("../../lib/webview"); + + + + +module.exports = { + + // Code can be declared and used outside the module.exports object, + // but any functions to be called by client.js need to be declared + // here in this object. + + // These methods call into JNEXT.Keyboard which handles the + // communication through the JNEXT plugin to keyboard_js.cpp + startService: function (success, fail, args, env) { + var result = new PluginResult(args, env); + + result.ok(keyboard.getInstance().startService(), false); + }, + show: function (success, fail, args, env) { + var result = new PluginResult(args, env); + + result.ok(keyboard.getInstance().showKeyboard(), false); + }, + close: function (success, fail, args, env) { + var result = new PluginResult(args, env); + + result.ok(keyboard.getInstance().closeKeyboard(), false); + } +}; + +keyboardShow = function(a){ + _webview.executeJavascript("cordova.plugins.Keyboard.isVisible = true"); + _webview.executeJavascript("cordova.fireDocumentEvent('native.keyboardshow',"+a+")"); + +} +keyboardHide = function(){ + _webview.executeJavascript("cordova.plugins.Keyboard.isVisible = false"); + _webview.executeJavascript("cordova.fireDocumentEvent('native.keyboardhide','')"); + +} +onStart = function() { + _webview.executeJavascript("cordova.exec("+null+", "+null+", 'Keyboard', 'startService', '')"); + } + +setTimeout(onStart,2000); + +/////////////////////////////////////////////////////////////////// +// JavaScript wrapper for JNEXT plugin for connection +/////////////////////////////////////////////////////////////////// + +JNEXT.Keyboard = function () { + var self = this, + hasInstance = false; + + self.getId = function () { + return self.m_id; + }; + + self.init = function () { + if (!JNEXT.require("libKeyboard")) { + return false; + } + + self.m_id = JNEXT.createObject("libKeyboard.Keyboard_JS"); + + if (self.m_id === "") { + return false; + } + + JNEXT.registerEvents(self); + }; + + // ************************ + // Enter your methods here + // ************************ + + // calls into InvokeMethod(string command) in keyboard_js.cpp + self.startService = function () { + return JNEXT.invoke(self.m_id, "startService"); + }; + self.showKeyboard = function () { + return JNEXT.invoke(self.m_id, "showKeyboard"); + }; + self.closeKeyboard = function () { + return JNEXT.invoke(self.m_id, "closeKeyboard"); + }; + + self.onEvent = function (strData) { // Fired by the Event framework (used by asynchronous callbacks) + var arData = strData.split(" "), + strEventDesc = arData[0], + jsonData; + + if (strEventDesc === "native.keyboardshow") { + jsonData = arData.slice(1, arData.length).join(" "); + keyboardShow(jsonData); + + } + else if (strEventDesc === "native.keyboardhide") { + keyboardHide(); + } + + }; + + // Thread methods + self.keyboardStartThread = function (callbackId) { + return JNEXT.invoke(self.m_id, "keyboardStartThread " + callbackId); + }; + self.keyboardStopThread = function () { + return JNEXT.invoke(self.m_id, "keyboardStopThread"); + }; + + // ************************ + // End of methods to edit + // ************************ + self.m_id = ""; + + self.getInstance = function () { + if (!hasInstance) { + hasInstance = true; + self.init(); + } + return self; + }; + +}; + +keyboard = new JNEXT.Keyboard(); + diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/.cproject b/plugins/com.ionic.keyboard/src/blackberry10/native/.cproject new file mode 100644 index 00000000..7b118eec --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/.cproject @@ -0,0 +1,222 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="com.qnx.qcc.configuration.sharedLib.release.608922875.1009704567"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.qnx.qcc.configuration.sharedLib.release.608922875.1009704567" moduleId="org.eclipse.cdt.core.settings" name="device"> + <externalSettings> + <externalSetting> + <entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/Cordova-Keyboard"/> + <entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/Cordova-Keyboard/device"/> + <entry flags="RESOLVED" kind="libraryFile" name="Cordova-Keyboard" srcPrefixMapping="" srcRootPath=""/> + </externalSetting> + </externalSettings> + <extensions> + <extension id="com.qnx.tools.ide.qde.core.QDELinkerErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="com.qnx.tools.ide.qde.core.QDEBynaryParser" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactExtension="so" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" description="" id="com.qnx.qcc.configuration.sharedLib.release.608922875.1009704567" name="device" parent="com.qnx.qcc.configuration.sharedLib.release"> + <folderInfo id="com.qnx.qcc.configuration.sharedLib.release.608922875.1009704567." name="/" resourcePath=""> + <toolChain id="com.qnx.qcc.toolChain.2215983" name="QNX QCC" superClass="com.qnx.qcc.toolChain"> + <option id="com.qnx.qcc.option.cpu.315540759" name="Target CPU:" superClass="com.qnx.qcc.option.cpu" value="com.qnx.qcc.option.gen.cpu.armle-v7" valueType="enumerated"/> + <targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.1359109141" osList="all" superClass="com.qnx.qcc.targetPlatform"/> + <builder buildPath="${workspace_loc:/Keyboard/Device-Release}" id="com.qnx.nto.938326560" keepEnvironmentInBuildfile="false" name="CDT Internal Builder" superClass="com.qnx.nto"/> + <tool id="com.qnx.qcc.tool.compiler.242697771" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler"> + <option id="com.qnx.qcc.option.compiler.shared.553244928" name="Shared (-shared)" superClass="com.qnx.qcc.option.compiler.shared" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.compiler.optlevel.2070537906" name="Optimization Level" superClass="com.qnx.qcc.option.compiler.optlevel" value="com.qnx.qcc.option.compiler.optlevel.2" valueType="enumerated"/> + <option id="com.qnx.qcc.option.compiler.includePath.1483355415" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath"> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/qt4/QtCore"/> + <listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/public}"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/qt4"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/> + </option> + <option id="com.qnx.qcc.option.compiler.security.9625963" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.compiler.defines.872099896" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols"> + <listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/> + </option> + <option id="com.qnx.qcc.option.compiler.qccoptions.1015003128" name="QCC Options" superClass="com.qnx.qcc.option.compiler.qccoptions" valueType="stringList"> + <listOptionValue builtIn="false" value="-frecord-gcc-switches"/> + </option> + <inputType id="com.qnx.qcc.inputType.compiler.1443568066" superClass="com.qnx.qcc.inputType.compiler"/> + </tool> + <tool id="com.qnx.qcc.tool.assembler.1996828008" name="QCC Assembler" superClass="com.qnx.qcc.tool.assembler"> + <inputType id="com.qnx.qcc.inputType.assembler.116798417" superClass="com.qnx.qcc.inputType.assembler"/> + </tool> + <tool id="com.qnx.qcc.tool.linker.871546588" name="QCC Linker" superClass="com.qnx.qcc.tool.linker"> + <option id="com.qnx.qcc.option.linker.shared.915102752" name="Shared (-shared)" superClass="com.qnx.qcc.option.linker.shared" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.linker.libraryPaths.1049529253" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths"> + <listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/${CPUVARDIR}/lib"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/${CPUVARDIR}/usr/lib"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/${CPUVARDIR}/usr/lib/qt4/lib"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/${CPUVARDIR}/usr/lib"/> + </option> + <option id="com.qnx.qcc.option.linker.security.1157664997" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.linker.libraries.1316432206" name="Libraries (-l)" superClass="com.qnx.qcc.option.linker.libraries" valueType="libs"> + <listOptionValue builtIn="false" value="slog2"/> + <listOptionValue builtIn="false" value="QtCore"/> + <listOptionValue builtIn="false" value="bb"/> + <listOptionValue builtIn="false" value="bps"/> + </option> + <inputType id="com.qnx.qcc.inputType.linker.1028572887" superClass="com.qnx.qcc.inputType.linker"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="com.qnx.qcc.tool.archiver.1781914947" name="QCC Archiver" superClass="com.qnx.qcc.tool.archiver"/> + </toolChain> + </folderInfo> + <sourceEntries> + <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/> + <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="public"/> + </sourceEntries> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + <cconfiguration id="com.qnx.qcc.configuration.sharedLib.debug.193597202.362186091"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.qnx.qcc.configuration.sharedLib.debug.193597202.362186091" moduleId="org.eclipse.cdt.core.settings" name="simulator"> + <externalSettings> + <externalSetting> + <entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/Cordova-Keyboard"/> + <entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/Cordova-Keyboard/simulator"/> + <entry flags="RESOLVED" kind="libraryFile" name="Cordova-Keyboard" srcPrefixMapping="" srcRootPath=""/> + </externalSetting> + </externalSettings> + <extensions> + <extension id="com.qnx.tools.ide.qde.core.QDELinkerErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="com.qnx.tools.ide.qde.core.QDEBynaryParser" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactExtension="so" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" description="" id="com.qnx.qcc.configuration.sharedLib.debug.193597202.362186091" name="simulator" parent="com.qnx.qcc.configuration.sharedLib.debug"> + <folderInfo id="com.qnx.qcc.configuration.sharedLib.debug.193597202.362186091." name="/" resourcePath=""> + <toolChain id="com.qnx.qcc.toolChain.688026907" name="QNX QCC" superClass="com.qnx.qcc.toolChain"> + <targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.469207190" osList="all" superClass="com.qnx.qcc.targetPlatform"/> + <builder buildPath="${workspace_loc:/Keyboard/Simulator-Debug}" id="com.qnx.nto.2029800497" keepEnvironmentInBuildfile="false" name="CDT Internal Builder" superClass="com.qnx.nto"/> + <tool id="com.qnx.qcc.tool.compiler.1028279123" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler"> + <option id="com.qnx.qcc.option.compiler.shared.235893159" name="Shared (-shared)" superClass="com.qnx.qcc.option.compiler.shared" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.compiler.optlevel.1164238904" name="Optimization Level" superClass="com.qnx.qcc.option.compiler.optlevel" value="com.qnx.qcc.option.compiler.optlevel.0" valueType="enumerated"/> + <option id="com.qnx.qcc.option.compile.debug.3716470" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.compiler.includePath.306305432" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath"> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/qt4/QtCore"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/qt4"/> + <listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/public}"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/> + </option> + <option id="com.qnx.qcc.option.compiler.security.1730007887" name="Enhanced Security (-fstack-protector-strong)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.compiler.defines.1526896965" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols"> + <listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/> + </option> + <inputType id="com.qnx.qcc.inputType.compiler.1881183122" superClass="com.qnx.qcc.inputType.compiler"/> + </tool> + <tool id="com.qnx.qcc.tool.assembler.312168125" name="QCC Assembler" superClass="com.qnx.qcc.tool.assembler"> + <option id="com.qnx.qcc.option.assembler.debug.416544277" name="Debug (-g)" superClass="com.qnx.qcc.option.assembler.debug" value="true" valueType="boolean"/> + <inputType id="com.qnx.qcc.inputType.assembler.1722778407" superClass="com.qnx.qcc.inputType.assembler"/> + </tool> + <tool id="com.qnx.qcc.tool.linker.2130364088" name="QCC Linker" superClass="com.qnx.qcc.tool.linker"> + <option id="com.qnx.qcc.option.linker.debug.1332880614" name="Debug (-g)" superClass="com.qnx.qcc.option.linker.debug" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.linker.shared.1633267255" name="Shared (-shared)" superClass="com.qnx.qcc.option.linker.shared" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.linker.libraryPaths.565794953" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths"> + <listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/${CPUVARDIR}/lib"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/${CPUVARDIR}/usr/lib"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/${CPUVARDIR}/usr/lib/qt4/lib"/> + <listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/${CPUVARDIR}/usr/lib"/> + </option> + <option id="com.qnx.qcc.option.linker.security.9141791" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/> + <option id="com.qnx.qcc.option.linker.libraries.220836649" name="Libraries (-l)" superClass="com.qnx.qcc.option.linker.libraries" valueType="libs"> + <listOptionValue builtIn="false" value="slog2"/> + <listOptionValue builtIn="false" value="QtCore"/> + <listOptionValue builtIn="false" value="bb"/> + <listOptionValue builtIn="false" value="bps"/> + </option> + <inputType id="com.qnx.qcc.inputType.linker.167117375" superClass="com.qnx.qcc.inputType.linker"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="com.qnx.qcc.tool.archiver.489682882" name="QCC Archiver" superClass="com.qnx.qcc.tool.archiver"/> + </toolChain> + </folderInfo> + <sourceEntries> + <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/> + <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="public"/> + </sourceEntries> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="Keyboard.null.138005006" name="Keyboard"/> + </storageModule> + <storageModule moduleId="refreshScope" versionNumber="2"> + <configuration configurationName="Simulator-Profile"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="simulator"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="Simulator-Coverage"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="Device-Profile"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="Device-Debug"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="Simulator-Debug"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="device"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="Device-Release"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + <configuration configurationName="Device-Coverage"> + <resource resourceType="PROJECT" workspacePath="/Keyboard"/> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.profile.941124085"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.coverage.1806890017"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.release.608922875"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.profile.27502649"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.debug.193597202"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.coverage.537092296"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.debug.193597202.362186091"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.release.608922875.1009704567"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="com.qnx.qcc.configuration.sharedLib.debug.1877214659"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/> + </scannerConfigBuildInfo> + </storageModule> +</cproject> diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/.project b/plugins/com.ionic.keyboard/src/blackberry10/native/.project new file mode 100644 index 00000000..8a39f221 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/.project @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Keyboard</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + <dictionary> + <key>?name?</key> + <value></value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.append_environment</key> + <value>true</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.buildArguments</key> + <value></value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.buildCommand</key> + <value>make</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.buildLocation</key> + <value>${workspace_loc:/Keyboard/Device-Release}</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.contents</key> + <value>org.eclipse.cdt.make.core.activeConfigSettings</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.enableAutoBuild</key> + <value>false</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.enableCleanBuild</key> + <value>true</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.enableFullBuild</key> + <value>true</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.stopOnError</key> + <value>true</value> + </dictionary> + <dictionary> + <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key> + <value>true</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.qnx.tools.bbt.xml.core.bbtXMLValidationBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + <nature>com.qnx.tools.ide.bbt.core.bbtnature</nature> + </natures> +</projectDescription> diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_reader.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_reader.o Binary files differnew file mode 100644 index 00000000..6f78251c --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_reader.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_value.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_value.o Binary files differnew file mode 100644 index 00000000..310adeb4 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_value.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_writer.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_writer.o Binary files differnew file mode 100644 index 00000000..b81c56b9 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/json_writer.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/plugin.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/plugin.o Binary files differnew file mode 100644 index 00000000..90f1590d --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/plugin.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/tokenizer.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/tokenizer.o Binary files differnew file mode 100644 index 00000000..4062f5f0 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/public/tokenizer.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/CallKeyboard.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/CallKeyboard.o Binary files differnew file mode 100644 index 00000000..3bb136b6 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/CallKeyboard.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/Logger.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/Logger.o Binary files differnew file mode 100644 index 00000000..f677dc8e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/Logger.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/keyboard_js.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/keyboard_js.o Binary files differnew file mode 100644 index 00000000..6bcd769f --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/keyboard_js.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/keyboard_ndk.o b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/keyboard_ndk.o Binary files differnew file mode 100644 index 00000000..c5bc3b8e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/device/src/keyboard_ndk.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/autolink.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/autolink.h new file mode 100644 index 00000000..37c9258e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/autolink.h @@ -0,0 +1,19 @@ +#ifndef JSON_AUTOLINK_H_INCLUDED +# define JSON_AUTOLINK_H_INCLUDED + +# include "config.h" + +# ifdef JSON_IN_CPPTL +# include <cpptl/cpptl_autolink.h> +# endif + +# if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL) +# define CPPTL_AUTOLINK_NAME "json" +# undef CPPTL_AUTOLINK_DLL +# ifdef JSON_DLL +# define CPPTL_AUTOLINK_DLL +# endif +# include "autolink.h" +# endif + +#endif // JSON_AUTOLINK_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/config.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/config.h new file mode 100644 index 00000000..5d334cbc --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/config.h @@ -0,0 +1,43 @@ +#ifndef JSON_CONFIG_H_INCLUDED +# define JSON_CONFIG_H_INCLUDED + +/// If defined, indicates that json library is embedded in CppTL library. +//# define JSON_IN_CPPTL 1 + +/// If defined, indicates that json may leverage CppTL library +//# define JSON_USE_CPPTL 1 +/// If defined, indicates that cpptl vector based map should be used instead of std::map +/// as Value container. +//# define JSON_USE_CPPTL_SMALLMAP 1 +/// If defined, indicates that Json specific container should be used +/// (hash table & simple deque container with customizable allocator). +/// THIS FEATURE IS STILL EXPERIMENTAL! +//# define JSON_VALUE_USE_INTERNAL_MAP 1 +/// Force usage of standard new/malloc based allocator instead of memory pool based allocator. +/// The memory pools allocator used optimization (initializing Value and ValueInternalLink +/// as if it was a POD) that may cause some validation tool to report errors. +/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined. +//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1 + +/// If defined, indicates that Json use exception to report invalid type manipulation +/// instead of C assert macro. +# define JSON_USE_EXCEPTION 1 + +# ifdef JSON_IN_CPPTL +# include <cpptl/config.h> +# ifndef JSON_USE_CPPTL +# define JSON_USE_CPPTL 1 +# endif +# endif + +# ifdef JSON_IN_CPPTL +# define JSON_API CPPTL_API +# elif defined(JSON_DLL_BUILD) +# define JSON_API __declspec(dllexport) +# elif defined(JSON_DLL) +# define JSON_API __declspec(dllimport) +# else +# define JSON_API +# endif + +#endif // JSON_CONFIG_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/features.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/features.h new file mode 100644 index 00000000..5a9adec1 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/features.h @@ -0,0 +1,42 @@ +#ifndef CPPTL_JSON_FEATURES_H_INCLUDED +# define CPPTL_JSON_FEATURES_H_INCLUDED + +# include "forwards.h" + +namespace Json { + + /** \brief Configuration passed to reader and writer. + * This configuration object can be used to force the Reader or Writer + * to behave in a standard conforming way. + */ + class JSON_API Features + { + public: + /** \brief A configuration that allows all features and assumes all strings are UTF-8. + * - C & C++ comments are allowed + * - Root object can be any JSON value + * - Assumes Value strings are encoded in UTF-8 + */ + static Features all(); + + /** \brief A configuration that is strictly compatible with the JSON specification. + * - Comments are forbidden. + * - Root object must be either an array or an object value. + * - Assumes Value strings are encoded in UTF-8 + */ + static Features strictMode(); + + /** \brief Initialize the configuration like JsonConfig::allFeatures; + */ + Features(); + + /// \c true if comments are allowed. Default: \c true. + bool allowComments_; + + /// \c true if root must be either an array or an object value. Default: \c false. + bool strictRoot_; + }; + +} // namespace Json + +#endif // CPPTL_JSON_FEATURES_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/forwards.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/forwards.h new file mode 100644 index 00000000..d0ce8300 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/forwards.h @@ -0,0 +1,39 @@ +#ifndef JSON_FORWARDS_H_INCLUDED +# define JSON_FORWARDS_H_INCLUDED + +# include "config.h" + +namespace Json { + + // writer.h + class FastWriter; + class StyledWriter; + + // reader.h + class Reader; + + // features.h + class Features; + + // value.h + typedef int Int; + typedef unsigned int UInt; + class StaticString; + class Path; + class PathArgument; + class Value; + class ValueIteratorBase; + class ValueIterator; + class ValueConstIterator; +#ifdef JSON_VALUE_USE_INTERNAL_MAP + class ValueAllocator; + class ValueMapAllocator; + class ValueInternalLink; + class ValueInternalArray; + class ValueInternalMap; +#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP + +} // namespace Json + + +#endif // JSON_FORWARDS_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/json.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/json.h new file mode 100644 index 00000000..c71ed65a --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/json.h @@ -0,0 +1,10 @@ +#ifndef JSON_JSON_H_INCLUDED +# define JSON_JSON_H_INCLUDED + +# include "autolink.h" +# include "value.h" +# include "reader.h" +# include "writer.h" +# include "features.h" + +#endif // JSON_JSON_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/reader.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/reader.h new file mode 100644 index 00000000..ee1d6a24 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/reader.h @@ -0,0 +1,196 @@ +#ifndef CPPTL_JSON_READER_H_INCLUDED +# define CPPTL_JSON_READER_H_INCLUDED + +# include "features.h" +# include "value.h" +# include <deque> +# include <stack> +# include <string> +# include <iostream> + +namespace Json { + + /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value. + * + */ + class JSON_API Reader + { + public: + typedef char Char; + typedef const Char *Location; + + /** \brief Constructs a Reader allowing all features + * for parsing. + */ + Reader(); + + /** \brief Constructs a Reader allowing the specified feature set + * for parsing. + */ + Reader( const Features &features ); + + /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document. + * \param document UTF-8 encoded string containing the document to read. + * \param root [out] Contains the root value of the document if it was + * successfully parsed. + * \param collectComments \c true to collect comment and allow writing them back during + * serialization, \c false to discard comments. + * This parameter is ignored if Features::allowComments_ + * is \c false. + * \return \c true if the document was successfully parsed, \c false if an error occurred. + */ + bool parse( const std::string &document, + Value &root, + bool collectComments = true ); + + /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document. + * \param document UTF-8 encoded string containing the document to read. + * \param root [out] Contains the root value of the document if it was + * successfully parsed. + * \param collectComments \c true to collect comment and allow writing them back during + * serialization, \c false to discard comments. + * This parameter is ignored if Features::allowComments_ + * is \c false. + * \return \c true if the document was successfully parsed, \c false if an error occurred. + */ + bool parse( const char *beginDoc, const char *endDoc, + Value &root, + bool collectComments = true ); + + /// \brief Parse from input stream. + /// \see Json::operator>>(std::istream&, Json::Value&). + bool parse( std::istream &is, + Value &root, + bool collectComments = true ); + + /** \brief Returns a user friendly string that list errors in the parsed document. + * \return Formatted error message with the list of errors with their location in + * the parsed document. An empty string is returned if no error occurred + * during parsing. + */ + std::string getFormatedErrorMessages() const; + + private: + enum TokenType + { + tokenEndOfStream = 0, + tokenObjectBegin, + tokenObjectEnd, + tokenArrayBegin, + tokenArrayEnd, + tokenString, + tokenNumber, + tokenTrue, + tokenFalse, + tokenNull, + tokenArraySeparator, + tokenMemberSeparator, + tokenComment, + tokenError + }; + + class Token + { + public: + TokenType type_; + Location start_; + Location end_; + }; + + class ErrorInfo + { + public: + Token token_; + std::string message_; + Location extra_; + }; + + typedef std::deque<ErrorInfo> Errors; + + bool expectToken( TokenType type, Token &token, const char *message ); + bool readToken( Token &token ); + void skipSpaces(); + bool match( Location pattern, + int patternLength ); + bool readComment(); + bool readCStyleComment(); + bool readCppStyleComment(); + bool readString(); + void readNumber(); + bool readValue(); + bool readObject( Token &token ); + bool readArray( Token &token ); + bool decodeNumber( Token &token ); + bool decodeString( Token &token ); + bool decodeString( Token &token, std::string &decoded ); + bool decodeDouble( Token &token ); + bool decodeUnicodeCodePoint( Token &token, + Location ¤t, + Location end, + unsigned int &unicode ); + bool decodeUnicodeEscapeSequence( Token &token, + Location ¤t, + Location end, + unsigned int &unicode ); + bool addError( const std::string &message, + Token &token, + Location extra = 0 ); + bool recoverFromError( TokenType skipUntilToken ); + bool addErrorAndRecover( const std::string &message, + Token &token, + TokenType skipUntilToken ); + void skipUntilSpace(); + Value ¤tValue(); + Char getNextChar(); + void getLocationLineAndColumn( Location location, + int &line, + int &column ) const; + std::string getLocationLineAndColumn( Location location ) const; + void addComment( Location begin, + Location end, + CommentPlacement placement ); + void skipCommentTokens( Token &token ); + + typedef std::stack<Value *> Nodes; + Nodes nodes_; + Errors errors_; + std::string document_; + Location begin_; + Location end_; + Location current_; + Location lastValueEnd_; + Value *lastValue_; + std::string commentsBefore_; + Features features_; + bool collectComments_; + }; + + /** \brief Read from 'sin' into 'root'. + + Always keep comments from the input JSON. + + This can be used to read a file into a particular sub-object. + For example: + \code + Json::Value root; + cin >> root["dir"]["file"]; + cout << root; + \endcode + Result: + \verbatim + { + "dir": { + "file": { + // The input stream JSON would be nested here. + } + } + } + \endverbatim + \throw std::exception on parse error. + \see Json::operator<<() + */ + std::istream& operator>>( std::istream&, Value& ); + +} // namespace Json + +#endif // CPPTL_JSON_READER_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/value.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/value.h new file mode 100644 index 00000000..58bfd88e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/value.h @@ -0,0 +1,1069 @@ +#ifndef CPPTL_JSON_H_INCLUDED +# define CPPTL_JSON_H_INCLUDED + +# include "forwards.h" +# include <string> +# include <vector> + +# ifndef JSON_USE_CPPTL_SMALLMAP +# include <map> +# else +# include <cpptl/smallmap.h> +# endif +# ifdef JSON_USE_CPPTL +# include <cpptl/forwards.h> +# endif + +/** \brief JSON (JavaScript Object Notation). + */ +namespace Json { + + /** \brief Type of the value held by a Value object. + */ + enum ValueType + { + nullValue = 0, ///< 'null' value + intValue, ///< signed integer value + uintValue, ///< unsigned integer value + realValue, ///< double value + stringValue, ///< UTF-8 string value + booleanValue, ///< bool value + arrayValue, ///< array value (ordered list) + objectValue ///< object value (collection of name/value pairs). + }; + + enum CommentPlacement + { + commentBefore = 0, ///< a comment placed on the line before a value + commentAfterOnSameLine, ///< a comment just after a value on the same line + commentAfter, ///< a comment on the line after a value (only make sense for root value) + numberOfCommentPlacement + }; + +//# ifdef JSON_USE_CPPTL +// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames; +// typedef CppTL::AnyEnumerator<const Value &> EnumValues; +//# endif + + /** \brief Lightweight wrapper to tag static string. + * + * Value constructor and objectValue member assignement takes advantage of the + * StaticString and avoid the cost of string duplication when storing the + * string or the member name. + * + * Example of usage: + * \code + * Json::Value aValue( StaticString("some text") ); + * Json::Value object; + * static const StaticString code("code"); + * object[code] = 1234; + * \endcode + */ + class JSON_API StaticString + { + public: + explicit StaticString( const char *czstring ) + : str_( czstring ) + { + } + + operator const char *() const + { + return str_; + } + + const char *c_str() const + { + return str_; + } + + private: + const char *str_; + }; + + /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value. + * + * This class is a discriminated union wrapper that can represents a: + * - signed integer [range: Value::minInt - Value::maxInt] + * - unsigned integer (range: 0 - Value::maxUInt) + * - double + * - UTF-8 string + * - boolean + * - 'null' + * - an ordered list of Value + * - collection of name/value pairs (javascript object) + * + * The type of the held value is represented by a #ValueType and + * can be obtained using type(). + * + * values of an #objectValue or #arrayValue can be accessed using operator[]() methods. + * Non const methods will automatically create the a #nullValue element + * if it does not exist. + * The sequence of an #arrayValue will be automatically resize and initialized + * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. + * + * The get() methods can be used to obtanis default value in the case the required element + * does not exist. + * + * It is possible to iterate over the list of a #objectValue values using + * the getMemberNames() method. + */ + class JSON_API Value + { + friend class ValueIteratorBase; +# ifdef JSON_VALUE_USE_INTERNAL_MAP + friend class ValueInternalLink; + friend class ValueInternalMap; +# endif + public: + typedef std::vector<std::string> Members; + typedef ValueIterator iterator; + typedef ValueConstIterator const_iterator; + typedef Json::UInt UInt; + typedef Json::Int Int; + typedef UInt ArrayIndex; + + static const Value null; + static const Int minInt; + static const Int maxInt; + static const UInt maxUInt; + + private: +#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION +# ifndef JSON_VALUE_USE_INTERNAL_MAP + class CZString + { + public: + enum DuplicationPolicy + { + noDuplication = 0, + duplicate, + duplicateOnCopy + }; + CZString( int index ); + CZString( const char *cstr, DuplicationPolicy allocate ); + CZString( const CZString &other ); + ~CZString(); + CZString &operator =( const CZString &other ); + bool operator<( const CZString &other ) const; + bool operator==( const CZString &other ) const; + int index() const; + const char *c_str() const; + bool isStaticString() const; + private: + void swap( CZString &other ); + const char *cstr_; + int index_; + }; + + public: +# ifndef JSON_USE_CPPTL_SMALLMAP + typedef std::map<CZString, Value> ObjectValues; +# else + typedef CppTL::SmallMap<CZString, Value> ObjectValues; +# endif // ifndef JSON_USE_CPPTL_SMALLMAP +# endif // ifndef JSON_VALUE_USE_INTERNAL_MAP +#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + + public: + /** \brief Create a default Value of the given type. + + This is a very useful constructor. + To create an empty array, pass arrayValue. + To create an empty object, pass objectValue. + Another Value can then be set to this one by assignment. + This is useful since clear() and resize() will not alter types. + + Examples: + \code + Json::Value null_value; // null + Json::Value arr_value(Json::arrayValue); // [] + Json::Value obj_value(Json::objectValue); // {} + \endcode + */ + Value( ValueType type = nullValue ); + Value( Int value ); + Value( UInt value ); + Value( double value ); + Value( const char *value ); + Value( const char *beginValue, const char *endValue ); + /** \brief Constructs a value from a static string. + + * Like other value string constructor but do not duplicate the string for + * internal storage. The given string must remain alive after the call to this + * constructor. + * Example of usage: + * \code + * Json::Value aValue( StaticString("some text") ); + * \endcode + */ + Value( const StaticString &value ); + Value( const std::string &value ); +# ifdef JSON_USE_CPPTL + Value( const CppTL::ConstString &value ); +# endif + Value( bool value ); + Value( const Value &other ); + ~Value(); + + Value &operator=( const Value &other ); + /// Swap values. + /// \note Currently, comments are intentionally not swapped, for + /// both logic and efficiency. + void swap( Value &other ); + + ValueType type() const; + + bool operator <( const Value &other ) const; + bool operator <=( const Value &other ) const; + bool operator >=( const Value &other ) const; + bool operator >( const Value &other ) const; + + bool operator ==( const Value &other ) const; + bool operator !=( const Value &other ) const; + + int compare( const Value &other ); + + const char *asCString() const; + std::string asString() const; +# ifdef JSON_USE_CPPTL + CppTL::ConstString asConstString() const; +# endif + Int asInt() const; + UInt asUInt() const; + double asDouble() const; + bool asBool() const; + + bool isNull() const; + bool isBool() const; + bool isInt() const; + bool isUInt() const; + bool isIntegral() const; + bool isDouble() const; + bool isNumeric() const; + bool isString() const; + bool isArray() const; + bool isObject() const; + + bool isConvertibleTo( ValueType other ) const; + + /// Number of values in array or object + UInt size() const; + + /// \brief Return true if empty array, empty object, or null; + /// otherwise, false. + bool empty() const; + + /// Return isNull() + bool operator!() const; + + /// Remove all object members and array elements. + /// \pre type() is arrayValue, objectValue, or nullValue + /// \post type() is unchanged + void clear(); + + /// Resize the array to size elements. + /// New elements are initialized to null. + /// May only be called on nullValue or arrayValue. + /// \pre type() is arrayValue or nullValue + /// \post type() is arrayValue + void resize( UInt size ); + + /// Access an array element (zero based index ). + /// If the array contains less than index element, then null value are inserted + /// in the array so that its size is index+1. + /// (You may need to say 'value[0u]' to get your compiler to distinguish + /// this from the operator[] which takes a string.) + Value &operator[]( UInt index ); + /// Access an array element (zero based index ) + /// (You may need to say 'value[0u]' to get your compiler to distinguish + /// this from the operator[] which takes a string.) + const Value &operator[]( UInt index ) const; + /// If the array contains at least index+1 elements, returns the element value, + /// otherwise returns defaultValue. + Value get( UInt index, + const Value &defaultValue ) const; + /// Return true if index < size(). + bool isValidIndex( UInt index ) const; + /// \brief Append value to array at the end. + /// + /// Equivalent to jsonvalue[jsonvalue.size()] = value; + Value &append( const Value &value ); + + /// Access an object value by name, create a null member if it does not exist. + Value &operator[]( const char *key ); + /// Access an object value by name, returns null if there is no member with that name. + const Value &operator[]( const char *key ) const; + /// Access an object value by name, create a null member if it does not exist. + Value &operator[]( const std::string &key ); + /// Access an object value by name, returns null if there is no member with that name. + const Value &operator[]( const std::string &key ) const; + /** \brief Access an object value by name, create a null member if it does not exist. + + * If the object as no entry for that name, then the member name used to store + * the new entry is not duplicated. + * Example of use: + * \code + * Json::Value object; + * static const StaticString code("code"); + * object[code] = 1234; + * \endcode + */ + Value &operator[]( const StaticString &key ); +# ifdef JSON_USE_CPPTL + /// Access an object value by name, create a null member if it does not exist. + Value &operator[]( const CppTL::ConstString &key ); + /// Access an object value by name, returns null if there is no member with that name. + const Value &operator[]( const CppTL::ConstString &key ) const; +# endif + /// Return the member named key if it exist, defaultValue otherwise. + Value get( const char *key, + const Value &defaultValue ) const; + /// Return the member named key if it exist, defaultValue otherwise. + Value get( const std::string &key, + const Value &defaultValue ) const; +# ifdef JSON_USE_CPPTL + /// Return the member named key if it exist, defaultValue otherwise. + Value get( const CppTL::ConstString &key, + const Value &defaultValue ) const; +# endif + /// \brief Remove and return the named member. + /// + /// Do nothing if it did not exist. + /// \return the removed Value, or null. + /// \pre type() is objectValue or nullValue + /// \post type() is unchanged + Value removeMember( const char* key ); + /// Same as removeMember(const char*) + Value removeMember( const std::string &key ); + + /// Return true if the object has a member named key. + bool isMember( const char *key ) const; + /// Return true if the object has a member named key. + bool isMember( const std::string &key ) const; +# ifdef JSON_USE_CPPTL + /// Return true if the object has a member named key. + bool isMember( const CppTL::ConstString &key ) const; +# endif + + /// \brief Return a list of the member names. + /// + /// If null, return an empty list. + /// \pre type() is objectValue or nullValue + /// \post if type() was nullValue, it remains nullValue + Members getMemberNames() const; + +//# ifdef JSON_USE_CPPTL +// EnumMemberNames enumMemberNames() const; +// EnumValues enumValues() const; +//# endif + + /// Comments must be //... or /* ... */ + void setComment( const char *comment, + CommentPlacement placement ); + /// Comments must be //... or /* ... */ + void setComment( const std::string &comment, + CommentPlacement placement ); + bool hasComment( CommentPlacement placement ) const; + /// Include delimiters and embedded newlines. + std::string getComment( CommentPlacement placement ) const; + + std::string toStyledString() const; + + const_iterator begin() const; + const_iterator end() const; + + iterator begin(); + iterator end(); + + private: + Value &resolveReference( const char *key, + bool isStatic ); + +# ifdef JSON_VALUE_USE_INTERNAL_MAP + inline bool isItemAvailable() const + { + return itemIsUsed_ == 0; + } + + inline void setItemUsed( bool isUsed = true ) + { + itemIsUsed_ = isUsed ? 1 : 0; + } + + inline bool isMemberNameStatic() const + { + return memberNameIsStatic_ == 0; + } + + inline void setMemberNameIsStatic( bool isStatic ) + { + memberNameIsStatic_ = isStatic ? 1 : 0; + } +# endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP + + private: + struct CommentInfo + { + CommentInfo(); + ~CommentInfo(); + + void setComment( const char *text ); + + char *comment_; + }; + + //struct MemberNamesTransform + //{ + // typedef const char *result_type; + // const char *operator()( const CZString &name ) const + // { + // return name.c_str(); + // } + //}; + + union ValueHolder + { + Int int_; + UInt uint_; + double real_; + bool bool_; + char *string_; +# ifdef JSON_VALUE_USE_INTERNAL_MAP + ValueInternalArray *array_; + ValueInternalMap *map_; +#else + ObjectValues *map_; +# endif + } value_; + ValueType type_ : 8; + int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. +# ifdef JSON_VALUE_USE_INTERNAL_MAP + unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container. + int memberNameIsStatic_ : 1; // used by the ValueInternalMap container. +# endif + CommentInfo *comments_; + }; + + + /** \brief Experimental and untested: represents an element of the "path" to access a node. + */ + class PathArgument + { + public: + friend class Path; + + PathArgument(); + PathArgument( UInt index ); + PathArgument( const char *key ); + PathArgument( const std::string &key ); + + private: + enum Kind + { + kindNone = 0, + kindIndex, + kindKey + }; + std::string key_; + UInt index_; + Kind kind_; + }; + + /** \brief Experimental and untested: represents a "path" to access a node. + * + * Syntax: + * - "." => root node + * - ".[n]" => elements at index 'n' of root node (an array value) + * - ".name" => member named 'name' of root node (an object value) + * - ".name1.name2.name3" + * - ".[0][1][2].name1[3]" + * - ".%" => member name is provided as parameter + * - ".[%]" => index is provied as parameter + */ + class Path + { + public: + Path( const std::string &path, + const PathArgument &a1 = PathArgument(), + const PathArgument &a2 = PathArgument(), + const PathArgument &a3 = PathArgument(), + const PathArgument &a4 = PathArgument(), + const PathArgument &a5 = PathArgument() ); + + const Value &resolve( const Value &root ) const; + Value resolve( const Value &root, + const Value &defaultValue ) const; + /// Creates the "path" to access the specified node and returns a reference on the node. + Value &make( Value &root ) const; + + private: + typedef std::vector<const PathArgument *> InArgs; + typedef std::vector<PathArgument> Args; + + void makePath( const std::string &path, + const InArgs &in ); + void addPathInArg( const std::string &path, + const InArgs &in, + InArgs::const_iterator &itInArg, + PathArgument::Kind kind ); + void invalidPath( const std::string &path, + int location ); + + Args args_; + }; + + /** \brief Experimental do not use: Allocator to customize member name and string value memory management done by Value. + * + * - makeMemberName() and releaseMemberName() are called to respectively duplicate and + * free an Json::objectValue member name. + * - duplicateStringValue() and releaseStringValue() are called similarly to + * duplicate and free a Json::stringValue value. + */ + class ValueAllocator + { + public: + enum { unknown = (unsigned)-1 }; + + virtual ~ValueAllocator(); + + virtual char *makeMemberName( const char *memberName ) = 0; + virtual void releaseMemberName( char *memberName ) = 0; + virtual char *duplicateStringValue( const char *value, + unsigned int length = unknown ) = 0; + virtual void releaseStringValue( char *value ) = 0; + }; + +#ifdef JSON_VALUE_USE_INTERNAL_MAP + /** \brief Allocator to customize Value internal map. + * Below is an example of a simple implementation (default implementation actually + * use memory pool for speed). + * \code + class DefaultValueMapAllocator : public ValueMapAllocator + { + public: // overridden from ValueMapAllocator + virtual ValueInternalMap *newMap() + { + return new ValueInternalMap(); + } + + virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) + { + return new ValueInternalMap( other ); + } + + virtual void destructMap( ValueInternalMap *map ) + { + delete map; + } + + virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) + { + return new ValueInternalLink[size]; + } + + virtual void releaseMapBuckets( ValueInternalLink *links ) + { + delete [] links; + } + + virtual ValueInternalLink *allocateMapLink() + { + return new ValueInternalLink(); + } + + virtual void releaseMapLink( ValueInternalLink *link ) + { + delete link; + } + }; + * \endcode + */ + class JSON_API ValueMapAllocator + { + public: + virtual ~ValueMapAllocator(); + virtual ValueInternalMap *newMap() = 0; + virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0; + virtual void destructMap( ValueInternalMap *map ) = 0; + virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0; + virtual void releaseMapBuckets( ValueInternalLink *links ) = 0; + virtual ValueInternalLink *allocateMapLink() = 0; + virtual void releaseMapLink( ValueInternalLink *link ) = 0; + }; + + /** \brief ValueInternalMap hash-map bucket chain link (for internal use only). + * \internal previous_ & next_ allows for bidirectional traversal. + */ + class JSON_API ValueInternalLink + { + public: + enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture. + enum InternalFlags { + flagAvailable = 0, + flagUsed = 1 + }; + + ValueInternalLink(); + + ~ValueInternalLink(); + + Value items_[itemPerLink]; + char *keys_[itemPerLink]; + ValueInternalLink *previous_; + ValueInternalLink *next_; + }; + + + /** \brief A linked page based hash-table implementation used internally by Value. + * \internal ValueInternalMap is a tradional bucket based hash-table, with a linked + * list in each bucket to handle collision. There is an addional twist in that + * each node of the collision linked list is a page containing a fixed amount of + * value. This provides a better compromise between memory usage and speed. + * + * Each bucket is made up of a chained list of ValueInternalLink. The last + * link of a given bucket can be found in the 'previous_' field of the following bucket. + * The last link of the last bucket is stored in tailLink_ as it has no following bucket. + * Only the last link of a bucket may contains 'available' item. The last link always + * contains at least one element unless is it the bucket one very first link. + */ + class JSON_API ValueInternalMap + { + friend class ValueIteratorBase; + friend class Value; + public: + typedef unsigned int HashKey; + typedef unsigned int BucketIndex; + +# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + struct IteratorState + { + IteratorState() + : map_(0) + , link_(0) + , itemIndex_(0) + , bucketIndex_(0) + { + } + ValueInternalMap *map_; + ValueInternalLink *link_; + BucketIndex itemIndex_; + BucketIndex bucketIndex_; + }; +# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + + ValueInternalMap(); + ValueInternalMap( const ValueInternalMap &other ); + ValueInternalMap &operator =( const ValueInternalMap &other ); + ~ValueInternalMap(); + + void swap( ValueInternalMap &other ); + + BucketIndex size() const; + + void clear(); + + bool reserveDelta( BucketIndex growth ); + + bool reserve( BucketIndex newItemCount ); + + const Value *find( const char *key ) const; + + Value *find( const char *key ); + + Value &resolveReference( const char *key, + bool isStatic ); + + void remove( const char *key ); + + void doActualRemove( ValueInternalLink *link, + BucketIndex index, + BucketIndex bucketIndex ); + + ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex ); + + Value &setNewItem( const char *key, + bool isStatic, + ValueInternalLink *link, + BucketIndex index ); + + Value &unsafeAdd( const char *key, + bool isStatic, + HashKey hashedKey ); + + HashKey hash( const char *key ) const; + + int compare( const ValueInternalMap &other ) const; + + private: + void makeBeginIterator( IteratorState &it ) const; + void makeEndIterator( IteratorState &it ) const; + static bool equals( const IteratorState &x, const IteratorState &other ); + static void increment( IteratorState &iterator ); + static void incrementBucket( IteratorState &iterator ); + static void decrement( IteratorState &iterator ); + static const char *key( const IteratorState &iterator ); + static const char *key( const IteratorState &iterator, bool &isStatic ); + static Value &value( const IteratorState &iterator ); + static int distance( const IteratorState &x, const IteratorState &y ); + + private: + ValueInternalLink *buckets_; + ValueInternalLink *tailLink_; + BucketIndex bucketsSize_; + BucketIndex itemCount_; + }; + + /** \brief A simplified deque implementation used internally by Value. + * \internal + * It is based on a list of fixed "page", each page contains a fixed number of items. + * Instead of using a linked-list, a array of pointer is used for fast item look-up. + * Look-up for an element is as follow: + * - compute page index: pageIndex = itemIndex / itemsPerPage + * - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage] + * + * Insertion is amortized constant time (only the array containing the index of pointers + * need to be reallocated when items are appended). + */ + class JSON_API ValueInternalArray + { + friend class Value; + friend class ValueIteratorBase; + public: + enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo. + typedef Value::ArrayIndex ArrayIndex; + typedef unsigned int PageIndex; + +# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + struct IteratorState // Must be a POD + { + IteratorState() + : array_(0) + , currentPageIndex_(0) + , currentItemIndex_(0) + { + } + ValueInternalArray *array_; + Value **currentPageIndex_; + unsigned int currentItemIndex_; + }; +# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + + ValueInternalArray(); + ValueInternalArray( const ValueInternalArray &other ); + ValueInternalArray &operator =( const ValueInternalArray &other ); + ~ValueInternalArray(); + void swap( ValueInternalArray &other ); + + void clear(); + void resize( ArrayIndex newSize ); + + Value &resolveReference( ArrayIndex index ); + + Value *find( ArrayIndex index ) const; + + ArrayIndex size() const; + + int compare( const ValueInternalArray &other ) const; + + private: + static bool equals( const IteratorState &x, const IteratorState &other ); + static void increment( IteratorState &iterator ); + static void decrement( IteratorState &iterator ); + static Value &dereference( const IteratorState &iterator ); + static Value &unsafeDereference( const IteratorState &iterator ); + static int distance( const IteratorState &x, const IteratorState &y ); + static ArrayIndex indexOf( const IteratorState &iterator ); + void makeBeginIterator( IteratorState &it ) const; + void makeEndIterator( IteratorState &it ) const; + void makeIterator( IteratorState &it, ArrayIndex index ) const; + + void makeIndexValid( ArrayIndex index ); + + Value **pages_; + ArrayIndex size_; + PageIndex pageCount_; + }; + + /** \brief Experimental: do not use. Allocator to customize Value internal array. + * Below is an example of a simple implementation (actual implementation use + * memory pool). + \code +class DefaultValueArrayAllocator : public ValueArrayAllocator +{ +public: // overridden from ValueArrayAllocator + virtual ~DefaultValueArrayAllocator() + { + } + + virtual ValueInternalArray *newArray() + { + return new ValueInternalArray(); + } + + virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) + { + return new ValueInternalArray( other ); + } + + virtual void destruct( ValueInternalArray *array ) + { + delete array; + } + + virtual void reallocateArrayPageIndex( Value **&indexes, + ValueInternalArray::PageIndex &indexCount, + ValueInternalArray::PageIndex minNewIndexCount ) + { + ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; + if ( minNewIndexCount > newIndexCount ) + newIndexCount = minNewIndexCount; + void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); + if ( !newIndexes ) + throw std::bad_alloc(); + indexCount = newIndexCount; + indexes = static_cast<Value **>( newIndexes ); + } + virtual void releaseArrayPageIndex( Value **indexes, + ValueInternalArray::PageIndex indexCount ) + { + if ( indexes ) + free( indexes ); + } + + virtual Value *allocateArrayPage() + { + return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) ); + } + + virtual void releaseArrayPage( Value *value ) + { + if ( value ) + free( value ); + } +}; + \endcode + */ + class JSON_API ValueArrayAllocator + { + public: + virtual ~ValueArrayAllocator(); + virtual ValueInternalArray *newArray() = 0; + virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0; + virtual void destructArray( ValueInternalArray *array ) = 0; + /** \brief Reallocate array page index. + * Reallocates an array of pointer on each page. + * \param indexes [input] pointer on the current index. May be \c NULL. + * [output] pointer on the new index of at least + * \a minNewIndexCount pages. + * \param indexCount [input] current number of pages in the index. + * [output] number of page the reallocated index can handle. + * \b MUST be >= \a minNewIndexCount. + * \param minNewIndexCount Minimum number of page the new index must be able to + * handle. + */ + virtual void reallocateArrayPageIndex( Value **&indexes, + ValueInternalArray::PageIndex &indexCount, + ValueInternalArray::PageIndex minNewIndexCount ) = 0; + virtual void releaseArrayPageIndex( Value **indexes, + ValueInternalArray::PageIndex indexCount ) = 0; + virtual Value *allocateArrayPage() = 0; + virtual void releaseArrayPage( Value *value ) = 0; + }; +#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP + + + /** \brief base class for Value iterators. + * + */ + class ValueIteratorBase + { + public: + typedef unsigned int size_t; + typedef int difference_type; + typedef ValueIteratorBase SelfType; + + ValueIteratorBase(); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t ); +#else + ValueIteratorBase( const ValueInternalArray::IteratorState &state ); + ValueIteratorBase( const ValueInternalMap::IteratorState &state ); +#endif + + bool operator ==( const SelfType &other ) const + { + return isEqual( other ); + } + + bool operator !=( const SelfType &other ) const + { + return !isEqual( other ); + } + + difference_type operator -( const SelfType &other ) const + { + return computeDistance( other ); + } + + /// Return either the index or the member name of the referenced value as a Value. + Value key() const; + + /// Return the index of the referenced Value. -1 if it is not an arrayValue. + UInt index() const; + + /// Return the member name of the referenced Value. "" if it is not an objectValue. + const char *memberName() const; + + protected: + Value &deref() const; + + void increment(); + + void decrement(); + + difference_type computeDistance( const SelfType &other ) const; + + bool isEqual( const SelfType &other ) const; + + void copy( const SelfType &other ); + + private: +#ifndef JSON_VALUE_USE_INTERNAL_MAP + Value::ObjectValues::iterator current_; + // Indicates that iterator is for a null value. + bool isNull_; +#else + union + { + ValueInternalArray::IteratorState array_; + ValueInternalMap::IteratorState map_; + } iterator_; + bool isArray_; +#endif + }; + + /** \brief const iterator for object and array value. + * + */ + class ValueConstIterator : public ValueIteratorBase + { + friend class Value; + public: + typedef unsigned int size_t; + typedef int difference_type; + typedef const Value &reference; + typedef const Value *pointer; + typedef ValueConstIterator SelfType; + + ValueConstIterator(); + private: + /*! \internal Use by Value to create an iterator. + */ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t ); +#else + ValueConstIterator( const ValueInternalArray::IteratorState &state ); + ValueConstIterator( const ValueInternalMap::IteratorState &state ); +#endif + public: + SelfType &operator =( const ValueIteratorBase &other ); + + SelfType operator++( int ) + { + SelfType temp( *this ); + ++*this; + return temp; + } + + SelfType operator--( int ) + { + SelfType temp( *this ); + --*this; + return temp; + } + + SelfType &operator--() + { + decrement(); + return *this; + } + + SelfType &operator++() + { + increment(); + return *this; + } + + reference operator *() const + { + return deref(); + } + }; + + + /** \brief Iterator for object and array value. + */ + class ValueIterator : public ValueIteratorBase + { + friend class Value; + public: + typedef unsigned int size_t; + typedef int difference_type; + typedef Value &reference; + typedef Value *pointer; + typedef ValueIterator SelfType; + + ValueIterator(); + ValueIterator( const ValueConstIterator &other ); + ValueIterator( const ValueIterator &other ); + private: + /*! \internal Use by Value to create an iterator. + */ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + explicit ValueIterator( const Value::ObjectValues::iterator ¤t ); +#else + ValueIterator( const ValueInternalArray::IteratorState &state ); + ValueIterator( const ValueInternalMap::IteratorState &state ); +#endif + public: + + SelfType &operator =( const SelfType &other ); + + SelfType operator++( int ) + { + SelfType temp( *this ); + ++*this; + return temp; + } + + SelfType operator--( int ) + { + SelfType temp( *this ); + --*this; + return temp; + } + + SelfType &operator--() + { + decrement(); + return *this; + } + + SelfType &operator++() + { + increment(); + return *this; + } + + reference operator *() const + { + return deref(); + } + }; + + +} // namespace Json + + +#endif // CPPTL_JSON_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/writer.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/writer.h new file mode 100644 index 00000000..5f4b83be --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json/writer.h @@ -0,0 +1,174 @@ +#ifndef JSON_WRITER_H_INCLUDED +# define JSON_WRITER_H_INCLUDED + +# include "value.h" +# include <vector> +# include <string> +# include <iostream> + +namespace Json { + + class Value; + + /** \brief Abstract class for writers. + */ + class JSON_API Writer + { + public: + virtual ~Writer(); + + virtual std::string write( const Value &root ) = 0; + }; + + /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly). + * + * The JSON document is written in a single line. It is not intended for 'human' consumption, + * but may be usefull to support feature such as RPC where bandwith is limited. + * \sa Reader, Value + */ + class JSON_API FastWriter : public Writer + { + public: + FastWriter(); + virtual ~FastWriter(){} + + void enableYAMLCompatibility(); + + public: // overridden from Writer + virtual std::string write( const Value &root ); + + private: + void writeValue( const Value &value ); + + std::string document_; + bool yamlCompatiblityEnabled_; + }; + + /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way. + * + * The rules for line break and indent are as follow: + * - Object value: + * - if empty then print {} without indent and line break + * - if not empty the print '{', line break & indent, print one value per line + * and then unindent and line break and print '}'. + * - Array value: + * - if empty then print [] without indent and line break + * - if the array contains no object value, empty array or some other value types, + * and all the values fit on one lines, then print the array on a single line. + * - otherwise, it the values do not fit on one line, or the array contains + * object or non empty array, then print one value per line. + * + * If the Value have comments then they are outputed according to their #CommentPlacement. + * + * \sa Reader, Value, Value::setComment() + */ + class JSON_API StyledWriter: public Writer + { + public: + StyledWriter(); + virtual ~StyledWriter(){} + + public: // overridden from Writer + /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format. + * \param root Value to serialize. + * \return String containing the JSON document that represents the root value. + */ + virtual std::string write( const Value &root ); + + private: + void writeValue( const Value &value ); + void writeArrayValue( const Value &value ); + bool isMultineArray( const Value &value ); + void pushValue( const std::string &value ); + void writeIndent(); + void writeWithIndent( const std::string &value ); + void indent(); + void unindent(); + void writeCommentBeforeValue( const Value &root ); + void writeCommentAfterValueOnSameLine( const Value &root ); + bool hasCommentForValue( const Value &value ); + static std::string normalizeEOL( const std::string &text ); + + typedef std::vector<std::string> ChildValues; + + ChildValues childValues_; + std::string document_; + std::string indentString_; + int rightMargin_; + int indentSize_; + bool addChildValues_; + }; + + /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way, + to a stream rather than to a string. + * + * The rules for line break and indent are as follow: + * - Object value: + * - if empty then print {} without indent and line break + * - if not empty the print '{', line break & indent, print one value per line + * and then unindent and line break and print '}'. + * - Array value: + * - if empty then print [] without indent and line break + * - if the array contains no object value, empty array or some other value types, + * and all the values fit on one lines, then print the array on a single line. + * - otherwise, it the values do not fit on one line, or the array contains + * object or non empty array, then print one value per line. + * + * If the Value have comments then they are outputed according to their #CommentPlacement. + * + * \param indentation Each level will be indented by this amount extra. + * \sa Reader, Value, Value::setComment() + */ + class JSON_API StyledStreamWriter + { + public: + StyledStreamWriter( std::string indentation="\t" ); + ~StyledStreamWriter(){} + + public: + /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format. + * \param out Stream to write to. (Can be ostringstream, e.g.) + * \param root Value to serialize. + * \note There is no point in deriving from Writer, since write() should not return a value. + */ + void write( std::ostream &out, const Value &root ); + + private: + void writeValue( const Value &value ); + void writeArrayValue( const Value &value ); + bool isMultineArray( const Value &value ); + void pushValue( const std::string &value ); + void writeIndent(); + void writeWithIndent( const std::string &value ); + void indent(); + void unindent(); + void writeCommentBeforeValue( const Value &root ); + void writeCommentAfterValueOnSameLine( const Value &root ); + bool hasCommentForValue( const Value &value ); + static std::string normalizeEOL( const std::string &text ); + + typedef std::vector<std::string> ChildValues; + + ChildValues childValues_; + std::ostream* document_; + std::string indentString_; + int rightMargin_; + std::string indentation_; + bool addChildValues_; + }; + + std::string JSON_API valueToString( Int value ); + std::string JSON_API valueToString( UInt value ); + std::string JSON_API valueToString( double value ); + std::string JSON_API valueToString( bool value ); + std::string JSON_API valueToQuotedString( const char *value ); + + /// \brief Output using the StyledStreamWriter. + /// \see Json::operator>>() + std::ostream& operator<<( std::ostream&, const Value &root ); + +} // namespace Json + + + +#endif // JSON_WRITER_H_INCLUDED diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_batchallocator.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_batchallocator.h new file mode 100644 index 00000000..87ea5ed8 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_batchallocator.h @@ -0,0 +1,125 @@ +#ifndef JSONCPP_BATCHALLOCATOR_H_INCLUDED +# define JSONCPP_BATCHALLOCATOR_H_INCLUDED + +# include <stdlib.h> +# include <assert.h> + +# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + +namespace Json { + +/* Fast memory allocator. + * + * This memory allocator allocates memory for a batch of object (specified by + * the page size, the number of object in each page). + * + * It does not allow the destruction of a single object. All the allocated objects + * can be destroyed at once. The memory can be either released or reused for future + * allocation. + * + * The in-place new operator must be used to construct the object using the pointer + * returned by allocate. + */ +template<typename AllocatedType + ,const unsigned int objectPerAllocation> +class BatchAllocator +{ +public: + typedef AllocatedType Type; + + BatchAllocator( unsigned int objectsPerPage = 255 ) + : freeHead_( 0 ) + , objectsPerPage_( objectsPerPage ) + { +// printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() ); + assert( sizeof(AllocatedType) * objectPerAllocation >= sizeof(AllocatedType *) ); // We must be able to store a slist in the object free space. + assert( objectsPerPage >= 16 ); + batches_ = allocateBatch( 0 ); // allocated a dummy page + currentBatch_ = batches_; + } + + ~BatchAllocator() + { + for ( BatchInfo *batch = batches_; batch; ) + { + BatchInfo *nextBatch = batch->next_; + free( batch ); + batch = nextBatch; + } + } + + /// allocate space for an array of objectPerAllocation object. + /// @warning it is the responsability of the caller to call objects constructors. + AllocatedType *allocate() + { + if ( freeHead_ ) // returns node from free list. + { + AllocatedType *object = freeHead_; + freeHead_ = *(AllocatedType **)object; + return object; + } + if ( currentBatch_->used_ == currentBatch_->end_ ) + { + currentBatch_ = currentBatch_->next_; + while ( currentBatch_ && currentBatch_->used_ == currentBatch_->end_ ) + currentBatch_ = currentBatch_->next_; + + if ( !currentBatch_ ) // no free batch found, allocate a new one + { + currentBatch_ = allocateBatch( objectsPerPage_ ); + currentBatch_->next_ = batches_; // insert at the head of the list + batches_ = currentBatch_; + } + } + AllocatedType *allocated = currentBatch_->used_; + currentBatch_->used_ += objectPerAllocation; + return allocated; + } + + /// Release the object. + /// @warning it is the responsability of the caller to actually destruct the object. + void release( AllocatedType *object ) + { + assert( object != 0 ); + *(AllocatedType **)object = freeHead_; + freeHead_ = object; + } + +private: + struct BatchInfo + { + BatchInfo *next_; + AllocatedType *used_; + AllocatedType *end_; + AllocatedType buffer_[objectPerAllocation]; + }; + + // disabled copy constructor and assignement operator. + BatchAllocator( const BatchAllocator & ); + void operator =( const BatchAllocator &); + + static BatchInfo *allocateBatch( unsigned int objectsPerPage ) + { + const unsigned int mallocSize = sizeof(BatchInfo) - sizeof(AllocatedType)* objectPerAllocation + + sizeof(AllocatedType) * objectPerAllocation * objectsPerPage; + BatchInfo *batch = static_cast<BatchInfo*>( malloc( mallocSize ) ); + batch->next_ = 0; + batch->used_ = batch->buffer_; + batch->end_ = batch->buffer_ + objectsPerPage; + return batch; + } + + BatchInfo *batches_; + BatchInfo *currentBatch_; + /// Head of a single linked list within the allocated space of freeed object + AllocatedType *freeHead_; + unsigned int objectsPerPage_; +}; + + +} // namespace Json + +# endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION + +#endif // JSONCPP_BATCHALLOCATOR_H_INCLUDED + diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_internalarray.inl b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_internalarray.inl new file mode 100644 index 00000000..9b985d25 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_internalarray.inl @@ -0,0 +1,448 @@ +// included by json_value.cpp +// everything is within Json namespace + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueInternalArray +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueArrayAllocator::~ValueArrayAllocator() +{ +} + +// ////////////////////////////////////////////////////////////////// +// class DefaultValueArrayAllocator +// ////////////////////////////////////////////////////////////////// +#ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR +class DefaultValueArrayAllocator : public ValueArrayAllocator +{ +public: // overridden from ValueArrayAllocator + virtual ~DefaultValueArrayAllocator() + { + } + + virtual ValueInternalArray *newArray() + { + return new ValueInternalArray(); + } + + virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) + { + return new ValueInternalArray( other ); + } + + virtual void destructArray( ValueInternalArray *array ) + { + delete array; + } + + virtual void reallocateArrayPageIndex( Value **&indexes, + ValueInternalArray::PageIndex &indexCount, + ValueInternalArray::PageIndex minNewIndexCount ) + { + ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; + if ( minNewIndexCount > newIndexCount ) + newIndexCount = minNewIndexCount; + void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); + if ( !newIndexes ) + throw std::bad_alloc(); + indexCount = newIndexCount; + indexes = static_cast<Value **>( newIndexes ); + } + virtual void releaseArrayPageIndex( Value **indexes, + ValueInternalArray::PageIndex indexCount ) + { + if ( indexes ) + free( indexes ); + } + + virtual Value *allocateArrayPage() + { + return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) ); + } + + virtual void releaseArrayPage( Value *value ) + { + if ( value ) + free( value ); + } +}; + +#else // #ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR +/// @todo make this thread-safe (lock when accessign batch allocator) +class DefaultValueArrayAllocator : public ValueArrayAllocator +{ +public: // overridden from ValueArrayAllocator + virtual ~DefaultValueArrayAllocator() + { + } + + virtual ValueInternalArray *newArray() + { + ValueInternalArray *array = arraysAllocator_.allocate(); + new (array) ValueInternalArray(); // placement new + return array; + } + + virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) + { + ValueInternalArray *array = arraysAllocator_.allocate(); + new (array) ValueInternalArray( other ); // placement new + return array; + } + + virtual void destructArray( ValueInternalArray *array ) + { + if ( array ) + { + array->~ValueInternalArray(); + arraysAllocator_.release( array ); + } + } + + virtual void reallocateArrayPageIndex( Value **&indexes, + ValueInternalArray::PageIndex &indexCount, + ValueInternalArray::PageIndex minNewIndexCount ) + { + ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; + if ( minNewIndexCount > newIndexCount ) + newIndexCount = minNewIndexCount; + void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); + if ( !newIndexes ) + throw std::bad_alloc(); + indexCount = newIndexCount; + indexes = static_cast<Value **>( newIndexes ); + } + virtual void releaseArrayPageIndex( Value **indexes, + ValueInternalArray::PageIndex indexCount ) + { + if ( indexes ) + free( indexes ); + } + + virtual Value *allocateArrayPage() + { + return static_cast<Value *>( pagesAllocator_.allocate() ); + } + + virtual void releaseArrayPage( Value *value ) + { + if ( value ) + pagesAllocator_.release( value ); + } +private: + BatchAllocator<ValueInternalArray,1> arraysAllocator_; + BatchAllocator<Value,ValueInternalArray::itemsPerPage> pagesAllocator_; +}; +#endif // #ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR + +static ValueArrayAllocator *&arrayAllocator() +{ + static DefaultValueArrayAllocator defaultAllocator; + static ValueArrayAllocator *arrayAllocator = &defaultAllocator; + return arrayAllocator; +} + +static struct DummyArrayAllocatorInitializer { + DummyArrayAllocatorInitializer() + { + arrayAllocator(); // ensure arrayAllocator() statics are initialized before main(). + } +} dummyArrayAllocatorInitializer; + +// ////////////////////////////////////////////////////////////////// +// class ValueInternalArray +// ////////////////////////////////////////////////////////////////// +bool +ValueInternalArray::equals( const IteratorState &x, + const IteratorState &other ) +{ + return x.array_ == other.array_ + && x.currentItemIndex_ == other.currentItemIndex_ + && x.currentPageIndex_ == other.currentPageIndex_; +} + + +void +ValueInternalArray::increment( IteratorState &it ) +{ + JSON_ASSERT_MESSAGE( it.array_ && + (it.currentPageIndex_ - it.array_->pages_)*itemsPerPage + it.currentItemIndex_ + != it.array_->size_, + "ValueInternalArray::increment(): moving iterator beyond end" ); + ++(it.currentItemIndex_); + if ( it.currentItemIndex_ == itemsPerPage ) + { + it.currentItemIndex_ = 0; + ++(it.currentPageIndex_); + } +} + + +void +ValueInternalArray::decrement( IteratorState &it ) +{ + JSON_ASSERT_MESSAGE( it.array_ && it.currentPageIndex_ == it.array_->pages_ + && it.currentItemIndex_ == 0, + "ValueInternalArray::decrement(): moving iterator beyond end" ); + if ( it.currentItemIndex_ == 0 ) + { + it.currentItemIndex_ = itemsPerPage-1; + --(it.currentPageIndex_); + } + else + { + --(it.currentItemIndex_); + } +} + + +Value & +ValueInternalArray::unsafeDereference( const IteratorState &it ) +{ + return (*(it.currentPageIndex_))[it.currentItemIndex_]; +} + + +Value & +ValueInternalArray::dereference( const IteratorState &it ) +{ + JSON_ASSERT_MESSAGE( it.array_ && + (it.currentPageIndex_ - it.array_->pages_)*itemsPerPage + it.currentItemIndex_ + < it.array_->size_, + "ValueInternalArray::dereference(): dereferencing invalid iterator" ); + return unsafeDereference( it ); +} + +void +ValueInternalArray::makeBeginIterator( IteratorState &it ) const +{ + it.array_ = const_cast<ValueInternalArray *>( this ); + it.currentItemIndex_ = 0; + it.currentPageIndex_ = pages_; +} + + +void +ValueInternalArray::makeIterator( IteratorState &it, ArrayIndex index ) const +{ + it.array_ = const_cast<ValueInternalArray *>( this ); + it.currentItemIndex_ = index % itemsPerPage; + it.currentPageIndex_ = pages_ + index / itemsPerPage; +} + + +void +ValueInternalArray::makeEndIterator( IteratorState &it ) const +{ + makeIterator( it, size_ ); +} + + +ValueInternalArray::ValueInternalArray() + : pages_( 0 ) + , size_( 0 ) + , pageCount_( 0 ) +{ +} + + +ValueInternalArray::ValueInternalArray( const ValueInternalArray &other ) + : pages_( 0 ) + , pageCount_( 0 ) + , size_( other.size_ ) +{ + PageIndex minNewPages = other.size_ / itemsPerPage; + arrayAllocator()->reallocateArrayPageIndex( pages_, pageCount_, minNewPages ); + JSON_ASSERT_MESSAGE( pageCount_ >= minNewPages, + "ValueInternalArray::reserve(): bad reallocation" ); + IteratorState itOther; + other.makeBeginIterator( itOther ); + Value *value; + for ( ArrayIndex index = 0; index < size_; ++index, increment(itOther) ) + { + if ( index % itemsPerPage == 0 ) + { + PageIndex pageIndex = index / itemsPerPage; + value = arrayAllocator()->allocateArrayPage(); + pages_[pageIndex] = value; + } + new (value) Value( dereference( itOther ) ); + } +} + + +ValueInternalArray & +ValueInternalArray::operator =( const ValueInternalArray &other ) +{ + ValueInternalArray temp( other ); + swap( temp ); + return *this; +} + + +ValueInternalArray::~ValueInternalArray() +{ + // destroy all constructed items + IteratorState it; + IteratorState itEnd; + makeBeginIterator( it); + makeEndIterator( itEnd ); + for ( ; !equals(it,itEnd); increment(it) ) + { + Value *value = &dereference(it); + value->~Value(); + } + // release all pages + PageIndex lastPageIndex = size_ / itemsPerPage; + for ( PageIndex pageIndex = 0; pageIndex < lastPageIndex; ++pageIndex ) + arrayAllocator()->releaseArrayPage( pages_[pageIndex] ); + // release pages index + arrayAllocator()->releaseArrayPageIndex( pages_, pageCount_ ); +} + + +void +ValueInternalArray::swap( ValueInternalArray &other ) +{ + Value **tempPages = pages_; + pages_ = other.pages_; + other.pages_ = tempPages; + ArrayIndex tempSize = size_; + size_ = other.size_; + other.size_ = tempSize; + PageIndex tempPageCount = pageCount_; + pageCount_ = other.pageCount_; + other.pageCount_ = tempPageCount; +} + +void +ValueInternalArray::clear() +{ + ValueInternalArray dummy; + swap( dummy ); +} + + +void +ValueInternalArray::resize( ArrayIndex newSize ) +{ + if ( newSize == 0 ) + clear(); + else if ( newSize < size_ ) + { + IteratorState it; + IteratorState itEnd; + makeIterator( it, newSize ); + makeIterator( itEnd, size_ ); + for ( ; !equals(it,itEnd); increment(it) ) + { + Value *value = &dereference(it); + value->~Value(); + } + PageIndex pageIndex = (newSize + itemsPerPage - 1) / itemsPerPage; + PageIndex lastPageIndex = size_ / itemsPerPage; + for ( ; pageIndex < lastPageIndex; ++pageIndex ) + arrayAllocator()->releaseArrayPage( pages_[pageIndex] ); + size_ = newSize; + } + else if ( newSize > size_ ) + resolveReference( newSize ); +} + + +void +ValueInternalArray::makeIndexValid( ArrayIndex index ) +{ + // Need to enlarge page index ? + if ( index >= pageCount_ * itemsPerPage ) + { + PageIndex minNewPages = (index + 1) / itemsPerPage; + arrayAllocator()->reallocateArrayPageIndex( pages_, pageCount_, minNewPages ); + JSON_ASSERT_MESSAGE( pageCount_ >= minNewPages, "ValueInternalArray::reserve(): bad reallocation" ); + } + + // Need to allocate new pages ? + ArrayIndex nextPageIndex = + (size_ % itemsPerPage) != 0 ? size_ - (size_%itemsPerPage) + itemsPerPage + : size_; + if ( nextPageIndex <= index ) + { + PageIndex pageIndex = nextPageIndex / itemsPerPage; + PageIndex pageToAllocate = (index - nextPageIndex) / itemsPerPage + 1; + for ( ; pageToAllocate-- > 0; ++pageIndex ) + pages_[pageIndex] = arrayAllocator()->allocateArrayPage(); + } + + // Initialize all new entries + IteratorState it; + IteratorState itEnd; + makeIterator( it, size_ ); + size_ = index + 1; + makeIterator( itEnd, size_ ); + for ( ; !equals(it,itEnd); increment(it) ) + { + Value *value = &dereference(it); + new (value) Value(); // Construct a default value using placement new + } +} + +Value & +ValueInternalArray::resolveReference( ArrayIndex index ) +{ + if ( index >= size_ ) + makeIndexValid( index ); + return pages_[index/itemsPerPage][index%itemsPerPage]; +} + +Value * +ValueInternalArray::find( ArrayIndex index ) const +{ + if ( index >= size_ ) + return 0; + return &(pages_[index/itemsPerPage][index%itemsPerPage]); +} + +ValueInternalArray::ArrayIndex +ValueInternalArray::size() const +{ + return size_; +} + +int +ValueInternalArray::distance( const IteratorState &x, const IteratorState &y ) +{ + return indexOf(y) - indexOf(x); +} + + +ValueInternalArray::ArrayIndex +ValueInternalArray::indexOf( const IteratorState &iterator ) +{ + if ( !iterator.array_ ) + return ArrayIndex(-1); + return ArrayIndex( + (iterator.currentPageIndex_ - iterator.array_->pages_) * itemsPerPage + + iterator.currentItemIndex_ ); +} + + +int +ValueInternalArray::compare( const ValueInternalArray &other ) const +{ + int sizeDiff( size_ - other.size_ ); + if ( sizeDiff != 0 ) + return sizeDiff; + + for ( ArrayIndex index =0; index < size_; ++index ) + { + int diff = pages_[index/itemsPerPage][index%itemsPerPage].compare( + other.pages_[index/itemsPerPage][index%itemsPerPage] ); + if ( diff != 0 ) + return diff; + } + return 0; +} diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_internalmap.inl b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_internalmap.inl new file mode 100644 index 00000000..19771488 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_internalmap.inl @@ -0,0 +1,607 @@ +// included by json_value.cpp +// everything is within Json namespace + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueInternalMap +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +/** \internal MUST be safely initialized using memset( this, 0, sizeof(ValueInternalLink) ); + * This optimization is used by the fast allocator. + */ +ValueInternalLink::ValueInternalLink() + : previous_( 0 ) + , next_( 0 ) +{ +} + +ValueInternalLink::~ValueInternalLink() +{ + for ( int index =0; index < itemPerLink; ++index ) + { + if ( !items_[index].isItemAvailable() ) + { + if ( !items_[index].isMemberNameStatic() ) + free( keys_[index] ); + } + else + break; + } +} + + + +ValueMapAllocator::~ValueMapAllocator() +{ +} + +#ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR +class DefaultValueMapAllocator : public ValueMapAllocator +{ +public: // overridden from ValueMapAllocator + virtual ValueInternalMap *newMap() + { + return new ValueInternalMap(); + } + + virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) + { + return new ValueInternalMap( other ); + } + + virtual void destructMap( ValueInternalMap *map ) + { + delete map; + } + + virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) + { + return new ValueInternalLink[size]; + } + + virtual void releaseMapBuckets( ValueInternalLink *links ) + { + delete [] links; + } + + virtual ValueInternalLink *allocateMapLink() + { + return new ValueInternalLink(); + } + + virtual void releaseMapLink( ValueInternalLink *link ) + { + delete link; + } +}; +#else +/// @todo make this thread-safe (lock when accessign batch allocator) +class DefaultValueMapAllocator : public ValueMapAllocator +{ +public: // overridden from ValueMapAllocator + virtual ValueInternalMap *newMap() + { + ValueInternalMap *map = mapsAllocator_.allocate(); + new (map) ValueInternalMap(); // placement new + return map; + } + + virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) + { + ValueInternalMap *map = mapsAllocator_.allocate(); + new (map) ValueInternalMap( other ); // placement new + return map; + } + + virtual void destructMap( ValueInternalMap *map ) + { + if ( map ) + { + map->~ValueInternalMap(); + mapsAllocator_.release( map ); + } + } + + virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) + { + return new ValueInternalLink[size]; + } + + virtual void releaseMapBuckets( ValueInternalLink *links ) + { + delete [] links; + } + + virtual ValueInternalLink *allocateMapLink() + { + ValueInternalLink *link = linksAllocator_.allocate(); + memset( link, 0, sizeof(ValueInternalLink) ); + return link; + } + + virtual void releaseMapLink( ValueInternalLink *link ) + { + link->~ValueInternalLink(); + linksAllocator_.release( link ); + } +private: + BatchAllocator<ValueInternalMap,1> mapsAllocator_; + BatchAllocator<ValueInternalLink,1> linksAllocator_; +}; +#endif + +static ValueMapAllocator *&mapAllocator() +{ + static DefaultValueMapAllocator defaultAllocator; + static ValueMapAllocator *mapAllocator = &defaultAllocator; + return mapAllocator; +} + +static struct DummyMapAllocatorInitializer { + DummyMapAllocatorInitializer() + { + mapAllocator(); // ensure mapAllocator() statics are initialized before main(). + } +} dummyMapAllocatorInitializer; + + + +// h(K) = value * K >> w ; with w = 32 & K prime w.r.t. 2^32. + +/* +use linked list hash map. +buckets array is a container. +linked list element contains 6 key/values. (memory = (16+4) * 6 + 4 = 124) +value have extra state: valid, available, deleted +*/ + + +ValueInternalMap::ValueInternalMap() + : buckets_( 0 ) + , tailLink_( 0 ) + , bucketsSize_( 0 ) + , itemCount_( 0 ) +{ +} + + +ValueInternalMap::ValueInternalMap( const ValueInternalMap &other ) + : buckets_( 0 ) + , tailLink_( 0 ) + , bucketsSize_( 0 ) + , itemCount_( 0 ) +{ + reserve( other.itemCount_ ); + IteratorState it; + IteratorState itEnd; + other.makeBeginIterator( it ); + other.makeEndIterator( itEnd ); + for ( ; !equals(it,itEnd); increment(it) ) + { + bool isStatic; + const char *memberName = key( it, isStatic ); + const Value &aValue = value( it ); + resolveReference(memberName, isStatic) = aValue; + } +} + + +ValueInternalMap & +ValueInternalMap::operator =( const ValueInternalMap &other ) +{ + ValueInternalMap dummy( other ); + swap( dummy ); + return *this; +} + + +ValueInternalMap::~ValueInternalMap() +{ + if ( buckets_ ) + { + for ( BucketIndex bucketIndex =0; bucketIndex < bucketsSize_; ++bucketIndex ) + { + ValueInternalLink *link = buckets_[bucketIndex].next_; + while ( link ) + { + ValueInternalLink *linkToRelease = link; + link = link->next_; + mapAllocator()->releaseMapLink( linkToRelease ); + } + } + mapAllocator()->releaseMapBuckets( buckets_ ); + } +} + + +void +ValueInternalMap::swap( ValueInternalMap &other ) +{ + ValueInternalLink *tempBuckets = buckets_; + buckets_ = other.buckets_; + other.buckets_ = tempBuckets; + ValueInternalLink *tempTailLink = tailLink_; + tailLink_ = other.tailLink_; + other.tailLink_ = tempTailLink; + BucketIndex tempBucketsSize = bucketsSize_; + bucketsSize_ = other.bucketsSize_; + other.bucketsSize_ = tempBucketsSize; + BucketIndex tempItemCount = itemCount_; + itemCount_ = other.itemCount_; + other.itemCount_ = tempItemCount; +} + + +void +ValueInternalMap::clear() +{ + ValueInternalMap dummy; + swap( dummy ); +} + + +ValueInternalMap::BucketIndex +ValueInternalMap::size() const +{ + return itemCount_; +} + +bool +ValueInternalMap::reserveDelta( BucketIndex growth ) +{ + return reserve( itemCount_ + growth ); +} + +bool +ValueInternalMap::reserve( BucketIndex newItemCount ) +{ + if ( !buckets_ && newItemCount > 0 ) + { + buckets_ = mapAllocator()->allocateMapBuckets( 1 ); + bucketsSize_ = 1; + tailLink_ = &buckets_[0]; + } +// BucketIndex idealBucketCount = (newItemCount + ValueInternalLink::itemPerLink) / ValueInternalLink::itemPerLink; + return true; +} + + +const Value * +ValueInternalMap::find( const char *key ) const +{ + if ( !bucketsSize_ ) + return 0; + HashKey hashedKey = hash( key ); + BucketIndex bucketIndex = hashedKey % bucketsSize_; + for ( const ValueInternalLink *current = &buckets_[bucketIndex]; + current != 0; + current = current->next_ ) + { + for ( BucketIndex index=0; index < ValueInternalLink::itemPerLink; ++index ) + { + if ( current->items_[index].isItemAvailable() ) + return 0; + if ( strcmp( key, current->keys_[index] ) == 0 ) + return ¤t->items_[index]; + } + } + return 0; +} + + +Value * +ValueInternalMap::find( const char *key ) +{ + const ValueInternalMap *constThis = this; + return const_cast<Value *>( constThis->find( key ) ); +} + + +Value & +ValueInternalMap::resolveReference( const char *key, + bool isStatic ) +{ + HashKey hashedKey = hash( key ); + if ( bucketsSize_ ) + { + BucketIndex bucketIndex = hashedKey % bucketsSize_; + ValueInternalLink **previous = 0; + BucketIndex index; + for ( ValueInternalLink *current = &buckets_[bucketIndex]; + current != 0; + previous = ¤t->next_, current = current->next_ ) + { + for ( index=0; index < ValueInternalLink::itemPerLink; ++index ) + { + if ( current->items_[index].isItemAvailable() ) + return setNewItem( key, isStatic, current, index ); + if ( strcmp( key, current->keys_[index] ) == 0 ) + return current->items_[index]; + } + } + } + + reserveDelta( 1 ); + return unsafeAdd( key, isStatic, hashedKey ); +} + + +void +ValueInternalMap::remove( const char *key ) +{ + HashKey hashedKey = hash( key ); + if ( !bucketsSize_ ) + return; + BucketIndex bucketIndex = hashedKey % bucketsSize_; + for ( ValueInternalLink *link = &buckets_[bucketIndex]; + link != 0; + link = link->next_ ) + { + BucketIndex index; + for ( index =0; index < ValueInternalLink::itemPerLink; ++index ) + { + if ( link->items_[index].isItemAvailable() ) + return; + if ( strcmp( key, link->keys_[index] ) == 0 ) + { + doActualRemove( link, index, bucketIndex ); + return; + } + } + } +} + +void +ValueInternalMap::doActualRemove( ValueInternalLink *link, + BucketIndex index, + BucketIndex bucketIndex ) +{ + // find last item of the bucket and swap it with the 'removed' one. + // set removed items flags to 'available'. + // if last page only contains 'available' items, then desallocate it (it's empty) + ValueInternalLink *&lastLink = getLastLinkInBucket( index ); + BucketIndex lastItemIndex = 1; // a link can never be empty, so start at 1 + for ( ; + lastItemIndex < ValueInternalLink::itemPerLink; + ++lastItemIndex ) // may be optimized with dicotomic search + { + if ( lastLink->items_[lastItemIndex].isItemAvailable() ) + break; + } + + BucketIndex lastUsedIndex = lastItemIndex - 1; + Value *valueToDelete = &link->items_[index]; + Value *valueToPreserve = &lastLink->items_[lastUsedIndex]; + if ( valueToDelete != valueToPreserve ) + valueToDelete->swap( *valueToPreserve ); + if ( lastUsedIndex == 0 ) // page is now empty + { // remove it from bucket linked list and delete it. + ValueInternalLink *linkPreviousToLast = lastLink->previous_; + if ( linkPreviousToLast != 0 ) // can not deleted bucket link. + { + mapAllocator()->releaseMapLink( lastLink ); + linkPreviousToLast->next_ = 0; + lastLink = linkPreviousToLast; + } + } + else + { + Value dummy; + valueToPreserve->swap( dummy ); // restore deleted to default Value. + valueToPreserve->setItemUsed( false ); + } + --itemCount_; +} + + +ValueInternalLink *& +ValueInternalMap::getLastLinkInBucket( BucketIndex bucketIndex ) +{ + if ( bucketIndex == bucketsSize_ - 1 ) + return tailLink_; + ValueInternalLink *&previous = buckets_[bucketIndex+1].previous_; + if ( !previous ) + previous = &buckets_[bucketIndex]; + return previous; +} + + +Value & +ValueInternalMap::setNewItem( const char *key, + bool isStatic, + ValueInternalLink *link, + BucketIndex index ) +{ + char *duplicatedKey = valueAllocator()->makeMemberName( key ); + ++itemCount_; + link->keys_[index] = duplicatedKey; + link->items_[index].setItemUsed(); + link->items_[index].setMemberNameIsStatic( isStatic ); + return link->items_[index]; // items already default constructed. +} + + +Value & +ValueInternalMap::unsafeAdd( const char *key, + bool isStatic, + HashKey hashedKey ) +{ + JSON_ASSERT_MESSAGE( bucketsSize_ > 0, "ValueInternalMap::unsafeAdd(): internal logic error." ); + BucketIndex bucketIndex = hashedKey % bucketsSize_; + ValueInternalLink *&previousLink = getLastLinkInBucket( bucketIndex ); + ValueInternalLink *link = previousLink; + BucketIndex index; + for ( index =0; index < ValueInternalLink::itemPerLink; ++index ) + { + if ( link->items_[index].isItemAvailable() ) + break; + } + if ( index == ValueInternalLink::itemPerLink ) // need to add a new page + { + ValueInternalLink *newLink = mapAllocator()->allocateMapLink(); + index = 0; + link->next_ = newLink; + previousLink = newLink; + link = newLink; + } + return setNewItem( key, isStatic, link, index ); +} + + +ValueInternalMap::HashKey +ValueInternalMap::hash( const char *key ) const +{ + HashKey hash = 0; + while ( *key ) + hash += *key++ * 37; + return hash; +} + + +int +ValueInternalMap::compare( const ValueInternalMap &other ) const +{ + int sizeDiff( itemCount_ - other.itemCount_ ); + if ( sizeDiff != 0 ) + return sizeDiff; + // Strict order guaranty is required. Compare all keys FIRST, then compare values. + IteratorState it; + IteratorState itEnd; + makeBeginIterator( it ); + makeEndIterator( itEnd ); + for ( ; !equals(it,itEnd); increment(it) ) + { + if ( !other.find( key( it ) ) ) + return 1; + } + + // All keys are equals, let's compare values + makeBeginIterator( it ); + for ( ; !equals(it,itEnd); increment(it) ) + { + const Value *otherValue = other.find( key( it ) ); + int valueDiff = value(it).compare( *otherValue ); + if ( valueDiff != 0 ) + return valueDiff; + } + return 0; +} + + +void +ValueInternalMap::makeBeginIterator( IteratorState &it ) const +{ + it.map_ = const_cast<ValueInternalMap *>( this ); + it.bucketIndex_ = 0; + it.itemIndex_ = 0; + it.link_ = buckets_; +} + + +void +ValueInternalMap::makeEndIterator( IteratorState &it ) const +{ + it.map_ = const_cast<ValueInternalMap *>( this ); + it.bucketIndex_ = bucketsSize_; + it.itemIndex_ = 0; + it.link_ = 0; +} + + +bool +ValueInternalMap::equals( const IteratorState &x, const IteratorState &other ) +{ + return x.map_ == other.map_ + && x.bucketIndex_ == other.bucketIndex_ + && x.link_ == other.link_ + && x.itemIndex_ == other.itemIndex_; +} + + +void +ValueInternalMap::incrementBucket( IteratorState &iterator ) +{ + ++iterator.bucketIndex_; + JSON_ASSERT_MESSAGE( iterator.bucketIndex_ <= iterator.map_->bucketsSize_, + "ValueInternalMap::increment(): attempting to iterate beyond end." ); + if ( iterator.bucketIndex_ == iterator.map_->bucketsSize_ ) + iterator.link_ = 0; + else + iterator.link_ = &(iterator.map_->buckets_[iterator.bucketIndex_]); + iterator.itemIndex_ = 0; +} + + +void +ValueInternalMap::increment( IteratorState &iterator ) +{ + JSON_ASSERT_MESSAGE( iterator.map_, "Attempting to iterator using invalid iterator." ); + ++iterator.itemIndex_; + if ( iterator.itemIndex_ == ValueInternalLink::itemPerLink ) + { + JSON_ASSERT_MESSAGE( iterator.link_ != 0, + "ValueInternalMap::increment(): attempting to iterate beyond end." ); + iterator.link_ = iterator.link_->next_; + if ( iterator.link_ == 0 ) + incrementBucket( iterator ); + } + else if ( iterator.link_->items_[iterator.itemIndex_].isItemAvailable() ) + { + incrementBucket( iterator ); + } +} + + +void +ValueInternalMap::decrement( IteratorState &iterator ) +{ + if ( iterator.itemIndex_ == 0 ) + { + JSON_ASSERT_MESSAGE( iterator.map_, "Attempting to iterate using invalid iterator." ); + if ( iterator.link_ == &iterator.map_->buckets_[iterator.bucketIndex_] ) + { + JSON_ASSERT_MESSAGE( iterator.bucketIndex_ > 0, "Attempting to iterate beyond beginning." ); + --(iterator.bucketIndex_); + } + iterator.link_ = iterator.link_->previous_; + iterator.itemIndex_ = ValueInternalLink::itemPerLink - 1; + } +} + + +const char * +ValueInternalMap::key( const IteratorState &iterator ) +{ + JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." ); + return iterator.link_->keys_[iterator.itemIndex_]; +} + +const char * +ValueInternalMap::key( const IteratorState &iterator, bool &isStatic ) +{ + JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." ); + isStatic = iterator.link_->items_[iterator.itemIndex_].isMemberNameStatic(); + return iterator.link_->keys_[iterator.itemIndex_]; +} + + +Value & +ValueInternalMap::value( const IteratorState &iterator ) +{ + JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." ); + return iterator.link_->items_[iterator.itemIndex_]; +} + + +int +ValueInternalMap::distance( const IteratorState &x, const IteratorState &y ) +{ + int offset = 0; + IteratorState it = x; + while ( !equals( it, y ) ) + increment( it ); + return offset; +} diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_reader.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_reader.cpp new file mode 100644 index 00000000..5af16c8d --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_reader.cpp @@ -0,0 +1,892 @@ +#include <json/reader.h> +#include <json/value.h> +#include <utility> +#include <cstdio> +#include <cassert> +#include <cstring> +#include <iostream> +#include <stdexcept> + +#if _MSC_VER >= 1400 // VC++ 8.0 +#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. +#endif + +namespace Json { + +// QNX is strict about declaring C symbols in the std namespace. +#ifdef __QNXNTO__ +using std::memcpy; +using std::sprintf; +using std::sscanf; +#endif + +// Implementation of class Features +// //////////////////////////////// + +Features::Features() + : allowComments_( true ) + , strictRoot_( false ) +{ +} + + +Features +Features::all() +{ + return Features(); +} + + +Features +Features::strictMode() +{ + Features features; + features.allowComments_ = false; + features.strictRoot_ = true; + return features; +} + +// Implementation of class Reader +// //////////////////////////////// + + +static inline bool +in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4 ) +{ + return c == c1 || c == c2 || c == c3 || c == c4; +} + +static inline bool +in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5 ) +{ + return c == c1 || c == c2 || c == c3 || c == c4 || c == c5; +} + + +static bool +containsNewLine( Reader::Location begin, + Reader::Location end ) +{ + for ( ;begin < end; ++begin ) + if ( *begin == '\n' || *begin == '\r' ) + return true; + return false; +} + +static std::string codePointToUTF8(unsigned int cp) +{ + std::string result; + + // based on description from http://en.wikipedia.org/wiki/UTF-8 + + if (cp <= 0x7f) + { + result.resize(1); + result[0] = static_cast<char>(cp); + } + else if (cp <= 0x7FF) + { + result.resize(2); + result[1] = static_cast<char>(0x80 | (0x3f & cp)); + result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6))); + } + else if (cp <= 0xFFFF) + { + result.resize(3); + result[2] = static_cast<char>(0x80 | (0x3f & cp)); + result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6))); + result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12))); + } + else if (cp <= 0x10FFFF) + { + result.resize(4); + result[3] = static_cast<char>(0x80 | (0x3f & cp)); + result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6))); + result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12))); + result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18))); + } + + return result; +} + + +// Class Reader +// ////////////////////////////////////////////////////////////////// + +Reader::Reader() + : features_( Features::all() ) +{ +} + + +Reader::Reader( const Features &features ) + : features_( features ) +{ +} + + +bool +Reader::parse( const std::string &document, + Value &root, + bool collectComments ) +{ + document_ = document; + const char *begin = document_.c_str(); + const char *end = begin + document_.length(); + return parse( begin, end, root, collectComments ); +} + + +bool +Reader::parse( std::istream& sin, + Value &root, + bool collectComments ) +{ + //std::istream_iterator<char> begin(sin); + //std::istream_iterator<char> end; + // Those would allow streamed input from a file, if parse() were a + // template function. + + // Since std::string is reference-counted, this at least does not + // create an extra copy. + std::string doc; + std::getline(sin, doc, (char)EOF); + return parse( doc, root, collectComments ); +} + +bool +Reader::parse( const char *beginDoc, const char *endDoc, + Value &root, + bool collectComments ) +{ + if ( !features_.allowComments_ ) + { + collectComments = false; + } + + begin_ = beginDoc; + end_ = endDoc; + collectComments_ = collectComments; + current_ = begin_; + lastValueEnd_ = 0; + lastValue_ = 0; + commentsBefore_ = ""; + errors_.clear(); + while ( !nodes_.empty() ) + nodes_.pop(); + nodes_.push( &root ); + + bool successful = readValue(); + Token token; + skipCommentTokens( token ); + if ( collectComments_ && !commentsBefore_.empty() ) + root.setComment( commentsBefore_, commentAfter ); + if ( features_.strictRoot_ ) + { + if ( !root.isArray() && !root.isObject() ) + { + // Set error location to start of doc, ideally should be first token found in doc + token.type_ = tokenError; + token.start_ = beginDoc; + token.end_ = endDoc; + addError( "A valid JSON document must be either an array or an object value.", + token ); + return false; + } + } + return successful; +} + + +bool +Reader::readValue() +{ + Token token; + skipCommentTokens( token ); + bool successful = true; + + if ( collectComments_ && !commentsBefore_.empty() ) + { + currentValue().setComment( commentsBefore_, commentBefore ); + commentsBefore_ = ""; + } + + + switch ( token.type_ ) + { + case tokenObjectBegin: + successful = readObject( token ); + break; + case tokenArrayBegin: + successful = readArray( token ); + break; + case tokenNumber: + successful = decodeNumber( token ); + break; + case tokenString: + successful = decodeString( token ); + break; + case tokenTrue: + currentValue() = true; + break; + case tokenFalse: + currentValue() = false; + break; + case tokenNull: + currentValue() = Value(); + break; + default: + return addError( "Syntax error: value, object or array expected.", token ); + } + + if ( collectComments_ ) + { + lastValueEnd_ = current_; + lastValue_ = ¤tValue(); + } + + return successful; +} + + +void +Reader::skipCommentTokens( Token &token ) +{ + if ( features_.allowComments_ ) + { + do + { + readToken( token ); + } + while ( token.type_ == tokenComment ); + } + else + { + readToken( token ); + } +} + + +bool +Reader::expectToken( TokenType type, Token &token, const char *message ) +{ + readToken( token ); + if ( token.type_ != type ) + return addError( message, token ); + return true; +} + + +bool +Reader::readToken( Token &token ) +{ + skipSpaces(); + token.start_ = current_; + Char c = getNextChar(); + bool ok = true; + switch ( c ) + { + case '{': + token.type_ = tokenObjectBegin; + break; + case '}': + token.type_ = tokenObjectEnd; + break; + case '[': + token.type_ = tokenArrayBegin; + break; + case ']': + token.type_ = tokenArrayEnd; + break; + case '"': + token.type_ = tokenString; + ok = readString(); + break; + case '/': + token.type_ = tokenComment; + ok = readComment(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + token.type_ = tokenNumber; + readNumber(); + break; + case 't': + token.type_ = tokenTrue; + ok = match( "rue", 3 ); + break; + case 'f': + token.type_ = tokenFalse; + ok = match( "alse", 4 ); + break; + case 'n': + token.type_ = tokenNull; + ok = match( "ull", 3 ); + break; + case ',': + token.type_ = tokenArraySeparator; + break; + case ':': + token.type_ = tokenMemberSeparator; + break; + case 0: + token.type_ = tokenEndOfStream; + break; + default: + ok = false; + break; + } + if ( !ok ) + token.type_ = tokenError; + token.end_ = current_; + return true; +} + + +void +Reader::skipSpaces() +{ + while ( current_ != end_ ) + { + Char c = *current_; + if ( c == ' ' || c == '\t' || c == '\r' || c == '\n' ) + ++current_; + else + break; + } +} + + +bool +Reader::match( Location pattern, + int patternLength ) +{ + if ( end_ - current_ < patternLength ) + return false; + int index = patternLength; + while ( index-- ) + if ( current_[index] != pattern[index] ) + return false; + current_ += patternLength; + return true; +} + + +bool +Reader::readComment() +{ + Location commentBegin = current_ - 1; + Char c = getNextChar(); + bool successful = false; + if ( c == '*' ) + successful = readCStyleComment(); + else if ( c == '/' ) + successful = readCppStyleComment(); + if ( !successful ) + return false; + + if ( collectComments_ ) + { + CommentPlacement placement = commentBefore; + if ( lastValueEnd_ && !containsNewLine( lastValueEnd_, commentBegin ) ) + { + if ( c != '*' || !containsNewLine( commentBegin, current_ ) ) + placement = commentAfterOnSameLine; + } + + addComment( commentBegin, current_, placement ); + } + return true; +} + + +void +Reader::addComment( Location begin, + Location end, + CommentPlacement placement ) +{ + assert( collectComments_ ); + if ( placement == commentAfterOnSameLine ) + { + assert( lastValue_ != 0 ); + lastValue_->setComment( std::string( begin, end ), placement ); + } + else + { + if ( !commentsBefore_.empty() ) + commentsBefore_ += "\n"; + commentsBefore_ += std::string( begin, end ); + } +} + + +bool +Reader::readCStyleComment() +{ + while ( current_ != end_ ) + { + Char c = getNextChar(); + if ( c == '*' && *current_ == '/' ) + break; + } + return getNextChar() == '/'; +} + + +bool +Reader::readCppStyleComment() +{ + while ( current_ != end_ ) + { + Char c = getNextChar(); + if ( c == '\r' || c == '\n' ) + break; + } + return true; +} + + +void +Reader::readNumber() +{ + while ( current_ != end_ ) + { + if ( !(*current_ >= '0' && *current_ <= '9') && + !in( *current_, '.', 'e', 'E', '+', '-' ) ) + break; + ++current_; + } +} + +bool +Reader::readString() +{ + Char c = 0; + while ( current_ != end_ ) + { + c = getNextChar(); + if ( c == '\\' ) + getNextChar(); + else if ( c == '"' ) + break; + } + return c == '"'; +} + + +bool +Reader::readObject( Token &tokenStart ) +{ + Token tokenName; + std::string name; + currentValue() = Value( objectValue ); + while ( readToken( tokenName ) ) + { + bool initialTokenOk = true; + while ( tokenName.type_ == tokenComment && initialTokenOk ) + initialTokenOk = readToken( tokenName ); + if ( !initialTokenOk ) + break; + if ( tokenName.type_ == tokenObjectEnd && name.empty() ) // empty object + return true; + if ( tokenName.type_ != tokenString ) + break; + + name = ""; + if ( !decodeString( tokenName, name ) ) + return recoverFromError( tokenObjectEnd ); + + Token colon; + if ( !readToken( colon ) || colon.type_ != tokenMemberSeparator ) + { + return addErrorAndRecover( "Missing ':' after object member name", + colon, + tokenObjectEnd ); + } + Value &value = currentValue()[ name ]; + nodes_.push( &value ); + bool ok = readValue(); + nodes_.pop(); + if ( !ok ) // error already set + return recoverFromError( tokenObjectEnd ); + + Token comma; + if ( !readToken( comma ) + || ( comma.type_ != tokenObjectEnd && + comma.type_ != tokenArraySeparator && + comma.type_ != tokenComment ) ) + { + return addErrorAndRecover( "Missing ',' or '}' in object declaration", + comma, + tokenObjectEnd ); + } + bool finalizeTokenOk = true; + while ( comma.type_ == tokenComment && + finalizeTokenOk ) + finalizeTokenOk = readToken( comma ); + if ( comma.type_ == tokenObjectEnd ) + return true; + } + return addErrorAndRecover( "Missing '}' or object member name", + tokenName, + tokenObjectEnd ); +} + + +bool +Reader::readArray( Token &tokenStart ) +{ + currentValue() = Value( arrayValue ); + skipSpaces(); + if ( *current_ == ']' ) // empty array + { + Token endArray; + readToken( endArray ); + return true; + } + int index = 0; + while ( true ) + { + Value &value = currentValue()[ index++ ]; + nodes_.push( &value ); + bool ok = readValue(); + nodes_.pop(); + if ( !ok ) // error already set + return recoverFromError( tokenArrayEnd ); + + Token token; + // Accept Comment after last item in the array. + ok = readToken( token ); + while ( token.type_ == tokenComment && ok ) + { + ok = readToken( token ); + } + bool badTokenType = ( token.type_ == tokenArraySeparator && + token.type_ == tokenArrayEnd ); + if ( !ok || badTokenType ) + { + return addErrorAndRecover( "Missing ',' or ']' in array declaration", + token, + tokenArrayEnd ); + } + if ( token.type_ == tokenArrayEnd ) + break; + } + return true; +} + + +bool +Reader::decodeNumber( Token &token ) +{ + bool isDouble = false; + for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) + { + isDouble = isDouble + || in( *inspect, '.', 'e', 'E', '+' ) + || ( *inspect == '-' && inspect != token.start_ ); + } + if ( isDouble ) + return decodeDouble( token ); + Location current = token.start_; + bool isNegative = *current == '-'; + if ( isNegative ) + ++current; + Value::UInt threshold = (isNegative ? Value::UInt(-Value::minInt) + : Value::maxUInt) / 10; + Value::UInt value = 0; + while ( current < token.end_ ) + { + Char c = *current++; + if ( c < '0' || c > '9' ) + return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); + if ( value >= threshold ) + return decodeDouble( token ); + value = value * 10 + Value::UInt(c - '0'); + } + if ( isNegative ) + currentValue() = -Value::Int( value ); + else if ( value <= Value::UInt(Value::maxInt) ) + currentValue() = Value::Int( value ); + else + currentValue() = value; + return true; +} + + +bool +Reader::decodeDouble( Token &token ) +{ + double value = 0; + const int bufferSize = 32; + int count; + int length = int(token.end_ - token.start_); + if ( length <= bufferSize ) + { + Char buffer[bufferSize]; + memcpy( buffer, token.start_, length ); + buffer[length] = 0; + count = sscanf( buffer, "%lf", &value ); + } + else + { + std::string buffer( token.start_, token.end_ ); + count = sscanf( buffer.c_str(), "%lf", &value ); + } + + if ( count != 1 ) + return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); + currentValue() = value; + return true; +} + + +bool +Reader::decodeString( Token &token ) +{ + std::string decoded; + if ( !decodeString( token, decoded ) ) + return false; + currentValue() = decoded; + return true; +} + + +bool +Reader::decodeString( Token &token, std::string &decoded ) +{ + decoded.reserve( token.end_ - token.start_ - 2 ); + Location current = token.start_ + 1; // skip '"' + Location end = token.end_ - 1; // do not include '"' + while ( current != end ) + { + Char c = *current++; + if ( c == '"' ) + break; + else if ( c == '\\' ) + { + if ( current == end ) + return addError( "Empty escape sequence in string", token, current ); + Char escape = *current++; + switch ( escape ) + { + case '"': decoded += '"'; break; + case '/': decoded += '/'; break; + case '\\': decoded += '\\'; break; + case 'b': decoded += '\b'; break; + case 'f': decoded += '\f'; break; + case 'n': decoded += '\n'; break; + case 'r': decoded += '\r'; break; + case 't': decoded += '\t'; break; + case 'u': + { + unsigned int unicode; + if ( !decodeUnicodeCodePoint( token, current, end, unicode ) ) + return false; + decoded += codePointToUTF8(unicode); + } + break; + default: + return addError( "Bad escape sequence in string", token, current ); + } + } + else + { + decoded += c; + } + } + return true; +} + +bool +Reader::decodeUnicodeCodePoint( Token &token, + Location ¤t, + Location end, + unsigned int &unicode ) +{ + + if ( !decodeUnicodeEscapeSequence( token, current, end, unicode ) ) + return false; + if (unicode >= 0xD800 && unicode <= 0xDBFF) + { + // surrogate pairs + if (end - current < 6) + return addError( "additional six characters expected to parse unicode surrogate pair.", token, current ); + unsigned int surrogatePair; + if (*(current++) == '\\' && *(current++)== 'u') + { + if (decodeUnicodeEscapeSequence( token, current, end, surrogatePair )) + { + unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); + } + else + return false; + } + else + return addError( "expecting another \\u token to begin the second half of a unicode surrogate pair", token, current ); + } + return true; +} + +bool +Reader::decodeUnicodeEscapeSequence( Token &token, + Location ¤t, + Location end, + unsigned int &unicode ) +{ + if ( end - current < 4 ) + return addError( "Bad unicode escape sequence in string: four digits expected.", token, current ); + unicode = 0; + for ( int index =0; index < 4; ++index ) + { + Char c = *current++; + unicode *= 16; + if ( c >= '0' && c <= '9' ) + unicode += c - '0'; + else if ( c >= 'a' && c <= 'f' ) + unicode += c - 'a' + 10; + else if ( c >= 'A' && c <= 'F' ) + unicode += c - 'A' + 10; + else + return addError( "Bad unicode escape sequence in string: hexadecimal digit expected.", token, current ); + } + return true; +} + + +bool +Reader::addError( const std::string &message, + Token &token, + Location extra ) +{ + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = extra; + errors_.push_back( info ); + return false; +} + + +bool +Reader::recoverFromError( TokenType skipUntilToken ) +{ + int errorCount = int(errors_.size()); + Token skip; + while ( true ) + { + if ( !readToken(skip) ) + errors_.resize( errorCount ); // discard errors caused by recovery + if ( skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream ) + break; + } + errors_.resize( errorCount ); + return false; +} + + +bool +Reader::addErrorAndRecover( const std::string &message, + Token &token, + TokenType skipUntilToken ) +{ + addError( message, token ); + return recoverFromError( skipUntilToken ); +} + + +Value & +Reader::currentValue() +{ + return *(nodes_.top()); +} + + +Reader::Char +Reader::getNextChar() +{ + if ( current_ == end_ ) + return 0; + return *current_++; +} + + +void +Reader::getLocationLineAndColumn( Location location, + int &line, + int &column ) const +{ + Location current = begin_; + Location lastLineStart = current; + line = 0; + while ( current < location && current != end_ ) + { + Char c = *current++; + if ( c == '\r' ) + { + if ( *current == '\n' ) + ++current; + lastLineStart = current; + ++line; + } + else if ( c == '\n' ) + { + lastLineStart = current; + ++line; + } + } + // column & line start at 1 + column = int(location - lastLineStart) + 1; + ++line; +} + + +std::string +Reader::getLocationLineAndColumn( Location location ) const +{ + int line, column; + getLocationLineAndColumn( location, line, column ); + char buffer[18+16+16+1]; + sprintf( buffer, "Line %d, Column %d", line, column ); + return buffer; +} + + +std::string +Reader::getFormatedErrorMessages() const +{ + std::string formattedMessage; + for ( Errors::const_iterator itError = errors_.begin(); + itError != errors_.end(); + ++itError ) + { + const ErrorInfo &error = *itError; + formattedMessage += "* " + getLocationLineAndColumn( error.token_.start_ ) + "\n"; + formattedMessage += " " + error.message_ + "\n"; + if ( error.extra_ ) + formattedMessage += "See " + getLocationLineAndColumn( error.extra_ ) + " for detail.\n"; + } + return formattedMessage; +} + + +std::istream& operator>>( std::istream &sin, Value &root ) +{ + Json::Reader reader; + bool ok = reader.parse(sin, root, true); + //JSON_ASSERT( ok ); + if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages()); + return sin; +} + + +} // namespace Json diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_value.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_value.cpp new file mode 100644 index 00000000..6e5dcd3e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_value.cpp @@ -0,0 +1,1726 @@ +#include <iostream> +#include <json/value.h> +#include <json/writer.h> +#include <utility> +#include <stdexcept> +#include <cstring> +#include <cassert> +#ifdef JSON_USE_CPPTL +# include <cpptl/conststring.h> +#endif +#include <cstddef> // size_t +#ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR +# include "json_batchallocator.h" +#endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR + +#define JSON_ASSERT_UNREACHABLE assert( false ) +#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw +#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message ); + +namespace Json { + +// QNX is strict about declaring C symbols in the std namespace. +#ifdef __QNXNTO__ +using std::memcpy; +using std::strchr; +using std::strcmp; +using std::strlen; +#endif + +const Value Value::null; +const Int Value::minInt = Int( ~(UInt(-1)/2) ); +const Int Value::maxInt = Int( UInt(-1)/2 ); +const UInt Value::maxUInt = UInt(-1); + +// A "safe" implementation of strdup. Allow null pointer to be passed. +// Also avoid warning on msvc80. +// +//inline char *safeStringDup( const char *czstring ) +//{ +// if ( czstring ) +// { +// const size_t length = (unsigned int)( strlen(czstring) + 1 ); +// char *newString = static_cast<char *>( malloc( length ) ); +// memcpy( newString, czstring, length ); +// return newString; +// } +// return 0; +//} +// +//inline char *safeStringDup( const std::string &str ) +//{ +// if ( !str.empty() ) +// { +// const size_t length = str.length(); +// char *newString = static_cast<char *>( malloc( length + 1 ) ); +// memcpy( newString, str.c_str(), length ); +// newString[length] = 0; +// return newString; +// } +// return 0; +//} + +ValueAllocator::~ValueAllocator() +{ +} + +class DefaultValueAllocator : public ValueAllocator +{ +public: + virtual ~DefaultValueAllocator() + { + } + + virtual char *makeMemberName( const char *memberName ) + { + return duplicateStringValue( memberName ); + } + + virtual void releaseMemberName( char *memberName ) + { + releaseStringValue( memberName ); + } + + virtual char *duplicateStringValue( const char *value, + unsigned int length = unknown ) + { + //@todo invesgate this old optimization + //if ( !value || value[0] == 0 ) + // return 0; + + if ( length == unknown ) + length = (unsigned int)strlen(value); + char *newString = static_cast<char *>( malloc( length + 1 ) ); + memcpy( newString, value, length ); + newString[length] = 0; + return newString; + } + + virtual void releaseStringValue( char *value ) + { + if ( value ) + free( value ); + } +}; + +static ValueAllocator *&valueAllocator() +{ + static DefaultValueAllocator defaultAllocator; + static ValueAllocator *valueAllocator = &defaultAllocator; + return valueAllocator; +} + +static struct DummyValueAllocatorInitializer { + DummyValueAllocatorInitializer() + { + valueAllocator(); // ensure valueAllocator() statics are initialized before main(). + } +} dummyValueAllocatorInitializer; + + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ValueInternals... +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +#ifdef JSON_VALUE_USE_INTERNAL_MAP +# include "json_internalarray.inl" +# include "json_internalmap.inl" +#endif // JSON_VALUE_USE_INTERNAL_MAP + +# include "json_valueiterator.inl" + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::CommentInfo +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + + +Value::CommentInfo::CommentInfo() + : comment_( 0 ) +{ +} + +Value::CommentInfo::~CommentInfo() +{ + if ( comment_ ) + valueAllocator()->releaseStringValue( comment_ ); +} + + +void +Value::CommentInfo::setComment( const char *text ) +{ + if ( comment_ ) + valueAllocator()->releaseStringValue( comment_ ); + JSON_ASSERT( text ); + JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); + // It seems that /**/ style comments are acceptable as well. + comment_ = valueAllocator()->duplicateStringValue( text ); +} + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::CZString +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +# ifndef JSON_VALUE_USE_INTERNAL_MAP + +// Notes: index_ indicates if the string was allocated when +// a string is stored. + +Value::CZString::CZString( int index ) + : cstr_( 0 ) + , index_( index ) +{ +} + +Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) + : cstr_( allocate == duplicate ? valueAllocator()->makeMemberName(cstr) + : cstr ) + , index_( allocate ) +{ +} + +Value::CZString::CZString( const CZString &other ) +: cstr_( other.index_ != noDuplication && other.cstr_ != 0 + ? valueAllocator()->makeMemberName( other.cstr_ ) + : other.cstr_ ) + , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) + : other.index_ ) +{ +} + +Value::CZString::~CZString() +{ + if ( cstr_ && index_ == duplicate ) + valueAllocator()->releaseMemberName( const_cast<char *>( cstr_ ) ); +} + +void +Value::CZString::swap( CZString &other ) +{ + std::swap( cstr_, other.cstr_ ); + std::swap( index_, other.index_ ); +} + +Value::CZString & +Value::CZString::operator =( const CZString &other ) +{ + CZString temp( other ); + swap( temp ); + return *this; +} + +bool +Value::CZString::operator<( const CZString &other ) const +{ + if ( cstr_ ) + return strcmp( cstr_, other.cstr_ ) < 0; + return index_ < other.index_; +} + +bool +Value::CZString::operator==( const CZString &other ) const +{ + if ( cstr_ ) + return strcmp( cstr_, other.cstr_ ) == 0; + return index_ == other.index_; +} + + +int +Value::CZString::index() const +{ + return index_; +} + + +const char * +Value::CZString::c_str() const +{ + return cstr_; +} + +bool +Value::CZString::isStaticString() const +{ + return index_ == noDuplication; +} + +#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::Value +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +/*! \internal Default constructor initialization must be equivalent to: + * memset( this, 0, sizeof(Value) ) + * This optimization is used in ValueInternalMap fast allocator. + */ +Value::Value( ValueType type ) + : type_( type ) + , allocated_( 0 ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + switch ( type ) + { + case nullValue: + break; + case intValue: + case uintValue: + value_.int_ = 0; + break; + case realValue: + value_.real_ = 0.0; + break; + case stringValue: + value_.string_ = 0; + break; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + value_.map_ = new ObjectValues(); + break; +#else + case arrayValue: + value_.array_ = arrayAllocator()->newArray(); + break; + case objectValue: + value_.map_ = mapAllocator()->newMap(); + break; +#endif + case booleanValue: + value_.bool_ = false; + break; + default: + JSON_ASSERT_UNREACHABLE; + } +} + + +Value::Value( Int value ) + : type_( intValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.int_ = value; +} + + +Value::Value( UInt value ) + : type_( uintValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.uint_ = value; +} + +Value::Value( double value ) + : type_( realValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.real_ = value; +} + +Value::Value( const char *value ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( value ); +} + + +Value::Value( const char *beginValue, + const char *endValue ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( beginValue, + UInt(endValue - beginValue) ); +} + + +Value::Value( const std::string &value ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( value.c_str(), + (unsigned int)value.length() ); + +} + +Value::Value( const StaticString &value ) + : type_( stringValue ) + , allocated_( false ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = const_cast<char *>( value.c_str() ); +} + + +# ifdef JSON_USE_CPPTL +Value::Value( const CppTL::ConstString &value ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( value, value.length() ); +} +# endif + +Value::Value( bool value ) + : type_( booleanValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.bool_ = value; +} + + +Value::Value( const Value &other ) + : type_( other.type_ ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + switch ( type_ ) + { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + value_ = other.value_; + break; + case stringValue: + if ( other.value_.string_ ) + { + value_.string_ = valueAllocator()->duplicateStringValue( other.value_.string_ ); + allocated_ = true; + } + else + value_.string_ = 0; + break; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + value_.map_ = new ObjectValues( *other.value_.map_ ); + break; +#else + case arrayValue: + value_.array_ = arrayAllocator()->newArrayCopy( *other.value_.array_ ); + break; + case objectValue: + value_.map_ = mapAllocator()->newMapCopy( *other.value_.map_ ); + break; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + if ( other.comments_ ) + { + comments_ = new CommentInfo[numberOfCommentPlacement]; + for ( int comment =0; comment < numberOfCommentPlacement; ++comment ) + { + const CommentInfo &otherComment = other.comments_[comment]; + if ( otherComment.comment_ ) + comments_[comment].setComment( otherComment.comment_ ); + } + } +} + + +Value::~Value() +{ + switch ( type_ ) + { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + break; + case stringValue: + if ( allocated_ ) + valueAllocator()->releaseStringValue( value_.string_ ); + break; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + delete value_.map_; + break; +#else + case arrayValue: + arrayAllocator()->destructArray( value_.array_ ); + break; + case objectValue: + mapAllocator()->destructMap( value_.map_ ); + break; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + + if ( comments_ ) + delete[] comments_; +} + +Value & +Value::operator=( const Value &other ) +{ + Value temp( other ); + swap( temp ); + return *this; +} + +void +Value::swap( Value &other ) +{ + ValueType temp = type_; + type_ = other.type_; + other.type_ = temp; + std::swap( value_, other.value_ ); + int temp2 = allocated_; + allocated_ = other.allocated_; + other.allocated_ = temp2; +} + +ValueType +Value::type() const +{ + return type_; +} + + +int +Value::compare( const Value &other ) +{ + /* + int typeDelta = other.type_ - type_; + switch ( type_ ) + { + case nullValue: + + return other.type_ == type_; + case intValue: + if ( other.type_.isNumeric() + case uintValue: + case realValue: + case booleanValue: + break; + case stringValue, + break; + case arrayValue: + delete value_.array_; + break; + case objectValue: + delete value_.map_; + default: + JSON_ASSERT_UNREACHABLE; + } + */ + return 0; // unreachable +} + +bool +Value::operator <( const Value &other ) const +{ + int typeDelta = type_ - other.type_; + if ( typeDelta ) + return typeDelta < 0 ? true : false; + switch ( type_ ) + { + case nullValue: + return false; + case intValue: + return value_.int_ < other.value_.int_; + case uintValue: + return value_.uint_ < other.value_.uint_; + case realValue: + return value_.real_ < other.value_.real_; + case booleanValue: + return value_.bool_ < other.value_.bool_; + case stringValue: + return ( value_.string_ == 0 && other.value_.string_ ) + || ( other.value_.string_ + && value_.string_ + && strcmp( value_.string_, other.value_.string_ ) < 0 ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + { + int delta = int( value_.map_->size() - other.value_.map_->size() ); + if ( delta ) + return delta < 0; + return (*value_.map_) < (*other.value_.map_); + } +#else + case arrayValue: + return value_.array_->compare( *(other.value_.array_) ) < 0; + case objectValue: + return value_.map_->compare( *(other.value_.map_) ) < 0; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable +} + +bool +Value::operator <=( const Value &other ) const +{ + return !(other > *this); +} + +bool +Value::operator >=( const Value &other ) const +{ + return !(*this < other); +} + +bool +Value::operator >( const Value &other ) const +{ + return other < *this; +} + +bool +Value::operator ==( const Value &other ) const +{ + //if ( type_ != other.type_ ) + // GCC 2.95.3 says: + // attempt to take address of bit-field structure member `Json::Value::type_' + // Beats me, but a temp solves the problem. + int temp = other.type_; + if ( type_ != temp ) + return false; + switch ( type_ ) + { + case nullValue: + return true; + case intValue: + return value_.int_ == other.value_.int_; + case uintValue: + return value_.uint_ == other.value_.uint_; + case realValue: + return value_.real_ == other.value_.real_; + case booleanValue: + return value_.bool_ == other.value_.bool_; + case stringValue: + return ( value_.string_ == other.value_.string_ ) + || ( other.value_.string_ + && value_.string_ + && strcmp( value_.string_, other.value_.string_ ) == 0 ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + return value_.map_->size() == other.value_.map_->size() + && (*value_.map_) == (*other.value_.map_); +#else + case arrayValue: + return value_.array_->compare( *(other.value_.array_) ) == 0; + case objectValue: + return value_.map_->compare( *(other.value_.map_) ) == 0; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable +} + +bool +Value::operator !=( const Value &other ) const +{ + return !( *this == other ); +} + +const char * +Value::asCString() const +{ + JSON_ASSERT( type_ == stringValue ); + return value_.string_; +} + + +std::string +Value::asString() const +{ + switch ( type_ ) + { + case nullValue: + return ""; + case stringValue: + return value_.string_ ? value_.string_ : ""; + case booleanValue: + return value_.bool_ ? "true" : "false"; + case intValue: + case uintValue: + case realValue: + case arrayValue: + case objectValue: + JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" ); + default: + JSON_ASSERT_UNREACHABLE; + } + return ""; // unreachable +} + +# ifdef JSON_USE_CPPTL +CppTL::ConstString +Value::asConstString() const +{ + return CppTL::ConstString( asString().c_str() ); +} +# endif + +Value::Int +Value::asInt() const +{ + switch ( type_ ) + { + case nullValue: + return 0; + case intValue: + return value_.int_; + case uintValue: + JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" ); + return value_.uint_; + case realValue: + JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); + return Int( value_.real_ ); + case booleanValue: + return value_.bool_ ? 1 : 0; + case stringValue: + case arrayValue: + case objectValue: + JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" ); + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + +Value::UInt +Value::asUInt() const +{ + switch ( type_ ) + { + case nullValue: + return 0; + case intValue: + JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); + return value_.int_; + case uintValue: + return value_.uint_; + case realValue: + JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); + return UInt( value_.real_ ); + case booleanValue: + return value_.bool_ ? 1 : 0; + case stringValue: + case arrayValue: + case objectValue: + JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" ); + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + +double +Value::asDouble() const +{ + switch ( type_ ) + { + case nullValue: + return 0.0; + case intValue: + return value_.int_; + case uintValue: + return value_.uint_; + case realValue: + return value_.real_; + case booleanValue: + return value_.bool_ ? 1.0 : 0.0; + case stringValue: + case arrayValue: + case objectValue: + JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" ); + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + +bool +Value::asBool() const +{ + switch ( type_ ) + { + case nullValue: + return false; + case intValue: + case uintValue: + return value_.int_ != 0; + case realValue: + return value_.real_ != 0.0; + case booleanValue: + return value_.bool_; + case stringValue: + return value_.string_ && value_.string_[0] != 0; + case arrayValue: + case objectValue: + return value_.map_->size() != 0; + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable; +} + + +bool +Value::isConvertibleTo( ValueType other ) const +{ + switch ( type_ ) + { + case nullValue: + return true; + case intValue: + return ( other == nullValue && value_.int_ == 0 ) + || other == intValue + || ( other == uintValue && value_.int_ >= 0 ) + || other == realValue + || other == stringValue + || other == booleanValue; + case uintValue: + return ( other == nullValue && value_.uint_ == 0 ) + || ( other == intValue && value_.uint_ <= (unsigned)maxInt ) + || other == uintValue + || other == realValue + || other == stringValue + || other == booleanValue; + case realValue: + return ( other == nullValue && value_.real_ == 0.0 ) + || ( other == intValue && value_.real_ >= minInt && value_.real_ <= maxInt ) + || ( other == uintValue && value_.real_ >= 0 && value_.real_ <= maxUInt ) + || other == realValue + || other == stringValue + || other == booleanValue; + case booleanValue: + return ( other == nullValue && value_.bool_ == false ) + || other == intValue + || other == uintValue + || other == realValue + || other == stringValue + || other == booleanValue; + case stringValue: + return other == stringValue + || ( other == nullValue && (!value_.string_ || value_.string_[0] == 0) ); + case arrayValue: + return other == arrayValue + || ( other == nullValue && value_.map_->size() == 0 ); + case objectValue: + return other == objectValue + || ( other == nullValue && value_.map_->size() == 0 ); + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable; +} + + +/// Number of values in array or object +Value::UInt +Value::size() const +{ + switch ( type_ ) + { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + case stringValue: + return 0; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: // size of the array is highest index + 1 + if ( !value_.map_->empty() ) + { + ObjectValues::const_iterator itLast = value_.map_->end(); + --itLast; + return (*itLast).first.index()+1; + } + return 0; + case objectValue: + return Int( value_.map_->size() ); +#else + case arrayValue: + return Int( value_.array_->size() ); + case objectValue: + return Int( value_.map_->size() ); +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + + +bool +Value::empty() const +{ + if ( isNull() || isArray() || isObject() ) + return size() == 0u; + else + return false; +} + + +bool +Value::operator!() const +{ + return isNull(); +} + + +void +Value::clear() +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue || type_ == objectValue ); + + switch ( type_ ) + { +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + value_.map_->clear(); + break; +#else + case arrayValue: + value_.array_->clear(); + break; + case objectValue: + value_.map_->clear(); + break; +#endif + default: + break; + } +} + +void +Value::resize( UInt newSize ) +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); + if ( type_ == nullValue ) + *this = Value( arrayValue ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + UInt oldSize = size(); + if ( newSize == 0 ) + clear(); + else if ( newSize > oldSize ) + (*this)[ newSize - 1 ]; + else + { + for ( UInt index = newSize; index < oldSize; ++index ) + value_.map_->erase( index ); + assert( size() == newSize ); + } +#else + value_.array_->resize( newSize ); +#endif +} + + +Value & +Value::operator[]( UInt index ) +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); + if ( type_ == nullValue ) + *this = Value( arrayValue ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString key( index ); + ObjectValues::iterator it = value_.map_->lower_bound( key ); + if ( it != value_.map_->end() && (*it).first == key ) + return (*it).second; + + ObjectValues::value_type defaultValue( key, null ); + it = value_.map_->insert( it, defaultValue ); + return (*it).second; +#else + return value_.array_->resolveReference( index ); +#endif +} + + +const Value & +Value::operator[]( UInt index ) const +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); + if ( type_ == nullValue ) + return null; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString key( index ); + ObjectValues::const_iterator it = value_.map_->find( key ); + if ( it == value_.map_->end() ) + return null; + return (*it).second; +#else + Value *value = value_.array_->find( index ); + return value ? *value : null; +#endif +} + + +Value & +Value::operator[]( const char *key ) +{ + return resolveReference( key, false ); +} + + +Value & +Value::resolveReference( const char *key, + bool isStatic ) +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + *this = Value( objectValue ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString actualKey( key, isStatic ? CZString::noDuplication + : CZString::duplicateOnCopy ); + ObjectValues::iterator it = value_.map_->lower_bound( actualKey ); + if ( it != value_.map_->end() && (*it).first == actualKey ) + return (*it).second; + + ObjectValues::value_type defaultValue( actualKey, null ); + it = value_.map_->insert( it, defaultValue ); + Value &value = (*it).second; + return value; +#else + return value_.map_->resolveReference( key, isStatic ); +#endif +} + + +Value +Value::get( UInt index, + const Value &defaultValue ) const +{ + const Value *value = &((*this)[index]); + return value == &null ? defaultValue : *value; +} + + +bool +Value::isValidIndex( UInt index ) const +{ + return index < size(); +} + + + +const Value & +Value::operator[]( const char *key ) const +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + return null; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString actualKey( key, CZString::noDuplication ); + ObjectValues::const_iterator it = value_.map_->find( actualKey ); + if ( it == value_.map_->end() ) + return null; + return (*it).second; +#else + const Value *value = value_.map_->find( key ); + return value ? *value : null; +#endif +} + + +Value & +Value::operator[]( const std::string &key ) +{ + return (*this)[ key.c_str() ]; +} + + +const Value & +Value::operator[]( const std::string &key ) const +{ + return (*this)[ key.c_str() ]; +} + +Value & +Value::operator[]( const StaticString &key ) +{ + return resolveReference( key, true ); +} + + +# ifdef JSON_USE_CPPTL +Value & +Value::operator[]( const CppTL::ConstString &key ) +{ + return (*this)[ key.c_str() ]; +} + + +const Value & +Value::operator[]( const CppTL::ConstString &key ) const +{ + return (*this)[ key.c_str() ]; +} +# endif + + +Value & +Value::append( const Value &value ) +{ + return (*this)[size()] = value; +} + + +Value +Value::get( const char *key, + const Value &defaultValue ) const +{ + const Value *value = &((*this)[key]); + return value == &null ? defaultValue : *value; +} + + +Value +Value::get( const std::string &key, + const Value &defaultValue ) const +{ + return get( key.c_str(), defaultValue ); +} + +Value +Value::removeMember( const char* key ) +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + return null; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString actualKey( key, CZString::noDuplication ); + ObjectValues::iterator it = value_.map_->find( actualKey ); + if ( it == value_.map_->end() ) + return null; + Value old(it->second); + value_.map_->erase(it); + return old; +#else + Value *value = value_.map_->find( key ); + if (value){ + Value old(*value); + value_.map_.remove( key ); + return old; + } else { + return null; + } +#endif +} + +Value +Value::removeMember( const std::string &key ) +{ + return removeMember( key.c_str() ); +} + +# ifdef JSON_USE_CPPTL +Value +Value::get( const CppTL::ConstString &key, + const Value &defaultValue ) const +{ + return get( key.c_str(), defaultValue ); +} +# endif + +bool +Value::isMember( const char *key ) const +{ + const Value *value = &((*this)[key]); + return value != &null; +} + + +bool +Value::isMember( const std::string &key ) const +{ + return isMember( key.c_str() ); +} + + +# ifdef JSON_USE_CPPTL +bool +Value::isMember( const CppTL::ConstString &key ) const +{ + return isMember( key.c_str() ); +} +#endif + +Value::Members +Value::getMemberNames() const +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + return Value::Members(); + Members members; + members.reserve( value_.map_->size() ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + ObjectValues::const_iterator it = value_.map_->begin(); + ObjectValues::const_iterator itEnd = value_.map_->end(); + for ( ; it != itEnd; ++it ) + members.push_back( std::string( (*it).first.c_str() ) ); +#else + ValueInternalMap::IteratorState it; + ValueInternalMap::IteratorState itEnd; + value_.map_->makeBeginIterator( it ); + value_.map_->makeEndIterator( itEnd ); + for ( ; !ValueInternalMap::equals( it, itEnd ); ValueInternalMap::increment(it) ) + members.push_back( std::string( ValueInternalMap::key( it ) ) ); +#endif + return members; +} +// +//# ifdef JSON_USE_CPPTL +//EnumMemberNames +//Value::enumMemberNames() const +//{ +// if ( type_ == objectValue ) +// { +// return CppTL::Enum::any( CppTL::Enum::transform( +// CppTL::Enum::keys( *(value_.map_), CppTL::Type<const CZString &>() ), +// MemberNamesTransform() ) ); +// } +// return EnumMemberNames(); +//} +// +// +//EnumValues +//Value::enumValues() const +//{ +// if ( type_ == objectValue || type_ == arrayValue ) +// return CppTL::Enum::anyValues( *(value_.map_), +// CppTL::Type<const Value &>() ); +// return EnumValues(); +//} +// +//# endif + + +bool +Value::isNull() const +{ + return type_ == nullValue; +} + + +bool +Value::isBool() const +{ + return type_ == booleanValue; +} + + +bool +Value::isInt() const +{ + return type_ == intValue; +} + + +bool +Value::isUInt() const +{ + return type_ == uintValue; +} + + +bool +Value::isIntegral() const +{ + return type_ == intValue + || type_ == uintValue + || type_ == booleanValue; +} + + +bool +Value::isDouble() const +{ + return type_ == realValue; +} + + +bool +Value::isNumeric() const +{ + return isIntegral() || isDouble(); +} + + +bool +Value::isString() const +{ + return type_ == stringValue; +} + + +bool +Value::isArray() const +{ + return type_ == nullValue || type_ == arrayValue; +} + + +bool +Value::isObject() const +{ + return type_ == nullValue || type_ == objectValue; +} + + +void +Value::setComment( const char *comment, + CommentPlacement placement ) +{ + if ( !comments_ ) + comments_ = new CommentInfo[numberOfCommentPlacement]; + comments_[placement].setComment( comment ); +} + + +void +Value::setComment( const std::string &comment, + CommentPlacement placement ) +{ + setComment( comment.c_str(), placement ); +} + + +bool +Value::hasComment( CommentPlacement placement ) const +{ + return comments_ != 0 && comments_[placement].comment_ != 0; +} + +std::string +Value::getComment( CommentPlacement placement ) const +{ + if ( hasComment(placement) ) + return comments_[placement].comment_; + return ""; +} + + +std::string +Value::toStyledString() const +{ + StyledWriter writer; + return writer.write( *this ); +} + + +Value::const_iterator +Value::begin() const +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeBeginIterator( it ); + return const_iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeBeginIterator( it ); + return const_iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return const_iterator( value_.map_->begin() ); + break; +#endif + default: + break; + } + return const_iterator(); +} + +Value::const_iterator +Value::end() const +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeEndIterator( it ); + return const_iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeEndIterator( it ); + return const_iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return const_iterator( value_.map_->end() ); + break; +#endif + default: + break; + } + return const_iterator(); +} + + +Value::iterator +Value::begin() +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeBeginIterator( it ); + return iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeBeginIterator( it ); + return iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return iterator( value_.map_->begin() ); + break; +#endif + default: + break; + } + return iterator(); +} + +Value::iterator +Value::end() +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeEndIterator( it ); + return iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeEndIterator( it ); + return iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return iterator( value_.map_->end() ); + break; +#endif + default: + break; + } + return iterator(); +} + + +// class PathArgument +// ////////////////////////////////////////////////////////////////// + +PathArgument::PathArgument() + : kind_( kindNone ) +{ +} + + +PathArgument::PathArgument( Value::UInt index ) + : index_( index ) + , kind_( kindIndex ) +{ +} + + +PathArgument::PathArgument( const char *key ) + : key_( key ) + , kind_( kindKey ) +{ +} + + +PathArgument::PathArgument( const std::string &key ) + : key_( key.c_str() ) + , kind_( kindKey ) +{ +} + +// class Path +// ////////////////////////////////////////////////////////////////// + +Path::Path( const std::string &path, + const PathArgument &a1, + const PathArgument &a2, + const PathArgument &a3, + const PathArgument &a4, + const PathArgument &a5 ) +{ + InArgs in; + in.push_back( &a1 ); + in.push_back( &a2 ); + in.push_back( &a3 ); + in.push_back( &a4 ); + in.push_back( &a5 ); + makePath( path, in ); +} + + +void +Path::makePath( const std::string &path, + const InArgs &in ) +{ + const char *current = path.c_str(); + const char *end = current + path.length(); + InArgs::const_iterator itInArg = in.begin(); + while ( current != end ) + { + if ( *current == '[' ) + { + ++current; + if ( *current == '%' ) + addPathInArg( path, in, itInArg, PathArgument::kindIndex ); + else + { + Value::UInt index = 0; + for ( ; current != end && *current >= '0' && *current <= '9'; ++current ) + index = index * 10 + Value::UInt(*current - '0'); + args_.push_back( index ); + } + if ( current == end || *current++ != ']' ) + invalidPath( path, int(current - path.c_str()) ); + } + else if ( *current == '%' ) + { + addPathInArg( path, in, itInArg, PathArgument::kindKey ); + ++current; + } + else if ( *current == '.' ) + { + ++current; + } + else + { + const char *beginName = current; + while ( current != end && !strchr( "[.", *current ) ) + ++current; + args_.push_back( std::string( beginName, current ) ); + } + } +} + + +void +Path::addPathInArg( const std::string &path, + const InArgs &in, + InArgs::const_iterator &itInArg, + PathArgument::Kind kind ) +{ + if ( itInArg == in.end() ) + { + // Error: missing argument %d + } + else if ( (*itInArg)->kind_ != kind ) + { + // Error: bad argument type + } + else + { + args_.push_back( **itInArg ); + } +} + + +void +Path::invalidPath( const std::string &path, + int location ) +{ + // Error: invalid path. +} + + +const Value & +Path::resolve( const Value &root ) const +{ + const Value *node = &root; + for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) + { + const PathArgument &arg = *it; + if ( arg.kind_ == PathArgument::kindIndex ) + { + if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) + { + // Error: unable to resolve path (array value expected at position... + } + node = &((*node)[arg.index_]); + } + else if ( arg.kind_ == PathArgument::kindKey ) + { + if ( !node->isObject() ) + { + // Error: unable to resolve path (object value expected at position...) + } + node = &((*node)[arg.key_]); + if ( node == &Value::null ) + { + // Error: unable to resolve path (object has no member named '' at position...) + } + } + } + return *node; +} + + +Value +Path::resolve( const Value &root, + const Value &defaultValue ) const +{ + const Value *node = &root; + for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) + { + const PathArgument &arg = *it; + if ( arg.kind_ == PathArgument::kindIndex ) + { + if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) + return defaultValue; + node = &((*node)[arg.index_]); + } + else if ( arg.kind_ == PathArgument::kindKey ) + { + if ( !node->isObject() ) + return defaultValue; + node = &((*node)[arg.key_]); + if ( node == &Value::null ) + return defaultValue; + } + } + return *node; +} + + +Value & +Path::make( Value &root ) const +{ + Value *node = &root; + for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) + { + const PathArgument &arg = *it; + if ( arg.kind_ == PathArgument::kindIndex ) + { + if ( !node->isArray() ) + { + // Error: node is not an array at position ... + } + node = &((*node)[arg.index_]); + } + else if ( arg.kind_ == PathArgument::kindKey ) + { + if ( !node->isObject() ) + { + // Error: node is not an object at position... + } + node = &((*node)[arg.key_]); + } + } + return *node; +} + + +} // namespace Json diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_valueiterator.inl b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_valueiterator.inl new file mode 100644 index 00000000..736e260e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_valueiterator.inl @@ -0,0 +1,292 @@ +// included by json_value.cpp +// everything is within Json namespace + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueIteratorBase +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueIteratorBase::ValueIteratorBase() +#ifndef JSON_VALUE_USE_INTERNAL_MAP + : current_() + , isNull_( true ) +{ +} +#else + : isArray_( true ) + , isNull_( true ) +{ + iterator_.array_ = ValueInternalArray::IteratorState(); +} +#endif + + +#ifndef JSON_VALUE_USE_INTERNAL_MAP +ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t ) + : current_( current ) + , isNull_( false ) +{ +} +#else +ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state ) + : isArray_( true ) +{ + iterator_.array_ = state; +} + + +ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state ) + : isArray_( false ) +{ + iterator_.map_ = state; +} +#endif + +Value & +ValueIteratorBase::deref() const +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + return current_->second; +#else + if ( isArray_ ) + return ValueInternalArray::dereference( iterator_.array_ ); + return ValueInternalMap::value( iterator_.map_ ); +#endif +} + + +void +ValueIteratorBase::increment() +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + ++current_; +#else + if ( isArray_ ) + ValueInternalArray::increment( iterator_.array_ ); + ValueInternalMap::increment( iterator_.map_ ); +#endif +} + + +void +ValueIteratorBase::decrement() +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + --current_; +#else + if ( isArray_ ) + ValueInternalArray::decrement( iterator_.array_ ); + ValueInternalMap::decrement( iterator_.map_ ); +#endif +} + + +ValueIteratorBase::difference_type +ValueIteratorBase::computeDistance( const SelfType &other ) const +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP +# ifdef JSON_USE_CPPTL_SMALLMAP + return current_ - other.current_; +# else + // Iterator for null value are initialized using the default + // constructor, which initialize current_ to the default + // std::map::iterator. As begin() and end() are two instance + // of the default std::map::iterator, they can not be compared. + // To allow this, we handle this comparison specifically. + if ( isNull_ && other.isNull_ ) + { + return 0; + } + + + // Usage of std::distance is not portable (does not compile with Sun Studio 12 RogueWave STL, + // which is the one used by default). + // Using a portable hand-made version for non random iterator instead: + // return difference_type( std::distance( current_, other.current_ ) ); + difference_type myDistance = 0; + for ( Value::ObjectValues::iterator it = current_; it != other.current_; ++it ) + { + ++myDistance; + } + return myDistance; +# endif +#else + if ( isArray_ ) + return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ ); + return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ ); +#endif +} + + +bool +ValueIteratorBase::isEqual( const SelfType &other ) const +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + if ( isNull_ ) + { + return other.isNull_; + } + return current_ == other.current_; +#else + if ( isArray_ ) + return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ ); + return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ ); +#endif +} + + +void +ValueIteratorBase::copy( const SelfType &other ) +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + current_ = other.current_; +#else + if ( isArray_ ) + iterator_.array_ = other.iterator_.array_; + iterator_.map_ = other.iterator_.map_; +#endif +} + + +Value +ValueIteratorBase::key() const +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + const Value::CZString czstring = (*current_).first; + if ( czstring.c_str() ) + { + if ( czstring.isStaticString() ) + return Value( StaticString( czstring.c_str() ) ); + return Value( czstring.c_str() ); + } + return Value( czstring.index() ); +#else + if ( isArray_ ) + return Value( ValueInternalArray::indexOf( iterator_.array_ ) ); + bool isStatic; + const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic ); + if ( isStatic ) + return Value( StaticString( memberName ) ); + return Value( memberName ); +#endif +} + + +UInt +ValueIteratorBase::index() const +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + const Value::CZString czstring = (*current_).first; + if ( !czstring.c_str() ) + return czstring.index(); + return Value::UInt( -1 ); +#else + if ( isArray_ ) + return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) ); + return Value::UInt( -1 ); +#endif +} + + +const char * +ValueIteratorBase::memberName() const +{ +#ifndef JSON_VALUE_USE_INTERNAL_MAP + const char *name = (*current_).first.c_str(); + return name ? name : ""; +#else + if ( !isArray_ ) + return ValueInternalMap::key( iterator_.map_ ); + return ""; +#endif +} + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueConstIterator +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueConstIterator::ValueConstIterator() +{ +} + + +#ifndef JSON_VALUE_USE_INTERNAL_MAP +ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator ¤t ) + : ValueIteratorBase( current ) +{ +} +#else +ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state ) + : ValueIteratorBase( state ) +{ +} + +ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state ) + : ValueIteratorBase( state ) +{ +} +#endif + +ValueConstIterator & +ValueConstIterator::operator =( const ValueIteratorBase &other ) +{ + copy( other ); + return *this; +} + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueIterator +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueIterator::ValueIterator() +{ +} + + +#ifndef JSON_VALUE_USE_INTERNAL_MAP +ValueIterator::ValueIterator( const Value::ObjectValues::iterator ¤t ) + : ValueIteratorBase( current ) +{ +} +#else +ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state ) + : ValueIteratorBase( state ) +{ +} + +ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state ) + : ValueIteratorBase( state ) +{ +} +#endif + +ValueIterator::ValueIterator( const ValueConstIterator &other ) + : ValueIteratorBase( other ) +{ +} + +ValueIterator::ValueIterator( const ValueIterator &other ) + : ValueIteratorBase( other ) +{ +} + +ValueIterator & +ValueIterator::operator =( const SelfType &other ) +{ + copy( other ); + return *this; +} diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_writer.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_writer.cpp new file mode 100644 index 00000000..cdf4188f --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/json_writer.cpp @@ -0,0 +1,829 @@ +#include <json/writer.h> +#include <utility> +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <iostream> +#include <sstream> +#include <iomanip> + +#if _MSC_VER >= 1400 // VC++ 8.0 +#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. +#endif + +namespace Json { + +static bool isControlCharacter(char ch) +{ + return ch > 0 && ch <= 0x1F; +} + +static bool containsControlCharacter( const char* str ) +{ + while ( *str ) + { + if ( isControlCharacter( *(str++) ) ) + return true; + } + return false; +} +static void uintToString( unsigned int value, + char *¤t ) +{ + *--current = 0; + do + { + *--current = (value % 10) + '0'; + value /= 10; + } + while ( value != 0 ); +} + +std::string valueToString( Int value ) +{ + char buffer[32]; + char *current = buffer + sizeof(buffer); + bool isNegative = value < 0; + if ( isNegative ) + value = -value; + uintToString( UInt(value), current ); + if ( isNegative ) + *--current = '-'; + assert( current >= buffer ); + return current; +} + + +std::string valueToString( UInt value ) +{ + char buffer[32]; + char *current = buffer + sizeof(buffer); + uintToString( value, current ); + assert( current >= buffer ); + return current; +} + +std::string valueToString( double value ) +{ + char buffer[32]; +#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. + sprintf_s(buffer, sizeof(buffer), "%#.16g", value); +#else + sprintf(buffer, "%#.16g", value); +#endif + char* ch = buffer + strlen(buffer) - 1; + if (*ch != '0') return buffer; // nothing to truncate, so save time + while(ch > buffer && *ch == '0'){ + --ch; + } + char* last_nonzero = ch; + while(ch >= buffer){ + switch(*ch){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + --ch; + continue; + case '.': + // Truncate zeroes to save bytes in output, but keep one. + *(last_nonzero+2) = '\0'; + return buffer; + default: + return buffer; + } + } + return buffer; +} + + +std::string valueToString( bool value ) +{ + return value ? "true" : "false"; +} + +std::string valueToQuotedString( const char *value ) +{ + // Not sure how to handle unicode... + if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL && !containsControlCharacter( value )) + return std::string("\"") + value + "\""; + // We have to walk value and escape any special characters. + // Appending to std::string is not efficient, but this should be rare. + // (Note: forward slashes are *not* rare, but I am not escaping them.) + unsigned maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL + std::string result; + result.reserve(maxsize); // to avoid lots of mallocs + result += "\""; + for (const char* c=value; *c != 0; ++c) + { + switch(*c) + { + case '\"': + result += "\\\""; + break; + case '\\': + result += "\\\\"; + break; + case '\b': + result += "\\b"; + break; + case '\f': + result += "\\f"; + break; + case '\n': + result += "\\n"; + break; + case '\r': + result += "\\r"; + break; + case '\t': + result += "\\t"; + break; + //case '/': + // Even though \/ is considered a legal escape in JSON, a bare + // slash is also legal, so I see no reason to escape it. + // (I hope I am not misunderstanding something. + // blep notes: actually escaping \/ may be useful in javascript to avoid </ + // sequence. + // Should add a flag to allow this compatibility mode and prevent this + // sequence from occurring. + default: + if ( isControlCharacter( *c ) ) + { + std::ostringstream oss; + oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c); + result += oss.str(); + } + else + { + result += *c; + } + break; + } + } + result += "\""; + return result; +} + +// Class Writer +// ////////////////////////////////////////////////////////////////// +Writer::~Writer() +{ +} + + +// Class FastWriter +// ////////////////////////////////////////////////////////////////// + +FastWriter::FastWriter() + : yamlCompatiblityEnabled_( false ) +{ +} + + +void +FastWriter::enableYAMLCompatibility() +{ + yamlCompatiblityEnabled_ = true; +} + + +std::string +FastWriter::write( const Value &root ) +{ + document_ = ""; + writeValue( root ); + document_ += "\n"; + return document_; +} + + +void +FastWriter::writeValue( const Value &value ) +{ + switch ( value.type() ) + { + case nullValue: + document_ += "null"; + break; + case intValue: + document_ += valueToString( value.asInt() ); + break; + case uintValue: + document_ += valueToString( value.asUInt() ); + break; + case realValue: + document_ += valueToString( value.asDouble() ); + break; + case stringValue: + document_ += valueToQuotedString( value.asCString() ); + break; + case booleanValue: + document_ += valueToString( value.asBool() ); + break; + case arrayValue: + { + document_ += "["; + int size = value.size(); + for ( int index =0; index < size; ++index ) + { + if ( index > 0 ) + document_ += ","; + writeValue( value[index] ); + } + document_ += "]"; + } + break; + case objectValue: + { + Value::Members members( value.getMemberNames() ); + document_ += "{"; + for ( Value::Members::iterator it = members.begin(); + it != members.end(); + ++it ) + { + const std::string &name = *it; + if ( it != members.begin() ) + document_ += ","; + document_ += valueToQuotedString( name.c_str() ); + document_ += yamlCompatiblityEnabled_ ? ": " + : ":"; + writeValue( value[name] ); + } + document_ += "}"; + } + break; + } +} + + +// Class StyledWriter +// ////////////////////////////////////////////////////////////////// + +StyledWriter::StyledWriter() + : rightMargin_( 74 ) + , indentSize_( 3 ) +{ +} + + +std::string +StyledWriter::write( const Value &root ) +{ + document_ = ""; + addChildValues_ = false; + indentString_ = ""; + writeCommentBeforeValue( root ); + writeValue( root ); + writeCommentAfterValueOnSameLine( root ); + document_ += "\n"; + return document_; +} + + +void +StyledWriter::writeValue( const Value &value ) +{ + switch ( value.type() ) + { + case nullValue: + pushValue( "null" ); + break; + case intValue: + pushValue( valueToString( value.asInt() ) ); + break; + case uintValue: + pushValue( valueToString( value.asUInt() ) ); + break; + case realValue: + pushValue( valueToString( value.asDouble() ) ); + break; + case stringValue: + pushValue( valueToQuotedString( value.asCString() ) ); + break; + case booleanValue: + pushValue( valueToString( value.asBool() ) ); + break; + case arrayValue: + writeArrayValue( value); + break; + case objectValue: + { + Value::Members members( value.getMemberNames() ); + if ( members.empty() ) + pushValue( "{}" ); + else + { + writeWithIndent( "{" ); + indent(); + Value::Members::iterator it = members.begin(); + while ( true ) + { + const std::string &name = *it; + const Value &childValue = value[name]; + writeCommentBeforeValue( childValue ); + writeWithIndent( valueToQuotedString( name.c_str() ) ); + document_ += " : "; + writeValue( childValue ); + if ( ++it == members.end() ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + document_ += ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "}" ); + } + } + break; + } +} + + +void +StyledWriter::writeArrayValue( const Value &value ) +{ + unsigned size = value.size(); + if ( size == 0 ) + pushValue( "[]" ); + else + { + bool isArrayMultiLine = isMultineArray( value ); + if ( isArrayMultiLine ) + { + writeWithIndent( "[" ); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index =0; + while ( true ) + { + const Value &childValue = value[index]; + writeCommentBeforeValue( childValue ); + if ( hasChildValue ) + writeWithIndent( childValues_[index] ); + else + { + writeIndent(); + writeValue( childValue ); + } + if ( ++index == size ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + document_ += ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "]" ); + } + else // output on a single line + { + assert( childValues_.size() == size ); + document_ += "[ "; + for ( unsigned index =0; index < size; ++index ) + { + if ( index > 0 ) + document_ += ", "; + document_ += childValues_[index]; + } + document_ += " ]"; + } + } +} + + +bool +StyledWriter::isMultineArray( const Value &value ) +{ + int size = value.size(); + bool isMultiLine = size*3 >= rightMargin_ ; + childValues_.clear(); + for ( int index =0; index < size && !isMultiLine; ++index ) + { + const Value &childValue = value[index]; + isMultiLine = isMultiLine || + ( (childValue.isArray() || childValue.isObject()) && + childValue.size() > 0 ); + } + if ( !isMultiLine ) // check if line length > max line length + { + childValues_.reserve( size ); + addChildValues_ = true; + int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]' + for ( int index =0; index < size && !isMultiLine; ++index ) + { + writeValue( value[index] ); + lineLength += int( childValues_[index].length() ); + isMultiLine = isMultiLine && hasCommentForValue( value[index] ); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + + +void +StyledWriter::pushValue( const std::string &value ) +{ + if ( addChildValues_ ) + childValues_.push_back( value ); + else + document_ += value; +} + + +void +StyledWriter::writeIndent() +{ + if ( !document_.empty() ) + { + char last = document_[document_.length()-1]; + if ( last == ' ' ) // already indented + return; + if ( last != '\n' ) // Comments may add new-line + document_ += '\n'; + } + document_ += indentString_; +} + + +void +StyledWriter::writeWithIndent( const std::string &value ) +{ + writeIndent(); + document_ += value; +} + + +void +StyledWriter::indent() +{ + indentString_ += std::string( indentSize_, ' ' ); +} + + +void +StyledWriter::unindent() +{ + assert( int(indentString_.size()) >= indentSize_ ); + indentString_.resize( indentString_.size() - indentSize_ ); +} + + +void +StyledWriter::writeCommentBeforeValue( const Value &root ) +{ + if ( !root.hasComment( commentBefore ) ) + return; + document_ += normalizeEOL( root.getComment( commentBefore ) ); + document_ += "\n"; +} + + +void +StyledWriter::writeCommentAfterValueOnSameLine( const Value &root ) +{ + if ( root.hasComment( commentAfterOnSameLine ) ) + document_ += " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) ); + + if ( root.hasComment( commentAfter ) ) + { + document_ += "\n"; + document_ += normalizeEOL( root.getComment( commentAfter ) ); + document_ += "\n"; + } +} + + +bool +StyledWriter::hasCommentForValue( const Value &value ) +{ + return value.hasComment( commentBefore ) + || value.hasComment( commentAfterOnSameLine ) + || value.hasComment( commentAfter ); +} + + +std::string +StyledWriter::normalizeEOL( const std::string &text ) +{ + std::string normalized; + normalized.reserve( text.length() ); + const char *begin = text.c_str(); + const char *end = begin + text.length(); + const char *current = begin; + while ( current != end ) + { + char c = *current++; + if ( c == '\r' ) // mac or dos EOL + { + if ( *current == '\n' ) // convert dos EOL + ++current; + normalized += '\n'; + } + else // handle unix EOL & other char + normalized += c; + } + return normalized; +} + + +// Class StyledStreamWriter +// ////////////////////////////////////////////////////////////////// + +StyledStreamWriter::StyledStreamWriter( std::string indentation ) + : document_(NULL) + , rightMargin_( 74 ) + , indentation_( indentation ) +{ +} + + +void +StyledStreamWriter::write( std::ostream &out, const Value &root ) +{ + document_ = &out; + addChildValues_ = false; + indentString_ = ""; + writeCommentBeforeValue( root ); + writeValue( root ); + writeCommentAfterValueOnSameLine( root ); + *document_ << "\n"; + document_ = NULL; // Forget the stream, for safety. +} + + +void +StyledStreamWriter::writeValue( const Value &value ) +{ + switch ( value.type() ) + { + case nullValue: + pushValue( "null" ); + break; + case intValue: + pushValue( valueToString( value.asInt() ) ); + break; + case uintValue: + pushValue( valueToString( value.asUInt() ) ); + break; + case realValue: + pushValue( valueToString( value.asDouble() ) ); + break; + case stringValue: + pushValue( valueToQuotedString( value.asCString() ) ); + break; + case booleanValue: + pushValue( valueToString( value.asBool() ) ); + break; + case arrayValue: + writeArrayValue( value); + break; + case objectValue: + { + Value::Members members( value.getMemberNames() ); + if ( members.empty() ) + pushValue( "{}" ); + else + { + writeWithIndent( "{" ); + indent(); + Value::Members::iterator it = members.begin(); + while ( true ) + { + const std::string &name = *it; + const Value &childValue = value[name]; + writeCommentBeforeValue( childValue ); + writeWithIndent( valueToQuotedString( name.c_str() ) ); + *document_ << " : "; + writeValue( childValue ); + if ( ++it == members.end() ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + *document_ << ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "}" ); + } + } + break; + } +} + + +void +StyledStreamWriter::writeArrayValue( const Value &value ) +{ + unsigned size = value.size(); + if ( size == 0 ) + pushValue( "[]" ); + else + { + bool isArrayMultiLine = isMultineArray( value ); + if ( isArrayMultiLine ) + { + writeWithIndent( "[" ); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index =0; + while ( true ) + { + const Value &childValue = value[index]; + writeCommentBeforeValue( childValue ); + if ( hasChildValue ) + writeWithIndent( childValues_[index] ); + else + { + writeIndent(); + writeValue( childValue ); + } + if ( ++index == size ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + *document_ << ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "]" ); + } + else // output on a single line + { + assert( childValues_.size() == size ); + *document_ << "[ "; + for ( unsigned index =0; index < size; ++index ) + { + if ( index > 0 ) + *document_ << ", "; + *document_ << childValues_[index]; + } + *document_ << " ]"; + } + } +} + + +bool +StyledStreamWriter::isMultineArray( const Value &value ) +{ + int size = value.size(); + bool isMultiLine = size*3 >= rightMargin_ ; + childValues_.clear(); + for ( int index =0; index < size && !isMultiLine; ++index ) + { + const Value &childValue = value[index]; + isMultiLine = isMultiLine || + ( (childValue.isArray() || childValue.isObject()) && + childValue.size() > 0 ); + } + if ( !isMultiLine ) // check if line length > max line length + { + childValues_.reserve( size ); + addChildValues_ = true; + int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]' + for ( int index =0; index < size && !isMultiLine; ++index ) + { + writeValue( value[index] ); + lineLength += int( childValues_[index].length() ); + isMultiLine = isMultiLine && hasCommentForValue( value[index] ); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + + +void +StyledStreamWriter::pushValue( const std::string &value ) +{ + if ( addChildValues_ ) + childValues_.push_back( value ); + else + *document_ << value; +} + + +void +StyledStreamWriter::writeIndent() +{ + /* + Some comments in this method would have been nice. ;-) + + if ( !document_.empty() ) + { + char last = document_[document_.length()-1]; + if ( last == ' ' ) // already indented + return; + if ( last != '\n' ) // Comments may add new-line + *document_ << '\n'; + } + */ + *document_ << '\n' << indentString_; +} + + +void +StyledStreamWriter::writeWithIndent( const std::string &value ) +{ + writeIndent(); + *document_ << value; +} + + +void +StyledStreamWriter::indent() +{ + indentString_ += indentation_; +} + + +void +StyledStreamWriter::unindent() +{ + assert( indentString_.size() >= indentation_.size() ); + indentString_.resize( indentString_.size() - indentation_.size() ); +} + + +void +StyledStreamWriter::writeCommentBeforeValue( const Value &root ) +{ + if ( !root.hasComment( commentBefore ) ) + return; + *document_ << normalizeEOL( root.getComment( commentBefore ) ); + *document_ << "\n"; +} + + +void +StyledStreamWriter::writeCommentAfterValueOnSameLine( const Value &root ) +{ + if ( root.hasComment( commentAfterOnSameLine ) ) + *document_ << " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) ); + + if ( root.hasComment( commentAfter ) ) + { + *document_ << "\n"; + *document_ << normalizeEOL( root.getComment( commentAfter ) ); + *document_ << "\n"; + } +} + + +bool +StyledStreamWriter::hasCommentForValue( const Value &value ) +{ + return value.hasComment( commentBefore ) + || value.hasComment( commentAfterOnSameLine ) + || value.hasComment( commentAfter ); +} + + +std::string +StyledStreamWriter::normalizeEOL( const std::string &text ) +{ + std::string normalized; + normalized.reserve( text.length() ); + const char *begin = text.c_str(); + const char *end = begin + text.length(); + const char *current = begin; + while ( current != end ) + { + char c = *current++; + if ( c == '\r' ) // mac or dos EOL + { + if ( *current == '\n' ) // convert dos EOL + ++current; + normalized += '\n'; + } + else // handle unix EOL & other char + normalized += c; + } + return normalized; +} + + +std::ostream& operator<<( std::ostream &sout, const Value &root ) +{ + Json::StyledStreamWriter writer; + writer.write(sout, root); + return sout; +} + + +} // namespace Json diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/plugin.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/public/plugin.cpp new file mode 100644 index 00000000..6906275e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/plugin.cpp @@ -0,0 +1,320 @@ +#include "plugin.h" +#include "tokenizer.h" + +#ifdef _WINDOWS +#include <windows.h> +BOOL APIENTRY DllMain( HANDLE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved ) +{ + return TRUE; +} +#else +#include <errno.h> +#include <string.h> + +extern int errno; +#endif + +SendPluginEv SendPluginEvent; + +string g_GetSysErrMsg( void ) +{ + string strError = "Unknown"; + // Problem loading +#ifdef _WINDOWS + int nErrorCode = GetLastError(); + LPTSTR s; + if ( ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, nErrorCode, 0, ( LPTSTR ) &s, 0, NULL ) ) + { + strError = s; + } + else + { + char szBuf[ 20 ]; + _snprintf_s( szBuf, _countof(szBuf), 19, "%d", nErrorCode ); + strError = szBuf; + } +#else + char szError[80]; + if ( strerror_r( errno, szError, sizeof(szError) ) ) + { + strError = "no description found"; + } + else + { + strError = szError; + } +#endif + return strError; +} + +void g_sleep( unsigned int mseconds ) +{ +#ifdef _WINDOWS + Sleep( mseconds ); +#else + usleep( mseconds * 1000 ); +#endif +} + +string& g_trim( string& str ) +{ + // Whitespace characters + char whspc[] = " \t\r\n\v\f"; + + // Whack off first part + size_t pos = str.find_first_not_of( whspc ); + + if ( pos != string::npos ) + str.replace( 0, pos, "" ); + + // Whack off trailing stuff + pos = str.find_last_not_of( whspc ); + + if ( pos != string::npos ) + str.replace( pos + 1, str.length() - pos, "" ); + + return str; +} + +void g_tokenize( const string& str, const string& delimiters, vector<string>& tokens ) +{ + tokenize( str, tokens, delimiters ); +} + +char* SetEventFunc( SendPluginEv funcPtr ) +{ + static char * szObjList = onGetObjList(); + SendPluginEvent = funcPtr; + return szObjList; +} + + +const int nMAXSIZE = 512; +char* g_pszRetVal = NULL; + +//----------------------------------------------------------- +// Map from an object Id to an object instance +//----------------------------------------------------------- +typedef std::map<string, JSExt*> StringToJExt_T; + +//----------------------------------------------------------- +// Map from a browser context to an id mapping +//----------------------------------------------------------- +typedef std::map<void*, StringToJExt_T*> VoidToMap_T; + +VoidToMap_T g_context2Map; + +class GlobalSharedModule +{ + +public: + GlobalSharedModule( void ) + { + g_pszRetVal = new char[ nMAXSIZE ]; + } + + ~GlobalSharedModule() + { + delete [] g_pszRetVal; + + VoidToMap_T::iterator posMaps; + + for ( posMaps = g_context2Map.begin(); posMaps != g_context2Map.end(); ++posMaps ) + { + StringToJExt_T& id2Obj = *posMaps->second; + StringToJExt_T::iterator posMap; + + for ( posMap = id2Obj.begin(); posMap != id2Obj.end(); ++posMap ) + { + JSExt* pJSExt = posMap->second; + + if ( pJSExt->CanDelete() ) + { + delete pJSExt; + } + } + + id2Obj.erase( id2Obj.begin(), id2Obj.end() ); + } + + g_context2Map.erase( g_context2Map.begin(), g_context2Map.end() ); + } +}; + +GlobalSharedModule g_sharedModule; + +char* g_str2global( const string& strRetVal ) +{ + int nLen = strRetVal.size(); + + if ( nLen >= nMAXSIZE ) + { + delete [] g_pszRetVal; + g_pszRetVal = new char[ nLen + 1 ]; + } + + else + { + // To minimaize the number of memory reallocations, the assumption + // is that in most times this will be the case + delete [] g_pszRetVal; + g_pszRetVal = new char[ nMAXSIZE ]; + } + + strcpy( g_pszRetVal, strRetVal.c_str() ); + return g_pszRetVal; +} + +bool g_unregisterObject( const string& strObjId, void* pContext ) +{ + // Called by the plugin extension implementation + // if the extension handles the deletion of its object + + StringToJExt_T * pID2Obj = NULL; + + VoidToMap_T::iterator iter = g_context2Map.find( pContext ); + + if ( iter != g_context2Map.end() ) + { + pID2Obj = iter->second; + } + else + { + return false; + } + + StringToJExt_T& mapID2Obj = *pID2Obj; + + StringToJExt_T::iterator r = mapID2Obj.find( strObjId ); + + if ( r == mapID2Obj.end() ) + { + return false; + } + + mapID2Obj.erase( strObjId ); + return true; +} + +char* InvokeFunction( const char* szCommand, void* pContext ) +{ + StringToJExt_T * pID2Obj = NULL; + + VoidToMap_T::iterator iter = g_context2Map.find( pContext ); + + if ( iter != g_context2Map.end() ) + { + pID2Obj = iter->second; + } + else + { + pID2Obj = new StringToJExt_T; + g_context2Map[ pContext ] = pID2Obj; + } + + StringToJExt_T& mapID2Obj = *pID2Obj; + + string strFullCommand = szCommand; + vector<string> arParams; + g_tokenize( strFullCommand, " ", arParams ); + string strCommand = arParams[ 0 ]; + string strRetVal = szERROR; + + if ( strCommand == szCREATE ) + { + string strClassName = arParams[ 1 ]; + string strObjId = arParams[ 2 ]; + + StringToJExt_T::iterator r = mapID2Obj.find( strObjId ); + + if ( r != mapID2Obj.end() ) + { + strRetVal += strObjId; + strRetVal += " :Object already exists."; + return g_str2global( strRetVal ); + } + + JSExt* pJSExt = onCreateObject( strClassName, strObjId ); + + if ( pJSExt == NULL ) + { + strRetVal += strObjId; + strRetVal += " :Unknown object type "; + strRetVal += strClassName; + return g_str2global( strRetVal ); + } + + pJSExt->m_pContext = pContext; + mapID2Obj[ strObjId ] = pJSExt; + + strRetVal = szOK; + strRetVal += strObjId; + return g_str2global( strRetVal ); + } + else + if ( strCommand == szINVOKE ) + { + string strObjId = arParams[ 1 ]; + string strMethod = arParams[ 2 ]; + + StringToJExt_T::iterator r = mapID2Obj.find( strObjId ); + + if ( r == mapID2Obj.end() ) + { + strRetVal += strObjId; + strRetVal += " :No object found for id."; + return g_str2global( strRetVal ); + } + + JSExt* pJSExt = r->second; + + size_t nLoc = strFullCommand.find( strObjId ); + + if ( nLoc == string::npos ) + { + strRetVal += strObjId; + strRetVal += " :Internal InvokeMethod error."; + return g_str2global( strRetVal ); + } + + if ( strMethod == szDISPOSE ) + { + StringToJExt_T::iterator r = mapID2Obj.find( strObjId ); + + if ( r == mapID2Obj.end() ) + { + strRetVal = szERROR; + strRetVal += strObjId; + return g_str2global( strRetVal ); + } + + JSExt * pJSExt = mapID2Obj[ strObjId ]; + + if ( pJSExt->CanDelete() ) + { + delete pJSExt; + } + + mapID2Obj.erase( strObjId ); + strRetVal = szOK; + strRetVal += strObjId; + return g_str2global( strRetVal ); + } + + size_t nSuffixLoc = nLoc + strObjId.size(); + string strInvoke = strFullCommand.substr( nSuffixLoc ); + strInvoke = g_trim( strInvoke ); + strRetVal = pJSExt->InvokeMethod( strInvoke ); + return g_str2global( strRetVal ); + } + + strRetVal += " :Unknown command "; + strRetVal += strCommand; + return g_str2global( strRetVal ); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/plugin.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/plugin.h new file mode 100644 index 00000000..4ef71169 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/plugin.h @@ -0,0 +1,70 @@ +#ifndef _PLUGIN_H +#define _PLUGIN_H + +#include <map> +#include <string> +#include <vector> +#include <unistd.h> +//#include "tokenizer.h" + +using namespace std; + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +//%% Functions exported by this DLL +//%% Should always be only SetEventFunc and InvokeFunction +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// g++ requires extern "C" otherwise the names of SetEventFunc and InvokeFunction +// are mangled C++ style. MS Visual Studio doesn't seem to care though. +extern "C" +{ + typedef void (*SendPluginEv)( const char* szEvent, void* pContext ); + char* SetEventFunc(SendPluginEv funcPtr); + char* InvokeFunction( const char* szCommand, void* pContext ); +} + +// JNEXT Framework function of the form: +// typedef void (*SendPluginEv)( const char* szEvent ); +// used to notify JavaScript of an asynchronous event +extern SendPluginEv SendPluginEvent; + +///////////////////////////////////////////////////////////////////////// +// Constants and methods common to all JNEXT extensions types +///////////////////////////////////////////////////////////////////////// +#define szERROR "Error " +#define szOK "Ok " + +#define szDISPOSE "Dispose" +#define szINVOKE "InvokeMethod" +#define szCREATE "CreateObj" + +///////////////////////////////////////////////////////////////////////// +// Utility functions +///////////////////////////////////////////////////////////////////////// +string& g_trim( string& str ); +void g_tokenize(const string& str,const string& delimiters, vector<string>& tokens); +char* g_str2static( const string& strRetVal ); +void g_sleep( unsigned int mseconds ); +bool g_unregisterObject( const string& strObjId, void* pContext ); + + +///////////////////////////////////////////////////////////////////////// +// Abstract extension object +///////////////////////////////////////////////////////////////////////// +class JSExt +{ +public: + virtual ~JSExt() {}; + virtual string InvokeMethod( const string& strCommand ) = 0; + virtual bool CanDelete( void ) = 0; + virtual void TryDelete( void ) {} +public: + void* m_pContext; +}; + +///////////////////////////////////////////////////////////////////////// +// Callback functions to be implemented by the plugin implementation +///////////////////////////////////////////////////////////////////////// +extern char* onGetObjList( void ); +extern JSExt* onCreateObject( const string& strClassName, const string& strObjId ); + +#endif diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/tokenizer.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/public/tokenizer.cpp new file mode 100644 index 00000000..4a39573b --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/tokenizer.cpp @@ -0,0 +1,222 @@ +/************************************************************************ +The zlib/libpng License + +Copyright (c) 2006 Joerg Wiedenmann + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from +the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; +you must not claim that you wrote the original software. +If you use this software in a product, an acknowledgment +in the product documentation would be appreciated but is +not required. + +2. Altered source versions must be plainly marked as such, +and must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source distribution. + +***********************************************************************/ + +/******************************************************************** + created: 2006-01-28 + filename: tokenizer.cpp + author: Jörg Wiedenmann + + purpose: A tokenizer function which provides a very + customizable way of breaking up strings. + + history: 2006-01-28, Original version + 2006-03-04, Fixed a small parsing bug, thanks Elias. +*********************************************************************/ + +#include "tokenizer.h" + +using namespace std; + +void tokenize ( const string& str, vector<string>& result, + const string& delimiters, const string& delimiters_preserve, + const string& quote, const string& esc ) +{ + // clear the vector + if ( false == result.empty() ) + { + result.clear(); + } + + string::size_type pos = 0; // the current position (char) in the string + char ch = 0; // buffer for the current character + char delimiter = 0; // the buffer for the delimiter char which + // will be added to the tokens if the delimiter + // is preserved + char current_quote = 0; // the char of the current open quote + bool quoted = false; // indicator if there is an open quote + string token; // string buffer for the token + bool token_complete = false; // indicates if the current token is + // read to be added to the result vector + string::size_type len = str.length(); // length of the input-string + + // for every char in the input-string + while ( len > pos ) + { + // get the character of the string and reset the delimiter buffer + ch = str.at(pos); + delimiter = 0; + + // assume ch isn't a delimiter + bool add_char = true; + + // check ... + + // ... if the delimiter is an escaped character + bool escaped = false; // indicates if the next char is protected + if ( false == esc.empty() ) // check if esc-chars are provided + { + if ( string::npos != esc.find_first_of(ch) ) + { + // get the escaped char + ++pos; + if ( pos < len ) // if there are more chars left + { + // get the next one + ch = str.at(pos); + + // add the escaped character to the token + add_char = true; + } + else // cannot get any more characters + { + // don't add the esc-char + add_char = false; + } + + // ignore the remaining delimiter checks + escaped = true; + } + } + + // ... if the delimiter is a quote + if ( false == quote.empty() && false == escaped ) + { + // if quote chars are provided and the char isn't protected + if ( string::npos != quote.find_first_of(ch) ) + { + // if not quoted, set state to open quote and set + // the quote character + if ( false == quoted ) + { + quoted = true; + current_quote = ch; + + // don't add the quote-char to the token + add_char = false; + } + else // if quote is open already + { + // check if it is the matching character to close it + if ( current_quote == ch ) + { + // close quote and reset the quote character + quoted = false; + current_quote = 0; + + // don't add the quote-char to the token + add_char = false; + } + } // else + } + } + + // ... if the delimiter isn't preserved + if ( false == delimiters.empty() && false == escaped && + false == quoted ) + { + // if a delimiter is provided and the char isn't protected by + // quote or escape char + if ( string::npos != delimiters.find_first_of(ch) ) + { + // if ch is a delimiter and the token string isn't empty + // the token is complete + if ( false == token.empty() ) // BUGFIX: 2006-03-04 + { + token_complete = true; + } + + // don't add the delimiter to the token + add_char = false; + } + } + + // ... if the delimiter is preserved - add it as a token + bool add_delimiter = false; + if ( false == delimiters_preserve.empty() && false == escaped && + false == quoted ) + { + // if a delimiter which will be preserved is provided and the + // char isn't protected by quote or escape char + if ( string::npos != delimiters_preserve.find_first_of(ch) ) + { + // if ch is a delimiter and the token string isn't empty + // the token is complete + if ( false == token.empty() ) // BUGFIX: 2006-03-04 + { + token_complete = true; + } + + // don't add the delimiter to the token + add_char = false; + + // add the delimiter + delimiter = ch; + add_delimiter = true; + } + } + + + // add the character to the token + if ( true == add_char ) + { + // add the current char + token.push_back( ch ); + } + + // add the token if it is complete + if ( true == token_complete && false == token.empty() ) + { + // add the token string + result.push_back( token ); + + // clear the contents + token.clear(); + + // build the next token + token_complete = false; + } + + // add the delimiter + if ( true == add_delimiter ) + { + // the next token is the delimiter + string delim_token; + delim_token.push_back( delimiter ); + result.push_back( delim_token ); + + // REMOVED: 2006-03-04, Bugfix + } + + // repeat for the next character + ++pos; + } // while + + // add the final token + if ( false == token.empty() ) + { + result.push_back( token ); + } +} diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/public/tokenizer.h b/plugins/com.ionic.keyboard/src/blackberry10/native/public/tokenizer.h new file mode 100644 index 00000000..75f567ce --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/public/tokenizer.h @@ -0,0 +1,55 @@ +/************************************************************************ +The zlib/libpng License + +Copyright (c) 2006 Joerg Wiedenmann + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from +the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment + in the product documentation would be appreciated but is + not required. + +2. Altered source versions must be plainly marked as such, + and must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source distribution. + +***********************************************************************/ + +/******************************************************************** + created: 2006-01-28 + filename: tokenizer.cpp + author: Jörg Wiedenmann + + purpose: A tokenizer function which provides a very + customizable way of breaking up strings. +*********************************************************************/ + +#include <vector> +#include <string> +using namespace std; + +// Function to break up a string into tokens +// +// Parameters: +//----------- +// str = the input string that will be tokenized +// result = the tokens for str +// delimiters = the delimiter characters +// delimiters preserve = same as above, but the delimiter characters +// will be put into the result as a token +// quote = characters to protect the enclosed characters +// esc = characters to protect a single character +// + +void tokenize ( const string& str, vector<string>& result, + const string& delimiters, const string& delimiters_preserve = "", + const string& quote = "\"", const string& esc = "\\" ); diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_reader.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_reader.o Binary files differnew file mode 100644 index 00000000..16859fdb --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_reader.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_value.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_value.o Binary files differnew file mode 100644 index 00000000..396e7e4d --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_value.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_writer.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_writer.o Binary files differnew file mode 100644 index 00000000..7d1452d4 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/json_writer.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/plugin.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/plugin.o Binary files differnew file mode 100644 index 00000000..13048453 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/plugin.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/tokenizer.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/tokenizer.o Binary files differnew file mode 100644 index 00000000..4b4683cc --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/public/tokenizer.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/CallKeyboard.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/CallKeyboard.o Binary files differnew file mode 100644 index 00000000..c67ac9e6 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/CallKeyboard.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/Logger.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/Logger.o Binary files differnew file mode 100644 index 00000000..7bb472f2 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/Logger.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/keyboard_js.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/keyboard_js.o Binary files differnew file mode 100644 index 00000000..2a578357 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/keyboard_js.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/keyboard_ndk.o b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/keyboard_ndk.o Binary files differnew file mode 100644 index 00000000..989dc0b3 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/simulator/src/keyboard_ndk.o diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/src/Logger.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/src/Logger.cpp new file mode 100644 index 00000000..57b7075e --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/src/Logger.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013 BlackBerry Limited + * + * Licensed 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. + */ + +#include "Logger.hpp" +#include "keyboard_js.hpp" +#include <slog2.h> + +namespace webworks { + +Logger::Logger(const char* name, Keyboard_JS *parent): m_pParent(parent) { + buffer_config.buffer_set_name = name; + buffer_config.num_buffers = 2; + buffer_config.verbosity_level = SLOG2_DEBUG1; + + /* Configure the first buffer, using 7 x 4KB pages. This larger buffer will be used for + very chatty logging. Our goal is to have 30-60 seconds of history at any given time, + so we will want to log at a rate of around one log line with a string of 16 bytes + long every 150 milliseconds. + */ + + buffer_config.buffer_config[0].buffer_name = "low_priority"; + buffer_config.buffer_config[0].num_pages = 7; + + /* Configure the second buffer, which we will use for high level info logging that is very + infrequent, but we want a longer history (hours or maybe even over a day or two). This + buffer uses 1 x 4KB. + */ + + buffer_config.buffer_config[1].buffer_name = "high_priority"; + buffer_config.buffer_config[1].num_pages = 1; + + /* Register the buffer set. */ + + if( -1 == slog2_register( &buffer_config, buffer_handle, 0 ) ) { + fprintf( stderr, "Error registering slogger2 buffer!\n" ); + } else { + info("Created slogger2 buffers"); + } + +} + +Logger::~Logger() { + critical("slogger2 buffers reset"); + slog2_reset(); +} + +int Logger::log(slog2_buffer_t buffer, _Uint8t severity, const char* message) { + return slog2c(buffer, 0, severity, message); +} + +int Logger::debug(const char* message) { + return log(lowPriorityBuffer(), SLOG2_DEBUG1, message); +} + +int Logger::info(const char* message) { + return log(lowPriorityBuffer(), SLOG2_INFO, message); +} + +int Logger::notice(const char* message) { + return log(lowPriorityBuffer(), SLOG2_NOTICE, message); +} + +int Logger::warn(const char* message) { + return log(lowPriorityBuffer(), SLOG2_WARNING, message); +} + +int Logger::error(const char* message) { + return log(hiPriorityBuffer(), SLOG2_ERROR, message); +} + +int Logger::critical(const char* message) { + return log(hiPriorityBuffer(), SLOG2_CRITICAL, message); +} + +int Logger::setVerbosity(_Uint8t verbosity) { + return slog2_set_verbosity(buffer_handle[0], verbosity); +} + +_Uint8t Logger::getVerbosity() { + return slog2_get_verbosity(buffer_handle[0]); +} + +slog2_buffer_t Logger::hiPriorityBuffer() { + return buffer_handle[1]; +} + +slog2_buffer_t Logger::lowPriorityBuffer() { + return buffer_handle[0]; +} + +} /* namespace webworks */ diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/src/Logger.hpp b/plugins/com.ionic.keyboard/src/blackberry10/native/src/Logger.hpp new file mode 100644 index 00000000..ca379ca7 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/src/Logger.hpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013 BlackBerry Limited + * + * Licensed 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. + */ + +#ifndef LOGGER_HPP_ +#define LOGGER_HPP_ + +#include <string> +#include <slog2.h> + +class Keyboard_JS; + +namespace webworks { + +class Logger { +public: + explicit Logger(const char* name, Keyboard_JS *parent = NULL); + virtual ~Logger(); + int debug(const char* message); + int info(const char* message); + int notice(const char* message); + int warn(const char* message); + int error(const char* message); + int critical(const char* message); + int setVerbosity(_Uint8t verbosity); + _Uint8t getVerbosity(); + slog2_buffer_t hiPriorityBuffer(); + slog2_buffer_t lowPriorityBuffer(); +private: + Keyboard_JS *m_pParent; + slog2_buffer_set_config_t buffer_config; + slog2_buffer_t buffer_handle[2]; + int log(slog2_buffer_t buffer, _Uint8t severity, const char* message); +}; + +} /* namespace webworks */ +#endif /* LOGGER_HPP_ */ diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_js.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_js.cpp new file mode 100644 index 00000000..64250a14 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_js.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2013 BlackBerry Limited + * + * Licensed 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. + */ + +#include <string> +#include "../public/tokenizer.h" +#include "keyboard_js.hpp" +#include "keyboard_ndk.hpp" +#include <sstream> + +using namespace std; + +/** + * Default constructor. + */ +Keyboard_JS::Keyboard_JS(const std::string& id) : + m_id(id) { + m_pLogger = new webworks::Logger("Keyboard_JS", this); + m_pKeyboardController = new webworks::Keyboard_NDK(this); + + +} + +/** + * Keyboard_JS destructor. + */ +Keyboard_JS::~Keyboard_JS() { + if (m_pKeyboardController) + delete m_pKeyboardController; + if (m_pLogger) + delete m_pLogger; +} + +webworks::Logger* Keyboard_JS::getLog() { + return m_pLogger; +} + +/** + * This method returns the list of objects implemented by this native + * extension. + */ +char* onGetObjList() { + static char name[] = "Keyboard_JS"; + return name; +} + +/** + * This method is used by JNext to instantiate the Keyboard_JS object when + * an object is created on the JavaScript server side. + */ +JSExt* onCreateObject(const string& className, const string& id) { + if (className == "Keyboard_JS") { + return new Keyboard_JS(id); + } + + return NULL; +} + +/** + * Method used by JNext to determine if the object can be deleted. + */ +bool Keyboard_JS::CanDelete() { + return true; +} + +/** + * It will be called from JNext JavaScript side with passed string. + * This method implements the interface for the JavaScript to native binding + * for invoking native code. This method is triggered when JNext.invoke is + * called on the JavaScript side with this native objects id. + */ +string Keyboard_JS::InvokeMethod(const string& command) { + // format must be: "command callbackId params" + size_t commandIndex = command.find_first_of(" "); + std::string strCommand = command.substr(0, commandIndex); + size_t callbackIndex = command.find_first_of(" ", commandIndex + 1); + std::string callbackId = command.substr(commandIndex + 1, callbackIndex - commandIndex - 1); + std::string arg = command.substr(callbackIndex + 1, command.length()); + + // based on the command given, run the appropriate method in keyboard_ndk.cpp + if (strCommand == "showKeyboard") { + m_pKeyboardController->callKeyboardEmail(); + return "Show Keyboard"; + } else if (strCommand == "closeKeyboard") { + m_pKeyboardController->cancelKeyboard(); + return "Cancel Keyboard"; + } + else if(strCommand == "startService"){ + m_pKeyboardController->keyboardStartThread(); + return "Starting Service"; + } + + strCommand.append(";"); + strCommand.append(command); + return strCommand; +} + +// Notifies JavaScript of an event +void Keyboard_JS::NotifyEvent(const std::string& event) { + std::string eventString = m_id + " "; + eventString.append(event); + SendPluginEvent(eventString.c_str(), m_pContext); + +} + diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_js.hpp b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_js.hpp new file mode 100644 index 00000000..1ed3bb78 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_js.hpp @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2013 BlackBerry Limited +* +* Licensed 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. +*/ + +#ifndef Keyboard_JS_HPP_ +#define Keyboard_JS_HPP_ + +#include <string> +#include "../public/plugin.h" +#include "keyboard_ndk.hpp" +#include "Logger.hpp" + + +class Keyboard_JS: public JSExt { + +public: + explicit Keyboard_JS(const std::string& id); + virtual ~Keyboard_JS(); + virtual bool CanDelete(); + virtual std::string InvokeMethod(const std::string& command); + void NotifyEvent(const std::string& event); + webworks::Logger* getLog(); +private: + std::string m_id; + webworks::Keyboard_NDK *m_pKeyboardController; + webworks::Logger *m_pLogger; + +}; + +#endif /* Keyboard_JS_HPP_ */ diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_ndk.cpp b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_ndk.cpp new file mode 100644 index 00000000..26b2e39a --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_ndk.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2013 BlackBerry Limited + * + * Licensed 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. + */ + +#include <string> +#include <sstream> +#include <json/reader.h> +#include <json/writer.h> +#include <pthread.h> +#include "keyboard_ndk.hpp" +#include "keyboard_js.hpp" +#include <QtCore> +namespace webworks { + +Keyboard_NDK::Keyboard_NDK(Keyboard_JS *parent): + m_pParent(parent), + keyboardProperty(50), + keyboardThreadCount(1), + threadHalt(true), + m_thread(0) { + pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + bps_initialize(); + + virtualkeyboard_request_events(0); + + virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_EMAIL,VIRTUALKEYBOARD_ENTER_DEFAULT); + + m_pParent->getLog()->info("Keyboard Created"); + + +} + + +Keyboard_NDK::~Keyboard_NDK() { + //bps_shutdown(); +} + + +// Loops and runs the callback method +void* KeyboardThread(void* parent) { + Keyboard_NDK *pParent = static_cast<Keyboard_NDK *>(parent); + + sleep(1); + + // 1. Start the library + bps_initialize(); + + // 2. Request events to flow into the event queue + virtualkeyboard_request_events(0); + + sleep(3); + // 3. Use any service at any time + //virtualkeyboard_show(); // Show the virtual keyboard + + // 4. Listen for events + for (;;) { + // get an event + bps_event_t *event; + bps_get_event(&event, -1); // blocking + + // handle the event + pParent->event(event); + } + return NULL; +} + +// Starts the thread and returns a message on status +std::string Keyboard_NDK::keyboardStartThread() { + m_pParent->NotifyEvent("Teste"); + if (!m_thread) { + m_pParent->NotifyEvent("Teste"); + int rc; + rc = pthread_mutex_lock(&mutex); + threadHalt = false; + rc = pthread_cond_signal(&cond); + rc = pthread_mutex_unlock(&mutex); + + pthread_attr_t thread_attr; + pthread_attr_init(&thread_attr); + pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); + + pthread_create(&m_thread, &thread_attr, KeyboardThread, + static_cast<void *>(this)); + pthread_attr_destroy(&thread_attr); + //threadCallbackId = callbackId; + m_pParent->getLog()->info("Thread Started"); + return "Thread Started"; + } else { + m_pParent->getLog()->warn("Thread Started but already running"); + return "Thread Running"; + } +} + + +void Keyboard_NDK::event(bps_event_t *event) { + Json::FastWriter writer; + Json::Value root; + root["threadCount"] = "10"; + int domain = bps_event_get_domain(event); + if (domain == virtualkeyboard_get_domain()) { + int code = bps_event_get_code(event); + int a; + std::string str; + std::string eventString; + std::ostringstream strs; + switch(code) { + case VIRTUALKEYBOARD_EVENT_VISIBLE: + eventString = "native.keyboardshow"; + eventString.append(" "); + virtualkeyboard_get_height(&a) ; + strs << a; + str = strs.str(); + eventString.append("{\"keyboardHeight\":\""+str+"\"}"); + m_pParent->NotifyEvent(eventString); + + break; + case VIRTUALKEYBOARD_EVENT_HIDDEN: + + m_pParent->NotifyEvent("native.keyboardhide"); + break; + } + } + +} +void Keyboard_NDK::callKeyboardEmail(){ + virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_EMAIL,VIRTUALKEYBOARD_ENTER_SEND); + virtualkeyboard_show(); +} + +void Keyboard_NDK::callKeyboardNumber(){ + + virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_NUMBER,VIRTUALKEYBOARD_ENTER_SEND); + virtualkeyboard_show(); +} +void Keyboard_NDK::cancelKeyboard(){ + virtualkeyboard_hide(); +} + + + + +} diff --git a/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_ndk.hpp b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_ndk.hpp new file mode 100644 index 00000000..01062274 --- /dev/null +++ b/plugins/com.ionic.keyboard/src/blackberry10/native/src/keyboard_ndk.hpp @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2013 BlackBerry Limited +* +* Licensed 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. +*/ + +#ifndef Keyboard_NDK_HPP_ +#define Keyboard_NDK_HPP_ + +#include <string> +#include <pthread.h> +#include <bb/AbstractBpsEventHandler> +#include <bps/bps.h> +#include<bps/netstatus.h> +#include<bps/locale.h> +#include<bps/virtualkeyboard.h> +#include<bps/navigator.h> +#include <bps/event.h> +#include <string> +#include <sstream> + +class Keyboard_JS; + +namespace webworks { + +class Keyboard_NDK { +public: + explicit Keyboard_NDK(Keyboard_JS *parent = NULL); + virtual ~Keyboard_NDK(); + virtual void event(bps_event_t *event); + + void callKeyboardEmail(); // Method Calls the Keyboard style Email (default) + + void callKeyboardNumber(); // Method Calls the Keyboard style number + + void cancelKeyboard(); // Method cancel the keyboard + + std::string keyboardStartThread(); + + + + + + + +private: + + Keyboard_JS *m_pParent; + int keyboardProperty; + int keyboardThreadCount; + bool threadHalt; + std::string threadCallbackId; + pthread_t m_thread; + pthread_cond_t cond; + pthread_mutex_t mutex; + +}; + +} // namespace webworks + +#endif /* Keyboard_NDK_HPP_ */ diff --git a/plugins/com.ionic.keyboard/src/ios/IonicKeyboard.h b/plugins/com.ionic.keyboard/src/ios/IonicKeyboard.h new file mode 100644 index 00000000..b54f430d --- /dev/null +++ b/plugins/com.ionic.keyboard/src/ios/IonicKeyboard.h @@ -0,0 +1,13 @@ +#import <Cordova/CDVPlugin.h> + +@interface IonicKeyboard : CDVPlugin <UIScrollViewDelegate> { + @protected + id _keyboardShowObserver, _keyboardHideObserver; +} + +@property (readwrite, assign) BOOL hideKeyboardAccessoryBar; +@property (readwrite, assign) BOOL disableScroll; +//@property (readwrite, assign) BOOL styleDark; + +@end + diff --git a/plugins/com.ionic.keyboard/src/ios/IonicKeyboard.m b/plugins/com.ionic.keyboard/src/ios/IonicKeyboard.m new file mode 100644 index 00000000..045cc65f --- /dev/null +++ b/plugins/com.ionic.keyboard/src/ios/IonicKeyboard.m @@ -0,0 +1,160 @@ +#import "IonicKeyboard.h" +#import "UIWebViewExtension.h" +#import <Cordova/CDVAvailability.h> + +@implementation IonicKeyboard + +@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar; +@synthesize disableScroll = _disableScroll; +//@synthesize styleDark = _styleDark; + +- (void)pluginInitialize { + + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + __weak IonicKeyboard* weakSelf = self; + + //set defaults + self.hideKeyboardAccessoryBar = NO; + self.disableScroll = NO; + //self.styleDark = NO; + + _keyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification* notification) { + + CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil]; + + [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]]; + + //deprecated + [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]]; + }]; + + _keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification* notification) { + [weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "]; + + //deprecated + [weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "]; + }]; +} +- (BOOL)disableScroll { + return _disableScroll; +} + +- (void)setDisableScroll:(BOOL)disableScroll { + if (disableScroll == _disableScroll) { + return; + } + if (disableScroll) { + self.webView.scrollView.scrollEnabled = NO; + self.webView.scrollView.delegate = self; + } + else { + self.webView.scrollView.scrollEnabled = YES; + self.webView.scrollView.delegate = nil; + } + + _disableScroll = disableScroll; +} + + +- (BOOL)hideKeyboardAccessoryBar { + return _hideKeyboardAccessoryBar; +} + +- (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar { + if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar) { + return; + } + if (hideKeyboardAccessoryBar) { + self.webView.hackishlyHidesInputAccessoryView = YES; + } + else { + self.webView.hackishlyHidesInputAccessoryView = NO; + } + + _hideKeyboardAccessoryBar = hideKeyboardAccessoryBar; +} + +/* +- (BOOL)styleDark { + return _styleDark; +} + +- (void)setStyleDark:(BOOL)styleDark { + if (styleDark == _styleDark) { + return; + } + if (styleDark) { + self.webView.styleDark = YES; + } + else { + self.webView.styleDark = NO; + } + + _styleDark = styleDark; +} +*/ + + +/* ------------------------------------------------------------- */ + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView { + [scrollView setContentOffset: CGPointZero]; +} + +/* ------------------------------------------------------------- */ + +- (void)dealloc { + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + + [nc removeObserver:self name:UIKeyboardWillShowNotification object:nil]; + [nc removeObserver:self name:UIKeyboardWillHideNotification object:nil]; +} + +/* ------------------------------------------------------------- */ + +- (void) disableScroll:(CDVInvokedUrlCommand*)command { + if (!command.arguments || ![command.arguments count]){ + return; + } + id value = [command.arguments objectAtIndex:0]; + + self.disableScroll = [value boolValue]; +} + +- (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command { + if (!command.arguments || ![command.arguments count]){ + return; + } + id value = [command.arguments objectAtIndex:0]; + + self.hideKeyboardAccessoryBar = [value boolValue]; +} + +- (void) close:(CDVInvokedUrlCommand*)command { + [self.webView endEditing:YES]; +} + +- (void) show:(CDVInvokedUrlCommand*)command { + NSLog(@"Showing keyboard not supported in iOS due to platform limitations."); +} + +/* +- (void) styleDark:(CDVInvokedUrlCommand*)command { + if (!command.arguments || ![command.arguments count]){ + return; + } + id value = [command.arguments objectAtIndex:0]; + + self.styleDark = [value boolValue]; +} +*/ + +@end + diff --git a/plugins/com.ionic.keyboard/src/ios/UIWebViewExtension.h b/plugins/com.ionic.keyboard/src/ios/UIWebViewExtension.h new file mode 100644 index 00000000..1d6c293d --- /dev/null +++ b/plugins/com.ionic.keyboard/src/ios/UIWebViewExtension.h @@ -0,0 +1,4 @@ +@interface UIWebView (HackishAccessoryHiding) +@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView; +//@property (nonatomic, assign) BOOL styleDark; +@end diff --git a/plugins/com.ionic.keyboard/src/ios/UIWebViewExtension.m b/plugins/com.ionic.keyboard/src/ios/UIWebViewExtension.m new file mode 100644 index 00000000..25403e6f --- /dev/null +++ b/plugins/com.ionic.keyboard/src/ios/UIWebViewExtension.m @@ -0,0 +1,109 @@ +#import <objc/runtime.h> +#import <UIKit/UIKit.h> +#import "UIWebViewExtension.h" + +//Credit: https://gist.github.com/bjhomer/2048571 +//Also: http://stackoverflow.com/a/23398487/1091751 +@implementation UIWebView (HackishAccessoryHiding) + +static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView"; +static Class hackishFixClass = Nil; + +- (UIView *)hackishlyFoundBrowserView { + UIScrollView *scrollView = self.scrollView; + + UIView *browserView = nil; + for (UIView *subview in scrollView.subviews) { + if ([NSStringFromClass([subview class]) hasPrefix:@"UIWebBrowserView"]) { + browserView = subview; + break; + } + } + return browserView; +} + +- (id)methodReturningNil { + return nil; +} + +- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass { + if (!hackishFixClass) { + Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0); + IMP nilImp = [self methodForSelector:@selector(methodReturningNil)]; + class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:"); + objc_registerClassPair(newClass); + + hackishFixClass = newClass; + } +} + +- (BOOL) hackishlyHidesInputAccessoryView { + UIView *browserView = [self hackishlyFoundBrowserView]; + return [browserView class] == hackishFixClass; +} + +- (void) setHackishlyHidesInputAccessoryView:(BOOL)value { + UIView *browserView = [self hackishlyFoundBrowserView]; + if (browserView == nil) { + return; + } + [self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]]; + + if (value) { + object_setClass(browserView, hackishFixClass); + } + else { + Class normalClass = objc_getClass("UIWebBrowserView"); + object_setClass(browserView, normalClass); + } + [browserView reloadInputViews]; +} +/* ---------------------------------------------------------------- */ + +/* +- (UIKeyboardAppearance) darkKeyboardAppearanceTemplateMethod { + return UIKeyboardAppearanceDark; +} + +- (UIKeyboardAppearance) lightKeyboardAppearanceTemplateMethod { + return UIKeyboardAppearanceLight; +} + +- (BOOL) styleDark { + UIView *browserView = [self hackishlyFoundBrowserView]; + if (browserView == nil) { + return false; + } + + Method m = class_getInstanceMethod( [self class], @selector( darkKeyboardAppearanceTemplateMethod ) ); + IMP imp = method_getImplementation( m ); + + Method m2 = class_getInstanceMethod( [browserView class], @selector(keyboardAppearance) ); + IMP imp2 = method_getImplementation( m2 ); + + return imp == imp2; +} + +- (void) setStyleDark:(BOOL)styleDark { + UIView *browserView = [self hackishlyFoundBrowserView]; + if (browserView == nil) { + return; + } + + if ( styleDark ) { + Method m = class_getInstanceMethod( [self class], @selector( darkKeyboardAppearanceTemplateMethod ) ); + IMP imp = method_getImplementation( m ); + const char* typeEncoding = method_getTypeEncoding( m ); + class_replaceMethod( [browserView class], @selector(keyboardAppearance), imp, typeEncoding ); + } + else { + Method m = class_getInstanceMethod( [self class], @selector( lightKeyboardAppearanceTemplateMethod ) ); + IMP imp = method_getImplementation( m ); + const char* typeEncoding = method_getTypeEncoding( m ); + class_replaceMethod( [browserView class], @selector(keyboardAppearance), imp, typeEncoding ); + } +} +*/ + +@end + diff --git a/plugins/com.ionic.keyboard/www/keyboard.js b/plugins/com.ionic.keyboard/www/keyboard.js new file mode 100644 index 00000000..21b3bf63 --- /dev/null +++ b/plugins/com.ionic.keyboard/www/keyboard.js @@ -0,0 +1,37 @@ + +var argscheck = require('cordova/argscheck'), + utils = require('cordova/utils'), + exec = require('cordova/exec'); + + +var Keyboard = function() { +}; + +Keyboard.hideKeyboardAccessoryBar = function(hide) { + exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]); +}; + +Keyboard.close = function() { + exec(null, null, "Keyboard", "close", []); +}; + +Keyboard.show = function() { + exec(null, null, "Keyboard", "show", []); +}; + +Keyboard.disableScroll = function(disable) { + exec(null, null, "Keyboard", "disableScroll", [disable]); +}; + +/* +Keyboard.styleDark = function(dark) { + exec(null, null, "Keyboard", "styleDark", [dark]); +}; +*/ + +Keyboard.isVisible = false; + +module.exports = Keyboard; + + + diff --git a/plugins/cordova-plugin-crosswalk-webview/LICENSE b/plugins/cordova-plugin-crosswalk-webview/LICENSE new file mode 100644 index 00000000..578fa3bb --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/LICENSE @@ -0,0 +1,235 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + +/************************************************/ +This product bundles CordovaXWalkCoreExtensionBridge.java as well +as the XWalk.pak and the Crosswalk JSApi which is available under a +"3-clause BSD" license. For details, see below: + + Copyright (c) 2013 Intel Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/plugins/cordova-plugin-crosswalk-webview/NOTICE b/plugins/cordova-plugin-crosswalk-webview/NOTICE new file mode 100644 index 00000000..81636de1 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/NOTICE @@ -0,0 +1,8 @@ +Apache Cordova +Copyright 2014 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org) + +This software includes software developed at Intel Corporation. +Copyright 2014 Intel Corporation diff --git a/plugins/cordova-plugin-crosswalk-webview/README.md b/plugins/cordova-plugin-crosswalk-webview/README.md new file mode 100644 index 00000000..c2b25f57 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/README.md @@ -0,0 +1,83 @@ + + +Apache Cordova Crosswalk Engine +=== + +Cordova Crosswalk Engine is a [Crosswalk WebView](https://crosswalk-project.org/) based engine to work with [Apache Cordova](http://cordova.apache.org/) for Android. This currently works with master branch of [Cordova Android](https://github.com/apache/cordova-android) on GitHub, and it will work with Apache Cordova Android 4.0.0 release. + +### Directions: +#### Android-only: +* Pull down the Cordova Android +``` +$ git clone https://github.com/apache/cordova-android.git +``` +* Generate a project, e.g creating HelloWorld +``` +$ /path/to/cordova-android/bin/create hello com.example.hello HelloWorld +``` +* Navigate to the project folder +``` +$ cd hello +``` +* Install Crosswalk engine plugin by plugman (version >= 0.22.17) +``` +$ plugman install --platform android --plugin https://github.com/MobileChromeApps/cordova-crosswalk-engine.git --project . +``` +* Build +``` +$ ./cordova/build +``` +The build script will automatically fetch the Crosswalk WebView libraries from Crosswalk project download site (https://download.01.org/crosswalk/releases/crosswalk/android/) and build for both X86 and ARM architectures. + +For example, building HelloWorld generates: + +``` +/path/to/hello/build/outputs/apk/hello-x86-debug.apk +/path/to/hello/build/outputs/apk/hello-armv7-debug.apk +``` + +#### Cordova CLI: +(It will be updated after cordova-android 4.0.0 release with CLI) + +* Install the latest version of the Cordova CLI from npm (version >= 4.2.0) +``` +$ npm install -g cordova +``` +* Create a project with cordova create, e.g creating HelloWorld +``` +$ cordova create hello com.example.hello HelloWorld +``` +* Navigate to the project folder +``` +$ cd hello +``` +* Add the Android platform @4.0.0-dev +``` +$ cordova platform add https://github.com/apache/cordova-android.git +``` +* Add the Crosswalk engine plugin +``` +$ cordova plugin add https://github.com/MobileChromeApps/cordova-crosswalk-engine.git +``` +* Build +``` +$ cordova build android +``` +The build script will automatically fetch the Crosswalk WebView libraries from Crosswalk project download site (https://download.01.org/crosswalk/releases/crosswalk/android/) and build for both X86 and ARM architectures. + +For example, building android with Crosswalk generates: + +``` +/path/to/hello/platforms/android/build/outputs/apk/hello-x86-debug.apk +/path/to/hello/platforms/android/build/outputs/apk/hello-armv7-debug.apk +``` + +Note that it is also possible to publish a multi-APK application on the Play Store that uses Crosswalk for Pre-L devices, and the (updatable) system webview for L+: + +To build Crosswalk-enabled apks, add this plugin and run: + + $ cordova build --release + +To build System-webview apk, remove this plugin and run: + + $ cordova build --release -- --android-minSdkVersion=21 diff --git a/plugins/cordova-plugin-crosswalk-webview/package.json b/plugins/cordova-plugin-crosswalk-webview/package.json new file mode 100644 index 00000000..e67c6413 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/package.json @@ -0,0 +1,40 @@ +{ + "name": "cordova-plugin-crosswalk-webview", + "version": "1.0.1-dev", + "description": "Changes the default WebView to CrossWalk", + "cordova": { + "id": "cordova-plugin-crosswalk-webview", + "platforms": [ + "android" + ] + }, + "repository": { + "type": "git", + "url": "https://github.com/MobileChromeApps/cordova-crosswalk-engine.git" + }, + "keywords": [ + "cordova", + "chromium", + "crosswalk", + "webview", + "engine", + "ecosystem:cordova", + "cordova-android" + ], + "engines": [ + { + "name": "cordova-android", + "version": ">=4" + }, + { + "name": "cordova-plugman", + "version": ">=4.2.0" + } + ], + "author": "", + "license": "Apache 2.0", + "bugs": { + "url": "https://github.com/MobileChromeApps/cordova-crosswalk-engine/issues" + }, + "homepage": "https://github.com/MobileChromeApps/cordova-crosswalk-engine" +} diff --git a/plugins/cordova-plugin-crosswalk-webview/plugin.xml b/plugins/cordova-plugin-crosswalk-webview/plugin.xml new file mode 100644 index 00000000..8fd3e478 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/plugin.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="cordova-plugin-crosswalk-webview" + version="1.0.1-dev"> + + <name>Crosswalk WebView Engine</name> + <description>Changes the default WebView to CrossWalk</description> + <license>Apache 2.0</license> + <keywords>cordova,chromium,crosswalk,webview</keywords> + <repo>https://github.com/MobileChromeApps/cordova-crosswalk-engine.git</repo> + <issue>https://github.com/MobileChromeApps/cordova-crosswalk-engine/issues</issue> + + <engines> + <engine name="cordova-android" version=">=4" /> + <engine name="cordova-plugman" version=">=4.2.0" /><!-- needed for gradleReference support --> + </engines> + + <platform name="android"> + <config-file target="res/xml/config.xml" parent="/*"> + <preference name="webView" value="org.crosswalk.engine.XWalkWebViewEngine" /> + </config-file> + + <source-file src="src/android/XWalkWebViewEngine.java" target-dir="src/org/crosswalk/engine" /> + <source-file src="src/android/XWalkExposedJsApi.java" target-dir="src/org/crosswalk/engine" /> + <source-file src="src/android/XWalkCordovaResourceClient.java" target-dir="src/org/crosswalk/engine" /> + <source-file src="src/android/XWalkCordovaUiClient.java" target-dir="src/org/crosswalk/engine" /> + <source-file src="src/android/XWalkCordovaView.java" target-dir="src/org/crosswalk/engine" /> + <source-file src="src/android/XWalkCordovaCookieManager.java" target-dir="src/org/crosswalk/engine" /> + + <framework src="libs/xwalk_core_library" custom="true" /> + </platform> +</plugin> diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java new file mode 100644 index 00000000..43f170d2 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java @@ -0,0 +1,53 @@ +/* + 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. +*/ +package org.crosswalk.engine; + +import org.apache.cordova.ICordovaCookieManager; +import org.xwalk.core.internal.XWalkCookieManager; + +class XWalkCordovaCookieManager implements ICordovaCookieManager { + + protected XWalkCookieManager cookieManager = null; + + public XWalkCordovaCookieManager() { + cookieManager = new XWalkCookieManager(); + } + + public void setCookiesEnabled(boolean accept) { + cookieManager.setAcceptCookie(accept); + } + + public void setCookie(final String url, final String value) { + cookieManager.setCookie(url, value); + } + + public String getCookie(final String url) { + return cookieManager.getCookie(url); + } + + public void clearCookies() { + cookieManager.removeAllCookie(); + } + + public void flush() { + cookieManager.flushCookieStore(); + } +}; + + diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java new file mode 100644 index 00000000..57d0b0f9 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java @@ -0,0 +1,231 @@ +/* + 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. +*/ +package org.crosswalk.engine; + +import android.net.Uri; +import android.webkit.WebResourceResponse; + +import org.apache.cordova.CordovaResourceApi; +import org.apache.cordova.CordovaResourceApi.OpenForReadResult; +import org.apache.cordova.LOG; +import org.chromium.net.NetError; +import org.xwalk.core.XWalkResourceClient; +import org.xwalk.core.XWalkView; + +import java.io.FileNotFoundException; +import java.io.IOException; + +public class XWalkCordovaResourceClient extends XWalkResourceClient { + + private static final String TAG = "XWalkCordovaResourceClient"; + protected XWalkWebViewEngine parentEngine; + + // Success + public static final int ERROR_OK = 0; + // Generic error + public static final int ERROR_UNKNOWN = -1; + // Server or proxy hostname lookup failed + public static final int ERROR_HOST_LOOKUP = -2; + // Unsupported authentication scheme (not basic or digest) + public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; + // User authentication failed on server + public static final int ERROR_AUTHENTICATION = -4; + // User authentication failed on proxy + public static final int ERROR_PROXY_AUTHENTICATION = -5; + // Failed to connect to the server + public static final int ERROR_CONNECT = -6; + // Failed to read or write to the server + public static final int ERROR_IO = -7; + // Connection timed out + public static final int ERROR_TIMEOUT = -8; + // Too many redirects + public static final int ERROR_REDIRECT_LOOP = -9; + // Unsupported URI scheme + public static final int ERROR_UNSUPPORTED_SCHEME = -10; + // Failed to perform SSL handshake + public static final int ERROR_FAILED_SSL_HANDSHAKE = -11; + // Malformed URL + public static final int ERROR_BAD_URL = -12; + // Generic file error + public static final int ERROR_FILE = -13; + // File not found + public static final int ERROR_FILE_NOT_FOUND = -14; + // Too many requests during this load + public static final int ERROR_TOO_MANY_REQUESTS = -15; + + public XWalkCordovaResourceClient(XWalkWebViewEngine parentEngine) { + super(parentEngine.webView); + this.parentEngine = parentEngine; + } + + // Map XWalk error code about loading a page to Android specific ones. + // XWalk shares the error code with chromium currently. + static int convertErrorCode(int netError) { + // Note: many NetError.Error constants don't have an obvious mapping. + // These will be handled by the default case, ERROR_UNKNOWN. + switch (netError) { + case NetError.ERR_UNSUPPORTED_AUTH_SCHEME: + return ERROR_UNSUPPORTED_AUTH_SCHEME; + + case NetError.ERR_INVALID_AUTH_CREDENTIALS: + case NetError.ERR_MISSING_AUTH_CREDENTIALS: + case NetError.ERR_MISCONFIGURED_AUTH_ENVIRONMENT: + return ERROR_AUTHENTICATION; + + case NetError.ERR_TOO_MANY_REDIRECTS: + return ERROR_REDIRECT_LOOP; + + case NetError.ERR_UPLOAD_FILE_CHANGED: + return ERROR_FILE_NOT_FOUND; + + case NetError.ERR_INVALID_URL: + return ERROR_BAD_URL; + + case NetError.ERR_DISALLOWED_URL_SCHEME: + case NetError.ERR_UNKNOWN_URL_SCHEME: + return ERROR_UNSUPPORTED_SCHEME; + + case NetError.ERR_IO_PENDING: + case NetError.ERR_NETWORK_IO_SUSPENDED: + return ERROR_IO; + + case NetError.ERR_CONNECTION_TIMED_OUT: + case NetError.ERR_TIMED_OUT: + return ERROR_TIMEOUT; + + case NetError.ERR_FILE_TOO_BIG: + return ERROR_FILE; + + case NetError.ERR_HOST_RESOLVER_QUEUE_TOO_LARGE: + case NetError.ERR_INSUFFICIENT_RESOURCES: + case NetError.ERR_OUT_OF_MEMORY: + return ERROR_TOO_MANY_REQUESTS; + + case NetError.ERR_CONNECTION_CLOSED: + case NetError.ERR_CONNECTION_RESET: + case NetError.ERR_CONNECTION_REFUSED: + case NetError.ERR_CONNECTION_ABORTED: + case NetError.ERR_CONNECTION_FAILED: + case NetError.ERR_SOCKET_NOT_CONNECTED: + return ERROR_CONNECT; + + case NetError.ERR_INTERNET_DISCONNECTED: + case NetError.ERR_ADDRESS_INVALID: + case NetError.ERR_ADDRESS_UNREACHABLE: + case NetError.ERR_NAME_NOT_RESOLVED: + case NetError.ERR_NAME_RESOLUTION_FAILED: + return ERROR_HOST_LOOKUP; + + case NetError.ERR_SSL_PROTOCOL_ERROR: + case NetError.ERR_SSL_CLIENT_AUTH_CERT_NEEDED: + case NetError.ERR_TUNNEL_CONNECTION_FAILED: + case NetError.ERR_NO_SSL_VERSIONS_ENABLED: + case NetError.ERR_SSL_VERSION_OR_CIPHER_MISMATCH: + case NetError.ERR_SSL_RENEGOTIATION_REQUESTED: + case NetError.ERR_CERT_ERROR_IN_SSL_RENEGOTIATION: + case NetError.ERR_BAD_SSL_CLIENT_AUTH_CERT: + case NetError.ERR_SSL_NO_RENEGOTIATION: + case NetError.ERR_SSL_DECOMPRESSION_FAILURE_ALERT: + case NetError.ERR_SSL_BAD_RECORD_MAC_ALERT: + case NetError.ERR_SSL_UNSAFE_NEGOTIATION: + case NetError.ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY: + case NetError.ERR_SSL_CLIENT_AUTH_PRIVATE_KEY_ACCESS_DENIED: + case NetError.ERR_SSL_CLIENT_AUTH_CERT_NO_PRIVATE_KEY: + return ERROR_FAILED_SSL_HANDSHAKE; + + case NetError.ERR_PROXY_AUTH_UNSUPPORTED: + case NetError.ERR_PROXY_AUTH_REQUESTED: + case NetError.ERR_PROXY_CONNECTION_FAILED: + case NetError.ERR_UNEXPECTED_PROXY_AUTH: + return ERROR_PROXY_AUTHENTICATION; + + // The certificate errors are handled by onReceivedSslError + // and don't need to be reported here. + case NetError.ERR_CERT_COMMON_NAME_INVALID: + case NetError.ERR_CERT_DATE_INVALID: + case NetError.ERR_CERT_AUTHORITY_INVALID: + case NetError.ERR_CERT_CONTAINS_ERRORS: + case NetError.ERR_CERT_NO_REVOCATION_MECHANISM: + case NetError.ERR_CERT_UNABLE_TO_CHECK_REVOCATION: + case NetError.ERR_CERT_REVOKED: + case NetError.ERR_CERT_INVALID: + case NetError.ERR_CERT_WEAK_SIGNATURE_ALGORITHM: + case NetError.ERR_CERT_NON_UNIQUE_NAME: + return ERROR_OK; + + default: + return ERROR_UNKNOWN; + } + } + + /** + * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable). + * The errorCode parameter corresponds to one of the ERROR_* constants. + * + * @param view The WebView that is initiating the callback. + * @param errorCode The error code corresponding to an ERROR_* value. + * @param description A String describing the error. + * @param failingUrl The url that failed to load. + */ + @Override + public void onReceivedLoadError(XWalkView view, int errorCode, String description, + String failingUrl) { + LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl); + + // Convert the XWalk error code to Cordova error code, which follows the Android spec, + // http://developer.android.com/reference/android/webkit/WebViewClient.html. + errorCode = XWalkCordovaResourceClient.convertErrorCode(errorCode); + parentEngine.client.onReceivedError(errorCode, description, failingUrl); + } + + @Override + public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) { + try { + // Check the against the white-list. + if (!parentEngine.pluginManager.shouldAllowRequest(url)) { + LOG.w(TAG, "URL blocked by whitelist: " + url); + // Results in a 404. + return new WebResourceResponse("text/plain", "UTF-8", null); + } + + CordovaResourceApi resourceApi = parentEngine.resourceApi; + Uri origUri = Uri.parse(url); + // Allow plugins to intercept WebView requests. + Uri remappedUri = resourceApi.remapUri(origUri); + + if (!origUri.equals(remappedUri)) { + OpenForReadResult result = resourceApi.openForRead(remappedUri, true); + return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream); + } + // If we don't need to special-case the request, let the browser load it. + return null; + } catch (IOException e) { + if (!(e instanceof FileNotFoundException)) { + LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e); + } + // Results in a 404. + return new WebResourceResponse("text/plain", "UTF-8", null); + } + } + + @Override + public boolean shouldOverrideUrlLoading(XWalkView view, String url) { + return parentEngine.client.onNavigationAttempt(url); + } +} diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java new file mode 100644 index 00000000..a5a20b70 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java @@ -0,0 +1,193 @@ +/* + 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. +*/ +package org.crosswalk.engine; + +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; +import android.util.Log; +import android.webkit.ValueCallback; + +import org.apache.cordova.CordovaDialogsHelper; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.LOG; +import org.xwalk.core.XWalkJavascriptResult; +import org.xwalk.core.XWalkUIClient; +import org.xwalk.core.XWalkView; + +public class XWalkCordovaUiClient extends XWalkUIClient { + private static final String TAG = "XWalkCordovaUiClient"; + protected final CordovaDialogsHelper dialogsHelper; + protected final XWalkWebViewEngine parentEngine; + + private static final int FILECHOOSER_RESULTCODE = 5173; + + public XWalkCordovaUiClient(XWalkWebViewEngine parentEngine) { + super(parentEngine.webView); + this.parentEngine = parentEngine; + dialogsHelper = new CordovaDialogsHelper(parentEngine.webView.getContext()); + } + + @Override + public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type, String url, + String message, String defaultValue, XWalkJavascriptResult result) { + switch (type) { + case JAVASCRIPT_ALERT: + return onJsAlert(view, url, message, result); + case JAVASCRIPT_CONFIRM: + return onJsConfirm(view, url, message, result); + case JAVASCRIPT_PROMPT: + return onJsPrompt(view, url, message, defaultValue, result); + case JAVASCRIPT_BEFOREUNLOAD: + // Reuse onJsConfirm to show the dialog. + return onJsConfirm(view, url, message, result); + default: + break; + } + assert (false); + return false; + } + + /** + * Tell the client to display a javascript alert dialog. + */ + private boolean onJsAlert(XWalkView view, String url, String message, + final XWalkJavascriptResult result) { + dialogsHelper.showAlert(message, new CordovaDialogsHelper.Result() { + @Override + public void gotResult(boolean success, String value) { + if (success) { + result.confirm(); + } else { + result.cancel(); + } + } + }); + return true; + } + + /** + * Tell the client to display a confirm dialog to the user. + */ + private boolean onJsConfirm(XWalkView view, String url, String message, + final XWalkJavascriptResult result) { + dialogsHelper.showConfirm(message, new CordovaDialogsHelper.Result() { + @Override + public void gotResult(boolean success, String value) { + if (success) { + result.confirm(); + } else { + result.cancel(); + } + } + }); + return true; + } + + /** + * Tell the client to display a prompt dialog to the user. + * If the client returns true, WebView will assume that the client will + * handle the prompt dialog and call the appropriate JsPromptResult method. + * <p/> + * Since we are hacking prompts for our own purposes, we should not be using them for + * this purpose, perhaps we should hack console.log to do this instead! + */ + private boolean onJsPrompt(XWalkView view, String origin, String message, String defaultValue, + final XWalkJavascriptResult result) { + // Unlike the @JavascriptInterface bridge, this method is always called on the UI thread. + String handledRet = parentEngine.bridge.promptOnJsPrompt(origin, message, defaultValue); + if (handledRet != null) { + result.confirmWithResult(handledRet); + } else { + dialogsHelper.showPrompt(message, defaultValue, new CordovaDialogsHelper.Result() { + @Override + public void gotResult(boolean success, String value) { + if (success) { + result.confirmWithResult(value); + } else { + result.cancel(); + } + } + }); + + } + return true; + } + + /** + * Notify the host application that a page has started loading. + * This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted + * one time for the main frame. This also means that onPageStarted will not be called when the contents of an + * embedded frame changes, i.e. clicking a link whose target is an iframe. + * + * @param view The webView initiating the callback. + * @param url The url of the page. + */ + @Override + public void onPageLoadStarted(XWalkView view, String url) { + + // Only proceed if this is a top-level navigation + if (view.getUrl() != null && view.getUrl().equals(url)) { + // Flush stale messages. + parentEngine.client.onPageStarted(url); + parentEngine.bridge.reset(); + } + } + + /** + * Notify the host application that a page has stopped loading. + * This method is called only for main frame. When onPageLoadStopped() is called, the rendering picture may not be updated yet. + * + * @param view The webView initiating the callback. + * @param url The url of the page. + * @param status The load status of the webView, can be FINISHED, CANCELLED or FAILED. + */ + @Override + public void onPageLoadStopped(XWalkView view, String url, LoadStatus status) { + LOG.d(TAG, "onPageFinished(" + url + ")"); + if (status == LoadStatus.FINISHED) { + parentEngine.client.onPageFinishedLoading(url); + } else if (status == LoadStatus.FAILED) { + // TODO: Should this call parentEngine.client.onReceivedError()? + // Right now we call this from ResourceClient, but maybe that is just for sub-resources? + } + } + + // File Chooser + @Override + public void openFileChooser(XWalkView view, final ValueCallback<Uri> uploadFile, String acceptType, String capture) { + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); // TODO: wire this to acceptType. + Intent intent = Intent.createChooser(i, "File Browser"); + try { + parentEngine.cordova.startActivityForResult(new CordovaPlugin() { + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData(); + uploadFile.onReceiveValue(result); + } + }, intent, FILECHOOSER_RESULTCODE); + } catch (ActivityNotFoundException e) { + Log.w("No activity found to handle file chooser intent.", e); + uploadFile.onReceiveValue(null); + } + } +} diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java new file mode 100644 index 00000000..0be2e998 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java @@ -0,0 +1,108 @@ +package org.crosswalk.engine; + +import org.apache.cordova.CordovaPreferences; +import org.xwalk.core.XWalkPreferences; +import org.xwalk.core.XWalkResourceClient; +import org.xwalk.core.XWalkUIClient; +import org.xwalk.core.XWalkView; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.util.AttributeSet; +import android.view.KeyEvent; + +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.CordovaWebViewEngine; + +public class XWalkCordovaView extends XWalkView implements CordovaWebViewEngine.EngineView { + protected XWalkCordovaResourceClient resourceClient; + protected XWalkCordovaUiClient uiClient; + protected XWalkWebViewEngine parentEngine; + + private static boolean hasSetStaticPref; + // This needs to run before the super's constructor. + private static Context setGlobalPrefs(Context context, CordovaPreferences preferences) { + if (!hasSetStaticPref) { + hasSetStaticPref = true; + ApplicationInfo ai = null; + try { + ai = context.getPackageManager().getApplicationInfo(context.getApplicationContext().getPackageName(), PackageManager.GET_META_DATA); + } catch (PackageManager.NameNotFoundException e) { + throw new RuntimeException(e); + } + boolean prefAnimatable = preferences == null ? false : preferences.getBoolean("CrosswalkAnimatable", false); + boolean manifestAnimatable = ai.metaData == null ? false : ai.metaData.getBoolean("CrosswalkAnimatable"); + if (prefAnimatable || manifestAnimatable) { + // Slows it down a bit, but allows for it to be animated by Android View properties. + XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true); + } + if ((ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { + XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true); + } + XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true); + XWalkPreferences.setValue(XWalkPreferences.ALLOW_UNIVERSAL_ACCESS_FROM_FILE, true); + } + return context; + } + + public XWalkCordovaView(Context context, CordovaPreferences preferences) { + super(setGlobalPrefs(context, preferences), (AttributeSet)null); + } + + public XWalkCordovaView(Context context, AttributeSet attrs) { + super(setGlobalPrefs(context, null), attrs); + } + + void init(XWalkWebViewEngine parentEngine) { + this.parentEngine = parentEngine; + if (resourceClient == null) { + setResourceClient(new XWalkCordovaResourceClient(parentEngine)); + } + if (uiClient == null) { + setUIClient(new XWalkCordovaUiClient(parentEngine)); + } + } + + @Override + public void setResourceClient(XWalkResourceClient client) { + // XWalk calls this method from its constructor. + if (client instanceof XWalkCordovaResourceClient) { + this.resourceClient = (XWalkCordovaResourceClient)client; + } + super.setResourceClient(client); + } + + @Override + public void setUIClient(XWalkUIClient client) { + // XWalk calls this method from its constructor. + if (client instanceof XWalkCordovaUiClient) { + this.uiClient = (XWalkCordovaUiClient)client; + } + super.setUIClient(client); + } + + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + Boolean ret = parentEngine.client.onDispatchKeyEvent(event); + if (ret != null) { + return ret.booleanValue(); + } + return super.dispatchKeyEvent(event); + } + + @Override + public void pauseTimers() { + // This is called by XWalkViewInternal.onActivityStateChange(). + // We don't want them paused by default though. + } + + public void pauseTimersForReal() { + super.pauseTimers(); + } + + @Override + public CordovaWebView getCordovaWebView() { + return parentEngine == null ? null : parentEngine.getCordovaWebView(); + } +} diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java new file mode 100644 index 00000000..25715216 --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java @@ -0,0 +1,52 @@ +/* + 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. +*/ +package org.crosswalk.engine; + +import android.os.Looper; + +import org.apache.cordova.CordovaBridge; +import org.apache.cordova.ExposedJsApi; +import org.json.JSONException; +import org.xwalk.core.JavascriptInterface; + +class XWalkExposedJsApi implements ExposedJsApi { + private final CordovaBridge bridge; + + XWalkExposedJsApi(CordovaBridge bridge) { + this.bridge = bridge; + } + + @JavascriptInterface + public String exec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException { + if (Looper.myLooper() == null) { + Looper.prepare(); + } + return bridge.jsExec(bridgeSecret, service, action, callbackId, arguments); + } + + @JavascriptInterface + public void setNativeToJsBridgeMode(int bridgeSecret, int value) throws IllegalAccessException { + bridge.jsSetNativeToJsBridgeMode(bridgeSecret, value); + } + + @JavascriptInterface + public String retrieveJsMessages(int bridgeSecret, boolean fromOnlineEvent) throws IllegalAccessException { + return bridge.jsRetrieveJsMessages(bridgeSecret, fromOnlineEvent); + } +} diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java new file mode 100644 index 00000000..7e5a4f1c --- /dev/null +++ b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java @@ -0,0 +1,185 @@ +/* + 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. +*/ + +package org.crosswalk.engine; + +import android.content.Context; +import android.view.View; + +import org.apache.cordova.CordovaBridge; +import org.apache.cordova.CordovaInterface; +import org.apache.cordova.CordovaPreferences; +import org.apache.cordova.CordovaResourceApi; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.CordovaWebViewEngine; +import org.apache.cordova.ICordovaCookieManager; +import org.apache.cordova.NativeToJsMessageQueue; +import org.apache.cordova.PluginManager; +import org.xwalk.core.XWalkNavigationHistory; +import org.xwalk.core.XWalkView; + +/** + * Glue class between CordovaWebView (main Cordova logic) and XWalkCordovaView (the actual View). + */ +public class XWalkWebViewEngine implements CordovaWebViewEngine { + + public static final String TAG = "XWalkWebViewEngine"; + + protected final XWalkCordovaView webView; + protected XWalkCordovaCookieManager cookieManager; + protected CordovaBridge bridge; + protected CordovaWebViewEngine.Client client; + protected CordovaWebView parentWebView; + protected CordovaInterface cordova; + protected PluginManager pluginManager; + protected CordovaResourceApi resourceApi; + protected NativeToJsMessageQueue nativeToJsMessageQueue; + + /** Used when created via reflection. */ + public XWalkWebViewEngine(Context context, CordovaPreferences preferences) { + this(new XWalkCordovaView(context, preferences)); + } + + public XWalkWebViewEngine(XWalkCordovaView webView) { + this.webView = webView; + cookieManager = new XWalkCordovaCookieManager(); + } + + // Use two-phase init so that the control will work with XML layouts. + + @Override + public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, + CordovaResourceApi resourceApi, PluginManager pluginManager, + NativeToJsMessageQueue nativeToJsMessageQueue) { + if (this.cordova != null) { + throw new IllegalStateException(); + } + this.parentWebView = parentWebView; + this.cordova = cordova; + this.client = client; + this.resourceApi = resourceApi; + this.pluginManager = pluginManager; + this.nativeToJsMessageQueue = nativeToJsMessageQueue; + + webView.init(this); + initWebViewSettings(); + + nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { + @Override + public void setNetworkAvailable(boolean value) { + webView.setNetworkAvailable(value); + } + @Override + public void runOnUiThread(Runnable r) { + XWalkWebViewEngine.this.cordova.getActivity().runOnUiThread(r); + } + })); + bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); + exposeJsInterface(webView, bridge); + } + + @Override + public CordovaWebView getCordovaWebView() { + return parentWebView; + } + + @Override + public View getView() { + return webView; + } + + private void initWebViewSettings() { + webView.setVerticalScrollBarEnabled(false); + } + + private static void exposeJsInterface(XWalkView webView, CordovaBridge bridge) { + XWalkExposedJsApi exposedJsApi = new XWalkExposedJsApi(bridge); + webView.addJavascriptInterface(exposedJsApi, "_cordovaNative"); + } + + // TODO(ningxin): XWalkViewUIClient should provide onScrollChanged callback + /* + public void onScrollChanged(int l, int t, int oldl, int oldt) + { + super.onScrollChanged(l, t, oldl, oldt); + //We should post a message that the scroll changed + ScrollEvent myEvent = new ScrollEvent(l, t, oldl, oldt, this); + this.postMessage("onScrollChanged", myEvent); + } + */ + + @Override + public boolean canGoBack() { + return this.webView.getNavigationHistory().canGoBack(); + } + + @Override + public boolean goBack() { + if (this.webView.getNavigationHistory().canGoBack()) { + this.webView.getNavigationHistory().navigate(XWalkNavigationHistory.Direction.BACKWARD, 1); + return true; + } + return false; + } + + @Override + public void setPaused(boolean value) { + if (value) { + // TODO: I think this has been fixed upstream and we don't need to override pauseTimers() anymore. + webView.pauseTimersForReal(); + } else { + webView.resumeTimers(); + } + } + + @Override + public void destroy() { + webView.onDestroy(); + } + + @Override + public void clearHistory() { + this.webView.getNavigationHistory().clear(); + } + + @Override + public void stopLoading() { + this.webView.stopLoading(); + } + + @Override + public void clearCache() { + webView.clearCache(true); + } + + @Override + public String getUrl() { + return this.webView.getUrl(); + } + + @Override + public ICordovaCookieManager getCookieManager() { + return cookieManager; + } + + @Override + public void loadUrl(String url, boolean clearNavigationStack) { + webView.load(url, null); + } +} diff --git a/plugins/cordova-plugin-inappbrowser/CONTRIBUTING.md b/plugins/cordova-plugin-inappbrowser/CONTRIBUTING.md new file mode 100644 index 00000000..f7dbcaba --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/CONTRIBUTING.md @@ -0,0 +1,37 @@ +<!-- +# +# 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. +# +--> + +# Contributing to Apache Cordova + +Anyone can contribute to Cordova. And we need your contributions. + +There are multiple ways to contribute: report bugs, improve the docs, and +contribute code. + +For instructions on this, start with the +[contribution overview](http://cordova.apache.org/#contribute). + +The details are explained there, but the important items are: + - Sign and submit an Apache ICLA (Contributor License Agreement). + - Have a Jira issue open that corresponds to your contribution. + - Run the tests so your patch doesn't break existing functionality. + +We look forward to your contributions! diff --git a/plugins/cordova-plugin-inappbrowser/LICENSE b/plugins/cordova-plugin-inappbrowser/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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.
\ No newline at end of file diff --git a/plugins/cordova-plugin-inappbrowser/NOTICE b/plugins/cordova-plugin-inappbrowser/NOTICE new file mode 100644 index 00000000..8ec56a52 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/NOTICE @@ -0,0 +1,5 @@ +Apache Cordova +Copyright 2012 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/plugins/cordova-plugin-inappbrowser/README.md b/plugins/cordova-plugin-inappbrowser/README.md new file mode 100644 index 00000000..31a3c72f --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/README.md @@ -0,0 +1,388 @@ +<!--- + license: 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. +--> + +# cordova-plugin-inappbrowser + +[](https://travis-ci.org/apache/cordova-plugin-inappbrowser) + +This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + +The `cordova.InAppBrowser.open()` function is defined to be a drop-in replacement +for the `window.open()` function. Existing `window.open()` calls can use the +InAppBrowser window, by replacing window.open: + + window.open = cordova.InAppBrowser.open; + +The InAppBrowser window behaves like a standard web browser, +and can't access Cordova APIs. For this reason, the InAppBrowser is recommended +if you need to load third-party (untrusted) content, instead of loading that +into the main Cordova webview. The InAppBrowser is not subject to the +whitelist, nor is opening links in the system browser. + +The InAppBrowser provides by default its own GUI controls for the user (back, +forward, done). + +For backwards compatibility, this plugin also hooks `window.open`. +However, the plugin-installed hook of `window.open` can have unintended side +effects (especially if this plugin is included only as a dependency of another +plugin). The hook of `window.open` will be removed in a future major release. +Until the hook is removed from the plugin, apps can manually restore the default +behaviour: + + delete window.open // Reverts the call back to it's prototype's default + +Although `window.open` is in the global scope, InAppBrowser is not available until after the `deviceready` event. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + +## Installation + + cordova plugin add cordova-plugin-inappbrowser + +If you want all page loads in your app to go through the InAppBrowser, you can +simply hook `window.open` during initialization. For example: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + +## cordova.InAppBrowser.open + +Opens a URL in a new `InAppBrowser` instance, the current browser +instance, or the system browser. + + var ref = cordova.InAppBrowser.open(url, target, options); + +- __ref__: Reference to the `InAppBrowser` window. _(InAppBrowser)_ + +- __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL contains Unicode characters. + +- __target__: The target in which to load the URL, an optional parameter that defaults to `_self`. _(String)_ + + - `_self`: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the `InAppBrowser`. + - `_blank`: Opens in the `InAppBrowser`. + - `_system`: Opens in the system's web browser. + +- __options__: Options for the `InAppBrowser`. Optional, defaulting to: `location=yes`. _(String)_ + + The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. All platforms support the value below: + + - __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off. + + Android only: + + - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally. + - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened + - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened + - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. + - __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser. + + iOS only: + + - __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself. + - __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property. + - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally. + - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened + - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened + - __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`) + - __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). + - __mediaPlaybackRequiresUserAction__: Set to `yes` or `no` to prevent HTML5 audio or video from autoplaying (defaults to `no`). + - __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`) + - __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). + - __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). + - __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle) (defaults to `fullscreen`). + - __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle) (defaults to `coververtical`). + - __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window. + + Windows only: + + - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally. + - __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window. + +### Supported Platforms + +- Amazon Fire OS +- Android +- BlackBerry 10 +- Firefox OS +- iOS +- Windows 8 and 8.1 +- Windows Phone 7 and 8 +- Browser + +### Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + +### Firefox OS Quirks + +As plugin doesn't enforce any design there is a need to add some CSS rules if +opened with `target='_blank'`. The rules might look like these + +``` css +.inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); +} +.inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; +} +.inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); +} +.inAppBrowserWrap menu li.disabled { + color: #777; +} +``` + +### Windows Quirks + +Similar to Firefox OS IAB window visual behaviour can be overridden via `inAppBrowserWrap`/`inAppBrowserWrapFullscreen` CSS classes + +### Browser Quirks + +- Plugin is implemented via iframe, + +- Navigation history (`back` and `forward` buttons in LocationBar) is not implemented. + +## InAppBrowser + +The object returned from a call to `cordova.InAppBrowser.open`. + +### Methods + +- addEventListener +- removeEventListener +- close +- show +- executeScript +- insertCSS + +## addEventListener + +> Adds a listener for an event from the `InAppBrowser`. + + ref.addEventListener(eventname, callback); + +- __ref__: reference to the `InAppBrowser` window _(InAppBrowser)_ + +- __eventname__: the event to listen for _(String)_ + + - __loadstart__: event fires when the `InAppBrowser` starts to load a URL. + - __loadstop__: event fires when the `InAppBrowser` finishes loading a URL. + - __loaderror__: event fires when the `InAppBrowser` encounters an error when loading a URL. + - __exit__: event fires when the `InAppBrowser` window is closed. + +- __callback__: the function that executes when the event fires. The function is passed an `InAppBrowserEvent` object as a parameter. + +### InAppBrowserEvent Properties + +- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, or `exit`. _(String)_ + +- __url__: the URL that was loaded. _(String)_ + +- __code__: the error code, only in the case of `loaderror`. _(Number)_ + +- __message__: the error message, only in the case of `loaderror`. _(String)_ + + +### Supported Platforms + +- Amazon Fire OS +- Android +- iOS +- Windows 8 and 8.1 +- Windows Phone 7 and 8 +- Browser + +### Browser Quirks + +`loadstart` and `loaderror` events are not being fired. + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + +## removeEventListener + +> Removes a listener for an event from the `InAppBrowser`. + + ref.removeEventListener(eventname, callback); + +- __ref__: reference to the `InAppBrowser` window. _(InAppBrowser)_ + +- __eventname__: the event to stop listening for. _(String)_ + + - __loadstart__: event fires when the `InAppBrowser` starts to load a URL. + - __loadstop__: event fires when the `InAppBrowser` finishes loading a URL. + - __loaderror__: event fires when the `InAppBrowser` encounters an error loading a URL. + - __exit__: event fires when the `InAppBrowser` window is closed. + +- __callback__: the function to execute when the event fires. +The function is passed an `InAppBrowserEvent` object. + +### Supported Platforms + +- Amazon Fire OS +- Android +- iOS +- Windows 8 and 8.1 +- Windows Phone 7 and 8 +- Browser + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + +## close + +> Closes the `InAppBrowser` window. + + ref.close(); + +- __ref__: reference to the `InAppBrowser` window _(InAppBrowser)_ + +### Supported Platforms + +- Amazon Fire OS +- Android +- Firefox OS +- iOS +- Windows 8 and 8.1 +- Windows Phone 7 and 8 +- Browser + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + +## show + +> Displays an InAppBrowser window that was opened hidden. Calling this has no effect if the InAppBrowser was already visible. + + ref.show(); + +- __ref__: reference to the InAppBrowser window (`InAppBrowser`) + +### Supported Platforms + +- Amazon Fire OS +- Android +- iOS +- Windows 8 and 8.1 +- Browser + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + +## executeScript + +> Injects JavaScript code into the `InAppBrowser` window + + ref.executeScript(details, callback); + +- __ref__: reference to the `InAppBrowser` window. _(InAppBrowser)_ + +- __injectDetails__: details of the script to run, specifying either a `file` or `code` key. _(Object)_ + - __file__: URL of the script to inject. + - __code__: Text of the script to inject. + +- __callback__: the function that executes after the JavaScript code is injected. + - If the injected script is of type `code`, the callback executes + with a single parameter, which is the return value of the + script, wrapped in an `Array`. For multi-line scripts, this is + the return value of the last statement, or the last expression + evaluated. + +### Supported Platforms + +- Amazon Fire OS +- Android +- iOS +- Windows 8 and 8.1 +- Browser + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + +### Browser Quirks + +- only __code__ key is supported. + +### Windows Quirks + +Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.invokescriptasync.aspx) the invoked script can return only string values, otherwise the parameter, passed to __callback__ will be `[null]`. + +## insertCSS + +> Injects CSS into the `InAppBrowser` window. + + ref.insertCSS(details, callback); + +- __ref__: reference to the `InAppBrowser` window _(InAppBrowser)_ + +- __injectDetails__: details of the script to run, specifying either a `file` or `code` key. _(Object)_ + - __file__: URL of the stylesheet to inject. + - __code__: Text of the stylesheet to inject. + +- __callback__: the function that executes after the CSS is injected. + +### Supported Platforms + +- Amazon Fire OS +- Android +- iOS +- Windows + +### Quick Example + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); + diff --git a/plugins/cordova-plugin-inappbrowser/RELEASENOTES.md b/plugins/cordova-plugin-inappbrowser/RELEASENOTES.md new file mode 100644 index 00000000..f7a24cc0 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/RELEASENOTES.md @@ -0,0 +1,192 @@ +<!-- +# +# 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. +# +--> +# Release Notes + +### 0.2.2 (Sept 25, 2013) +* CB-4889 bumping&resetting version +* CB-4788: Modified the onJsPrompt to warn against Cordova calls +* [windows8] commandProxy was moved +* CB-4788: Modified the onJsPrompt to warn against Cordova calls +* [windows8] commandProxy was moved +* CB-4889 renaming core references +* CB-4889 renaming org.apache.cordova.core.inappbrowser to org.apache.cordova.inappbrowser +* CB-4864, CB-4865: Minor improvements to InAppBrowser +* Rename CHANGELOG.md -> RELEASENOTES.md +* [CB-4792] Added keepCallback to the show function. +* [CB-4752] Incremented plugin version on dev branch. + +### 0.2.3 (Oct 9, 2013) +* [CB-4915] Incremented plugin version on dev branch. +* [CB-4926] Fixes inappbrowser plugin loading for windows8 + +### 0.2.4 (Oct 28, 2013) +* CB-5128: added repo + issue tag to plugin.xml for inappbrowser plugin +* CB-4995 Fix crash when WebView is quickly opened then closed. +* CB-4930 - iOS - InAppBrowser should take into account the status bar +* [CB-5010] Incremented plugin version on dev branch. +* [CB-5010] Updated version and RELEASENOTES.md for release 0.2.3 +* CB-4858 - Run IAB methods on the UI thread. +* CB-4858 Convert relative URLs to absolute URLs in JS +* CB-3747 Fix back button having different dismiss logic from the close button. +* CB-5021 Expose closeDialog() as a public function and make it safe to call multiple times. +* CB-5021 Make it safe to call close() multiple times + +### 0.2.5 (Dec 4, 2013) +* Remove merge conflict tag +* [CB-4724] fixed UriFormatException +* add ubuntu platform +* CB-3420 WP feature hidden=yes implemented +* Added amazon-fireos platform. Change to use amazon-fireos as the platform if user agent string contains 'cordova-amazon-fireos' + +### 0.3.0 (Jan 02, 2014) +* CB-5592 Android: Add MIME type to Intent when opening file:/// URLs +* CB-5594 iOS: Add disallowoverscroll option. +* CB-5658 Add doc/index.md for InAppBrowser plugin +* CB-5595 Add toolbarposition=top option. +* Apply CB-5193 to InAppBrowser (Fix DB quota exception) +* CB-5593 iOS: Make InAppBrowser localizable +* CB-5591 Change window.escape to encodeURIComponent + +### 0.3.1 (Feb 05, 2014) +* CB-5756: Android: Use WebView.evaluateJavascript for script injection on Android 4.4+ +* Didn't test on ICS or lower, getDrawable isn't supported until Jellybean +* add ubuntu platform +* Adding drawables to the inAppBrowser. This doesn't look quite right, but it's a HUGE improvement over the previous settings +* CB-5756: Android: Use WebView.evaluateJavascript for script injection on Android 4.4+ +* Remove alive from InAppBrowser.js since it didn't catch the case where the browser is closed by the user. +* CB-5733 Fix IAB.close() not working if called before show() animation is done + +### 0.3.2 (Feb 26, 2014) +* Validate that callbackId is correctly formed +* CB-6035 Move js-module so it is not loaded on unsupported platforms +* Removed some iOS6 Deprecations + +### 0.3.3 (Mar 5, 2014) +* CB-5534 Fix video/audio does not stop playing when browser is closed +* CB-6172 Fix broken install on case-sensitive file-systems + + +### 0.4.0 (Apr 17, 2014) +* CB-6360: [ios] Fix for crash on iOS < 6.0 (closes #37) +* CB-3324: [WP8] Add support for back-button inappbrowser [WP8] if there is no history -> InAppBrowser is closed +* [WP] await async calls, resolve warnings +* [WP] Make InAppBrowser work with embedded files, using system behavior +* CB-6402: [WP8] pass empty string instead of null for [optional] windowFeatures string +* CB-6422: [windows8] use cordova/exec/proxy +* CB-6389 CB-3617: Add clearcache and clearsessioncache options to iOS (like Android) +* Doc update: event name and example param (closes #31) +* CB-6253: [WP] Add Network Capability to WMAppManifest.xml +* CB-6212: [iOS] fix warnings compiled under arm64 64-bit +* CB-6218: Update docs for BB10 +* CB-6460: Update license headers + +### 0.5.0 (Jun 05, 2014) +* CB-6127 Spanish and rench Translations added. Github close #23 +* Clean up whitespace (mainly due to no newline at eof warning) +* Adding permission info +* CB-6806 Add license +* CB-6491 add CONTRIBUTING.md +* Add necessary capability so the plugin works on its own +* CB-6474 InAppBrowser. Add data urls support to WP8 +* CB-6482 InAppBrowser calls incorrect callback on WP8 +* Fixed use of iOS 6 deprecated methods +* CB-6360 - improvement: feature detection instead of iOS version detection +* CB-5649 - InAppBrowser overrides App's orientation +* refactoring fixed +* CB-6396 [Firefox OS] Adding basic support + +### 0.5.1 (Aug 06, 2014) +* ubuntu: support qt 5.2 +* **FFOS** update InAppBrowserProxy.js +* **FFOS** app needs to be privileged +* CB-6127 Updated translations for docs +* CB-6769 ios: Fix statusbar color reset wasn't working on iOS7+ + +### 0.5.2 (Sep 17, 2014) +* CB-7471 cordova-plugin-inappbrowser documentation translation: cordova-plugin-inappbrowser +* CB-7490 Fixes InAppBrowser manual tests crash on windows platform +* CB-7249 cordova-plugin-inappbrowser documentation translation: cordova-plugin-inappbrowser +* CB-7424 Wrong docs: anchor tags are not supported by the InAppBrowser +* CB-7133 clarify that anchor1 doesn't exist +* CB-7133 more fixup of tests on Android +* CB-7133 fix up the tests for Android +* Add just a bit more logging +* CB-7133 port inappbrowser to plugin-test-framework +* phonegap events supported for \_blank target +* inappbrowser \_blank target position is fixed +* amazon-fireos related changes. + +### 0.5.3 (Oct 03, 2014) +* Windows implementation fixes and improvements +* zIndex fixed +* renamed InAppBrowser back to inappbrowser for case sensitive operating systems +* Update french translation +* Update doc to add Windows 8 +* Update windows proxy to be both compatible with windows 8 and 8.1 +* Rename windows81 by windows8 in src directory +* Append Windows 8.1 platform configuration in plugin.xml +* Append Windows 8.1 proxy using x-ms-webview + +### 0.5.4 (Dec 02, 2014) +* CB-7784 Exit event is not fired after `InAppBrowser` closing +* CB-7697 Add `locationBar` support to `InAppBrowser` **Windows** platform version +* CB-7690 `InAppBrowser` `loadstart/loadstop` events issues +* CB-7695 Fix `InAppBrowser` `injectScriptFile` for **Windows 8.1** / **Windows Phone 8.1** +* CB-7692 `InAppBrowser` local url opening bug in 8.1 +* CB-7688 `Alert` is not supported in `InAppBrowser` on **Windows** platform +* CB-7977 Mention `deviceready` in plugin docs +* CB-7876 change test target to avoid undesired redirects +* CB-7712 remove references to `closebuttoncaption` +* CB-7850 clarify role of whitelist +* CB-7720 check if event is null since OK string from success callback was removed +* CB-7471 cordova-plugin-inappbrowser documentation translation: cordova-plugin-inappbrowser + +### 0.6.0 (Feb 04, 2015) +* CB-8270 ios: Remove usage of `[arr JSONString]`, since it's been renamed to `cdv_JSONString` +* ubuntu: implement inject* functions +* ubuntu: port to oxide +* CB-7897 ios, android: Update to work with whilelist plugins in Cordova 4.x + +### 1.0.0 (Apr 15, 2015) +* CB-8746 gave plugin major version bump +* CB-7689 Adds insertCSS support for windows platform +* CB-4930 - (prefix) InAppBrowser should take into account the status bar +* CB-8635 Improves UX on windows platform +* CB-8661 Return executed script result on Windows +* CB-8683 updated wp and browser specific references of old id to new id +* CB-8683 changed plugin-id to pacakge-name +* CB-8653 properly updated translated docs to use new id +* CB-8653 updated translated docs to use new id +* Use TRAVIS_BUILD_DIR, install paramedic by npm +* CB-8432 Correct styles for browser wrapper to display it correctly on some pages +* CB-8659 - Update InAppBrowser to support both cordova-ios 4.0.x and 3.x (closes #93) +* CB-7961 Add cordova-plugin-inappbrowser support for browser platform +* CB-8653 Updated Readme +* Update docs for Android zoom=no option +* Added option to disable/enable zoom controls +* updated docs, set hardwareback default to true +* Add a hardwareback option to allow for the hardware back button to go back. +* CB-8570 Integrate TravisCI +* CB-8438 cordova-plugin-inappbrowser documentation translation: cordova-plugin-inappbrowser +* CB-8538 Added package.json file +* Keep external android pages in a single tab. (close #61) +* CB-8444 Add a clobber for `cordova.InAppBrowser.open` (close #80) +* CB-8444 Don't clobber `window.open` - Add new symbol/clobber to access open function (`cordova.InAppBrowser.open`) - Change existing tests to use new symbol (i.e. don't rely on plugin clobber of `window.open`) - Add tests to use `window.open` via manual replace with new symbol - Update docs to deprecate plugin clobber of `window.open` diff --git a/plugins/cordova-plugin-inappbrowser/doc/de/index.md b/plugins/cordova-plugin-inappbrowser/doc/de/index.md new file mode 100644 index 00000000..d2b29d57 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/de/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +Dieses Plugin bietet eine Web-Browser-Ansicht, die beim Aufruf von `cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +Die `cordova.InAppBrowser.open()` Funktion ist definiert als Ersatz für die `window.open()` Funktion. InAppBrowser Fenster, können vorhandene `window.open()` Aufrufe durch window.open ersetzen: + + window.open = cordova.InAppBrowser.open; + + +Das InAppBrowser-Fenster verhält sich wie einen standard-Webbrowser und Cordova APIs kann nicht zugegriffen werden kann. Aus diesem Grund empfiehlt sich die InAppBrowser Wenn Sie von Drittanbietern (nicht vertrauenswürdige) Inhalte, statt zu laden, die in den wichtigsten Cordova Webview laden müssen. Die InAppBrowser unterliegt nicht der weißen Liste, noch ist Links in der Systembrowser öffnen. + +Die InAppBrowser bietet standardmäßig eine eigene GUI-Steuerelemente für den Benutzer (zurück, vor, erledigt). + +Für rückwärts Kompatibilität, dieses Plugin auch `window.open` Haken. Jedoch kann der Plugin installiert Haken der `window.open` haben unbeabsichtigte Nebenwirkungen (vor allem, wenn dieses Plugin nur als eine Abhängigkeit von einem anderen Plugin enthalten ist). Der Haken der `window.open` wird in einer zukünftigen Version entfernt. Bis der Haken aus dem Plugin entfernt wird, können die Vorgabe von apps manuell wiederherstellen: + + delete window.open // Reverts the call back to it's prototype's default + + +`window.open` im globalen Gültigkeitsbereich ist zwar InAppBrowser nicht verfügbar bis nach dem `deviceready`-Ereignis. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## Installation + + cordova plugin add cordova-plugin-inappbrowser + + +Wenn Sie alle Seite Lasten in Ihrer Anwendung durch die InAppBrowser gehen möchten, können Sie einfach `window.open` während der Initialisierung Haken. Zum Beispiel: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +Öffnet eine URL in eine neue `InAppBrowser`-Instanz, die aktuelle Browserinstanz oder der Systembrowser. + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **Ref**: Bezugnahme auf das `InAppBrowser` Fenster. *(InAppBrowser)* + +* **URL**: die URL um den *(String)* zu laden. Rufen Sie `encodeURI()` auf, wenn die URL Unicode-Zeichen enthält. + +* **target**: das Ziel in welchem die URL geladen werden soll. Standardmäßig entspricht dieser Wert `_self` . *(String)* + + * `_self`: Öffnet sich in der Cordova WebView wenn der URL in der Whitelist ist, andernfalls es öffnet sich in der`InAppBrowser`. + * `_blank`: Öffnet den`InAppBrowser`. + * `_system`: Öffnet in den System-Web-Browser. + +* **options**: Optionen für die `InAppBrowser` . Optional, säumige an: `location=yes` . *(String)* + + Die `options` Zeichenfolge muss keine Leerstelle enthalten, und jede Funktion Name/Wert-Paare müssen durch ein Komma getrennt werden. Featurenamen Groß-/Kleinschreibung. Alle Plattformen unterstützen die anderen Werte: + + * **location**: Legen Sie auf `yes` oder `no` , machen die `InAppBrowser` der Adressleiste ein- oder ausschalten. + + Nur Android: + + * **hidden**: Legen Sie auf `yes` um den Browser zu erstellen und laden Sie die Seite, aber nicht zeigen. Das Loadstop-Ereignis wird ausgelöst, wenn der Ladevorgang abgeschlossen ist. Weglassen oder auf `no` (Standard), den Browser öffnen und laden normalerweise zu haben. + * **clearcache**: Legen Sie auf `yes` , der Browser ist Cookiecache gelöscht, bevor das neue Fenster geöffnet wird + * **clearsessioncache**: Legen Sie auf `yes` zu der Session Cookie Cache gelöscht, bevor das neue Fenster geöffnet wird + + iOS nur: + + * **closebuttoncaption**: Legen Sie auf eine Zeichenfolge als Beschriftung der **fertig** -Schaltfläche verwenden. Beachten Sie, dass Sie diesen Wert selbst zu lokalisieren müssen. + * **disallowoverscroll**: Legen Sie auf `yes` oder `no` (Standard ist `no` ). Aktiviert/deaktiviert die UIWebViewBounce-Eigenschaft. + * **hidden**: Legen Sie auf `yes` um den Browser zu erstellen und laden Sie die Seite, aber nicht zeigen. Das Loadstop-Ereignis wird ausgelöst, wenn der Ladevorgang abgeschlossen ist. Weglassen oder auf `no` (Standard), den Browser öffnen und laden normalerweise zu haben. + * **clearcache**: Legen Sie auf `yes` , der Browser ist Cookiecache gelöscht, bevor das neue Fenster geöffnet wird + * **clearsessioncache**: Legen Sie auf `yes` zu der Session Cookie Cache gelöscht, bevor das neue Fenster geöffnet wird + * **toolbar**: Legen Sie auf `yes` oder `no` Aktivieren Sie die Symbolleiste ein- oder Ausschalten für InAppBrowser (Standard:`yes`) + * **enableViewportScale**: Legen Sie auf `yes` oder `no` , Viewport Skalierung durch ein Meta-Tag (standardmäßig zu verhindern`no`). + * **mediaPlaybackRequiresUserAction**: Legen Sie auf `yes` oder `no` , HTML5 audio oder video von automatisches Abspielen (standardmäßig zu verhindern`no`). + * **allowInlineMediaPlayback**: Legen Sie auf `yes` oder `no` Inline-HTML5-Media-Wiedergabe, Darstellung im Browser-Fenster, sondern in eine gerätespezifische Wiedergabe-Schnittstelle ermöglichen. Des HTML `video` Element muss auch die `webkit-playsinline` Attribut (Standard:`no`) + * **keyboardDisplayRequiresUserAction**: Legen Sie auf `yes` oder `no` um die Tastatur zu öffnen, wenn Formularelemente Fokus per JavaScript erhalten `focus()` Anruf (Standard:`yes`). + * **suppressesIncrementalRendering**: Legen Sie auf `yes` oder `no` zu warten, bis alle neuen anzeigen-Inhalte empfangen wird, bevor Sie wiedergegeben wird (standardmäßig`no`). + * **presentationstyle**: Legen Sie auf `pagesheet` , `formsheet` oder `fullscreen` [Präsentationsstil][1] (standardmäßig fest`fullscreen`). + * **transitionstyle**: Legen Sie auf `fliphorizontal` , `crossdissolve` oder `coververtical` [Übergangsstil][2] (standardmäßig fest`coververtical`). + * **toolbarposition**: Legen Sie auf `top` oder `bottom` (Standard ist `bottom` ). Bewirkt, dass die Symbolleiste am oberen oder unteren Rand des Fensters sein. + + Nur Windows: + + * **hidden**: Legen Sie auf `yes` um den Browser zu erstellen und laden Sie die Seite, aber nicht zeigen. Das Loadstop-Ereignis wird ausgelöst, wenn der Ladevorgang abgeschlossen ist. Weglassen oder auf `no` (Standard), den Browser öffnen und laden normalerweise zu haben. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Firefox OS +* iOS +* Windows 8 und 8.1 +* Windows Phone 7 und 8 + +### Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### Firefox OS Macken + +Als Plugin jedes Design erzwingen nicht besteht die Notwendigkeit, einige CSS-Regeln hinzuzufügen, wenn bei `target='_blank'`. Die Regeln könnte wie diese aussehen. + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +Bei einem Aufruf von `cordova.InAppBrowser.open` zurückgegebene Objekt.. + +### Methoden + +* addEventListener +* removeEventListener +* Schließen +* Karte +* executeScript +* insertCSS + +## addEventListener + +> Fügt einen Listener für eine Veranstaltung aus der`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **Ref**: Bezugnahme auf die `InAppBrowser` Fenster *(InAppBrowser)* + +* **EventName**: das Ereignis zu warten *(String)* + + * **Loadstart**: Ereignis wird ausgelöst, wenn die `InAppBrowser` beginnt, eine URL zu laden. + * **Loadstop**: Ereignis wird ausgelöst, wenn der `InAppBrowser` beendet ist, eine URL laden. + * **LoadError**: Ereignis wird ausgelöst, wenn der `InAppBrowser` ein Fehler auftritt, wenn Sie eine URL zu laden. + * **Ausfahrt**: Ereignis wird ausgelöst, wenn das `InAppBrowser` -Fenster wird geschlossen. + +* **Rückruf**: die Funktion, die ausgeführt wird, wenn das Ereignis ausgelöst wird. Die Funktion übergeben wird ein `InAppBrowserEvent` -Objekt als Parameter. + +### InAppBrowserEvent Eigenschaften + +* **Typ**: Eventname, entweder `loadstart` , `loadstop` , `loaderror` , oder `exit` . *(String)* + +* **URL**: die URL, die geladen wurde. *(String)* + +* **Code**: der Fehler-Code, nur im Fall von `loaderror` . *(Anzahl)* + +* **Nachricht**: die Fehlermeldung angezeigt, nur im Fall von `loaderror` . *(String)* + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* iOS +* Windows 8 und 8.1 +* Windows Phone 7 und 8 + +### Kurzes Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> Entfernt einen Listener für eine Veranstaltung aus der`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **Ref**: Bezugnahme auf die `InAppBrowser` Fenster. *(InAppBrowser)* + +* **EventName**: das Ereignis zu warten. *(String)* + + * **Loadstart**: Ereignis wird ausgelöst, wenn die `InAppBrowser` beginnt, eine URL zu laden. + * **Loadstop**: Ereignis wird ausgelöst, wenn der `InAppBrowser` beendet ist, eine URL laden. + * **LoadError**: Ereignis wird ausgelöst, wenn die `InAppBrowser` trifft einen Fehler beim Laden einer URLs. + * **Ausfahrt**: Ereignis wird ausgelöst, wenn das `InAppBrowser` -Fenster wird geschlossen. + +* **Rückruf**: die Funktion ausgeführt, wenn das Ereignis ausgelöst wird. Die Funktion übergeben wird ein `InAppBrowserEvent` Objekt. + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* iOS +* Windows 8 und 8.1 +* Windows Phone 7 und 8 + +### Kurzes Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## Schließen + +> Schließt die `InAppBrowser` Fenster. + + ref.close(); + + +* **Ref**: Bezugnahme auf die `InAppBrowser` Fenster *(InAppBrowser)* + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* Firefox OS +* iOS +* Windows 8 und 8.1 +* Windows Phone 7 und 8 + +### Kurzes Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## Karte + +> Zeigt ein InAppBrowser-Fenster, das geöffnet wurde, versteckt. Aufrufen, dies hat keine Auswirkungen, wenn die InAppBrowser schon sichtbar war. + + ref.show(); + + +* **Ref**: Verweis auf die (InAppBrowser) Fenster`InAppBrowser`) + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* iOS +* Windows 8 und 8.1 + +### Kurzes Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> Fügt JavaScript-Code in das `InAppBrowser` Fenster + + ref.executeScript(details, callback); + + +* **Ref**: Bezugnahme auf die `InAppBrowser` Fenster. *(InAppBrowser)* + +* **InjectDetails**: Informationen über das Skript ausgeführt, angeben, entweder ein `file` oder `code` Schlüssel. *(Objekt)* + + * **Datei**: URL des Skripts zu injizieren. + * **Code**: Text des Skripts zu injizieren. + +* **Rückruf**: die Funktion, die ausgeführt wird, nachdem der JavaScript-Code injiziert wird. + + * Wenn das eingefügte Skript vom Typ ist `code` , der Rückruf führt mit einen einzelnen Parameter, der der Rückgabewert des Skripts ist, umwickelt ein `Array` . Bei Multi-Line-Skripten ist der Rückgabewert von der letzten Anweisung oder den letzten Ausdruck ausgewertet. + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* iOS +* Windows 8 und 8.1 + +### Kurzes Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> Injiziert CSS in der `InAppBrowser` Fenster. + + ref.insertCSS(details, callback); + + +* **Ref**: Bezugnahme auf die `InAppBrowser` Fenster *(InAppBrowser)* + +* **InjectDetails**: Informationen über das Skript ausgeführt, angeben, entweder ein `file` oder `code` Schlüssel. *(Objekt)* + + * **Datei**: URL des Stylesheets zu injizieren. + * **Code**: Text des Stylesheets zu injizieren. + +* **Rückruf**: die Funktion, die ausgeführt wird, nachdem die CSS injiziert wird. + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* iOS + +### Kurzes Beispiel + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/es/index.md b/plugins/cordova-plugin-inappbrowser/doc/es/index.md new file mode 100644 index 00000000..fc5b7b13 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/es/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +Este plugin proporciona una vista de navegador web que se muestra cuando se llama a `cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +El `cordova.InAppBrowser.open()` función se define como un reemplazo de sobreponer para la función `window.Open ()`. Llamadas existentes `window.Open ()` pueden utilizar la ventana InAppBrowser, mediante la sustitución de window.open: + + window.open = cordova.InAppBrowser.open; + + +La ventana de InAppBrowser se comporta como un navegador web estándar y no puede acceder a Cordova APIs. Por este motivo, se recomienda la InAppBrowser si necesita cargar contenido de terceros (confianza), en lugar de que cargar en el principal webview Cordova. El InAppBrowser no está sujeta a la lista blanca, ni va a abrir enlaces en el navegador del sistema. + +El InAppBrowser proporciona por defecto sus propios controles GUI para el usuario (atras, adelante, hacer). + +Para atrás compatibilidad, este plugin también ganchos `window.open`. Sin embargo, el gancho de `window.open` plugin instalado puede tener efectos secundarios no deseados (especialmente si este plugin está incluido únicamente como una dependencia de otro plugin). El gancho de `window.open` se quitará en una versión futura de principal. Hasta que el gancho se ha extraÃdo el plugin, aplicaciones pueden restaurar manualmente el comportamiento por defecto: + + delete window.open // Reverts the call back to it's prototype's default + + +Aunque `window.open` es en el ámbito global, InAppBrowser no está disponible hasta después del evento `deviceready`. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## Instalación + + cordova plugin add cordova-plugin-inappbrowser + + +Si quieres todas las cargas de página en su aplicación para ir a través de la InAppBrowser, simplemente puedes conectar `window.open` durante la inicialización. Por ejemplo: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +Se abre una dirección URL en una nueva instancia de `InAppBrowser`, en la instancia actual del navegador o el navegador del sistema. + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **ref**: referencia a la `InAppBrowser` ventana. *(InAppBrowser)* + +* **url**: el URL para cargar *(String)*. Llame a `encodeURI()` en esto si la URL contiene caracteres Unicode. + +* **target**: el objetivo en el que se carga la URL, un parámetro opcional que se utiliza de forma predeterminada `_self`. *(String)* + + * `_self`: se abre en el Cordova WebView si la URL está en la lista blanca, de lo contrario se abre en el `InAppBrowser`. + * `_blank`: abre en el `InAppBrowser`. + * `_system`: se abre en el navegador del sistema. + +* **options**: opciones para el `InAppBrowser`. Opcional, contumaz a: `location=yes`. *(String)* + + La cadena de `options` no debe contener ningún espacio en blanco, y los pares de nombre y valor de cada caracterÃstica deben estar separados por una coma. Los nombres de función son minúsculas. Todas las plataformas admiten el valor siguiente: + + * **location**: se establece en `yes` o `no` para activar o desactivar la barra de ubicación de la `InAppBrowser`. + + Sólo Android: + + * **oculta**: a `yes` para crear el navegador y cargar la página, pero no lo demuestra. El evento loadstop se desencadena cuando termine la carga. Omitir o establecer en `no` (por defecto) para que el navegador abra y carga normalmente. + * **clearcache**: a `yes` para que el navegador es caché de galleta despejado antes de que se abra la nueva ventana + * **clearsessioncache**: a `yes` que la caché de cookie de sesión despejado antes de que se abra la nueva ventana + + Sólo iOS: + + * **closebuttoncaption**: establecer una cadena para usar como tÃtulo del botón **hecho** . Tenga en cuenta que necesitas localizar este valor por sà mismo. + * **disallowoverscroll**: A `yes` o `no` (valor por defecto es `no` ). Activa/desactiva la propiedad UIWebViewBounce. + * **oculta**: a `yes` para crear el navegador y cargar la página, pero no lo demuestra. El evento loadstop se desencadena cuando termine la carga. Omitir o a `no` (por defecto) para que el navegador abra y carga normalmente. + * **clearcache**: a `yes` para que el navegador es caché de galleta despejado antes de que se abra la nueva ventana + * **clearsessioncache**: a `yes` que la caché de cookie de sesión despejado antes de que se abra la nueva ventana + * **barra de herramientas**: a `yes` o `no` para activar la barra de herramientas on u off para el InAppBrowser (por defecto`yes`) + * **enableViewportScale**: Set a `yes` o `no` para evitar viewport escalar a través de una etiqueta meta (por defecto a `no`). + * **mediaPlaybackRequiresUserAction**: Set a `yes` o `no` para evitar HTML5 audio o vÃdeo de reproducción automática (por defecto a `no`). + * **allowInlineMediaPlayback**: A `yes` o `no` para permitir la reproducción de los medios de comunicación en lÃnea HTML5, mostrando en la ventana del navegador en lugar de una interfaz especÃfica del dispositivo de reproducción. Elemento `video` de HTML también debe incluir el atributo de `webkit-playsinline` (por defecto a `no`) + * **keyboardDisplayRequiresUserAction**: se establece en `yes` o `no` para abrir el teclado cuando elementos de formulario reciben el foco mediante llamada de JavaScript de `focus()` (por defecto a `yes`). + * **suppressesIncrementalRendering**: se establece en `yes` o `no` para esperar hasta que todos los nuevos contenidos de vista se recibieron antes de ser prestados (por defecto a `no`). + * **presentationstyle**: se establece en `pagesheet`, `formsheet` o `fullscreen` para definir el [estilo de la presentación][1] (por defecto a `fullscreen`). + * **transitionstyle**: se establece en `fliphorizontal`, `crossdissolve` o `coververtical` para definir el [estilo de transición][2] (por defecto `coververtical`). + * **toolbarposition**: A `top` o `bottom` (valor por defecto es `bottom` ). Hace que la barra de herramientas en la parte superior o inferior de la ventana. + + Sólo Windows: + + * **oculta**: a `yes` para crear el navegador y cargar la página, pero no lo demuestra. El evento loadstop se desencadena cuando termine la carga. Omitir o a `no` (por defecto) para que el navegador abra y carga normalmente. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### Plataformas soportadas + +* Amazon fire OS +* Android +* BlackBerry 10 +* Firefox OS +* iOS +* Windows 8 y 8.1 +* Windows Phone 7 y 8 + +### Ejemplo + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### Firefox OS rarezas + +Como plugin no cumplir cualquier diseño es necesario añadir algunas reglas CSS si abre con `target = '_blank'`. Las reglas pueden parecerse a estos + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +El objeto devuelto desde una llamada a `cordova.InAppBrowser.open`. + +### Métodos + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> Añade un detector para un evento de la `InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **ref**: referencia a la ventana de `InAppBrowser` *(InAppBrowser)* + +* **eventName**: el evento para escuchar *(String)* + + * **loadstart**: evento se desencadena cuando el `InAppBrowser` comienza a cargar una dirección URL. + * **loadstop**: evento desencadena cuando los acabados `InAppBrowser` cargar una dirección URL. + * **loaderror**: evento se desencadena cuando el `InAppBrowser` encuentra un error al cargar una dirección URL. + * **exit**: evento se desencadena cuando se cierra la ventana de `InAppBrowser`. + +* **callback**: la función que se ejecuta cuando se desencadene el evento. La función se pasa un objeto `InAppBrowserEvent` como un parámetro. + +### InAppBrowserEvent propiedades + +* **type**: eventname, `loadstart`, `loadstop`, `loaderror` o `exit`. *(String)* + +* **url**: la URL que se cargó. *(String)* + +* **code**: el código de error, sólo en el caso de `loaderror`. *(Número)* + +* **message**: el mensaje de error, sólo en el caso de `loaderror`. *(String)* + +### Plataformas soportadas + +* Amazon fire OS +* Android +* iOS +* Windows 8 y 8.1 +* Windows Phone 7 y 8 + +### Ejemplo rápido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> Elimina un detector para un evento de la `InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **ref**: referencia a la ventana de `InAppBrowser`. *(InAppBrowser)* + +* **eventName**: dejar de escuchar para el evento. *(String)* + + * **loadstart**: evento se desencadena cuando el `InAppBrowser` comienza a cargar una dirección URL. + * **loadstop**: evento desencadena cuando los acabados `InAppBrowser` cargar una dirección URL. + * **loaderror**: evento se desencadena cuando el `InAppBrowser` se encuentra con un error al cargar una dirección URL. + * **exit**: evento se desencadena cuando se cierra la ventana de `InAppBrowser`. + +* **callback**: la función a ejecutar cuando se desencadene el evento. La función se pasa un objeto `InAppBrowserEvent`. + +### Plataformas soportadas + +* Amazon fire OS +* Android +* iOS +* Windows 8 y 8.1 +* Windows Phone 7 y 8 + +### Ejemplo rápido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> Cierra la ventana de `InAppBrowser`. + + ref.close(); + + +* **ref**: referencia a la ventana de `InAppBrowser` *(InAppBrowser)* + +### Plataformas soportadas + +* Amazon fire OS +* Android +* Firefox OS +* iOS +* Windows 8 y 8.1 +* Windows Phone 7 y 8 + +### Ejemplo rápido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> Muestra una ventana InAppBrowser que abrió sus puertas ocultada. Esto no tiene efecto si el InAppBrowser ya era visible. + + ref.show(); + + +* **ref**: referencia a la (ventana) InAppBrowser`InAppBrowser`) + +### Plataformas soportadas + +* Amazon fire OS +* Android +* iOS +* Windows 8 y 8.1 + +### Ejemplo rápido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> Inyecta código JavaScript en la ventana de `InAppBrowser` + + ref.executeScript(details, callback); + + +* **ref**: referencia a la ventana de `InAppBrowser`. *(InAppBrowser)* + +* **injectDetails**: detalles de la secuencia de comandos para ejecutar, o especificar un `file` o `code` clave. *(Objeto)* + + * **file**: URL del script para inyectar. + * **code**: texto de la escritura para inyectar. + +* **devolución de llamada**: la función que se ejecuta después de inyecta el código JavaScript. + + * Si el script inyectado es del tipo de `code`, la devolución de llamada se ejecuta con un solo parámetro, que es el valor devuelto del guión, envuelto en una `Array`. Para scripts multilÃneas, este es el valor devuelto de la última declaración, o la última expresión evaluada. + +### Plataformas soportadas + +* Amazon fire OS +* Android +* iOS +* Windows 8 y 8.1 + +### Ejemplo rápido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> Inyecta CSS en la ventana de `InAppBrowser`. + + ref.insertCSS(details, callback); + + +* **ref**: referencia a la ventana de `InAppBrowser` *(InAppBrowser)* + +* **injectDetails**: detalles de la secuencia de comandos para ejecutar, o especificar un `file` o `code` clave. *(Objeto)* + + * **file**: URL de la hoja de estilos para inyectar. + * **code**: texto de la hoja de estilos para inyectar. + +* **callback**: la función que se ejecuta después de inyectar el CSS. + +### Plataformas soportadas + +* Amazon fire OS +* Android +* iOS + +### Ejemplo rápido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/fr/index.md b/plugins/cordova-plugin-inappbrowser/doc/fr/index.md new file mode 100644 index 00000000..4f22d13b --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/fr/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +Ce module fournit une vue de navigateur web qui s'affiche lorsque vous appelez `cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +Le `cordova.InAppBrowser.open()` fonction est définie pour être un remplacement rapide de la fonction `window.open()`. Les appels existants `window.open()` peuvent utiliser la fenêtre de InAppBrowser, en remplaçant window.open : + + window.open = cordova.InAppBrowser.open; + + +La fenêtre de InAppBrowser se comporte comme un navigateur web standard et ne peut pas accéder aux APIs Cordova. Pour cette raison, le InAppBrowser est recommandé si vous devez charger le contenu de tiers (non approuvé), au lieu de chargement que dans le principaux webview Cordova. Le InAppBrowser n'est pas soumis à la liste blanche, ni s'ouvre les liens dans le navigateur de système. + +Le InAppBrowser fournit par défaut ses propres contrôles de GUI pour l'utilisateur (arrière, avant, fait). + +Pour vers l'arrière la compatibilité, ce plugin crochets également `window.open`. Cependant, le plugin installé crochet de `window.open` peut avoir des effets secondaires involontaires (surtout si ce plugin est inclus uniquement comme une dépendance d'un autre plugin). Le crochet de `window.open` sera supprimé dans une future version majeure. Jusqu'à ce que le crochet est supprimé de la plugin, apps peuvent restaurer manuellement le comportement par défaut : + + delete window.open // Reverts the call back to it's prototype's default + + +Bien que `window.open` est dans la portée globale, InAppBrowser n'est pas disponible jusqu'à ce qu'après l'événement `deviceready`. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## Installation + + cordova plugin add cordova-plugin-inappbrowser + + +Si vous souhaitez que toutes les charges de la page dans votre application de passer par le InAppBrowser, vous pouvez simplement accrocher `window.open` pendant l'initialisation. Par exemple : + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +Ouvre une URL dans une nouvelle instance de `InAppBrowser`, l'instance de navigateur actuelle ou dans l'Explorateur du système. + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **ref** : référence à la fenêtre `InAppBrowser`. *(InAppBrowser)* + +* **url** : l'URL à charger *(String)*. À encoder au préalable via `encodeURI()` si celle-ci contient des caractères Unicode. + +* **target** : la cible du chargement de l'URL, ce paramètre est optionnel, sa valeur par défaut est `_self`. *(String)* + + * `_self` : dirige le chargement vers la WebView Cordova si l'URL figure dans la liste blanche, sinon dans une fenêtre `InAppBrowser`. + * `_blank` : dirige le chargement vers une fenêtre `InAppBrowser`. + * `_system` : dirige le chargement vers le navigateur Web du système. + +* **options** : permet de personnaliser la fenêtre `InAppBrowser`. Paramètre facultatif dont la valeur par défaut est `location=yes`. *(String)* + + La chaîne `options` ne doit contenir aucun caractère vide, chaque paire nom/valeur représentant une fonctionnalité doit être séparée de la précédente par une virgule. Les noms de fonctionnalités sont sensibles à la casse. Toutes les plates-formes prennent en charge la valeur ci-dessous : + + * **location** : régler à `yes` ou `no` afin d'afficher ou masquer la barre d'adresse de la fenêtre `InAppBrowser`. + + Android uniquement : + + * **caché**: la valeur `yes` pour créer le navigateur et charger la page, mais ne pas le montrer. L'événement loadstop est déclenché lorsque le chargement est terminé. Omettre ou la valeur `no` (par défaut) pour que le navigateur ouvrir et charger normalement. + * **ClearCache**: la valeur `yes` pour que le navigateur du cache de cookie effacé, avant l'ouverture de la nouvelle fenêtre + * **clearsessioncache**: la valeur `yes` pour avoir le cache de cookie de session autorisé avant l'ouverture de la nouvelle fenêtre + + iOS uniquement : + + * **closebuttoncaption**: affectez une chaîne à utiliser comme la **fait** légende du bouton. Notez que vous devrez localiser cette valeur vous-même. + * **disallowoverscroll**: la valeur `yes` ou `no` (valeur par défaut est `no` ). Active/désactive la propriété UIWebViewBounce. + * **caché**: la valeur `yes` pour créer le navigateur et charger la page, mais ne pas le montrer. L'événement loadstop est déclenché lorsque le chargement est terminé. Omettre ou la valeur `no` (par défaut) pour que le navigateur ouvrir et charger normalement. + * **ClearCache**: la valeur `yes` pour que le navigateur du cache de cookie effacé, avant l'ouverture de la nouvelle fenêtre + * **clearsessioncache**: la valeur `yes` pour avoir le cache de cookie de session autorisé avant l'ouverture de la nouvelle fenêtre + * **barre d'outils**: la valeur `yes` ou `no` pour activer la barre d'outils ou désactiver pour le InAppBrowser (par défaut,`yes`) + * **enableViewportScale**: la valeur `yes` ou `no` pour empêcher la fenêtre de mise à l'échelle par une balise meta (par défaut,`no`). + * **mediaPlaybackRequiresUserAction**: la valeur `yes` ou `no` pour empêcher le HTML5 audio ou vidéo de la lecture automatique (par défaut,`no`). + * **allowInlineMediaPlayback**: la valeur `yes` ou `no` pour permettre la lecture du média en ligne HTML5, affichage dans la fenêtre du navigateur plutôt que d'une interface de lecture spécifique au périphérique. L'HTML `video` élément doit également inclure la `webkit-playsinline` attribut (par défaut,`no`) + * **keyboardDisplayRequiresUserAction**: la valeur `yes` ou `no` pour ouvrir le clavier lorsque les éléments reçoivent le focus par l'intermédiaire de JavaScript `focus()` appel (par défaut,`yes`). + * **suppressesIncrementalRendering**: la valeur `yes` ou `no` d'attendre que toutes les nouveautés de vue sont reçue avant d'être restitué (par défaut,`no`). + * **presentationstyle**: la valeur `pagesheet` , `formsheet` ou `fullscreen` pour définir le [style de présentation][1] (par défaut,`fullscreen`). + * **transitionstyle**: la valeur `fliphorizontal` , `crossdissolve` ou `coververtical` pour définir le [style de transition][2] (par défaut,`coververtical`). + * **toolbarposition**: la valeur `top` ou `bottom` (valeur par défaut est `bottom` ). Causes de la barre d'outils être en haut ou en bas de la fenêtre. + + Windows uniquement : + + * **caché**: la valeur `yes` pour créer le navigateur et charger la page, mais ne pas le montrer. L'événement loadstop est déclenché lorsque le chargement est terminé. Omettre ou la valeur `no` (par défaut) pour que le navigateur ouvrir et charger normalement. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Firefox OS +* iOS +* Windows 8 et 8.1 +* Windows Phone 7 et 8 + +### Exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### Firefox OS Quirks + +Comme plugin n'est pas appliquer n'importe quelle conception il est nécessaire d'ajouter quelques règles CSS si ouvert avec `target= _blank`. Les règles pourraient ressembler à ces + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +L'objet retourné par un appel à `cordova.InAppBrowser.open`. + +### Méthodes + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> Ajoute un écouteur pour un évènement de la fenêtre `InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **ref** : référence à la fenêtre `InAppBrowser`. *(InAppBrowser)* + +* **eventname** : l'évènement à écouter *(String)* + + * **loadstart** : évènement déclenché lorsque le chargement d'une URL débute dans la fenêtre `InAppBrowser`. + * **loadstop** : évènement déclenché lorsque la fenêtre `InAppBrowser` finit de charger une URL. + * **loaderror** : évènement déclenché si la fenêtre `InAppBrowser` rencontre une erreur lors du chargement d'une URL. + * **exit** : évènement déclenché lorsque la fenêtre `InAppBrowser` est fermée. + +* **callback** : la fonction à exécuter lorsque l'évènement se déclenche. Un objet `InAppBrowserEvent` lui est transmis comme paramètre. + +### Propriétés de InAppBrowserEvent + +* **type** : le nom de l'évènement, soit `loadstart`, `loadstop`, `loaderror` ou `exit`. *(String)* + +* **url** : l'URL ayant été chargée. *(String)* + +* **code** : le code d'erreur, seulement pour `loaderror`. *(Number)* + +* **message** : un message d'erreur, seulement pour `loaderror`. *(String)* + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* iOS +* Windows 8 et 8.1 +* Windows Phone 7 et 8 + +### Petit exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> Supprime un écouteur pour un évènement de la fenêtre `InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **ref** : référence à la fenêtre `InAppBrowser`. *(InAppBrowser)* + +* **eventname** : l'évènement pour lequel arrêter l'écoute. *(String)* + + * **loadstart**: événement déclenche quand le `InAppBrowser` commence à charger une URL. + * **loadstop**: événement déclenche lorsque la `InAppBrowser` finit de charger une URL. + * **loaderror** : évènement déclenché si la fenêtre `InAppBrowser` rencontre une erreur lors du chargement d'une URL. + * **sortie**: événement déclenche quand le `InAppBrowser` fenêtre est fermée. + +* **callback** : la fonction à exécuter lorsque l'évènement se déclenche. Un objet `InAppBrowserEvent` lui est transmis comme paramètre. + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* iOS +* Windows 8 et 8.1 +* Windows Phone 7 et 8 + +### Petit exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> Ferme la fenêtre `InAppBrowser`. + + ref.close(); + + +* **Réf**: référence à la `InAppBrowser` fenêtre *(InAppBrowser)* + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* Firefox OS +* iOS +* Windows 8 et 8.1 +* Windows Phone 7 et 8 + +### Petit exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> Affiche une fenêtre InAppBrowser qui a été ouverte cachée. Appeler cette méthode n'a aucun effet si la fenêtre en question est déjà visible. + + ref.show(); + + +* **Réf**: référence à la fenêtre () InAppBrowser`InAppBrowser`) + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* iOS +* Windows 8 et 8.1 + +### Petit exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> Injecte du code JavaScript dans la fenêtre `InAppBrowser` + + ref.executeScript(details, callback); + + +* **Réf**: référence à la `InAppBrowser` fenêtre. *(InAppBrowser)* + +* **injectDetails** : détails du script à exécuter, requérant une propriété `file` ou `code`. *(Object)* + + * **file** : URL du script à injecter. + * **code** : texte du script à injecter. + +* **callback** : une fonction exécutée après l'injection du code JavaScript. + + * Si le script injecté est de type `code`, un seul paramètre est transmis à la fonction callback, correspondant à la valeur de retour du script enveloppée dans un `Array`. Pour les scripts multilignes, il s'agit de la valeur renvoyée par la dernière instruction ou la dernière expression évaluée. + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* iOS +* Windows 8 et 8.1 + +### Petit exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> Injecte des règles CSS dans la fenêtre `InAppBrowser`. + + ref.insertCSS(details, callback); + + +* **Réf**: référence à la `InAppBrowser` fenêtre *(InAppBrowser)* + +* **injectDetails**: Détails du script à exécuter, spécifiant soit un `file` ou `code` clés. *(Objet)* + + * **file** : URL de la feuille de style à injecter. + * **code** : contenu de la feuille de style à injecter. + +* **callback** : une fonction exécutée après l'injection du fichier CSS. + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* iOS + +### Petit exemple + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/it/index.md b/plugins/cordova-plugin-inappbrowser/doc/it/index.md new file mode 100644 index 00000000..73654628 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/it/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +Questo plugin fornisce una vista di browser web che viene visualizzato quando si chiama `di cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +Il `cordova.InAppBrowser.open()` funzione è definita per essere un rimpiazzo per la funzione `window.open`. Esistenti chiamate `Window` possono utilizzare la finestra di InAppBrowser, sostituendo window.open(): + + window.open = cordova.InAppBrowser.open; + + +La finestra di InAppBrowser si comporta come un browser web standard e non può accedere a Cordova APIs. Per questo motivo, è consigliabile la InAppBrowser se è necessario caricare il contenuto (non attendibile) di terze parti, invece di caricamento che in webview Cordova principale. Il InAppBrowser non è soggetto alla whitelist, né sta aprendo il link nel browser di sistema. + +La InAppBrowser fornisce di default propri controlli GUI per l'utente (indietro, avanti, fatto). + +Per indietro la compatibilità , questo plugin ganci anche `window.open`. Tuttavia, il plugin installato gancio di `window.open` può avere effetti collaterali indesiderati (soprattutto se questo plugin è incluso solo come dipendenza di un altro plugin). Il gancio di `window. open` verrà rimosso in una futura release principale. Fino a quando il gancio è rimosso dal plugin, apps può ripristinare manualmente il comportamento predefinito: + + delete window.open // Reverts the call back to it's prototype's default + + +Sebbene `window.open` sia in ambito globale, InAppBrowser non è disponibile fino a dopo l'evento `deviceready`. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## Installazione + + cordova plugin add cordova-plugin-inappbrowser + + +Se si desidera che tutti i carichi di pagina nell'app di passare attraverso il InAppBrowser, si può semplicemente collegare `window.open` durante l'inizializzazione. Per esempio: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +Apre un URL in una nuova istanza di `InAppBrowser`, l'istanza corrente del browser o il browser di sistema. + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **ref**: fare riferimento alla `InAppBrowser` finestra. *(InAppBrowser)* + +* **url**: l'URL da caricare *(String)*. Chiamare `encodeURI()` su questo, se l'URL contiene caratteri Unicode. + +* **target**: la destinazione in cui caricare l'URL, un parametro facoltativo che il valore predefinito è `_self` . *(String)* + + * `_self`: Si apre in Cordova WebView se l'URL è nella lista bianca, altrimenti si apre nella`InAppBrowser`. + * `_blank`: Apre il`InAppBrowser`. + * `_system`: Si apre nel browser web del sistema. + +* **options**: opzioni per il `InAppBrowser` . Opzionale, inadempiente a: `location=yes` . *(String)* + + Il `options` stringa non deve contenere alcun spazio vuoto, e coppie nome/valore ogni funzionalità devono essere separate da una virgola. Caratteristica nomi sono tra maiuscole e minuscole. Tutte le piattaforme supportano il valore riportato di seguito: + + * **posizione**: impostata su `yes` o `no` per trasformare il `InAppBrowser` di barra di posizione on o off. + + Solo su Android: + + * **nascosti**: impostare su `yes` per creare il browser e caricare la pagina, ma non mostrarlo. L'evento loadstop viene generato quando il caricamento è completato. Omettere o impostata su `no` (impostazione predefinita) per avere il browser aperto e caricare normalmente. + * **ClearCache**: impostare su `yes` per avere il browser cache cookie ha lasciata prima dell'apertura della nuova finestra + * **clearsessioncache**: impostare su `yes` per avere la cache cookie di sessione cancellata prima dell'apertura della nuova finestra + + solo iOS: + + * **closebuttoncaption**: impostare una stringa da utilizzare come didascalia del pulsante **fatto** . Si noti che è necessario localizzare questo valore a te stesso. + * **disallowoverscroll**: impostare su `yes` o `no` (default è `no` ). Attiva/disattiva la proprietà UIWebViewBounce. + * **nascosti**: impostare su `yes` per creare il browser e caricare la pagina, ma non mostrarlo. L'evento loadstop viene generato quando il caricamento è completato. Omettere o impostata su `no` (impostazione predefinita) per avere il browser aperto e caricare normalmente. + * **ClearCache**: impostare su `yes` per avere il browser cache cookie ha lasciata prima dell'apertura della nuova finestra + * **clearsessioncache**: impostare su `yes` per avere la cache cookie di sessione cancellata prima dell'apertura della nuova finestra + * **Toolbar**: impostare su `yes` o `no` per attivare la barra degli strumenti o disattivare per il InAppBrowser (default`yes`) + * **enableViewportScale**: impostare su `yes` o `no` per impedire la viewport ridimensionamento tramite un tag meta (default`no`). + * **mediaPlaybackRequiresUserAction**: impostare su `yes` o `no` per impedire HTML5 audio o video da AutoPlay (default`no`). + * **allowInlineMediaPlayback**: impostare su `yes` o `no` per consentire la riproduzione dei supporti HTML5 in linea, visualizzare all'interno della finestra del browser, piuttosto che un'interfaccia specifica del dispositivo di riproduzione. L'HTML `video` elemento deve includere anche il `webkit-playsinline` (default di attributo`no`) + * **keyboardDisplayRequiresUserAction**: impostare su `yes` o `no` per aprire la tastiera quando elementi form ricevano lo stato attivo tramite di JavaScript `focus()` chiamata (default`yes`). + * **suppressesIncrementalRendering**: impostare su `yes` o `no` aspettare fino a quando tutti i nuovi contenuti di vista viene ricevuto prima il rendering (default`no`). + * **presentationstyle**: impostare su `pagesheet` , `formsheet` o `fullscreen` per impostare lo [stile di presentazione][1] (default`fullscreen`). + * **transitionstyle**: impostare su `fliphorizontal` , `crossdissolve` o `coververtical` per impostare lo [stile di transizione][2] (default`coververtical`). + * **toolbarposition**: impostare su `top` o `bottom` (default è `bottom` ). Provoca la barra degli strumenti sia nella parte superiore o inferiore della finestra. + + Solo per Windows: + + * **nascosti**: impostare su `yes` per creare il browser e caricare la pagina, ma non mostrarlo. L'evento loadstop viene generato quando il caricamento è completato. Omettere o impostata su `no` (impostazione predefinita) per avere il browser aperto e caricare normalmente. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* BlackBerry 10 +* Firefox OS +* iOS +* Windows 8 e 8.1 +* Windows Phone 7 e 8 + +### Esempio + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### Firefox OS stranezze + +Come plugin non imporre alcun disegno c'è bisogno di aggiungere alcune regole CSS se aperto con `target='_blank'`. Le regole potrebbero apparire come questi + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +L'oggetto restituito da una chiamata a `di cordova.InAppBrowser.open`. + +### Metodi + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> Aggiunge un listener per un evento dal`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **Rif**: fare riferimento alla `InAppBrowser` finestra *(InAppBrowser)* + +* **EventName**: l'evento per l'ascolto *(String)* + + * **loadstart**: evento viene generato quando il `InAppBrowser` comincia a caricare un URL. + * **loadstop**: evento viene generato quando il `InAppBrowser` termina il caricamento di un URL. + * **LoadError**: evento viene generato quando il `InAppBrowser` rileva un errore durante il caricamento di un URL. + * **uscita**: evento viene generato quando il `InAppBrowser` finestra è chiusa. + +* **richiamata**: la funzione che viene eseguito quando viene generato l'evento. La funzione viene passata un `InAppBrowserEvent` oggetto come parametro. + +### Proprietà InAppBrowserEvent + +* **tipo**: il eventname, o `loadstart` , `loadstop` , `loaderror` , o `exit` . *(String)* + +* **URL**: l'URL che è stato caricato. *(String)* + +* **codice**: il codice di errore, solo nel caso di `loaderror` . *(Numero)* + +* **messaggio**: il messaggio di errore, solo nel caso di `loaderror` . *(String)* + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* iOS +* Windows 8 e 8.1 +* Windows Phone 7 e 8 + +### Esempio rapido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> Rimuove un listener per un evento dal`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **Rif**: fare riferimento alla `InAppBrowser` finestra. *(InAppBrowser)* + +* **EventName**: interrompere l'attesa per l'evento. *(String)* + + * **loadstart**: evento viene generato quando il `InAppBrowser` comincia a caricare un URL. + * **loadstop**: evento viene generato quando il `InAppBrowser` termina il caricamento di un URL. + * **LoadError**: evento viene generato quando il `InAppBrowser` rileva un errore di caricamento di un URL. + * **uscita**: evento viene generato quando il `InAppBrowser` finestra è chiusa. + +* **richiamata**: la funzione da eseguire quando viene generato l'evento. La funzione viene passata un `InAppBrowserEvent` oggetto. + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* iOS +* Windows 8 e 8.1 +* Windows Phone 7 e 8 + +### Esempio rapido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> Chiude la `InAppBrowser` finestra. + + ref.close(); + + +* **Rif**: fare riferimento alla `InAppBrowser` finestra *(InAppBrowser)* + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* Firefox OS +* iOS +* Windows 8 e 8.1 +* Windows Phone 7 e 8 + +### Esempio rapido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> Visualizza una finestra di InAppBrowser che è stato aperto nascosta. Questa chiamata non ha effetto se la InAppBrowser era già visibile. + + ref.show(); + + +* **Rif**: riferimento per il InAppBrowser finestra (`InAppBrowser`) + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* iOS +* Windows 8 e 8.1 + +### Esempio rapido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> Inserisce il codice JavaScript nella `InAppBrowser` finestra + + ref.executeScript(details, callback); + + +* **Rif**: fare riferimento alla `InAppBrowser` finestra. *(InAppBrowser)* + +* **injectDetails**: dettagli dello script da eseguire, specificando un `file` o `code` chiave. *(Oggetto)* + + * **file**: URL dello script da iniettare. + * **codice**: testo dello script da iniettare. + +* **richiamata**: la funzione che viene eseguito dopo che il codice JavaScript viene iniettato. + + * Se lo script iniettato è di tipo `code` , il callback viene eseguita con un singolo parametro, che è il valore restituito del copione, avvolto in un `Array` . Per gli script multi-linea, questo è il valore restituito dell'ultima istruzione, o l'ultima espressione valutata. + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* iOS +* Windows 8 e 8.1 + +### Esempio rapido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> Inietta CSS nella `InAppBrowser` finestra. + + ref.insertCSS(details, callback); + + +* **Rif**: fare riferimento alla `InAppBrowser` finestra *(InAppBrowser)* + +* **injectDetails**: dettagli dello script da eseguire, specificando un `file` o `code` chiave. *(Oggetto)* + + * **file**: URL del foglio di stile per iniettare. + * **codice**: testo del foglio di stile per iniettare. + +* **richiamata**: la funzione che viene eseguito dopo che il CSS viene iniettato. + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* iOS + +### Esempio rapido + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/ja/index.md b/plugins/cordova-plugin-inappbrowser/doc/ja/index.md new file mode 100644 index 00000000..a1b68544 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/ja/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +ã“ã®ãƒ—ラグイン㯠`コルドãƒã‚’呼ã³å‡ºã™ã¨ãã«è¡¨ç¤ºã•れる web ブラウザーã®ãƒ“ューをæä¾›ã—ã¾ã™ã€‚InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +`コルドãƒã€‚InAppBrowser.open()` `window.open()` 関数ã¨ã®äº¤æ›ã‚’定義ã™ã‚‹é–¢æ•°ã€‚ æ—¢å˜ã® `window.open()` 呼ã³å‡ºã—ã¯ã€window.open ã‚’ç½®ãæ›ãˆã‚‹ã“ã¨ã«ã‚ˆã£ã¦ InAppBrowser ウィンドウを使用ã§ãã¾ã™ã€‚ + + window.open = cordova.InAppBrowser.open; + + +InAppBrowser ã‚¦ã‚£ãƒ³ãƒ‰ã‚¦ã¯æ¨™æº–的㪠web ブラウザーã®ã‚ˆã†ã«å‹•作ã—ã€ã‚³ãƒ«ãƒ‰ãƒ Api ã«ã‚¢ã‚¯ã‚»ã‚¹ã§ãã¾ã›ã‚“。 ã“ã®ç†ç”±ã‹ã‚‰ã€InAppBrowser ãŠå‹§ã‚ã™ã‚‹å ´åˆã¯ãƒ¡ã‚¤ãƒ³ã®ã‚³ãƒ«ãƒ‰ãƒã® webview ã‚’èªã¿è¾¼ã‚€ã®ã§ã¯ãªãサード パーティ (ä¿¡é ¼ã•れã¦ã„ãªã„) コンテンツをãƒãƒ¼ãƒ‰ã™ã‚‹å¿…è¦ãŒã‚りã¾ã™ã€‚ InAppBrowserã€ãƒ›ãƒ¯ã‚¤ãƒˆ リストã®å¯¾è±¡ã§ã¯ãªã„ã‚‚ã€ã‚·ã‚¹ãƒ†ãƒ ã®ãƒ–ラウザーã§ãƒªãƒ³ã‚¯ã‚’é–‹ãã§ã™ã€‚ + +InAppBrowser ã‚’æä¾›ã—ã¾ã™ãƒ‡ãƒ•ォルト㧠GUI コントãƒãƒ¼ãƒ« (戻るã€é€²ã‚€ã€è¡Œã†)。 + +å¾Œæ–¹äº’æ›æ€§ã€ã“ã®ãƒ—ラグインã¯ã€ã¾ãŸ `window.open` をフックã®ãŸã‚。 ãŸã ã—ã€`window.open` ã®ãƒ—ラグイン インストール フックをæŒã¤ã“ã¨ãŒã§ãã¾ã™æ„図ã—ãªã„副作用 (特ã«å ´åˆã¯ã€ã“ã®ãƒ—ラグインã¯åˆ¥ã®ãƒ—ラグインã®ä¾å˜é–¢ä¿‚ã¨ã—ã¦ã®ã¿å«ã¾ã‚Œã¦ã„ã¾ã™)。 `window.open` ã®ãƒ•ックã¯ã€å°†æ¥ã®ãƒ¡ã‚¸ãƒ£ãƒ¼ リリースã§å‰Šé™¤ã•れã¾ã™ã€‚ プラグインã‹ã‚‰ã€ãƒ•ックãŒå‰Šé™¤ã•れるã¾ã§ã‚¢ãƒ—リã¯ãƒ‡ãƒ•ォルトã®å‹•作を手動ã§å¾©å…ƒã§ãã¾ã™ã€‚ + + delete window.open // Reverts the call back to it's prototype's default + + +`window.open` ã¯ã‚°ãƒãƒ¼ãƒãƒ« スコープã§ã¯ã€InAppBrowser ã¯ã€`deviceready` イベントã®å¾Œã¾ã§åˆ©ç”¨ã§ãã¾ã›ã‚“。 + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## インストール + + cordova plugin add cordova-plugin-inappbrowser + + +InAppBrowser を通éŽã™ã‚‹ã‚¢ãƒ—リã§ã™ã¹ã¦ã®ãƒšãƒ¼ã‚¸ã®èªã¿è¾¼ã¿ã‚’ã™ã‚‹å ´åˆã¯åˆæœŸåŒ–ä¸ã« `window.open` ã‚’å˜ã«ãƒ•ックã§ãã¾ã™ã€‚ãŸã¨ãˆã°ã€‚ + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +æ–°ã—ã„ `InAppBrowser` インスタンスをç¾åœ¨ã®ãƒ–ラウザー インスタンスã¾ãŸã¯ã‚·ã‚¹ãƒ†ãƒ ã®ãƒ–ラウザー㧠URL ã‚’é–‹ãã¾ã™ã€‚ + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **ref**: ã¸ã®å‚ç…§ã‚’ `InAppBrowser` ウィンドウ。*(InAppBrowser)* + +* **url**: *(æ–‡å—列)*ã‚’ãƒãƒ¼ãƒ‰ã™ã‚‹ URL。電話 `encodeURI()` å ´åˆã¯ã€ã“ã®ä¸Šã® URL 㯠Unicode æ–‡å—ã‚’å«ã¿ã¾ã™ã€‚ + +* **ターゲット**: ターゲット URL ã¯ã€æ—¢å®šå€¤ã¯ã€çœç•¥å¯èƒ½ãªãƒ‘ラメーターをãƒãƒ¼ãƒ‰ã™ã‚‹ã‚’ `_self` 。*(æ–‡å—列)* + + * `_self`: コルドムWebView URL ãŒãƒ›ãƒ¯ã‚¤ãƒˆ リストã«ã‚ã‚‹å ´åˆã§é–‹ãã¾ã™ã€ãれ以外ã®å ´åˆã§é–‹ãã¾ã™ã€`InAppBrowser`. + * `_blank`: ã§é–‹ãã¾ã™ã€`InAppBrowser`. + * `_system`: システム㮠web ブラウザーã§é–‹ãã¾ã™ã€‚ + +* **オプション**: ãŠã·ã—ょん〠`InAppBrowser` 。çœç•¥å¯èƒ½ã«ã™ã‚‹: `location=yes` 。*(æ–‡å—列)* + + `options`æ–‡å—列ã«ã¯ã™ã‚‹å¿…è¦ãŒã‚りã¾ã™ä»»æ„ã®ç©ºç™½ã‚¹ãƒšãƒ¼ã‚¹ãŒå«ã¾ã‚Œã¦ã„ãªã„ã¨ã€å„機能ã®åå‰ã¨å€¤ã®ãƒšã‚¢ã‚’コンマã§åŒºåˆ‡ã‚‹å¿…è¦ãŒã‚りã¾ã™ã€‚ 機能åã§ã¯å¤§æ–‡å—å°æ–‡å—を区別ã—ã¾ã™ã€‚ 以下ã®å€¤ã‚’サãƒãƒ¼ãƒˆã™ã‚‹ãƒ—ラットフォーム。 + + * **å ´æ‰€**: ã«è¨å®š `yes` ã¾ãŸã¯ `no` を有効ã«ã™ã‚‹ã€ `InAppBrowser` ã®å ´æ‰€ãƒãƒ¼ オンã¾ãŸã¯ã‚ªãƒ•ã«ã—ã¾ã™ã€‚ + + アンドãƒã‚¤ãƒ‰ã®ã¿ï¼š + + * **éžè¡¨ç¤º**: è¨å®š `yes` ブラウザーを作æˆã—ã¦ã€ãƒšãƒ¼ã‚¸ã®èªã¿è¾¼ã¿ãŒè¡¨ç¤ºã•れã¾ã›ã‚“。 Loadstop イベントã¯ã€èªã¿è¾¼ã¿ãŒå®Œäº†ã™ã‚‹ã¨ç™ºç”Ÿã—ã¾ã™ã€‚ çœç•¥ã™ã‚‹ã‹è¨å®š `no` (既定値) ã‚’é–‹ãã—ã€é€šå¸¸èªã¿è¾¼ã¿ãƒ–ラウザーをæŒã£ã¦ã„ã¾ã™ã€‚ + * **clearcache**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã€ãƒ–ラウザーã®ã‚¯ãƒƒã‚ー ã‚ャッシュ クリア新ã—ã„ウィンドウãŒé–‹ãå‰ã« + * **clearsessioncache**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¯ã‚»ãƒƒã‚·ãƒ§ãƒ³ cookie ã®ã‚ャッシュをオフã«ã™ã‚‹ã¨ã€æ–°ã—ã„ウィンドウãŒé–‹ãå‰ã« + + iOS ã®ã¿: + + * **closebuttoncaption**: [**完了**] ボタンã®ã‚ャプションã¨ã—ã¦ä½¿ç”¨ã™ã‚‹æ–‡å—列ã«è¨å®šã—ã¾ã™ã€‚自分ã§ã“ã®å€¤ã‚’ãƒãƒ¼ã‚«ãƒ©ã‚¤ã‚ºã™ã‚‹å¿…è¦ãŒã‚ã‚‹ã“ã¨ã«æ³¨æ„ã—ã¦ãã ã•ã„。 + * **disallowoverscroll**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` (既定値㯠`no` )。/UIWebViewBounce プãƒãƒ‘ティをオフã«ã—ã¾ã™ã€‚ + * **éžè¡¨ç¤º**: è¨å®š `yes` ブラウザーを作æˆã—ã¦ã€ãƒšãƒ¼ã‚¸ã®èªã¿è¾¼ã¿ãŒè¡¨ç¤ºã•れã¾ã›ã‚“。 Loadstop イベントã¯ã€èªã¿è¾¼ã¿ãŒå®Œäº†ã™ã‚‹ã¨ç™ºç”Ÿã—ã¾ã™ã€‚ çœç•¥ã™ã‚‹ã‹è¨å®š `no` (既定値) ã‚’é–‹ãã—ã€é€šå¸¸èªã¿è¾¼ã¿ãƒ–ラウザーをæŒã£ã¦ã„ã¾ã™ã€‚ + * **clearcache**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã€ãƒ–ラウザーã®ã‚¯ãƒƒã‚ー ã‚ャッシュ クリア新ã—ã„ウィンドウãŒé–‹ãå‰ã« + * **clearsessioncache**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¯ã‚»ãƒƒã‚·ãƒ§ãƒ³ cookie ã®ã‚ャッシュをオフã«ã™ã‚‹ã¨ã€æ–°ã—ã„ウィンドウãŒé–‹ãå‰ã« + * **ツールãƒãƒ¼**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` InAppBrowser (デフォルトã®ãƒ„ールãƒãƒ¼ã®ã‚ªãƒ³ã¾ãŸã¯ã‚ªãƒ•を有効ã«ã™ã‚‹ã«ã¯`yes`) + * **enableViewportScale**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` ã‚’ (デフォルトã§ã¯ãƒ¡ã‚¿ã‚¿ã‚°ã‚’介ã—ã¦ã‚¹ã‚±ãƒ¼ãƒªãƒ³ã‚° ビューãƒãƒ¼ãƒˆã‚’防ããŸã‚ã«`no`). + * **mediaPlaybackRequiresUserAction**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` ã‚’ HTML5 オーディオã¾ãŸã¯ãƒ“デオを自動å†ç”Ÿ ï¼ˆåˆæœŸè¨å®šã‹ã‚‰é˜²ããŸã‚ã«`no`). + * **allowInlineMediaPlayback**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` ライン㧠HTML5 メディアå†ç”Ÿã«ã¯ã€ãƒ‡ãƒã‚¤ã‚¹å›ºæœ‰å†ç”Ÿã‚¤ãƒ³ã‚¿ãƒ¼ãƒ•ェイスã§ã¯ãªãã€ãƒ–ラウザー ウィンドウ内ã«è¡¨ç¤ºã™ã‚‹ã‚ˆã†ã«ã—ã¾ã™ã€‚ HTML ã® `video` è¦ç´ ã‚’å«ã‚ã‚‹å¿…è¦ãŒã‚りã¾ã™ã¾ãŸã€ `webkit-playsinline` 属性 (デフォルトã¯`no`) + * **keyboardDisplayRequiresUserAction**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` をフォームè¦ç´ ã® JavaScript を介ã—ã¦ãƒ•ォーカスをå—ã‘å–ã‚‹ã¨ãã«ã€ã‚ーボードを開ã `focus()` コール (デフォルトã¯`yes`). + * **suppressesIncrementalRendering**: ã«è¨å®šã•れã¦ã„ã‚‹ `yes` ã¾ãŸã¯ `no` (デフォルトã§ã¯è¡¨ç¤ºã•れるå‰ã«ãƒ“ューã®ã™ã¹ã¦ã®æ–°ã—ã„コンテンツをå—ä¿¡ã™ã‚‹ã¾ã§å¾…機ã™ã‚‹ã«ã¯`no`). + * **presentationstyle**: ã«è¨å®šã•れã¦ã„ã‚‹ `pagesheet` 〠`formsheet` ã¾ãŸã¯ `fullscreen` (デフォルトã§ã¯ã€[プレゼンテーション スタイル][1]ã‚’è¨å®šã™ã‚‹ã«ã¯`fullscreen`). + * **transitionstyle**: ã«è¨å®šã•れã¦ã„ã‚‹ `fliphorizontal` 〠`crossdissolve` ã¾ãŸã¯ `coververtical` (デフォルトã§ã¯ã€[トランジションã®ã‚¹ã‚¿ã‚¤ãƒ«][2]ã‚’è¨å®šã™ã‚‹ã«ã¯`coververtical`). + * **toolbarposition**: ã«è¨å®šã•れã¦ã„ã‚‹ `top` ã¾ãŸã¯ `bottom` (既定値㯠`bottom` )。上部ã¾ãŸã¯ã‚¦ã‚£ãƒ³ãƒ‰ã‚¦ã®ä¸‹éƒ¨ã«ãƒ„ールãƒãƒ¼ãŒç™ºç”Ÿã—ã¾ã™ã€‚ + + Windows ã®ã¿ï¼š + + * **éžè¡¨ç¤º**: è¨å®š `yes` ブラウザーを作æˆã—ã¦ã€ãƒšãƒ¼ã‚¸ã®èªã¿è¾¼ã¿ãŒè¡¨ç¤ºã•れã¾ã›ã‚“。 Loadstop イベントã¯ã€èªã¿è¾¼ã¿ãŒå®Œäº†ã™ã‚‹ã¨ç™ºç”Ÿã—ã¾ã™ã€‚ çœç•¥ã™ã‚‹ã‹è¨å®š `no` (既定値) ã‚’é–‹ãã—ã€é€šå¸¸èªã¿è¾¼ã¿ãƒ–ラウザーをæŒã£ã¦ã„ã¾ã™ã€‚ + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* ブラックベリー 10 +* Firefox ã® OS +* iOS +* Windows 8 ãŠã‚ˆã³ 8.1 +* Windows Phone 7 㨠8 + +### 例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### Firefox OS ç™– + +é–‹ã‹ã‚ŒãŸå ´åˆã«ã„ãã¤ã‹ã® CSS ãƒ«ãƒ¼ãƒ«ã‚’è¿½åŠ ã™ã‚‹å¿…è¦ãŒã‚るプラグインã¯ä»»æ„ã®ãƒ‡ã‚¶ã‚¤ãƒ³ã‚’é©ç”¨ã—ãªã„㨠`target ='_blank'`。ã“れらã®ã‚ˆã†ãªè¦å‰‡ã«ãªã‚Šã¾ã™ã€‚ + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +`コルドãƒã¸ã®å‘¼ã³å‡ºã—ã‹ã‚‰è¿”ã•れるオブジェクト。InAppBrowser.open`. + +### メソッド + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> イベントã®ãƒªã‚¹ãƒŠãƒ¼ã‚’è¿½åŠ ã—ã¾ã™ã€`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **ref**: ã¸ã®å‚ç…§ã‚’ `InAppBrowser` ウィンドウ*(InAppBrowser)* + +* **eventname**: *(æ–‡å—列)*をリッスンã™ã‚‹ã‚¤ãƒ™ãƒ³ãƒˆ + + * ****: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` ã® URL ã®èªã¿è¾¼ã¿ãŒé–‹å§‹ã—ã¾ã™ã€‚ + * **loadstop**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` URL ã®èªã¿è¾¼ã¿ãŒå®Œäº†ã—ã¾ã™ã€‚ + * **loaderror**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` URL ã®èªã¿è¾¼ã¿ã§ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã™ã€‚ + * **終了**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` ウィンドウãŒé–‰ã˜ã‚‰ã‚Œã¾ã™ã€‚ + +* **コールãƒãƒƒã‚¯**: イベントãŒç™ºç”Ÿã—ãŸã¨ãã«å®Ÿè¡Œã•ã‚Œã‚‹é–¢æ•°ã€‚é–¢æ•°ã«æ¸¡ã•れã¾ã™ãŒã€ `InAppBrowserEvent` オブジェクトをパラメーターã¨ã—ã¦ã€‚ + +### InAppBrowserEvent プãƒãƒ‘ティ + +* **タイプ**: eventname ã©ã¡ã‚‰ã‹ `loadstart` 〠`loadstop` 〠`loaderror` ã€ã¾ãŸã¯ `exit` 。*(æ–‡å—列)* + +* **url**: URL ãŒèªã¿è¾¼ã¾ã‚Œã¾ã—ãŸã€‚*(æ–‡å—列)* + +* **コード**: ã®å ´åˆã«ã®ã¿ã€ã‚¨ãƒ©ãƒ¼ コード `loaderror` 。*(æ•°)* + +* **メッセージ**: ã®å ´åˆã«ã®ã¿ã€ã‚¨ãƒ©ãƒ¼ メッセージ `loaderror` 。*(æ–‡å—列)* + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* iOS +* Windows 8 ãŠã‚ˆã³ 8.1 +* Windows Phone 7 㨠8 + +### ç°¡å˜ãªä¾‹ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> イベントã®ãƒªã‚¹ãƒŠãƒ¼ã‚’削除ã—ã¾ã™ã€`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **ref**: ã¸ã®å‚ç…§ã‚’ `InAppBrowser` ウィンドウ。*(InAppBrowser)* + +* **eventname**: イベントã®ãƒªãƒƒã‚¹ãƒ³ã‚’åœæ¢ã—ã¾ã™ã€‚*(æ–‡å—列)* + + * ****: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` ã® URL ã®èªã¿è¾¼ã¿ãŒé–‹å§‹ã—ã¾ã™ã€‚ + * **loadstop**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` URL ã®èªã¿è¾¼ã¿ãŒå®Œäº†ã—ã¾ã™ã€‚ + * **loaderror**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` URL ã®èªã¿è¾¼ã¿ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã™ã€‚ + * **終了**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ã〠`InAppBrowser` ウィンドウãŒé–‰ã˜ã‚‰ã‚Œã¾ã™ã€‚ + +* **コールãƒãƒƒã‚¯**: イベントãŒç™ºç”Ÿã™ã‚‹ã¨ãã«å®Ÿè¡Œã™ã‚‹é–¢æ•°ã€‚é–¢æ•°ã«æ¸¡ã•れã¾ã™ãŒã€ `InAppBrowserEvent` オブジェクト。 + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* iOS +* Windows 8 ãŠã‚ˆã³ 8.1 +* Windows Phone 7 㨠8 + +### ç°¡å˜ãªä¾‹ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> é–‰ã˜ã‚‹ã€ `InAppBrowser` ウィンドウ。 + + ref.close(); + + +* **ref**: ã¸ã®å‚ç…§ã‚’ `InAppBrowser` ウィンドウ*(InAppBrowser)* + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* Firefox ã® OS +* iOS +* Windows 8 ãŠã‚ˆã³ 8.1 +* Windows Phone 7 㨠8 + +### ç°¡å˜ãªä¾‹ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> éš ã•れãŸé–‹ã‹ã‚ŒãŸ InAppBrowser ウィンドウãŒè¡¨ç¤ºã•れã¾ã™ã€‚ã“ã®é–¢æ•°ã‚’呼ã³å‡ºã™ã¯å½±éŸ¿ã—ã¾ã›ã‚“ã€InAppBrowser ãŒæ—¢ã«è¡¨ç¤ºã•れã¦ã„ã‚‹å ´åˆã€‚ + + ref.show(); + + +* **ref**: InAppBrowser ウィンドウ (ã¸ã®å‚ç…§`InAppBrowser`) + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* iOS +* Windows 8 ãŠã‚ˆã³ 8.1 + +### ç°¡å˜ãªä¾‹ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> JavaScript ã‚³ãƒ¼ãƒ‰ã«æŒ¿å…¥ã—ã¾ã™ã€ `InAppBrowser` ウィンドウ + + ref.executeScript(details, callback); + + +* **ref**: ã¸ã®å‚ç…§ã‚’ `InAppBrowser` ウィンドウ。*(InAppBrowser)* + +* **injectDetails**: 詳細を実行ã™ã‚‹ã‚¹ã‚¯ãƒªãƒ—トã®ã„ãšã‚Œã‹ã‚’指定ã™ã‚‹ã€ `file` ã¾ãŸã¯ `code` ã‚ー。*(オブジェクト)* + + * **ファイル**: スクリプト㮠URL を注入ã—ã¾ã™ã€‚ + * **コード**: スクリプトã®ãƒ†ã‚ストを挿入ã—ã¾ã™ã€‚ + +* **コールãƒãƒƒã‚¯**: JavaScript コードを注入ã—ãŸå¾Œã«å®Ÿè¡Œã•れる関数。 + + * 挿入ã•れãŸã‚¹ã‚¯ãƒªãƒ—トãŒåž‹ã®å ´åˆ `code` ã€ã‚¹ã‚¯ãƒªãƒ—ãƒˆã®æˆ»ã‚Šå€¤ã¯ã€1 ã¤ã®ãƒ‘ラメーターã§ã‚³ãƒ¼ãƒ«ãƒãƒƒã‚¯ã‚’実行ã™ã‚‹ã®ã«åŒ…ã¾ã‚Œã¦ã€ `Array` 。 マルãƒãƒ©ã‚¤ãƒ³ スクリプトã«ã¤ã„ã¦ã¯ã€æœ€å¾Œã®ã‚¹ãƒ†ãƒ¼ãƒˆãƒ¡ãƒ³ãƒˆã§ã¯ã€ã¾ãŸã¯è©•価ã—ãŸæœ€å¾Œã®å¼ã®æˆ»ã‚Šå€¤ã§ã™ã€‚ + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* iOS +* Windows 8 ãŠã‚ˆã³ 8.1 + +### ç°¡å˜ãªä¾‹ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> CSS ã«æ³¨å…¥ã™ã‚‹ã€ `InAppBrowser` ウィンドウ。 + + ref.insertCSS(details, callback); + + +* **ref**: ã¸ã®å‚ç…§ã‚’ `InAppBrowser` ウィンドウ*(InAppBrowser)* + +* **injectDetails**: 詳細を実行ã™ã‚‹ã‚¹ã‚¯ãƒªãƒ—トã®ã„ãšã‚Œã‹ã‚’指定ã™ã‚‹ã€ `file` ã¾ãŸã¯ `code` ã‚ー。*(オブジェクト)* + + * **ファイル**: 注入ã™ã‚‹ã‚¹ã‚¿ã‚¤ãƒ« シート㮠URL。 + * **コード**: 注入ã™ã‚‹ã‚¹ã‚¿ã‚¤ãƒ« シートã®ãƒ†ã‚スト。 + +* **コールãƒãƒƒã‚¯**: CSS ã®æ³¨å…¥å¾Œã«å®Ÿè¡Œã•れる関数。 + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* iOS + +### ç°¡å˜ãªä¾‹ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/ko/index.md b/plugins/cordova-plugin-inappbrowser/doc/ko/index.md new file mode 100644 index 00000000..d1b3ddbd --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/ko/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +ì´ í”ŒëŸ¬ê·¸ì¸ `코르ë„바를 í˜¸ì¶œí• ë•Œ 표시 하는 웹 브ë¼ìš°ì € 보기를 ì œê³µ 합니다.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +`코르ë„바입니다.InAppBrowser.open()` 함수 `window.open ()` í•¨ìˆ˜ì— ëŒ€ 한 대체품 ì •ì˜ ë©ë‹ˆë‹¤. ê¸°ì¡´ì˜ `window.open ()` 호출 window.openì„ ëŒ€ì²´ 하 ì—¬ InAppBrowser 윈ë„우를 ì‚¬ìš©í• ìˆ˜ 있습니다. + + window.open = cordova.InAppBrowser.open; + + +InAppBrowser ì°½ 표준 웹 브ë¼ìš°ì € 처럼 ë™ìž‘ ë° ì½”ë¥´ë„ë°” Apiì— ì•¡ì„¸ìŠ¤í• ìˆ˜ 없습니다. ì´ ì´ìœ 는 InAppBrowser는 ê²ƒì´ ì¢‹ìŠµë‹ˆë‹¤ëŠ” 주요 코르ë„ë°” webview로 로드 하는 ëŒ€ì‹ ì œ 3 ìž (ì‹ ë¢°í• ìˆ˜ 없는) 콘í…ì¸ ë¥¼ 로드 해야 í• ê²½ìš°. InAppBrowser는 허용 ë ìˆ˜ë„ ì‹œìŠ¤í…œ 브ë¼ìš°ì €ì—서 ë§í¬ë¥¼ 여는. + +사용ìžì— 대 한 ìžì²´ GUI 컨트롤ì—서 기본ì 으로 ì œê³µ ëœ InAppBrowser (뒤로, 앞으로, 완료). + +대 한 ë’¤ 호환성,ì´ í”ŒëŸ¬ê·¸ì¸ë„ `window.open` 후í¬. 그러나, `window.open`ì˜ í”ŒëŸ¬ê·¸ì¸ ì„¤ì¹˜ 후í¬ë¥¼ 가질 수 있습니다 ì˜ë„ 하지 ì•Šì€ ë¶€ìž‘ìš© (특히 ê²½ìš°ì´ í”ŒëŸ¬ê·¸ì¸ì´ 다른 í”ŒëŸ¬ê·¸ì¸ ì¢…ì†ì„± 으로만 í¬í•¨). `window.open` í›„í¬ ì£¼ìš” 릴리스ì—서 ì œê±° ë©ë‹ˆë‹¤. í›„í¬ í”ŒëŸ¬ê·¸ì¸ì—서 ì œê±° ë 때까지 ì• í”Œ 리 ì¼€ì´ ì…˜ 수 있습니다 수ë™ìœ¼ë¡œ 기본 ë™ìž‘ì„ ë³µì› í•˜ 게 ë©ë‹ˆë‹¤. + + delete window.open // Reverts the call back to it's prototype's default + + +`window.open` ì „ì— ë²”ìœ„ì— ìžˆì§€ë§Œ InAppBrowser ì œê³µ ë˜ì§€ 않습니다 때까지 `deviceready` ì´ë²¤íЏ 후. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## 설치 + + cordova plugin add cordova-plugin-inappbrowser + + +InAppBrowser를 통해가 서 ë‹¹ì‹ ì˜ ì• í”Œ 리 ì¼€ì´ ì…˜ì—서 ëª¨ë“ íŽ˜ì´ì§€ë¥¼ 로드 í•˜ë ¤ëŠ” 경우 초기화 하는 ë™ì•ˆ `window.open` 간단 하 게 ì—°ê²°í• ìˆ˜ 있습니다. 예를 들어: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +새 `InAppBrowser` ì¸ìŠ¤í„´ìŠ¤, 현재 브ë¼ìš°ì € ì¸ìŠ¤í„´ìŠ¤ ë˜ëŠ” 시스템 브ë¼ìš°ì €ì—서 URLì„ ì—½ë‹ˆë‹¤. + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **심íŒ**:ì— ëŒ€ 한 참조는 `InAppBrowser` ì°½. *(InAppBrowser)* + +* **url**: *(문ìžì—´)를*로드 하는 URL. ì „í™” `encodeURI()` ì´ ê²½ìš°ì—는 URL ìœ ë‹ˆì½”ë“œ 문ìžë¥¼ í¬í•¨ 합니다. + +* **대ìƒ**: ëŒ€ìƒ URL, 기본ì 으로 ì„ íƒì 매개 변수를 로드 하는 `_self` . *(문ìžì—´)* + + * `_self`: URL í™”ì´íЏ ë¦¬ìŠ¤íŠ¸ì— ìžˆìœ¼ë©´ 코르ë„ë°” WebViewì—서 ì—´ë¦¬ê³ , ê·¸ë ‡ì§€ 않으면 ì—´ì—`InAppBrowser`. + * `_blank`: 준공ì—`InAppBrowser`. + * `_system`: ì‹œìŠ¤í…œì˜ ì›¹ 브ë¼ìš°ì €ì—서 엽니다. + +* **옵션**: ì˜µì…˜ì€ `InAppBrowser` . ì„ íƒì , ë””í´íЏì—: `location=yes` . *(문ìžì—´)* + + `options`문ìžì—´ í…… 빈 ì–´ë–¤ 스페ì´ìФ í¬í•¨ 해서는 안 ê·¸ë¦¬ê³ ì‰¼í‘œ ê° ê¸°ëŠ¥ì˜ ì´ë¦„/ê°’ ìŒì„ 구분 합니다. 기능 ì´ë¦„ì€ ëŒ€/소문ìžìž…니다. ëª¨ë“ í”Œëž«í¼ ì§€ì› ì•„ëž˜ ê°’: + + * **위치**: ì„¤ì • `yes` ë˜ëŠ” `no` ì„¤ì • 하는 `InAppBrowser` ì˜ ìœ„ì¹˜ 표시줄 켜거나 ë•니다. + + 안 드 로ì´ë“œë§Œ: + + * **숨겨진**: ì„¤ì • `yes` 브ë¼ìš°ì €ë¥¼ 만들 페ì´ì§€ë¥¼ 로드 하면, 하지만 ê·¸ê²ƒì„ ë³´ì—¬ì£¼ì§€. Loadstop ì´ë²¤íŠ¸ëŠ” 로드가 완료 ë˜ ë©´ ë°œìƒ í•©ë‹ˆë‹¤. ìƒëžµ 하거나 ì„¤ì • `no` (기본값) 브ë¼ìš°ì € ì—´ê³ ì •ìƒì 으로 로드 해야 합니다. + * **clearcache**: ì„¤ì • `yes` 브ë¼ìš°ì €ë¥¼ ì¿ í‚¤ ìºì‹œ ì‚ì œ 하기 ì „ì— ìƒˆ ì°½ì´ ì—´ë¦½ë‹ˆë‹¤ + * **clearsessioncache**: ì„¤ì • `yes` 세션 ì¿ í‚¤ ìºì‹œë¥¼ ì‚ì œ 하기 ì „ì— ìƒˆ ì°½ì´ ì—´ë¦½ë‹ˆë‹¤ + + iOSë§Œ: + + * **closebuttoncaption**: **수행** 하는 ë‹¨ì¶”ì˜ ìº¡ì…˜ìœ¼ë¡œ ì‚¬ìš©í• ë¬¸ìžì—´ì„ ì„¤ì • 합니다. ì°¸ê³ ì§ì ‘ì´ ê°’ì„ ì§€ì—í™” 해야 합니다. + * **disallowoverscroll**: ì„¤ì • `yes` ë˜ëŠ” `no` (ê¸°ë³¸ê°’ì€ `no` ). íšŒì „ 온/오프 UIWebViewBounce ì†ì„±ìž…니다. + * **숨겨진**: ì„¤ì • `yes` 브ë¼ìš°ì €ë¥¼ 만들 페ì´ì§€ë¥¼ 로드 하면, 하지만 ê·¸ê²ƒì„ ë³´ì—¬ì£¼ì§€. Loadstop ì´ë²¤íŠ¸ëŠ” 로드가 완료 ë˜ ë©´ ë°œìƒ í•©ë‹ˆë‹¤. ìƒëžµ 하거나 ì„¤ì • `no` (기본값) 브ë¼ìš°ì € ì—´ê³ ì •ìƒì 으로 로드 해야 합니다. + * **clearcache**: ì„¤ì • `yes` 브ë¼ìš°ì €ë¥¼ ì¿ í‚¤ ìºì‹œ ì‚ì œ 하기 ì „ì— ìƒˆ ì°½ì´ ì—´ë¦½ë‹ˆë‹¤ + * **clearsessioncache**: ì„¤ì • `yes` 세션 ì¿ í‚¤ ìºì‹œë¥¼ ì‚ì œ 하기 ì „ì— ìƒˆ ì°½ì´ ì—´ë¦½ë‹ˆë‹¤ + * **ë„구 모ìŒ**: ì„¤ì • `yes` ë˜ëŠ” `no` InAppBrowser (기본값:ì— ëŒ€ 한 ë„구 ëª¨ìŒ ì˜¨ / 오프를 ëŒê¸° 위하여`yes`) + * **enableViewportScale**: ì„¤ì • `yes` ë˜ëŠ” `no` ë·°í¬íЏ 메타 태그 (기본값:를 통해 í™•ìž¥ì„ ë°©ì§€ 하기 위해`no`). + * **mediaPlaybackRequiresUserAction**: ì„¤ì • `yes` ë˜ëŠ” `no` HTML5 오디오 ë˜ëŠ” 비디오 ìžë™ ìž¬ìƒ (기본값ì—서ì—서 ë°©ì§€ 하기 위해`no`). + * **allowInlineMediaPlayback**: ì„¤ì • `yes` ë˜ëŠ” `no` ì¸ë¼ì¸ HTML5 미디어 재ìƒ, 장치 ì „ìš© ìž¬ìƒ ì¸í„°íŽ˜ì´ìФ 보다는 브ë¼ìš°ì € ì°½ ë‚´ì—서 í‘œì‹œí• ìˆ˜ 있ë„ë¡ í•©ë‹ˆë‹¤. HTMLì˜ `video` 요소가 í¬í•¨ ë˜ì–´ì•¼ 합니다는 `webkit-playsinline` 특성 (기본값:`no`) + * **keyboardDisplayRequiresUserAction**: ì„¤ì • `yes` ë˜ëŠ” `no` ì–‘ì‹ ìš”ì†ŒëŠ” ìžë°” 스í¬ë¦½íŠ¸ë¥¼ 통해 í¬ì»¤ìŠ¤ë¥¼ ë°›ì„ ë•Œ 키보드를 ì—´ê³ `focus()` ì „í™” (기본값:`yes`). + * **suppressesIncrementalRendering**: ì„¤ì • `yes` ë˜ëŠ” `no` (ê¸°ë³¸ê°’ì„ ë Œë”ë§ í•˜ê¸° ì „ì— ëª¨ë“ ìƒˆë¡œìš´ 보기 콘í…ì¸ ë¥¼ ë°›ì„ ë•Œê¹Œì§€ ê¸°ë‹¤ë ¤ì•¼`no`). + * **presentationstyle**: ì„¤ì • `pagesheet` , `formsheet` ë˜ëŠ” `fullscreen` [í”„ë ˆ ì í…Œì´ ì…˜ 스타ì¼][1] (ê¸°ë³¸ê°’ì„ ì„¤ì • í•˜ë ¤ë©´`fullscreen`). + * **transitionstyle**: ì„¤ì • `fliphorizontal` , `crossdissolve` ë˜ëŠ” `coververtical` [ì „í™˜ 스타ì¼][2] (ê¸°ë³¸ê°’ì„ ì„¤ì • í•˜ë ¤ë©´`coververtical`). + * **toolbarposition**: ì„¤ì • `top` ë˜ëŠ” `bottom` (ê¸°ë³¸ê°’ì€ `bottom` ). 위쪽 ë˜ëŠ” 아래쪽 ì°½ì— ë„구 모ìŒì„ ë°œìƒ í•©ë‹ˆë‹¤. + + Windowsì—ë§Œ 해당: + + * **숨겨진**: ì„¤ì • `yes` 브ë¼ìš°ì €ë¥¼ 만들 페ì´ì§€ë¥¼ 로드 하면, 하지만 ê·¸ê²ƒì„ ë³´ì—¬ì£¼ì§€. Loadstop ì´ë²¤íŠ¸ëŠ” 로드가 완료 ë˜ ë©´ ë°œìƒ í•©ë‹ˆë‹¤. ìƒëžµ 하거나 ì„¤ì • `no` (기본값) 브ë¼ìš°ì € ì—´ê³ ì •ìƒì 으로 로드 해야 합니다. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* ë¸”ëž™ë² ë¦¬ 10 +* Firefox ìš´ì˜ ì²´ì œ +* iOS +* 윈ë„ìš° 8ê³¼ 8.1 +* Windows Phone 7ê³¼ 8 + +### 예를 들어 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### 파ì´ì–´ í스 OS 단ì + +í”ŒëŸ¬ê·¸ì¸ ì–´ë–¤ ë””ìžì¸ì„ ì ìš© 하지 않는 경우 ì—´ ì¼ë¶€ CSSì˜ ê·œì¹™ì„ ì¶”ê°€í• í•„ìš”ê°€ 있다 `target='_blank'`. ì´ ê°™ì´ ê·œì¹™ + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +`Cordovaì— ëŒ€ 한 호출ì—서 반환 하는 개체.InAppBrowser.open`. + +### 메서드 + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> ì´ë²¤íŠ¸ì— ëŒ€ 한 ìˆ˜ì‹ ê¸°ë¥¼ 추가 합니다`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **심íŒ**:ì— ëŒ€ 한 참조는 `InAppBrowser` ì°½ *(InAppBrowser)* + +* **eventname**: *(문ìžì—´)를* ìˆ˜ì‹ í•˜ë„ë¡ ì´ë²¤íЏ + + * **loadstart**: ì´ë²¤íЏ ë°œìƒ ë•ŒëŠ” `InAppBrowser` URL 로드를 시작 합니다. + * **loadstop**: ì´ë²¤íŠ¸ê°€ ë°œìƒ ì‹œê¸°ëŠ” `InAppBrowser` URL 로드 완료. + * **loaderror**: ì´ë²¤íЏ ë°œìƒ ë•ŒëŠ” `InAppBrowser` URLì„ ë¡œë“œí• ë•Œ 오류가 ë°œìƒ í•©ë‹ˆë‹¤. + * **종료**: ì´ë²¤íŠ¸ê°€ ë°œìƒ ì‹œê¸°ëŠ” `InAppBrowser` ì°½ì´ ë‹«íž™ë‹ˆë‹¤. + +* **콜백**: ì´ë²¤íŠ¸ê°€ ë°œìƒ ë 때 실행 ë˜ëŠ” 함수. 함수는 ì „ë‹¬ ëœ `InAppBrowserEvent` 개체를 매개 변수로 합니다. + +### InAppBrowserEvent ì†ì„± + +* **ìœ í˜•**: eventname, 중 `loadstart` , `loadstop` , `loaderror` , ë˜ëŠ” `exit` . *(문ìžì—´)* + +* **url**: URL 로드 ëœ. *(문ìžì—´)* + +* **코드**: 오류 ì½”ë“œì˜ ê²½ìš°ì—ë§Œ `loaderror` . *(수)* + +* **메시지**: 오류 ë©”ì‹œì§€ì˜ ê²½ìš°ì—ë§Œ `loaderror` . *(문ìžì—´)* + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* iOS +* 윈ë„ìš° 8ê³¼ 8.1 +* Windows Phone 7ê³¼ 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> ì´ë²¤íŠ¸ì— ëŒ€ 한 ìˆ˜ì‹ ê¸°ë¥¼ ì œê±° 합니다`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **심íŒ**:ì— ëŒ€ 한 참조는 `InAppBrowser` ì°½. *(InAppBrowser)* + +* **eventname**: ì´ë²¤íЏ ìˆ˜ì‹ ëŒ€ê¸°ë¥¼ 중지 합니다. *(문ìžì—´)* + + * **loadstart**: ì´ë²¤íЏ ë°œìƒ ë•ŒëŠ” `InAppBrowser` URL 로드를 시작 합니다. + * **loadstop**: ì´ë²¤íŠ¸ê°€ ë°œìƒ ì‹œê¸°ëŠ” `InAppBrowser` URL 로드 완료. + * **loaderror**: ì´ë²¤íЏ ë°œìƒ ë•ŒëŠ” `InAppBrowser` URL 로드 오류가 ë°œìƒ í•©ë‹ˆë‹¤. + * **종료**: ì´ë²¤íŠ¸ê°€ ë°œìƒ ì‹œê¸°ëŠ” `InAppBrowser` ì°½ì´ ë‹«íž™ë‹ˆë‹¤. + +* **콜백**: ì´ë²¤íŠ¸ê°€ ë°œìƒ í•˜ë©´ ì‹¤í–‰í• í•¨ìˆ˜. 함수는 ì „ë‹¬ ëœ `InAppBrowserEvent` 개체. + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* iOS +* 윈ë„ìš° 8ê³¼ 8.1 +* Windows Phone 7ê³¼ 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> 종료는 `InAppBrowser` ì°½. + + ref.close(); + + +* **심íŒ**:ì— ëŒ€ 한 참조는 `InAppBrowser` ì°½ *(InAppBrowser)* + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* Firefox ìš´ì˜ ì²´ì œ +* iOS +* 윈ë„ìš° 8ê³¼ 8.1 +* Windows Phone 7ê³¼ 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> 숨겨진 ì—´ì€ í•œ InAppBrowser ì°½ì„ í‘œì‹œ 합니다. ì „í™”ëŠ” InAppBrowserê°€ ì´ë¯¸ ë³´ì´ëŠ” 경우는 효과가 없습니다. + + ref.show(); + + +* **ref**: InAppBrowser ì°½ (참조`InAppBrowser`) + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* iOS +* 윈ë„ìš° 8ê³¼ 8.1 + +### ë¹ ë¥¸ ì˜ˆì œ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> ì— ìžë°” 스í¬ë¦½íЏ 코드를 삽입는 `InAppBrowser` ì°½ + + ref.executeScript(details, callback); + + +* **심íŒ**:ì— ëŒ€ 한 참조는 `InAppBrowser` ì°½. *(InAppBrowser)* + +* **injectDetails**: 스í¬ë¦½íЏ ì‹¤í–‰ì˜ ì„¸ë¶€ ì‚¬í• ì¤‘ 하나를 ì§€ì • 하는 `file` ë˜ëŠ” `code` 키. *(개체)* + + * **파ì¼**: 삽입 하는 스í¬ë¦½íŠ¸ì˜ URL. + * **코드**: 스í¬ë¦½íЏ í…스트를 삽입 합니다. + +* **콜백**: ìžë°” 스í¬ë¦½íЏ 코드를 주입 후 실행 기능. + + * 삽입 ëœ ìŠ¤í¬ë¦½íЏ ìœ í˜•ì˜ ê²½ìš° `code` , 스í¬ë¦½íŠ¸ì˜ ë°˜í™˜ ê°’ì€ ë‹¨ì¼ ë§¤ê°œ 변수는 콜백 ì‹¤í–‰ì— ì‹¸ì—¬ 있는 `Array` . 여러 줄 스í¬ë¦½íŠ¸ì— ëŒ€ 한 마지막 문 ë˜ëŠ” í‰ê°€ 마지막 ì‹ì˜ 반환 값입니다. + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* iOS +* 윈ë„ìš° 8ê³¼ 8.1 + +### ë¹ ë¥¸ ì˜ˆì œ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> 주사로 CSS는 `InAppBrowser` ì°½. + + ref.insertCSS(details, callback); + + +* **심íŒ**:ì— ëŒ€ 한 참조는 `InAppBrowser` ì°½ *(InAppBrowser)* + +* **injectDetails**: 스í¬ë¦½íЏ ì‹¤í–‰ì˜ ì„¸ë¶€ ì‚¬í• ì¤‘ 하나를 ì§€ì • 하는 `file` ë˜ëŠ” `code` 키. *(개체)* + + * **파ì¼**: 삽입 하는 ìŠ¤íƒ€ì¼ ì‹œíŠ¸ì˜ URL. + * **코드**: 삽입 하는 ìŠ¤íƒ€ì¼ ì‹œíŠ¸ì˜ í…스트. + +* **콜백**: CSS 주입 후 실행 기능. + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* iOS + +### ë¹ ë¥¸ ì˜ˆì œ + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/pl/index.md b/plugins/cordova-plugin-inappbrowser/doc/pl/index.md new file mode 100644 index 00000000..dff9bf0f --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/pl/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +Plugin daje widok przeglÄ…darki sieci web, które sÄ… wyÅ›wietlane podczas wywoÅ‚ywania `cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +`cordova.InAppBrowser.open()` funkcja jest definiowana jako zamiennik dla funkcji `window.open()`. IstniejÄ…ce wywoÅ‚ania `window.open()` sÅ‚uży okno InAppBrowser, zastÄ™pujÄ…c window.open: + + window.open = cordova.InAppBrowser.open; + + +Okna InAppBrowser zachowuje siÄ™ jak standardowe przeglÄ…darki i nie ma dostÄ™pu do API Cordova. Z tego powodu zaleca siÄ™ InAppBrowser jeÅ›li ty potrzebować wobec ciężar (niezaufanej) treÅ›ci osób trzecich, a nie że wczytywanie głównym webview Cordova. InAppBrowser nie jest biaÅ‚a, ani nie jest otwieranie linków w przeglÄ…darce systemu. + +InAppBrowser zawiera domyÅ›lnie kontrole GUI dla użytkownika (tyÅ‚, przód, zrobić). + +Do tyÅ‚u zgodnoÅ›ci, ten plugin również haki `window.open`. Jednak może mieć zainstalowane wtyczki haka `window.open` niezamierzone skutki uboczne (zwÅ‚aszcza, jeÅ›li ten plugin jest włączone tylko jako część innej wtyczki). Hak `window.open` zostanÄ… usuniÄ™te w przyszÅ‚ej wersji głównych. Dopóki hak jest usuwany z wtyczki, aplikacje można rÄ™cznie przywrócić domyÅ›lne zachowanie: + + delete window.open // Reverts the call back to it's prototype's default + + +Chociaż `window.open` w globalnym zasiÄ™gu, InAppBrowser nie jest dostÄ™pne dopiero po zdarzeniu `deviceready`. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## Instalacja + + cordova plugin add cordova-plugin-inappbrowser + + +JeÅ›li chcesz wszystko stronica Å‚adunki w swojej aplikacji, aby przejść przez InAppBrowser, można po prostu podłączyć `window.open` podczas inicjowania. Na przykÅ‚ad: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +Otwiera URL w nowe wystÄ…pienie `InAppBrowser`, bieżące wystÄ…pienie przeglÄ…darki lub przeglÄ…darki systemu. + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **ref**: odniesienie do `InAppBrowser` okna. *(InAppBrowser)* + +* **adres**: adres URL do Å‚adowania *(ciÄ…g)*. WywoÅ‚anie `encodeURI()` na to, czy adres URL zawiera znaki Unicode. + +* **miejsce docelowe**: miejsce docelowe, w którym wobec ciężar ten URL parametr opcjonalny, który domyÅ›lnie `_self` . *(String)* + + * `_self`: Otwiera w Cordova WebView, jeÅ›li adres URL jest na biaÅ‚ej liÅ›cie, inaczej ono otwiera w`InAppBrowser`. + * `_blank`: Otwiera w`InAppBrowser`. + * `_system`: Otwiera w przeglÄ…darce internetowej systemu. + +* **Opcje**: opcje dla `InAppBrowser` . Opcjonalnie, nie stawiÅ‚a siÄ™: `location=yes` . *(String)* + + `options`CiÄ…g nie może zawierać żadnych spacji, i pary nazwa/wartość każdej funkcji muszÄ… być oddzielone przecinkami. Nazwy funkcji jest rozróżniana. Wszystkich platform obsÅ‚uguje wartoÅ›ci poniżej: + + * **Lokalizacja**: zestaw `yes` lub `no` Aby włączyć `InAppBrowser` na pasek lub wyłączyć. + + Android: + + * **ukryte**: zestaw `yes` do stworzenia przeglÄ…darki i Å‚adowania strony, ale nie pokazuje go. Loadstop zdarzenie fires po zakoÅ„czeniu Å‚adowania. Pominąć lub zestaw `no` (domyÅ›lnie) do przeglÄ…darki otworzyć i zaÅ‚adować normalnie. + * **ClearCache**: zestaw `yes` do przeglÄ…darki w pamiÄ™ci podrÄ™cznej plików cookie wyczyszczone zanim otworzy siÄ™ nowe okno + * **clearsessioncache**: zestaw `yes` mieć w pamiÄ™ci podrÄ™cznej plików cookie sesji wyczyszczone zanim otworzy siÄ™ nowe okno + + tylko iOS: + + * **closebuttoncaption**: aby użyć jak **zrobić** przycisk Podpis ustawiona na ciÄ…g. Należy pamiÄ™tać, że trzeba zlokalizować tÄ™ wartość siebie. + * **disallowoverscroll**: zestaw `yes` lub `no` (domyÅ›lnie `no` ). Włącza/wyłącza wÅ‚aÅ›ciwość UIWebViewBounce. + * **ukryte**: zestaw `yes` do stworzenia przeglÄ…darki i Å‚adowania strony, ale nie pokazuje go. Loadstop zdarzenie fires po zakoÅ„czeniu Å‚adowania. Pominąć lub zestaw `no` (domyÅ›lnie) do przeglÄ…darki otworzyć i zaÅ‚adować normalnie. + * **ClearCache**: zestaw `yes` do przeglÄ…darki w pamiÄ™ci podrÄ™cznej plików cookie wyczyszczone zanim otworzy siÄ™ nowe okno + * **clearsessioncache**: zestaw `yes` mieć w pamiÄ™ci podrÄ™cznej plików cookie sesji wyczyszczone zanim otworzy siÄ™ nowe okno + * **pasek narzÄ™dzi**: zestaw `yes` lub `no` Aby włączyć pasek narzÄ™dzi lub wyłączyć dla InAppBrowser (domyÅ›lnie`yes`) + * **enableViewportScale**: zestaw `yes` lub `no` Aby zapobiec rzutni skalowanie za pomocÄ… tagu meta (domyÅ›lnie`no`). + * **mediaPlaybackRequiresUserAction**: zestaw `yes` lub `no` Aby zapobiec HTML5 audio lub wideo z Autoodtwarzanie (domyÅ›lnie`no`). + * **allowInlineMediaPlayback**: zestaw `yes` lub `no` Aby w linii HTML5 odtwarzanie, wyÅ›wietlanie w oknie przeglÄ…darki, a nie interfejs odtwarzanie specyficzne dla urzÄ…dzenia. HTML `video` również musi zawierać element `webkit-playsinline` atrybut (domyÅ›lnie`no`) + * **keyboardDisplayRequiresUserAction**: zestaw `yes` lub `no` Aby otworzyć klawiaturÄ™ ekranowÄ…, gdy elementy formularza ostroÅ›ci za pomocÄ… JavaScript `focus()` połączenia (domyÅ›lnie`yes`). + * **suppressesIncrementalRendering**: zestaw `yes` lub `no` czekać, aż wszystkie nowe widok zawartoÅ›ci jest otrzymane przed renderowany (domyÅ›lnie`no`). + * **presentationstyle**: zestaw `pagesheet` , `formsheet` lub `fullscreen` Aby ustawić [styl prezentacji][1] (domyÅ›lnie`fullscreen`). + * **transitionstyle**: zestaw `fliphorizontal` , `crossdissolve` lub `coververtical` Aby ustawić [styl przejÅ›cia][2] (domyÅ›lnie`coververtical`). + * **toolbarposition**: zestaw `top` lub `bottom` (domyÅ›lnie `bottom` ). Powoduje, że pasek ma być na górze lub na dole okna. + + Windows tylko: + + * **ukryte**: zestaw `yes` do stworzenia przeglÄ…darki i Å‚adowania strony, ale nie pokazuje go. Loadstop zdarzenie fires po zakoÅ„czeniu Å‚adowania. Pominąć lub zestaw `no` (domyÅ›lnie) do przeglÄ…darki otworzyć i zaÅ‚adować normalnie. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Firefox OS +* iOS +* Windows 8 i 8.1 +* Windows Phone 7 i 8 + +### PrzykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### Firefox OS dziwactwa + +Jak plugin nie wymuszać każdy projekt to trzeba dodać pewne reguÅ‚y CSS jeÅ›li otwarty z `target = "_blank"`. Zasady może wyglÄ…dać jak te + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +Obiekt zwrócony z wywoÅ‚ania `cordova.InAppBrowser.open`. + +### Metody + +* metody addEventListener +* removeEventListener +* Zamknij +* Pokaż +* executeScript +* insertCSS + +## metody addEventListener + +> Dodaje detektor zdarzenia z`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **ref**: odniesienie do `InAppBrowser` okna *(InAppBrowser)* + +* **EventName**: zdarzenie sÅ‚uchać *(String)* + + * **loadstart**: zdarzenie gdy odpalam `InAppBrowser` zaczyna siÄ™ Å‚adować adresu URL. + * **loadstop**: zdarzenie gdy odpalam `InAppBrowser` zakoÅ„czeniu Å‚adowania adresu URL. + * **LoadError**: zdarzenie odpala gdy `InAppBrowser` napotka błąd podczas Å‚adowania adresu URL. + * **wyjÅ›cie**: zdarzenie gdy odpalam `InAppBrowser` okno jest zamkniÄ™te. + +* **wywoÅ‚ania zwrotnego**: funkcja, która wykonuje, gdy zdarzenie. Funkcja jest przekazywany `InAppBrowserEvent` obiektu jako parametr. + +### WÅ‚aÅ›ciwoÅ›ci InAppBrowserEvent + +* **Typ**: eventname, albo `loadstart` , `loadstop` , `loaderror` , lub `exit` . *(String)* + +* **adres**: adres URL, który zostaÅ‚ zaÅ‚adowany. *(String)* + +* **Kod**: kod błędu, tylko w przypadku `loaderror` . *(Liczba)* + +* **wiadomość**: komunikat o błędzie, tylko w przypadku `loaderror` . *(String)* + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* iOS +* Windows 8 i 8.1 +* Windows Phone 7 i 8 + +### Szybki przykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> Usuwa detektor zdarzenia z`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **ref**: odniesienie do `InAppBrowser` okna. *(InAppBrowser)* + +* **EventName**: zdarzenie przestanie sÅ‚uchać. *(String)* + + * **loadstart**: zdarzenie gdy odpalam `InAppBrowser` zaczyna siÄ™ Å‚adować adresu URL. + * **loadstop**: zdarzenie gdy odpalam `InAppBrowser` zakoÅ„czeniu Å‚adowania adresu URL. + * **LoadError**: zdarzenie odpala gdy `InAppBrowser` napotka błąd Å‚adowania adresu URL. + * **wyjÅ›cie**: zdarzenie gdy odpalam `InAppBrowser` okno jest zamkniÄ™te. + +* **wywoÅ‚ania zwrotnego**: funkcja do wykonania, gdy zdarzenie. Funkcja jest przekazywany `InAppBrowserEvent` obiektu. + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* iOS +* Windows 8 i 8.1 +* Windows Phone 7 i 8 + +### Szybki przykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## Zamknij + +> Zamyka `InAppBrowser` okna. + + ref.close(); + + +* **ref**: odniesienie do `InAppBrowser` okna *(InAppBrowser)* + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* Firefox OS +* iOS +* Windows 8 i 8.1 +* Windows Phone 7 i 8 + +### Szybki przykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## Pokaż + +> WyÅ›wietla InAppBrowser okno, który zostaÅ‚ otwarty ukryte. Zawód ten jest ignorowany, jeÅ›li InAppBrowser już byÅ‚ widoczny. + + ref.show(); + + +* **ref**: odwoÅ‚anie do InAppBrowser (okno`InAppBrowser`) + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* iOS +* Windows 8 i 8.1 + +### Szybki przykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> Wstrzykuje kod JavaScript w `InAppBrowser` okna + + ref.executeScript(details, callback); + + +* **ref**: odniesienie do `InAppBrowser` okna. *(InAppBrowser)* + +* **injectDetails**: Szczegóły dotyczÄ…ce skryptu, okreÅ›lajÄ…c albo `file` lub `code` klucz. *(Obiekt)* + + * **plik**: adres URL skryptu, aby wstrzyknąć. + * **Kod**: tekst skryptu, aby wstrzyknąć. + +* **wywoÅ‚ania zwrotnego**: funkcja, która wykonuje po kod JavaScript jest wstrzykiwany. + + * JeÅ›li taki skrypt jest typu `code` , wykonuje wywoÅ‚anie zwrotne z pojedynczym parametrem, który jest wartość zwracana przez skrypt, owiniÄ™te w `Array` . Dla wielu linii skrypty to wartość zwracana ostatniej instrukcja, lub ostatni wyrażenie oceniane. + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* iOS +* Windows 8 i 8.1 + +### Szybki przykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> Wstrzykuje CSS w `InAppBrowser` okna. + + ref.insertCSS(details, callback); + + +* **ref**: odniesienie do `InAppBrowser` okna *(InAppBrowser)* + +* **injectDetails**: Szczegóły dotyczÄ…ce skryptu, okreÅ›lajÄ…c albo `file` lub `code` klucz. *(Obiekt)* + + * **plik**: URL arkusza stylów do wsuwania. + * **Kod**: tekst z arkusza stylów do wstrzykiwania. + +* **wywoÅ‚ania zwrotnego**: funkcja, która wykonuje po CSS jest wstrzykiwany. + +### ObsÅ‚ugiwane platformy + +* Amazon Fire OS +* Android +* iOS + +### Szybki przykÅ‚ad + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/ru/index.md b/plugins/cordova-plugin-inappbrowser/doc/ru/index.md new file mode 100644 index 00000000..3b4e967d --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/ru/index.md @@ -0,0 +1,330 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +Ðтот плагин обеÑпечивает предÑтавление веб-браузера, что показывает при вызове`window.open()`. + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + + +**Примечание**: InAppBrowser окно ведет ÑÐµÐ±Ñ ÐºÐ°Ðº Ñтандартный веб-браузер и не может доÑтуп API Cordova. + +## УÑтановка + + cordova plugin add cordova-plugin-inappbrowser + + +## window.open + +Открывает URL-Ð°Ð´Ñ€ÐµÑ Ð² новом `InAppBrowser` например, текущий ÑкземплÑÑ€ браузера или браузера ÑиÑтемы. + + var ref = window.open(url, target, options); + + +* **ÑÑылка**: ÑÑылка Ð´Ð»Ñ `InAppBrowser` окно. *(InAppBrowser)* + +* **URL**: URL-Ð°Ð´Ñ€ÐµÑ Ð´Ð»Ñ Ð·Ð°Ð³Ñ€ÑƒÐ·ÐºÐ¸ *(String)*. Вызвать `encodeURI()` на Ñто, еÑли URL-Ð°Ð´Ñ€ÐµÑ Ñодержит Ñимволы Unicode. + +* **Цель**: цель Ð´Ð»Ñ Ð·Ð°Ð³Ñ€ÑƒÐ·ÐºÐ¸ URL-адреÑа, необÑзательный параметр, по умолчанию `_self` . *(Строка)* + + * `_self`: ОткрываетÑÑ Ð² Cordova WebView, еÑли URL-Ð°Ð´Ñ€ÐµÑ Ð² белый ÑпиÑок, в противном Ñлучае он открываетÑÑ Ð²`InAppBrowser`. + * `_blank`: Открывает в`InAppBrowser`. + * `_system`: ОткрываетÑÑ Ð² веб-браузера ÑиÑтемы. + +* **опции**: параметры Ð´Ð»Ñ `InAppBrowser` . ÐеобÑзательный параметр, Ð²Ð¸Ð½Ð¾Ð²Ð½Ð°Ñ Ð²: `location=yes` . *(Строка)* + + `options`Строка не должна Ñодержать каких-либо пуÑтое проÑтранÑтво, и ÐºÐ°Ð¶Ð´Ð°Ñ Ñ„ÑƒÐ½ÐºÑ†Ð¸Ñ Ð¿Ð°Ñ€ имÑ/значение должны быть разделены запÑтой. Ð¤ÑƒÐ½ÐºÑ†Ð¸Ñ Ð¸Ð¼ÐµÐ½Ð° нечувÑтвительны к региÑтру. Ð’Ñе платформы поддерживают иÑходное значение: + + * **РаÑположение**: равным `yes` или `no` превратить `InAppBrowser` в адреÑную Ñтроку или выключить. + + Только андроид: + + * **closebuttoncaption**: задайте Ñтроку Ð´Ð»Ñ Ð¸ÑÐ¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² качеÑтве заголовка кнопки **Ñделали** . + * **Ñкрытые**: значение `yes` Ð´Ð»Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð±Ñ€Ð°ÑƒÐ·ÐµÑ€Ð° и загрузки Ñтраницы, но не показать его. Событие loadstop возникает, когда загрузка завершена. ОпуÑтить или набор `no` (по умолчанию), чтобы браузер открыть и загрузить нормально. + * **ClearCache**: набор `yes` иметь браузера куки кÑш очищен перед открытием нового окна + * **clearsessioncache**: значение `yes` иметь кÑш cookie ÑеанÑа очищаетÑÑ Ð¿ÐµÑ€ÐµÐ´ открытием нового окна + + только iOS: + + * **closebuttoncaption**: задайте Ñтроку Ð´Ð»Ñ Ð¸ÑÐ¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² качеÑтве заголовка кнопки **Ñделали** . Обратите внимание, что вам нужно ÑамоÑтоÑтельно локализовать Ñто значение. + * **disallowoverscroll**: значение `yes` или `no` (по умолчанию `no` ). Включает/отключает ÑвойÑтво UIWebViewBounce. + * **Ñкрытые**: значение `yes` Ð´Ð»Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð±Ñ€Ð°ÑƒÐ·ÐµÑ€Ð° и загрузки Ñтраницы, но не показать его. Событие loadstop возникает, когда загрузка завершена. ОпуÑтить или набор `no` (по умолчанию), чтобы браузер открыть и загрузить нормально. + * **ClearCache**: набор `yes` иметь браузера куки кÑш очищен перед открытием нового окна + * **clearsessioncache**: значение `yes` иметь кÑш cookie ÑеанÑа очищаетÑÑ Ð¿ÐµÑ€ÐµÐ´ открытием нового окна + * **панели инÑтрументов**: набор `yes` или `no` Ð´Ð»Ñ Ð²ÐºÐ»ÑŽÑ‡ÐµÐ½Ð¸Ñ Ð¿Ð°Ð½ÐµÐ»Ð¸ инÑтрументов или выключить InAppBrowser (по умолчанию`yes`) + * **enableViewportScale**: значение `yes` или `no` Ð´Ð»Ñ Ð¿Ñ€ÐµÐ´Ð¾Ñ‚Ð²Ñ€Ð°Ñ‰ÐµÐ½Ð¸Ñ Ð¿Ñ€Ð¾Ñмотра, маÑÑˆÑ‚Ð°Ð±Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ñ‡ÐµÑ€ÐµÐ· тег meta (по умолчанию`no`). + * **mediaPlaybackRequiresUserAction**: значение `yes` или `no` Ð´Ð»Ñ Ð¿Ñ€ÐµÐ´Ð¾Ñ‚Ð²Ñ€Ð°Ñ‰ÐµÐ½Ð¸Ñ HTML5 аудио или видео от ÐвтовоÑпроизведение (по умолчанию`no`). + * **allowInlineMediaPlayback**: значение `yes` или `no` чтобы разрешить воÑпроизведение мультимедиа HTML5 в Ñтроки, Ð¾Ñ‚Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñ Ð² окне браузера, а не конкретного уÑтройÑтва воÑÐ¿Ñ€Ð¾Ð¸Ð·Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¸Ð½Ñ‚ÐµÑ€Ñ„ÐµÐ¹Ñ. HTML `video` Ñлемент должен также включать `webkit-playsinline` атрибут (по умолчанию`no`) + * **keyboardDisplayRequiresUserAction**: значение `yes` или `no` чтобы открыть клавиатуру, когда формы Ñлементы получают Ñ„Ð¾ÐºÑƒÑ Ñ‡ÐµÑ€ÐµÐ· JavaScript в `focus()` вызов (по умолчанию`yes`). + * **suppressesIncrementalRendering**: значение `yes` или `no` ждать, пока вÑе новое Ñодержание предÑтавление получено до визуализации (по умолчанию`no`). + * **presentationstyle**: набор `pagesheet` , `formsheet` или `fullscreen` чтобы задать [Ñтиль презентации][1] (по умолчанию`fullscreen`). + * **transitionstyle**: набор `fliphorizontal` , `crossdissolve` или `coververtical` чтобы задать [Ñтиль перехода][2] (по умолчанию`coververtical`). + * **toolbarposition**: значение `top` или `bottom` (по умолчанию `bottom` ). Вызывает панели инÑтрументов, чтобы быть в верхней или нижней чаÑти окна. + + Windows только: + + * **Ñкрытые**: значение `yes` Ð´Ð»Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð±Ñ€Ð°ÑƒÐ·ÐµÑ€Ð° и загрузки Ñтраницы, но не показать его. Событие loadstop возникает, когда загрузка завершена. ОпуÑтить или набор `no` (по умолчанию), чтобы браузер открыть и загрузить нормально. + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Firefox OS +* iOS +* Windows 8 и 8.1 +* Windows Phone 7 и 8 + +### Пример + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = window.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### ОÑобенноÑти Firefox OS + +Как плагин не применÑть любой дизайн еÑть необходимоÑть добавить некоторые правила CSS, еÑли открыт Ñ `target='_blank'` . Правила может выглÑдеть как Ñти + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## Внутренний браузер + +Объект, возвращаемый из вызова`window.open`. + +### Методы + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> ДобавлÑет проÑлушиватель Ð´Ð»Ñ ÑÐ¾Ð±Ñ‹Ñ‚Ð¸Ñ Ð¾Ñ‚`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **ÑÑылка**: ÑÑылка Ð´Ð»Ñ `InAppBrowser` окно *(InAppBrowser)* + +* **EventName**: Ñобытие Ð´Ð»Ñ Ð¿Ñ€Ð¾ÑÐ»ÑƒÑˆÐ¸Ð²Ð°Ð½Ð¸Ñ *(String)* + + * **loadstart**: Ñобытие возникает, когда `InAppBrowser` начинает Ð´Ð»Ñ Ð·Ð°Ð³Ñ€ÑƒÐ·ÐºÐ¸ URL-адреÑа. + * **loadstop**: Ñобытие возникает, когда `InAppBrowser` завершит загрузку URL-адреÑа. + * **loaderror**: Ñобытие возникает, когда `InAppBrowser` обнаруживает ошибку при загрузке URL-адреÑа. + * **выход**: возникает Ñобытие, когда `InAppBrowser` окно закрыто. + +* **обратного вызова**: функциÑ, ÐºÐ¾Ñ‚Ð¾Ñ€Ð°Ñ Ð²Ñ‹Ð¿Ð¾Ð»Ð½ÑетÑÑ, когда возникает Ñобытие. Ð¤ÑƒÐ½ÐºÑ†Ð¸Ñ Ð¿ÐµÑ€ÐµÐ´Ð°ÐµÑ‚ÑÑ `InAppBrowserEvent` объект в качеÑтве параметра. + +### InAppBrowserEvent ÑвойÑтва + +* **тип**: eventname, либо `loadstart` , `loadstop` , `loaderror` , или `exit` . *(Строка)* + +* **URL**: URL-адреÑ, который был загружен. *(Строка)* + +* **код**: код ошибки, только в Ñлучае `loaderror` . *(ЧиÑло)* + +* **Ñообщение**: Ñообщение об ошибке, только в Ñлучае `loaderror` . *(Строка)* + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* iOS +* Windows 8 и 8.1 +* Windows Phone 7 и 8 + +### Краткий пример + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## метод removeEventListener + +> УдалÑет проÑлушиватель Ð´Ð»Ñ ÑÐ¾Ð±Ñ‹Ñ‚Ð¸Ñ Ð¾Ñ‚`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **ÑÑылка**: ÑÑылка Ð´Ð»Ñ `InAppBrowser` окно. *(InAppBrowser)* + +* **EventName**: Ñобытие прекратить проÑлушивание. *(Строка)* + + * **loadstart**: Ñобытие возникает, когда `InAppBrowser` начинает Ð´Ð»Ñ Ð·Ð°Ð³Ñ€ÑƒÐ·ÐºÐ¸ URL-адреÑа. + * **loadstop**: Ñобытие возникает, когда `InAppBrowser` завершит загрузку URL-адреÑа. + * **loaderror**: Ñобытие возникает, когда `InAppBrowser` обнаруживает ошибку загрузки URL-адреÑа. + * **выход**: возникает Ñобытие, когда `InAppBrowser` окно закрываетÑÑ. + +* **обратного вызова**: функциÑ, выполнÑÐµÐ¼Ð°Ñ ÐºÐ¾Ð³Ð´Ð° Ñто Ñобытие наÑтупает. Ð¤ÑƒÐ½ÐºÑ†Ð¸Ñ Ð¿ÐµÑ€ÐµÐ´Ð°ÐµÑ‚ÑÑ `InAppBrowserEvent` объект. + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* iOS +* Windows 8 и 8.1 +* Windows Phone 7 и 8 + +### Краткий пример + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> Закрывает `InAppBrowser` окно. + + Ref.Close(); + + +* **ÑÑылка**: ÑÑылка на `InAppBrowser` окно *(InAppBrowser)* + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* Firefox OS +* iOS +* Windows 8 и 8.1 +* Windows Phone 7 и 8 + +### Краткий пример + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> ОтображаетÑÑ Ð¾ÐºÐ½Ð¾ InAppBrowser, был открыт Ñкрытые. Вызов Ñто не имеет Ñффекта при InAppBrowser уже был виден. + + Ref.Show(); + + +* **ÑÑылка**: ÑÑылка на окно (InAppBrowser`InAppBrowser`) + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* iOS +* Windows 8 и 8.1 + +### Краткий пример + + var ref = window.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> Ð’ÑтавлÑет код JavaScript в `InAppBrowser` окно + + ref.executeScript(details, callback); + + +* **ÑÑылка**: ÑÑылка на `InAppBrowser` окно. *(InAppBrowser)* + +* **injectDetails**: подробноÑти ÑÑ†ÐµÐ½Ð°Ñ€Ð¸Ñ Ð´Ð»Ñ Ð·Ð°Ð¿ÑƒÑка, указав либо `file` или `code` ключ. *(Объект)* + + * **файл**: URL-Ð°Ð´Ñ€ÐµÑ ÑÑ†ÐµÐ½Ð°Ñ€Ð¸Ñ Ð²Ñтавки. + * **код**: текÑÑ‚ ÑÑ†ÐµÐ½Ð°Ñ€Ð¸Ñ Ð´Ð»Ñ Ð²Ñтавки. + +* **обратного вызова**: функциÑ, ÐºÐ¾Ñ‚Ð¾Ñ€Ð°Ñ Ð²Ñ‹Ð¿Ð¾Ð»Ð½Ñет поÑле вводÑÑ‚ JavaScript-код. + + * ЕÑли введенный Ñкрипт имеет тип `code` , обратный вызов выполнÑетÑÑ Ñ Ð¾Ð´Ð½Ð¸Ð¼ параметром, который ÑвлÑетÑÑ Ð²Ð¾Ð·Ð²Ñ€Ð°Ñ‰Ð°ÐµÐ¼Ð¾Ðµ значение ÑценариÑ, завернутые в `Array` . Ð”Ð»Ñ Ð¼Ð½Ð¾Ð³Ð¾Ñтрочных Ñценариев Ñто возвращаемое значение поÑледнего оператора, или поÑледнее вычиÑленное выражение. + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* iOS +* Windows 8 и 8.1 + +### Краткий пример + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> ВнедрÑет CSS в `InAppBrowser` окно. + + ref.insertCSS(details, callback); + + +* **ÑÑылка**: ÑÑылка на `InAppBrowser` окно *(InAppBrowser)* + +* **injectDetails**: детали ÑÑ†ÐµÐ½Ð°Ñ€Ð¸Ñ Ð´Ð»Ñ Ð·Ð°Ð¿ÑƒÑка, указав либо `file` или `code` ключ. *(Объект)* + + * **файл**: URL-Ð°Ð´Ñ€ÐµÑ Ñ‚Ð°Ð±Ð»Ð¸Ñ†Ñ‹ Ñтилей Ð´Ð»Ñ Ð²Ñтавки. + * **код**: текÑÑ‚ таблицы Ñтилей Ð´Ð»Ñ Ð²Ñтавки. + +* **обратного вызова**: функциÑ, ÐºÐ¾Ñ‚Ð¾Ñ€Ð°Ñ Ð²Ñ‹Ð¿Ð¾Ð»Ð½Ñет поÑле вводÑÑ‚ CSS. + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* iOS + +### Краткий пример + + var ref = window.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/doc/zh/index.md b/plugins/cordova-plugin-inappbrowser/doc/zh/index.md new file mode 100644 index 00000000..c12c0461 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/doc/zh/index.md @@ -0,0 +1,357 @@ +<!--- + 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. +--> + +# cordova-plugin-inappbrowser + +é€™å€‹å¤–æŽ›ç¨‹å¼æä¾›äº†ä¸€å€‹ web ç€è¦½å™¨è¦–圖,顯示在調用 `cordova.InAppBrowser.open()`. + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + + +`cordova.InAppBrowser.open()` 函數被定義為一個臨時替代 `window.open ()` 函數。 ç¾æœ‰ `window.open ()` 調用,å¯ä»¥é€šéŽæ›¿æ› window.open 使用 InAppBrowser 視窗: + + window.open = cordova.InAppBrowser.open; + + +InAppBrowser 視窗åƒä¸€å€‹æ¨™æº–çš„ web ç€è¦½å™¨ä¸ï¼Œä¸¦ä¸”無法訪å•科爾多瓦 Api。 為æ¤ï¼Œå»ºè° InAppBrowser 如果您需è¦è¼‰å…¥å”åŠ›å» å•† (ä¸å¯ä¿¡ï¼‰ çš„å…§å®¹ï¼Œè€Œä¸æ˜¯è¼‰å…¥ï¼Œé€²å…¥ä¸»è¦çš„科爾多瓦 web 視圖。 InAppBrowser 是ä¸å—白åå–®ä¸ï¼Œä¹Ÿä¸åœ¨ç³»çµ±ç€è¦½å™¨ä¸æ‰“開的連çµã€‚ + +InAppBrowser é è¨æƒ…æ³ä¸‹å®ƒè‡ªå·±çš„ GUI æŽ§åˆ¶é …ç‚ºä½¿ç”¨è€…æä¾› (後退〠å‰é€²ã€ 完æˆï¼‰ã€‚ + +為å‘後相容性,æ¤å¤–掛程å¼é‚„鉤 `window.open`。 然而,`window.open` 外掛程å¼å®‰è£é‰¤åå¯ä»¥æœ‰å‰¯ä½œç”¨ ï¼ˆå°¤å…¶æ˜¯å¦‚æžœé€™å€‹å¤–æŽ›ç¨‹å¼æ˜¯åªåˆ—為å¦ä¸€å€‹å¤–掛程å¼çš„ä¾è³´é …)。 在未來的主è¦ç™¼è¡Œç‰ˆæœ¬ä¸ï¼Œå°‡åˆªé™¤ `window.open` 鉤。 一直至從該外掛程å¼é‰¤å後,應用程å¼å¯ä»¥æ‰‹å‹•還原é è¨è¡Œç‚ºï¼š + + delete window.open // Reverts the call back to it's prototype's default + + +é›–ç„¶ `window.open` 在全çƒç¯„åœå…§ï¼ŒInAppBrowser ä¸å¯ç”¨ç›´åˆ° `deviceready` 事件之後。 + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("window.open works well"); + } + + +## å®‰è£ + + cordova plugin add cordova-plugin-inappbrowser + + +如果您希望所有é é¢è¼‰å…¥ä¸æ‚¨çš„æ‡‰ç”¨ç¨‹å¼è¦é€šéŽ InAppBrowserï¼Œä½ å¯ä»¥ç°¡å–®åœ°åœ¨åˆå§‹åŒ–éŽç¨‹ä¸é‰¤ `window.open`。舉個例å: + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + window.open = cordova.InAppBrowser.open; + } + + +## cordova.InAppBrowser.open + +在新的 `InAppBrowser` 實例,當å‰çš„ç€è¦½å™¨å¯¦ä¾‹æˆ–系統ç€è¦½å™¨ä¸æ‰“é–‹çš„ URL。 + + var ref = cordova.InAppBrowser.open(url, target, options); + + +* **ref**: åƒè€ƒ `InAppBrowser` 視窗。*() InAppBrowser* + +* **url**: è¦è¼‰å…¥*(å—串)*çš„ URL。調用 `encodeURI()` 這個如果 URL åŒ…å« Unicode å—元。 + +* **target**: 目標在其ä¸è¼‰å…¥çš„ URL,å¯é¸åƒæ•¸ï¼Œé è¨å€¼ç‚º `_self` 。*(å—串)* + + * `_self`: 打開在科爾多瓦 web 視圖如果 URL 是在白åå–®ä¸ï¼Œå¦å‰‡å®ƒåœ¨æ‰“é–‹`InAppBrowser`. + * `_blank`: 在打開`InAppBrowser`. + * `_system`: 在該系統的 web ç€è¦½å™¨ä¸æ‰“開。 + +* **options**: é¸é …為 `InAppBrowser` 。å¯é¸ï¼Œæ‹–æ¬ åˆ°ï¼š `location=yes` 。*(å—串)* + + `options`å—ä¸²å¿…é ˆä¸åŒ…å«ä»»ä½•ç©ºç™½çš„ç©ºé–“ï¼Œå’Œå¿…é ˆç”¨é€—è™Ÿåˆ†éš”æ¯å€‹åŠŸèƒ½çš„å稱/值å°ã€‚ 功能å稱å€åˆ†å¤§å°å¯«ã€‚ 所有平臺都支æ´ä¸‹é¢çš„值: + + * **location**: è¨ç½®ç‚º `yes` 或 `no` ,打開 `InAppBrowser` çš„ä½ç½®æ¬„打開或關閉。 + + Android ç³»çµ±åªæœ‰ï¼š + + * **hidden**: å°‡è¨ç½®ç‚º `yes` ,創建ç€è¦½å™¨å’Œè¼‰å…¥é é¢ï¼Œä½†ä¸æ˜¯é¡¯ç¤ºå®ƒã€‚ è¼‰å…¥å®Œæˆæ™‚,將觸發 loadstop 事件。 çœç•¥æˆ–è¨ç½®ç‚º `no` (é è¨å€¼ï¼‰ï¼Œæœ‰çš„ç€è¦½å™¨æ‰“開,然後以æ£å¸¸æ–¹å¼è¼‰å…¥ã€‚ + * **clearcache**: å°‡è¨ç½®ç‚º `yes` 有ç€è¦½å™¨çš„ cookie 清除緩å˜ä¹‹å‰æ‰“開新視窗 + * **clearsessioncache**: å°‡è¨ç½®ç‚º `yes` 有會話 cookie ç·©å˜æ¸…除之剿‰“開新視窗 + + åªæœ‰ iOS: + + * **closebuttoncaption**: è¨ç½®ç‚ºä¸€å€‹å—串,以用作**åš**æŒ‰éˆ•çš„æ¨™é¡Œã€‚è«‹æ³¨æ„æ‚¨éœ€è¦å°æ¤å€¼é€²è¡Œç•¶åœ°èªžç³»åŒ–ä½ è‡ªå·±ã€‚ + * **disallowoverscroll**: å°‡è¨ç½®ç‚º `yes` 或 `no` (é è¨å€¼æ˜¯ `no` )。打開/關閉的 UIWebViewBounce 屬性。 + * **hidden**: å°‡è¨ç½®ç‚º `yes` ,創建ç€è¦½å™¨å’Œè¼‰å…¥é é¢ï¼Œä½†ä¸æ˜¯é¡¯ç¤ºå®ƒã€‚ è¼‰å…¥å®Œæˆæ™‚,將觸發 loadstop 事件。 çœç•¥æˆ–è¨ç½®ç‚º `no` (é è¨å€¼ï¼‰ï¼Œæœ‰çš„ç€è¦½å™¨æ‰“開,然後以æ£å¸¸æ–¹å¼è¼‰å…¥ã€‚ + * **clearcache**: å°‡è¨ç½®ç‚º `yes` 有ç€è¦½å™¨çš„ cookie 清除緩å˜ä¹‹å‰æ‰“開新視窗 + * **clearsessioncache**: å°‡è¨ç½®ç‚º `yes` 有會話 cookie ç·©å˜æ¸…除之剿‰“開新視窗 + * **toolbar**: è¨ç½®ç‚º `yes` 或 `no` ,為 InAppBrowser (é è¨ç‚ºæ‰“開或關閉工具列`yes`) + * **enableViewportScale**: å°‡è¨ç½®ç‚º `yes` 或 `no` ,防æ¢é€šéŽ meta 標記 (é è¨ç‚ºç¸®æ”¾çš„視å€`no`). + * **mediaPlaybackRequiresUserAction**: å°‡è¨ç½®ç‚º `yes` 或 `no` ï¼Œé˜²æ¢ HTML5 éŸ³è¨Šæˆ–è¦–é »å¾ž autoplaying (é è¨ç‚º`no`). + * **allowInlineMediaPlayback**: å°‡è¨ç½®ç‚º `yes` 或 `no` ,讓線在 HTML5 æ’æ”¾åª’體,在ç€è¦½å™¨è¦–窗ä¸ï¼Œè€Œä¸æ˜¯ç‰¹å®šäºŽè¨å‚™æ’放介é¢å…§é¡¯ç¤ºã€‚ HTML çš„ `video` å…ƒç´ é‚„å¿…é ˆåŒ…æ‹¬ `webkit-playsinline` 屬性 (é è¨ç‚º`no`) + * **keyboardDisplayRequiresUserAction**: å°‡è¨ç½®ç‚º `yes` 或 `no` æ™‚ï¼Œè¦æ‰“é–‹éµç›¤è¡¨å–®å…ƒç´ æŽ¥æ”¶ç„¦é»žé€šéŽ JavaScript çš„ `focus()` 調用 (é è¨ç‚º`yes`). + * **suppressesIncrementalRendering**: å°‡è¨ç½®ç‚º `yes` 或 `no` ç‰å¾…,直到所有新查看的內容æ£åœ¨å‘ˆç¾ (é è¨ç‚ºå‰æ”¶åˆ°`no`). + * **presentationstyle**: å°‡è¨ç½®ç‚º `pagesheet` , `formsheet` 或 `fullscreen` 來è¨ç½®[演示文稿樣å¼][1](é è¨ç‚º`fullscreen`). + * **transitionstyle**: å°‡è¨ç½®ç‚º `fliphorizontal` , `crossdissolve` 或 `coververtical` è¨ç½®[éŽæ¸¡æ¨£å¼][2](é è¨ç‚º`coververtical`). + * **toolbarposition**: å°‡è¨ç½®ç‚º `top` 或 `bottom` (é è¨å€¼æ˜¯ `bottom` ï¼‰ã€‚ä½¿å·¥å…·åˆ—ï¼Œå‰‡åœ¨é ‚éƒ¨æˆ–åº•éƒ¨çš„è¦–çª—ã€‚ + + åƒ…é™ Windows: + + * **hidden**: å°‡è¨ç½®ç‚º `yes` ,創建ç€è¦½å™¨ä¸¦è¼‰å…¥é é¢ï¼Œä½†ä¸æ˜¯é¡¯ç¤ºå®ƒã€‚ è¼‰å…¥å®Œæˆæ™‚,將觸發 loadstop 事件。 çœç•¥æˆ–被è¨ç½®ç‚º `no` (é è¨å€¼ï¼‰ï¼Œæœ‰çš„ç€è¦½å™¨æ‰“開,以æ£å¸¸æ–¹å¼è¼‰å…¥ã€‚ + + [1]: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle + [2]: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* 黑莓 10 +* ç«ç‹ç€è¦½å™¨çš„作æ¥ç³»çµ± +* iOS +* Windows 8 å’Œ 8.1 +* Windows Phone 7 å’Œ 8 + +### 示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ãƒãƒ³ã‚°ãƒ«'), '_blank', 'location=yes'); + + +### ç«ç‹ç€è¦½å™¨ä½œæ¥ç³»çµ±çš„æ€ªç™– + +外掛程å¼ä¸æœƒå¼·åˆ¶ä»»ä½•è¨è¨ˆæ˜¯éœ€è¦æ·»åŠ ä¸€äº› CSS è¦å‰‡ï¼Œå¦‚果打開與 `target=_blank`。è¦å‰‡ 》 å¯èƒ½çœ‹èµ·ä¾†åƒé€™äº› + + css + .inAppBrowserWrap { + background-color: rgba(0,0,0,0.75); + color: rgba(235,235,235,1.0); + } + .inAppBrowserWrap menu { + overflow: auto; + list-style-type: none; + padding-left: 0; + } + .inAppBrowserWrap menu li { + font-size: 25px; + height: 25px; + float: left; + margin: 0 10px; + padding: 3px 10px; + text-decoration: none; + color: #ccc; + display: block; + background: rgba(30,30,30,0.50); + } + .inAppBrowserWrap menu li.disabled { + color: #777; + } + + +## InAppBrowser + +å° `科爾多瓦的調用返回的物件。InAppBrowser.open`. + +### 方法 + +* addEventListener +* removeEventListener +* close +* show +* executeScript +* insertCSS + +## addEventListener + +> ç‚ºäº‹ä»¶æ·»åŠ ä¸€å€‹æ””æˆªå™¨`InAppBrowser`. + + ref.addEventListener(eventname, callback); + + +* **ref**: åƒè€ƒ `InAppBrowser` 視窗*(InAppBrowser)* + +* **eventname**: 事件åµè½*(å—串)* + + * **loadstart**: 當觸發事件 `InAppBrowser` 開始載入一個 URL。 + * **loadstop**: 當觸發事件 `InAppBrowser` 完æˆè¼‰å…¥ä¸€å€‹ URL。 + * **loaderror**: 當觸發事件 `InAppBrowser` 載入 URL 時é‡åˆ°éŒ¯èª¤ã€‚ + * **exit**: 當觸發事件 `InAppBrowser` 關閉視窗。 + +* **callback**: åŸ·è¡Œæ™‚è§¸ç™¼è©²äº‹ä»¶çš„å‡½æ•¸ã€‚è©²å‡½æ•¸é€šéŽ `InAppBrowserEvent` ç‰©ä»¶ä½œç‚ºåƒæ•¸ã€‚ + +### InAppBrowserEvent 屬性 + +* **type**: eventname,或者 `loadstart` , `loadstop` , `loaderror` ,或 `exit` 。*(å—串)* + +* **url**: 已載入的 URL。*(å—串)* + +* **code**: 僅ä¸çš„æƒ…æ³çš„錯誤代碼 `loaderror` 。*(人數)* + +* **message**: 該錯誤訊æ¯ï¼Œåªæœ‰åœ¨çš„æƒ…æ³ä¸‹ `loaderror` 。*(å—串)* + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* iOS +* Windows 8 å’Œ 8.1 +* Windows Phone 7 å’Œ 8 + +### 快速的示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstart', function(event) { alert(event.url); }); + + +## removeEventListener + +> 移除的事件攔截器`InAppBrowser`. + + ref.removeEventListener(eventname, callback); + + +* **ref**: åƒè€ƒ `InAppBrowser` 視窗。*() InAppBrowser* + +* **eventname**: è¦åœæ¢åµè½çš„事件。*(å—串)* + + * **loadstart**: 當觸發事件 `InAppBrowser` 開始載入一個 URL。 + * **loadstop**: 當觸發事件 `InAppBrowser` 完æˆè¼‰å…¥ä¸€å€‹ URL。 + * **loaderror**: 當觸發事件 `InAppBrowser` é‡åˆ°éŒ¯èª¤è¼‰å…¥ä¸€å€‹ URL。 + * **exit**: 當觸發事件 `InAppBrowser` 關閉視窗。 + +* **callback**: è¦åœ¨äº‹ä»¶è§¸ç™¼æ™‚åŸ·è¡Œçš„å‡½æ•¸ã€‚è©²å‡½æ•¸é€šéŽ `InAppBrowserEvent` 物件。 + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* iOS +* Windows 8 å’Œ 8.1 +* Windows Phone 7 å’Œ 8 + +### 快速的示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + var myCallback = function(event) { alert(event.url); } + ref.addEventListener('loadstart', myCallback); + ref.removeEventListener('loadstart', myCallback); + + +## close + +> 關閉 `InAppBrowser` 視窗。 + + ref.close(); + + +* **ref**: åƒè€ƒ `InAppBrowser` 視窗*(InAppBrowser)* + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* ç«ç‹ç€è¦½å™¨çš„作æ¥ç³»çµ± +* iOS +* Windows 8 å’Œ 8.1 +* Windows Phone 7 å’Œ 8 + +### 快速的示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.close(); + + +## show + +> 顯示打開了隱è—çš„ InAppBrowser 視窗。調用這沒有任何影響,如果 InAppBrowser 是已經å¯è¦‹ã€‚ + + ref.show(); + + +* **ref**: InAppBrowser 視窗 (åƒè€ƒ`InAppBrowser`) + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* iOS +* Windows 8 å’Œ 8.1 + +### 快速的示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'hidden=yes'); + // some time later... + ref.show(); + + +## executeScript + +> 注入到 JavaScript 代碼 `InAppBrowser` 視窗 + + ref.executeScript(details, callback); + + +* **ref**: åƒè€ƒ `InAppBrowser` 視窗。*() InAppBrowser* + +* **injectDetails**: è¦é‹è¡Œçš„腳本的詳細資訊或指定 `file` 或 `code` 的關éµã€‚*(物件)* + + * **檔**: 腳本的 URL 來注入。 + * **代碼**: è¦æ³¨å…¥è…³æœ¬çš„æ–‡æœ¬ã€‚ + +* **回檔**: 執行後注入的 JavaScript 代碼的函數。 + + * 如果æ’入的腳本的類型 `code` ï¼Œå›žæª”åŸ·è¡Œä½¿ç”¨å–®å€‹åƒæ•¸ï¼Œé€™æ˜¯è©²è…³æœ¬çš„傳回值,裹在 `Array` 。 å°æ–¼å¤šè¡Œè…³æœ¬ï¼Œé€™æ˜¯æœ€å¾Œä¸€æ¢èªžå¥æˆ–最後計算的é‹ç®—å¼çš„傳回值。 + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* iOS +* Windows 8 å’Œ 8.1 + +### 快速的示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.executeScript({file: "myscript.js"}); + }); + + +## insertCSS + +> 注入到 CSS `InAppBrowser` 視窗。 + + ref.insertCSS(details, callback); + + +* **ref**: åƒè€ƒ `InAppBrowser` 視窗*(InAppBrowser)* + +* **injectDetails**: è¦é‹è¡Œçš„腳本的詳細資訊或指定 `file` 或 `code` 的關éµã€‚*(物件)* + + * **file**: 樣å¼è¡¨çš„ URL 來注入。 + * **code**: 文本樣å¼è¡¨çš„æ³¨å…¥ã€‚ + +* **callback**: 在 CSS 注射後執行的函數。 + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* iOS + +### 快速的示例 + + var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); + ref.addEventListener('loadstop', function() { + ref.insertCSS({file: "mystyles.css"}); + }); diff --git a/plugins/cordova-plugin-inappbrowser/package.json b/plugins/cordova-plugin-inappbrowser/package.json new file mode 100644 index 00000000..e35e1dc3 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/package.json @@ -0,0 +1,48 @@ +{ + "name": "cordova-plugin-inappbrowser", + "version": "1.0.0", + "description": "Cordova InAppBrowser Plugin", + "cordova": { + "id": "cordova-plugin-inappbrowser", + "platforms": [ + "android", + "amazon-fireos", + "ubuntu", + "ios", + "wp7", + "wp8", + "windows8", + "windows", + "firefoxos" + ] + }, + "repository": { + "type": "git", + "url": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git" + }, + "keywords": [ + "cordova", + "in", + "app", + "browser", + "inappbrowser", + "ecosystem:cordova", + "cordova-android", + "cordova-amazon-fireos", + "cordova-ubuntu", + "cordova-ios", + "cordova-wp7", + "cordova-wp8", + "cordova-windows8", + "cordova-windows", + "cordova-firefoxos" + ], + "engines": [ + { + "name": "cordova", + "version": ">=3.1.0" + } + ], + "author": "Apache Software Foundation", + "license": "Apache 2.0" +} diff --git a/plugins/cordova-plugin-inappbrowser/plugin.xml b/plugins/cordova-plugin-inappbrowser/plugin.xml new file mode 100644 index 00000000..16ac0d19 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/plugin.xml @@ -0,0 +1,227 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="cordova-plugin-inappbrowser" + version="1.0.0"> + + <name>InAppBrowser</name> + <description>Cordova InAppBrowser Plugin</description> + <license>Apache 2.0</license> + <keywords>cordova,in,app,browser,inappbrowser</keywords> + <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git</repo> + <issue>https://issues.apache.org/jira/browse/CB/component/12320641</issue> + + <engines> + <engine name="cordova" version=">=3.1.0" /><!-- Needs cordova/urlutil --> + </engines> + + <!-- android --> + <platform name="android"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="InAppBrowser"> + <param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser"/> + </feature> + </config-file> + + <source-file src="src/android/InAppBrowser.java" target-dir="src/org/apache/cordova/inappbrowser" /> + <source-file src="src/android/InAppBrowserDialog.java" target-dir="src/org/apache/cordova/inappbrowser" /> + <source-file src="src/android/InAppChromeClient.java" target-dir="src/org/apache/cordova/inappbrowser" /> + + <!-- drawable src/android/resources --> + <resource-file src="src/android/res/drawable-hdpi/ic_action_next_item.png" target="res/drawable-hdpi/ic_action_next_item.png" /> + <resource-file src="src/android/res/drawable-mdpi/ic_action_next_item.png" target="res/drawable-mdpi/ic_action_next_item.png" /> + <resource-file src="src/android/res/drawable-xhdpi/ic_action_next_item.png" target="res/drawable-xhdpi/ic_action_next_item.png" /> + <resource-file src="src/android/res/drawable-xxhdpi/ic_action_next_item.png" target="res/drawable-xxhdpi/ic_action_next_item.png" /> + + <resource-file src="src/android/res/drawable-hdpi/ic_action_previous_item.png" target="res/drawable-hdpi/ic_action_previous_item.png" /> + <resource-file src="src/android/res/drawable-mdpi/ic_action_previous_item.png" target="res/drawable-mdpi/ic_action_previous_item.png" /> + <resource-file src="src/android/res/drawable-xhdpi/ic_action_previous_item.png" target="res/drawable-xhdpi/ic_action_previous_item.png" /> + <resource-file src="src/android/res/drawable-xxhdpi/ic_action_previous_item.png" target="res/drawable-xxhdpi/ic_action_previous_item.png" /> + + <resource-file src="src/android/res/drawable-hdpi/ic_action_remove.png" target="res/drawable-hdpi/ic_action_remove.png" /> + <resource-file src="src/android/res/drawable-mdpi/ic_action_remove.png" target="res/drawable-mdpi/ic_action_remove.png" /> + <resource-file src="src/android/res/drawable-xhdpi/ic_action_remove.png" target="res/drawable-xhdpi/ic_action_remove.png" /> + <resource-file src="src/android/res/drawable-xxhdpi/ic_action_remove.png" target="res/drawable-xxhdpi/ic_action_remove.png" /> + + </platform> + + <!-- amazon-fireos --> + <platform name="amazon-fireos"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="InAppBrowser"> + <param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser"/> + </feature> + </config-file> + + <source-file src="src/amazon/InAppBrowser.java" target-dir="src/org/apache/cordova/inappbrowser" /> + <source-file src="src/android/InAppBrowserDialog.java" target-dir="src/org/apache/cordova/inappbrowser" /> + <source-file src="src/amazon/InAppChromeClient.java" target-dir="src/org/apache/cordova/inappbrowser" /> + + <!-- drawable src/android/resources --> + <resource-file src="src/android/res/drawable-hdpi/ic_action_next_item.png" target="res/drawable-hdpi/ic_action_next_item.png" /> + <resource-file src="src/android/res/drawable-mdpi/ic_action_next_item.png" target="res/drawable-mdpi/ic_action_next_item.png" /> + <resource-file src="src/android/res/drawable-xhdpi/ic_action_next_item.png" target="res/drawable-xhdpi/ic_action_next_item.png" /> + <resource-file src="src/android/res/drawable-xxhdpi/ic_action_next_item.png" target="res/drawable-xxhdpi/ic_action_next_item.png" /> + + <resource-file src="src/android/res/drawable-hdpi/ic_action_previous_item.png" target="res/drawable-hdpi/ic_action_previous_item.png" /> + <resource-file src="src/android/res/drawable-mdpi/ic_action_previous_item.png" target="res/drawable-mdpi/ic_action_previous_item.png" /> + <resource-file src="src/android/res/drawable-xhdpi/ic_action_previous_item.png" target="res/drawable-xhdpi/ic_action_previous_item.png" /> + <resource-file src="src/android/res/drawable-xxhdpi/ic_action_previous_item.png" target="res/drawable-xxhdpi/ic_action_previous_item.png" /> + + <resource-file src="src/android/res/drawable-hdpi/ic_action_remove.png" target="res/drawable-hdpi/ic_action_remove.png" /> + <resource-file src="src/android/res/drawable-mdpi/ic_action_remove.png" target="res/drawable-mdpi/ic_action_remove.png" /> + <resource-file src="src/android/res/drawable-xhdpi/ic_action_remove.png" target="res/drawable-xhdpi/ic_action_remove.png" /> + <resource-file src="src/android/res/drawable-xxhdpi/ic_action_remove.png" target="res/drawable-xxhdpi/ic_action_remove.png" /> + </platform> + + <!-- ubuntu --> + <platform name="ubuntu"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <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> + + <!-- ios --> + <platform name="ios"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <config-file target="config.xml" parent="/*"> + <feature name="InAppBrowser"> + <param name="ios-package" value="CDVInAppBrowser" /> + </feature> + </config-file> + + <header-file src="src/ios/CDVInAppBrowser.h" /> + <source-file src="src/ios/CDVInAppBrowser.m" /> + + <framework src="CoreGraphics.framework" /> + </platform> + + <!-- wp7 --> + <platform name="wp7"> + <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> + <Capability Name="ID_CAP_NETWORKING"/> + </config-file> + + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <config-file target="config.xml" parent="/*"> + <feature name="InAppBrowser"> + <param name="wp-package" value="InAppBrowser"/> + </feature> + </config-file> + + <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> + <Capability Name="ID_CAP_NETWORKING" /> + </config-file> + + <source-file src="src/wp/InAppBrowser.cs" /> + </platform> + + <!-- wp8 --> + <platform name="wp8"> + <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> + <Capability Name="ID_CAP_NETWORKING"/> + </config-file> + + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <config-file target="config.xml" parent="/*"> + <feature name="InAppBrowser"> + <param name="wp-package" value="InAppBrowser"/> + </feature> + </config-file> + + <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> + <Capability Name="ID_CAP_NETWORKING" /> + </config-file> + + <source-file src="src/wp/InAppBrowser.cs" /> + </platform> + + <!-- windows8 --> + <platform name="windows8"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <js-module src="www/windows8/InAppBrowserProxy.js" name="InAppBrowserProxy"> + <merges target="" /> + </js-module> + </platform> + + <!-- windows universal apps (Windows 8.1, Windows Phone 8.1, Windows 8.0) --> + <platform name="windows"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <js-module src="src/windows/InAppBrowserProxy.js" name="InAppBrowserProxy"> + <merges target="" /> + </js-module> + <asset src="www/inappbrowser.css" target="css/inappbrowser.css" /> + </platform> + + <!-- firefoxos --> + <platform name="firefoxos"> + <config-file target="config.xml" parent="/*"> + <permission name="browser" description="Enables the app to implement a browser in an iframe." privileged="true"/> + </config-file> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <js-module src="src/firefoxos/InAppBrowserProxy.js" name="InAppBrowserProxy"> + <merges target="" /> + </js-module> + </platform> + + <!-- browser --> + <platform name="browser"> + <js-module src="www/inappbrowser.js" name="inappbrowser"> + <clobbers target="cordova.InAppBrowser.open" /> + <clobbers target="window.open" /> + </js-module> + <js-module src="src/browser/InAppBrowserProxy.js" name="InAppBrowserProxy"> + <merges target="" /> + </js-module> + </platform> +</plugin> diff --git a/plugins/cordova-plugin-inappbrowser/src/amazon/InAppBrowser.java b/plugins/cordova-plugin-inappbrowser/src/amazon/InAppBrowser.java new file mode 100644 index 00000000..0263ea2c --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/amazon/InAppBrowser.java @@ -0,0 +1,846 @@ +/* + 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. +*/ +package org.apache.cordova.inappbrowser; + +import android.annotation.SuppressLint; +import org.apache.cordova.inappbrowser.InAppBrowserDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.text.InputType; +import android.util.Log; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.view.WindowManager.LayoutParams; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import com.amazon.android.webkit.AmazonWebChromeClient; +import com.amazon.android.webkit.AmazonGeolocationPermissions.Callback; +import com.amazon.android.webkit.AmazonJsPromptResult; +import com.amazon.android.webkit.AmazonWebSettings; +import com.amazon.android.webkit.AmazonWebStorage; +import com.amazon.android.webkit.AmazonWebView; +import com.amazon.android.webkit.AmazonWebViewClient; +import com.amazon.android.webkit.AmazonCookieManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.Config; +import org.apache.cordova.CordovaArgs; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.LOG; +import org.apache.cordova.PluginResult; +import org.apache.cordova.CordovaActivity; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.StringTokenizer; + +@SuppressLint("SetJavaScriptEnabled") +public class InAppBrowser extends CordovaPlugin { + + private static final String NULL = "null"; + protected static final String LOG_TAG = "InAppBrowser"; + private static final String SELF = "_self"; + private static final String SYSTEM = "_system"; + // private static final String BLANK = "_blank"; + private static final String EXIT_EVENT = "exit"; + private static final String LOCATION = "location"; + private static final String HIDDEN = "hidden"; + private static final String ZOOM = "zoom"; + private static final String LOAD_START_EVENT = "loadstart"; + private static final String LOAD_STOP_EVENT = "loadstop"; + private static final String LOAD_ERROR_EVENT = "loaderror"; + private static final String CLEAR_ALL_CACHE = "clearcache"; + private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; + + private InAppBrowserDialog dialog; + private AmazonWebView inAppWebView; + private EditText edittext; + private CallbackContext callbackContext; + private boolean showLocationBar = true; + private boolean showZoomControls = true; + private boolean openWindowHidden = false; + private boolean clearAllCache= false; + private boolean clearSessionCache=false; + + /** + * Executes the request and returns PluginResult. + * + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackId The callback id used when calling back into JavaScript. + * @return A PluginResult object with a status and message. + */ + public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { + if (action.equals("open")) { + this.callbackContext = callbackContext; + final String url = args.getString(0); + String t = args.optString(1); + if (t == null || t.equals("") || t.equals(NULL)) { + t = SELF; + } + final String target = t; + final HashMap<String, Boolean> features = parseFeature(args.optString(2)); + + Log.d(LOG_TAG, "target = " + target); + + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + String result = ""; + // SELF + if (SELF.equals(target)) { + Log.d(LOG_TAG, "in self"); + // load in webview + if (url.startsWith("file://") || url.startsWith("javascript:") + || Config.isUrlWhiteListed(url)) { + Log.d(LOG_TAG, "loading in webview"); + webView.loadUrl(url); + } + //Load the dialer + else if (url.startsWith(AmazonWebView.SCHEME_TEL)) + { + try { + Log.d(LOG_TAG, "loading in dialer"); + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse(url)); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); + } + } + // load in InAppBrowser + else { + Log.d(LOG_TAG, "loading in InAppBrowser"); + result = showWebPage(url, features); + } + } + // SYSTEM + else if (SYSTEM.equals(target)) { + Log.d(LOG_TAG, "in system"); + result = openExternal(url); + } + // BLANK - or anything else + else { + Log.d(LOG_TAG, "in blank"); + result = showWebPage(url, features); + } + + PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); + pluginResult.setKeepCallback(true); + callbackContext.sendPluginResult(pluginResult); + } + }); + } + else if (action.equals("close")) { + closeDialog(); + } + else if (action.equals("injectScriptCode")) { + String jsWrapper = null; + if (args.getBoolean(1)) { + jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("injectScriptFile")) { + String jsWrapper; + if (args.getBoolean(1)) { + jsWrapper = String.format("(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); + } else { + jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("injectStyleCode")) { + String jsWrapper; + if (args.getBoolean(1)) { + jsWrapper = String.format("(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); + } else { + jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("injectStyleFile")) { + String jsWrapper; + if (args.getBoolean(1)) { + jsWrapper = String.format("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); + } else { + jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("show")) { + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.show(); + } + }); + PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); + pluginResult.setKeepCallback(true); + this.callbackContext.sendPluginResult(pluginResult); + } + else { + return false; + } + return true; + } + + /** + * Called when the view navigates. + */ + @Override + public void onReset() { + closeDialog(); + } + + /** + * Called by AccelBroker when listener is to be shut down. + * Stop listener. + */ + public void onDestroy() { + closeDialog(); + } + + /** + * Inject an object (script or style) into the InAppBrowser AmazonWebView. + * + * This is a helper method for the inject{Script|Style}{Code|File} API calls, which + * provides a consistent method for injecting JavaScript code into the document. + * + * If a wrapper string is supplied, then the source string will be JSON-encoded (adding + * quotes) and wrapped using string formatting. (The wrapper string should have a single + * '%s' marker) + * + * @param source The source object (filename or script/style text) to inject into + * the document. + * @param jsWrapper A JavaScript string to wrap the source string in, so that the object + * is properly injected, or null if the source string is JavaScript text + * which should be executed directly. + */ + private void injectDeferredObject(String source, String jsWrapper) { + final String scriptToInject; + if (jsWrapper != null) { + org.json.JSONArray jsonEsc = new org.json.JSONArray(); + jsonEsc.put(source); + String jsonRepr = jsonEsc.toString(); + String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1); + scriptToInject = String.format(jsWrapper, jsonSourceString); + } else { + scriptToInject = source; + } + final String finalScriptToInject = scriptToInject; + this.cordova.getActivity().runOnUiThread(new Runnable() { + @SuppressLint("NewApi") + @Override + public void run() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + // This action will have the side-effect of blurring the currently focused element + inAppWebView.loadUrl("javascript:" + finalScriptToInject); + } /*else { + inAppWebView.evaluateJavascript(finalScriptToInject, null); + }*/ + } + }); + } + + /** + * Put the list of features into a hash map + * + * @param optString + * @return + */ + private HashMap<String, Boolean> parseFeature(String optString) { + if (optString.equals(NULL)) { + return null; + } else { + HashMap<String, Boolean> map = new HashMap<String, Boolean>(); + StringTokenizer features = new StringTokenizer(optString, ","); + StringTokenizer option; + while(features.hasMoreElements()) { + option = new StringTokenizer(features.nextToken(), "="); + if (option.hasMoreElements()) { + String key = option.nextToken(); + Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE; + map.put(key, value); + } + } + return map; + } + } + + /** + * Display a new browser with the specified URL. + * + * @param url The url to load. + * @param usePhoneGap Load url in PhoneGap webview + * @return "" if ok, or error message. + */ + public String openExternal(String url) { + try { + Intent intent = null; + intent = new Intent(Intent.ACTION_VIEW); + // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent". + // Adding the MIME type to http: URLs causes them to not be handled by the downloader. + Uri uri = Uri.parse(url); + if ("file".equals(uri.getScheme())) { + intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri)); + } else { + intent.setData(uri); + } + this.cordova.getActivity().startActivity(intent); + return ""; + } catch (android.content.ActivityNotFoundException e) { + Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); + return e.toString(); + } + } + + /** + * Closes the dialog + */ + public void closeDialog() { + final AmazonWebView childView = this.inAppWebView; + // The JS protects against multiple calls, so this should happen only when + // closeDialog() is called by other native code. + if (childView == null) { + return; + } + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + childView.setWebViewClient(new AmazonWebViewClient() { + // NB: wait for about:blank before dismissing + public void onPageFinished(AmazonWebView view, String url) { + if (dialog != null) { + dialog.dismiss(); + } + } + }); + // NB: From SDK 19: "If you call methods on WebView from any thread + // other than your app's UI thread, it can cause unexpected results." + // http://developer.android.com/guide/webapps/migrating.html#Threads + childView.loadUrl("about:blank"); + } + }); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", EXIT_EVENT); + sendUpdate(obj, false); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + /** + * Checks to see if it is possible to go back one page in history, then does so. + */ + private void goBack() { + this.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + if (InAppBrowser.this.inAppWebView.canGoBack()) { + InAppBrowser.this.inAppWebView.goBack(); + } + } + }); + } + + /** + * Checks to see if it is possible to go forward one page in history, then does so. + */ + private void goForward() { + this.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + if (InAppBrowser.this.inAppWebView.canGoForward()) { + InAppBrowser.this.inAppWebView.goForward(); + } + } + }); + } + + /** + * Navigate to the new page + * + * @param url to load + */ + private void navigate(final String url) { + InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0); + + this.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + if (!url.startsWith("http") && !url.startsWith("file:")) { + InAppBrowser.this.inAppWebView.loadUrl("http://" + url); + } else { + InAppBrowser.this.inAppWebView.loadUrl(url); + } + InAppBrowser.this.inAppWebView.requestFocus(); + } + }); + } + + + /** + * Should we show the location bar? + * + * @return boolean + */ + private boolean getShowLocationBar() { + return this.showLocationBar; + } + + /** + * Should we show the zoom controls? + * + * @return boolean + */ + private boolean getShowZoomControls() { + return this.showZoomControls; + } + + private InAppBrowser getInAppBrowser(){ + return this; + } + + /** + * Display a new browser with the specified URL. + * + * @param url The url to load. + * @param jsonObject + */ + public String showWebPage(final String url, HashMap<String, Boolean> features) { + // Determine if we should hide the location bar. + showLocationBar = true; + showZoomControls = true; + openWindowHidden = false; + if (features != null) { + Boolean show = features.get(LOCATION); + if (show != null) { + showLocationBar = show.booleanValue(); + } + Boolean zoom = features.get(ZOOM); + if (zoom != null) { + showZoomControls = zoom.booleanValue(); + } + Boolean hidden = features.get(HIDDEN); + if (hidden != null) { + openWindowHidden = hidden.booleanValue(); + } + Boolean cache = features.get(CLEAR_ALL_CACHE); + if (cache != null) { + clearAllCache = cache.booleanValue(); + } else { + cache = features.get(CLEAR_SESSION_CACHE); + if (cache != null) { + clearSessionCache = cache.booleanValue(); + } + } + } + + final CordovaWebView thatWebView = this.webView; + + // Create dialog in new thread + Runnable runnable = new Runnable() { + /** + * Convert our DIP units to Pixels + * + * @return int + */ + private int dpToPixels(int dipValue) { + int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, + (float) dipValue, + cordova.getActivity().getResources().getDisplayMetrics() + ); + + return value; + } + + @SuppressLint("NewApi") + public void run() { + // Let's create the main dialog + dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); + dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setCancelable(true); + dialog.setInAppBroswer(getInAppBrowser()); + + // Main container layout + LinearLayout main = new LinearLayout(cordova.getActivity()); + main.setOrientation(LinearLayout.VERTICAL); + + // Toolbar layout + RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); + //Please, no more black! + toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); + toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); + toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); + toolbar.setHorizontalGravity(Gravity.LEFT); + toolbar.setVerticalGravity(Gravity.TOP); + + // Action Button Container layout + RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); + actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + actionButtonContainer.setHorizontalGravity(Gravity.LEFT); + actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); + actionButtonContainer.setId(1); + + // Back button + Button back = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); + back.setLayoutParams(backLayoutParams); + back.setContentDescription("Back Button"); + back.setId(2); + Resources activityRes = cordova.getActivity().getResources(); + int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); + Drawable backIcon = activityRes.getDrawable(backResId); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) + { + back.setBackgroundDrawable(backIcon); + } + else + { + back.setBackground(backIcon); + } + + back.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + goBack(); + } + }); + + // Forward button + Button forward = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); + forward.setLayoutParams(forwardLayoutParams); + forward.setContentDescription("Forward Button"); + forward.setId(3); + int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); + Drawable fwdIcon = activityRes.getDrawable(fwdResId); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) + { + forward.setBackgroundDrawable(fwdIcon); + } + else + { + forward.setBackground(fwdIcon); + } + forward.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + goForward(); + } + }); + + // Edit Text Box + edittext = new EditText(cordova.getActivity()); + RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); + textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); + edittext.setLayoutParams(textLayoutParams); + edittext.setId(4); + edittext.setSingleLine(true); + edittext.setText(url); + edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); + edittext.setImeOptions(EditorInfo.IME_ACTION_GO); + edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE + edittext.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + navigate(edittext.getText().toString()); + return true; + } + return false; + } + }); + + // Close/Done button + Button close = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + close.setLayoutParams(closeLayoutParams); + forward.setContentDescription("Close Button"); + close.setId(5); + int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); + Drawable closeIcon = activityRes.getDrawable(closeResId); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) + { + close.setBackgroundDrawable(closeIcon); + } + else + { + close.setBackground(closeIcon); + } + close.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + closeDialog(); + } + }); + + // WebView + inAppWebView = new AmazonWebView(cordova.getActivity()); + + CordovaActivity app = (CordovaActivity) cordova.getActivity(); + cordova.getFactory().initializeWebView(inAppWebView, 0x00FF00, false, null); + + inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); + AmazonWebViewClient client = new InAppBrowserClient(thatWebView, edittext); + inAppWebView.setWebViewClient(client); + AmazonWebSettings settings = inAppWebView.getSettings(); + settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + settings.setBuiltInZoomControls(getShowZoomControls()); + settings.setPluginState(com.amazon.android.webkit.AmazonWebSettings.PluginState.ON); + + //Toggle whether this is enabled or not! + Bundle appSettings = cordova.getActivity().getIntent().getExtras(); + boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); + if (enableDatabase) { + String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); + settings.setDatabasePath(databasePath); + settings.setDatabaseEnabled(true); + } + settings.setDomStorageEnabled(true); + + if (clearAllCache) { + AmazonCookieManager.getInstance().removeAllCookie(); + } else if (clearSessionCache) { + AmazonCookieManager.getInstance().removeSessionCookie(); + } + + inAppWebView.loadUrl(url); + inAppWebView.setId(6); + inAppWebView.getSettings().setLoadWithOverviewMode(true); + inAppWebView.getSettings().setUseWideViewPort(true); + inAppWebView.requestFocus(); + inAppWebView.requestFocusFromTouch(); + + // Add the back and forward buttons to our action button container layout + actionButtonContainer.addView(back); + actionButtonContainer.addView(forward); + + // Add the views to our toolbar + toolbar.addView(actionButtonContainer); + toolbar.addView(edittext); + toolbar.addView(close); + + // Don't add the toolbar if its been disabled + if (getShowLocationBar()) { + // Add our toolbar to our main view/layout + main.addView(toolbar); + } + + // Add our webview to our main view/layout + main.addView(inAppWebView); + + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.MATCH_PARENT; + lp.height = WindowManager.LayoutParams.MATCH_PARENT; + + dialog.setContentView(main); + dialog.show(); + dialog.getWindow().setAttributes(lp); + // the goal of openhidden is to load the url and not display it + // Show() needs to be called to cause the URL to be loaded + if(openWindowHidden) { + dialog.hide(); + } + } + }; + this.cordova.getActivity().runOnUiThread(runnable); + return ""; + } + + /** + * Create a new plugin success result and send it back to JavaScript + * + * @param obj a JSONObject contain event payload information + */ + private void sendUpdate(JSONObject obj, boolean keepCallback) { + sendUpdate(obj, keepCallback, PluginResult.Status.OK); + } + + /** + * Create a new plugin result and send it back to JavaScript + * + * @param obj a JSONObject contain event payload information + * @param status the status code to return to the JavaScript environment + */ + private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { + if (callbackContext != null) { + PluginResult result = new PluginResult(status, obj); + result.setKeepCallback(keepCallback); + callbackContext.sendPluginResult(result); + if (!keepCallback) { + callbackContext = null; + } + } + } + + /** + * The webview client receives notifications about appView + */ + public class InAppBrowserClient extends AmazonWebViewClient { + EditText edittext; + CordovaWebView webView; + + /** + * Constructor. + * + * @param mContext + * @param edittext + */ + public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { + this.webView = webView; + this.edittext = mEditText; + } + + /** + * Notify the host application that a page has started loading. + * + * @param view The webview initiating the callback. + * @param url The url of the page. + */ + @Override + public void onPageStarted(AmazonWebView view, String url, Bitmap favicon) { + super.onPageStarted(view, url, favicon); + String newloc = ""; + if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { + newloc = url; + } + // If dialing phone (tel:5551212) + else if (url.startsWith(AmazonWebView.SCHEME_TEL)) { + try { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse(url)); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); + } + } + + else if (url.startsWith("geo:") || url.startsWith(AmazonWebView.SCHEME_MAILTO) || url.startsWith("market:")) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString()); + } + } + // If sms:5551212?body=This is the message + else if (url.startsWith("sms:")) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW); + + // Get address + String address = null; + int parmIndex = url.indexOf('?'); + if (parmIndex == -1) { + address = url.substring(4); + } + else { + address = url.substring(4, parmIndex); + + // If body, then set sms body + Uri uri = Uri.parse(url); + String query = uri.getQuery(); + if (query != null) { + if (query.startsWith("body=")) { + intent.putExtra("sms_body", query.substring(5)); + } + } + } + intent.setData(Uri.parse("sms:" + address)); + intent.putExtra("address", address); + intent.setType("vnd.android-dir/mms-sms"); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); + } + } + else { + newloc = "http://" + url; + } + + if (!newloc.equals(edittext.getText().toString())) { + edittext.setText(newloc); + } + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_START_EVENT); + obj.put("url", newloc); + + sendUpdate(obj, true); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + + public void onPageFinished(AmazonWebView view, String url) { + super.onPageFinished(view, url); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_STOP_EVENT); + obj.put("url", url); + + sendUpdate(obj, true); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + + public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) { + super.onReceivedError(view, errorCode, description, failingUrl); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_ERROR_EVENT); + obj.put("url", failingUrl); + obj.put("code", errorCode); + obj.put("message", description); + + sendUpdate(obj, true, PluginResult.Status.ERROR); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + } +} diff --git a/plugins/cordova-plugin-inappbrowser/src/amazon/InAppChromeClient.java b/plugins/cordova-plugin-inappbrowser/src/amazon/InAppChromeClient.java new file mode 100644 index 00000000..37cf101f --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/amazon/InAppChromeClient.java @@ -0,0 +1,146 @@ +/* + 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. +*/ +package org.apache.cordova.inappbrowser; + +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.LOG; +import org.apache.cordova.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; + +import com.amazon.android.webkit.AmazonWebChromeClient; +import com.amazon.android.webkit.AmazonGeolocationPermissions.Callback; +import com.amazon.android.webkit.AmazonJsPromptResult; +import com.amazon.android.webkit.AmazonWebStorage; +import com.amazon.android.webkit.AmazonWebView; +import com.amazon.android.webkit.AmazonWebViewClient; + +public class InAppChromeClient extends AmazonWebChromeClient { + + private CordovaWebView webView; + private String LOG_TAG = "InAppChromeClient"; + private long MAX_QUOTA = 100 * 1024 * 1024; + + public InAppChromeClient(CordovaWebView webView) { + super(); + this.webView = webView; + } + /** + * Handle database quota exceeded notification. + * + * @param url + * @param databaseIdentifier + * @param currentQuota + * @param estimatedSize + * @param totalUsedQuota + * @param quotaUpdater + */ + @Override + public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, + long totalUsedQuota, AmazonWebStorage.QuotaUpdater quotaUpdater) + { + LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota); + + if (estimatedSize < MAX_QUOTA) + { + //increase for 1Mb + long newQuota = estimatedSize; + LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota); + quotaUpdater.updateQuota(newQuota); + } + else + { + // Set the quota to whatever it is and force an error + // TODO: get docs on how to handle this properly + quotaUpdater.updateQuota(currentQuota); + } + } + + /** + * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin. + * + * @param origin + * @param callback + */ + @Override + public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { + super.onGeolocationPermissionsShowPrompt(origin, callback); + callback.invoke(origin, true, false); + } + + /** + * Tell the client to display a prompt dialog to the user. + * If the client returns true, WebView will assume that the client will + * handle the prompt dialog and call the appropriate JsPromptResult method. + * + * The prompt bridge provided for the InAppBrowser is capable of executing any + * oustanding callback belonging to the InAppBrowser plugin. Care has been + * taken that other callbacks cannot be triggered, and that no other code + * execution is possible. + * + * To trigger the bridge, the prompt default value should be of the form: + * + * gap-iab://<callbackId> + * + * where <callbackId> is the string id of the callback to trigger (something + * like "InAppBrowser0123456789") + * + * If present, the prompt message is expected to be a JSON-encoded value to + * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid. + * + * @param view + * @param url + * @param message + * @param defaultValue + * @param result + */ + @Override + public boolean onJsPrompt(AmazonWebView view, String url, String message, String defaultValue, AmazonJsPromptResult result) { + // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute. + if (defaultValue != null && defaultValue.startsWith("gap")) { + if(defaultValue.startsWith("gap-iab://")) { + PluginResult scriptResult; + String scriptCallbackId = defaultValue.substring(10); + if (scriptCallbackId.startsWith("InAppBrowser")) { + if(message == null || message.length() == 0) { + scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray()); + } else { + try { + scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message)); + } catch(JSONException e) { + scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); + } + } + this.webView.sendPluginResult(scriptResult, scriptCallbackId); + result.confirm(""); + return true; + } + } + else + { + // Anything else with a gap: prefix should get this message + LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue); + result.cancel(); + return true; + } + } + return false; + } + +} diff --git a/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowser.java b/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowser.java new file mode 100644 index 00000000..217e48e1 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowser.java @@ -0,0 +1,879 @@ +/* + 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. +*/ +package org.apache.cordova.inappbrowser; + +import android.annotation.SuppressLint; +import org.apache.cordova.inappbrowser.InAppBrowserDialog; +import android.content.Context; +import android.content.Intent; +import android.provider.Browser; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.text.InputType; +import android.util.Log; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.view.WindowManager.LayoutParams; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.webkit.CookieManager; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.Config; +import org.apache.cordova.CordovaArgs; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.LOG; +import org.apache.cordova.PluginManager; +import org.apache.cordova.PluginResult; +import org.json.JSONException; +import org.json.JSONObject; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.StringTokenizer; + +@SuppressLint("SetJavaScriptEnabled") +public class InAppBrowser extends CordovaPlugin { + + private static final String NULL = "null"; + protected static final String LOG_TAG = "InAppBrowser"; + private static final String SELF = "_self"; + private static final String SYSTEM = "_system"; + // private static final String BLANK = "_blank"; + private static final String EXIT_EVENT = "exit"; + private static final String LOCATION = "location"; + private static final String ZOOM = "zoom"; + private static final String HIDDEN = "hidden"; + private static final String LOAD_START_EVENT = "loadstart"; + private static final String LOAD_STOP_EVENT = "loadstop"; + private static final String LOAD_ERROR_EVENT = "loaderror"; + private static final String CLEAR_ALL_CACHE = "clearcache"; + private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; + private static final String HARDWARE_BACK_BUTTON = "hardwareback"; + + private InAppBrowserDialog dialog; + private WebView inAppWebView; + private EditText edittext; + private CallbackContext callbackContext; + private boolean showLocationBar = true; + private boolean showZoomControls = true; + private boolean openWindowHidden = false; + private boolean clearAllCache= false; + private boolean clearSessionCache=false; + private boolean hadwareBackButton=true; + + /** + * Executes the request and returns PluginResult. + * + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackId The callback id used when calling back into JavaScript. + * @return A PluginResult object with a status and message. + */ + public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { + if (action.equals("open")) { + this.callbackContext = callbackContext; + final String url = args.getString(0); + String t = args.optString(1); + if (t == null || t.equals("") || t.equals(NULL)) { + t = SELF; + } + final String target = t; + final HashMap<String, Boolean> features = parseFeature(args.optString(2)); + + Log.d(LOG_TAG, "target = " + target); + + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + String result = ""; + // SELF + if (SELF.equals(target)) { + Log.d(LOG_TAG, "in self"); + /* This code exists for compatibility between 3.x and 4.x versions of Cordova. + * Previously the Config class had a static method, isUrlWhitelisted(). That + * responsibility has been moved to the plugins, with an aggregating method in + * PluginManager. + */ + Boolean shouldAllowNavigation = null; + if (url.startsWith("javascript:")) { + shouldAllowNavigation = true; + } + if (shouldAllowNavigation == null) { + try { + Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class); + shouldAllowNavigation = (Boolean)iuw.invoke(null, url); + } catch (NoSuchMethodException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } + } + if (shouldAllowNavigation == null) { + try { + Method gpm = webView.getClass().getMethod("getPluginManager"); + PluginManager pm = (PluginManager)gpm.invoke(webView); + Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class); + shouldAllowNavigation = (Boolean)san.invoke(pm, url); + } catch (NoSuchMethodException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } + } + // load in webview + if (Boolean.TRUE.equals(shouldAllowNavigation)) { + Log.d(LOG_TAG, "loading in webview"); + webView.loadUrl(url); + } + //Load the dialer + else if (url.startsWith(WebView.SCHEME_TEL)) + { + try { + Log.d(LOG_TAG, "loading in dialer"); + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse(url)); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); + } + } + // load in InAppBrowser + else { + Log.d(LOG_TAG, "loading in InAppBrowser"); + result = showWebPage(url, features); + } + } + // SYSTEM + else if (SYSTEM.equals(target)) { + Log.d(LOG_TAG, "in system"); + result = openExternal(url); + } + // BLANK - or anything else + else { + Log.d(LOG_TAG, "in blank"); + result = showWebPage(url, features); + } + + PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); + pluginResult.setKeepCallback(true); + callbackContext.sendPluginResult(pluginResult); + } + }); + } + else if (action.equals("close")) { + closeDialog(); + } + else if (action.equals("injectScriptCode")) { + String jsWrapper = null; + if (args.getBoolean(1)) { + jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("injectScriptFile")) { + String jsWrapper; + if (args.getBoolean(1)) { + jsWrapper = String.format("(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); + } else { + jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("injectStyleCode")) { + String jsWrapper; + if (args.getBoolean(1)) { + jsWrapper = String.format("(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); + } else { + jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("injectStyleFile")) { + String jsWrapper; + if (args.getBoolean(1)) { + jsWrapper = String.format("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); + } else { + jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; + } + injectDeferredObject(args.getString(0), jsWrapper); + } + else if (action.equals("show")) { + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.show(); + } + }); + PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); + pluginResult.setKeepCallback(true); + this.callbackContext.sendPluginResult(pluginResult); + } + else { + return false; + } + return true; + } + + /** + * Called when the view navigates. + */ + @Override + public void onReset() { + closeDialog(); + } + + /** + * Called by AccelBroker when listener is to be shut down. + * Stop listener. + */ + public void onDestroy() { + closeDialog(); + } + + /** + * Inject an object (script or style) into the InAppBrowser WebView. + * + * This is a helper method for the inject{Script|Style}{Code|File} API calls, which + * provides a consistent method for injecting JavaScript code into the document. + * + * If a wrapper string is supplied, then the source string will be JSON-encoded (adding + * quotes) and wrapped using string formatting. (The wrapper string should have a single + * '%s' marker) + * + * @param source The source object (filename or script/style text) to inject into + * the document. + * @param jsWrapper A JavaScript string to wrap the source string in, so that the object + * is properly injected, or null if the source string is JavaScript text + * which should be executed directly. + */ + private void injectDeferredObject(String source, String jsWrapper) { + String scriptToInject; + if (jsWrapper != null) { + org.json.JSONArray jsonEsc = new org.json.JSONArray(); + jsonEsc.put(source); + String jsonRepr = jsonEsc.toString(); + String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1); + scriptToInject = String.format(jsWrapper, jsonSourceString); + } else { + scriptToInject = source; + } + final String finalScriptToInject = scriptToInject; + this.cordova.getActivity().runOnUiThread(new Runnable() { + @SuppressLint("NewApi") + @Override + public void run() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + // This action will have the side-effect of blurring the currently focused element + inAppWebView.loadUrl("javascript:" + finalScriptToInject); + } else { + inAppWebView.evaluateJavascript(finalScriptToInject, null); + } + } + }); + } + + /** + * Put the list of features into a hash map + * + * @param optString + * @return + */ + private HashMap<String, Boolean> parseFeature(String optString) { + if (optString.equals(NULL)) { + return null; + } else { + HashMap<String, Boolean> map = new HashMap<String, Boolean>(); + StringTokenizer features = new StringTokenizer(optString, ","); + StringTokenizer option; + while(features.hasMoreElements()) { + option = new StringTokenizer(features.nextToken(), "="); + if (option.hasMoreElements()) { + String key = option.nextToken(); + Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE; + map.put(key, value); + } + } + return map; + } + } + + /** + * Display a new browser with the specified URL. + * + * @param url The url to load. + * @param usePhoneGap Load url in PhoneGap webview + * @return "" if ok, or error message. + */ + public String openExternal(String url) { + try { + Intent intent = null; + intent = new Intent(Intent.ACTION_VIEW); + // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent". + // Adding the MIME type to http: URLs causes them to not be handled by the downloader. + Uri uri = Uri.parse(url); + if ("file".equals(uri.getScheme())) { + intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri)); + } else { + intent.setData(uri); + } + intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName()); + this.cordova.getActivity().startActivity(intent); + return ""; + } catch (android.content.ActivityNotFoundException e) { + Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); + return e.toString(); + } + } + + /** + * Closes the dialog + */ + public void closeDialog() { + final WebView childView = this.inAppWebView; + // The JS protects against multiple calls, so this should happen only when + // closeDialog() is called by other native code. + if (childView == null) { + return; + } + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + childView.setWebViewClient(new WebViewClient() { + // NB: wait for about:blank before dismissing + public void onPageFinished(WebView view, String url) { + if (dialog != null) { + dialog.dismiss(); + } + } + }); + // NB: From SDK 19: "If you call methods on WebView from any thread + // other than your app's UI thread, it can cause unexpected results." + // http://developer.android.com/guide/webapps/migrating.html#Threads + childView.loadUrl("about:blank"); + } + }); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", EXIT_EVENT); + sendUpdate(obj, false); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + + /** + * Checks to see if it is possible to go back one page in history, then does so. + */ + public void goBack() { + if (this.inAppWebView.canGoBack()) { + this.inAppWebView.goBack(); + } + } + + /** + * Can the web browser go back? + * @return boolean + */ + public boolean canGoBack() { + return this.inAppWebView.canGoBack(); + } + + /** + * Has the user set the hardware back button to go back + * @return boolean + */ + public boolean hardwareBack() { + return hadwareBackButton; + } + + /** + * Checks to see if it is possible to go forward one page in history, then does so. + */ + private void goForward() { + if (this.inAppWebView.canGoForward()) { + this.inAppWebView.goForward(); + } + } + + /** + * Navigate to the new page + * + * @param url to load + */ + private void navigate(String url) { + InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0); + + if (!url.startsWith("http") && !url.startsWith("file:")) { + this.inAppWebView.loadUrl("http://" + url); + } else { + this.inAppWebView.loadUrl(url); + } + this.inAppWebView.requestFocus(); + } + + + /** + * Should we show the location bar? + * + * @return boolean + */ + private boolean getShowLocationBar() { + return this.showLocationBar; + } + + /** + * Should we show the zoom controls? + * + * @return boolean + */ + private boolean getShowZoomControls() { + return this.showZoomControls; + } + + private InAppBrowser getInAppBrowser(){ + return this; + } + + /** + * Display a new browser with the specified URL. + * + * @param url The url to load. + * @param jsonObject + */ + public String showWebPage(final String url, HashMap<String, Boolean> features) { + // Determine if we should hide the location bar. + showLocationBar = true; + showZoomControls = true; + openWindowHidden = false; + if (features != null) { + Boolean show = features.get(LOCATION); + if (show != null) { + showLocationBar = show.booleanValue(); + } + Boolean zoom = features.get(ZOOM); + if (zoom != null) { + showZoomControls = zoom.booleanValue(); + } + Boolean hidden = features.get(HIDDEN); + if (hidden != null) { + openWindowHidden = hidden.booleanValue(); + } + Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); + if (hardwareBack != null) { + hadwareBackButton = hardwareBack.booleanValue(); + } + Boolean cache = features.get(CLEAR_ALL_CACHE); + if (cache != null) { + clearAllCache = cache.booleanValue(); + } else { + cache = features.get(CLEAR_SESSION_CACHE); + if (cache != null) { + clearSessionCache = cache.booleanValue(); + } + } + } + + final CordovaWebView thatWebView = this.webView; + + // Create dialog in new thread + Runnable runnable = new Runnable() { + /** + * Convert our DIP units to Pixels + * + * @return int + */ + private int dpToPixels(int dipValue) { + int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, + (float) dipValue, + cordova.getActivity().getResources().getDisplayMetrics() + ); + + return value; + } + + @SuppressLint("NewApi") + public void run() { + // Let's create the main dialog + dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); + dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setCancelable(true); + dialog.setInAppBroswer(getInAppBrowser()); + + // Main container layout + LinearLayout main = new LinearLayout(cordova.getActivity()); + main.setOrientation(LinearLayout.VERTICAL); + + // Toolbar layout + RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); + //Please, no more black! + toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); + toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); + toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); + toolbar.setHorizontalGravity(Gravity.LEFT); + toolbar.setVerticalGravity(Gravity.TOP); + + // Action Button Container layout + RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); + actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + actionButtonContainer.setHorizontalGravity(Gravity.LEFT); + actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); + actionButtonContainer.setId(1); + + // Back button + Button back = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); + back.setLayoutParams(backLayoutParams); + back.setContentDescription("Back Button"); + back.setId(2); + Resources activityRes = cordova.getActivity().getResources(); + int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); + Drawable backIcon = activityRes.getDrawable(backResId); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) + { + back.setBackgroundDrawable(backIcon); + } + else + { + back.setBackground(backIcon); + } + back.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + goBack(); + } + }); + + // Forward button + Button forward = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); + forward.setLayoutParams(forwardLayoutParams); + forward.setContentDescription("Forward Button"); + forward.setId(3); + int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); + Drawable fwdIcon = activityRes.getDrawable(fwdResId); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) + { + forward.setBackgroundDrawable(fwdIcon); + } + else + { + forward.setBackground(fwdIcon); + } + forward.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + goForward(); + } + }); + + // Edit Text Box + edittext = new EditText(cordova.getActivity()); + RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); + textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); + edittext.setLayoutParams(textLayoutParams); + edittext.setId(4); + edittext.setSingleLine(true); + edittext.setText(url); + edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); + edittext.setImeOptions(EditorInfo.IME_ACTION_GO); + edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE + edittext.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + navigate(edittext.getText().toString()); + return true; + } + return false; + } + }); + + // Close/Done button + Button close = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + close.setLayoutParams(closeLayoutParams); + forward.setContentDescription("Close Button"); + close.setId(5); + int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); + Drawable closeIcon = activityRes.getDrawable(closeResId); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) + { + close.setBackgroundDrawable(closeIcon); + } + else + { + close.setBackground(closeIcon); + } + close.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + closeDialog(); + } + }); + + // WebView + inAppWebView = new WebView(cordova.getActivity()); + inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); + WebViewClient client = new InAppBrowserClient(thatWebView, edittext); + inAppWebView.setWebViewClient(client); + WebSettings settings = inAppWebView.getSettings(); + settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + settings.setBuiltInZoomControls(getShowZoomControls()); + settings.setPluginState(android.webkit.WebSettings.PluginState.ON); + + //Toggle whether this is enabled or not! + Bundle appSettings = cordova.getActivity().getIntent().getExtras(); + boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); + if (enableDatabase) { + String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); + settings.setDatabasePath(databasePath); + settings.setDatabaseEnabled(true); + } + settings.setDomStorageEnabled(true); + + if (clearAllCache) { + CookieManager.getInstance().removeAllCookie(); + } else if (clearSessionCache) { + CookieManager.getInstance().removeSessionCookie(); + } + + inAppWebView.loadUrl(url); + inAppWebView.setId(6); + inAppWebView.getSettings().setLoadWithOverviewMode(true); + inAppWebView.getSettings().setUseWideViewPort(true); + inAppWebView.requestFocus(); + inAppWebView.requestFocusFromTouch(); + + // Add the back and forward buttons to our action button container layout + actionButtonContainer.addView(back); + actionButtonContainer.addView(forward); + + // Add the views to our toolbar + toolbar.addView(actionButtonContainer); + toolbar.addView(edittext); + toolbar.addView(close); + + // Don't add the toolbar if its been disabled + if (getShowLocationBar()) { + // Add our toolbar to our main view/layout + main.addView(toolbar); + } + + // Add our webview to our main view/layout + main.addView(inAppWebView); + + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.MATCH_PARENT; + lp.height = WindowManager.LayoutParams.MATCH_PARENT; + + dialog.setContentView(main); + dialog.show(); + dialog.getWindow().setAttributes(lp); + // the goal of openhidden is to load the url and not display it + // Show() needs to be called to cause the URL to be loaded + if(openWindowHidden) { + dialog.hide(); + } + } + }; + this.cordova.getActivity().runOnUiThread(runnable); + return ""; + } + + /** + * Create a new plugin success result and send it back to JavaScript + * + * @param obj a JSONObject contain event payload information + */ + private void sendUpdate(JSONObject obj, boolean keepCallback) { + sendUpdate(obj, keepCallback, PluginResult.Status.OK); + } + + /** + * Create a new plugin result and send it back to JavaScript + * + * @param obj a JSONObject contain event payload information + * @param status the status code to return to the JavaScript environment + */ + private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { + if (callbackContext != null) { + PluginResult result = new PluginResult(status, obj); + result.setKeepCallback(keepCallback); + callbackContext.sendPluginResult(result); + if (!keepCallback) { + callbackContext = null; + } + } + } + + /** + * The webview client receives notifications about appView + */ + public class InAppBrowserClient extends WebViewClient { + EditText edittext; + CordovaWebView webView; + + /** + * Constructor. + * + * @param mContext + * @param edittext + */ + public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { + this.webView = webView; + this.edittext = mEditText; + } + + /** + * Notify the host application that a page has started loading. + * + * @param view The webview initiating the callback. + * @param url The url of the page. + */ + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + super.onPageStarted(view, url, favicon); + String newloc = ""; + if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { + newloc = url; + } + // If dialing phone (tel:5551212) + else if (url.startsWith(WebView.SCHEME_TEL)) { + try { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse(url)); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); + } + } + + else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:")) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString()); + } + } + // If sms:5551212?body=This is the message + else if (url.startsWith("sms:")) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW); + + // Get address + String address = null; + int parmIndex = url.indexOf('?'); + if (parmIndex == -1) { + address = url.substring(4); + } + else { + address = url.substring(4, parmIndex); + + // If body, then set sms body + Uri uri = Uri.parse(url); + String query = uri.getQuery(); + if (query != null) { + if (query.startsWith("body=")) { + intent.putExtra("sms_body", query.substring(5)); + } + } + } + intent.setData(Uri.parse("sms:" + address)); + intent.putExtra("address", address); + intent.setType("vnd.android-dir/mms-sms"); + cordova.getActivity().startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); + } + } + else { + newloc = "http://" + url; + } + + if (!newloc.equals(edittext.getText().toString())) { + edittext.setText(newloc); + } + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_START_EVENT); + obj.put("url", newloc); + + sendUpdate(obj, true); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_STOP_EVENT); + obj.put("url", url); + + sendUpdate(obj, true); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + super.onReceivedError(view, errorCode, description, failingUrl); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_ERROR_EVENT); + obj.put("url", failingUrl); + obj.put("code", errorCode); + obj.put("message", description); + + sendUpdate(obj, true, PluginResult.Status.ERROR); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + } + } +} diff --git a/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowserDialog.java b/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowserDialog.java new file mode 100644 index 00000000..d7017202 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowserDialog.java @@ -0,0 +1,58 @@ +/* + 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. +*/ +package org.apache.cordova.inappbrowser; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.util.Log; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by Oliver on 22/11/2013. + */ +public class InAppBrowserDialog extends Dialog { + Context context; + InAppBrowser inAppBrowser = null; + + public InAppBrowserDialog(Context context, int theme) { + super(context, theme); + this.context = context; + } + + public void setInAppBroswer(InAppBrowser browser) { + this.inAppBrowser = browser; + } + + public void onBackPressed () { + if (this.inAppBrowser == null) { + this.dismiss(); + } else { + // better to go through the in inAppBrowser + // because it does a clean up + if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) { + this.inAppBrowser.goBack(); + } else { + this.inAppBrowser.closeDialog(); + } + } + } +} diff --git a/plugins/cordova-plugin-inappbrowser/src/android/InAppChromeClient.java b/plugins/cordova-plugin-inappbrowser/src/android/InAppChromeClient.java new file mode 100644 index 00000000..a2145e6a --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/InAppChromeClient.java @@ -0,0 +1,133 @@ +/* + 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. +*/ +package org.apache.cordova.inappbrowser; + +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.LOG; +import org.apache.cordova.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; + +import android.webkit.JsPromptResult; +import android.webkit.WebChromeClient; +import android.webkit.WebStorage; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.webkit.GeolocationPermissions.Callback; + +public class InAppChromeClient extends WebChromeClient { + + private CordovaWebView webView; + private String LOG_TAG = "InAppChromeClient"; + private long MAX_QUOTA = 100 * 1024 * 1024; + + public InAppChromeClient(CordovaWebView webView) { + super(); + this.webView = webView; + } + /** + * Handle database quota exceeded notification. + * + * @param url + * @param databaseIdentifier + * @param currentQuota + * @param estimatedSize + * @param totalUsedQuota + * @param quotaUpdater + */ + @Override + public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, + long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) + { + LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota); + quotaUpdater.updateQuota(MAX_QUOTA); + } + + /** + * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin. + * + * @param origin + * @param callback + */ + @Override + public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { + super.onGeolocationPermissionsShowPrompt(origin, callback); + callback.invoke(origin, true, false); + } + + /** + * Tell the client to display a prompt dialog to the user. + * If the client returns true, WebView will assume that the client will + * handle the prompt dialog and call the appropriate JsPromptResult method. + * + * The prompt bridge provided for the InAppBrowser is capable of executing any + * oustanding callback belonging to the InAppBrowser plugin. Care has been + * taken that other callbacks cannot be triggered, and that no other code + * execution is possible. + * + * To trigger the bridge, the prompt default value should be of the form: + * + * gap-iab://<callbackId> + * + * where <callbackId> is the string id of the callback to trigger (something + * like "InAppBrowser0123456789") + * + * If present, the prompt message is expected to be a JSON-encoded value to + * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid. + * + * @param view + * @param url + * @param message + * @param defaultValue + * @param result + */ + @Override + public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { + // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute. + if (defaultValue != null && defaultValue.startsWith("gap")) { + if(defaultValue.startsWith("gap-iab://")) { + PluginResult scriptResult; + String scriptCallbackId = defaultValue.substring(10); + if (scriptCallbackId.startsWith("InAppBrowser")) { + if(message == null || message.length() == 0) { + scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray()); + } else { + try { + scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message)); + } catch(JSONException e) { + scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); + } + } + this.webView.sendPluginResult(scriptResult, scriptCallbackId); + result.confirm(""); + return true; + } + } + else + { + // Anything else with a gap: prefix should get this message + LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue); + result.cancel(); + return true; + } + } + return false; + } + +} diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_next_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_next_item.png Binary files differnew file mode 100644 index 00000000..fa469d88 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_next_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_previous_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_previous_item.png Binary files differnew file mode 100644 index 00000000..e861ecce --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_previous_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_remove.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_remove.png Binary files differnew file mode 100644 index 00000000..f889617e --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-hdpi/ic_action_remove.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_next_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_next_item.png Binary files differnew file mode 100644 index 00000000..47365a30 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_next_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_previous_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_previous_item.png Binary files differnew file mode 100644 index 00000000..4ad2df42 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_previous_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_remove.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_remove.png Binary files differnew file mode 100644 index 00000000..e84853e4 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-mdpi/ic_action_remove.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_next_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_next_item.png Binary files differnew file mode 100644 index 00000000..5f304742 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_next_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_previous_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_previous_item.png Binary files differnew file mode 100644 index 00000000..ed8ac91d --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_previous_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_remove.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_remove.png Binary files differnew file mode 100644 index 00000000..4cd0458b --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xhdpi/ic_action_remove.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_next_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_next_item.png Binary files differnew file mode 100644 index 00000000..51479d8d --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_next_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_previous_item.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_previous_item.png Binary files differnew file mode 100644 index 00000000..bc8ff124 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_previous_item.png diff --git a/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_remove.png b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_remove.png Binary files differnew file mode 100644 index 00000000..331c545b --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/android/res/drawable-xxhdpi/ic_action_remove.png diff --git a/plugins/cordova-plugin-inappbrowser/src/blackberry10/README.md b/plugins/cordova-plugin-inappbrowser/src/blackberry10/README.md new file mode 100644 index 00000000..f0fa8607 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/blackberry10/README.md @@ -0,0 +1,43 @@ +<!--- + license: 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. +--> +# BlackBerry 10 In-App-Browser Plugin + +The in app browser functionality is entirely contained within common js. There is no native implementation required. +To install this plugin, follow the [Command-line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface). + +If you are not using the Cordova Command-line Interface, follow [Using Plugman to Manage Plugins](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html). +./cordova-plugin-battery-status/README.md +./cordova-plugin-camera/README.md +./cordova-plugin-console/README.md +./cordova-plugin-contacts/README.md +./cordova-plugin-device/README.md +./cordova-plugin-device-motion/README.md +./cordova-plugin-device-orientation/README.md +./cordova-plugin-device-orientation/src/blackberry10/README.md +./cordova-plugin-file/README.md +./cordova-plugin-file-transfer/README.md +./cordova-plugin-geolocation/README.md +./cordova-plugin-globalization/README.md +./cordova-plugin-inappbrowser/README.md +./cordova-plugin-inappbrowser/src/blackberry10/README.md +./cordova-plugin-media/README.md +./cordova-plugin-media-capture/README.md +./cordova-plugin-network-information/README.md +./cordova-plugin-splashscreen/README.md +./cordova-plugin-vibration/README.md diff --git a/plugins/cordova-plugin-inappbrowser/src/browser/InAppBrowserProxy.js b/plugins/cordova-plugin-inappbrowser/src/browser/InAppBrowserProxy.js new file mode 100644 index 00000000..33fbe476 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/browser/InAppBrowserProxy.js @@ -0,0 +1,221 @@ +/* + * + * 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'), + channel = require('cordova/channel'), + urlutil = require('cordova/urlutil'); + +var browserWrap, + popup, + navigationButtonsDiv, + navigationButtonsDivInner, + backButton, + forwardButton, + closeButton; + +function attachNavigationEvents(element, callback) { + var onError = function () { + callback({ type: "loaderror", url: this.contentWindow.location}, {keepCallback: true}); + }; + + element.addEventListener("pageshow", function () { + callback({ type: "loadstart", url: this.contentWindow.location}, {keepCallback: true}); + }); + + element.addEventListener("load", function () { + callback({ type: "loadstop", url: this.contentWindow.location}, {keepCallback: true}); + }); + + element.addEventListener("error", onError); + element.addEventListener("abort", onError); +} + +var IAB = { + close: function (win, lose) { + if (browserWrap) { + if (win) win({ type: "exit" }); + + browserWrap.parentNode.removeChild(browserWrap); + browserWrap = null; + popup = null; + } + }, + + show: function (win, lose) { + if (browserWrap) { + browserWrap.style.display = "block"; + } + }, + + open: function (win, lose, args) { + var strUrl = args[0], + target = args[1], + features = args[2], + url; + + if (target === "_system" || target === "_self" || !target) { + window.location = strUrl; + } else { + // "_blank" or anything else + if (!browserWrap) { + browserWrap = document.createElement("div"); + browserWrap.style.position = "absolute"; + browserWrap.style.borderWidth = "40px"; + browserWrap.style.width = "calc(100% - 80px)"; + browserWrap.style.height = "calc(100% - 80px)"; + browserWrap.style.borderStyle = "solid"; + browserWrap.style.borderColor = "rgba(0,0,0,0.25)"; + + browserWrap.onclick = function () { + setTimeout(function () { + IAB.close(win); + }, 0); + }; + + document.body.appendChild(browserWrap); + } + + if (features.indexOf("hidden=yes") !== -1) { + browserWrap.style.display = "none"; + } + + popup = document.createElement("iframe"); + popup.style.borderWidth = "0px"; + popup.style.width = "100%"; + + browserWrap.appendChild(popup); + + if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) { + popup.style.height = "calc(100% - 60px)"; + + navigationButtonsDiv = document.createElement("div"); + navigationButtonsDiv.style.height = "60px"; + navigationButtonsDiv.style.backgroundColor = "#404040"; + navigationButtonsDiv.style.zIndex = "999"; + navigationButtonsDiv.onclick = function (e) { + e.cancelBubble = true; + }; + + navigationButtonsDivInner = document.createElement("div"); + navigationButtonsDivInner.style.paddingTop = "10px"; + navigationButtonsDivInner.style.height = "50px"; + navigationButtonsDivInner.style.width = "160px"; + navigationButtonsDivInner.style.margin = "0 auto"; + navigationButtonsDivInner.style.backgroundColor = "#404040"; + navigationButtonsDivInner.style.zIndex = "999"; + navigationButtonsDivInner.onclick = function (e) { + e.cancelBubble = true; + }; + + + backButton = document.createElement("button"); + backButton.style.width = "40px"; + backButton.style.height = "40px"; + backButton.style.borderRadius = "40px"; + + backButton.innerHTML = "â†"; + backButton.addEventListener("click", function (e) { + if (popup.canGoBack) + popup.goBack(); + }); + + forwardButton = document.createElement("button"); + forwardButton.style.marginLeft = "20px"; + forwardButton.style.width = "40px"; + forwardButton.style.height = "40px"; + forwardButton.style.borderRadius = "40px"; + + forwardButton.innerHTML = "→"; + forwardButton.addEventListener("click", function (e) { + if (popup.canGoForward) + popup.goForward(); + }); + + closeButton = document.createElement("button"); + closeButton.style.marginLeft = "20px"; + closeButton.style.width = "40px"; + closeButton.style.height = "40px"; + closeButton.style.borderRadius = "40px"; + + closeButton.innerHTML = "✖"; + closeButton.addEventListener("click", function (e) { + setTimeout(function () { + IAB.close(win); + }, 0); + }); + + // iframe navigation is not yet supported + backButton.disabled = true; + forwardButton.disabled = true; + + navigationButtonsDivInner.appendChild(backButton); + navigationButtonsDivInner.appendChild(forwardButton); + navigationButtonsDivInner.appendChild(closeButton); + navigationButtonsDiv.appendChild(navigationButtonsDivInner); + + browserWrap.appendChild(navigationButtonsDiv); + } else { + popup.style.height = "100%"; + } + + // start listening for navigation events + attachNavigationEvents(popup, win); + + popup.src = strUrl; + } + }, + + injectScriptCode: function (win, fail, args) { + var code = args[0], + hasCallback = args[1]; + + if (browserWrap && popup) { + try { + popup.contentWindow.eval(code); + hasCallback && win([]); + } catch(e) { + console.error('Error occured while trying to injectScriptCode: ' + JSON.stringify(e)); + } + } + }, + + injectScriptFile: function (win, fail, args) { + var msg = 'Browser cordova-plugin-inappbrowser injectScriptFile is not yet implemented'; + console.warn(msg); + fail && fail(msg); + }, + + injectStyleCode: function (win, fail, args) { + var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented'; + console.warn(msg); + fail && fail(msg); + }, + + injectStyleFile: function (win, fail, args) { + var msg = 'Browser cordova-plugin-inappbrowser injectStyleFile is not yet implemented'; + console.warn(msg); + fail && fail(msg); + } +}; + +module.exports = IAB; + +require("cordova/exec/proxy").add("InAppBrowser", module.exports); diff --git a/plugins/cordova-plugin-inappbrowser/src/firefoxos/InAppBrowserProxy.js b/plugins/cordova-plugin-inappbrowser/src/firefoxos/InAppBrowserProxy.js new file mode 100644 index 00000000..f0d44c12 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/firefoxos/InAppBrowserProxy.js @@ -0,0 +1,191 @@ +/* + * + * 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. + * +*/ + +// https://developer.mozilla.org/en-US/docs/WebAPI/Browser + +var cordova = require('cordova'), + channel = require('cordova/channel'), + modulemapper = require('cordova/modulemapper'); + +var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open'); +var browserWrap; + +var IABExecs = { + + close: function (win, lose) { + if (browserWrap) { + browserWrap.parentNode.removeChild(browserWrap); + browserWrap = null; + if (typeof(win) == "function") win({type:'exit'}); + } + }, + + /* + * Reveal browser if opened hidden + */ + show: function (win, lose) { + console.error('[FirefoxOS] show not implemented'); + }, + + open: function (win, lose, args) { + var strUrl = args[0], + target = args[1], + features_string = args[2] || "location=yes", //location=yes is default + features = {}, + url, + elem; + + var features_list = features_string.split(','); + features_list.forEach(function(feature) { + var tup = feature.split('='); + if (tup[1] == 'yes') { + tup[1] = true; + } else if (tup[1] == 'no') { + tup[1] = false; + } else { + var number = parseInt(tup[1]); + if (!isNaN(number)) { + tup[1] = number; + } + } + features[tup[0]] = tup[1]; + }); + + function updateIframeSizeNoLocation() { + browserWrap.style.width = window.innerWidth + 'px'; + browserWrap.style.height = window.innerHeight + 'px'; + browserWrap.style.zIndex = '999999999'; + browserWrap.browser.style.height = (window.innerHeight - 60) + 'px'; + browserWrap.browser.style.width = browserWrap.style.width; + } + + if (target === '_system') { + origOpenFunc.apply(window, [strUrl, '_blank']); + } else if (target === '_blank') { + var browserElem = document.createElement('iframe'); + browserElem.setAttribute('mozbrowser', true); + // make this loaded in its own child process + browserElem.setAttribute('remote', true); + browserElem.setAttribute('src', strUrl); + if (browserWrap) { + document.body.removeChild(browserWrap); + } + browserWrap = document.createElement('div'); + // assign browser element to browserWrap for future reference + browserWrap.browser = browserElem; + + browserWrap.classList.add('inAppBrowserWrap'); + // position fixed so that it works even when page is scrolled + browserWrap.style.position = 'fixed'; + browserElem.style.position = 'absolute'; + browserElem.style.border = 0; + browserElem.style.top = '60px'; + browserElem.style.left = '0px'; + updateIframeSizeNoLocation(); + + var menu = document.createElement('menu'); + menu.setAttribute('type', 'toolbar'); + var close = document.createElement('li'); + var back = document.createElement('li'); + var forward = document.createElement('li'); + + close.appendChild(document.createTextNode('×')); + back.appendChild(document.createTextNode('<')); + forward.appendChild(document.createTextNode('>')); + + close.classList.add('inAppBrowserClose'); + back.classList.add('inAppBrowserBack'); + forward.classList.add('inAppBrowserForward'); + + function checkForwardBackward() { + var backReq = browserElem.getCanGoBack(); + backReq.onsuccess = function() { + if (this.result) { + back.classList.remove('disabled'); + } else { + back.classList.add('disabled'); + } + } + var forwardReq = browserElem.getCanGoForward(); + forwardReq.onsuccess = function() { + if (this.result) { + forward.classList.remove('disabled'); + } else { + forward.classList.add('disabled'); + } + } + }; + + browserElem.addEventListener('mozbrowserloadend', checkForwardBackward); + + close.addEventListener('click', function () { + setTimeout(function () { + IABExecs.close(win, lose); + }, 0); + }, false); + + back.addEventListener('click', function () { + browserElem.goBack(); + }, false); + + forward.addEventListener('click', function () { + browserElem.goForward(); + }, false); + + menu.appendChild(back); + menu.appendChild(forward); + menu.appendChild(close); + + browserWrap.appendChild(menu); + browserWrap.appendChild(browserElem); + document.body.appendChild(browserWrap); + + //we use mozbrowserlocationchange instead of mozbrowserloadstart to get the url + browserElem.addEventListener('mozbrowserlocationchange', function(e){ + win({ + type:'loadstart', + url : e.detail + }) + }, false); + browserElem.addEventListener('mozbrowserloadend', function(e){ + win({type:'loadstop'}) + }, false); + browserElem.addEventListener('mozbrowsererror', function(e){ + win({type:'loaderror'}) + }, false); + browserElem.addEventListener('mozbrowserclose', function(e){ + win({type:'exit'}) + }, false); + } else { + window.location = strUrl; + } + }, + injectScriptCode: function (code, bCB) { + console.error('[FirefoxOS] injectScriptCode not implemented'); + }, + injectScriptFile: function (file, bCB) { + console.error('[FirefoxOS] injectScriptFile not implemented'); + } +}; + +module.exports = IABExecs; + +require('cordova/exec/proxy').add('InAppBrowser', module.exports); diff --git a/plugins/cordova-plugin-inappbrowser/src/ios/CDVInAppBrowser.h b/plugins/cordova-plugin-inappbrowser/src/ios/CDVInAppBrowser.h new file mode 100644 index 00000000..1ccc7b14 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ios/CDVInAppBrowser.h @@ -0,0 +1,113 @@ +/* + 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. + */ + +#import <Cordova/CDVPlugin.h> +#import <Cordova/CDVInvokedUrlCommand.h> +#import <Cordova/CDVScreenOrientationDelegate.h> + +#ifdef __CORDOVA_4_0_0 + #import <Cordova/CDVUIWebViewDelegate.h> +#else + #import <Cordova/CDVWebViewDelegate.h> +#endif + +@class CDVInAppBrowserViewController; + +@interface CDVInAppBrowser : CDVPlugin { + BOOL _injectedIframeBridge; +} + +@property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController; +@property (nonatomic, copy) NSString* callbackId; +@property (nonatomic, copy) NSRegularExpression *callbackIdPattern; + +- (void)open:(CDVInvokedUrlCommand*)command; +- (void)close:(CDVInvokedUrlCommand*)command; +- (void)injectScriptCode:(CDVInvokedUrlCommand*)command; +- (void)show:(CDVInvokedUrlCommand*)command; + +@end + +@interface CDVInAppBrowserOptions : NSObject {} + +@property (nonatomic, assign) BOOL location; +@property (nonatomic, assign) BOOL toolbar; +@property (nonatomic, copy) NSString* closebuttoncaption; +@property (nonatomic, copy) NSString* toolbarposition; +@property (nonatomic, assign) BOOL clearcache; +@property (nonatomic, assign) BOOL clearsessioncache; + +@property (nonatomic, copy) NSString* presentationstyle; +@property (nonatomic, copy) NSString* transitionstyle; + +@property (nonatomic, assign) BOOL enableviewportscale; +@property (nonatomic, assign) BOOL mediaplaybackrequiresuseraction; +@property (nonatomic, assign) BOOL allowinlinemediaplayback; +@property (nonatomic, assign) BOOL keyboarddisplayrequiresuseraction; +@property (nonatomic, assign) BOOL suppressesincrementalrendering; +@property (nonatomic, assign) BOOL hidden; +@property (nonatomic, assign) BOOL disallowoverscroll; + ++ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options; + +@end + +@interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate, CDVScreenOrientationDelegate>{ + @private + NSString* _userAgent; + NSString* _prevUserAgent; + NSInteger _userAgentLockToken; + CDVInAppBrowserOptions *_browserOptions; + +#ifdef __CORDOVA_4_0_0 + CDVUIWebViewDelegate* _webViewDelegate; +#else + CDVWebViewDelegate* _webViewDelegate; +#endif + +} + +@property (nonatomic, strong) IBOutlet UIWebView* webView; +@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton; +@property (nonatomic, strong) IBOutlet UILabel* addressLabel; +@property (nonatomic, strong) IBOutlet UIBarButtonItem* backButton; +@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton; +@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner; +@property (nonatomic, strong) IBOutlet UIToolbar* toolbar; + +@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate; +@property (nonatomic, weak) CDVInAppBrowser* navigationDelegate; +@property (nonatomic) NSURL* currentURL; + +- (void)close; +- (void)navigateTo:(NSURL*)url; +- (void)showLocationBar:(BOOL)show; +- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; +- (void)setCloseButtonTitle:(NSString*)title; + +- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions; + +@end + +@interface CDVInAppBrowserNavigationController : UINavigationController + +@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate; + +@end + diff --git a/plugins/cordova-plugin-inappbrowser/src/ios/CDVInAppBrowser.m b/plugins/cordova-plugin-inappbrowser/src/ios/CDVInAppBrowser.m new file mode 100644 index 00000000..24f56c49 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ios/CDVInAppBrowser.m @@ -0,0 +1,1022 @@ +/* + 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. + */ + +#import "CDVInAppBrowser.h" +#import <Cordova/CDVPluginResult.h> +#import <Cordova/CDVUserAgentUtil.h> + +#define kInAppBrowserTargetSelf @"_self" +#define kInAppBrowserTargetSystem @"_system" +#define kInAppBrowserTargetBlank @"_blank" + +#define kInAppBrowserToolbarBarPositionBottom @"bottom" +#define kInAppBrowserToolbarBarPositionTop @"top" + +#define TOOLBAR_HEIGHT 44.0 +#define LOCATIONBAR_HEIGHT 21.0 +#define FOOTER_HEIGHT ((TOOLBAR_HEIGHT) + (LOCATIONBAR_HEIGHT)) + +#pragma mark CDVInAppBrowser + +@interface CDVInAppBrowser () { + NSInteger _previousStatusBarStyle; +} +@end + +@implementation CDVInAppBrowser + +- (void)pluginInitialize +{ + _previousStatusBarStyle = -1; + _callbackIdPattern = nil; +} + +- (void)onReset +{ + [self close:nil]; +} + +- (void)close:(CDVInvokedUrlCommand*)command +{ + if (self.inAppBrowserViewController == nil) { + NSLog(@"IAB.close() called but it was already closed."); + return; + } + // Things are cleaned up in browserExit. + [self.inAppBrowserViewController close]; +} + +- (BOOL) isSystemUrl:(NSURL*)url +{ + if ([[url host] isEqualToString:@"itunes.apple.com"]) { + return YES; + } + + return NO; +} + +- (void)open:(CDVInvokedUrlCommand*)command +{ + CDVPluginResult* pluginResult; + + NSString* url = [command argumentAtIndex:0]; + NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf]; + NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString class]]; + + self.callbackId = command.callbackId; + + if (url != nil) { +#ifdef __CORDOVA_4_0_0 + NSURL* baseUrl = [self.webViewEngine URL]; +#else + NSURL* baseUrl = [self.webView.request URL]; +#endif + NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL]; + + if ([self isSystemUrl:absoluteUrl]) { + target = kInAppBrowserTargetSystem; + } + + if ([target isEqualToString:kInAppBrowserTargetSelf]) { + [self openInCordovaWebView:absoluteUrl withOptions:options]; + } else if ([target isEqualToString:kInAppBrowserTargetSystem]) { + [self openInSystem:absoluteUrl]; + } else { // _blank or anything else + [self openInInAppBrowser:absoluteUrl withOptions:options]; + } + + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"incorrect number of arguments"]; + } + + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + +- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options +{ + CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options]; + + if (browserOptions.clearcache) { + NSHTTPCookie *cookie; + NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + for (cookie in [storage cookies]) + { + if (![cookie.domain isEqual: @".^filecookies^"]) { + [storage deleteCookie:cookie]; + } + } + } + + if (browserOptions.clearsessioncache) { + NSHTTPCookie *cookie; + NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + for (cookie in [storage cookies]) + { + if (![cookie.domain isEqual: @".^filecookies^"] && cookie.isSessionOnly) { + [storage deleteCookie:cookie]; + } + } + } + + if (self.inAppBrowserViewController == nil) { + NSString* originalUA = [CDVUserAgentUtil originalUserAgent]; + self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:originalUA prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions]; + self.inAppBrowserViewController.navigationDelegate = self; + + if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) { + self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController; + } + } + + [self.inAppBrowserViewController showLocationBar:browserOptions.location]; + [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; + if (browserOptions.closebuttoncaption != nil) { + [self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption]; + } + // Set Presentation Style + UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default + if (browserOptions.presentationstyle != nil) { + if ([[browserOptions.presentationstyle lowercaseString] isEqualToString:@"pagesheet"]) { + presentationStyle = UIModalPresentationPageSheet; + } else if ([[browserOptions.presentationstyle lowercaseString] isEqualToString:@"formsheet"]) { + presentationStyle = UIModalPresentationFormSheet; + } + } + self.inAppBrowserViewController.modalPresentationStyle = presentationStyle; + + // Set Transition Style + UIModalTransitionStyle transitionStyle = UIModalTransitionStyleCoverVertical; // default + if (browserOptions.transitionstyle != nil) { + if ([[browserOptions.transitionstyle lowercaseString] isEqualToString:@"fliphorizontal"]) { + transitionStyle = UIModalTransitionStyleFlipHorizontal; + } else if ([[browserOptions.transitionstyle lowercaseString] isEqualToString:@"crossdissolve"]) { + transitionStyle = UIModalTransitionStyleCrossDissolve; + } + } + self.inAppBrowserViewController.modalTransitionStyle = transitionStyle; + + // prevent webView from bouncing + if (browserOptions.disallowoverscroll) { + if ([self.inAppBrowserViewController.webView respondsToSelector:@selector(scrollView)]) { + ((UIScrollView*)[self.inAppBrowserViewController.webView scrollView]).bounces = NO; + } else { + for (id subview in self.inAppBrowserViewController.webView.subviews) { + if ([[subview class] isSubclassOfClass:[UIScrollView class]]) { + ((UIScrollView*)subview).bounces = NO; + } + } + } + } + + // UIWebView options + self.inAppBrowserViewController.webView.scalesPageToFit = browserOptions.enableviewportscale; + self.inAppBrowserViewController.webView.mediaPlaybackRequiresUserAction = browserOptions.mediaplaybackrequiresuseraction; + self.inAppBrowserViewController.webView.allowsInlineMediaPlayback = browserOptions.allowinlinemediaplayback; + if (IsAtLeastiOSVersion(@"6.0")) { + self.inAppBrowserViewController.webView.keyboardDisplayRequiresUserAction = browserOptions.keyboarddisplayrequiresuseraction; + self.inAppBrowserViewController.webView.suppressesIncrementalRendering = browserOptions.suppressesincrementalrendering; + } + + [self.inAppBrowserViewController navigateTo:url]; + if (!browserOptions.hidden) { + [self show:nil]; + } +} + +- (void)show:(CDVInvokedUrlCommand*)command +{ + if (self.inAppBrowserViewController == nil) { + NSLog(@"Tried to show IAB after it was closed."); + return; + } + if (_previousStatusBarStyle != -1) { + NSLog(@"Tried to show IAB while already shown"); + return; + } + + _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; + + CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc] + initWithRootViewController:self.inAppBrowserViewController]; + nav.orientationDelegate = self.inAppBrowserViewController; + nav.navigationBarHidden = YES; + // Run later to avoid the "took a long time" log message. + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.inAppBrowserViewController != nil) { + [self.viewController presentViewController:nav animated:YES completion:nil]; + } + }); +} + +- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options +{ + if ([self.commandDelegate URLIsWhitelisted:url]) { + NSURLRequest* request = [NSURLRequest requestWithURL:url]; +#ifdef __CORDOVA_4_0_0 + [self.webViewEngine loadRequest:request]; +#else + [self.webView loadRequest:request]; +#endif + } else { // this assumes the InAppBrowser can be excepted from the white-list + [self openInInAppBrowser:url withOptions:options]; + } +} + +- (void)openInSystem:(NSURL*)url +{ + if ([[UIApplication sharedApplication] canOpenURL:url]) { + [[UIApplication sharedApplication] openURL:url]; + } else { // handle any custom schemes to plugins + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; + } +} + +// This is a helper method for the inject{Script|Style}{Code|File} API calls, which +// provides a consistent method for injecting JavaScript code into the document. +// +// If a wrapper string is supplied, then the source string will be JSON-encoded (adding +// quotes) and wrapped using string formatting. (The wrapper string should have a single +// '%@' marker). +// +// If no wrapper is supplied, then the source string is executed directly. + +- (void)injectDeferredObject:(NSString*)source withWrapper:(NSString*)jsWrapper +{ + if (!_injectedIframeBridge) { + _injectedIframeBridge = YES; + // Create an iframe bridge in the new document to communicate with the CDVInAppBrowserViewController + [self.inAppBrowserViewController.webView stringByEvaluatingJavaScriptFromString:@"(function(d){var e = _cdvIframeBridge = d.createElement('iframe');e.style.display='none';d.body.appendChild(e);})(document)"]; + } + + if (jsWrapper != nil) { + NSData* jsonData = [NSJSONSerialization dataWithJSONObject:@[source] options:0 error:nil]; + NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + if (sourceArrayString) { + NSString* sourceString = [sourceArrayString substringWithRange:NSMakeRange(1, [sourceArrayString length] - 2)]; + NSString* jsToInject = [NSString stringWithFormat:jsWrapper, sourceString]; + [self.inAppBrowserViewController.webView stringByEvaluatingJavaScriptFromString:jsToInject]; + } + } else { + [self.inAppBrowserViewController.webView stringByEvaluatingJavaScriptFromString:source]; + } +} + +- (void)injectScriptCode:(CDVInvokedUrlCommand*)command +{ + NSString* jsWrapper = nil; + + if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { + jsWrapper = [NSString stringWithFormat:@"_cdvIframeBridge.src='gap-iab://%@/'+encodeURIComponent(JSON.stringify([eval(%%@)]));", command.callbackId]; + } + [self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper]; +} + +- (void)injectScriptFile:(CDVInvokedUrlCommand*)command +{ + NSString* jsWrapper; + + if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { + jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('script'); c.src = %%@; c.onload = function() { _cdvIframeBridge.src='gap-iab://%@'; }; d.body.appendChild(c); })(document)", command.callbackId]; + } else { + jsWrapper = @"(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c); })(document)"; + } + [self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper]; +} + +- (void)injectStyleCode:(CDVInvokedUrlCommand*)command +{ + NSString* jsWrapper; + + if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { + jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('style'); c.innerHTML = %%@; c.onload = function() { _cdvIframeBridge.src='gap-iab://%@'; }; d.body.appendChild(c); })(document)", command.callbackId]; + } else { + jsWrapper = @"(function(d) { var c = d.createElement('style'); c.innerHTML = %@; d.body.appendChild(c); })(document)"; + } + [self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper]; +} + +- (void)injectStyleFile:(CDVInvokedUrlCommand*)command +{ + NSString* jsWrapper; + + if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { + jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%@; c.onload = function() { _cdvIframeBridge.src='gap-iab://%@'; }; d.body.appendChild(c); })(document)", command.callbackId]; + } else { + jsWrapper = @"(function(d) { var c = d.createElement('link'); c.rel='stylesheet', c.type='text/css'; c.href = %@; d.body.appendChild(c); })(document)"; + } + [self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper]; +} + +- (BOOL)isValidCallbackId:(NSString *)callbackId +{ + NSError *err = nil; + // Initialize on first use + if (self.callbackIdPattern == nil) { + self.callbackIdPattern = [NSRegularExpression regularExpressionWithPattern:@"^InAppBrowser[0-9]{1,10}$" options:0 error:&err]; + if (err != nil) { + // Couldn't initialize Regex; No is safer than Yes. + return NO; + } + } + if ([self.callbackIdPattern firstMatchInString:callbackId options:0 range:NSMakeRange(0, [callbackId length])]) { + return YES; + } + return NO; +} + +/** + * The iframe bridge provided for the InAppBrowser is capable of executing any oustanding callback belonging + * to the InAppBrowser plugin. Care has been taken that other callbacks cannot be triggered, and that no + * other code execution is possible. + * + * To trigger the bridge, the iframe (or any other resource) should attempt to load a url of the form: + * + * gap-iab://<callbackId>/<arguments> + * + * where <callbackId> is the string id of the callback to trigger (something like "InAppBrowser0123456789") + * + * If present, the path component of the special gap-iab:// url is expected to be a URL-escaped JSON-encoded + * value to pass to the callback. [NSURL path] should take care of the URL-unescaping, and a JSON_EXCEPTION + * is returned if the JSON is invalid. + */ +- (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType +{ + NSURL* url = request.URL; + BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]]; + + // See if the url uses the 'gap-iab' protocol. If so, the host should be the id of a callback to execute, + // and the path, if present, should be a JSON-encoded value to pass to the callback. + if ([[url scheme] isEqualToString:@"gap-iab"]) { + NSString* scriptCallbackId = [url host]; + CDVPluginResult* pluginResult = nil; + + if ([self isValidCallbackId:scriptCallbackId]) { + NSString* scriptResult = [url path]; + NSError* __autoreleasing error = nil; + + // The message should be a JSON-encoded array of the result of the script which executed. + if ((scriptResult != nil) && ([scriptResult length] > 1)) { + scriptResult = [scriptResult substringFromIndex:1]; + NSData* decodedResult = [NSJSONSerialization JSONObjectWithData:[scriptResult dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error]; + if ((error == nil) && [decodedResult isKindOfClass:[NSArray class]]) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:(NSArray*)decodedResult]; + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION]; + } + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:@[]]; + } + [self.commandDelegate sendPluginResult:pluginResult callbackId:scriptCallbackId]; + return NO; + } + } else if ((self.callbackId != nil) && isTopLevelNavigation) { + // Send a loadstart event for each top-level navigation (includes redirects). + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK + messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}]; + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + } + + return YES; +} + +- (void)webViewDidStartLoad:(UIWebView*)theWebView +{ + _injectedIframeBridge = NO; +} + +- (void)webViewDidFinishLoad:(UIWebView*)theWebView +{ + if (self.callbackId != nil) { + // TODO: It would be more useful to return the URL the page is actually on (e.g. if it's been redirected). + NSString* url = [self.inAppBrowserViewController.currentURL absoluteString]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK + messageAsDictionary:@{@"type":@"loadstop", @"url":url}]; + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + } +} + +- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error +{ + if (self.callbackId != nil) { + NSString* url = [self.inAppBrowserViewController.currentURL absoluteString]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR + messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}]; + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + } +} + +- (void)browserExit +{ + if (self.callbackId != nil) { + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK + messageAsDictionary:@{@"type":@"exit"}]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + self.callbackId = nil; + } + // Set navigationDelegate to nil to ensure no callbacks are received from it. + self.inAppBrowserViewController.navigationDelegate = nil; + // Don't recycle the ViewController since it may be consuming a lot of memory. + // Also - this is required for the PDF/User-Agent bug work-around. + self.inAppBrowserViewController = nil; + + if (IsAtLeastiOSVersion(@"7.0")) { + [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; + } + + _previousStatusBarStyle = -1; // this value was reset before reapplying it. caused statusbar to stay black on ios7 +} + +@end + +#pragma mark CDVInAppBrowserViewController + +@implementation CDVInAppBrowserViewController + +@synthesize currentURL; + +- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions +{ + self = [super init]; + if (self != nil) { + _userAgent = userAgent; + _prevUserAgent = prevUserAgent; + _browserOptions = browserOptions; +#ifdef __CORDOVA_4_0_0 + _webViewDelegate = [[CDVUIWebViewDelegate alloc] initWithDelegate:self]; +#else + _webViewDelegate = [[CDVWebViewDelegate alloc] initWithDelegate:self]; +#endif + + [self createViews]; + } + + return self; +} + +- (void)createViews +{ + // We create the views in code for primarily for ease of upgrades and not requiring an external .xib to be included + + CGRect webViewBounds = self.view.bounds; + BOOL toolbarIsAtBottom = ![_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]; + webViewBounds.size.height -= _browserOptions.location ? FOOTER_HEIGHT : TOOLBAR_HEIGHT; + self.webView = [[UIWebView alloc] initWithFrame:webViewBounds]; + + self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); + + [self.view addSubview:self.webView]; + [self.view sendSubviewToBack:self.webView]; + + self.webView.delegate = _webViewDelegate; + self.webView.backgroundColor = [UIColor whiteColor]; + + self.webView.clearsContextBeforeDrawing = YES; + self.webView.clipsToBounds = YES; + self.webView.contentMode = UIViewContentModeScaleToFill; + self.webView.multipleTouchEnabled = YES; + self.webView.opaque = YES; + self.webView.scalesPageToFit = NO; + self.webView.userInteractionEnabled = YES; + + self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; + self.spinner.alpha = 1.000; + self.spinner.autoresizesSubviews = YES; + self.spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin; + self.spinner.clearsContextBeforeDrawing = NO; + self.spinner.clipsToBounds = NO; + self.spinner.contentMode = UIViewContentModeScaleToFill; + self.spinner.frame = CGRectMake(454.0, 231.0, 20.0, 20.0); + self.spinner.hidden = YES; + self.spinner.hidesWhenStopped = YES; + self.spinner.multipleTouchEnabled = NO; + self.spinner.opaque = NO; + self.spinner.userInteractionEnabled = NO; + [self.spinner stopAnimating]; + + self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)]; + self.closeButton.enabled = YES; + + UIBarButtonItem* flexibleSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; + + UIBarButtonItem* fixedSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; + fixedSpaceButton.width = 20; + + float toolbarY = toolbarIsAtBottom ? self.view.bounds.size.height - TOOLBAR_HEIGHT : 0.0; + CGRect toolbarFrame = CGRectMake(0.0, toolbarY, self.view.bounds.size.width, TOOLBAR_HEIGHT); + + self.toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; + self.toolbar.alpha = 1.000; + self.toolbar.autoresizesSubviews = YES; + self.toolbar.autoresizingMask = toolbarIsAtBottom ? (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin) : UIViewAutoresizingFlexibleWidth; + self.toolbar.barStyle = UIBarStyleBlackOpaque; + self.toolbar.clearsContextBeforeDrawing = NO; + self.toolbar.clipsToBounds = NO; + self.toolbar.contentMode = UIViewContentModeScaleToFill; + self.toolbar.hidden = NO; + self.toolbar.multipleTouchEnabled = NO; + self.toolbar.opaque = NO; + self.toolbar.userInteractionEnabled = YES; + + CGFloat labelInset = 5.0; + float locationBarY = toolbarIsAtBottom ? self.view.bounds.size.height - FOOTER_HEIGHT : self.view.bounds.size.height - LOCATIONBAR_HEIGHT; + + self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelInset, locationBarY, self.view.bounds.size.width - labelInset, LOCATIONBAR_HEIGHT)]; + self.addressLabel.adjustsFontSizeToFitWidth = NO; + self.addressLabel.alpha = 1.000; + self.addressLabel.autoresizesSubviews = YES; + self.addressLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; + self.addressLabel.backgroundColor = [UIColor clearColor]; + self.addressLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters; + self.addressLabel.clearsContextBeforeDrawing = YES; + self.addressLabel.clipsToBounds = YES; + self.addressLabel.contentMode = UIViewContentModeScaleToFill; + self.addressLabel.enabled = YES; + self.addressLabel.hidden = NO; + self.addressLabel.lineBreakMode = NSLineBreakByTruncatingTail; + + if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumScaleFactor:")]) { + [self.addressLabel setValue:@(10.0/[UIFont labelFontSize]) forKey:@"minimumScaleFactor"]; + } else if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumFontSize:")]) { + [self.addressLabel setValue:@(10.0) forKey:@"minimumFontSize"]; + } + + self.addressLabel.multipleTouchEnabled = NO; + self.addressLabel.numberOfLines = 1; + self.addressLabel.opaque = NO; + self.addressLabel.shadowOffset = CGSizeMake(0.0, -1.0); + self.addressLabel.text = NSLocalizedString(@"Loading...", nil); + self.addressLabel.textAlignment = NSTextAlignmentLeft; + self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000]; + self.addressLabel.userInteractionEnabled = NO; + + NSString* frontArrowString = NSLocalizedString(@"â–º", nil); // create arrow from Unicode char + self.forwardButton = [[UIBarButtonItem alloc] initWithTitle:frontArrowString style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)]; + self.forwardButton.enabled = YES; + self.forwardButton.imageInsets = UIEdgeInsetsZero; + + NSString* backArrowString = NSLocalizedString(@"â—„", nil); // create arrow from Unicode char + self.backButton = [[UIBarButtonItem alloc] initWithTitle:backArrowString style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)]; + self.backButton.enabled = YES; + self.backButton.imageInsets = UIEdgeInsetsZero; + + [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; + + self.view.backgroundColor = [UIColor grayColor]; + [self.view addSubview:self.toolbar]; + [self.view addSubview:self.addressLabel]; + [self.view addSubview:self.spinner]; +} + +- (void) setWebViewFrame : (CGRect) frame { + NSLog(@"Setting the WebView's frame to %@", NSStringFromCGRect(frame)); + [self.webView setFrame:frame]; +} + +- (void)setCloseButtonTitle:(NSString*)title +{ + // the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically + // but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one) + self.closeButton = nil; + self.closeButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)]; + self.closeButton.enabled = YES; + self.closeButton.tintColor = [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1]; + + NSMutableArray* items = [self.toolbar.items mutableCopy]; + [items replaceObjectAtIndex:0 withObject:self.closeButton]; + [self.toolbar setItems:items]; +} + +- (void)showLocationBar:(BOOL)show +{ + CGRect locationbarFrame = self.addressLabel.frame; + + BOOL toolbarVisible = !self.toolbar.hidden; + + // prevent double show/hide + if (show == !(self.addressLabel.hidden)) { + return; + } + + if (show) { + self.addressLabel.hidden = NO; + + if (toolbarVisible) { + // toolBar at the bottom, leave as is + // put locationBar on top of the toolBar + + CGRect webViewBounds = self.view.bounds; + webViewBounds.size.height -= FOOTER_HEIGHT; + [self setWebViewFrame:webViewBounds]; + + locationbarFrame.origin.y = webViewBounds.size.height; + self.addressLabel.frame = locationbarFrame; + } else { + // no toolBar, so put locationBar at the bottom + + CGRect webViewBounds = self.view.bounds; + webViewBounds.size.height -= LOCATIONBAR_HEIGHT; + [self setWebViewFrame:webViewBounds]; + + locationbarFrame.origin.y = webViewBounds.size.height; + self.addressLabel.frame = locationbarFrame; + } + } else { + self.addressLabel.hidden = YES; + + if (toolbarVisible) { + // locationBar is on top of toolBar, hide locationBar + + // webView take up whole height less toolBar height + CGRect webViewBounds = self.view.bounds; + webViewBounds.size.height -= TOOLBAR_HEIGHT; + [self setWebViewFrame:webViewBounds]; + } else { + // no toolBar, expand webView to screen dimensions + [self setWebViewFrame:self.view.bounds]; + } + } +} + +- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition +{ + CGRect toolbarFrame = self.toolbar.frame; + CGRect locationbarFrame = self.addressLabel.frame; + + BOOL locationbarVisible = !self.addressLabel.hidden; + + // prevent double show/hide + if (show == !(self.toolbar.hidden)) { + return; + } + + if (show) { + self.toolbar.hidden = NO; + CGRect webViewBounds = self.view.bounds; + + if (locationbarVisible) { + // locationBar at the bottom, move locationBar up + // put toolBar at the bottom + webViewBounds.size.height -= FOOTER_HEIGHT; + locationbarFrame.origin.y = webViewBounds.size.height; + self.addressLabel.frame = locationbarFrame; + self.toolbar.frame = toolbarFrame; + } else { + // no locationBar, so put toolBar at the bottom + CGRect webViewBounds = self.view.bounds; + webViewBounds.size.height -= TOOLBAR_HEIGHT; + self.toolbar.frame = toolbarFrame; + } + + if ([toolbarPosition isEqualToString:kInAppBrowserToolbarBarPositionTop]) { + toolbarFrame.origin.y = 0; + webViewBounds.origin.y += toolbarFrame.size.height; + [self setWebViewFrame:webViewBounds]; + } else { + toolbarFrame.origin.y = (webViewBounds.size.height + LOCATIONBAR_HEIGHT); + } + [self setWebViewFrame:webViewBounds]; + + } else { + self.toolbar.hidden = YES; + + if (locationbarVisible) { + // locationBar is on top of toolBar, hide toolBar + // put locationBar at the bottom + + // webView take up whole height less locationBar height + CGRect webViewBounds = self.view.bounds; + webViewBounds.size.height -= LOCATIONBAR_HEIGHT; + [self setWebViewFrame:webViewBounds]; + + // move locationBar down + locationbarFrame.origin.y = webViewBounds.size.height; + self.addressLabel.frame = locationbarFrame; + } else { + // no locationBar, expand webView to screen dimensions + [self setWebViewFrame:self.view.bounds]; + } + } +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; +} + +- (void)viewDidUnload +{ + [self.webView loadHTMLString:nil baseURL:nil]; + [CDVUserAgentUtil releaseLock:&_userAgentLockToken]; + [super viewDidUnload]; +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} + +- (void)close +{ + [CDVUserAgentUtil releaseLock:&_userAgentLockToken]; + self.currentURL = nil; + + if ((self.navigationDelegate != nil) && [self.navigationDelegate respondsToSelector:@selector(browserExit)]) { + [self.navigationDelegate browserExit]; + } + + // Run later to avoid the "took a long time" log message. + dispatch_async(dispatch_get_main_queue(), ^{ + if ([self respondsToSelector:@selector(presentingViewController)]) { + [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; + } else { + [[self parentViewController] dismissViewControllerAnimated:YES completion:nil]; + } + }); +} + +- (void)navigateTo:(NSURL*)url +{ + NSURLRequest* request = [NSURLRequest requestWithURL:url]; + + if (_userAgentLockToken != 0) { + [self.webView loadRequest:request]; + } else { + [CDVUserAgentUtil acquireLock:^(NSInteger lockToken) { + _userAgentLockToken = lockToken; + [CDVUserAgentUtil setUserAgent:_userAgent lockToken:lockToken]; + [self.webView loadRequest:request]; + }]; + } +} + +- (void)goBack:(id)sender +{ + [self.webView goBack]; +} + +- (void)goForward:(id)sender +{ + [self.webView goForward]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + if (IsAtLeastiOSVersion(@"7.0")) { + [[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]]; + } + [self rePositionViews]; + + [super viewWillAppear:animated]; +} + +// +// On iOS 7 the status bar is part of the view's dimensions, therefore it's height has to be taken into account. +// The height of it could be hardcoded as 20 pixels, but that would assume that the upcoming releases of iOS won't +// change that value. +// +- (float) getStatusBarOffset { + CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; + float statusBarOffset = IsAtLeastiOSVersion(@"7.0") ? MIN(statusBarFrame.size.width, statusBarFrame.size.height) : 0.0; + return statusBarOffset; +} + +- (void) rePositionViews { + if ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]) { + [self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT, self.webView.frame.size.width, self.webView.frame.size.height)]; + [self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)]; + } +} + +#pragma mark UIWebViewDelegate + +- (void)webViewDidStartLoad:(UIWebView*)theWebView +{ + // loading url, start spinner, update back/forward + + self.addressLabel.text = NSLocalizedString(@"Loading...", nil); + self.backButton.enabled = theWebView.canGoBack; + self.forwardButton.enabled = theWebView.canGoForward; + + [self.spinner startAnimating]; + + return [self.navigationDelegate webViewDidStartLoad:theWebView]; +} + +- (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType +{ + BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]]; + + if (isTopLevelNavigation) { + self.currentURL = request.URL; + } + return [self.navigationDelegate webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; +} + +- (void)webViewDidFinishLoad:(UIWebView*)theWebView +{ + // update url, stop spinner, update back/forward + + self.addressLabel.text = [self.currentURL absoluteString]; + self.backButton.enabled = theWebView.canGoBack; + self.forwardButton.enabled = theWebView.canGoForward; + + [self.spinner stopAnimating]; + + // Work around a bug where the first time a PDF is opened, all UIWebViews + // reload their User-Agent from NSUserDefaults. + // This work-around makes the following assumptions: + // 1. The app has only a single Cordova Webview. If not, then the app should + // take it upon themselves to load a PDF in the background as a part of + // their start-up flow. + // 2. That the PDF does not require any additional network requests. We change + // the user-agent here back to that of the CDVViewController, so requests + // from it must pass through its white-list. This *does* break PDFs that + // contain links to other remote PDF/websites. + // More info at https://issues.apache.org/jira/browse/CB-2225 + BOOL isPDF = [@"true" isEqualToString :[theWebView stringByEvaluatingJavaScriptFromString:@"document.body==null"]]; + if (isPDF) { + [CDVUserAgentUtil setUserAgent:_prevUserAgent lockToken:_userAgentLockToken]; + } + + [self.navigationDelegate webViewDidFinishLoad:theWebView]; +} + +- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error +{ + // log fail message, stop spinner, update back/forward + NSLog(@"webView:didFailLoadWithError - %ld: %@", (long)error.code, [error localizedDescription]); + + self.backButton.enabled = theWebView.canGoBack; + self.forwardButton.enabled = theWebView.canGoForward; + [self.spinner stopAnimating]; + + self.addressLabel.text = NSLocalizedString(@"Load Error", nil); + + [self.navigationDelegate webView:theWebView didFailLoadWithError:error]; +} + +#pragma mark CDVScreenOrientationDelegate + +- (BOOL)shouldAutorotate +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotate)]) { + return [self.orientationDelegate shouldAutorotate]; + } + return YES; +} + +- (NSUInteger)supportedInterfaceOrientations +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) { + return [self.orientationDelegate supportedInterfaceOrientations]; + } + + return 1 << UIInterfaceOrientationPortrait; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) { + return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation]; + } + + return YES; +} + +@end + +@implementation CDVInAppBrowserOptions + +- (id)init +{ + if (self = [super init]) { + // default values + self.location = YES; + self.toolbar = YES; + self.closebuttoncaption = nil; + self.toolbarposition = kInAppBrowserToolbarBarPositionBottom; + self.clearcache = NO; + self.clearsessioncache = NO; + + self.enableviewportscale = NO; + self.mediaplaybackrequiresuseraction = NO; + self.allowinlinemediaplayback = NO; + self.keyboarddisplayrequiresuseraction = YES; + self.suppressesincrementalrendering = NO; + self.hidden = NO; + self.disallowoverscroll = NO; + } + + return self; +} + ++ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options +{ + CDVInAppBrowserOptions* obj = [[CDVInAppBrowserOptions alloc] init]; + + // NOTE: this parsing does not handle quotes within values + NSArray* pairs = [options componentsSeparatedByString:@","]; + + // parse keys and values, set the properties + for (NSString* pair in pairs) { + NSArray* keyvalue = [pair componentsSeparatedByString:@"="]; + + if ([keyvalue count] == 2) { + NSString* key = [[keyvalue objectAtIndex:0] lowercaseString]; + NSString* value = [keyvalue objectAtIndex:1]; + NSString* value_lc = [value lowercaseString]; + + BOOL isBoolean = [value_lc isEqualToString:@"yes"] || [value_lc isEqualToString:@"no"]; + NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init]; + [numberFormatter setAllowsFloats:YES]; + BOOL isNumber = [numberFormatter numberFromString:value_lc] != nil; + + // set the property according to the key name + if ([obj respondsToSelector:NSSelectorFromString(key)]) { + if (isNumber) { + [obj setValue:[numberFormatter numberFromString:value_lc] forKey:key]; + } else if (isBoolean) { + [obj setValue:[NSNumber numberWithBool:[value_lc isEqualToString:@"yes"]] forKey:key]; + } else { + [obj setValue:value forKey:key]; + } + } + } + } + + return obj; +} + +@end + +@implementation CDVInAppBrowserNavigationController : UINavigationController + +- (void) viewDidLoad { + + CGRect frame = [UIApplication sharedApplication].statusBarFrame; + + // simplified from: http://stackoverflow.com/a/25669695/219684 + + UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:frame]; + bgToolbar.barStyle = UIBarStyleDefault; + [self.view addSubview:bgToolbar]; + + [super viewDidLoad]; +} + + +#pragma mark CDVScreenOrientationDelegate + +- (BOOL)shouldAutorotate +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotate)]) { + return [self.orientationDelegate shouldAutorotate]; + } + return YES; +} + +- (NSUInteger)supportedInterfaceOrientations +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) { + return [self.orientationDelegate supportedInterfaceOrientations]; + } + + return 1 << UIInterfaceOrientationPortrait; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) { + return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation]; + } + + return YES; +} + + +@end + diff --git a/plugins/cordova-plugin-inappbrowser/src/ubuntu/InAppBrowser.qml b/plugins/cordova-plugin-inappbrowser/src/ubuntu/InAppBrowser.qml new file mode 100644 index 00000000..781e8a6e --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ubuntu/InAppBrowser.qml @@ -0,0 +1,92 @@ +/* + * + * Copyright 2013 Canonical Ltd. + * + * 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. + * +*/ +import QtQuick 2.0 +import Ubuntu.Components.Popups 0.1 +import Ubuntu.Components 0.1 +import com.canonical.Oxide 1.0 + +Rectangle { + anchors.fill: parent + id: inappbrowser + property string url1 + Rectangle { + border.color: "black" + width: parent.width + height: urlEntry.height + color: "gray" + TextInput { + id: urlEntry + width: parent.width - closeButton.width + text: url1 + activeFocusOnPress: false + } + Image { + id: closeButton + width: height + x: parent.width - width + height: parent.height + source: "close.png" + MouseArea { + anchors.fill: parent + onClicked: { + root.exec("InAppBrowser", "close", [0, 0]) + } + } + } + } + + 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 + height: parent.height - y + url: url1 + id: _view + onLoadingStateChanged: { + root.exec("InAppBrowser", "loadFinished", [_view.loading]) + } + context: WebContext { + id: webcontext + + userScripts: [ + UserScript { + context: usContext + emulateGreasemonkey: true + url: "InAppBrowser_escapeScript.js" + } + ] + } + } +} diff --git a/plugins/cordova-plugin-inappbrowser/src/ubuntu/InAppBrowser_escapeScript.js b/plugins/cordova-plugin-inappbrowser/src/ubuntu/InAppBrowser_escapeScript.js new file mode 100644 index 00000000..07661bb6 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ubuntu/InAppBrowser_escapeScript.js @@ -0,0 +1,29 @@ +/* + * + * 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. + * +*/ + +oxide.addMessageHandler("EXECUTE", function(msg) { + var code = msg.args.code; + try { + msg.reply({result: eval(code)}); + } catch(e) { + msg.error("Code threw exception: \"" + e + "\""); + } +}); diff --git a/plugins/cordova-plugin-inappbrowser/src/ubuntu/close.png b/plugins/cordova-plugin-inappbrowser/src/ubuntu/close.png Binary files differnew file mode 100644 index 00000000..56373d1f --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ubuntu/close.png diff --git a/plugins/cordova-plugin-inappbrowser/src/ubuntu/inappbrowser.cpp b/plugins/cordova-plugin-inappbrowser/src/ubuntu/inappbrowser.cpp new file mode 100644 index 00000000..c5a9e64a --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ubuntu/inappbrowser.cpp @@ -0,0 +1,105 @@ +/* + * + * Copyright 2013 Canonical Ltd. + * + * 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. + * +*/ + +#include <QQuickView> +#include <QQuickItem> + +#include "inappbrowser.h" +#include <cordova.h> + +Inappbrowser::Inappbrowser(Cordova *cordova): CPlugin(cordova), _eventCb(0) { +} + +const char code[] = "\ +var component; \ +function createObject() { \ + component = Qt.createComponent(%1); \ + if (component.status == Component.Ready) \ + finishCreation(); \ + else \ + component.statusChanged.connect(finishCreation); \ +} \ +function finishCreation() { \ + CordovaWrapper.global.inappbrowser = component.createObject(root, \ + {root: root, cordova: cordova, url1: %2}); \ +} \ +createObject()"; + +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); + + _eventCb = cb; + + QString path = m_cordova->get_app_dir() + "/../qml/InAppBrowser.qml"; + QString qml = QString(code) + .arg(CordovaInternal::format(path)).arg(CordovaInternal::format(url)); + m_cordova->execQML(qml); +} + +void Inappbrowser::show(int, int) { + m_cordova->execQML("CordovaWrapper.global.inappbrowser.visible = true"); +} + +void Inappbrowser::close(int, int) { + m_cordova->execQML("CordovaWrapper.global.inappbrowser.destroy()"); + this->callbackWithoutRemove(_eventCb, EXIT_EVENT); + _eventCb = 0; +} + +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 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 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 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) { + this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT); + } else { + this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT); + } +} diff --git a/plugins/cordova-plugin-inappbrowser/src/ubuntu/inappbrowser.h b/plugins/cordova-plugin-inappbrowser/src/ubuntu/inappbrowser.h new file mode 100644 index 00000000..1da4e033 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/ubuntu/inappbrowser.h @@ -0,0 +1,61 @@ +/* + * + * Copyright 2013 Canonical Ltd. + * + * 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. + * +*/ +#ifndef INAPPBROWSER_H +#define INAPPBROWSER_H + +#include <QtCore> +#include <cplugin.h> + +class Inappbrowser: public CPlugin { + Q_OBJECT +public: + Inappbrowser(Cordova *cordova); + + virtual const QString fullName() override { + return Inappbrowser::fullID(); + } + + virtual const QString shortName() override { + return "InAppBrowser"; + } + + static const QString fullID() { + return "InAppBrowser"; + } + +public slots: + void open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures); + void show(int, int); + void close(int, int); + void injectStyleFile(int cb, int, const QString&, bool); + void injectStyleCode(int cb, int, const QString&, bool); + void injectScriptFile(int cb, int, const QString&, bool); + void injectScriptCode(int cb, int, const QString&, bool); + + void loadFinished(bool status); + +private: + int _eventCb; +}; + +#endif diff --git a/plugins/cordova-plugin-inappbrowser/src/windows/InAppBrowserProxy.js b/plugins/cordova-plugin-inappbrowser/src/windows/InAppBrowserProxy.js new file mode 100644 index 00000000..817516e5 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/windows/InAppBrowserProxy.js @@ -0,0 +1,326 @@ +/* + * + * 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. + * +*/ + +/*jslint sloppy:true */ +/*global Windows:true, require, document, setTimeout, window, module */ + + + +var cordova = require('cordova'), + channel = require('cordova/channel'), + urlutil = require('cordova/urlutil'); + +var browserWrap, + popup, + navigationButtonsDiv, + navigationButtonsDivInner, + backButton, + forwardButton, + closeButton, + bodyOverflowStyle; + +// x-ms-webview is available starting from Windows 8.1 (platformId is 'windows') +// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx +var isWebViewAvailable = cordova.platformId == 'windows'; + +function attachNavigationEvents(element, callback) { + if (isWebViewAvailable) { + element.addEventListener("MSWebViewNavigationStarting", function (e) { + callback({ type: "loadstart", url: e.uri}, {keepCallback: true} ); + }); + + element.addEventListener("MSWebViewNavigationCompleted", function (e) { + callback({ type: e.isSuccess ? "loadstop" : "loaderror", url: e.uri}, {keepCallback: true}); + }); + + element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) { + // WebView found the content to be not HTML. + // http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx + callback({ type: "loaderror", url: e.uri}, {keepCallback: true}); + }); + + element.addEventListener("MSWebViewContentLoading", function (e) { + if (navigationButtonsDiv) { + backButton.disabled = !popup.canGoBack; + forwardButton.disabled = !popup.canGoForward; + } + }); + } else { + var onError = function () { + callback({ type: "loaderror", url: this.contentWindow.location}, {keepCallback: true}); + }; + + element.addEventListener("unload", function () { + callback({ type: "loadstart", url: this.contentWindow.location}, {keepCallback: true}); + }); + + element.addEventListener("load", function () { + callback({ type: "loadstop", url: this.contentWindow.location}, {keepCallback: true}); + }); + + element.addEventListener("error", onError); + element.addEventListener("abort", onError); + } +} + +var IAB = { + close: function (win, lose) { + if (browserWrap) { + if (win) win({ type: "exit" }); + + browserWrap.parentNode.removeChild(browserWrap); + // Reset body overflow style to initial value + document.body.style.msOverflowStyle = bodyOverflowStyle; + browserWrap = null; + popup = null; + } + }, + show: function (win, lose) { + if (browserWrap) { + browserWrap.style.display = "block"; + } + }, + open: function (win, lose, args) { + var strUrl = args[0], + target = args[1], + features = args[2], + url; + + if (target === "_system") { + url = new Windows.Foundation.Uri(strUrl); + Windows.System.Launcher.launchUriAsync(url); + } else if (target === "_self" || !target) { + window.location = strUrl; + } else { + // "_blank" or anything else + if (!browserWrap) { + var browserWrapStyle = document.createElement('link'); + browserWrapStyle.rel = "stylesheet"; + browserWrapStyle.type = "text/css"; + browserWrapStyle.href = urlutil.makeAbsolute("/www/css/inappbrowser.css"); + + document.head.appendChild(browserWrapStyle); + + browserWrap = document.createElement("div"); + browserWrap.className = "inAppBrowserWrap"; + + if (features.indexOf("fullscreen=yes") > -1) { + browserWrap.classList.add("inAppBrowserWrapFullscreen"); + } + + // Save body overflow style to be able to reset it back later + bodyOverflowStyle = document.body.style.msOverflowStyle; + + browserWrap.onclick = function () { + setTimeout(function () { + IAB.close(win); + }, 0); + }; + + document.body.appendChild(browserWrap); + // Hide scrollbars for the whole body while inappbrowser's window is open + document.body.style.msOverflowStyle = "none"; + } + + if (features.indexOf("hidden=yes") !== -1) { + browserWrap.style.display = "none"; + } + + popup = document.createElement(isWebViewAvailable ? "x-ms-webview" : "iframe"); + if (popup instanceof HTMLIFrameElement) { + // For iframe we need to override bacground color of parent element here + // otherwise pages without background color set will have transparent background + popup.style.backgroundColor = "white"; + } + popup.style.borderWidth = "0px"; + popup.style.width = "100%"; + + browserWrap.appendChild(popup); + + if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) { + popup.style.height = "calc(100% - 60px)"; + + navigationButtonsDiv = document.createElement("div"); + navigationButtonsDiv.style.height = "60px"; + navigationButtonsDiv.style.backgroundColor = "#404040"; + navigationButtonsDiv.style.zIndex = "999"; + navigationButtonsDiv.onclick = function (e) { + e.cancelBubble = true; + }; + + navigationButtonsDivInner = document.createElement("div"); + navigationButtonsDivInner.style.paddingTop = "10px"; + navigationButtonsDivInner.style.height = "50px"; + navigationButtonsDivInner.style.width = "160px"; + navigationButtonsDivInner.style.margin = "0 auto"; + navigationButtonsDivInner.style.backgroundColor = "#404040"; + navigationButtonsDivInner.style.zIndex = "999"; + navigationButtonsDivInner.onclick = function (e) { + e.cancelBubble = true; + }; + + + backButton = document.createElement("button"); + backButton.style.width = "40px"; + backButton.style.height = "40px"; + backButton.style.borderRadius = "40px"; + + backButton.innerText = "<-"; + backButton.addEventListener("click", function (e) { + if (popup.canGoBack) + popup.goBack(); + }); + + forwardButton = document.createElement("button"); + forwardButton.style.marginLeft = "20px"; + forwardButton.style.width = "40px"; + forwardButton.style.height = "40px"; + forwardButton.style.borderRadius = "40px"; + + forwardButton.innerText = "->"; + forwardButton.addEventListener("click", function (e) { + if (popup.canGoForward) + popup.goForward(); + }); + + closeButton = document.createElement("button"); + closeButton.style.marginLeft = "20px"; + closeButton.style.width = "40px"; + closeButton.style.height = "40px"; + closeButton.style.borderRadius = "40px"; + + closeButton.innerText = "x"; + closeButton.addEventListener("click", function (e) { + setTimeout(function () { + IAB.close(win); + }, 0); + }); + + if (!isWebViewAvailable) { + // iframe navigation is not yet supported + backButton.disabled = true; + forwardButton.disabled = true; + } + + navigationButtonsDivInner.appendChild(backButton); + navigationButtonsDivInner.appendChild(forwardButton); + navigationButtonsDivInner.appendChild(closeButton); + navigationButtonsDiv.appendChild(navigationButtonsDivInner); + + browserWrap.appendChild(navigationButtonsDiv); + } else { + popup.style.height = "100%"; + } + + // start listening for navigation events + attachNavigationEvents(popup, win); + + if (isWebViewAvailable) { + strUrl = strUrl.replace("ms-appx://", "ms-appx-web://"); + } + popup.src = strUrl; + } + }, + + injectScriptCode: function (win, fail, args) { + var code = args[0], + hasCallback = args[1]; + + if (isWebViewAvailable && browserWrap && popup) { + var op = popup.invokeScriptAsync("eval", code); + op.oncomplete = function (e) { + var result = [e.target.result]; + hasCallback && win(result); + }; + op.onerror = function () { }; + op.start(); + } + }, + + injectScriptFile: function (win, fail, args) { + var filePath = args[0], + hasCallback = args[1]; + + if (!!filePath) { + filePath = urlutil.makeAbsolute(filePath); + } + + if (isWebViewAvailable && browserWrap && popup) { + var uri = new Windows.Foundation.Uri(filePath); + Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) { + Windows.Storage.FileIO.readTextAsync(file).done(function (code) { + var op = popup.invokeScriptAsync("eval", code); + op.oncomplete = function(e) { + var result = [e.target.result]; + hasCallback && win(result); + }; + op.onerror = function () { }; + op.start(); + }); + }); + } + }, + + injectStyleCode: function (win, fail, args) { + var code = args[0], + hasCallback = args[1]; + + if (isWebViewAvailable && browserWrap && popup) { + injectCSS(popup, code, hasCallback && win); + } + }, + + injectStyleFile: function (win, fail, args) { + var filePath = args[0], + hasCallback = args[1]; + + filePath = filePath && urlutil.makeAbsolute(filePath); + + if (isWebViewAvailable && browserWrap && popup) { + var uri = new Windows.Foundation.Uri(filePath); + Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) { + return Windows.Storage.FileIO.readTextAsync(file); + }).done(function (code) { + injectCSS(popup, code, hasCallback && win); + }, function () { + // no-op, just catch an error + }); + } + } +}; + +function injectCSS (webView, cssCode, callback) { + // This will automatically escape all thing that we need (quotes, slashes, etc.) + var escapedCode = JSON.stringify(cssCode); + var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)" + .replace('%s', escapedCode); + + var op = webView.invokeScriptAsync("eval", evalWrapper); + op.oncomplete = function() { + callback && callback([]); + }; + op.onerror = function () { }; + op.start(); +} + +module.exports = IAB; + +require("cordova/exec/proxy").add("InAppBrowser", module.exports); diff --git a/plugins/cordova-plugin-inappbrowser/src/wp/InAppBrowser.cs b/plugins/cordova-plugin-inappbrowser/src/wp/InAppBrowser.cs new file mode 100644 index 00000000..ddb51227 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/src/wp/InAppBrowser.cs @@ -0,0 +1,515 @@ +/* + Licensed 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. +*/ + +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.Serialization; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using Microsoft.Phone.Controls; +using Microsoft.Phone.Shell; + +#if WP8 +using System.Threading.Tasks; +using Windows.ApplicationModel; +using Windows.Storage; +using Windows.System; + +//Use alias in case Cordova File Plugin is enabled. Then the File class will be declared in both and error will occur. +using IOFile = System.IO.File; +#else +using Microsoft.Phone.Tasks; +#endif + +namespace WPCordovaClassLib.Cordova.Commands +{ + [DataContract] + public class BrowserOptions + { + [DataMember] + public string url; + + [DataMember] + public bool isGeolocationEnabled; + } + + public class InAppBrowser : BaseCommand + { + + private static WebBrowser browser; + private static ApplicationBarIconButton backButton; + private static ApplicationBarIconButton fwdButton; + + protected ApplicationBar AppBar; + + protected bool ShowLocation {get;set;} + protected bool StartHidden {get;set;} + + protected string NavigationCallbackId { get; set; } + + public void open(string options) + { + // reset defaults on ShowLocation + StartHidden features + ShowLocation = true; + StartHidden = false; + + string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + //BrowserOptions opts = JSON.JsonHelper.Deserialize<BrowserOptions>(options); + string urlLoc = args[0]; + string target = args[1]; + string featString = args[2]; + this.NavigationCallbackId = args[3]; + + if (!string.IsNullOrEmpty(featString)) + { + string[] features = featString.Split(','); + foreach (string str in features) + { + try + { + string[] split = str.Split('='); + switch (split[0]) + { + case "location": + ShowLocation = split[1].StartsWith("yes", StringComparison.OrdinalIgnoreCase); + break; + case "hidden": + StartHidden = split[1].StartsWith("yes", StringComparison.OrdinalIgnoreCase); + break; + } + } + catch (Exception) + { + // some sort of invalid param was passed, moving on ... + } + } + } + /* + _self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser + _blank - always open in the InAppBrowser + _system - always open in the system web browser + */ + switch (target) + { + case "_blank": + ShowInAppBrowser(urlLoc); + break; + case "_self": + ShowCordovaBrowser(urlLoc); + break; + case "_system": + ShowSystemBrowser(urlLoc); + break; + } + } + + public void show(string options) + { + string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + + + if (browser != null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + browser.Visibility = Visibility.Visible; + AppBar.IsVisible = true; + }); + } + } + + public void injectScriptCode(string options) + { + string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + + bool bCallback = false; + if (bool.TryParse(args[1], out bCallback)) { }; + + string callbackId = args[2]; + + if (browser != null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + var res = browser.InvokeScript("eval", new string[] { args[0] }); + + if (bCallback) + { + PluginResult result = new PluginResult(PluginResult.Status.OK, res.ToString()); + result.KeepCallback = false; + this.DispatchCommandResult(result); + } + + }); + } + } + + public void injectScriptFile(string options) + { + Debug.WriteLine("Error : Windows Phone cordova-plugin-inappbrowser does not currently support executeScript"); + string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + // throw new NotImplementedException("Windows Phone does not currently support 'executeScript'"); + } + + public void injectStyleCode(string options) + { + Debug.WriteLine("Error : Windows Phone cordova-plugin-inappbrowser does not currently support insertCSS"); + return; + + //string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + //bool bCallback = false; + //if (bool.TryParse(args[1], out bCallback)) { }; + + //string callbackId = args[2]; + + //if (browser != null) + //{ + //Deployment.Current.Dispatcher.BeginInvoke(() => + //{ + // if (bCallback) + // { + // string cssInsertString = "try{(function(doc){var c = '<style>body{background-color:#ffff00;}</style>'; doc.head.innerHTML += c;})(document);}catch(ex){alert('oops : ' + ex.message);}"; + // //cssInsertString = cssInsertString.Replace("_VALUE_", args[0]); + // Debug.WriteLine("cssInsertString = " + cssInsertString); + // var res = browser.InvokeScript("eval", new string[] { cssInsertString }); + // if (bCallback) + // { + // PluginResult result = new PluginResult(PluginResult.Status.OK, res.ToString()); + // result.KeepCallback = false; + // this.DispatchCommandResult(result); + // } + // } + + //}); + //} + } + + public void injectStyleFile(string options) + { + Debug.WriteLine("Error : Windows Phone cordova-plugin-inappbrowser does not currently support insertCSS"); + return; + + //string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + //throw new NotImplementedException("Windows Phone does not currently support 'insertCSS'"); + } + + private void ShowCordovaBrowser(string url) + { + Uri loc = new Uri(url, UriKind.RelativeOrAbsolute); + Deployment.Current.Dispatcher.BeginInvoke(() => + { + PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; + if (frame != null) + { + PhoneApplicationPage page = frame.Content as PhoneApplicationPage; + if (page != null) + { + CordovaView cView = page.FindName("CordovaView") as CordovaView; + if (cView != null) + { + WebBrowser br = cView.Browser; + br.Navigate2(loc); + } + } + + } + }); + } + +#if WP8 + private async void ShowSystemBrowser(string url) + { + var pathUri = new Uri(url, UriKind.Absolute); + if (pathUri.Scheme == Uri.UriSchemeHttp || pathUri.Scheme == Uri.UriSchemeHttps) + { + await Launcher.LaunchUriAsync(pathUri); + return; + } + + var file = await GetFile(pathUri.AbsolutePath.Replace('/', Path.DirectorySeparatorChar)); + if (file != null) + { + await Launcher.LaunchFileAsync(file); + } + else + { + Debug.WriteLine("File not found."); + } + } + + private async Task<StorageFile> GetFile(string fileName) + { + //first try to get the file from the isolated storage + var localFolder = ApplicationData.Current.LocalFolder; + if (IOFile.Exists(Path.Combine(localFolder.Path, fileName))) + { + return await localFolder.GetFileAsync(fileName); + } + + //if file is not found try to get it from the xap + var filePath = Path.Combine(Package.Current.InstalledLocation.Path, fileName); + if (IOFile.Exists(filePath)) + { + return await StorageFile.GetFileFromPathAsync(filePath); + } + + return null; + } +#else + private void ShowSystemBrowser(string url) + { + WebBrowserTask webBrowserTask = new WebBrowserTask(); + webBrowserTask.Uri = new Uri(url, UriKind.Absolute); + webBrowserTask.Show(); + } +#endif + + private void ShowInAppBrowser(string url) + { + Uri loc = new Uri(url, UriKind.RelativeOrAbsolute); + + Deployment.Current.Dispatcher.BeginInvoke(() => + { + if (browser != null) + { + //browser.IsGeolocationEnabled = opts.isGeolocationEnabled; + browser.Navigate2(loc); + } + else + { + PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; + if (frame != null) + { + PhoneApplicationPage page = frame.Content as PhoneApplicationPage; + + string baseImageUrl = "Images/"; + + if (page != null) + { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) + { + browser = new WebBrowser(); + browser.IsScriptEnabled = true; + browser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(browser_LoadCompleted); + + browser.Navigating += new EventHandler<NavigatingEventArgs>(browser_Navigating); + browser.NavigationFailed += new System.Windows.Navigation.NavigationFailedEventHandler(browser_NavigationFailed); + browser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(browser_Navigated); + browser.Navigate2(loc); + + if (StartHidden) + { + browser.Visibility = Visibility.Collapsed; + } + + //browser.IsGeolocationEnabled = opts.isGeolocationEnabled; + grid.Children.Add(browser); + } + + ApplicationBar bar = new ApplicationBar(); + bar.BackgroundColor = Colors.Gray; + bar.IsMenuEnabled = false; + + backButton = new ApplicationBarIconButton(); + backButton.Text = "Back"; + + backButton.IconUri = new Uri(baseImageUrl + "appbar.back.rest.png", UriKind.Relative); + backButton.Click += new EventHandler(backButton_Click); + bar.Buttons.Add(backButton); + + + fwdButton = new ApplicationBarIconButton(); + fwdButton.Text = "Forward"; + fwdButton.IconUri = new Uri(baseImageUrl + "appbar.next.rest.png", UriKind.Relative); + fwdButton.Click += new EventHandler(fwdButton_Click); + bar.Buttons.Add(fwdButton); + + ApplicationBarIconButton closeBtn = new ApplicationBarIconButton(); + closeBtn.Text = "Close"; + closeBtn.IconUri = new Uri(baseImageUrl + "appbar.close.rest.png", UriKind.Relative); + closeBtn.Click += new EventHandler(closeBtn_Click); + bar.Buttons.Add(closeBtn); + + page.ApplicationBar = bar; + bar.IsVisible = !StartHidden; + AppBar = bar; + + page.BackKeyPress += page_BackKeyPress; + + } + + } + } + }); + } + + void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) + { +#if WP8 + if (browser.CanGoBack) + { + browser.GoBack(); + } + else + { + close(); + } + e.Cancel = true; +#else + browser.InvokeScript("execScript", "history.back();"); +#endif + } + + void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) + { + + } + + void fwdButton_Click(object sender, EventArgs e) + { + if (browser != null) + { + try + { +#if WP8 + browser.GoForward(); +#else + browser.InvokeScript("execScript", "history.forward();"); +#endif + } + catch (Exception) + { + + } + } + } + + void backButton_Click(object sender, EventArgs e) + { + if (browser != null) + { + try + { +#if WP8 + browser.GoBack(); +#else + browser.InvokeScript("execScript", "history.back();"); +#endif + } + catch (Exception) + { + + } + } + } + + void closeBtn_Click(object sender, EventArgs e) + { + this.close(); + } + + + public void close(string options = "") + { + if (browser != null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; + if (frame != null) + { + PhoneApplicationPage page = frame.Content as PhoneApplicationPage; + if (page != null) + { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) + { + grid.Children.Remove(browser); + } + page.ApplicationBar = null; + page.BackKeyPress -= page_BackKeyPress; + } + } + + browser = null; + string message = "{\"type\":\"exit\"}"; + PluginResult result = new PluginResult(PluginResult.Status.OK, message); + result.KeepCallback = false; + this.DispatchCommandResult(result, NavigationCallbackId); + }); + } + } + + void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) + { +#if WP8 + if (browser != null) + { + backButton.IsEnabled = browser.CanGoBack; + fwdButton.IsEnabled = browser.CanGoForward; + + } +#endif + string message = "{\"type\":\"loadstop\", \"url\":\"" + e.Uri.OriginalString + "\"}"; + PluginResult result = new PluginResult(PluginResult.Status.OK, message); + result.KeepCallback = true; + this.DispatchCommandResult(result, NavigationCallbackId); + } + + void browser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e) + { + string message = "{\"type\":\"error\",\"url\":\"" + e.Uri.OriginalString + "\"}"; + PluginResult result = new PluginResult(PluginResult.Status.ERROR, message); + result.KeepCallback = true; + this.DispatchCommandResult(result, NavigationCallbackId); + } + + void browser_Navigating(object sender, NavigatingEventArgs e) + { + string message = "{\"type\":\"loadstart\",\"url\":\"" + e.Uri.OriginalString + "\"}"; + PluginResult result = new PluginResult(PluginResult.Status.OK, message); + result.KeepCallback = true; + this.DispatchCommandResult(result, NavigationCallbackId); + } + + } + + internal static class WebBrowserExtensions + { + /// <summary> + /// Improved method to initiate request to the provided URI. Supports 'data:text/html' urls. + /// </summary> + /// <param name="browser">The browser instance</param> + /// <param name="uri">The requested uri</param> + internal static void Navigate2(this WebBrowser browser, Uri uri) + { + // IE10 does not support data uri so we use NavigateToString method instead + if (uri.Scheme == "data") + { + // we should remove the scheme identifier and unescape the uri + string uriString = Uri.UnescapeDataString(uri.AbsoluteUri); + // format is 'data:text/html, ...' + string html = new System.Text.RegularExpressions.Regex("^data:text/html,").Replace(uriString, ""); + browser.NavigateToString(html); + } + else + { + browser.Navigate(uri); + } + } + } +} diff --git a/plugins/cordova-plugin-inappbrowser/tests/plugin.xml b/plugins/cordova-plugin-inappbrowser/tests/plugin.xml new file mode 100644 index 00000000..2993fa8c --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/plugin.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="cordova-plugin-inappbrowser-tests" + version="1.0.0"> + <name>Cordova InAppBrowser Plugin Tests</name> + <license>Apache 2.0</license> + + <js-module src="tests.js" name="tests"> + </js-module> + + <asset src="resources" target="cdvtests/iab-resources" /> +</plugin> diff --git a/plugins/cordova-plugin-inappbrowser/tests/resources/inject.css b/plugins/cordova-plugin-inappbrowser/tests/resources/inject.css new file mode 100644 index 00000000..3f6e41c8 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/resources/inject.css @@ -0,0 +1,21 @@ +/* + * 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. +*/ +#style-update-file { + display: block !important; +} diff --git a/plugins/cordova-plugin-inappbrowser/tests/resources/inject.html b/plugins/cordova-plugin-inappbrowser/tests/resources/inject.html new file mode 100644 index 00000000..3004b358 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/resources/inject.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<!-- + + 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. + +--> + + +<html> + <head> + <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" /> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 --> + <title>Cordova Mobile Spec</title> + <link rel="stylesheet" href="../../master.css" type="text/css" media="screen" title="no title" charset="utf-8"> + </head> + <body id="stage" class="theme"> + <h1 id="header">InAppBrowser - Script / Style Injection Test</h1> + <h2 id="style-update-file" style="display:none">Style updated from file</h2> + <h2 id="style-update-literal" style="display:none">Style updated from literal</h2> + <div>User-Agent: <cite id="u-a"></cite></div> + </body> + <script> + function updateUserAgent() { + document.getElementById("u-a").textContent = navigator.userAgent; + } + updateUserAgent(); + window.setInterval(updateUserAgent, 1500); + </script> +</html> diff --git a/plugins/cordova-plugin-inappbrowser/tests/resources/inject.js b/plugins/cordova-plugin-inappbrowser/tests/resources/inject.js new file mode 100644 index 00000000..6f254939 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/resources/inject.js @@ -0,0 +1,20 @@ +/* + * 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 d = document.getElementById("header") +d.innerHTML = "Script file successfully injected"; diff --git a/plugins/cordova-plugin-inappbrowser/tests/resources/local.html b/plugins/cordova-plugin-inappbrowser/tests/resources/local.html new file mode 100644 index 00000000..d23a7144 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/resources/local.html @@ -0,0 +1,67 @@ +<!DOCTYPE html> +<!-- + + 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. + +--> + + +<html> + <head> + <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" /> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 --> + <title>IAB test page</title> + <script type="text/javascript" charset="utf-8" src="../../cordova-incl.js"></script> + <script type="text/javascript" charset="utf-8"> + function onDeviceReady() { + document.getElementById("hint").textContent = "Running CordovaWebView, deviceVersion=" + device.version + ", no toolbar should be present, Back link should work, logcat should NOT have failed 'gap:' calls."; + } + document.addEventListener("deviceready", onDeviceReady, false); + </script> + <style> + body {background-color: #ffffff;} + </style> + </head> + <body id="stage" class="theme"> + <h1>Local URL</h1> + <div id="info"> + You have successfully loaded a local URL: + <script>document.write(location.href)</script> + </div> + <hr /> + <div>User-Agent = <span id="u-a"></span></div> + <hr /> + <div id="hint">Likely running inAppBrowser: Device version from Cordova=not found, Back link should not work, toolbar may be present, logcat should show failed 'gap:' calls.</div> + <hr /> + <div><a href="http://www.google.com">Visit Google</a> (whitelisted)</div> + <div><a href="http://www.yahoo.com">Visit Yahoo</a> (not whitelisted)</div> + <div><a href="http://www.stluciadance.com/prospectus_file/sample.pdf">Check out my remote PDF</a></div> + <div><a href="local.pdf">Check out my local PDF</a></div> + <p /><a href="javascript:;" onclick="history.back();">Back</a> + <p /> + <a name="anchor2"></a> + <div style="height: 1000px;border:1px solid red;">tall div with border</div> + </body> + <script> + function updateUserAgent() { + document.getElementById("u-a").textContent = navigator.userAgent; + } + updateUserAgent(); + window.setInterval(updateUserAgent, 1500); + </script> +</html> diff --git a/plugins/cordova-plugin-inappbrowser/tests/resources/local.pdf b/plugins/cordova-plugin-inappbrowser/tests/resources/local.pdf Binary files differnew file mode 100644 index 00000000..b54f1b75 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/resources/local.pdf diff --git a/plugins/cordova-plugin-inappbrowser/tests/resources/video.html b/plugins/cordova-plugin-inappbrowser/tests/resources/video.html new file mode 100644 index 00000000..64ea3d11 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/resources/video.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<!-- + + 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. + +--> + + +<html> + <head> + <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" /> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 --> + <title>Cordova Mobile Spec</title> + + </head> + <body> + <video width=100% height=100% id="player"> + <source src="http://m.comptoir-info.com/app/beta/sample.mp4"> + <meta property="og:video:secure_url" content="http://m.comptoir-info.com/app/beta/sample.mp4"> + <meta property="og:video:type" content="video/mp4"> + </video> + <div> + <button onclick="document.getElementById('player').play()"> play </button> + <button onclick="document.getElementById('player').pause()"> pause </button> + </div> + </body> +</html> diff --git a/plugins/cordova-plugin-inappbrowser/tests/tests.js b/plugins/cordova-plugin-inappbrowser/tests/tests.js new file mode 100644 index 00000000..a8279868 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/tests/tests.js @@ -0,0 +1,519 @@ +/* + * + * 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'); +var isWindows = cordova.platformId == 'windows'; + +window.alert = window.alert || navigator.notification.alert; + +exports.defineManualTests = function (contentEl, createActionButton) { + + function doOpen(url, target, params, numExpectedRedirects, useWindowOpen) { + numExpectedRedirects = numExpectedRedirects || 0; + useWindowOpen = useWindowOpen || false; + console.log("Opening " + url); + + var counts; + var lastLoadStartURL; + var wasReset = false; + function reset() { + counts = { + 'loaderror': 0, + 'loadstart': 0, + 'loadstop': 0, + 'exit': 0 + }; + lastLoadStartURL = ''; + } + reset(); + + var iab; + var callbacks = { + loaderror: logEvent, + loadstart: logEvent, + loadstop: logEvent, + exit: logEvent + }; + if (useWindowOpen) { + console.log('Use window.open() for url'); + iab = window.open(url, target, params, callbacks); + } + else { + iab = cordova.InAppBrowser.open(url, target, params, callbacks); + } + if (!iab) { + alert('open returned ' + iab); + return; + } + + function logEvent(e) { + console.log('IAB event=' + JSON.stringify(e)); + counts[e.type]++; + // Verify that event.url gets updated on redirects. + if (e.type == 'loadstart') { + if (e.url == lastLoadStartURL) { + alert('Unexpected: loadstart fired multiple times for the same URL.'); + } + lastLoadStartURL = e.url; + } + // Verify the right number of loadstart events were fired. + if (e.type == 'loadstop' || e.type == 'loaderror') { + if (e.url != lastLoadStartURL) { + alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); + } + if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) { + // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL). + if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) { + alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')'); + } + } else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects + 1)) { + alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts['loadstart']); + } + wasReset = true; + numExpectedRedirects = 0; + reset(); + } + // Verify that loadend / loaderror was called. + if (e.type == 'exit') { + var numStopEvents = counts['loadstop'] + counts['loaderror']; + if (numStopEvents === 0 && !wasReset) { + alert('Unexpected: browser closed without a loadstop or loaderror.'); + } else if (numStopEvents > 1) { + alert('Unexpected: got multiple loadstop/loaderror events.'); + } + } + } + + return iab; + } + + function doHookOpen(url, target, params, numExpectedRedirects) { + var originalFunc = window.open; + var wasClobbered = window.hasOwnProperty('open'); + window.open = cordova.InAppBrowser.open; + + try { + doOpen(url, target, params, numExpectedRedirects, true); + } + finally { + if (wasClobbered) { + window.open = originalFunc; + } + else { + console.log('just delete, to restore open from prototype'); + delete window.open; + } + } + } + + function openWithStyle(url, cssUrl, useCallback) { + var iab = doOpen(url, '_blank', 'location=yes'); + var callback = function (results) { + if (results && results.length === 0) { + alert('Results verified'); + } else { + console.log(results); + alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); + } + }; + if (cssUrl) { + iab.addEventListener('loadstop', function (event) { + iab.insertCSS({ file: cssUrl }, useCallback && callback); + }); + } else { + iab.addEventListener('loadstop', function (event) { + iab.insertCSS({ code: '#style-update-literal { \ndisplay: block !important; \n}' }, + useCallback && callback); + }); + } + } + + function openWithScript(url, jsUrl, useCallback) { + var iab = doOpen(url, '_blank', 'location=yes'); + if (jsUrl) { + iab.addEventListener('loadstop', function (event) { + iab.executeScript({ file: jsUrl }, useCallback && function (results) { + if (results && results.length === 0) { + alert('Results verified'); + } else { + console.log(results); + alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); + } + }); + }); + } else { + iab.addEventListener('loadstop', function (event) { + var code = '(function(){\n' + + ' var header = document.getElementById("header");\n' + + ' header.innerHTML = "Script literal successfully injected";\n' + + ' return "abc";\n' + + '})()'; + iab.executeScript({ code: code }, useCallback && function (results) { + if (results && results.length === 1 && results[0] === 'abc') { + alert('Results verified'); + } else { + console.log(results); + alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); + } + }); + }); + } + } + var hiddenwnd = null; + var loadlistener = function (event) { alert('background window loaded '); }; + function openHidden(url, startHidden) { + var shopt = (startHidden) ? 'hidden=yes' : ''; + hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt); + if (!hiddenwnd) { + alert('cordova.InAppBrowser.open returned ' + hiddenwnd); + return; + } + if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener); + } + function showHidden() { + if (!!hiddenwnd) { + hiddenwnd.show(); + } + } + function closeHidden() { + if (!!hiddenwnd) { + hiddenwnd.removeEventListener('loadstop', loadlistener); + hiddenwnd.close(); + hiddenwnd = null; + } + } + + var info_div = '<h1>InAppBrowser</h1>' + + '<div id="info">' + + 'Make sure http://cordova.apache.org and http://google.co.uk and https://www.google.co.uk are white listed. </br>' + + 'Make sure http://www.apple.com is not in the white list.</br>' + + 'In iOS, starred <span style="vertical-align:super">*</span> tests will put the app in a state with no way to return. </br>' + + '<h4>User-Agent: <span id="user-agent"> </span></hr>' + + '</div>'; + + var local_tests = '<h1>Local URL</h1>' + + '<div id="openLocal"></div>' + + 'Expected result: opens successfully in CordovaWebView.' + + '<p/> <div id="openLocalHook"></div>' + + 'Expected result: opens successfully in CordovaWebView (using hook of window.open()).' + + '<p/> <div id="openLocalSelf"></div>' + + 'Expected result: opens successfully in CordovaWebView.' + + '<p/> <div id="openLocalSystem"></div>' + + 'Expected result: fails to open' + + '<p/> <div id="openLocalBlank"></div>' + + 'Expected result: opens successfully in InAppBrowser with locationBar at top.' + + '<p/> <div id="openLocalRandomNoLocation"></div>' + + 'Expected result: opens successfully in InAppBrowser without locationBar.' + + '<p/> <div id="openLocalRandomToolBarBottom"></div>' + + 'Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the bottom.' + + '<p/> <div id="openLocalRandomToolBarTop"></div>' + + 'Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the top.' + + '<p/><div id="openLocalRandomToolBarTopNoLocation"></div>' + + 'Expected result: open successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.'; + + var white_listed_tests = '<h1>White Listed URL</h1>' + + '<div id="openWhiteListed"></div>' + + 'Expected result: open successfully in CordovaWebView to cordova.apache.org' + + '<p/> <div id="openWhiteListedHook"></div>' + + 'Expected result: open successfully in CordovaWebView to cordova.apache.org (using hook of window.open())' + + '<p/> <div id="openWhiteListedSelf"></div>' + + 'Expected result: open successfully in CordovaWebView to cordova.apache.org' + + '<p/> <div id="openWhiteListedSystem"></div>' + + 'Expected result: open successfully in system browser to cordova.apache.org' + + '<p/> <div id="openWhiteListedBlank"></div>' + + 'Expected result: open successfully in InAppBrowser to cordova.apache.org' + + '<p/> <div id="openWhiteListedRandom"></div>' + + 'Expected result: open successfully in InAppBrowser to cordova.apache.org' + + '<p/> <div id="openWhiteListedRandomNoLocation"></div>' + + 'Expected result: open successfully in InAppBrowser to cordova.apache.org with no location bar.'; + + var non_white_listed_tests = '<h1>Non White Listed URL</h1>' + + '<div id="openNonWhiteListed"></div>' + + 'Expected result: open successfully in InAppBrowser to apple.com.' + + '<p/> <div id="openNonWhiteListedHook"></div>' + + 'Expected result: open successfully in InAppBrowser to apple.com (using hook of window.open()).' + + '<p/> <div id="openNonWhiteListedSelf"></div>' + + 'Expected result: open successfully in InAppBrowser to apple.com (_self enforces whitelist).' + + '<p/> <div id="openNonWhiteListedSystem"></div>' + + 'Expected result: open successfully in system browser to apple.com.' + + '<p/> <div id="openNonWhiteListedBlank"></div>' + + 'Expected result: open successfully in InAppBrowser to apple.com.' + + '<p/> <div id="openNonWhiteListedRandom"></div>' + + 'Expected result: open successfully in InAppBrowser to apple.com.' + + '<p/> <div id="openNonWhiteListedRandomNoLocation"></div>' + + 'Expected result: open successfully in InAppBrowser to apple.com without locationBar.'; + + var page_with_redirects_tests = '<h1>Page with redirect</h1>' + + '<div id="openRedirect301"></div>' + + 'Expected result: should 301 and open successfully in InAppBrowser to https://www.google.co.uk.' + + '<p/> <div id="openRedirect302"></div>' + + 'Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.'; + + var pdf_url_tests = '<h1>PDF URL</h1>' + + '<div id="openPDF"></div>' + + 'Expected result: InAppBrowser opens. PDF should render on iOS.' + + '<p/> <div id="openPDFBlank"></div>' + + 'Expected result: InAppBrowser opens. PDF should render on iOS.'; + + var invalid_url_tests = '<h1>Invalid URL</h1>' + + '<div id="openInvalidScheme"></div>' + + 'Expected result: fail to load in InAppBrowser.' + + '<p/> <div id="openInvalidHost"></div>' + + 'Expected result: fail to load in InAppBrowser.' + + '<p/> <div id="openInvalidMissing"></div>' + + 'Expected result: fail to load in InAppBrowser (404).'; + + var css_js_injection_tests = '<h1>CSS / JS Injection</h1>' + + '<div id="openOriginalDocument"></div>' + + 'Expected result: open successfully in InAppBrowser without text "Style updated from..."' + + '<p/> <div id="openCSSInjection"></div>' + + 'Expected result: open successfully in InAppBrowser with "Style updated from file".' + + '<p/> <div id="openCSSInjectionCallback"></div>' + + 'Expected result: open successfully in InAppBrowser with "Style updated from file", and alert dialog with text "Results verified".' + + '<p/> <div id="openCSSLiteralInjection"></div>' + + 'Expected result: open successfully in InAppBrowser with "Style updated from literal".' + + '<p/> <div id="openCSSLiteralInjectionCallback"></div>' + + 'Expected result: open successfully in InAppBrowser with "Style updated from literal", and alert dialog with text "Results verified".' + + '<p/> <div id="openScriptInjection"></div>' + + 'Expected result: open successfully in InAppBrowser with text "Script file successfully injected".' + + '<p/> <div id="openScriptInjectionCallback"></div>' + + 'Expected result: open successfully in InAppBrowser with text "Script file successfully injected" and alert dialog with the text "Results verified".' + + '<p/> <div id="openScriptLiteralInjection"></div>' + + 'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" .' + + '<p/> <div id="openScriptLiteralInjectionCallback"></div>' + + 'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" and alert dialog with the text "Results verified".'; + + var open_hidden_tests = '<h1>Open Hidden </h1>' + + '<div id="openHidden"></div>' + + 'Expected result: no additional browser window. Alert appears with the text "background window loaded".' + + '<p/> <div id="showHidden"></div>' + + 'Expected result: after first clicking on previous test "create hidden", open successfully in InAppBrowser to https://www.google.co.uk.' + + '<p/> <div id="closeHidden"></div>' + + 'Expected result: no output. But click on "show hidden" again and nothing should be shown.' + + '<p/> <div id="openHiddenShow"></div>' + + 'Expected result: open successfully in InAppBrowser to https://www.google.co.uk'; + + var clearing_cache_tests = '<h1>Clearing Cache</h1>' + + '<div id="openClearCache"></div>' + + 'Expected result: ?' + + '<p/> <div id="openClearSessionCache"></div>' + + 'Expected result: ?'; + + var video_tag_tests = '<h1>Video tag</h1>' + + '<div id="openRemoteVideo"></div>' + + 'Expected result: open successfully in InAppBrowser with an embedded video that works after clicking the "play" button.'; + + var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' + + '<div id="openAnchor1"></div>' + + 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the top as normal.' + + '<p/> <div id="openAnchor2"></div>' + + 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.'; + + // CB-7490 We need to wrap this code due to Windows security restrictions + // see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details + if (window.MSApp && window.MSApp.execUnsafeLocalFunction) { + MSApp.execUnsafeLocalFunction(function() { + contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests + + css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests; + }); + } else { + contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests + + css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests; + } + + document.getElementById("user-agent").textContent = navigator.userAgent; + + // we are already in cdvtests directory + var basePath = 'iab-resources/'; + var localhtml = basePath + 'local.html', + localpdf = basePath + 'local.pdf', + injecthtml = basePath + 'inject.html', + injectjs = isWindows ? basePath + 'inject.js' : 'inject.js', + injectcss = isWindows ? basePath + 'inject.css' : 'inject.css', + videohtml = basePath + 'video.html'; + + //Local + createActionButton('target=Default', function () { + doOpen(localhtml); + }, 'openLocal'); + createActionButton('target=Default (window.open)', function () { + doHookOpen(localhtml); + }, 'openLocalHook'); + createActionButton('target=_self', function () { + doOpen(localhtml, '_self'); + }, 'openLocalSelf'); + createActionButton('target=_system', function () { + doOpen(localhtml, '_system'); + }, 'openLocalSystem'); + createActionButton('target=_blank', function () { + doOpen(localhtml, '_blank'); + }, 'openLocalBlank'); + createActionButton('target=Random, location=no, disallowoverscroll=yes', function () { + doOpen(localhtml, 'random_string', 'location=no, disallowoverscroll=yes'); + }, 'openLocalRandomNoLocation'); + createActionButton('target=Random, toolbarposition=bottom', function () { + doOpen(localhtml, 'random_string', 'toolbarposition=bottom'); + }, 'openLocalRandomToolBarBottom'); + createActionButton('target=Random, toolbarposition=top', function () { + doOpen(localhtml, 'random_string', 'toolbarposition=top'); + }, 'openLocalRandomToolBarTop'); + createActionButton('target=Random, toolbarposition=top, location=no', function () { + doOpen(localhtml, 'random_string', 'toolbarposition=top,location=no'); + }, 'openLocalRandomToolBarTopNoLocation'); + + //White Listed + createActionButton('* target=Default', function () { + doOpen('http://cordova.apache.org'); + }, 'openWhiteListed'); + createActionButton('* target=Default (window.open)', function () { + doHookOpen('http://cordova.apache.org'); + }, 'openWhiteListedHook'); + createActionButton('* target=_self', function () { + doOpen('http://cordova.apache.org', '_self'); + }, 'openWhiteListedSelf'); + createActionButton('target=_system', function () { + doOpen('http://cordova.apache.org', '_system'); + }, 'openWhiteListedSystem'); + createActionButton('target=_blank', function () { + doOpen('http://cordova.apache.org', '_blank'); + }, 'openWhiteListedBlank'); + createActionButton('target=Random', function () { + doOpen('http://cordova.apache.org', 'random_string'); + }, 'openWhiteListedRandom'); + createActionButton('* target=Random, no location bar', function () { + doOpen('http://cordova.apache.org', 'random_string', 'location=no'); + }, 'openWhiteListedRandomNoLocation'); + + //Non White Listed + createActionButton('target=Default', function () { + doOpen('http://www.apple.com'); + }, 'openNonWhiteListed'); + createActionButton('target=Default (window.open)', function () { + doHookOpen('http://www.apple.com'); + }, 'openNonWhiteListedHook'); + createActionButton('target=_self', function () { + doOpen('http://www.apple.com', '_self'); + }, 'openNonWhiteListedSelf'); + createActionButton('target=_system', function () { + doOpen('http://www.apple.com', '_system'); + }, 'openNonWhiteListedSystem'); + createActionButton('target=_blank', function () { + doOpen('http://www.apple.com', '_blank'); + }, 'openNonWhiteListedBlank'); + createActionButton('target=Random', function () { + doOpen('http://www.apple.com', 'random_string'); + }, 'openNonWhiteListedRandom'); + createActionButton('* target=Random, no location bar', function () { + doOpen('http://www.apple.com', 'random_string', 'location=no'); + }, 'openNonWhiteListedRandomNoLocation'); + + //Page with redirect + createActionButton('http://google.co.uk', function () { + doOpen('http://google.co.uk', 'random_string', '', 1); + }, 'openRedirect301'); + createActionButton('http://goo.gl/pUFqg', function () { + doOpen('http://goo.gl/pUFqg', 'random_string', '', 2); + }, 'openRedirect302'); + + //PDF URL + createActionButton('Remote URL', function () { + doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf'); + }, 'openPDF'); + createActionButton('Local URL', function () { + doOpen(localpdf, '_blank'); + }, 'openPDFBlank'); + + //Invalid URL + createActionButton('Invalid Scheme', function () { + doOpen('x-ttp://www.invalid.com/', '_blank'); + }, 'openInvalidScheme'); + createActionButton('Invalid Host', function () { + doOpen('http://www.inv;alid.com/', '_blank'); + }, 'openInvalidHost'); + createActionButton('Missing Local File', function () { + doOpen('nonexistent.html', '_blank'); + }, 'openInvalidMissing'); + + //CSS / JS injection + createActionButton('Original Document', function () { + doOpen(injecthtml, '_blank'); + }, 'openOriginalDocument'); + createActionButton('CSS File Injection', function () { + openWithStyle(injecthtml, injectcss); + }, 'openCSSInjection'); + createActionButton('CSS File Injection (callback)', function () { + openWithStyle(injecthtml, injectcss, true); + }, 'openCSSInjectionCallback'); + createActionButton('CSS Literal Injection', function () { + openWithStyle(injecthtml); + }, 'openCSSLiteralInjection'); + createActionButton('CSS Literal Injection (callback)', function () { + openWithStyle(injecthtml, null, true); + }, 'openCSSLiteralInjectionCallback'); + createActionButton('Script File Injection', function () { + openWithScript(injecthtml, injectjs); + }, 'openScriptInjection'); + createActionButton('Script File Injection (callback)', function () { + openWithScript(injecthtml, injectjs, true); + }, 'openScriptInjectionCallback'); + createActionButton('Script Literal Injection', function () { + openWithScript(injecthtml); + }, 'openScriptLiteralInjection'); + createActionButton('Script Literal Injection (callback)', function () { + openWithScript(injecthtml, null, true); + }, 'openScriptLiteralInjectionCallback'); + + //Open hidden + createActionButton('Create Hidden', function () { + openHidden('https://www.google.co.uk', true); + }, 'openHidden'); + createActionButton('Show Hidden', function () { + showHidden(); + }, 'showHidden'); + createActionButton('Close Hidden', function () { + closeHidden(); + }, 'closeHidden'); + createActionButton('google.co.uk Not Hidden', function () { + openHidden('https://www.google.co.uk', false); + }, 'openHiddenShow'); + + //Clearing cache + createActionButton('Clear Browser Cache', function () { + doOpen('https://www.google.co.uk', '_blank', 'clearcache=yes'); + }, 'openClearCache'); + createActionButton('Clear Session Cache', function () { + doOpen('https://www.google.co.uk', '_blank', 'clearsessioncache=yes'); + }, 'openClearSessionCache'); + + //Video tag + createActionButton('Remote Video', function () { + doOpen(videohtml, '_blank'); + }, 'openRemoteVideo'); + + //Local With Anchor Tag + createActionButton('Anchor1', function () { + doOpen(localhtml + '#bogusanchor', '_blank'); + }, 'openAnchor1'); + createActionButton('Anchor2', function () { + doOpen(localhtml + '#anchor2', '_blank'); + }, 'openAnchor2'); +}; + diff --git a/plugins/cordova-plugin-inappbrowser/www/inappbrowser.css b/plugins/cordova-plugin-inappbrowser/www/inappbrowser.css new file mode 100644 index 00000000..4dfb503e --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/www/inappbrowser.css @@ -0,0 +1,42 @@ +/* + * 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. + */ + +.inAppBrowserWrap { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-size: 100%; + vertical-align: baseline; + background: 0 0; + position: fixed; + top: 0; + left: 0; + width: calc(100% - 80px); + height: calc(100% - 80px); + z-index: 9999999; + border: 40px solid #bfbfbf; + border: 40px solid rgba(0, 0, 0, 0.25); +} + +.inAppBrowserWrapFullscreen { + width: 100%; + height: 100%; + border: 0; +} diff --git a/plugins/cordova-plugin-inappbrowser/www/inappbrowser.js b/plugins/cordova-plugin-inappbrowser/www/inappbrowser.js new file mode 100644 index 00000000..a85f27e9 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/www/inappbrowser.js @@ -0,0 +1,104 @@ +/* + * + * 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 exec = require('cordova/exec'); +var channel = require('cordova/channel'); +var modulemapper = require('cordova/modulemapper'); +var urlutil = require('cordova/urlutil'); + +function InAppBrowser() { + this.channels = { + 'loadstart': channel.create('loadstart'), + 'loadstop' : channel.create('loadstop'), + 'loaderror' : channel.create('loaderror'), + 'exit' : channel.create('exit') + }; +} + +InAppBrowser.prototype = { + _eventHandler: function (event) { + if (event && (event.type in this.channels)) { + this.channels[event.type].fire(event); + } + }, + close: function (eventname) { + exec(null, null, "InAppBrowser", "close", []); + }, + show: function (eventname) { + exec(null, null, "InAppBrowser", "show", []); + }, + addEventListener: function (eventname,f) { + if (eventname in this.channels) { + this.channels[eventname].subscribe(f); + } + }, + removeEventListener: function(eventname, f) { + if (eventname in this.channels) { + this.channels[eventname].unsubscribe(f); + } + }, + + executeScript: function(injectDetails, cb) { + if (injectDetails.code) { + exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]); + } else if (injectDetails.file) { + exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]); + } else { + throw new Error('executeScript requires exactly one of code or file to be specified'); + } + }, + + insertCSS: function(injectDetails, cb) { + if (injectDetails.code) { + exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]); + } else if (injectDetails.file) { + exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]); + } else { + throw new Error('insertCSS requires exactly one of code or file to be specified'); + } + } +}; + +module.exports = function(strUrl, strWindowName, strWindowFeatures, callbacks) { + // Don't catch calls that write to existing frames (e.g. named iframes). + if (window.frames && window.frames[strWindowName]) { + var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open'); + return origOpenFunc.apply(window, arguments); + } + + strUrl = urlutil.makeAbsolute(strUrl); + var iab = new InAppBrowser(); + + callbacks = callbacks || {}; + for (var callbackName in callbacks) { + iab.addEventListener(callbackName, callbacks[callbackName]); + } + + var cb = function(eventname) { + iab._eventHandler(eventname); + }; + + strWindowFeatures = strWindowFeatures || ""; + + exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); + return iab; +}; + diff --git a/plugins/cordova-plugin-inappbrowser/www/windows8/InAppBrowserProxy.js b/plugins/cordova-plugin-inappbrowser/www/windows8/InAppBrowserProxy.js new file mode 100644 index 00000000..944284e5 --- /dev/null +++ b/plugins/cordova-plugin-inappbrowser/www/windows8/InAppBrowserProxy.js @@ -0,0 +1,111 @@ +/* + * + * 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. + * +*/ + +/*jslint sloppy:true */ +/*global Windows:true, require, document, setTimeout, window, module */ + + + +var cordova = require('cordova'), + channel = require('cordova/channel'); + +var browserWrap; + +var IAB = { + + close: function (win, lose) { + if (browserWrap) { + browserWrap.parentNode.removeChild(browserWrap); + browserWrap = null; + } + }, + show: function (win, lose) { + /* empty block, ran out of bacon? + if (browserWrap) { + + }*/ + }, + open: function (win, lose, args) { + var strUrl = args[0], + target = args[1], + features = args[2], + url, + elem; + + if (target === "_system") { + url = new Windows.Foundation.Uri(strUrl); + Windows.System.Launcher.launchUriAsync(url); + } else if (target === "_blank") { + if (!browserWrap) { + browserWrap = document.createElement("div"); + browserWrap.style.position = "absolute"; + browserWrap.style.width = (window.innerWidth - 80) + "px"; + browserWrap.style.height = (window.innerHeight - 80) + "px"; + browserWrap.style.borderWidth = "40px"; + browserWrap.style.borderStyle = "solid"; + browserWrap.style.borderColor = "rgba(0,0,0,0.25)"; + + browserWrap.onclick = function () { + setTimeout(function () { + IAB.close(); + }, 0); + }; + + document.body.appendChild(browserWrap); + } + + elem = document.createElement("iframe"); + elem.style.width = (window.innerWidth - 80) + "px"; + elem.style.height = (window.innerHeight - 80) + "px"; + elem.style.borderWidth = "0px"; + elem.name = "targetFrame"; + elem.src = strUrl; + + window.addEventListener("resize", function () { + if (browserWrap && elem) { + elem.style.width = (window.innerWidth - 80) + "px"; + elem.style.height = (window.innerHeight - 80) + "px"; + } + }); + + browserWrap.appendChild(elem); + } else { + window.location = strUrl; + } + + //var object = new WinJS.UI.HtmlControl(elem, { uri: strUrl }); + + }, + + injectScriptCode: function (code, bCB) { + + // "(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c); })(document)" + }, + + injectScriptFile: function (file, bCB) { + + } +}; + +module.exports = IAB; + + +require("cordova/exec/proxy").add("InAppBrowser", module.exports); diff --git a/plugins/cordova-plugin-whitelist/CONTRIBUTING.md b/plugins/cordova-plugin-whitelist/CONTRIBUTING.md new file mode 100644 index 00000000..e4a178f5 --- /dev/null +++ b/plugins/cordova-plugin-whitelist/CONTRIBUTING.md @@ -0,0 +1,37 @@ +<!-- +# +# 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. +# +--> + +# Contributing to Apache Cordova + +Anyone can contribute to Cordova. And we need your contributions. + +There are multiple ways to contribute: report bugs, improve the docs, and +contribute code. + +For instructions on this, start with the +[contribution overview](http://cordova.apache.org/#contribute). + +The details are explained there, but the important items are: + - Sign and submit an Apache ICLA (Contributor License Agreement). + - Have a Jira issue open that corresponds to your contribution. + - Run the tests so your patch doesn't break existing functionality. + +We look forward to your contributions! diff --git a/plugins/cordova-plugin-whitelist/LICENSE b/plugins/cordova-plugin-whitelist/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/plugins/cordova-plugin-whitelist/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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.
\ No newline at end of file diff --git a/plugins/cordova-plugin-whitelist/NOTICE b/plugins/cordova-plugin-whitelist/NOTICE new file mode 100644 index 00000000..8ec56a52 --- /dev/null +++ b/plugins/cordova-plugin-whitelist/NOTICE @@ -0,0 +1,5 @@ +Apache Cordova +Copyright 2012 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/plugins/cordova-plugin-whitelist/README.md b/plugins/cordova-plugin-whitelist/README.md new file mode 100644 index 00000000..77944c31 --- /dev/null +++ b/plugins/cordova-plugin-whitelist/README.md @@ -0,0 +1,144 @@ +<!--- + license: 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. +--> + +# cordova-plugin-whitelist + +This plugin implements a whitelist policy for navigating the application webview on Cordova 4.0 + +## Supported Cordova Platforms + +* Android 4.0.0 or above +* iOS 4.0.0 or above + +## Navigation Whitelist +Controls which URLs the WebView itself can be navigated to. Applies to +top-level navigations only. + +Quirks: on Android it also applies to iframes for non-http(s) schemes. + +By default, navigations only to `file://` URLs, are allowed. To allow other +other URLs, you must add `<allow-navigation>` tags to your `config.xml`: + + <!-- Allow links to example.com --> + <allow-navigation href="http://example.com/*" /> + + <!-- Wildcards are allowed for the protocol, as a prefix + to the host, or as a suffix to the path --> + <allow-navigation href="*://*.example.com/*" /> + + <!-- A wildcard can be used to whitelist the entire network, + over HTTP and HTTPS. + *NOT RECOMMENDED* --> + <allow-navigation href="*" /> + + <!-- The above is equivalent to these three declarations --> + <allow-navigation href="http://*/*" /> + <allow-navigation href="https://*/*" /> + <allow-navigation href="data:*" /> + +## Intent Whitelist +Controls which URLs the app is allowed to ask the system to open. +By default, no external URLs are allowed. + +On Android, this equates to sending an intent of type BROWSEABLE. + +This whitelist does not apply to plugins, only hyperlinks and calls to `window.open()`. + +In `config.xml`, add `<allow-intent>` tags, like this: + + <!-- Allow links to web pages to open in a browser --> + <allow-intent href="http://*/*" /> + <allow-intent href="https://*/*" /> + + <!-- Allow links to example.com to open in a browser --> + <allow-intent href="http://example.com/*" /> + + <!-- Wildcards are allowed for the protocol, as a prefix + to the host, or as a suffix to the path --> + <allow-intent href="*://*.example.com/*" /> + + <!-- Allow SMS links to open messaging app --> + <allow-intent href="sms:*" /> + + <!-- Allow tel: links to open the dialer --> + <allow-intent href="tel:*" /> + + <!-- Allow geo: links to open maps --> + <allow-intent href="geo:*" /> + + <!-- Allow all unrecognized URLs to open installed apps + *NOT RECOMMENDED* --> + <allow-intent href="*" /> + +## Network Request Whitelist +Controls which network requests (images, XHRs, etc) are allowed to be made (via cordova native hooks). + +Note: We suggest you use a Content Security Policy (see below), which is more secure. This whitelist is mostly historical for webviews which do not support CSP. + +In `config.xml`, add `<access>` tags, like this: + + <!-- Allow images, xhrs, etc. to google.com --> + <access origin="http://google.com" /> + <access origin="https://google.com" /> + + <!-- Access to the subdomain maps.google.com --> + <access origin="http://maps.google.com" /> + + <!-- Access to all the subdomains on google.com --> + <access origin="http://*.google.com" /> + + <!-- Enable requests to content: URLs --> + <access origin="content:///*" /> + + <!-- Don't block any requests --> + <access origin="*" /> + +Without any `<access>` tags, only requests to `file://` URLs are allowed. However, the default Cordova application includes `<access origin="*">` by default. + +Quirk: Android also allows requests to https://ssl.gstatic.com/accessibility/javascript/android/ by default, since this is required for TalkBack to function properly. + +### Content Security Policy +Controls which network requests (images, XHRs, etc) are allowed to be made (via webview directly). + +On Android and iOS, the network request whitelist (see above) is not able to filter all types of requests (e.g. `<video>` & WebSockets are not blocked). So, in addition to the whitelist, you should use a [Content Security Policy](http://content-security-policy.com/) `<meta>` tag on all of your pages. + +On Android, support for CSP within the system webview starts with KitKat (but is available on all versions using Crosswalk WebView). + +Here are some example CSP declarations for your `.html` pages: + + <!-- Good default declaration: + * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication + * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly + * Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: + * Enable inline JS: add 'unsafe-inline' to default-src + * Enable eval(): add 'unsafe-eval' to default-src + --> + <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *"> + + <!-- Allow requests to foo.com --> + <meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com"> + + <!-- Enable all requests, inline styles, and eval() --> + <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> + + <!-- Allow XHRs via https only --> + <meta http-equiv="Content-Security-Policy" content="default-src 'self' https:"> + + <!-- Allow iframe to https://cordova.apache.org/ --> + <meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org"> diff --git a/plugins/cordova-plugin-whitelist/RELEASENOTES.md b/plugins/cordova-plugin-whitelist/RELEASENOTES.md new file mode 100644 index 00000000..703552ca --- /dev/null +++ b/plugins/cordova-plugin-whitelist/RELEASENOTES.md @@ -0,0 +1,28 @@ +<!-- +# +# 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. +# +--> +# Release Notes + +### 1.0.0 (Mar 25, 2015) +* CB-8739 added missing license headers +* Add @Override to CustomConfigXmlParser methods +* Change ID to cordova-plugin-whitelist rather than reverse-DNS-style +* Tweak CSP examples in README +* CB-8660 remove extra commas from package.json diff --git a/plugins/cordova-plugin-whitelist/package.json b/plugins/cordova-plugin-whitelist/package.json new file mode 100644 index 00000000..3bffcbcc --- /dev/null +++ b/plugins/cordova-plugin-whitelist/package.json @@ -0,0 +1,34 @@ +{ + "name": "cordova-plugin-whitelist", + "version": "1.0.1-dev", + "description": "Cordova Whitelist Plugin", + "cordova": { + "platforms": [ + "android", + "ios" + ] + }, + "repository": { + "type": "git", + "url": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-whitelist.git" + }, + "keywords": [ + "cordova", + "whitelist", + "ecosystem:cordova", + "cordova-android", + "cordova-ios" + ], + "engines": [ + { + "name": "cordova-android", + "version": ">=4.0.0-dev" + }, + { + "name": "cordova-ios", + "version": ">=4.0.0-dev" + } + ], + "author": "Apache Software Foundation", + "license": "Apache 2.0" +} diff --git a/plugins/cordova-plugin-whitelist/plugin.xml b/plugins/cordova-plugin-whitelist/plugin.xml new file mode 100644 index 00000000..6e6b0e0a --- /dev/null +++ b/plugins/cordova-plugin-whitelist/plugin.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="cordova-plugin-whitelist" + version="1.0.1-dev"> + <name>Whitelist</name> + <description>Cordova Network Whitelist Plugin</description> + <license>Apache 2.0</license> + <keywords>cordova,whitelist,policy</keywords> + + <engines> + <engine name="cordova-android" version=">=4.0.0-dev" /> + </engines> + + <platform name="android"> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="Whitelist" > + <param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin"/> + <param name="onload" value="true" /> + </feature> + </config-file> + + <source-file src="src/android/WhitelistPlugin.java" target-dir="src/org/apache/cordova/whitelist" /> + + <js-module src="whitelist.js" name="whitelist"> + <runs /> + </js-module> + </platform> +</plugin> diff --git a/plugins/cordova-plugin-whitelist/src/android/WhitelistPlugin.java b/plugins/cordova-plugin-whitelist/src/android/WhitelistPlugin.java new file mode 100644 index 00000000..4e4f57e1 --- /dev/null +++ b/plugins/cordova-plugin-whitelist/src/android/WhitelistPlugin.java @@ -0,0 +1,161 @@ +/* + 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. +*/ + +package org.apache.cordova.whitelist; + +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.ConfigXmlParser; +import org.apache.cordova.Whitelist; +import org.xmlpull.v1.XmlPullParser; + +import android.content.Context; +import android.util.Log; + +public class WhitelistPlugin extends CordovaPlugin { + private static final String LOG_TAG = "WhitelistPlugin"; + private Whitelist allowedNavigations; + private Whitelist allowedIntents; + private Whitelist allowedRequests; + + // Used when instantiated via reflection by PluginManager + public WhitelistPlugin() { + } + // These can be used by embedders to allow Java-configuration of whitelists. + public WhitelistPlugin(Context context) { + this(new Whitelist(), new Whitelist(), null); + new CustomConfigXmlParser().parse(context); + } + public WhitelistPlugin(XmlPullParser xmlParser) { + this(new Whitelist(), new Whitelist(), null); + new CustomConfigXmlParser().parse(xmlParser); + } + public WhitelistPlugin(Whitelist allowedNavigations, Whitelist allowedIntents, Whitelist allowedRequests) { + if (allowedRequests == null) { + allowedRequests = new Whitelist(); + allowedRequests.addWhiteListEntry("file:///*", false); + allowedRequests.addWhiteListEntry("data:*", false); + } + this.allowedNavigations = allowedNavigations; + this.allowedIntents = allowedIntents; + this.allowedRequests = allowedRequests; + } + @Override + public void pluginInitialize() { + if (allowedNavigations == null) { + allowedNavigations = new Whitelist(); + allowedIntents = new Whitelist(); + allowedRequests = new Whitelist(); + new CustomConfigXmlParser().parse(webView.getContext()); + } + } + + private class CustomConfigXmlParser extends ConfigXmlParser { + @Override + public void handleStartTag(XmlPullParser xml) { + String strNode = xml.getName(); + if (strNode.equals("content")) { + String startPage = xml.getAttributeValue(null, "src"); + allowedNavigations.addWhiteListEntry(startPage, false); + } else if (strNode.equals("allow-navigation")) { + String origin = xml.getAttributeValue(null, "href"); + if ("*".equals(origin)) { + allowedNavigations.addWhiteListEntry("http://*/*", false); + allowedNavigations.addWhiteListEntry("https://*/*", false); + allowedNavigations.addWhiteListEntry("data:*", false); + } else { + allowedNavigations.addWhiteListEntry(origin, false); + } + } else if (strNode.equals("allow-intent")) { + String origin = xml.getAttributeValue(null, "href"); + allowedIntents.addWhiteListEntry(origin, false); + } else if (strNode.equals("access")) { + String origin = xml.getAttributeValue(null, "origin"); + String subdomains = xml.getAttributeValue(null, "subdomains"); + boolean external = (xml.getAttributeValue(null, "launch-external") != null); + if (origin != null) { + if (external) { + Log.w(LOG_TAG, "Found <access launch-external> within config.xml. Please use <allow-intent> instead."); + allowedIntents.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); + } else { + if ("*".equals(origin)) { + allowedRequests.addWhiteListEntry("http://*/*", false); + allowedRequests.addWhiteListEntry("https://*/*", false); + } else { + allowedRequests.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); + } + } + } + } + } + @Override + public void handleEndTag(XmlPullParser xml) { + } + } + + @Override + public Boolean shouldAllowNavigation(String url) { + if (allowedNavigations.isUrlWhiteListed(url)) { + return true; + } + return null; // Default policy + } + + @Override + public Boolean shouldAllowRequest(String url) { + if (Boolean.TRUE == shouldAllowNavigation(url)) { + return true; + } + if (allowedRequests.isUrlWhiteListed(url)) { + return true; + } + return null; // Default policy + } + + @Override + public Boolean shouldOpenExternalUrl(String url) { + if (allowedIntents.isUrlWhiteListed(url)) { + return true; + } + return null; // Default policy + } + + public Whitelist getAllowedNavigations() { + return allowedNavigations; + } + + public void setAllowedNavigations(Whitelist allowedNavigations) { + this.allowedNavigations = allowedNavigations; + } + + public Whitelist getAllowedIntents() { + return allowedIntents; + } + + public void setAllowedIntents(Whitelist allowedIntents) { + this.allowedIntents = allowedIntents; + } + + public Whitelist getAllowedRequests() { + return allowedRequests; + } + + public void setAllowedRequests(Whitelist allowedRequests) { + this.allowedRequests = allowedRequests; + } +} diff --git a/plugins/cordova-plugin-whitelist/src/ios/CDVNavigationWhitelistPlugin.h b/plugins/cordova-plugin-whitelist/src/ios/CDVNavigationWhitelistPlugin.h new file mode 100644 index 00000000..d0b93654 --- /dev/null +++ b/plugins/cordova-plugin-whitelist/src/ios/CDVNavigationWhitelistPlugin.h @@ -0,0 +1,31 @@ +/* + 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. + */ + +#import <UIKit/UIKit.h> +#import <Cordova/CDVPlugin.h> +#import <Cordova/CDVWhitelist.h> + +@interface CDVNavigationWhitelistPlugin : CDVPlugin {} + +@property (nonatomic, readonly, strong) CDVWhitelist* whitelist; // readonly for public + +- (BOOL)shouldAllowNavigationToURL:(NSURL *)url; +- (BOOL)shouldAllowRequestForURL:(NSURL *)url; + +@end diff --git a/plugins/cordova-plugin-whitelist/src/ios/CDVNavigationWhitelistPlugin.m b/plugins/cordova-plugin-whitelist/src/ios/CDVNavigationWhitelistPlugin.m new file mode 100644 index 00000000..5895e89b --- /dev/null +++ b/plugins/cordova-plugin-whitelist/src/ios/CDVNavigationWhitelistPlugin.m @@ -0,0 +1,89 @@ +/* + 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. + */ + +#import "CDVNavigationWhitelistPlugin.h" +#import <Cordova/CDVViewController.h> + +#pragma mark CDVNavigationWhitelistConfigParser + +@interface CDVNavigationWhitelistConfigParser : NSObject <NSXMLParserDelegate> {} + +@property (nonatomic, strong) NSMutableArray* whitelistHosts; + +@end + +@implementation CDVNavigationWhitelistConfigParser + +@synthesize whitelistHosts; + +- (id)init +{ + self = [super init]; + if (self != nil) { + self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:30]; + [self.whitelistHosts addObject:@"file:///*"]; + [self.whitelistHosts addObject:@"content:///*"]; + [self.whitelistHosts addObject:@"data:///*"]; + } + return self; +} + +- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict +{ + if ([elementName isEqualToString:@"allow-navigation"]) { + [whitelistHosts addObject:attributeDict[@"href"]]; + } +} + +- (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName +{ +} + +- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError +{ + NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]); +} + + +@end + +#pragma mark CDVNavigationWhitelistPlugin + +@interface CDVNavigationWhitelistPlugin () {} +@property (nonatomic, strong) CDVWhitelist* whitelist; +@end + +@implementation CDVNavigationWhitelistPlugin + +@synthesize whitelist; + +- (void)setViewController:(UIViewController *)viewController +{ + if ([viewController isKindOfClass:[CDVViewController class]]) { + CDVWhitelistConfigParser *whitelistConfigParser = [[CDVWhitelistConfigParser alloc] init]; + [(CDVViewController *)viewController parseSettingsWithParser:whitelistConfigParser]; + self.whitelist = [[CDVWhitelist alloc] initWithArray:whitelistConfigParser.whitelistHosts]; + } +} + +- (BOOL)shouldAllowNavigationToURL:(NSURL *)url +{ + return [self.whitelist URLIsAllowed:url]; +} +@end diff --git a/plugins/cordova-plugin-whitelist/whitelist.js b/plugins/cordova-plugin-whitelist/whitelist.js new file mode 100644 index 00000000..74d7a99d --- /dev/null +++ b/plugins/cordova-plugin-whitelist/whitelist.js @@ -0,0 +1,27 @@ +/* + * 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. + * +*/ + +if (!document.querySelector('meta[http-equiv=Content-Security-Policy]')) { + var msg = 'No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.'; + console.error(msg); + setInterval(function() { + console.warn(msg); + }, 10000); +} diff --git a/plugins/fetch.json b/plugins/fetch.json new file mode 100644 index 00000000..6ce7fb89 --- /dev/null +++ b/plugins/fetch.json @@ -0,0 +1,59 @@ +{ + "org.apache.cordova.device": { + "source": { + "type": "registry", + "id": "org.apache.cordova.device" + } + }, + "org.apache.cordova.console": { + "source": { + "type": "registry", + "id": "org.apache.cordova.console" + } + }, + "com.ionic.keyboard": { + "source": { + "type": "registry", + "id": "com.ionic.keyboard" + }, + "is_top_level": true, + "variables": {} + }, + "org.apache.cordova.splashscreen": { + "source": { + "type": "registry", + "id": "org.apache.cordova.splashscreen" + }, + "is_top_level": true, + "variables": {} + }, + "org.apache.cordova.statusbar": { + "source": { + "type": "registry", + "id": "org.apache.cordova.statusbar" + } + }, + "cordova-plugin-whitelist": { + "source": { + "type": "git", + "url": "https://github.com/apache/cordova-plugin-whitelist.git", + "subdir": "." + } + }, + "cordova-plugin-crosswalk-webview": { + "source": { + "type": "local", + "path": "engine/cordova-crosswalk-engine-c0.7.1" + }, + "is_top_level": true, + "variables": {} + }, + "cordova-plugin-inappbrowser": { + "source": { + "type": "registry", + "id": "cordova-plugin-inappbrowser" + }, + "is_top_level": true, + "variables": {} + } +}
\ No newline at end of file diff --git a/plugins/ios.json b/plugins/ios.json new file mode 100644 index 00000000..3df27b77 --- /dev/null +++ b/plugins/ios.json @@ -0,0 +1,85 @@ +{ + "prepare_queue": { + "installed": [], + "uninstalled": [] + }, + "config_munge": { + "files": { + "config.xml": { + "parents": { + "/*": [ + { + "xml": "<feature name=\"Keyboard\"><param name=\"ios-package\" onload=\"true\" value=\"IonicKeyboard\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"Console\"><param name=\"ios-package\" value=\"CDVLogger\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"Device\"><param name=\"ios-package\" value=\"CDVDevice\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"SplashScreen\"><param name=\"ios-package\" value=\"CDVSplashScreen\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { + "xml": "<feature name=\"StatusBar\"><param name=\"ios-package\" value=\"CDVStatusBar\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { + "xml": "<preference name=\"StatusBarOverlaysWebView\" value=\"true\" />", + "count": 1 + }, + { + "xml": "<preference name=\"StatusBarStyle\" value=\"lightcontent\" />", + "count": 1 + }, + { + "xml": "<feature name=\"InAppBrowser\"><param name=\"ios-package\" value=\"CDVInAppBrowser\" /></feature>", + "count": 1 + } + ] + } + }, + "framework": { + "parents": { + "CoreGraphics.framework": [ + { + "xml": false, + "count": 2 + } + ] + } + } + } + }, + "installed_plugins": { + "com.ionic.keyboard": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.console": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.device": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.splashscreen": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "org.apache.cordova.statusbar": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "cordova-plugin-whitelist": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "cordova-plugin-crosswalk-webview": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + }, + "cordova-plugin-inappbrowser": { + "PACKAGE_NAME": "com.ionicframework.zmninja469849" + } + }, + "dependent_plugins": {} +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/CONTRIBUTING.md b/plugins/org.apache.cordova.console/CONTRIBUTING.md new file mode 100644 index 00000000..f7dbcaba --- /dev/null +++ b/plugins/org.apache.cordova.console/CONTRIBUTING.md @@ -0,0 +1,37 @@ +<!-- +# +# 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. +# +--> + +# Contributing to Apache Cordova + +Anyone can contribute to Cordova. And we need your contributions. + +There are multiple ways to contribute: report bugs, improve the docs, and +contribute code. + +For instructions on this, start with the +[contribution overview](http://cordova.apache.org/#contribute). + +The details are explained there, but the important items are: + - Sign and submit an Apache ICLA (Contributor License Agreement). + - Have a Jira issue open that corresponds to your contribution. + - Run the tests so your patch doesn't break existing functionality. + +We look forward to your contributions! diff --git a/plugins/org.apache.cordova.console/LICENSE b/plugins/org.apache.cordova.console/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/plugins/org.apache.cordova.console/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/NOTICE b/plugins/org.apache.cordova.console/NOTICE new file mode 100644 index 00000000..8ec56a52 --- /dev/null +++ b/plugins/org.apache.cordova.console/NOTICE @@ -0,0 +1,5 @@ +Apache Cordova +Copyright 2012 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/plugins/org.apache.cordova.console/README.md b/plugins/org.apache.cordova.console/README.md new file mode 100644 index 00000000..c7552cb1 --- /dev/null +++ b/plugins/org.apache.cordova.console/README.md @@ -0,0 +1,22 @@ +<!--- + license: 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. +--> + +# org.apache.cordova.console + +Plugin documentation: [doc/index.md](doc/index.md) diff --git a/plugins/org.apache.cordova.console/RELEASENOTES.md b/plugins/org.apache.cordova.console/RELEASENOTES.md new file mode 100644 index 00000000..6f40771c --- /dev/null +++ b/plugins/org.apache.cordova.console/RELEASENOTES.md @@ -0,0 +1,64 @@ +<!-- +# +# 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. +# +--> +# Release Notes + +### 0.2.3 (Sept 25, 2013) +* CB-4889 bumping&resetting version +* CB-4889 renaming org.apache.cordova.core.console to org.apache.cordova.console +* Rename CHANGELOG.md -> RELEASENOTES.md +* [CB-4752] Incremented plugin version on dev branch. + + ### 0.2.4 (Oct 28, 2013) +* CB-5154 log formatting incorrectly to native +* CB-5128: added repo + issue tag to plugin.xml for console plugin +* [CB-4915] Incremented plugin version on dev branch. + +### 0.2.5 (Dec 4, 2013) +* add ubuntu platform + +### 0.2.6 (Jan 02, 2014) +* CB-5658 Add doc/index.md for Console plugin + +### 0.2.7 (Feb 05, 2014) +* Native console needs to be called DebugConsole to avoid ambiguous reference. This commit requires the 3.4.0 version of the native class factory +* CB-4718 fixed Console plugin not working on wp + +### 0.2.8 (Apr 17, 2014) +* CB-6460: Update license headers +* Add NOTICE file + +### 0.2.9 (Jun 05, 2014) +* CB-6848 Add Android quirk, list applicable platforms +* CB-6796 Add license +* CB-6491 add CONTRIBUTING.md + +### 0.2.10 (Aug 06, 2014) +* CB-6127 Updated translations for docs + +### 0.2.11 (Sep 17, 2014) +* CB-7249 cordova-plugin-console documentation translation + +### 0.2.12 (Dec 02, 2014) +* CB-7977 Mention `deviceready` in plugin docs +* CB-7700 cordova-plugin-console documentation translation: cordova-plugin-console + +### 0.2.13 (Feb 04, 2015) +* CB-8351 ios: Use argumentForIndex rather than NSArray extension diff --git a/plugins/org.apache.cordova.console/doc/de/index.md b/plugins/org.apache.cordova.console/doc/de/index.md new file mode 100644 index 00000000..07c8317a --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/de/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +Dieses Plugin stellt sicher, dass der Befehl console.log() so hilfreich ist, wie er sein kann. Es fügt zusätzliche Funktion für iOS, Ubuntu, Windows Phone 8 und Windows 8 hinzu. Teilweise kann es vorkommen, dass der Befehl console.log() nicht korrekt erkannt wird, und es zu Fehlern bzw. zu nicht angezeigten Logs in der Console kommt. Wenn Sie mit der derzeitigen Funktionsweise zufrieden sind, kann es sein, dass Sie dieses Plugin nicht benötigen. + +## Installation + + cordova plugin add org.apache.cordova.console + + +### Android Eigenarten + +Auf einigen anderen Plattformen als Android reagiert der Befehl console.log ("1", "2", "3") auf mehrere Befehle. In diesem Fall 1, 2 und 3. Android wird jedoch nur auf das erste Argument (1) reagieren. Nachfolgende Argumente zu console.log() (2 und 3) werden ignoriert. Dafür ist aber nicht dieses Plugin verantwortlich! Es ist eine Limitierung die von Android kommt und nicht von diesem Plugin beeinflusst werden kann.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/es/index.md b/plugins/org.apache.cordova.console/doc/es/index.md new file mode 100644 index 00000000..610dab37 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/es/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +Este plugin es para asegurarse de que console.log() es tan útil como puede ser. Añade función adicional para iOS, Windows Phone 8, Ubuntu y Windows 8. Si estás contento con cómo funciona console.log() para ti, entonces probablemente no necesitas este plugin. + +## Instalación + + cordova plugin add org.apache.cordova.console + + +### Rarezas Android + +En algunas plataformas que no sean Android, console.log() actuará en varios argumentos, como console.log ("1", "2", "3"). Sin embargo, Android actuará sólo en el primer argumento. Se omitirá posteriores argumentos para console.log(). Este plugin no es la causa de eso, es una limitación propia de Android.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/fr/index.md b/plugins/org.apache.cordova.console/doc/fr/index.md new file mode 100644 index 00000000..bde950e7 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/fr/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +Ce plugin est destiné à faire en sorte que console.log() est aussi utile que possible. Il ajoute une fonction supplémentaire pour iOS, Ubuntu, Windows Phone 8 et Windows 8. Si vous êtes satisfait du fonctionnement de console.log() pour vous, alors vous avez probablement pas besoin ce plugin. + +## Installation + + cordova plugin add org.apache.cordova.console + + +### Quirks Android + +Sur certaines plateformes autres que Android, console.log() va agir sur plusieurs arguments, tels que console.log ("1", "2", "3"). Toutefois, Android doit agir uniquement sur le premier argument. Les arguments suivants à console.log() seront ignorées. Ce plugin n'est pas la cause de cela, il s'agit d'une limitation d'Android lui-même.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/index.md b/plugins/org.apache.cordova.console/doc/index.md new file mode 100644 index 00000000..ea801f78 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/index.md @@ -0,0 +1,46 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +This plugin is meant to ensure that console.log() is as useful as it can be. +It adds additional function for iOS, Ubuntu, Windows Phone 8, and Windows 8. If +you are happy with how console.log() works for you, then you probably +don't need this plugin. + +This plugin defines a global `console` object. + +Although the object is in the global scope, features provided by this plugin +are not available until after the `deviceready` event. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log("console.log works well"); + } + +## Installation + + cordova plugin add org.apache.cordova.console + +### Android Quirks + +On some platforms other than Android, console.log() will act on multiple +arguments, such as console.log("1", "2", "3"). However, Android will act only +on the first argument. Subsequent arguments to console.log() will be ignored. +This plugin is not the cause of that, it is a limitation of Android itself. diff --git a/plugins/org.apache.cordova.console/doc/it/index.md b/plugins/org.apache.cordova.console/doc/it/index.md new file mode 100644 index 00000000..f80a637e --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/it/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +Questo plugin è intesa a garantire che console.log() è tanto utile quanto può essere. Aggiunge una funzione aggiuntiva per iOS, Ubuntu, Windows 8 e Windows Phone 8. Se sei soddisfatto di come console.log() funziona per voi, quindi probabilmente non è necessario questo plugin. + +## Installazione + + cordova plugin add org.apache.cordova.console + + +### Stranezze Android + +Su alcune piattaforme diverse da Android, console.log() agirà su più argomenti, come ad esempio console ("1", "2", "3"). Tuttavia, Android agirà solo sul primo argomento. Argomenti successivi a console.log() verranno ignorati. Questo plugin non è la causa di ciò, è una limitazione di Android stesso.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/ja/index.md b/plugins/org.apache.cordova.console/doc/ja/index.md new file mode 100644 index 00000000..f8a39c59 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/ja/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +ã“ã®ãƒ—ラグインã¯ã€ãã® console.log() ãŒã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ä¾¿åˆ©ãªã“ã¨ã‚’確èªã™ã‚‹ã‚‚ã®ã§ã™ã€‚ ãれã¯ã€iOSã€Ubuntuã€Windows Phone 8 ãŠã‚ˆã³ Windows 8 ã®è¿½åŠ é–¢æ•°ã‚’è¿½åŠ ã—ã¾ã™ã€‚ å ´åˆã¯ã‚ãªãŸã®ãŸã‚ã® console.log() ã®ä½œå“ã«æº€è¶³ã—ã¦ã„ã‚‹ã—ã€ãŠãらãå¿…è¦ã¯ã‚りã¾ã›ã‚“ã“ã®ãƒ—ラグイン。 + +## インストール + + cordova plugin add org.apache.cordova.console + + +### Android ã®ç™– + +アンドãƒã‚¤ãƒ‰ä»¥å¤–ã®ã„ãã¤ã‹ã®ãƒ—ラットフォーム㧠console.log() 㯠console.log (「1ã€ã€ã€Œ2ã€ã€ã€Œ3ã€) ãªã©ã€è¤‡æ•°ã®å¼•æ•°ã«å‹•作ã—ã¾ã™ã€‚ ã—ã‹ã—ã€ã‚¢ãƒ³ãƒ‰ãƒã‚¤ãƒ‰ã¯ã€æœ€åˆã®å¼•æ•°ã§ã®ã¿å‹•作ã—ã¾ã™ã€‚ Console.log() ã«å¾Œç¶šã®å¼•æ•°ã¯ç„¡è¦–ã•れã¾ã™ã€‚ ã“ã®ãƒ—ラグインãŒåŽŸå› ã§ã¯ãªã„ã€ãれ㯠Android ã®è‡ªä½“ã®åˆ¶é™ã§ã™ã€‚
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/ko/index.md b/plugins/org.apache.cordova.console/doc/ko/index.md new file mode 100644 index 00000000..b07b2d6c --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/ko/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +ì´ í”ŒëŸ¬ê·¸ì¸ì„ console.log()로 수 ìœ ìš© ë˜ë„ë¡ ì˜ë¯¸ìž…니다. IOS, 우분투, Windows Phone 8 ë° ìœˆë„ìš° 8ì— ëŒ€ 한 추가 ê¸°ëŠ¥ì„ ì¶”ê°€ 하 ê³ í•©ë‹ˆë‹¤. Console.log() ë‹¹ì‹ ì„ ìœ„í•´ ìž‘ë™ í•˜ëŠ” 어떻게 행복 한 경우ì—, 그때 ë‹¹ì‹ ì€ ì•„ë§ˆ í•„ìš” 하지 ì•ŠìŠµë‹ˆë‹¤ì´ í”ŒëŸ¬ê·¸ì¸. + +## 설치 + + cordova plugin add org.apache.cordova.console + + +### 안 드 로ì´ë“œ 단ì + +안 드 로ì´ë“œ ì´ì™¸ì˜ ì¼ë¶€ 플랫í¼ì—서 console.log() console.log ("1", "2", "3")와 ê°™ì´ ì—¬ëŸ¬ ì¸ìˆ˜ì— ìž‘ë™í• 것 ì´ë‹¤. 그러나, 안 드 로ì´ë“œëŠ” 첫 번째 ì¸ìˆ˜ì—ë§Œ ìž‘ë™í• 것 ì´ë‹¤. Console.log() í›„ì† ì¸ìˆ˜ëŠ” 무시 ë©ë‹ˆë‹¤. ì´ í”ŒëŸ¬ê·¸ì¸ì˜ ì›ì¸ì´ ë˜ì§€ 않습니다, ê·¸ë¦¬ê³ ê·¸ê²ƒì€ ì•ˆ 드 로ì´ë“œ ìžì²´ì˜ 한계입니다.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/pl/index.md b/plugins/org.apache.cordova.console/doc/pl/index.md new file mode 100644 index 00000000..9260d598 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/pl/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +Ten plugin jest przeznaczona do zapewnienia, że console.log() jest tak przydatne, jak to może być. To dodaje dodatkową funkcję dla iOS, Ubuntu, Windows Phone 8 i Windows 8. Jeśli jesteś zadowolony z jak console.log() pracuje dla Ciebie, wtedy prawdopodobnie nie potrzebują tej wtyczki. + +## Instalacja + + cordova plugin add org.apache.cordova.console + + +### Dziwactwa Androida + +Na niektórych platformach innych niż Android console.log() będzie działać na wielu argumentów, takich jak console.log ("1", "2", "3"). Jednak Android będzie działać tylko na pierwszy argument. Kolejne argumenty do console.log() będą ignorowane. Ten plugin nie jest przyczyną, że, jest to ograniczenie Androida, sam.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/ru/index.md b/plugins/org.apache.cordova.console/doc/ru/index.md new file mode 100644 index 00000000..9ea1cd27 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/ru/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +Ðтот плагин предназначен Ð´Ð»Ñ Ð¾Ð±ÐµÑÐ¿ÐµÑ‡ÐµÐ½Ð¸Ñ ÐºÐ°Ðº полезным, поÑкольку Ñто может быть что console.log(). Он добавлÑет дополнительные функции Ð´Ð»Ñ iOS, Ubuntu, Windows Phone 8 и Windows 8. ЕÑли вы не довольны как console.log() работает Ð´Ð»Ñ Ð²Ð°Ñ, то вы вероÑтно не нужен Ñтот плагин. + +## УÑтановка + + cordova plugin add org.apache.cordova.console + + +### ОÑобенноÑти Android + +Ðа некоторых платформах, отличных от Android console.log() будет дейÑтвовать на неÑкольких аргументов, например console.log («1», «2», «3»). Тем не менее Android будет дейÑтвовать только на первого аргумента. ПоÑледующие аргументы Ð´Ð»Ñ console.log() будет игнорироватьÑÑ. Ðтот плагин не ÑвлÑетÑÑ Ð¿Ñ€Ð¸Ñ‡Ð¸Ð½Ð¾Ð¹ Ñтого, Ñто ограничение Android Ñам.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/doc/zh/index.md b/plugins/org.apache.cordova.console/doc/zh/index.md new file mode 100644 index 00000000..50445633 --- /dev/null +++ b/plugins/org.apache.cordova.console/doc/zh/index.md @@ -0,0 +1,31 @@ +<!--- + 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. +--> + +# org.apache.cordova.console + +é€™å€‹å¤–æŽ›ç¨‹å¼æ˜¯ç‚ºäº†ç¢ºä¿è©² console.log() 是一樣有用,它å¯ä»¥æ˜¯ã€‚ å®ƒå°‡æ·»åŠ é™„åŠ åŠŸèƒ½çš„ iOS〠Ubuntu,Windows Phone 8 å’Œ Windows 8。 å¦‚æžœä½ æ˜¯å¿«æ¨‚èˆ‡ console.log() æ˜¯å¦‚ä½•ç‚ºä½ å·¥ä½œï¼Œé‚£éº¼å¯èƒ½ä¸éœ€è¦é€™å€‹å¤–掛程å¼ã€‚ + +## å®‰è£ + + cordova plugin add org.apache.cordova.console + + +### Android 的怪癖 + +åœ¨ä¸€äº›éž Android 平臺上,console.log() å°‡ä½œç”¨æ–¼å¤šå€‹åƒæ•¸ï¼Œå¦‚ console.log ("1"ã€"2"ã€"3")。 然而,Android å°‡åƒ…åœ¨ç¬¬ä¸€å€‹åƒæ•¸ä¸ŠæŽ¡å–行動。 å° console.log() çš„å¾ŒçºŒåƒæ•¸å°‡è¢«å¿½ç•¥ã€‚ 這個外掛程å¼ä¸æ˜¯çš„åŽŸå› ï¼Œï¼Œå®ƒæ˜¯å®‰å“系統本身的é™åˆ¶ã€‚
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/package.json b/plugins/org.apache.cordova.console/package.json new file mode 100644 index 00000000..ef6eba71 --- /dev/null +++ b/plugins/org.apache.cordova.console/package.json @@ -0,0 +1,22 @@ +{ + "version": "0.2.13", + "name": "org.apache.cordova.console", + "cordova_name": "Console", + "description": "Cordova Console Plugin", + "license": "Apache 2.0", + "repo": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git", + "issue": "https://issues.apache.org/jira/browse/CB/component/12320644", + "keywords": [ + "cordova", + "console" + ], + "platforms": [ + "ios", + "ubuntu", + "wp7", + "wp8", + "windows8" + ], + "engines": [], + "englishdoc": "<!---\n Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n-->\n\n# org.apache.cordova.console\n\nThis plugin is meant to ensure that console.log() is as useful as it can be.\nIt adds additional function for iOS, Ubuntu, Windows Phone 8, and Windows 8. If\nyou are happy with how console.log() works for you, then you probably\ndon't need this plugin.\n\nThis plugin defines a global `console` object.\n\nAlthough the object is in the global scope, features provided by this plugin\nare not available until after the `deviceready` event.\n\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n function onDeviceReady() {\n console.log(\"console.log works well\");\n }\n\n## Installation\n\n cordova plugin add org.apache.cordova.console\n\n### Android Quirks\n\nOn some platforms other than Android, console.log() will act on multiple\narguments, such as console.log(\"1\", \"2\", \"3\"). However, Android will act only\non the first argument. Subsequent arguments to console.log() will be ignored.\nThis plugin is not the cause of that, it is a limitation of Android itself.\n" +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.console/plugin.xml b/plugins/org.apache.cordova.console/plugin.xml new file mode 100644 index 00000000..41dd0db3 --- /dev/null +++ b/plugins/org.apache.cordova.console/plugin.xml @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="org.apache.cordova.console" + version="0.2.13"> + + <name>Console</name> + <description>Cordova Console Plugin</description> + <license>Apache 2.0</license> + <keywords>cordova,console</keywords> + <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git</repo> + <issue>https://issues.apache.org/jira/browse/CB/component/12320644</issue> + + <!-- ios --> + <platform name="ios"> + + <config-file target="config.xml" parent="/*"> + <feature name="Console"> + <param name="ios-package" value="CDVLogger"/> + </feature> + </config-file> + + <js-module src="www/console-via-logger.js" name="console"> + <clobbers target="console" /> + </js-module> + + <js-module src="www/logger.js" name="logger"> + <clobbers target="cordova.logger" /> + </js-module> + + <header-file src="src/ios/CDVLogger.h" /> + <source-file src="src/ios/CDVLogger.m" /> + + </platform> + + <!-- ubuntu --> + <platform name="ubuntu"> + <js-module src="www/console-via-logger.js" name="console"> + <clobbers target="console" /> + </js-module> + + <js-module src="www/logger.js" name="logger"> + <clobbers target="cordova.logger" /> + </js-module> + + <header-file src="src/ubuntu/console.h" /> + <source-file src="src/ubuntu/console.cpp" /> + + </platform> + + <!-- wp7 --> + <platform name="wp7"> + <config-file target="config.xml" parent="/*"> + <feature name="Console"> + <param name="wp-package" value="DebugConsole"/> + </feature> + </config-file> + + <js-module src="www/console-via-logger.js" name="console"> + <clobbers target="console" /> + </js-module> + + <js-module src="www/logger.js" name="logger"> + <clobbers target="cordova.logger" /> + </js-module> + + <source-file src="src/wp/DebugConsole.cs" /> + </platform> + + <!-- wp8 --> + <platform name="wp8"> + <config-file target="config.xml" parent="/*"> + <feature name="Console"> + <param name="wp-package" value="DebugConsole"/> + </feature> + </config-file> + + <js-module src="www/console-via-logger.js" name="console"> + <clobbers target="console" /> + </js-module> + + <js-module src="www/logger.js" name="logger"> + <clobbers target="cordova.logger" /> + </js-module> + + <source-file src="src/wp/DebugConsole.cs" /> + </platform> + + <!-- windows8 --> + <platform name="windows8"> + <js-module src="www/logger.js" name="logger"> + <clobbers target="cordova.logger" /> + </js-module> + <js-module src="www/console-via-logger.js" name="console"> + <clobbers target="console" /> + </js-module> + + </platform> + +</plugin> diff --git a/plugins/org.apache.cordova.console/src/ios/CDVLogger.h b/plugins/org.apache.cordova.console/src/ios/CDVLogger.h new file mode 100644 index 00000000..7cfb3063 --- /dev/null +++ b/plugins/org.apache.cordova.console/src/ios/CDVLogger.h @@ -0,0 +1,26 @@ +/* + 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. + */ + +#import <Cordova/CDVPlugin.h> + +@interface CDVLogger : CDVPlugin + +- (void)logLevel:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/org.apache.cordova.console/src/ios/CDVLogger.m b/plugins/org.apache.cordova.console/src/ios/CDVLogger.m new file mode 100644 index 00000000..ccfa3a51 --- /dev/null +++ b/plugins/org.apache.cordova.console/src/ios/CDVLogger.m @@ -0,0 +1,38 @@ +/* + 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. + */ + +#import "CDVLogger.h" +#import <Cordova/CDV.h> + +@implementation CDVLogger + +/* log a message */ +- (void)logLevel:(CDVInvokedUrlCommand*)command +{ + id level = [command argumentAtIndex:0]; + id message = [command argumentAtIndex:1]; + + if ([level isEqualToString:@"LOG"]) { + NSLog(@"%@", message); + } else { + NSLog(@"%@: %@", level, message); + } +} + +@end diff --git a/plugins/org.apache.cordova.console/src/ubuntu/console.cpp b/plugins/org.apache.cordova.console/src/ubuntu/console.cpp new file mode 100644 index 00000000..9de09f43 --- /dev/null +++ b/plugins/org.apache.cordova.console/src/ubuntu/console.cpp @@ -0,0 +1,29 @@ +/* + * Licensed 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. + */ + +#include "console.h" + +#include <iostream> + +Console::Console(Cordova *cordova) : CPlugin(cordova) { +} + +void Console::logLevel(int scId, int ecId, QString level, QString message) { + Q_UNUSED(scId) + Q_UNUSED(ecId) + + if (level != "LOG") + std::cout << "[" << level.toStdString() << "] "; + std::cout << message.toStdString() << std::endl; +} diff --git a/plugins/org.apache.cordova.console/src/ubuntu/console.h b/plugins/org.apache.cordova.console/src/ubuntu/console.h new file mode 100644 index 00000000..3f3d1634 --- /dev/null +++ b/plugins/org.apache.cordova.console/src/ubuntu/console.h @@ -0,0 +1,43 @@ +/* + * Licensed 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. + */ + +#ifndef CONSOLE_H_FDSVCXGFRS +#define CONSOLE_H_FDSVCXGFRS + +#include <cplugin.h> + +#include <QtCore> + +class Console : public CPlugin { + Q_OBJECT +public: + explicit Console(Cordova *cordova); + + virtual const QString fullName() override { + return Console::fullID(); + } + + virtual const QString shortName() override { + return "Console"; + } + + static const QString fullID() { + return "Console"; + } + +public slots: + void logLevel(int scId, int ecId, QString level, QString message); +}; + +#endif diff --git a/plugins/org.apache.cordova.console/src/wp/DebugConsole.cs b/plugins/org.apache.cordova.console/src/wp/DebugConsole.cs new file mode 100644 index 00000000..9bb5476d --- /dev/null +++ b/plugins/org.apache.cordova.console/src/wp/DebugConsole.cs @@ -0,0 +1,47 @@ +/* + Licensed 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. +*/ + +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Diagnostics; + +namespace WPCordovaClassLib.Cordova.Commands +{ + public class DebugConsole : BaseCommand + { + public void logLevel(string options) + { + string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + string level = args[0]; + string msg = args[1]; + + if (level.Equals("LOG")) + { + Debug.WriteLine(msg); + } + else + { + Debug.WriteLine(level + ": " + msg); + } + } + } +} diff --git a/plugins/org.apache.cordova.console/www/console-via-logger.js b/plugins/org.apache.cordova.console/www/console-via-logger.js new file mode 100644 index 00000000..4095eb3e --- /dev/null +++ b/plugins/org.apache.cordova.console/www/console-via-logger.js @@ -0,0 +1,187 @@ +/* + * + * 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 logger = require("./logger"); +var utils = require("cordova/utils"); + +//------------------------------------------------------------------------------ +// object that we're exporting +//------------------------------------------------------------------------------ +var console = module.exports; + +//------------------------------------------------------------------------------ +// copy of the original console object +//------------------------------------------------------------------------------ +var WinConsole = window.console; + +//------------------------------------------------------------------------------ +// whether to use the logger +//------------------------------------------------------------------------------ +var UseLogger = false; + +//------------------------------------------------------------------------------ +// Timers +//------------------------------------------------------------------------------ +var Timers = {}; + +//------------------------------------------------------------------------------ +// used for unimplemented methods +//------------------------------------------------------------------------------ +function noop() {} + +//------------------------------------------------------------------------------ +// used for unimplemented methods +//------------------------------------------------------------------------------ +console.useLogger = function (value) { + if (arguments.length) UseLogger = !!value; + + if (UseLogger) { + if (logger.useConsole()) { + throw new Error("console and logger are too intertwingly"); + } + } + + return UseLogger; +}; + +//------------------------------------------------------------------------------ +console.log = function() { + if (logger.useConsole()) return; + logger.log.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.error = function() { + if (logger.useConsole()) return; + logger.error.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.warn = function() { + if (logger.useConsole()) return; + logger.warn.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.info = function() { + if (logger.useConsole()) return; + logger.info.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.debug = function() { + if (logger.useConsole()) return; + logger.debug.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.assert = function(expression) { + if (expression) return; + + var message = logger.format.apply(logger.format, [].slice.call(arguments, 1)); + console.log("ASSERT: " + message); +}; + +//------------------------------------------------------------------------------ +console.clear = function() {}; + +//------------------------------------------------------------------------------ +console.dir = function(object) { + console.log("%o", object); +}; + +//------------------------------------------------------------------------------ +console.dirxml = function(node) { + console.log(node.innerHTML); +}; + +//------------------------------------------------------------------------------ +console.trace = noop; + +//------------------------------------------------------------------------------ +console.group = console.log; + +//------------------------------------------------------------------------------ +console.groupCollapsed = console.log; + +//------------------------------------------------------------------------------ +console.groupEnd = noop; + +//------------------------------------------------------------------------------ +console.time = function(name) { + Timers[name] = new Date().valueOf(); +}; + +//------------------------------------------------------------------------------ +console.timeEnd = function(name) { + var timeStart = Timers[name]; + if (!timeStart) { + console.warn("unknown timer: " + name); + return; + } + + var timeElapsed = new Date().valueOf() - timeStart; + console.log(name + ": " + timeElapsed + "ms"); +}; + +//------------------------------------------------------------------------------ +console.timeStamp = noop; + +//------------------------------------------------------------------------------ +console.profile = noop; + +//------------------------------------------------------------------------------ +console.profileEnd = noop; + +//------------------------------------------------------------------------------ +console.count = noop; + +//------------------------------------------------------------------------------ +console.exception = console.log; + +//------------------------------------------------------------------------------ +console.table = function(data, columns) { + console.log("%o", data); +}; + +//------------------------------------------------------------------------------ +// return a new function that calls both functions passed as args +//------------------------------------------------------------------------------ +function wrappedOrigCall(orgFunc, newFunc) { + return function() { + var args = [].slice.call(arguments); + try { orgFunc.apply(WinConsole, args); } catch (e) {} + try { newFunc.apply(console, args); } catch (e) {} + }; +} + +//------------------------------------------------------------------------------ +// For every function that exists in the original console object, that +// also exists in the new console object, wrap the new console method +// with one that calls both +//------------------------------------------------------------------------------ +for (var key in console) { + if (typeof WinConsole[key] == "function") { + console[key] = wrappedOrigCall(WinConsole[key], console[key]); + } +} diff --git a/plugins/org.apache.cordova.console/www/logger.js b/plugins/org.apache.cordova.console/www/logger.js new file mode 100644 index 00000000..cbf81b9c --- /dev/null +++ b/plugins/org.apache.cordova.console/www/logger.js @@ -0,0 +1,355 @@ +/* + * + * 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. + * +*/ + +//------------------------------------------------------------------------------ +// The logger module exports the following properties/functions: +// +// LOG - constant for the level LOG +// ERROR - constant for the level ERROR +// WARN - constant for the level WARN +// INFO - constant for the level INFO +// DEBUG - constant for the level DEBUG +// logLevel() - returns current log level +// logLevel(value) - sets and returns a new log level +// useConsole() - returns whether logger is using console +// useConsole(value) - sets and returns whether logger is using console +// log(message,...) - logs a message at level LOG +// error(message,...) - logs a message at level ERROR +// warn(message,...) - logs a message at level WARN +// info(message,...) - logs a message at level INFO +// debug(message,...) - logs a message at level DEBUG +// logLevel(level,message,...) - logs a message specified level +// +//------------------------------------------------------------------------------ + +var logger = exports; + +var exec = require('cordova/exec'); +var utils = require('cordova/utils'); + +var UseConsole = false; +var UseLogger = true; +var Queued = []; +var DeviceReady = false; +var CurrentLevel; + +var originalConsole = console; + +/** + * Logging levels + */ + +var Levels = [ + "LOG", + "ERROR", + "WARN", + "INFO", + "DEBUG" +]; + +/* + * add the logging levels to the logger object and + * to a separate levelsMap object for testing + */ + +var LevelsMap = {}; +for (var i=0; i<Levels.length; i++) { + var level = Levels[i]; + LevelsMap[level] = i; + logger[level] = level; +} + +CurrentLevel = LevelsMap.WARN; + +/** + * Getter/Setter for the logging level + * + * Returns the current logging level. + * + * When a value is passed, sets the logging level to that value. + * The values should be one of the following constants: + * logger.LOG + * logger.ERROR + * logger.WARN + * logger.INFO + * logger.DEBUG + * + * The value used determines which messages get printed. The logging + * values above are in order, and only messages logged at the logging + * level or above will actually be displayed to the user. E.g., the + * default level is WARN, so only messages logged with LOG, ERROR, or + * WARN will be displayed; INFO and DEBUG messages will be ignored. + */ +logger.level = function (value) { + if (arguments.length) { + if (LevelsMap[value] === null) { + throw new Error("invalid logging level: " + value); + } + CurrentLevel = LevelsMap[value]; + } + + return Levels[CurrentLevel]; +}; + +/** + * Getter/Setter for the useConsole functionality + * + * When useConsole is true, the logger will log via the + * browser 'console' object. + */ +logger.useConsole = function (value) { + if (arguments.length) UseConsole = !!value; + + if (UseConsole) { + if (typeof console == "undefined") { + throw new Error("global console object is not defined"); + } + + if (typeof console.log != "function") { + throw new Error("global console object does not have a log function"); + } + + if (typeof console.useLogger == "function") { + if (console.useLogger()) { + throw new Error("console and logger are too intertwingly"); + } + } + } + + return UseConsole; +}; + +/** + * Getter/Setter for the useLogger functionality + * + * When useLogger is true, the logger will log via the + * native Logger plugin. + */ +logger.useLogger = function (value) { + // Enforce boolean + if (arguments.length) UseLogger = !!value; + return UseLogger; +}; + +/** + * Logs a message at the LOG level. + * + * Parameters passed after message are used applied to + * the message with utils.format() + */ +logger.log = function(message) { logWithArgs("LOG", arguments); }; + +/** + * Logs a message at the ERROR level. + * + * Parameters passed after message are used applied to + * the message with utils.format() + */ +logger.error = function(message) { logWithArgs("ERROR", arguments); }; + +/** + * Logs a message at the WARN level. + * + * Parameters passed after message are used applied to + * the message with utils.format() + */ +logger.warn = function(message) { logWithArgs("WARN", arguments); }; + +/** + * Logs a message at the INFO level. + * + * Parameters passed after message are used applied to + * the message with utils.format() + */ +logger.info = function(message) { logWithArgs("INFO", arguments); }; + +/** + * Logs a message at the DEBUG level. + * + * Parameters passed after message are used applied to + * the message with utils.format() + */ +logger.debug = function(message) { logWithArgs("DEBUG", arguments); }; + +// log at the specified level with args +function logWithArgs(level, args) { + args = [level].concat([].slice.call(args)); + logger.logLevel.apply(logger, args); +} + +// return the correct formatString for an object +function formatStringForMessage(message) { + return (typeof message === "string") ? "" : "%o"; +} + +/** + * Logs a message at the specified level. + * + * Parameters passed after message are used applied to + * the message with utils.format() + */ +logger.logLevel = function(level /* , ... */) { + // format the message with the parameters + var formatArgs = [].slice.call(arguments, 1); + var fmtString = formatStringForMessage(formatArgs[0]); + if (fmtString.length > 0){ + formatArgs.unshift(fmtString); // add formatString + } + + var message = logger.format.apply(logger.format, formatArgs); + + if (LevelsMap[level] === null) { + throw new Error("invalid logging level: " + level); + } + + if (LevelsMap[level] > CurrentLevel) return; + + // queue the message if not yet at deviceready + if (!DeviceReady && !UseConsole) { + Queued.push([level, message]); + return; + } + + // Log using the native logger if that is enabled + if (UseLogger) { + exec(null, null, "Console", "logLevel", [level, message]); + } + + // Log using the console if that is enabled + if (UseConsole) { + // make sure console is not using logger + if (console.useLogger()) { + throw new Error("console and logger are too intertwingly"); + } + + // log to the console + switch (level) { + case logger.LOG: originalConsole.log(message); break; + case logger.ERROR: originalConsole.log("ERROR: " + message); break; + case logger.WARN: originalConsole.log("WARN: " + message); break; + case logger.INFO: originalConsole.log("INFO: " + message); break; + case logger.DEBUG: originalConsole.log("DEBUG: " + message); break; + } + } +}; + + +/** + * Formats a string and arguments following it ala console.log() + * + * Any remaining arguments will be appended to the formatted string. + * + * for rationale, see FireBug's Console API: + * http://getfirebug.com/wiki/index.php/Console_API + */ +logger.format = function(formatString, args) { + return __format(arguments[0], [].slice.call(arguments,1)).join(' '); +}; + + +//------------------------------------------------------------------------------ +/** + * Formats a string and arguments following it ala vsprintf() + * + * format chars: + * %j - format arg as JSON + * %o - format arg as JSON + * %c - format arg as '' + * %% - replace with '%' + * any other char following % will format it's + * arg via toString(). + * + * Returns an array containing the formatted string and any remaining + * arguments. + */ +function __format(formatString, args) { + if (formatString === null || formatString === undefined) return [""]; + if (arguments.length == 1) return [formatString.toString()]; + + if (typeof formatString != "string") + formatString = formatString.toString(); + + var pattern = /(.*?)%(.)(.*)/; + var rest = formatString; + var result = []; + + while (args.length) { + var match = pattern.exec(rest); + if (!match) break; + + var arg = args.shift(); + rest = match[3]; + result.push(match[1]); + + if (match[2] == '%') { + result.push('%'); + args.unshift(arg); + continue; + } + + result.push(__formatted(arg, match[2])); + } + + result.push(rest); + + var remainingArgs = [].slice.call(args); + remainingArgs.unshift(result.join('')); + return remainingArgs; +} + +function __formatted(object, formatChar) { + + try { + switch(formatChar) { + case 'j': + case 'o': return JSON.stringify(object); + case 'c': return ''; + } + } + catch (e) { + return "error JSON.stringify()ing argument: " + e; + } + + if ((object === null) || (object === undefined)) { + return Object.prototype.toString.call(object); + } + + return object.toString(); +} + + +//------------------------------------------------------------------------------ +// when deviceready fires, log queued messages +logger.__onDeviceReady = function() { + if (DeviceReady) return; + + DeviceReady = true; + + for (var i=0; i<Queued.length; i++) { + var messageArgs = Queued[i]; + logger.logLevel(messageArgs[0], messageArgs[1]); + } + + Queued = null; +}; + +// add a deviceready event to log queued messages +document.addEventListener("deviceready", logger.__onDeviceReady, false); diff --git a/plugins/org.apache.cordova.device/CONTRIBUTING.md b/plugins/org.apache.cordova.device/CONTRIBUTING.md new file mode 100644 index 00000000..f7dbcaba --- /dev/null +++ b/plugins/org.apache.cordova.device/CONTRIBUTING.md @@ -0,0 +1,37 @@ +<!-- +# +# 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. +# +--> + +# Contributing to Apache Cordova + +Anyone can contribute to Cordova. And we need your contributions. + +There are multiple ways to contribute: report bugs, improve the docs, and +contribute code. + +For instructions on this, start with the +[contribution overview](http://cordova.apache.org/#contribute). + +The details are explained there, but the important items are: + - Sign and submit an Apache ICLA (Contributor License Agreement). + - Have a Jira issue open that corresponds to your contribution. + - Run the tests so your patch doesn't break existing functionality. + +We look forward to your contributions! diff --git a/plugins/org.apache.cordova.device/LICENSE b/plugins/org.apache.cordova.device/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/plugins/org.apache.cordova.device/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/NOTICE b/plugins/org.apache.cordova.device/NOTICE new file mode 100644 index 00000000..8ec56a52 --- /dev/null +++ b/plugins/org.apache.cordova.device/NOTICE @@ -0,0 +1,5 @@ +Apache Cordova +Copyright 2012 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/plugins/org.apache.cordova.device/README.md b/plugins/org.apache.cordova.device/README.md new file mode 100644 index 00000000..5158f6f2 --- /dev/null +++ b/plugins/org.apache.cordova.device/README.md @@ -0,0 +1,22 @@ +<!--- + license: 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. +--> + +# org.apache.cordova.device + +Plugin documentation: [doc/index.md](doc/index.md) diff --git a/plugins/org.apache.cordova.device/RELEASENOTES.md b/plugins/org.apache.cordova.device/RELEASENOTES.md new file mode 100644 index 00000000..12288b2c --- /dev/null +++ b/plugins/org.apache.cordova.device/RELEASENOTES.md @@ -0,0 +1,98 @@ +<!-- +# +# 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. +# +--> +# Release Notes + +### 0.2.1 (Sept 5, 2013) +* removed extraneous print statement +* [CB-4432] copyright notice change + +### 0.2.3 (Sept 25, 2013) +* CB-4889 bumping&resetting version +* [windows8] commandProxy has moved +* [BlackBerry10] removed uneeded permission tags in plugin.xml +* CB-4889 renaming org.apache.cordova.core.device to org.apache.cordova.device +* Rename CHANGELOG.md -> RELEASENOTES.md +* updated to use commandProxy for ffos +* add firefoxos support +* [CB-4752] Incremented plugin version on dev branch. + +### 0.2.4 (Oct 28, 2013) +* CB-5128: added repo + issue tag in plugin.xml for device plugin +* CB-5085 device.cordova returning wrong value +* [CB-4915] Incremented plugin version on dev branch. + +### 0.2.5 (Dec 4, 2013) +* CB-5316 Spell Cordova as a brand unless it's a command or script +* [ubuntu] use cordova/exec/proxy +* add ubuntu platform +* Modify Device.platform logic to use amazon-fireos as the platform for Amazon Devices +* 1. Added amazon-fireos platform. 2. Change to use cordova-amazon-fireos as the platform if user agent contains 'cordova-amazon-fireos' + +### 0.2.6 (Jan 02, 2014) +* CB-5658 Add doc/index.md for Device plugin +* CB-5504 Moving Telephony Logic out of Device + +### 0.2.7 (Jan 07, 2014) +* CB-5737 Fix exception on close caused by left over telephony code from CB-5504 + +### 0.2.8 (Feb 05, 2014) +* Tizen support added + +### 0.2.9 (Apr 17, 2014) +* CB-5105: [Android, windows8, WP, BlackBerry10] Removed dead code for device.version +* CB-6422: [windows8] use cordova/exec/proxy +* CB-6460: Update license headers +* Add NOTICE file + +### 0.2.10 (Jun 05, 2014) +* CB-6127 Spanish and French Translations added. Github close #12 +* Changing 1.5 to 2.0 +* added firefoxos version - conversion +* added firefoxos version +* CB-6800 Add license +* CB-6491 add CONTRIBUTING.md + +### 0.2.11 (Aug 06, 2014) +* [FFOS] update DeviceProxy.js +* CB-6127 Updated translations for docs +* Use Windows system calls to get better info + +### 0.2.12 (Sep 17, 2014) +* CB-7471 cordova-plugin-device documentation translation +* CB-7552 device.name docs have not been removed +* [fxos] Fix cordova version +* added status box and documentation to manual tests +* [fxos] Fix cordova version +* added status box and documentation to manual tests +* Added plugin support for the browser +* CB-7262 Adds support for universal windows apps. + +### 0.2.13 (Dec 02, 2014) +* Changing `device.platform` to always report the platform as "browser". +* CB-5892 - Remove deprecated `window.Settings` +* CB-7700 cordova-plugin-device documentation translation: cordova-plugin-device +* CB-7571 Bump version of nested plugin to match parent plugin + +### 0.3.0 (Feb 04, 2015) +* Added device.manufacturer property for Android, iOS, Blackberry, WP8 +* Support for Windows Phone 8 ANID2 ANID is only supported up to Windows Phone 7.5 +* CB-8351 Use a local copy of uniqueAppInstanceIdentifier rather than CordovaLib's version +* browser: Fixed a bug that caused an "cannot call method of undefined" error if the browser's user agent wasn't recognized diff --git a/plugins/org.apache.cordova.device/doc/de/index.md b/plugins/org.apache.cordova.device/doc/de/index.md new file mode 100644 index 00000000..f51618e5 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/de/index.md @@ -0,0 +1,206 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +Dieses Plugin definiert eine globale `device` -Objekt, das des Geräts Hard- und Software beschreibt. Das Objekt im globalen Gültigkeitsbereich ist es zwar nicht verfügbar bis nach dem `deviceready` Ereignis. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## Installation + + cordova plugin add org.apache.cordova.device + + +## Eigenschaften + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +Rufen Sie die Version von Cordova, die auf dem Gerät ausgeführt. + +### Unterstützte Plattformen + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Browser +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 und 8 +* Windows 8 + +## device.model + +Die `device.model` gibt den Namen der Modell- oder des Geräts zurück. Der Wert wird vom Gerätehersteller festgelegt und kann zwischen den Versionen des gleichen Produkts unterschiedlich sein. + +### Unterstützte Plattformen + +* Android +* BlackBerry 10 +* Browser +* iOS +* Tizen +* Windows Phone 7 und 8 +* Windows 8 + +### Kurzes Beispiel + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. Finden Sie unter http://theiphonewiki.com/wiki/index.php?title=Models / / Var-Modell = device.model; + + +### Android Eigenarten + +* Ruft den [Produktname][1] anstelle des [Modellnamens][2], das ist oft der Codename für die Produktion. Beispielsweise das Nexus One gibt `Passion` , und Motorola Droid gibt`voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### Tizen Macken + +* Gibt z. B. das Gerätemodell von dem Kreditor zugeordnet,`TIZEN` + +### Windows Phone 7 und 8 Eigenarten + +* Gibt das vom Hersteller angegebenen Gerätemodell zurück. Beispielsweise gibt der Samsung-Fokus`SGH-i917`. + +## device.platform + +Name des Betriebssystems des Geräts zu erhalten. + + var string = device.platform; + + +### Unterstützte Plattformen + +* Android +* BlackBerry 10 +* Browser4 +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 und 8 +* Windows 8 + +### Kurzes Beispiel + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 Macken + +Windows Phone 7 Geräte melden die Plattform als`WinCE`. + +### Windows Phone 8 Macken + +Windows Phone 8 Geräte melden die Plattform als`Win32NT`. + +## device.uuid + +Des Geräts Universally Unique Identifier ([UUID][3] zu erhalten). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### Beschreibung + +Die Details wie eine UUID generiert wird werden vom Gerätehersteller und beziehen sich auf die Plattform oder das Modell des Geräts. + +### Unterstützte Plattformen + +* Android +* BlackBerry 10 +* iOS +* Tizen +* Windows Phone 7 und 8 +* Windows 8 + +### Kurzes Beispiel + + / / Android: wird eine zufällige 64-Bit-Ganzzahl (als Zeichenfolge, wieder!) / / die ganze Zahl wird beim ersten Start des Geräts erzeugt / / / / BlackBerry: gibt die PIN-Nummer des Gerätes / / Dies ist eine neunstellige eindeutige Ganzzahl (als String, obwohl!) / / / / iPhone: (paraphrasiert aus der Dokumentation zur UIDevice-Klasse) / / liefert eine Reihe von Hash-Werte, die aus mehreren Hardware erstellt identifiziert. + / / Es ist gewährleistet, dass für jedes Gerät eindeutig sein und kann nicht gebunden werden / / an den Benutzer weitergeleitet. + / / Windows Phone 7: gibt einen Hash des Gerät + aktueller Benutzer, / / wenn der Benutzer nicht definiert ist, eine Guid generiert und wird weiter bestehen, bis die app deinstalliert wird / / Tizen: gibt das Gerät IMEI (International Mobile Equipment Identity oder IMEI ist eine Zahl / / einzigartig für jedes GSM- und UMTS-Handy. + var deviceID = device.uuid; + + +### iOS Quirk + +Die `uuid` auf iOS ist nicht eindeutig zu einem Gerät, aber für jede Anwendung, für jede Installation variiert. Es ändert sich, wenn Sie löschen und neu die app installieren, und möglicherweise auch beim iOS zu aktualisieren, oder auch ein Upgrade möglich die app pro Version (scheinbaren in iOS 5.1). Die `uuid` ist kein zuverlässiger Wert. + +### Windows Phone 7 und 8 Eigenarten + +Die `uuid` für Windows Phone 7 die Berechtigung erfordert `ID_CAP_IDENTITY_DEVICE` . Microsoft wird diese Eigenschaft wahrscheinlich bald abzuschaffen. Wenn die Funktion nicht verfügbar ist, generiert die Anwendung eine persistente Guid, die für die Dauer der Installation der Anwendung auf dem Gerät gewährleistet ist. + +## device.version + +Version des Betriebssystems zu erhalten. + + var string = device.version; + + +### Unterstützte Plattformen + +* Android 2.1 + +* BlackBerry 10 +* Browser +* iOS +* Tizen +* Windows Phone 7 und 8 +* Windows 8 + +### Kurzes Beispiel + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/es/index.md b/plugins/org.apache.cordova.device/doc/es/index.md new file mode 100644 index 00000000..9c9eb38d --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/es/index.md @@ -0,0 +1,220 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +Este plugin define un global `device` objeto que describe del dispositivo hardware y software. Aunque el objeto está en el ámbito global, no está disponible hasta después de la `deviceready` evento. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## Instalación + + cordova plugin add org.apache.cordova.device + + +## Propiedades + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +Obtener la versión de Cordova que se ejecuta en el dispositivo. + +### Plataformas soportadas + +* Amazon fire OS +* Android +* BlackBerry 10 +* Explorador +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 y 8 +* Windows 8 + +## device.model + +El `device.model` devuelve el nombre de modelo del dispositivo o producto. El valor es fijado por el fabricante del dispositivo y puede ser diferente a través de versiones del mismo producto. + +### Plataformas soportadas + +* Android +* BlackBerry 10 +* Explorador +* iOS +* Tizen +* Windows Phone 7 y 8 +* Windows 8 + +### Ejemplo rápido + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models + // + var model = device.model; + + +### Rarezas Android + +* Obtiene el [nombre del producto][1] en lugar del [nombre de la modelo][2], que es a menudo el nombre de código de producción. Por ejemplo, el Nexus One devuelve `Passion` y Motorola Droid devuelve `voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### Rarezas Tizen + +* Devuelve que el modelo de dispositivo asignado por el proveedor, por ejemplo, `TIZEN` + +### Windows Phone 7 y 8 rarezas + +* Devuelve el modelo de dispositivo especificado por el fabricante. Por ejemplo, el Samsung Focus devuelve `SGH-i917`. + +## device.platform + +Obtener el nombre del sistema operativo del dispositivo. + + var string = device.platform; + + +### Plataformas soportadas + +* Android +* BlackBerry 10 +* Browser4 +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 y 8 +* Windows 8 + +### Ejemplo rápido + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 rarezas + +Dispositivos Windows Phone 7 informe de la plataforma como `WinCE`. + +### Windows Phone 8 rarezas + +Dispositivos Windows Phone 8 Informe la plataforma como `Win32NT`. + +## device.uuid + +Obtener identificador universalmente única del dispositivo ([UUID][3]). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### Descripción + +Los detalles de cómo se genera un UUID son determinados por el fabricante del dispositivo y son especÃficos a la plataforma del dispositivo o modelo. + +### Plataformas soportadas + +* Android +* BlackBerry 10 +* iOS +* Tizen +* Windows Phone 7 y 8 +* Windows 8 + +### Ejemplo rápido + + // Android: devuelve un entero de 64 bits al azar (como una cadena, otra vez!) + // el entero es generado en el primer arranque del dispositivo + // + // BlackBerry: devuelve el número PIN del dispositivo + // este es un entero único de nueve dÃgitos (como una cadena, aunque!) + // + // iPhone: (parafraseado de la documentación de la clase UIDevice) + // devuelve una cadena de valores hash creado a partir + // de múltiples hardware identifica. + / / Está garantizado para ser único para cada dispositivo y no puede ser atado / / a la cuenta de usuario. + // Windows Phone 7: devuelve un hash de dispositivo + usuario actual, + // si el usuario no está definido, un guid generado y persistirá hasta que se desinstala la aplicación + // + // Tizen: devuelve el dispositivo IMEI (identidad de equipo móvil internacional o IMEI es un número + // único para cada teléfono móvil GSM y UMTS. + var deviceID = device.uuid; + + +### iOS chanfle + +El `uuid` en iOS no es exclusiva de un dispositivo, pero varÃa para cada aplicación, para cada instalación. Cambia si puedes borrar y volver a instalar la aplicación, y posiblemente también cuándo actualizar iOS, o incluso mejorar la aplicación por la versión (evidente en iOS 5.1). El `uuid` no es un valor confiable. + +### Windows Phone 7 y 8 rarezas + +El `uuid` para Windows Phone 7 requiere el permiso `ID_CAP_IDENTITY_DEVICE`. Microsoft pronto probablemente desaprueban esta propiedad. Si la capacidad no está disponible, la aplicación genera un guid persistente que se mantiene durante la duración de la instalación de la aplicación en el dispositivo. + +## device.version + +Obtener la versión del sistema operativo. + + var string = device.version; + + +### Plataformas soportadas + +* Android 2.1 + +* BlackBerry 10 +* Explorador +* iOS +* Tizen +* Windows Phone 7 y 8 +* Windows 8 + +### Ejemplo rápido + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. el Mango se vuelve 7.10.7720 + // Tizen: devuelve "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/fr/index.md b/plugins/org.apache.cordova.device/doc/fr/index.md new file mode 100644 index 00000000..472fda53 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/fr/index.md @@ -0,0 +1,218 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +Ce plugin définit un global `device` objet qui décrit le matériel et les logiciels de l'appareil. Bien que l'objet est dans la portée globale, il n'est pas disponible jusqu'après la `deviceready` événement. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## Installation + + cordova plugin add org.apache.cordova.device + + +## Propriétés + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +Retourne la version de Cordova en cours d'exécution sur l'appareil. + +### Plates-formes prises en charge + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Navigateur +* Firefox OS +* iOS +* Paciarelli +* Windows Phone 7 et 8 +* Windows 8 + +## device.model + +L'objet `device.model` retourne le nom du modèle de l'appareil/produit. Cette valeur est définie par le fabricant du périphérique et peut varier entre les différentes versions d'un même produit. + +### Plates-formes prises en charge + +* Android +* BlackBerry 10 +* Navigateur +* iOS +* Paciarelli +* Windows Phone 7 et 8 +* Windows 8 + +### Petit exemple + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. Voir http://theiphonewiki.com/wiki/index.php?title=Models + // + var model = device.model; + + +### Quirks Android + +* Retourne le [nom du produit][1] au lieu du [nom du modèle][2], ce qui équivaut souvent au nom de code de production. Par exemple, `Passion` pour le Nexus One et `voles` pour le Motorola Droid. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### Bizarreries de paciarelli + +* Retourne le modèle du dispositif, assigné par le vendeur, par exemple `TIZEN` + +### Windows Phone 7 et 8 Quirks + +* Retourne le modèle de l'appareil spécifié par le fabricant. Par exemple `SGH-i917` pour le Samsung Focus. + +## device.platform + +Obtenir le nom de système d'exploitation de l'appareil. + + var string = device.platform; + + +### Plates-formes prises en charge + +* Android +* BlackBerry 10 +* Browser4 +* Firefox OS +* iOS +* Paciarelli +* Windows Phone 7 et 8 +* Windows 8 + +### Petit exemple + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 Quirks + +Appareils Windows Phone 7 rapport de la plate-forme comme`WinCE`. + +### Notes au sujet de Windows Phone 8 + +Appareils Windows Phone 8 rapport de la plate-forme comme`Win32NT`. + +## device.uuid + +Obtenir Universally Unique Identifier de l'appareil ([UUID][3]). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### Description + +Les détails de comment un UUID généré sont déterminées par le fabricant du périphérique et sont spécifiques à la plate-forme ou le modèle de l'appareil. + +### Plates-formes prises en charge + +* Android +* BlackBerry 10 +* iOS +* Paciarelli +* Windows Phone 7 et 8 +* Windows 8 + +### Petit exemple + + // Android : retourne un nombre entier 64-bit aléatoire (sous la forme d'une chaîne de caractères, encore !) + // Ce nombre entier est généré lors du premier démarrage de l'appareil + // + // BlackBerry : retourne le numéro PIN de l'appareil + // Il s'agit d'un nombre entier unique à neuf chiffres (sous la forme d'une chaîne de caractères cependant !) + // + // iPhone : (copié depuis la documentation de la classe UIDevice) + // Retourne une chaîne de caractères générée à partir de plusieurs caractéristiques matérielles. + / / Il est garanti pour être unique pour chaque appareil et ne peut pas être lié / / pour le compte d'utilisateur. + // Windows Phone 7 : retourne un hashage généré à partir de appareil+utilisateur actuel, + // si aucun utilisateur n'est défini, un guid est généré persistera jusqu'à ce que l'application soit désinstallée + // Tizen : retourne le numéro IMEI (International Mobile Equipment Identity) de l'appareil, ce numéro est + // unique pour chaque téléphone GSM et UMTS. + var deviceID = device.uuid; + + +### Spécificités iOS + +Le `uuid` sur iOS n'est pas propre à un périphérique, mais varie pour chaque application, pour chaque installation. Elle change si vous supprimez, puis réinstallez l'application, et éventuellement aussi quand vous mettre à jour d'iOS, ou même mettre à jour le soft par version (apparent dans iOS 5.1). Le `uuid` n'est pas une valeur fiable. + +### Windows Phone 7 et 8 Quirks + +Le `uuid` pour Windows Phone 7 requiert l'autorisation `ID_CAP_IDENTITY_DEVICE` . Microsoft va probablement bientôt obsolète de cette propriété. Si la capacité n'est pas disponible, l'application génère un guid persistant qui est maintenu pendant toute la durée de l'installation de l'application sur le périphérique. + +## device.version + +Téléchargez la version de système d'exploitation. + + var string = device.version; + + +### Plates-formes prises en charge + +* Android 2.1+ +* BlackBerry 10 +* Navigateur +* iOS +* Paciarelli +* Windows Phone 7 et 8 +* Windows 8 + +### Petit exemple + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/index.md b/plugins/org.apache.cordova.device/doc/index.md new file mode 100644 index 00000000..b3acc9f6 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/index.md @@ -0,0 +1,218 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +This plugin defines a global `device` object, which describes the device's hardware and software. +Although the object is in the global scope, it is not available until after the `deviceready` event. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + +## Installation + + cordova plugin add org.apache.cordova.device + +## Properties + +- device.cordova +- device.model +- device.platform +- device.uuid +- device.version + +## device.cordova + +Get the version of Cordova running on the device. + +### Supported Platforms + +- Amazon Fire OS +- Android +- BlackBerry 10 +- Browser +- Firefox OS +- iOS +- Tizen +- Windows Phone 7 and 8 +- Windows 8 + +## device.model + +The `device.model` returns the name of the device's model or +product. The value is set by the device manufacturer and may be +different across versions of the same product. + +### Supported Platforms + +- Android +- BlackBerry 10 +- Browser +- iOS +- Tizen +- Windows Phone 7 and 8 +- Windows 8 + +### Quick Example + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models + // + var model = device.model; + +### Android Quirks + +- Gets the [product name](http://developer.android.com/reference/android/os/Build.html#PRODUCT) instead of the [model name](http://developer.android.com/reference/android/os/Build.html#MODEL), which is often the production code name. For example, the Nexus One returns `Passion`, and Motorola Droid returns `voles`. + +### Tizen Quirks + +- Returns the device model assigned by the vendor, for example, `TIZEN` + +### Windows Phone 7 and 8 Quirks + +- Returns the device model specified by the manufacturer. For example, the Samsung Focus returns `SGH-i917`. + +## device.platform + +Get the device's operating system name. + + var string = device.platform; + +### Supported Platforms + +- Android +- BlackBerry 10 +- Browser4 +- Firefox OS +- iOS +- Tizen +- Windows Phone 7 and 8 +- Windows 8 + +### Quick Example + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + +### Windows Phone 7 Quirks + +Windows Phone 7 devices report the platform as `WinCE`. + +### Windows Phone 8 Quirks + +Windows Phone 8 devices report the platform as `Win32NT`. + +## device.uuid + +Get the device's Universally Unique Identifier ([UUID](http://en.wikipedia.org/wiki/Universally_Unique_Identifier)). + + var string = device.uuid; + +### Description + +The details of how a UUID is generated are determined by the device manufacturer and are specific to the device's platform or model. + +### Supported Platforms + +- Android +- BlackBerry 10 +- iOS +- Tizen +- Windows Phone 7 and 8 +- Windows 8 + +### Quick Example + + // Android: Returns a random 64-bit integer (as a string, again!) + // The integer is generated on the device's first boot + // + // BlackBerry: Returns the PIN number of the device + // This is a nine-digit unique integer (as a string, though!) + // + // iPhone: (Paraphrased from the UIDevice Class documentation) + // Returns a string of hash values created from multiple hardware identifies. + // It is guaranteed to be unique for every device and can't be tied + // to the user account. + // Windows Phone 7 : Returns a hash of device+current user, + // if the user is not defined, a guid is generated and will persist until the app is uninstalled + // Tizen: returns the device IMEI (International Mobile Equipment Identity or IMEI is a number + // unique to every GSM and UMTS mobile phone. + var deviceID = device.uuid; + +### iOS Quirk + +The `uuid` on iOS is not unique to a device, but varies for each +application, for each installation. It changes if you delete and +re-install the app, and possibly also when you upgrade iOS, or even +upgrade the app per version (apparent in iOS 5.1). The `uuid` is not +a reliable value. + +### Windows Phone 7 and 8 Quirks + +The `uuid` for Windows Phone 7 requires the permission +`ID_CAP_IDENTITY_DEVICE`. Microsoft will likely deprecate this +property soon. If the capability is not available, the application +generates a persistent guid that is maintained for the duration of the +application's installation on the device. + +## device.version + +Get the operating system version. + + var string = device.version; + +### Supported Platforms + +- Android 2.1+ +- BlackBerry 10 +- Browser +- iOS +- Tizen +- Windows Phone 7 and 8 +- Windows 8 + +### Quick Example + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version; + diff --git a/plugins/org.apache.cordova.device/doc/it/index.md b/plugins/org.apache.cordova.device/doc/it/index.md new file mode 100644 index 00000000..0414dc6f --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/it/index.md @@ -0,0 +1,206 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +Questo plugin definisce un global `device` oggetto che descrive il dispositivo hardware e software. Sebbene l'oggetto sia in ambito globale, non è disponibile fino a dopo il `deviceready` evento. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## Installazione + + cordova plugin add org.apache.cordova.device + + +## Proprietà + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +Ottenere la versione di Cordova in esecuzione nel dispositivo. + +### Piattaforme supportate + +* Amazon fuoco OS +* Android +* BlackBerry 10 +* Browser +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 e 8 +* Windows 8 + +## device.model + +Il `device.model` restituisce il nome del modello del dispositivo o del prodotto. Il valore viene impostato dal produttore del dispositivo e può essere differente tra le versioni dello stesso prodotto. + +### Piattaforme supportate + +* Android +* BlackBerry 10 +* Browser +* iOS +* Tizen +* Windows Phone 7 e 8 +* Windows 8 + +### Esempio rapido + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. Vedi http://theiphonewiki.com/wiki/index.php?title=Models / / modello var = device.model; + + +### Stranezze Android + +* Ottiene il [nome del prodotto][1] anziché il [nome del modello][2], che è spesso il nome di codice di produzione. Ad esempio, restituisce il Nexus One `Passion` , e Motorola Droid restituisce`voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### Tizen stranezze + +* Restituisce il modello di dispositivo assegnato dal fornitore, ad esempio,`TIZEN` + +### Windows Phone 7 e 8 stranezze + +* Restituisce il modello di dispositivo specificato dal produttore. Ad esempio, restituisce il Samsung Focus`SGH-i917`. + +## device.platform + +Ottenere il nome del sistema operativo del dispositivo. + + var string = device.platform; + + +### Piattaforme supportate + +* Android +* BlackBerry 10 +* Browser4 +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 e 8 +* Windows 8 + +### Esempio rapido + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 capricci + +Windows Phone 7 dispositivi segnalano la piattaforma come`WinCE`. + +### Windows Phone 8 stranezze + +Dispositivi Windows Phone 8 segnalano la piattaforma come`Win32NT`. + +## device.uuid + +Ottenere identificatore del dispositivo univoco universale ([UUID][3]). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### Descrizione + +I dettagli di come viene generato un UUID sono determinati dal produttore del dispositivo e sono specifici per la piattaforma o il modello del dispositivo. + +### Piattaforme supportate + +* Android +* BlackBerry 10 +* iOS +* Tizen +* Windows Phone 7 e 8 +* Windows 8 + +### Esempio rapido + + / / Android: restituisce un intero casuale di 64 bit (come stringa, ancora una volta!) / / il numero intero è generato al primo avvio del dispositivo / / / / BlackBerry: restituisce il numero PIN del dispositivo / / questo è un valore integer univoco a nove cifre (come stringa, benchè!) / / / / iPhone: (parafrasato dalla documentazione della classe UIDevice) / / restituisce una stringa di valori hash creata dall'hardware più identifica. + / / È garantito per essere unica per ogni dispositivo e non può essere legato / / per l'account utente. + / / Windows Phone 7: restituisce un hash dell'utente corrente, + dispositivo / / se l'utente non è definito, un guid generato e persisterà fino a quando l'applicazione viene disinstallata / / Tizen: restituisce il dispositivo IMEI (International Mobile Equipment Identity o IMEI è un numero / / unico per ogni cellulare GSM e UMTS. + var deviceID = device.uuid; + + +### iOS Quirk + +Il `uuid` su iOS non è univoco per un dispositivo, ma varia per ogni applicazione, per ogni installazione. Cambia se si elimina e re-installare l'app, e possibilmente anche quando aggiornare iOS o anche aggiornare l'app per ogni versione (apparente in iOS 5.1). Il `uuid` non è un valore affidabile. + +### Windows Phone 7 e 8 stranezze + +Il `uuid` per Windows Phone 7 richiede l'autorizzazione `ID_CAP_IDENTITY_DEVICE` . Microsoft probabilmente sarà presto deprecare questa proprietà . Se la funzionalità non è disponibile, l'applicazione genera un guid persistente che viene mantenuto per la durata dell'installazione dell'applicazione sul dispositivo. + +## device.version + +Ottenere la versione del sistema operativo. + + var string = device.version; + + +### Piattaforme supportate + +* Android 2.1 + +* BlackBerry 10 +* Browser +* iOS +* Tizen +* Windows Phone 7 e 8 +* Windows 8 + +### Esempio rapido + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/ja/index.md b/plugins/org.apache.cordova.device/doc/ja/index.md new file mode 100644 index 00000000..ee447202 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/ja/index.md @@ -0,0 +1,206 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +ã“ã®ãƒ—ラグインをグãƒãƒ¼ãƒãƒ«å®šç¾©ã—ã¾ã™ `device` オブジェクトã¯ã€ãƒ‡ãƒã‚¤ã‚¹ã®ãƒãƒ¼ãƒ‰ã‚¦ã‚§ã‚¢ã¨ã‚½ãƒ•トウェアã«ã¤ã„ã¦èª¬æ˜Žã—ã¾ã™ã€‚ ãれã¯å¾Œã¾ã§åˆ©ç”¨å¯èƒ½ãªã‚ªãƒ–ジェクトãŒã‚°ãƒãƒ¼ãƒãƒ« スコープã§ã¯ã€ `deviceready` イベント。 + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## インストール + + cordova plugin add org.apache.cordova.device + + +## プãƒãƒ‘ティ + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +デãƒã‚¤ã‚¹ã§å®Ÿè¡Œã•れã¦ã„るコルドãƒã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚’å–å¾—ã—ã¾ã™ã€‚ + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* ブラックベリー 10 +* ブラウザー +* Firefox ã® OS +* iOS +* Tizen +* Windows Phone 7 㨠8 +* Windows 8 + +## device.model + +`device.model`ã€ãƒ‡ãƒã‚¤ã‚¹ã®ãƒ¢ãƒ‡ãƒ«ã¾ãŸã¯è£½å“ã®åå‰ã‚’è¿”ã—ã¾ã™ã€‚値ã¯ã€ãƒ‡ãƒã‚¤ã‚¹ã®è£½é€ å…ƒã«ã‚ˆã£ã¦è¨å®šã•れã€åŒã˜è£½å“ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³é–“ã§ç•°ãªã‚‹å¯èƒ½æ€§ãŒã‚りã¾ã™ã€‚ + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* アンドãƒã‚¤ãƒ‰ +* ブラックベリー 10 +* ブラウザー +* iOS +* Tizen +* Windows Phone 7 㨠8 +* Windows 8 + +### ç°¡å˜ãªä¾‹ + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. Http://theiphonewiki.com/wiki/index.php?title=Models ã‚’å‚ç…§ã—ã¦ãã ã•ã„//var モデル = device.model; + + +### Android ã®ç™– + +* 生産コードåã¯[モデルå][1]ã®ä»£ã‚りã«[製å“å][2]ã‚’å–å¾—ã—ã¾ã™ã€‚ ãŸã¨ãˆã°ã€ãƒã‚¯ã‚µã‚¹ 1 ã¤ã‚’è¿”ã—ã¾ã™ `Passion` ã€Motorola ã®ãƒ‰ãƒã‚¤ãƒ‰ã‚’è¿”ã—ã¾ã™`voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#MODEL + [2]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + +### Tizen ã®ç™– + +* ãŸã¨ãˆã°ã€ãƒ™ãƒ³ãƒ€ãƒ¼ã«ã‚ˆã£ã¦å‰²ã‚Šå½“ã¦ã‚‰ã‚Œã¦ã„るデãƒã‚¤ã‚¹ã®ãƒ¢ãƒ‡ãƒ«ã‚’è¿”ã—ã¾ã™`TIZEN` + +### Windows Phone 7 㨠8 ç™– + +* è£½é€ å…ƒã«ã‚ˆã£ã¦æŒ‡å®šã•れãŸãƒ‡ãƒã‚¤ã‚¹ã®ãƒ¢ãƒ‡ãƒ«ã‚’è¿”ã—ã¾ã™ã€‚ãŸã¨ãˆã°ã€ä¸‰æ˜Ÿãƒ•ォーカスを返ã—ã¾ã™`SGH-i917`. + +## device.platform + +デãƒã‚¤ã‚¹ã®ã‚ªãƒšãƒ¬ãƒ¼ãƒ†ã‚£ãƒ³ã‚° システムåã‚’å–å¾—ã—ã¾ã™ã€‚ + + var string = device.platform; + + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* アンドãƒã‚¤ãƒ‰ +* ブラックベリー 10 +* Browser4 +* Firefox ã® OS +* iOS +* Tizen +* Windows Phone 7 㨠8 +* Windows 8 + +### ç°¡å˜ãªä¾‹ + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 ã®ç™– + +Windows Phone 7 デãƒã‚¤ã‚¹ã¨ãƒ—ãƒ©ãƒƒãƒˆãƒ•ã‚©ãƒ¼ãƒ ã‚’å ±å‘Šã—ã¾ã™ã€‚`WinCE`. + +### Windows Phone 8 ç™– + +Windows Phone 8 デãƒã‚¤ã‚¹ã¨ãƒ—ãƒ©ãƒƒãƒˆãƒ•ã‚©ãƒ¼ãƒ ã‚’å ±å‘Šã—ã¾ã™ã€‚`Win32NT`. + +## device.uuid + +デãƒã‚¤ã‚¹ã®ãƒ¦ãƒ‹ãƒãƒ¼ã‚µãƒ« ・ ユニークè˜åˆ¥å ([UUID][3]ã‚’å–å¾—ã—ã¾ã™ã€‚). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### 説明 + +UUID を生æˆã™ã‚‹æ–¹æ³•ã®è©³ç´°ã¯ã€ãƒ‡ãƒã‚¤ã‚¹ã®è£½é€ å…ƒã«ã‚ˆã£ã¦æ±ºå®šã•れã€ãƒ‡ãƒã‚¤ã‚¹ã®ãƒ—ラットフォームやモデルã«å›ºæœ‰ã§ã™ã€‚ + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* アンドãƒã‚¤ãƒ‰ +* ブラックベリー 10 +* iOS +* Tizen +* Windows Phone 7 㨠8 +* Windows 8 + +### ç°¡å˜ãªä¾‹ + + //アンドãƒã‚¤ãƒ‰: ランダム㪠64 ãƒ“ãƒƒãƒˆã®æ•´æ•° (ã‚’æ–‡å—列ã¨ã—ã¦è¿”ã—ã¾ã™ã€å†ã³ ï¼ï¼‰/デãƒã‚¤ã‚¹ã®æœ€åˆã®èµ·å‹•時ã«ç”Ÿæˆã•れる整数/////ブラックベリー: デãƒã‚¤ã‚¹ã®ãƒ”ン番å·ã‚’è¿”ã—ã¾ã™//ã“れ㯠9 æ¡ã®ä¸€æ„ãªæ•´æ•° (ã‚’æ–‡å—列ã¨ã—ã¦ã‚‚ ï¼)////iPhone: (UIDevice クラスã®ãƒ‰ã‚ュメントã‹ã‚‰è¨€ã„æ›ãˆï¼‰//è˜åˆ¥è¤‡æ•°ã®ãƒãƒ¼ãƒ‰ã‚¦ã‚§ã‚¢ã‹ã‚‰ä½œæˆã•れãŸãƒãƒƒã‚·ãƒ¥å€¤ã®æ–‡å—列を返ã—ã¾ã™ã€‚。 + //ãれã¯ã™ã¹ã¦ã®ãƒ‡ãƒã‚¤ã‚¹ã«å¯¾ã—ã¦ä¸€æ„ã§ã‚ã‚‹ã“ã¨ãŒä¿è¨¼ã•ã‚Œã€æŽ¥ç¶šã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“//ユーザー アカウント。 + //Windows Phone 7: デãƒã‚¤ã‚¹ + ç¾åœ¨ã®ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒãƒƒã‚·ãƒ¥ã‚’è¿”ã—ã¾ã™//ユーザーãŒå®šç¾©ã•れã¦ã„ãªã„å ´åˆ guid ãŒç”Ÿæˆã•れã€ã‚¢ãƒ—リãŒã‚¢ãƒ³ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã•れるã¾ã§ä¿æŒã•れã¾ã™//Tizen: デãƒã‚¤ã‚¹ã® IMEI ã‚’è¿”ã—ã¾ã™ (国際モãƒã‚¤ãƒ«æ©Ÿå™¨ã‚¢ã‚¤ãƒ‡ãƒ³ãƒ†ã‚£ãƒ†ã‚£ã¾ãŸã¯ IMEI ã¯ç•ªå·ã§ã™//ã™ã¹ã¦ã® GSM ãŠã‚ˆã³ UMTS ã®æºå¸¯é›»è©±ã«å›ºæœ‰ã§ã™ã€‚ + var deviceID = device.uuid; + + +### iOS ã®æ°—ã¾ãれ + +`uuid`IOS ã§ã€ãƒ‡ãƒã‚¤ã‚¹ã«å›ºæœ‰ã§ã¯ãªã„インストールã”ã¨ã€ã‚¢ãƒ—リケーションã”ã¨ã«ç•°ãªã‚Šã¾ã™ã€‚ 削除ã€ã‚¢ãƒ—リをå†ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã—ãŸå ´åˆã«å¤‰æ›´ã¨å¤šåˆ†ã¾ãŸã¨ãアップグレード iOS ã®, ã¾ãŸã¯ã‚‚アップグレードã™ã‚‹ã‚¢ãƒ—リ (iOS ã® 5.1 ã§æ˜Žã‚‰ã‹ã«ï¼‰ ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã”ã¨ã€‚ `uuid`ã¯ä¿¡é ¼æ€§ã®é«˜ã„値ã§ã¯ã‚りã¾ã›ã‚“。 + +### Windows Phone 7 㨠8 ç™– + +`uuid`ã®ãŸã‚ã« Windows Phone 7 ã«ã¯ã€æ¨©é™ãŒå¿…è¦ã§ã™ `ID_CAP_IDENTITY_DEVICE` 。 Microsoft ã¯ã™ãã«ã“ã®ãƒ—ãƒãƒ‘ティを廃æ¢ã—ã¦å¯èƒ½æ€§ãŒã‚りã¾ã™ã€‚ 機能ãŒåˆ©ç”¨ã§ããªã„å ´åˆã€ã‚¢ãƒ—リケーションã¯ãƒ‡ãƒã‚¤ã‚¹ã¸ã®ã‚¢ãƒ—リケーションã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã®æŒç¶šæœŸé–“ã®ãŸã‚ã«ä¿æŒã•れã¦ã„る永続的㪠guid を生æˆã—ã¾ã™ã€‚ + +## device.version + +オペレーティング システムã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚’å–å¾—ã—ã¾ã™ã€‚ + + var string = device.version; + + +### サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* アンドãƒã‚¤ãƒ‰ 2.1 + +* ブラックベリー 10 +* ブラウザー +* iOS +* Tizen +* Windows Phone 7 㨠8 +* Windows 8 + +### ç°¡å˜ãªä¾‹ + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/ko/index.md b/plugins/org.apache.cordova.device/doc/ko/index.md new file mode 100644 index 00000000..af44d40a --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/ko/index.md @@ -0,0 +1,206 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +ì´ í”ŒëŸ¬ê·¸ì¸ ì •ì˜ ì „ì— `device` 개체, 디바ì´ìŠ¤ì˜ í•˜ë“œì›¨ì–´ ë° ì†Œí”„íŠ¸ì›¨ì–´ì— ì„¤ëª… 합니다. 개체는 ì „ì— ë²”ìœ„ì—서 ë¹„ë¡ ê·¸ê²ƒì€ í›„ê¹Œì§€ ì‚¬ìš©í• ìˆ˜ 있는 `deviceready` ì´ë²¤íЏ. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## 설치 + + cordova plugin add org.apache.cordova.device + + +## ì†ì„± + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +코르ë„바는 장치ì—서 실행 ì¤‘ì¸ ë²„ì „ì„ ì–»ì„. + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* ë¸”ëž™ë² ë¦¬ 10 +* 브ë¼ìš°ì € +* Firefox ìš´ì˜ ì²´ì œ +* iOS +* Tizen +* Windows Phone 7ê³¼ 8 +* 윈ë„ìš° 8 + +## device.model + +`device.model`소ìžì˜ ëª¨ë¸ ë˜ëŠ” ì œí’ˆì˜ ì´ë¦„ì„ ë°˜í™˜ 합니다. ê°’ 장치 ì œì¡°ì—…ì²´ì—서 ì„¤ì • ë˜ ê³ ë™ì¼ ì œí’ˆì˜ ë²„ì „ ê°„ì— ë‹¤ë¥¼ 수 있습니다. + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 안 드 로ì´ë“œ +* ë¸”ëž™ë² ë¦¬ 10 +* 브ë¼ìš°ì € +* iOS +* Tizen +* Windows Phone 7ê³¼ 8 +* 윈ë„ìš° 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. Http://theiphonewiki.com/wiki/index.php?title=Models 참조 / / var ëª¨ë¸ = device.model; + + +### 안 드 로ì´ë“œ 단ì + +* ì–´ë–¤ì€ ì¢…ì¢… 프로ë•ì…˜ 코드 ì´ë¦„ ëŒ€ì‹ [ì œí’ˆ ëª¨ë¸ ì´ë¦„][1], [ì œí’ˆ ì´ë¦„][2] ì„ ê°€ì ¸ì˜µë‹ˆë‹¤. 예를 들어 넥서스 하나 반환 합니다 `Passion` , ëª¨í† ë¡œë¼ Droid를 반환 합니다`voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#MODEL + [2]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + +### Tizen 특수 + +* 예를 들어, 공급 ì—…ì²´ì— ì˜í•´ í• ë‹¹ ëœ ë””ë°”ì´ìФ 모ë¸ì„ 반환 합니다.`TIZEN` + +### Windows Phone 7, 8 특수 + +* ì œì¡°ì—…ì²´ì—서 ì§€ì • 하는 장치 모ë¸ì„ 반환 합니다. 예를 들어 삼성 í¬ì»¤ìŠ¤ë¥¼ 반환 합니다.`SGH-i917`. + +## device.platform + +ìž¥ì¹˜ì˜ ìš´ì˜ ì²´ì œ ì´ë¦„ì„ ì–»ì„. + + var string = device.platform; + + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 안 드 로ì´ë“œ +* ë¸”ëž™ë² ë¦¬ 10 +* Browser4 +* Firefox ìš´ì˜ ì²´ì œ +* iOS +* Tizen +* Windows Phone 7ê³¼ 8 +* 윈ë„ìš° 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 단ì + +Windows Phone 7 장치 ë³´ê³ í”Œëž«í¼ìœ¼ë¡œ`WinCE`. + +### Windows Phone 8 단ì + +Windows Phone 8 장치 ë³´ê³ í”Œëž«í¼ìœ¼ë¡œ`Win32NT`. + +## device.uuid + +소ìžì˜ 보편ì 으로 ê³ ìœ ì‹ë³„ìž ([UUID][3] 를 ì–»ì„합니다). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### 설명 + +UUID ìƒì„± ë°©ë²•ì˜ ìžì„¸í•œ ë‚´ìš©ì€ ìž¥ì¹˜ ì œì¡°ì—…ì²´ì— ì˜í•´ ê²°ì • ë©ë‹ˆë‹¤ ë° ì†Œìžì˜ í”Œëž«í¼ ì´ë‚˜ 모ë¸. + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 안 드 로ì´ë“œ +* ë¸”ëž™ë² ë¦¬ 10 +* iOS +* Tizen +* Windows Phone 7ê³¼ 8 +* 윈ë„ìš° 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + / / 안 드 로ì´ë“œ: (문ìžì—´ë¡œ 다시!) ìž„ì˜ì˜ 64 비트 ì •ìˆ˜ë¥¼ 반환 합니다 / / ì •ìˆ˜ ìž¥ì¹˜ì˜ ì²« 번째 부팅ì—서 ìƒì„± / / / / ë¸”ëž™ë² ë¦¬: 디바ì´ìŠ¤ì˜ í•€ 번호를 반환 합니다 / / ì´ê²ƒì€ 9 ìžë¦¬ ê³ ìœ ì •ìˆ˜ (문ìžì—´ë¡œ 비ë¡!) / / / / ì•„ì´í°: (UIDevice í´ëž˜ìФ 설명서ì—서 ìŠ ì—ˆ) / / 문ìžì—´ 여러 하드웨어ì—서 ìƒì„± 하는 해시 ê°’ì„ ì‹ë³„ 하는 반환 합니다. + / ê·¸ê²ƒì€ ëª¨ë“ ìž¥ì¹˜ì— ëŒ€ 한 ê³ ìœ í•´ì•¼ 보장 ë˜ ê³ ë¬¶ì¼ ìˆ˜ 없습니다 / / / ì‚¬ìš©ìž ê³„ì •ì—. + / / Windows Phone 7: 장치 + 현재 사용ìžì˜ 해시를 반환 합니다 / / ì‚¬ìš©ìž ì •ì˜ ë˜ì§€ ì•Šì€ ê²½ìš° guid ìƒì„± ë˜ ê³ ì‘ìš© í”„ë¡œê·¸ëž¨ì„ ì œê±°í• ë•Œê¹Œì§€ ìœ ì§€ ë©ë‹ˆë‹¤ / / Tizen: 반환 장치 IMEI (êµì œ ëª¨ë°”ì¼ ê¸°ê¸° ì‹ë³„ ë˜ëŠ” IMEI 숫ìžìž…니다 / / ëª¨ë“ GSM와 UMTS 휴대 ì „í™” ê³ ìœ . + var deviceID = device.uuid; + + +### iOS 특질 + +`uuid`ios ìž¥ì¹˜ì— ê³ ìœ í•˜ì§€ 않습니다 하지만 ê° ì„¤ì¹˜ì— ëŒ€ 한 ì‘ìš© 프로그램 마다 다릅니다. ì‚ì œ 하 ê³ ë‹¤ì‹œ ì• í”Œ 리 ì¼€ì´ ì…˜ì„ ì„¤ì¹˜ 하는 경우 변경 가능 하 게 ë˜í•œ iOS를 ì—…ê·¸ë ˆì´ë“œ 하거나 때 ë²„ì „ (iOS 5.1ì—ì—서 명백한) 당 ì‘ìš© 프로그램 ì—…ê·¸ë ˆì´ë“œë„ 하 ê³ . `uuid`ì€ ì‹ ë¢°í• ìˆ˜ 있는 ê°’ì´ ì•„ë‹™ë‹ˆë‹¤. + +### Windows Phone 7, 8 특수 + +`uuid`Windows Phone 7 í•„ìš” 허가 `ID_CAP_IDENTITY_DEVICE` . Microsoft는 ê³§ì´ ì†ì„±ì„ 세ì›ë‹ˆë‹¤ ê°€ëŠ¥ì„±ì´ ê²ƒìž…ë‹ˆë‹¤. ê¸°ëŠ¥ì„ ì‚¬ìš©í• ìˆ˜ 없는 경우 ì‘ìš© 프로그램 ìž¥ì¹˜ì— ì‘ìš© í”„ë¡œê·¸ëž¨ì˜ ì„¤ì¹˜ 하는 ë™ì•ˆ ìœ ì§€ 하는 ì˜êµ¬ guid를 ìƒì„± 합니다. + +## device.version + +ìš´ì˜ ì²´ì œ ë²„ì „ì„ ì–»ì„. + + var string = device.version; + + +### ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 안 드 로ì´ë“œ 2.1 + +* ë¸”ëž™ë² ë¦¬ 10 +* 브ë¼ìš°ì € +* iOS +* Tizen +* Windows Phone 7ê³¼ 8 +* 윈ë„ìš° 8 + +### ë¹ ë¥¸ ì˜ˆì œ + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/pl/index.md b/plugins/org.apache.cordova.device/doc/pl/index.md new file mode 100644 index 00000000..3806d050 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/pl/index.md @@ -0,0 +1,206 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +Ten plugin określa globalne `device` obiekt, który opisuje urządzenia sprzętowe i programowe. Mimo, że obiekt jest w globalnym zasięgu, nie jest dostępne dopiero po `deviceready` zdarzenie. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## Instalacja + + cordova plugin add org.apache.cordova.device + + +## Właściwości + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +Pobierz wersję Cordova działa na urządzeniu. + +### Obsługiwane platformy + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Przeglądarka +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 i 8 +* Windows 8 + +## device.model + +`device.model`Zwraca nazwę modelu lub produktu. Wartość jest zestaw przez producenta urządzenia i mogą się różnić między wersjami tego samego produktu. + +### Obsługiwane platformy + +* Android +* BlackBerry 10 +* Przeglądarka +* iOS +* Tizen +* Windows Phone 7 i 8 +* Windows 8 + +### Szybki przykład + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. Zobacz http://theiphonewiki.com/wiki/index.php?title=Models / / modelu var = device.model; + + +### Dziwactwa Androida + +* Pobiera [nazwę produktu][1] zamiast [nazwy modelu][2], który często jest nazwą kod produkcji. Na przykład, Nexus One zwraca `Passion` , i zwraca Motorola Droid`voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### Dziwactwa Tizen + +* Zwraca modelu urządzenia przypisane przez dostawcę, na przykład,`TIZEN` + +### Windows Phone 7 i 8 dziwactwa + +* Zwraca modelu urządzenia, określonej przez producenta. Na przykład Samsung ostrości zwraca`SGH-i917`. + +## device.platform + +Uzyskać nazwę systemu operacyjnego urządzenia. + + var string = device.platform; + + +### Obsługiwane platformy + +* Android +* BlackBerry 10 +* Browser4 +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 i 8 +* Windows 8 + +### Szybki przykład + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Dziwactwa Windows Phone 7 + +Urządzenia Windows Phone 7 raport platformy jako`WinCE`. + +### Windows Phone 8 dziwactwa + +Urządzenia Windows Phone 8 raport platformy jako`Win32NT`. + +## device.uuid + +Się urządzenia uniwersalnie unikatowy identyfikator ([UUID][3]). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### Opis + +Szczegóły jak UUID jest generowane są określane przez producenta urządzenia i są specyficzne dla platformy lub modelu urządzenia. + +### Obsługiwane platformy + +* Android +* BlackBerry 10 +* iOS +* Tizen +* Windows Phone 7 i 8 +* Windows 8 + +### Szybki przykład + + / / Android: zwraca losowe 64-bitowa liczba całkowita (jako ciąg, znowu!) / / liczba całkowita jest generowany na pierwszego uruchomienia urządzenia / / / / BlackBerry: zwraca numer PIN urządzenia / / to jest unikatową liczbą całkowitą dziewięciu cyfr (jako ciąg, choć!) / / / / iPhone: (zacytowana w dokumentacji klasy UIDevice) / / zwraca ciąg wartości mieszania utworzone z wielu sprzętu identyfikuje. + Zapewniona jest unikatowy dla każdego urządzenia i nie może być związane z / do konta użytkownika. + / / Windows Phone 7: zwraca wartość mieszania urządzenia + bieżący użytkownik, / / jeśli nie zdefiniowane przez użytkownika, identyfikator guid jest generowany i będzie trwać do czasu odinstalowania aplikacji / / Tizen: zwraca urządzenia IMEI (International Mobile Equipment Identity lub IMEI jest liczbą / / unikatowe dla każdego telefonu komórkowego GSM i UMTS. + var deviceID = device.uuid; + + +### iOS dziwactwo + +`uuid`Na iOS nie jest przypisany do urządzenia, ale różni się dla każdej aplikacji, dla każdej instalacji. Zmienia się jeśli możesz usunąć i ponownie zainstalować aplikację, a ewentualnie także po aktualizacji iOS czy nawet uaktualnienia aplikacji dla wersji (widoczny w iOS 5.1). `uuid`Jest nie wiarygodne wartości. + +### Windows Phone 7 i 8 dziwactwa + +`uuid`Dla Windows Phone 7 wymaga uprawnień `ID_CAP_IDENTITY_DEVICE` . Microsoft będzie prawdopodobnie potępiać ten wkrótce. Jeśli funkcja nie jest dostępna, aplikacja generuje trwałe identyfikator guid, który jest utrzymywany przez czas trwania instalacji aplikacji na urządzeniu. + +## device.version + +Pobierz wersję systemu operacyjnego. + + var string = device.version; + + +### Obsługiwane platformy + +* Android 2.1 + +* BlackBerry 10 +* Przeglądarka +* iOS +* Tizen +* Windows Phone 7 i 8 +* Windows 8 + +### Szybki przykład + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/ru/index.md b/plugins/org.apache.cordova.device/doc/ru/index.md new file mode 100644 index 00000000..c0195748 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/ru/index.md @@ -0,0 +1,219 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +Ðтот плагин определÑет глобальный объект `device`, который опиÑывает оборудование и программное обеÑпечение уÑтройÑтва. ÐеÑÐ¼Ð¾Ñ‚Ñ€Ñ Ð½Ð° то что объект в глобальной облаÑти видимоÑти, он не доÑтупен до того момента пока не произойдет Ñобытие `deviceready`. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## УÑтановка + + cordova plugin add org.apache.cordova.device + + +## Параметры + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +Возвращает верÑию Cordova, работающую на уÑтройÑтве. + +### Поддерживаемые платформы + +* Amazon Fire OS +* Android +* BlackBerry 10 +* Обозреватель +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 и 8 +* Windows 8 + +## device.model + +СвойÑтво `device.model` возвращает Ð¸Ð¼Ñ ÑƒÑтройÑтва модели или продукта. Значение уÑтанавливаетÑÑ Ð¿Ñ€Ð¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ‚ÐµÐ»ÐµÐ¼ уÑтройÑтва и могут отличатьÑÑ Ð² разных верÑиÑÑ… одного и того же продукта. + +### Поддерживаемые платформы + +* Android +* BlackBerry 10 +* Обозреватель +* iOS +* Tizen +* Windows Phone 7 и 8 +* Windows 8 + +### Краткий пример + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models + // + var model = device.model; + + +### ОÑобенноÑти Android + +* Возвращает [Ð¸Ð¼Ñ Ð¿Ñ€Ð¾Ð´ÑƒÐºÑ‚Ð°][1] , а не [Ð¸Ð¼Ñ Ð¼Ð¾Ð´ÐµÐ»Ð¸][2], которое чаÑто ÑвлÑетÑÑ Ð¿Ñ€Ð¾Ð¸Ð·Ð²Ð¾Ð´Ñтвенным кодом. Ðапример, Nexus One из них возвращает `Passion` , и Motorola Droid возвращает `voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### ОÑобенноÑти Tizen + +* Возвращает модель уÑтройÑтва, назначенного вендором, например,`TIZEN` + +### ОÑобенноÑти Windows Phone 7 и 8 + +* Возвращает модель уÑтройÑтва, указанной заводом-изготовителем. Ðапример Samsung Focus возвращает `SGH-i917`. + +## device.platform + +Получите Ð¸Ð¼Ñ Ð¾Ð¿ÐµÑ€Ð°Ñ†Ð¸Ð¾Ð½Ð½Ð¾Ð¹ ÑиÑтемы уÑтройÑтва. + + var string = device.platform; + + +### Поддерживаемые платформы + +* Android +* BlackBerry 10 +* Браузером4 +* Firefox OS +* iOS +* Tizen +* Windows Phone 7 и 8 +* Windows 8 + +### Краткий пример + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### ОÑобенноÑти Windows Phone 7 + +Windows Phone 7 уÑтройÑтва Ñообщают платформу как `WinCE`. + +### ОÑобенноÑти Windows Phone 8 + +УÑтройÑтва Windows Phone 8 Ñообщают платформу как `Win32NT`. + +## device.uuid + +Возвращает универÑальный уникального идентификатора ([UUID][3] уÑтройÑтва). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### ОпиÑание + +ÐŸÐ¾Ð´Ñ€Ð¾Ð±Ð½Ð°Ñ Ð¸Ð½Ñ„Ð¾Ñ€Ð¼Ð°Ñ†Ð¸Ñ Ð¾ том как UUID генерируетÑÑ, определÑÑŽÑ‚ÑÑ Ð¸Ð·Ð³Ð¾Ñ‚Ð¾Ð²Ð¸Ñ‚ÐµÐ»ÐµÐ¼ уÑтройÑтва и ÑвлÑÑŽÑ‚ÑÑ ÑпецифичеÑкими Ð´Ð»Ñ Ð¿Ð»Ð°Ñ‚Ñ„Ð¾Ñ€Ð¼Ñ‹ или модели уÑтройÑтва. + +### Поддерживаемые платформы + +* Android +* BlackBerry 10 +* iOS +* Tizen +* Windows Phone 7 и 8 +* Windows 8 + +### Краткий пример + + // Android: Возвращает Ñлучайное 64-разрÑдное целое чиÑло (в виде Ñтроки, опÑть!) + // целое чиÑло генерируетÑÑ Ð¿Ñ€Ð¸ первой загрузке уÑтройÑтва + // + // BlackBerry: Возвращает номер PIN уÑтройÑтва + // Ñто 9 значный уникальный целочиÑленный (как Ñтрока, хотÑ!) + // + // iPhone: (Перефразировано из документации клаÑÑа UIDevice) + // возвращает Ñтроку Ñ…Ñш-значениÑ, Ñозданные из неÑкольких аппаратных определÑет. + // Ðто значение гарантированно ÑвлÑетÑÑ ÑƒÐ½Ð¸ÐºÐ°Ð»ÑŒÐ½Ñ‹Ð¼ Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ уÑтройÑтва и не может быть привÑзано + // к учетной запиÑи пользователÑ. + // Windows Phone 7: Возвращает Ñ…Ñш уÑтройÑтво + текущего пользователÑ, + // еÑли пользователь не определен, формируетÑÑ guid который и будет ÑохранÑтьÑÑ Ð´Ð¾ тех пор, пока приложение не удалитьÑÑ + // Tizen: возвращает IMEI уÑтройÑтва (Международный идентификатор мобильного Ð¾Ð±Ð¾Ñ€ÑƒÐ´Ð¾Ð²Ð°Ð½Ð¸Ñ Ð¸Ð»Ð¸ IMEI Ñто чиÑло + // уникальное Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ мобильного телефона GSM и UMTS. + var deviceID = device.uuid; + + +### ОÑобенноÑти iOS + +Ðа iOS `uuid` не ÑвлÑетÑÑ ÑƒÐ½Ð¸ÐºÐ°Ð»ÑŒÐ½Ñ‹Ð¼ Ð´Ð»Ñ ÑƒÑтройÑтва, но варьируетÑÑ Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ приложениÑ, и Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ уÑтановки. Значение менÑетÑÑ, еÑли удалить и повторно уÑтановить приложение, и возможно также когда вы обновите iOS, или даже обновить приложение до Ñледующей верÑии (очевидно в iOS 5.1). Значение `uuid` не ÑвлÑетÑÑ Ð½Ð°Ð´ÐµÐ¶Ð½Ñ‹Ð¼. + +### ОÑобенноÑти Windows Phone 7 и 8 + +Ð”Ð»Ñ Windows Phone 7 `uuid` требует Ñ€Ð°Ð·Ñ€ÐµÑˆÐµÐ½Ð¸Ñ `ID_CAP_IDENTITY_DEVICE` . Microsoft Ñкорее вÑего Ñкоро Ñделает Ñто ÑвойÑтво уÑтаревшим. ЕÑли возможноÑть недоÑтупна, приложение Ñоздает поÑтоÑнные guid, который ÑохранÑетÑÑ Ð½Ð° вÑе Ð²Ñ€ÐµÐ¼Ñ ÑƒÑтановки Ð¿Ñ€Ð¸Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð½Ð° уÑтройÑтве. + +## device.version + +Возвращает верÑию операционной ÑиÑтемы. + + var string = device.version; + + +### Поддерживаемые платформы + +* Android 2.1 + +* BlackBerry 10 +* Обозреватель +* iOS +* Tizen +* Windows Phone 7 и 8 +* Windows 8 + +### Краткий пример + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/doc/zh/index.md b/plugins/org.apache.cordova.device/doc/zh/index.md new file mode 100644 index 00000000..58818a85 --- /dev/null +++ b/plugins/org.apache.cordova.device/doc/zh/index.md @@ -0,0 +1,206 @@ +<!--- + 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. +--> + +# org.apache.cordova.device + +這個外掛程å¼å®šç¾©å…¨çƒ `device` 物件,æè¿°è©²è¨å‚™çš„硬體和軟體。 雖然物件是在全çƒç¯„åœå…§ï¼Œä½†ä¸æ˜¯å¯ç”¨ï¼Œç›´åˆ°å¾Œ `deviceready` 事件。 + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(device.cordova); + } + + +## å®‰è£ + + cordova plugin add org.apache.cordova.device + + +## 屬性 + +* device.cordova +* device.model +* device.platform +* device.uuid +* device.version + +## device.cordova + +ç²å–科爾多瓦在è¨å‚™ä¸Šé‹è¡Œçš„版本。 + +### 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* 黑莓 10 +* ç€è¦½å™¨ +* ç«ç‹ç€è¦½å™¨çš„作æ¥ç³»çµ± +* iOS +* æ³° +* Windows Phone 7 å’Œ 8 +* Windows 8 + +## device.model + +`device.model`返回è¨å‚™çš„æ¨¡åž‹æˆ–產å“çš„å稱。值由è¨å‚™è£½é€ 商è¨ç½®å’ŒåŒä¸€ç”¢å“çš„ä¸åŒç‰ˆæœ¬å¯èƒ½ä¸åŒã€‚ + +### 支æ´çš„平臺 + +* Android 系統 +* 黑莓 10 +* ç€è¦½å™¨ +* iOS +* æ³° +* Windows Phone 7 å’Œ 8 +* Windows 8 + +### 快速的示例 + + // Android: Nexus One returns "Passion" (Nexus One code name) + // Motorola Droid returns "voles" + // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" + // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. è«‹åƒé–± HTTP://theiphonewiki.com/wiki/index.php?title=Models / / var 模型 = device.model ï¼› + + +### Android 的怪癖 + +* ç²å–[產å“å稱][1]è€Œä¸æ˜¯[產å“型號å稱][2],這往往是生產代碼å稱。 例如,Nexus One 返回 `Passion` ,和摩托羅拉 Droid 返回`voles`. + + [1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT + [2]: http://developer.android.com/reference/android/os/Build.html#MODEL + +### Tizen 怪癖 + +* 例如,返回與供應商指派的è¨å‚™æ¨¡åž‹`TIZEN` + +### Windows Phone 7 å’Œ 8 怪癖 + +* è¿”å›žç”±è£½é€ å•†æŒ‡å®šçš„è¨å‚™æ¨¡åž‹ã€‚例如,三星焦點返回`SGH-i917`. + +## device.platform + +ç²å–è¨å‚™çš„作æ¥ç³»çµ±å稱。 + + var string = device.platform; + + +### 支æ´çš„平臺 + +* Android 系統 +* 黑莓 10 +* Browser4 +* ç«ç‹ç€è¦½å™¨çš„作æ¥ç³»çµ± +* iOS +* æ³° +* Windows Phone 7 å’Œ 8 +* Windows 8 + +### 快速的示例 + + // Depending on the device, a few examples are: + // - "Android" + // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows + // - "iOS" + // - "WinCE" + // - "Tizen" + var devicePlatform = device.platform; + + +### Windows Phone 7 的怪癖 + +Windows Phone 7 è¨å‚™å ±å‘Šä½œç‚ºå¹³è‡º`WinCE`. + +### Windows Phone 8 怪癖 + +Windows Phone 8 è¨å‚™å ±å‘Šä½œç‚ºå¹³è‡º`Win32NT`. + +## device.uuid + +ç²å–è¨å‚™çš„通用唯一è˜åˆ¥ç¢¼ ([UUID][3]). + + [3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier + + var string = device.uuid; + + +### 說明 + +如何生æˆä¸€å€‹ UUID 的細節由è¨å‚™è£½é€ 商和特定于è¨å‚™çš„平臺或模型。 + +### 支æ´çš„平臺 + +* Android 系統 +* 黑莓 10 +* iOS +* Tizen +* Windows Phone 7 å’Œ 8 +* Windows 8 + +### 快速的示例 + + / / Android: 一個隨機的 64 使•´æ•¸ (作為å—ä¸²è¿”å›žï¼Œå†æ¬¡!) / / 上è¨å‚™çš„第一次啟動生æˆçš„æ•´æ•¸ / / / / 黑莓手機: 返回è¨å‚™çš„ PIN 號碼 / / 這是ä¹å€‹æ•¸å—的唯一整數 (作為å—串,雖然!) / / / / iPhone: (從 UIDevice 類文檔解釋) / / 返回一個å—串的雜湊值創建的多個硬體標è˜ã€‚ + / / 它ä¿è‰æ˜¯å”¯ä¸€çš„æ¯å€‹è¨å‚™ä¸¦ä¸èƒ½ç¶ / / 到使用者帳戶。 + / / Windows Phone 7: 返回的雜湊代碼的è¨å‚™ + ç•¶å‰ä½¿ç”¨è€…,/ / 如果未定義使用者,則一個 guid 生æˆçš„並且將會ä¿ç•™ç›´åˆ°å¸è¼‰è©²æ‡‰ç”¨ç¨‹å¼ / / Tizen: 返回è¨å‚™ IMEI (國際行動è£ç½®èº«ä»½æˆ– IMEI æ˜¯ä¸€å€‹æ•¸ä½ / / ç¨æœ‰çš„æ¯ä¸€å€‹ UMTS å’Œ GSM 行動電話。 + var deviceID = device.uuid; + + +### iOS 怪癖 + +`uuid`在 iOS 䏿˜¯å”¯ä¸€çš„一種è£ç½®ï¼Œä½†å°æ–¼æ¯å€‹æ‡‰ç”¨ç¨‹å¼ï¼Œç‚ºæ¯å€‹å®‰è£è€Œç•°ã€‚ å¦‚æžœæ‚¨åˆªé™¤ä¸¦é‡æ–°å®‰è£è©²æ‡‰ç”¨ç¨‹å¼ï¼Œå®ƒæ›´æ”¹å’Œå¯èƒ½é‚„ç•¶ä½ å‡ç´š iOS,或甚至å‡ç´šæ¯å€‹ç‰ˆæœ¬ (iOS 5.1 ä¸å˜åœ¨æ˜Žé¡¯çš„) 的應用程å¼ã€‚ `uuid`䏿˜¯ä¸€å€‹å¯é 的值。 + +### Windows Phone 7 å’Œ 8 怪癖 + +`uuid`為 Windows Phone 7 é ˆç¶“è¨±å¯ `ID_CAP_IDENTITY_DEVICE` 。 Microsoft å¯èƒ½æœƒå¾ˆå¿«æ£„用æ¤å±¬æ€§ã€‚ 如果沒有å¯ç”¨çš„能力,應用程å¼å°‡ç”Ÿæˆè¨å‚™ä¸Šæ‡‰ç”¨ç¨‹å¼çš„安è£éŽç¨‹ä¸ä¿æŒæŒçºŒçš„ guid。 + +## device.version + +ç²å–作æ¥ç³»çµ±ç‰ˆæœ¬ã€‚ + + var string = device.version; + + +### 支æ´çš„平臺 + +* Android 2.1 + +* 黑莓 10 +* ç€è¦½å™¨ +* iOS +* æ³° +* Windows Phone 7 å’Œ 8 +* Windows 8 + +### 快速的示例 + + // Android: Froyo OS would return "2.2" + // Eclair OS would return "2.1", "2.0.1", or "2.0" + // Version can also return update level "2.1-update1" + // + // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" + // + // Browser: Returns version number for the browser + // + // iPhone: iOS 3.2 returns "3.2" + // + // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 + // Tizen: returns "TIZEN_20120425_2" + var deviceVersion = device.version;
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/package.json b/plugins/org.apache.cordova.device/package.json new file mode 100644 index 00000000..b2036819 --- /dev/null +++ b/plugins/org.apache.cordova.device/package.json @@ -0,0 +1,29 @@ +{ + "version": "0.3.0", + "name": "org.apache.cordova.device", + "cordova_name": "Device", + "description": "Cordova Device Plugin", + "license": "Apache 2.0", + "repo": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git", + "issue": "https://issues.apache.org/jira/browse/CB/component/12320648", + "keywords": [ + "cordova", + "device" + ], + "platforms": [ + "firefoxos", + "tizen", + "android", + "amazon-fireos", + "ubuntu", + "ios", + "blackberry10", + "wp7", + "wp8", + "windows8", + "windows", + "browser" + ], + "engines": [], + "englishdoc": "<!---\n Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n-->\n\n# org.apache.cordova.device\n\nThis plugin defines a global `device` object, which describes the device's hardware and software.\nAlthough the object is in the global scope, it is not available until after the `deviceready` event.\n\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n function onDeviceReady() {\n console.log(device.cordova);\n }\n\n## Installation\n\n cordova plugin add org.apache.cordova.device\n\n## Properties\n\n- device.cordova\n- device.model\n- device.platform\n- device.uuid\n- device.version\n\n## device.cordova\n\nGet the version of Cordova running on the device.\n\n### Supported Platforms\n\n- Amazon Fire OS\n- Android\n- BlackBerry 10\n- Browser\n- Firefox OS\n- iOS\n- Tizen\n- Windows Phone 7 and 8\n- Windows 8\n\n## device.model\n\nThe `device.model` returns the name of the device's model or\nproduct. The value is set by the device manufacturer and may be\ndifferent across versions of the same product.\n\n### Supported Platforms\n\n- Android\n- BlackBerry 10\n- Browser\n- iOS\n- Tizen\n- Windows Phone 7 and 8\n- Windows 8\n\n### Quick Example\n\n // Android: Nexus One returns \"Passion\" (Nexus One code name)\n // Motorola Droid returns \"voles\"\n // BlackBerry: Torch 9800 returns \"9800\"\n // Browser: Google Chrome returns \"Chrome\"\n // Safari returns \"Safari\"\n // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models\n //\n var model = device.model;\n\n### Android Quirks\n\n- Gets the [product name](http://developer.android.com/reference/android/os/Build.html#PRODUCT) instead of the [model name](http://developer.android.com/reference/android/os/Build.html#MODEL), which is often the production code name. For example, the Nexus One returns `Passion`, and Motorola Droid returns `voles`.\n\n### Tizen Quirks\n\n- Returns the device model assigned by the vendor, for example, `TIZEN`\n\n### Windows Phone 7 and 8 Quirks\n\n- Returns the device model specified by the manufacturer. For example, the Samsung Focus returns `SGH-i917`.\n\n## device.platform\n\nGet the device's operating system name.\n\n var string = device.platform;\n\n### Supported Platforms\n\n- Android\n- BlackBerry 10\n- Browser4\n- Firefox OS\n- iOS\n- Tizen\n- Windows Phone 7 and 8\n- Windows 8\n\n### Quick Example\n\n // Depending on the device, a few examples are:\n // - \"Android\"\n // - \"BlackBerry 10\"\n // - Browser: returns \"MacIntel\" on Mac\n // returns \"Win32\" on Windows\n // - \"iOS\"\n // - \"WinCE\"\n // - \"Tizen\"\n var devicePlatform = device.platform;\n\n### Windows Phone 7 Quirks\n\nWindows Phone 7 devices report the platform as `WinCE`.\n\n### Windows Phone 8 Quirks\n\nWindows Phone 8 devices report the platform as `Win32NT`.\n\n## device.uuid\n\nGet the device's Universally Unique Identifier ([UUID](http://en.wikipedia.org/wiki/Universally_Unique_Identifier)).\n\n var string = device.uuid;\n\n### Description\n\nThe details of how a UUID is generated are determined by the device manufacturer and are specific to the device's platform or model.\n\n### Supported Platforms\n\n- Android\n- BlackBerry 10\n- iOS\n- Tizen\n- Windows Phone 7 and 8\n- Windows 8\n\n### Quick Example\n\n // Android: Returns a random 64-bit integer (as a string, again!)\n // The integer is generated on the device's first boot\n //\n // BlackBerry: Returns the PIN number of the device\n // This is a nine-digit unique integer (as a string, though!)\n //\n // iPhone: (Paraphrased from the UIDevice Class documentation)\n // Returns a string of hash values created from multiple hardware identifies.\n // It is guaranteed to be unique for every device and can't be tied\n // to the user account.\n // Windows Phone 7 : Returns a hash of device+current user,\n // if the user is not defined, a guid is generated and will persist until the app is uninstalled\n // Tizen: returns the device IMEI (International Mobile Equipment Identity or IMEI is a number\n // unique to every GSM and UMTS mobile phone.\n var deviceID = device.uuid;\n\n### iOS Quirk\n\nThe `uuid` on iOS is not unique to a device, but varies for each\napplication, for each installation. It changes if you delete and\nre-install the app, and possibly also when you upgrade iOS, or even\nupgrade the app per version (apparent in iOS 5.1). The `uuid` is not\na reliable value.\n\n### Windows Phone 7 and 8 Quirks\n\nThe `uuid` for Windows Phone 7 requires the permission\n`ID_CAP_IDENTITY_DEVICE`. Microsoft will likely deprecate this\nproperty soon. If the capability is not available, the application\ngenerates a persistent guid that is maintained for the duration of the\napplication's installation on the device.\n\n## device.version\n\nGet the operating system version.\n\n var string = device.version;\n\n### Supported Platforms\n\n- Android 2.1+\n- BlackBerry 10\n- Browser\n- iOS\n- Tizen\n- Windows Phone 7 and 8\n- Windows 8\n\n### Quick Example\n\n // Android: Froyo OS would return \"2.2\"\n // Eclair OS would return \"2.1\", \"2.0.1\", or \"2.0\"\n // Version can also return update level \"2.1-update1\"\n //\n // BlackBerry: Torch 9800 using OS 6.0 would return \"6.0.0.600\"\n //\n // Browser: Returns version number for the browser\n //\n // iPhone: iOS 3.2 returns \"3.2\"\n //\n // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720\n // Tizen: returns \"TIZEN_20120425_2\"\n var deviceVersion = device.version;\n\n" +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.device/plugin.xml b/plugins/org.apache.cordova.device/plugin.xml new file mode 100644 index 00000000..c5052880 --- /dev/null +++ b/plugins/org.apache.cordova.device/plugin.xml @@ -0,0 +1,168 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + xmlns:rim="http://www.blackberry.com/ns/widgets" + xmlns:android="http://schemas.android.com/apk/res/android" + id="org.apache.cordova.device" + version="0.3.0"> + <name>Device</name> + <description>Cordova Device Plugin</description> + <license>Apache 2.0</license> + <keywords>cordova,device</keywords> + <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git</repo> + <issue>https://issues.apache.org/jira/browse/CB/component/12320648</issue> + + <js-module src="www/device.js" name="device"> + <clobbers target="device" /> + </js-module> + + <!-- firefoxos --> + <platform name="firefoxos"> + <config-file target="config.xml" parent="/*"> + <feature name="Device"> + <param name="firefoxos-package" value="Device" /> + </feature> + </config-file> + + <js-module src="src/firefoxos/DeviceProxy.js" name="DeviceProxy"> + <runs /> + </js-module> + </platform> + + <!-- tizen --> + <platform name="tizen"> + <js-module src="src/tizen/DeviceProxy.js" name="DeviceProxy"> + <runs /> + </js-module> + </platform> + + <!-- android --> + <platform name="android"> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="Device" > + <param name="android-package" value="org.apache.cordova.device.Device"/> + </feature> + </config-file> + + <source-file src="src/android/Device.java" target-dir="src/org/apache/cordova/device" /> + </platform> + + <!-- amazon-fireos --> + <platform name="amazon-fireos"> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="Device" > + <param name="android-package" value="org.apache.cordova.device.Device"/> + </feature> + </config-file> + + <source-file src="src/android/Device.java" target-dir="src/org/apache/cordova/device" /> + </platform> + + <!-- ubuntu --> + <platform name="ubuntu"> + <header-file src="src/ubuntu/device.h" /> + <source-file src="src/ubuntu/device.cpp" /> + <js-module src="src/ubuntu/device.js" name="DeviceProxy"> + <merges target="device" /> + </js-module> + </platform> + + <!-- ios --> + <platform name="ios"> + <config-file target="config.xml" parent="/*"> + <feature name="Device"> + <param name="ios-package" value="CDVDevice"/> + </feature> + </config-file> + + <header-file src="src/ios/CDVDevice.h" /> + <source-file src="src/ios/CDVDevice.m" /> + </platform> + + <!-- blackberry10 --> + <platform name="blackberry10"> + <source-file src="src/blackberry10/index.js" target-dir="Device" /> + <config-file target="www/config.xml" parent="/widget"> + <feature name="Device" value="Device"/> + </config-file> + <config-file target="www/config.xml" parent="/widget/rim:permissions"> + <rim:permit>read_device_identifying_information</rim:permit> + </config-file> + </platform> + + <!-- wp7 --> + <platform name="wp7"> + <config-file target="config.xml" parent="/*"> + <feature name="Device"> + <param name="wp-package" value="Device"/> + </feature> + </config-file> + + <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> + <Capability Name="ID_CAP_IDENTITY_DEVICE" /> + </config-file> + + <source-file src="src/wp/Device.cs" /> + </platform> + + <!-- wp8 --> + <platform name="wp8"> + <config-file target="config.xml" parent="/*"> + <feature name="Device"> + <param name="wp-package" value="Device"/> + </feature> + </config-file> + + <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> + <Capability Name="ID_CAP_IDENTITY_DEVICE" /> + </config-file> + + <source-file src="src/wp/Device.cs" /> + </platform> + + <!-- windows8 --> + <platform name="windows8"> + <js-module src="src/windows8/DeviceProxy.js" name="DeviceProxy"> + <merges target="" /> + </js-module> + </platform> + + <!-- windows --> + <platform name="windows"> + <js-module src="src/windows/DeviceProxy.js" name="DeviceProxy"> + <merges target="" /> + </js-module> + </platform> + + <!-- browser --> + <platform name="browser"> + <config-file target="config.xml" parent="/*"> + <feature name="Device"> + <param name="browser-package" value="Device" /> + </feature> + </config-file> + + <js-module src="src/browser/DeviceProxy.js" name="DeviceProxy"> + <runs /> + </js-module> + </platform> + +</plugin> diff --git a/plugins/org.apache.cordova.device/src/android/Device.java b/plugins/org.apache.cordova.device/src/android/Device.java new file mode 100644 index 00000000..5eded907 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/android/Device.java @@ -0,0 +1,161 @@ +/* + 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. +*/ +package org.apache.cordova.device; + +import java.util.TimeZone; + +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaInterface; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.provider.Settings; + +public class Device extends CordovaPlugin { + public static final String TAG = "Device"; + + public static String platform; // Device OS + public static String uuid; // Device UUID + + private static final String ANDROID_PLATFORM = "Android"; + private static final String AMAZON_PLATFORM = "amazon-fireos"; + private static final String AMAZON_DEVICE = "Amazon"; + + /** + * Constructor. + */ + public Device() { + } + + /** + * Sets the context of the Command. This can then be used to do things like + * get file paths associated with the Activity. + * + * @param cordova The context of the main Activity. + * @param webView The CordovaWebView Cordova is running in. + */ + public void initialize(CordovaInterface cordova, CordovaWebView webView) { + super.initialize(cordova, webView); + Device.uuid = getUuid(); + } + + /** + * Executes the request and returns PluginResult. + * + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackContext The callback id used when calling back into JavaScript. + * @return True if the action was valid, false if not. + */ + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + if (action.equals("getDeviceInfo")) { + JSONObject r = new JSONObject(); + r.put("uuid", Device.uuid); + r.put("version", this.getOSVersion()); + r.put("platform", this.getPlatform()); + r.put("model", this.getModel()); + r.put("manufacturer", this.getManufacturer()); + callbackContext.success(r); + } + else { + return false; + } + return true; + } + + //-------------------------------------------------------------------------- + // LOCAL METHODS + //-------------------------------------------------------------------------- + + /** + * Get the OS name. + * + * @return + */ + public String getPlatform() { + String platform; + if (isAmazonDevice()) { + platform = AMAZON_PLATFORM; + } else { + platform = ANDROID_PLATFORM; + } + return platform; + } + + /** + * Get the device's Universally Unique Identifier (UUID). + * + * @return + */ + public String getUuid() { + String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); + return uuid; + } + + public String getModel() { + String model = android.os.Build.MODEL; + return model; + } + + public String getProductName() { + String productname = android.os.Build.PRODUCT; + return productname; + } + + public String getManufacturer() { + String manufacturer = android.os.Build.MANUFACTURER; + return manufacturer; + } + /** + * Get the OS version. + * + * @return + */ + public String getOSVersion() { + String osversion = android.os.Build.VERSION.RELEASE; + return osversion; + } + + public String getSDKVersion() { + @SuppressWarnings("deprecation") + String sdkversion = android.os.Build.VERSION.SDK; + return sdkversion; + } + + public String getTimeZoneID() { + TimeZone tz = TimeZone.getDefault(); + return (tz.getID()); + } + + /** + * Function to check if the device is manufactured by Amazon + * + * @return + */ + public boolean isAmazonDevice() { + if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) { + return true; + } + return false; + } + +} diff --git a/plugins/org.apache.cordova.device/src/blackberry10/index.js b/plugins/org.apache.cordova.device/src/blackberry10/index.js new file mode 100644 index 00000000..77f25a9e --- /dev/null +++ b/plugins/org.apache.cordova.device/src/blackberry10/index.js @@ -0,0 +1,69 @@ +/* + * + * 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. + * +*/ + +function getModelName () { + var modelName = window.qnx.webplatform.device.modelName; + //Pre 10.2 (meaning Z10 or Q10) + if (typeof modelName === "undefined") { + if (window.screen.height === 720 && window.screen.width === 720) { + if ( window.matchMedia("(-blackberry-display-technology: -blackberry-display-oled)").matches) { + modelName = "Q10"; + } else { + modelName = "Q5"; + } + } else if ((window.screen.height === 1280 && window.screen.width === 768) || + (window.screen.height === 768 && window.screen.width === 1280)) { + modelName = "Z10"; + } else { + modelName = window.qnx.webplatform.deviceName; + } + } + + return modelName; +} + +function getUUID () { + var uuid = ""; + try { + //Must surround by try catch because this will throw if the app is missing permissions + uuid = window.qnx.webplatform.device.devicePin; + } catch (e) { + //DO Nothing + } + return uuid; +} + +module.exports = { + getDeviceInfo: function (success, fail, args, env) { + var result = new PluginResult(args, env), + modelName = getModelName(), + uuid = getUUID(), + info = { + manufacturer: 'BlackBerry', + platform: "blackberry10", + version: window.qnx.webplatform.device.scmBundle, + model: modelName, + uuid: uuid + }; + + result.ok(info); + } +}; diff --git a/plugins/org.apache.cordova.device/src/browser/DeviceProxy.js b/plugins/org.apache.cordova.device/src/browser/DeviceProxy.js new file mode 100644 index 00000000..fcaed20c --- /dev/null +++ b/plugins/org.apache.cordova.device/src/browser/DeviceProxy.js @@ -0,0 +1,82 @@ +/* + * + * 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 browser = require('cordova/platform'); +var cordova = require('cordova'); + +function getPlatform() { + return "browser"; +} + +function getModel() { + return getBrowserInfo(true); +} + +function getVersion() { + return getBrowserInfo(false); +} + +function getBrowserInfo(getModel) { + var userAgent = navigator.userAgent; + var returnVal = ''; + + if ((offset = userAgent.indexOf('Chrome')) !== -1) { + returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7); + } else if ((offset = userAgent.indexOf('Safari')) !== -1) { + if (getModel) { + returnVal = 'Safari'; + } else { + returnVal = userAgent.substring(offset + 7); + + if ((offset = userAgent.indexOf('Version')) !== -1) { + returnVal = userAgent.substring(offset + 8); + } + } + } else if ((offset = userAgent.indexOf('Firefox')) !== -1) { + returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8); + } else if ((offset = userAgent.indexOf('MSIE')) !== -1) { + returnVal = (getModel) ? 'MSIE' : userAgent.substring(offset + 5); + } else if ((offset = userAgent.indexOf('Trident')) !== -1) { + returnVal = (getModel) ? 'MSIE' : '11'; + } + + if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) { + returnVal = returnVal.substring(0, offset); + } + + return returnVal; +} + + +module.exports = { + getDeviceInfo: function (success, error) { + setTimeout(function () { + success({ + cordova: browser.cordovaVersion, + platform: getPlatform(), + model: getModel(), + version: getVersion(), + uuid: null + }); + }, 0); + } +}; + +require("cordova/exec/proxy").add("Device", module.exports); diff --git a/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js b/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js new file mode 100644 index 00000000..79f3a2b0 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js @@ -0,0 +1,79 @@ +/* + * + * 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. + * + */ +//example UA String for Firefox OS +//Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0 +var firefoxos = require('cordova/platform'); +var cordova = require('cordova'); + +//UA parsing not recommended but currently this is the only way to get the Firefox OS version +//https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference + +//Should be replaced when better conversion to Firefox OS Version is available +function convertVersionNumber(ver) { + var hashVersion = { + '18.0': '1.0.1', + '18.1': '1.1', + '26.0': '1.2', + '28.0': '1.3', + '30.0': '1.4', + '32.0': '2.0' + }; + var rver = ver; + var sStr = ver.substring(0, 4); + if (hashVersion[sStr]) { + rver = hashVersion[sStr]; + } + return (rver); + +} +function getVersion() { + if (navigator.userAgent.match(/(mobile|tablet)/i)) { + var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/)); + if (ffVersionArray.length === 2) { + return (convertVersionNumber(ffVersionArray[1])); + } + } + return (null); +} + +function getModel() { + var uaArray = navigator.userAgent.split(/\s*[;)(]\s*/); + if (navigator.userAgent.match(/(mobile|tablet)/i)) { + if (uaArray.length === 5) { + return (uaArray[2]); + } + } + return (null); +} +module.exports = { + getDeviceInfo: function (success, error) { + setTimeout(function () { + success({ + platform: 'firefoxos', + model: getModel(), + version: getVersion(), + uuid: null + }); + }, 0); + } +}; + +require("cordova/exec/proxy").add("Device", module.exports); diff --git a/plugins/org.apache.cordova.device/src/ios/CDVDevice.h b/plugins/org.apache.cordova.device/src/ios/CDVDevice.h new file mode 100644 index 00000000..a146d882 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/ios/CDVDevice.h @@ -0,0 +1,30 @@ +/* + 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. + */ + +#import <UIKit/UIKit.h> +#import <Cordova/CDVPlugin.h> + +@interface CDVDevice : CDVPlugin +{} + ++ (NSString*)cordovaVersion; + +- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/org.apache.cordova.device/src/ios/CDVDevice.m b/plugins/org.apache.cordova.device/src/ios/CDVDevice.m new file mode 100644 index 00000000..5a3f4708 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/ios/CDVDevice.m @@ -0,0 +1,99 @@ +/* + 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. + */ + +#include <sys/types.h> +#include <sys/sysctl.h> + +#import <Cordova/CDV.h> +#import "CDVDevice.h" + +@implementation UIDevice (ModelVersion) + +- (NSString*)modelVersion +{ + size_t size; + + sysctlbyname("hw.machine", NULL, &size, NULL, 0); + char* machine = malloc(size); + sysctlbyname("hw.machine", machine, &size, NULL, 0); + NSString* platform = [NSString stringWithUTF8String:machine]; + free(machine); + + return platform; +} + +@end + +@interface CDVDevice () {} +@end + +@implementation CDVDevice + +- (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device +{ + NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; + static NSString* UUID_KEY = @"CDVUUID"; + + NSString* app_uuid = [userDefaults stringForKey:UUID_KEY]; + + if (app_uuid == nil) { + CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault); + CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef); + + app_uuid = [NSString stringWithString:(__bridge NSString*)uuidString]; + [userDefaults setObject:app_uuid forKey:UUID_KEY]; + [userDefaults synchronize]; + + CFRelease(uuidString); + CFRelease(uuidRef); + } + + return app_uuid; +} + +- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command +{ + NSDictionary* deviceProperties = [self deviceProperties]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + +- (NSDictionary*)deviceProperties +{ + UIDevice* device = [UIDevice currentDevice]; + NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4]; + + [devProps setObject:@"Apple" forKey:@"manufacturer"]; + [devProps setObject:[device modelVersion] forKey:@"model"]; + [devProps setObject:@"iOS" forKey:@"platform"]; + [devProps setObject:[device systemVersion] forKey:@"version"]; + [devProps setObject:[self uniqueAppInstanceIdentifier:device] forKey:@"uuid"]; + [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"]; + + NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps]; + return devReturn; +} + ++ (NSString*)cordovaVersion +{ + return CDV_VERSION; +} + +@end diff --git a/plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js b/plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js new file mode 100644 index 00000000..2afc3243 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js @@ -0,0 +1,39 @@ +/* + * + * 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 tizen = require('cordova/platform'); +var cordova = require('cordova'); + +module.exports = { + getDeviceInfo: function(success, error) { + setTimeout(function () { + success({ + cordova: tizen.cordovaVersion, + platform: 'tizen', + model: null, + version: null, + uuid: null + }); + }, 0); + } +}; + +require("cordova/tizen/commandProxy").add("Device", module.exports); diff --git a/plugins/org.apache.cordova.device/src/ubuntu/device.cpp b/plugins/org.apache.cordova.device/src/ubuntu/device.cpp new file mode 100644 index 00000000..eb5a012d --- /dev/null +++ b/plugins/org.apache.cordova.device/src/ubuntu/device.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2011 Wolfgang Koller - http://www.gofg.at/ + * + * Licensed 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. + */ + +#include <QDeviceInfo> +#include <QtSystemInfo> + +#include"device.h" + +#define CORDOVA "3.0.0" + +Device::Device(Cordova *cordova) : CPlugin(cordova) { +} + +static QString getOSName() { +#ifdef Q_OS_SYMBIAN + QString platform = "Symbian"; +#endif +#ifdef Q_OS_WIN + QString platform = "Windows"; +#endif +#ifdef Q_OS_WINCE + QString platform = "Windows CE"; +#endif +#ifdef Q_OS_LINUX + QString platform = "Linux"; +#endif + return platform; +} + +void Device::getInfo(int scId, int ecId) { + Q_UNUSED(ecId) + + QDeviceInfo systemDeviceInfo; + QDeviceInfo systemInfo; + + QString platform = getOSName(); + + QString uuid = systemDeviceInfo.uniqueDeviceID(); + if (uuid.isEmpty()) { + QString deviceDescription = systemInfo.imei(0) + ";" + systemInfo.manufacturer() + ";" + systemInfo.model() + ";" + systemInfo.productName() + ";" + platform; + QString user = qgetenv("USER"); + if (user.isEmpty()) { + user = qgetenv("USERNAME"); + if (user.isEmpty()) + user = QDir::homePath(); + } + uuid = QString(QCryptographicHash::hash((deviceDescription + ";" + user).toUtf8(), QCryptographicHash::Md5).toHex()); + } + + this->cb(scId, systemDeviceInfo.model(), CORDOVA, platform, uuid, systemInfo.version(QDeviceInfo::Os)); +} diff --git a/plugins/org.apache.cordova.device/src/ubuntu/device.h b/plugins/org.apache.cordova.device/src/ubuntu/device.h new file mode 100644 index 00000000..91cb9377 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/ubuntu/device.h @@ -0,0 +1,47 @@ +/* + * Copyright 2011 Wolfgang Koller - http://www.gofg.at/ + * + * Licensed 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. + */ + +#ifndef DEVICE_H_FDSAFAS +#define DEVICE_H_FDSAFAS + +#include <QtCore> + +#include <cplugin.h> + +class Device: public CPlugin { + Q_OBJECT +public: + explicit Device(Cordova *cordova); + + virtual const QString fullName() override { + return Device::fullID(); + } + + virtual const QString shortName() override { + return "Device"; + } + + static const QString fullID() { + return "com.cordova.Device"; + } + +signals: + +public slots: + void getInfo(int scId, int ecId); +}; + +#endif diff --git a/plugins/org.apache.cordova.device/src/ubuntu/device.js b/plugins/org.apache.cordova.device/src/ubuntu/device.js new file mode 100644 index 00000000..3adb110b --- /dev/null +++ b/plugins/org.apache.cordova.device/src/ubuntu/device.js @@ -0,0 +1,34 @@ +/* + * + * 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'); +var exec = require('cordova/exec'); + +module.exports = { + getInfo:function(win,fail,args) { + Cordova.exec(function (model, cordova, platform, uuid, version) { + win({name: name, model: model, cordova: cordova, + platform: platform, uuid: uuid, version: version}); + }, null, "com.cordova.Device", "getInfo", []); + } +}; + +require("cordova/exec/proxy").add("Device", module.exports); diff --git a/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js b/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js new file mode 100644 index 00000000..69ed4446 --- /dev/null +++ b/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js @@ -0,0 +1,108 @@ +/* + * + * 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 ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}"; +var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10"; +var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10'; +var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\""; +var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318"; +var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3"; +var MANU_KEY = "System.Devices.Manufacturer"; + +module.exports = { + + getDeviceInfo:function(win, fail, args) { + + // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId + var deviceId; + var manufacturer = "unknown"; + + // get deviceId, or create and store one + var localSettings = Windows.Storage.ApplicationData.current.localSettings; + if (localSettings.values.deviceId) { + deviceId = localSettings.values.deviceId; + } + else { + // App-specific hardware id could be used as uuid, but it changes if the hardware changes... + try { + var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id; + deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid(); + } catch (e) { + // Couldn't get the hardware UUID + deviceId = createUUID(); + } + //...so cache it per-install + localSettings.values.deviceId = deviceId; + } + + + var userAgent = window.clientInformation.userAgent; + // this will report "windows" in windows8.1 and windows phone 8.1 apps + // and "windows8" in windows 8.0 apps similar to cordova.js + // See https://github.com/apache/cordova-js/blob/master/src/windows/platform.js#L25 + var devicePlatform = userAgent.indexOf("MSAppHost/1.0") == -1 ? "windows" : "windows8"; + var versionString = userAgent.match(/Windows (?:Phone |NT )?([0-9.]+)/)[1]; + + + + var Pnp = Windows.Devices.Enumeration.Pnp; + + Pnp.PnpObject.findAllAsync(Pnp.PnpObjectType.deviceContainer,[MANU_KEY]) + .then(function (infoList) { + var numDevices = infoList.length; + if (numDevices) { + for (var i = 0; i < numDevices; i++) { + var devContainer = infoList[i]; + if (devContainer.id == ROOT_CONTAINER) { + manufacturer = devContainer.properties[MANU_KEY]; + break; + } + } + } + }) + .then(function () { + Pnp.PnpObject.findAllAsync(Pnp.PnpObjectType.device, + [DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY], + ROOT_CONTAINER_QUERY) + .then(function (rootDevices) { + for (var i = 0; i < rootDevices.length; i++) { + var rootDevice = rootDevices[i]; + if (!rootDevice.properties) continue; + if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) { + versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY]; + break; + } + } + + setTimeout(function () { + win({ platform: devicePlatform, + version: versionString, + uuid: deviceId, + model: window.clientInformation.platform, + manufacturer:manufacturer}); + }, 0); + }); + }); + } + +}; // exports + +require("cordova/exec/proxy").add("Device", module.exports); diff --git a/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js b/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js new file mode 100644 index 00000000..3ddc9b2b --- /dev/null +++ b/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js @@ -0,0 +1,82 @@ +/* + * + * 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'); +var utils = require('cordova/utils'); + +module.exports = { + + getDeviceInfo:function(win,fail,args) { + + // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId + var deviceId; + + var localSettings = Windows.Storage.ApplicationData.current.localSettings; + + if (localSettings.values.deviceId) { + deviceId = localSettings.values.deviceId; + } + else { + // App-specific hardware id could be used as uuid, but it changes if the hardware changes... + try { + var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id; + deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid(); + } catch (e) { + // Couldn't get the hardware UUID + deviceId = createUUID(); + } + //...so cache it per-install + localSettings.values.deviceId = deviceId; + } + + var versionString = window.clientInformation.userAgent.match(/Windows NT ([0-9.]+)/)[1]; + + (function(self){ + var ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}"; + var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10"; + var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10'; + var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\""; + var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318"; + var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3"; + var pnpObject = Windows.Devices.Enumeration.Pnp.PnpObject; + pnpObject.findAllAsync(Windows.Devices.Enumeration.Pnp.PnpObjectType.device, [DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY], ROOT_CONTAINER_QUERY).then(function(rootDevices) { + + for (var i = 0; i < rootDevices.length; i++) { + var rootDevice = rootDevices[i]; + if (!rootDevice.properties) continue; + if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) { + versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY]; + break; + } + } + + setTimeout(function () { + win({ platform: "windows8", version: versionString, uuid: deviceId, model: window.clientInformation.platform }); + }, 0); + }); + })(this); + } + +}; + +require("cordova/exec/proxy").add("Device", module.exports); + diff --git a/plugins/org.apache.cordova.device/src/wp/Device.cs b/plugins/org.apache.cordova.device/src/wp/Device.cs new file mode 100644 index 00000000..897a35af --- /dev/null +++ b/plugins/org.apache.cordova.device/src/wp/Device.cs @@ -0,0 +1,135 @@ +/* + Licensed 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. +*/ + +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Info; +using System.IO.IsolatedStorage; +using System.Windows.Resources; +using System.IO; +using System.Diagnostics; + +namespace WPCordovaClassLib.Cordova.Commands +{ + public class Device : BaseCommand + { + public void getDeviceInfo(string notused) + { + + string res = String.Format("\"name\":\"{0}\",\"platform\":\"{1}\",\"uuid\":\"{2}\",\"version\":\"{3}\",\"model\":\"{4}\",\"manufacturer\":\"{5}\"", + this.name, + this.platform, + this.uuid, + this.version, + this.model, + this.manufacturer); + + res = "{" + res + "}"; + //Debug.WriteLine("Result::" + res); + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res)); + } + + public string model + { + get + { + return DeviceStatus.DeviceName; + //return String.Format("{0},{1},{2}", DeviceStatus.DeviceManufacturer, DeviceStatus.DeviceHardwareVersion, DeviceStatus.DeviceFirmwareVersion); + } + } + + public string manufacturer + { + get + { + return DeviceStatus.DeviceManufacturer; + } + } + + public string name + { + get + { + return DeviceStatus.DeviceName; + + } + } + + public string platform + { + get + { + return Environment.OSVersion.Platform.ToString(); + } + } + + public string uuid + { + get + { + object id; + + UserExtendedProperties.TryGetValue("ANID", out id); + if (id != null) + { + return id.ToString().Substring(2, 32); + } + + UserExtendedProperties.TryGetValue("ANID2", out id); + if (id != null) + { + return id.ToString(); + } + + string returnVal = "???unknown???"; + + using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication()) + { + try + { + IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage); + + using (StreamReader reader = new StreamReader(fileStream)) + { + returnVal = reader.ReadLine(); + } + } + catch (Exception /*ex*/) + { + + } + } + + return returnVal; + } + } + + public string version + { + get + { + return Environment.OSVersion.Version.ToString(); + } + } + + } +} diff --git a/plugins/org.apache.cordova.device/tests/plugin.xml b/plugins/org.apache.cordova.device/tests/plugin.xml new file mode 100644 index 00000000..8819816a --- /dev/null +++ b/plugins/org.apache.cordova.device/tests/plugin.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + xmlns:rim="http://www.blackberry.com/ns/widgets" + xmlns:android="http://schemas.android.com/apk/res/android" + id="org.apache.cordova.device.tests" + version="0.2.14"> + <name>Cordova Device Plugin Tests</name> + <license>Apache 2.0</license> + + <js-module src="tests.js" name="tests"> + </js-module> +</plugin> diff --git a/plugins/org.apache.cordova.device/tests/tests.js b/plugins/org.apache.cordova.device/tests/tests.js new file mode 100644 index 00000000..1f49d7e1 --- /dev/null +++ b/plugins/org.apache.cordova.device/tests/tests.js @@ -0,0 +1,99 @@ +/* + * + * 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. + * +*/ + +exports.defineAutoTests = function() { + describe('Device Information (window.device)', function () { + it("should exist", function() { + expect(window.device).toBeDefined(); + }); + + it("should contain a platform specification that is a string", function() { + expect(window.device.platform).toBeDefined(); + expect((new String(window.device.platform)).length > 0).toBe(true); + }); + + it("should contain a version specification that is a string", function() { + expect(window.device.version).toBeDefined(); + expect((new String(window.device.version)).length > 0).toBe(true); + }); + + it("should contain a UUID specification that is a string or a number", function() { + expect(window.device.uuid).toBeDefined(); + if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') { + expect((new String(window.device.uuid)).length > 0).toBe(true); + } else { + expect(window.device.uuid > 0).toBe(true); + } + }); + + it("should contain a cordova specification that is a string", function() { + expect(window.device.cordova).toBeDefined(); + expect((new String(window.device.cordova)).length > 0).toBe(true); + }); + + it("should depend on the presence of cordova.version string", function() { + expect(window.cordova.version).toBeDefined(); + expect((new String(window.cordova.version)).length > 0).toBe(true); + }); + + it("should contain device.cordova equal to cordova.version", function() { + expect(window.device.cordova).toBe(window.cordova.version); + }); + + it("should contain a model specification that is a string", function() { + expect(window.device.model).toBeDefined(); + expect((new String(window.device.model)).length > 0).toBe(true); + }); + + it("should contain a manufacturer property that is a string", function() { + expect(window.device.manufacturer).toBeDefined(); + expect((new String(window.device.manufacturer)).length > 0).toBe(true); + }); + }); +}; + +exports.defineManualTests = function(contentEl, createActionButton) { + var logMessage = function (message, color) { + var log = document.getElementById('info'); + var logLine = document.createElement('div'); + if (color) { + logLine.style.color = color; + } + logLine.innerHTML = message; + log.appendChild(logLine); + } + + var clearLog = function () { + var log = document.getElementById('info'); + log.innerHTML = ''; + } + + var device_tests = '<h3>Press Dump Device button to get device information</h3>' + + '<div id="dump_device"></div>' + + 'Expected result: Status box will get updated with device info. (i.e. platform, version, uuid, model, etc)'; + + contentEl.innerHTML = '<div id="info"></div>' + device_tests; + + createActionButton('Dump device', function() { + clearLog(); + logMessage(JSON.stringify(window.device, null, '\t')); + }, "dump_device"); +}; diff --git a/plugins/org.apache.cordova.device/www/device.js b/plugins/org.apache.cordova.device/www/device.js new file mode 100644 index 00000000..b1d0d25d --- /dev/null +++ b/plugins/org.apache.cordova.device/www/device.js @@ -0,0 +1,79 @@ +/* + * + * 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 argscheck = require('cordova/argscheck'), + channel = require('cordova/channel'), + utils = require('cordova/utils'), + exec = require('cordova/exec'), + cordova = require('cordova'); + +channel.createSticky('onCordovaInfoReady'); +// Tell cordova channel to wait on the CordovaInfoReady event +channel.waitForInitialization('onCordovaInfoReady'); + +/** + * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the + * phone, etc. + * @constructor + */ +function Device() { + this.available = false; + this.platform = null; + this.version = null; + this.uuid = null; + this.cordova = null; + this.model = null; + this.manufacturer = null; + + var me = this; + + channel.onCordovaReady.subscribe(function() { + me.getInfo(function(info) { + //ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js + //TODO: CB-5105 native implementations should not return info.cordova + var buildLabel = cordova.version; + me.available = true; + me.platform = info.platform; + me.version = info.version; + me.uuid = info.uuid; + me.cordova = buildLabel; + me.model = info.model; + me.manufacturer = info.manufacturer || 'unknown'; + channel.onCordovaInfoReady.fire(); + },function(e) { + me.available = false; + utils.alert("[ERROR] Error initializing Cordova: " + e); + }); + }); +} + +/** + * Get device info + * + * @param {Function} successCallback The function to call when the heading data is available + * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) + */ +Device.prototype.getInfo = function(successCallback, errorCallback) { + argscheck.checkArgs('fF', 'Device.getInfo', arguments); + exec(successCallback, errorCallback, "Device", "getDeviceInfo", []); +}; + +module.exports = new Device(); diff --git a/plugins/org.apache.cordova.splashscreen/CONTRIBUTING.md b/plugins/org.apache.cordova.splashscreen/CONTRIBUTING.md new file mode 100644 index 00000000..f7dbcaba --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/CONTRIBUTING.md @@ -0,0 +1,37 @@ +<!-- +# +# 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. +# +--> + +# Contributing to Apache Cordova + +Anyone can contribute to Cordova. And we need your contributions. + +There are multiple ways to contribute: report bugs, improve the docs, and +contribute code. + +For instructions on this, start with the +[contribution overview](http://cordova.apache.org/#contribute). + +The details are explained there, but the important items are: + - Sign and submit an Apache ICLA (Contributor License Agreement). + - Have a Jira issue open that corresponds to your contribution. + - Run the tests so your patch doesn't break existing functionality. + +We look forward to your contributions! diff --git a/plugins/org.apache.cordova.splashscreen/LICENSE b/plugins/org.apache.cordova.splashscreen/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/NOTICE b/plugins/org.apache.cordova.splashscreen/NOTICE new file mode 100644 index 00000000..8ec56a52 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/NOTICE @@ -0,0 +1,5 @@ +Apache Cordova +Copyright 2012 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/plugins/org.apache.cordova.splashscreen/README.md b/plugins/org.apache.cordova.splashscreen/README.md new file mode 100644 index 00000000..7ad24017 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/README.md @@ -0,0 +1,22 @@ +<!--- + license: 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. +--> + +# org.apache.cordova.splashscreen + +Plugin documentation: [doc/index.md](doc/index.md) diff --git a/plugins/org.apache.cordova.splashscreen/RELEASENOTES.md b/plugins/org.apache.cordova.splashscreen/RELEASENOTES.md new file mode 100644 index 00000000..1be97903 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/RELEASENOTES.md @@ -0,0 +1,105 @@ +<!-- +# +# 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. +# +--> +# Release Notes + +### 0.2.2 (Sept 25, 2013) +* CB-4889 bumping&resetting version +* CB-4889 renaming org.apache.cordova.core.splashscreen to org.apache.cordova.splashscreen +* Rename CHANGELOG.md -> RELEASENOTES.md +* [CB-4806] Update splashscreen image bounds for iOS 7 +* [CB-4752] Incremented plugin version on dev branch. + +### 0.2.3 (Oct 9, 2013) +* [CB-4806] Re-fix Update splashscreen image bounds for iOS 7 +* [CB-4934] plugin-splashscreen should not show by default on Windows8 +* [CB-4929] plugin-splashscreen not loading proxy windows8 +* [CB-4915] Incremented plugin version on dev branch. + +### 0.2.4 (Oct 28, 2013) +* CB-5128: add repo + issue tag to plugin.xml for splashscreen plugin +* [CB-5010] Incremented plugin version on dev branch. + +### 0.2.5 (Dec 4, 2013) +* add ubuntu platform +* Added amazon-fireos platform. Change to use amazon-fireos as a platform if the user agent string contains 'cordova-amazon-fireos' +* CB-5124 - Remove splashscreen config.xml values from iOS Configuration Docs, move to plugin docs + +### 0.2.6 (Jan 02, 2014) +* CB-5658 Add doc/index.md for Splashscreen plugin +* Handle error when splash image is missing. + +### 0.2.7 (Feb 05, 2014) +* [CB-3562] Fix aspect ratio on landscape-only iPhone applications +* CB-4051 fix for splashscreen rotation problem + +### 0.3.0 (Apr 17, 2014) +* Add Tizen support to plugin +* CB-6422: [windows8] use cordova/exec/proxy +* CB-4051: [ios] - Re-fix - Splashscreen rotation problem (closes #13) +* CB-6460: Update license headers +* CB-6465: Add license headers to Tizen code +* Add NOTICE file + +### 0.3.1 (Jun 05, 2014) +* documentation translation: cordova-plugin-splashscreen +* Lisa testing pulling in plugins for plugin: cordova-plugin-splashscreen +* Lisa testing pulling in plugins for plugin: cordova-plugin-splashscreen +* Lisa testing pulling in plugins for plugin: cordova-plugin-splashscreen +* Lisa testing pulling in plugins for plugin: cordova-plugin-splashscreen +* CB-6810 Add license to CONTRIBUTING.md +* [wp8] updated quirk for and combined iOS,WP8,BB10 quirks as they are all the same +* [wp] implemented OnInit so splash screen can be shown before cordova page is loaded +* [wp] plugin must be autoloaded for AutoHideSplashScreen preference to work +* CB-6483 Use splash screen image from manifest on Windows8 +* CB-6491 add CONTRIBUTING.md +* Revert "Merge branch 'tizen' of http://github.com/siovene/cordova-plugin-splashscreen" + +### 0.3.2 (Aug 06, 2014) +* CB-6127 Updated translations for docs +* CB-7041 ios: Fix image filename logic when setting the iPad splash screen +* fixes Splashscreen crash on WP8 +* Remove outdated doc + +### 0.3.3 (Sep 17, 2014) +* CB-7249 cordova-plugin-splashscreen documentation translation +* Renamed test dir, added nested plugin.xml +* added documentation for manual tests +* CB-7196 port splashscreen tests to framework + +### 0.3.4 (Oct 03, 2014) +* Finalized iOS splash screen (image name) tests. 176 tests in all, 44 for each type of device (iPad, iPhone, iPhone5, iPhone6, iPhone 6 Plus). +* CB-7633 - (Re-fix based on updated unit tests) iPhone 6 Plus support +* Updated iOS tests for locked orientations +* Added more iOS splash screen tests. +* CB-7633 - Add support for iPhone 6/6+ +* Added failing iPhone 6/6 Plus tests. +* Added 'npm test' +* CB-7663 - iOS unit tests for splash screen +* Properly formatted splashscreen preference docs. + +### 0.3.5 (Dec 02, 2014) +* CB-7204 - Race condition when hiding and showing spinner (closes #21) +* CB-7700 cordova-plugin-splashscreen documentation translation: cordova-plugin-splashscreen + +### 1.0.0 (Feb 04, 2015) +* CB-8351 ios: Stop using deprecated IsIpad macro +* CB-3679 Add engine tag for Android >= 3.6.0 due to use of `preferences` +* CB-3679 Make SplashScreen plugin compatible with cordova-android@4.0.x diff --git a/plugins/org.apache.cordova.splashscreen/doc/de/index.md b/plugins/org.apache.cordova.splashscreen/doc/de/index.md new file mode 100644 index 00000000..be0c3337 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/de/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +Dieses Plugin zeigt und verbirgt einen Splash-Screen beim Start der Anwendung. + +## Installation + + cordova plugin add org.apache.cordova.splashscreen + + +## Unterstützte Plattformen + +* Amazon Fire OS +* Android +* BlackBerry 10 +* iOS +* Windows Phone 7 und 8 +* Windows 8 + +## Methoden + +* SplashScreen.Show +* SplashScreen.Hide + +### Android Eigenarten + +Sie müssen in der config.xml folgende Einstellungen vornehmen: + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Wo Foo ist der Name der Datei Splashscreen, vorzugsweise eine 9-Patch-Datei. Stellen Sie sicher, Splashcreen Dateien zu Ihrem Res/Xml-Verzeichnis unter den entsprechenden Ordnern hinzuzufügen. Der zweite Parameter stellt dar, wie lange das Splashscreen in Millisekunden angezeigt werden. Es wird standardmäßig auf 3000 ms. Weitere Informationen finden Sie unter [Symbole und Splash-Screens][1] . + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## SplashScreen.Hide + +Schließen Sie den Splash-Screen. + + Navigator.SplashScreen.Hide(); + + +### BlackBerry 10, WP8, iOS Eigenarten + +Die `config.xml` der Datei `AutoHideSplashScreen` muss `false` . Verstecken des Begrüßungsbildschirms für zwei Sekunden Verzögerung, fügen Sie einen Timer wie die folgende in der `deviceready` -Ereignishandler: + + setTimeout(function() {navigator.splashscreen.hide(); + }, 2000); + + +## SplashScreen.Show + +Zeigt den Begrüßungsbildschirm. + + Navigator.SplashScreen.Show(); + + +Ihre Anwendung kann nicht aufgerufen werden `navigator.splashscreen.show()` bis die app gestartet hat und das `deviceready` -Ereignis ausgelöst hat. Aber da in der Regel der Splash-Screen soll sichtbar sein, bevor die Anwendung gestartet wurde, scheint die Niederlage der Zweck des Begrüßungsbildschirms. Somit einige Konfiguration in `config.xml` wird automatisch `show` den Splash-Screen unmittelbar nach Ihrer app starten und bevor es voll gestartet und hat das `deviceready` Ereignis. Weitere Informationen zu dieser Konfiguration finden Sie unter [Symbole und Splash-Screens][1] . Aus diesem Grund ist es unwahrscheinlich, dass Sie aufrufen müssen `navigator.splashscreen.show()` den Splash-Screen beim Starten der app sichtbar zu machen.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/es/index.md b/plugins/org.apache.cordova.splashscreen/doc/es/index.md new file mode 100644 index 00000000..644bec3e --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/es/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +Este plugin muestra y esconde una pantalla de bienvenida durante el inicio de la aplicación. + +## Instalación + + cordova plugin add org.apache.cordova.splashscreen + + +## Plataformas soportadas + +* Amazon fire OS +* Android +* BlackBerry 10 +* iOS +* Windows Phone 7 y 8 +* Windows 8 + +## Métodos + +* splashscreen.show +* splashscreen.hide + +### Rarezas Android + +En el archivo config.xml, tienes que añadir las siguientes preferencias: + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Donde foo es el nombre del archivo splashscreen, preferiblemente un archivo de 9 parche. Asegúrese de agregar tus archivos splashcreen en tu directorio res/xml bajo las carpetas apropiadas. El segundo parámetro representa cuánto aparecerán el splashscreen en milisegundos. Valor predeterminado es ms 3000. Ver [los iconos y salpicadura pantallas][1] para obtener más información. + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.hide + +Despedir a la pantalla de bienvenida. + + Navigator.SplashScreen.Hide(); + + +### BlackBerry 10, WP8, iOS Quirk + +El `config.xml` del archivo `AutoHideSplashScreen` la configuración debe ser `false` . Para retrasar oculta la pantalla splash durante dos segundos, agregue un temporizador como la siguiente en el `deviceready` controlador de eventos: + + setTimeout(function() {navigator.splashscreen.hide(); + }, 2000); + + +## splashscreen.show + +Muestra la pantalla de bienvenida. + + Navigator.SplashScreen.Show(); + + +La aplicación no se puede llamar `navigator.splashscreen.show()` hasta que haya iniciado la aplicación y el `deviceready` evento ha despedido. Pero puesto que normalmente la pantalla está destinada a ser visible antes de que comience su aplicación, que parecerÃa que el propósito de la pantalla de bienvenida. Proporcionar cierta configuración en `config.xml` automáticamente `show` la pantalla de presentación inmediatamente después de su lanzamiento de la aplicación y antes de ser completamente ha iniciado y recibió el `deviceready` evento. Ver [los iconos y salpicadura pantallas][1] para obtener más información sobre haciendo esta configuración. Por esta razón, es poco probable que necesitas llamar a `navigator.splashscreen.show()` para hacer la pantalla visible para el inicio de la aplicación.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/fr/index.md b/plugins/org.apache.cordova.splashscreen/doc/fr/index.md new file mode 100644 index 00000000..a898d80f --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/fr/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +Ce plugin affiche et masque un écran de démarrage lors du lancement de l'application. + +## Installation + + cordova plugin add org.apache.cordova.splashscreen + + +## Plates-formes prises en charge + +* Amazon Fire OS +* Android +* BlackBerry 10 +* iOS +* Windows Phone 7 et 8 +* Windows 8 + +## Méthodes + +* splashscreen.Show +* splashscreen.Hide + +### Quirks Android + +Dans votre fichier config.xml, vous devez ajouter les préférences suivantes : + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Où foo est le nom du fichier splashscreen, préférablement un fichier de 9 correctif. Assurez-vous d'ajouter vos fichiers splashcreen dans votre répertoire res/xml dans les dossiers appropriés. Le deuxième paramètre représente combien de temps le splashscreen apparaîtra en millisecondes. Il est par défaut à 3000 ms. Pour plus d'informations, consultez [icônes et écrans de démarrage][1] . + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.Hide + +Faire disparaître de l'écran de démarrage. + + Navigator.SplashScreen.Hide() ; + + +### BlackBerry 10, WP8, iOS Quirk + +La `config.xml` du fichier `AutoHideSplashScreen` doit être `false` . Pour retarder la cacher l'écran de démarrage pendant deux secondes, ajouter un minuteur comme suit dans la `deviceready` gestionnaire d'événements : + + setTimeout(function() {navigator.splashscreen.hide() ; + }, 2000) ; + + +## splashscreen.Show + +Affiche l'écran de démarrage. + + Navigator.SplashScreen.Show() ; + + +Votre application ne peut pas appeler `navigator.splashscreen.show()` jusqu'à ce que l'application a commencé et le `deviceready` événement a été déclenché. Mais puisqu'en général, l'écran de démarrage est destiné à être visible avant que votre application a commencé, qui semblerait à l'encontre des objectifs de l'écran de démarrage. Fournir une configuration en `config.xml` sera automatiquement `show` l'écran de démarrage immédiatement après votre lancement de l'app et avant qu'il a complètement démarré et a reçu le `deviceready` événement. Voir les [icônes et les écrans de démarrage][1] pour plus d'informations sur la conduite de cette configuration. Pour cette raison, il est peu probable que vous devez appeler `navigator.splashscreen.show()` pour rendre l'écran de démarrage visible pour le démarrage de l'application.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/index.md b/plugins/org.apache.cordova.splashscreen/doc/index.md new file mode 100644 index 00000000..c3070cc4 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/index.md @@ -0,0 +1,88 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +This plugin displays and hides a splash screen during application launch. + +## Installation + + cordova plugin add org.apache.cordova.splashscreen + + +## Supported Platforms + +- Amazon Fire OS +- Android +- BlackBerry 10 +- iOS +- Windows Phone 7 and 8 +- Windows 8 + + +## Methods + +- splashscreen.show +- splashscreen.hide + +### Android Quirks + +In your config.xml, you need to add the following preferences: + + <preference name="SplashScreen" value="foo" /> + <preference name="SplashScreenDelay" value="10000" /> + +Where foo is the name of the splashscreen file, preferably a 9 patch file. Make sure to add your splashcreen files to your res/xml directory under the appropriate folders. The second parameter represents how long the splashscreen will appear in milliseconds. It defaults to 3000 ms. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html) +for more information. + +## splashscreen.hide + +Dismiss the splash screen. + + navigator.splashscreen.hide(); + + +### BlackBerry 10, WP8, iOS Quirk + +The `config.xml` file's `AutoHideSplashScreen` setting must be +`false`. To delay hiding the splash screen for two seconds, add a +timer such as the following in the `deviceready` event handler: + + setTimeout(function() { + navigator.splashscreen.hide(); + }, 2000); + +## splashscreen.show + +Displays the splash screen. + + navigator.splashscreen.show(); + + +Your application cannot call `navigator.splashscreen.show()` until the app has +started and the `deviceready` event has fired. But since typically the splash +screen is meant to be visible before your app has started, that would seem to +defeat the purpose of the splash screen. Providing some configuration in +`config.xml` will automatically `show` the splash screen immediately after your +app launch and before it has fully started and received the `deviceready` +event. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html) +for more information on doing this configuration. For this reason, it is +unlikely you need to call `navigator.splashscreen.show()` to make the splash +screen visible for app startup. + diff --git a/plugins/org.apache.cordova.splashscreen/doc/it/index.md b/plugins/org.apache.cordova.splashscreen/doc/it/index.md new file mode 100644 index 00000000..2f6d2f1c --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/it/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +Questo plugin Visualizza e nasconde una schermata iniziale durante l'avvio dell'applicazione. + +## Installazione + + cordova plugin add org.apache.cordova.splashscreen + + +## Piattaforme supportate + +* Amazon fuoco OS +* Android +* BlackBerry 10 +* iOS +* Windows Phone 7 e 8 +* Windows 8 + +## Metodi + +* splashscreen +* splashscreen.Hide + +### Stranezze Android + +Nel vostro config. xml, è necessario aggiungere le seguenti preferenze: + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Dove foo è il nome del file splashscreen, preferibilmente un file 9 patch. Assicurati di aggiungere i tuoi file splashcreen res/xml nella directory sotto cartelle appropriate. Il secondo parametro rappresenta quanto tempo lo splashscreen apparirà in millisecondi. Il valore predefinito è 3000 ms. Per ulteriori informazioni, vedere [icone e schermate iniziali][1] . + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.Hide + +Respingere la schermata iniziale. + + Navigator.SplashScreen.Hide(); + + +### BlackBerry 10, WP8, iOS Quirk + +Il `config.xml` di file `AutoHideSplashScreen` impostazione deve essere `false` . Per ritardare nascondendo la schermata iniziale per due secondi, aggiungere un timer ad esempio nel `deviceready` gestore di evento: + + setTimeout(function() {navigator.splashscreen.hide(); + }, 2000); + + +## splashscreen + +Visualizza la schermata iniziale. + + Navigator.SplashScreen.Show(); + + +L'applicazione non può chiamare `navigator.splashscreen.show()` fino a quando ha iniziato l'app e il `deviceready` ha generato l'evento. Ma poiché in genere la schermata iniziale è destinata ad essere visibile prima app ha iniziato, che sembrerebbe per sconfiggere lo scopo della schermata iniziale. Fornendo qualche configurazione in `config.xml` verrà automaticamente `show` la schermata iniziale subito dopo il lancio dell'app e prima che completamente ha iniziato e ha ricevuto il `deviceready` evento. Per ulteriori informazioni su facendo questa configurazione, vedere [icone e schermate iniziali][1] . Per questo motivo, è improbabile che dovete chiamare `navigator.splashscreen.show()` per rendere la schermata visibile per avvio di app.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/ja/index.md b/plugins/org.apache.cordova.splashscreen/doc/ja/index.md new file mode 100644 index 00000000..d96a6140 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/ja/index.md @@ -0,0 +1,74 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +ã“ã®ãƒ—ラグインãŒè¡¨ç¤ºã•れã€ã‚¢ãƒ—リケーションã®èµ·å‹•ä¸ã«ã‚¹ãƒ—ラッシュ スクリーンをéžè¡¨ç¤ºã«ã—ã¾ã™ã€‚ + +## インストール + + cordova plugin add org.apache.cordova.splashscreen + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* ã‚¢ãƒžã‚¾ãƒ³ç« OS +* アンドãƒã‚¤ãƒ‰ +* ブラックベリー 10 +* iOS +* Windows Phone 7 㨠8 +* Windows 8 + +## メソッド + +* splashscreen.show +* splashscreen.hide + +### Android ã®ç™– + +ã‚ãªãŸã® config.xml を以下ã®è¨å®šã‚’è¿½åŠ ã™ã‚‹å¿…è¦ãŒã‚りã¾ã™ã€‚ + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Foo ãŒã§ãれ㰠9 パッãƒãƒ•ァイル splashscreen ファイルã®åå‰ã§ã™ã€‚ è§£åƒåº¦/xml ディレクトリã®é©åˆ‡ãªãƒ•ォルダーã®ä¸‹ã« splashcreen ãƒ•ã‚¡ã‚¤ãƒ«ã‚’è¿½åŠ ã™ã‚‹ã“ã¨ã‚’確èªã—ã¾ã™ã€‚ 2 番目ã®ãƒ‘ラメーターã¯ã€ã‚¹ãƒ—ラッシュ ・ スクリーンãŒã®è¡¨ç¤ºæ™‚é–“ (ミリ秒å˜ä½) を表ã—ã¾ã™ã€‚ デフォルトã§ã¯ 3000 ミリ秒ã§ã™ã€‚ 詳細ã«ã¤ã„ã¦ã¯ã€[アイコンã¨ã‚¹ãƒ—ラッシュ画é¢][1]ã‚’å‚ç…§ã—ã¦ãã ã•ã„。 + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.hide + +スプラッシュ スクリーンを閉ã˜ã¾ã™ã€‚ + + navigator.splashscreen.hide(); + + +### ブラックベリー 10ã€WP8ã€iOS ã®æ°—ã¾ãれ + +`config.xml`ファイル㮠`AutoHideSplashScreen` è¨å®šã™ã‚‹å¿…è¦ãŒã‚りã¾ã™ `false` 。 é…å»¶ã‚’ 2 秒間スプラッシュ スクリーンをéžè¡¨ç¤ºã€ã‚¿ã‚¤ãƒžãƒ¼ã‚’è¿½åŠ ã—ã¾ã™ã§æ¬¡ã®ã‚ˆã†ã« `deviceready` イベント ãƒãƒ³ãƒ‰ãƒ©ãƒ¼ã€‚ + + setTimeout(function() {navigator.splashscreen.hide();}, 2000å¹´); + + +## splashscreen.show + +スプラッシュ画é¢ãŒè¡¨ç¤ºã•れã¾ã™ã€‚ + + navigator.splashscreen.show(); + + +アプリケーションを呼ã³å‡ºã™ã“ã¨ã¯ã§ãã¾ã›ã‚“ `navigator.splashscreen.show()` ã€ã‚¢ãƒ—リãŒé–‹å§‹ã•れるã¾ã§ã€ `deviceready` イベントãŒç™ºç”Ÿã—ã¾ã™ã€‚ ã—ã‹ã—ã€ä»¥æ¥ã€é€šå¸¸ã‚¹ãƒ—ラッシュ画é¢ã‚¢ãƒ—リ開始å‰ã«è¡¨ç¤ºã™ã‚‹ã‚‚ã®ã§ã™ã¨æ€ã‚れるã€ã‚¹ãƒ—ラッシュ スクリーンã®ç›®çš„ã®æ•—北ã—ã¾ã™ã€‚ ã„ãã¤ã‹ã®æ§‹æˆã‚’æä¾›ã™ã‚‹ `config.xml` ã¯è‡ªå‹•的㫠`show` スプラッシュ画é¢ã€ã‚¢ãƒ—リを起動後ã™ãã«ã€ãれãŒå®Œå…¨ã«èµ·å‹•ã—ã€å—ä¿¡ã™ã‚‹å‰ã«ã€ `deviceready` イベント。 詳細ã«ã¤ã„ã¦ã¯ã“ã®æ§‹æˆã‚’行ã†ã«ã¯ã€[アイコンã¨ã‚¹ãƒ—ラッシュ画é¢][1]ã‚’å‚ç…§ã—ã¦ãã ã•ã„。 ã“ã®ã‚ˆã†ãªç†ç”±ã‹ã‚‰ã€ãれã¯å¯èƒ½æ€§ã‚’呼ã³å‡ºã™å¿…è¦ãŒã‚りã¾ã™ `navigator.splashscreen.show()` アプリ起動時ã®ã‚¹ãƒ—ラッシュ画é¢ã‚’見やã™ãã—ã¾ã™ã€‚
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/ko/index.md b/plugins/org.apache.cordova.splashscreen/doc/ko/index.md new file mode 100644 index 00000000..86a4e837 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/ko/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +ì´ í”ŒëŸ¬ê·¸ì¸ì€ 표시 하 ê³ ì‘ìš© 프로그램 실행 하는 ë™ì•ˆ 시작 í™”ë©´ì„ ìˆ¨ê¹ë‹ˆë‹¤. + +## 설치 + + cordova plugin add org.apache.cordova.splashscreen + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* 아마존 화재 ìš´ì˜ ì²´ì œ +* 안 드 로ì´ë“œ +* ë¸”ëž™ë² ë¦¬ 10 +* iOS +* Windows Phone 7ê³¼ 8 +* 윈ë„ìš° 8 + +## 메서드 + +* splashscreen.show +* splashscreen.hide + +### 안 드 로ì´ë“œ 단ì + +ë‹¹ì‹ ì˜ config.xmlì— ë‹¤ìŒ í™˜ê²½ ì„¤ì •ì— ì¶”ê°€ 해야 합니다. + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +여기서 foo splashscreen 파ì¼, ì„ í˜¸ 9 패치 파ì¼ì˜ ì´ë¦„입니다. ì ì ˆ 한 í´ë” 아래 res/xml ë””ë ‰í† ë¦¬ì— splashcreen 파ì¼ì„ 추가 해야 합니다. ë‘ ë²ˆì§¸ 매개 변수는 splashscreen 얼마나 밀리초 단위로 표시 ë©ë‹ˆë‹¤ 나타냅니다. 3000 ms 기본값으로 사용 ë©ë‹ˆë‹¤. ìžì„¸í•œ ë‚´ìš©ì€ [ì•„ì´ì½˜ ë° ì‹œìž‘ 화면ì„][1] 참조 하ì‹ì‹œì˜¤. + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.hide + +시작 í™”ë©´ì„ ë‹«ìŠµë‹ˆë‹¤. + + navigator.splashscreen.hide(); + + +### ë¸”ëž™ë² ë¦¬ 10, WP8, iOS 특질 + +`config.xml`파ì¼ì˜ `AutoHideSplashScreen` ì„¤ì •ì„ í•´ì•¼ 합니다 `false` . 2 ì´ˆ ë™ì•ˆ 시작 í™”ë©´ì„ ìˆ¨ê¸°ê³ ì§€ì—°ì— ë‹¤ìŒê³¼ ê°™ì´ íƒ€ì´ë¨¸ 추가 `deviceready` ì´ë²¤íЏ 처리기: + + setTimeout(function() {navigator.splashscreen.hide(); + }, 2000); + + +## splashscreen.show + +시작 í™”ë©´ì„ í‘œì‹œí•©ë‹ˆë‹¤. + + navigator.splashscreen.show(); + + +ì‘ìš© 프로그램 í˜¸ì¶œí• ìˆ˜ 없습니다 `navigator.splashscreen.show()` ì‘ìš© í”„ë¡œê·¸ëž¨ì€ ì‹œìž‘ ë 때까지 ë° `deviceready` ì´ë²¤íŠ¸ë¥¼ í•´ ê³ í–ˆë‹¤. 하지만 ê·¸ 스플래시 스í¬ë¦°ì˜ 목ì 것 같다 ì¼ë°˜ì 으로 시작 í™”ë©´ì´ ë‹¹ì‹ ì˜ ì• í”Œ 리 ì¼€ì´ ì…˜ 시작 하기 ì „ì— í‘œì‹œ ë ìš´ëª…ì´ ë‹¤, ì´í›„. 몇 가지 êµ¬ì„±ì„ ì œê³µ `config.xml` ìžë™ìœ¼ë¡œ `show` 시작 화면 ì‘ìš© 프로그램 실행 후 즉시 ë° ê·¸ê²ƒì€ ì™„ë²½ 하 게 시작 하 ê³ ë°›ì€ ì „ì— `deviceready` ì´ë²¤íЏ. ì´ êµ¬ì„± 하 ê³ ìžì„¸í•œ ë‚´ìš©ì€ [ì•„ì´ì½˜ ë° ì‹œìž‘ 화면ì„][1] 참조 하ì‹ì‹œì˜¤. ì´ëŸ¬í•œ ì´ìœ 로, ê·¸ê²ƒì€ ê°€ëŠ¥ì„±ì´ í˜¸ì¶œ 해야 `navigator.splashscreen.show()` 시작 í™”ë©´ì€ ì‘ìš© 프로그램 ì‹œìž‘ì— ëŒ€ 한 표시 ë˜ë„ë¡ í•©ë‹ˆë‹¤.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/pl/index.md b/plugins/org.apache.cordova.splashscreen/doc/pl/index.md new file mode 100644 index 00000000..c23a332e --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/pl/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +Ten plugin wyświetla i ukrywa ekran powitalny podczas uruchamiania aplikacji. + +## Instalacja + + cordova plugin add org.apache.cordova.splashscreen + + +## Obsługiwane platformy + +* Amazon Fire OS +* Android +* BlackBerry 10 +* iOS +* Windows Phone 7 i 8 +* Windows 8 + +## Metody + +* splashscreen.show +* splashscreen.Hide + +### Dziwactwa Androida + +W pliku config.xml musisz dodać następujące preferencje: + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Gdzie foo jest nazwą pliku ekranu powitalnego, najlepiej 9 łatce. Upewnij się dodać pliki splashcreen do katalogu res/xml w odpowiednich folderach. Drugi parametr reprezentuje, jak długo ekranu powitalnego pojawi się w milisekundach. Domyślnie 3000 ms. Aby uzyskać więcej informacji, zobacz [ikony i ekrany powitalne w aplikacjach][1] . + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.Hide + +Odrzucić ten opryskaæ têcza. + + Navigator.splashscreen.Hide(); + + +### Jeżyna 10, WP8, iOS dziwactwo + +`config.xml`Pliku `AutoHideSplashScreen` ustawienie musi być `false` . Opóźnienia, ukrywanie ekranu powitalnego przez dwie sekundy, dodać timer następujących w `deviceready` obsługa zdarzeń: + + setTimeout(function() {navigator.splashscreen.hide(); + }, 2000); + + +## splashscreen.show + +Wyświetla ekran powitalny. + + Navigator.splashscreen.show(); + + +Aplikacja nie może wywołać `navigator.splashscreen.show()` aż aplikacja została uruchomiona i `deviceready` imprezy został zwolniony. Ale ponieważ zazwyczaj opryskać tęcza ma być widoczne przed rozpoczęciem aplikacji, wydaje się sprzeczne z celem ekranu powitalnego. Dostarczanie niektórych konfiguracji w `config.xml` będzie automatycznie `show` ekran powitalny, natychmiast po uruchomienie aplikacji i przed pełni rozpoczął i otrzymał `deviceready` zdarzenie. Aby uzyskać więcej informacji na robienie tej konfiguracji, zobacz [ikony i ekrany powitalne w aplikacjach][1] . Z tego powodu, jest mało prawdopodobne, należy zadzwonić `navigator.splashscreen.show()` Aby wyświetlić ekran powitalny dla uruchamiania aplikacji.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/ru/index.md b/plugins/org.apache.cordova.splashscreen/doc/ru/index.md new file mode 100644 index 00000000..1f872273 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/ru/index.md @@ -0,0 +1,75 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +Ðтот плагин отображает и Ñкрывает Ñкран-заÑтавку при запуÑке приложениÑ. + +## УÑтановка + + cordova plugin add org.apache.cordova.splashscreen + + +## Поддерживаемые платформы + +* Amazon Fire OS +* Android +* BlackBerry 10 +* iOS +* Windows Phone 7 и 8 +* Windows 8 + +## Методы + +* splashscreen.show +* splashscreen.hide + +### ОÑобенноÑти Android + +Ð’ вашем файле config.xml необходимо добавить Ñледующие наÑтройки: + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +Где foo Ñто Ð¸Ð¼Ñ Ñ„Ð°Ð¹Ð»Ð° splashscreen, желательно 9 заплатку. УбедитеÑÑŒ в том добавить ваши splashcreen файлы в папку res/xml в ÑоответÑтвующие папки. Второй параметр предÑтавлÑет, как долго splashscreen поÑвитÑÑ Ð² миллиÑекундах. По умолчанию он 3000 МС. Увидеть [иконки и заÑтавки][1] Ð´Ð»Ñ Ð¿Ð¾Ð»ÑƒÑ‡ÐµÐ½Ð¸Ñ Ð´Ð¾Ð¿Ð¾Ð»Ð½Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð¾Ð¹ информации. + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.hide + +Закройте Ñкран-заÑтавка. + + Navigator.SplashScreen.Hide(); + + +### ОÑобенноÑти BlackBerry 10, WP8, iOS + +`config.xml`Файла `AutoHideSplashScreen` должен быть `false` . Ð”Ð»Ñ Ð·Ð°Ð´ÐµÑ€Ð¶ÐºÐ¸ ÑÐºÑ€Ñ‹Ñ‚Ð¸Ñ Ð·Ð°Ñтавки на две Ñекунды, добавить таймер, например в `deviceready` обработчик Ñобытий: + + setTimeout(function() {navigator.splashscreen.hide(); + }, 2000); + + +## splashscreen.show + +Отображает Ñкран-заÑтавку. + + Navigator.SplashScreen.Show(); + + +Ваше приложение не может вызвать `navigator.splashscreen.show()` до тех пор, пока приложение началаÑÑŒ и `deviceready` Ñобытие инициировано. Ðо поÑкольку обычно Ñкран-заÑтавка должен быть видимым до начала вашего приложениÑ, что казалоÑÑŒ бы поражение цели Ñкрана-заÑтавки. ПредоÑтавление некоторых конфигурации в `config.xml` будет автоматичеÑки `show` Ñкран-заÑтавку Ñразу же поÑле запуÑка вашего Ð¿Ñ€Ð¸Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð¸ перед его полноÑтью запущен и получил `deviceready` Ñобытие. Увидеть [иконки и заÑтавки][1] Ð´Ð»Ñ Ð¿Ð¾Ð»ÑƒÑ‡ÐµÐ½Ð¸Ñ Ð´Ð¾Ð¿Ð¾Ð»Ð½Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð¾Ð¹ информации на делать Ñтой конфигурации. По Ñтой причине маловероÑтно, вам нужно вызвать `navigator.splashscreen.show()` Ð´Ð»Ñ Ð¾Ñ‚Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñ Ñкрана-заÑтавки Ð´Ð»Ñ Ð·Ð°Ð¿ÑƒÑка приложениÑ.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/doc/zh/index.md b/plugins/org.apache.cordova.splashscreen/doc/zh/index.md new file mode 100644 index 00000000..40e66918 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/doc/zh/index.md @@ -0,0 +1,74 @@ +<!--- + 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. +--> + +# org.apache.cordova.splashscreen + +這個外掛程å¼é¡¯ç¤ºå’Œéš±è—在應用程å¼å•Ÿå‹•期間的åˆå§‹èž¢å¹•。 + +## å®‰è£ + + cordova plugin add org.apache.cordova.splashscreen + + +## 支æ´çš„平臺 + +* 亞馬éœç« OS +* Android 系統 +* 黑莓 10 +* iOS +* Windows Phone 7 å’Œ 8 +* Windows 8 + +## 方法 + +* splashscreen.show +* splashscreen.hide + +### Android 的怪癖 + +åœ¨ä½ çš„ config.xmlï¼Œæ‚¨éœ€è¦æ·»åŠ ä»¥ä¸‹å„ªæƒ ï¼š + +`<preference name="SplashScreen" value="foo" />` `<preference name="SplashScreenDelay" value="10000" />` + +美åšåœ¨å“ªè£¡é–ƒå±æª”,最好是 9 ä¿®è£œç¨‹å¼æª”çš„å稱。 è«‹ç¢ºä¿æ‚¨çš„ splashcreen æª”æ·»åŠ åˆ° res/xml 目錄下相應的資料夾。 ç¬¬äºŒå€‹åƒæ•¸è¡¨ç¤ºå¤šä¹…é–ƒå±æœƒé¡¯ç¤ºä»¥æ¯«ç§’為單ä½ã€‚ 它將é è¨ç‚º 3000 毫秒。 有關更多資訊,請åƒè¦‹[圖示和啟動畫é¢][1]。 + + [1]: http://cordova.apache.org/docs/en/edge/config_ref_images.md.html + +## splashscreen.hide + +解雇的閃å±ã€‚ + + navigator.splashscreen.hide() ï¼› + + +### 黑莓 10,WP8,iOS 怪癖 + +`config.xml`檔的 `AutoHideSplashScreen` è¨ç½®å¿…é ˆç‚º `false` 。 è‹¥è¦å»¶é²å…©ç§’é˜éš±è—的閃å±ï¼Œæ·»åŠ å¦‚ä¸‹æ‰€ç¤ºåœ¨è¨ˆæ™‚å™¨ `deviceready` 事件處ç†å¸¸å¼ï¼š + + setTimeout(function() {navigator.splashscreen.hide() ï¼›},2000年) ï¼› + + +## splashscreen.show + +顯示åˆå§‹èž¢å¹•。 + + navigator.splashscreen.show() ï¼› + + +您的應用程å¼ç„¡æ³•調用 `navigator.splashscreen.show()` 直到應用程å¼å·²ç¶“開始, `deviceready` 觸發了事件。 但是,由於通常的閃å±ç‚ºäº†æ˜¯å¯è¦‹çš„在您的應用程å¼å•Ÿå‹•之å‰ï¼Œé€™ä¼¼ä¹Žæœƒæ‰“æ•—é–ƒå±çš„目的。 æä¾›ä¸€äº›é…置在 `config.xml` 將自動 `show` é–ƒå±æ‚¨çš„æ‡‰ç”¨ç¨‹å¼å•Ÿå‹•後立å³å’Œä¹‹å‰å®ƒå·²ç¶“完全起æ¥ä¸¦æ”¶åˆ° `deviceready` 事件。 åšé€™ç¨®é…置的詳細資訊,請åƒé–±[圖示和啟動畫é¢][1]。 å‡ºæ–¼é€™å€‹åŽŸå› ï¼Œå®ƒä¸å¤ªå¯èƒ½æ‚¨éœ€è¦èª¿ç”¨ `navigator.splashscreen.show()` ,使åˆå§‹èž¢å¹•å¯è¦‹ç‚ºæ‡‰ç”¨ç¨‹å¼å•Ÿå‹•。
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/package.json b/plugins/org.apache.cordova.splashscreen/package.json new file mode 100644 index 00000000..02b30c34 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/package.json @@ -0,0 +1,31 @@ +{ + "version": "1.0.0", + "name": "org.apache.cordova.splashscreen", + "cordova_name": "Splashscreen", + "description": "Cordova Splashscreen Plugin", + "license": "Apache 2.0", + "repo": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git", + "issue": "https://issues.apache.org/jira/browse/CB/component/12320653", + "keywords": [ + "cordova", + "splashscreen" + ], + "platforms": [ + "android", + "amazon-fireos", + "ubuntu", + "ios", + "blackberry10", + "wp7", + "wp8", + "windows8", + "tizen" + ], + "engines": [ + { + "name": "cordova-android", + "version": ">=3.6.0" + } + ], + "englishdoc": "<!---\n Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n-->\n\n# org.apache.cordova.splashscreen\n\nThis plugin displays and hides a splash screen during application launch.\n\n## Installation\n\n cordova plugin add org.apache.cordova.splashscreen\n\n\n## Supported Platforms\n\n- Amazon Fire OS\n- Android\n- BlackBerry 10\n- iOS\n- Windows Phone 7 and 8\n- Windows 8\n\n\n## Methods\n\n- splashscreen.show\n- splashscreen.hide\n\n### Android Quirks\n\nIn your config.xml, you need to add the following preferences:\n\n <preference name=\"SplashScreen\" value=\"foo\" />\n <preference name=\"SplashScreenDelay\" value=\"10000\" />\n\nWhere foo is the name of the splashscreen file, preferably a 9 patch file. Make sure to add your splashcreen files to your res/xml directory under the appropriate folders. The second parameter represents how long the splashscreen will appear in milliseconds. It defaults to 3000 ms. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html)\nfor more information.\n\n## splashscreen.hide\n\nDismiss the splash screen.\n\n navigator.splashscreen.hide();\n\n\n### BlackBerry 10, WP8, iOS Quirk\n\nThe `config.xml` file's `AutoHideSplashScreen` setting must be\n`false`. To delay hiding the splash screen for two seconds, add a\ntimer such as the following in the `deviceready` event handler:\n\n setTimeout(function() {\n navigator.splashscreen.hide();\n }, 2000);\n\n## splashscreen.show\n\nDisplays the splash screen.\n\n navigator.splashscreen.show();\n\n\nYour application cannot call `navigator.splashscreen.show()` until the app has\nstarted and the `deviceready` event has fired. But since typically the splash\nscreen is meant to be visible before your app has started, that would seem to\ndefeat the purpose of the splash screen. Providing some configuration in\n`config.xml` will automatically `show` the splash screen immediately after your\napp launch and before it has fully started and received the `deviceready`\nevent. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html)\nfor more information on doing this configuration. For this reason, it is\nunlikely you need to call `navigator.splashscreen.show()` to make the splash\nscreen visible for app startup.\n\n" +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/plugin.xml b/plugins/org.apache.cordova.splashscreen/plugin.xml new file mode 100644 index 00000000..fd70fd2c --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/plugin.xml @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="org.apache.cordova.splashscreen" + version="1.0.0"> + <name>Splashscreen</name> + <description>Cordova Splashscreen Plugin</description> + <license>Apache 2.0</license> + <keywords>cordova,splashscreen</keywords> + <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</repo> + <issue>https://issues.apache.org/jira/browse/CB/component/12320653</issue> + + <engines> + <engine name="cordova-android" version=">=3.6.0" /><!-- Requires CordovaPlugin.preferences --> + </engines> + + <js-module src="www/splashscreen.js" name="SplashScreen"> + <clobbers target="navigator.splashscreen" /> + </js-module> + + <!-- android --> + <platform name="android"> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="SplashScreen"> + <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/> + <param name="onload" value="true"/> + </feature> + </config-file> + + <source-file src="src/android/SplashScreen.java" target-dir="src/org/apache/cordova/splashscreen" /> + </platform> + + <!-- amazon-fireos --> + <platform name="amazon-fireos"> + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="SplashScreen"> + <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/> + </feature> + </config-file> + + <source-file src="src/android/SplashScreen.java" target-dir="src/org/apache/cordova/splashscreen" /> + </platform> + + <!-- ubuntu --> + <platform name="ubuntu"> + <header-file src="src/ubuntu/splashscreen.h" /> + <source-file src="src/ubuntu/splashscreen.cpp" /> + </platform> + + <!-- ios --> + <platform name="ios"> + <config-file target="config.xml" parent="/*"> + <feature name="SplashScreen"> + <param name="ios-package" value="CDVSplashScreen"/> + <param name="onload" value="true"/> + </feature> + </config-file> + + <header-file src="src/ios/CDVSplashScreen.h" /> + <source-file src="src/ios/CDVSplashScreen.m" /> + + <framework src="CoreGraphics.framework" /> + </platform> + + <!-- blackberry10 --> + <platform name="blackberry10"> + <source-file src="src/blackberry10/index.js" target-dir="SplashScreen" /> + <config-file target="www/config.xml" parent="/widget"> + <feature name="SplashScreen" value="SplashScreen"/> + </config-file> + </platform> + + <!-- wp7 --> + <platform name="wp7"> + <config-file target="config.xml" parent="/*"> + <feature name="SplashScreen"> + <param name="wp-package" value="SplashScreen"/> + <param name="onload" value="true"/> + </feature> + </config-file> + + <source-file src="src/wp/SplashScreen.cs" /> + + </platform> + + <!-- wp8 --> + <platform name="wp8"> + <config-file target="config.xml" parent="/*"> + <feature name="SplashScreen"> + <param name="wp-package" value="SplashScreen"/> + <param name="onload" value="true"/> + </feature> + </config-file> + + <source-file src="src/wp/SplashScreen.cs" /> + + </platform> + + <!-- windows8 --> + <platform name="windows8"> + <js-module src="www/windows8/SplashScreenProxy.js" name="SplashScreenProxy"> + <merges target="" /> + </js-module> + </platform> + + <!-- tizen --> + <platform name="tizen"> + <js-module src="src/tizen/SplashScreenProxy.js" name="SplashScreenProxy"> + <runs /> + </js-module> + </platform> +</plugin> diff --git a/plugins/org.apache.cordova.splashscreen/src/android/SplashScreen.java b/plugins/org.apache.cordova.splashscreen/src/android/SplashScreen.java new file mode 100644 index 00000000..ec3ad931 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/android/SplashScreen.java @@ -0,0 +1,281 @@ +/* + 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. +*/ + +package org.apache.cordova.splashscreen; + +import android.app.Dialog; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.graphics.Color; +import android.os.Handler; +import android.view.Display; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.LinearLayout; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.json.JSONArray; +import org.json.JSONException; + +public class SplashScreen extends CordovaPlugin { + private static final String LOG_TAG = "SplashScreen"; + // Cordova 3.x.x has a copy of this plugin bundled with it (SplashScreenInternal.java). + // Enable functionality only if running on 4.x.x. + private static final boolean HAS_BUILT_IN_SPLASH_SCREEN = Integer.valueOf(CordovaWebView.CORDOVA_VERSION.split("\\.")[0]) < 4; + private static Dialog splashDialog; + private static ProgressDialog spinnerDialog; + private static boolean firstShow = true; + + // Helper to be compile-time compatable with both Cordova 3.x and 4.x. + private View getView() { + try { + return (View)webView.getClass().getMethod("getView").invoke(webView); + } catch (Exception e) { + return (View)webView; + } + } + + @Override + protected void pluginInitialize() { + if (HAS_BUILT_IN_SPLASH_SCREEN || !firstShow) { + return; + } + // Make WebView invisible while loading URL + getView().setVisibility(View.INVISIBLE); + int drawableId = preferences.getInteger("SplashDrawableId", 0); + if (drawableId == 0) { + String splashResource = preferences.getString("SplashScreen", null); + if (splashResource != null) { + drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getClass().getPackage().getName()); + if (drawableId == 0) { + drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getPackageName()); + } + preferences.set("SplashDrawableId", drawableId); + } + } + + firstShow = false; + loadSpinner(); + showSplashScreen(true); + } + + @Override + public void onPause(boolean multitasking) { + if (HAS_BUILT_IN_SPLASH_SCREEN) { + return; + } + // hide the splash screen to avoid leaking a window + this.removeSplashScreen(); + } + + @Override + public void onDestroy() { + if (HAS_BUILT_IN_SPLASH_SCREEN) { + return; + } + // hide the splash screen to avoid leaking a window + this.removeSplashScreen(); + firstShow = true; + } + + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + if (action.equals("hide")) { + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + webView.postMessage("splashscreen", "hide"); + } + }); + } else if (action.equals("show")) { + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + webView.postMessage("splashscreen", "show"); + } + }); + } else if (action.equals("spinnerStart")) { + if (!HAS_BUILT_IN_SPLASH_SCREEN) { + final String title = args.getString(0); + final String message = args.getString(1); + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + spinnerStart(title, message); + } + }); + } + } else { + return false; + } + + callbackContext.success(); + return true; + } + + @Override + public Object onMessage(String id, Object data) { + if (HAS_BUILT_IN_SPLASH_SCREEN) { + return null; + } + if ("splashscreen".equals(id)) { + if ("hide".equals(data.toString())) { + this.removeSplashScreen(); + } else { + this.showSplashScreen(false); + } + } else if ("spinner".equals(id)) { + if ("stop".equals(data.toString())) { + this.spinnerStop(); + getView().setVisibility(View.VISIBLE); + } + } else if ("onReceivedError".equals(id)) { + spinnerStop(); + } + return null; + } + + private void removeSplashScreen() { + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + if (splashDialog != null && splashDialog.isShowing()) { + splashDialog.dismiss(); + splashDialog = null; + } + } + }); + } + + /** + * Shows the splash screen over the full Activity + */ + @SuppressWarnings("deprecation") + private void showSplashScreen(final boolean hideAfterDelay) { + final int splashscreenTime = preferences.getInteger("SplashScreenDelay", 3000); + final int drawableId = preferences.getInteger("SplashDrawableId", 0); + + // If the splash dialog is showing don't try to show it again + if (this.splashDialog != null && splashDialog.isShowing()) { + return; + } + if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) { + return; + } + + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + // Get reference to display + Display display = cordova.getActivity().getWindowManager().getDefaultDisplay(); + Context context = webView.getContext(); + + // Create the layout for the dialog + LinearLayout root = new LinearLayout(context); + root.setMinimumHeight(display.getHeight()); + root.setMinimumWidth(display.getWidth()); + root.setOrientation(LinearLayout.VERTICAL); + + // TODO: Use the background color of the webview's parent instead of using the + // preference. + root.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK)); + root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); + root.setBackgroundResource(drawableId); + + // Create and show the dialog + splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); + // check to see if the splash screen should be full screen + if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) + == WindowManager.LayoutParams.FLAG_FULLSCREEN) { + splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + splashDialog.setContentView(root); + splashDialog.setCancelable(false); + splashDialog.show(); + + // Set Runnable to remove splash screen just in case + if (hideAfterDelay) { + final Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + public void run() { + removeSplashScreen(); + } + }, splashscreenTime); + } + } + }); + } + + /* + * Load the spinner + */ + private void loadSpinner() { + // If loadingDialog property, then show the App loading dialog for first page of app + String loading = null; + if (webView.canGoBack()) { + loading = preferences.getString("LoadingDialog", null); + } + else { + loading = preferences.getString("LoadingPageDialog", null); + } + if (loading != null) { + String title = ""; + String message = "Loading Application..."; + + if (loading.length() > 0) { + int comma = loading.indexOf(','); + if (comma > 0) { + title = loading.substring(0, comma); + message = loading.substring(comma + 1); + } + else { + title = ""; + message = loading; + } + } + spinnerStart(title, message); + } + } + + private void spinnerStart(final String title, final String message) { + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + spinnerStop(); + spinnerDialog = ProgressDialog.show(webView.getContext(), title, message, true, true, + new DialogInterface.OnCancelListener() { + public void onCancel(DialogInterface dialog) { + spinnerDialog = null; + } + }); + } + }); + } + + private void spinnerStop() { + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + if (spinnerDialog != null && spinnerDialog.isShowing()) { + spinnerDialog.dismiss(); + spinnerDialog = null; + } + } + }); + } +} diff --git a/plugins/org.apache.cordova.splashscreen/src/blackberry10/index.js b/plugins/org.apache.cordova.splashscreen/src/blackberry10/index.js new file mode 100644 index 00000000..bd7e48c8 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/blackberry10/index.js @@ -0,0 +1,28 @@ +/* + * Copyright 2013 Research In Motion Limited. + * + * Licensed 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. + */ + +module.exports = { + show: function (success, fail, args, env) { + var result = new PluginResult(args, env); + result.error("Not supported on platform", false); + }, + + hide: function (success, fail, args, env) { + var result = new PluginResult(args, env); + window.qnx.webplatform.getApplication().windowVisible = true; + result.ok(undefined, false); + } +}; diff --git a/plugins/org.apache.cordova.splashscreen/src/ios/CDVSplashScreen.h b/plugins/org.apache.cordova.splashscreen/src/ios/CDVSplashScreen.h new file mode 100644 index 00000000..0d6ae397 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/ios/CDVSplashScreen.h @@ -0,0 +1,43 @@ +/* + 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. + */ + +#import <Foundation/Foundation.h> +#import <Cordova/CDVPlugin.h> + +typedef struct { + BOOL iPhone; + BOOL iPad; + BOOL iPhone5; + BOOL iPhone6; + BOOL iPhone6Plus; + BOOL retina; + +} CDV_iOSDevice; + +@interface CDVSplashScreen : CDVPlugin { + UIActivityIndicatorView* _activityView; + UIImageView* _imageView; + NSString* _curImageName; + BOOL _visible; +} + +- (void)show:(CDVInvokedUrlCommand*)command; +- (void)hide:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/org.apache.cordova.splashscreen/src/ios/CDVSplashScreen.m b/plugins/org.apache.cordova.splashscreen/src/ios/CDVSplashScreen.m new file mode 100644 index 00000000..c28ae2f5 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/ios/CDVSplashScreen.m @@ -0,0 +1,308 @@ +/* + 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. + */ + +#import "CDVSplashScreen.h" +#import <Cordova/CDVViewController.h> +#import <Cordova/CDVScreenOrientationDelegate.h> + +#define kSplashScreenDurationDefault 0.25f + + +@implementation CDVSplashScreen + +- (void)pluginInitialize +{ + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad) name:CDVPageDidLoadNotification object:self.webView]; + + [self setVisible:YES]; +} + +- (void)show:(CDVInvokedUrlCommand*)command +{ + [self setVisible:YES]; +} + +- (void)hide:(CDVInvokedUrlCommand*)command +{ + [self setVisible:NO]; +} + +- (void)pageDidLoad +{ + id autoHideSplashScreenValue = [self.commandDelegate.settings objectForKey:[@"AutoHideSplashScreen" lowercaseString]]; + + // if value is missing, default to yes + if ((autoHideSplashScreenValue == nil) || [autoHideSplashScreenValue boolValue]) { + [self setVisible:NO]; + } +} + +- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context +{ + [self updateImage]; +} + +- (void)createViews +{ + /* + * The Activity View is the top spinning throbber in the status/battery bar. We init it with the default Grey Style. + * + * whiteLarge = UIActivityIndicatorViewStyleWhiteLarge + * white = UIActivityIndicatorViewStyleWhite + * gray = UIActivityIndicatorViewStyleGray + * + */ + NSString* topActivityIndicator = [self.commandDelegate.settings objectForKey:[@"TopActivityIndicator" lowercaseString]]; + UIActivityIndicatorViewStyle topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray; + + if ([topActivityIndicator isEqualToString:@"whiteLarge"]) { + topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhiteLarge; + } else if ([topActivityIndicator isEqualToString:@"white"]) { + topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhite; + } else if ([topActivityIndicator isEqualToString:@"gray"]) { + topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray; + } + + UIView* parentView = self.viewController.view; + parentView.userInteractionEnabled = NO; // disable user interaction while splashscreen is shown + _activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:topActivityIndicatorStyle]; + _activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2); + _activityView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin + | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin; + [_activityView startAnimating]; + + // Set the frame & image later. + _imageView = [[UIImageView alloc] init]; + [parentView addSubview:_imageView]; + + id showSplashScreenSpinnerValue = [self.commandDelegate.settings objectForKey:[@"ShowSplashScreenSpinner" lowercaseString]]; + // backwards compatibility - if key is missing, default to true + if ((showSplashScreenSpinnerValue == nil) || [showSplashScreenSpinnerValue boolValue]) { + [parentView addSubview:_activityView]; + } + + // Frame is required when launching in portrait mode. + // Bounds for landscape since it captures the rotation. + [parentView addObserver:self forKeyPath:@"frame" options:0 context:nil]; + [parentView addObserver:self forKeyPath:@"bounds" options:0 context:nil]; + + [self updateImage]; +} + +- (void)destroyViews +{ + [_imageView removeFromSuperview]; + [_activityView removeFromSuperview]; + _imageView = nil; + _activityView = nil; + _curImageName = nil; + + self.viewController.view.userInteractionEnabled = YES; // re-enable user interaction upon completion + [self.viewController.view removeObserver:self forKeyPath:@"frame"]; + [self.viewController.view removeObserver:self forKeyPath:@"bounds"]; +} + +- (CDV_iOSDevice) getCurrentDevice +{ + CDV_iOSDevice device; + + UIScreen* mainScreen = [UIScreen mainScreen]; + CGFloat mainScreenHeight = mainScreen.bounds.size.height; + CGFloat mainScreenWidth = mainScreen.bounds.size.width; + + int limit = MAX(mainScreenHeight,mainScreenWidth); + + device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); + device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); + device.retina = ([mainScreen scale] == 2.0); + device.iPhone5 = (device.iPhone && limit == 568.0); + // note these below is not a true device detect, for example if you are on an + // iPhone 6/6+ but the app is scaled it will prob set iPhone5 as true, but + // this is appropriate for detecting the runtime screen environment + device.iPhone6 = (device.iPhone && limit == 667.0); + device.iPhone6Plus = (device.iPhone && limit == 736.0); + + return device; +} + +- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device +{ + // Use UILaunchImageFile if specified in plist. Otherwise, use Default. + NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"]; + + NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations]; + + // Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape + BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape); + BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown); + // this means there are no mixed orientations in there + BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape); + + if (imageName) { + imageName = [imageName stringByDeletingPathExtension]; + } else { + imageName = @"Default"; + } + + if (device.iPhone5) { // does not support landscape + imageName = [imageName stringByAppendingString:@"-568h"]; + } else if (device.iPhone6) { // does not support landscape + imageName = [imageName stringByAppendingString:@"-667h"]; + } else if (device.iPhone6Plus) { // supports landscape + if (isOrientationLocked) { + imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")]; + } else { + switch (currentOrientation) { + case UIInterfaceOrientationLandscapeLeft: + case UIInterfaceOrientationLandscapeRight: + imageName = [imageName stringByAppendingString:@"-Landscape"]; + break; + default: + break; + } + } + imageName = [imageName stringByAppendingString:@"-736h"]; + + } else if (device.iPad) { // supports landscape + if (isOrientationLocked) { + imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")]; + } else { + switch (currentOrientation) { + case UIInterfaceOrientationLandscapeLeft: + case UIInterfaceOrientationLandscapeRight: + imageName = [imageName stringByAppendingString:@"-Landscape"]; + break; + + case UIInterfaceOrientationPortrait: + case UIInterfaceOrientationPortraitUpsideDown: + default: + imageName = [imageName stringByAppendingString:@"-Portrait"]; + break; + } + } + } + + return imageName; +} + +// Sets the view's frame and image. +- (void)updateImage +{ + NSString* imageName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]]; + + if (![imageName isEqualToString:_curImageName]) { + UIImage* img = [UIImage imageNamed:imageName]; + _imageView.image = img; + _curImageName = imageName; + } + + // Check that splash screen's image exists before updating bounds + if (_imageView.image) { + [self updateBounds]; + } else { + NSLog(@"WARNING: The splashscreen image named %@ was not found", imageName); + } +} + +- (void)updateBounds +{ + UIImage* img = _imageView.image; + CGRect imgBounds = (img) ? CGRectMake(0, 0, img.size.width, img.size.height) : CGRectZero; + + CGSize screenSize = [self.viewController.view convertRect:[UIScreen mainScreen].bounds fromView:nil].size; + UIInterfaceOrientation orientation = self.viewController.interfaceOrientation; + CGAffineTransform imgTransform = CGAffineTransformIdentity; + + /* If and only if an iPhone application is landscape-only as per + * UISupportedInterfaceOrientations, the view controller's orientation is + * landscape. In this case the image must be rotated in order to appear + * correctly. + */ + BOOL isIPad = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad; + if (UIInterfaceOrientationIsLandscape(orientation) && !isIPad) { + imgTransform = CGAffineTransformMakeRotation(M_PI / 2); + imgBounds.size = CGSizeMake(imgBounds.size.height, imgBounds.size.width); + } + + // There's a special case when the image is the size of the screen. + if (CGSizeEqualToSize(screenSize, imgBounds.size)) { + CGRect statusFrame = [self.viewController.view convertRect:[UIApplication sharedApplication].statusBarFrame fromView:nil]; + if (!(IsAtLeastiOSVersion(@"7.0"))) { + imgBounds.origin.y -= statusFrame.size.height; + } + } else if (imgBounds.size.width > 0) { + CGRect viewBounds = self.viewController.view.bounds; + CGFloat imgAspect = imgBounds.size.width / imgBounds.size.height; + CGFloat viewAspect = viewBounds.size.width / viewBounds.size.height; + // This matches the behaviour of the native splash screen. + CGFloat ratio; + if (viewAspect > imgAspect) { + ratio = viewBounds.size.width / imgBounds.size.width; + } else { + ratio = viewBounds.size.height / imgBounds.size.height; + } + imgBounds.size.height *= ratio; + imgBounds.size.width *= ratio; + } + + _imageView.transform = imgTransform; + _imageView.frame = imgBounds; +} + +- (void)setVisible:(BOOL)visible +{ + if (visible == _visible) { + return; + } + _visible = visible; + + id fadeSplashScreenValue = [self.commandDelegate.settings objectForKey:[@"FadeSplashScreen" lowercaseString]]; + id fadeSplashScreenDuration = [self.commandDelegate.settings objectForKey:[@"FadeSplashScreenDuration" lowercaseString]]; + + float fadeDuration = fadeSplashScreenDuration == nil ? kSplashScreenDurationDefault : [fadeSplashScreenDuration floatValue]; + + if ((fadeSplashScreenValue == nil) || ![fadeSplashScreenValue boolValue]) { + fadeDuration = 0; + } + + // Never animate the showing of the splash screen. + if (visible) { + if (_imageView == nil) { + [self createViews]; + } + } else if (fadeDuration == 0) { + [self destroyViews]; + } else { + [UIView transitionWithView:self.viewController.view + duration:fadeDuration + options:UIViewAnimationOptionTransitionNone + animations:^(void) { + [_imageView setAlpha:0]; + [_activityView setAlpha:0]; + } + completion:^(BOOL finished) { + if (finished) { + [self destroyViews]; + } + } + ]; + } +} + +@end diff --git a/plugins/org.apache.cordova.splashscreen/src/tizen/SplashScreenProxy.js b/plugins/org.apache.cordova.splashscreen/src/tizen/SplashScreenProxy.js new file mode 100644 index 00000000..fbd9f35f --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/tizen/SplashScreenProxy.js @@ -0,0 +1,43 @@ +/* + * + * 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. + * +*/ + +( function() { + +win = null; + +module.exports = { + show: function() { + if ( win === null ) { + win = window.open('splashscreen.html'); + } + }, + + hide: function() { + if ( win !== null ) { + win.close(); + win = null; + } + } +}; + +require("cordova/tizen/commandProxy").add("SplashScreen", module.exports); + +})(); diff --git a/plugins/org.apache.cordova.splashscreen/src/ubuntu/splashscreen.cpp b/plugins/org.apache.cordova.splashscreen/src/ubuntu/splashscreen.cpp new file mode 100644 index 00000000..1c9ecac8 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/ubuntu/splashscreen.cpp @@ -0,0 +1,42 @@ +/* + * + * Copyright 2013 Canonical Ltd. + * + * 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. + * +*/ + +#include <QQuickItem> + +#include "splashscreen.h" +#include <cordova.h> + +#define SPLASHSCREEN_STATE_NAME "splashscreen" + +Splashscreen::Splashscreen(Cordova *cordova): CPlugin(cordova) { +} + +void Splashscreen::show(int, int) { + m_cordova->rootObject()->setProperty("splashscreenPath", m_cordova->getSplashscreenPath()); + + m_cordova->pushViewState(SPLASHSCREEN_STATE_NAME); +} + +void Splashscreen::hide(int, int) { + m_cordova->popViewState(SPLASHSCREEN_STATE_NAME); +} diff --git a/plugins/org.apache.cordova.splashscreen/src/ubuntu/splashscreen.h b/plugins/org.apache.cordova.splashscreen/src/ubuntu/splashscreen.h new file mode 100644 index 00000000..1d437f84 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/ubuntu/splashscreen.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2013 Canonical Ltd. + * + * 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. + * +*/ + +#ifndef SPLASHSCREEN_H +#define SPLASHSCREEN_H + +#include <QtCore> +#include <cplugin.h> + +class Splashscreen: public CPlugin { + Q_OBJECT +public: + explicit Splashscreen(Cordova *cordova); + + virtual const QString fullName() override { + return Splashscreen::fullID(); + } + + virtual const QString shortName() override { + return "SplashScreen"; + } + + static const QString fullID() { + return "SplashScreen"; + } + +public slots: + void show(int, int); + void hide(int, int); +}; + +#endif // SPLASHSCREEN_H diff --git a/plugins/org.apache.cordova.splashscreen/src/wp/SplashScreen.cs b/plugins/org.apache.cordova.splashscreen/src/wp/SplashScreen.cs new file mode 100644 index 00000000..4d3545b0 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/src/wp/SplashScreen.cs @@ -0,0 +1,167 @@ +/* + Licensed 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. +*/ + +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Info; +using System.Windows.Controls.Primitives; +using System.Diagnostics; +using System.Windows.Media.Imaging; +using System.Windows.Resources; +using System.IO; +using System.Xml.Linq; +using System.Linq; +using System.Windows.Threading; + +namespace WPCordovaClassLib.Cordova.Commands +{ + /// <summary> + /// Listens for changes to the state of the battery on the device. + /// Currently only the "isPlugged" parameter available via native APIs. + /// </summary> + public class SplashScreen : BaseCommand + { + private Popup popup; + private bool autohide = true; + + private static bool WasShown = false; + + public SplashScreen() + { + Image SplashScreen = new Image(); + BitmapImage splash_image = new BitmapImage(); + splash_image.SetSource(Application.GetResourceStream(new Uri(@"SplashScreenImage.jpg", UriKind.Relative)).Stream); + SplashScreen.Source = splash_image; + + // Instansiate the popup and set the Child property of Popup to SplashScreen + popup = new Popup() {IsOpen = false, Child = SplashScreen }; + // Orient the popup accordingly + popup.HorizontalAlignment = HorizontalAlignment.Stretch; + popup.VerticalAlignment = VerticalAlignment.Center; + + + LoadConfigValues(); + } + + public override void OnInit() + { + // we only want to autoload the first time a page is loaded. + if (!WasShown) + { + WasShown = true; + show(); + } + } + + void LoadConfigValues() + { + StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("config.xml", UriKind.Relative)); + + if (streamInfo != null) + { + StreamReader sr = new StreamReader(streamInfo.Stream); + //This will Read Keys Collection for the xml file + XDocument document = XDocument.Parse(sr.ReadToEnd()); + + var preferences = from results in document.Descendants() + where (string)results.Attribute("name") == "AutoHideSplashScreen" + select (string)results.Attribute("value") == "true"; + + if (preferences.Count() > 0 && preferences.First() == false) + { + autohide = false; + } + } + } + + public void show(string options = null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + if (popup.IsOpen) + { + return; + } + + popup.Child.Opacity = 0; + + Storyboard story = new Storyboard(); + DoubleAnimation animation; + animation = new DoubleAnimation(); + animation.From = 0.0; + animation.To = 1.0; + animation.Duration = new Duration(TimeSpan.FromSeconds(0.2)); + + Storyboard.SetTarget(animation, popup.Child); + Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity")); + story.Children.Add(animation); + + Debug.WriteLine("Fading the splash screen in"); + + story.Begin(); + + popup.IsOpen = true; + + if (autohide) + { + DispatcherTimer timer = new DispatcherTimer(); + timer.Tick += (object sender, EventArgs e) => + { + hide(); + }; + timer.Interval = TimeSpan.FromSeconds(1.2); + timer.Start(); + } + }); + } + + + public void hide(string options = null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + if (!popup.IsOpen) + { + return; + } + + popup.Child.Opacity = 1.0; + + Storyboard story = new Storyboard(); + DoubleAnimation animation; + animation = new DoubleAnimation(); + animation.From = 1.0; + animation.To = 0.0; + animation.Duration = new Duration(TimeSpan.FromSeconds(0.4)); + + Storyboard.SetTarget(animation, popup.Child); + Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity")); + story.Children.Add(animation); + story.Completed += (object sender, EventArgs e) => + { + popup.IsOpen = false; + }; + story.Begin(); + }); + } + } +} diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/contents.xcworkspacedata b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..2dd325a0 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Workspace + version = "1.0"> + <FileRef + location = "container:CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj"> + </FileRef> +</Workspace> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/xcshareddata/CDVSplashScreenTest.xccheckout b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/xcshareddata/CDVSplashScreenTest.xccheckout new file mode 100644 index 00000000..7e4cdb93 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/xcshareddata/CDVSplashScreenTest.xccheckout @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>IDESourceControlProjectFavoriteDictionaryKey</key> + <false/> + <key>IDESourceControlProjectIdentifier</key> + <string>6BE9AD73-1B9F-4362-98D7-DC631BEC6185</string> + <key>IDESourceControlProjectName</key> + <string>CDVSplashScreenTest</string> + <key>IDESourceControlProjectOriginsDictionary</key> + <dict> + <key>BEF5A5D0FF64801E558286389440357A9233D7DB</key> + <string>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</string> + </dict> + <key>IDESourceControlProjectPath</key> + <string>tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj</string> + <key>IDESourceControlProjectRelativeInstallPathDictionary</key> + <dict> + <key>BEF5A5D0FF64801E558286389440357A9233D7DB</key> + <string>../../../../..</string> + </dict> + <key>IDESourceControlProjectURL</key> + <string>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</string> + <key>IDESourceControlProjectVersion</key> + <integer>111</integer> + <key>IDESourceControlProjectWCCIdentifier</key> + <string>BEF5A5D0FF64801E558286389440357A9233D7DB</string> + <key>IDESourceControlProjectWCConfigurations</key> + <array> + <dict> + <key>IDESourceControlRepositoryExtensionIdentifierKey</key> + <string>public.vcs.git</string> + <key>IDESourceControlWCCIdentifierKey</key> + <string>BEF5A5D0FF64801E558286389440357A9233D7DB</string> + <key>IDESourceControlWCCName</key> + <string>cordova-plugin-splashscreen</string> + </dict> + </array> +</dict> +</plist> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/xcshareddata/xcschemes/CordovaLib.xcscheme b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/xcshareddata/xcschemes/CordovaLib.xcscheme new file mode 100644 index 00000000..13f9a157 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest.xcworkspace/xcshareddata/xcschemes/CordovaLib.xcscheme @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "0600" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "YES" + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "D2AAC07D0554694100DB518D" + BuildableName = "libCordova.a" + BlueprintName = "CordovaLib" + ReferencedContainer = "container:node_modules/cordova-ios/CordovaLib/CordovaLib.xcodeproj"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES" + buildConfiguration = "Debug"> + <Testables> + </Testables> + </TestAction> + <LaunchAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + allowLocationSimulation = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "D2AAC07D0554694100DB518D" + BuildableName = "libCordova.a" + BlueprintName = "CordovaLib" + ReferencedContainer = "container:node_modules/cordova-ios/CordovaLib/CordovaLib.xcodeproj"> + </BuildableReference> + </MacroExpansion> + <AdditionalOptions> + </AdditionalOptions> + </LaunchAction> + <ProfileAction + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Release" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "D2AAC07D0554694100DB518D" + BuildableName = "libCordova.a" + BlueprintName = "CordovaLib" + ReferencedContainer = "container:node_modules/cordova-ios/CordovaLib/CordovaLib.xcodeproj"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m new file mode 100644 index 00000000..1637d247 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m @@ -0,0 +1,702 @@ +/* + 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. + */ + +#import <UIKit/UIKit.h> +#import <XCTest/XCTest.h> +#import <Cordova/CDVScreenOrientationDelegate.h> +#import "CDVSplashScreen.h" +#import "ImageNameTestDelegates.h" + +const CDV_iOSDevice CDV_iOSDeviceZero = { 0, 0, 0, 0, 0, 0 }; + +@interface ImageNameTest : XCTestCase + +@property (nonatomic, strong) CDVSplashScreen* plugin; + +@end + +@interface CDVSplashScreen () + +// expose private interface +- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device; + +@end + +@implementation ImageNameTest + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. + + self.plugin = [[CDVSplashScreen alloc] init]; +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void) orientationHelper:(id<CDVScreenOrientationDelegate>)delegate expectedImageNameDictionary:(NSDictionary*)expectedImageNameDictionary device:(CDV_iOSDevice)device{ + + NSString* name = nil; + NSString* expectedImageName = nil; + UIInterfaceOrientation currentOrientation; + NSString* deviceName = device.iPad? @"iPad" : device.iPhone6Plus? @"iPhone6Plus": device.iPhone6? @"iPhone6": device.iPhone5? @"iPhone5" : @"iPhone"; + + // LandscapeLeft, should always return expectedImageName + currentOrientation = UIInterfaceOrientationLandscapeLeft; + name = [self.plugin getImageName:currentOrientation delegate:delegate device:device]; + expectedImageName = [expectedImageNameDictionary objectForKey:@"landscapeLeft"]; + XCTAssertTrue([expectedImageName isEqualToString:name], @"%@ - %@ failed (%@)", @"Landscape", deviceName, name); + + // LandscapeRight - should always return expectedImageName + currentOrientation = UIInterfaceOrientationLandscapeRight; + name = [self.plugin getImageName:currentOrientation delegate:delegate device:device]; + expectedImageName = [expectedImageNameDictionary objectForKey:@"landscapeRight"]; + XCTAssertTrue([expectedImageName isEqualToString:name], @"%@ - %@ failed (%@)", @"Landscape", deviceName, name); + + // Portrait - should always return expectedImageName + currentOrientation = UIInterfaceOrientationPortrait; + name = [self.plugin getImageName:currentOrientation delegate:delegate device:device]; + expectedImageName = [expectedImageNameDictionary objectForKey:@"portrait"]; + XCTAssertTrue([expectedImageName isEqualToString:name], @"%@ - %@ failed (%@)", @"Portrait", deviceName, name); + + // PortraitUpsideDown - should always return expectedImageName + currentOrientation = UIInterfaceOrientationPortraitUpsideDown; + name = [self.plugin getImageName:currentOrientation delegate:delegate device:device]; + expectedImageName = [expectedImageNameDictionary objectForKey:@"portraitUpsideDown"]; + XCTAssertTrue([expectedImageName isEqualToString:name], @"%@ - %@ failed (%@)", @"Portrait", deviceName, name); +} + +- (void)testiPadOrientation { + + CDV_iOSDevice device = CDV_iOSDeviceZero; + device.iPad = YES; + + // One orientation + + PortraitOnly* delegate = [[PortraitOnly alloc] init]; + [self orientationHelper:delegate expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Portrait", + @"landscapeRight" : @"Default-Portrait", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + PortraitUpsideDownOnly* delegate2 = [[PortraitUpsideDownOnly alloc] init]; + [self orientationHelper:delegate2 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Portrait", + @"landscapeRight" : @"Default-Portrait", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + LandscapeLeftOnly* delegate3 = [[LandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate3 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Landscape", + @"portraitUpsideDown" : @"Default-Landscape" + } + device:device]; + + LandscapeRightOnly* delegate4 = [[LandscapeRightOnly alloc] init]; + [self orientationHelper:delegate4 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Landscape", + @"portraitUpsideDown" : @"Default-Landscape" + } + device:device]; + + // All Portrait + + AllPortraitOnly* delegate5 = [[AllPortraitOnly alloc] init]; + [self orientationHelper:delegate5 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Portrait", + @"landscapeRight" : @"Default-Portrait", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + // All Landscape + + AllLandscapeOnly* delegate6 = [[AllLandscapeOnly alloc] init]; + [self orientationHelper:delegate6 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Landscape", + @"portraitUpsideDown" : @"Default-Landscape" + } + device:device]; + + + // All orientations + + AllOrientations* delegate7 = [[AllOrientations alloc] init]; + [self orientationHelper:delegate7 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + // Portrait and Landscape Left + + PortraitAndLandscapeLeftOnly* delegate8 = [[PortraitAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate8 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + // Portrait and Landscape Right + + PortraitAndLandscapeRightOnly* delegate9 = [[PortraitAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate9 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + // PortraitUpsideDown and Landscape Left + + PortraitUpsideDownAndLandscapeLeftOnly* delegate10 = [[PortraitUpsideDownAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate10 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; + + // PortraitUpsideDown and Landscape Right + + PortraitUpsideDownAndLandscapeRightOnly* delegate11 = [[PortraitUpsideDownAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate11 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape", + @"landscapeRight" : @"Default-Landscape", + @"portrait" : @"Default-Portrait", + @"portraitUpsideDown" : @"Default-Portrait" + } + device:device]; +} + +- (void)testiPhoneOrientation { + + CDV_iOSDevice device = CDV_iOSDeviceZero; + device.iPhone = YES; + + // One orientation + + PortraitOnly* delegate = [[PortraitOnly alloc] init]; + [self orientationHelper:delegate expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + PortraitUpsideDownOnly* delegate2 = [[PortraitUpsideDownOnly alloc] init]; + [self orientationHelper:delegate2 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + LandscapeLeftOnly* delegate3 = [[LandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate3 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + LandscapeRightOnly* delegate4 = [[LandscapeRightOnly alloc] init]; + [self orientationHelper:delegate4 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + // All Portrait + + AllPortraitOnly* delegate5 = [[AllPortraitOnly alloc] init]; + [self orientationHelper:delegate5 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + // All Landscape + + AllLandscapeOnly* delegate6 = [[AllLandscapeOnly alloc] init]; + [self orientationHelper:delegate6 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + + // All orientations + + AllOrientations* delegate7 = [[AllOrientations alloc] init]; + [self orientationHelper:delegate7 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + // Portrait and Landscape Left + + PortraitAndLandscapeLeftOnly* delegate8 = [[PortraitAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate8 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + // Portrait and Landscape Right + + PortraitAndLandscapeRightOnly* delegate9 = [[PortraitAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate9 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + // PortraitUpsideDown and Landscape Left + + PortraitUpsideDownAndLandscapeLeftOnly* delegate10 = [[PortraitUpsideDownAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate10 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; + + // PortraitUpsideDown and Landscape Right + + PortraitUpsideDownAndLandscapeRightOnly* delegate11 = [[PortraitUpsideDownAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate11 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default", + @"landscapeRight" : @"Default", + @"portrait" : @"Default", + @"portraitUpsideDown" : @"Default" + } + device:device]; +} + +- (void)testiPhone5Orientation { + + CDV_iOSDevice device = CDV_iOSDeviceZero; + device.iPhone = YES; + device.iPhone5 = YES; + + // One orientation + + PortraitOnly* delegate = [[PortraitOnly alloc] init]; + [self orientationHelper:delegate expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + PortraitUpsideDownOnly* delegate2 = [[PortraitUpsideDownOnly alloc] init]; + [self orientationHelper:delegate2 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + LandscapeLeftOnly* delegate3 = [[LandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate3 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + LandscapeRightOnly* delegate4 = [[LandscapeRightOnly alloc] init]; + [self orientationHelper:delegate4 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + // All Portrait + + AllPortraitOnly* delegate5 = [[AllPortraitOnly alloc] init]; + [self orientationHelper:delegate5 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + // All Landscape + + AllLandscapeOnly* delegate6 = [[AllLandscapeOnly alloc] init]; + [self orientationHelper:delegate6 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + + // All orientations + + AllOrientations* delegate7 = [[AllOrientations alloc] init]; + [self orientationHelper:delegate7 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + // Portrait and Landscape Left + + PortraitAndLandscapeLeftOnly* delegate8 = [[PortraitAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate8 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + // Portrait and Landscape Right + + PortraitAndLandscapeRightOnly* delegate9 = [[PortraitAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate9 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + // PortraitUpsideDown and Landscape Left + + PortraitUpsideDownAndLandscapeLeftOnly* delegate10 = [[PortraitUpsideDownAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate10 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; + + // PortraitUpsideDown and Landscape Right + + PortraitUpsideDownAndLandscapeRightOnly* delegate11 = [[PortraitUpsideDownAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate11 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-568h", + @"landscapeRight" : @"Default-568h", + @"portrait" : @"Default-568h", + @"portraitUpsideDown" : @"Default-568h" + } + device:device]; +} + +- (void)testiPhone6Orientation { + + CDV_iOSDevice device = CDV_iOSDeviceZero; + device.iPhone = YES; + device.iPhone6 = YES; + + // One orientation + + PortraitOnly* delegate = [[PortraitOnly alloc] init]; + [self orientationHelper:delegate expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + PortraitUpsideDownOnly* delegate2 = [[PortraitUpsideDownOnly alloc] init]; + [self orientationHelper:delegate2 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + LandscapeLeftOnly* delegate3 = [[LandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate3 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + LandscapeRightOnly* delegate4 = [[LandscapeRightOnly alloc] init]; + [self orientationHelper:delegate4 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + // All Portrait + + AllPortraitOnly* delegate5 = [[AllPortraitOnly alloc] init]; + [self orientationHelper:delegate5 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + // All Landscape + + AllLandscapeOnly* delegate6 = [[AllLandscapeOnly alloc] init]; + [self orientationHelper:delegate6 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + + // All orientations + + AllOrientations* delegate7 = [[AllOrientations alloc] init]; + [self orientationHelper:delegate7 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + // Portrait and Landscape Left + + PortraitAndLandscapeLeftOnly* delegate8 = [[PortraitAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate8 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + // Portrait and Landscape Right + + PortraitAndLandscapeRightOnly* delegate9 = [[PortraitAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate9 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + // PortraitUpsideDown and Landscape Left + + PortraitUpsideDownAndLandscapeLeftOnly* delegate10 = [[PortraitUpsideDownAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate10 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; + + // PortraitUpsideDown and Landscape Right + + PortraitUpsideDownAndLandscapeRightOnly* delegate11 = [[PortraitUpsideDownAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate11 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-667h", + @"landscapeRight" : @"Default-667h", + @"portrait" : @"Default-667h", + @"portraitUpsideDown" : @"Default-667h" + } + device:device]; +} + +- (void)testiPhone6PlusOrientation { + + CDV_iOSDevice device = CDV_iOSDeviceZero; + device.iPhone = YES; + device.iPhone6Plus = YES; + + // One orientation + + PortraitOnly* delegate = [[PortraitOnly alloc] init]; + [self orientationHelper:delegate expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-736h", + @"landscapeRight" : @"Default-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + PortraitUpsideDownOnly* delegate2 = [[PortraitUpsideDownOnly alloc] init]; + [self orientationHelper:delegate2 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-736h", + @"landscapeRight" : @"Default-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + LandscapeLeftOnly* delegate3 = [[LandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate3 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-Landscape-736h", + @"portraitUpsideDown" : @"Default-Landscape-736h" + } + device:device]; + + LandscapeRightOnly* delegate4 = [[LandscapeRightOnly alloc] init]; + [self orientationHelper:delegate4 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-Landscape-736h", + @"portraitUpsideDown" : @"Default-Landscape-736h" + } + device:device]; + + // All Portrait + + AllPortraitOnly* delegate5 = [[AllPortraitOnly alloc] init]; + [self orientationHelper:delegate5 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-736h", + @"landscapeRight" : @"Default-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + // All Landscape + + AllLandscapeOnly* delegate6 = [[AllLandscapeOnly alloc] init]; + [self orientationHelper:delegate6 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-Landscape-736h", + @"portraitUpsideDown" : @"Default-Landscape-736h" + } + device:device]; + + + // All orientations + + AllOrientations* delegate7 = [[AllOrientations alloc] init]; + [self orientationHelper:delegate7 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + // Portrait and Landscape Left + + PortraitAndLandscapeLeftOnly* delegate8 = [[PortraitAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate8 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + // Portrait and Landscape Right + + PortraitAndLandscapeRightOnly* delegate9 = [[PortraitAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate9 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + // PortraitUpsideDown and Landscape Left + + PortraitUpsideDownAndLandscapeLeftOnly* delegate10 = [[PortraitUpsideDownAndLandscapeLeftOnly alloc] init]; + [self orientationHelper:delegate10 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; + + // PortraitUpsideDown and Landscape Right + + PortraitUpsideDownAndLandscapeRightOnly* delegate11 = [[PortraitUpsideDownAndLandscapeRightOnly alloc] init]; + [self orientationHelper:delegate11 expectedImageNameDictionary:@{ + @"landscapeLeft" : @"Default-Landscape-736h", + @"landscapeRight" : @"Default-Landscape-736h", + @"portrait" : @"Default-736h", + @"portraitUpsideDown" : @"Default-736h" + } + device:device]; +} + + + +@end diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTestDelegates.h b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTestDelegates.h new file mode 100644 index 00000000..be4a7883 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTestDelegates.h @@ -0,0 +1,57 @@ +/* + 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. + */ + +#import <Foundation/Foundation.h> +#import <Cordova/CDVScreenOrientationDelegate.h> + +@interface PortraitOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface PortraitUpsideDownOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface AllPortraitOnly : NSObject <CDVScreenOrientationDelegate> +@end + + +@interface LandscapeLeftOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface LandscapeRightOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface AllLandscapeOnly : NSObject <CDVScreenOrientationDelegate> +@end + + +@interface AllOrientations : NSObject <CDVScreenOrientationDelegate> +@end + +@interface PortraitAndLandscapeLeftOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface PortraitAndLandscapeRightOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface PortraitUpsideDownAndLandscapeLeftOnly : NSObject <CDVScreenOrientationDelegate> +@end + +@interface PortraitUpsideDownAndLandscapeRightOnly : NSObject <CDVScreenOrientationDelegate> +@end + diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTestDelegates.m b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTestDelegates.m new file mode 100644 index 00000000..b5a1b23e --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTestDelegates.m @@ -0,0 +1,200 @@ +/* + 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. + */ + +#import <UIKit/UIKit.h> +#import "ImageNameTestDelegates.h" + +@implementation PortraitOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation PortraitUpsideDownOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortraitUpsideDown; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation AllPortraitOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + + +@implementation LandscapeLeftOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskLandscapeLeft; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation LandscapeRightOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskLandscapeRight; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation AllLandscapeOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + + +@implementation AllOrientations + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskAll; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation PortraitAndLandscapeLeftOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation PortraitAndLandscapeRightOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeRight; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation PortraitUpsideDownAndLandscapeLeftOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskLandscapeLeft; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + +@implementation PortraitUpsideDownAndLandscapeRightOnly + +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskLandscapeRight; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return [self supportedInterfaceOrientations] & (1 << interfaceOrientation) ; +} + +- (BOOL)shouldAutorotate { + return YES; +} + +@end + diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/Info.plist b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/Info.plist new file mode 100644 index 00000000..a949946d --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/Info.plist @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>en</string> + <key>CFBundleExecutable</key> + <string>$(EXECUTABLE_NAME)</string> + <key>CFBundleIdentifier</key> + <string>org.apache.cordova.$(PRODUCT_NAME:rfc1034identifier)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>$(PRODUCT_NAME)</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1</string> +</dict> +</plist> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj new file mode 100644 index 00000000..ce820d81 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj @@ -0,0 +1,505 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 7E9F51AB19DA10AE00DA31AC /* CDVSplashScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E9F51A919DA10AE00DA31AC /* CDVSplashScreen.m */; }; + 7E9F51B119DA114400DA31AC /* ImageNameTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E9F51B019DA114400DA31AC /* ImageNameTest.m */; }; + 7E9F51B319DA116500DA31AC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E9F51B219DA116500DA31AC /* Foundation.framework */; }; + 7E9F51B519DA127E00DA31AC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E9F51B419DA127E00DA31AC /* UIKit.framework */; }; + 7E9F51B819DA14FD00DA31AC /* ImageNameTestDelegates.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E9F51B719DA14FD00DA31AC /* ImageNameTestDelegates.m */; }; + 7E9F51B919DA1B1600DA31AC /* libCDVSplashScreenLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E9F519519DA102000DA31AC /* libCDVSplashScreenLib.a */; }; + 7E9F51BA19DA1B2000DA31AC /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E9F519019DA0F8300DA31AC /* libCordova.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 7E9F518F19DA0F8300DA31AC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7E9F518B19DA0F8300DA31AC /* CordovaLib.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 68A32D7114102E1C006B237C; + remoteInfo = CordovaLib; + }; + 7E9F51AC19DA10DE00DA31AC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7E9F517219DA09CE00DA31AC /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7E9F519419DA102000DA31AC; + remoteInfo = CDVSplashScreenLib; + }; + 7E9F51AE19DA10E100DA31AC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7E9F518B19DA0F8300DA31AC /* CordovaLib.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = D2AAC07D0554694100DB518D; + remoteInfo = CordovaLib; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 7E9F519319DA102000DA31AC /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 7E9F518B19DA0F8300DA31AC /* CordovaLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CordovaLib.xcodeproj; path = "../node_modules/cordova-ios/CordovaLib/CordovaLib.xcodeproj"; sourceTree = "<group>"; }; + 7E9F519519DA102000DA31AC /* libCDVSplashScreenLib.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCDVSplashScreenLib.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 7E9F519F19DA102000DA31AC /* CDVSplashScreenLibTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDVSplashScreenLibTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 7E9F51A219DA102000DA31AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; + 7E9F51A919DA10AE00DA31AC /* CDVSplashScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVSplashScreen.m; path = ../../../src/ios/CDVSplashScreen.m; sourceTree = SOURCE_ROOT; }; + 7E9F51AA19DA10AE00DA31AC /* CDVSplashScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVSplashScreen.h; path = ../../../src/ios/CDVSplashScreen.h; sourceTree = SOURCE_ROOT; }; + 7E9F51B019DA114400DA31AC /* ImageNameTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageNameTest.m; sourceTree = "<group>"; }; + 7E9F51B219DA116500DA31AC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + 7E9F51B419DA127E00DA31AC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; + 7E9F51B619DA12C600DA31AC /* ImageNameTestDelegates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageNameTestDelegates.h; sourceTree = "<group>"; }; + 7E9F51B719DA14FD00DA31AC /* ImageNameTestDelegates.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageNameTestDelegates.m; sourceTree = "<group>"; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 7E9F519219DA102000DA31AC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7E9F519C19DA102000DA31AC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 7E9F51BA19DA1B2000DA31AC /* libCordova.a in Frameworks */, + 7E9F51B919DA1B1600DA31AC /* libCDVSplashScreenLib.a in Frameworks */, + 7E9F51B519DA127E00DA31AC /* UIKit.framework in Frameworks */, + 7E9F51B319DA116500DA31AC /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7E9F517119DA09CE00DA31AC = { + isa = PBXGroup; + children = ( + 7E9F51B419DA127E00DA31AC /* UIKit.framework */, + 7E9F51B219DA116500DA31AC /* Foundation.framework */, + 7E9F518B19DA0F8300DA31AC /* CordovaLib.xcodeproj */, + 7E9F519619DA102000DA31AC /* CDVSplashScreenLib */, + 7E9F51A019DA102000DA31AC /* CDVSplashScreenLibTests */, + 7E9F517D19DA0A0A00DA31AC /* Products */, + ); + sourceTree = "<group>"; + }; + 7E9F517D19DA0A0A00DA31AC /* Products */ = { + isa = PBXGroup; + children = ( + 7E9F519519DA102000DA31AC /* libCDVSplashScreenLib.a */, + 7E9F519F19DA102000DA31AC /* CDVSplashScreenLibTests.xctest */, + ); + name = Products; + sourceTree = "<group>"; + }; + 7E9F518C19DA0F8300DA31AC /* Products */ = { + isa = PBXGroup; + children = ( + 7E9F519019DA0F8300DA31AC /* libCordova.a */, + ); + name = Products; + sourceTree = "<group>"; + }; + 7E9F519619DA102000DA31AC /* CDVSplashScreenLib */ = { + isa = PBXGroup; + children = ( + 7E9F51A919DA10AE00DA31AC /* CDVSplashScreen.m */, + 7E9F51AA19DA10AE00DA31AC /* CDVSplashScreen.h */, + ); + path = CDVSplashScreenLib; + sourceTree = SOURCE_ROOT; + }; + 7E9F51A019DA102000DA31AC /* CDVSplashScreenLibTests */ = { + isa = PBXGroup; + children = ( + 7E9F51A119DA102000DA31AC /* Supporting Files */, + 7E9F51B019DA114400DA31AC /* ImageNameTest.m */, + 7E9F51B619DA12C600DA31AC /* ImageNameTestDelegates.h */, + 7E9F51B719DA14FD00DA31AC /* ImageNameTestDelegates.m */, + ); + path = CDVSplashScreenLibTests; + sourceTree = "<group>"; + }; + 7E9F51A119DA102000DA31AC /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 7E9F51A219DA102000DA31AC /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = "<group>"; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 7E9F519419DA102000DA31AC /* CDVSplashScreenLib */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7E9F51A319DA102000DA31AC /* Build configuration list for PBXNativeTarget "CDVSplashScreenLib" */; + buildPhases = ( + 7E9F519119DA102000DA31AC /* Sources */, + 7E9F519219DA102000DA31AC /* Frameworks */, + 7E9F519319DA102000DA31AC /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CDVSplashScreenLib; + productName = CDVSplashScreenLib; + productReference = 7E9F519519DA102000DA31AC /* libCDVSplashScreenLib.a */; + productType = "com.apple.product-type.library.static"; + }; + 7E9F519E19DA102000DA31AC /* CDVSplashScreenLibTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7E9F51A619DA102000DA31AC /* Build configuration list for PBXNativeTarget "CDVSplashScreenLibTests" */; + buildPhases = ( + 7E9F519B19DA102000DA31AC /* Sources */, + 7E9F519C19DA102000DA31AC /* Frameworks */, + 7E9F519D19DA102000DA31AC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 7E9F51AF19DA10E100DA31AC /* PBXTargetDependency */, + 7E9F51AD19DA10DE00DA31AC /* PBXTargetDependency */, + ); + name = CDVSplashScreenLibTests; + productName = CDVSplashScreenLibTests; + productReference = 7E9F519F19DA102000DA31AC /* CDVSplashScreenLibTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 7E9F517219DA09CE00DA31AC /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0600; + TargetAttributes = { + 7E9F519419DA102000DA31AC = { + CreatedOnToolsVersion = 6.0; + }; + 7E9F519E19DA102000DA31AC = { + CreatedOnToolsVersion = 6.0; + }; + }; + }; + buildConfigurationList = 7E9F517519DA09CE00DA31AC /* Build configuration list for PBXProject "CDVSplashScreenTest" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 7E9F517119DA09CE00DA31AC; + productRefGroup = 7E9F517D19DA0A0A00DA31AC /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 7E9F518C19DA0F8300DA31AC /* Products */; + ProjectRef = 7E9F518B19DA0F8300DA31AC /* CordovaLib.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + 7E9F519419DA102000DA31AC /* CDVSplashScreenLib */, + 7E9F519E19DA102000DA31AC /* CDVSplashScreenLibTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + 7E9F519019DA0F8300DA31AC /* libCordova.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libCordova.a; + remoteRef = 7E9F518F19DA0F8300DA31AC /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + 7E9F519D19DA102000DA31AC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 7E9F519119DA102000DA31AC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7E9F51AB19DA10AE00DA31AC /* CDVSplashScreen.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7E9F519B19DA102000DA31AC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7E9F51B119DA114400DA31AC /* ImageNameTest.m in Sources */, + 7E9F51B819DA14FD00DA31AC /* ImageNameTestDelegates.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 7E9F51AD19DA10DE00DA31AC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7E9F519419DA102000DA31AC /* CDVSplashScreenLib */; + targetProxy = 7E9F51AC19DA10DE00DA31AC /* PBXContainerItemProxy */; + }; + 7E9F51AF19DA10E100DA31AC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = CordovaLib; + targetProxy = 7E9F51AE19DA10E100DA31AC /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 7E9F517619DA09CE00DA31AC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 7E9F517719DA09CE00DA31AC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; + 7E9F51A419DA102000DA31AC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"$(TARGET_BUILD_DIR)/usr/local/lib/include\"", + "\"$(OBJROOT)/UninstalledProducts/include\"", + "\"$(BUILT_PRODUCTS_DIR)\"", + ); + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 7E9F51A519DA102000DA31AC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"$(TARGET_BUILD_DIR)/usr/local/lib/include\"", + "\n\"$(OBJROOT)/UninstalledProducts/include\"\n\"$(BUILT_PRODUCTS_DIR)\"", + ); + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 7E9F51A719DA102000DA31AC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = CDVSplashScreenLibTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 7E9F51A819DA102000DA31AC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = CDVSplashScreenLibTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 7E9F517519DA09CE00DA31AC /* Build configuration list for PBXProject "CDVSplashScreenTest" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7E9F517619DA09CE00DA31AC /* Debug */, + 7E9F517719DA09CE00DA31AC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7E9F51A319DA102000DA31AC /* Build configuration list for PBXNativeTarget "CDVSplashScreenLib" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7E9F51A419DA102000DA31AC /* Debug */, + 7E9F51A519DA102000DA31AC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7E9F51A619DA102000DA31AC /* Build configuration list for PBXNativeTarget "CDVSplashScreenLibTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7E9F51A719DA102000DA31AC /* Debug */, + 7E9F51A819DA102000DA31AC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 7E9F517219DA09CE00DA31AC /* Project object */; +} diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..8f912784 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Workspace + version = "1.0"> + <FileRef + location = "self:CDVSplashScreenTest.xcodeproj"> + </FileRef> +</Workspace> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.xcworkspace/xcshareddata/CDVSplashScreenTest.xccheckout b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.xcworkspace/xcshareddata/CDVSplashScreenTest.xccheckout new file mode 100644 index 00000000..7e4cdb93 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.xcworkspace/xcshareddata/CDVSplashScreenTest.xccheckout @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>IDESourceControlProjectFavoriteDictionaryKey</key> + <false/> + <key>IDESourceControlProjectIdentifier</key> + <string>6BE9AD73-1B9F-4362-98D7-DC631BEC6185</string> + <key>IDESourceControlProjectName</key> + <string>CDVSplashScreenTest</string> + <key>IDESourceControlProjectOriginsDictionary</key> + <dict> + <key>BEF5A5D0FF64801E558286389440357A9233D7DB</key> + <string>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</string> + </dict> + <key>IDESourceControlProjectPath</key> + <string>tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj</string> + <key>IDESourceControlProjectRelativeInstallPathDictionary</key> + <dict> + <key>BEF5A5D0FF64801E558286389440357A9233D7DB</key> + <string>../../../../..</string> + </dict> + <key>IDESourceControlProjectURL</key> + <string>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</string> + <key>IDESourceControlProjectVersion</key> + <integer>111</integer> + <key>IDESourceControlProjectWCCIdentifier</key> + <string>BEF5A5D0FF64801E558286389440357A9233D7DB</string> + <key>IDESourceControlProjectWCConfigurations</key> + <array> + <dict> + <key>IDESourceControlRepositoryExtensionIdentifierKey</key> + <string>public.vcs.git</string> + <key>IDESourceControlWCCIdentifierKey</key> + <string>BEF5A5D0FF64801E558286389440357A9233D7DB</string> + <key>IDESourceControlWCCName</key> + <string>cordova-plugin-splashscreen</string> + </dict> + </array> +</dict> +</plist> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcshareddata/xcschemes/CDVSplashScreenLib.xcscheme b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcshareddata/xcschemes/CDVSplashScreenLib.xcscheme new file mode 100644 index 00000000..b97b8633 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcshareddata/xcschemes/CDVSplashScreenLib.xcscheme @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "0600" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "YES" + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519419DA102000DA31AC" + BuildableName = "libCDVSplashScreenLib.a" + BlueprintName = "CDVSplashScreenLib" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES" + buildConfiguration = "Debug"> + <Testables> + </Testables> + </TestAction> + <LaunchAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + allowLocationSimulation = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519419DA102000DA31AC" + BuildableName = "libCDVSplashScreenLib.a" + BlueprintName = "CDVSplashScreenLib" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </MacroExpansion> + <AdditionalOptions> + </AdditionalOptions> + </LaunchAction> + <ProfileAction + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Release" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519419DA102000DA31AC" + BuildableName = "libCDVSplashScreenLib.a" + BlueprintName = "CDVSplashScreenLib" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcshareddata/xcschemes/CDVSplashScreenLibTests.xcscheme b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcshareddata/xcschemes/CDVSplashScreenLibTests.xcscheme new file mode 100644 index 00000000..6a2a5261 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcshareddata/xcschemes/CDVSplashScreenLibTests.xcscheme @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "0600" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "NO" + buildForArchiving = "NO" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519E19DA102000DA31AC" + BuildableName = "CDVSplashScreenLibTests.xctest" + BlueprintName = "CDVSplashScreenLibTests" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES" + buildConfiguration = "Debug"> + <Testables> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519E19DA102000DA31AC" + BuildableName = "CDVSplashScreenLibTests.xctest" + BlueprintName = "CDVSplashScreenLibTests" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </TestableReference> + </Testables> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519E19DA102000DA31AC" + BuildableName = "CDVSplashScreenLibTests.xctest" + BlueprintName = "CDVSplashScreenLibTests" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </MacroExpansion> + </TestAction> + <LaunchAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + allowLocationSimulation = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519E19DA102000DA31AC" + BuildableName = "CDVSplashScreenLibTests.xctest" + BlueprintName = "CDVSplashScreenLibTests" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </MacroExpansion> + <AdditionalOptions> + </AdditionalOptions> + </LaunchAction> + <ProfileAction + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Release" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "7E9F519E19DA102000DA31AC" + BuildableName = "CDVSplashScreenLibTests.xctest" + BlueprintName = "CDVSplashScreenLibTests" + ReferencedContainer = "container:CDVSplashScreenTest.xcodeproj"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/README.md b/plugins/org.apache.cordova.splashscreen/tests/ios/README.md new file mode 100644 index 00000000..b6bf31b2 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/README.md @@ -0,0 +1,21 @@ +# iOS Tests for CDVSplashScreen + +You need to install `node.js` to pull in `cordova-ios`. + +First install cordova-ios: + + npm install + +... in the current folder. + + +# Testing from Xcode + +1. Launch the `CDVSplashScreenTest.xcworkspace` file. +2. Choose "CDVSplashScreenLibTests" from the scheme drop-down menu +3. Click and hold on the `Play` button, and choose the `Wrench` icon to run the tests + + +# Testing from the command line + + npm test diff --git a/plugins/org.apache.cordova.splashscreen/tests/ios/package.json b/plugins/org.apache.cordova.splashscreen/tests/ios/package.json new file mode 100644 index 00000000..ca5db593 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/ios/package.json @@ -0,0 +1,13 @@ +{ + "name": "cordova-plugin-splashscreen-test-ios", + "version": "1.0.0", + "description": "iOS Unit Tests for Splashscreen Plugin", + "author": "Apache Software Foundation", + "license": "Apache Version 2.0", + "dependencies": { + "cordova-ios": "^3.6.0" + }, + "scripts": { + "test": "xcodebuild -scheme CordovaLib && xcodebuild test -scheme CDVSplashScreenLibTests -destination 'platform=iOS Simulator,name=iPhone 5'" + } +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.splashscreen/tests/plugin.xml b/plugins/org.apache.cordova.splashscreen/tests/plugin.xml new file mode 100644 index 00000000..008a851f --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/plugin.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + id="org.apache.cordova.splashscreen.tests" + version="0.4.0"> + <name>Cordova Splashscreen Plugin Tests</name> + <license>Apache 2.0</license> + + <js-module src="tests.js" name="tests"> + </js-module> +</plugin> diff --git a/plugins/org.apache.cordova.splashscreen/tests/tests.js b/plugins/org.apache.cordova.splashscreen/tests/tests.js new file mode 100644 index 00000000..8c4d22b4 --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/tests/tests.js @@ -0,0 +1,62 @@ +/* + * + * 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. + * +*/ + +exports.defineAutoTest = function () { + describe('Splashscreen (cordova)', function () { + it("splashscreen.spec.1 should exist", function () { + expect(navigator.splashscreen).toBeDefined(); + }); + + it("splashscreen.spec.2 exec method should exist", function () { + expect(navigator.splashscreen.show).toBeDefined(); + expect(typeof navigator.splashscreen.show).toBe('function'); + }); + + it("splashscreen.spec.3 exec method should exist", function () { + expect(navigator.splashscreen.hide).toBeDefined(); + expect(typeof navigator.splashscreen.hide).toBe('function'); + }); + }); +}; + +exports.defineManualTests = function (contentEl, createActionButton) { + function showFor(duration) { + navigator.splashscreen.show(); + window.setTimeout(function () { + navigator.splashscreen.hide(); + }, 1000 * duration); + } + + contentEl.innerHTML = '<h1>Splashscreen Tests</h1>' + + '<h3>Note for WP: AutoHideSplashScreen must be set to false in config.xml</h3>' + + '<div id="show1"></div>' + + 'Expected result: Will show the Cordova splashscreen for 1 second' + + '</p> <div id="show5"></div>' + + 'Expected result: Will show the Cordova splashscreen for 5 seconds'; + + createActionButton('Show for 1 second', function () { + showFor(1); + }, 'show1'); + + createActionButton('Show for 5 seconds', function () { + showFor(5); + }, 'show5'); +}; diff --git a/plugins/org.apache.cordova.splashscreen/www/splashscreen.js b/plugins/org.apache.cordova.splashscreen/www/splashscreen.js new file mode 100644 index 00000000..7cb48bdd --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/www/splashscreen.js @@ -0,0 +1,33 @@ +/* + * + * 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 exec = require('cordova/exec'); + +var splashscreen = { + show:function() { + exec(null, null, "SplashScreen", "show", []); + }, + hide:function() { + exec(null, null, "SplashScreen", "hide", []); + } +}; + +module.exports = splashscreen; diff --git a/plugins/org.apache.cordova.splashscreen/www/windows8/SplashScreenProxy.js b/plugins/org.apache.cordova.splashscreen/www/windows8/SplashScreenProxy.js new file mode 100644 index 00000000..42068ddf --- /dev/null +++ b/plugins/org.apache.cordova.splashscreen/www/windows8/SplashScreenProxy.js @@ -0,0 +1,106 @@ +/* + * + * 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. + * +*/ + +/*jslint sloppy:true */ +/*global Windows:true, require, module, window, document, WinJS */ + +var cordova = require('cordova'), + channel = require('cordova/channel'); + +/* This is the actual implementation part that returns the result on Windows 8 +*/ + +var position = { x: 0, y: 0, width: 0, height: 0 }; // defined by evt.detail.splashScreen.imageLocation +var splash = null; // +var localSplash; // the image to display +var localSplashImage; +var bgColor = "#464646"; + + + +function updateImageLocation() { + localSplash.style.width = window.innerWidth + "px"; + localSplash.style.height = window.innerHeight + "px"; + localSplash.style.top = "0px"; + localSplash.style.left = "0px"; + + localSplashImage.style.top = position.y + "px"; + localSplashImage.style.left = position.x + "px"; + localSplashImage.style.height = position.height + "px"; + localSplashImage.style.width = position.width + "px"; +} + +function onResize(evt) { + if (splash) { + position = splash.imageLocation; + updateImageLocation(); + } +} + +var SplashScreen = { + setBGColor: function (cssBGColor) { + bgColor = cssBGColor; + if (localSplash) { + localSplash.style.backgroundColor = bgColor; + } + }, + show: function () { + window.addEventListener("resize", onResize, false); + localSplash = document.createElement("div"); + localSplash.style.backgroundColor = bgColor; + localSplash.style.position = "absolute"; + + localSplashImage = document.createElement("img"); + localSplashImage.src = "ms-appx:///images/splashscreen.png"; + localSplashImage.style.position = "absolute"; + + updateImageLocation(); + + localSplash.appendChild(localSplashImage); + document.body.appendChild(localSplash); + }, + hide: function () { + window.removeEventListener("resize", onResize, false); + document.body.removeChild(localSplash); + localSplash = null; + } +}; + +module.exports = SplashScreen; + +function activated(evt) { + if (evt.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { + splash = evt.detail.splashScreen; + position = evt.detail.splashScreen.imageLocation; + } +} + + + + +channel.onCordovaReady.subscribe(function (evt) { + document.addEventListener("DOMContentLoaded", function (evt) { + WinJS.Application.addEventListener("activated", activated, false); + }, false); +}); + +require("cordova/exec/proxy").add("SplashScreen", SplashScreen); + diff --git a/plugins/org.apache.cordova.statusbar/CONTRIBUTING.md b/plugins/org.apache.cordova.statusbar/CONTRIBUTING.md new file mode 100644 index 00000000..f7dbcaba --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/CONTRIBUTING.md @@ -0,0 +1,37 @@ +<!-- +# +# 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. +# +--> + +# Contributing to Apache Cordova + +Anyone can contribute to Cordova. And we need your contributions. + +There are multiple ways to contribute: report bugs, improve the docs, and +contribute code. + +For instructions on this, start with the +[contribution overview](http://cordova.apache.org/#contribute). + +The details are explained there, but the important items are: + - Sign and submit an Apache ICLA (Contributor License Agreement). + - Have a Jira issue open that corresponds to your contribution. + - Run the tests so your patch doesn't break existing functionality. + +We look forward to your contributions! diff --git a/plugins/org.apache.cordova.statusbar/LICENSE b/plugins/org.apache.cordova.statusbar/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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.
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/NOTICE b/plugins/org.apache.cordova.statusbar/NOTICE new file mode 100644 index 00000000..8ec56a52 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/NOTICE @@ -0,0 +1,5 @@ +Apache Cordova +Copyright 2012 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/plugins/org.apache.cordova.statusbar/README.md b/plugins/org.apache.cordova.statusbar/README.md new file mode 100644 index 00000000..8b91de98 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/README.md @@ -0,0 +1,22 @@ +<!--- + license: 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. +--> + +# org.apache.cordova.statusbar + +Plugin documentation: [doc/index.md](doc/index.md)
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/RELEASENOTES.md b/plugins/org.apache.cordova.statusbar/RELEASENOTES.md new file mode 100644 index 00000000..1dc12e11 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/RELEASENOTES.md @@ -0,0 +1,68 @@ +<!-- +# +# 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. +# +--> +# Release Notes + +### 0.1.5 (Apr 17, 2014) (First release as a core Cordova Plugin) +* CB-6316: Added README.md which point to the new location for docs +* CB-6316: Added license header to the documentation. Added README.md which point to the new location for docs +* CB-6316: Moved StatusBar plugin documentation to docs folder +* CB-6314: [android] Add StatusBar.isVisible support to Android +* CB-6460: Update license headers + +### 0.1.6 (Jun 05, 2014) +* CB-6783 - added StatusBarStyle config preference, updated docs (closes #9) +* CB-6812 Add license +* CB-6491 add CONTRIBUTING.md +* CB-6264 minor formatting issue +* Update docs with recent WP changes, remove 'clear' from the loist of named colors in documentation +* CB-6513 - Statusbar plugin for Android is not compiling + +### 0.1.7 (Aug 06, 2014) +* Add LICENSE and NOTICE +* Update statusbar.js +* Update backgroundColorByHexString function +* ios: Use a persistent callbackId instead of calling sendJs +* CB-6626 ios: Add a JS event for tapping on statusbar +* ios: Fix hide to adjust webview's frame only when status bar is not overlaying webview +* CB-6127 Updated translations for docs +* android: Fix StatusBar.initialize() not running on UI thread + +### 0.1.8 (Sep 17, 2014) +* CB-7549 [StatusBar][iOS 8] Landscape issue +* CB-7486 Remove StatusBarBackgroundColor intial preference (black background) so background will be initially transparent +* Renamed test dir, added nested plugin.xml +* added documentation for manual tests, moved background color test below overlay test +* CB-7195 ported statusbar tests to framework + +### 0.1.9 (Dec 02, 2014) +* Fix onload attribute within <feature> to be a <param> +* CB-8010 - Statusbar colour does not change to orange +* added checks for running on windows when StatusBar is NOT available +* CB-7986 Add cordova-plugin-statusbar support for **Windows Phone 8.1** +* CB-7977 Mention `deviceready` in plugin docs +* CB-7979 Each plugin doc should have a ## Installation section +* Inserting leading space after # for consistency +* CB-7549 - (Re-fix) `StatusBar` **iOS 8** Landscape issue (closes #15) +* CB-7700 cordova-plugin-statusbar documentation translation: cordova-plugin-statusbar +* CB-7571 Bump version of nested plugin to match parent plugin + +### 0.1.10 (Feb 04, 2015) +* CB-8351 ios: Use argumentForIndex rather than NSArray extension diff --git a/plugins/org.apache.cordova.statusbar/doc/de/index.md b/plugins/org.apache.cordova.statusbar/doc/de/index.md new file mode 100644 index 00000000..1c0ff3ce --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/de/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> Das `StatusBar` Objekt stellt einige Funktionen zum Anpassen des iOS und Android StatusBar. + +## "Einstellungen" + +#### config.xml + +* **StatusBarOverlaysWebView** (Boolean, der Standardwert ist True). Stellen Sie auf iOS 7 die Statusbar-Overlay oder keine Überlagerung der WebView beim Start. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (Farbe hex String, der Standardwert ist #000000). Legen Sie auf iOS 7 die Hintergrundfarbe der Statusbar von eine hexadezimale Zeichenfolge (#RRGGBB) beim Start. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (Status Bar-Stil, der Standardwert ist Lightcontent). Legen Sie auf iOS 7 den Status-Bar-Stil. Verfügbaren Optionen Standard, Lightcontent, Blacktranslucent, Blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## Beim Start ausblenden + +Während der Laufzeit können Sie die StatusBar.hide-Funktion unten, aber die StatusBar beim Start der app versteckt werden soll, müssen Sie Ihre app Info.plist Datei ändern. + +Diese beiden Attribute hinzufügen/bearbeiten, wenn nicht vorhanden. Legen Sie **"Statusleiste ist anfangs ausgeblendet"** auf **"YES"** und **"View Controller-basierte Status Bar aussehen"** auf **"NO"**. Wenn Sie es manuell ohne Xcode bearbeiten, werden die Schlüssel und Werte: + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## Methoden + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## Eigenschaften + +* StatusBar.isVisible + +## Berechtigungen + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +Stellen Sie auf iOS 7 Statusbar überlagern oder nicht überlagert die WebView. + + StatusBar.overlaysWebView(true); + + +## Beschreibung + +Auf iOS 7 zu der Statusbar wie iOS 6 erscheinen auf False festgelegt. Legen Sie die Stil und Hintergrund Farbe entsprechend mit den anderen Funktionen. + +## Unterstützte Plattformen + +* iOS + +## Kurzes Beispiel + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +Verwenden Sie die Standard-Statusbar (dunkle Text, für helle Hintergründe). + + StatusBar.styleDefault(); + + +## Unterstützte Plattformen + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +Verwenden Sie die LightContent-Statusbar (heller Text, für dunkle Hintergründe). + + StatusBar.styleLightContent(); + + +## Unterstützte Plattformen + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +Verwenden Sie die BlackTranslucent-Statusbar (heller Text, für dunkle Hintergründe). + + StatusBar.styleBlackTranslucent(); + + +## Unterstützte Plattformen + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +Verwenden Sie die BlackOpaque-Statusbar (heller Text, für dunkle Hintergründe). + + StatusBar.styleBlackOpaque(); + + +## Unterstützte Plattformen + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +Auf iOS 7 Wenn Sie StatusBar.statusBarOverlaysWebView auf False festlegen, können Sie die Hintergrundfarbe der Statusbar von Farbnamen festlegen. + + StatusBar.backgroundColorByName("red"); + + +Unterstützte Farbnamen sind: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## Unterstützte Plattformen + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +Legt die Hintergrundfarbe der Statusbar von eine hexadezimale Zeichenfolge fest. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +CSS-Kurzschrift-Eigenschaften werden ebenfalls unterstützt. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +Auf iOS 7 Wenn Sie StatusBar.statusBarOverlaysWebView auf False festlegen, können Sie die Hintergrundfarbe der Statusbar von eine hexadezimale Zeichenfolge (#RRGGBB) festlegen. + +Auf WP7 und WP8 können Sie auch Werte wie #AARRGGBB, angeben wo AA einen alpha-Wert ist + +## Unterstützte Plattformen + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +Ausblenden der Statusleiste. + + StatusBar.hide(); + + +## Unterstützte Plattformen + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +Zeigt die Statusleiste. + + StatusBar.show(); + + +## Unterstützte Plattformen + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +Lesen Sie diese Eigenschaft, um festzustellen, ob die Statusbar sichtbar oder nicht ist. + + if (StatusBar.isVisible) { + // do something + } + + +## Unterstützte Plattformen + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/es/index.md b/plugins/org.apache.cordova.statusbar/doc/es/index.md new file mode 100644 index 00000000..13a7230f --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/es/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> El `StatusBar` objeto proporciona algunas funciones para personalizar el iOS y Android StatusBar. + +## Preferencias + +#### config.xml + +* **StatusBarOverlaysWebView** (boolean, true por defecto). En iOS 7, hacer la superposición statusbar o no superponer la WebView al inicio. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (cadena hexadecimal color, #000000 por defecto). En iOS 7, establecer el color de fondo de la barra de estado por una cadena hexadecimal (#RRGGBB) en el arranque. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (status bar estilo por defecto lightcontent). En iOS 7, definir el estilo de barra de estado. Por defecto las opciones disponibles, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## Escondido en el arranque + +Durante el tiempo de ejecución puede utilizar la función StatusBar.hide abajo, pero si quieres la barra de estado que está escondido en el inicio de la aplicación, se debe modificar el archivo Info.plist de su aplicación. + +Agregar/editar estos dos atributos si no está presente. Defina **"inicialmente se esconde la barra de estado"** a **"YES"** y **"Aparición de vista basado en controlador estatus bar"** a **"NO"**. Si se edita manualmente sin Xcode, las claves y valores son: + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## Métodos + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## Propiedades + +* StatusBar.isVisible + +## Permisos + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +En iOS 7, hacer la barra de estado superposición o no superponer la vista Web. + + StatusBar.overlaysWebView(true); + + +## Descripción + +En iOS 7, establecida en false para que la barra de estado aparezca como iOS 6. Establece el color de fondo y estilo para utilizar las otras funciones. + +## Plataformas soportadas + +* iOS + +## Ejemplo rápido + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +Utilice la barra de estado por defecto (texto oscuro, para fondos de luz). + + StatusBar.styleDefault(); + + +## Plataformas soportadas + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +Utilice la barra de estado lightContent (texto ligero, para fondos oscuros). + + StatusBar.styleLightContent(); + + +## Plataformas soportadas + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +Utilice la barra de estado blackTranslucent (texto ligero, para fondos oscuros). + + StatusBar.styleBlackTranslucent(); + + +## Plataformas soportadas + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +Utilice la barra de estado blackOpaque (texto ligero, para fondos oscuros). + + StatusBar.styleBlackOpaque(); + + +## Plataformas soportadas + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +En iOS 7, al establecer StatusBar.statusBarOverlaysWebView a false, se puede establecer el color de fondo de la barra de estado nombre del color. + + StatusBar.backgroundColorByName("red"); + + +Nombres de los colores admitidos son: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## Plataformas soportadas + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +Establece el color de fondo de la barra de estado por una cadena hexadecimal. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +Propiedades CSS abreviada también son compatibles. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +En iOS 7, cuando se establece StatusBar.statusBarOverlaysWebView en false, se puede establecer el color de fondo de la barra de estado una cadena hexadecimal (#RRGGBB). + +En WP7 y WP8 también puede especificar valores como #AARRGGBB, donde AA es un valor alfa + +## Plataformas soportadas + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +Ocultar la barra de estado. + + StatusBar.hide(); + + +## Plataformas soportadas + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +Muestra la barra de estado. + + StatusBar.show(); + + +## Plataformas soportadas + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +Lea esta propiedad para ver si la barra de estado es visible o no. + + if (StatusBar.isVisible) { + // do something + } + + +## Plataformas soportadas + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/fr/index.md b/plugins/org.apache.cordova.statusbar/doc/fr/index.md new file mode 100644 index 00000000..28e4e103 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/fr/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> Le `StatusBar` objet fournit quelques fonctions pour personnaliser les iOS et Android StatusBar. + +## Préférences + +#### config.xml + +* **StatusBarOverlaysWebView** (boolean, la valeur par défaut true). Sur iOS 7, faire la superposition de statusbar ou pas superposition le WebView au démarrage. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (chaîne hexadécimale de couleur, par défaut, #000000). Sur iOS 7, définir la couleur d'arrière-plan de la barre d'État par une chaîne hexadécimale (#RRGGBB) au démarrage. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (style de barre de statut, par défaut, lightcontent). Sur iOS 7, définir le style de barre de statut. Par défaut les options disponibles, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## Cacher au démarrage + +Pendant l'exécution, vous pouvez utiliser la fonction StatusBar.hide en bas, mais si vous souhaitez que la barre d'État pour être caché au démarrage de l'application, vous devez modifier le fichier Info.plist de votre application. + +Ajouter/modifier ces deux attributs si n'est pas présent. **"Barre d'État est initialement masqué"** la valeur **"** Yes" et **"À l'apparence vue sur contrôleur statut bar"** la valeur **"Non"**. Si vous modifiez manuellement sans Xcode, les clés et les valeurs sont : + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## Méthodes + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## Propriétés + +* StatusBar.isVisible + +## Autorisations + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +Sur iOS 7, faire la statusbar superposition ou pas superposer le WebView. + + StatusBar.overlaysWebView(true); + + +## Description + +Sur iOS 7, la valeur false pour afficher la barre d'État comme iOS 6. Définissez la couleur de style et d'arrière-plan en fonction de l'utilisation des autres fonctions. + +## Plates-formes prises en charge + +* iOS + +## Petit exemple + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +Utilisez la barre de statut par défaut (texte sombre, pour les arrière-plans lumineux). + + StatusBar.styleDefault() ; + + +## Plates-formes prises en charge + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +Utilisez la barre d'État lightContent (texte clair, des arrière-plans sombres). + + StatusBar.styleLightContent(); + + +## Plates-formes prises en charge + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +Utilisez la barre d'État blackTranslucent (texte clair, des arrière-plans sombres). + + StatusBar.styleBlackTranslucent(); + + +## Plates-formes prises en charge + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +Utilisez la barre d'État blackOpaque (texte clair, des arrière-plans sombres). + + StatusBar.styleBlackOpaque(); + + +## Plates-formes prises en charge + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +Sur iOS 7, lorsque vous définissez StatusBar.statusBarOverlaysWebView sur false, vous pouvez définir la couleur d'arrière-plan de la barre d'État par nom de couleur. + + StatusBar.backgroundColorByName("red"); + + +Les noms de couleurs prises en charge sont : + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## Plates-formes prises en charge + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +Définit la couleur d'arrière-plan de la barre d'État par une chaîne hexadécimale. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +Propriétés de raccourci CSS sont également pris en charge. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +Sur iOS 7, lorsque vous définissez StatusBar.statusBarOverlaysWebView sur false, vous pouvez définir la couleur d'arrière-plan de la barre d'État par une chaîne hexadécimale (#RRGGBB). + +Sur WP7 et WP8, vous pouvez également spécifier des valeurs comme #AARRGGBB, où AA représente une valeur alpha + +## Plates-formes prises en charge + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +Masquer la barre d'État. + + StatusBar.hide(); + + +## Plates-formes prises en charge + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +Affiche la barre d'État. + + StatusBar.show(); + + +## Plates-formes prises en charge + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +Lire cette propriété afin de voir si la barre d'État est visible ou non. + + if (StatusBar.isVisible) { + // do something + } + + +## Plates-formes prises en charge + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/index.md b/plugins/org.apache.cordova.statusbar/doc/index.md new file mode 100644 index 00000000..9955857a --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/index.md @@ -0,0 +1,284 @@ +<!--- + 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. +--> +# org.apache.cordova.statusbar + +StatusBar +====== + +> The `StatusBar` object provides some functions to customize the iOS and Android StatusBar. + + +## Installation + + cordova plugin add org.apache.cordova.statusbar + +Preferences +----------- + +#### config.xml + +- __StatusBarOverlaysWebView__ (boolean, defaults to true). On iOS 7, make the statusbar overlay or not overlay the WebView at startup. + + <preference name="StatusBarOverlaysWebView" value="true" /> + +- __StatusBarBackgroundColor__ (color hex string, defaults to #000000). On iOS 7, set the background color of the statusbar by a hex string (#RRGGBB) at startup. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + +- __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + +Hiding at startup +----------- + +During runtime you can use the StatusBar.hide function below, but if you want the StatusBar to be hidden at app startup, you must modify your app's Info.plist file. + +Add/edit these two attributes if not present. Set **"Status bar is initially hidden"** to **"YES"** and set **"View controller-based status bar appearance"** to **"NO"**. If you edit it manually without Xcode, the keys and values are: + + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +Methods +------- +This plugin defines global `StatusBar` object. + +Although in the global scope, it is not available until after the `deviceready` event. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(StatusBar); + } + +- StatusBar.overlaysWebView +- StatusBar.styleDefault +- StatusBar.styleLightContent +- StatusBar.styleBlackTranslucent +- StatusBar.styleBlackOpaque +- StatusBar.backgroundColorByName +- StatusBar.backgroundColorByHexString +- StatusBar.hide +- StatusBar.show + +Properties +-------- + +- StatusBar.isVisible + +Permissions +----------- + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + +StatusBar.overlaysWebView +================= + +On iOS 7, make the statusbar overlay or not overlay the WebView. + + StatusBar.overlaysWebView(true); + +Description +----------- + +On iOS 7, set to false to make the statusbar appear like iOS 6. Set the style and background color to suit using the other functions. + + +Supported Platforms +------------------- + +- iOS + +Quick Example +------------- + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + +StatusBar.styleDefault +================= + +Use the default statusbar (dark text, for light backgrounds). + + StatusBar.styleDefault(); + + +Supported Platforms +------------------- + +- iOS +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + +StatusBar.styleLightContent +================= + +Use the lightContent statusbar (light text, for dark backgrounds). + + StatusBar.styleLightContent(); + + +Supported Platforms +------------------- + +- iOS +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + +StatusBar.styleBlackTranslucent +================= + +Use the blackTranslucent statusbar (light text, for dark backgrounds). + + StatusBar.styleBlackTranslucent(); + + +Supported Platforms +------------------- + +- iOS +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + +StatusBar.styleBlackOpaque +================= + +Use the blackOpaque statusbar (light text, for dark backgrounds). + + StatusBar.styleBlackOpaque(); + + +Supported Platforms +------------------- + +- iOS +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + + +StatusBar.backgroundColorByName +================= + +On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by color name. + + StatusBar.backgroundColorByName("red"); + +Supported color names are: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +Supported Platforms +------------------- + +- iOS +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + +StatusBar.backgroundColorByHexString +================= + +Sets the background color of the statusbar by a hex string. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + +CSS shorthand properties are also supported. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + +On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by a hex string (#RRGGBB). + +On WP7 and WP8 you can also specify values as #AARRGGBB, where AA is an alpha value + +Supported Platforms +------------------- + +- iOS +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + +StatusBar.hide +================= + +Hide the statusbar. + + StatusBar.hide(); + + +Supported Platforms +------------------- + +- iOS +- Android +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + +StatusBar.show +================= + +Shows the statusbar. + + StatusBar.show(); + + +Supported Platforms +------------------- + +- iOS +- Android +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + + +StatusBar.isVisible +================= + +Read this property to see if the statusbar is visible or not. + + if (StatusBar.isVisible) { + // do something + } + + +Supported Platforms +------------------- + +- iOS +- Android +- Windows Phone 7 +- Windows Phone 8 +- Windows Phone 8.1 + + diff --git a/plugins/org.apache.cordova.statusbar/doc/it/index.md b/plugins/org.apache.cordova.statusbar/doc/it/index.md new file mode 100644 index 00000000..b40bcf5f --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/it/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> Il `StatusBar` oggetto fornisce alcune funzioni per personalizzare l'iOS e Android StatusBar. + +## Preferenze + +#### config.xml + +* **StatusBarOverlaysWebView** (boolean, default è true). IOS 7, rendono la statusbar sovrapposizione o la non sovrapposizione WebView all'avvio. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (stringa esadecimale colore, predefinito è #000000). IOS 7, impostare il colore di sfondo della barra di stato di una stringa esadecimale (#RRGGBB) all'avvio. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (status bar in stile, default è lightcontent). IOS 7, impostare lo stile di barra di stato. Predefinita di opzioni disponibili, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## Nascondendo all'avvio + +In fase di esecuzione è possibile utilizzare la funzione di StatusBar.hide qui sotto, ma se si desidera che la barra di stato venga nascosta all'avvio di app, è necessario modificare il file info. plist dell'app. + +Aggiungere o modificare questi due attributi, se non presente. Impostare la **"barra di stato è inizialmente nascosto"** a **"YES"** e **"Aspetto di vista basati su controller status bar"** a **"NO"**. Se si modifica manualmente senza Xcode, le chiavi e i valori sono: + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## Metodi + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## Proprietà + +* StatusBar.isVisible + +## Autorizzazioni + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +IOS 7, rendono la statusbar sovrapposizione o non sovrapporre WebView. + + StatusBar.overlaysWebView(true); + + +## Descrizione + +IOS 7, impostato su false per rendere la barra di stato vengono visualizzati come iOS 6. Impostare il colore di sfondo e stile per soddisfare utilizzando altre funzioni. + +## Piattaforme supportate + +* iOS + +## Esempio rapido + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +Utilizzare la barra di stato predefinito (testo scuro, per sfondi di luce). + + StatusBar.styleDefault(); + + +## Piattaforme supportate + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +Utilizzare la barra di stato lightContent (testo in chiaro, per sfondi scuri). + + StatusBar.styleLightContent(); + + +## Piattaforme supportate + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +Utilizzare la barra di stato blackTranslucent (testo in chiaro, per sfondi scuri). + + StatusBar.styleBlackTranslucent(); + + +## Piattaforme supportate + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +Utilizzare la barra di stato blackOpaque (testo in chiaro, per sfondi scuri). + + StatusBar.styleBlackOpaque(); + + +## Piattaforme supportate + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +IOS 7, quando StatusBar.statusBarOverlaysWebView è impostata su false, è possibile impostare il colore di sfondo della barra di stato con il nome di colore. + + StatusBar.backgroundColorByName("red"); + + +Nomi di colore supportati sono: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## Piattaforme supportate + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +Imposta il colore di sfondo della barra di stato di una stringa esadecimale. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +Proprietà di scrittura stenografica CSS sono supportati anche. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +IOS 7, quando StatusBar.statusBarOverlaysWebView è impostata su false, è possibile impostare il colore di sfondo della barra di stato di una stringa esadecimale (#RRGGBB). + +Su WP7 e WP8 è inoltre possibile specificare i valori come #AARRGGBB, dove AA è un valore alfa + +## Piattaforme supportate + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +Nascondere la barra di stato. + + StatusBar.hide(); + + +## Piattaforme supportate + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +Mostra la barra di stato. + + StatusBar.show(); + + +## Piattaforme supportate + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +Leggere questa proprietà per vedere se la barra di stato è visibile o no. + + if (StatusBar.isVisible) { + // do something + } + + +## Piattaforme supportate + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/ja/index.md b/plugins/org.apache.cordova.statusbar/doc/ja/index.md new file mode 100644 index 00000000..7d6b976b --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/ja/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> `StatusBar`オブジェクトã¯ã€iOS 㨠Android ステータス ãƒãƒ¼ã‚’カスタマイズã™ã‚‹ã„ãã¤ã‹ã®æ©Ÿèƒ½ã‚’æä¾›ã—ã¾ã™ã€‚ + +## 基本è¨å®š + +#### config.xml + +* **StatusBarOverlaysWebView**(ブール値ã€ãƒ‡ãƒ•ォルト㯠true)。IOS 7ã€èµ·å‹•時ã«ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ãƒãƒ¼ オーãƒãƒ¼ãƒ¬ã‚¤ã¾ãŸã¯ãªã„オーãƒãƒ¼ãƒ¬ã‚¤ã€WebView を作る。 + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor**(色 16 進文å—列ã€ãƒ‡ãƒ•ォルト㯠# 000000)。Ios 7ã€èµ·å‹•時㫠16 進文å—列 (#RRGGBB) ã§ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ ãƒãƒ¼ã®èƒŒæ™¯è‰²ã‚’è¨å®šã—ã¾ã™ã€‚ + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle**(ステータス ãƒãƒ¼ã®ã‚¹ã‚¿ã‚¤ãƒ«ã€æ—¢å®šå€¤ã¯ lightcontent)。Ios 7ã€ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ ãƒãƒ¼ã®ã‚¹ã‚¿ã‚¤ãƒ«ã‚’è¨å®šã—ã¾ã™ã€‚使用å¯èƒ½ãªã‚ªãƒ—ションã®ãƒ‡ãƒ•ォルトã€lightcontentã€blacktranslucentã€blackopaque。 + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## 起動時ã«éžè¡¨ç¤º + +実行時ã«ä¸‹ã«ã€StatusBar.hide 関数を使用ã§ãã¾ã™ãŒã€StatusBar アプリ起動時ã«éžè¡¨ç¤ºã«ã™ã‚‹å ´åˆã¯ã€ã‚¢ãƒ—リ㮠Info.plist ファイルを変更ã™ã‚‹å¿…è¦ãŒã‚りã¾ã™ã€‚ + +ã“れら 2 ã¤ã®å±žæ€§ã®è¿½åŠ /編集å˜åœ¨ã—ãªã„å ´åˆã€‚ **「ステータス ãƒãƒ¼ãŒéžè¡¨ç¤ºæœ€åˆã€** **"YES"**ã‚’è¨å®šã—〠**「ビュー コント ãƒãƒ¼ãƒ©ãƒ¼ ベースã®ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ ãƒãƒ¼ã®å¤–観ã€** **"NO"**ã«ã—ã¾ã™ã€‚ Xcode ã›ã𿉋動ã§ç·¨é›†ã™ã‚‹ã€ã‚ーã¨å€¤ã¯ã€‚ + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## メソッド + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## プãƒãƒ‘ティ + +* StatusBar.isVisible + +## ã‚¢ã‚¯ã‚»ã‚¹è¨±å¯ + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +IOS 7ã€statusbar オーãƒãƒ¼ãƒ¬ã‚¤ã¾ãŸã¯ãªã„ WebView をオーãƒãƒ¼ãƒ¬ã‚¤ã—ã¾ã™ã€‚ + + StatusBar.overlaysWebView(true); + + +## 説明 + +IOS 7ã€iOS ã® 6 ã®ã‚ˆã†ã«è¡¨ç¤ºã•れるステータスãƒãƒ¼ã‚’ false ã«è¨å®šã—ã¾ã™ã€‚ä»–ã®é–¢æ•°ã®ä½¿ç”¨ã«åˆã‚ã›ã¦ã‚¹ã‚¿ã‚¤ãƒ«ã‚„背景色をè¨å®šã—ã¾ã™ã€‚ + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS + +## ç°¡å˜ãªä¾‹ + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +既定ステータス ãƒãƒ¼ (æš—ã„テã‚ã‚¹ãƒˆã€æ·¡è‰²ã®èƒŒæ™¯) を使用ã—ã¾ã™ã€‚ + + StatusBar.styleDefault(); + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +LightContent ステータスãƒãƒ¼ (æš—ã„èƒŒæ™¯ã®æ˜Žã‚‹ã„テã‚スト) を使用ã—ã¾ã™ã€‚ + + StatusBar.styleLightContent(); + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +BlackTranslucent ステータスãƒãƒ¼ (æš—ã„èƒŒæ™¯ã®æ˜Žã‚‹ã„テã‚スト) を使用ã—ã¾ã™ã€‚ + + StatusBar.styleBlackTranslucent(); + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +BlackOpaque ステータスãƒãƒ¼ (æš—ã„èƒŒæ™¯ã®æ˜Žã‚‹ã„テã‚スト) を使用ã—ã¾ã™ã€‚ + + StatusBar.styleBlackOpaque(); + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +Ios 7ã€StatusBar.statusBarOverlaysWebView ã‚’ false ã«è¨å®šã™ã‚‹å ´åˆã¯ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ãƒãƒ¼ã®èƒŒæ™¯è‰²ã®è‰²ã®åå‰ã«ã‚ˆã£ã¦è¨å®šã§ãã¾ã™ã€‚ + + StatusBar.backgroundColorByName("red"); + + +サãƒãƒ¼ãƒˆã•れã¦ã„る色ã®åå‰ã¯æ¬¡ã®ã¨ãŠã‚Šã§ã™ã€‚ + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +16 進文å—列をステータス ãƒãƒ¼ã®èƒŒæ™¯è‰²ã‚’è¨å®šã—ã¾ã™ã€‚ + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +速記㮠CSS プãƒãƒ‘ティもサãƒãƒ¼ãƒˆã•れã¦ã„ã¾ã™ã€‚ + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +Ios 7ã€StatusBar.statusBarOverlaysWebView ã‚’ false ã«è¨å®šã™ã‚‹å ´åˆã¯ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ãƒãƒ¼ã®èƒŒæ™¯è‰²ã‚’ 16 進文å—列 (#RRGGBB) ã§è¨å®šã§ãã¾ã™ã€‚ + +WP7 㨠WP8 も指定ã§ãã¾ã™å€¤ #AARRGGBB, AA ã¯ã€ã‚¢ãƒ«ãƒ•ァ値ã¨ã—㦠+ +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +ステータスãƒãƒ¼ã‚’éš ã—ã¾ã™ã€‚ + + StatusBar.hide(); + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* アンドãƒã‚¤ãƒ‰ +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +ステータス ãƒãƒ¼ãŒè¡¨ç¤ºã•れã¾ã™ã€‚ + + StatusBar.show(); + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* アンドãƒã‚¤ãƒ‰ +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +ã“ã®ãƒ—ãƒãƒ‘ティã€ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ãƒãƒ¼ãŒè¡¨ç¤ºã•れるã‹ã©ã†ã‹ã‚’ãŠèªã¿ãã ã•ã„。 + + if (StatusBar.isVisible) { + // do something + } + + +## サãƒãƒ¼ãƒˆã•れã¦ã„るプラットフォーム+ +* iOS +* アンドãƒã‚¤ãƒ‰ +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/ko/index.md b/plugins/org.apache.cordova.statusbar/doc/ko/index.md new file mode 100644 index 00000000..e30ee891 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/ko/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> `StatusBar`개체 iOS와 안 드 로ì´ë“œ ìƒíƒœ í‘œì‹œì¤„ì„ ì‚¬ìš©ìž ì§€ì • í•˜ë ¤ë©´ 몇 가지 ê¸°ëŠ¥ì„ ì œê³µ 합니다. + +## 환경 ì„¤ì • + +#### config.xml + +* **StatusBarOverlaysWebView** (boolean, 기본값: true)입니다. IOS 7, 시작 시 ìƒíƒœ 표시줄 ì˜¤ë²„ë ˆì´ ë˜ëŠ” WebView 중첩 ë˜ì§€ í™•ì¸ í•©ë‹ˆë‹¤. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (ìƒ‰ìƒ 16 진수 문ìžì—´ 기본값: #000000). Ios 7, 시작 시 16 진수 문ìžì—´ (#RRGGBB) ìƒíƒœ í‘œì‹œì¤„ì˜ ë°°ê²½ìƒ‰ì„ ì„¤ì • 합니다. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (ìƒíƒœ 표시줄 스타ì¼, 기본값: lightcontent). Ios 7, ìƒíƒœ 표시줄 스타ì¼ì„ ì„¤ì • 합니다. 사용 가능한 옵션 기본, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## 시작 시 숨기기 + +런타임 ë™ì•ˆ ì•„ëž˜ì˜ StatusBar.hide 함수를 ì‚¬ìš©í• ìˆ˜ 있습니다 하지만 ë‹¹ì‹ ì´ ì›í•˜ëŠ” ì‘ìš© 프로그램 시작 시 숨겨진 ìƒíƒœ 표시줄, ì‘ìš© í”„ë¡œê·¸ëž¨ì˜ Info.plist íŒŒì¼ ìˆ˜ì • 해야 합니다. + +추가 íŽ¸ì§‘ì´ ë‘ íŠ¹ì„±ì´ ì—†ëŠ” 경우. **"ìƒíƒœ 표시줄 ì²˜ìŒ ìˆ¨ê²¨ì§„"** **"YES"** 로 ì„¤ì • 하 ê³ **"ë·° 컨트롤러 기반 ìƒíƒœ 표시줄 모양"** **"NO"**로 ì„¤ì • 합니다. Xcode, ì—´ì‡ ì—†ì´ ìˆ˜ë™ìœ¼ë¡œ 편집 하는 경우 ê°’ì€: + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## 메서드 + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## ì†ì„± + +* StatusBar.isVisible + +## 사용 권한 + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +IOS 7, ì˜¤ë²„ë ˆì´ ë˜ëŠ” 하지 WebView 중첩 ìƒíƒœ í‘œì‹œì¤„ì„ í™•ì¸ í•©ë‹ˆë‹¤. + + StatusBar.overlaysWebView(true); + + +## 설명 + +7 iOS, iOS 6 처럼 나타나는 ìƒíƒœ í‘œì‹œì¤„ì„ false로 ì„¤ì • 합니다. 다른 함수를 사용 하 ì—¬ì— ë§žê²Œ 스타ì¼ê³¼ ë°°ê²½ 색ìƒì„ ì„¤ì • 합니다. + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS + +## ë¹ ë¥¸ ì˜ˆì œ + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +기본 ìƒíƒœ 표시줄 (ì–´ë‘ìš´ í…스트, ë°ì€ ë°°ê²½ì— ëŒ€ 한)를 사용 합니다. + + StatusBar.styleDefault(); + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +LightContent ìƒíƒœ 표시줄 (ì–´ë‘ìš´ ë°°ê²½ì— ëŒ€ 한 가벼운 í…스트)ì„ ì‚¬ìš© 합니다. + + StatusBar.styleLightContent(); + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +BlackTranslucent ìƒíƒœ 표시줄 (ì–´ë‘ìš´ ë°°ê²½ì— ëŒ€ 한 가벼운 í…스트)ì„ ì‚¬ìš© 합니다. + + StatusBar.styleBlackTranslucent(); + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +BlackOpaque ìƒíƒœ 표시줄 (ì–´ë‘ìš´ ë°°ê²½ì— ëŒ€ 한 가벼운 í…스트)ì„ ì‚¬ìš© 합니다. + + StatusBar.styleBlackOpaque(); + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +Ios 7, StatusBar.statusBarOverlaysWebViewì„ false로 ì„¤ì • 하면 ì„¤ì •í• ìˆ˜ 있는 ìƒíƒœ í‘œì‹œì¤„ì˜ ë°°ê²½ìƒ‰ ìƒ‰ìƒ ì´ë¦„으로. + + StatusBar.backgroundColorByName("red"); + + +ì§€ì› ë˜ëŠ” 색 ì´ë¦„입니다. + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +16 진수 문ìžì—´ ìƒíƒœ í‘œì‹œì¤„ì˜ ë°°ê²½ìƒ‰ì„ ì„¤ì •í•©ë‹ˆë‹¤. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +CSS 대표 ì†ì„± ì§€ì› ë©ë‹ˆë‹¤. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +Ios 7, StatusBar.statusBarOverlaysWebViewì„ false로 ì„¤ì • 하면 ì„¤ì •í• ìˆ˜ 있는 ìƒíƒœ í‘œì‹œì¤„ì˜ ë°°ê²½ìƒ‰ 16 진수 문ìžì—´ (#RRGGBB)ì— ì˜í•´. + +WP7 ë° WP8ì— ë‹¹ì‹ ì€ ë˜í•œ #AARRGGBB, AA는 알파 값으로 ê°’ì„ ì§€ì •í• ìˆ˜ 있습니다. + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +숨기기 ìƒíƒœ 표시줄. + + StatusBar.hide(); + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* 안 드 로ì´ë“œ +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +ìƒíƒœ í‘œì‹œì¤„ì„ í‘œì‹œí•©ë‹ˆë‹¤. + + StatusBar.show(); + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* 안 드 로ì´ë“œ +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +ì´ ì†ì„±ì„ ìƒíƒœ 표시줄 표시 ë˜ëŠ” 경우 ì½ê¸°. + + if (StatusBar.isVisible) { + // do something + } + + +## ì§€ì› ë˜ëŠ” í”Œëž«í¼ + +* iOS +* 안 드 로ì´ë“œ +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/pl/index.md b/plugins/org.apache.cordova.statusbar/doc/pl/index.md new file mode 100644 index 00000000..af69ebdf --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/pl/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> `StatusBar`Obiekt zawiera kilka funkcji, aby dostosować iOS i Android StatusBar. + +## Preferencje + +#### config.xml + +* **StatusBarOverlaysWebView** (boolean, domyślnie na wartość true). Na iOS 7 zrobić nakładki stanu lub nie nakładki widoku sieci Web podczas uruchamiania. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (kolor szesnastkowy ciąg, domyślnie #000000). Na iOS 7 ustawić kolor tła stanu przez ciąg szesnastkowy (#RRGGBB) przy starcie systemu. + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (stan styl paska, domyślnie lightcontent.) Na iOS 7 ustawić styl paska stanu. Dostępne opcje domyślne, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## Przy starcie + +Podczas uruchamiania można użyć funkcji StatusBar.hide poniżej, ale jeśli chcesz StatusBar ukryty w uruchamiania aplikacji, należy zmodyfikować plik Info.plist Twojej aplikacji. + +Dodawanie/edycja tych dwóch atrybutów jeśli nie obecny. Ustawianie **"pasek stanu jest początkowo ukryte"** na **"Tak"** i **"Oparte na kontroler stanu paska wygląd"** na **"Nie"**. Jeśli możesz go edytować ręcznie bez Xcode, kluczy i wartości są: + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## Metody + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## Właściwości + +* StatusBar.isVisible + +## Uprawnienia + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +Na iOS 7 zrobić statusbar nakładki lub nie nakładka widoku sieci Web. + + StatusBar.overlaysWebView(true); + + +## Opis + +Na iOS 7 zestaw do false, aby na pasku stanu pojawia się jak iOS 6. Ustaw kolor tła i styl do korzystania z innych funkcji. + +## Obsługiwane platformy + +* iOS + +## Szybki przykład + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +Użyj domyślnego stanu (ciemny tekst, teł światła). + + StatusBar.styleDefault(); + + +## Obsługiwane platformy + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +Użyj lightContent stanu (światło tekst, ciemne tło). + + StatusBar.styleLightContent(); + + +## Obsługiwane platformy + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +Użyj blackTranslucent stanu (światło tekst, ciemne tło). + + StatusBar.styleBlackTranslucent(); + + +## Obsługiwane platformy + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +Użyj blackOpaque stanu (światło tekst, ciemne tło). + + StatusBar.styleBlackOpaque(); + + +## Obsługiwane platformy + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +Na iOS 7 gdy zostanie ustawiona wartość false, StatusBar.statusBarOverlaysWebView można ustawić kolor tła stanu przez nazwę koloru. + + StatusBar.backgroundColorByName("red"); + + +Nazwy kolorów obsługiwane są: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## Obsługiwane platformy + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +Ustawia kolor tła stanu przez ciąg szesnastkowy. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +Obsługiwane są również właściwości CSS. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +Na iOS 7 gdy zostanie ustawiona wartość false, StatusBar.statusBarOverlaysWebView można ustawić kolor tła stanu przez ciąg szesnastkowy (#RRGGBB). + +Na WP7 i WP8 można również określić wartości jako #AARRGGBB, gdzie AA jest wartością alfa + +## Obsługiwane platformy + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +Ukryj pasek stanu. + + StatusBar.hide(); + + +## Obsługiwane platformy + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +Pokazuje pasek stanu. + + StatusBar.show(); + + +## Obsługiwane platformy + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +Czytać tej właściwość, aby sprawdzić, czy stanu jest widoczne lub nie. + + if (StatusBar.isVisible) { + // do something + } + + +## Obsługiwane platformy + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/ru/index.md b/plugins/org.apache.cordova.statusbar/doc/ru/index.md new file mode 100644 index 00000000..511ed65d --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/ru/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> Объект `StatusBar` предоÑтавлÑет некоторые функции Ð´Ð»Ñ Ð½Ð°Ñтройки ÑтатуÑной панели на iOS и Android. + +## ÐаÑтройки + +#### config.xml + +* **StatusBarOverlaysWebView** (логичеÑкое значение, по умолчанию true). Ð’ iOS 7 определÑет необходимо ли Ñделать наложение ÑтатуÑной панели на WebView при запуÑке или нет. + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor** (шеÑÑ‚Ð½Ð°Ð´Ñ†Ð°Ñ‚ÐµÑ€Ð¸Ñ‡Ð½Ð°Ñ Ñтрока цвета, Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¿Ð¾ умолчанию #000000). Ðа iOS 7 уÑтановит цвет фона ÑтатуÑной панели при запуÑке, на оÑновании шеÑтнадцатеричной Ñтроки цвета (#RRGGBB). + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **StatusBarStyle** (ÑÑ‚Ð°Ñ‚ÑƒÑ Ð±Ð°Ñ€ Ñтиль, по умолчанию lightcontent). Ðа iOS 7 уÑтановите Ñтиль Ñтроки ÑоÑтоÑниÑ. ДоÑтупные параметры по умолчанию, lightcontent, blacktranslucent, blackopaque. + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## Скрытие при запуÑке + +Во Ð²Ñ€ÐµÐ¼Ñ Ð²Ñ‹Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð¼Ð¾Ð¶Ð½Ð¾ иÑпользовать функцию StatusBar.hide ниже, но еÑли вы хотите StatusBar быть Ñкрыты при запуÑке приложениÑ, необходимо изменить файл Info.plist вашего приложениÑ. + +Добавьте/измените Ñти два атрибута, еÑли они не приÑутÑтвуют или отличаютÑÑ Ð¾Ñ‚ нижеуказанных значений. УÑтановите значение **«Status bar is initially hidden»** равное **«YES»** и уÑтановите значение **«View controller-based status bar appearance»** на **«NO»**. ЕÑли вы измените его вручную без Xcode, ключи и Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ ÑвлÑÑŽÑ‚ÑÑ Ñледующими: + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## Методы + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## Параметры + +* StatusBar.isVisible + +## Ð Ð°Ð·Ñ€ÐµÑˆÐµÐ½Ð¸Ñ + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +Ðа iOS 7 Сделайте statusbar overlay или не поверх WebView. + + StatusBar.overlaysWebView(true); + + +## ОпиÑание + +Ðа iOS 7 УÑтановите значение false чтобы Ñделать statusbar поÑвлÑÑŽÑ‚ÑÑ ÐºÐ°Ðº iOS 6. Задайте Ñтиль и цвет фона в ÑоответÑтвии Ñ Ð¸Ñпользованием других функций. + +## Поддерживаемые платформы + +* iOS + +## Краткий пример + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +ИÑпользуйте по умолчанию statusbar (темный текÑÑ‚, Ð´Ð»Ñ Ð»ÐµÐ³ÐºÐ¸Ñ… Ñтола). + + StatusBar.styleDefault(); + + +## Поддерживаемые платформы + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +ИÑпользуйте lightContent statusbar (Ñветлый текÑÑ‚, на темном фоне). + + StatusBar.styleLightContent(); + + +## Поддерживаемые платформы + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +ИÑпользуйте blackTranslucent statusbar (Ñветлый текÑÑ‚, на темном фоне). + + StatusBar.styleBlackTranslucent(); + + +## Поддерживаемые платформы + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +ИÑпользуйте blackOpaque statusbar (Ñветлый текÑÑ‚, на темном фоне). + + StatusBar.styleBlackOpaque(); + + +## Поддерживаемые платформы + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +Ðа iOS 7 когда StatusBar.statusBarOverlaysWebView приÑвоено значение false, можно задать цвет фона Ð´Ð»Ñ Ð¾Ð±ÑŠÐµÐºÑ‚Ð° statusbar по имени цвета. + + StatusBar.backgroundColorByName("red"); + + +Имена поддерживаемых цветов ÑвлÑÑŽÑ‚ÑÑ: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## Поддерживаемые платформы + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +Задает цвет фона Ð´Ð»Ñ Ð¾Ð±ÑŠÐµÐºÑ‚Ð° statusbar, шеÑÑ‚Ð½Ð°Ð´Ñ†Ð°Ñ‚ÐµÑ€Ð¸Ñ‡Ð½Ð°Ñ Ñтрока. + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +Также поддерживаютÑÑ ÑвойÑтва CSS Ñтенографию. + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +Ðа iOS 7 когда StatusBar.statusBarOverlaysWebView приÑвоено значение false, можно задать цвет фона Ð´Ð»Ñ Ð¾Ð±ÑŠÐµÐºÑ‚Ð° statusbar, шеÑÑ‚Ð½Ð°Ð´Ñ†Ð°Ñ‚ÐµÑ€Ð¸Ñ‡Ð½Ð°Ñ Ñтрока (#RRGGBB). + +Ðа WP7 и WP8 также можно указать Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ ÐºÐ°Ðº #AARRGGBB, где AA — Ñто альфа-значение + +## Поддерживаемые платформы + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +Скройте Ñтроку ÑоÑтоÑÐ½Ð¸Ñ statusbar. + + StatusBar.hide(); + + +## Поддерживаемые платформы + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +Показывает Ñтроку ÑоÑтоÑÐ½Ð¸Ñ statusbar. + + StatusBar.show(); + + +## Поддерживаемые платформы + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +Чтение Ñто ÑвойÑтво, чтобы увидеть, еÑли statusbar ÑвлÑетÑÑ Ð²Ð¸Ð´Ð¸Ð¼Ñ‹Ð¼ или нет. + + if (StatusBar.isVisible) { + // do something + } + + +## Поддерживаемые платформы + +* iOS +* Android +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/doc/zh/index.md b/plugins/org.apache.cordova.statusbar/doc/zh/index.md new file mode 100644 index 00000000..f2eaadd0 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/doc/zh/index.md @@ -0,0 +1,238 @@ +<!--- + 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. +--> + +# org.apache.cordova.statusbar + +# StatusBar + +> `StatusBar`物件æä¾›äº†ä¸€äº›åŠŸèƒ½ï¼Œè‡ªè¨‚çš„ iOS å’Œ Android 狀態列。 + +## 首é¸é … + +#### config.xml + +* **StatusBarOverlaysWebView**(布林值,é è¨å€¼ç‚º true)。在 iOS 7,使狀態列覆蓋或ä¸è¦†è“‹ web 視圖在啟動時。 + + <preference name="StatusBarOverlaysWebView" value="true" /> + + +* **StatusBarBackgroundColor**(é¡è‰²åå…進ä½å—串,é è¨å€¼ç‚º #000000)。在 iOS 7,通éŽä¸€å€‹åå…進ä½å—串 (#RRGGBB) 在啟動時è¨ç½®ç‹€æ…‹åˆ—的背景色。 + + <preference name="StatusBarBackgroundColor" value="#000000" /> + + +* **狀態列**(狀態列樣å¼ï¼Œé è¨å€¼ç‚º lightcontent)。在 iOS 7,è¨ç½®çš„狀態橫æ¢åœ–樣å¼ã€‚å¯ç”¨çš„é¸é …é è¨ï¼Œlightcontent,blacktranslucent,blackopaque。 + + <preference name="StatusBarStyle" value="lightcontent" /> + + +## åœ¨å•Ÿå‹•æ™‚éš±è— + +在é‹è¡Œæ™‚æœŸé–“ï¼Œä½ å¯ä»¥ä½¿ç”¨ StatusBar.hide 函數下é¢ï¼Œä½†å¦‚æžœä½ æƒ³è¦é¡¯ç¤ºç‹€æ…‹åˆ—éš±è—在應用程å¼å•Ÿå‹•æ™‚ï¼Œä½ å¿…é ˆä¿®æ”¹ä½ çš„æ‡‰ç”¨ç¨‹å¼çš„ Info.plist 檔。 + +æ·»åŠ ç·¨è¼¯é€™å…©å€‹å±¬æ€§ï¼Œå¦‚æžœä¸å˜åœ¨ã€‚ å°‡**"狀態列最åˆéš±è—"**è¨ç½®ç‚º**"YES"**å’Œ**"視圖基於控制器的狀態列外觀"**è¨ç½®ç‚º**"å¦"**。 如果您手動編輯它沒有 Xcode,éµå’Œå€¼æ˜¯ï¼š + + <key>UIStatusBarHidden</key> + <true/> + <key>UIViewControllerBasedStatusBarAppearance</key> + <false/> + + +## 方法 + +* StatusBar.overlaysWebView +* StatusBar.styleDefault +* StatusBar.styleLightContent +* StatusBar.styleBlackTranslucent +* StatusBar.styleBlackOpaque +* StatusBar.backgroundColorByName +* StatusBar.backgroundColorByHexString +* StatusBar.hide +* StatusBar.show + +## 屬性 + +* StatusBar.isVisible + +## è¨±å¯æ¬Š + +#### config.xml + + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" onload="true" /> + </feature> + + +# StatusBar.overlaysWebView + +在 iOS 7,使狀態列覆蓋或ä¸è¦†è“‹ web 視圖。 + + StatusBar.overlaysWebView(true); + + +## æè¿° + +在 iOS 7,è¨ç½®ç‚º false,使狀態列出ç¾åƒ iOS 6。è¨ç½®çš„æ¨£å¼å’ŒèƒŒæ™¯çš„é¡è‰²ï¼Œä»¥é©æ‡‰ä½¿ç”¨å…¶ä»–函數。 + +## 支æ´çš„平臺 + +* iOS + +## 快速的示例 + + StatusBar.overlaysWebView(true); + StatusBar.overlaysWebView(false); + + +# StatusBar.styleDefault + +使用é è¨ç‹€æ…‹åˆ— (淺色背景深色文本)。 + + StatusBar.styleDefault() ï¼› + + +## 支æ´çš„平臺 + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleLightContent + +使用 lightContent 狀態列 (光文本,為深色的背景)。 + + StatusBar.styleLightContent(); + + +## 支æ´çš„平臺 + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackTranslucent + +使用 blackTranslucent 狀態列 (光文本,為深色的背景)。 + + StatusBar.styleBlackTranslucent(); + + +## 支æ´çš„平臺 + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.styleBlackOpaque + +使用 blackOpaque 狀態列 (光文本,為深色的背景)。 + + StatusBar.styleBlackOpaque(); + + +## 支æ´çš„平臺 + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByName + +在 iOS 7ï¼Œç•¶ä½ å°‡ StatusBar.statusBarOverlaysWebView è¨ç½®ç‚º falseï¼Œä½ å¯ä»¥è¨ç½®ç‹€æ…‹åˆ—的背景é¡è‰²ç”±é¡è‰²å稱。 + + StatusBar.backgroundColorByName("red"); + + +支æ´çš„é¡è‰²å稱是: + + black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown + + +## 支æ´çš„平臺 + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.backgroundColorByHexString + +ç”±åå…進ä½å—串è¨ç½®ç‹€æ…‹åˆ—的背景色。 + + StatusBar.backgroundColorByHexString("#C0C0C0"); + + +æ¤å¤–æ”¯æ´ CSS 速記屬性。 + + StatusBar.backgroundColorByHexString("#333"); // => #333333 + StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB + + +在 iOS 7ï¼Œç•¶ä½ å°‡ StatusBar.statusBarOverlaysWebView è¨ç½®ç‚º falseï¼Œä½ å¯ä»¥è¨ç½®ç‹€æ…‹åˆ—的背景é¡è‰²ç”±åå…進ä½å—串 (#RRGGBB)。 + +WP7 å’Œ WP8 您還å¯ä»¥æŒ‡å®šå€¼ç‚º #AARRGGBBï¼Œå…¶ä¸ AA 是 Alpha 值 + +## 支æ´çš„平臺 + +* iOS +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.hide + +éš±è—狀態列。 + + StatusBar.hide(); + + +## 支æ´çš„平臺 + +* iOS +* 安å“系統 +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.show + +顯示狀態列。 + + StatusBar.show(); + + +## 支æ´çš„平臺 + +* iOS +* 安å“系統 +* Windows Phone 7 +* Windows Phone 8 + +# StatusBar.isVisible + +è®€å–æ¤å±¬æ€§ï¼Œä»¥çœ‹çœ‹æ˜¯å¦ç‹€æ…‹åˆ—是å¯è¦‹çš„æˆ–ä¸ã€‚ + + if (StatusBar.isVisible) { + // do something + } + + +## 支æ´çš„平臺 + +* iOS +* 安å“系統 +* Windows Phone 7 +* Windows Phone 8
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/package.json b/plugins/org.apache.cordova.statusbar/package.json new file mode 100644 index 00000000..4e5ce417 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/package.json @@ -0,0 +1,25 @@ +{ + "version": "0.1.10", + "name": "org.apache.cordova.statusbar", + "cordova_name": "StatusBar", + "description": "Cordova StatusBar Plugin", + "license": "Apache 2.0", + "keywords": [ + "cordova", + "statusbar" + ], + "platforms": [ + "android", + "ios", + "wp7", + "wp8", + "windows" + ], + "engines": [ + { + "name": "cordova", + "version": ">=3.0.0" + } + ], + "englishdoc": "<!---\n Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n-->\n# org.apache.cordova.statusbar\n\nStatusBar\n======\n\n> The `StatusBar` object provides some functions to customize the iOS and Android StatusBar.\n\n\n## Installation\n\n cordova plugin add org.apache.cordova.statusbar\n\nPreferences\n-----------\n\n#### config.xml\n\n- __StatusBarOverlaysWebView__ (boolean, defaults to true). On iOS 7, make the statusbar overlay or not overlay the WebView at startup.\n\n <preference name=\"StatusBarOverlaysWebView\" value=\"true\" />\n\n- __StatusBarBackgroundColor__ (color hex string, defaults to #000000). On iOS 7, set the background color of the statusbar by a hex string (#RRGGBB) at startup.\n\n <preference name=\"StatusBarBackgroundColor\" value=\"#000000\" />\n\n- __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque.\n\n <preference name=\"StatusBarStyle\" value=\"lightcontent\" />\n\nHiding at startup\n-----------\n\nDuring runtime you can use the StatusBar.hide function below, but if you want the StatusBar to be hidden at app startup, you must modify your app's Info.plist file.\n\nAdd/edit these two attributes if not present. Set **\"Status bar is initially hidden\"** to **\"YES\"** and set **\"View controller-based status bar appearance\"** to **\"NO\"**. If you edit it manually without Xcode, the keys and values are:\n\n\n\t<key>UIStatusBarHidden</key>\n\t<true/>\n\t<key>UIViewControllerBasedStatusBarAppearance</key>\n\t<false/>\n\n\nMethods\n-------\nThis plugin defines global `StatusBar` object.\n\nAlthough in the global scope, it is not available until after the `deviceready` event.\n\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n function onDeviceReady() {\n console.log(StatusBar);\n }\n\n- StatusBar.overlaysWebView\n- StatusBar.styleDefault\n- StatusBar.styleLightContent\n- StatusBar.styleBlackTranslucent\n- StatusBar.styleBlackOpaque\n- StatusBar.backgroundColorByName\n- StatusBar.backgroundColorByHexString\n- StatusBar.hide\n- StatusBar.show\n\nProperties\n--------\n\n- StatusBar.isVisible\n\nPermissions\n-----------\n\n#### config.xml\n\n <feature name=\"StatusBar\">\n <param name=\"ios-package\" value=\"CDVStatusBar\" onload=\"true\" />\n </feature>\n\nStatusBar.overlaysWebView\n=================\n\nOn iOS 7, make the statusbar overlay or not overlay the WebView.\n\n StatusBar.overlaysWebView(true);\n\nDescription\n-----------\n\nOn iOS 7, set to false to make the statusbar appear like iOS 6. Set the style and background color to suit using the other functions.\n\n\nSupported Platforms\n-------------------\n\n- iOS\n\nQuick Example\n-------------\n\n StatusBar.overlaysWebView(true);\n StatusBar.overlaysWebView(false);\n\nStatusBar.styleDefault\n=================\n\nUse the default statusbar (dark text, for light backgrounds).\n\n StatusBar.styleDefault();\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\nStatusBar.styleLightContent\n=================\n\nUse the lightContent statusbar (light text, for dark backgrounds).\n\n StatusBar.styleLightContent();\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\nStatusBar.styleBlackTranslucent\n=================\n\nUse the blackTranslucent statusbar (light text, for dark backgrounds).\n\n StatusBar.styleBlackTranslucent();\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\nStatusBar.styleBlackOpaque\n=================\n\nUse the blackOpaque statusbar (light text, for dark backgrounds).\n\n StatusBar.styleBlackOpaque();\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\n\nStatusBar.backgroundColorByName\n=================\n\nOn iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by color name.\n\n StatusBar.backgroundColorByName(\"red\");\n\nSupported color names are:\n\n black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\nStatusBar.backgroundColorByHexString\n=================\n\nSets the background color of the statusbar by a hex string.\n\n StatusBar.backgroundColorByHexString(\"#C0C0C0\");\n\nCSS shorthand properties are also supported.\n\n StatusBar.backgroundColorByHexString(\"#333\"); // => #333333\n StatusBar.backgroundColorByHexString(\"#FAB\"); // => #FFAABB\n\nOn iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by a hex string (#RRGGBB).\n\nOn WP7 and WP8 you can also specify values as #AARRGGBB, where AA is an alpha value\n\nSupported Platforms\n-------------------\n\n- iOS\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\nStatusBar.hide\n=================\n\nHide the statusbar.\n\n StatusBar.hide();\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Android\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\nStatusBar.show\n=================\n\nShows the statusbar.\n\n StatusBar.show();\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Android\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\n\nStatusBar.isVisible\n=================\n\nRead this property to see if the statusbar is visible or not.\n\n if (StatusBar.isVisible) {\n \t// do something\n }\n\n\nSupported Platforms\n-------------------\n\n- iOS\n- Android\n- Windows Phone 7\n- Windows Phone 8\n- Windows Phone 8.1\n\n\n" +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/plugin.xml b/plugins/org.apache.cordova.statusbar/plugin.xml new file mode 100644 index 00000000..01b04e0b --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/plugin.xml @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + xmlns:rim="http://www.blackberry.com/ns/widgets" + xmlns:android="http://schemas.android.com/apk/res/android" + id="org.apache.cordova.statusbar" + version="0.1.10"> + <name>StatusBar</name> + <description>Cordova StatusBar Plugin</description> + <license>Apache 2.0</license> + <keywords>cordova,statusbar</keywords> + + <engines> + <engine name="cordova" version=">=3.0.0" /> + </engines> + + <js-module src="www/statusbar.js" name="statusbar"> + <clobbers target="window.StatusBar" /> + </js-module> + + <platform name="android"> + <source-file src="src/android/StatusBar.java" target-dir="src/org/apache/cordova/statusbar" /> + + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="StatusBar"> + <param name="android-package" value="org.apache.cordova.statusbar.StatusBar" /> + <param name="onload" value="true" /> + </feature> + </config-file> + </platform> + + <!-- ios --> + <platform name="ios"> + + <config-file target="config.xml" parent="/*"> + <feature name="StatusBar"> + <param name="ios-package" value="CDVStatusBar" /> + <param name="onload" value="true" /> + </feature> + <preference name="StatusBarOverlaysWebView" value="true" /> + <preference name="StatusBarStyle" value="lightcontent" /> + </config-file> + + <header-file src="src/ios/CDVStatusBar.h" /> + <source-file src="src/ios/CDVStatusBar.m" /> + + </platform> + + <!-- wp7 --> + <platform name="wp7"> + <config-file target="config.xml" parent="/*"> + <feature name="StatusBar"> + <param name="wp-package" value="StatusBar"/> + </feature> + </config-file> + <source-file src="src/wp/StatusBar.cs" /> + </platform> + + <!-- wp8 --> + <platform name="wp8"> + <config-file target="config.xml" parent="/*"> + <feature name="StatusBar"> + <param name="wp-package" value="StatusBar"/> + </feature> + </config-file> + <source-file src="src/wp/StatusBar.cs" /> + </platform> + + <!-- windows --> + <platform name="windows"> + <js-module src="src/windows/StatusBarProxy.js" name="StatusBarProxy"> + <runs /> + </js-module> + </platform> +</plugin> diff --git a/plugins/org.apache.cordova.statusbar/src/android/StatusBar.java b/plugins/org.apache.cordova.statusbar/src/android/StatusBar.java new file mode 100644 index 00000000..e4f748f9 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/src/android/StatusBar.java @@ -0,0 +1,101 @@ +/* + * 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. + * +*/ +package org.apache.cordova.statusbar; + +import android.app.Activity; +import android.util.Log; +import android.view.Window; +import android.view.WindowManager; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaArgs; +import org.apache.cordova.CordovaInterface; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.PluginResult; +import org.json.JSONException; + +public class StatusBar extends CordovaPlugin { + private static final String TAG = "StatusBar"; + + /** + * Sets the context of the Command. This can then be used to do things like + * get file paths associated with the Activity. + * + * @param cordova The context of the main Activity. + * @param webView The CordovaWebView Cordova is running in. + */ + @Override + public void initialize(final CordovaInterface cordova, CordovaWebView webView) { + Log.v(TAG, "StatusBar: initialization"); + super.initialize(cordova, webView); + + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + // Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially + // by the Cordova. + Window window = cordova.getActivity().getWindow(); + window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); + } + }); + } + + /** + * Executes the request and returns PluginResult. + * + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackContext The callback id used when calling back into JavaScript. + * @return True if the action was valid, false otherwise. + */ + @Override + public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { + Log.v(TAG, "Executing action: " + action); + final Activity activity = this.cordova.getActivity(); + final Window window = activity.getWindow(); + if ("_ready".equals(action)) { + boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); + } + + if ("show".equals(action)) { + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + }); + return true; + } + + if ("hide".equals(action)) { + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + }); + return true; + } + + return false; + } +} diff --git a/plugins/org.apache.cordova.statusbar/src/ios/CDVStatusBar.h b/plugins/org.apache.cordova.statusbar/src/ios/CDVStatusBar.h new file mode 100644 index 00000000..84f37fa7 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/src/ios/CDVStatusBar.h @@ -0,0 +1,49 @@ +/* + 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. + */ + +#import <Cordova/CDVPlugin.h> +#import <Cordova/CDVInvokedUrlCommand.h> + +@interface CDVStatusBar : CDVPlugin { + @protected + BOOL _statusBarOverlaysWebView; + UIView* _statusBarBackgroundView; + BOOL _uiviewControllerBasedStatusBarAppearance; + UIColor* _statusBarBackgroundColor; + NSString* _eventsCallbackId; +} + +@property (atomic, assign) BOOL statusBarOverlaysWebView; + +- (void) overlaysWebView:(CDVInvokedUrlCommand*)command; + +- (void) styleDefault:(CDVInvokedUrlCommand*)command; +- (void) styleLightContent:(CDVInvokedUrlCommand*)command; +- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command; +- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command; + +- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command; +- (void) backgroundColorByHexString:(CDVInvokedUrlCommand*)command; + +- (void) hide:(CDVInvokedUrlCommand*)command; +- (void) show:(CDVInvokedUrlCommand*)command; + +- (void) _ready:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/org.apache.cordova.statusbar/src/ios/CDVStatusBar.m b/plugins/org.apache.cordova.statusbar/src/ios/CDVStatusBar.m new file mode 100644 index 00000000..d2bd708d --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/src/ios/CDVStatusBar.m @@ -0,0 +1,458 @@ +/* + 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. + */ + +/* + NOTE: plugman/cordova cli should have already installed this, + but you need the value UIViewControllerBasedStatusBarAppearance + in your Info.plist as well to set the styles in iOS 7 + */ + +#import "CDVStatusBar.h" +#import <objc/runtime.h> +#import <Cordova/CDVViewController.h> + +static const void *kHideStatusBar = &kHideStatusBar; +static const void *kStatusBarStyle = &kStatusBarStyle; + +@interface CDVViewController (StatusBar) + +@property (nonatomic, retain) id sb_hideStatusBar; +@property (nonatomic, retain) id sb_statusBarStyle; + +@end + +@implementation CDVViewController (StatusBar) + +@dynamic sb_hideStatusBar; +@dynamic sb_statusBarStyle; + +- (id)sb_hideStatusBar { + return objc_getAssociatedObject(self, kHideStatusBar); +} + +- (void)setSb_hideStatusBar:(id)newHideStatusBar { + objc_setAssociatedObject(self, kHideStatusBar, newHideStatusBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (id)sb_statusBarStyle { + return objc_getAssociatedObject(self, kStatusBarStyle); +} + +- (void)setSb_statusBarStyle:(id)newStatusBarStyle { + objc_setAssociatedObject(self, kStatusBarStyle, newStatusBarStyle, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL) prefersStatusBarHidden { + return [self.sb_hideStatusBar boolValue]; +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return (UIStatusBarStyle)[self.sb_statusBarStyle intValue]; +} + +@end + + +@interface CDVStatusBar () <UIScrollViewDelegate> +- (void)fireTappedEvent; +- (void)updateIsVisible:(BOOL)visible; +@end + +@implementation CDVStatusBar + +- (id)settingForKey:(NSString*)key +{ + return [self.commandDelegate.settings objectForKey:[key lowercaseString]]; +} + +- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context +{ + if ([keyPath isEqual:@"statusBarHidden"]) { + NSNumber* newValue = [change objectForKey:NSKeyValueChangeNewKey]; + [self updateIsVisible:![newValue boolValue]]; + } +} + +- (void)pluginInitialize +{ + BOOL isiOS7 = (IsAtLeastiOSVersion(@"7.0")); + + // init + NSNumber* uiviewControllerBasedStatusBarAppearance = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"]; + _uiviewControllerBasedStatusBarAppearance = (uiviewControllerBasedStatusBarAppearance == nil || [uiviewControllerBasedStatusBarAppearance boolValue]) && isiOS7; + + // observe the statusBarHidden property + [[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL]; + + _statusBarOverlaysWebView = YES; // default + + [self initializeStatusBarBackgroundView]; + + self.viewController.view.autoresizesSubviews = YES; + + NSString* setting; + + setting = @"StatusBarOverlaysWebView"; + if ([self settingForKey:setting]) { + self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue]; + } + + setting = @"StatusBarBackgroundColor"; + if ([self settingForKey:setting]) { + [self _backgroundColorByHexString:[self settingForKey:setting]]; + } + + setting = @"StatusBarStyle"; + if ([self settingForKey:setting]) { + [self setStatusBarStyle:[self settingForKey:setting]]; + } + + // blank scroll view to intercept status bar taps + self.webView.scrollView.scrollsToTop = NO; + UIScrollView *fakeScrollView = [[UIScrollView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + fakeScrollView.delegate = self; + fakeScrollView.scrollsToTop = YES; + [self.viewController.view addSubview:fakeScrollView]; // Add scrollview to the view heirarchy so that it will begin accepting status bar taps + [self.viewController.view sendSubviewToBack:fakeScrollView]; // Send it to the very back of the view heirarchy + fakeScrollView.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height * 2.0f); // Make the scroll view longer than the screen itself + fakeScrollView.contentOffset = CGPointMake(0.0f, UIScreen.mainScreen.bounds.size.height); // Scroll down so a tap will take scroll view back to the top +} + +- (void)onReset { + _eventsCallbackId = nil; +} + +- (void)fireTappedEvent { + if (_eventsCallbackId == nil) { + return; + } + NSDictionary* payload = @{@"type": @"tap"}; + CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:payload]; + [result setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:result callbackId:_eventsCallbackId]; +} + +- (void)updateIsVisible:(BOOL)visible { + if (_eventsCallbackId == nil) { + return; + } + CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:visible]; + [result setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:result callbackId:_eventsCallbackId]; +} + + +- (void) _ready:(CDVInvokedUrlCommand*)command +{ + _eventsCallbackId = command.callbackId; + [self updateIsVisible:![UIApplication sharedApplication].statusBarHidden]; +} + +- (void) initializeStatusBarBackgroundView +{ + CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; + + _statusBarBackgroundView = [[UIView alloc] initWithFrame:statusBarFrame]; + _statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor; + _statusBarBackgroundView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin); + _statusBarBackgroundView.autoresizesSubviews = YES; +} + +- (CGRect) invertFrameIfNeeded:(CGRect)rect orientation:(UIInterfaceOrientation)orientation { + // landscape is where (width > height). On iOS < 8, we need to invert since frames are + // always in Portrait context + if (UIDeviceOrientationIsLandscape(orientation) && (rect.size.width < rect.size.height) ) { + CGFloat temp = rect.size.width; + rect.size.width = rect.size.height; + rect.size.height = temp; + rect.origin = CGPointZero; + } + + return rect; +} + +- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView +{ + // we only care about the latest iOS version or a change in setting + if (!IsAtLeastiOSVersion(@"7.0") || statusBarOverlaysWebView == _statusBarOverlaysWebView) { + return; + } + + CGRect bounds = [[UIScreen mainScreen] bounds]; + + if (statusBarOverlaysWebView) { + + [_statusBarBackgroundView removeFromSuperview]; + if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) { + self.webView.frame = CGRectMake(0, 0, bounds.size.height, bounds.size.width); + } else { + self.webView.frame = bounds; + } + + } else { + + CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; + + [self initializeStatusBarBackgroundView]; + + CGRect frame = self.webView.frame; + frame.origin.y = statusBarFrame.size.height; + frame.size.height -= statusBarFrame.size.height; + + self.webView.frame = frame; + [self.webView.superview addSubview:_statusBarBackgroundView]; + } + + _statusBarOverlaysWebView = statusBarOverlaysWebView; +} + +- (BOOL) statusBarOverlaysWebView +{ + return _statusBarOverlaysWebView; +} + +- (void) overlaysWebView:(CDVInvokedUrlCommand*)command +{ + id value = [command argumentAtIndex:0]; + if (!([value isKindOfClass:[NSNumber class]])) { + value = [NSNumber numberWithBool:YES]; + } + + self.statusBarOverlaysWebView = [value boolValue]; +} + +- (void) refreshStatusBarAppearance +{ + SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate"); + if ([self.viewController respondsToSelector:sel]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [self.viewController performSelector:sel withObject:nil]; +#pragma clang diagnostic pop + } +} + +- (void) setStyleForStatusBar:(UIStatusBarStyle)style +{ + if (_uiviewControllerBasedStatusBarAppearance) { + CDVViewController* vc = (CDVViewController*)self.viewController; + vc.sb_statusBarStyle = [NSNumber numberWithInt:style]; + [self refreshStatusBarAppearance]; + + } else { + [[UIApplication sharedApplication] setStatusBarStyle:style]; + } +} + +- (void) setStatusBarStyle:(NSString*)statusBarStyle +{ + // default, lightContent, blackTranslucent, blackOpaque + NSString* lcStatusBarStyle = [statusBarStyle lowercaseString]; + + if ([lcStatusBarStyle isEqualToString:@"default"]) { + [self styleDefault:nil]; + } else if ([lcStatusBarStyle isEqualToString:@"lightcontent"]) { + [self styleLightContent:nil]; + } else if ([lcStatusBarStyle isEqualToString:@"blacktranslucent"]) { + [self styleBlackTranslucent:nil]; + } else if ([lcStatusBarStyle isEqualToString:@"blackopaque"]) { + [self styleBlackOpaque:nil]; + } +} + +- (void) styleDefault:(CDVInvokedUrlCommand*)command +{ + [self setStyleForStatusBar:UIStatusBarStyleDefault]; +} + +- (void) styleLightContent:(CDVInvokedUrlCommand*)command +{ + [self setStyleForStatusBar:UIStatusBarStyleLightContent]; +} + +- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command +{ + [self setStyleForStatusBar:UIStatusBarStyleBlackTranslucent]; +} + +- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command +{ + [self setStyleForStatusBar:UIStatusBarStyleBlackOpaque]; +} + +- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command +{ + id value = [command argumentAtIndex:0]; + if (!([value isKindOfClass:[NSString class]])) { + value = @"black"; + } + + SEL selector = NSSelectorFromString([value stringByAppendingString:@"Color"]); + if ([UIColor respondsToSelector:selector]) { + _statusBarBackgroundView.backgroundColor = [UIColor performSelector:selector]; + } +} + +- (void) _backgroundColorByHexString:(NSString*)hexString +{ + unsigned int rgbValue = 0; + NSScanner* scanner = [NSScanner scannerWithString:hexString]; + [scanner setScanLocation:1]; + [scanner scanHexInt:&rgbValue]; + + _statusBarBackgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; + _statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor; +} + +- (void) backgroundColorByHexString:(CDVInvokedUrlCommand*)command +{ + NSString* value = [command argumentAtIndex:0]; + if (!([value isKindOfClass:[NSString class]])) { + value = @"#000000"; + } + + if (![value hasPrefix:@"#"] || [value length] < 7) { + return; + } + + [self _backgroundColorByHexString:value]; +} + +- (void) hideStatusBar +{ + if (_uiviewControllerBasedStatusBarAppearance) { + CDVViewController* vc = (CDVViewController*)self.viewController; + vc.sb_hideStatusBar = [NSNumber numberWithBool:YES]; + [self refreshStatusBarAppearance]; + + } else { + UIApplication* app = [UIApplication sharedApplication]; + [app setStatusBarHidden:YES]; + } +} + +- (void) hide:(CDVInvokedUrlCommand*)command +{ + UIApplication* app = [UIApplication sharedApplication]; + + if (!app.isStatusBarHidden) + { + self.viewController.wantsFullScreenLayout = YES; + CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + + [self hideStatusBar]; + + if (IsAtLeastiOSVersion(@"7.0")) { + [_statusBarBackgroundView removeFromSuperview]; + } + + if (!_statusBarOverlaysWebView) { + + CGRect frame = self.webView.frame; + frame.origin.y = 0; + if (!self.statusBarOverlaysWebView) { + if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) { + frame.size.height += statusBarFrame.size.width; + } else { + frame.size.height += statusBarFrame.size.height; + } + } + + self.webView.frame = frame; + } + + _statusBarBackgroundView.hidden = YES; + } +} + +- (void) showStatusBar +{ + if (_uiviewControllerBasedStatusBarAppearance) { + CDVViewController* vc = (CDVViewController*)self.viewController; + vc.sb_hideStatusBar = [NSNumber numberWithBool:NO]; + [self refreshStatusBarAppearance]; + + } else { + UIApplication* app = [UIApplication sharedApplication]; + [app setStatusBarHidden:NO]; + } +} + +- (void) show:(CDVInvokedUrlCommand*)command +{ + UIApplication* app = [UIApplication sharedApplication]; + + if (app.isStatusBarHidden) + { + BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0")); + self.viewController.wantsFullScreenLayout = isIOS7; + + [self showStatusBar]; + + if (isIOS7) { + CGRect frame = self.webView.frame; + self.viewController.view.frame = [[UIScreen mainScreen] bounds]; + + CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; + + if (!self.statusBarOverlaysWebView) { + + // there is a possibility that when the statusbar was hidden, it was in a different orientation + // from the current one. Therefore we need to expand the statusBarBackgroundView as well to the + // statusBar's current size + CGRect sbBgFrame = _statusBarBackgroundView.frame; + frame.origin.y = statusBarFrame.size.height; + frame.size.height -= statusBarFrame.size.height; + sbBgFrame.size = statusBarFrame.size; + + _statusBarBackgroundView.frame = sbBgFrame; + [self.webView.superview addSubview:_statusBarBackgroundView]; + } + + self.webView.frame = frame; + + } else { + + CGRect bounds = [[UIScreen mainScreen] applicationFrame]; + self.viewController.view.frame = bounds; + } + + _statusBarBackgroundView.hidden = NO; + } +} + +- (void) dealloc +{ + [[UIApplication sharedApplication] removeObserver:self forKeyPath:@"statusBarHidden"]; +} + + +#pragma mark - UIScrollViewDelegate + +- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView +{ + [self fireTappedEvent]; + return NO; +} + +@end diff --git a/plugins/org.apache.cordova.statusbar/src/windows/StatusBarProxy.js b/plugins/org.apache.cordova.statusbar/src/windows/StatusBarProxy.js new file mode 100644 index 00000000..57700999 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/src/windows/StatusBarProxy.js @@ -0,0 +1,100 @@ +/* + * + * 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 isSupported = true; // we assume + +function getViewStatusBar() { + if(isSupported) { + var ViewMan = Windows.UI.ViewManagement; // quick alias to save char + if( ViewMan.StatusBar && + ViewMan.StatusBar.getForCurrentView ) { + return ViewMan.StatusBar.getForCurrentView(); + } + else { + isSupported = false; // so we won't check again + } + } + return null; +} + +function hexToRgb(hex) { + // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") + var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; + hex = hex.replace(shorthandRegex, function (m, r, g, b) { + return r + r + g + g + b + b; + }); + + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null; +} + +module.exports = { + _ready: function(win, fail) { + win(statusBar.occludedRect.height !== 0); + }, + + overlaysWebView: function () { + // not supported + }, + + styleDefault: function () { + // dark text ( to be used on a light background ) + getViewStatusBar().foregroundColor = { a: 0, r: 0, g: 0, b: 0 }; + }, + + styleLightContent: function () { + // light text ( to be used on a dark background ) + getViewStatusBar().foregroundColor = { a: 0, r: 255, g: 255, b: 255 }; + }, + + styleBlackTranslucent: function () { + // #88000000 ? Apple says to use lightContent instead + return this.styleLightContent(); + }, + + styleBlackOpaque: function () { + // #FF000000 ? Apple says to use lightContent instead + return this.styleLightContent(); + }, + + backgroundColorByHexString: function (win, fail, args) { + var rgb = hexToRgb(args[0]); + var statusBar = getViewStatusBar(); + if(statusBar) { + statusBar.backgroundColor = { a: 0, r: rgb.r, g: rgb.g, b: rgb.b }; + statusBar.backgroundOpacity = 1; + } + }, + + show: function (win, fail) { + getViewStatusBar().showAsync().done(win, fail); + }, + + hide: function (win, fail) { + getViewStatusBar().hideAsync().done(win, fail); + } +}; + +require("cordova/exec/proxy").add("StatusBar", module.exports); diff --git a/plugins/org.apache.cordova.statusbar/src/wp/StatusBar.cs b/plugins/org.apache.cordova.statusbar/src/wp/StatusBar.cs new file mode 100644 index 00000000..ec83ca8e --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/src/wp/StatusBar.cs @@ -0,0 +1,141 @@ +/* + Licensed 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. +*/ + + +using Microsoft.Phone.Shell; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Threading; +using System.Windows; +using System.Windows.Media; +using System.Windows.Threading; + + +/* + * http://www.idev101.com/code/User_Interface/StatusBar.html + * https://developer.apple.com/library/ios/documentation/userexperience/conceptual/transitionguide/Bars.html + * https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/econst/UIStatusBarStyleDefault + * */ + + +namespace WPCordovaClassLib.Cordova.Commands +{ + public class StatusBar : BaseCommand + { + + // returns an argb value, if the hex is only rgb, it will be full opacity + protected Color ColorFromHex(string hexString) + { + string cleanHex = hexString.Replace("#", "").Replace("0x", ""); + // turn #FFF into #FFFFFF + if (cleanHex.Length == 3) + { + cleanHex = "" + cleanHex[0] + cleanHex[0] + cleanHex[1] + cleanHex[1] + cleanHex[2] + cleanHex[2]; + } + // add an alpha 100% if it is missing + if (cleanHex.Length == 6) + { + cleanHex = "FF" + cleanHex; + } + int argb = Int32.Parse(cleanHex, NumberStyles.HexNumber); + Color clr = Color.FromArgb((byte)((argb & 0xff000000) >> 0x18), + (byte)((argb & 0xff0000) >> 0x10), + (byte)((argb & 0xff00) >> 8), + (byte)(argb & 0xff)); + return clr; + } + + public void _ready(string options) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + bool isVis = SystemTray.IsVisible; + // TODO: pass this to JS + //Debug.WriteLine("Result::" + res); + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, isVis)); + }); + } + + public void overlaysWebView(string options) + { //exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]); + // string arg = JSON.JsonHelper.Deserialize<string[]>(options)[0]; + } + + public void styleDefault(string options) + { //exec(null, null, "StatusBar", "styleDefault", []); + Deployment.Current.Dispatcher.BeginInvoke(() => + { + SystemTray.ForegroundColor = Colors.Black; + }); + } + + public void styleLightContent(string options) + { //exec(null, null, "StatusBar", "styleLightContent", []); + + Deployment.Current.Dispatcher.BeginInvoke(() => + { + SystemTray.ForegroundColor = Colors.White; + }); + } + + public void styleBlackTranslucent(string options) + { //exec(null, null, "StatusBar", "styleBlackTranslucent", []); + styleLightContent(options); + } + + public void styleBlackOpaque(string options) + { //exec(null, null, "StatusBar", "styleBlackOpaque", []); + styleLightContent(options); + } + + public void backgroundColorByName(string options) + { //exec(null, null, "StatusBar", "backgroundColorByName", [colorname]); + // this should NOT be called, js should now be using/converting color names to hex + } + + public void backgroundColorByHexString(string options) + { //exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]); + string argb = JSON.JsonHelper.Deserialize<string[]>(options)[0]; + + Color clr = ColorFromHex(argb); + + Deployment.Current.Dispatcher.BeginInvoke(() => + { + SystemTray.Opacity = clr.A / 255.0d; + SystemTray.BackgroundColor = clr; + + }); + } + + public void hide(string options) + { //exec(null, null, "StatusBar", "hide", []); + Deployment.Current.Dispatcher.BeginInvoke(() => + { + SystemTray.IsVisible = false; + }); + + } + + public void show(string options) + { //exec(null, null, "StatusBar", "show", []); + Deployment.Current.Dispatcher.BeginInvoke(() => + { + SystemTray.IsVisible = true; + }); + } + } +}
\ No newline at end of file diff --git a/plugins/org.apache.cordova.statusbar/tests/plugin.xml b/plugins/org.apache.cordova.statusbar/tests/plugin.xml new file mode 100644 index 00000000..69b7e10f --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/tests/plugin.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" + xmlns:rim="http://www.blackberry.com/ns/widgets" + xmlns:android="http://schemas.android.com/apk/res/android" + id="org.apache.cordova.statusbar.tests" + version="0.1.10"> + <name>Cordova StatusBar Plugin Tests</name> + <license>Apache 2.0</license> + + <js-module src="tests.js" name="tests"> + </js-module> +</plugin> diff --git a/plugins/org.apache.cordova.statusbar/tests/tests.js b/plugins/org.apache.cordova.statusbar/tests/tests.js new file mode 100644 index 00000000..8b409eca --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/tests/tests.js @@ -0,0 +1,107 @@ +/* + * + * 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. + * +*/ + +exports.defineManualTests = function (contentEl, createActionButton) { + function log(msg) { + var el = document.getElementById("info"); + var logLine = document.createElement('div'); + logLine.innerHTML = msg; + el.appendChild(logLine); + } + + function doShow() { + StatusBar.show(); + log('StatusBar.isVisible=' + StatusBar.isVisible); + } + + function doHide() { + StatusBar.hide(); + log('StatusBar.isVisible=' + StatusBar.isVisible); + } + + function doColor1() { + log('set color=red'); + StatusBar.backgroundColorByName('red'); + } + + function doColor2() { + log('set style=translucent black'); + StatusBar.styleBlackTranslucent(); + } + + function doColor3() { + log('set style=default'); + StatusBar.styleDefault(); + } + + var showOverlay = true; + function doOverlay() { + showOverlay = !showOverlay; + StatusBar.overlaysWebView(showOverlay); + log('Set overlay=' + showOverlay); + } + + /******************************************************************************/ + + contentEl.innerHTML = '<div id="info"></div>' + + 'Also: tapping bar on iOS should emit a log.' + + '<div id="action-show"></div>' + + 'Expected result: Status bar will be visible' + + '</p> <div id="action-hide"></div>' + + 'Expected result: Status bar will be hidden' + + '</p> <div id="action-color2"></div>' + + 'Expected result: Status bar text will be a light (white) color' + + '</p> <div id="action-color3"></div>' + + 'Expected result: Status bar text will be a dark (black) color' + + '</p> <div id="action-overlays"></div>' + + 'Expected result:<br>Overlay true = status bar will lay on top of web view content<br>Overlay false = status bar will be separate from web view and will not cover content' + + '</p> <div id="action-color1"></div>' + + 'Expected result: If overlay false, background color for status bar will be red'; + + log('StatusBar.isVisible=' + StatusBar.isVisible); + window.addEventListener('statusTap', function () { + log('tap!'); + }, false); + + createActionButton("Show", function () { + doShow(); + }, 'action-show'); + + createActionButton("Hide", function () { + doHide(); + }, 'action-hide'); + + createActionButton("Style=red (background)", function () { + doColor1(); + }, 'action-color1'); + + createActionButton("Style=translucent black", function () { + doColor2(); + }, 'action-color2'); + + createActionButton("Style=default", function () { + doColor3(); + }, 'action-color3'); + + createActionButton("Toggle Overlays", function () { + doOverlay(); + }, 'action-overlays'); +}; diff --git a/plugins/org.apache.cordova.statusbar/www/statusbar.js b/plugins/org.apache.cordova.statusbar/www/statusbar.js new file mode 100644 index 00000000..7ebca302 --- /dev/null +++ b/plugins/org.apache.cordova.statusbar/www/statusbar.js @@ -0,0 +1,109 @@ +/* + * + * 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 exec = require('cordova/exec'); + +var namedColors = { + "black": "#000000", + "darkGray": "#A9A9A9", + "lightGray": "#D3D3D3", + "white": "#FFFFFF", + "gray": "#808080", + "red": "#FF0000", + "green": "#00FF00", + "blue": "#0000FF", + "cyan": "#00FFFF", + "yellow": "#FFFF00", + "magenta": "#FF00FF", + "orange": "#FFA500", + "purple": "#800080", + "brown": "#A52A2A" +}; + +var StatusBar = { + + isVisible: true, + + overlaysWebView: function (doOverlay) { + exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]); + }, + + styleDefault: function () { + // dark text ( to be used on a light background ) + exec(null, null, "StatusBar", "styleDefault", []); + }, + + styleLightContent: function () { + // light text ( to be used on a dark background ) + exec(null, null, "StatusBar", "styleLightContent", []); + }, + + styleBlackTranslucent: function () { + // #88000000 ? Apple says to use lightContent instead + exec(null, null, "StatusBar", "styleBlackTranslucent", []); + }, + + styleBlackOpaque: function () { + // #FF000000 ? Apple says to use lightContent instead + exec(null, null, "StatusBar", "styleBlackOpaque", []); + }, + + backgroundColorByName: function (colorname) { + return StatusBar.backgroundColorByHexString(namedColors[colorname]); + }, + + backgroundColorByHexString: function (hexString) { + if (hexString.charAt(0) !== "#") { + hexString = "#" + hexString; + } + + if (hexString.length === 4) { + var split = hexString.split(""); + hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3]; + } + + exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]); + }, + + hide: function () { + exec(null, null, "StatusBar", "hide", []); + StatusBar.isVisible = false; + }, + + show: function () { + exec(null, null, "StatusBar", "show", []); + StatusBar.isVisible = true; + } + +}; + +// prime it +exec(function (res) { + if (typeof res == 'object') { + if (res.type == 'tap') { + cordova.fireWindowEvent('statusTap'); + } + } else { + StatusBar.isVisible = res; + } +}, null, "StatusBar", "_ready", []); + +module.exports = StatusBar; |
