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 | |
202 BrowserThread::PostBlockingPoolTask( | 234 BrowserThread::PostBlockingPoolTask( |
203 FROM_HERE, | 235 FROM_HERE, |
204 base::Bind( | 236 base::Bind( |
205 &ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool, | 237 &ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool, |
206 this, extension_id, reply_msg)); | 238 this, paths_to_load, extension_id, |
239 extensions::LocaleInfo::GetDefaultLocale(extension), reply_msg)); | |
Devlin
2017/02/14 17:45:49
If the extension isn't localized, we only return t
atuchin
2017/02/15 08:17:29
Done, take a look.
I thought about that before. It
| |
207 } | 240 } |
208 | 241 |
209 void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool( | 242 void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool( |
210 const std::string& extension_id, | 243 const std::vector<base::FilePath>& extension_paths, |
244 const std::string& main_extension_id, | |
245 const std::string& default_locale, | |
211 IPC::Message* reply_msg) { | 246 IPC::Message* reply_msg) { |
212 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 247 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
213 | 248 |
214 const extensions::ExtensionSet& extension_set = | |
215 extension_info_map_->extensions(); | |
216 | |
217 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( | 249 std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( |
218 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports( | 250 extensions::file_util::LoadMessageBundleSubstitutionMapFromPaths( |
219 extension_id, extension_set)); | 251 extension_paths, main_extension_id, default_locale)); |
220 | 252 |
221 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, | 253 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, |
222 *dictionary_map); | 254 *dictionary_map); |
223 Send(reply_msg); | 255 Send(reply_msg); |
224 } | 256 } |
225 | 257 |
226 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( | 258 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( |
227 const std::string& extension_id, | 259 const std::string& extension_id, |
228 const ExtensionHostMsg_APIActionOrEvent_Params& params) { | 260 const ExtensionHostMsg_APIActionOrEvent_Params& params) { |
229 if (!ShouldLogExtensionAction(extension_id)) | 261 if (!ShouldLogExtensionAction(extension_id)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( | 318 bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( |
287 const std::string& extension_id) const { | 319 const std::string& extension_id) const { |
288 // We only send these IPCs if activity logging is enabled, but due to race | 320 // 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 | 321 // conditions (e.g. logging gets disabled but the renderer sends the message |
290 // before it gets updated), we still need this check here. | 322 // before it gets updated), we still need this check here. |
291 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 323 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
292 return profile_ && | 324 return profile_ && |
293 g_browser_process->profile_manager()->IsValidProfile(profile_) && | 325 g_browser_process->profile_manager()->IsValidProfile(profile_) && |
294 activity_log_ && activity_log_->ShouldLog(extension_id); | 326 activity_log_ && activity_log_->ShouldLog(extension_id); |
295 } | 327 } |
OLD | NEW |