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 25 matching lines...) Expand all Loading... | |
| 36 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 36 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" | 37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" |
| 38 #include "content/browser/ssl/ssl_host_state.h" | 38 #include "content/browser/ssl/ssl_host_state.h" |
| 39 #include "content/browser/web_contents/web_contents_view_android.h" | 39 #include "content/browser/web_contents/web_contents_view_android.h" |
| 40 #include "content/common/input/web_input_event_traits.h" | 40 #include "content/common/input/web_input_event_traits.h" |
| 41 #include "content/common/input_messages.h" | 41 #include "content/common/input_messages.h" |
| 42 #include "content/common/view_messages.h" | 42 #include "content/common/view_messages.h" |
| 43 #include "content/public/browser/browser_accessibility_state.h" | 43 #include "content/public/browser/browser_accessibility_state.h" |
| 44 #include "content/public/browser/browser_context.h" | 44 #include "content/public/browser/browser_context.h" |
| 45 #include "content/public/browser/favicon_status.h" | 45 #include "content/public/browser/favicon_status.h" |
| 46 #include "content/public/browser/notification_details.h" | |
| 47 #include "content/public/browser/notification_service.h" | |
| 48 #include "content/public/browser/notification_source.h" | |
| 49 #include "content/public/browser/notification_types.h" | |
| 50 #include "content/public/browser/render_frame_host.h" | 46 #include "content/public/browser/render_frame_host.h" |
| 51 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/common/content_client.h" | 48 #include "content/public/common/content_client.h" |
| 53 #include "content/public/common/content_switches.h" | 49 #include "content/public/common/content_switches.h" |
| 54 #include "content/public/common/menu_item.h" | 50 #include "content/public/common/menu_item.h" |
| 55 #include "content/public/common/page_transition_types.h" | 51 #include "content/public/common/page_transition_types.h" |
| 56 #include "content/public/common/user_agent.h" | 52 #include "content/public/common/user_agent.h" |
| 57 #include "jni/ContentViewCore_jni.h" | 53 #include "jni/ContentViewCore_jni.h" |
| 58 #include "third_party/WebKit/public/web/WebBindings.h" | 54 #include "third_party/WebKit/public/web/WebBindings.h" |
| 59 #include "third_party/WebKit/public/web/WebInputEvent.h" | 55 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 } | 251 } |
| 256 | 252 |
| 257 ContentViewCoreImpl::~ContentViewCoreImpl() { | 253 ContentViewCoreImpl::~ContentViewCoreImpl() { |
| 258 JNIEnv* env = base::android::AttachCurrentThread(); | 254 JNIEnv* env = base::android::AttachCurrentThread(); |
| 259 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 255 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 260 java_ref_.reset(); | 256 java_ref_.reset(); |
| 261 if (!j_obj.is_null()) { | 257 if (!j_obj.is_null()) { |
| 262 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 258 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| 263 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 259 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
| 264 } | 260 } |
| 265 // Make sure nobody calls back into this object while we are tearing things | |
| 266 // down. | |
| 267 notification_registrar_.RemoveAll(); | |
| 268 } | 261 } |
| 269 | 262 |
| 270 base::android::ScopedJavaLocalRef<jobject> | 263 base::android::ScopedJavaLocalRef<jobject> |
| 271 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, jobject obj) { | 264 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, jobject obj) { |
| 272 return web_contents_->GetJavaWebContents(); | 265 return web_contents_->GetJavaWebContents(); |
| 273 } | 266 } |
| 274 | 267 |
| 275 void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, | 268 void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, |
| 276 jobject obj) { | 269 jobject obj) { |
| 277 DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); | 270 DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); |
| 278 java_ref_.reset(); | 271 java_ref_.reset(); |
| 279 } | 272 } |
| 280 | 273 |
| 281 void ContentViewCoreImpl::InitWebContents() { | 274 void ContentViewCoreImpl::InitWebContents() { |
| 282 DCHECK(web_contents_); | 275 DCHECK(web_contents_); |
| 283 notification_registrar_.Add( | |
| 284 this, NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
| 285 Source<WebContents>(web_contents_)); | |
| 286 notification_registrar_.Add( | |
| 287 this, NOTIFICATION_RENDERER_PROCESS_CREATED, | |
| 288 content::NotificationService::AllBrowserContextsAndSources()); | |
| 289 notification_registrar_.Add( | |
| 290 this, NOTIFICATION_WEB_CONTENTS_CONNECTED, | |
| 291 Source<WebContents>(web_contents_)); | |
| 292 | |
| 293 static_cast<WebContentsViewAndroid*>( | 276 static_cast<WebContentsViewAndroid*>( |
| 294 static_cast<WebContentsImpl*>(web_contents_)->GetView())-> | 277 static_cast<WebContentsImpl*>(web_contents_)->GetView())-> |
| 295 SetContentViewCore(this); | 278 SetContentViewCore(this); |
| 296 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); | 279 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); |
| 297 web_contents_->SetUserData(kContentViewUserDataKey, | 280 web_contents_->SetUserData(kContentViewUserDataKey, |
| 298 new ContentViewUserData(this)); | 281 new ContentViewUserData(this)); |
| 299 } | 282 } |
| 300 | 283 |
| 301 void ContentViewCoreImpl::Observe(int type, | 284 void ContentViewCoreImpl::RenderViewReady() { |
| 302 const NotificationSource& source, | 285 JNIEnv* env = AttachCurrentThread(); |
| 303 const NotificationDetails& details) { | 286 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 304 switch (type) { | 287 if (!obj.is_null()) |
| 305 case NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { | 288 Java_ContentViewCore_onRenderProcessChange(env, obj.obj()); |
| 306 std::pair<RenderViewHost*, RenderViewHost*>* switched_details = | |
| 307 Details<std::pair<RenderViewHost*, RenderViewHost*> >(details).ptr(); | |
| 308 int old_pid = 0; | |
| 309 if (switched_details->first) { | |
| 310 old_pid = GetRenderProcessIdFromRenderViewHost( | |
| 311 switched_details->first); | |
| 312 | 289 |
| 313 RenderWidgetHostViewAndroid* view = | |
| 314 static_cast<RenderWidgetHostViewAndroid*>( | |
| 315 switched_details->first->GetView()); | |
| 316 if (view) | |
| 317 view->SetContentViewCore(NULL); | |
| 318 | |
| 319 view = static_cast<RenderWidgetHostViewAndroid*>( | |
| 320 switched_details->second->GetView()); | |
| 321 | |
| 322 if (view) | |
| 323 view->SetContentViewCore(this); | |
| 324 } | |
| 325 int new_pid = GetRenderProcessIdFromRenderViewHost( | |
| 326 web_contents_->GetRenderViewHost()); | |
| 327 if (new_pid != old_pid) { | |
| 328 // Notify the Java side of the change of the current renderer process. | |
| 329 JNIEnv* env = AttachCurrentThread(); | |
| 330 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 331 if (!obj.is_null()) { | |
| 332 Java_ContentViewCore_onRenderProcessSwap(env, obj.obj()); | |
| 333 } | |
| 334 } | |
| 335 SetFocusInternal(HasFocus()); | |
| 336 | |
| 337 SetAccessibilityEnabledInternal(accessibility_enabled_); | |
| 338 break; | |
| 339 } | |
| 340 case NOTIFICATION_RENDERER_PROCESS_CREATED: { | |
| 341 // Notify the Java side of the current renderer process. | |
| 342 RenderProcessHost* source_process_host = | |
| 343 Source<RenderProcessHost>(source).ptr(); | |
| 344 RenderProcessHost* current_process_host = | |
| 345 web_contents_->GetRenderViewHost()->GetProcess(); | |
| 346 | |
| 347 if (source_process_host == current_process_host) { | |
| 348 JNIEnv* env = AttachCurrentThread(); | |
| 349 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 350 if (!obj.is_null()) { | |
| 351 Java_ContentViewCore_onRenderProcessSwap(env, obj.obj()); | |
| 352 } | |
| 353 } | |
| 354 break; | |
| 355 } | |
| 356 case NOTIFICATION_WEB_CONTENTS_CONNECTED: { | |
| 357 JNIEnv* env = AttachCurrentThread(); | |
| 358 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 359 if (!obj.is_null()) { | |
| 360 Java_ContentViewCore_onWebContentsConnected(env, obj.obj()); | |
| 361 } | |
| 362 break; | |
| 363 } | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 void ContentViewCoreImpl::RenderViewReady() { | |
| 368 if (device_orientation_ != 0) | 290 if (device_orientation_ != 0) |
| 369 SendOrientationChangeEventInternal(); | 291 SendOrientationChangeEventInternal(); |
| 370 } | 292 } |
| 371 | 293 |
| 294 void ContentViewCoreImpl::RenderViewHostChanged(RenderViewHost* old_host, | |
| 295 RenderViewHost* new_host) { | |
| 296 int old_pid = 0; | |
| 297 if (old_host) { | |
| 298 old_pid = GetRenderProcessIdFromRenderViewHost(old_host); | |
| 299 | |
| 300 RenderWidgetHostViewAndroid* view = | |
| 301 static_cast<RenderWidgetHostViewAndroid*>(old_host->GetView()); | |
| 302 if (view) | |
| 303 view->SetContentViewCore(NULL); | |
| 304 | |
| 305 view = static_cast<RenderWidgetHostViewAndroid*>(new_host->GetView()); | |
| 306 if (view) | |
| 307 view->SetContentViewCore(this); | |
|
ppi
2014/05/22 15:58:44
Looking at what attachImeAdapter() cares about (at
no sievers
2014/05/22 20:44:57
I don't think the patch is changing the behavior i
Avi (use Gerrit)
2014/05/22 21:14:27
This is exactly the analog to NOTIFICATION_RENDER_
| |
| 308 } | |
| 309 int new_pid = GetRenderProcessIdFromRenderViewHost( | |
| 310 web_contents_->GetRenderViewHost()); | |
| 311 if (new_pid != old_pid) { | |
| 312 // Notify the Java side that the renderer process changed. | |
| 313 JNIEnv* env = AttachCurrentThread(); | |
| 314 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 315 if (!obj.is_null()) { | |
| 316 Java_ContentViewCore_onRenderProcessChange(env, obj.obj()); | |
| 317 } | |
| 318 } | |
| 319 | |
| 320 SetFocusInternal(HasFocus()); | |
| 321 SetAccessibilityEnabledInternal(accessibility_enabled_); | |
| 322 } | |
| 323 | |
| 372 RenderWidgetHostViewAndroid* | 324 RenderWidgetHostViewAndroid* |
| 373 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 325 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
| 374 RenderWidgetHostView* rwhv = NULL; | 326 RenderWidgetHostView* rwhv = NULL; |
| 375 if (web_contents_) { | 327 if (web_contents_) { |
| 376 rwhv = web_contents_->GetRenderWidgetHostView(); | 328 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 377 if (web_contents_->ShowingInterstitialPage()) { | 329 if (web_contents_->ShowingInterstitialPage()) { |
| 378 rwhv = static_cast<InterstitialPageImpl*>( | 330 rwhv = static_cast<InterstitialPageImpl*>( |
| 379 web_contents_->GetInterstitialPage())-> | 331 web_contents_->GetInterstitialPage())-> |
| 380 GetRenderViewHost()->GetView(); | 332 GetRenderViewHost()->GetView(); |
| 381 } | 333 } |
| (...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1663 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1615 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1664 retained_objects_set); | 1616 retained_objects_set); |
| 1665 return reinterpret_cast<intptr_t>(view); | 1617 return reinterpret_cast<intptr_t>(view); |
| 1666 } | 1618 } |
| 1667 | 1619 |
| 1668 bool RegisterContentViewCore(JNIEnv* env) { | 1620 bool RegisterContentViewCore(JNIEnv* env) { |
| 1669 return RegisterNativesImpl(env); | 1621 return RegisterNativesImpl(env); |
| 1670 } | 1622 } |
| 1671 | 1623 |
| 1672 } // namespace content | 1624 } // namespace content |
| OLD | NEW |