| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/web_contents_observer_proxy.h" | 5 #include "content/browser/android/web_contents_observer_proxy.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/optional.h" | 12 #include "base/optional.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/common/android/media_metadata_android.h" | 16 #include "content/common/android/media_metadata_android.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
| 20 #include "content/public/common/media_metadata.h" | 20 #include "content/public/common/media_metadata.h" |
| 21 #include "jni/NavigationHandle_jni.h" |
| 21 #include "jni/WebContentsObserverProxy_jni.h" | 22 #include "jni/WebContentsObserverProxy_jni.h" |
| 22 | 23 |
| 23 using base::android::AttachCurrentThread; | 24 using base::android::AttachCurrentThread; |
| 24 using base::android::JavaParamRef; | 25 using base::android::JavaParamRef; |
| 25 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
| 26 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
| 27 using base::android::ConvertUTF16ToJavaString; | 28 using base::android::ConvertUTF16ToJavaString; |
| 28 | 29 |
| 30 namespace { |
| 31 |
| 32 // static |
| 33 static base::android::ScopedJavaLocalRef<jobject> CreateJavaNavigationHandle( |
| 34 JNIEnv* env, |
| 35 content::NavigationHandle* navigation_handle) { |
| 36 ScopedJavaLocalRef<jstring> j_url( |
| 37 ConvertUTF8ToJavaString(env, navigation_handle->GetURL().spec())); |
| 38 |
| 39 GURL validated_url(navigation_handle->GetURL()); |
| 40 if (navigation_handle->GetRenderFrameHost() && |
| 41 navigation_handle->GetRenderFrameHost()->GetProcess()) { |
| 42 navigation_handle->GetRenderFrameHost()->GetProcess()->FilterURL( |
| 43 false, &validated_url); |
| 44 } |
| 45 |
| 46 ScopedJavaLocalRef<jstring> j_validated_url( |
| 47 ConvertUTF8ToJavaString(env, validated_url.spec())); |
| 48 return content::Java_NavigationHandle_createNavigationHandle( |
| 49 env, j_url, j_validated_url, navigation_handle->IsInMainFrame(), |
| 50 navigation_handle->IsSamePage(), navigation_handle->GetPageTransition(), |
| 51 navigation_handle->HasCommitted(), navigation_handle->IsErrorPage()); |
| 52 } |
| 53 |
| 54 } // namespace |
| 55 |
| 29 namespace content { | 56 namespace content { |
| 30 | 57 |
| 31 // TODO(dcheng): File a bug. This class incorrectly passes just a frame ID, | 58 // TODO(dcheng): File a bug. This class incorrectly passes just a frame ID, |
| 32 // which is not sufficient to identify a frame (since frame IDs are scoped per | 59 // which is not sufficient to identify a frame (since frame IDs are scoped per |
| 33 // render process, and so may collide). | 60 // render process, and so may collide). |
| 34 WebContentsObserverProxy::WebContentsObserverProxy(JNIEnv* env, | 61 WebContentsObserverProxy::WebContentsObserverProxy(JNIEnv* env, |
| 35 jobject obj, | 62 jobject obj, |
| 36 WebContents* web_contents) | 63 WebContents* web_contents) |
| 37 : WebContentsObserver(web_contents) { | 64 : WebContentsObserver(web_contents) { |
| 38 DCHECK(obj); | 65 DCHECK(obj); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 101 |
| 75 void WebContentsObserverProxy::RenderProcessGone( | 102 void WebContentsObserverProxy::RenderProcessGone( |
| 76 base::TerminationStatus termination_status) { | 103 base::TerminationStatus termination_status) { |
| 77 JNIEnv* env = AttachCurrentThread(); | 104 JNIEnv* env = AttachCurrentThread(); |
| 78 ScopedJavaLocalRef<jobject> obj(java_observer_); | 105 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 79 jboolean was_oom_protected = | 106 jboolean was_oom_protected = |
| 80 termination_status == base::TERMINATION_STATUS_OOM_PROTECTED; | 107 termination_status == base::TERMINATION_STATUS_OOM_PROTECTED; |
| 81 Java_WebContentsObserverProxy_renderProcessGone(env, obj, was_oom_protected); | 108 Java_WebContentsObserverProxy_renderProcessGone(env, obj, was_oom_protected); |
| 82 } | 109 } |
| 83 | 110 |
| 84 void WebContentsObserverProxy::DidFinishNavigation( | |
| 85 NavigationHandle* navigation_handle) { | |
| 86 JNIEnv* env = AttachCurrentThread(); | |
| 87 ScopedJavaLocalRef<jobject> obj(java_observer_); | |
| 88 ScopedJavaLocalRef<jstring> jstring_url( | |
| 89 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); | |
| 90 Java_WebContentsObserverProxy_didFinishNavigation( | |
| 91 env, obj, navigation_handle->IsInMainFrame(), | |
| 92 navigation_handle->IsErrorPage(), navigation_handle->HasCommitted()); | |
| 93 } | |
| 94 | |
| 95 void WebContentsObserverProxy::DidStartLoading() { | 111 void WebContentsObserverProxy::DidStartLoading() { |
| 96 JNIEnv* env = AttachCurrentThread(); | 112 JNIEnv* env = AttachCurrentThread(); |
| 97 ScopedJavaLocalRef<jobject> obj(java_observer_); | 113 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 98 ScopedJavaLocalRef<jstring> jstring_url( | 114 ScopedJavaLocalRef<jstring> jstring_url( |
| 99 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); | 115 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); |
| 100 if (auto* entry = web_contents()->GetController().GetPendingEntry()) { | 116 if (auto* entry = web_contents()->GetController().GetPendingEntry()) { |
| 101 base_url_of_last_started_data_url_ = entry->GetBaseURLForDataURL(); | 117 base_url_of_last_started_data_url_ = entry->GetBaseURLForDataURL(); |
| 102 } | 118 } |
| 103 Java_WebContentsObserverProxy_didStartLoading(env, obj, jstring_url); | 119 Java_WebContentsObserverProxy_didStartLoading(env, obj, jstring_url); |
| 104 } | 120 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 Java_WebContentsObserverProxy_didNavigateAnyFrame( | 197 Java_WebContentsObserverProxy_didNavigateAnyFrame( |
| 182 env, obj, jstring_url, jstring_base_url, jboolean_is_reload); | 198 env, obj, jstring_url, jstring_base_url, jboolean_is_reload); |
| 183 } | 199 } |
| 184 | 200 |
| 185 void WebContentsObserverProxy::DocumentAvailableInMainFrame() { | 201 void WebContentsObserverProxy::DocumentAvailableInMainFrame() { |
| 186 JNIEnv* env = AttachCurrentThread(); | 202 JNIEnv* env = AttachCurrentThread(); |
| 187 ScopedJavaLocalRef<jobject> obj(java_observer_); | 203 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 188 Java_WebContentsObserverProxy_documentAvailableInMainFrame(env, obj); | 204 Java_WebContentsObserverProxy_documentAvailableInMainFrame(env, obj); |
| 189 } | 205 } |
| 190 | 206 |
| 207 void WebContentsObserverProxy::DidStartNavigation( |
| 208 NavigationHandle* navigation_handle) { |
| 209 JNIEnv* env = AttachCurrentThread(); |
| 210 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 211 Java_WebContentsObserverProxy_didStartNavigation( |
| 212 env, obj, CreateJavaNavigationHandle(env, navigation_handle)); |
| 213 } |
| 214 |
| 215 void WebContentsObserverProxy::DidRedirectNavigation( |
| 216 NavigationHandle* navigation_handle) { |
| 217 JNIEnv* env = AttachCurrentThread(); |
| 218 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 219 Java_WebContentsObserverProxy_didRedirectNavigation( |
| 220 env, obj, CreateJavaNavigationHandle(env, navigation_handle)); |
| 221 } |
| 222 |
| 223 void WebContentsObserverProxy::ReadyToCommitNavigation( |
| 224 NavigationHandle* navigation_handle) { |
| 225 JNIEnv* env = AttachCurrentThread(); |
| 226 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 227 Java_WebContentsObserverProxy_readyToCommitNavigation( |
| 228 env, obj, CreateJavaNavigationHandle(env, navigation_handle)); |
| 229 } |
| 230 |
| 231 void WebContentsObserverProxy::DidFinishNavigation( |
| 232 NavigationHandle* navigation_handle) { |
| 233 JNIEnv* env = AttachCurrentThread(); |
| 234 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 235 Java_WebContentsObserverProxy_didFinishNavigation( |
| 236 env, obj, CreateJavaNavigationHandle(env, navigation_handle)); |
| 237 } |
| 238 |
| 191 void WebContentsObserverProxy::DidStartProvisionalLoadForFrame( | 239 void WebContentsObserverProxy::DidStartProvisionalLoadForFrame( |
| 192 RenderFrameHost* render_frame_host, | 240 RenderFrameHost* render_frame_host, |
| 193 const GURL& validated_url, | 241 const GURL& validated_url, |
| 194 bool is_error_page) { | 242 bool is_error_page) { |
| 195 JNIEnv* env = AttachCurrentThread(); | 243 JNIEnv* env = AttachCurrentThread(); |
| 196 ScopedJavaLocalRef<jobject> obj(java_observer_); | 244 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 197 ScopedJavaLocalRef<jstring> jstring_url( | 245 ScopedJavaLocalRef<jstring> jstring_url( |
| 198 ConvertUTF8ToJavaString(env, validated_url.spec())); | 246 ConvertUTF8ToJavaString(env, validated_url.spec())); |
| 199 // TODO(dcheng): Does Java really need the parent frame ID? It doesn't appear | 247 // TODO(dcheng): Does Java really need the parent frame ID? It doesn't appear |
| 200 // to be used at all, and it just adds complexity here. | 248 // to be used at all, and it just adds complexity here. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 // a base URL if there has been a loadUrl("javascript:...") after | 389 // a base URL if there has been a loadUrl("javascript:...") after |
| 342 // loadDataWithBaseUrl. | 390 // loadDataWithBaseUrl. |
| 343 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); | 391 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); |
| 344 } | 392 } |
| 345 } | 393 } |
| 346 | 394 |
| 347 bool RegisterWebContentsObserverProxy(JNIEnv* env) { | 395 bool RegisterWebContentsObserverProxy(JNIEnv* env) { |
| 348 return RegisterNativesImpl(env); | 396 return RegisterNativesImpl(env); |
| 349 } | 397 } |
| 350 } // namespace content | 398 } // namespace content |
| OLD | NEW |