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 = | |
235 extensions::LocaleInfo::GetDefaultLocale(extension); | |
236 if (default_locale.empty()) { | |
Devlin
2017/02/17 15:57:38
nit: Let's actually move this above finding the pa
atuchin
2017/02/17 16:22:46
Done.
| |
237 // A little optimization: send the answer here to avoid an extra thread hop. | |
238 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( | |
239 extensions::file_util::LoadNonLocalizedMessageBundleSubstitutionMap( | |
240 extension_id)); | |
241 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, | |
242 *dictionary_map); | |
243 Send(reply_msg); | |
244 return; | |
245 } | |
246 | |
202 BrowserThread::PostBlockingPoolTask( | 247 BrowserThread::PostBlockingPoolTask( |
203 FROM_HERE, | 248 FROM_HERE, |
204 base::Bind( | 249 base::Bind( |
205 &ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool, | 250 &ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool, |
206 this, extension_id, reply_msg)); | 251 this, paths_to_load, extension_id, default_locale, reply_msg)); |
207 } | 252 } |
208 | 253 |
209 void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool( | 254 void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool( |
210 const std::string& extension_id, | 255 const std::vector<base::FilePath>& extension_paths, |
256 const std::string& main_extension_id, | |
257 const std::string& default_locale, | |
211 IPC::Message* reply_msg) { | 258 IPC::Message* reply_msg) { |
212 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 259 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
213 | 260 |
214 const extensions::ExtensionSet& extension_set = | |
215 extension_info_map_->extensions(); | |
216 | |
217 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( | 261 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( |
218 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports( | 262 extensions::file_util::LoadMessageBundleSubstitutionMapFromPaths( |
219 extension_id, extension_set)); | 263 extension_paths, main_extension_id, default_locale)); |
220 | 264 |
221 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, | 265 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, |
222 *dictionary_map); | 266 *dictionary_map); |
223 Send(reply_msg); | 267 Send(reply_msg); |
224 } | 268 } |
225 | 269 |
226 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( | 270 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( |
227 const std::string& extension_id, | 271 const std::string& extension_id, |
228 const ExtensionHostMsg_APIActionOrEvent_Params& params) { | 272 const ExtensionHostMsg_APIActionOrEvent_Params& params) { |
229 if (!ShouldLogExtensionAction(extension_id)) | 273 if (!ShouldLogExtensionAction(extension_id)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( | 330 bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( |
287 const std::string& extension_id) const { | 331 const std::string& extension_id) const { |
288 // We only send these IPCs if activity logging is enabled, but due to race | 332 // 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 | 333 // conditions (e.g. logging gets disabled but the renderer sends the message |
290 // before it gets updated), we still need this check here. | 334 // before it gets updated), we still need this check here. |
291 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 335 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
292 return profile_ && | 336 return profile_ && |
293 g_browser_process->profile_manager()->IsValidProfile(profile_) && | 337 g_browser_process->profile_manager()->IsValidProfile(profile_) && |
294 activity_log_ && activity_log_->ShouldLog(extension_id); | 338 activity_log_ && activity_log_->ShouldLog(extension_id); |
295 } | 339 } |
OLD | NEW |