OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "content/browser/frame_host/navigation_controller_android.h" | 5 #include "content/browser/frame_host/navigation_controller_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "content/public/browser/navigation_controller.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | |
10 #include "content/browser/frame_host/navigation_entry_impl.h" | |
Yaron
2014/07/22 20:49:05
can this just use content/public/browser/frame_hos
AKVT
2014/07/23 11:49:23
"favicon_status.h" header is missing in navigation
Yaron
2014/07/23 18:58:37
I think you should include it too then. You aren't
| |
11 #include "content/browser/ssl/ssl_host_state.h" | |
9 #include "jni/NavigationControllerImpl_jni.h" | 12 #include "jni/NavigationControllerImpl_jni.h" |
13 #include "ui/gfx/android/java_bitmap.h" | |
10 | 14 |
11 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
16 using base::android::ConvertJavaStringToUTF16; | |
17 using base::android::ConvertJavaStringToUTF8; | |
18 using base::android::ConvertUTF16ToJavaString; | |
19 using base::android::ConvertUTF8ToJavaString; | |
12 | 20 |
13 namespace content { | 21 namespace content { |
14 | 22 |
15 // static | 23 // static |
16 bool NavigationControllerAndroid::Register(JNIEnv* env) { | 24 bool NavigationControllerAndroid::Register(JNIEnv* env) { |
17 return RegisterNativesImpl(env); | 25 return RegisterNativesImpl(env); |
18 } | 26 } |
19 | 27 |
20 NavigationControllerAndroid::NavigationControllerAndroid( | 28 NavigationControllerAndroid::NavigationControllerAndroid( |
21 NavigationController* navigation_controller) | 29 NavigationController* navigation_controller) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 jobject obj) { | 102 jobject obj) { |
95 navigation_controller_->CancelPendingReload(); | 103 navigation_controller_->CancelPendingReload(); |
96 } | 104 } |
97 | 105 |
98 void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env, | 106 void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env, |
99 jobject obj, | 107 jobject obj, |
100 jint index) { | 108 jint index) { |
101 navigation_controller_->GoToIndex(index); | 109 navigation_controller_->GoToIndex(index); |
102 } | 110 } |
103 | 111 |
112 void NavigationControllerAndroid::LoadUrl( | |
113 NavigationController::LoadURLParams& params) { | |
114 navigation_controller_->LoadURLWithParams(params); | |
115 } | |
116 | |
117 void NavigationControllerAndroid::LoadUrl( | |
118 JNIEnv* env, jobject obj, | |
119 jstring url, | |
120 jint load_url_type, | |
121 jint transition_type, | |
122 jstring j_referrer_url, | |
123 jint referrer_policy, | |
124 jint ua_override_option, | |
125 jstring extra_headers, | |
126 jbyteArray post_data, | |
127 jstring base_url_for_data_url, | |
128 jstring virtual_url_for_data_url, | |
129 jboolean can_load_local_resources, | |
130 jboolean is_renderer_initiated) { | |
131 DCHECK(url); | |
132 NavigationController::LoadURLParams params( | |
133 GURL(ConvertJavaStringToUTF8(env, url))); | |
134 | |
135 params.load_type = static_cast<NavigationController::LoadURLType>( | |
136 load_url_type); | |
137 params.transition_type = PageTransitionFromInt(transition_type); | |
138 params.override_user_agent = | |
139 static_cast<NavigationController::UserAgentOverrideOption>( | |
140 ua_override_option); | |
141 | |
142 if (extra_headers) | |
143 params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers); | |
144 | |
145 if (post_data) { | |
146 std::vector<uint8> http_body_vector; | |
147 base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector); | |
148 params.browser_initiated_post_data = | |
149 base::RefCountedBytes::TakeVector(&http_body_vector); | |
150 } | |
151 | |
152 if (base_url_for_data_url) { | |
153 params.base_url_for_data_url = | |
154 GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url)); | |
155 } | |
156 | |
157 if (virtual_url_for_data_url) { | |
158 params.virtual_url_for_data_url = | |
159 GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url)); | |
160 } | |
161 | |
162 params.can_load_local_resources = can_load_local_resources; | |
163 if (j_referrer_url) { | |
164 params.referrer = content::Referrer( | |
165 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), | |
166 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | |
167 } | |
168 | |
169 params.is_renderer_initiated = is_renderer_initiated; | |
170 | |
171 LoadUrl(params); | |
Yaron
2014/07/22 20:49:05
just call LoadUrlWithParams directly and get rid o
AKVT
2014/07/23 11:49:23
Done.
| |
172 } | |
173 | |
174 void NavigationControllerAndroid::ClearHistory(JNIEnv* env, jobject obj) { | |
175 // TODO(creis): Do callers of this need to know if it fails? | |
176 if (navigation_controller_->CanPruneAllButLastCommitted()) | |
177 navigation_controller_->PruneAllButLastCommitted(); | |
178 } | |
179 | |
180 namespace { | |
Yaron
2014/07/22 20:49:05
please move this namespace up above all the member
AKVT
2014/07/23 11:49:23
Done.
| |
181 | |
182 static void AddNavigationEntryToHistory( | |
183 JNIEnv* env, | |
184 jobject obj, | |
185 jobject history, | |
186 NavigationEntry* entry, | |
187 int index) { | |
188 // Get the details of the current entry | |
189 ScopedJavaLocalRef<jstring> j_url( | |
190 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); | |
191 ScopedJavaLocalRef<jstring> j_virtual_url( | |
192 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); | |
193 ScopedJavaLocalRef<jstring> j_original_url( | |
194 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); | |
195 ScopedJavaLocalRef<jstring> j_title( | |
196 ConvertUTF16ToJavaString(env, entry->GetTitle())); | |
197 ScopedJavaLocalRef<jobject> j_bitmap; | |
198 const FaviconStatus& status = entry->GetFavicon(); | |
199 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) | |
200 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | |
201 | |
202 // Add the item to the list | |
203 Java_NavigationControllerImpl_addToNavigationHistory( | |
204 env, obj, history, index, j_url.obj(), j_virtual_url.obj(), | |
205 j_original_url.obj(), j_title.obj(), j_bitmap.obj()); | |
206 } | |
207 | |
208 } // namespace | |
209 | |
210 jint NavigationControllerAndroid::GetNavigationHistory( | |
211 JNIEnv* env, | |
212 jobject obj, | |
213 jobject history) { | |
214 // Iterate through navigation entries to populate the list | |
215 int count = navigation_controller_->GetEntryCount(); | |
216 for (int i = 0; i < count; ++i) { | |
217 AddNavigationEntryToHistory( | |
218 env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); | |
219 } | |
220 | |
221 return navigation_controller_->GetCurrentEntryIndex(); | |
222 } | |
223 | |
224 void NavigationControllerAndroid::GetDirectedNavigationHistory( | |
225 JNIEnv* env, | |
226 jobject obj, | |
227 jobject history, | |
228 jboolean is_forward, | |
229 jint max_entries) { | |
230 // Iterate through navigation entries to populate the list | |
231 int count = navigation_controller_->GetEntryCount(); | |
232 int num_added = 0; | |
233 int increment_value = is_forward ? 1 : -1; | |
234 for (int i = navigation_controller_->GetCurrentEntryIndex() + increment_value; | |
235 i >= 0 && i < count; | |
236 i += increment_value) { | |
237 if (num_added >= max_entries) | |
238 break; | |
239 | |
240 AddNavigationEntryToHistory( | |
241 env, obj, history, navigation_controller_->GetEntryAtIndex(i), i); | |
242 num_added++; | |
243 } | |
244 } | |
245 | |
246 ScopedJavaLocalRef<jstring> | |
247 NavigationControllerAndroid::GetOriginalUrlForActiveNavigationEntry( | |
248 JNIEnv* env, | |
249 jobject obj) { | |
250 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); | |
251 if (entry == NULL) | |
252 return ScopedJavaLocalRef<jstring>(env, NULL); | |
253 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); | |
254 } | |
255 | |
256 void NavigationControllerAndroid::ClearSslPreferences( | |
257 JNIEnv* env, | |
258 jobject obj) { | |
259 SSLHostState* state = SSLHostState::GetFor( | |
260 navigation_controller_->GetBrowserContext()); | |
261 state->Clear(); | |
262 } | |
263 | |
264 bool NavigationControllerAndroid::GetUseDesktopUserAgent( | |
265 JNIEnv* env, | |
266 jobject obj) { | |
267 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); | |
268 return entry && entry->GetIsOverridingUserAgent(); | |
269 } | |
270 | |
271 void NavigationControllerAndroid::SetUseDesktopUserAgent( | |
272 JNIEnv* env, | |
273 jobject obj, | |
274 jboolean enabled, | |
275 jboolean reload_on_state_change) { | |
276 if (GetUseDesktopUserAgent(env, obj) == enabled) | |
277 return; | |
278 | |
279 // Make sure the navigation entry actually exists. | |
280 NavigationEntry* entry = navigation_controller_->GetVisibleEntry(); | |
281 if (!entry) | |
282 return; | |
283 | |
284 // Set the flag in the NavigationEntry. | |
285 entry->SetIsOverridingUserAgent(enabled); | |
286 | |
287 // Send the override to the renderer. | |
288 if (reload_on_state_change) { | |
289 // Reloading the page will send the override down as part of the | |
290 // navigation IPC message. | |
291 navigation_controller_->ReloadOriginalRequestURL(false); | |
292 } | |
293 } | |
294 | |
104 } // namespace content | 295 } // namespace content |
OLD | NEW |