Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "content/browser/renderer_host/render_view_host_impl.h" | 30 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 31 #include "content/browser/renderer_host/render_widget_host_impl.h" | 31 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 32 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 32 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 33 #include "content/browser/ssl/ssl_host_state.h" | 33 #include "content/browser/ssl/ssl_host_state.h" |
| 34 #include "content/browser/web_contents/web_contents_view_android.h" | 34 #include "content/browser/web_contents/web_contents_view_android.h" |
| 35 #include "content/common/input_messages.h" | 35 #include "content/common/input_messages.h" |
| 36 #include "content/common/view_messages.h" | 36 #include "content/common/view_messages.h" |
| 37 #include "content/public/browser/browser_accessibility_state.h" | 37 #include "content/public/browser/browser_accessibility_state.h" |
| 38 #include "content/public/browser/browser_context.h" | 38 #include "content/public/browser/browser_context.h" |
| 39 #include "content/public/browser/favicon_status.h" | 39 #include "content/public/browser/favicon_status.h" |
| 40 #include "content/public/browser/notification_details.h" | |
| 41 #include "content/public/browser/notification_service.h" | |
| 42 #include "content/public/browser/notification_source.h" | |
| 43 #include "content/public/browser/notification_types.h" | |
| 44 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/common/content_client.h" | 41 #include "content/public/common/content_client.h" |
| 46 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 47 #include "content/public/common/menu_item.h" | 43 #include "content/public/common/menu_item.h" |
| 48 #include "content/public/common/page_transition_types.h" | 44 #include "content/public/common/page_transition_types.h" |
| 49 #include "jni/ContentViewCore_jni.h" | 45 #include "jni/ContentViewCore_jni.h" |
| 50 #include "third_party/WebKit/public/web/WebBindings.h" | 46 #include "third_party/WebKit/public/web/WebBindings.h" |
| 51 #include "third_party/WebKit/public/web/WebInputEvent.h" | 47 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 52 #include "ui/base/android/view_android.h" | 48 #include "ui/base/android/view_android.h" |
| 53 #include "ui/base/android/window_android.h" | 49 #include "ui/base/android/window_android.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 } | 190 } |
| 195 | 191 |
| 196 ContentViewCoreImpl::~ContentViewCoreImpl() { | 192 ContentViewCoreImpl::~ContentViewCoreImpl() { |
| 197 JNIEnv* env = base::android::AttachCurrentThread(); | 193 JNIEnv* env = base::android::AttachCurrentThread(); |
| 198 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 194 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 199 java_ref_.reset(); | 195 java_ref_.reset(); |
| 200 if (!j_obj.is_null()) { | 196 if (!j_obj.is_null()) { |
| 201 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 197 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| 202 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 198 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
| 203 } | 199 } |
| 204 // Make sure nobody calls back into this object while we are tearing things | |
| 205 // down. | |
| 206 notification_registrar_.RemoveAll(); | |
| 207 } | 200 } |
| 208 | 201 |
| 209 void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, | 202 void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, |
| 210 jobject obj) { | 203 jobject obj) { |
| 211 DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); | 204 DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); |
| 212 java_ref_.reset(); | 205 java_ref_.reset(); |
| 213 } | 206 } |
| 214 | 207 |
| 215 void ContentViewCoreImpl::InitWebContents() { | 208 void ContentViewCoreImpl::InitWebContents() { |
| 216 DCHECK(web_contents_); | 209 DCHECK(web_contents_); |
| 217 notification_registrar_.Add( | |
| 218 this, NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
| 219 Source<WebContents>(web_contents_)); | |
| 220 notification_registrar_.Add( | |
| 221 this, NOTIFICATION_RENDERER_PROCESS_CREATED, | |
| 222 content::NotificationService::AllBrowserContextsAndSources()); | |
| 223 notification_registrar_.Add( | |
| 224 this, NOTIFICATION_WEB_CONTENTS_CONNECTED, | |
| 225 Source<WebContents>(web_contents_)); | |
| 226 | |
| 227 static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> | 210 static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> |
| 228 SetContentViewCore(this); | 211 SetContentViewCore(this); |
| 229 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); | 212 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); |
| 230 web_contents_->SetUserData(kContentViewUserDataKey, | 213 web_contents_->SetUserData(kContentViewUserDataKey, |
| 231 new ContentViewUserData(this)); | 214 new ContentViewUserData(this)); |
| 232 } | 215 } |
| 233 | 216 |
| 234 void ContentViewCoreImpl::Observe(int type, | |
| 235 const NotificationSource& source, | |
| 236 const NotificationDetails& details) { | |
| 237 switch (type) { | |
| 238 case NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { | |
| 239 std::pair<RenderViewHost*, RenderViewHost*>* switched_details = | |
| 240 Details<std::pair<RenderViewHost*, RenderViewHost*> >(details).ptr(); | |
| 241 int old_pid = 0; | |
| 242 if (switched_details->first) { | |
| 243 old_pid = GetRenderProcessIdFromRenderViewHost( | |
| 244 switched_details->first); | |
| 245 } | |
| 246 int new_pid = GetRenderProcessIdFromRenderViewHost( | |
| 247 web_contents_->GetRenderViewHost()); | |
| 248 if (new_pid != old_pid) { | |
| 249 // Notify the Java side of the change of the current renderer process. | |
| 250 JNIEnv* env = AttachCurrentThread(); | |
| 251 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 252 if (!obj.is_null()) { | |
| 253 Java_ContentViewCore_onRenderProcessSwap( | |
| 254 env, obj.obj(), old_pid, new_pid); | |
| 255 } | |
| 256 } | |
| 257 SetFocusInternal(HasFocus()); | |
| 258 break; | |
| 259 } | |
| 260 case NOTIFICATION_RENDERER_PROCESS_CREATED: { | |
| 261 // Notify the Java side of the current renderer process. | |
| 262 RenderProcessHost* source_process_host = | |
| 263 Source<RenderProcessHost>(source).ptr(); | |
| 264 RenderProcessHost* current_process_host = | |
| 265 web_contents_->GetRenderViewHost()->GetProcess(); | |
| 266 | |
| 267 if (source_process_host == current_process_host) { | |
| 268 int pid = GetRenderProcessIdFromRenderViewHost( | |
| 269 web_contents_->GetRenderViewHost()); | |
| 270 JNIEnv* env = AttachCurrentThread(); | |
| 271 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 272 if (!obj.is_null()) { | |
| 273 Java_ContentViewCore_onRenderProcessSwap(env, obj.obj(), 0, pid); | |
| 274 } | |
| 275 } | |
| 276 break; | |
| 277 } | |
| 278 case NOTIFICATION_WEB_CONTENTS_CONNECTED: { | |
| 279 JNIEnv* env = AttachCurrentThread(); | |
| 280 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 281 if (!obj.is_null()) { | |
| 282 Java_ContentViewCore_onWebContentsConnected(env, obj.obj()); | |
| 283 } | |
| 284 break; | |
| 285 } | |
| 286 } | |
| 287 } | |
| 288 | |
| 289 void ContentViewCoreImpl::RenderViewReady() { | 217 void ContentViewCoreImpl::RenderViewReady() { |
|
Avi (use Gerrit)
2013/11/21 21:28:26
== NOTIFICATION_WEB_CONTENTS_CONNECTED
| |
| 290 if (device_orientation_ != 0) | 218 if (device_orientation_ != 0) |
| 291 SendOrientationChangeEventInternal(); | 219 SendOrientationChangeEventInternal(); |
| 220 | |
| 221 // The render process is ready (it may not have been ready at the time that | |
| 222 // RenderViewHostChanged was received), so inform the Java side. | |
| 223 int pid = GetRenderProcessIdFromRenderViewHost( | |
| 224 web_contents_->GetRenderViewHost()); | |
| 225 JNIEnv* env = AttachCurrentThread(); | |
| 226 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 227 if (!obj.is_null()) { | |
| 228 Java_ContentViewCore_onRenderProcessSwap(env, obj.obj(), 0, pid); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 void ContentViewCoreImpl::RenderViewHostChanged(RenderViewHost* old_host, | |
| 233 RenderViewHost* new_host) { | |
|
Avi (use Gerrit)
2013/11/21 21:28:26
== NOTIFICATION_RENDER_VIEW_HOST_CHANGED
| |
| 234 int old_pid = 0; | |
| 235 if (old_host) | |
| 236 old_pid = GetRenderProcessIdFromRenderViewHost(old_host); | |
| 237 int new_pid = GetRenderProcessIdFromRenderViewHost(new_host); | |
| 238 | |
| 239 if (new_pid != old_pid) { | |
| 240 // Notify the Java side of the change of the current renderer process. | |
| 241 JNIEnv* env = AttachCurrentThread(); | |
| 242 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 243 if (!obj.is_null()) { | |
| 244 Java_ContentViewCore_onRenderProcessSwap( | |
| 245 env, obj.obj(), old_pid, new_pid); | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 SetFocusInternal(HasFocus()); | |
| 292 } | 250 } |
| 293 | 251 |
| 294 RenderWidgetHostViewAndroid* | 252 RenderWidgetHostViewAndroid* |
| 295 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 253 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
| 296 RenderWidgetHostView* rwhv = NULL; | 254 RenderWidgetHostView* rwhv = NULL; |
| 297 if (web_contents_) { | 255 if (web_contents_) { |
| 298 rwhv = web_contents_->GetRenderWidgetHostView(); | 256 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 299 if (web_contents_->ShowingInterstitialPage()) { | 257 if (web_contents_->ShowingInterstitialPage()) { |
| 300 rwhv = static_cast<InterstitialPageImpl*>( | 258 rwhv = static_cast<InterstitialPageImpl*>( |
| 301 web_contents_->GetInterstitialPage())-> | 259 web_contents_->GetInterstitialPage())-> |
| (...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1636 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1594 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1637 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1595 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1638 return reinterpret_cast<intptr_t>(view); | 1596 return reinterpret_cast<intptr_t>(view); |
| 1639 } | 1597 } |
| 1640 | 1598 |
| 1641 bool RegisterContentViewCore(JNIEnv* env) { | 1599 bool RegisterContentViewCore(JNIEnv* env) { |
| 1642 return RegisterNativesImpl(env); | 1600 return RegisterNativesImpl(env); |
| 1643 } | 1601 } |
| 1644 | 1602 |
| 1645 } // namespace content | 1603 } // namespace content |
| OLD | NEW |