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. 4 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_ 7 8 #include <map> 9 #include <string> 10 #include <utility> 11 12 #include "base/memory/singleton.h" 13 14 namespace extensions { 15 16 class WebViewGuest; 17 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 { 21 public: 22 struct WebViewInfo { 23 int embedder_process_id; 24 int instance_id; 25 std::string partition_id; 26 std::string embedder_extension_id; 27 }; 28 29 static WebViewRendererState* GetInstance(); 30 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); 35 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); 39 40 // Returns true if the given renderer is used by webviews. 41 bool IsGuest(int render_process_id); 42 43 private: 44 friend class WebViewGuest; 45 friend struct DefaultSingletonTraits<WebViewRendererState>; 46 47 typedef std::pair<int, int> RenderId; 48 typedef std::map<RenderId, WebViewInfo> WebViewInfoMap; 49 50 struct WebViewPartitionInfo { 51 int web_view_count; 52 std::string partition_id; 53 WebViewPartitionInfo() {} 54 WebViewPartitionInfo(int count, std::string partition): 55 web_view_count(count), 56 partition_id(partition) {} 57 }; 58 59 typedef std::map<int, WebViewPartitionInfo> WebViewPartitionIDMap; 60 61 WebViewRendererState(); 62 ~WebViewRendererState(); 63 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); 68 69 WebViewInfoMap webview_info_map_; 70 WebViewPartitionIDMap webview_partition_id_map_; 71 72 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState); 73 }; 74 75 } // namespace extensions 76 77 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ 78