1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_BASE_H_
6#define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_BASE_H_
7
8#include "base/callback_forward.h"
9#include "base/supports_user_data.h"
10#include "content/public/browser/javascript_dialog_manager.h"
11
12class GURL;
13
14namespace content {
15class WebContents;
16}
17
18namespace net {
19class SSLCertRequestInfo;
20class X509Certificate;
21}
22
23namespace android_webview {
24
25// browser/ layer interface for AwContensClientBridge, as DEPS prevents this
26// layer from depending on native/ where the implementation lives. The
27// implementor of the base class plumbs the request to the Java side and
28// eventually to the webviewclient. This layering hides the details of
29// native/ from browser/ layer.
30class AwContentsClientBridgeBase {
31 public:
32  typedef base::Callback<void(net::X509Certificate*)> SelectCertificateCallback;
33
34  // Adds the handler to the UserData registry.
35  static void Associate(content::WebContents* web_contents,
36                        AwContentsClientBridgeBase* handler);
37  static void Disassociate(content::WebContents* web_contents);
38  static AwContentsClientBridgeBase* FromWebContents(
39      content::WebContents* web_contents);
40  static AwContentsClientBridgeBase* FromID(int render_process_id,
41                                            int render_frame_id);
42
43  virtual ~AwContentsClientBridgeBase();
44
45  virtual void AllowCertificateError(int cert_error,
46                                     net::X509Certificate* cert,
47                                     const GURL& request_url,
48                                     const base::Callback<void(bool)>& callback,
49                                     bool* cancel_request) = 0;
50  virtual void SelectClientCertificate(
51      net::SSLCertRequestInfo* cert_request_info,
52      const SelectCertificateCallback& callback) = 0;
53
54  virtual void RunJavaScriptDialog(
55      content::JavaScriptMessageType message_type,
56      const GURL& origin_url,
57      const base::string16& message_text,
58      const base::string16& default_prompt_text,
59      const content::JavaScriptDialogManager::DialogClosedCallback& callback)
60      = 0;
61
62  virtual void RunBeforeUnloadDialog(
63      const GURL& origin_url,
64      const base::string16& message_text,
65      const content::JavaScriptDialogManager::DialogClosedCallback& callback)
66      = 0;
67
68  virtual bool ShouldOverrideUrlLoading(const base::string16& url) = 0;
69};
70
71}  // namespace android_webview
72
73#endif  // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_BASE_H_
74