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 webview_partition_id_map_
.find(render_process_id
) !=
26 webview_partition_id_map_
.end();
29 void WebViewRendererState::AddGuest(int guest_process_id
,
31 const WebViewInfo
& webview_info
) {
32 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
33 RenderId
render_id(guest_process_id
, guest_routing_id
);
34 webview_info_map_
[render_id
] = webview_info
;
35 WebViewPartitionIDMap::iterator iter
=
36 webview_partition_id_map_
.find(guest_process_id
);
37 if (iter
!= webview_partition_id_map_
.end()) {
38 ++iter
->second
.web_view_count
;
41 WebViewPartitionInfo
partition_info(1, webview_info
.partition_id
);
42 webview_partition_id_map_
[guest_process_id
] = partition_info
;
45 void WebViewRendererState::RemoveGuest(int guest_process_id
,
46 int guest_routing_id
) {
47 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
48 RenderId
render_id(guest_process_id
, guest_routing_id
);
49 webview_info_map_
.erase(render_id
);
50 WebViewPartitionIDMap::iterator iter
=
51 webview_partition_id_map_
.find(guest_process_id
);
52 if (iter
!= webview_partition_id_map_
.end() &&
53 iter
->second
.web_view_count
> 1) {
54 --iter
->second
.web_view_count
;
57 webview_partition_id_map_
.erase(guest_process_id
);
60 bool WebViewRendererState::GetInfo(int guest_process_id
,
62 WebViewInfo
* webview_info
) {
63 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
64 RenderId
render_id(guest_process_id
, guest_routing_id
);
65 WebViewInfoMap::iterator iter
= webview_info_map_
.find(render_id
);
66 if (iter
!= webview_info_map_
.end()) {
67 *webview_info
= iter
->second
;
73 bool WebViewRendererState::GetOwnerInfo(int guest_process_id
,
74 int* owner_process_id
,
75 std::string
* owner_extension_id
) const {
76 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
77 // TODO(fsamuel): Store per-process info in WebViewPartitionInfo instead of in
79 for (const auto& info
: webview_info_map_
) {
80 if (info
.first
.first
== guest_process_id
) {
82 *owner_process_id
= info
.second
.embedder_process_id
;
83 if (owner_extension_id
)
84 *owner_extension_id
= info
.second
.owner_extension_id
;
91 bool WebViewRendererState::GetPartitionID(int guest_process_id
,
92 std::string
* partition_id
) {
93 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
94 WebViewPartitionIDMap::iterator iter
=
95 webview_partition_id_map_
.find(guest_process_id
);
96 if (iter
!= webview_partition_id_map_
.end()) {
97 *partition_id
= iter
->second
.partition_id
;
103 } // namespace extensions