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

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

Issue 955473002: Move DeclarativeUserScriptManager/Master and UserScriptLoader to //extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 #include "chrome/browser/extensions/extension_user_script_loader.h" 5 #include "extensions/browser/extension_user_script_loader.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
19 #include "extensions/browser/component_extension_resource_manager.h" 19 #include "extensions/browser/component_extension_resource_manager.h"
20 #include "extensions/browser/content_verifier.h" 20 #include "extensions/browser/content_verifier.h"
21 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/extensions_browser_client.h" 23 #include "extensions/browser/extensions_browser_client.h"
24 #include "extensions/common/file_util.h" 24 #include "extensions/common/file_util.h"
25 #include "extensions/common/manifest_handlers/default_locale_handler.h" 25 #include "extensions/common/manifest_handlers/default_locale_handler.h"
26 #include "extensions/common/message_bundle.h" 26 #include "extensions/common/message_bundle.h"
27 #include "extensions/common/one_shot_event.h" 27 #include "extensions/common/one_shot_event.h"
28 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
29 29
30 using content::BrowserContext;
31
30 namespace extensions { 32 namespace extensions {
31 33
32 namespace { 34 namespace {
33 35
34 // Verifies file contents as they are read. 36 // Verifies file contents as they are read.
35 void VerifyContent(const scoped_refptr<ContentVerifier>& verifier, 37 void VerifyContent(const scoped_refptr<ContentVerifier>& verifier,
36 const std::string& extension_id, 38 const std::string& extension_id,
37 const base::FilePath& extension_root, 39 const base::FilePath& extension_root,
38 const base::FilePath& relative_path, 40 const base::FilePath& relative_path,
39 const std::string& content) { 41 const std::string& content) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 script_file->set_content(content.substr(strlen(base::kUtf8ByteOrderMark))); 104 script_file->set_content(content.substr(strlen(base::kUtf8ByteOrderMark)));
103 else 105 else
104 script_file->set_content(content); 106 script_file->set_content(content);
105 107
106 return true; 108 return true;
107 } 109 }
108 110
109 } // namespace 111 } // namespace
110 112
111 ExtensionUserScriptLoader::ExtensionUserScriptLoader( 113 ExtensionUserScriptLoader::ExtensionUserScriptLoader(
112 Profile* profile, 114 BrowserContext* browser_context,
113 const HostID& host_id, 115 const HostID& host_id,
114 bool listen_for_extension_system_loaded) 116 bool listen_for_extension_system_loaded)
115 : UserScriptLoader(profile, 117 : UserScriptLoader(
116 host_id, 118 browser_context,
117 ExtensionSystem::Get(profile)->content_verifier()), 119 host_id,
120 ExtensionSystem::Get(browser_context)->content_verifier()),
118 extension_registry_observer_(this), 121 extension_registry_observer_(this),
119 weak_factory_(this) { 122 weak_factory_(this) {
120 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); 123 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context));
121 if (listen_for_extension_system_loaded) { 124 if (listen_for_extension_system_loaded) {
122 ExtensionSystem::Get(profile)->ready().Post( 125 ExtensionSystem::Get(browser_context)
123 FROM_HERE, 126 ->ready()
124 base::Bind(&ExtensionUserScriptLoader::OnExtensionSystemReady, 127 .Post(FROM_HERE,
125 weak_factory_.GetWeakPtr())); 128 base::Bind(&ExtensionUserScriptLoader::OnExtensionSystemReady,
129 weak_factory_.GetWeakPtr()));
126 } else { 130 } else {
127 SetReady(true); 131 SetReady(true);
128 } 132 }
129 } 133 }
130 134
131 ExtensionUserScriptLoader::~ExtensionUserScriptLoader() { 135 ExtensionUserScriptLoader::~ExtensionUserScriptLoader() {
132 } 136 }
133 137
134 void ExtensionUserScriptLoader::UpdateHostsInfo( 138 void ExtensionUserScriptLoader::UpdateHostsInfo(
135 const std::set<HostID>& changed_hosts) { 139 const std::set<HostID>& changed_hosts) {
136 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 140 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context());
137 for (const HostID& host_id : changed_hosts) { 141 for (const HostID& host_id : changed_hosts) {
138 const Extension* extension = 142 const Extension* extension =
139 registry->GetExtensionById(host_id.id(), ExtensionRegistry::ENABLED); 143 registry->GetExtensionById(host_id.id(), ExtensionRegistry::ENABLED);
140 // |changed_hosts_| may include hosts that have been removed, 144 // |changed_hosts_| may include hosts that have been removed,
141 // which leads to the above lookup failing. In this case, just continue. 145 // which leads to the above lookup failing. In this case, just continue.
142 if (!extension) 146 if (!extension)
143 continue; 147 continue;
144 AddHostInfo(host_id, ExtensionSet::ExtensionPathAndDefaultLocale( 148 AddHostInfo(host_id, ExtensionSet::ExtensionPathAndDefaultLocale(
145 extension->path(), 149 extension->path(),
146 LocaleInfo::GetDefaultLocale(extension))); 150 LocaleInfo::GetDefaultLocale(extension)));
(...skipping 10 matching lines...) Expand all
157 const Extension* extension, 161 const Extension* extension,
158 UnloadedExtensionInfo::Reason reason) { 162 UnloadedExtensionInfo::Reason reason) {
159 RemoveHostInfo(HostID(HostID::EXTENSIONS, extension->id())); 163 RemoveHostInfo(HostID(HostID::EXTENSIONS, extension->id()));
160 } 164 }
161 165
162 void ExtensionUserScriptLoader::OnExtensionSystemReady() { 166 void ExtensionUserScriptLoader::OnExtensionSystemReady() {
163 SetReady(true); 167 SetReady(true);
164 } 168 }
165 169
166 } // namespace extensions 170 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_user_script_loader.h ('k') | extensions/browser/user_script_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698