1 // Copyright 2015 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 "android_webview/browser/aw_permission_manager.h"
7 #include "android_webview/browser/aw_browser_permission_request_delegate.h"
8 #include "base/callback.h"
9 #include "content/public/browser/permission_type.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h"
14 namespace android_webview
{
18 void CallbackPermisisonStatusWrapper(
19 const base::Callback
<void(content::PermissionStatus
)>& callback
,
21 callback
.Run(allowed
? content::PERMISSION_STATUS_GRANTED
22 : content::PERMISSION_STATUS_DENIED
);
25 } // anonymous namespace
27 AwPermissionManager::AwPermissionManager()
28 : content::PermissionManager() {
31 AwPermissionManager::~AwPermissionManager() {
34 void AwPermissionManager::RequestPermission(
35 content::PermissionType permission
,
36 content::WebContents
* web_contents
,
40 const base::Callback
<void(content::PermissionStatus
)>& callback
) {
41 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
42 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
43 AwBrowserPermissionRequestDelegate
* delegate
=
44 AwBrowserPermissionRequestDelegate::FromID(render_process_id
,
47 DVLOG(0) << "Dropping permission request for "
48 << static_cast<int>(permission
);
49 callback
.Run(content::PERMISSION_STATUS_DENIED
);
54 case content::PermissionType::GEOLOCATION
:
55 delegate
->RequestGeolocationPermission(
56 origin
, base::Bind(&CallbackPermisisonStatusWrapper
, callback
));
58 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER
:
59 delegate
->RequestProtectedMediaIdentifierPermission(
60 origin
, base::Bind(&CallbackPermisisonStatusWrapper
, callback
));
62 case content::PermissionType::MIDI_SYSEX
:
63 case content::PermissionType::NOTIFICATIONS
:
64 case content::PermissionType::PUSH_MESSAGING
:
65 NOTIMPLEMENTED() << "RequestPermission is not implemented for "
66 << static_cast<int>(permission
);
67 callback
.Run(content::PERMISSION_STATUS_DENIED
);
69 case content::PermissionType::NUM
:
70 NOTREACHED() << "PermissionType::NUM was not expected here.";
71 callback
.Run(content::PERMISSION_STATUS_DENIED
);
76 void AwPermissionManager::CancelPermissionRequest(
77 content::PermissionType permission
,
78 content::WebContents
* web_contents
,
81 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
82 int render_view_id
= web_contents
->GetRenderViewHost()->GetRoutingID();
83 AwBrowserPermissionRequestDelegate
* delegate
=
84 AwBrowserPermissionRequestDelegate::FromID(render_process_id
,
90 case content::PermissionType::GEOLOCATION
:
91 delegate
->CancelGeolocationPermissionRequests(origin
);
93 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER
:
94 delegate
->CancelProtectedMediaIdentifierPermissionRequests(origin
);
96 case content::PermissionType::MIDI_SYSEX
:
97 case content::PermissionType::NOTIFICATIONS
:
98 case content::PermissionType::PUSH_MESSAGING
:
99 NOTIMPLEMENTED() << "CancelPermission not implemented for "
100 << static_cast<int>(permission
);
102 case content::PermissionType::NUM
:
103 NOTREACHED() << "PermissionType::NUM was not expected here.";
108 void AwPermissionManager::ResetPermission(
109 content::PermissionType permission
,
110 const GURL
& requesting_origin
,
111 const GURL
& embedding_origin
) {
114 content::PermissionStatus
AwPermissionManager::GetPermissionStatus(
115 content::PermissionType permission
,
116 const GURL
& requesting_origin
,
117 const GURL
& embedding_origin
) {
118 return content::PERMISSION_STATUS_DENIED
;
121 void AwPermissionManager::RegisterPermissionUsage(
122 content::PermissionType permission
,
123 const GURL
& requesting_origin
,
124 const GURL
& embedding_origin
) {
127 int AwPermissionManager::SubscribePermissionStatusChange(
128 content::PermissionType permission
,
129 const GURL
& requesting_origin
,
130 const GURL
& embedding_origin
,
131 const base::Callback
<void(content::PermissionStatus
)>& callback
) {
135 void AwPermissionManager::UnsubscribePermissionStatusChange(
136 int subscription_id
) {
139 } // namespace android_webview