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

Unified Diff: chrome/browser/renderer_host/chrome_extension_message_filter.cc

Issue 2686463003: [Extensions] Fix a data race in ChromeExtensionMessageFilter. (Closed)
Patch Set: [Extensions] Fix a data race in ChromeExtensionMessageFilter. Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/renderer_host/chrome_extension_message_filter.h ('k') | extensions/browser/info_map.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/chrome_extension_message_filter.cc
diff --git a/chrome/browser/renderer_host/chrome_extension_message_filter.cc b/chrome/browser/renderer_host/chrome_extension_message_filter.cc
index 85891b1d32db5d30812f3d1b1c4933fd5278438d..00ddafb9de78af7b132cab4d1d973c74335b2956 100644
--- a/chrome/browser/renderer_host/chrome_extension_message_filter.cc
+++ b/chrome/browser/renderer_host/chrome_extension_message_filter.cc
@@ -28,8 +28,10 @@
#include "extensions/browser/extension_system.h"
#include "extensions/common/api/messaging/message.h"
#include "extensions/common/extension_messages.h"
+#include "extensions/common/extension_set.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest_handlers/default_locale_handler.h"
+#include "extensions/common/manifest_handlers/shared_module_info.h"
#include "extensions/common/message_bundle.h"
using content::BrowserThread;
@@ -199,24 +201,66 @@ void ChromeExtensionMessageFilter::OnPostMessage(
void ChromeExtensionMessageFilter::OnGetExtMessageBundle(
const std::string& extension_id, IPC::Message* reply_msg) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ const extensions::ExtensionSet& extension_set =
+ extension_info_map_->extensions();
+ const extensions::Extension* extension = extension_set.GetByID(extension_id);
+
+ if (!extension) { // The extension has gone.
+ ExtensionHostMsg_GetMessageBundle::WriteReplyParams(
+ reply_msg, extensions::MessageBundle::SubstitutionMap());
+ Send(reply_msg);
+ return;
+ }
+
+ const std::string& default_locale =
+ extensions::LocaleInfo::GetDefaultLocale(extension);
+ if (default_locale.empty()) {
+ // A little optimization: send the answer here to avoid an extra thread hop.
+ std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map(
+ extensions::file_util::LoadNonLocalizedMessageBundleSubstitutionMap(
+ extension_id));
+ ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg,
+ *dictionary_map);
+ Send(reply_msg);
+ return;
+ }
+
+ std::vector<base::FilePath> paths_to_load;
+ paths_to_load.push_back(extension->path());
+
+ auto imports = extensions::SharedModuleInfo::GetImports(extension);
+ // Iterate through the imports in reverse. This will allow later imported
+ // modules to override earlier imported modules, as the list order is
+ // maintained from the definition in manifest.json of the imports.
+ for (auto it = imports.rbegin(); it != imports.rend(); ++it) {
+ const extensions::Extension* imported_extension =
+ extension_set.GetByID(it->extension_id);
+ if (!imported_extension) {
+ NOTREACHED() << "Missing shared module " << it->extension_id;
+ continue;
+ }
+ paths_to_load.push_back(imported_extension->path());
+ }
+
BrowserThread::PostBlockingPoolTask(
FROM_HERE,
base::Bind(
&ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool,
- this, extension_id, reply_msg));
+ this, paths_to_load, extension_id, default_locale, reply_msg));
}
void ChromeExtensionMessageFilter::OnGetExtMessageBundleOnBlockingPool(
- const std::string& extension_id,
+ const std::vector<base::FilePath>& extension_paths,
+ const std::string& main_extension_id,
+ const std::string& default_locale,
IPC::Message* reply_msg) {
DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
- const extensions::ExtensionSet& extension_set =
- extension_info_map_->extensions();
-
std::unique_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map(
- extensions::file_util::LoadMessageBundleSubstitutionMapWithImports(
- extension_id, extension_set));
+ extensions::file_util::LoadMessageBundleSubstitutionMapFromPaths(
+ extension_paths, main_extension_id, default_locale));
ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg,
*dictionary_map);
« no previous file with comments | « chrome/browser/renderer_host/chrome_extension_message_filter.h ('k') | extensions/browser/info_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698