Commit e60e6be8 authored by koz@chromium.org's avatar koz@chromium.org

Make miscellaneous_bindings.js not depend on onLoad().


BUG=136469
TBR=ben@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10698163

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149145 0039d316-1c4b-4281-b951-d872f2087c98
parent fdd27736
...@@ -29,18 +29,6 @@ const char kValidateCallbacks[] = "validateCallbacks"; ...@@ -29,18 +29,6 @@ const char kValidateCallbacks[] = "validateCallbacks";
const char kValidateAPI[] = "validateAPI"; const char kValidateAPI[] = "validateAPI";
#endif #endif
std::string GetContextTypeDescription(Feature::Context context_type) {
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";
}
NOTREACHED();
return "";
}
} // namespace } // namespace
ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context,
...@@ -54,7 +42,7 @@ ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, ...@@ -54,7 +42,7 @@ ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context,
VLOG(1) << "Created context:\n" VLOG(1) << "Created context:\n"
<< " extension id: " << GetExtensionID() << "\n" << " extension id: " << GetExtensionID() << "\n"
<< " frame: " << web_frame_ << "\n" << " frame: " << web_frame_ << "\n"
<< " context type: " << GetContextTypeDescription(context_type); << " context type: " << GetContextTypeDescription();
} }
ChromeV8Context::~ChromeV8Context() { ChromeV8Context::~ChromeV8Context() {
...@@ -170,7 +158,7 @@ void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, ...@@ -170,7 +158,7 @@ void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process,
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::Handle<v8::Value> argv[] = { v8::Handle<v8::Value> argv[] = {
v8::String::New(GetExtensionID().c_str()), v8::String::New(GetExtensionID().c_str()),
v8::String::New(GetContextTypeDescription(context_type_).c_str()), v8::String::New(GetContextTypeDescription().c_str()),
v8::Boolean::New(is_incognito_process), v8::Boolean::New(is_incognito_process),
v8::Integer::New(manifest_version), v8::Integer::New(manifest_version),
}; };
...@@ -181,3 +169,15 @@ void ChromeV8Context::DispatchOnUnloadEvent() { ...@@ -181,3 +169,15 @@ void ChromeV8Context::DispatchOnUnloadEvent() {
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL);
} }
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";
}
NOTREACHED();
return "";
}
...@@ -99,6 +99,9 @@ class ChromeV8Context { ...@@ -99,6 +99,9 @@ class ChromeV8Context {
// APIs are available, returns an empty set. // APIs are available, returns an empty set.
const std::set<std::string>& GetAvailableExtensionAPIs(); const std::set<std::string>& GetAvailableExtensionAPIs();
// Returns a string description of the type of context this is.
std::string GetContextTypeDescription();
private: private:
// The v8 context the bindings are accessible to. We keep a strong reference // The v8 context the bindings are accessible to. We keep a strong reference
// to it for simplicity. In the case of content scripts, this is necessary // to it for simplicity. In the case of content scripts, this is necessary
......
...@@ -196,6 +196,56 @@ class LazyBackgroundPageNativeHandler : public ChromeV8Extension { ...@@ -196,6 +196,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("InIncognitoContext",
base::Bind(&ProcessInfoNativeHandler::InIncognitoContext,
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> InIncognitoContext(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 { class ChannelNativeHandler : public NativeHandler {
public: public:
explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel) explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel)
...@@ -738,6 +788,16 @@ void ExtensionDispatcher::DidCreateScriptContext( ...@@ -738,6 +788,16 @@ void ExtensionDispatcher::DidCreateScriptContext(
static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); static_cast<chrome::VersionInfo::Channel>(chrome_channel_))));
module_system->RegisterNativeHandler("logging", module_system->RegisterNativeHandler("logging",
scoped_ptr<NativeHandler>(new LoggingNativeHandler())); scoped_ptr<NativeHandler>(new LoggingNativeHandler()));
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)));
GetOrCreateChrome(v8_context); GetOrCreateChrome(v8_context);
// Loading JavaScript is expensive, so only run the full API bindings // Loading JavaScript is expensive, so only run the full API bindings
...@@ -784,9 +844,6 @@ void ExtensionDispatcher::DidCreateScriptContext( ...@@ -784,9 +844,6 @@ void ExtensionDispatcher::DidCreateScriptContext(
context->set_module_system(module_system.Pass()); context->set_module_system(module_system.Pass());
int manifest_version = 1;
if (extension)
manifest_version = extension->manifest_version();
context->DispatchOnLoadEvent( context->DispatchOnLoadEvent(
ChromeRenderProcessObserver::is_incognito_process(), ChromeRenderProcessObserver::is_incognito_process(),
manifest_version); manifest_version);
......
...@@ -10,6 +10,18 @@ var OpenChannelToExtension = extensionNatives.OpenChannelToExtension; ...@@ -10,6 +10,18 @@ var OpenChannelToExtension = extensionNatives.OpenChannelToExtension;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var inIncognitoContext = requireNative('process').InIncognitoContext();
chrome.extension = chrome.extension || {};
var manifestVersion = requireNative('process').GetManifestVersion();
if (manifestVersion < 2) {
chrome.self = chrome.extension;
chrome.extension.inIncognitoTab = inIncognitoContext;
}
chrome.extension.inIncognitoContext = inIncognitoContext;
// This should match chrome.windows.WINDOW_ID_NONE. // This should match chrome.windows.WINDOW_ID_NONE.
// //
// We can't use chrome.windows.WINDOW_ID_NONE directly because the // We can't use chrome.windows.WINDOW_ID_NONE directly because the
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
var BindToGC = miscNatives.BindToGC; var BindToGC = miscNatives.BindToGC;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var manifestVersion;
var extensionId; var processNatives = requireNative('process');
var manifestVersion = processNatives.GetManifestVersion();
var extensionId = processNatives.GetExtensionId();
// The reserved channel name for the sendRequest/sendMessage APIs. // The reserved channel name for the sendRequest/sendMessage APIs.
// Note: sendRequest is deprecated. // Note: sendRequest is deprecated.
...@@ -288,22 +290,3 @@ ...@@ -288,22 +290,3 @@
} }
}); });
} }
// This function is called on context initialization for both content scripts
// and extension contexts.
chromeHidden.onLoad.addListener(function(tempExtensionId,
isExtensionProcess,
inIncognitoContext,
tempManifestVersion) {
extensionId = tempExtensionId;
manifestVersion = tempManifestVersion;
chrome.extension = chrome.extension || {};
if (manifestVersion < 2) {
chrome.self = chrome.extension;
chrome.extension.inIncognitoTab = inIncognitoContext;
}
chrome.extension.inIncognitoContext = inIncognitoContext;
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment