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

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

Issue 1852513003: Convert //android_webview to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git is hard Created 4 years, 8 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 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 #include <utility> 8 #include <utility>
9 9
10 #include "android_webview/browser/aw_browser_context.h" 10 #include "android_webview/browser/aw_browser_context.h"
(...skipping 27 matching lines...) Expand all
38 #include "base/android/jni_android.h" 38 #include "base/android/jni_android.h"
39 #include "base/android/jni_array.h" 39 #include "base/android/jni_array.h"
40 #include "base/android/jni_string.h" 40 #include "base/android/jni_string.h"
41 #include "base/android/locale_utils.h" 41 #include "base/android/locale_utils.h"
42 #include "base/android/scoped_java_ref.h" 42 #include "base/android/scoped_java_ref.h"
43 #include "base/atomicops.h" 43 #include "base/atomicops.h"
44 #include "base/bind.h" 44 #include "base/bind.h"
45 #include "base/callback.h" 45 #include "base/callback.h"
46 #include "base/command_line.h" 46 #include "base/command_line.h"
47 #include "base/memory/memory_pressure_listener.h" 47 #include "base/memory/memory_pressure_listener.h"
48 #include "base/memory/ptr_util.h"
48 #include "base/message_loop/message_loop.h" 49 #include "base/message_loop/message_loop.h"
49 #include "base/pickle.h" 50 #include "base/pickle.h"
50 #include "base/strings/string16.h" 51 #include "base/strings/string16.h"
51 #include "base/supports_user_data.h" 52 #include "base/supports_user_data.h"
52 #include "components/autofill/content/browser/content_autofill_driver_factory.h" 53 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
53 #include "components/autofill/core/browser/autofill_manager.h" 54 #include "components/autofill/core/browser/autofill_manager.h"
54 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 55 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
55 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 56 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
56 #include "components/navigation_interception/intercept_navigation_delegate.h" 57 #include "components/navigation_interception/intercept_navigation_delegate.h"
57 #include "content/public/browser/android/content_view_core.h" 58 #include "content/public/browser/android/content_view_core.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // static 173 // static
173 AwBrowserPermissionRequestDelegate* AwBrowserPermissionRequestDelegate::FromID( 174 AwBrowserPermissionRequestDelegate* AwBrowserPermissionRequestDelegate::FromID(
174 int render_process_id, int render_frame_id) { 175 int render_process_id, int render_frame_id) {
175 AwContents* aw_contents = AwContents::FromWebContents( 176 AwContents* aw_contents = AwContents::FromWebContents(
176 content::WebContents::FromRenderFrameHost( 177 content::WebContents::FromRenderFrameHost(
177 content::RenderFrameHost::FromID(render_process_id, 178 content::RenderFrameHost::FromID(render_process_id,
178 render_frame_id))); 179 render_frame_id)));
179 return aw_contents; 180 return aw_contents;
180 } 181 }
181 182
182 AwContents::AwContents(scoped_ptr<WebContents> web_contents) 183 AwContents::AwContents(std::unique_ptr<WebContents> web_contents)
183 : shared_renderer_state_( 184 : shared_renderer_state_(
184 this, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), 185 this,
186 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
185 browser_view_renderer_( 187 browser_view_renderer_(
186 this, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 188 this,
189 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
187 base::CommandLine::ForCurrentProcess()->HasSwitch( 190 base::CommandLine::ForCurrentProcess()->HasSwitch(
188 switches::kDisablePageVisibility)), 191 switches::kDisablePageVisibility)),
189 web_contents_(std::move(web_contents)), 192 web_contents_(std::move(web_contents)),
190 renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()) { 193 renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()) {
191 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1); 194 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1);
192 browser_view_renderer_.SetSharedRendererState(&shared_renderer_state_); 195 browser_view_renderer_.SetSharedRendererState(&shared_renderer_state_);
193 icon_helper_.reset(new IconHelper(web_contents_.get())); 196 icon_helper_.reset(new IconHelper(web_contents_.get()));
194 icon_helper_->SetListener(this); 197 icon_helper_->SetListener(this);
195 web_contents_->SetUserData(android_webview::kAwContentsUserDataKey, 198 web_contents_->SetUserData(android_webview::kAwContentsUserDataKey,
196 new AwContentsUserData(this)); 199 new AwContentsUserData(this));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 232
230 contents_client_bridge_.reset( 233 contents_client_bridge_.reset(
231 new AwContentsClientBridge(env, contents_client_bridge)); 234 new AwContentsClientBridge(env, contents_client_bridge));
232 AwContentsClientBridgeBase::Associate(web_contents_.get(), 235 AwContentsClientBridgeBase::Associate(web_contents_.get(),
233 contents_client_bridge_.get()); 236 contents_client_bridge_.get());
234 237
235 AwContentsIoThreadClientImpl::Associate(web_contents_.get(), 238 AwContentsIoThreadClientImpl::Associate(web_contents_.get(),
236 io_thread_client); 239 io_thread_client);
237 240
238 InterceptNavigationDelegate::Associate( 241 InterceptNavigationDelegate::Associate(
239 web_contents_.get(), 242 web_contents_.get(), base::WrapUnique(new InterceptNavigationDelegate(
240 make_scoped_ptr(new InterceptNavigationDelegate( 243 env, intercept_navigation_delegate)));
241 env, intercept_navigation_delegate)));
242 244
243 // Finally, having setup the associations, release any deferred requests 245 // Finally, having setup the associations, release any deferred requests
244 for (content::RenderFrameHost* rfh : web_contents_->GetAllFrames()) { 246 for (content::RenderFrameHost* rfh : web_contents_->GetAllFrames()) {
245 int render_process_id = rfh->GetProcess()->GetID(); 247 int render_process_id = rfh->GetProcess()->GetID();
246 int render_frame_id = rfh->GetRoutingID(); 248 int render_frame_id = rfh->GetRoutingID();
247 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(render_process_id, 249 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(render_process_id,
248 render_frame_id); 250 render_frame_id);
249 } 251 }
250 } 252 }
251 253
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 void AwContents::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 322 void AwContents::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
321 java_ref_.reset(); 323 java_ref_.reset();
322 delete this; 324 delete this;
323 } 325 }
324 326
325 static jlong Init(JNIEnv* env, 327 static jlong Init(JNIEnv* env,
326 const JavaParamRef<jclass>&, 328 const JavaParamRef<jclass>&,
327 const JavaParamRef<jobject>& browser_context) { 329 const JavaParamRef<jobject>& browser_context) {
328 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather 330 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather
329 // than hard-code the default instance lookup here. 331 // than hard-code the default instance lookup here.
330 scoped_ptr<WebContents> web_contents(content::WebContents::Create( 332 std::unique_ptr<WebContents> web_contents(content::WebContents::Create(
331 content::WebContents::CreateParams(AwBrowserContext::GetDefault()))); 333 content::WebContents::CreateParams(AwBrowserContext::GetDefault())));
332 // Return an 'uninitialized' instance; most work is deferred until the 334 // Return an 'uninitialized' instance; most work is deferred until the
333 // subsequent SetJavaPeers() call. 335 // subsequent SetJavaPeers() call.
334 return reinterpret_cast<intptr_t>(new AwContents(std::move(web_contents))); 336 return reinterpret_cast<intptr_t>(new AwContents(std::move(web_contents)));
335 } 337 }
336 338
337 static void SetForceAuxiliaryBitmapRendering( 339 static void SetForceAuxiliaryBitmapRendering(
338 JNIEnv* env, 340 JNIEnv* env,
339 const JavaParamRef<jclass>&, 341 const JavaParamRef<jclass>&,
340 jboolean force_auxiliary_bitmap_rendering) { 342 jboolean force_auxiliary_bitmap_rendering) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 const JavaParamRef<jstring>& origin, 599 const JavaParamRef<jstring>& origin,
598 jlong resources) { 600 jlong resources) {
599 permission_request_handler_->PreauthorizePermission( 601 permission_request_handler_->PreauthorizePermission(
600 GURL(base::android::ConvertJavaStringToUTF8(env, origin)), resources); 602 GURL(base::android::ConvertJavaStringToUTF8(env, origin)), resources);
601 } 603 }
602 604
603 void AwContents::RequestProtectedMediaIdentifierPermission( 605 void AwContents::RequestProtectedMediaIdentifierPermission(
604 const GURL& origin, 606 const GURL& origin,
605 const base::Callback<void(bool)>& callback) { 607 const base::Callback<void(bool)>& callback) {
606 permission_request_handler_->SendRequest( 608 permission_request_handler_->SendRequest(
607 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( 609 std::unique_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
608 origin, AwPermissionRequest::ProtectedMediaId, callback))); 610 origin, AwPermissionRequest::ProtectedMediaId, callback)));
609 } 611 }
610 612
611 void AwContents::CancelProtectedMediaIdentifierPermissionRequests( 613 void AwContents::CancelProtectedMediaIdentifierPermissionRequests(
612 const GURL& origin) { 614 const GURL& origin) {
613 permission_request_handler_->CancelRequest( 615 permission_request_handler_->CancelRequest(
614 origin, AwPermissionRequest::ProtectedMediaId); 616 origin, AwPermissionRequest::ProtectedMediaId);
615 } 617 }
616 618
617 void AwContents::RequestGeolocationPermission( 619 void AwContents::RequestGeolocationPermission(
618 const GURL& origin, 620 const GURL& origin,
619 const base::Callback<void(bool)>& callback) { 621 const base::Callback<void(bool)>& callback) {
620 JNIEnv* env = AttachCurrentThread(); 622 JNIEnv* env = AttachCurrentThread();
621 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 623 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
622 if (obj.is_null()) 624 if (obj.is_null())
623 return; 625 return;
624 626
625 if (Java_AwContents_useLegacyGeolocationPermissionAPI(env, obj.obj())) { 627 if (Java_AwContents_useLegacyGeolocationPermissionAPI(env, obj.obj())) {
626 ShowGeolocationPrompt(origin, callback); 628 ShowGeolocationPrompt(origin, callback);
627 return; 629 return;
628 } 630 }
629 permission_request_handler_->SendRequest( 631 permission_request_handler_->SendRequest(
630 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( 632 std::unique_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
631 origin, AwPermissionRequest::Geolocation, callback))); 633 origin, AwPermissionRequest::Geolocation, callback)));
632 } 634 }
633 635
634 void AwContents::CancelGeolocationPermissionRequests(const GURL& origin) { 636 void AwContents::CancelGeolocationPermissionRequests(const GURL& origin) {
635 JNIEnv* env = AttachCurrentThread(); 637 JNIEnv* env = AttachCurrentThread();
636 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 638 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
637 if (obj.is_null()) 639 if (obj.is_null())
638 return; 640 return;
639 641
640 if (Java_AwContents_useLegacyGeolocationPermissionAPI(env, obj.obj())) { 642 if (Java_AwContents_useLegacyGeolocationPermissionAPI(env, obj.obj())) {
641 HideGeolocationPrompt(origin); 643 HideGeolocationPrompt(origin);
642 return; 644 return;
643 } 645 }
644 permission_request_handler_->CancelRequest( 646 permission_request_handler_->CancelRequest(
645 origin, AwPermissionRequest::Geolocation); 647 origin, AwPermissionRequest::Geolocation);
646 } 648 }
647 649
648 void AwContents::RequestMIDISysexPermission( 650 void AwContents::RequestMIDISysexPermission(
649 const GURL& origin, 651 const GURL& origin,
650 const base::Callback<void(bool)>& callback) { 652 const base::Callback<void(bool)>& callback) {
651 permission_request_handler_->SendRequest( 653 permission_request_handler_->SendRequest(
652 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( 654 std::unique_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
653 origin, AwPermissionRequest::MIDISysex, callback))); 655 origin, AwPermissionRequest::MIDISysex, callback)));
654 } 656 }
655 657
656 void AwContents::CancelMIDISysexPermissionRequests(const GURL& origin) { 658 void AwContents::CancelMIDISysexPermissionRequests(const GURL& origin) {
657 permission_request_handler_->CancelRequest( 659 permission_request_handler_->CancelRequest(
658 origin, AwPermissionRequest::AwPermissionRequest::MIDISysex); 660 origin, AwPermissionRequest::AwPermissionRequest::MIDISysex);
659 } 661 }
660 662
661 void AwContents::FindAllAsync(JNIEnv* env, 663 void AwContents::FindAllAsync(JNIEnv* env,
662 const JavaParamRef<jobject>& obj, 664 const JavaParamRef<jobject>& obj,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_EmptySize", 970 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_EmptySize",
969 TRACE_EVENT_SCOPE_THREAD); 971 TRACE_EVENT_SCOPE_THREAD);
970 return false; 972 return false;
971 } 973 }
972 974
973 // TODO(hush): Right now webview size is passed in as the auxiliary bitmap 975 // TODO(hush): Right now webview size is passed in as the auxiliary bitmap
974 // size, which might hurt performace (only for software draws with auxiliary 976 // size, which might hurt performace (only for software draws with auxiliary
975 // bitmap). For better performance, get global visible rect, transform it 977 // bitmap). For better performance, get global visible rect, transform it
976 // from screen space to view space, then intersect with the webview in 978 // from screen space to view space, then intersect with the webview in
977 // viewspace. Use the resulting rect as the auxiliary bitmap. 979 // viewspace. Use the resulting rect as the auxiliary bitmap.
978 scoped_ptr<SoftwareCanvasHolder> canvas_holder = SoftwareCanvasHolder::Create( 980 std::unique_ptr<SoftwareCanvasHolder> canvas_holder =
979 canvas, scroll, view_size, g_force_auxiliary_bitmap_rendering); 981 SoftwareCanvasHolder::Create(canvas, scroll, view_size,
982 g_force_auxiliary_bitmap_rendering);
980 if (!canvas_holder || !canvas_holder->GetCanvas()) { 983 if (!canvas_holder || !canvas_holder->GetCanvas()) {
981 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_NoSoftwareCanvas", 984 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_NoSoftwareCanvas",
982 TRACE_EVENT_SCOPE_THREAD); 985 TRACE_EVENT_SCOPE_THREAD);
983 return false; 986 return false;
984 } 987 }
985 return browser_view_renderer_.OnDrawSoftware(canvas_holder->GetCanvas()); 988 return browser_view_renderer_.OnDrawSoftware(canvas_holder->GetCanvas());
986 } 989 }
987 990
988 void AwContents::SetPendingWebContentsForPopup( 991 void AwContents::SetPendingWebContentsForPopup(
989 scoped_ptr<content::WebContents> pending) { 992 std::unique_ptr<content::WebContents> pending) {
990 DCHECK_CURRENTLY_ON(BrowserThread::UI); 993 DCHECK_CURRENTLY_ON(BrowserThread::UI);
991 if (pending_contents_.get()) { 994 if (pending_contents_.get()) {
992 // TODO(benm): Support holding multiple pop up window requests. 995 // TODO(benm): Support holding multiple pop up window requests.
993 LOG(WARNING) << "Blocking popup window creation as an outstanding " 996 LOG(WARNING) << "Blocking popup window creation as an outstanding "
994 << "popup window is still pending."; 997 << "popup window is still pending.";
995 base::MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); 998 base::MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release());
996 return; 999 return;
997 } 1000 }
998 pending_contents_.reset(new AwContents(std::move(pending))); 1001 pending_contents_.reset(new AwContents(std::move(pending)));
999 // Set dip_scale for pending contents, which is necessary for the later 1002 // Set dip_scale for pending contents, which is necessary for the later
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 const JavaParamRef<jobject>& obj) { 1305 const JavaParamRef<jobject>& obj) {
1303 web_contents_->ResumeLoadingCreatedWebContents(); 1306 web_contents_->ResumeLoadingCreatedWebContents();
1304 } 1307 }
1305 1308
1306 void SetShouldDownloadFavicons(JNIEnv* env, 1309 void SetShouldDownloadFavicons(JNIEnv* env,
1307 const JavaParamRef<jclass>& jclazz) { 1310 const JavaParamRef<jclass>& jclazz) {
1308 g_should_download_favicons = true; 1311 g_should_download_favicons = true;
1309 } 1312 }
1310 1313
1311 } // namespace android_webview 1314 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | android_webview/native/aw_contents_client_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698