Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / declarative_user_script_master.h
blobeb27b0c0c6c7fc58b109e05d75fb61c47eb717fa
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_DECLARATIVE_USER_SCRIPT_MASTER_H_
6 #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
8 #include <set>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "extensions/common/host_id.h"
14 namespace content {
15 class BrowserContext;
18 namespace extensions {
20 class UserScript;
21 class UserScriptLoader;
23 // Manages declarative user scripts for a single extension. Owns a
24 // UserScriptLoader to which file loading and shared memory management
25 // operations are delegated, and provides an interface for adding, removing,
26 // and clearing scripts.
27 class DeclarativeUserScriptMaster {
28 public:
29 DeclarativeUserScriptMaster(content::BrowserContext* browser_context,
30 const HostID& host_id);
31 ~DeclarativeUserScriptMaster();
33 // Adds script to shared memory region. This may not happen right away if a
34 // script load is in progress.
35 void AddScript(const UserScript& script);
37 // Adds a set of scripts to shared meomory region. The fetch of the content
38 // of the script on WebUI requires to start URL request to the associated
39 // render specified by |render_process_id, render_view_id|.
40 // This may not happen right away if a script load is in progress.
41 void AddScripts(const std::set<UserScript>& scripts,
42 int render_process_id,
43 int render_view_id);
45 // Removes script from shared memory region. This may not happen right away if
46 // a script load is in progress.
47 void RemoveScript(const UserScript& script);
49 // Removes a set of scripts from shared memory region. This may not happen
50 // right away if a script load is in progress.
51 void RemoveScripts(const std::set<UserScript>& scripts);
53 // Removes all scripts from shared memory region. This may not happen right
54 // away if a script load is in progress.
55 void ClearScripts();
57 const HostID& host_id() const { return host_id_; }
59 UserScriptLoader* loader() { return loader_.get(); }
61 private:
62 // ID of host that owns scripts that this component manages.
63 HostID host_id_;
65 // Script loader that handles loading contents of scripts into shared memory
66 // and notifying renderers of script updates.
67 scoped_ptr<UserScriptLoader> loader_;
69 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster);
72 } // namespace extensions
74 #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_