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_
12 #include "base/memory/singleton.h"
14 namespace extensions
{
18 // This class keeps track of <webview> renderer state for use on the IO thread.
19 // All methods should be called on the IO thread.
20 class WebViewRendererState
{
23 int embedder_process_id
;
25 int rules_registry_id
;
26 std::string partition_id
;
27 std::string owner_extension_id
;
30 static WebViewRendererState
* GetInstance();
32 // Looks up the information for the embedder <webview> for a given render
33 // view, if one exists. Called on the IO thread.
34 bool GetInfo(int guest_process_id
, int guest_routing_id
,
35 WebViewInfo
* webview_info
);
37 // Looks up the information for the owner for a given guest process in a
38 // <webview>. Called on the IO thread.
39 bool GetOwnerInfo(int guest_process_id
,
40 int* owner_process_id
,
41 std::string
* owner_extension_id
) const;
43 // Looks up the partition info for the embedder <webview> for a given guest
44 // process. Called on the IO thread.
45 bool GetPartitionID(int guest_process_id
, std::string
* partition_id
);
47 // Returns true if the given renderer is used by webviews.
48 bool IsGuest(int render_process_id
);
51 friend class WebViewGuest
;
52 friend struct DefaultSingletonTraits
<WebViewRendererState
>;
54 typedef std::pair
<int, int> RenderId
;
55 typedef std::map
<RenderId
, WebViewInfo
> WebViewInfoMap
;
57 struct WebViewPartitionInfo
{
59 std::string partition_id
;
60 WebViewPartitionInfo() {}
61 WebViewPartitionInfo(int count
, std::string partition
):
62 web_view_count(count
),
63 partition_id(partition
) {}
66 typedef std::map
<int, WebViewPartitionInfo
> WebViewPartitionIDMap
;
68 WebViewRendererState();
69 ~WebViewRendererState();
71 // Adds or removes a <webview> guest render process from the set.
72 void AddGuest(int render_process_host_id
, int routing_id
,
73 const WebViewInfo
& webview_info
);
74 void RemoveGuest(int render_process_host_id
, int routing_id
);
76 WebViewInfoMap webview_info_map_
;
77 WebViewPartitionIDMap webview_partition_id_map_
;
79 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState
);
82 } // namespace extensions
84 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_