[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 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 | |||||
hanxi | 3b2b3df | 2015-02-24 15:28:07 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ |
6 | #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ | ||||
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 7 | |
dcheng | f5d24108 | 2016-04-21 03:43:11 | [diff] [blame] | 8 | #include <memory> |
hanxi | feb6a64f | 2015-04-24 19:21:40 | [diff] [blame] | 9 | #include <set> |
10 | |||||
avi | c9cec10 | 2015-12-23 00:39:26 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 12 | #include "base/scoped_observer.h" |
hanxi | feb6a64f | 2015-04-24 19:21:40 | [diff] [blame] | 13 | #include "extensions/common/host_id.h" |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 14 | |
hanxi | 3b2b3df | 2015-02-24 15:28:07 | [diff] [blame] | 15 | namespace content { |
16 | class BrowserContext; | ||||
17 | } | ||||
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 18 | |
19 | namespace extensions { | ||||
20 | |||||
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 21 | class UserScript; |
hanxi | feb6a64f | 2015-04-24 19:21:40 | [diff] [blame] | 22 | class UserScriptLoader; |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 23 | |
lazyboy | 4884705 | 2016-08-12 22:37:23 | [diff] [blame] | 24 | struct UserScriptIDPair; |
25 | |||||
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 26 | // Manages declarative user scripts for a single extension. Owns a |
27 | // UserScriptLoader to which file loading and shared memory management | ||||
28 | // operations are delegated, and provides an interface for adding, removing, | ||||
29 | // and clearing scripts. | ||||
hanxi | c0503d7 | 2015-02-05 14:27:32 | [diff] [blame] | 30 | class DeclarativeUserScriptMaster { |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 31 | public: |
hanxi | 3b2b3df | 2015-02-24 15:28:07 | [diff] [blame] | 32 | DeclarativeUserScriptMaster(content::BrowserContext* browser_context, |
33 | const HostID& host_id); | ||||
hanxi | c0503d7 | 2015-02-05 14:27:32 | [diff] [blame] | 34 | ~DeclarativeUserScriptMaster(); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 35 | |
36 | // Adds script to shared memory region. This may not happen right away if a | ||||
37 | // script load is in progress. | ||||
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 38 | void AddScript(std::unique_ptr<UserScript> script); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 39 | |
hanxi | feb6a64f | 2015-04-24 19:21:40 | [diff] [blame] | 40 | // Adds a set of scripts to shared meomory region. The fetch of the content |
41 | // of the script on WebUI requires to start URL request to the associated | ||||
rdevlin.cronin | cfd9cd2 | 2016-08-10 20:50:07 | [diff] [blame] | 42 | // render specified by |render_process_id, render_frame_id|. |
hanxi | feb6a64f | 2015-04-24 19:21:40 | [diff] [blame] | 43 | // This may not happen right away if a script load is in progress. |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 44 | void AddScripts( |
45 | std::unique_ptr<std::vector<std::unique_ptr<UserScript>>> scripts, | ||||
46 | int render_process_id, | ||||
47 | int render_frame_id); | ||||
hanxi | 05a02505 | 2015-04-16 19:15:32 | [diff] [blame] | 48 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 49 | // Removes script from shared memory region. This may not happen right away if |
50 | // a script load is in progress. | ||||
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 51 | void RemoveScript(const UserScriptIDPair& script); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 52 | |
hanxi | 05a02505 | 2015-04-16 19:15:32 | [diff] [blame] | 53 | // Removes a set of scripts from shared memory region. This may not happen |
54 | // right away if a script load is in progress. | ||||
lazyboy | 4884705 | 2016-08-12 22:37:23 | [diff] [blame] | 55 | void RemoveScripts(const std::set<UserScriptIDPair>& scripts); |
hanxi | 05a02505 | 2015-04-16 19:15:32 | [diff] [blame] | 56 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 57 | // Removes all scripts from shared memory region. This may not happen right |
58 | // away if a script load is in progress. | ||||
59 | void ClearScripts(); | ||||
60 | |||||
hanxi | c0503d7 | 2015-02-05 14:27:32 | [diff] [blame] | 61 | const HostID& host_id() const { return host_id_; } |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 62 | |
hanxi | 9bd85fa | 2015-05-05 19:55:00 | [diff] [blame] | 63 | UserScriptLoader* loader() { return loader_.get(); } |
64 | |||||
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 65 | private: |
hanxi | c0503d7 | 2015-02-05 14:27:32 | [diff] [blame] | 66 | // ID of host that owns scripts that this component manages. |
67 | HostID host_id_; | ||||
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 68 | |
69 | // Script loader that handles loading contents of scripts into shared memory | ||||
70 | // and notifying renderers of script updates. | ||||
dcheng | f5d24108 | 2016-04-21 03:43:11 | [diff] [blame] | 71 | std::unique_ptr<UserScriptLoader> loader_; |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 72 | |
73 | DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster); | ||||
74 | }; | ||||
75 | |||||
76 | } // namespace extensions | ||||
77 | |||||
hanxi | 3b2b3df | 2015-02-24 15:28:07 | [diff] [blame] | 78 | #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ |