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

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: Clean up. 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 ExtensionRegistry; 19 class ExtensionRegistry;
20 20
21 // UserScriptLoader for extensions. 21 // UserScriptLoader for extensions.
22 class ExtensionUserScriptLoader : public UserScriptLoader, 22 class ExtensionUserScriptLoader : public UserScriptLoader,
23 public ExtensionRegistryObserver { 23 public ExtensionRegistryObserver {
24 public: 24 public:
25 using PathAndDefaultLocale = std::pair<base::FilePath, std::string>;
Devlin 2015/04/24 17:50:59 Why do these need to be public? And can't Substit
Xi Han 2015/04/24 18:28:54 There are several functions in the anonymous names
26 using HostsInfo = std::map<HostID, PathAndDefaultLocale>;
27
28 using SubstitutionMap = std::map<std::string, std::string>;
29
25 // The listen_for_extension_system_loaded is only set true when initilizing 30 // The listen_for_extension_system_loaded is only set true when initilizing
26 // the Extension System, e.g, when constructs SharedUserScriptMaster in 31 // the Extension System, e.g, when constructs SharedUserScriptMaster in
27 // ExtensionSystemImpl. 32 // ExtensionSystemImpl.
28 ExtensionUserScriptLoader(content::BrowserContext* browser_context, 33 ExtensionUserScriptLoader(content::BrowserContext* browser_context,
29 const HostID& host_id, 34 const HostID& host_id,
30 bool listen_for_extension_system_loaded); 35 bool listen_for_extension_system_loaded);
31 ~ExtensionUserScriptLoader() override; 36 ~ExtensionUserScriptLoader() override;
32 37
38 // A wrapper around the method to load user scripts, which is normally run on
39 // the file thread. Exposed only for tests.
40 void LoadScriptsForTest(UserScriptList* user_scripts);
41
33 private: 42 private:
34 // UserScriptLoader: 43 // UserScriptLoader:
35 void UpdateHostsInfo(const std::set<HostID>& changed_hosts) override; 44 void LoadScripts(scoped_ptr<UserScriptList> user_scripts,
36 LoadUserScriptsContentFunction GetLoadUserScriptsFunction() override; 45 const std::set<HostID>& changed_hosts,
46 const std::set<int>& added_script_ids,
47 LoadScriptsCallback callback) override;
48
49 // Updates |hosts_info_| to contain info for each element of
50 // |changed_hosts_|.
51 void UpdateHostsInfo(const std::set<HostID>& changed_hosts);
37 52
38 // ExtensionRegistryObserver: 53 // ExtensionRegistryObserver:
39 void OnExtensionUnloaded(content::BrowserContext* browser_context, 54 void OnExtensionUnloaded(content::BrowserContext* browser_context,
40 const Extension* extension, 55 const Extension* extension,
41 UnloadedExtensionInfo::Reason reason) override; 56 UnloadedExtensionInfo::Reason reason) override;
42 57
43 // Initiates script load when we have been waiting for the extension system 58 // Initiates script load when we have been waiting for the extension system
44 // to be ready. 59 // to be ready.
45 void OnExtensionSystemReady(); 60 void OnExtensionSystemReady();
46 61
62 // Maps host info needed for localization to a host ID.
63 HostsInfo hosts_info_;
64
65 // Manages content verification of the loaded user scripts.
66 scoped_refptr<ContentVerifier> content_verifier_;
67
47 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 68 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
48 extension_registry_observer_; 69 extension_registry_observer_;
49 70
50 base::WeakPtrFactory<ExtensionUserScriptLoader> weak_factory_; 71 base::WeakPtrFactory<ExtensionUserScriptLoader> weak_factory_;
51 72
52 DISALLOW_COPY_AND_ASSIGN(ExtensionUserScriptLoader); 73 DISALLOW_COPY_AND_ASSIGN(ExtensionUserScriptLoader);
53 }; 74 };
54 75
55 } // namespace extensions 76 } // namespace extensions
56 77
57 #endif // EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_ 78 #endif // EXTENSIONS_BROWSER_EXTENSION_USER_SCRIPT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698