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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return ContentViewCoreImpl::FromWebContents(web_contents); | 203 return ContentViewCoreImpl::FromWebContents(web_contents); |
204 } | 204 } |
205 | 205 |
206 // static | 206 // static |
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(JNIEnv* env, | 213 ContentViewCoreImpl::ContentViewCoreImpl( |
214 jobject obj, | 214 JNIEnv* env, |
215 WebContents* web_contents, | 215 jobject obj, |
216 ui::ViewAndroid* view_android, | 216 WebContents* web_contents, |
217 ui::WindowAndroid* window_android) | 217 ui::ViewAndroid* view_android, |
| 218 ui::WindowAndroid* window_android, |
| 219 jobject java_bridge_retained_object_set) |
218 : WebContentsObserver(web_contents), | 220 : WebContentsObserver(web_contents), |
219 java_ref_(env, obj), | 221 java_ref_(env, obj), |
220 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 222 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
221 root_layer_(cc::SolidColorLayer::Create()), | 223 root_layer_(cc::SolidColorLayer::Create()), |
222 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 224 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
223 view_android_(view_android), | 225 view_android_(view_android), |
224 window_android_(window_android), | 226 window_android_(window_android), |
225 device_orientation_(0), | 227 device_orientation_(0), |
226 geolocation_needs_pause_(false), | 228 geolocation_needs_pause_(false), |
227 accessibility_enabled_(false) { | 229 accessibility_enabled_(false) { |
(...skipping 10 matching lines...) Expand all Loading... |
238 // Currently, the only use case we have for overriding a user agent involves | 240 // Currently, the only use case we have for overriding a user agent involves |
239 // spoofing a desktop Linux user agent for "Request desktop site". | 241 // spoofing a desktop Linux user agent for "Request desktop site". |
240 // Automatically set it for all WebContents so that it is available when a | 242 // Automatically set it for all WebContents so that it is available when a |
241 // NavigationEntry requires the user agent to be overridden. | 243 // NavigationEntry requires the user agent to be overridden. |
242 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 244 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
243 std::string product = content::GetContentClient()->GetProduct(); | 245 std::string product = content::GetContentClient()->GetProduct(); |
244 std::string spoofed_ua = | 246 std::string spoofed_ua = |
245 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 247 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
246 web_contents->SetUserAgentOverride(spoofed_ua); | 248 web_contents->SetUserAgentOverride(spoofed_ua); |
247 | 249 |
| 250 java_bridge_dispatcher_host_manager_.reset( |
| 251 new JavaBridgeDispatcherHostManager(web_contents, |
| 252 java_bridge_retained_object_set)); |
| 253 |
248 InitWebContents(); | 254 InitWebContents(); |
249 } | 255 } |
250 | 256 |
251 ContentViewCoreImpl::~ContentViewCoreImpl() { | 257 ContentViewCoreImpl::~ContentViewCoreImpl() { |
252 JNIEnv* env = base::android::AttachCurrentThread(); | 258 JNIEnv* env = base::android::AttachCurrentThread(); |
253 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 259 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
254 java_ref_.reset(); | 260 java_ref_.reset(); |
255 if (!j_obj.is_null()) { | 261 if (!j_obj.is_null()) { |
256 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 262 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
257 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 263 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { | 1277 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { |
1272 // TODO(creis): Do callers of this need to know if it fails? | 1278 // TODO(creis): Do callers of this need to know if it fails? |
1273 if (web_contents_->GetController().CanPruneAllButLastCommitted()) | 1279 if (web_contents_->GetController().CanPruneAllButLastCommitted()) |
1274 web_contents_->GetController().PruneAllButLastCommitted(); | 1280 web_contents_->GetController().PruneAllButLastCommitted(); |
1275 } | 1281 } |
1276 | 1282 |
1277 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1283 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
1278 JNIEnv* env, | 1284 JNIEnv* env, |
1279 jobject obj, | 1285 jobject obj, |
1280 jboolean allow) { | 1286 jboolean allow) { |
1281 web_contents_->java_bridge_dispatcher_host_manager() | 1287 java_bridge_dispatcher_host_manager_->SetAllowObjectContentsInspection(allow); |
1282 ->SetAllowObjectContentsInspection(allow); | |
1283 } | 1288 } |
1284 | 1289 |
1285 void ContentViewCoreImpl::AddJavascriptInterface( | 1290 void ContentViewCoreImpl::AddJavascriptInterface( |
1286 JNIEnv* env, | 1291 JNIEnv* env, |
1287 jobject /* obj */, | 1292 jobject /* obj */, |
1288 jobject object, | 1293 jobject object, |
1289 jstring name, | 1294 jstring name, |
1290 jclass safe_annotation_clazz, | 1295 jclass safe_annotation_clazz) { |
1291 jobject retained_object_set) { | |
1292 ScopedJavaLocalRef<jobject> scoped_object(env, object); | 1296 ScopedJavaLocalRef<jobject> scoped_object(env, object); |
1293 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); | 1297 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); |
1294 JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set); | |
1295 | 1298 |
1296 // JavaBoundObject creates the NPObject with a ref count of 1, and | 1299 // JavaBoundObject creates the NPObject with a ref count of 1, and |
1297 // JavaBridgeDispatcherHostManager takes its own ref. | 1300 // JavaBridgeDispatcherHostManager takes its own ref. |
1298 JavaBridgeDispatcherHostManager* java_bridge = | 1301 NPObject* bound_object = JavaBoundObject::Create( |
1299 web_contents_->java_bridge_dispatcher_host_manager(); | 1302 scoped_object, |
1300 java_bridge->SetRetainedObjectSet(weak_retained_object_set); | 1303 scoped_clazz, |
1301 NPObject* bound_object = | 1304 java_bridge_dispatcher_host_manager_->AsWeakPtr(), |
1302 JavaBoundObject::Create(scoped_object, | 1305 java_bridge_dispatcher_host_manager_->GetAllowObjectContentsInspection()); |
1303 scoped_clazz, | 1306 java_bridge_dispatcher_host_manager_->AddNamedObject( |
1304 java_bridge->AsWeakPtr(), | 1307 ConvertJavaStringToUTF16(env, name), bound_object); |
1305 java_bridge->GetAllowObjectContentsInspection()); | |
1306 java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name), | |
1307 bound_object); | |
1308 blink::WebBindings::releaseObject(bound_object); | 1308 blink::WebBindings::releaseObject(bound_object); |
1309 } | 1309 } |
1310 | 1310 |
1311 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1311 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
1312 jobject /* obj */, | 1312 jobject /* obj */, |
1313 jstring name) { | 1313 jstring name) { |
1314 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | 1314 java_bridge_dispatcher_host_manager_->RemoveNamedObject( |
1315 ConvertJavaStringToUTF16(env, name)); | 1315 ConvertJavaStringToUTF16(env, name)); |
1316 } | 1316 } |
1317 | 1317 |
1318 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1318 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
1319 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1319 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
1320 gfx::Size physical_size( | 1320 gfx::Size physical_size( |
1321 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1321 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
1322 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1322 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
1323 root_layer_->SetBounds(physical_size); | 1323 root_layer_->SetBounds(physical_size); |
1324 | 1324 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 static_cast<WebContentsImpl*>(web_contents)->GetView()); | 1681 static_cast<WebContentsImpl*>(web_contents)->GetView()); |
1682 DCHECK(wcva); | 1682 DCHECK(wcva); |
1683 wcva->SetContentViewCore(NULL); | 1683 wcva->SetContentViewCore(NULL); |
1684 } | 1684 } |
1685 | 1685 |
1686 // This is called for each ContentView. | 1686 // This is called for each ContentView. |
1687 jlong Init(JNIEnv* env, | 1687 jlong Init(JNIEnv* env, |
1688 jobject obj, | 1688 jobject obj, |
1689 jlong native_web_contents, | 1689 jlong native_web_contents, |
1690 jlong view_android, | 1690 jlong view_android, |
1691 jlong window_android) { | 1691 jlong window_android, |
| 1692 jobject retained_objects_set) { |
1692 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1693 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1693 env, obj, | 1694 env, obj, |
1694 reinterpret_cast<WebContents*>(native_web_contents), | 1695 reinterpret_cast<WebContents*>(native_web_contents), |
1695 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1696 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1696 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1697 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1698 retained_objects_set); |
1697 return reinterpret_cast<intptr_t>(view); | 1699 return reinterpret_cast<intptr_t>(view); |
1698 } | 1700 } |
1699 | 1701 |
1700 bool RegisterContentViewCore(JNIEnv* env) { | 1702 bool RegisterContentViewCore(JNIEnv* env) { |
1701 return RegisterNativesImpl(env); | 1703 return RegisterNativesImpl(env); |
1702 } | 1704 } |
1703 | 1705 |
1704 } // namespace content | 1706 } // namespace content |
OLD | NEW |