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 3 // found in the LICENSE file. 4 5 #include "android_webview/native/aw_geolocation_permission_context.h" 6 7 #include "android_webview/native/aw_contents.h" 8 #include "base/bind.h" 9 #include "base/callback.h" 10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/web_contents.h" 13 14 namespace android_webview { 15 16 AwGeolocationPermissionContext::~AwGeolocationPermissionContext() { 17 } 18 19 void 20 AwGeolocationPermissionContext::RequestGeolocationPermissionOnUIThread( 21 int render_process_id, 22 int render_view_id, 23 int bridge_id, 24 const GURL& requesting_frame, 25 base::Callback<void(bool)> callback) { 26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 27 28 AwContents* aw_contents = 29 AwContents::FromID(render_process_id, render_view_id); 30 if (!aw_contents) { 31 callback.Run(false); 32 return; 33 } 34 aw_contents->ShowGeolocationPrompt(requesting_frame, callback); 35 } 36 37 void 38 AwGeolocationPermissionContext::RequestGeolocationPermission( 39 int render_process_id, 40 int render_view_id, 41 int bridge_id, 42 const GURL& requesting_frame, 43 base::Callback<void(bool)> callback) { 44 content::BrowserThread::PostTask( 45 content::BrowserThread::UI, FROM_HERE, 46 base::Bind( 47 &AwGeolocationPermissionContext:: 48 RequestGeolocationPermissionOnUIThread, 49 this, 50 render_process_id, 51 render_view_id, 52 bridge_id, 53 requesting_frame, 54 callback)); 55 } 56 57 // static 58 content::GeolocationPermissionContext* 59 AwGeolocationPermissionContext::Create(AwBrowserContext* browser_context) { 60 return new AwGeolocationPermissionContext(); 61 } 62 63 void 64 AwGeolocationPermissionContext::CancelGeolocationPermissionRequestOnUIThread( 65 int render_process_id, 66 int render_view_id, 67 int bridge_id, 68 const GURL& requesting_frame) { 69 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 70 71 AwContents* aw_contents = 72 AwContents::FromID(render_process_id, render_view_id); 73 if (aw_contents) { 74 aw_contents->HideGeolocationPrompt(requesting_frame); 75 } 76 } 77 78 void 79 AwGeolocationPermissionContext::CancelGeolocationPermissionRequest( 80 int render_process_id, 81 int render_view_id, 82 int bridge_id, 83 const GURL& requesting_frame) { 84 content::BrowserThread::PostTask( 85 content::BrowserThread::UI, FROM_HERE, 86 base::Bind( 87 &AwGeolocationPermissionContext:: 88 CancelGeolocationPermissionRequestOnUIThread, 89 this, 90 render_process_id, 91 render_view_id, 92 bridge_id, 93 requesting_frame)); 94 } 95 96 } // namespace android_webview 97