| 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 #include "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "content/browser/android/content_view_client.h" | 12 #include "content/browser/android/content_view_client.h" |
| 13 #include "content/browser/android/load_url_params.h" |
| 13 #include "content/browser/android/touch_point.h" | 14 #include "content/browser/android/touch_point.h" |
| 14 #include "content/browser/renderer_host/java/java_bound_object.h" | 15 #include "content/browser/renderer_host/java/java_bound_object.h" |
| 15 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" | 16 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_impl.h" | 18 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 19 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 19 #include "content/browser/web_contents/navigation_controller_impl.h" | 20 #include "content/browser/web_contents/navigation_controller_impl.h" |
| 20 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/favicon_status.h" | 22 #include "content/public/browser/favicon_status.h" |
| 22 #include "content/public/browser/interstitial_page.h" | 23 #include "content/public/browser/interstitial_page.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 27 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/common/page_transition_types.h" |
| 29 #include "jni/ContentViewCore_jni.h" | 31 #include "jni/ContentViewCore_jni.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" |
| 33 #include "ui/gfx/android/java_bitmap.h" | 35 #include "ui/gfx/android/java_bitmap.h" |
| 34 #include "webkit/glue/webmenuitem.h" | 36 #include "webkit/glue/webmenuitem.h" |
| 35 | 37 |
| 36 using base::android::AttachCurrentThread; | 38 using base::android::AttachCurrentThread; |
| 37 using base::android::ConvertJavaStringToUTF16; | 39 using base::android::ConvertJavaStringToUTF16; |
| 40 using base::android::ConvertJavaStringToUTF8; |
| 38 using base::android::ConvertUTF16ToJavaString; | 41 using base::android::ConvertUTF16ToJavaString; |
| 39 using base::android::ConvertUTF8ToJavaString; | 42 using base::android::ConvertUTF8ToJavaString; |
| 40 using base::android::GetClass; | 43 using base::android::GetClass; |
| 41 using base::android::HasField; | 44 using base::android::HasField; |
| 45 using base::android::JavaByteArrayToByteVector; |
| 42 using base::android::ScopedJavaGlobalRef; | 46 using base::android::ScopedJavaGlobalRef; |
| 43 using base::android::ScopedJavaLocalRef; | 47 using base::android::ScopedJavaLocalRef; |
| 44 using WebKit::WebInputEvent; | 48 using WebKit::WebInputEvent; |
| 45 using WebKit::WebInputEventFactory; | 49 using WebKit::WebInputEventFactory; |
| 46 | 50 |
| 47 // Describes the type and enabled state of a select popup item. | 51 // Describes the type and enabled state of a select popup item. |
| 48 // Keep in sync with the value defined in SelectPopupDialog.java | 52 // Keep in sync with the value defined in SelectPopupDialog.java |
| 49 enum PopupItemType { | 53 enum PopupItemType { |
| 50 POPUP_ITEM_TYPE_GROUP = 0, | 54 POPUP_ITEM_TYPE_GROUP = 0, |
| 51 POPUP_ITEM_TYPE_DISABLED, | 55 POPUP_ITEM_TYPE_DISABLED, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 176 |
| 173 jint ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, jobject obj, | 177 jint ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, jobject obj, |
| 174 jstring script) { | 178 jstring script) { |
| 175 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 179 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 176 | 180 |
| 177 string16 script_utf16 = ConvertJavaStringToUTF16(env, script); | 181 string16 script_utf16 = ConvertJavaStringToUTF16(env, script); |
| 178 return host->ExecuteJavascriptInWebFrameNotifyResult(string16(), | 182 return host->ExecuteJavascriptInWebFrameNotifyResult(string16(), |
| 179 script_utf16); | 183 script_utf16); |
| 180 } | 184 } |
| 181 | 185 |
| 182 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, | 186 void ContentViewCoreImpl::LoadUrl( |
| 183 jobject, | 187 JNIEnv* env, jobject obj, |
| 184 jstring jurl, | 188 jstring url, |
| 185 int page_transition) { | 189 jint load_url_type, |
| 186 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 190 jint transition_type, |
| 191 jint ua_override_option, |
| 192 jstring extra_headers, |
| 193 jbyteArray post_data, |
| 194 jstring base_url_for_data_url, |
| 195 jstring virtual_url_for_data_url) { |
| 196 DCHECK(url); |
| 197 NavigationController::LoadURLParams params( |
| 198 GURL(ConvertJavaStringToUTF8(env, url))); |
| 187 | 199 |
| 188 LoadUrl(url, page_transition); | 200 params.load_type = static_cast<NavigationController::LoadURLType>( |
| 189 } | 201 load_url_type); |
| 202 params.transition_type = PageTransitionFromInt(transition_type); |
| 203 params.override_user_agent = |
| 204 static_cast<NavigationController::UserAgentOverrideOption>( |
| 205 ua_override_option); |
| 190 | 206 |
| 191 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitizationWithUserAgentOverride( | 207 if (extra_headers) |
| 192 JNIEnv* env, | 208 params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers); |
| 193 jobject, | |
| 194 jstring jurl, | |
| 195 int page_transition, | |
| 196 jstring user_agent_override) { | |
| 197 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | |
| 198 | 209 |
| 199 LoadUrlWithUserAgentOverride( | 210 if (post_data) { |
| 200 url, | 211 std::vector<uint8> http_body_vector; |
| 201 page_transition, | 212 JavaByteArrayToByteVector(env, post_data, &http_body_vector); |
| 202 base::android::ConvertJavaStringToUTF8(env, user_agent_override)); | 213 params.browser_initiated_post_data = |
| 214 base::RefCountedBytes::TakeVector(&http_body_vector); |
| 215 } |
| 216 |
| 217 if (base_url_for_data_url) { |
| 218 params.base_url_for_data_url = |
| 219 GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url)); |
| 220 } |
| 221 |
| 222 if (virtual_url_for_data_url) { |
| 223 params.virtual_url_for_data_url = |
| 224 GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url)); |
| 225 } |
| 226 |
| 227 LoadUrl(params); |
| 203 } | 228 } |
| 204 | 229 |
| 205 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( | 230 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( |
| 206 JNIEnv* env, jobject) const { | 231 JNIEnv* env, jobject) const { |
| 207 return ConvertUTF8ToJavaString(env, web_contents()->GetURL().spec()); | 232 return ConvertUTF8ToJavaString(env, web_contents()->GetURL().spec()); |
| 208 } | 233 } |
| 209 | 234 |
| 210 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetTitle( | 235 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetTitle( |
| 211 JNIEnv* env, jobject obj) const { | 236 JNIEnv* env, jobject obj) const { |
| 212 return ConvertUTF16ToJavaString(env, web_contents()->GetTitle()); | 237 return ConvertUTF16ToJavaString(env, web_contents()->GetTitle()); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 j_bitmap.obj()); | 454 j_bitmap.obj()); |
| 430 } | 455 } |
| 431 | 456 |
| 432 return controller.GetCurrentEntryIndex(); | 457 return controller.GetCurrentEntryIndex(); |
| 433 } | 458 } |
| 434 | 459 |
| 435 // -------------------------------------------------------------------------- | 460 // -------------------------------------------------------------------------- |
| 436 // Methods called from native code | 461 // Methods called from native code |
| 437 // -------------------------------------------------------------------------- | 462 // -------------------------------------------------------------------------- |
| 438 | 463 |
| 439 void ContentViewCoreImpl::LoadUrl(const GURL& url, int page_transition) { | 464 void ContentViewCoreImpl::LoadUrl( |
| 440 content::Referrer referer; | 465 NavigationController::LoadURLParams& params) { |
| 441 | 466 web_contents()->GetController().LoadURLWithParams(params); |
| 442 web_contents()->GetController().LoadURL( | 467 PostLoadUrl(params.url); |
| 443 url, referer, content::PageTransitionFromInt(page_transition), | |
| 444 std::string()); | |
| 445 PostLoadUrl(url); | |
| 446 } | |
| 447 | |
| 448 void ContentViewCoreImpl::LoadUrlWithUserAgentOverride( | |
| 449 const GURL& url, | |
| 450 int page_transition, | |
| 451 const std::string& user_agent_override) { | |
| 452 web_contents()->SetUserAgentOverride(user_agent_override); | |
| 453 bool is_overriding_user_agent(!user_agent_override.empty()); | |
| 454 | |
| 455 content::NavigationController::LoadURLParams load_url_params(url); | |
| 456 load_url_params.transition_type = | |
| 457 content::PageTransitionFromInt(page_transition); | |
| 458 load_url_params.override_user_agent = is_overriding_user_agent ? | |
| 459 content::NavigationController::UA_OVERRIDE_TRUE : | |
| 460 content::NavigationController::UA_OVERRIDE_FALSE; | |
| 461 | |
| 462 web_contents()->GetController().LoadURLWithParams(load_url_params); | |
| 463 | |
| 464 PostLoadUrl(url); | |
| 465 } | 468 } |
| 466 | 469 |
| 467 void ContentViewCoreImpl::PostLoadUrl(const GURL& url) { | 470 void ContentViewCoreImpl::PostLoadUrl(const GURL& url) { |
| 468 tab_crashed_ = false; | 471 tab_crashed_ = false; |
| 469 // TODO(tedchoc): Update the content view client of the page load request. | 472 // TODO(tedchoc): Update the content view client of the page load request. |
| 470 } | 473 } |
| 471 | 474 |
| 472 // ---------------------------------------------------------------------------- | 475 // ---------------------------------------------------------------------------- |
| 473 // Native JNI methods | 476 // Native JNI methods |
| 474 // ---------------------------------------------------------------------------- | 477 // ---------------------------------------------------------------------------- |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 626 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
| 624 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 627 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
| 625 return false; | 628 return false; |
| 626 } | 629 } |
| 627 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 630 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
| 628 | 631 |
| 629 return RegisterNativesImpl(env) >= 0; | 632 return RegisterNativesImpl(env) >= 0; |
| 630 } | 633 } |
| 631 | 634 |
| 632 } // namespace content | 635 } // namespace content |
| OLD | NEW |