OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/declarative_user_script_master.h" | 5 #include "extensions/browser/declarative_user_script_master.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 10 #include "extensions/browser/extension_user_script_loader.h" |
| 11 #include "extensions/browser/web_ui_user_script_loader.h" |
10 | 12 |
11 namespace extensions { | 13 namespace extensions { |
12 | 14 |
13 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster( | 15 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster( |
14 content::BrowserContext* browser_context, | 16 content::BrowserContext* browser_context, |
15 const HostID& host_id) | 17 const HostID& host_id) |
16 : host_id_(host_id), | 18 : host_id_(host_id) { |
17 loader_(browser_context, | 19 switch (host_id_.type()) { |
18 host_id, | 20 case HostID::EXTENSIONS: |
19 false /* listen_for_extension_system_loaded */) { | 21 loader_.reset(new ExtensionUserScriptLoader( |
| 22 browser_context, host_id, |
| 23 false /* listen_for_extension_system_loaded */)); |
| 24 break; |
| 25 case HostID::WEBUI: |
| 26 loader_.reset(new WebUIUserScriptLoader(browser_context, host_id)); |
| 27 break; |
| 28 } |
20 } | 29 } |
21 | 30 |
22 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { | 31 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { |
23 } | 32 } |
24 | 33 |
25 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) { | 34 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) { |
26 std::set<UserScript> set; | 35 std::set<UserScript> set; |
27 set.insert(script); | 36 set.insert(script); |
28 loader_.AddScripts(set); | 37 loader_->AddScripts(set); |
29 } | 38 } |
30 | 39 |
31 void DeclarativeUserScriptMaster::AddScripts( | 40 void DeclarativeUserScriptMaster::AddScripts( |
32 const std::set<UserScript>& scripts) { | 41 const std::set<UserScript>& scripts, |
33 loader_.AddScripts(scripts); | 42 int render_process_id, |
| 43 int render_view_id) { |
| 44 loader_->AddScripts(scripts, render_process_id, render_view_id); |
34 } | 45 } |
35 | 46 |
36 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) { | 47 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) { |
37 std::set<UserScript> set; | 48 std::set<UserScript> set; |
38 set.insert(script); | 49 set.insert(script); |
39 loader_.RemoveScripts(set); | 50 loader_->RemoveScripts(set); |
40 } | 51 } |
41 | 52 |
42 void DeclarativeUserScriptMaster::RemoveScripts( | 53 void DeclarativeUserScriptMaster::RemoveScripts( |
43 const std::set<UserScript>& scripts) { | 54 const std::set<UserScript>& scripts) { |
44 loader_.RemoveScripts(scripts); | 55 loader_->RemoveScripts(scripts); |
45 } | 56 } |
46 | 57 |
47 void DeclarativeUserScriptMaster::ClearScripts() { | 58 void DeclarativeUserScriptMaster::ClearScripts() { |
48 loader_.ClearScripts(); | 59 loader_->ClearScripts(true); |
49 } | 60 } |
50 | 61 |
51 } // namespace extensions | 62 } // namespace extensions |
OLD | NEW |