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

Side by Side Diff: android_webview/native/aw_contents.cc

Issue 24228003: Upstream ShouldOverrideUrlLoading changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed a non-related line to keep chrome bots happy Created 7 years 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 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 "android_webview/native/aw_contents.h" 5 #include "android_webview/native/aw_contents.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "android_webview/browser/aw_browser_context.h" 9 #include "android_webview/browser/aw_browser_context.h"
10 #include "android_webview/browser/aw_browser_main_parts.h" 10 #include "android_webview/browser/aw_browser_main_parts.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 browser_view_renderer_( 182 browser_view_renderer_(
183 new InProcessViewRenderer(this, java_renderer_helper(), 183 new InProcessViewRenderer(this, java_renderer_helper(),
184 web_contents_.get())) { 184 web_contents_.get())) {
185 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1); 185 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1);
186 icon_helper_.reset(new IconHelper(web_contents_.get())); 186 icon_helper_.reset(new IconHelper(web_contents_.get()));
187 icon_helper_->SetListener(this); 187 icon_helper_->SetListener(this);
188 web_contents_->SetUserData(kAwContentsUserDataKey, 188 web_contents_->SetUserData(kAwContentsUserDataKey,
189 new AwContentsUserData(this)); 189 new AwContentsUserData(this));
190 render_view_host_ext_.reset( 190 render_view_host_ext_.reset(
191 new AwRenderViewHostExt(this, web_contents_.get())); 191 new AwRenderViewHostExt(this, web_contents_.get()));
192 AwContentsIoThreadClientImpl::RegisterPendingContents(web_contents_.get());
193 192
194 AwAutofillManagerDelegate* autofill_manager_delegate = 193 AwAutofillManagerDelegate* autofill_manager_delegate =
195 AwAutofillManagerDelegate::FromWebContents(web_contents_.get()); 194 AwAutofillManagerDelegate::FromWebContents(web_contents_.get());
196 if (autofill_manager_delegate) 195 if (autofill_manager_delegate)
197 InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData()); 196 InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData());
198 197
199 SetAndroidWebViewRendererPrefs(); 198 SetAndroidWebViewRendererPrefs();
200 } 199 }
201 200
202 void AwContents::SetJavaPeers(JNIEnv* env, 201 void AwContents::SetJavaPeers(JNIEnv* env,
(...skipping 12 matching lines...) Expand all
215 new AwWebContentsDelegate(env, web_contents_delegate)); 214 new AwWebContentsDelegate(env, web_contents_delegate));
216 web_contents_->SetDelegate(web_contents_delegate_.get()); 215 web_contents_->SetDelegate(web_contents_delegate_.get());
217 216
218 contents_client_bridge_.reset( 217 contents_client_bridge_.reset(
219 new AwContentsClientBridge(env, contents_client_bridge)); 218 new AwContentsClientBridge(env, contents_client_bridge));
220 AwContentsClientBridgeBase::Associate(web_contents_.get(), 219 AwContentsClientBridgeBase::Associate(web_contents_.get(),
221 contents_client_bridge_.get()); 220 contents_client_bridge_.get());
222 221
223 AwContentsIoThreadClientImpl::Associate( 222 AwContentsIoThreadClientImpl::Associate(
224 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, io_thread_client)); 223 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, io_thread_client));
225 int child_id = web_contents_->GetRenderProcessHost()->GetID();
226 int route_id = web_contents_->GetRoutingID();
227 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id);
228 224
229 InterceptNavigationDelegate::Associate( 225 InterceptNavigationDelegate::Associate(
230 web_contents_.get(), 226 web_contents_.get(),
231 make_scoped_ptr(new InterceptNavigationDelegate( 227 make_scoped_ptr(new InterceptNavigationDelegate(
232 env, intercept_navigation_delegate))); 228 env, intercept_navigation_delegate)));
229
230 // Finally, having setup the associations, release any deferred requests
231 int child_id = web_contents_->GetRenderProcessHost()->GetID();
232 int route_id = web_contents_->GetRoutingID();
233 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id);
233 } 234 }
234 235
235 void AwContents::SetSaveFormData(bool enabled) { 236 void AwContents::SetSaveFormData(bool enabled) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
237 InitAutofillIfNecessary(enabled); 238 InitAutofillIfNecessary(enabled);
238 // We need to check for the existence, since autofill_manager_delegate 239 // We need to check for the existence, since autofill_manager_delegate
239 // may not be created when the setting is false. 240 // may not be created when the setting is false.
240 if (AutofillDriverImpl::FromWebContents(web_contents_.get())) { 241 if (AutofillDriverImpl::FromWebContents(web_contents_.get())) {
241 AwAutofillManagerDelegate::FromWebContents(web_contents_.get())-> 242 AwAutofillManagerDelegate::FromWebContents(web_contents_.get())->
242 SetSaveFormData(enabled); 243 SetSaveFormData(enabled);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 294 }
294 295
295 AwContents::~AwContents() { 296 AwContents::~AwContents() {
296 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); 297 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this);
297 web_contents_->RemoveUserData(kAwContentsUserDataKey); 298 web_contents_->RemoveUserData(kAwContentsUserDataKey);
298 if (find_helper_.get()) 299 if (find_helper_.get())
299 find_helper_->SetListener(NULL); 300 find_helper_->SetListener(NULL);
300 if (icon_helper_.get()) 301 if (icon_helper_.get())
301 icon_helper_->SetListener(NULL); 302 icon_helper_->SetListener(NULL);
302 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); 303 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1);
304 // When the last WebView is destroyed free all discardable memory allocated by
305 // Chromium, because the app process may continue to run for a long time
306 // without ever using another WebView.
307 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
308 base::MemoryPressureListener::NotifyMemoryPressure(
309 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
310 }
303 } 311 }
304 312
305 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { 313 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
307 DCHECK(web_contents_); 315 DCHECK(web_contents_);
308 return reinterpret_cast<jint>(web_contents_.get()); 316 return reinterpret_cast<jint>(web_contents_.get());
309 } 317 }
310 318
311 void AwContents::Destroy(JNIEnv* env, jobject obj) { 319 void AwContents::Destroy(JNIEnv* env, jobject obj) {
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 320 java_ref_.reset();
313 delete this; 321 // We do not delete AwContents immediately. Some applications try to delete
314 322 // Webview in ShouldOverrideUrlLoading callback, which is a sync IPC from
315 // When the last WebView is destroyed free all discardable memory allocated by 323 // Webkit.
316 // Chromium, because the app process may continue to run for a long time 324 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
317 // without ever using another WebView.
318 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
319 base::MemoryPressureListener::NotifyMemoryPressure(
320 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
321 }
322 } 325 }
323 326
324 static jlong Init(JNIEnv* env, jclass, jobject browser_context) { 327 static jlong Init(JNIEnv* env, jclass, jobject browser_context) {
325 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather 328 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather
326 // than hard-code the default instance lookup here. 329 // than hard-code the default instance lookup here.
327 scoped_ptr<WebContents> web_contents(content::WebContents::Create( 330 scoped_ptr<WebContents> web_contents(content::WebContents::Create(
328 content::WebContents::CreateParams(AwBrowserContext::GetDefault()))); 331 content::WebContents::CreateParams(AwBrowserContext::GetDefault())));
329 // Return an 'uninitialized' instance; most work is deferred until the 332 // Return an 'uninitialized' instance; most work is deferred until the
330 // subsequent SetJavaPeers() call. 333 // subsequent SetJavaPeers() call.
331 return reinterpret_cast<intptr_t>(new AwContents(web_contents.Pass())); 334 return reinterpret_cast<intptr_t>(new AwContents(web_contents.Pass()));
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 void AwContents::TrimMemory(JNIEnv* env, jobject obj, jint level) { 984 void AwContents::TrimMemory(JNIEnv* env, jobject obj, jint level) {
982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 985 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
983 browser_view_renderer_->TrimMemory(level); 986 browser_view_renderer_->TrimMemory(level);
984 } 987 }
985 988
986 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { 989 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) {
987 g_should_download_favicons = true; 990 g_should_download_favicons = true;
988 } 991 }
989 992
990 } // namespace android_webview 993 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698