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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 return ContentViewCoreImpl::FromWebContents(web_contents); | 202 return ContentViewCoreImpl::FromWebContents(web_contents); |
203 } | 203 } |
204 | 204 |
205 // static | 205 // static |
206 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 206 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
207 jobject obj) { | 207 jobject obj) { |
208 return reinterpret_cast<ContentViewCore*>( | 208 return reinterpret_cast<ContentViewCore*>( |
209 Java_ContentViewCore_getNativeContentViewCore(env, obj)); | 209 Java_ContentViewCore_getNativeContentViewCore(env, obj)); |
210 } | 210 } |
211 | 211 |
212 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, | 212 ContentViewCoreImpl::ContentViewCoreImpl( |
213 jobject obj, | 213 JNIEnv* env, |
214 WebContents* web_contents, | 214 jobject obj, |
215 ui::ViewAndroid* view_android, | 215 WebContents* web_contents, |
216 ui::WindowAndroid* window_android) | 216 ui::ViewAndroid* view_android, |
| 217 ui::WindowAndroid* window_android, |
| 218 jobject java_bridge_retained_object_set) |
217 : WebContentsObserver(web_contents), | 219 : WebContentsObserver(web_contents), |
218 java_ref_(env, obj), | 220 java_ref_(env, obj), |
219 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 221 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
220 root_layer_(cc::Layer::Create()), | 222 root_layer_(cc::Layer::Create()), |
221 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 223 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
222 view_android_(view_android), | 224 view_android_(view_android), |
223 window_android_(window_android), | 225 window_android_(window_android), |
224 device_orientation_(0), | 226 device_orientation_(0), |
225 geolocation_needs_pause_(false) { | 227 geolocation_needs_pause_(false) { |
226 CHECK(web_contents) << | 228 CHECK(web_contents) << |
227 "A ContentViewCoreImpl should be created with a valid WebContents."; | 229 "A ContentViewCoreImpl should be created with a valid WebContents."; |
228 | 230 |
229 // Currently, the only use case we have for overriding a user agent involves | 231 // Currently, the only use case we have for overriding a user agent involves |
230 // spoofing a desktop Linux user agent for "Request desktop site". | 232 // spoofing a desktop Linux user agent for "Request desktop site". |
231 // Automatically set it for all WebContents so that it is available when a | 233 // Automatically set it for all WebContents so that it is available when a |
232 // NavigationEntry requires the user agent to be overridden. | 234 // NavigationEntry requires the user agent to be overridden. |
233 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 235 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
234 std::string product = content::GetContentClient()->GetProduct(); | 236 std::string product = content::GetContentClient()->GetProduct(); |
235 std::string spoofed_ua = | 237 std::string spoofed_ua = |
236 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 238 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
237 web_contents->SetUserAgentOverride(spoofed_ua); | 239 web_contents->SetUserAgentOverride(spoofed_ua); |
238 | 240 |
| 241 java_bridge_dispatcher_host_manager_.reset( |
| 242 new JavaBridgeDispatcherHostManager(web_contents, |
| 243 java_bridge_retained_object_set)); |
| 244 |
239 InitWebContents(); | 245 InitWebContents(); |
240 } | 246 } |
241 | 247 |
242 ContentViewCoreImpl::~ContentViewCoreImpl() { | 248 ContentViewCoreImpl::~ContentViewCoreImpl() { |
243 JNIEnv* env = base::android::AttachCurrentThread(); | 249 JNIEnv* env = base::android::AttachCurrentThread(); |
244 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 250 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
245 java_ref_.reset(); | 251 java_ref_.reset(); |
246 if (!j_obj.is_null()) { | 252 if (!j_obj.is_null()) { |
247 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 253 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
248 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 254 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { | 1261 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { |
1256 // TODO(creis): Do callers of this need to know if it fails? | 1262 // TODO(creis): Do callers of this need to know if it fails? |
1257 if (web_contents_->GetController().CanPruneAllButLastCommitted()) | 1263 if (web_contents_->GetController().CanPruneAllButLastCommitted()) |
1258 web_contents_->GetController().PruneAllButLastCommitted(); | 1264 web_contents_->GetController().PruneAllButLastCommitted(); |
1259 } | 1265 } |
1260 | 1266 |
1261 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1267 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
1262 JNIEnv* env, | 1268 JNIEnv* env, |
1263 jobject obj, | 1269 jobject obj, |
1264 jboolean allow) { | 1270 jboolean allow) { |
1265 web_contents_->java_bridge_dispatcher_host_manager() | 1271 java_bridge_dispatcher_host_manager_->SetAllowObjectContentsInspection(allow); |
1266 ->SetAllowObjectContentsInspection(allow); | |
1267 } | 1272 } |
1268 | 1273 |
1269 void ContentViewCoreImpl::AddJavascriptInterface( | 1274 void ContentViewCoreImpl::AddJavascriptInterface( |
1270 JNIEnv* env, | 1275 JNIEnv* env, |
1271 jobject /* obj */, | 1276 jobject /* obj */, |
1272 jobject object, | 1277 jobject object, |
1273 jstring name, | 1278 jstring name, |
1274 jclass safe_annotation_clazz, | 1279 jclass safe_annotation_clazz) { |
1275 jobject retained_object_set) { | |
1276 ScopedJavaLocalRef<jobject> scoped_object(env, object); | 1280 ScopedJavaLocalRef<jobject> scoped_object(env, object); |
1277 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); | 1281 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); |
1278 JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set); | |
1279 | 1282 |
1280 // JavaBoundObject creates the NPObject with a ref count of 1, and | 1283 // JavaBoundObject creates the NPObject with a ref count of 1, and |
1281 // JavaBridgeDispatcherHostManager takes its own ref. | 1284 // JavaBridgeDispatcherHostManager takes its own ref. |
1282 JavaBridgeDispatcherHostManager* java_bridge = | 1285 NPObject* bound_object = JavaBoundObject::Create( |
1283 web_contents_->java_bridge_dispatcher_host_manager(); | 1286 scoped_object, |
1284 java_bridge->SetRetainedObjectSet(weak_retained_object_set); | 1287 scoped_clazz, |
1285 NPObject* bound_object = | 1288 java_bridge_dispatcher_host_manager_->AsWeakPtr(), |
1286 JavaBoundObject::Create(scoped_object, | 1289 java_bridge_dispatcher_host_manager_->GetAllowObjectContentsInspection()); |
1287 scoped_clazz, | 1290 java_bridge_dispatcher_host_manager_->AddNamedObject( |
1288 java_bridge->AsWeakPtr(), | 1291 ConvertJavaStringToUTF16(env, name), bound_object); |
1289 java_bridge->GetAllowObjectContentsInspection()); | |
1290 java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name), | |
1291 bound_object); | |
1292 blink::WebBindings::releaseObject(bound_object); | 1292 blink::WebBindings::releaseObject(bound_object); |
1293 } | 1293 } |
1294 | 1294 |
1295 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1295 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
1296 jobject /* obj */, | 1296 jobject /* obj */, |
1297 jstring name) { | 1297 jstring name) { |
1298 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | 1298 java_bridge_dispatcher_host_manager_->RemoveNamedObject( |
1299 ConvertJavaStringToUTF16(env, name)); | 1299 ConvertJavaStringToUTF16(env, name)); |
1300 } | 1300 } |
1301 | 1301 |
1302 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1302 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
1303 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1303 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
1304 if (view) { | 1304 if (view) { |
1305 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 1305 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
1306 view->GetRenderWidgetHost()); | 1306 view->GetRenderWidgetHost()); |
1307 host->SendScreenRects(); | 1307 host->SendScreenRects(); |
1308 view->WasResized(); | 1308 view->WasResized(); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 static_cast<WebContentsViewAndroid*>(web_contents->GetView()); | 1655 static_cast<WebContentsViewAndroid*>(web_contents->GetView()); |
1656 DCHECK(wcva); | 1656 DCHECK(wcva); |
1657 wcva->SetContentViewCore(NULL); | 1657 wcva->SetContentViewCore(NULL); |
1658 } | 1658 } |
1659 | 1659 |
1660 // This is called for each ContentView. | 1660 // This is called for each ContentView. |
1661 jlong Init(JNIEnv* env, | 1661 jlong Init(JNIEnv* env, |
1662 jobject obj, | 1662 jobject obj, |
1663 jlong native_web_contents, | 1663 jlong native_web_contents, |
1664 jlong view_android, | 1664 jlong view_android, |
1665 jlong window_android) { | 1665 jlong window_android, |
| 1666 jobject retained_objects_set) { |
1666 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1667 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1667 env, obj, | 1668 env, obj, |
1668 reinterpret_cast<WebContents*>(native_web_contents), | 1669 reinterpret_cast<WebContents*>(native_web_contents), |
1669 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1670 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1670 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1671 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1672 retained_objects_set); |
1671 return reinterpret_cast<intptr_t>(view); | 1673 return reinterpret_cast<intptr_t>(view); |
1672 } | 1674 } |
1673 | 1675 |
1674 bool RegisterContentViewCore(JNIEnv* env) { | 1676 bool RegisterContentViewCore(JNIEnv* env) { |
1675 return RegisterNativesImpl(env); | 1677 return RegisterNativesImpl(env); |
1676 } | 1678 } |
1677 | 1679 |
1678 } // namespace content | 1680 } // namespace content |
OLD | NEW |