Skip to content

Commit

Permalink
Merge pull request #73 from Wizcorp/develop
Browse files Browse the repository at this point in the history
Update Master
  • Loading branch information
aogilvie committed Nov 27, 2014
2 parents bfcf2d9 + 0fff683 commit b8f1c08
Show file tree
Hide file tree
Showing 175 changed files with 10,150 additions and 5,302 deletions.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Contributing

:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:

The following is a set of guidelines for contributing to this plugin.

These are just guidelines, not rules, use your best judgement and feel free to propose changes to this document in a pull request.

## Getting Help

Before creating a Github issue make sure you...

- Search the [issues list](https://github.com/Wizcorp/phonegap-plugin-wizViewManager/issues) for existing closed or still open issues
- Create a Github issue

#### Creating an Issue

When submitting an issue please add as much of the following information:

- Tell us what you expected to happen and what actually happened. ("It doesn't work" is **not** a solveable problem)
- Provide sample code so people can test and debug the problem.
- Provide `adb logcat` or Xcode console output.

Can you solve the problem yourself? If so see the next section on Pull Requests and send us the fix!!! <3

## Pull Requests

- Include screenshots and animated GIFs in your pull request whenever possible.
- Try to follow the [JavaScript](https://github.com/Wizcorp/javascript-styleguide/blob/master/README.md), [Objective-C](http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml) or [Java](https://google-styleguide.googlecode.com/svn/trunk/javaguide.html) style guides. Although these are just guides, please at least support continuety (that means **using 4 spaces please**).
- **Send your pull request to the develop branch.**
- If you can, provide sample testing code.
4 changes: 2 additions & 2 deletions platforms/android/.classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
4 changes: 2 additions & 2 deletions platforms/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="io.cordova.hellocordova" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<application android:allowBackup="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="HelloCordova" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
4 changes: 2 additions & 2 deletions platforms/android/CordovaLib/.classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion platforms/android/CordovaLib/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.apache.cordova" android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="8" />
<uses-sdk android:minSdkVersion="10" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -19,20 +17,38 @@
under the License.
*/

var exec = require('./exec'),
path = require('path'),
ROOT = path.join(__dirname, '..', '..');

/*
* Cleans the project using ant
* Returns a promise.
*/
module.exports.run = function() {
return exec('ant clean -f "' + path.join(ROOT, 'build.xml') + '"');

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}

module.exports.help = function() {
console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]));
console.log('Cleans the project directory.');
process.exit(0);
apply plugin: 'android-library'

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
33 changes: 31 additions & 2 deletions platforms/android/CordovaLib/src/com/squareup/okhttp/Address.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.squareup.okhttp;

import com.squareup.okhttp.internal.Util;
import java.net.Proxy;
import java.net.UnknownHostException;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;

Expand All @@ -38,16 +40,23 @@ public final class Address {
final int uriPort;
final SSLSocketFactory sslSocketFactory;
final HostnameVerifier hostnameVerifier;
final OkAuthenticator authenticator;
final List<String> transports;

public Address(String uriHost, int uriPort, SSLSocketFactory sslSocketFactory,
HostnameVerifier hostnameVerifier, Proxy proxy) throws UnknownHostException {
HostnameVerifier hostnameVerifier, OkAuthenticator authenticator, Proxy proxy,
List<String> transports) throws UnknownHostException {
if (uriHost == null) throw new NullPointerException("uriHost == null");
if (uriPort <= 0) throw new IllegalArgumentException("uriPort <= 0: " + uriPort);
if (authenticator == null) throw new IllegalArgumentException("authenticator == null");
if (transports == null) throw new IllegalArgumentException("transports == null");
this.proxy = proxy;
this.uriHost = uriHost;
this.uriPort = uriPort;
this.sslSocketFactory = sslSocketFactory;
this.hostnameVerifier = hostnameVerifier;
this.authenticator = authenticator;
this.transports = Util.immutableList(transports);
}

/** Returns the hostname of the origin server. */
Expand Down Expand Up @@ -79,6 +88,22 @@ public HostnameVerifier getHostnameVerifier() {
return hostnameVerifier;
}


/**
* Returns the client's authenticator. This method never returns null.
*/
public OkAuthenticator getAuthenticator() {
return authenticator;
}

/**
* Returns the client's transports. This method always returns a non-null list
* that contains "http/1.1", possibly among other transports.
*/
public List<String> getTransports() {
return transports;
}

/**
* Returns this address's explicitly-specified HTTP proxy, or null to
* delegate to the HTTP client's proxy selector.
Expand All @@ -94,7 +119,9 @@ public Proxy getProxy() {
&& this.uriHost.equals(that.uriHost)
&& this.uriPort == that.uriPort
&& equal(this.sslSocketFactory, that.sslSocketFactory)
&& equal(this.hostnameVerifier, that.hostnameVerifier);
&& equal(this.hostnameVerifier, that.hostnameVerifier)
&& equal(this.authenticator, that.authenticator)
&& equal(this.transports, that.transports);
}
return false;
}
Expand All @@ -105,7 +132,9 @@ && equal(this.sslSocketFactory, that.sslSocketFactory)
result = 31 * result + uriPort;
result = 31 * result + (sslSocketFactory != null ? sslSocketFactory.hashCode() : 0);
result = 31 * result + (hostnameVerifier != null ? hostnameVerifier.hashCode() : 0);
result = 31 * result + (authenticator != null ? authenticator.hashCode() : 0);
result = 31 * result + (proxy != null ? proxy.hashCode() : 0);
result = 31 * result + transports.hashCode();
return result;
}
}
78 changes: 61 additions & 17 deletions platforms/android/CordovaLib/src/com/squareup/okhttp/Connection.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.OutputStream;
import java.net.Proxy;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.Arrays;
import javax.net.ssl.SSLSocket;
Expand Down Expand Up @@ -92,24 +93,20 @@ public Connection(Route route) {

public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
throws IOException {
if (connected) {
throw new IllegalStateException("already connected");
}
connected = true;
if (connected) throw new IllegalStateException("already connected");

socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
socket.connect(route.inetSocketAddress, connectTimeout);
Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
socket.setSoTimeout(readTimeout);
in = socket.getInputStream();
out = socket.getOutputStream();

if (route.address.sslSocketFactory != null) {
upgradeToTls(tunnelRequest);
} else {
streamWrapper();
}

// Use MTU-sized buffers to send fewer packets.
int mtu = Platform.get().getMtu(socket);
in = new BufferedInputStream(in, mtu);
out = new BufferedOutputStream(out, mtu);
connected = true;
}

/**
Expand All @@ -134,7 +131,8 @@ private void upgradeToTls(TunnelRequest tunnelRequest) throws IOException {
platform.supportTlsIntolerantServer(sslSocket);
}

if (route.modernTls) {
boolean useNpn = route.modernTls && route.address.transports.contains("spdy/3");
if (useNpn) {
platform.setNpnProtocols(sslSocket, NPN_PROTOCOLS);
}

Expand All @@ -148,14 +146,15 @@ private void upgradeToTls(TunnelRequest tunnelRequest) throws IOException {

out = sslSocket.getOutputStream();
in = sslSocket.getInputStream();
streamWrapper();

byte[] selectedProtocol;
if (route.modernTls
&& (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) {
if (useNpn && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) {
if (Arrays.equals(selectedProtocol, SPDY3)) {
sslSocket.setSoTimeout(0); // SPDY timeouts are set per-stream.
spdyConnection = new SpdyConnection.Builder(route.address.getUriHost(), true, in, out)
.build();
spdyConnection.sendConnectionHeader();
} else if (!Arrays.equals(selectedProtocol, HTTP_11)) {
throw new IOException(
"Unexpected NPN transport " + new String(selectedProtocol, "ISO-8859-1"));
Expand Down Expand Up @@ -190,6 +189,39 @@ public boolean isAlive() {
return !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown();
}

/**
* Returns true if we are confident that we can read data from this
* connection. This is more expensive and more accurate than {@link
* #isAlive()}; callers should check {@link #isAlive()} first.
*/
public boolean isReadable() {
if (!(in instanceof BufferedInputStream)) {
return true; // Optimistic.
}
if (isSpdy()) {
return true; // Optimistic. We can't test SPDY because its streams are in use.
}
BufferedInputStream bufferedInputStream = (BufferedInputStream) in;
try {
int readTimeout = socket.getSoTimeout();
try {
socket.setSoTimeout(1);
bufferedInputStream.mark(1);
if (bufferedInputStream.read() == -1) {
return false; // Stream is exhausted; socket is closed.
}
bufferedInputStream.reset();
return true;
} finally {
socket.setSoTimeout(readTimeout);
}
} catch (SocketTimeoutException ignored) {
return true; // Read timed out; socket is good.
} catch (IOException e) {
return false; // Couldn't read; socket is closed.
}
}

public void resetIdleStartTime() {
if (spdyConnection != null) {
throw new IllegalStateException("spdyConnection != null");
Expand All @@ -207,7 +239,7 @@ public boolean isIdle() {
* {@code keepAliveDurationNs}.
*/
public boolean isExpired(long keepAliveDurationNs) {
return isIdle() && System.nanoTime() - getIdleStartTimeNs() > keepAliveDurationNs;
return getIdleStartTimeNs() < System.nanoTime() - keepAliveDurationNs;
}

/**
Expand All @@ -220,7 +252,8 @@ public long getIdleStartTimeNs() {

/** Returns the transport appropriate for this connection. */
public Object newTransport(HttpEngine httpEngine) throws IOException {
return (spdyConnection != null) ? new SpdyTransport(httpEngine, spdyConnection)
return (spdyConnection != null)
? new SpdyTransport(httpEngine, spdyConnection)
: new HttpTransport(httpEngine, out, in);
}

Expand Down Expand Up @@ -258,6 +291,11 @@ public boolean requiresTunnel() {
return route.address.sslSocketFactory != null && route.proxy.type() == Proxy.Type.HTTP;
}

public void updateReadTimeout(int newTimeout) throws IOException {
if (!connected) throw new IllegalStateException("updateReadTimeout - not connected");
socket.setSoTimeout(newTimeout);
}

/**
* To make an HTTPS connection over an HTTP proxy, send an unencrypted
* CONNECT request to create the proxy connection. This may need to be
Expand All @@ -275,8 +313,9 @@ private void makeTunnel(TunnelRequest tunnelRequest) throws IOException {
case HTTP_PROXY_AUTH:
requestHeaders = new RawHeaders(requestHeaders);
URL url = new URL("https", tunnelRequest.host, tunnelRequest.port, "/");
boolean credentialsFound = HttpAuthenticator.processAuthHeader(HTTP_PROXY_AUTH,
responseHeaders, requestHeaders, route.proxy, url);
boolean credentialsFound = HttpAuthenticator.processAuthHeader(
route.address.authenticator, HTTP_PROXY_AUTH, responseHeaders, requestHeaders,
route.proxy, url);
if (credentialsFound) {
continue;
} else {
Expand All @@ -288,4 +327,9 @@ private void makeTunnel(TunnelRequest tunnelRequest) throws IOException {
}
}
}

private void streamWrapper() throws IOException {
in = new BufferedInputStream(in, 4096);
out = new BufferedOutputStream(out, 256);
}
}
Loading

0 comments on commit b8f1c08

Please sign in to comment.