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_
12 #include "base/basictypes.h"
13 #include "base/memory/singleton.h"
17 // This class keeps track of renderer state for use on the IO thread. All
18 // methods should be called on the IO thread except for Init and Shutdown.
19 class ExtensionRendererState
{
22 int embedder_process_id
;
23 int embedder_routing_id
;
27 static ExtensionRendererState
* GetInstance();
29 // These are called on the UI thread to start and stop listening to tab
34 // Looks up the information for the embedder <webview> for a given render
35 // view, if one exists. Called on the IO thread.
36 bool GetWebViewInfo(int guest_process_id
, int guest_routing_id
,
37 WebViewInfo
* webview_info
);
39 // Looks up the tab and window ID for a given render view. Returns true
40 // if we have the IDs in our map. Called on the IO thread.
41 bool GetTabAndWindowId(
42 int render_process_host_id
, int routing_id
, int* tab_id
, int* window_id
);
45 class RenderViewHostObserver
;
47 friend class TabObserver
;
48 friend class WebViewGuest
;
49 friend struct DefaultSingletonTraits
<ExtensionRendererState
>;
51 typedef std::pair
<int, int> RenderId
;
52 typedef std::pair
<int, int> TabAndWindowId
;
53 typedef std::map
<RenderId
, TabAndWindowId
> TabAndWindowIdMap
;
54 typedef std::map
<RenderId
, WebViewInfo
> WebViewInfoMap
;
56 ExtensionRendererState();
57 ~ExtensionRendererState();
59 // Adds or removes a render view from our map.
60 void SetTabAndWindowId(
61 int render_process_host_id
, int routing_id
, int tab_id
, int window_id
);
62 void ClearTabAndWindowId(
63 int render_process_host_id
, int routing_id
);
65 // Adds or removes a <webview> guest render process from the set.
66 void AddWebView(int render_process_host_id
, int routing_id
,
67 const WebViewInfo
& webview_info
);
68 void RemoveWebView(int render_process_host_id
, int routing_id
);
70 TabObserver
* observer_
;
71 TabAndWindowIdMap map_
;
72 WebViewInfoMap webview_info_map_
;
74 DISALLOW_COPY_AND_ASSIGN(ExtensionRendererState
);
77 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_