Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 253013002: Pass RenderFrameHost to WebContentObservers' message handlers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Android tests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 CHECK(web_contents) << 229 CHECK(web_contents) <<
228 "A ContentViewCoreImpl should be created with a valid WebContents."; 230 "A ContentViewCoreImpl should be created with a valid WebContents.";
229 231
230 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); 232 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj));
231 gfx::Size physical_size( 233 gfx::Size physical_size(
232 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 234 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
233 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 235 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
234 root_layer_->SetBounds(physical_size); 236 root_layer_->SetBounds(physical_size);
235 root_layer_->SetIsDrawable(true); 237 root_layer_->SetIsDrawable(true);
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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { 1274 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) {
1269 // TODO(creis): Do callers of this need to know if it fails? 1275 // TODO(creis): Do callers of this need to know if it fails?
1270 if (web_contents_->GetController().CanPruneAllButLastCommitted()) 1276 if (web_contents_->GetController().CanPruneAllButLastCommitted())
1271 web_contents_->GetController().PruneAllButLastCommitted(); 1277 web_contents_->GetController().PruneAllButLastCommitted();
1272 } 1278 }
1273 1279
1274 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( 1280 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection(
1275 JNIEnv* env, 1281 JNIEnv* env,
1276 jobject obj, 1282 jobject obj,
1277 jboolean allow) { 1283 jboolean allow) {
1278 web_contents_->java_bridge_dispatcher_host_manager() 1284 java_bridge_dispatcher_host_manager_->SetAllowObjectContentsInspection(allow);
1279 ->SetAllowObjectContentsInspection(allow);
1280 } 1285 }
1281 1286
1282 void ContentViewCoreImpl::AddJavascriptInterface( 1287 void ContentViewCoreImpl::AddJavascriptInterface(
1283 JNIEnv* env, 1288 JNIEnv* env,
1284 jobject /* obj */, 1289 jobject /* obj */,
1285 jobject object, 1290 jobject object,
1286 jstring name, 1291 jstring name,
1287 jclass safe_annotation_clazz, 1292 jclass safe_annotation_clazz) {
1288 jobject retained_object_set) {
1289 ScopedJavaLocalRef<jobject> scoped_object(env, object); 1293 ScopedJavaLocalRef<jobject> scoped_object(env, object);
1290 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); 1294 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz);
1291 JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set);
1292 1295
1293 // JavaBoundObject creates the NPObject with a ref count of 1, and 1296 // JavaBoundObject creates the NPObject with a ref count of 1, and
1294 // JavaBridgeDispatcherHostManager takes its own ref. 1297 // JavaBridgeDispatcherHostManager takes its own ref.
1295 JavaBridgeDispatcherHostManager* java_bridge = 1298 NPObject* bound_object = JavaBoundObject::Create(
1296 web_contents_->java_bridge_dispatcher_host_manager(); 1299 scoped_object,
1297 java_bridge->SetRetainedObjectSet(weak_retained_object_set); 1300 scoped_clazz,
1298 NPObject* bound_object = 1301 java_bridge_dispatcher_host_manager_->AsWeakPtr(),
1299 JavaBoundObject::Create(scoped_object, 1302 java_bridge_dispatcher_host_manager_->GetAllowObjectContentsInspection());
1300 scoped_clazz, 1303 java_bridge_dispatcher_host_manager_->AddNamedObject(
1301 java_bridge->AsWeakPtr(), 1304 ConvertJavaStringToUTF16(env, name), bound_object);
1302 java_bridge->GetAllowObjectContentsInspection());
1303 java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name),
1304 bound_object);
1305 blink::WebBindings::releaseObject(bound_object); 1305 blink::WebBindings::releaseObject(bound_object);
1306 } 1306 }
1307 1307
1308 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, 1308 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env,
1309 jobject /* obj */, 1309 jobject /* obj */,
1310 jstring name) { 1310 jstring name) {
1311 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( 1311 java_bridge_dispatcher_host_manager_->RemoveNamedObject(
1312 ConvertJavaStringToUTF16(env, name)); 1312 ConvertJavaStringToUTF16(env, name));
1313 } 1313 }
1314 1314
1315 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { 1315 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) {
1316 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 1316 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
1317 gfx::Size physical_size( 1317 gfx::Size physical_size(
1318 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 1318 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
1319 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 1319 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
1320 root_layer_->SetBounds(physical_size); 1320 root_layer_->SetBounds(physical_size);
1321 1321
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 static_cast<WebContentsImpl*>(web_contents)->GetView()); 1673 static_cast<WebContentsImpl*>(web_contents)->GetView());
1674 DCHECK(wcva); 1674 DCHECK(wcva);
1675 wcva->SetContentViewCore(NULL); 1675 wcva->SetContentViewCore(NULL);
1676 } 1676 }
1677 1677
1678 // This is called for each ContentView. 1678 // This is called for each ContentView.
1679 jlong Init(JNIEnv* env, 1679 jlong Init(JNIEnv* env,
1680 jobject obj, 1680 jobject obj,
1681 jlong native_web_contents, 1681 jlong native_web_contents,
1682 jlong view_android, 1682 jlong view_android,
1683 jlong window_android) { 1683 jlong window_android,
1684 jobject retained_objects_set) {
1684 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1685 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1685 env, obj, 1686 env, obj,
1686 reinterpret_cast<WebContents*>(native_web_contents), 1687 reinterpret_cast<WebContents*>(native_web_contents),
1687 reinterpret_cast<ui::ViewAndroid*>(view_android), 1688 reinterpret_cast<ui::ViewAndroid*>(view_android),
1688 reinterpret_cast<ui::WindowAndroid*>(window_android)); 1689 reinterpret_cast<ui::WindowAndroid*>(window_android),
1690 retained_objects_set);
1689 return reinterpret_cast<intptr_t>(view); 1691 return reinterpret_cast<intptr_t>(view);
1690 } 1692 }
1691 1693
1692 bool RegisterContentViewCore(JNIEnv* env) { 1694 bool RegisterContentViewCore(JNIEnv* env) {
1693 return RegisterNativesImpl(env); 1695 return RegisterNativesImpl(env);
1694 } 1696 }
1695 1697
1696 } // namespace content 1698 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/frame_host/interstitial_page_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698