Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / extensions / browser / guest_view / web_view / web_view_renderer_state.h
blobb6be959c823975bcd5aefd3d8092f401f8335380
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
13 #include "base/memory/singleton.h"
15 namespace extensions {
17 class WebViewGuest;
19 // This class keeps track of <webview> renderer state for use on the IO thread.
20 // All methods should be called on the IO thread.
21 class WebViewRendererState {
22 public:
23 struct WebViewInfo {
24 int embedder_process_id;
25 int instance_id;
26 int rules_registry_id;
27 std::string partition_id;
28 std::string owner_host;
29 std::set<int> content_script_ids;
31 WebViewInfo();
32 ~WebViewInfo();
35 static WebViewRendererState* GetInstance();
37 // Looks up the information for the embedder <webview> for a given render
38 // view, if one exists. Called on the IO thread.
39 bool GetInfo(int guest_process_id, int guest_routing_id,
40 WebViewInfo* web_view_info);
42 // Looks up the information for the owner for a given guest process in a
43 // <webview>. Called on the IO thread.
44 bool GetOwnerInfo(int guest_process_id,
45 int* owner_process_id,
46 std::string* owner_host) const;
48 // Looks up the partition info for the embedder <webview> for a given guest
49 // process. Called on the IO thread.
50 bool GetPartitionID(int guest_process_id, std::string* partition_id);
52 // Returns true if the given renderer is used by webviews.
53 bool IsGuest(int render_process_id);
55 void AddContentScriptIDs(int embedder_process_id,
56 int view_instance_id,
57 const std::set<int>& script_ids);
58 void RemoveContentScriptIDs(int embedder_process_id,
59 int view_instance_id,
60 const std::set<int>& script_ids);
62 private:
63 friend class WebViewGuest;
64 friend struct DefaultSingletonTraits<WebViewRendererState>;
66 using RenderId = std::pair<int, int>;
67 using WebViewInfoMap = std::map<RenderId, WebViewInfo>;
69 struct WebViewPartitionInfo {
70 int web_view_count;
71 std::string partition_id;
72 WebViewPartitionInfo() {}
73 WebViewPartitionInfo(int count, std::string partition):
74 web_view_count(count),
75 partition_id(partition) {}
78 using WebViewPartitionIDMap = std::map<int, WebViewPartitionInfo>;
80 WebViewRendererState();
81 ~WebViewRendererState();
83 // Adds or removes a <webview> guest render process from the set.
84 void AddGuest(int render_process_host_id, int routing_id,
85 const WebViewInfo& web_view_info);
86 void RemoveGuest(int render_process_host_id, int routing_id);
88 WebViewInfoMap web_view_info_map_;
89 WebViewPartitionIDMap web_view_partition_id_map_;
91 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState);
94 } // namespace extensions
96 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_