You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2017/06/27 21:21:53 UTC
[12/51] [partial] cordova-lib git commit: Reorganized unit test
directory. Changes include: - consolidate spec-cordova/ and spec-plugman/
into a single spec/ dir. - put jasmine config and helper modules in top-level
spec dir. - changed package.json npm r
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaClientCertRequest.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaClientCertRequest.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaClientCertRequest.java
deleted file mode 100644
index 455d2f9..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaClientCertRequest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- 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;
-
-import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-
-/**
- * Specifies interface for handling certificate requests.
- */
-public interface ICordovaClientCertRequest {
- /**
- * Cancel this request
- */
- public void cancel();
-
- /*
- * Returns the host name of the server requesting the certificate.
- */
- public String getHost();
-
- /*
- * Returns the acceptable types of asymmetric keys (can be null).
- */
- public String[] getKeyTypes();
-
- /*
- * Returns the port number of the server requesting the certificate.
- */
- public int getPort();
-
- /*
- * Returns the acceptable certificate issuers for the certificate matching the private key (can be null).
- */
- public Principal[] getPrincipals();
-
- /*
- * Ignore the request for now. Do not remember user's choice.
- */
- public void ignore();
-
- /*
- * Proceed with the specified private key and client certificate chain. Remember the user's positive choice and use it for future requests.
- *
- * @param privateKey The privateKey
- * @param chain The certificate chain
- */
- public void proceed(PrivateKey privateKey, X509Certificate[] chain);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaCookieManager.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaCookieManager.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaCookieManager.java
deleted file mode 100644
index e776194..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaCookieManager.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- 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;
-
-public interface ICordovaCookieManager {
-
- public void setCookiesEnabled(boolean accept);
-
- public void setCookie(final String url, final String value);
-
- public String getCookie(final String url);
-
- public void clearCookies();
-
- public void flush();
-};
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaHttpAuthHandler.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaHttpAuthHandler.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaHttpAuthHandler.java
deleted file mode 100644
index c55818a..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ICordovaHttpAuthHandler.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- 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;
-
-/**
- * Specifies interface for HTTP auth handler object which is used to handle auth requests and
- * specifying user credentials.
- */
- public interface ICordovaHttpAuthHandler {
- /**
- * Instructs the WebView to cancel the authentication request.
- */
- public void cancel ();
-
- /**
- * Instructs the WebView to proceed with the authentication with the given credentials.
- *
- * @param username The user name
- * @param password The password
- */
- public void proceed (String username, String password);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/LOG.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/LOG.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/LOG.java
deleted file mode 100755
index 9fe7a7d..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/LOG.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- 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;
-
-import android.util.Log;
-
-/**
- * Log to Android logging system.
- *
- * Log message can be a string or a printf formatted string with arguments.
- * See http://developer.android.com/reference/java/util/Formatter.html
- */
-public class LOG {
-
- public static final int VERBOSE = Log.VERBOSE;
- public static final int DEBUG = Log.DEBUG;
- public static final int INFO = Log.INFO;
- public static final int WARN = Log.WARN;
- public static final int ERROR = Log.ERROR;
-
- // Current log level
- public static int LOGLEVEL = Log.ERROR;
-
- /**
- * Set the current log level.
- *
- * @param logLevel
- */
- public static void setLogLevel(int logLevel) {
- LOGLEVEL = logLevel;
- Log.i("CordovaLog", "Changing log level to " + logLevel);
- }
-
- /**
- * Set the current log level.
- *
- * @param logLevel
- */
- public static void setLogLevel(String logLevel) {
- if ("VERBOSE".equals(logLevel)) LOGLEVEL = VERBOSE;
- else if ("DEBUG".equals(logLevel)) LOGLEVEL = DEBUG;
- else if ("INFO".equals(logLevel)) LOGLEVEL = INFO;
- else if ("WARN".equals(logLevel)) LOGLEVEL = WARN;
- else if ("ERROR".equals(logLevel)) LOGLEVEL = ERROR;
- Log.i("CordovaLog", "Changing log level to " + logLevel + "(" + LOGLEVEL + ")");
- }
-
- /**
- * Determine if log level will be logged
- *
- * @param logLevel
- * @return true if the parameter passed in is greater than or equal to the current log level
- */
- public static boolean isLoggable(int logLevel) {
- return (logLevel >= LOGLEVEL);
- }
-
- /**
- * Verbose log message.
- *
- * @param tag
- * @param s
- */
- public static void v(String tag, String s) {
- if (LOG.VERBOSE >= LOGLEVEL) Log.v(tag, s);
- }
-
- /**
- * Debug log message.
- *
- * @param tag
- * @param s
- */
- public static void d(String tag, String s) {
- if (LOG.DEBUG >= LOGLEVEL) Log.d(tag, s);
- }
-
- /**
- * Info log message.
- *
- * @param tag
- * @param s
- */
- public static void i(String tag, String s) {
- if (LOG.INFO >= LOGLEVEL) Log.i(tag, s);
- }
-
- /**
- * Warning log message.
- *
- * @param tag
- * @param s
- */
- public static void w(String tag, String s) {
- if (LOG.WARN >= LOGLEVEL) Log.w(tag, s);
- }
-
- /**
- * Error log message.
- *
- * @param tag
- * @param s
- */
- public static void e(String tag, String s) {
- if (LOG.ERROR >= LOGLEVEL) Log.e(tag, s);
- }
-
- /**
- * Verbose log message.
- *
- * @param tag
- * @param s
- * @param e
- */
- public static void v(String tag, String s, Throwable e) {
- if (LOG.VERBOSE >= LOGLEVEL) Log.v(tag, s, e);
- }
-
- /**
- * Debug log message.
- *
- * @param tag
- * @param s
- * @param e
- */
- public static void d(String tag, String s, Throwable e) {
- if (LOG.DEBUG >= LOGLEVEL) Log.d(tag, s, e);
- }
-
- /**
- * Info log message.
- *
- * @param tag
- * @param s
- * @param e
- */
- public static void i(String tag, String s, Throwable e) {
- if (LOG.INFO >= LOGLEVEL) Log.i(tag, s, e);
- }
-
- /**
- * Warning log message.
- *
- * @param tag
- * @param e
- */
- public static void w(String tag, Throwable e) {
- if (LOG.WARN >= LOGLEVEL) Log.w(tag, e);
- }
-
- /**
- * Warning log message.
- *
- * @param tag
- * @param s
- * @param e
- */
- public static void w(String tag, String s, Throwable e) {
- if (LOG.WARN >= LOGLEVEL) Log.w(tag, s, e);
- }
-
- /**
- * Error log message.
- *
- * @param tag
- * @param s
- * @param e
- */
- public static void e(String tag, String s, Throwable e) {
- if (LOG.ERROR >= LOGLEVEL) Log.e(tag, s, e);
- }
-
- /**
- * Verbose log message with printf formatting.
- *
- * @param tag
- * @param s
- * @param args
- */
- public static void v(String tag, String s, Object... args) {
- if (LOG.VERBOSE >= LOGLEVEL) Log.v(tag, String.format(s, args));
- }
-
- /**
- * Debug log message with printf formatting.
- *
- * @param tag
- * @param s
- * @param args
- */
- public static void d(String tag, String s, Object... args) {
- if (LOG.DEBUG >= LOGLEVEL) Log.d(tag, String.format(s, args));
- }
-
- /**
- * Info log message with printf formatting.
- *
- * @param tag
- * @param s
- * @param args
- */
- public static void i(String tag, String s, Object... args) {
- if (LOG.INFO >= LOGLEVEL) Log.i(tag, String.format(s, args));
- }
-
- /**
- * Warning log message with printf formatting.
- *
- * @param tag
- * @param s
- * @param args
- */
- public static void w(String tag, String s, Object... args) {
- if (LOG.WARN >= LOGLEVEL) Log.w(tag, String.format(s, args));
- }
-
- /**
- * Error log message with printf formatting.
- *
- * @param tag
- * @param s
- * @param args
- */
- public static void e(String tag, String s, Object... args) {
- if (LOG.ERROR >= LOGLEVEL) Log.e(tag, String.format(s, args));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/NativeToJsMessageQueue.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/NativeToJsMessageQueue.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/NativeToJsMessageQueue.java
deleted file mode 100755
index a8f59fa..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- 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;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-
-/**
- * Holds the list of messages to be sent to the WebView.
- */
-public class NativeToJsMessageQueue {
- private static final String LOG_TAG = "JsMessageQueue";
-
- // Set this to true to force plugin results to be encoding as
- // JS instead of the custom format (useful for benchmarking).
- // Doesn't work for multipart messages.
- private static final boolean FORCE_ENCODE_USING_EVAL = false;
-
- // Disable sending back native->JS messages during an exec() when the active
- // exec() is asynchronous. Set this to true when running bridge benchmarks.
- static final boolean DISABLE_EXEC_CHAINING = false;
-
- // Arbitrarily chosen upper limit for how much data to send to JS in one shot.
- // This currently only chops up on message boundaries. It may be useful
- // to allow it to break up messages.
- private static int MAX_PAYLOAD_SIZE = 50 * 1024 * 10240;
-
- /**
- * When true, the active listener is not fired upon enqueue. When set to false,
- * the active listener will be fired if the queue is non-empty.
- */
- private boolean paused;
-
- /**
- * The list of JavaScript statements to be sent to JavaScript.
- */
- private final LinkedList<JsMessage> queue = new LinkedList<JsMessage>();
-
- /**
- * The array of listeners that can be used to send messages to JS.
- */
- private ArrayList<BridgeMode> bridgeModes = new ArrayList<BridgeMode>();
-
- /**
- * When null, the bridge is disabled. This occurs during page transitions.
- * When disabled, all callbacks are dropped since they are assumed to be
- * relevant to the previous page.
- */
- private BridgeMode activeBridgeMode;
-
- public void addBridgeMode(BridgeMode bridgeMode) {
- bridgeModes.add(bridgeMode);
- }
-
- public boolean isBridgeEnabled() {
- return activeBridgeMode != null;
- }
-
- public boolean isEmpty() {
- return queue.isEmpty();
- }
-
- /**
- * Changes the bridge mode.
- */
- public void setBridgeMode(int value) {
- if (value < -1 || value >= bridgeModes.size()) {
- LOG.d(LOG_TAG, "Invalid NativeToJsBridgeMode: " + value);
- } else {
- BridgeMode newMode = value < 0 ? null : bridgeModes.get(value);
- if (newMode != activeBridgeMode) {
- LOG.d(LOG_TAG, "Set native->JS mode to " + (newMode == null ? "null" : newMode.getClass().getSimpleName()));
- synchronized (this) {
- activeBridgeMode = newMode;
- if (newMode != null) {
- newMode.reset();
- if (!paused && !queue.isEmpty()) {
- newMode.onNativeToJsMessageAvailable(this);
- }
- }
- }
- }
- }
- }
-
- /**
- * Clears all messages and resets to the default bridge mode.
- */
- public void reset() {
- synchronized (this) {
- queue.clear();
- setBridgeMode(-1);
- }
- }
-
- private int calculatePackedMessageLength(JsMessage message) {
- int messageLen = message.calculateEncodedLength();
- String messageLenStr = String.valueOf(messageLen);
- return messageLenStr.length() + messageLen + 1;
- }
-
- private void packMessage(JsMessage message, StringBuilder sb) {
- int len = message.calculateEncodedLength();
- sb.append(len)
- .append(' ');
- message.encodeAsMessage(sb);
- }
-
- /**
- * Combines and returns queued messages combined into a single string.
- * Combines as many messages as possible, while staying under MAX_PAYLOAD_SIZE.
- * Returns null if the queue is empty.
- */
- public String popAndEncode(boolean fromOnlineEvent) {
- synchronized (this) {
- if (activeBridgeMode == null) {
- return null;
- }
- activeBridgeMode.notifyOfFlush(this, fromOnlineEvent);
- if (queue.isEmpty()) {
- return null;
- }
- int totalPayloadLen = 0;
- int numMessagesToSend = 0;
- for (JsMessage message : queue) {
- int messageSize = calculatePackedMessageLength(message);
- if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) {
- break;
- }
- totalPayloadLen += messageSize;
- numMessagesToSend += 1;
- }
-
- StringBuilder sb = new StringBuilder(totalPayloadLen);
- for (int i = 0; i < numMessagesToSend; ++i) {
- JsMessage message = queue.removeFirst();
- packMessage(message, sb);
- }
-
- if (!queue.isEmpty()) {
- // Attach a char to indicate that there are more messages pending.
- sb.append('*');
- }
- String ret = sb.toString();
- return ret;
- }
- }
-
- /**
- * Same as popAndEncode(), except encodes in a form that can be executed as JS.
- */
- public String popAndEncodeAsJs() {
- synchronized (this) {
- int length = queue.size();
- if (length == 0) {
- return null;
- }
- int totalPayloadLen = 0;
- int numMessagesToSend = 0;
- for (JsMessage message : queue) {
- int messageSize = message.calculateEncodedLength() + 50; // overestimate.
- if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) {
- break;
- }
- totalPayloadLen += messageSize;
- numMessagesToSend += 1;
- }
- boolean willSendAllMessages = numMessagesToSend == queue.size();
- StringBuilder sb = new StringBuilder(totalPayloadLen + (willSendAllMessages ? 0 : 100));
- // Wrap each statement in a try/finally so that if one throws it does
- // not affect the next.
- for (int i = 0; i < numMessagesToSend; ++i) {
- JsMessage message = queue.removeFirst();
- if (willSendAllMessages && (i + 1 == numMessagesToSend)) {
- message.encodeAsJsMessage(sb);
- } else {
- sb.append("try{");
- message.encodeAsJsMessage(sb);
- sb.append("}finally{");
- }
- }
- if (!willSendAllMessages) {
- sb.append("window.setTimeout(function(){cordova.require('cordova/plugin/android/polling').pollOnce();},0);");
- }
- for (int i = willSendAllMessages ? 1 : 0; i < numMessagesToSend; ++i) {
- sb.append('}');
- }
- String ret = sb.toString();
- return ret;
- }
- }
-
- /**
- * Add a JavaScript statement to the list.
- */
- public void addJavaScript(String statement) {
- enqueueMessage(new JsMessage(statement));
- }
-
- /**
- * Add a JavaScript statement to the list.
- */
- public void addPluginResult(PluginResult result, String callbackId) {
- if (callbackId == null) {
- LOG.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
- return;
- }
- // Don't send anything if there is no result and there is no need to
- // clear the callbacks.
- boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
- boolean keepCallback = result.getKeepCallback();
- if (noResult && keepCallback) {
- return;
- }
- JsMessage message = new JsMessage(result, callbackId);
- if (FORCE_ENCODE_USING_EVAL) {
- StringBuilder sb = new StringBuilder(message.calculateEncodedLength() + 50);
- message.encodeAsJsMessage(sb);
- message = new JsMessage(sb.toString());
- }
-
- enqueueMessage(message);
- }
-
- private void enqueueMessage(JsMessage message) {
- synchronized (this) {
- if (activeBridgeMode == null) {
- LOG.d(LOG_TAG, "Dropping Native->JS message due to disabled bridge");
- return;
- }
- queue.add(message);
- if (!paused) {
- activeBridgeMode.onNativeToJsMessageAvailable(this);
- }
- }
- }
-
- public void setPaused(boolean value) {
- if (paused && value) {
- // This should never happen. If a use-case for it comes up, we should
- // change pause to be a counter.
- LOG.e(LOG_TAG, "nested call to setPaused detected.", new Throwable());
- }
- paused = value;
- if (!value) {
- synchronized (this) {
- if (!queue.isEmpty() && activeBridgeMode != null) {
- activeBridgeMode.onNativeToJsMessageAvailable(this);
- }
- }
- }
- }
-
- public static abstract class BridgeMode {
- public abstract void onNativeToJsMessageAvailable(NativeToJsMessageQueue queue);
- public void notifyOfFlush(NativeToJsMessageQueue queue, boolean fromOnlineEvent) {}
- public void reset() {}
- }
-
- /** Uses JS polls for messages on a timer.. */
- public static class NoOpBridgeMode extends BridgeMode {
- @Override public void onNativeToJsMessageAvailable(NativeToJsMessageQueue queue) {
- }
- }
-
- /** Uses webView.loadUrl("javascript:") to execute messages. */
- public static class LoadUrlBridgeMode extends BridgeMode {
- private final CordovaWebViewEngine engine;
- private final CordovaInterface cordova;
-
- public LoadUrlBridgeMode(CordovaWebViewEngine engine, CordovaInterface cordova) {
- this.engine = engine;
- this.cordova = cordova;
- }
-
- @Override
- public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- String js = queue.popAndEncodeAsJs();
- if (js != null) {
- engine.loadUrl("javascript:" + js, false);
- }
- }
- });
- }
- }
-
- /** Uses online/offline events to tell the JS when to poll for messages. */
- public static class OnlineEventsBridgeMode extends BridgeMode {
- private final OnlineEventsBridgeModeDelegate delegate;
- private boolean online;
- private boolean ignoreNextFlush;
-
- public interface OnlineEventsBridgeModeDelegate {
- void setNetworkAvailable(boolean value);
- void runOnUiThread(Runnable r);
- }
-
- public OnlineEventsBridgeMode(OnlineEventsBridgeModeDelegate delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public void reset() {
- delegate.runOnUiThread(new Runnable() {
- public void run() {
- online = false;
- // If the following call triggers a notifyOfFlush, then ignore it.
- ignoreNextFlush = true;
- delegate.setNetworkAvailable(true);
- }
- });
- }
-
- @Override
- public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
- delegate.runOnUiThread(new Runnable() {
- public void run() {
- if (!queue.isEmpty()) {
- ignoreNextFlush = false;
- delegate.setNetworkAvailable(online);
- }
- }
- });
- }
- // Track when online/offline events are fired so that we don't fire excess events.
- @Override
- public void notifyOfFlush(final NativeToJsMessageQueue queue, boolean fromOnlineEvent) {
- if (fromOnlineEvent && !ignoreNextFlush) {
- online = !online;
- }
- }
- }
-
- /** Uses webView.evaluateJavascript to execute messages. */
- public static class EvalBridgeMode extends BridgeMode {
- private final CordovaWebViewEngine engine;
- private final CordovaInterface cordova;
-
- public EvalBridgeMode(CordovaWebViewEngine engine, CordovaInterface cordova) {
- this.engine = engine;
- this.cordova = cordova;
- }
-
- @Override
- public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- String js = queue.popAndEncodeAsJs();
- if (js != null) {
- engine.evaluateJavascript(js, null);
- }
- }
- });
- }
- }
-
-
-
- private static class JsMessage {
- final String jsPayloadOrCallbackId;
- final PluginResult pluginResult;
- JsMessage(String js) {
- if (js == null) {
- throw new NullPointerException();
- }
- jsPayloadOrCallbackId = js;
- pluginResult = null;
- }
- JsMessage(PluginResult pluginResult, String callbackId) {
- if (callbackId == null || pluginResult == null) {
- throw new NullPointerException();
- }
- jsPayloadOrCallbackId = callbackId;
- this.pluginResult = pluginResult;
- }
-
- static int calculateEncodedLengthHelper(PluginResult pluginResult) {
- switch (pluginResult.getMessageType()) {
- case PluginResult.MESSAGE_TYPE_BOOLEAN: // f or t
- case PluginResult.MESSAGE_TYPE_NULL: // N
- return 1;
- case PluginResult.MESSAGE_TYPE_NUMBER: // n
- return 1 + pluginResult.getMessage().length();
- case PluginResult.MESSAGE_TYPE_STRING: // s
- return 1 + pluginResult.getStrMessage().length();
- case PluginResult.MESSAGE_TYPE_BINARYSTRING:
- return 1 + pluginResult.getMessage().length();
- case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
- return 1 + pluginResult.getMessage().length();
- case PluginResult.MESSAGE_TYPE_MULTIPART:
- int ret = 1;
- for (int i = 0; i < pluginResult.getMultipartMessagesSize(); i++) {
- int length = calculateEncodedLengthHelper(pluginResult.getMultipartMessage(i));
- int argLength = String.valueOf(length).length();
- ret += argLength + 1 + length;
- }
- return ret;
- case PluginResult.MESSAGE_TYPE_JSON:
- default:
- return pluginResult.getMessage().length();
- }
- }
-
- int calculateEncodedLength() {
- if (pluginResult == null) {
- return jsPayloadOrCallbackId.length() + 1;
- }
- int statusLen = String.valueOf(pluginResult.getStatus()).length();
- int ret = 2 + statusLen + 1 + jsPayloadOrCallbackId.length() + 1;
- return ret + calculateEncodedLengthHelper(pluginResult);
- }
-
- static void encodeAsMessageHelper(StringBuilder sb, PluginResult pluginResult) {
- switch (pluginResult.getMessageType()) {
- case PluginResult.MESSAGE_TYPE_BOOLEAN:
- sb.append(pluginResult.getMessage().charAt(0)); // t or f.
- break;
- case PluginResult.MESSAGE_TYPE_NULL: // N
- sb.append('N');
- break;
- case PluginResult.MESSAGE_TYPE_NUMBER: // n
- sb.append('n')
- .append(pluginResult.getMessage());
- break;
- case PluginResult.MESSAGE_TYPE_STRING: // s
- sb.append('s');
- sb.append(pluginResult.getStrMessage());
- break;
- case PluginResult.MESSAGE_TYPE_BINARYSTRING: // S
- sb.append('S');
- sb.append(pluginResult.getMessage());
- break;
- case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: // A
- sb.append('A');
- sb.append(pluginResult.getMessage());
- break;
- case PluginResult.MESSAGE_TYPE_MULTIPART:
- sb.append('M');
- for (int i = 0; i < pluginResult.getMultipartMessagesSize(); i++) {
- PluginResult multipartMessage = pluginResult.getMultipartMessage(i);
- sb.append(String.valueOf(calculateEncodedLengthHelper(multipartMessage)));
- sb.append(' ');
- encodeAsMessageHelper(sb, multipartMessage);
- }
- break;
- case PluginResult.MESSAGE_TYPE_JSON:
- default:
- sb.append(pluginResult.getMessage()); // [ or {
- }
- }
-
- void encodeAsMessage(StringBuilder sb) {
- if (pluginResult == null) {
- sb.append('J')
- .append(jsPayloadOrCallbackId);
- return;
- }
- int status = pluginResult.getStatus();
- boolean noResult = status == PluginResult.Status.NO_RESULT.ordinal();
- boolean resultOk = status == PluginResult.Status.OK.ordinal();
- boolean keepCallback = pluginResult.getKeepCallback();
-
- sb.append((noResult || resultOk) ? 'S' : 'F')
- .append(keepCallback ? '1' : '0')
- .append(status)
- .append(' ')
- .append(jsPayloadOrCallbackId)
- .append(' ');
-
- encodeAsMessageHelper(sb, pluginResult);
- }
-
- void buildJsMessage(StringBuilder sb) {
- switch (pluginResult.getMessageType()) {
- case PluginResult.MESSAGE_TYPE_MULTIPART:
- int size = pluginResult.getMultipartMessagesSize();
- for (int i=0; i<size; i++) {
- PluginResult subresult = pluginResult.getMultipartMessage(i);
- JsMessage submessage = new JsMessage(subresult, jsPayloadOrCallbackId);
- submessage.buildJsMessage(sb);
- if (i < (size-1)) {
- sb.append(",");
- }
- }
- break;
- case PluginResult.MESSAGE_TYPE_BINARYSTRING:
- sb.append("atob('")
- .append(pluginResult.getMessage())
- .append("')");
- break;
- case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
- sb.append("cordova.require('cordova/base64').toArrayBuffer('")
- .append(pluginResult.getMessage())
- .append("')");
- break;
- default:
- sb.append(pluginResult.getMessage());
- }
- }
-
- void encodeAsJsMessage(StringBuilder sb) {
- if (pluginResult == null) {
- sb.append(jsPayloadOrCallbackId);
- } else {
- int status = pluginResult.getStatus();
- boolean success = (status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal());
- sb.append("cordova.callbackFromNative('")
- .append(jsPayloadOrCallbackId)
- .append("',")
- .append(success)
- .append(",")
- .append(status)
- .append(",[");
- buildJsMessage(sb);
- sb.append("],")
- .append(pluginResult.getKeepCallback())
- .append(");");
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginEntry.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginEntry.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginEntry.java
deleted file mode 100755
index c56c453..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginEntry.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- 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;
-
-import org.apache.cordova.CordovaPlugin;
-
-/**
- * This class represents a service entry object.
- */
-public final class PluginEntry {
-
- /**
- * The name of the service that this plugin implements
- */
- public final String service;
-
- /**
- * The plugin class name that implements the service.
- */
- public final String pluginClass;
-
- /**
- * The pre-instantiated plugin to use for this entry.
- */
- public final CordovaPlugin plugin;
-
- /**
- * Flag that indicates the plugin object should be created when PluginManager is initialized.
- */
- public final boolean onload;
-
- /**
- * Constructs with a CordovaPlugin already instantiated.
- */
- public PluginEntry(String service, CordovaPlugin plugin) {
- this(service, plugin.getClass().getName(), true, plugin);
- }
-
- /**
- * @param service The name of the service
- * @param pluginClass The plugin class name
- * @param onload Create plugin object when HTML page is loaded
- */
- public PluginEntry(String service, String pluginClass, boolean onload) {
- this(service, pluginClass, onload, null);
- }
-
- private PluginEntry(String service, String pluginClass, boolean onload, CordovaPlugin plugin) {
- this.service = service;
- this.pluginClass = pluginClass;
- this.onload = onload;
- this.plugin = plugin;
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginManager.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginManager.java
deleted file mode 100755
index c9576a6..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginManager.java
+++ /dev/null
@@ -1,526 +0,0 @@
-/*
- 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;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-
-import org.json.JSONException;
-
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Debug;
-
-/**
- * PluginManager is exposed to JavaScript in the Cordova WebView.
- *
- * Calling native plugin code can be done by calling PluginManager.exec(...)
- * from JavaScript.
- */
-public class PluginManager {
- private static String TAG = "PluginManager";
- private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug.isDebuggerConnected() ? 60 : 16;
-
- // List of service entries
- private final LinkedHashMap<String, CordovaPlugin> pluginMap = new LinkedHashMap<String, CordovaPlugin>();
- private final LinkedHashMap<String, PluginEntry> entryMap = new LinkedHashMap<String, PluginEntry>();
-
- private final CordovaInterface ctx;
- private final CordovaWebView app;
- private boolean isInitialized;
-
- private CordovaPlugin permissionRequester;
-
- public PluginManager(CordovaWebView cordovaWebView, CordovaInterface cordova, Collection<PluginEntry> pluginEntries) {
- this.ctx = cordova;
- this.app = cordovaWebView;
- setPluginEntries(pluginEntries);
- }
-
- public Collection<PluginEntry> getPluginEntries() {
- return entryMap.values();
- }
-
- public void setPluginEntries(Collection<PluginEntry> pluginEntries) {
- if (isInitialized) {
- this.onPause(false);
- this.onDestroy();
- pluginMap.clear();
- entryMap.clear();
- }
- for (PluginEntry entry : pluginEntries) {
- addService(entry);
- }
- if (isInitialized) {
- startupPlugins();
- }
- }
-
- /**
- * Init when loading a new HTML page into webview.
- */
- public void init() {
- LOG.d(TAG, "init()");
- isInitialized = true;
- this.onPause(false);
- this.onDestroy();
- pluginMap.clear();
- this.startupPlugins();
- }
-
- /**
- * Create plugins objects that have onload set.
- */
- private void startupPlugins() {
- for (PluginEntry entry : entryMap.values()) {
- // Add a null entry to for each non-startup plugin to avoid ConcurrentModificationException
- // When iterating plugins.
- if (entry.onload) {
- getPlugin(entry.service);
- } else {
- pluginMap.put(entry.service, null);
- }
- }
- }
-
- /**
- * Receives a request for execution and fulfills it by finding the appropriate
- * Java class and calling it's execute method.
- *
- * PluginManager.exec can be used either synchronously or async. In either case, a JSON encoded
- * string is returned that will indicate if any errors have occurred when trying to find
- * or execute the class denoted by the clazz argument.
- *
- * @param service String containing the service to run
- * @param action String containing the action that the class is supposed to perform. This is
- * passed to the plugin execute method and it is up to the plugin developer
- * how to deal with it.
- * @param callbackId String containing the id of the callback that is execute in JavaScript if
- * this is an async plugin call.
- * @param rawArgs An Array literal string containing any arguments needed in the
- * plugin execute method.
- */
- public void exec(final String service, final String action, final String callbackId, final String rawArgs) {
- CordovaPlugin plugin = getPlugin(service);
- if (plugin == null) {
- LOG.d(TAG, "exec() call to unknown plugin: " + service);
- PluginResult cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
- app.sendPluginResult(cr, callbackId);
- return;
- }
- CallbackContext callbackContext = new CallbackContext(callbackId, app);
- try {
- long pluginStartTime = System.currentTimeMillis();
- boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext);
- long duration = System.currentTimeMillis() - pluginStartTime;
-
- if (duration > SLOW_EXEC_WARNING_THRESHOLD) {
- LOG.w(TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool().");
- }
- if (!wasValidAction) {
- PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
- callbackContext.sendPluginResult(cr);
- }
- } catch (JSONException e) {
- PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
- callbackContext.sendPluginResult(cr);
- } catch (Exception e) {
- LOG.e(TAG, "Uncaught exception from plugin", e);
- callbackContext.error(e.getMessage());
- }
- }
-
- /**
- * Get the plugin object that implements the service.
- * If the plugin object does not already exist, then create it.
- * If the service doesn't exist, then return null.
- *
- * @param service The name of the service.
- * @return CordovaPlugin or null
- */
- public CordovaPlugin getPlugin(String service) {
- CordovaPlugin ret = pluginMap.get(service);
- if (ret == null) {
- PluginEntry pe = entryMap.get(service);
- if (pe == null) {
- return null;
- }
- if (pe.plugin != null) {
- ret = pe.plugin;
- } else {
- ret = instantiatePlugin(pe.pluginClass);
- }
- ret.privateInitialize(service, ctx, app, app.getPreferences());
- pluginMap.put(service, ret);
- }
- return ret;
- }
-
- /**
- * Add a plugin class that implements a service to the service entry table.
- * This does not create the plugin object instance.
- *
- * @param service The service name
- * @param className The plugin class name
- */
- public void addService(String service, String className) {
- PluginEntry entry = new PluginEntry(service, className, false);
- this.addService(entry);
- }
-
- /**
- * Add a plugin class that implements a service to the service entry table.
- * This does not create the plugin object instance.
- *
- * @param entry The plugin entry
- */
- public void addService(PluginEntry entry) {
- this.entryMap.put(entry.service, entry);
- if (entry.plugin != null) {
- entry.plugin.privateInitialize(entry.service, ctx, app, app.getPreferences());
- pluginMap.put(entry.service, entry.plugin);
- }
- }
-
- /**
- * Called when the system is about to start resuming a previous activity.
- *
- * @param multitasking Flag indicating if multitasking is turned on for app
- */
- public void onPause(boolean multitasking) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onPause(multitasking);
- }
- }
- }
-
- /**
- * Called when the system received an HTTP authentication request. Plugins can use
- * the supplied HttpAuthHandler to process this auth challenge.
- *
- * @param view The WebView that is initiating the callback
- * @param handler The HttpAuthHandler used to set the WebView's response
- * @param host The host requiring authentication
- * @param realm The realm for which authentication is required
- *
- * @return Returns True if there is a plugin which will resolve this auth challenge, otherwise False
- *
- */
- public boolean onReceivedHttpAuthRequest(CordovaWebView view, ICordovaHttpAuthHandler handler, String host, String realm) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null && plugin.onReceivedHttpAuthRequest(app, handler, host, realm)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Called when he system received an SSL client certificate request. Plugin can use
- * the supplied ClientCertRequest to process this certificate challenge.
- *
- * @param view The WebView that is initiating the callback
- * @param request The client certificate request
- *
- * @return Returns True if plugin will resolve this auth challenge, otherwise False
- *
- */
- public boolean onReceivedClientCertRequest(CordovaWebView view, ICordovaClientCertRequest request) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null && plugin.onReceivedClientCertRequest(app, request)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Called when the activity will start interacting with the user.
- *
- * @param multitasking Flag indicating if multitasking is turned on for app
- */
- public void onResume(boolean multitasking) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onResume(multitasking);
- }
- }
- }
-
- /**
- * Called when the activity is becoming visible to the user.
- */
- public void onStart() {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onStart();
- }
- }
- }
-
- /**
- * Called when the activity is no longer visible to the user.
- */
- public void onStop() {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onStop();
- }
- }
- }
-
- /**
- * The final call you receive before your activity is destroyed.
- */
- public void onDestroy() {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onDestroy();
- }
- }
- }
-
- /**
- * Send a message to all plugins.
- *
- * @param id The message id
- * @param data The message data
- * @return Object to stop propagation or null
- */
- public Object postMessage(String id, Object data) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- Object obj = plugin.onMessage(id, data);
- if (obj != null) {
- return obj;
- }
- }
- }
- return ctx.onMessage(id, data);
- }
-
- /**
- * Called when the activity receives a new intent.
- */
- public void onNewIntent(Intent intent) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onNewIntent(intent);
- }
- }
- }
-
- /**
- * Called when the webview is going to request an external resource.
- *
- * This delegates to the installed plugins, and returns true/false for the
- * first plugin to provide a non-null result. If no plugins respond, then
- * the default policy is applied.
- *
- * @param url The URL that is being requested.
- * @return Returns true to allow the resource to load,
- * false to block the resource.
- */
- public boolean shouldAllowRequest(String url) {
- for (PluginEntry entry : this.entryMap.values()) {
- CordovaPlugin plugin = pluginMap.get(entry.service);
- if (plugin != null) {
- Boolean result = plugin.shouldAllowRequest(url);
- if (result != null) {
- return result;
- }
- }
- }
-
- // Default policy:
- if (url.startsWith("blob:") || url.startsWith("data:") || url.startsWith("about:blank")) {
- return true;
- }
- // TalkBack requires this, so allow it by default.
- if (url.startsWith("https://ssl.gstatic.com/accessibility/javascript/android/")) {
- return true;
- }
- if (url.startsWith("file://")) {
- //This directory on WebKit/Blink based webviews contains SQLite databases!
- //DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
- return !url.contains("/app_webview/");
- }
- return false;
- }
-
- /**
- * Called when the webview is going to change the URL of the loaded content.
- *
- * This delegates to the installed plugins, and returns true/false for the
- * first plugin to provide a non-null result. If no plugins respond, then
- * the default policy is applied.
- *
- * @param url The URL that is being requested.
- * @return Returns true to allow the navigation,
- * false to block the navigation.
- */
- public boolean shouldAllowNavigation(String url) {
- for (PluginEntry entry : this.entryMap.values()) {
- CordovaPlugin plugin = pluginMap.get(entry.service);
- if (plugin != null) {
- Boolean result = plugin.shouldAllowNavigation(url);
- if (result != null) {
- return result;
- }
- }
- }
-
- // Default policy:
- return url.startsWith("file://") || url.startsWith("about:blank");
- }
-
-
- /**
- * Called when the webview is requesting the exec() bridge be enabled.
- */
- public boolean shouldAllowBridgeAccess(String url) {
- for (PluginEntry entry : this.entryMap.values()) {
- CordovaPlugin plugin = pluginMap.get(entry.service);
- if (plugin != null) {
- Boolean result = plugin.shouldAllowBridgeAccess(url);
- if (result != null) {
- return result;
- }
- }
- }
-
- // Default policy:
- return url.startsWith("file://");
- }
-
- /**
- * Called when the webview is going not going to navigate, but may launch
- * an Intent for an URL.
- *
- * This delegates to the installed plugins, and returns true/false for the
- * first plugin to provide a non-null result. If no plugins respond, then
- * the default policy is applied.
- *
- * @param url The URL that is being requested.
- * @return Returns true to allow the URL to launch an intent,
- * false to block the intent.
- */
- public Boolean shouldOpenExternalUrl(String url) {
- for (PluginEntry entry : this.entryMap.values()) {
- CordovaPlugin plugin = pluginMap.get(entry.service);
- if (plugin != null) {
- Boolean result = plugin.shouldOpenExternalUrl(url);
- if (result != null) {
- return result;
- }
- }
- }
- // Default policy:
- // External URLs are not allowed
- return false;
- }
-
- /**
- * Called when the URL of the webview changes.
- *
- * @param url The URL that is being changed to.
- * @return Return false to allow the URL to load, return true to prevent the URL from loading.
- */
- public boolean onOverrideUrlLoading(String url) {
- for (PluginEntry entry : this.entryMap.values()) {
- CordovaPlugin plugin = pluginMap.get(entry.service);
- if (plugin != null && plugin.onOverrideUrlLoading(url)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Called when the app navigates or refreshes.
- */
- public void onReset() {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onReset();
- }
- }
- }
-
- Uri remapUri(Uri uri) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- Uri ret = plugin.remapUri(uri);
- if (ret != null) {
- return ret;
- }
- }
- }
- return null;
- }
-
- /**
- * Create a plugin based on class name.
- */
- private CordovaPlugin instantiatePlugin(String className) {
- CordovaPlugin ret = null;
- try {
- Class<?> c = null;
- if ((className != null) && !("".equals(className))) {
- c = Class.forName(className);
- }
- if (c != null & CordovaPlugin.class.isAssignableFrom(c)) {
- ret = (CordovaPlugin) c.newInstance();
- }
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("Error adding plugin " + className + ".");
- }
- return ret;
- }
-
- /**
- * Called by the system when the device configuration changes while your activity is running.
- *
- * @param newConfig The new device configuration
- */
- public void onConfigurationChanged(Configuration newConfig) {
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- plugin.onConfigurationChanged(newConfig);
- }
- }
- }
-
- public Bundle onSaveInstanceState() {
- Bundle state = new Bundle();
- for (CordovaPlugin plugin : this.pluginMap.values()) {
- if (plugin != null) {
- Bundle pluginState = plugin.onSaveInstanceState();
- if(pluginState != null) {
- state.putBundle(plugin.getServiceName(), pluginState);
- }
- }
- }
- return state;
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginResult.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginResult.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginResult.java
deleted file mode 100644
index 2b3ac72..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/PluginResult.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- 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;
-
-import java.util.List;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import android.util.Base64;
-
-public class PluginResult {
- private final int status;
- private final int messageType;
- private boolean keepCallback = false;
- private String strMessage;
- private String encodedMessage;
- private List<PluginResult> multipartMessages;
-
- public PluginResult(Status status) {
- this(status, PluginResult.StatusMessages[status.ordinal()]);
- }
-
- public PluginResult(Status status, String message) {
- this.status = status.ordinal();
- this.messageType = message == null ? MESSAGE_TYPE_NULL : MESSAGE_TYPE_STRING;
- this.strMessage = message;
- }
-
- public PluginResult(Status status, JSONArray message) {
- this.status = status.ordinal();
- this.messageType = MESSAGE_TYPE_JSON;
- encodedMessage = message.toString();
- }
-
- public PluginResult(Status status, JSONObject message) {
- this.status = status.ordinal();
- this.messageType = MESSAGE_TYPE_JSON;
- encodedMessage = message.toString();
- }
-
- public PluginResult(Status status, int i) {
- this.status = status.ordinal();
- this.messageType = MESSAGE_TYPE_NUMBER;
- this.encodedMessage = ""+i;
- }
-
- public PluginResult(Status status, float f) {
- this.status = status.ordinal();
- this.messageType = MESSAGE_TYPE_NUMBER;
- this.encodedMessage = ""+f;
- }
-
- public PluginResult(Status status, boolean b) {
- this.status = status.ordinal();
- this.messageType = MESSAGE_TYPE_BOOLEAN;
- this.encodedMessage = Boolean.toString(b);
- }
-
- public PluginResult(Status status, byte[] data) {
- this(status, data, false);
- }
-
- public PluginResult(Status status, byte[] data, boolean binaryString) {
- this.status = status.ordinal();
- this.messageType = binaryString ? MESSAGE_TYPE_BINARYSTRING : MESSAGE_TYPE_ARRAYBUFFER;
- this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
- }
-
- // The keepCallback and status of multipartMessages are ignored.
- public PluginResult(Status status, List<PluginResult> multipartMessages) {
- this.status = status.ordinal();
- this.messageType = MESSAGE_TYPE_MULTIPART;
- this.multipartMessages = multipartMessages;
- }
-
- public void setKeepCallback(boolean b) {
- this.keepCallback = b;
- }
-
- public int getStatus() {
- return status;
- }
-
- public int getMessageType() {
- return messageType;
- }
-
- public String getMessage() {
- if (encodedMessage == null) {
- encodedMessage = JSONObject.quote(strMessage);
- }
- return encodedMessage;
- }
-
- public int getMultipartMessagesSize() {
- return multipartMessages.size();
- }
-
- public PluginResult getMultipartMessage(int index) {
- return multipartMessages.get(index);
- }
-
- /**
- * If messageType == MESSAGE_TYPE_STRING, then returns the message string.
- * Otherwise, returns null.
- */
- public String getStrMessage() {
- return strMessage;
- }
-
- public boolean getKeepCallback() {
- return this.keepCallback;
- }
-
- @Deprecated // Use sendPluginResult instead of sendJavascript.
- public String getJSONString() {
- return "{\"status\":" + this.status + ",\"message\":" + this.getMessage() + ",\"keepCallback\":" + this.keepCallback + "}";
- }
-
- @Deprecated // Use sendPluginResult instead of sendJavascript.
- public String toCallbackString(String callbackId) {
- // If no result to be sent and keeping callback, then no need to sent back to JavaScript
- if ((status == PluginResult.Status.NO_RESULT.ordinal()) && keepCallback) {
- return null;
- }
-
- // Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
- if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
- return toSuccessCallbackString(callbackId);
- }
-
- return toErrorCallbackString(callbackId);
- }
-
- @Deprecated // Use sendPluginResult instead of sendJavascript.
- public String toSuccessCallbackString(String callbackId) {
- return "cordova.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
- }
-
- @Deprecated // Use sendPluginResult instead of sendJavascript.
- public String toErrorCallbackString(String callbackId) {
- return "cordova.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
- }
-
- public static final int MESSAGE_TYPE_STRING = 1;
- public static final int MESSAGE_TYPE_JSON = 2;
- public static final int MESSAGE_TYPE_NUMBER = 3;
- public static final int MESSAGE_TYPE_BOOLEAN = 4;
- public static final int MESSAGE_TYPE_NULL = 5;
- public static final int MESSAGE_TYPE_ARRAYBUFFER = 6;
- // Use BINARYSTRING when your string may contain null characters.
- // This is required to work around a bug in the platform :(.
- public static final int MESSAGE_TYPE_BINARYSTRING = 7;
- public static final int MESSAGE_TYPE_MULTIPART = 8;
-
- public static String[] StatusMessages = new String[] {
- "No result",
- "OK",
- "Class not found",
- "Illegal access",
- "Instantiation error",
- "Malformed url",
- "IO error",
- "Invalid action",
- "JSON error",
- "Error"
- };
-
- public enum Status {
- NO_RESULT,
- OK,
- CLASS_NOT_FOUND_EXCEPTION,
- ILLEGAL_ACCESS_EXCEPTION,
- INSTANTIATION_EXCEPTION,
- MALFORMED_URL_EXCEPTION,
- IO_EXCEPTION,
- INVALID_ACTION,
- JSON_EXCEPTION,
- ERROR
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ResumeCallback.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ResumeCallback.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ResumeCallback.java
deleted file mode 100644
index 49a43b5..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/ResumeCallback.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- 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;
-
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ResumeCallback extends CallbackContext {
- private final String TAG = "CordovaResumeCallback";
- private String serviceName;
- private PluginManager pluginManager;
-
- public ResumeCallback(String serviceName, PluginManager pluginManager) {
- super("resumecallback", null);
- this.serviceName = serviceName;
- this.pluginManager = pluginManager;
- }
-
- @Override
- public void sendPluginResult(PluginResult pluginResult) {
- synchronized (this) {
- if (finished) {
- LOG.w(TAG, serviceName + " attempted to send a second callback to ResumeCallback\nResult was: " + pluginResult.getMessage());
- return;
- } else {
- finished = true;
- }
- }
-
- JSONObject event = new JSONObject();
- JSONObject pluginResultObject = new JSONObject();
-
- try {
- pluginResultObject.put("pluginServiceName", this.serviceName);
- pluginResultObject.put("pluginStatus", PluginResult.StatusMessages[pluginResult.getStatus()]);
-
- event.put("action", "resume");
- event.put("pendingResult", pluginResultObject);
- } catch (JSONException e) {
- LOG.e(TAG, "Unable to create resume object for Activity Result");
- }
-
- PluginResult eventResult = new PluginResult(PluginResult.Status.OK, event);
-
- // We send a list of results to the js so that we don't have to decode
- // the PluginResult passed to this CallbackContext into JSON twice.
- // The results are combined into an event payload before the event is
- // fired on the js side of things (see platform.js)
- List<PluginResult> result = new ArrayList<PluginResult>();
- result.add(eventResult);
- result.add(pluginResult);
-
- CoreAndroid appPlugin = (CoreAndroid) pluginManager.getPlugin(CoreAndroid.PLUGIN_NAME);
- appPlugin.sendResumeEvent(new PluginResult(PluginResult.Status.OK, result));
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/Whitelist.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/Whitelist.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/Whitelist.java
deleted file mode 100644
index d0f823c..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/Whitelist.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- 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;
-
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.cordova.LOG;
-
-import android.net.Uri;
-
-public class Whitelist {
- private static class URLPattern {
- public Pattern scheme;
- public Pattern host;
- public Integer port;
- public Pattern path;
-
- private String regexFromPattern(String pattern, boolean allowWildcards) {
- final String toReplace = "\\.[]{}()^$?+|";
- StringBuilder regex = new StringBuilder();
- for (int i=0; i < pattern.length(); i++) {
- char c = pattern.charAt(i);
- if (c == '*' && allowWildcards) {
- regex.append(".");
- } else if (toReplace.indexOf(c) > -1) {
- regex.append('\\');
- }
- regex.append(c);
- }
- return regex.toString();
- }
-
- public URLPattern(String scheme, String host, String port, String path) throws MalformedURLException {
- try {
- if (scheme == null || "*".equals(scheme)) {
- this.scheme = null;
- } else {
- this.scheme = Pattern.compile(regexFromPattern(scheme, false), Pattern.CASE_INSENSITIVE);
- }
- if ("*".equals(host)) {
- this.host = null;
- } else if (host.startsWith("*.")) {
- this.host = Pattern.compile("([a-z0-9.-]*\\.)?" + regexFromPattern(host.substring(2), false), Pattern.CASE_INSENSITIVE);
- } else {
- this.host = Pattern.compile(regexFromPattern(host, false), Pattern.CASE_INSENSITIVE);
- }
- if (port == null || "*".equals(port)) {
- this.port = null;
- } else {
- this.port = Integer.parseInt(port,10);
- }
- if (path == null || "/*".equals(path)) {
- this.path = null;
- } else {
- this.path = Pattern.compile(regexFromPattern(path, true));
- }
- } catch (NumberFormatException e) {
- throw new MalformedURLException("Port must be a number");
- }
- }
-
- public boolean matches(Uri uri) {
- try {
- return ((scheme == null || scheme.matcher(uri.getScheme()).matches()) &&
- (host == null || host.matcher(uri.getHost()).matches()) &&
- (port == null || port.equals(uri.getPort())) &&
- (path == null || path.matcher(uri.getPath()).matches()));
- } catch (Exception e) {
- LOG.d(TAG, e.toString());
- return false;
- }
- }
- }
-
- private ArrayList<URLPattern> whiteList;
-
- public static final String TAG = "Whitelist";
-
- public Whitelist() {
- this.whiteList = new ArrayList<URLPattern>();
- }
-
- /* Match patterns (from http://developer.chrome.com/extensions/match_patterns.html)
- *
- * <url-pattern> := <scheme>://<host><path>
- * <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome-extension'
- * <host> := '*' | '*.' <any char except '/' and '*'>+
- * <path> := '/' <any chars>
- *
- * We extend this to explicitly allow a port attached to the host, and we allow
- * the scheme to be omitted for backwards compatibility. (Also host is not required
- * to begin with a "*" or "*.".)
- */
- public void addWhiteListEntry(String origin, boolean subdomains) {
- if (whiteList != null) {
- try {
- // Unlimited access to network resources
- if (origin.compareTo("*") == 0) {
- LOG.d(TAG, "Unlimited access to network resources");
- whiteList = null;
- }
- else { // specific access
- Pattern parts = Pattern.compile("^((\\*|[A-Za-z-]+):(//)?)?(\\*|((\\*\\.)?[^*/:]+))?(:(\\d+))?(/.*)?");
- Matcher m = parts.matcher(origin);
- if (m.matches()) {
- String scheme = m.group(2);
- String host = m.group(4);
- // Special case for two urls which are allowed to have empty hosts
- if (("file".equals(scheme) || "content".equals(scheme)) && host == null) host = "*";
- String port = m.group(8);
- String path = m.group(9);
- if (scheme == null) {
- // XXX making it stupid friendly for people who forget to include protocol/SSL
- whiteList.add(new URLPattern("http", host, port, path));
- whiteList.add(new URLPattern("https", host, port, path));
- } else {
- whiteList.add(new URLPattern(scheme, host, port, path));
- }
- }
- }
- } catch (Exception e) {
- LOG.d(TAG, "Failed to add origin %s", origin);
- }
- }
- }
-
-
- /**
- * Determine if URL is in approved list of URLs to load.
- *
- * @param uri
- * @return true if wide open or whitelisted
- */
- public boolean isUrlWhiteListed(String uri) {
- // If there is no whitelist, then it's wide open
- if (whiteList == null) return true;
-
- Uri parsedUri = Uri.parse(uri);
- // Look for match in white list
- Iterator<URLPattern> pit = whiteList.iterator();
- while (pit.hasNext()) {
- URLPattern p = pit.next();
- if (p.matches(parsedUri)) {
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemCookieManager.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemCookieManager.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemCookieManager.java
deleted file mode 100644
index acf795f..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemCookieManager.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- 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.engine;
-
-import android.annotation.TargetApi;
-import android.os.Build;
-import android.webkit.CookieManager;
-import android.webkit.WebView;
-
-import org.apache.cordova.ICordovaCookieManager;
-
-class SystemCookieManager implements ICordovaCookieManager {
-
- protected final WebView webView;
- private final CookieManager cookieManager;
-
- //Added because lint can't see the conditional RIGHT ABOVE this
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- public SystemCookieManager(WebView webview) {
- webView = webview;
- cookieManager = CookieManager.getInstance();
-
- //REALLY? Nobody has seen this UNTIL NOW?
- cookieManager.setAcceptFileSchemeCookies(true);
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- cookieManager.setAcceptThirdPartyCookies(webView, true);
- }
- }
-
- 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() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- cookieManager.flush();
- }
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d164a88f/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemExposedJsApi.java
----------------------------------------------------------------------
diff --git a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemExposedJsApi.java b/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemExposedJsApi.java
deleted file mode 100755
index 94c3d93..0000000
--- a/spec-plugman/projects/android/CordovaLib/src/org/apache/cordova/engine/SystemExposedJsApi.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- 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.engine;
-
-import android.webkit.JavascriptInterface;
-
-import org.apache.cordova.CordovaBridge;
-import org.apache.cordova.ExposedJsApi;
-import org.json.JSONException;
-
-/**
- * Contains APIs that the JS can call. All functions in here should also have
- * an equivalent entry in CordovaChromeClient.java, and be added to
- * cordova-js/lib/android/plugin/android/promptbasednativeapi.js
- */
-class SystemExposedJsApi implements ExposedJsApi {
- private final CordovaBridge bridge;
-
- SystemExposedJsApi(CordovaBridge bridge) {
- this.bridge = bridge;
- }
-
- @JavascriptInterface
- public String exec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException {
- 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);
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org