OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ |
6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | 6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ |
7 | 7 |
8 #include "base/android/jni_helper.h" | 8 #include "base/android/jni_helper.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "content/public/browser/native_web_keyboard_event.h" | 10 #include "content/public/browser/native_web_keyboard_event.h" |
11 #include "content/public/browser/web_contents_delegate.h" | |
12 #include "content/public/common/javascript_message_type.h" | 11 #include "content/public/common/javascript_message_type.h" |
13 #include "content/public/common/referrer.h" | 12 #include "content/public/common/referrer.h" |
14 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
15 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
16 | 15 |
17 class FindHelper; | 16 class FindHelper; |
18 | 17 |
19 namespace content { | 18 namespace content { |
| 19 |
20 class DownloadItem; | 20 class DownloadItem; |
21 struct FindMatchRect; | |
22 class JavaScriptDialogCreator; | 21 class JavaScriptDialogCreator; |
23 class NativeWebKeyboardEvent; | 22 struct NativeWebKeyboardEvent; |
24 class RenderViewHost; | 23 class RenderViewHost; |
25 class WebContents; | 24 class WebContents; |
26 } | |
27 | 25 |
28 namespace content { | 26 // These enums must be kept in sync with ContentViewClient.java |
29 | |
30 // This enum must be kept in sync with ContentViewClient.java | |
31 enum ContentViewClientError { | 27 enum ContentViewClientError { |
32 // Success | 28 // Success |
33 CONTENT_VIEW_CLIENT_ERROR_OK = 0, | 29 CONTENT_VIEW_CLIENT_ERROR_OK = 0, |
34 // Generic error | 30 // Generic error |
35 CONTENT_VIEW_CLIENT_ERROR_UNKNOWN = -1, | 31 CONTENT_VIEW_CLIENT_ERROR_UNKNOWN = -1, |
36 // Server or proxy hostname lookup failed | 32 // Server or proxy hostname lookup failed |
37 CONTENT_VIEW_CLIENT_ERROR_HOST_LOOKUP = -2, | 33 CONTENT_VIEW_CLIENT_ERROR_HOST_LOOKUP = -2, |
38 // Unsupported authentication scheme (not basic or digest) | 34 // Unsupported authentication scheme (not basic or digest) |
39 CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_AUTH_SCHEME = -3, | 35 CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_AUTH_SCHEME = -3, |
40 // User authentication failed on server | 36 // User authentication failed on server |
(...skipping 15 matching lines...) Expand all Loading... |
56 // Malformed URL | 52 // Malformed URL |
57 CONTENT_VIEW_CLIENT_ERROR_BAD_URL = -12, | 53 CONTENT_VIEW_CLIENT_ERROR_BAD_URL = -12, |
58 // Generic file error | 54 // Generic file error |
59 CONTENT_VIEW_CLIENT_ERROR_FILE = -13, | 55 CONTENT_VIEW_CLIENT_ERROR_FILE = -13, |
60 // File not found | 56 // File not found |
61 CONTENT_VIEW_CLIENT_ERROR_FILE_NOT_FOUND = -14, | 57 CONTENT_VIEW_CLIENT_ERROR_FILE_NOT_FOUND = -14, |
62 // Too many requests during this load | 58 // Too many requests during this load |
63 CONTENT_VIEW_CLIENT_ERROR_TOO_MANY_REQUESTS = -15, | 59 CONTENT_VIEW_CLIENT_ERROR_TOO_MANY_REQUESTS = -15, |
64 }; | 60 }; |
65 | 61 |
66 // Native mirror of ContentViewClient.java. Uses as a client of | 62 // Native mirror of ContentViewClient.java. Used as a client of |
67 // ContentView, the main FrameLayout on Android. | 63 // ContentView, the main FrameLayout on Android. |
68 class ContentViewClient : public WebContentsDelegate { | 64 // TODO(joth): Delete this C++ class, to make it Java-only. All the callbacks |
| 65 // defined here originate in WebContentsObserver; we should have a dedicated |
| 66 // bridge class for that rather than overloading ContentViewClient with this. |
| 67 // See http://crbug.com/137967 |
| 68 class ContentViewClient { |
69 public: | 69 public: |
70 ContentViewClient(JNIEnv* env, jobject obj); | 70 ContentViewClient(JNIEnv* env, jobject obj); |
| 71 ~ContentViewClient(); |
71 | 72 |
72 static ContentViewClient* CreateNativeContentViewClient(JNIEnv* env, | 73 static ContentViewClient* CreateNativeContentViewClient(JNIEnv* env, |
73 jobject obj); | 74 jobject obj); |
74 | 75 |
75 // Called by ContentView: | 76 // Called by ContentView: |
76 void OnInternalPageLoadRequest(WebContents* source, | 77 void OnInternalPageLoadRequest(WebContents* source, |
77 const GURL& url); | 78 const GURL& url); |
78 void OnPageStarted(const GURL& url); | 79 void OnPageStarted(const GURL& url); |
79 void OnPageFinished(const GURL& url); | 80 void OnPageFinished(const GURL& url); |
80 void OnLoadStarted(); | 81 void OnLoadStarted(); |
81 void OnLoadStopped(); | 82 void OnLoadStopped(); |
82 void OnReceivedError(int error_code, | 83 void OnReceivedError(int error_code, |
83 const string16& description, | 84 const string16& description, |
84 const GURL& url); | 85 const GURL& url); |
85 void OnDidCommitMainFrame(const GURL& url, | 86 void OnDidCommitMainFrame(const GURL& url, |
86 const GURL& base_url); | 87 const GURL& base_url); |
87 void OnInterstitialShown(); | 88 void OnInterstitialShown(); |
88 void OnInterstitialHidden(); | 89 void OnInterstitialHidden(); |
89 | 90 |
90 void SetFindHelper(FindHelper* find_helper); | |
91 void SetJavaScriptDialogCreator( | 91 void SetJavaScriptDialogCreator( |
92 JavaScriptDialogCreator* javascript_dialog_creator); | 92 JavaScriptDialogCreator* javascript_dialog_creator); |
93 | 93 |
94 bool OnJSModalDialog(JavaScriptMessageType type, | 94 bool OnJSModalDialog(JavaScriptMessageType type, |
95 bool is_before_unload_dialog, | 95 bool is_before_unload_dialog, |
96 const GURL& url, | 96 const GURL& url, |
97 const string16& message, | 97 const string16& message, |
98 const string16& default_value); | 98 const string16& default_value); |
99 | 99 |
100 // Returns the actual load progress, a value between 0 (nothing loaded) and | |
101 // 1 (page fully loaded). | |
102 virtual double GetLoadProgress() const; | |
103 | |
104 // Overridden from WebContentsDelegate: | |
105 virtual WebContents* OpenURLFromTab( | |
106 WebContents* source, | |
107 const OpenURLParams& params) OVERRIDE; | |
108 virtual bool ShouldIgnoreNavigation( | |
109 WebContents* source, | |
110 const GURL& url, | |
111 const Referrer& referrer, | |
112 WindowOpenDisposition disposition, | |
113 PageTransition transition_type) OVERRIDE; | |
114 virtual void NavigationStateChanged(const WebContents* source, | |
115 unsigned changed_flags) OVERRIDE; | |
116 virtual void AddNewContents(WebContents* source, | |
117 WebContents* new_contents, | |
118 WindowOpenDisposition disposition, | |
119 const gfx::Rect& initial_pos, | |
120 bool user_gesture) OVERRIDE; | |
121 virtual void ActivateContents(WebContents* contents) OVERRIDE; | |
122 virtual void DeactivateContents(WebContents* contents) OVERRIDE; | |
123 virtual void LoadingStateChanged(WebContents* source) OVERRIDE; | |
124 virtual void LoadProgressChanged(double load_progress) OVERRIDE; | |
125 virtual void CloseContents(WebContents* source) OVERRIDE; | |
126 virtual void MoveContents(WebContents* source, | |
127 const gfx::Rect& pos) OVERRIDE; | |
128 // TODO(merge): WARNING! method no longer available on the base class. | |
129 // See http://b/issue?id=5862108 | |
130 virtual void URLStarredChanged(WebContents* source, bool starred); | |
131 virtual void UpdateTargetURL(WebContents* source, | |
132 int32 page_id, | |
133 const GURL& url) OVERRIDE; | |
134 virtual bool CanDownload(RenderViewHost* source, | |
135 int request_id, | |
136 const std::string& request_method) OVERRIDE; | |
137 virtual void OnStartDownload(WebContents* source, | |
138 DownloadItem* download) OVERRIDE; | |
139 virtual void FindReply(WebContents* tab, | |
140 int request_id, | |
141 int number_of_matches, | |
142 const gfx::Rect& selection_rect, | |
143 int active_match_ordinal, | |
144 bool final_update) OVERRIDE; | |
145 virtual void OnReceiveFindMatchRects(int version, | |
146 const std::vector<FindMatchRect>& rects, | |
147 const FindMatchRect& active_rect) OVERRIDE; | |
148 virtual bool ShouldOverrideLoading(const GURL& url) OVERRIDE; | |
149 virtual void HandleKeyboardEvent( | |
150 const NativeWebKeyboardEvent& event) OVERRIDE; | |
151 virtual JavaScriptDialogCreator* GetJavaScriptDialogCreator() OVERRIDE; | |
152 virtual void RunFileChooser( | |
153 WebContents* tab, | |
154 const FileChooserParams& params) OVERRIDE; | |
155 virtual bool TakeFocus(bool reverse) OVERRIDE; | |
156 | |
157 virtual ~ContentViewClient(); | |
158 | |
159 private: | 100 private: |
160 // Get the closest ContentViewClient match to the given Chrome error code. | 101 // Get the closest ContentViewClient match to the given Chrome error code. |
161 static ContentViewClientError ToContentViewClientError(int net_error); | 102 static ContentViewClientError ToContentViewClientError(int net_error); |
162 | 103 |
163 // We use this to keep track of whether the navigation we get in | |
164 // ShouldIgnoreNavigation has been initiated by the ContentView or not. We | |
165 // need the GURL, because the active navigation entry doesn't change on | |
166 // redirects. | |
167 GURL last_requested_navigation_url_; | |
168 | |
169 // We depend on ContentView.java to hold a ref to the client object. If we | 104 // We depend on ContentView.java to hold a ref to the client object. If we |
170 // were to hold a hard ref from native we could end up with a cyclic | 105 // were to hold a hard ref from native we could end up with a cyclic |
171 // ownership leak (the GC can't collect cycles if part of the cycle is caused | 106 // ownership leak (the GC can't collect cycles if part of the cycle is caused |
172 // by native). | 107 // by native). |
173 JavaObjectWeakGlobalRef weak_java_client_; | 108 JavaObjectWeakGlobalRef weak_java_client_; |
174 | |
175 // Used to process find replies. Owned by the ContentView. The ContentView | |
176 // NULLs this pointer when the FindHelper goes away. | |
177 FindHelper* find_helper_; | |
178 | |
179 // The object responsible for creating JavaScript dialogs. | |
180 JavaScriptDialogCreator* javascript_dialog_creator_; | |
181 | |
182 // Indicates the load state of the page. 0.0 means nothing loaded, 1 means | |
183 // fully loaded. | |
184 double load_progress_; | |
185 }; | 109 }; |
186 | 110 |
187 bool RegisterContentViewClient(JNIEnv* env); | 111 bool RegisterContentViewClient(JNIEnv* env); |
188 | 112 |
189 } // namespace content | 113 } // namespace content |
190 | 114 |
191 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | 115 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ |
OLD | NEW |