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 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_
13 #include "base/memory/singleton.h"
15 namespace extensions
{
19 // This class keeps track of <webview> renderer state for use on the IO thread.
20 // All methods should be called on the IO thread.
21 class WebViewRendererState
{
24 int embedder_process_id
;
26 int rules_registry_id
;
27 std::string partition_id
;
28 std::string owner_host
;
29 std::set
<int> content_script_ids
;
35 static WebViewRendererState
* GetInstance();
37 // Looks up the information for the embedder <webview> for a given render
38 // view, if one exists. Called on the IO thread.
39 bool GetInfo(int guest_process_id
, int guest_routing_id
,
40 WebViewInfo
* web_view_info
);
42 // Looks up the information for the owner for a given guest process in a
43 // <webview>. Called on the IO thread.
44 bool GetOwnerInfo(int guest_process_id
,
45 int* owner_process_id
,
46 std::string
* owner_host
) const;
48 // Looks up the partition info for the embedder <webview> for a given guest
49 // process. Called on the IO thread.
50 bool GetPartitionID(int guest_process_id
, std::string
* partition_id
);
52 // Returns true if the given renderer is used by webviews.
53 bool IsGuest(int render_process_id
);
55 void AddContentScriptIDs(int embedder_process_id
,
57 const std::set
<int>& script_ids
);
58 void RemoveContentScriptIDs(int embedder_process_id
,
60 const std::set
<int>& script_ids
);
63 friend class WebViewGuest
;
64 friend struct DefaultSingletonTraits
<WebViewRendererState
>;
66 using RenderId
= std::pair
<int, int>;
67 using WebViewInfoMap
= std::map
<RenderId
, WebViewInfo
>;
69 struct WebViewPartitionInfo
{
71 std::string partition_id
;
72 WebViewPartitionInfo() {}
73 WebViewPartitionInfo(int count
, std::string partition
):
74 web_view_count(count
),
75 partition_id(partition
) {}
78 using WebViewPartitionIDMap
= std::map
<int, WebViewPartitionInfo
>;
80 WebViewRendererState();
81 ~WebViewRendererState();
83 // Adds or removes a <webview> guest render process from the set.
84 void AddGuest(int render_process_host_id
, int routing_id
,
85 const WebViewInfo
& web_view_info
);
86 void RemoveGuest(int render_process_host_id
, int routing_id
);
88 WebViewInfoMap web_view_info_map_
;
89 WebViewPartitionIDMap web_view_partition_id_map_
;
91 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState
);
94 } // namespace extensions
96 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_