[Extensions] Don't inject mojo bindings for every context

Currently, the module system injects mojo bindings for every created
script context, because some extension APIs rely on their existence.
However, these bindings are slow and costly to construct. Only create
them for blessed extension contexts.

We should be able to drill this down further and create them even more
rarely, but do this until we can investigate more, since this helps in
the 99% case.

BUG=637155

Review-Url: https://codereview.chromium.org/2243323002
Cr-Commit-Position: refs/heads/master@{#412086}
diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc
index 4665d753..8f0fbaf7 100644
--- a/extensions/renderer/module_system.cc
+++ b/extensions/renderer/module_system.cc
@@ -169,7 +169,12 @@
   SetPrivate(global, kModuleSystem, v8::External::New(isolate, this));
 
   gin::ModuleRegistry::From(context->v8_context())->AddObserver(this);
-  if (context_->GetRenderFrame()) {
+  // 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_->GetRenderFrame()->EnsureMojoBuiltinsAreAvailable(
         context->isolate(), context->v8_context());
   }