| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // WebViewRendererState manages state data for WebView guest renderer processes. | 5 // WebViewRendererState manages state data for WebView guest renderer processes. |
| 6 // | 6 // |
| 7 // This class's data can be accessed via its methods from both the UI and IO | 7 // This class's data can be accessed via its methods from both the UI and IO |
| 8 // threads, and uses locks to mediate this access. When making changes to this | 8 // threads, and uses locks to mediate this access. When making changes to this |
| 9 // class, ensure that you avoid introducing any reentrant code in the methods, | 9 // class, ensure that you avoid introducing any reentrant code in the methods, |
| 10 // and that you always aquire the locks in the order |web_view_info_map_lock_| | 10 // and that you always aquire the locks in the order |web_view_info_map_lock_| |
| 11 // -> |web_view_partition_id_map_lock_| (if both are needed in one method). | 11 // -> |web_view_partition_id_map_lock_| (if both are needed in one method). |
| 12 | 12 |
| 13 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ | 13 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ |
| 14 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ | 14 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ |
| 15 | 15 |
| 16 #include <map> | 16 #include <map> |
| 17 #include <set> | 17 #include <set> |
| 18 #include <string> | 18 #include <string> |
| 19 #include <utility> | 19 #include <utility> |
| 20 | 20 |
| 21 #include "base/memory/singleton.h" | 21 #include "base/memory/singleton.h" |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 class WebViewGuest; | 25 class WebViewGuest; |
| 26 | 26 |
| 27 // This class keeps track of <webview> renderer state for use on the IO thread. | |
| 28 // All methods should be called on the IO thread. | |
| 29 class WebViewRendererState { | 27 class WebViewRendererState { |
| 30 public: | 28 public: |
| 31 struct WebViewInfo { | 29 struct WebViewInfo { |
| 32 int embedder_process_id; | 30 int embedder_process_id; |
| 33 int instance_id; | 31 int instance_id; |
| 34 int rules_registry_id; | 32 int rules_registry_id; |
| 35 std::string partition_id; | 33 std::string partition_id; |
| 36 std::string owner_host; | 34 std::string owner_host; |
| 37 std::set<int> content_script_ids; | 35 std::set<int> content_script_ids; |
| 38 | 36 |
| 39 WebViewInfo(); | 37 WebViewInfo(); |
| 40 ~WebViewInfo(); | 38 ~WebViewInfo(); |
| 41 }; | 39 }; |
| 42 | 40 |
| 43 static WebViewRendererState* GetInstance(); | 41 static WebViewRendererState* GetInstance(); |
| 44 | 42 |
| 45 // Looks up the information for the embedder <webview> for a given render | 43 // Looks up the information for the embedder WebView for a RenderViewHost, |
| 46 // view, if one exists. Called on the IO thread. | 44 // given its process and view ID. Returns true and writes the information to |
| 45 // |web_view_info| if found, otherwise returns false. |
| 47 bool GetInfo(int guest_process_id, | 46 bool GetInfo(int guest_process_id, |
| 48 int guest_routing_id, | 47 int guest_routing_id, |
| 49 WebViewInfo* web_view_info) const; | 48 WebViewInfo* web_view_info) const; |
| 50 | 49 |
| 51 // Looks up the information for the owner for a given guest process in a | 50 // Looks up the information for the owner of a WebView guest process, given |
| 52 // <webview>. Called on the IO thread. | 51 // its process ID. Returns true and writes the info to |owner_process_id| and |
| 52 // |owner_host| if found, otherwise returns false. |
| 53 bool GetOwnerInfo(int guest_process_id, | 53 bool GetOwnerInfo(int guest_process_id, |
| 54 int* owner_process_id, | 54 int* owner_process_id, |
| 55 std::string* owner_host) const; | 55 std::string* owner_host) const; |
| 56 | 56 |
| 57 // Looks up the partition info for the embedder <webview> for a given guest | 57 // Looks up the partition ID for a WebView guest process, given its |
| 58 // process. Called on the IO thread. | 58 // process ID. Returns true and writes the partition ID to |partition_id| if |
| 59 // found, otherwise returns false. |
| 59 bool GetPartitionID(int guest_process_id, std::string* partition_id) const; | 60 bool GetPartitionID(int guest_process_id, std::string* partition_id) const; |
| 60 | 61 |
| 61 // Returns true if the given renderer is used by webviews. | 62 // Returns true if the renderer with process ID |render_process_id| is a |
| 63 // WebView guest process. |
| 62 bool IsGuest(int render_process_id) const; | 64 bool IsGuest(int render_process_id) const; |
| 63 | 65 |
| 64 void AddContentScriptIDs(int embedder_process_id, | 66 void AddContentScriptIDs(int embedder_process_id, |
| 65 int view_instance_id, | 67 int view_instance_id, |
| 66 const std::set<int>& script_ids); | 68 const std::set<int>& script_ids); |
| 67 void RemoveContentScriptIDs(int embedder_process_id, | 69 void RemoveContentScriptIDs(int embedder_process_id, |
| 68 int view_instance_id, | 70 int view_instance_id, |
| 69 const std::set<int>& script_ids); | 71 const std::set<int>& script_ids); |
| 70 | 72 |
| 71 private: | 73 private: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 WebViewPartitionInfo(int count, std::string partition): | 84 WebViewPartitionInfo(int count, std::string partition): |
| 83 web_view_count(count), | 85 web_view_count(count), |
| 84 partition_id(partition) {} | 86 partition_id(partition) {} |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 using WebViewPartitionIDMap = std::map<int, WebViewPartitionInfo>; | 89 using WebViewPartitionIDMap = std::map<int, WebViewPartitionInfo>; |
| 88 | 90 |
| 89 WebViewRendererState(); | 91 WebViewRendererState(); |
| 90 ~WebViewRendererState(); | 92 ~WebViewRendererState(); |
| 91 | 93 |
| 92 // Adds or removes a <webview> guest render process from the set. | 94 // Adds/removes a WebView guest render process to/from the set. |
| 93 void AddGuest(int render_process_host_id, int routing_id, | 95 void AddGuest(int render_process_host_id, int routing_id, |
| 94 const WebViewInfo& web_view_info); | 96 const WebViewInfo& web_view_info); |
| 95 void RemoveGuest(int render_process_host_id, int routing_id); | 97 void RemoveGuest(int render_process_host_id, int routing_id); |
| 96 | 98 |
| 97 // Locks are used to mediate access to these maps from both the UI and IO | 99 // Locks are used to mediate access to these maps from both the UI and IO |
| 98 // threads. | 100 // threads. |
| 99 WebViewInfoMap web_view_info_map_; | 101 WebViewInfoMap web_view_info_map_; |
| 100 mutable base::Lock web_view_info_map_lock_; | 102 mutable base::Lock web_view_info_map_lock_; |
| 101 WebViewPartitionIDMap web_view_partition_id_map_; | 103 WebViewPartitionIDMap web_view_partition_id_map_; |
| 102 mutable base::Lock web_view_partition_id_map_lock_; | 104 mutable base::Lock web_view_partition_id_map_lock_; |
| 103 | 105 |
| 104 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState); | 106 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState); |
| 105 }; | 107 }; |
| 106 | 108 |
| 107 } // namespace extensions | 109 } // namespace extensions |
| 108 | 110 |
| 109 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ | 111 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_ |
| OLD | NEW |