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

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

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