| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 207 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
| 208 jobject obj) { | 208 jobject obj) { |
| 209 return reinterpret_cast<ContentViewCore*>( | 209 return reinterpret_cast<ContentViewCore*>( |
| 210 Java_ContentViewCore_getNativeContentViewCore(env, obj)); | 210 Java_ContentViewCore_getNativeContentViewCore(env, obj)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 ContentViewCoreImpl::ContentViewCoreImpl( | 213 ContentViewCoreImpl::ContentViewCoreImpl( |
| 214 JNIEnv* env, | 214 JNIEnv* env, |
| 215 jobject obj, | 215 jobject obj, |
| 216 WebContents* web_contents, | 216 WebContents* web_contents, |
| 217 jobject view_android, | 217 jobject view_android_delegate, |
| 218 ui::WindowAndroid* window_android, | 218 ui::WindowAndroid* window_android, |
| 219 jobject java_bridge_retained_object_set) | 219 jobject java_bridge_retained_object_set) |
| 220 : WebContentsObserver(web_contents), | 220 : WebContentsObserver(web_contents), |
| 221 java_ref_(env, obj), | 221 java_ref_(env, obj), |
| 222 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 222 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 223 root_layer_(cc::SolidColorLayer::Create()), | 223 root_layer_(cc::SolidColorLayer::Create()), |
| 224 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 224 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
| 225 view_android_(new ui::ViewAndroid(view_android, window_android)), | 225 view_android_(new ui::ViewAndroid(view_android_delegate, window_android)), |
| 226 window_android_(window_android), | 226 window_android_(window_android), |
| 227 device_orientation_(0), | 227 device_orientation_(0), |
| 228 accessibility_enabled_(false) { | 228 accessibility_enabled_(false) { |
| 229 CHECK(web_contents) << | 229 CHECK(web_contents) << |
| 230 "A ContentViewCoreImpl should be created with a valid WebContents."; | 230 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 231 DCHECK(window_android_); | 231 DCHECK(window_android_); |
| 232 | 232 |
| 233 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); | 233 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); |
| 234 gfx::Size physical_size( | 234 gfx::Size physical_size( |
| 235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 | 1238 |
| 1239 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { | 1239 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { |
| 1240 JNIEnv* env = AttachCurrentThread(); | 1240 JNIEnv* env = AttachCurrentThread(); |
| 1241 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1241 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1242 if (obj.is_null()) | 1242 if (obj.is_null()) |
| 1243 return true; | 1243 return true; |
| 1244 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, | 1244 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, |
| 1245 obj.obj()); | 1245 obj.obj()); |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 void ContentViewCoreImpl::IncrementKeepScreenOnCount() { |
| 1249 JNIEnv* env = AttachCurrentThread(); |
| 1250 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1251 if (obj.is_null()) |
| 1252 return; |
| 1253 Java_ContentViewCore_incrementKeepScreenOnCount(env, obj.obj()); |
| 1254 } |
| 1255 |
| 1256 void ContentViewCoreImpl::DecrementKeepScreenOnCount() { |
| 1257 JNIEnv* env = AttachCurrentThread(); |
| 1258 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1259 if (obj.is_null()) |
| 1260 return; |
| 1261 Java_ContentViewCore_decrementKeepScreenOnCount(env, obj.obj()); |
| 1262 } |
| 1263 |
| 1248 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { | 1264 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { |
| 1249 accessibility_enabled_ = enabled; | 1265 accessibility_enabled_ = enabled; |
| 1250 BrowserAccessibilityStateImpl* accessibility_state = | 1266 BrowserAccessibilityStateImpl* accessibility_state = |
| 1251 BrowserAccessibilityStateImpl::GetInstance(); | 1267 BrowserAccessibilityStateImpl::GetInstance(); |
| 1252 if (enabled) { | 1268 if (enabled) { |
| 1253 // This enables accessibility globally unless it was explicitly disallowed | 1269 // This enables accessibility globally unless it was explicitly disallowed |
| 1254 // by a command-line flag. | 1270 // by a command-line flag. |
| 1255 accessibility_state->OnScreenReaderDetected(); | 1271 accessibility_state->OnScreenReaderDetected(); |
| 1256 // If it was actually enabled globally, enable it for this RenderWidget now. | 1272 // If it was actually enabled globally, enable it for this RenderWidget now. |
| 1257 if (accessibility_state->IsAccessibleBrowser() && web_contents_) | 1273 if (accessibility_state->IsAccessibleBrowser() && web_contents_) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( | 1374 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( |
| 1359 static_cast<WebContentsImpl*>(web_contents())->GetView()); | 1375 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
| 1360 DCHECK(wcva); | 1376 DCHECK(wcva); |
| 1361 wcva->SetContentViewCore(NULL); | 1377 wcva->SetContentViewCore(NULL); |
| 1362 } | 1378 } |
| 1363 | 1379 |
| 1364 // This is called for each ContentView. | 1380 // This is called for each ContentView. |
| 1365 jlong Init(JNIEnv* env, | 1381 jlong Init(JNIEnv* env, |
| 1366 jobject obj, | 1382 jobject obj, |
| 1367 jobject web_contents, | 1383 jobject web_contents, |
| 1368 jobject view_android, | 1384 jobject view_android_delegate, |
| 1369 jlong window_android, | 1385 jlong window_android, |
| 1370 jobject retained_objects_set) { | 1386 jobject retained_objects_set) { |
| 1371 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1387 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1372 env, obj, WebContents::FromJavaWebContents(web_contents), view_android, | 1388 env, obj, WebContents::FromJavaWebContents(web_contents), |
| 1389 view_android_delegate, |
| 1373 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1390 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1374 retained_objects_set); | 1391 retained_objects_set); |
| 1375 return reinterpret_cast<intptr_t>(view); | 1392 return reinterpret_cast<intptr_t>(view); |
| 1376 } | 1393 } |
| 1377 | 1394 |
| 1378 static jobject FromWebContentsAndroid( | 1395 static jobject FromWebContentsAndroid( |
| 1379 JNIEnv* env, | 1396 JNIEnv* env, |
| 1380 jclass clazz, | 1397 jclass clazz, |
| 1381 jobject jweb_contents) { | 1398 jobject jweb_contents) { |
| 1382 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1399 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1383 if (!web_contents) | 1400 if (!web_contents) |
| 1384 return NULL; | 1401 return NULL; |
| 1385 | 1402 |
| 1386 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1403 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1387 if (!view) | 1404 if (!view) |
| 1388 return NULL; | 1405 return NULL; |
| 1389 | 1406 |
| 1390 return view->GetJavaObject().Release(); | 1407 return view->GetJavaObject().Release(); |
| 1391 } | 1408 } |
| 1392 | 1409 |
| 1393 bool RegisterContentViewCore(JNIEnv* env) { | 1410 bool RegisterContentViewCore(JNIEnv* env) { |
| 1394 return RegisterNativesImpl(env); | 1411 return RegisterNativesImpl(env); |
| 1395 } | 1412 } |
| 1396 | 1413 |
| 1397 } // namespace content | 1414 } // namespace content |
| OLD | NEW |