OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/permissions/permission_dispatcher.h" | 5 #include "content/child/permissions/permission_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "content/public/child/worker_thread.h" | 11 #include "content/public/child/worker_thread.h" |
12 #include "content/public/common/service_registry.h" | 12 #include "content/public/common/service_registry.h" |
13 #include "third_party/WebKit/public/platform/WebURL.h" | 13 #include "third_party/WebKit/public/platform/WebURL.h" |
14 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" | 14 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" |
15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
16 | 16 |
17 using blink::WebPermissionObserver; | 17 using blink::WebPermissionObserver; |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 PermissionName GetPermissionName(blink::WebPermissionType type) { | 23 PermissionName GetPermissionName(blink::WebPermissionType type) { |
24 switch (type) { | 24 switch (type) { |
25 case blink::WebPermissionTypeGeolocation: | 25 case blink::WebPermissionTypeGeolocation: |
26 return PERMISSION_NAME_GEOLOCATION; | 26 return PermissionName::GEOLOCATION; |
27 case blink::WebPermissionTypeNotifications: | 27 case blink::WebPermissionTypeNotifications: |
28 return PERMISSION_NAME_NOTIFICATIONS; | 28 return PermissionName::NOTIFICATIONS; |
29 case blink::WebPermissionTypePushNotifications: | 29 case blink::WebPermissionTypePushNotifications: |
30 return PERMISSION_NAME_PUSH_NOTIFICATIONS; | 30 return PermissionName::PUSH_NOTIFICATIONS; |
31 case blink::WebPermissionTypeMidiSysEx: | 31 case blink::WebPermissionTypeMidiSysEx: |
32 return PERMISSION_NAME_MIDI_SYSEX; | 32 return PermissionName::MIDI_SYSEX; |
33 case blink::WebPermissionTypeDurableStorage: | 33 case blink::WebPermissionTypeDurableStorage: |
34 return PERMISSION_NAME_DURABLE_STORAGE; | 34 return PermissionName::DURABLE_STORAGE; |
35 case blink::WebPermissionTypeMidi: | 35 case blink::WebPermissionTypeMidi: |
36 return PERMISSION_NAME_MIDI; | 36 return PermissionName::MIDI; |
37 default: | 37 default: |
38 // The default statement is only there to prevent compilation failures if | 38 // The default statement is only there to prevent compilation failures if |
39 // WebPermissionType enum gets extended. | 39 // WebPermissionType enum gets extended. |
40 NOTREACHED(); | 40 NOTREACHED(); |
41 return PERMISSION_NAME_GEOLOCATION; | 41 return PermissionName::GEOLOCATION; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 PermissionStatus GetPermissionStatus(blink::WebPermissionStatus status) { | 45 PermissionStatus GetPermissionStatus(blink::WebPermissionStatus status) { |
46 switch (status) { | 46 switch (status) { |
47 case blink::WebPermissionStatusGranted: | 47 case blink::WebPermissionStatusGranted: |
48 return PERMISSION_STATUS_GRANTED; | 48 return PermissionStatus::GRANTED; |
49 case blink::WebPermissionStatusDenied: | 49 case blink::WebPermissionStatusDenied: |
50 return PERMISSION_STATUS_DENIED; | 50 return PermissionStatus::DENIED; |
51 case blink::WebPermissionStatusPrompt: | 51 case blink::WebPermissionStatusPrompt: |
52 return PERMISSION_STATUS_ASK; | 52 return PermissionStatus::ASK; |
53 } | 53 } |
54 | 54 |
55 NOTREACHED(); | 55 NOTREACHED(); |
56 return PERMISSION_STATUS_DENIED; | 56 return PermissionStatus::DENIED; |
57 } | 57 } |
58 | 58 |
59 blink::WebPermissionStatus GetWebPermissionStatus(PermissionStatus status) { | 59 blink::WebPermissionStatus GetWebPermissionStatus(PermissionStatus status) { |
60 switch (status) { | 60 switch (status) { |
61 case PERMISSION_STATUS_GRANTED: | 61 case PermissionStatus::GRANTED: |
62 return blink::WebPermissionStatusGranted; | 62 return blink::WebPermissionStatusGranted; |
63 case PERMISSION_STATUS_DENIED: | 63 case PermissionStatus::DENIED: |
64 return blink::WebPermissionStatusDenied; | 64 return blink::WebPermissionStatusDenied; |
65 case PERMISSION_STATUS_ASK: | 65 case PermissionStatus::ASK: |
66 return blink::WebPermissionStatusPrompt; | 66 return blink::WebPermissionStatusPrompt; |
67 } | 67 } |
68 | 68 |
69 NOTREACHED(); | 69 NOTREACHED(); |
70 return blink::WebPermissionStatusDenied; | 70 return blink::WebPermissionStatusDenied; |
71 } | 71 } |
72 | 72 |
73 const int kNoWorkerThread = 0; | 73 const int kNoWorkerThread = 0; |
74 | 74 |
75 } // anonymous namespace | 75 } // anonymous namespace |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 void PermissionDispatcher::startListening( | 124 void PermissionDispatcher::startListening( |
125 blink::WebPermissionType type, | 125 blink::WebPermissionType type, |
126 const blink::WebURL& origin, | 126 const blink::WebURL& origin, |
127 WebPermissionObserver* observer) { | 127 WebPermissionObserver* observer) { |
128 if (!IsObservable(type)) | 128 if (!IsObservable(type)) |
129 return; | 129 return; |
130 | 130 |
131 RegisterObserver(observer); | 131 RegisterObserver(observer); |
132 | 132 |
133 GetNextPermissionChange(type, | 133 GetNextPermissionChange(type, origin.string().utf8(), observer, |
134 origin.string().utf8(), | |
135 observer, | |
136 // We initialize with an arbitrary value because the | 134 // We initialize with an arbitrary value because the |
137 // mojo service wants a value. Worst case, the | 135 // mojo service wants a value. Worst case, the |
138 // observer will get notified about a non-change which | 136 // observer will get notified about a non-change which |
139 // should be a no-op. After the first notification, | 137 // should be a no-op. After the first notification, |
140 // GetNextPermissionChange will be called with the | 138 // GetNextPermissionChange will be called with the |
141 // latest known value. | 139 // latest known value. |
142 PERMISSION_STATUS_ASK); | 140 PermissionStatus::ASK); |
143 } | 141 } |
144 | 142 |
145 void PermissionDispatcher::stopListening(WebPermissionObserver* observer) { | 143 void PermissionDispatcher::stopListening(WebPermissionObserver* observer) { |
146 UnregisterObserver(observer); | 144 UnregisterObserver(observer); |
147 } | 145 } |
148 | 146 |
149 void PermissionDispatcher::QueryPermissionForWorker( | 147 void PermissionDispatcher::QueryPermissionForWorker( |
150 blink::WebPermissionType type, | 148 blink::WebPermissionType type, |
151 const std::string& origin, | 149 const std::string& origin, |
152 blink::WebPermissionCallback* callback, | 150 blink::WebPermissionCallback* callback, |
(...skipping 24 matching lines...) Expand all Loading... |
177 int worker_thread_id) { | 175 int worker_thread_id) { |
178 RevokePermissionInternal(type, origin, callback, worker_thread_id); | 176 RevokePermissionInternal(type, origin, callback, worker_thread_id); |
179 } | 177 } |
180 | 178 |
181 void PermissionDispatcher::StartListeningForWorker( | 179 void PermissionDispatcher::StartListeningForWorker( |
182 blink::WebPermissionType type, | 180 blink::WebPermissionType type, |
183 const std::string& origin, | 181 const std::string& origin, |
184 int worker_thread_id, | 182 int worker_thread_id, |
185 const base::Callback<void(blink::WebPermissionStatus)>& callback) { | 183 const base::Callback<void(blink::WebPermissionStatus)>& callback) { |
186 GetPermissionServicePtr()->GetNextPermissionChange( | 184 GetPermissionServicePtr()->GetNextPermissionChange( |
187 GetPermissionName(type), | 185 GetPermissionName(type), origin, |
188 origin, | |
189 // We initialize with an arbitrary value because the mojo service wants a | 186 // We initialize with an arbitrary value because the mojo service wants a |
190 // value. Worst case, the observer will get notified about a non-change | 187 // value. Worst case, the observer will get notified about a non-change |
191 // which should be a no-op. After the first notification, | 188 // which should be a no-op. After the first notification, |
192 // GetNextPermissionChange will be called with the latest known value. | 189 // GetNextPermissionChange will be called with the latest known value. |
193 PERMISSION_STATUS_ASK, | 190 PermissionStatus::ASK, |
194 base::Bind(&PermissionDispatcher::OnPermissionChangedForWorker, | 191 base::Bind(&PermissionDispatcher::OnPermissionChangedForWorker, |
195 base::Unretained(this), | 192 base::Unretained(this), worker_thread_id, callback)); |
196 worker_thread_id, | |
197 callback)); | |
198 } | 193 } |
199 | 194 |
200 void PermissionDispatcher::GetNextPermissionChangeForWorker( | 195 void PermissionDispatcher::GetNextPermissionChangeForWorker( |
201 blink::WebPermissionType type, | 196 blink::WebPermissionType type, |
202 const std::string& origin, | 197 const std::string& origin, |
203 blink::WebPermissionStatus status, | 198 blink::WebPermissionStatus status, |
204 int worker_thread_id, | 199 int worker_thread_id, |
205 const base::Callback<void(blink::WebPermissionStatus)>& callback) { | 200 const base::Callback<void(blink::WebPermissionStatus)>& callback) { |
206 GetPermissionServicePtr()->GetNextPermissionChange( | 201 GetPermissionServicePtr()->GetNextPermissionChange( |
207 GetPermissionName(type), | 202 GetPermissionName(type), |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 origin, | 399 origin, |
405 current_status, | 400 current_status, |
406 base::Bind(&PermissionDispatcher::OnPermissionChanged, | 401 base::Bind(&PermissionDispatcher::OnPermissionChanged, |
407 base::Unretained(this), | 402 base::Unretained(this), |
408 type, | 403 type, |
409 origin, | 404 origin, |
410 base::Unretained(observer))); | 405 base::Unretained(observer))); |
411 } | 406 } |
412 | 407 |
413 } // namespace content | 408 } // namespace content |
OLD | NEW |