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

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

Issue 10854251: Allow the creation of partially spoofed user agents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed flag Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "content/browser/android/content_view_client.h" 12 #include "content/browser/android/content_view_client.h"
13 #include "content/browser/android/load_url_params.h" 13 #include "content/browser/android/load_url_params.h"
14 #include "content/browser/android/touch_point.h" 14 #include "content/browser/android/touch_point.h"
15 #include "content/browser/renderer_host/java/java_bound_object.h" 15 #include "content/browser/renderer_host/java/java_bound_object.h"
16 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h" 16 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h"
17 #include "content/browser/renderer_host/render_view_host_impl.h" 17 #include "content/browser/renderer_host/render_view_host_impl.h"
18 #include "content/browser/renderer_host/render_widget_host_impl.h" 18 #include "content/browser/renderer_host/render_widget_host_impl.h"
19 #include "content/browser/renderer_host/render_widget_host_view_android.h" 19 #include "content/browser/renderer_host/render_widget_host_view_android.h"
20 #include "content/browser/web_contents/navigation_controller_impl.h" 20 #include "content/browser/web_contents/navigation_controller_impl.h"
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/favicon_status.h" 22 #include "content/public/browser/favicon_status.h"
23 #include "content/public/browser/interstitial_page.h" 23 #include "content/public/browser/interstitial_page.h"
24 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/content_client.h"
30 #include "content/public/common/page_transition_types.h" 31 #include "content/public/common/page_transition_types.h"
31 #include "jni/ContentViewCore_jni.h" 32 #include "jni/ContentViewCore_jni.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h"
35 #include "ui/gfx/android/java_bitmap.h" 36 #include "ui/gfx/android/java_bitmap.h"
37 #include "webkit/glue/user_agent.h"
36 #include "webkit/glue/webmenuitem.h" 38 #include "webkit/glue/webmenuitem.h"
37 39
38 using base::android::AttachCurrentThread; 40 using base::android::AttachCurrentThread;
39 using base::android::ConvertJavaStringToUTF16; 41 using base::android::ConvertJavaStringToUTF16;
40 using base::android::ConvertJavaStringToUTF8; 42 using base::android::ConvertJavaStringToUTF8;
41 using base::android::ConvertUTF16ToJavaString; 43 using base::android::ConvertUTF16ToJavaString;
42 using base::android::ConvertUTF8ToJavaString; 44 using base::android::ConvertUTF8ToJavaString;
43 using base::android::GetClass; 45 using base::android::GetClass;
44 using base::android::HasField; 46 using base::android::HasField;
45 using base::android::JavaByteArrayToByteVector; 47 using base::android::JavaByteArrayToByteVector;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 web_contents_(static_cast<WebContentsImpl*>(web_contents)), 90 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
89 tab_crashed_(false) { 91 tab_crashed_(false) {
90 DCHECK(web_contents) << 92 DCHECK(web_contents) <<
91 "A ContentViewCoreImpl should be created with a valid WebContents."; 93 "A ContentViewCoreImpl should be created with a valid WebContents.";
92 94
93 InitJNI(env, obj); 95 InitJNI(env, obj);
94 96
95 notification_registrar_.Add(this, 97 notification_registrar_.Add(this,
96 NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, 98 NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT,
97 NotificationService::AllSources()); 99 NotificationService::AllSources());
100
101 // Currently, the only use case we have for overriding a user agent involves
102 // spoofing a desktop Linux user agent for "Request desktop site".
103 // Automatically set it for all WebContents.
Charlie Reis 2012/08/24 21:38:43 I don't understand this comment. Request desktop
gone 2012/08/24 23:50:35 The main reason we set it here is that we don't sa
Charlie Reis 2012/08/25 00:11:10 Sorry if I'm just missing something basic, but is
gone 2012/08/25 00:23:49 D'oh, yeah, that's all that does. It just sets th
104 const char kLinuxInfoStr[] = "X11; Linux x86_64";
105 std::string product = content::GetContentClient()->GetProduct();
106 std::string spoofed_ua =
107 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product);
108 web_contents->SetUserAgentOverride(spoofed_ua);
98 } 109 }
99 110
100 ContentViewCoreImpl::~ContentViewCoreImpl() { 111 ContentViewCoreImpl::~ContentViewCoreImpl() {
101 // Make sure nobody calls back into this object while we are tearing things 112 // Make sure nobody calls back into this object while we are tearing things
102 // down. 113 // down.
103 notification_registrar_.RemoveAll(); 114 notification_registrar_.RemoveAll();
104 115
105 delete java_object_; 116 delete java_object_;
106 java_object_ = NULL; 117 java_object_ = NULL;
107 java_ref_.reset(); 118 java_ref_.reset();
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { 627 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) {
617 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; 628 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!";
618 return false; 629 return false;
619 } 630 }
620 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); 631 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I");
621 632
622 return RegisterNativesImpl(env) >= 0; 633 return RegisterNativesImpl(env) >= 0;
623 } 634 }
624 635
625 } // namespace content 636 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698