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/public/browser/browser_thread.h"
6 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
8 using content::BrowserThread
;
10 namespace extensions
{
13 WebViewRendererState
* WebViewRendererState::GetInstance() {
14 return Singleton
<WebViewRendererState
>::get();
17 WebViewRendererState::WebViewRendererState() {
20 WebViewRendererState::~WebViewRendererState() {
23 bool WebViewRendererState::IsGuest(int render_process_id
) {
24 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
25 return web_view_partition_id_map_
.find(render_process_id
) !=
26 web_view_partition_id_map_
.end();
29 void WebViewRendererState::AddGuest(int guest_process_id
,
31 const WebViewInfo
& web_view_info
) {
32 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
33 RenderId
render_id(guest_process_id
, guest_routing_id
);
35 web_view_info_map_
.find(render_id
) != web_view_info_map_
.end();
36 web_view_info_map_
[render_id
] = web_view_info
;
40 auto iter
= web_view_partition_id_map_
.find(guest_process_id
);
41 if (iter
!= web_view_partition_id_map_
.end()) {
42 ++iter
->second
.web_view_count
;
45 WebViewPartitionInfo
partition_info(1, web_view_info
.partition_id
);
46 web_view_partition_id_map_
[guest_process_id
] = partition_info
;
49 void WebViewRendererState::RemoveGuest(int guest_process_id
,
50 int guest_routing_id
) {
51 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
52 RenderId
render_id(guest_process_id
, guest_routing_id
);
53 web_view_info_map_
.erase(render_id
);
54 auto iter
= web_view_partition_id_map_
.find(guest_process_id
);
55 if (iter
!= web_view_partition_id_map_
.end() &&
56 iter
->second
.web_view_count
> 1) {
57 --iter
->second
.web_view_count
;
60 web_view_partition_id_map_
.erase(guest_process_id
);
63 bool WebViewRendererState::GetInfo(int guest_process_id
,
65 WebViewInfo
* web_view_info
) {
66 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
67 RenderId
render_id(guest_process_id
, guest_routing_id
);
68 auto iter
= web_view_info_map_
.find(render_id
);
69 if (iter
!= web_view_info_map_
.end()) {
70 *web_view_info
= iter
->second
;
76 bool WebViewRendererState::GetOwnerInfo(int guest_process_id
,
77 int* owner_process_id
,
78 std::string
* owner_extension_id
) const {
79 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
80 // TODO(fsamuel): Store per-process info in WebViewPartitionInfo instead of in
82 for (const auto& info
: web_view_info_map_
) {
83 if (info
.first
.first
== guest_process_id
) {
85 *owner_process_id
= info
.second
.embedder_process_id
;
86 if (owner_extension_id
)
87 *owner_extension_id
= info
.second
.owner_extension_id
;
94 bool WebViewRendererState::GetPartitionID(int guest_process_id
,
95 std::string
* partition_id
) {
96 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
98 auto iter
= web_view_partition_id_map_
.find(guest_process_id
);
99 if (iter
!= web_view_partition_id_map_
.end()){
100 *partition_id
= iter
->second
.partition_id
;
106 } // namespace extensions