Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: extensions/browser/extension_user_script_loader.h

Issue 1056533002: Implement <webview>.addContentScript/removeContentScript API [2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webview_addremove_contentscripts_2
Patch Set: nits. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_ 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_ 6 #define EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_
7 7
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "extensions/browser/extension_registry_observer.h" 9 #include "extensions/browser/extension_registry_observer.h"
10 #include "extensions/browser/user_script_loader.h" 10 #include "extensions/browser/user_script_loader.h"
11 #include "extensions/common/extension.h" 11 #include "extensions/common/extension.h"
12 12
13 namespace content { 13 namespace content {
14 class BrowserContext; 14 class BrowserContext;
15 } 15 }
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 class ContentVerifier;
19 class ExtensionRegistry; 20 class ExtensionRegistry;
20 21
21 // UserScriptLoader for extensions. 22 // UserScriptLoader for extensions.
22 class ExtensionUserScriptLoader : public UserScriptLoader, 23 class ExtensionUserScriptLoader : public UserScriptLoader,
23 public ExtensionRegistryObserver { 24 public ExtensionRegistryObserver {
24 public: 25 public:
26 using PathAndDefaultLocale = std::pair<base::FilePath, std::string>;
27 using HostsInfo = std::map<HostID, PathAndDefaultLocale>;
28
25 // The listen_for_extension_system_loaded is only set true when initilizing 29 // The listen_for_extension_system_loaded is only set true when initilizing
26 // the Extension System, e.g, when constructs SharedUserScriptMaster in 30 // the Extension System, e.g, when constructs SharedUserScriptMaster in
27 // ExtensionSystemImpl. 31 // ExtensionSystemImpl.
28 ExtensionUserScriptLoader(content::BrowserContext* browser_context, 32 ExtensionUserScriptLoader(content::BrowserContext* browser_context,
29 const HostID& host_id, 33 const HostID& host_id,
30 bool listen_for_extension_system_loaded); 34 bool listen_for_extension_system_loaded);
31 ~ExtensionUserScriptLoader() override; 35 ~ExtensionUserScriptLoader() override;
32 36
37 // A wrapper around the method to load user scripts, which is normally run on
38 // the file thread. Exposed only for tests.
39 void LoadScriptsForTest(UserScriptList* user_scripts);
40
33 private: 41 private:
34 // UserScriptLoader: 42 // UserScriptLoader:
35 void UpdateHostsInfo(const std::set<HostID>& changed_hosts) override; 43 void LoadScripts(scoped_ptr<UserScriptList> user_scripts,
36 LoadUserScriptsContentFunction GetLoadUserScriptsFunction() override; 44 const std::set<HostID>& changed_hosts,
45 const std::set<int>& added_script_ids,
46 LoadScriptsCallback callback) override;
47
48 // Updates |hosts_info_| to contain info for each element of
49 // |changed_hosts_|.
50 void UpdateHostsInfo(const std::set<HostID>& changed_hosts);
37 51
38 // ExtensionRegistryObserver: 52 // ExtensionRegistryObserver:
39 void OnExtensionUnloaded(content::BrowserContext* browser_context, 53 void OnExtensionUnloaded(content::BrowserContext* browser_context,
40 const Extension* extension, 54 const Extension* extension,
41 UnloadedExtensionInfo::Reason reason) override; 55 UnloadedExtensionInfo::Reason reason) override;
42 56
43 // Initiates script load when we have been waiting for the extension system 57 // Initiates script load when we have been waiting for the extension system
44 // to be ready. 58 // to be ready.
45 void OnExtensionSystemReady(); 59 void OnExtensionSystemReady();
46 60
61 // Maps host info needed for localization to a host ID.
62 HostsInfo hosts_info_;
63
64 // Manages content verification of the loaded user scripts.
65 scoped_refptr<ContentVerifier> content_verifier_;
66
47 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 67 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
48 extension_registry_observer_; 68 extension_registry_observer_;
49 69
50 base::WeakPtrFactory<ExtensionUserScriptLoader> weak_factory_; 70 base::WeakPtrFactory<ExtensionUserScriptLoader> weak_factory_;
51 71
52 DISALLOW_COPY_AND_ASSIGN(ExtensionUserScriptLoader); 72 DISALLOW_COPY_AND_ASSIGN(ExtensionUserScriptLoader);
53 }; 73 };
54 74
55 } // namespace extensions 75 } // namespace extensions
56 76
57 #endif // EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_ 77 #endif // EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_
OLDNEW
« no previous file with comments | « extensions/browser/declarative_user_script_master.cc ('k') | extensions/browser/extension_user_script_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698