Skip to content

Commit

Permalink
Merge branch 'chromium_64' into 'feature/mimicvpn'
Browse files Browse the repository at this point in the history
  • Loading branch information
Imre Otto committed Dec 10, 2018
2 parents 2c2d58f + bf8a7ed commit 45f5734
Show file tree
Hide file tree
Showing 15 changed files with 548 additions and 290 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ source_set("xwalk_runtime") {
"//components/cdm/renderer",
# "//components/devtools_http_handler",
"//components/error_page/common",
"//components/keyed_service/content",
"//components/nacl/common:features",
"//components/resources:components_resources",
"//components/strings",
Expand Down
3 changes: 2 additions & 1 deletion DEPS.xwalk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#orig
#chromium_crosswalk_rev = 'dd39e4fbbc1e4417cef2f908cc0a42af1e2120aa'

chromium_crosswalk_rev = '9db0e92d9c998c3c3d8627e1254c9167775b6ef9'
chromium_crosswalk_rev = 'dd6a800798d3cf2d14c6f7df2892ba70b5d813b0'
#9db0e92d9c998c3c3d8627e1254c9167775b6ef9'
#11f4efb7a21c9060b6b47920d5a16190e7b8af53'
#202c98d560da445d3c3e1d8befaabd386efa5ed9'
#5fb45679b8286bb0f58889651cc940959445f2c6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
package com.tenta.xwalk.refactor;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Picture;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
Expand All @@ -25,6 +27,7 @@
import android.webkit.WebResourceResponse;
import android.widget.Toast;

import org.chromium.base.ContentUriUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.components.navigation_interception.InterceptNavigationDelegate;
Expand Down Expand Up @@ -629,77 +632,89 @@ public boolean shouldCreateWebContents(String contentUrl) {
return true;
}

/**
* Async task to get file names
* @author iotto
*
*/
private static class GetDisplayNameTask extends AsyncTask<Void, Void, String[]> {
final int mProcessId;
final int mRenderId;
final int mModeFlags;
final String[] mFilePaths;
final Context mContext;

public GetDisplayNameTask(Context context, int processId, int renderId, int modeFlags, String[] filePaths) {
mProcessId = processId;
mRenderId = renderId;
mModeFlags = modeFlags;
mFilePaths = filePaths;
mContext = context;
}

@Override
protected String[] doInBackground(Void... voids) {
String[] displayNames = new String[mFilePaths.length];
for (int i = 0; i < mFilePaths.length; i++) {
displayNames[i] = resolveFileName(mFilePaths[i]);
}
return displayNames;
}

@Override
protected void onPostExecute(String[] result) {
nativeOnFilesSelected(mProcessId, mRenderId, mModeFlags, mFilePaths, result);
}

/**
* @return the display name of a path if it is a content URI and is present in the database
* or an empty string otherwise.
*/
private String resolveFileName(String filePath) {
if (filePath == null)
return "";
Uri uri = Uri.parse(filePath);
return ContentUriUtils.getDisplayName(
uri, mContext, MediaStore.MediaColumns.DISPLAY_NAME);
}
}

@Override
public boolean shouldOverrideRunFileChooser(
final int processId, final int renderId, final int modeFlags,
public boolean shouldOverrideRunFileChooser(final int processId, final int renderId, final int modeFlags,
String acceptTypes, boolean capture) {
abstract class UriCallback implements ValueCallback<Uri> {
abstract class UriCallback implements ValueCallback<String[]> {
boolean syncNullReceived = false;
boolean syncCallFinished = false;

protected String resolveFileName(Uri uri, ContentResolver contentResolver) {
if (contentResolver == null || uri == null)
return "";
Cursor cursor = null;
try {
cursor = contentResolver.query(uri, null, null, null, null);

if (cursor != null && cursor.getCount() >= 1) {
cursor.moveToFirst();
int index = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
if (index > -1)
return cursor.getString(index);
}
} catch (NullPointerException e) {
// Some android models don't handle the provider call correctly.
// see crbug.com/345393
return "";
} finally {
if (cursor != null)
cursor.close();
}
return "";
int processId;
int renderId;
int modeFlags;
public UriCallback(int processId, int renderId, int modeFlags) {
this.processId = processId;
this.renderId = renderId;
this.modeFlags = modeFlags;
}
}
UriCallback uploadFile = new UriCallback() {
UriCallback uploadFile = new UriCallback(processId, renderId, modeFlags) {
boolean completed = false;

@Override
public void onReceiveValue(Uri value) {
public void onReceiveValue(String[] results) {
if (completed) {
throw new IllegalStateException("Duplicate openFileChooser result");
}
if (value == null && !syncCallFinished) {
syncNullReceived = true;
return;
}
completed = true;
if (value == null) {
nativeOnFilesNotSelected(mNativeContentsClientBridge,
processId, renderId, modeFlags);
if (results == null || results.length == 0) {
syncNullReceived = true;
nativeOnFilesSelected(processId, renderId, modeFlags, null, null);
} else {
String result = "";
String displayName = null;
if (ContentResolver.SCHEME_FILE.equals(value.getScheme())) {
result = value.getSchemeSpecificPart();
displayName = value.getLastPathSegment();
} else if (ContentResolver.SCHEME_CONTENT.equals(value.getScheme())) {
result = value.toString();
displayName = resolveFileName(
value, mXWalkView.getContext().getContentResolver());
} else {
result = value.getPath();
displayName = value.getLastPathSegment();
}
if (displayName == null || displayName.isEmpty())
displayName = result;
nativeOnFilesSelected(mNativeContentsClientBridge,
processId, renderId, modeFlags, result, displayName);

GetDisplayNameTask task =
new GetDisplayNameTask(mXWalkView.getContext(), processId, renderId, modeFlags, results);
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
};
mXWalkUIClient.openFileChooser(
mXWalkView, uploadFile, acceptTypes, Boolean.toString(capture));
mXWalkUIClient.openFileChooser(mXWalkView, uploadFile, acceptTypes, capture, modeFlags);
uploadFile.syncCallFinished = true;
return !uploadFile.syncNullReceived;
}
Expand Down Expand Up @@ -982,11 +997,8 @@ private native void nativeConfirmJsResult(long nativeXWalkContentsClientBridge,
private native void nativeNotificationClosed(long nativeXWalkContentsClientBridge, int id,
boolean byUser);

private native void nativeOnFilesSelected(long nativeXWalkContentsClientBridge,
int processId, int renderId, int mode_flags, String filepath, String displayName);

private native void nativeOnFilesNotSelected(long nativeXWalkContentsClientBridge,
int processId, int renderId, int mode_flags);
private static native void nativeOnFilesSelected(int processId, int renderId, int mode_flags, String[] filePath,
String[] displayName);

private native void nativeDownloadIcon(long nativeXWalkContentsClientBridge, String url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.ValueCallback;
import android.widget.EditText;
Expand Down Expand Up @@ -271,15 +269,15 @@ public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
* @param uploadFile the callback class to handle the result from caller. It MUST be invoked in
* all cases. Leave it not invoked will block all following requests to open file
* chooser.
* @param acceptType value of the 'accept' attribute of the input tag associated with this file
* @param acceptType comma separated value(s) of the 'accept' attribute of the input tag associated with this file
* picker.
* @param capture value of the 'capture' attribute of the input tag associated with this file
* picker
* @param capture If true, the data should be obtained using the device's camera/mic/etc.
* @param modeFlags flags of android.webkit.WebChromeClient.FileChooserParams
*
* @since 1.0
*/
//TODO(iotto) : @XWalkAPI
public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
String acceptType, String capture) {
public void openFileChooser(XWalkView view, ValueCallback<String[]> uploadFile, String acceptType, boolean capture,
int modeFlags) {
uploadFile.onReceiveValue(null);
}

Expand Down
45 changes: 30 additions & 15 deletions runtime/browser/android/xwalk_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "xwalk/runtime/browser/xwalk_runner.h"
#include "jni/XWalkContent_jni.h"

#if defined(TENTA_CHROMIUM_BUILD)
#ifdef TENTA_CHROMIUM_BUILD
#include "xwalk/third_party/tenta/meta_fs/meta_errors.h"
#include "xwalk/third_party/tenta/meta_fs/meta_db.h"
#include "xwalk/third_party/tenta/meta_fs/meta_file.h"
Expand All @@ -63,8 +63,15 @@
#include "xwalk/third_party/tenta/meta_fs/jni/meta_virtual_file.h"
#include "xwalk/third_party/tenta/meta_fs/jni/java_byte_array.h"
#include "xwalk/third_party/tenta/chromium_cache/meta_cache_backend.h"
#include "xwalk/third_party/tenta/crosswalk_extensions/tenta_history_store.h"
#endif

#include "tenta_history_store.h"
#include "browser/tenta_tab_model.h"

using namespace tenta::ext;
namespace metafs = ::tenta::fs;
#endif // #ifdef TENTA_CHROMIUM_BUILD

#include "meta_logging.h"

using base::android::AttachCurrentThread;
using base::android::ConvertUTF8ToJavaString;
Expand All @@ -75,11 +82,6 @@ using content::WebContents;
using navigation_interception::InterceptNavigationDelegate;
using xwalk::application_manifest_keys::kDisplay;

#ifdef TENTA_CHROMIUM_BUILD
using tenta::ext::TentaHistoryStore;
namespace metafs = ::tenta::fs;
#endif

namespace keys = xwalk::application_manifest_keys;

namespace xwalk {
Expand Down Expand Up @@ -227,7 +229,8 @@ XWalkContent* XWalkContent::FromWebContents(content::WebContents* web_contents)
}

XWalkContent::XWalkContent(std::unique_ptr<content::WebContents> web_contents)
: web_contents_(std::move(web_contents)) {
: web_contents_(std::move(web_contents)),
tab_id(base::Time::Now().ToInternalValue()) {
xwalk_autofill_manager_.reset(new XWalkAutofillManager(web_contents_.get()));
XWalkContentLifecycleNotifier::OnXWalkViewCreated();
}
Expand Down Expand Up @@ -257,6 +260,13 @@ XWalkContent::~XWalkContent() {
#ifdef TENTA_CHROMIUM_BUILD
TentaHistoryStore* h_store = TentaHistoryStore::GetInstance();
h_store->SetController(reinterpret_cast<intptr_t>(this), nullptr);

TentaTabModel * tab_model = TentaTabModelFactory::GetForContext(web_contents_->GetBrowserContext());
if ( tab_model ) {
tab_model->RemoveTab(tab_id);
} else {
TENTA_LOG_NET(ERROR) << __func__ << " NULL_tab_model";
}
#endif
}

Expand All @@ -279,8 +289,17 @@ void XWalkContent::SetJavaPeers(

#ifdef TENTA_CHROMIUM_BUILD
// Net Error handler on client side
::tenta::ext::TentaNetErrorClient::CreateForWebContents(web_contents_.get());
::tenta::ext::TentaNetErrorClient::FromWebContents(web_contents_.get())->SetListener(this);
TentaNetErrorClient::CreateForWebContents(web_contents_.get());
TentaNetErrorClient::FromWebContents(web_contents_.get())->SetListener(this);

// new tab created notify tabModel
// TODO(iotto) : Have a TabId
TentaTabModel * tab_model = TentaTabModelFactory::GetForContext(web_contents_->GetBrowserContext());
if ( tab_model ) {
tab_model->AddTab(tab_id, web_contents_.get());
} else {
TENTA_LOG_NET(ERROR) << __func__ << " NULL_tab_model";
}
#endif // TENTA_CHROMIUM_BUILD

// XWalk does not use disambiguation popup for multiple targets.
Expand Down Expand Up @@ -867,10 +886,6 @@ static jlong JNI_XWalkContent_Init(JNIEnv* env, const JavaParamRef<jobject>& obj
return reinterpret_cast<intptr_t>(new XWalkContent(std::move(web_contents)));
}

bool RegisterXWalkContent(JNIEnv* env) {
return true;
}

namespace {

void ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref, const GURL& origin) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/browser/android/xwalk_content.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ class XWalkContent :
OriginCallback;
// The first element in the list is always the currently pending request.
std::list<OriginCallback> pending_geolocation_prompts_;
};

bool RegisterXWalkContent(JNIEnv* env);
int tab_id; // curent webview ID
};

} // namespace xwalk

Expand Down
Loading

0 comments on commit 45f5734

Please sign in to comment.