OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | |
6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | |
7 | |
8 #include "base/android/jni_helper.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "content/public/browser/native_web_keyboard_event.h" | |
11 #include "content/public/common/javascript_message_type.h" | |
12 #include "content/public/common/referrer.h" | |
13 #include "googleurl/src/gurl.h" | |
14 #include "net/base/net_errors.h" | |
15 | |
16 namespace content { | |
17 | |
18 class DownloadItem; | |
19 class JavaScriptDialogCreator; | |
20 struct NativeWebKeyboardEvent; | |
21 class RenderViewHost; | |
22 class WebContents; | |
23 | |
24 // These enums must be kept in sync with ContentViewClient.java | |
25 enum ContentViewClientError { | |
26 // Success | |
27 CONTENT_VIEW_CLIENT_ERROR_OK = 0, | |
28 // Generic error | |
29 CONTENT_VIEW_CLIENT_ERROR_UNKNOWN = -1, | |
30 // Server or proxy hostname lookup failed | |
31 CONTENT_VIEW_CLIENT_ERROR_HOST_LOOKUP = -2, | |
32 // Unsupported authentication scheme (not basic or digest) | |
33 CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_AUTH_SCHEME = -3, | |
34 // User authentication failed on server | |
35 CONTENT_VIEW_CLIENT_ERROR_AUTHENTICATION = -4, | |
36 // User authentication failed on proxy | |
37 CONTENT_VIEW_CLIENT_ERROR_PROXY_AUTHENTICATION = -5, | |
38 // Failed to connect to the server | |
39 CONTENT_VIEW_CLIENT_ERROR_CONNECT = -6, | |
40 // Failed to read or write to the server | |
41 CONTENT_VIEW_CLIENT_ERROR_IO = -7, | |
42 // Connection timed out | |
43 CONTENT_VIEW_CLIENT_ERROR_TIMEOUT = -8, | |
44 // Too many redirects | |
45 CONTENT_VIEW_CLIENT_ERROR_REDIRECT_LOOP = -9, | |
46 // Unsupported URI scheme | |
47 CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_SCHEME = -10, | |
48 // Failed to perform SSL handshake | |
49 CONTENT_VIEW_CLIENT_ERROR_FAILED_SSL_HANDSHAKE = -11, | |
50 // Malformed URL | |
51 CONTENT_VIEW_CLIENT_ERROR_BAD_URL = -12, | |
52 // Generic file error | |
53 CONTENT_VIEW_CLIENT_ERROR_FILE = -13, | |
54 // File not found | |
55 CONTENT_VIEW_CLIENT_ERROR_FILE_NOT_FOUND = -14, | |
56 // Too many requests during this load | |
57 CONTENT_VIEW_CLIENT_ERROR_TOO_MANY_REQUESTS = -15, | |
58 }; | |
59 | |
60 // Native mirror of ContentViewClient.java. Used as a client of | |
61 // ContentView, the main FrameLayout on Android. | |
62 // TODO(joth): Delete this C++ class, to make it Java-only. All the callbacks | |
63 // defined here originate in WebContentsObserver; we should have a dedicated | |
64 // bridge class for that rather than overloading ContentViewClient with this. | |
65 // See http://crbug.com/137967 | |
66 class ContentViewClient { | |
67 public: | |
68 ContentViewClient(JNIEnv* env, jobject obj); | |
69 ~ContentViewClient(); | |
70 | |
71 static ContentViewClient* CreateNativeContentViewClient(JNIEnv* env, | |
72 jobject obj); | |
73 | |
74 // Called by ContentView: | |
75 void OnPageStarted(const GURL& url); | |
76 void OnPageFinished(const GURL& url); | |
77 void OnLoadStarted(); | |
78 void OnLoadStopped(); | |
79 void OnReceivedError(int error_code, | |
80 const string16& description, | |
81 const GURL& url); | |
82 void OnDidCommitMainFrame(const GURL& url, | |
83 const GURL& base_url); | |
84 void OnInterstitialShown(); | |
85 void OnInterstitialHidden(); | |
86 | |
87 void SetJavaScriptDialogCreator( | |
88 JavaScriptDialogCreator* javascript_dialog_creator); | |
89 | |
90 bool OnJSModalDialog(JavaScriptMessageType type, | |
91 bool is_before_unload_dialog, | |
92 const GURL& url, | |
93 const string16& message, | |
94 const string16& default_value); | |
95 | |
96 private: | |
97 // Get the closest ContentViewClient match to the given Chrome error code. | |
98 static ContentViewClientError ToContentViewClientError(int net_error); | |
99 | |
100 // We depend on ContentView.java to hold a ref to the client object. If we | |
101 // were to hold a hard ref from native we could end up with a cyclic | |
102 // ownership leak (the GC can't collect cycles if part of the cycle is caused | |
103 // by native). | |
104 JavaObjectWeakGlobalRef weak_java_client_; | |
105 }; | |
106 | |
107 bool RegisterContentViewClient(JNIEnv* env); | |
108 | |
109 } // namespace content | |
110 | |
111 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | |
OLD | NEW |