12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <jni.h> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "android_webview/browser/aw_contents_client_bridge_base.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/android/jni_helper.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/android/scoped_java_ref.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/id_map.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/javascript_dialog_manager.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace net { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class X509Certificate; 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace android_webview { 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A class that handles the Java<->Native communication for the 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// AwContentsClient. AwContentsClientBridge is created and owned by 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// native AwContents class and it only has a weak reference to the 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// its Java peer. Since the Java AwContentsClientBridge can have 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// indirect refs from the Application (via callbacks) and so can outlive 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// webview, this class notifies it before being destroyed and to nullify 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// any references. 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AwContentsClientBridge : public AwContentsClientBridgeBase { 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AwContentsClientBridge(JNIEnv* env, jobject obj); 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~AwContentsClientBridge(); 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // AwContentsClientBridgeBase implementation 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void AllowCertificateError(int cert_error, 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) net::X509Certificate* cert, 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& request_url, 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Callback<void(bool)>& callback, 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool* cancel_request) OVERRIDE; 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RunJavaScriptDialog( 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::JavaScriptMessageType message_type, 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const GURL& origin_url, 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const string16& message_text, 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const string16& default_prompt_text, 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const content::JavaScriptDialogManager::DialogClosedCallback& callback) 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OVERRIDE; 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RunBeforeUnloadDialog( 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const GURL& origin_url, 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const string16& message_text, 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const content::JavaScriptDialogManager::DialogClosedCallback& callback) 54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OVERRIDE; 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual bool ShouldOverrideUrlLoading(const base::string16& url) OVERRIDE; 56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Methods called from Java. 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id); 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt); 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void CancelJsResult(JNIEnv*, jobject, int id); 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JavaObjectWeakGlobalRef java_ref_; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef const base::Callback<void(bool)> CertErrorCallback; 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_; 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer> 68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) pending_js_dialog_callbacks_; 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool RegisterAwContentsClientBridge(JNIEnv* env); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace android_webview 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_ 76