1 // Copyright (c) 2013 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_
13 #include "base/basictypes.h"
14 #include "base/memory/singleton.h"
19 class ResourceRequestInfo
;
22 // This class keeps track of renderer state for use on the IO thread. All
23 // methods should be called on the IO thread except for Init and Shutdown.
24 class ExtensionRendererState
{
27 int embedder_process_id
;
29 std::string partition_id
;
30 std::string extension_id
;
33 static ExtensionRendererState
* GetInstance();
35 // These are called on the UI thread to start and stop listening to tab
40 // Looks up the information for the embedder <webview> for a given render
41 // view, if one exists. Called on the IO thread.
42 bool GetWebViewInfo(int guest_process_id
, int guest_routing_id
,
43 WebViewInfo
* webview_info
);
45 // Looks up the tab and window ID for a given request. Returns true if we have
46 // the IDs in our map. Called on the IO thread.
47 bool GetTabAndWindowId(
48 const content::ResourceRequestInfo
* info
, int* tab_id
, int* window_id
);
50 // Returns true if the given renderer is used by webviews.
51 bool IsWebViewRenderer(int render_process_id
);
54 class RenderViewHostObserver
;
56 friend class TabObserver
;
57 friend class WebViewGuest
;
58 friend struct DefaultSingletonTraits
<ExtensionRendererState
>;
60 typedef std::pair
<int, int> RenderId
;
61 typedef std::pair
<int, int> TabAndWindowId
;
62 typedef std::map
<RenderId
, TabAndWindowId
> TabAndWindowIdMap
;
63 typedef std::map
<RenderId
, WebViewInfo
> WebViewInfoMap
;
65 ExtensionRendererState();
66 ~ExtensionRendererState();
68 // Adds or removes a render view from our map.
69 void SetTabAndWindowId(
70 int render_process_host_id
, int routing_id
, int tab_id
, int window_id
);
71 void ClearTabAndWindowId(
72 int render_process_host_id
, int routing_id
);
74 // Adds or removes a <webview> guest render process from the set.
75 void AddWebView(int render_process_host_id
, int routing_id
,
76 const WebViewInfo
& webview_info
);
77 void RemoveWebView(int render_process_host_id
, int routing_id
);
79 TabObserver
* observer_
;
80 TabAndWindowIdMap map_
;
81 WebViewInfoMap webview_info_map_
;
83 DISALLOW_COPY_AND_ASSIGN(ExtensionRendererState
);
86 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_