Index: chrome/renderer/extensions/extension_dispatcher.cc |
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc |
index 9dc2c8954edc4be345b945cc391a0e72a98ad5d3..840e68d2c4b4384317b2a79c9ccb164c1e0b6818 100644 |
--- a/chrome/renderer/extensions/extension_dispatcher.cc |
+++ b/chrome/renderer/extensions/extension_dispatcher.cc |
@@ -195,6 +195,56 @@ class LazyBackgroundPageNativeHandler : public ChromeV8Extension { |
} |
}; |
+class ProcessInfoNativeHandler : public ChromeV8Extension { |
+ public: |
+ explicit ProcessInfoNativeHandler( |
+ ExtensionDispatcher* dispatcher, |
+ const std::string& extension_id, |
+ const std::string& context_type, |
+ bool is_incognito_context, |
+ int manifest_version) |
+ : ChromeV8Extension(dispatcher), |
+ extension_id_(extension_id), |
+ context_type_(context_type), |
+ is_incognito_context_(is_incognito_context), |
+ manifest_version_(manifest_version) { |
+ RouteFunction("GetExtensionId", |
+ base::Bind(&ProcessInfoNativeHandler::GetExtensionId, |
+ base::Unretained(this))); |
+ RouteFunction("GetContextType", |
+ base::Bind(&ProcessInfoNativeHandler::GetContextType, |
+ base::Unretained(this))); |
+ RouteFunction("IsIncognitoContext", |
+ base::Bind(&ProcessInfoNativeHandler::IsIncognitoContext, |
+ base::Unretained(this))); |
+ RouteFunction("GetManifestVersion", |
+ base::Bind(&ProcessInfoNativeHandler::GetManifestVersion, |
+ base::Unretained(this))); |
+ } |
+ |
+ v8::Handle<v8::Value> GetExtensionId(const v8::Arguments& args) { |
+ return v8::String::New(extension_id_.c_str()); |
+ } |
+ |
+ v8::Handle<v8::Value> GetContextType(const v8::Arguments& args) { |
+ return v8::String::New(context_type_.c_str()); |
+ } |
+ |
+ v8::Handle<v8::Value> IsIncognitoContext(const v8::Arguments& args) { |
+ return v8::Boolean::New(is_incognito_context_); |
+ } |
+ |
+ v8::Handle<v8::Value> GetManifestVersion(const v8::Arguments& args) { |
+ return v8::Integer::New(manifest_version_); |
+ } |
+ |
+ private: |
+ std::string extension_id_; |
+ std::string context_type_; |
+ bool is_incognito_context_; |
+ int manifest_version_; |
+}; |
+ |
class ChannelNativeHandler : public NativeHandler { |
public: |
explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel) |
@@ -690,6 +740,14 @@ void ExtensionDispatcher::DidCreateScriptContext( |
module_system->RegisterNativeHandler("channel", |
scoped_ptr<NativeHandler>(new ChannelNativeHandler( |
static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); |
+ |
+ int manifest_version = extension ? extension->manifest_version() : 1; |
+ module_system->RegisterNativeHandler("process", |
+ scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
+ this, context->GetExtensionID(), |
+ context->GetContextTypeDescription(), |
+ ChromeRenderProcessObserver::is_incognito_process(), |
+ manifest_version))); |
// Create the 'chrome' variable if it doesn't already exist. |
{ |
v8::HandleScope handle_scope; |
@@ -744,9 +802,6 @@ void ExtensionDispatcher::DidCreateScriptContext( |
context->set_module_system(module_system.Pass()); |
- int manifest_version = 1; |
- if (extension) |
- manifest_version = extension->manifest_version(); |
context->DispatchOnLoadEvent( |
ChromeRenderProcessObserver::is_incognito_process(), |
manifest_version); |