Remove render view id from the audio input and output, part two!
[chromium-blink-merge.git] / content / browser / permissions / permission_service_context.cc
blob6922fb608e04a772fb2efc1cb2d368d939fca2c4
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
3 // found in the LICENSE file.
5 #include "content/browser/permissions/permission_service_context.h"
7 #include "content/browser/permissions/permission_service_impl.h"
8 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/web_contents.h"
13 namespace content {
15 PermissionServiceContext::PermissionServiceContext(
16 RenderFrameHost* render_frame_host)
17 : WebContentsObserver(WebContents::FromRenderFrameHost(render_frame_host)),
18 render_frame_host_(render_frame_host),
19 render_process_host_(nullptr) {
22 PermissionServiceContext::PermissionServiceContext(
23 RenderProcessHost* render_process_host)
24 : WebContentsObserver(nullptr),
25 render_frame_host_(nullptr),
26 render_process_host_(render_process_host) {
29 PermissionServiceContext::~PermissionServiceContext() {
32 void PermissionServiceContext::CreateService(
33 mojo::InterfaceRequest<PermissionService> request) {
34 PermissionServiceImpl* service =
35 new PermissionServiceImpl(this);
37 services_.push_back(service);
38 mojo::WeakBindToRequest(service, &request);
41 void PermissionServiceContext::ServiceHadConnectionError(
42 PermissionServiceImpl* service) {
43 auto it = std::find(services_.begin(), services_.end(), service);
44 DCHECK(it != services_.end());
45 services_.erase(it);
48 void PermissionServiceContext::RenderFrameDeleted(
49 RenderFrameHost* render_frame_host) {
50 CancelPendingOperations(render_frame_host);
53 void PermissionServiceContext::DidNavigateAnyFrame(
54 RenderFrameHost* render_frame_host,
55 const LoadCommittedDetails& details,
56 const FrameNavigateParams& params) {
57 if (details.is_in_page)
58 return;
60 CancelPendingOperations(render_frame_host);
63 void PermissionServiceContext::CancelPendingOperations(
64 RenderFrameHost* render_frame_host) const {
65 if (render_frame_host != render_frame_host_)
66 return;
68 for (auto* service : services_)
69 service->CancelPendingOperations();
72 BrowserContext* PermissionServiceContext::GetBrowserContext() const {
73 if (!web_contents()) {
74 DCHECK(render_process_host_);
75 return render_process_host_->GetBrowserContext();
77 return web_contents()->GetBrowserContext();
80 GURL PermissionServiceContext::GetEmbeddingOrigin() const {
81 return web_contents() ? web_contents()->GetLastCommittedURL().GetOrigin()
82 : GURL();
85 } // namespace content