1 // Copyright 2013 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.
5 #include "content/browser/browser_plugin/browser_plugin_geolocation_permission_context.h"
8 #include "content/browser/browser_plugin/browser_plugin_guest.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
16 BrowserPluginGeolocationPermissionContext::
17 BrowserPluginGeolocationPermissionContext() {
20 BrowserPluginGeolocationPermissionContext::
21 ~BrowserPluginGeolocationPermissionContext() {
24 void BrowserPluginGeolocationPermissionContext::RequestGeolocationPermission(
25 int render_process_id
,
28 const GURL
& requesting_frame
,
29 base::Callback
<void(bool)> callback
) {
30 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
31 BrowserThread::PostTask(
32 BrowserThread::UI
, FROM_HERE
,
34 &BrowserPluginGeolocationPermissionContext::
35 RequestGeolocationPermission
,
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
46 // Note that callback.Run(true) allows geolocation access, callback.Run(false)
47 // denies geolocation access.
48 // We need to go to the renderer to ask embedder's js if we are allowed to
49 // have geolocation access.
50 RenderViewHost
* rvh
= RenderViewHost::FromID(render_process_id
,
53 DCHECK(rvh
->GetProcess()->IsGuest());
54 WebContentsImpl
* guest_web_contents
=
55 static_cast<WebContentsImpl
*>(rvh
->GetDelegate()->GetAsWebContents());
56 BrowserPluginGuest
* guest
= guest_web_contents
->GetBrowserPluginGuest();
57 guest
->AskEmbedderForGeolocationPermission(bridge_id
,
63 void BrowserPluginGeolocationPermissionContext::
64 CancelGeolocationPermissionRequest(int render_process_id
,
67 const GURL
& requesting_frame
) {
68 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
69 BrowserThread::PostTask(
70 BrowserThread::UI
, FROM_HERE
,
72 &BrowserPluginGeolocationPermissionContext::
73 CancelGeolocationPermissionRequest
,
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
82 RenderViewHost
* rvh
= RenderViewHost::FromID(render_process_id
,
85 DCHECK(rvh
->GetProcess()->IsGuest());
86 WebContentsImpl
* guest_web_contents
=
87 static_cast<WebContentsImpl
*>(rvh
->GetDelegate()->GetAsWebContents());
88 BrowserPluginGuest
* guest
= guest_web_contents
->GetBrowserPluginGuest();
90 guest
->CancelGeolocationRequest(bridge_id
);
94 } // namespace content