Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: android_webview/browser/aw_permission_manager.cc

Issue 1011953003: Refactor Permissions related method out of ContentBrowserClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission_type_enum_class
Patch Set: fix cros Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « android_webview/browser/aw_permission_manager.h ('k') | chrome/browser/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "android_webview/browser/aw_permission_manager.h"
6
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"
13
14 namespace android_webview {
15
16 namespace {
17
18 void CallbackPermisisonStatusWrapper(
19 const base::Callback<void(content::PermissionStatus)>& callback,
20 bool allowed) {
21 callback.Run(allowed ? content::PERMISSION_STATUS_GRANTED
22 : content::PERMISSION_STATUS_DENIED);
23 }
24
25 } // anonymous namespace
26
27 AwPermissionManager::AwPermissionManager()
28 : content::PermissionManager() {
29 }
30
31 AwPermissionManager::~AwPermissionManager() {
32 }
33
34 void AwPermissionManager::RequestPermission(
35 content::PermissionType permission,
36 content::WebContents* web_contents,
37 int request_id,
38 const GURL& origin,
39 bool user_gesture,
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,
45 render_view_id);
46 if (!delegate) {
47 DVLOG(0) << "Dropping permission request for "
48 << static_cast<int>(permission);
49 callback.Run(content::PERMISSION_STATUS_DENIED);
50 return;
51 }
52
53 switch (permission) {
54 case content::PermissionType::GEOLOCATION:
55 delegate->RequestGeolocationPermission(
56 origin, base::Bind(&CallbackPermisisonStatusWrapper, callback));
57 break;
58 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
59 delegate->RequestProtectedMediaIdentifierPermission(
60 origin, base::Bind(&CallbackPermisisonStatusWrapper, callback));
61 break;
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);
68 break;
69 case content::PermissionType::NUM:
70 NOTREACHED() << "PermissionType::NUM was not expected here.";
71 callback.Run(content::PERMISSION_STATUS_DENIED);
72 break;
73 }
74 }
75
76 void AwPermissionManager::CancelPermissionRequest(
77 content::PermissionType permission,
78 content::WebContents* web_contents,
79 int request_id,
80 const GURL& origin) {
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,
85 render_view_id);
86 if (!delegate)
87 return;
88
89 switch (permission) {
90 case content::PermissionType::GEOLOCATION:
91 delegate->CancelGeolocationPermissionRequests(origin);
92 break;
93 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
94 delegate->CancelProtectedMediaIdentifierPermissionRequests(origin);
95 break;
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);
101 break;
102 case content::PermissionType::NUM:
103 NOTREACHED() << "PermissionType::NUM was not expected here.";
104 break;
105 }
106 }
107
108 void AwPermissionManager::ResetPermission(
109 content::PermissionType permission,
110 const GURL& requesting_origin,
111 const GURL& embedding_origin) {
112 }
113
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;
119 }
120
121 void AwPermissionManager::RegisterPermissionUsage(
122 content::PermissionType permission,
123 const GURL& requesting_origin,
124 const GURL& embedding_origin) {
125 }
126
127 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/aw_permission_manager.h ('k') | chrome/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698