Don't create cross origins references in the extension system

BUG=504011
R=kalman@chromium.org,haraken@chromium.org

Review URL: https://codereview.chromium.org/1235863003

Cr-Commit-Position: refs/heads/master@{#338573}
diff --git a/extensions/renderer/v8_context_native_handler.cc b/extensions/renderer/v8_context_native_handler.cc
index ed915cc..37f052ba 100644
--- a/extensions/renderer/v8_context_native_handler.cc
+++ b/extensions/renderer/v8_context_native_handler.cc
@@ -8,6 +8,7 @@
 #include "extensions/common/features/feature.h"
 #include "extensions/renderer/dispatcher.h"
 #include "extensions/renderer/script_context.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
 
 namespace extensions {
 
@@ -53,7 +54,8 @@
       v8::Local<v8::Object>::Cast(args[0])->CreationContext();
   ScriptContext* context =
       dispatcher_->script_context_set().GetByV8Context(v8_context);
-  args.GetReturnValue().Set(context->module_system()->NewInstance());
+  if (blink::WebFrame::scriptCanAccess(context->web_frame()))
+    args.GetReturnValue().Set(context->module_system()->NewInstance());
 }
 
 void V8ContextNativeHandler::RunWithNativesEnabledModuleSystem(