Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 10698163: Make miscellaneous_bindings.js not depend on onLoad(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698