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 std::string partition_id
;
26 std::string embedder_extension_id
;
29 static WebViewRendererState
* GetInstance();
31 // Looks up the information for the embedder <webview> for a given render
32 // view, if one exists. Called on the IO thread.
33 bool GetInfo(int guest_process_id
, int guest_routing_id
,
34 WebViewInfo
* webview_info
);
36 // Looks up the partition info for the embedder <webview> for a given guest
37 // process. Called on the IO thread.
38 bool GetPartitionID(int guest_process_id
, std::string
* partition_id
);
40 // Returns true if the given renderer is used by webviews.
41 bool IsGuest(int render_process_id
);
44 friend class WebViewGuest
;
45 friend struct DefaultSingletonTraits
<WebViewRendererState
>;
47 typedef std::pair
<int, int> RenderId
;
48 typedef std::map
<RenderId
, WebViewInfo
> WebViewInfoMap
;
50 struct WebViewPartitionInfo
{
52 std::string partition_id
;
53 WebViewPartitionInfo() {}
54 WebViewPartitionInfo(int count
, std::string partition
):
55 web_view_count(count
),
56 partition_id(partition
) {}
59 typedef std::map
<int, WebViewPartitionInfo
> WebViewPartitionIDMap
;
61 WebViewRendererState();
62 ~WebViewRendererState();
64 // Adds or removes a <webview> guest render process from the set.
65 void AddGuest(int render_process_host_id
, int routing_id
,
66 const WebViewInfo
& webview_info
);
67 void RemoveGuest(int render_process_host_id
, int routing_id
);
69 WebViewInfoMap webview_info_map_
;
70 WebViewPartitionIDMap webview_partition_id_map_
;
72 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState
);
75 } // namespace extensions
77 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_