Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 using WebKit::WebInputEventFactory; | 58 using WebKit::WebInputEventFactory; |
| 59 | 59 |
| 60 // Describes the type and enabled state of a select popup item. | 60 // Describes the type and enabled state of a select popup item. |
| 61 // Keep in sync with the value defined in SelectPopupDialog.java | 61 // Keep in sync with the value defined in SelectPopupDialog.java |
| 62 enum PopupItemType { | 62 enum PopupItemType { |
| 63 POPUP_ITEM_TYPE_GROUP = 0, | 63 POPUP_ITEM_TYPE_GROUP = 0, |
| 64 POPUP_ITEM_TYPE_DISABLED, | 64 POPUP_ITEM_TYPE_DISABLED, |
| 65 POPUP_ITEM_TYPE_ENABLED | 65 POPUP_ITEM_TYPE_ENABLED |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 namespace content { | |
| 69 | |
| 68 namespace { | 70 namespace { |
| 69 jfieldID g_native_content_view; | 71 jfieldID g_native_content_view; |
| 72 | |
| 73 const void* kContentViewUserDataKey = &kContentViewUserDataKey; | |
| 70 } // namespace | 74 } // namespace |
| 71 | 75 |
| 72 namespace content { | 76 // Enables a callback when the underlying WebContents is destroyed, to enable |
| 77 // nulling the back-pointer. | |
| 78 class ContentViewCoreImpl::ContentViewUserData | |
| 79 : public base::SupportsUserData::Data { | |
| 80 public: | |
| 81 ContentViewUserData(ContentViewCoreImpl* content_view_core) | |
|
Jay Civelli
2012/10/15 17:11:49
explicit
joth
2012/10/15 20:11:35
Done.
| |
| 82 : content_view_core_(content_view_core) { | |
| 83 } | |
| 84 | |
| 85 virtual ~ContentViewUserData() { | |
| 86 // TODO(joth): When chrome has finished removing the TabContents class (see | |
| 87 // crbug.com/107201) consider inverting relationship, so ContentViewCore | |
| 88 // would own WebContents. The effectively requires making the WebContents | |
|
joth
2012/10/13 17:53:30
=> That effectively implies
joth
2012/10/15 20:11:35
Done.
| |
| 89 // destructor private on Android. | |
| 90 delete content_view_core_; | |
| 91 } | |
| 92 | |
| 93 ContentViewCoreImpl* get() { return content_view_core_; } | |
|
Jay Civelli
2012/10/15 17:11:49
const
joth
2012/10/15 20:11:35
Done.
| |
| 94 | |
| 95 private: | |
| 96 ContentViewCoreImpl* content_view_core_; | |
|
joth
2012/10/13 17:53:30
// Not using scoped_ptr as ContentViewCoreImpl des
joth
2012/10/15 20:11:35
Done.
| |
| 97 }; | |
|
Jay Civelli
2012/10/15 17:11:49
DISALLOW_...
joth
2012/10/15 20:11:35
Done.
| |
| 73 | 98 |
| 74 struct ContentViewCoreImpl::JavaObject { | 99 struct ContentViewCoreImpl::JavaObject { |
| 75 ScopedJavaGlobalRef<jclass> rect_clazz; | 100 ScopedJavaGlobalRef<jclass> rect_clazz; |
| 76 jmethodID rect_constructor; | 101 jmethodID rect_constructor; |
| 77 }; | 102 }; |
| 78 | 103 |
| 104 // static | |
| 105 ContentViewCoreImpl* ContentViewCoreImpl::FromWebContents( | |
| 106 content::WebContents* web_contents) { | |
| 107 ContentViewCoreImpl::ContentViewUserData* data = | |
| 108 reinterpret_cast<ContentViewCoreImpl::ContentViewUserData*>( | |
| 109 web_contents->GetUserData(kContentViewUserDataKey)); | |
| 110 return data ? data->get() : NULL; | |
| 111 } | |
| 112 | |
| 113 // static | |
| 114 ContentViewCore* ContentViewCore::FromWebContents( | |
| 115 content::WebContents* web_contents) { | |
| 116 return ContentViewCoreImpl::FromWebContents(web_contents); | |
| 117 } | |
| 118 | |
| 79 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 119 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
| 80 jobject obj) { | 120 jobject obj) { |
| 81 return reinterpret_cast<ContentViewCore*>( | 121 return reinterpret_cast<ContentViewCore*>( |
| 82 env->GetIntField(obj, g_native_content_view)); | 122 env->GetIntField(obj, g_native_content_view)); |
| 83 } | 123 } |
| 84 | 124 |
| 85 | |
| 86 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 125 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
| 87 bool hardware_accelerated, | 126 bool hardware_accelerated, |
| 88 WebContents* web_contents, | 127 WebContents* web_contents, |
| 89 ui::WindowAndroid* window_android) | 128 ui::WindowAndroid* window_android) |
| 90 : java_ref_(env, obj), | 129 : java_ref_(env, obj), |
| 91 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 130 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 92 tab_crashed_(false), | 131 tab_crashed_(false), |
| 93 window_android_(window_android) { | 132 window_android_(window_android) { |
| 94 DCHECK(web_contents) << | 133 DCHECK(web_contents) << |
| 95 "A ContentViewCoreImpl should be created with a valid WebContents."; | 134 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 112 // Currently, the only use case we have for overriding a user agent involves | 151 // Currently, the only use case we have for overriding a user agent involves |
| 113 // spoofing a desktop Linux user agent for "Request desktop site". | 152 // spoofing a desktop Linux user agent for "Request desktop site". |
| 114 // Automatically set it for all WebContents so that it is available when a | 153 // Automatically set it for all WebContents so that it is available when a |
| 115 // NavigationEntry requires the user agent to be overridden. | 154 // NavigationEntry requires the user agent to be overridden. |
| 116 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 155 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 117 std::string product = content::GetContentClient()->GetProduct(); | 156 std::string product = content::GetContentClient()->GetProduct(); |
| 118 std::string spoofed_ua = | 157 std::string spoofed_ua = |
| 119 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 158 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 120 web_contents->SetUserAgentOverride(spoofed_ua); | 159 web_contents->SetUserAgentOverride(spoofed_ua); |
| 121 | 160 |
| 122 InitWebContents(web_contents); | 161 InitWebContents(); |
| 123 } | 162 } |
| 124 | 163 |
| 125 ContentViewCoreImpl::~ContentViewCoreImpl() { | 164 ContentViewCoreImpl::~ContentViewCoreImpl() { |
| 165 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 166 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
| 167 java_ref_.reset(); | |
| 168 if (!j_obj.is_null()) { | |
| 169 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | |
| 170 env, j_obj.obj(), reinterpret_cast<jint>(this)); | |
| 171 } | |
| 126 // Make sure nobody calls back into this object while we are tearing things | 172 // Make sure nobody calls back into this object while we are tearing things |
| 127 // down. | 173 // down. |
| 128 notification_registrar_.RemoveAll(); | 174 notification_registrar_.RemoveAll(); |
| 129 | 175 |
| 130 delete java_object_; | 176 delete java_object_; |
| 131 java_object_ = NULL; | 177 java_object_ = NULL; |
| 178 } | |
| 179 | |
| 180 void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, | |
| 181 jobject obj) { | |
| 182 DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); | |
| 132 java_ref_.reset(); | 183 java_ref_.reset(); |
| 133 } | 184 } |
| 134 | 185 |
| 135 void ContentViewCoreImpl::Destroy(JNIEnv* env, jobject obj) { | 186 void ContentViewCoreImpl::InitWebContents() { |
| 136 delete this; | 187 DCHECK(web_contents_); |
| 137 } | |
| 138 | |
| 139 void ContentViewCoreImpl::InitWebContents(WebContents* web_contents) { | |
| 140 web_contents_ = static_cast<WebContentsImpl*>(web_contents); | |
| 141 notification_registrar_.Add(this, | 188 notification_registrar_.Add(this, |
| 142 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 189 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 143 Source<NavigationController>(&web_contents_->GetController())); | 190 Source<NavigationController>(&web_contents_->GetController())); |
| 144 | 191 |
| 145 static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> | 192 static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> |
| 146 SetContentViewCore(this); | 193 SetContentViewCore(this); |
| 194 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); | |
| 195 web_contents_->SetUserData(kContentViewUserDataKey, | |
| 196 new ContentViewUserData(this)); | |
| 147 } | 197 } |
| 148 | 198 |
| 149 void ContentViewCoreImpl::Observe(int type, | 199 void ContentViewCoreImpl::Observe(int type, |
| 150 const NotificationSource& source, | 200 const NotificationSource& source, |
| 151 const NotificationDetails& details) { | 201 const NotificationDetails& details) { |
| 152 switch (type) { | 202 switch (type) { |
| 153 case NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT: { | 203 case NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT: { |
| 154 if (!web_contents_ || Source<RenderViewHost>(source).ptr() != | 204 if (!web_contents_ || Source<RenderViewHost>(source).ptr() != |
| 155 web_contents_->GetRenderViewHost()) { | 205 web_contents_->GetRenderViewHost()) { |
| 156 return; | 206 return; |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 1016 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
| 967 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 1017 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
| 968 return false; | 1018 return false; |
| 969 } | 1019 } |
| 970 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 1020 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
| 971 | 1021 |
| 972 return RegisterNativesImpl(env) >= 0; | 1022 return RegisterNativesImpl(env) >= 0; |
| 973 } | 1023 } |
| 974 | 1024 |
| 975 } // namespace content | 1025 } // namespace content |
| OLD | NEW |