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

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

Issue 10696173: Revert "Revert 146000 - Split out ContentViewCore from ContentView for embedders." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase number deux Created 8 years, 5 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 (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_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_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "content/browser/android/content_view_client.h" 10 #include "content/browser/android/content_view_client.h"
11 #include "content/browser/web_contents/navigation_controller_impl.h" 11 #include "content/browser/web_contents/navigation_controller_impl.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "jni/content_view_jni.h" 14 #include "jni/content_view_core_jni.h"
15 15
16 using base::android::AttachCurrentThread; 16 using base::android::AttachCurrentThread;
17 using base::android::ConvertUTF16ToJavaString; 17 using base::android::ConvertUTF16ToJavaString;
18 using base::android::ConvertUTF8ToJavaString; 18 using base::android::ConvertUTF8ToJavaString;
19 using base::android::GetClass; 19 using base::android::GetClass;
20 using base::android::HasField; 20 using base::android::HasField;
21 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
22 22
23 namespace { 23 namespace {
24 jfieldID g_native_content_view; 24 jfieldID g_native_content_view;
25 } // namespace 25 } // namespace
26 26
27 namespace content { 27 namespace content {
28 28
29 struct ContentViewImpl::JavaObject { 29 struct ContentViewCoreImpl::JavaObject {
30 jweak obj; 30 jweak obj;
31 31
32 ScopedJavaLocalRef<jobject> View(JNIEnv* env) { 32 ScopedJavaLocalRef<jobject> View(JNIEnv* env) {
33 return GetRealObject(env, obj); 33 return GetRealObject(env, obj);
34 } 34 }
35 }; 35 };
36 36
37 // ---------------------------------------------------------------------------- 37 // ----------------------------------------------------------------------------
38 // Implementation of static ContentView public interfaces 38 // Implementation of static ContentViewCore public interfaces
39 39
40 ContentView* ContentView::Create(JNIEnv* env, jobject obj, 40 ContentViewCore* ContentViewCore::Create(JNIEnv* env, jobject obj,
41 WebContents* web_contents) { 41 WebContents* web_contents) {
42 return new ContentViewImpl(env, obj, web_contents); 42 return new ContentViewCoreImpl(env, obj, web_contents);
43 } 43 }
44 44
45 ContentView* ContentView::GetNativeContentView(JNIEnv* env, jobject obj) { 45 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env,
46 return reinterpret_cast<ContentView*>( 46 jobject obj) {
47 return reinterpret_cast<ContentViewCore*>(
47 env->GetIntField(obj, g_native_content_view)); 48 env->GetIntField(obj, g_native_content_view));
48 } 49 }
49 50
50 // ---------------------------------------------------------------------------- 51 // ----------------------------------------------------------------------------
51 52
52 ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj, 53 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj,
53 WebContents* web_contents) 54 WebContents* web_contents)
54 : web_contents_(web_contents), 55 : web_contents_(web_contents),
55 tab_crashed_(false) { 56 tab_crashed_(false) {
56 DCHECK(web_contents) << 57 DCHECK(web_contents) <<
57 "A ContentViewImpl should be created with a valid WebContents."; 58 "A ContentViewCoreImpl should be created with a valid WebContents.";
58 59
59 InitJNI(env, obj); 60 InitJNI(env, obj);
60 } 61 }
61 62
62 ContentViewImpl::~ContentViewImpl() { 63 ContentViewCoreImpl::~ContentViewCoreImpl() {
63 if (java_object_) { 64 if (java_object_) {
64 JNIEnv* env = AttachCurrentThread(); 65 JNIEnv* env = AttachCurrentThread();
65 env->DeleteWeakGlobalRef(java_object_->obj); 66 env->DeleteWeakGlobalRef(java_object_->obj);
66 delete java_object_; 67 delete java_object_;
67 java_object_ = 0; 68 java_object_ = 0;
68 } 69 }
69 } 70 }
70 71
71 void ContentViewImpl::Destroy(JNIEnv* env, jobject obj) { 72 void ContentViewCoreImpl::Destroy(JNIEnv* env, jobject obj) {
72 delete this; 73 delete this;
73 } 74 }
74 75
75 void ContentViewImpl::Observe(int type, 76 void ContentViewCoreImpl::Observe(int type,
76 const NotificationSource& source, 77 const NotificationSource& source,
77 const NotificationDetails& details) { 78 const NotificationDetails& details) {
78 // TODO(jrg) 79 // TODO(jrg)
79 } 80 }
80 81
81 void ContentViewImpl::InitJNI(JNIEnv* env, jobject obj) { 82 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) {
82 java_object_ = new JavaObject; 83 java_object_ = new JavaObject;
83 java_object_->obj = env->NewWeakGlobalRef(obj); 84 java_object_->obj = env->NewWeakGlobalRef(obj);
84 } 85 }
85 86
86 // ---------------------------------------------------------------------------- 87 // ----------------------------------------------------------------------------
87 // Methods called from Java via JNI 88 // Methods called from Java via JNI
88 // ---------------------------------------------------------------------------- 89 // ----------------------------------------------------------------------------
89 90
90 void ContentViewImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, 91 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env,
91 jobject, 92 jobject,
92 jstring jurl, 93 jstring jurl,
93 int page_transition) { 94 int page_transition) {
94 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); 95 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
95 96
96 LoadUrl(url, page_transition); 97 LoadUrl(url, page_transition);
97 } 98 }
98 99
99 void ContentViewImpl::LoadUrlWithoutUrlSanitizationWithUserAgentOverride( 100 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitizationWithUserAgentOverride(
100 JNIEnv* env, 101 JNIEnv* env,
101 jobject, 102 jobject,
102 jstring jurl, 103 jstring jurl,
103 int page_transition, 104 int page_transition,
104 jstring user_agent_override) { 105 jstring user_agent_override) {
105 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); 106 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
106 107
107 LoadUrlWithUserAgentOverride( 108 LoadUrlWithUserAgentOverride(
108 url, 109 url,
109 page_transition, 110 page_transition,
110 base::android::ConvertJavaStringToUTF8(env, user_agent_override)); 111 base::android::ConvertJavaStringToUTF8(env, user_agent_override));
111 } 112 }
112 113
113 ScopedJavaLocalRef<jstring> ContentViewImpl::GetURL( 114 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL(
114 JNIEnv* env, jobject) const { 115 JNIEnv* env, jobject) const {
115 return ConvertUTF8ToJavaString(env, web_contents()->GetURL().spec()); 116 return ConvertUTF8ToJavaString(env, web_contents()->GetURL().spec());
116 } 117 }
117 118
118 ScopedJavaLocalRef<jstring> ContentViewImpl::GetTitle( 119 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetTitle(
119 JNIEnv* env, jobject obj) const { 120 JNIEnv* env, jobject obj) const {
120 return ConvertUTF16ToJavaString(env, web_contents()->GetTitle()); 121 return ConvertUTF16ToJavaString(env, web_contents()->GetTitle());
121 } 122 }
122 123
123 jdouble ContentViewImpl::GetLoadProgress(JNIEnv* env, jobject obj) const { 124 jdouble ContentViewCoreImpl::GetLoadProgress(JNIEnv* env, jobject obj) const {
124 // An empty page never loads anything and always has a progress of 0. 125 // An empty page never loads anything and always has a progress of 0.
125 // We report 1 in that case so the UI does not assume the page is loading. 126 // We report 1 in that case so the UI does not assume the page is loading.
126 if (web_contents()->GetURL().is_empty() || !content_view_client_.get()) 127 if (web_contents()->GetURL().is_empty() || !content_view_client_.get())
127 return static_cast<jdouble>(1.0); 128 return static_cast<jdouble>(1.0);
128 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); 129 return static_cast<jdouble>(content_view_client_->GetLoadProgress());
129 } 130 }
130 131
131 jboolean ContentViewImpl::IsIncognito(JNIEnv* env, jobject obj) { 132 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) {
132 return web_contents()->GetBrowserContext()->IsOffTheRecord(); 133 return web_contents()->GetBrowserContext()->IsOffTheRecord();
133 } 134 }
134 135
135 jboolean ContentViewImpl::CanGoBack(JNIEnv* env, jobject obj) { 136 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) {
136 return web_contents_->GetController().CanGoBack(); 137 return web_contents_->GetController().CanGoBack();
137 } 138 }
138 139
139 jboolean ContentViewImpl::CanGoForward(JNIEnv* env, jobject obj) { 140 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) {
140 return web_contents_->GetController().CanGoForward(); 141 return web_contents_->GetController().CanGoForward();
141 } 142 }
142 143
143 jboolean ContentViewImpl::CanGoToOffset( 144 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj,
144 JNIEnv* env, jobject obj, jint offset) { 145 jint offset) {
145 return web_contents_->GetController().CanGoToOffset(offset); 146 return web_contents_->GetController().CanGoToOffset(offset);
146 } 147 }
147 148
148 void ContentViewImpl::GoBack(JNIEnv* env, jobject obj) { 149 void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) {
149 web_contents_->GetController().GoBack(); 150 web_contents_->GetController().GoBack();
150 tab_crashed_ = false; 151 tab_crashed_ = false;
151 } 152 }
152 153
153 void ContentViewImpl::GoForward(JNIEnv* env, jobject obj) { 154 void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) {
154 web_contents_->GetController().GoForward(); 155 web_contents_->GetController().GoForward();
155 tab_crashed_ = false; 156 tab_crashed_ = false;
156 } 157 }
157 158
158 void ContentViewImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { 159 void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) {
159 web_contents_->GetController().GoToOffset(offset); 160 web_contents_->GetController().GoToOffset(offset);
160 } 161 }
161 162
162 void ContentViewImpl::StopLoading(JNIEnv* env, jobject obj) { 163 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) {
163 web_contents_->Stop(); 164 web_contents_->Stop();
164 } 165 }
165 166
166 void ContentViewImpl::Reload(JNIEnv* env, jobject obj) { 167 void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) {
167 // Set check_for_repost parameter to false as we have no repost confirmation 168 // Set check_for_repost parameter to false as we have no repost confirmation
168 // dialog ("confirm form resubmission" screen will still appear, however). 169 // dialog ("confirm form resubmission" screen will still appear, however).
169 web_contents_->GetController().Reload(false); 170 web_contents_->GetController().Reload(false);
170 tab_crashed_ = false; 171 tab_crashed_ = false;
171 } 172 }
172 173
173 void ContentViewImpl::ClearHistory(JNIEnv* env, jobject obj) { 174 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) {
174 web_contents_->GetController().PruneAllButActive(); 175 web_contents_->GetController().PruneAllButActive();
175 } 176 }
176 177
177 jboolean ContentViewImpl::NeedsReload(JNIEnv* env, jobject obj) { 178 jboolean ContentViewCoreImpl::NeedsReload(JNIEnv* env, jobject obj) {
178 return web_contents_->GetController().NeedsReload(); 179 return web_contents_->GetController().NeedsReload();
179 } 180 }
180 181
181 void ContentViewImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { 182 void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) {
182 scoped_ptr<ContentViewClient> client( 183 scoped_ptr<ContentViewClient> client(
183 ContentViewClient::CreateNativeContentViewClient(env, jclient)); 184 ContentViewClient::CreateNativeContentViewClient(env, jclient));
184 185
185 web_contents_->SetDelegate(client.get()); 186 web_contents_->SetDelegate(client.get());
186 187
187 content_view_client_.swap(client); 188 content_view_client_.swap(client);
188 } 189 }
189 190
190 // -------------------------------------------------------------------------- 191 // --------------------------------------------------------------------------
191 // Methods called from native code 192 // Methods called from native code
192 // -------------------------------------------------------------------------- 193 // --------------------------------------------------------------------------
193 194
194 void ContentViewImpl::LoadUrl(const GURL& url, int page_transition) { 195 void ContentViewCoreImpl::LoadUrl(const GURL& url, int page_transition) {
195 content::Referrer referer; 196 content::Referrer referer;
196 197
197 web_contents()->GetController().LoadURL( 198 web_contents()->GetController().LoadURL(
198 url, referer, content::PageTransitionFromInt(page_transition), 199 url, referer, content::PageTransitionFromInt(page_transition),
199 std::string()); 200 std::string());
200 PostLoadUrl(url); 201 PostLoadUrl(url);
201 } 202 }
202 203
203 void ContentViewImpl::LoadUrlWithUserAgentOverride( 204 void ContentViewCoreImpl::LoadUrlWithUserAgentOverride(
204 const GURL& url, 205 const GURL& url,
205 int page_transition, 206 int page_transition,
206 const std::string& user_agent_override) { 207 const std::string& user_agent_override) {
207 web_contents()->SetUserAgentOverride(user_agent_override); 208 web_contents()->SetUserAgentOverride(user_agent_override);
208 bool is_overriding_user_agent(!user_agent_override.empty()); 209 bool is_overriding_user_agent(!user_agent_override.empty());
209 content::Referrer referer; 210 content::Referrer referer;
210 web_contents()->GetController().LoadURLWithUserAgentOverride( 211 web_contents()->GetController().LoadURLWithUserAgentOverride(
211 url, referer, content::PageTransitionFromInt(page_transition), 212 url, referer, content::PageTransitionFromInt(page_transition),
212 false, std::string(), is_overriding_user_agent); 213 false, std::string(), is_overriding_user_agent);
213 PostLoadUrl(url); 214 PostLoadUrl(url);
214 } 215 }
215 216
216 void ContentViewImpl::PostLoadUrl(const GURL& url) { 217 void ContentViewCoreImpl::PostLoadUrl(const GURL& url) {
217 tab_crashed_ = false; 218 tab_crashed_ = false;
218 // TODO(tedchoc): Update the content view client of the page load request. 219 // TODO(tedchoc): Update the content view client of the page load request.
219 } 220 }
220 221
221 // ---------------------------------------------------------------------------- 222 // ----------------------------------------------------------------------------
222 // Native JNI methods 223 // Native JNI methods
223 // ---------------------------------------------------------------------------- 224 // ----------------------------------------------------------------------------
224 225
225 // This is called for each ContentView. 226 // This is called for each ContentViewCore.
226 static jint Init(JNIEnv* env, jobject obj, jint native_web_contents) { 227 jint Init(JNIEnv* env, jobject obj, jint native_web_contents) {
227 ContentView* view = ContentView::Create( 228 ContentViewCore* view = ContentViewCore::Create(
228 env, obj, reinterpret_cast<WebContents*>(native_web_contents)); 229 env, obj, reinterpret_cast<WebContents*>(native_web_contents));
229 return reinterpret_cast<jint>(view); 230 return reinterpret_cast<jint>(view);
230 } 231 }
231 232
232 // -------------------------------------------------------------------------- 233 // --------------------------------------------------------------------------
233 // Public methods that call to Java via JNI 234 // Public methods that call to Java via JNI
234 // -------------------------------------------------------------------------- 235 // --------------------------------------------------------------------------
235 236
236 void ContentViewImpl::OnTabCrashed(const base::ProcessHandle handle) { 237 void ContentViewCoreImpl::OnTabCrashed(const base::ProcessHandle handle) {
237 NOTIMPLEMENTED() << "not upstreamed yet"; 238 NOTIMPLEMENTED() << "not upstreamed yet";
238 } 239 }
239 240
240 void ContentViewImpl::SetTitle(const string16& title) { 241 void ContentViewCoreImpl::SetTitle(const string16& title) {
241 NOTIMPLEMENTED() << "not upstreamed yet"; 242 NOTIMPLEMENTED() << "not upstreamed yet";
242 } 243 }
243 244
244 bool ContentViewImpl::HasFocus() { 245 bool ContentViewCoreImpl::HasFocus() {
245 NOTIMPLEMENTED() << "not upstreamed yet"; 246 NOTIMPLEMENTED() << "not upstreamed yet";
246 return false; 247 return false;
247 } 248 }
248 249
249 void ContentViewImpl::OnSelectionChanged(const std::string& text) { 250 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) {
250 NOTIMPLEMENTED() << "not upstreamed yet"; 251 NOTIMPLEMENTED() << "not upstreamed yet";
251 } 252 }
252 253
253 void ContentViewImpl::OnSelectionBoundsChanged( 254 void ContentViewCoreImpl::OnSelectionBoundsChanged(
254 int startx, 255 int startx,
255 int starty, 256 int starty,
256 base::i18n::TextDirection start_dir, 257 base::i18n::TextDirection start_dir,
257 int endx, 258 int endx,
258 int endy, 259 int endy,
259 base::i18n::TextDirection end_dir) { 260 base::i18n::TextDirection end_dir) {
260 NOTIMPLEMENTED() << "not upstreamed yet"; 261 NOTIMPLEMENTED() << "not upstreamed yet";
261 } 262 }
262 263
263 void ContentViewImpl::OnAcceleratedCompositingStateChange( 264 void ContentViewCoreImpl::OnAcceleratedCompositingStateChange(
264 RenderWidgetHostViewAndroid* rwhva, bool activated, bool force) { 265 RenderWidgetHostViewAndroid* rwhva, bool activated, bool force) {
265 NOTIMPLEMENTED() << "not upstreamed yet"; 266 NOTIMPLEMENTED() << "not upstreamed yet";
266 } 267 }
267 268
268 void ContentViewImpl::StartContentIntent(const GURL& content_url) { 269 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) {
269 JNIEnv* env = AttachCurrentThread(); 270 JNIEnv* env = AttachCurrentThread();
270 ScopedJavaLocalRef<jstring> jcontent_url = 271 ScopedJavaLocalRef<jstring> jcontent_url =
271 ConvertUTF8ToJavaString(env, content_url.spec()); 272 ConvertUTF8ToJavaString(env, content_url.spec());
272 Java_ContentView_startContentIntent(env, 273 Java_ContentViewCore_startContentIntent(env,
273 java_object_->View(env).obj(), 274 java_object_->View(env).obj(),
274 jcontent_url.obj()); 275 jcontent_url.obj());
275 } 276 }
276 277
277 // -------------------------------------------------------------------------- 278 // --------------------------------------------------------------------------
278 // Methods called from Java via JNI 279 // Methods called from Java via JNI
279 // -------------------------------------------------------------------------- 280 // --------------------------------------------------------------------------
280 281
281 // -------------------------------------------------------------------------- 282 // --------------------------------------------------------------------------
282 // Methods called from native code 283 // Methods called from native code
283 // -------------------------------------------------------------------------- 284 // --------------------------------------------------------------------------
284 285
285 gfx::Rect ContentViewImpl::GetBounds() const { 286 gfx::Rect ContentViewCoreImpl::GetBounds() const {
286 NOTIMPLEMENTED() << "not upstreamed yet"; 287 NOTIMPLEMENTED() << "not upstreamed yet";
287 return gfx::Rect(); 288 return gfx::Rect();
288 } 289 }
289 290
290 // ---------------------------------------------------------------------------- 291 // ----------------------------------------------------------------------------
291 292
292 bool RegisterContentView(JNIEnv* env) { 293 bool RegisterContentViewCore(JNIEnv* env) {
293 if (!base::android::HasClass(env, kContentViewClassPath)) { 294 if (!base::android::HasClass(env, kContentViewCoreClassPath)) {
294 DLOG(ERROR) << "Unable to find class ContentView!"; 295 DLOG(ERROR) << "Unable to find class ContentViewCore!";
295 return false; 296 return false;
296 } 297 }
297 ScopedJavaLocalRef<jclass> clazz = GetClass(env, kContentViewClassPath); 298 ScopedJavaLocalRef<jclass> clazz = GetClass(env, kContentViewCoreClassPath);
298 if (!HasField(env, clazz, "mNativeContentView", "I")) { 299 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) {
299 DLOG(ERROR) << "Unable to find ContentView.mNativeContentView!"; 300 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!";
300 return false; 301 return false;
301 } 302 }
302 g_native_content_view = GetFieldID(env, clazz, "mNativeContentView", "I"); 303 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I");
303 304
304 return RegisterNativesImpl(env) >= 0; 305 return RegisterNativesImpl(env) >= 0;
305 } 306 }
306 307
307 } // namespace content 308 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/android/content_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698