OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_CONTENT_SCRIPT_MANAGER_H | |
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/supports_user_data.h" | |
14 | |
15 struct HostID; | |
16 | |
17 namespace content { | |
18 class BrowserContext; | |
19 class WebContents; | |
20 } | |
21 | |
22 namespace extensions { | |
23 class UserScript; | |
24 | |
25 // WebViewContentScriptManager manages the content scripts that each webview | |
26 // guest adds and removes programmatically. | |
27 class WebViewContentScriptManager : public base::SupportsUserData::Data { | |
Devlin
2015/04/13 19:21:48
Please file a bug and add a TODO here linking to i
Xi Han
2015/04/14 19:05:52
Done.
| |
28 public: | |
29 explicit WebViewContentScriptManager( | |
30 content::BrowserContext* browser_context); | |
31 ~WebViewContentScriptManager() override; | |
32 | |
33 static WebViewContentScriptManager* Get( | |
34 content::BrowserContext* browser_context); | |
35 | |
36 // Adds content scripts for the guest specified by the |embedder_web_contents, | |
37 // view_instance_id|. | |
38 // The name of each content sccript is its key in |user_scripts| map. | |
39 void AddContentScripts(content::WebContents* embedder_web_contents, | |
40 int view_instance_id, | |
41 const HostID& host_id, | |
42 const std::map<std::string, UserScript>& user_scripts); | |
Devlin
2015/04/13 19:21:48
The name is stored on the UserScript, so we don't
Xi Han
2015/04/14 19:05:52
Done.
| |
43 | |
44 // Removes contents scipts whose names are in the |script_name_list| for the | |
45 // guest specified by |embedder_web_contents, view_instance_id|. | |
46 // If the |script_name_list| is empty, removes all the content scripts added | |
47 // for this guest. | |
48 void RemoveContentScripts(content::WebContents* embedder_web_contents, | |
49 int view_instance_id, | |
50 const HostID& host_id, | |
51 const std::vector<std::string>& script_name_list); | |
52 | |
53 // Returns whether the content script with |script_id| belonges to the guest | |
54 // specified by |embedder_process_id, view_instance_id|. | |
55 bool OwnsUserScript(int embedder_process_id, | |
56 int view_instance_id, | |
57 int script_id); | |
58 | |
59 // Returns the content script IDs added by the guest specified by | |
60 // |embedder_process_id, view_instance_id|. | |
61 std::set<int> GetContentScriptIDSet(int embedder_process_id, | |
62 int view_instance_id); | |
63 | |
64 private: | |
65 class OwnerWebContentsObserver; | |
66 | |
67 using GuestMapKey = std::pair<int, int>; | |
68 using ContentScriptMap = std::map<std::string, extensions::UserScript>; | |
69 using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>; | |
70 | |
71 using OwnerWebContentsObserverMap = | |
72 std::map<content::WebContents*, linked_ptr<OwnerWebContentsObserver>>; | |
73 | |
74 // Removes contents scripts from all the guests owned by the given embedder, | |
75 // which is specified by |embedder_web_content|. | |
76 // Called by OwnerWebContentsObserver when the observer sees a main frame | |
77 // navigation or sees the process has went away or the |embedder_web_contents| | |
78 // is being destroyed. | |
79 void RemoveContentScripts(content::WebContents* embedder_web_contents, | |
80 const HostID& host_id); | |
81 | |
82 OwnerWebContentsObserverMap owner_web_contents_observer_map_; | |
83 | |
84 GuestContentScriptMap guest_content_script_map_; | |
85 | |
86 content::BrowserContext* browser_context_; | |
Devlin
2015/04/13 19:21:48
DISALLOW_COPY_AND_ASSIGN
Xi Han
2015/04/14 19:05:52
Done.
| |
87 }; | |
88 | |
89 } // namespace extensions | |
90 | |
91 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGE R_H | |
OLD | NEW |