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_thread_proxy.h" | 5 #include "content/child/permissions/permission_dispatcher_thread_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
13 #include "content/child/permissions/permission_dispatcher.h" | 13 #include "content/child/permissions/permission_dispatcher.h" |
14 #include "content/child/worker_task_runner.h" | 14 #include "content/child/worker_task_runner.h" |
15 #include "third_party/WebKit/public/platform/WebURL.h" | 15 #include "third_party/WebKit/public/platform/WebURL.h" |
| 16 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" |
16 | 17 |
17 using base::LazyInstance; | 18 using base::LazyInstance; |
18 using base::ThreadLocalPointer; | 19 using base::ThreadLocalPointer; |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 LazyInstance<ThreadLocalPointer<PermissionDispatcherThreadProxy>>::Leaky | 25 LazyInstance<ThreadLocalPointer<PermissionDispatcherThreadProxy>>::Leaky |
25 g_permission_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 26 g_permission_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 main_thread_task_runner_->PostTask( | 61 main_thread_task_runner_->PostTask( |
61 FROM_HERE, | 62 FROM_HERE, |
62 base::Bind(&PermissionDispatcher::QueryPermissionForWorker, | 63 base::Bind(&PermissionDispatcher::QueryPermissionForWorker, |
63 base::Unretained(permission_dispatcher_), | 64 base::Unretained(permission_dispatcher_), |
64 type, | 65 type, |
65 origin.string().utf8(), | 66 origin.string().utf8(), |
66 base::Unretained(callback), | 67 base::Unretained(callback), |
67 WorkerTaskRunner::Instance()->CurrentWorkerId())); | 68 WorkerTaskRunner::Instance()->CurrentWorkerId())); |
68 } | 69 } |
69 | 70 |
| 71 void PermissionDispatcherThreadProxy::startListening( |
| 72 blink::WebPermissionType type, |
| 73 const blink::WebURL& origin, |
| 74 blink::WebPermissionObserver* observer) { |
| 75 if (!PermissionDispatcher::IsObservable(type)) |
| 76 return; |
| 77 |
| 78 RegisterObserver(observer); |
| 79 |
| 80 main_thread_task_runner_->PostTask(FROM_HERE, |
| 81 base::Bind(&PermissionDispatcher::StartListeningForWorker, |
| 82 base::Unretained(permission_dispatcher_), |
| 83 type, |
| 84 origin.string().utf8(), |
| 85 WorkerTaskRunner::Instance()->CurrentWorkerId(), |
| 86 base::Bind(&PermissionDispatcherThreadProxy::OnPermissionChanged, |
| 87 base::Unretained(this), |
| 88 type, |
| 89 origin.string().utf8(), |
| 90 base::Unretained(observer)))); |
| 91 } |
| 92 |
| 93 void PermissionDispatcherThreadProxy::stopListening( |
| 94 blink::WebPermissionObserver* observer) { |
| 95 UnregisterObserver(observer); |
| 96 } |
| 97 |
| 98 void PermissionDispatcherThreadProxy::OnPermissionChanged( |
| 99 blink::WebPermissionType type, |
| 100 const std::string& origin, |
| 101 blink::WebPermissionObserver* observer, |
| 102 blink::WebPermissionStatus status) { |
| 103 if (!IsObserverRegistered(observer)) |
| 104 return; |
| 105 |
| 106 observer->permissionChanged(type, status); |
| 107 |
| 108 main_thread_task_runner_->PostTask(FROM_HERE, |
| 109 base::Bind(&PermissionDispatcher::GetNextPermissionChangeForWorker, |
| 110 base::Unretained(permission_dispatcher_), |
| 111 type, |
| 112 origin, |
| 113 status, |
| 114 WorkerTaskRunner::Instance()->CurrentWorkerId(), |
| 115 base::Bind(&PermissionDispatcherThreadProxy::OnPermissionChanged, |
| 116 base::Unretained(this), |
| 117 type, |
| 118 origin, |
| 119 base::Unretained(observer)))); |
| 120 } |
| 121 |
70 void PermissionDispatcherThreadProxy::OnWorkerRunLoopStopped() { | 122 void PermissionDispatcherThreadProxy::OnWorkerRunLoopStopped() { |
71 delete this; | 123 delete this; |
72 } | 124 } |
73 | 125 |
74 } // namespace content | 126 } // namespace content |
OLD | NEW |