OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/permissions/permission_service_context.h" | 5 #include "content/browser/permissions/permission_service_context.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "content/browser/permissions/permission_service_impl.h" | 9 #include "content/browser/permissions/permission_service_impl.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 RenderProcessHost* render_process_host) | 65 RenderProcessHost* render_process_host) |
66 : WebContentsObserver(nullptr), | 66 : WebContentsObserver(nullptr), |
67 render_frame_host_(nullptr), | 67 render_frame_host_(nullptr), |
68 render_process_host_(render_process_host) { | 68 render_process_host_(render_process_host) { |
69 } | 69 } |
70 | 70 |
71 PermissionServiceContext::~PermissionServiceContext() { | 71 PermissionServiceContext::~PermissionServiceContext() { |
72 } | 72 } |
73 | 73 |
74 void PermissionServiceContext::CreateService( | 74 void PermissionServiceContext::CreateService( |
75 mojo::InterfaceRequest<blink::mojom::PermissionService> request) { | 75 blink::mojom::PermissionServiceRequest request) { |
76 services_.push_back( | 76 services_.AddBinding(base::MakeUnique<PermissionServiceImpl>(this), |
77 base::MakeUnique<PermissionServiceImpl>(this, std::move(request))); | 77 std::move(request)); |
78 } | 78 } |
79 | 79 |
80 void PermissionServiceContext::CreateSubscription( | 80 void PermissionServiceContext::CreateSubscription( |
81 PermissionType permission_type, | 81 PermissionType permission_type, |
82 const url::Origin& origin, | 82 const url::Origin& origin, |
83 PermissionObserverPtr observer) { | 83 PermissionObserverPtr observer) { |
84 BrowserContext* browser_context = GetBrowserContext(); | 84 BrowserContext* browser_context = GetBrowserContext(); |
85 DCHECK(browser_context); | 85 DCHECK(browser_context); |
86 if (!browser_context->GetPermissionManager()) | 86 if (!browser_context->GetPermissionManager()) |
87 return; | 87 return; |
88 | 88 |
89 auto subscription = | 89 auto subscription = |
90 base::MakeUnique<PermissionSubscription>(this, std::move(observer)); | 90 base::MakeUnique<PermissionSubscription>(this, std::move(observer)); |
91 GURL requesting_origin(origin.Serialize()); | 91 GURL requesting_origin(origin.Serialize()); |
92 GURL embedding_origin = GetEmbeddingOrigin(); | 92 GURL embedding_origin = GetEmbeddingOrigin(); |
93 int subscription_id = | 93 int subscription_id = |
94 browser_context->GetPermissionManager()->SubscribePermissionStatusChange( | 94 browser_context->GetPermissionManager()->SubscribePermissionStatusChange( |
95 permission_type, requesting_origin, | 95 permission_type, requesting_origin, |
96 // If the embedding_origin is empty, we'll use the |origin| instead. | 96 // If the embedding_origin is empty, we'll use the |origin| instead. |
97 embedding_origin.is_empty() ? requesting_origin : embedding_origin, | 97 embedding_origin.is_empty() ? requesting_origin : embedding_origin, |
98 base::Bind(&PermissionSubscription::OnPermissionStatusChanged, | 98 base::Bind(&PermissionSubscription::OnPermissionStatusChanged, |
99 base::Unretained(subscription.get()))); | 99 base::Unretained(subscription.get()))); |
100 subscription->set_id(subscription_id); | 100 subscription->set_id(subscription_id); |
101 subscriptions_[subscription_id] = std::move(subscription); | 101 subscriptions_[subscription_id] = std::move(subscription); |
102 } | 102 } |
103 | 103 |
104 void PermissionServiceContext::ServiceHadConnectionError( | |
105 PermissionServiceImpl* service) { | |
106 auto it = std::find_if( | |
107 services_.begin(), services_.end(), | |
108 [service](const std::unique_ptr<PermissionServiceImpl>& this_service) { | |
109 return service == this_service.get(); | |
110 }); | |
111 DCHECK(it != services_.end()); | |
112 services_.erase(it); | |
113 } | |
114 | |
115 void PermissionServiceContext::ObserverHadConnectionError(int subscription_id) { | 104 void PermissionServiceContext::ObserverHadConnectionError(int subscription_id) { |
116 auto it = subscriptions_.find(subscription_id); | 105 auto it = subscriptions_.find(subscription_id); |
117 DCHECK(it != subscriptions_.end()); | 106 DCHECK(it != subscriptions_.end()); |
118 subscriptions_.erase(it); | 107 subscriptions_.erase(it); |
119 } | 108 } |
120 | 109 |
121 void PermissionServiceContext::RenderFrameHostChanged( | 110 void PermissionServiceContext::RenderFrameHostChanged( |
122 RenderFrameHost* old_host, | 111 RenderFrameHost* old_host, |
123 RenderFrameHost* new_host) { | 112 RenderFrameHost* new_host) { |
124 CancelPendingOperations(old_host); | 113 CancelPendingOperations(old_host); |
125 } | 114 } |
126 | 115 |
127 void PermissionServiceContext::FrameDeleted( | 116 void PermissionServiceContext::FrameDeleted( |
128 RenderFrameHost* render_frame_host) { | 117 RenderFrameHost* render_frame_host) { |
129 CancelPendingOperations(render_frame_host); | 118 CancelPendingOperations(render_frame_host); |
130 } | 119 } |
131 | 120 |
132 void PermissionServiceContext::DidFinishNavigation( | 121 void PermissionServiceContext::DidFinishNavigation( |
133 NavigationHandle* navigation_handle) { | 122 NavigationHandle* navigation_handle) { |
134 if (!navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) | 123 if (!navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) |
135 return; | 124 return; |
136 | 125 |
137 CancelPendingOperations(navigation_handle->GetRenderFrameHost()); | 126 CancelPendingOperations(navigation_handle->GetRenderFrameHost()); |
138 } | 127 } |
139 | 128 |
140 void PermissionServiceContext::CancelPendingOperations( | 129 void PermissionServiceContext::CancelPendingOperations( |
raymes
2017/04/30 23:25:24
Maybe we should call this CloseBindings (or someth
Reilly Grant (use Gerrit)
2017/05/01 19:40:51
Done.
| |
141 RenderFrameHost* render_frame_host) { | 130 RenderFrameHost* render_frame_host) { |
142 DCHECK(render_frame_host_); | 131 DCHECK(render_frame_host_); |
143 if (render_frame_host != render_frame_host_) | 132 if (render_frame_host != render_frame_host_) |
144 return; | 133 return; |
145 | 134 |
146 for (const auto& service : services_) | 135 services_.CloseAllBindings(); |
147 service->CancelPendingOperations(); | |
raymes
2017/04/28 02:46:00
Please bear with my ignorance because my mojo-foo
Reilly Grant (use Gerrit)
2017/04/28 17:52:22
It's a good question. Yes, before the requests wou
| |
148 | |
149 subscriptions_.clear(); | 136 subscriptions_.clear(); |
150 } | 137 } |
151 | 138 |
152 BrowserContext* PermissionServiceContext::GetBrowserContext() const { | 139 BrowserContext* PermissionServiceContext::GetBrowserContext() const { |
153 if (!web_contents()) { | 140 if (!web_contents()) { |
154 DCHECK(render_process_host_); | 141 DCHECK(render_process_host_); |
155 return render_process_host_->GetBrowserContext(); | 142 return render_process_host_->GetBrowserContext(); |
156 } | 143 } |
157 return web_contents()->GetBrowserContext(); | 144 return web_contents()->GetBrowserContext(); |
158 } | 145 } |
159 | 146 |
160 GURL PermissionServiceContext::GetEmbeddingOrigin() const { | 147 GURL PermissionServiceContext::GetEmbeddingOrigin() const { |
161 return web_contents() ? web_contents()->GetLastCommittedURL().GetOrigin() | 148 return web_contents() ? web_contents()->GetLastCommittedURL().GetOrigin() |
162 : GURL(); | 149 : GURL(); |
163 } | 150 } |
164 | 151 |
165 RenderFrameHost* PermissionServiceContext::render_frame_host() const { | 152 RenderFrameHost* PermissionServiceContext::render_frame_host() const { |
166 return render_frame_host_; | 153 return render_frame_host_; |
167 } | 154 } |
168 | 155 |
169 } // namespace content | 156 } // namespace content |
OLD | NEW |