| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return ContentViewCoreImpl::FromWebContents(web_contents); | 206 return ContentViewCoreImpl::FromWebContents(web_contents); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // static | 209 // static |
| 210 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 210 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
| 211 jobject obj) { | 211 jobject obj) { |
| 212 return reinterpret_cast<ContentViewCore*>( | 212 return reinterpret_cast<ContentViewCore*>( |
| 213 Java_ContentViewCore_getNativeContentViewCore(env, obj)); | 213 Java_ContentViewCore_getNativeContentViewCore(env, obj)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, | 216 ContentViewCoreImpl::ContentViewCoreImpl( |
| 217 jobject obj, | 217 JNIEnv* env, |
| 218 WebContents* web_contents, | 218 jobject obj, |
| 219 ui::ViewAndroid* view_android, | 219 WebContents* web_contents, |
| 220 ui::WindowAndroid* window_android) | 220 ui::ViewAndroid* view_android, |
| 221 ui::WindowAndroid* window_android, |
| 222 jobject java_bridge_retained_object_set) |
| 221 : WebContentsObserver(web_contents), | 223 : WebContentsObserver(web_contents), |
| 222 java_ref_(env, obj), | 224 java_ref_(env, obj), |
| 223 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 225 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 224 root_layer_(cc::Layer::Create()), | 226 root_layer_(cc::Layer::Create()), |
| 225 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 227 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
| 226 vsync_interval_(base::TimeDelta::FromMicroseconds( | 228 vsync_interval_(base::TimeDelta::FromMicroseconds( |
| 227 kDefaultVSyncIntervalMicros)), | 229 kDefaultVSyncIntervalMicros)), |
| 228 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 230 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
| 229 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 231 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
| 230 view_android_(view_android), | 232 view_android_(view_android), |
| 231 window_android_(window_android), | 233 window_android_(window_android), |
| 232 device_orientation_(0), | 234 device_orientation_(0), |
| 233 geolocation_needs_pause_(false) { | 235 geolocation_needs_pause_(false) { |
| 234 CHECK(web_contents) << | 236 CHECK(web_contents) << |
| 235 "A ContentViewCoreImpl should be created with a valid WebContents."; | 237 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 236 | 238 |
| 237 // Currently, the only use case we have for overriding a user agent involves | 239 // Currently, the only use case we have for overriding a user agent involves |
| 238 // spoofing a desktop Linux user agent for "Request desktop site". | 240 // spoofing a desktop Linux user agent for "Request desktop site". |
| 239 // Automatically set it for all WebContents so that it is available when a | 241 // Automatically set it for all WebContents so that it is available when a |
| 240 // NavigationEntry requires the user agent to be overridden. | 242 // NavigationEntry requires the user agent to be overridden. |
| 241 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 243 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 242 std::string product = content::GetContentClient()->GetProduct(); | 244 std::string product = content::GetContentClient()->GetProduct(); |
| 243 std::string spoofed_ua = | 245 std::string spoofed_ua = |
| 244 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 246 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 245 web_contents->SetUserAgentOverride(spoofed_ua); | 247 web_contents->SetUserAgentOverride(spoofed_ua); |
| 246 | 248 |
| 249 java_bridge_dispatcher_host_manager_.reset( |
| 250 new JavaBridgeDispatcherHostManager(web_contents, |
| 251 java_bridge_retained_object_set)); |
| 252 |
| 247 InitWebContents(); | 253 InitWebContents(); |
| 248 } | 254 } |
| 249 | 255 |
| 250 ContentViewCoreImpl::~ContentViewCoreImpl() { | 256 ContentViewCoreImpl::~ContentViewCoreImpl() { |
| 251 JNIEnv* env = base::android::AttachCurrentThread(); | 257 JNIEnv* env = base::android::AttachCurrentThread(); |
| 252 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 258 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 253 java_ref_.reset(); | 259 java_ref_.reset(); |
| 254 if (!j_obj.is_null()) { | 260 if (!j_obj.is_null()) { |
| 255 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 261 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| 256 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 262 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { | 1288 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { |
| 1283 // TODO(creis): Do callers of this need to know if it fails? | 1289 // TODO(creis): Do callers of this need to know if it fails? |
| 1284 if (web_contents_->GetController().CanPruneAllButLastCommitted()) | 1290 if (web_contents_->GetController().CanPruneAllButLastCommitted()) |
| 1285 web_contents_->GetController().PruneAllButLastCommitted(); | 1291 web_contents_->GetController().PruneAllButLastCommitted(); |
| 1286 } | 1292 } |
| 1287 | 1293 |
| 1288 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1294 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
| 1289 JNIEnv* env, | 1295 JNIEnv* env, |
| 1290 jobject obj, | 1296 jobject obj, |
| 1291 jboolean allow) { | 1297 jboolean allow) { |
| 1292 web_contents_->java_bridge_dispatcher_host_manager() | 1298 java_bridge_dispatcher_host_manager_->SetAllowObjectContentsInspection(allow); |
| 1293 ->SetAllowObjectContentsInspection(allow); | |
| 1294 } | 1299 } |
| 1295 | 1300 |
| 1296 void ContentViewCoreImpl::AddJavascriptInterface( | 1301 void ContentViewCoreImpl::AddJavascriptInterface( |
| 1297 JNIEnv* env, | 1302 JNIEnv* env, |
| 1298 jobject /* obj */, | 1303 jobject /* obj */, |
| 1299 jobject object, | 1304 jobject object, |
| 1300 jstring name, | 1305 jstring name, |
| 1301 jclass safe_annotation_clazz, | 1306 jclass safe_annotation_clazz) { |
| 1302 jobject retained_object_set) { | |
| 1303 ScopedJavaLocalRef<jobject> scoped_object(env, object); | 1307 ScopedJavaLocalRef<jobject> scoped_object(env, object); |
| 1304 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); | 1308 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); |
| 1305 JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set); | |
| 1306 | 1309 |
| 1307 // JavaBoundObject creates the NPObject with a ref count of 1, and | 1310 // JavaBoundObject creates the NPObject with a ref count of 1, and |
| 1308 // JavaBridgeDispatcherHostManager takes its own ref. | 1311 // JavaBridgeDispatcherHostManager takes its own ref. |
| 1309 JavaBridgeDispatcherHostManager* java_bridge = | 1312 NPObject* bound_object = JavaBoundObject::Create( |
| 1310 web_contents_->java_bridge_dispatcher_host_manager(); | 1313 scoped_object, |
| 1311 java_bridge->SetRetainedObjectSet(weak_retained_object_set); | 1314 scoped_clazz, |
| 1312 NPObject* bound_object = | 1315 java_bridge_dispatcher_host_manager_->AsWeakPtr(), |
| 1313 JavaBoundObject::Create(scoped_object, | 1316 java_bridge_dispatcher_host_manager_->GetAllowObjectContentsInspection()); |
| 1314 scoped_clazz, | 1317 java_bridge_dispatcher_host_manager_->AddNamedObject( |
| 1315 java_bridge->AsWeakPtr(), | 1318 ConvertJavaStringToUTF16(env, name), bound_object); |
| 1316 java_bridge->GetAllowObjectContentsInspection()); | |
| 1317 java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name), | |
| 1318 bound_object); | |
| 1319 blink::WebBindings::releaseObject(bound_object); | 1319 blink::WebBindings::releaseObject(bound_object); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1322 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
| 1323 jobject /* obj */, | 1323 jobject /* obj */, |
| 1324 jstring name) { | 1324 jstring name) { |
| 1325 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | 1325 java_bridge_dispatcher_host_manager_->RemoveNamedObject( |
| 1326 ConvertJavaStringToUTF16(env, name)); | 1326 ConvertJavaStringToUTF16(env, name)); |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */, | 1329 void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */, |
| 1330 jlong timebase_micros, | 1330 jlong timebase_micros, |
| 1331 jlong interval_micros) { | 1331 jlong interval_micros) { |
| 1332 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1332 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 1333 if (!view) | 1333 if (!view) |
| 1334 return; | 1334 return; |
| 1335 | 1335 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 static_cast<WebContentsViewAndroid*>(web_contents->GetView()); | 1726 static_cast<WebContentsViewAndroid*>(web_contents->GetView()); |
| 1727 DCHECK(wcva); | 1727 DCHECK(wcva); |
| 1728 wcva->SetContentViewCore(NULL); | 1728 wcva->SetContentViewCore(NULL); |
| 1729 } | 1729 } |
| 1730 | 1730 |
| 1731 // This is called for each ContentView. | 1731 // This is called for each ContentView. |
| 1732 jlong Init(JNIEnv* env, | 1732 jlong Init(JNIEnv* env, |
| 1733 jobject obj, | 1733 jobject obj, |
| 1734 jlong native_web_contents, | 1734 jlong native_web_contents, |
| 1735 jlong view_android, | 1735 jlong view_android, |
| 1736 jlong window_android) { | 1736 jlong window_android, |
| 1737 jobject retained_objects_set) { |
| 1737 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1738 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1738 env, obj, | 1739 env, obj, |
| 1739 reinterpret_cast<WebContents*>(native_web_contents), | 1740 reinterpret_cast<WebContents*>(native_web_contents), |
| 1740 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1741 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1741 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1742 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1743 retained_objects_set); |
| 1742 return reinterpret_cast<intptr_t>(view); | 1744 return reinterpret_cast<intptr_t>(view); |
| 1743 } | 1745 } |
| 1744 | 1746 |
| 1745 bool RegisterContentViewCore(JNIEnv* env) { | 1747 bool RegisterContentViewCore(JNIEnv* env) { |
| 1746 return RegisterNativesImpl(env); | 1748 return RegisterNativesImpl(env); |
| 1747 } | 1749 } |
| 1748 | 1750 |
| 1749 } // namespace content | 1751 } // namespace content |
| OLD | NEW |