Skip to content

Commit

Permalink
Revert "[Android] Update shouldInterceptLoadRequest to Android L style"
Browse files Browse the repository at this point in the history
This reverts commit db7728d.

Reason: broke almost all tests because it uses
android.util.ArrayMap (API Level 19) whereas we need to support API
levels >= 14:

W/System.err( 5990): java.lang.NoClassDefFoundError: android.util.ArrayMap
W/System.err( 5990):    at org.xwalk.core.internal.XWalkContentsIoThreadClient.shouldInterceptRequest(XWalkContentsIoThreadClient.java:53)
W/System.err( 5990):    at dalvik.system.NativeStart.run(Native Method)
F/chromium( 5990): [FATAL:jni_android.cc(249)] Check failed: false. Please include Java exception stack in crash report

BUG=XWALK-3934
  • Loading branch information
Raphael Kubo da Costa committed Nov 5, 2015
1 parent 24849c6 commit 58b0f21
Show file tree
Hide file tree
Showing 31 changed files with 369 additions and 764 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is imported from the upstream.

package org.xwalk.core.internal;

import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;

import java.io.InputStream;

/**
* The response information that is to be returned for a particular resource fetch.
*/
@JNINamespace("xwalk")
class InterceptedRequestData {
private String mMimeType;
private String mCharset;
private InputStream mData;

public InterceptedRequestData(String mimeType, String encoding, InputStream data) {
mMimeType = mimeType;
mCharset = encoding;
mData = data;
}

@CalledByNative
public String getMimeType() {
return mMimeType;
}

@CalledByNative
public String getCharset() {
return mCharset;
}

@CalledByNative
public InputStream getData() {
return mData;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public boolean onTouchEvent(MotionEvent event) {
}

//--------------------------------------------------------------------------------------------
private class XWalkIoThreadClientImpl extends XWalkContentsIoThreadClient {
private class XWalkIoThreadClientImpl implements XWalkContentsIoThreadClient {
// All methods are called on the IO thread.

@Override
Expand All @@ -669,26 +669,28 @@ public int getCacheMode() {
}

@Override
public XWalkWebResourceResponse shouldInterceptRequest(
XWalkContentsClient.XWalkWebResourceRequest request) {
public InterceptedRequestData shouldInterceptRequest(final String url,
boolean isMainFrame) {

String url = request.url;
XWalkWebResourceResponse xwalkWebResourceResponse;
// Notify a resource load is started. This is not the best place to start the callback
// but it's a workable way.
mContentsClientBridge.getCallbackHelper().postOnResourceLoadStarted(url);

xwalkWebResourceResponse = mContentsClientBridge.shouldInterceptRequest(request);
WebResourceResponse webResourceResponse = mContentsClientBridge.shouldInterceptRequest(url);
InterceptedRequestData interceptedRequestData = null;

if (xwalkWebResourceResponse == null) {
if (webResourceResponse == null) {
mContentsClientBridge.getCallbackHelper().postOnLoadResource(url);
} else {
if (request.isMainFrame && xwalkWebResourceResponse.getData() == null) {
if (isMainFrame && webResourceResponse.getData() == null) {
mContentsClientBridge.getCallbackHelper().postOnReceivedError(
XWalkResourceClientInternal.ERROR_UNKNOWN, null, url);
XWalkResourceClientInternal.ERROR_UNKNOWN, null, url);
}
interceptedRequestData = new InterceptedRequestData(webResourceResponse.getMimeType(),
webResourceResponse.getEncoding(),
webResourceResponse.getData());
}
return xwalkWebResourceResponse;
return interceptedRequestData;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.ArrayMap;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
Expand Down Expand Up @@ -134,32 +133,16 @@ final XWalkContentsClientCallbackHelper getCallbackHelper() {
}

//--------------------------------------------------------------------------------------------
// XWalkViewInternal specific methods that map directly to XWalkViewClient/XWalkWebChromeClient
// XWalkViewInternal specific methods that map directly to XWalkViewClient / XWalkWebChromeClient
//--------------------------------------------------------------------------------------------

/**
* Parameters for the {@link XWalkContentsClient#shouldInterceptRequest} method.
*/
public static class XWalkWebResourceRequest {
// Url of the request.
public String url;
// Is this for the main frame or a child iframe?
public boolean isMainFrame;
// Was a gesture associated with the request? Don't trust can easily be spoofed.
public boolean hasUserGesture;
// Method used (GET/POST/OPTIONS)
public String method;
// Headers that would have been sent to server.
public ArrayMap<String, String> requestHeaders;
}
public abstract void getVisitedHistory(ValueCallback<String[]> callback);

public abstract void doUpdateVisitedHistory(String url, boolean isReload);

public abstract void onProgressChanged(int progress);

public abstract XWalkWebResourceResponse shouldInterceptRequest(
XWalkWebResourceRequest request);
public abstract WebResourceResponse shouldInterceptRequest(String url);

public abstract void onResourceLoadStarted(String url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Build;
import android.os.Message;
import android.os.Handler;
import android.provider.MediaStore;
Expand All @@ -31,9 +30,6 @@
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;

import javax.security.auth.x500.X500Principal;

Expand Down Expand Up @@ -248,29 +244,9 @@ public void onProgressChanged(int progress) {
}

@Override
public XWalkWebResourceResponse shouldInterceptRequest(XWalkWebResourceRequest request) {
public WebResourceResponse shouldInterceptRequest(String url) {
if (isOwnerActivityRunning()) {
WebResourceResponse response = mXWalkResourceClient.shouldInterceptLoadRequest(
mXWalkView, new WebResourceRequestHandlerInternal(request));
if (response == null) return null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
Map<String, String> responseHeaders = response.getResponseHeaders();
if (responseHeaders == null) responseHeaders = new HashMap<String, String>();

return new XWalkWebResourceResponse(
response.getMimeType(),
response.getEncoding(),
response.getData(),
response.getStatusCode(),
response.getReasonPhrase(),
responseHeaders);
} else {
return new XWalkWebResourceResponse(
response.getMimeType(),
response.getEncoding(),
response.getData());
}
return mXWalkResourceClient.shouldInterceptLoadRequest(mXWalkView, url);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,36 @@

package org.xwalk.core.internal;

import android.util.ArrayMap;

import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;

/**
* Delegate for handling callbacks. All methods are called on the IO thread.
*/
@JNINamespace("xwalk")
public abstract class XWalkContentsIoThreadClient {
interface XWalkContentsIoThreadClient {
@CalledByNative
public abstract int getCacheMode();
public int getCacheMode();

@CalledByNative
public abstract boolean shouldBlockContentUrls();
public InterceptedRequestData shouldInterceptRequest(String url, boolean isMainFrame);

@CalledByNative
public abstract boolean shouldBlockFileUrls();
public boolean shouldBlockContentUrls();

@CalledByNative
public abstract boolean shouldBlockNetworkLoads();
public boolean shouldBlockFileUrls();

@CalledByNative
public abstract void onDownloadStart(String url,
String userAgent,
String contentDisposition,
String mimeType,
long contentLength);
public boolean shouldBlockNetworkLoads();

@CalledByNative
public abstract void newLoginRequest(String realm, String account, String args);

public abstract XWalkWebResourceResponse shouldInterceptRequest(
XWalkContentsClient.XWalkWebResourceRequest request);
public void onDownloadStart(String url,
String userAgent,
String contentDisposition,
String mimeType,
long contentLength);

// Protected methods ---------------------------------------------------------------------------
@CalledByNative
protected XWalkWebResourceResponse shouldInterceptRequest(String url, boolean isMainFrame,
boolean hasUserGesture, String method, String[] requestHeaderNames,
String[] requestHeaderValues) {
XWalkContentsClient.XWalkWebResourceRequest request =
new XWalkContentsClient.XWalkWebResourceRequest();
request.url = url;
request.isMainFrame = isMainFrame;
request.hasUserGesture = hasUserGesture;
request.method = method;
request.requestHeaders = new ArrayMap<String, String>(requestHeaderNames.length);
for (int i = 0; i < requestHeaderNames.length; ++i) {
request.requestHeaders.put(requestHeaderNames[i], requestHeaderValues[i]);
}
return shouldInterceptRequest(request);
}
public void newLoginRequest(String realm, String account, String args);
}
Loading

0 comments on commit 58b0f21

Please sign in to comment.