Chromium Code Reviews| Index: extensions/renderer/module_system.cc |
| diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc |
| index f3fdf5d3c1704eb7bf6ba387d9f2b23945755920..e5fb1e9c542e23ae4f10e02f9b472b166920cf74 100644 |
| --- a/extensions/renderer/module_system.cc |
| +++ b/extensions/renderer/module_system.cc |
| @@ -111,6 +111,22 @@ void SetExportsProperty( |
| LOG(ERROR) << "Failed to set private property on the export."; |
| } |
| +bool ContextNeedsMojoBindings(ScriptContext* context) { |
| + // Mojo is only used from JS by some APIs so a context only needs the mojo |
| + // bindings at least one is available. |
|
Devlin
2016/10/13 14:44:14
nit: "if at least one is available"? (missing "if"
Sam McNally
2016/10/13 22:24:50
Done.
|
| + // |
| + // Prefer to use Mojo from C++ if possible rather than adding to this list. |
| + static const char* const kMojoUsingApis[] = { |
|
Devlin
2016/10/13 14:44:14
nitty nit: since variable names can't express the
Sam McNally
2016/10/13 22:24:50
Done.
|
| + "mimeHandlerPrivate", "mojoPrivate", |
| + }; |
| + |
| + for (const auto* api : kMojoUsingApis) { |
| + if (context->GetAvailability(api).is_available()) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| } // namespace |
| std::string ModuleSystem::ExceptionHandler::CreateExceptionString( |
| @@ -169,12 +185,9 @@ ModuleSystem::ModuleSystem(ScriptContext* context, const SourceMap* source_map) |
| SetPrivate(global, kModuleSystem, v8::External::New(isolate, this)); |
| gin::ModuleRegistry::From(context->v8_context())->AddObserver(this); |
| - // TODO(devlin): We really shouldn't be injecting mojo into every blessed |
| - // extension context - it's wasteful. But it's better than injecting into |
| - // every frame (previous behavior) so start with this while we investigate |
| - // further. See crbug.com/636655. |
| if (context_->GetRenderFrame() && |
| - context_->context_type() == Feature::BLESSED_EXTENSION_CONTEXT) { |
| + context_->context_type() == Feature::BLESSED_EXTENSION_CONTEXT && |
| + ContextNeedsMojoBindings(context_)) { |
| context_->GetRenderFrame()->EnsureMojoBuiltinsAreAvailable( |
| context->isolate(), context->v8_context()); |
| } |