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 "chrome/browser/renderer_host/chrome_extension_message_filter.h" | 5 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h" | 21 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h" |
22 #include "chrome/browser/extensions/api/messaging/message_service.h" | 22 #include "chrome/browser/extensions/api/messaging/message_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/common/extensions/chrome_extension_messages.h" | 25 #include "chrome/common/extensions/chrome_extension_messages.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
28 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
29 #include "extensions/common/api/messaging/message.h" | 29 #include "extensions/common/api/messaging/message.h" |
30 #include "extensions/common/extension_messages.h" | 30 #include "extensions/common/extension_messages.h" |
31 #include "extensions/common/extension_set.h" | |
31 #include "extensions/common/file_util.h" | 32 #include "extensions/common/file_util.h" |
32 #include "extensions/common/manifest_handlers/default_locale_handler.h" | 33 #include "extensions/common/manifest_handlers/default_locale_handler.h" |
34 #include "extensions/common/manifest_handlers/shared_module_info.h" | |
33 #include "extensions/common/message_bundle.h" | 35 #include "extensions/common/message_bundle.h" |
34 | 36 |
35 using content::BrowserThread; | 37 using content::BrowserThread; |
36 | 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 const uint32_t kFilteredMessageClasses[] = { | 41 const uint32_t kFilteredMessageClasses[] = { |
40 ChromeExtensionMsgStart, ExtensionMsgStart, | 42 ChromeExtensionMsgStart, ExtensionMsgStart, |
41 }; | 43 }; |
42 | 44 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 const extensions::PortId& port_id, | 194 const extensions::PortId& port_id, |
193 const extensions::Message& message) { | 195 const extensions::Message& message) { |
194 if (!profile_) | 196 if (!profile_) |
195 return; | 197 return; |
196 | 198 |
197 extensions::MessageService::Get(profile_)->PostMessage(port_id, message); | 199 extensions::MessageService::Get(profile_)->PostMessage(port_id, message); |
198 } | 200 } |
199 | 201 |
200 void ChromeExtensionMessageFilter::OnGetExtMessageBundle( | 202 void ChromeExtensionMessageFilter::OnGetExtMessageBundle( |
201 const std::string& extension_id, IPC::Message* reply_msg) { | 203 const std::string& extension_id, IPC::Message* reply_msg) { |
204 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
205 | |
206 const extensions::ExtensionSet& extension_set = | |
207 extension_info_map_->extensions(); | |
208 const extensions::Extension* extension = extension_set.GetByID(extension_id); | |
209 | |
210 if (!extension) { // The extension has gone. | |
211 ExtensionHostMsg_GetMessageBundle::WriteReplyParams( | |
212 reply_msg, extensions::MessageBundle::SubstitutionMap()); | |
213 Send(reply_msg); | |
214 return; | |
215 } | |
216 | |
217 std::vector<base::FilePath> paths_to_load; | |
218 paths_to_load.push_back(extension->path()); | |
219 | |
220 auto imports = extensions::SharedModuleInfo::GetImports(extension); | |
221 // Iterate through the imports in reverse. This will allow later imported | |
222 // modules to override earlier imported modules, as the list order is | |
223 // maintained from the definition in manifest.json of the imports. | |
224 for (auto it = imports.rbegin(); it != imports.rend(); ++it) { | |
225 const extensions::Extension* imported_extension = | |
226 extension_set.GetByID(it->extension_id); | |
227 if (!imported_extension) { | |
228 NOTREACHED() << "Missing shared module " << it->extension_id; | |
229 continue; | |
230 } | |
231 paths_to_load.push_back(imported_extension->path()); | |
232 } | |
233 | |
234 const std::string default_locale = | |
Devlin
2017/02/16 16:20:56
nit: const std::string&
atuchin
2017/02/17 06:22:02
Done.
| |
235 extensions::LocaleInfo::GetDefaultLocale(extension); | |
236 if (default_locale.empty()) { | |
237 // A little optimization: send the answer here to avoid an extra thread | |
238 // hope. | |
Devlin
2017/02/16 16:20:56
typo: s/hope/hop.
atuchin
2017/02/17 06:22:02
Done.
| |
239 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( | |
240 extensions::file_util::LoadNonLocalizedMessageBundleSubstitutionMap( | |
241 extension_id)); | |
242 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, | |
243 *dictionary_map); | |
244 Send(reply_msg); | |
245 return; | |
246 } | |
247 | |
202 BrowserThread::PostBlockingPoolTask( | 248 BrowserThread::PostBlockingPoolTask( |
203 FROM_HERE, | 249 FROM_HERE, |
204 base::Bind( | 250 base::Bind( |
205 &ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool, | 251 &ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool, |
206 this, extension_id, reply_msg)); | 252 this, paths_to_load, extension_id, default_locale, reply_msg)); |
207 } | 253 } |
208 | 254 |
209 void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool( | 255 void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool( |
210 const std::string& extension_id, | 256 const std::vector<base::FilePath>& extension_paths, |
257 const std::string& main_extension_id, | |
258 const std::string& default_locale, | |
211 IPC::Message* reply_msg) { | 259 IPC::Message* reply_msg) { |
212 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 260 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
213 | 261 |
214 const extensions::ExtensionSet& extension_set = | |
215 extension_info_map_->extensions(); | |
216 | |
217 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( | 262 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( |
218 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports( | 263 extensions::file_util::LoadMessageBundleSubstitutionMapFromPaths( |
219 extension_id, extension_set)); | 264 extension_paths, main_extension_id, default_locale)); |
220 | 265 |
221 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, | 266 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, |
222 *dictionary_map); | 267 *dictionary_map); |
223 Send(reply_msg); | 268 Send(reply_msg); |
224 } | 269 } |
225 | 270 |
226 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( | 271 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( |
227 const std::string& extension_id, | 272 const std::string& extension_id, |
228 const ExtensionHostMsg_APIActionOrEvent_Params& params) { | 273 const ExtensionHostMsg_APIActionOrEvent_Params& params) { |
229 if (!ShouldLogExtensionAction(extension_id)) | 274 if (!ShouldLogExtensionAction(extension_id)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( | 331 bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( |
287 const std::string& extension_id) const { | 332 const std::string& extension_id) const { |
288 // We only send these IPCs if activity logging is enabled, but due to race | 333 // We only send these IPCs if activity logging is enabled, but due to race |
289 // conditions (e.g. logging gets disabled but the renderer sends the message | 334 // conditions (e.g. logging gets disabled but the renderer sends the message |
290 // before it gets updated), we still need this check here. | 335 // before it gets updated), we still need this check here. |
291 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
292 return profile_ && | 337 return profile_ && |
293 g_browser_process->profile_manager()->IsValidProfile(profile_) && | 338 g_browser_process->profile_manager()->IsValidProfile(profile_) && |
294 activity_log_ && activity_log_->ShouldLog(extension_id); | 339 activity_log_ && activity_log_->ShouldLog(extension_id); |
295 } | 340 } |
OLD | NEW |