blob: 7542ba398da887b6f82e00b318ed867e5c469be7 [file] [log] [blame]
[email protected]15ad2ee2014-08-15 19:15:261// 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
hanxi3b2b3df2015-02-24 15:28:075#ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
6#define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
[email protected]15ad2ee2014-08-15 19:15:267
dchengf5d241082016-04-21 03:43:118#include <memory>
hanxifeb6a64f2015-04-24 19:21:409#include <set>
10
avic9cec102015-12-23 00:39:2611#include "base/macros.h"
[email protected]15ad2ee2014-08-15 19:15:2612#include "base/scoped_observer.h"
hanxifeb6a64f2015-04-24 19:21:4013#include "extensions/common/host_id.h"
[email protected]15ad2ee2014-08-15 19:15:2614
hanxi3b2b3df2015-02-24 15:28:0715namespace content {
16class BrowserContext;
17}
[email protected]15ad2ee2014-08-15 19:15:2618
19namespace extensions {
20
[email protected]15ad2ee2014-08-15 19:15:2621class UserScript;
hanxifeb6a64f2015-04-24 19:21:4022class UserScriptLoader;
[email protected]15ad2ee2014-08-15 19:15:2623
lazyboy48847052016-08-12 22:37:2324struct UserScriptIDPair;
25
[email protected]15ad2ee2014-08-15 19:15:2626// 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.
hanxic0503d72015-02-05 14:27:3230class DeclarativeUserScriptMaster {
[email protected]15ad2ee2014-08-15 19:15:2631 public:
hanxi3b2b3df2015-02-24 15:28:0732 DeclarativeUserScriptMaster(content::BrowserContext* browser_context,
33 const HostID& host_id);
hanxic0503d72015-02-05 14:27:3234 ~DeclarativeUserScriptMaster();
[email protected]15ad2ee2014-08-15 19:15:2635
36 // Adds script to shared memory region. This may not happen right away if a
37 // script load is in progress.
lazyboy12c77d72016-08-19 20:06:0938 void AddScript(std::unique_ptr<UserScript> script);
[email protected]15ad2ee2014-08-15 19:15:2639
hanxifeb6a64f2015-04-24 19:21:4040 // 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.cronincfd9cd22016-08-10 20:50:0742 // render specified by |render_process_id, render_frame_id|.
hanxifeb6a64f2015-04-24 19:21:4043 // This may not happen right away if a script load is in progress.
lazyboy12c77d72016-08-19 20:06:0944 void AddScripts(
45 std::unique_ptr<std::vector<std::unique_ptr<UserScript>>> scripts,
46 int render_process_id,
47 int render_frame_id);
hanxi05a025052015-04-16 19:15:3248
[email protected]15ad2ee2014-08-15 19:15:2649 // Removes script from shared memory region. This may not happen right away if
50 // a script load is in progress.
lazyboy12c77d72016-08-19 20:06:0951 void RemoveScript(const UserScriptIDPair& script);
[email protected]15ad2ee2014-08-15 19:15:2652
hanxi05a025052015-04-16 19:15:3253 // Removes a set of scripts from shared memory region. This may not happen
54 // right away if a script load is in progress.
lazyboy48847052016-08-12 22:37:2355 void RemoveScripts(const std::set<UserScriptIDPair>& scripts);
hanxi05a025052015-04-16 19:15:3256
[email protected]15ad2ee2014-08-15 19:15:2657 // 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
hanxic0503d72015-02-05 14:27:3261 const HostID& host_id() const { return host_id_; }
[email protected]15ad2ee2014-08-15 19:15:2662
hanxi9bd85fa2015-05-05 19:55:0063 UserScriptLoader* loader() { return loader_.get(); }
64
[email protected]15ad2ee2014-08-15 19:15:2665 private:
hanxic0503d72015-02-05 14:27:3266 // ID of host that owns scripts that this component manages.
67 HostID host_id_;
[email protected]15ad2ee2014-08-15 19:15:2668
69 // Script loader that handles loading contents of scripts into shared memory
70 // and notifying renderers of script updates.
dchengf5d241082016-04-21 03:43:1171 std::unique_ptr<UserScriptLoader> loader_;
[email protected]15ad2ee2014-08-15 19:15:2672
73 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster);
74};
75
76} // namespace extensions
77
hanxi3b2b3df2015-02-24 15:28:0778#endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_