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"
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 services_
.push_back(new PermissionServiceImpl(this, request
.Pass()));
37 void PermissionServiceContext::ServiceHadConnectionError(
38 PermissionServiceImpl
* service
) {
39 auto it
= std::find(services_
.begin(), services_
.end(), service
);
40 DCHECK(it
!= services_
.end());
44 void PermissionServiceContext::RenderFrameDeleted(
45 RenderFrameHost
* render_frame_host
) {
46 CancelPendingOperations(render_frame_host
);
49 void PermissionServiceContext::RenderFrameHostChanged(
50 RenderFrameHost
* old_host
,
51 RenderFrameHost
* new_host
) {
52 CancelPendingOperations(old_host
);
55 void PermissionServiceContext::DidNavigateAnyFrame(
56 RenderFrameHost
* render_frame_host
,
57 const LoadCommittedDetails
& details
,
58 const FrameNavigateParams
& params
) {
59 if (details
.is_in_page
)
62 CancelPendingOperations(render_frame_host
);
65 void PermissionServiceContext::CancelPendingOperations(
66 RenderFrameHost
* render_frame_host
) const {
67 DCHECK(render_frame_host_
);
68 if (render_frame_host
!= render_frame_host_
)
71 for (auto* service
: services_
)
72 service
->CancelPendingOperations();
75 BrowserContext
* PermissionServiceContext::GetBrowserContext() const {
76 if (!web_contents()) {
77 DCHECK(render_process_host_
);
78 return render_process_host_
->GetBrowserContext();
80 return web_contents()->GetBrowserContext();
83 GURL
PermissionServiceContext::GetEmbeddingOrigin() const {
84 return web_contents() ? web_contents()->GetLastCommittedURL().GetOrigin()
88 RenderFrameHost
* PermissionServiceContext::render_frame_host() const {
89 return render_frame_host_
;
92 } // namespace content