forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Webviewclient.onReceivedSslError
BUG= Review URL: https://chromiumcodereview.appspot.com/12091111 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184643 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
sgurun@chromium.org
committed
Feb 26, 2013
1 parent
6ac9e31
commit 01d1fee
Showing
19 changed files
with
475 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2013 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. | ||
|
||
#include "android_webview/browser/aw_contents_client_bridge_base.h" | ||
|
||
#include "content/public/browser/browser_thread.h" | ||
#include "content/public/browser/render_view_host.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
using content::BrowserThread; | ||
using content::WebContents; | ||
|
||
namespace android_webview { | ||
|
||
namespace { | ||
|
||
const void* kAwContentsClientBridgeBase = &kAwContentsClientBridgeBase; | ||
|
||
// This class is invented so that the UserData registry that we inject the | ||
// AwContentsClientBridgeBase object does not own and destroy it. | ||
class UserData : public base::SupportsUserData::Data { | ||
public: | ||
static AwContentsClientBridgeBase* GetContents( | ||
content::WebContents* web_contents) { | ||
if (!web_contents) | ||
return NULL; | ||
UserData* data = reinterpret_cast<UserData*>( | ||
web_contents->GetUserData(kAwContentsClientBridgeBase)); | ||
return data ? data->contents_ : NULL; | ||
} | ||
|
||
explicit UserData(AwContentsClientBridgeBase* ptr) : contents_(ptr) {} | ||
private: | ||
AwContentsClientBridgeBase* contents_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(UserData); | ||
}; | ||
|
||
} // namespace | ||
|
||
// static | ||
void AwContentsClientBridgeBase::Associate( | ||
WebContents* web_contents, | ||
AwContentsClientBridgeBase* handler) { | ||
web_contents->SetUserData(kAwContentsClientBridgeBase, | ||
new UserData(handler)); | ||
} | ||
|
||
// static | ||
AwContentsClientBridgeBase* AwContentsClientBridgeBase::FromWebContents( | ||
WebContents* web_contents) { | ||
return UserData::GetContents(web_contents); | ||
} | ||
|
||
// static | ||
AwContentsClientBridgeBase* AwContentsClientBridgeBase::FromID( | ||
int render_process_id, | ||
int render_view_id) { | ||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | ||
const content::RenderViewHost* rvh = | ||
content::RenderViewHost::FromID(render_process_id, render_view_id); | ||
if (!rvh) return NULL; | ||
content::WebContents* web_contents = | ||
content::WebContents::FromRenderViewHost(rvh); | ||
return UserData::GetContents(web_contents); | ||
} | ||
|
||
AwContentsClientBridgeBase::~AwContentsClientBridgeBase() { | ||
} | ||
|
||
} // namespace android_webview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2013 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. | ||
|
||
#ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_BASE_H_ | ||
#define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_BASE_H_ | ||
|
||
#include "base/callback_forward.h" | ||
#include "base/supports_user_data.h" | ||
|
||
class GURL; | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
namespace net { | ||
class X509Certificate; | ||
} | ||
|
||
namespace android_webview { | ||
|
||
// browser/ layer interface for AwContensClientBridge, as DEPS prevents this | ||
// layer from depending on native/ where the implementation lives. The | ||
// implementor of the base class plumbs the request to the Java side and | ||
// eventually to the webviewclient. This layering hides the details of | ||
// native/ from browser/ layer. | ||
class AwContentsClientBridgeBase { | ||
public: | ||
// Adds the handler to the UserData registry. | ||
static void Associate(content::WebContents* web_contents, | ||
AwContentsClientBridgeBase* handler); | ||
static AwContentsClientBridgeBase* FromWebContents( | ||
content::WebContents* web_contents); | ||
static AwContentsClientBridgeBase* FromID(int render_process_id, | ||
int render_view_id); | ||
|
||
virtual ~AwContentsClientBridgeBase(); | ||
|
||
virtual void AllowCertificateError(int cert_error, | ||
net::X509Certificate* cert, | ||
const GURL& request_url, | ||
const base::Callback<void(bool)>& callback, | ||
bool* cancel_request) = 0; | ||
}; | ||
|
||
} // namespace android_webview | ||
|
||
#endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_BASE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2013 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. | ||
|
||
package org.chromium.android_webview; | ||
|
||
import android.net.http.SslCertificate; | ||
import android.net.http.SslError; | ||
import android.webkit.ValueCallback; | ||
|
||
import org.chromium.base.CalledByNative; | ||
import org.chromium.base.JNINamespace; | ||
import org.chromium.base.ThreadUtils; | ||
|
||
/** | ||
* This class handles the JNI communication logic for the the AwContentsClient class. | ||
* Both the Java and the native peers of AwContentsClientBridge are owned by the | ||
* corresponding AwContents instances. This class and its native peer are connected | ||
* via weak references. The native AwContentsClientBridge sets up and clear these weak | ||
* references. | ||
*/ | ||
@JNINamespace("android_webview") | ||
public class AwContentsClientBridge { | ||
|
||
private AwContentsClient mClient; | ||
// The native peer of this object. | ||
private int mNativeContentsClientBridge; | ||
|
||
public AwContentsClientBridge(AwContentsClient client) { | ||
assert client != null; | ||
mClient = client; | ||
} | ||
|
||
// Used by the native peer to set/reset a weak ref to the native peer. | ||
@CalledByNative | ||
private void setNativeContentsClientBridge(int nativeContentsClientBridge) { | ||
mNativeContentsClientBridge = nativeContentsClientBridge; | ||
} | ||
|
||
// If returns false, the request is immediately canceled, and any call to proceedSslError | ||
// has no effect. If returns true, the request should be canceled or proceeded using | ||
// proceedSslError(). | ||
// Unlike the webview classic, we do not keep keep a database of certificates that | ||
// are allowed by the user, because this functionality is already handled via | ||
// ssl_policy in native layers. | ||
@CalledByNative | ||
private boolean allowCertificateError(int certError, byte[] derBytes, final String url, | ||
final int id) { | ||
final SslCertificate cert = SslUtil.getCertificateFromDerBytes(derBytes); | ||
if (cert == null) { | ||
// if the certificate or the client is null, cancel the request | ||
return false; | ||
} | ||
final SslError sslError = SslUtil.sslErrorFromNetErrorCode(certError, cert, url); | ||
ValueCallback<Boolean> callback = new ValueCallback<Boolean>() { | ||
@Override | ||
public void onReceiveValue(Boolean value) { | ||
proceedSslError(value.booleanValue(), id); | ||
} | ||
}; | ||
mClient.onReceivedSslError(callback, sslError); | ||
return true; | ||
} | ||
|
||
private void proceedSslError(boolean proceed, int id) { | ||
if (mNativeContentsClientBridge == 0) return; | ||
nativeProceedSslError(mNativeContentsClientBridge, proceed, id); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------- | ||
// Native methods | ||
//-------------------------------------------------------------------------------------------- | ||
private native void nativeProceedSslError(int nativeAwContentsClientBridge, boolean proceed, | ||
int id); | ||
} |
Oops, something went wrong.