OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/browser/browser_plugin/browser_plugin_geolocation_permission_c
ontext.h" | |
6 | |
7 #include "base/bind.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" | |
13 | |
14 namespace content { | |
15 | |
16 BrowserPluginGeolocationPermissionContext:: | |
17 BrowserPluginGeolocationPermissionContext() { | |
18 } | |
19 | |
20 BrowserPluginGeolocationPermissionContext:: | |
21 ~BrowserPluginGeolocationPermissionContext() { | |
22 } | |
23 | |
24 void BrowserPluginGeolocationPermissionContext::RequestGeolocationPermission( | |
25 int render_process_id, | |
26 int render_view_id, | |
27 int bridge_id, | |
28 const GURL& requesting_frame, | |
29 bool user_gesture, | |
30 base::Callback<void(bool)> callback) { | |
31 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
32 BrowserThread::PostTask( | |
33 BrowserThread::UI, FROM_HERE, | |
34 base::Bind( | |
35 &BrowserPluginGeolocationPermissionContext:: | |
36 RequestGeolocationPermission, | |
37 this, | |
38 render_process_id, | |
39 render_view_id, | |
40 bridge_id, | |
41 requesting_frame, | |
42 user_gesture, | |
43 callback)); | |
44 return; | |
45 } | |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
47 | |
48 // Note that callback.Run(true) allows geolocation access, callback.Run(false) | |
49 // denies geolocation access. | |
50 // We need to go to the renderer to ask embedder's js if we are allowed to | |
51 // have geolocation access. | |
52 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, | |
53 render_view_id); | |
54 if (rvh) { | |
55 DCHECK(rvh->GetProcess()->IsGuest()); | |
56 WebContentsImpl* guest_web_contents = | |
57 static_cast<WebContentsImpl*>(rvh->GetDelegate()->GetAsWebContents()); | |
58 BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest(); | |
59 guest->AskEmbedderForGeolocationPermission(bridge_id, | |
60 requesting_frame, | |
61 user_gesture, | |
62 callback); | |
63 } | |
64 } | |
65 | |
66 void BrowserPluginGeolocationPermissionContext:: | |
67 CancelGeolocationPermissionRequest(int render_process_id, | |
68 int render_view_id, | |
69 int bridge_id, | |
70 const GURL& requesting_frame) { | |
71 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
72 BrowserThread::PostTask( | |
73 BrowserThread::UI, FROM_HERE, | |
74 base::Bind( | |
75 &BrowserPluginGeolocationPermissionContext:: | |
76 CancelGeolocationPermissionRequest, | |
77 this, | |
78 render_process_id, | |
79 render_view_id, | |
80 bridge_id, | |
81 requesting_frame)); | |
82 return; | |
83 } | |
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
85 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, | |
86 render_view_id); | |
87 if (rvh) { | |
88 DCHECK(rvh->GetProcess()->IsGuest()); | |
89 WebContentsImpl* guest_web_contents = | |
90 static_cast<WebContentsImpl*>(rvh->GetDelegate()->GetAsWebContents()); | |
91 BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest(); | |
92 if (guest) | |
93 guest->CancelGeolocationRequest(bridge_id); | |
94 } | |
95 } | |
96 | |
97 } // namespace content | |
OLD | NEW |