blob: 59a23b58225043ebfbc216875ab66e0e92e156ee [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// 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_context.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
14namespace content {
15
16BrowserPluginGeolocationPermissionContext::
17 BrowserPluginGeolocationPermissionContext() {
18}
19
20BrowserPluginGeolocationPermissionContext::
21 ~BrowserPluginGeolocationPermissionContext() {
22}
23
24void BrowserPluginGeolocationPermissionContext::RequestGeolocationPermission(
25 int render_process_id,
26 int render_view_id,
27 int bridge_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,
33 base::Bind(
34 &BrowserPluginGeolocationPermissionContext::
35 RequestGeolocationPermission,
36 this,
37 render_process_id,
38 render_view_id,
39 bridge_id,
40 requesting_frame,
41 callback));
42 return;
43 }
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45
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,
51 render_view_id);
52 DCHECK(rvh);
53 if (rvh) {
54 DCHECK(rvh->GetProcess()->IsGuest());
55 WebContentsImpl* guest_web_contents =
56 static_cast<WebContentsImpl*>(rvh->GetDelegate()->GetAsWebContents());
57 BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest();
58 guest->AskEmbedderForGeolocationPermission(bridge_id,
59 requesting_frame,
60 callback);
61 }
62}
63
64void BrowserPluginGeolocationPermissionContext::
65 CancelGeolocationPermissionRequest(int render_process_id,
66 int render_view_id,
67 int bridge_id,
68 const GURL& requesting_frame) {
69 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
70 BrowserThread::PostTask(
71 BrowserThread::UI, FROM_HERE,
72 base::Bind(
73 &BrowserPluginGeolocationPermissionContext::
74 CancelGeolocationPermissionRequest,
75 this,
76 render_process_id,
77 render_view_id,
78 bridge_id,
79 requesting_frame));
80 return;
81 }
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
84 render_view_id);
85 if (rvh) {
86 DCHECK(rvh->GetProcess()->IsGuest());
87 WebContentsImpl* guest_web_contents =
88 static_cast<WebContentsImpl*>(rvh->GetDelegate()->GetAsWebContents());
89 BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest();
90 if (guest)
91 guest->CancelGeolocationRequest(bridge_id);
92 }
93}
94
95} // namespace content