blob: 50c73a92e382a46af2805b9bab29a6c4238c878c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/permissions/permission_service_context.h"
#include "content/browser/permissions/permission_service_impl.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
namespace content {
PermissionServiceContext::PermissionServiceContext(
RenderFrameHost* render_frame_host)
: WebContentsObserver(WebContents::FromRenderFrameHost(render_frame_host)),
render_frame_host_(render_frame_host),
render_process_host_(nullptr) {
}
PermissionServiceContext::PermissionServiceContext(
RenderProcessHost* render_process_host)
: WebContentsObserver(nullptr),
render_frame_host_(nullptr),
render_process_host_(render_process_host) {
}
PermissionServiceContext::~PermissionServiceContext() {
}
void PermissionServiceContext::CreateService(
mojo::InterfaceRequest<PermissionService> request) {
PermissionServiceImpl* service =
new PermissionServiceImpl(this);
services_.push_back(service);
mojo::WeakBindToRequest(service, &request);
}
void PermissionServiceContext::ServiceHadConnectionError(
PermissionServiceImpl* service) {
auto it = std::find(services_.begin(), services_.end(), service);
DCHECK(it != services_.end());
services_.erase(it);
}
void PermissionServiceContext::RenderFrameDeleted(
RenderFrameHost* render_frame_host) {
CancelPendingRequests(render_frame_host);
}
void PermissionServiceContext::DidNavigateAnyFrame(
RenderFrameHost* render_frame_host,
const LoadCommittedDetails& details,
const FrameNavigateParams& params) {
if (details.is_in_page)
return;
CancelPendingRequests(render_frame_host);
}
void PermissionServiceContext::CancelPendingRequests(
RenderFrameHost* render_frame_host) const {
if (render_frame_host != render_frame_host_)
return;
for (auto* service : services_)
service->CancelPendingRequests();
}
BrowserContext* PermissionServiceContext::GetBrowserContext() const {
if (!web_contents()) {
DCHECK(render_process_host_);
return render_process_host_->GetBrowserContext();
}
return web_contents()->GetBrowserContext();
}
GURL PermissionServiceContext::GetEmbeddingOrigin() const {
return web_contents() ? web_contents()->GetLastCommittedURL().GetOrigin()
: GURL();
}
} // namespace content
|