summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PRESUBMIT.py4
-rw-r--r--apps/shell/common/shell_extensions_client.cc2
-rw-r--r--apps/shell/common/shell_extensions_client.h1
-rw-r--r--chrome/chrome_renderer.gypi10
-rw-r--r--chrome/common/extensions/chrome_extensions_client.cc7
-rw-r--r--chrome/common/extensions/chrome_extensions_client.h1
-rw-r--r--chrome/renderer/extensions/app_bindings.cc2
-rw-r--r--chrome/renderer/extensions/binding_generating_native_handler.cc2
-rw-r--r--chrome/renderer/extensions/blob_native_handler.cc2
-rw-r--r--chrome/renderer/extensions/blob_native_handler.h5
-rw-r--r--chrome/renderer/extensions/cast_streaming_native_handler.h2
-rw-r--r--chrome/renderer/extensions/chrome_v8_context.cc159
-rw-r--r--chrome/renderer/extensions/chrome_v8_context.h118
-rw-r--r--chrome/renderer/extensions/chrome_v8_extension.h2
-rw-r--r--chrome/renderer/extensions/css_native_handler.h3
-rw-r--r--chrome/renderer/extensions/dispatcher.cc28
-rw-r--r--chrome/renderer/extensions/dispatcher.h5
-rw-r--r--chrome/renderer/extensions/extension_frame_helper.cc2
-rw-r--r--chrome/renderer/extensions/extension_helper.cc2
-rw-r--r--chrome/renderer/extensions/file_system_natives.cc3
-rw-r--r--chrome/renderer/extensions/file_system_natives.h3
-rw-r--r--chrome/renderer/extensions/logging_native_handler.cc2
-rw-r--r--chrome/renderer/extensions/logging_native_handler.h5
-rw-r--r--chrome/renderer/extensions/module_system_unittest.cc4
-rw-r--r--chrome/renderer/extensions/pepper_request_natives.cc10
-rw-r--r--chrome/renderer/extensions/pepper_request_natives.h3
-rw-r--r--chrome/renderer/extensions/render_view_observer_natives.cc10
-rw-r--r--chrome/renderer/extensions/render_view_observer_natives.h3
-rw-r--r--chrome/renderer/extensions/send_request_natives.cc2
-rw-r--r--chrome/renderer/extensions/set_icon_natives.cc2
-rw-r--r--chrome/renderer/extensions/user_script_scheduler.cc3
-rw-r--r--chrome/renderer/extensions/user_script_slave.cc21
-rw-r--r--chrome/renderer/extensions/user_script_slave.h4
-rw-r--r--chrome/renderer/extensions/utils_native_handler.h3
-rw-r--r--chrome/renderer/extensions/v8_schema_registry.cc2
-rw-r--r--chrome/renderer/resource_bundle_source_map.h2
-rw-r--r--chrome/test/base/module_system_test.cc4
-rw-r--r--chrome/test/base/module_system_test.h2
-rw-r--r--extensions/DEPS2
-rw-r--r--extensions/common/extensions_client.h4
-rw-r--r--extensions/extensions.gyp12
-rw-r--r--extensions/renderer/DEPS8
-rw-r--r--extensions/renderer/console.cc (renamed from chrome/renderer/extensions/console.cc)15
-rw-r--r--extensions/renderer/console.h (renamed from chrome/renderer/extensions/console.h)8
-rw-r--r--extensions/renderer/module_system.cc (renamed from chrome/renderer/extensions/module_system.cc)104
-rw-r--r--extensions/renderer/module_system.h (renamed from chrome/renderer/extensions/module_system.h)39
-rw-r--r--extensions/renderer/object_backed_native_handler.cc (renamed from chrome/renderer/extensions/object_backed_native_handler.cc)18
-rw-r--r--extensions/renderer/object_backed_native_handler.h (renamed from chrome/renderer/extensions/object_backed_native_handler.h)16
-rw-r--r--extensions/renderer/request_sender.cc (renamed from chrome/renderer/extensions/request_sender.cc)33
-rw-r--r--extensions/renderer/request_sender.h (renamed from chrome/renderer/extensions/request_sender.h)14
-rw-r--r--extensions/renderer/safe_builtins.cc (renamed from chrome/renderer/extensions/safe_builtins.cc)33
-rw-r--r--extensions/renderer/safe_builtins.h (renamed from chrome/renderer/extensions/safe_builtins.h)16
-rw-r--r--extensions/renderer/script_context.cc191
-rw-r--r--extensions/renderer/script_context.h145
54 files changed, 593 insertions, 510 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index f808fed..7c9408b 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -240,7 +240,9 @@ _BANNED_CPP_FUNCTIONS = (
'gin::Wrappable instead. See http://crbug.com/334679',
),
True,
- (),
+ (
+ r'extensions[/\\]renderer[/\\]safe_builtins\.*',
+ ),
),
)
diff --git a/apps/shell/common/shell_extensions_client.cc b/apps/shell/common/shell_extensions_client.cc
index 4e495d2..3dca9c9 100644
--- a/apps/shell/common/shell_extensions_client.cc
+++ b/apps/shell/common/shell_extensions_client.cc
@@ -179,4 +179,6 @@ base::StringPiece ShellExtensionsClient::GetAPISchema(
void ShellExtensionsClient::AddExtraFeatureFilters(
extensions::SimpleFeature* feature) const {}
+bool ShellExtensionsClient::ShouldSuppressFatalErrors() const { return true; }
+
} // namespace apps
diff --git a/apps/shell/common/shell_extensions_client.h b/apps/shell/common/shell_extensions_client.h
index 2cecb74..e920b38 100644
--- a/apps/shell/common/shell_extensions_client.h
+++ b/apps/shell/common/shell_extensions_client.h
@@ -42,6 +42,7 @@ class ShellExtensionsClient : public extensions::ExtensionsClient {
OVERRIDE;
virtual void AddExtraFeatureFilters(extensions::SimpleFeature* feature) const
OVERRIDE;
+ virtual bool ShouldSuppressFatalErrors() const OVERRIDE;
private:
ScriptingWhitelist scripting_whitelist_;
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index f2a3f15..e64d182 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -73,8 +73,6 @@
'renderer/extensions/chrome_v8_extension.h',
'renderer/extensions/chrome_v8_extension_handler.cc',
'renderer/extensions/chrome_v8_extension_handler.h',
- 'renderer/extensions/console.cc',
- 'renderer/extensions/console.h',
'renderer/extensions/content_watcher.cc',
'renderer/extensions/content_watcher.h',
'renderer/extensions/context_menus_custom_bindings.cc',
@@ -112,10 +110,6 @@
'renderer/extensions/media_galleries_custom_bindings.h',
'renderer/extensions/messaging_bindings.cc',
'renderer/extensions/messaging_bindings.h',
- 'renderer/extensions/module_system.cc',
- 'renderer/extensions/module_system.h',
- 'renderer/extensions/object_backed_native_handler.cc',
- 'renderer/extensions/object_backed_native_handler.h',
'renderer/extensions/page_actions_custom_bindings.cc',
'renderer/extensions/page_actions_custom_bindings.h',
'renderer/extensions/page_capture_custom_bindings.cc',
@@ -128,14 +122,10 @@
'renderer/extensions/renderer_permissions_policy_delegate.h',
'renderer/extensions/render_view_observer_natives.cc',
'renderer/extensions/render_view_observer_natives.h',
- 'renderer/extensions/request_sender.cc',
- 'renderer/extensions/request_sender.h',
'renderer/extensions/resource_request_policy.cc',
'renderer/extensions/resource_request_policy.h',
'renderer/extensions/runtime_custom_bindings.cc',
'renderer/extensions/runtime_custom_bindings.h',
- 'renderer/extensions/safe_builtins.cc',
- 'renderer/extensions/safe_builtins.h',
'renderer/extensions/send_request_natives.cc',
'renderer/extensions/send_request_natives.h',
'renderer/extensions/set_icon_natives.cc',
diff --git a/chrome/common/extensions/chrome_extensions_client.cc b/chrome/common/extensions/chrome_extensions_client.cc
index a45d4f8..8bda783 100644
--- a/chrome/common/extensions/chrome_extensions_client.cc
+++ b/chrome/common/extensions/chrome_extensions_client.cc
@@ -6,10 +6,12 @@
#include "apps/common/api/generated_schemas.h"
#include "base/command_line.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/api/generated_schemas.h"
#include "chrome/common/extensions/chrome_manifest_handlers.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/features/chrome_channel_feature_filter.h"
+#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/url_constants.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/api/generated_schemas.h"
@@ -180,6 +182,11 @@ void ChromeExtensionsClient::AddExtraFeatureFilters(
scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature)));
}
+bool ChromeExtensionsClient::ShouldSuppressFatalErrors() const {
+ // <= dev means dev, canary, and trunk.
+ return GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV;
+}
+
// static
ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() {
return g_client.Pointer();
diff --git a/chrome/common/extensions/chrome_extensions_client.h b/chrome/common/extensions/chrome_extensions_client.h
index 10f17de..49f3564 100644
--- a/chrome/common/extensions/chrome_extensions_client.h
+++ b/chrome/common/extensions/chrome_extensions_client.h
@@ -44,6 +44,7 @@ class ChromeExtensionsClient : public ExtensionsClient {
virtual base::StringPiece GetAPISchema(const std::string& name) const
OVERRIDE;
virtual void AddExtraFeatureFilters(SimpleFeature* feature) const OVERRIDE;
+ virtual bool ShouldSuppressFatalErrors() const OVERRIDE;
// Get the LazyInstance for ChromeExtensionsClient.
static ChromeExtensionsClient* GetInstance();
diff --git a/chrome/renderer/extensions/app_bindings.cc b/chrome/renderer/extensions/app_bindings.cc
index 3b6a7a4..e25b81b 100644
--- a/chrome/renderer/extensions/app_bindings.cc
+++ b/chrome/renderer/extensions/app_bindings.cc
@@ -12,7 +12,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "chrome/renderer/extensions/console.h"
#include "chrome/renderer/extensions/dispatcher.h"
#include "chrome/renderer/extensions/extension_helper.h"
#include "content/public/renderer/render_view.h"
@@ -20,6 +19,7 @@
#include "extensions/common/extension_messages.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest.h"
+#include "extensions/renderer/console.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
diff --git a/chrome/renderer/extensions/binding_generating_native_handler.cc b/chrome/renderer/extensions/binding_generating_native_handler.cc
index f58cdb6..91f2d91 100644
--- a/chrome/renderer/extensions/binding_generating_native_handler.cc
+++ b/chrome/renderer/extensions/binding_generating_native_handler.cc
@@ -4,7 +4,7 @@
#include "chrome/renderer/extensions/binding_generating_native_handler.h"
-#include "chrome/renderer/extensions/module_system.h"
+#include "extensions/renderer/module_system.h"
namespace extensions {
diff --git a/chrome/renderer/extensions/blob_native_handler.cc b/chrome/renderer/extensions/blob_native_handler.cc
index c7f4255..6c6bbfe 100644
--- a/chrome/renderer/extensions/blob_native_handler.cc
+++ b/chrome/renderer/extensions/blob_native_handler.cc
@@ -23,7 +23,7 @@ void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) {
namespace extensions {
-BlobNativeHandler::BlobNativeHandler(ChromeV8Context* context)
+BlobNativeHandler::BlobNativeHandler(ScriptContext* context)
: ObjectBackedNativeHandler(context) {
RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid));
}
diff --git a/chrome/renderer/extensions/blob_native_handler.h b/chrome/renderer/extensions/blob_native_handler.h
index d8d96e0..4eee852 100644
--- a/chrome/renderer/extensions/blob_native_handler.h
+++ b/chrome/renderer/extensions/blob_native_handler.h
@@ -5,9 +5,10 @@
#ifndef CHROME_RENDERER_EXTENSIONS_BLOB_NATIVE_HANDLER_H_
#define CHROME_RENDERER_EXTENSIONS_BLOB_NATIVE_HANDLER_H_
-#include "chrome/renderer/extensions/chrome_v8_extension.h"
+#include "extensions/renderer/object_backed_native_handler.h"
namespace extensions {
+class ScriptContext;
// This native handler is used to extract Blobs' UUIDs and pass them over to the
// browser process extension implementation via argument modification. This is
@@ -18,7 +19,7 @@ namespace extensions {
// app using this technique must be sure to keep a reference.
class BlobNativeHandler : public ObjectBackedNativeHandler {
public:
- explicit BlobNativeHandler(ChromeV8Context* context);
+ explicit BlobNativeHandler(ScriptContext* context);
};
} // namespace extensions
diff --git a/chrome/renderer/extensions/cast_streaming_native_handler.h b/chrome/renderer/extensions/cast_streaming_native_handler.h
index 4fe927f..a78e9b4 100644
--- a/chrome/renderer/extensions/cast_streaming_native_handler.h
+++ b/chrome/renderer/extensions/cast_streaming_native_handler.h
@@ -9,7 +9,7 @@
#include "base/memory/linked_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
#include "extensions/renderer/scoped_persistent.h"
#include "v8/include/v8.h"
diff --git a/chrome/renderer/extensions/chrome_v8_context.cc b/chrome/renderer/extensions/chrome_v8_context.cc
index 24fad4a..795d298 100644
--- a/chrome/renderer/extensions/chrome_v8_context.cc
+++ b/chrome/renderer/extensions/chrome_v8_context.cc
@@ -4,177 +4,24 @@
#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_split.h"
#include "base/values.h"
-#include "chrome/renderer/extensions/chrome_v8_extension.h"
-#include "chrome/renderer/extensions/module_system.h"
#include "chrome/renderer/extensions/user_script_slave.h"
-#include "content/public/renderer/render_view.h"
-#include "content/public/renderer/v8_value_converter.h"
-#include "extensions/common/extension.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/features/base_feature_provider.h"
+#include "extensions/renderer/module_system.h"
#include "third_party/WebKit/public/web/WebFrame.h"
-#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
-#include "third_party/WebKit/public/web/WebView.h"
#include "v8/include/v8.h"
-using content::V8ValueConverter;
-
namespace extensions {
ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context,
blink::WebFrame* web_frame,
const Extension* extension,
Feature::Context context_type)
- : v8_context_(v8_context),
- web_frame_(web_frame),
- extension_(extension),
- context_type_(context_type),
- safe_builtins_(this),
- pepper_request_proxy_(this),
- isolate_(v8_context->GetIsolate()) {
- VLOG(1) << "Created context:\n"
- << " extension id: " << GetExtensionID() << "\n"
- << " frame: " << web_frame_ << "\n"
- << " context type: " << GetContextTypeDescription();
-}
-
-ChromeV8Context::~ChromeV8Context() {
- VLOG(1) << "Destroyed context for extension\n"
- << " extension id: " << GetExtensionID();
- Invalidate();
-}
-
-void ChromeV8Context::Invalidate() {
- if (!is_valid())
- return;
- if (module_system_)
- module_system_->Invalidate();
- web_frame_ = NULL;
- v8_context_.reset();
-}
-
-std::string ChromeV8Context::GetExtensionID() const {
- return extension_.get() ? extension_->id() : std::string();
-}
-
-content::RenderView* ChromeV8Context::GetRenderView() const {
- if (web_frame_ && web_frame_->view())
- return content::RenderView::FromWebView(web_frame_->view());
- else
- return NULL;
-}
-
-GURL ChromeV8Context::GetURL() const {
- return web_frame_ ?
- UserScriptSlave::GetDataSourceURLForFrame(web_frame_) : GURL();
-}
-
-v8::Local<v8::Value> ChromeV8Context::CallFunction(
- v8::Handle<v8::Function> function,
- int argc,
- v8::Handle<v8::Value> argv[]) const {
- v8::EscapableHandleScope handle_scope(isolate());
- v8::Context::Scope scope(v8_context());
-
- blink::WebScopedMicrotaskSuppression suppression;
- if (!is_valid()) {
- return handle_scope.Escape(
- v8::Local<v8::Primitive>(v8::Undefined(isolate())));
- }
-
- v8::Handle<v8::Object> global = v8_context()->Global();
- if (!web_frame_)
- return handle_scope.Escape(function->Call(global, argc, argv));
- return handle_scope.Escape(
- v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled(
- function, global, argc, argv)));
-}
-
-bool ChromeV8Context::IsAnyFeatureAvailableToContext(const Feature& api) {
- return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
- api,
- extension_.get(),
- context_type_,
- UserScriptSlave::GetDataSourceURLForFrame(web_frame_));
-}
-
-Feature::Availability ChromeV8Context::GetAvailability(
- const std::string& api_name) {
- // Hack: Hosted apps should have the availability of messaging APIs based on
- // the URL of the page (which might have access depending on some extension
- // with externally_connectable), not whether the app has access to messaging
- // (which it won't).
- const Extension* extension = extension_.get();
- if (extension && extension->is_hosted_app() &&
- (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) {
- extension = NULL;
- }
- return ExtensionAPI::GetSharedInstance()->IsAvailable(api_name,
- extension,
- context_type_,
- GetURL());
-}
-
-void ChromeV8Context::DispatchEvent(const char* event_name,
- v8::Handle<v8::Array> args) const {
- v8::HandleScope handle_scope(isolate());
- v8::Context::Scope context_scope(v8_context());
-
- v8::Handle<v8::Value> argv[] = {
- v8::String::NewFromUtf8(isolate(), event_name), args};
- module_system_->CallModuleMethod(
- kEventBindings, "dispatchEvent", arraysize(argv), argv);
-}
-
-void ChromeV8Context::DispatchOnUnloadEvent() {
- module_system_->CallModuleMethod("unload_event", "dispatch");
-}
-
-std::string ChromeV8Context::GetContextTypeDescription() {
- switch (context_type_) {
- case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED";
- case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION";
- case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION";
- case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT";
- case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE";
- case Feature::BLESSED_WEB_PAGE_CONTEXT: return "BLESSED_WEB_PAGE";
- }
- NOTREACHED();
- return std::string();
-}
-
-ChromeV8Context* ChromeV8Context::GetContext() {
- return this;
-}
-
-void ChromeV8Context::OnResponseReceived(const std::string& name,
- int request_id,
- bool success,
- const base::ListValue& response,
- const std::string& error) {
- v8::HandleScope handle_scope(isolate());
-
- scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
- v8::Handle<v8::Value> argv[] = {
- v8::Integer::New(isolate(), request_id),
- v8::String::NewFromUtf8(isolate(), name.c_str()),
- v8::Boolean::New(isolate(), success),
- converter->ToV8Value(&response, v8_context_.NewHandle(isolate())),
- v8::String::NewFromUtf8(isolate(), error.c_str())
- };
-
- v8::Handle<v8::Value> retval = module_system_->CallModuleMethod(
- "sendRequest", "handleResponse", arraysize(argv), argv);
-
- // In debug, the js will validate the callback parameters and return a
- // string if a validation error has occured.
- DCHECK(retval.IsEmpty() || retval->IsUndefined())
- << *v8::String::Utf8Value(retval);
-}
+ : ScriptContext(v8_context, web_frame, extension, context_type),
+ pepper_request_proxy_(this) {}
} // namespace extensions
diff --git a/chrome/renderer/extensions/chrome_v8_context.h b/chrome/renderer/extensions/chrome_v8_context.h
index da08b8c..41c8403 100644
--- a/chrome/renderer/extensions/chrome_v8_context.h
+++ b/chrome/renderer/extensions/chrome_v8_context.h
@@ -9,12 +9,13 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "chrome/renderer/extensions/module_system.h"
#include "chrome/renderer/extensions/pepper_request_proxy.h"
-#include "chrome/renderer/extensions/request_sender.h"
-#include "chrome/renderer/extensions/safe_builtins.h"
#include "extensions/common/features/feature.h"
+#include "extensions/renderer/module_system.h"
+#include "extensions/renderer/request_sender.h"
+#include "extensions/renderer/safe_builtins.h"
#include "extensions/renderer/scoped_persistent.h"
+#include "extensions/renderer/script_context.h"
#include "v8/include/v8.h"
namespace blink {
@@ -29,130 +30,21 @@ namespace extensions {
class Extension;
// Chrome's wrapper for a v8 context.
-class ChromeV8Context : public RequestSender::Source {
+class ChromeV8Context : public ScriptContext {
public:
ChromeV8Context(v8::Handle<v8::Context> context,
blink::WebFrame* frame,
const Extension* extension,
Feature::Context context_type);
- virtual ~ChromeV8Context();
-
- // Clears the WebFrame for this contexts and invalidates the associated
- // ModuleSystem.
- void Invalidate();
-
- // Returns true if this context is still valid, false if it isn't.
- // A context becomes invalid via Invalidate().
- bool is_valid() const {
- return !v8_context_.IsEmpty();
- }
-
- v8::Handle<v8::Context> v8_context() const {
- return v8_context_.NewHandle(v8::Isolate::GetCurrent());
- }
-
- const Extension* extension() const {
- return extension_.get();
- }
-
- blink::WebFrame* web_frame() const {
- return web_frame_;
- }
-
- Feature::Context context_type() const {
- return context_type_;
- }
-
- void set_module_system(scoped_ptr<ModuleSystem> module_system) {
- module_system_ = module_system.Pass();
- }
-
- ModuleSystem* module_system() { return module_system_.get(); }
-
- SafeBuiltins* safe_builtins() {
- return &safe_builtins_;
- }
- const SafeBuiltins* safe_builtins() const {
- return &safe_builtins_;
- }
PepperRequestProxy* pepper_request_proxy() {
return &pepper_request_proxy_;
}
- // Returns the ID of the extension associated with this context, or empty
- // string if there is no such extension.
- std::string GetExtensionID() const;
-
- // Returns the RenderView associated with this context. Can return NULL if the
- // context is in the process of being destroyed.
- content::RenderView* GetRenderView() const;
-
- // Get the URL of this context's web frame.
- GURL GetURL() const;
-
- // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers
- // must do that if they want.
- //
- // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE.
- v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function,
- int argc,
- v8::Handle<v8::Value> argv[]) const;
-
- void DispatchEvent(const char* event_name, v8::Handle<v8::Array> args) const;
-
- // Fires the onunload event on the unload_event module.
- void DispatchOnUnloadEvent();
-
- // Returns the availability of the API |api_name|.
- Feature::Availability GetAvailability(const std::string& api_name);
-
- // Returns whether the API |api| or any part of the API could be
- // available in this context without taking into account the context's
- // extension.
- bool IsAnyFeatureAvailableToContext(const extensions::Feature& api);
-
- // Returns a string description of the type of context this is.
- std::string GetContextTypeDescription();
-
- // RequestSender::Source implementation.
- virtual ChromeV8Context* GetContext() OVERRIDE;
- virtual void OnResponseReceived(const std::string& name,
- int request_id,
- bool success,
- const base::ListValue& response,
- const std::string& error) OVERRIDE;
-
- v8::Isolate* isolate() const {
- return isolate_;
- }
-
private:
- // The v8 context the bindings are accessible to.
- ScopedPersistent<v8::Context> v8_context_;
-
- // The WebFrame associated with this context. This can be NULL because this
- // object can outlive is destroyed asynchronously.
- blink::WebFrame* web_frame_;
-
- // The extension associated with this context, or NULL if there is none. This
- // might be a hosted app in the case that this context is hosting a web URL.
- scoped_refptr<const Extension> extension_;
-
- // The type of context.
- Feature::Context context_type_;
-
- // Owns and structures the JS that is injected to set up extension bindings.
- scoped_ptr<ModuleSystem> module_system_;
-
- // Contains safe copies of builtin objects like Function.prototype.
- SafeBuiltins safe_builtins_;
-
// The proxy for this context for making API calls from Pepper via Javascript.
PepperRequestProxy pepper_request_proxy_;
- v8::Isolate* isolate_;
-
DISALLOW_COPY_AND_ASSIGN(ChromeV8Context);
};
diff --git a/chrome/renderer/extensions/chrome_v8_extension.h b/chrome/renderer/extensions/chrome_v8_extension.h
index 25ef15c..2fab470 100644
--- a/chrome/renderer/extensions/chrome_v8_extension.h
+++ b/chrome/renderer/extensions/chrome_v8_extension.h
@@ -9,7 +9,7 @@
#include "base/memory/linked_ptr.h"
#include "base/strings/string_piece.h"
#include "chrome/renderer/extensions/chrome_v8_extension_handler.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
#include "v8/include/v8.h"
#include <map>
diff --git a/chrome/renderer/extensions/css_native_handler.h b/chrome/renderer/extensions/css_native_handler.h
index 97ea62a..a216500 100644
--- a/chrome/renderer/extensions/css_native_handler.h
+++ b/chrome/renderer/extensions/css_native_handler.h
@@ -5,9 +5,10 @@
#ifndef CHROME_RENDERER_EXTENSIONS_CSS_NATIVE_HANDLER_H_
#define CHROME_RENDERER_EXTENSIONS_CSS_NATIVE_HANDLER_H_
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
namespace extensions {
+class ChromeV8Context;
class CssNativeHandler : public ObjectBackedNativeHandler {
public:
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc
index dbb84d4..51d68af 100644
--- a/chrome/renderer/extensions/dispatcher.cc
+++ b/chrome/renderer/extensions/dispatcher.cc
@@ -47,15 +47,11 @@
#include "chrome/renderer/extensions/logging_native_handler.h"
#include "chrome/renderer/extensions/media_galleries_custom_bindings.h"
#include "chrome/renderer/extensions/messaging_bindings.h"
-#include "chrome/renderer/extensions/module_system.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
#include "chrome/renderer/extensions/page_actions_custom_bindings.h"
#include "chrome/renderer/extensions/page_capture_custom_bindings.h"
#include "chrome/renderer/extensions/pepper_request_natives.h"
#include "chrome/renderer/extensions/render_view_observer_natives.h"
-#include "chrome/renderer/extensions/request_sender.h"
#include "chrome/renderer/extensions/runtime_custom_bindings.h"
-#include "chrome/renderer/extensions/safe_builtins.h"
#include "chrome/renderer/extensions/send_request_natives.h"
#include "chrome/renderer/extensions/set_icon_natives.h"
#include "chrome/renderer/extensions/sync_file_system_custom_bindings.h"
@@ -85,6 +81,11 @@
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/switches.h"
#include "extensions/common/view_type.h"
+#include "extensions/renderer/module_system.h"
+#include "extensions/renderer/object_backed_native_handler.h"
+#include "extensions/renderer/request_sender.h"
+#include "extensions/renderer/safe_builtins.h"
+#include "extensions/renderer/script_context.h"
#include "grit/common_resources.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/public/platform/WebString.h"
@@ -133,7 +134,7 @@ static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled";
//
// Note that this isn't necessarily an object, since webpages can write, for
// example, "window.chrome = true".
-v8::Handle<v8::Value> GetOrCreateChrome(ChromeV8Context* context) {
+v8::Handle<v8::Value> GetOrCreateChrome(ScriptContext* context) {
v8::Handle<v8::String> chrome_string(
v8::String::NewFromUtf8(context->isolate(), "chrome"));
v8::Handle<v8::Object> global(context->v8_context()->Global());
@@ -1131,11 +1132,11 @@ void Dispatcher::DidCreateScriptContext(
extension_id = "";
}
- Feature::Context context_type = ClassifyJavaScriptContext(
- extension,
- extension_group,
- UserScriptSlave::GetDataSourceURLForFrame(frame),
- frame->document().securityOrigin());
+ Feature::Context context_type =
+ ClassifyJavaScriptContext(extension,
+ extension_group,
+ ScriptContext::GetDataSourceURLForFrame(frame),
+ frame->document().securityOrigin());
ChromeV8Context* context =
new ChromeV8Context(v8_context, frame, extension, context_type);
@@ -1271,7 +1272,7 @@ std::string Dispatcher::GetExtensionID(const WebFrame* frame, int world_id) {
return std::string();
// Extension pages (chrome-extension:// URLs).
- GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame);
+ GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
return extensions_.GetExtensionOrAppIDByURL(frame_url);
}
@@ -1606,7 +1607,8 @@ void Dispatcher::OnExtensionResponse(int request_id,
}
bool Dispatcher::CheckContextAccessToExtensionAPI(
- const std::string& function_name, ChromeV8Context* context) const {
+ const std::string& function_name,
+ ScriptContext* context) const {
if (!context) {
DLOG(ERROR) << "Not in a v8::Context";
return false;
@@ -1621,7 +1623,7 @@ bool Dispatcher::CheckContextAccessToExtensionAPI(
// Theoretically we could end up with bindings being injected into sandboxed
// frames, for example content scripts. Don't let them execute API functions.
blink::WebFrame* frame = context->web_frame();
- if (IsSandboxedPage(UserScriptSlave::GetDataSourceURLForFrame(frame))) {
+ if (IsSandboxedPage(ScriptContext::GetDataSourceURLForFrame(frame))) {
static const char kMessage[] =
"%s cannot be used within a sandboxed frame.";
std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
diff --git a/chrome/renderer/extensions/dispatcher.h b/chrome/renderer/extensions/dispatcher.h
index 6ce0f62..a68d8a2 100644
--- a/chrome/renderer/extensions/dispatcher.h
+++ b/chrome/renderer/extensions/dispatcher.h
@@ -53,6 +53,7 @@ class Extension;
class FilteredEventRouter;
class ManifestPermissionSet;
class RequestSender;
+class ScriptContext;
class UserScriptSlave;
struct Message;
@@ -127,8 +128,8 @@ class Dispatcher : public content::RenderProcessObserver {
// Checks that the current context contains an extension that has permission
// to execute the specified function. If it does not, a v8 exception is thrown
// and the method returns false. Otherwise returns true.
- bool CheckContextAccessToExtensionAPI(
- const std::string& function_name, ChromeV8Context* context) const;
+ bool CheckContextAccessToExtensionAPI(const std::string& function_name,
+ ScriptContext* context) const;
// Dispatches the event named |event_name| to all render views.
void DispatchEvent(const std::string& extension_id,
diff --git a/chrome/renderer/extensions/extension_frame_helper.cc b/chrome/renderer/extensions/extension_frame_helper.cc
index 3fca946..f9b75e1 100644
--- a/chrome/renderer/extensions/extension_frame_helper.cc
+++ b/chrome/renderer/extensions/extension_frame_helper.cc
@@ -4,10 +4,10 @@
#include "chrome/renderer/extensions/extension_frame_helper.h"
-#include "chrome/renderer/extensions/console.h"
#include "chrome/renderer/extensions/dispatcher.h"
#include "content/public/renderer/render_frame.h"
#include "extensions/common/extension_messages.h"
+#include "extensions/renderer/console.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebFrame.h"
diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc
index 1428ac6..a4f27ddb 100644
--- a/chrome/renderer/extensions/extension_helper.cc
+++ b/chrome/renderer/extensions/extension_helper.cc
@@ -16,7 +16,6 @@
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "chrome/renderer/extensions/console.h"
#include "chrome/renderer/extensions/dispatcher.h"
#include "chrome/renderer/extensions/messaging_bindings.h"
#include "chrome/renderer/extensions/user_script_scheduler.h"
@@ -27,6 +26,7 @@
#include "extensions/common/api/messaging/message.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_messages.h"
+#include "extensions/renderer/console.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebDocument.h"
diff --git a/chrome/renderer/extensions/file_system_natives.cc b/chrome/renderer/extensions/file_system_natives.cc
index 113314e..8c83c8e 100644
--- a/chrome/renderer/extensions/file_system_natives.cc
+++ b/chrome/renderer/extensions/file_system_natives.cc
@@ -12,6 +12,7 @@
#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "chrome/renderer/extensions/user_script_slave.h"
#include "extensions/common/constants.h"
+#include "extensions/renderer/script_context.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDOMError.h"
@@ -47,7 +48,7 @@ void FileSystemNatives::GetIsolatedFileSystem(
DCHECK(webframe);
GURL context_url =
- extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe);
+ extensions::ScriptContext::GetDataSourceURLForFrame(webframe);
CHECK(context_url.SchemeIs(extensions::kExtensionScheme));
std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(),
diff --git a/chrome/renderer/extensions/file_system_natives.h b/chrome/renderer/extensions/file_system_natives.h
index 5ea1563..26f0257 100644
--- a/chrome/renderer/extensions/file_system_natives.h
+++ b/chrome/renderer/extensions/file_system_natives.h
@@ -6,9 +6,10 @@
#define CHROME_RENDERER_EXTENSIONS_FILE_SYSTEM_NATIVES_H_
#include "base/compiler_specific.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
namespace extensions {
+class ChromeV8Context;
// Custom bindings for the nativeFileSystem API.
class FileSystemNatives : public ObjectBackedNativeHandler {
diff --git a/chrome/renderer/extensions/logging_native_handler.cc b/chrome/renderer/extensions/logging_native_handler.cc
index 631fe56..9002b7d 100644
--- a/chrome/renderer/extensions/logging_native_handler.cc
+++ b/chrome/renderer/extensions/logging_native_handler.cc
@@ -9,7 +9,7 @@
namespace extensions {
-LoggingNativeHandler::LoggingNativeHandler(ChromeV8Context* context)
+LoggingNativeHandler::LoggingNativeHandler(ScriptContext* context)
: ObjectBackedNativeHandler(context) {
RouteFunction("DCHECK",
base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this)));
diff --git a/chrome/renderer/extensions/logging_native_handler.h b/chrome/renderer/extensions/logging_native_handler.h
index 40fd26b..f097c54 100644
--- a/chrome/renderer/extensions/logging_native_handler.h
+++ b/chrome/renderer/extensions/logging_native_handler.h
@@ -7,14 +7,15 @@
#include <string>
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
namespace extensions {
+class ScriptContext;
// Exposes logging.h macros to JavaScript bindings.
class LoggingNativeHandler : public ObjectBackedNativeHandler {
public:
- explicit LoggingNativeHandler(ChromeV8Context* context);
+ explicit LoggingNativeHandler(ScriptContext* context);
virtual ~LoggingNativeHandler();
// Equivalent to CHECK(predicate) << message.
diff --git a/chrome/renderer/extensions/module_system_unittest.cc b/chrome/renderer/extensions/module_system_unittest.cc
index fd41a41..84ccd7f 100644
--- a/chrome/renderer/extensions/module_system_unittest.cc
+++ b/chrome/renderer/extensions/module_system_unittest.cc
@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/test/base/module_system_test.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/renderer/extensions/module_system.h"
+#include "chrome/test/base/module_system_test.h"
+#include "extensions/renderer/module_system.h"
// TODO(cduvall/kalman): Put this file in extensions namespace.
using extensions::ModuleSystem;
diff --git a/chrome/renderer/extensions/pepper_request_natives.cc b/chrome/renderer/extensions/pepper_request_natives.cc
index fde2a14..8bfc77c 100644
--- a/chrome/renderer/extensions/pepper_request_natives.cc
+++ b/chrome/renderer/extensions/pepper_request_natives.cc
@@ -26,8 +26,12 @@ void PepperRequestNatives::SendResponse(
DCHECK(args[0]->IsInt32());
DCHECK(args[1]->IsArray());
int request_id = args[0]->Int32Value();
+
+ // TODO(rockot): This downcast should be eliminated.
+ // See http://crbug.com/362616.
+ ChromeV8Context* chrome_context = static_cast<ChromeV8Context*>(context());
if (args[2]->IsString()) {
- context()->pepper_request_proxy()->OnResponseReceived(
+ chrome_context->pepper_request_proxy()->OnResponseReceived(
request_id, false, base::ListValue(), *v8::String::Utf8Value(args[2]));
return;
}
@@ -35,11 +39,11 @@ void PepperRequestNatives::SendResponse(
scoped_ptr<content::V8ValueConverter> converter(
content::V8ValueConverter::create());
scoped_ptr<const base::Value> result(
- converter->FromV8Value(args[1], context()->v8_context()));
+ converter->FromV8Value(args[1], chrome_context->v8_context()));
DCHECK(result);
const base::ListValue* result_list = NULL;
CHECK(result->GetAsList(&result_list));
- context()->pepper_request_proxy()->OnResponseReceived(
+ chrome_context->pepper_request_proxy()->OnResponseReceived(
request_id, true, *result_list, "");
}
diff --git a/chrome/renderer/extensions/pepper_request_natives.h b/chrome/renderer/extensions/pepper_request_natives.h
index 28720d902..0f2b8d7 100644
--- a/chrome/renderer/extensions/pepper_request_natives.h
+++ b/chrome/renderer/extensions/pepper_request_natives.h
@@ -6,13 +6,14 @@
#define CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_NATIVES_H_
#include "base/compiler_specific.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
namespace base {
class Value;
}
namespace extensions {
+class ChromeV8Context;
// Custom bindings for handling API calls from pepper plugins.
class PepperRequestNatives : public ObjectBackedNativeHandler {
diff --git a/chrome/renderer/extensions/render_view_observer_natives.cc b/chrome/renderer/extensions/render_view_observer_natives.cc
index c1effe8..f13f3a2 100644
--- a/chrome/renderer/extensions/render_view_observer_natives.cc
+++ b/chrome/renderer/extensions/render_view_observer_natives.cc
@@ -8,6 +8,7 @@
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_observer.h"
#include "extensions/common/extension_api.h"
+#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
@@ -18,13 +19,10 @@ namespace {
// Deletes itself when done.
class LoadWatcher : public content::RenderViewObserver {
public:
- LoadWatcher(ChromeV8Context* context,
+ LoadWatcher(ScriptContext* context,
content::RenderView* view,
v8::Handle<v8::Function> cb)
- : content::RenderViewObserver(view),
- context_(context),
- callback_(cb) {
- }
+ : content::RenderViewObserver(view), context_(context), callback_(cb) {}
virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE {
CallbackAndDie(true);
@@ -45,7 +43,7 @@ class LoadWatcher : public content::RenderViewObserver {
delete this;
}
- ChromeV8Context* context_;
+ ScriptContext* context_;
ScopedPersistent<v8::Function> callback_;
DISALLOW_COPY_AND_ASSIGN(LoadWatcher);
};
diff --git a/chrome/renderer/extensions/render_view_observer_natives.h b/chrome/renderer/extensions/render_view_observer_natives.h
index cb2390a..7d9fb69 100644
--- a/chrome/renderer/extensions/render_view_observer_natives.h
+++ b/chrome/renderer/extensions/render_view_observer_natives.h
@@ -8,10 +8,7 @@
#include "chrome/renderer/extensions/chrome_v8_extension.h"
#include "v8/include/v8.h"
-class ChromeV8Context;
-
namespace extensions {
-
class Dispatcher;
// Native functions for JS to run callbacks upon RenderView events.
diff --git a/chrome/renderer/extensions/send_request_natives.cc b/chrome/renderer/extensions/send_request_natives.cc
index 49a7078..5a7c46b 100644
--- a/chrome/renderer/extensions/send_request_natives.cc
+++ b/chrome/renderer/extensions/send_request_natives.cc
@@ -6,7 +6,7 @@
#include "base/json/json_reader.h"
#include "content/public/renderer/v8_value_converter.h"
-#include "chrome/renderer/extensions/request_sender.h"
+#include "extensions/renderer/request_sender.h"
using content::V8ValueConverter;
diff --git a/chrome/renderer/extensions/set_icon_natives.cc b/chrome/renderer/extensions/set_icon_natives.cc
index b7f4e30..73590db 100644
--- a/chrome/renderer/extensions/set_icon_natives.cc
+++ b/chrome/renderer/extensions/set_icon_natives.cc
@@ -8,7 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/common/render_messages.h"
-#include "chrome/renderer/extensions/request_sender.h"
+#include "extensions/renderer/request_sender.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
diff --git a/chrome/renderer/extensions/user_script_scheduler.cc b/chrome/renderer/extensions/user_script_scheduler.cc
index 4a9bc7a..463047c 100644
--- a/chrome/renderer/extensions/user_script_scheduler.cc
+++ b/chrome/renderer/extensions/user_script_scheduler.cc
@@ -20,6 +20,7 @@
#include "extensions/common/extension_messages.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/permissions/permissions_data.h"
+#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebDocument.h"
@@ -260,7 +261,7 @@ void UserScriptScheduler::ExecuteCodeImpl(
params.request_id,
error,
render_view->GetPageId(),
- UserScriptSlave::GetDataSourceURLForFrame(frame_),
+ ScriptContext::GetDataSourceURLForFrame(frame_),
execution_results));
}
diff --git a/chrome/renderer/extensions/user_script_slave.cc b/chrome/renderer/extensions/user_script_slave.cc
index bdaff10..249b439 100644
--- a/chrome/renderer/extensions/user_script_slave.cc
+++ b/chrome/renderer/extensions/user_script_slave.cc
@@ -25,10 +25,10 @@
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/csp_info.h"
#include "extensions/common/permissions/permissions_data.h"
+#include "extensions/renderer/script_context.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebVector.h"
-#include "third_party/WebKit/public/web/WebDataSource.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
@@ -179,24 +179,9 @@ bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) {
return true;
}
-GURL UserScriptSlave::GetDataSourceURLForFrame(const WebFrame* frame) {
- // Normally we would use frame->document().url() to determine the document's
- // URL, but to decide whether to inject a content script, we use the URL from
- // the data source. This "quirk" helps prevents content scripts from
- // inadvertently adding DOM elements to the compose iframe in Gmail because
- // the compose iframe's dataSource URL is about:blank, but the document URL
- // changes to match the parent document after Gmail document.writes into
- // it to create the editor.
- // http://code.google.com/p/chromium/issues/detail?id=86742
- blink::WebDataSource* data_source = frame->provisionalDataSource() ?
- frame->provisionalDataSource() : frame->dataSource();
- CHECK(data_source);
- return GURL(data_source->request().url());
-}
-
void UserScriptSlave::InjectScripts(WebFrame* frame,
UserScript::RunLocation location) {
- GURL data_source_url = GetDataSourceURLForFrame(frame);
+ GURL data_source_url = ScriptContext::GetDataSourceURLForFrame(frame);
if (data_source_url.is_empty())
return;
@@ -302,7 +287,7 @@ void UserScriptSlave::InjectScripts(WebFrame* frame,
render_view->GetRoutingID(),
extensions_executing_scripts,
render_view->GetPageId(),
- GetDataSourceURLForFrame(top_frame)));
+ ScriptContext::GetDataSourceURLForFrame(top_frame)));
}
// Log debug info.
diff --git a/chrome/renderer/extensions/user_script_slave.h b/chrome/renderer/extensions/user_script_slave.h
index a538014c..2c7211b 100644
--- a/chrome/renderer/extensions/user_script_slave.h
+++ b/chrome/renderer/extensions/user_script_slave.h
@@ -32,10 +32,6 @@ class ExtensionSet;
// Manages installed UserScripts for a render process.
class UserScriptSlave {
public:
- // Utility to get the URL we will match against for a frame. If the frame has
- // committed, this is the commited URL. Otherwise it is the provisional URL.
- static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame);
-
explicit UserScriptSlave(const ExtensionSet* extensions);
~UserScriptSlave();
diff --git a/chrome/renderer/extensions/utils_native_handler.h b/chrome/renderer/extensions/utils_native_handler.h
index 41d95b0..b4e646b 100644
--- a/chrome/renderer/extensions/utils_native_handler.h
+++ b/chrome/renderer/extensions/utils_native_handler.h
@@ -5,9 +5,10 @@
#ifndef CHROME_RENDERER_EXTENSIONS_UTILS_NATIVE_HANDLER_H_
#define CHROME_RENDERER_EXTENSIONS_UTILS_NATIVE_HANDLER_H_
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
namespace extensions {
+class ChromeV8Context;
class UtilsNativeHandler : public ObjectBackedNativeHandler {
public:
diff --git a/chrome/renderer/extensions/v8_schema_registry.cc b/chrome/renderer/extensions/v8_schema_registry.cc
index 7a0975b..7c1b910 100644
--- a/chrome/renderer/extensions/v8_schema_registry.cc
+++ b/chrome/renderer/extensions/v8_schema_registry.cc
@@ -7,9 +7,9 @@
#include "base/logging.h"
#include "base/values.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
#include "content/public/renderer/v8_value_converter.h"
#include "extensions/common/extension_api.h"
+#include "extensions/renderer/object_backed_native_handler.h"
using content::V8ValueConverter;
diff --git a/chrome/renderer/resource_bundle_source_map.h b/chrome/renderer/resource_bundle_source_map.h
index a88b165..fddea7c 100644
--- a/chrome/renderer/resource_bundle_source_map.h
+++ b/chrome/renderer/resource_bundle_source_map.h
@@ -8,8 +8,8 @@
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/strings/string_piece.h"
-#include "chrome/renderer/extensions/module_system.h"
#include "chrome/renderer/static_v8_external_string_resource.h"
+#include "extensions/renderer/module_system.h"
#include "v8/include/v8.h"
#include <map>
diff --git a/chrome/test/base/module_system_test.cc b/chrome/test/base/module_system_test.cc
index 7d43e67..69976ba 100644
--- a/chrome/test/base/module_system_test.cc
+++ b/chrome/test/base/module_system_test.cc
@@ -15,9 +15,9 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "chrome/renderer/extensions/logging_native_handler.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
-#include "chrome/renderer/extensions/safe_builtins.h"
#include "chrome/renderer/extensions/utils_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
+#include "extensions/renderer/safe_builtins.h"
#include "ui/base/resource/resource_bundle.h"
#include <map>
diff --git a/chrome/test/base/module_system_test.h b/chrome/test/base/module_system_test.h
index 4a2959e..8402d57 100644
--- a/chrome/test/base/module_system_test.h
+++ b/chrome/test/base/module_system_test.h
@@ -6,7 +6,7 @@
#define CHROME_TEST_BASE_MODULE_SYSTEM_TEST_H_
#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "chrome/renderer/extensions/module_system.h"
+#include "extensions/renderer/module_system.h"
#include "extensions/renderer/scoped_persistent.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "v8/include/v8.h"
diff --git a/extensions/DEPS b/extensions/DEPS
index dbfc9ba..dc4fb7a 100644
--- a/extensions/DEPS
+++ b/extensions/DEPS
@@ -12,6 +12,8 @@ include_rules = [
#
# TODO(jamescook): Remove these. http://crbug.com/162530
"!chrome/browser/chrome_notification_types.h",
+ "!chrome/renderer/extensions/dispatcher.h",
+ "!chrome/renderer/extensions/extension_helper.h",
"!grit/chromium_strings.h",
"!grit/common_resources.h",
"!grit/extensions_api_resources.h",
diff --git a/extensions/common/extensions_client.h b/extensions/common/extensions_client.h
index 0b2e6cc..e9fb200 100644
--- a/extensions/common/extensions_client.h
+++ b/extensions/common/extensions_client.h
@@ -83,6 +83,10 @@ class ExtensionsClient {
// Appends extra filters to any Features created by the features system.
virtual void AddExtraFeatureFilters(SimpleFeature* feature) const = 0;
+ // Determines if certain fatal extensions errors should be surpressed
+ // (i.e., only logged) or allowed (i.e., logged before crashing).
+ virtual bool ShouldSuppressFatalErrors() const = 0;
+
// Return the extensions client.
static ExtensionsClient* Get();
diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp
index bf4a61d..658358b 100644
--- a/extensions/extensions.gyp
+++ b/extensions/extensions.gyp
@@ -413,9 +413,21 @@
'..',
],
'sources': [
+ 'renderer/console.cc',
+ 'renderer/console.h',
+ 'renderer/module_system.cc',
+ 'renderer/module_system.h',
'renderer/native_handler.cc',
'renderer/native_handler.h',
+ 'renderer/object_backed_native_handler.cc',
+ 'renderer/object_backed_native_handler.h',
+ 'renderer/request_sender.cc',
+ 'renderer/request_sender.h',
+ 'renderer/safe_builtins.cc',
+ 'renderer/safe_builtins.h',
'renderer/scoped_persistent.h',
+ 'renderer/script_context.cc',
+ 'renderer/script_context.h',
],
'dependencies': [
'../third_party/WebKit/public/blink.gyp:blink',
diff --git a/extensions/renderer/DEPS b/extensions/renderer/DEPS
index 3f29de9..3f93937 100644
--- a/extensions/renderer/DEPS
+++ b/extensions/renderer/DEPS
@@ -1,5 +1,11 @@
include_rules = [
+ "-content",
+ "+content/public/common",
+ "+content/public/renderer",
+
+ "+third_party/WebKit/public/web",
+
"-v8",
- "+v8/include"
+ "+v8/include",
]
diff --git a/chrome/renderer/extensions/console.cc b/extensions/renderer/console.cc
index 1c3dde3..c9f03f5 100644
--- a/chrome/renderer/extensions/console.cc
+++ b/extensions/renderer/console.cc
@@ -1,8 +1,8 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/extensions/console.h"
+#include "extensions/renderer/console.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
@@ -35,8 +35,7 @@ class ByContextFinder : public content::RenderViewVisitor {
private:
explicit ByContextFinder(v8::Handle<v8::Context> context)
- : context_(context), found_(NULL) {
- }
+ : context_(context), found_(NULL) {}
virtual bool Visit(content::RenderView* render_view) OVERRIDE {
ExtensionHelper* helper = ExtensionHelper::Get(render_view);
@@ -57,8 +56,8 @@ class ByContextFinder : public content::RenderViewVisitor {
void CheckWithMinidump(const std::string& message) {
char minidump[1024];
base::debug::Alias(&minidump);
- base::snprintf(minidump, arraysize(minidump),
- "e::console: %s", message.c_str());
+ base::snprintf(
+ minidump, arraysize(minidump), "e::console: %s", message.c_str());
CHECK(false) << message;
}
@@ -66,8 +65,8 @@ typedef void (*LogMethod)(v8::Handle<v8::Context> context,
const std::string& message);
void BoundLogMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
- LogMethod log_method = reinterpret_cast<LogMethod>(
- info.Data().As<v8::External>()->Value());
+ LogMethod log_method =
+ reinterpret_cast<LogMethod>(info.Data().As<v8::External>()->Value());
std::string message;
for (int i = 0; i < info.Length(); ++i) {
if (i > 0)
diff --git a/chrome/renderer/extensions/console.h b/extensions/renderer/console.h
index a1a6e28..847c54b 100644
--- a/chrome/renderer/extensions/console.h
+++ b/extensions/renderer/console.h
@@ -1,9 +1,9 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_EXTENSIONS_CONSOLE_H_
-#define CHROME_RENDERER_EXTENSIONS_CONSOLE_H_
+#ifndef EXTENSIONS_RENDERER_CONSOLE_H_
+#define EXTENSIONS_RENDERER_CONSOLE_H_
#include <string>
@@ -55,4 +55,4 @@ v8::Local<v8::Object> AsV8Object();
} // namespace extensions
-#endif // CHROME_RENDERER_EXTENSIONS_CONSOLE_H_
+#endif // EXTENSIONS_RENDERER_CONSOLE_H_
diff --git a/chrome/renderer/extensions/module_system.cc b/extensions/renderer/module_system.cc
index b050a9a..98daa20 100644
--- a/chrome/renderer/extensions/module_system.cc
+++ b/extensions/renderer/module_system.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/extensions/module_system.h"
+#include "extensions/renderer/module_system.h"
#include "base/bind.h"
#include "base/command_line.h"
@@ -10,13 +10,12 @@
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/features/feature_channel.h"
-#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "chrome/renderer/extensions/console.h"
-#include "chrome/renderer/extensions/safe_builtins.h"
#include "content/public/renderer/render_view.h"
#include "extensions/common/extension_messages.h"
+#include "extensions/common/extensions_client.h"
+#include "extensions/renderer/console.h"
+#include "extensions/renderer/safe_builtins.h"
+#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
@@ -39,7 +38,7 @@ const char* kModulesField = "modules";
// we're at the mercy of the extension or web page's environment. They can mess
// up our JS in unexpected ways. Hopefully dev/canary channel will pick up such
// problems, but given the wider variety on stable/beta it's impossible to know.
-void Fatal(ChromeV8Context* context, const std::string& message) {
+void Fatal(ScriptContext* context, const std::string& message) {
// Prepend some context metadata.
std::string full_message = "(";
if (!context->is_valid())
@@ -53,11 +52,10 @@ void Fatal(ChromeV8Context* context, const std::string& message) {
full_message += ") ";
full_message += message;
- // <= dev means dev, canary, and trunk.
- if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV)
- console::Fatal(context->isolate()->GetCallingContext(), full_message);
- else
+ if (ExtensionsClient::Get()->ShouldSuppressFatalErrors())
console::Error(context->isolate()->GetCallingContext(), full_message);
+ else
+ console::Fatal(context->isolate()->GetCallingContext(), full_message);
}
void Warn(v8::Isolate* isolate, const std::string& message) {
@@ -67,7 +65,7 @@ void Warn(v8::Isolate* isolate, const std::string& message) {
// Default exception handler which logs the exception.
class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler {
public:
- explicit DefaultExceptionHandler(ChromeV8Context* context)
+ explicit DefaultExceptionHandler(ScriptContext* context)
: context_(context) {}
// Fatally dumps the debug info from |try_catch| to the console.
@@ -87,10 +85,10 @@ class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler {
}
private:
- ChromeV8Context* context_;
+ ScriptContext* context_;
};
-} // namespace
+} // namespace
std::string ModuleSystem::ExceptionHandler::CreateExceptionString(
const v8::TryCatch& try_catch) {
@@ -118,32 +116,30 @@ std::string ModuleSystem::ExceptionHandler::CreateExceptionString(
error_message.c_str());
}
-ModuleSystem::ModuleSystem(ChromeV8Context* context, SourceMap* source_map)
+ModuleSystem::ModuleSystem(ScriptContext* context, SourceMap* source_map)
: ObjectBackedNativeHandler(context),
context_(context),
source_map_(source_map),
natives_enabled_(0),
exception_handler_(new DefaultExceptionHandler(context)) {
- RouteFunction("require",
+ RouteFunction(
+ "require",
base::Bind(&ModuleSystem::RequireForJs, base::Unretained(this)));
- RouteFunction("requireNative",
+ RouteFunction(
+ "requireNative",
base::Bind(&ModuleSystem::RequireNative, base::Unretained(this)));
RouteFunction("privates",
- base::Bind(&ModuleSystem::Private, base::Unretained(this)));
+ base::Bind(&ModuleSystem::Private, base::Unretained(this)));
v8::Handle<v8::Object> global(context->v8_context()->Global());
v8::Isolate* isolate = context->isolate();
- global->SetHiddenValue(
- v8::String::NewFromUtf8(isolate, kModulesField),
- v8::Object::New(isolate));
- global->SetHiddenValue(
- v8::String::NewFromUtf8(isolate, kModuleSystem),
- v8::External::New(isolate, this));
+ global->SetHiddenValue(v8::String::NewFromUtf8(isolate, kModulesField),
+ v8::Object::New(isolate));
+ global->SetHiddenValue(v8::String::NewFromUtf8(isolate, kModuleSystem),
+ v8::External::New(isolate, this));
}
-ModuleSystem::~ModuleSystem() {
- Invalidate();
-}
+ModuleSystem::~ModuleSystem() { Invalidate(); }
void ModuleSystem::Invalidate() {
if (!is_valid())
@@ -162,7 +158,8 @@ void ModuleSystem::Invalidate() {
// Invalidate all of the successfully required handlers we own.
for (NativeHandlerMap::iterator it = native_handler_map_.begin();
- it != native_handler_map_.end(); ++it) {
+ it != native_handler_map_.end();
+ ++it) {
it->second->Invalidate();
}
@@ -191,7 +188,7 @@ v8::Handle<v8::Value> ModuleSystem::Require(const std::string& module_name) {
}
void ModuleSystem::RequireForJs(
- const v8::FunctionCallbackInfo<v8::Value>& args) {
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Handle<v8::String> module_name = args[0]->ToString();
args.GetReturnValue().Set(RequireForJsInner(module_name));
}
@@ -224,8 +221,8 @@ v8::Local<v8::Value> ModuleSystem::RequireForJsInner(
Fatal(context_, "No source for require(" + module_name_str + ")");
return v8::Undefined(GetIsolate());
}
- v8::Handle<v8::String> wrapped_source(WrapSource(
- v8::Handle<v8::String>::Cast(source)));
+ v8::Handle<v8::String> wrapped_source(
+ WrapSource(v8::Handle<v8::String>::Cast(source)));
// Modules are wrapped in (function(){...}) so they always return functions.
v8::Handle<v8::Value> func_as_value = RunString(wrapped_source, module_name);
if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) {
@@ -292,9 +289,12 @@ v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
const std::string& method_name,
int argc,
v8::Handle<v8::Value> argv[]) {
- TRACE_EVENT2("v8", "v8.callModuleMethod",
- "module_name", module_name,
- "method_name", method_name);
+ TRACE_EVENT2("v8",
+ "v8.callModuleMethod",
+ "module_name",
+ module_name,
+ "method_name",
+ method_name);
v8::EscapableHandleScope handle_scope(GetIsolate());
v8::Context::Scope context_scope(context()->v8_context());
@@ -313,9 +313,8 @@ v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
v8::Local<v8::Primitive>(v8::Undefined(GetIsolate())));
}
- v8::Local<v8::Value> value =
- v8::Handle<v8::Object>::Cast(module)->Get(
- v8::String::NewFromUtf8(GetIsolate(), method_name.c_str()));
+ v8::Local<v8::Value> value = v8::Handle<v8::Object>::Cast(module)->Get(
+ v8::String::NewFromUtf8(GetIsolate(), method_name.c_str()));
if (value.IsEmpty() || !value->IsFunction()) {
Fatal(context_, module_name + "." + method_name + " is not a function");
return handle_scope.Escape(
@@ -334,7 +333,8 @@ v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
return handle_scope.Escape(result);
}
-void ModuleSystem::RegisterNativeHandler(const std::string& name,
+void ModuleSystem::RegisterNativeHandler(
+ const std::string& name,
scoped_ptr<NativeHandler> native_handler) {
native_handler_map_[name] =
linked_ptr<NativeHandler>(native_handler.release());
@@ -354,9 +354,7 @@ void ModuleSystem::RunString(const std::string& code, const std::string& name) {
void ModuleSystem::NativeLazyFieldGetter(
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
- LazyFieldGetterInner(property,
- info,
- &ModuleSystem::RequireNativeFromString);
+ LazyFieldGetterInner(property, info, &ModuleSystem::RequireNativeFromString);
}
// static
@@ -391,8 +389,10 @@ void ModuleSystem::LazyFieldGetterInner(
ModuleSystem* module_system = static_cast<ModuleSystem*>(
v8::Handle<v8::External>::Cast(module_system_value)->Value());
- std::string name = *v8::String::Utf8Value(parameters->Get(
- v8::String::NewFromUtf8(info.GetIsolate(), kModuleName))->ToString());
+ std::string name =
+ *v8::String::Utf8Value(
+ parameters->Get(v8::String::NewFromUtf8(info.GetIsolate(),
+ kModuleName))->ToString());
// Switch to our v8 context because we need functions created while running
// the require()d module to belong to our context, not the current one.
@@ -445,8 +445,8 @@ void ModuleSystem::SetLazyField(v8::Handle<v8::Object> object,
const std::string& field,
const std::string& module_name,
const std::string& module_field) {
- SetLazyField(object, field, module_name, module_field,
- &ModuleSystem::LazyFieldGetter);
+ SetLazyField(
+ object, field, module_name, module_field, &ModuleSystem::LazyFieldGetter);
}
void ModuleSystem::SetLazyField(v8::Handle<v8::Object> object,
@@ -470,11 +470,13 @@ void ModuleSystem::SetNativeLazyField(v8::Handle<v8::Object> object,
const std::string& field,
const std::string& module_name,
const std::string& module_field) {
- SetLazyField(object, field, module_name, module_field,
- &ModuleSystem::NativeLazyFieldGetter);
+ SetLazyField(object,
+ field,
+ module_name,
+ module_field,
+ &ModuleSystem::NativeLazyFieldGetter);
}
-
v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code,
v8::Handle<v8::String> name) {
v8::EscapableHandleScope handle_scope(GetIsolate());
@@ -482,8 +484,8 @@ v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code,
// Prepend extensions:: to |name| so that internal code can be differentiated
// from external code in stack traces. This has no effect on behaviour.
- std::string internal_name = base::StringPrintf("extensions::%s",
- *v8::String::Utf8Value(name));
+ std::string internal_name =
+ base::StringPrintf("extensions::%s", *v8::String::Utf8Value(name));
blink::WebScopedMicrotaskSuppression suppression;
v8::TryCatch try_catch;
diff --git a/chrome/renderer/extensions/module_system.h b/extensions/renderer/module_system.h
index 10caafe..eec25cc 100644
--- a/chrome/renderer/extensions/module_system.h
+++ b/extensions/renderer/module_system.h
@@ -1,25 +1,25 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_
-#define CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_
+#ifndef EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
+#define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
#include "extensions/renderer/native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
#include "v8/include/v8.h"
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
namespace extensions {
-class ChromeV8Context;
+class ScriptContext;
// A module system for JS similar to node.js' require() function.
// Each module has three variables in the global scope:
@@ -69,7 +69,7 @@ class ModuleSystem : public ObjectBackedNativeHandler {
};
// |source_map| is a weak pointer.
- ModuleSystem(ChromeV8Context* context, SourceMap* source_map);
+ ModuleSystem(ScriptContext* context, SourceMap* source_map);
virtual ~ModuleSystem();
// Require the specified module. This is the equivalent of calling
@@ -90,11 +90,10 @@ class ModuleSystem : public ObjectBackedNativeHandler {
const std::string& module_name,
const std::string& method_name,
std::vector<v8::Handle<v8::Value> >* args);
- v8::Local<v8::Value> CallModuleMethod(
- const std::string& module_name,
- const std::string& method_name,
- int argc,
- v8::Handle<v8::Value> argv[]);
+ v8::Local<v8::Value> CallModuleMethod(const std::string& module_name,
+ const std::string& method_name,
+ int argc,
+ v8::Handle<v8::Value> argv[]);
// Register |native_handler| as a potential target for requireNative(), so
// calls to requireNative(|name|) from JS will return a new object created by
@@ -141,7 +140,7 @@ class ModuleSystem : public ObjectBackedNativeHandler {
}
protected:
- friend class ChromeV8Context;
+ friend class ScriptContext;
virtual void Invalidate() OVERRIDE;
private:
@@ -165,7 +164,7 @@ class ModuleSystem : public ObjectBackedNativeHandler {
void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Local<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name);
- typedef v8::Handle<v8::Value> (ModuleSystem::*RequireFunction)(
+ typedef v8::Handle<v8::Value>(ModuleSystem::*RequireFunction)(
const std::string&);
// Base implementation of a LazyFieldGetter which uses |require_fn| to require
// modules.
@@ -194,7 +193,7 @@ class ModuleSystem : public ObjectBackedNativeHandler {
// provided function.
void CreateFunctionWrapper(const v8::FunctionCallbackInfo<v8::Value>& args);
- ChromeV8Context* context_;
+ ScriptContext* context_;
// A map from module names to the JS source for that module. GetSource()
// performs a lookup on this map.
@@ -218,4 +217,4 @@ class ModuleSystem : public ObjectBackedNativeHandler {
} // namespace extensions
-#endif // CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_
+#endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
diff --git a/chrome/renderer/extensions/object_backed_native_handler.cc b/extensions/renderer/object_backed_native_handler.cc
index 5496f48..9b699bc 100644
--- a/chrome/renderer/extensions/object_backed_native_handler.cc
+++ b/extensions/renderer/object_backed_native_handler.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "extensions/renderer/object_backed_native_handler.h"
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
-#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "chrome/renderer/extensions/console.h"
-#include "chrome/renderer/extensions/module_system.h"
+#include "extensions/renderer/console.h"
+#include "extensions/renderer/module_system.h"
+#include "extensions/renderer/script_context.h"
#include "v8/include/v8.h"
namespace extensions {
@@ -18,15 +18,13 @@ namespace {
const char* kHandlerFunction = "handler_function";
} // namespace
-ObjectBackedNativeHandler::ObjectBackedNativeHandler(ChromeV8Context* context)
+ObjectBackedNativeHandler::ObjectBackedNativeHandler(ScriptContext* context)
: router_data_(context->v8_context()->GetIsolate()),
context_(context),
object_template_(
v8::ObjectTemplate::New(context->v8_context()->GetIsolate())) {}
-ObjectBackedNativeHandler::~ObjectBackedNativeHandler() {
- Invalidate();
-}
+ObjectBackedNativeHandler::~ObjectBackedNativeHandler() { Invalidate(); }
v8::Handle<v8::Object> ObjectBackedNativeHandler::NewInstance() {
return object_template_.NewHandle(v8::Isolate::GetCurrent())->NewInstance();
@@ -97,4 +95,4 @@ void ObjectBackedNativeHandler::Invalidate() {
NativeHandler::Invalidate();
}
-} // namespace extensions
+} // namespace extensions
diff --git a/chrome/renderer/extensions/object_backed_native_handler.h b/extensions/renderer/object_backed_native_handler.h
index 87bee00..b87cd96 100644
--- a/chrome/renderer/extensions/object_backed_native_handler.h
+++ b/extensions/renderer/object_backed_native_handler.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
-#define CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
+#ifndef EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_
+#define EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_
#include <string>
#include <vector>
@@ -16,14 +16,14 @@
#include "v8/include/v8.h"
namespace extensions {
-class ChromeV8Context;
+class ScriptContext;
// An ObjectBackedNativeHandler is a factory for JS objects with functions on
// them that map to native C++ functions. Subclasses should call RouteFunction()
// in their constructor to define functions on the created JS objects.
class ObjectBackedNativeHandler : public NativeHandler {
public:
- explicit ObjectBackedNativeHandler(ChromeV8Context* context);
+ explicit ObjectBackedNativeHandler(ScriptContext* context);
virtual ~ObjectBackedNativeHandler();
// Create an object with bindings to the native functions defined through
@@ -42,7 +42,7 @@ class ObjectBackedNativeHandler : public NativeHandler {
void RouteFunction(const std::string& name,
const HandlerFunction& handler_function);
- ChromeV8Context* context() const { return context_; }
+ ScriptContext* context() const { return context_; }
virtual void Invalidate() OVERRIDE;
@@ -67,7 +67,7 @@ class ObjectBackedNativeHandler : public NativeHandler {
typedef v8::PersistentValueVector<v8::Object> RouterData;
RouterData router_data_;
- ChromeV8Context* context_;
+ ScriptContext* context_;
ScopedPersistent<v8::ObjectTemplate> object_template_;
@@ -76,4 +76,4 @@ class ObjectBackedNativeHandler : public NativeHandler {
} // namespace extensions
-#endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
+#endif // EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_
diff --git a/chrome/renderer/extensions/request_sender.cc b/extensions/renderer/request_sender.cc
index 597f3fb..3203d0d 100644
--- a/chrome/renderer/extensions/request_sender.cc
+++ b/extensions/renderer/request_sender.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/extensions/request_sender.h"
+#include "extensions/renderer/request_sender.h"
#include "base/values.h"
-#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "chrome/renderer/extensions/dispatcher.h"
#include "content/public/renderer/render_view.h"
#include "extensions/common/extension_messages.h"
+#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
@@ -17,10 +17,9 @@ namespace extensions {
// Contains info relevant to a pending API request.
struct PendingRequest {
- public :
+ public:
PendingRequest(const std::string& name, RequestSender::Source* source)
- : name(name), source(source) {
- }
+ : name(name), source(source) {}
std::string name;
RequestSender::Source* source;
@@ -40,12 +39,9 @@ RequestSender::ScopedTabID::~ScopedTabID() {
}
RequestSender::RequestSender(Dispatcher* dispatcher)
- : dispatcher_(dispatcher),
- source_tab_id_(-1) {
-}
+ : dispatcher_(dispatcher), source_tab_id_(-1) {}
-RequestSender::~RequestSender() {
-}
+RequestSender::~RequestSender() {}
void RequestSender::InsertRequest(int request_id,
PendingRequest* pending_request) {
@@ -73,7 +69,7 @@ void RequestSender::StartRequest(Source* source,
bool has_callback,
bool for_io_thread,
base::ListValue* value_args) {
- ChromeV8Context* context = source->GetContext();
+ ScriptContext* context = source->GetContext();
if (!context)
return;
@@ -85,8 +81,9 @@ void RequestSender::StartRequest(Source* source,
const std::set<std::string>& function_names = dispatcher_->function_names();
if (function_names.find(name) == function_names.end()) {
- NOTREACHED() << "Unexpected function " << name <<
- ". Did you remember to register it with ExtensionFunctionRegistry?";
+ NOTREACHED()
+ << "Unexpected function " << name
+ << ". Did you remember to register it with ExtensionFunctionRegistry?";
return;
}
@@ -114,8 +111,8 @@ void RequestSender::StartRequest(Source* source,
renderview->Send(new ExtensionHostMsg_RequestForIOThread(
renderview->GetRoutingID(), params));
} else {
- renderview->Send(new ExtensionHostMsg_Request(
- renderview->GetRoutingID(), params));
+ renderview->Send(
+ new ExtensionHostMsg_Request(renderview->GetRoutingID(), params));
}
}
@@ -130,8 +127,8 @@ void RequestSender::HandleResponse(int request_id,
return;
}
- request->source->OnResponseReceived(request->name, request_id, success,
- response, error);
+ request->source->OnResponseReceived(
+ request->name, request_id, success, response, error);
}
void RequestSender::InvalidateSource(Source* source) {
diff --git a/chrome/renderer/extensions/request_sender.h b/extensions/renderer/request_sender.h
index 1f59ab8..c3b8538 100644
--- a/chrome/renderer/extensions/request_sender.h
+++ b/extensions/renderer/request_sender.h
@@ -1,12 +1,12 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_
-#define CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_
+#ifndef EXTENSIONS_RENDERER_REQUEST_SENDER_H_
+#define EXTENSIONS_RENDERER_REQUEST_SENDER_H_
-#include <string>
#include <map>
+#include <string>
#include "base/memory/linked_ptr.h"
#include "v8/include/v8.h"
@@ -16,8 +16,8 @@ class ListValue;
}
namespace extensions {
-class ChromeV8Context;
class Dispatcher;
+class ScriptContext;
struct PendingRequest;
@@ -34,7 +34,7 @@ class RequestSender {
public:
virtual ~Source() {}
- virtual ChromeV8Context* GetContext() = 0;
+ virtual ScriptContext* GetContext() = 0;
virtual void OnResponseReceived(const std::string& name,
int request_id,
bool success,
@@ -103,4 +103,4 @@ class RequestSender {
} // namespace extensions
-#endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_
+#endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_
diff --git a/chrome/renderer/extensions/safe_builtins.cc b/extensions/renderer/safe_builtins.cc
index 783a910..1f32aaf 100644
--- a/chrome/renderer/extensions/safe_builtins.cc
+++ b/extensions/renderer/safe_builtins.cc
@@ -1,13 +1,13 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/extensions/safe_builtins.h"
+#include "extensions/renderer/safe_builtins.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
-#include "chrome/renderer/extensions/chrome_v8_context.h"
+#include "extensions/renderer/script_context.h"
namespace extensions {
@@ -127,8 +127,8 @@ void SaveImpl(const char* name,
v8::Local<v8::Value> value,
v8::Local<v8::Context> context) {
CHECK(!value.IsEmpty() && value->IsObject()) << name;
- context->Global()
- ->SetHiddenValue(MakeKey(name, context->GetIsolate()), value);
+ context->Global()->SetHiddenValue(MakeKey(name, context->GetIsolate()),
+ value);
}
v8::Local<v8::Object> Load(const char* name, v8::Handle<v8::Context> context) {
@@ -155,12 +155,11 @@ class ExtensionImpl : public v8::Extension {
}
static void Apply(const v8::FunctionCallbackInfo<v8::Value>& info) {
- CHECK(info.Length() == 5 &&
- info[0]->IsFunction() && // function
+ CHECK(info.Length() == 5 && info[0]->IsFunction() && // function
// info[1] could be an object or a string
- info[2]->IsObject() && // args
- info[3]->IsInt32() && // first_arg_index
- info[4]->IsInt32()); // args_length
+ info[2]->IsObject() && // args
+ info[3]->IsInt32() && // first_arg_index
+ info[4]->IsInt32()); // args_length
v8::Local<v8::Function> function = info[0].As<v8::Function>();
v8::Local<v8::Object> recv;
if (info[1]->IsObject()) {
@@ -179,7 +178,7 @@ class ExtensionImpl : public v8::Extension {
int args_length = static_cast<int>(info[4]->ToInt32()->Value());
int argc = args_length - first_arg_index;
- scoped_ptr<v8::Local<v8::Value>[]> argv(new v8::Local<v8::Value>[argc]);
+ scoped_ptr<v8::Local<v8::Value> []> argv(new v8::Local<v8::Value>[argc]);
for (int i = 0; i < argc; ++i) {
CHECK(args->Has(i + first_arg_index));
argv[i] = args->Get(i + first_arg_index);
@@ -191,9 +190,7 @@ class ExtensionImpl : public v8::Extension {
}
static void Save(const v8::FunctionCallbackInfo<v8::Value>& info) {
- CHECK(info.Length() == 2 &&
- info[0]->IsString() &&
- info[1]->IsObject());
+ CHECK(info.Length() == 2 && info[0]->IsString() && info[1]->IsObject());
SaveImpl(*v8::String::Utf8Value(info[0]),
info[1],
info.GetIsolate()->GetCallingContext());
@@ -203,11 +200,9 @@ class ExtensionImpl : public v8::Extension {
} // namespace
// static
-v8::Extension* SafeBuiltins::CreateV8Extension() {
- return new ExtensionImpl();
-}
+v8::Extension* SafeBuiltins::CreateV8Extension() { return new ExtensionImpl(); }
-SafeBuiltins::SafeBuiltins(ChromeV8Context* context) : context_(context) {}
+SafeBuiltins::SafeBuiltins(ScriptContext* context) : context_(context) {}
SafeBuiltins::~SafeBuiltins() {}
@@ -235,4 +230,4 @@ v8::Local<v8::Object> SafeBuiltins::GetString() const {
return Load("String", context_->v8_context());
}
-} // namespace extensions
+} // namespace extensions
diff --git a/chrome/renderer/extensions/safe_builtins.h b/extensions/renderer/safe_builtins.h
index f34a949..3c8db44 100644
--- a/chrome/renderer/extensions/safe_builtins.h
+++ b/extensions/renderer/safe_builtins.h
@@ -1,14 +1,14 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_EXTENSIONS_SAFE_BUILTINS_H_
-#define CHROME_RENDERER_EXTENSIONS_SAFE_BUILTINS_H_
+#ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
+#define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
#include "v8/include/v8.h"
namespace extensions {
-class ChromeV8Context;
+class ScriptContext;
// A collection of safe builtin objects, in that they won't be tained by
// extensions overriding methods on them.
@@ -17,7 +17,7 @@ class SafeBuiltins {
// Creates the v8::Extension which manages SafeBuiltins instances.
static v8::Extension* CreateV8Extension();
- explicit SafeBuiltins(ChromeV8Context* context);
+ explicit SafeBuiltins(ScriptContext* context);
virtual ~SafeBuiltins();
@@ -38,9 +38,9 @@ class SafeBuiltins {
v8::Local<v8::Object> GetString() const;
private:
- ChromeV8Context* context_;
+ ScriptContext* context_;
};
-} // namespace extensions
+} // namespace extensions
-#endif // CHROME_RENDERER_EXTENSIONS_SAFE_BUILTINS_H_
+#endif // EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
diff --git a/extensions/renderer/script_context.cc b/extensions/renderer/script_context.cc
new file mode 100644
index 0000000..77f72aa
--- /dev/null
+++ b/extensions/renderer/script_context.cc
@@ -0,0 +1,191 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/renderer/script_context.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_split.h"
+#include "base/values.h"
+#include "content/public/renderer/render_view.h"
+#include "content/public/renderer/v8_value_converter.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_api.h"
+#include "extensions/common/extension_urls.h"
+#include "extensions/common/features/base_feature_provider.h"
+#include "third_party/WebKit/public/web/WebDataSource.h"
+#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
+#include "third_party/WebKit/public/web/WebView.h"
+#include "v8/include/v8.h"
+
+using content::V8ValueConverter;
+
+namespace extensions {
+
+ScriptContext::ScriptContext(v8::Handle<v8::Context> v8_context,
+ blink::WebFrame* web_frame,
+ const Extension* extension,
+ Feature::Context context_type)
+ : v8_context_(v8_context),
+ web_frame_(web_frame),
+ extension_(extension),
+ context_type_(context_type),
+ safe_builtins_(this),
+ isolate_(v8_context->GetIsolate()) {
+ VLOG(1) << "Created context:\n"
+ << " extension id: " << GetExtensionID() << "\n"
+ << " frame: " << web_frame_ << "\n"
+ << " context type: " << GetContextTypeDescription();
+}
+
+ScriptContext::~ScriptContext() {
+ VLOG(1) << "Destroyed context for extension\n"
+ << " extension id: " << GetExtensionID();
+ Invalidate();
+}
+
+void ScriptContext::Invalidate() {
+ if (!is_valid())
+ return;
+ if (module_system_)
+ module_system_->Invalidate();
+ web_frame_ = NULL;
+ v8_context_.reset();
+}
+
+std::string ScriptContext::GetExtensionID() const {
+ return extension_.get() ? extension_->id() : std::string();
+}
+
+content::RenderView* ScriptContext::GetRenderView() const {
+ if (web_frame_ && web_frame_->view())
+ return content::RenderView::FromWebView(web_frame_->view());
+ else
+ return NULL;
+}
+
+v8::Local<v8::Value> ScriptContext::CallFunction(
+ v8::Handle<v8::Function> function,
+ int argc,
+ v8::Handle<v8::Value> argv[]) const {
+ v8::EscapableHandleScope handle_scope(isolate());
+ v8::Context::Scope scope(v8_context());
+
+ blink::WebScopedMicrotaskSuppression suppression;
+ if (!is_valid()) {
+ return handle_scope.Escape(
+ v8::Local<v8::Primitive>(v8::Undefined(isolate())));
+ }
+
+ v8::Handle<v8::Object> global = v8_context()->Global();
+ if (!web_frame_)
+ return handle_scope.Escape(function->Call(global, argc, argv));
+ return handle_scope.Escape(
+ v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled(
+ function, global, argc, argv)));
+}
+
+Feature::Availability ScriptContext::GetAvailability(
+ const std::string& api_name) {
+ // Hack: Hosted apps should have the availability of messaging APIs based on
+ // the URL of the page (which might have access depending on some extension
+ // with externally_connectable), not whether the app has access to messaging
+ // (which it won't).
+ const Extension* extension = extension_.get();
+ if (extension && extension->is_hosted_app() &&
+ (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) {
+ extension = NULL;
+ }
+ return ExtensionAPI::GetSharedInstance()->IsAvailable(
+ api_name, extension, context_type_, GetURL());
+}
+
+void ScriptContext::DispatchEvent(const char* event_name,
+ v8::Handle<v8::Array> args) const {
+ v8::HandleScope handle_scope(isolate());
+ v8::Context::Scope context_scope(v8_context());
+
+ v8::Handle<v8::Value> argv[] = {
+ v8::String::NewFromUtf8(isolate(), event_name), args};
+ module_system_->CallModuleMethod(
+ kEventBindings, "dispatchEvent", arraysize(argv), argv);
+}
+
+void ScriptContext::DispatchOnUnloadEvent() {
+ module_system_->CallModuleMethod("unload_event", "dispatch");
+}
+
+std::string ScriptContext::GetContextTypeDescription() {
+ switch (context_type_) {
+ case Feature::UNSPECIFIED_CONTEXT:
+ return "UNSPECIFIED";
+ case Feature::BLESSED_EXTENSION_CONTEXT:
+ return "BLESSED_EXTENSION";
+ case Feature::UNBLESSED_EXTENSION_CONTEXT:
+ return "UNBLESSED_EXTENSION";
+ case Feature::CONTENT_SCRIPT_CONTEXT:
+ return "CONTENT_SCRIPT";
+ case Feature::WEB_PAGE_CONTEXT:
+ return "WEB_PAGE";
+ case Feature::BLESSED_WEB_PAGE_CONTEXT:
+ return "BLESSED_WEB_PAGE";
+ }
+ NOTREACHED();
+ return std::string();
+}
+
+GURL ScriptContext::GetURL() const {
+ return web_frame() ? GetDataSourceURLForFrame(web_frame()) : GURL();
+}
+
+bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) {
+ return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
+ api, extension(), context_type(), GetDataSourceURLForFrame(web_frame()));
+}
+
+// static
+GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) {
+ // Normally we would use frame->document().url() to determine the document's
+ // URL, but to decide whether to inject a content script, we use the URL from
+ // the data source. This "quirk" helps prevents content scripts from
+ // inadvertently adding DOM elements to the compose iframe in Gmail because
+ // the compose iframe's dataSource URL is about:blank, but the document URL
+ // changes to match the parent document after Gmail document.writes into
+ // it to create the editor.
+ // http://code.google.com/p/chromium/issues/detail?id=86742
+ blink::WebDataSource* data_source = frame->provisionalDataSource()
+ ? frame->provisionalDataSource()
+ : frame->dataSource();
+ CHECK(data_source);
+ return GURL(data_source->request().url());
+}
+
+ScriptContext* ScriptContext::GetContext() { return this; }
+
+void ScriptContext::OnResponseReceived(const std::string& name,
+ int request_id,
+ bool success,
+ const base::ListValue& response,
+ const std::string& error) {
+ v8::HandleScope handle_scope(isolate());
+
+ scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
+ v8::Handle<v8::Value> argv[] = {
+ v8::Integer::New(isolate(), request_id),
+ v8::String::NewFromUtf8(isolate(), name.c_str()),
+ v8::Boolean::New(isolate(), success),
+ converter->ToV8Value(&response, v8_context_.NewHandle(isolate())),
+ v8::String::NewFromUtf8(isolate(), error.c_str())};
+
+ v8::Handle<v8::Value> retval = module_system()->CallModuleMethod(
+ "sendRequest", "handleResponse", arraysize(argv), argv);
+
+ // In debug, the js will validate the callback parameters and return a
+ // string if a validation error has occured.
+ DCHECK(retval.IsEmpty() || retval->IsUndefined())
+ << *v8::String::Utf8Value(retval);
+}
+
+} // namespace extensions
diff --git a/extensions/renderer/script_context.h b/extensions/renderer/script_context.h
new file mode 100644
index 0000000..c2cbb04
--- /dev/null
+++ b/extensions/renderer/script_context.h
@@ -0,0 +1,145 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
+#define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "extensions/common/features/feature.h"
+#include "extensions/renderer/module_system.h"
+#include "extensions/renderer/request_sender.h"
+#include "extensions/renderer/safe_builtins.h"
+#include "extensions/renderer/scoped_persistent.h"
+#include "v8/include/v8.h"
+
+namespace blink {
+class WebFrame;
+}
+
+namespace content {
+class RenderView;
+}
+
+namespace extensions {
+class Extension;
+
+// Extensions wrapper for a v8 context.
+class ScriptContext : public RequestSender::Source {
+ public:
+ ScriptContext(v8::Handle<v8::Context> context,
+ blink::WebFrame* frame,
+ const Extension* extension,
+ Feature::Context context_type);
+ virtual ~ScriptContext();
+
+ // Clears the WebFrame for this contexts and invalidates the associated
+ // ModuleSystem.
+ void Invalidate();
+
+ // Returns true if this context is still valid, false if it isn't.
+ // A context becomes invalid via Invalidate().
+ bool is_valid() const { return !v8_context_.IsEmpty(); }
+
+ v8::Handle<v8::Context> v8_context() const {
+ return v8_context_.NewHandle(v8::Isolate::GetCurrent());
+ }
+
+ const Extension* extension() const { return extension_.get(); }
+
+ blink::WebFrame* web_frame() const { return web_frame_; }
+
+ Feature::Context context_type() const { return context_type_; }
+
+ void set_module_system(scoped_ptr<ModuleSystem> module_system) {
+ module_system_ = module_system.Pass();
+ }
+
+ ModuleSystem* module_system() { return module_system_.get(); }
+
+ SafeBuiltins* safe_builtins() { return &safe_builtins_; }
+
+ const SafeBuiltins* safe_builtins() const { return &safe_builtins_; }
+
+ // Returns the ID of the extension associated with this context, or empty
+ // string if there is no such extension.
+ std::string GetExtensionID() const;
+
+ // Returns the RenderView associated with this context. Can return NULL if the
+ // context is in the process of being destroyed.
+ content::RenderView* GetRenderView() const;
+
+ // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers
+ // must do that if they want.
+ //
+ // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE.
+ v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function,
+ int argc,
+ v8::Handle<v8::Value> argv[]) const;
+
+ void DispatchEvent(const char* event_name, v8::Handle<v8::Array> args) const;
+
+ // Fires the onunload event on the unload_event module.
+ void DispatchOnUnloadEvent();
+
+ // Returns the availability of the API |api_name|.
+ Feature::Availability GetAvailability(const std::string& api_name);
+
+ // Returns a string description of the type of context this is.
+ std::string GetContextTypeDescription();
+
+ v8::Isolate* isolate() const { return isolate_; }
+
+ // Get the URL of this context's web frame.
+ GURL GetURL() const;
+
+ // Returns whether the API |api| or any part of the API could be
+ // available in this context without taking into account the context's
+ // extension.
+ bool IsAnyFeatureAvailableToContext(const extensions::Feature& api);
+
+ // Utility to get the URL we will match against for a frame. If the frame has
+ // committed, this is the commited URL. Otherwise it is the provisional URL.
+ static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame);
+
+ // RequestSender::Source implementation.
+ virtual ScriptContext* GetContext() OVERRIDE;
+ virtual void OnResponseReceived(const std::string& name,
+ int request_id,
+ bool success,
+ const base::ListValue& response,
+ const std::string& error) OVERRIDE;
+
+ protected:
+ // The v8 context the bindings are accessible to.
+ ScopedPersistent<v8::Context> v8_context_;
+
+ private:
+ // The WebFrame associated with this context. This can be NULL because this
+ // object can outlive is destroyed asynchronously.
+ blink::WebFrame* web_frame_;
+
+ // The extension associated with this context, or NULL if there is none. This
+ // might be a hosted app in the case that this context is hosting a web URL.
+ scoped_refptr<const Extension> extension_;
+
+ // The type of context.
+ Feature::Context context_type_;
+
+ // Owns and structures the JS that is injected to set up extension bindings.
+ scoped_ptr<ModuleSystem> module_system_;
+
+ // Contains safe copies of builtin objects like Function.prototype.
+ SafeBuiltins safe_builtins_;
+
+ v8::Isolate* isolate_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScriptContext);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_