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

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

Issue 15841013: Make miscellaneous_bindings and event_bindings Required as needed. Previously (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_context.h ('k') | chrome/renderer/extensions/chrome_v8_context_set.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/chrome_v8_context.cc
diff --git a/chrome/renderer/extensions/chrome_v8_context.cc b/chrome/renderer/extensions/chrome_v8_context.cc
index 47171c8cecb9e4bb88f996f4023928a5d876c67f..42b241abb9c338600e1402f4af4d90d05baa0476 100644
--- a/chrome/renderer/extensions/chrome_v8_context.cc
+++ b/chrome/renderer/extensions/chrome_v8_context.cc
@@ -4,7 +4,6 @@
#include "chrome/renderer/extensions/chrome_v8_context.h"
-#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_split.h"
@@ -19,6 +18,7 @@
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSuppression.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "v8/include/v8.h"
@@ -27,11 +27,7 @@ using content::V8ValueConverter;
namespace extensions {
namespace {
-
const char kChromeHidden[] = "chromeHidden";
-const char kValidateCallbacks[] = "validateCallbacks";
-const char kValidateAPI[] = "validateAPI";
-
} // namespace
ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context,
@@ -55,7 +51,7 @@ ChromeV8Context::~ChromeV8Context() {
}
void ChromeV8Context::Invalidate() {
- if (v8_context_.get().IsEmpty())
+ if (!is_valid())
return;
if (module_system_)
module_system_->Invalidate();
@@ -77,16 +73,6 @@ v8::Handle<v8::Value> ChromeV8Context::GetOrCreateChromeHidden(
if (hidden.IsEmpty() || hidden->IsUndefined()) {
hidden = v8::Object::New();
global->SetHiddenValue(v8::String::New(kChromeHidden), hidden);
-
- if (DCHECK_IS_ON()) {
- // Tell bindings.js to validate callbacks and events against their schema
- // definitions.
- v8::Local<v8::Object>::Cast(hidden)->Set(
- v8::String::New(kValidateCallbacks), v8::True());
- // Tell bindings.js to validate API for ambiguity.
- v8::Local<v8::Object>::Cast(hidden)->Set(
- v8::String::New(kValidateAPI), v8::True());
- }
}
DCHECK(hidden->IsObject());
@@ -105,52 +91,23 @@ content::RenderView* ChromeV8Context::GetRenderView() const {
return NULL;
}
-bool ChromeV8Context::CallChromeHiddenMethod(
- const std::string& function_name,
+v8::Local<v8::Value> ChromeV8Context::CallFunction(
+ v8::Handle<v8::Function> function,
int argc,
- v8::Handle<v8::Value>* argv,
- v8::Handle<v8::Value>* result) const {
- // ChromeV8ContextSet calls Invalidate() and then schedules a task to delete
- // this object. This check prevents a race from attempting to execute script
- // on a NULL web_frame_.
- if (!web_frame_)
- return false;
-
- v8::Context::Scope context_scope(v8_context_.get());
-
- // Look up the function name, which may be a sub-property like
- // "Port.dispatchOnMessage" in the hidden global variable.
- v8::Local<v8::Value> value = v8::Local<v8::Value>::New(GetChromeHidden());
- if (value.IsEmpty())
- return false;
-
- std::vector<std::string> components;
- base::SplitStringDontTrim(function_name, '.', &components);
- for (size_t i = 0; i < components.size(); ++i) {
- if (!value.IsEmpty() && value->IsObject()) {
- value = v8::Local<v8::Object>::Cast(value)->Get(
- v8::String::New(components[i].c_str()));
- }
- }
-
- if (value.IsEmpty() || !value->IsFunction()) {
- VLOG(1) << "Could not execute chrome hidden method: " << function_name;
- return false;
- }
-
- TRACE_EVENT1("v8", "v8.callChromeHiddenMethod",
- "function_name", function_name);
+ v8::Handle<v8::Value> argv[]) const {
+ v8::HandleScope handle_scope;
+ WebKit::WebScopedMicrotaskSuppression suppression;
+ if (!is_valid())
+ return handle_scope.Close(v8::Undefined());
- v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
- v8::Handle<v8::Value> result_temp =
+ v8::Handle<v8::Object> global = v8_context()->Global();
+ if (!web_frame_)
+ return handle_scope.Close(function->Call(global, argc, argv));
+ return handle_scope.Close(
web_frame_->callFunctionEvenIfScriptDisabled(function,
- v8::Object::New(),
+ global,
argc,
- argv);
- if (result)
- *result = result_temp;
-
- return true;
+ argv));
}
bool ChromeV8Context::IsAnyFeatureAvailableToContext(
@@ -171,8 +128,7 @@ Feature::Availability ChromeV8Context::GetAvailability(
}
void ChromeV8Context::DispatchOnUnloadEvent() {
- v8::HandleScope handle_scope;
- CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL);
+ module_system_->CallModuleMethod("on_unload", "dispatch");
}
std::string ChromeV8Context::GetContextTypeDescription() {
@@ -207,9 +163,9 @@ void ChromeV8Context::OnResponseReceived(const std::string& name,
v8::String::New(error.c_str())
};
- v8::Handle<v8::Value> retval;
- CHECK(CallChromeHiddenMethod("handleResponse", arraysize(argv), argv,
- &retval));
+ 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.
if (DCHECK_IS_ON()) {
@@ -220,4 +176,8 @@ void ChromeV8Context::OnResponseReceived(const std::string& name,
}
}
+bool ChromeV8Context::is_valid() const {
+ return !v8_context_.get().IsEmpty();
+}
+
} // namespace extensions
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_context.h ('k') | chrome/renderer/extensions/chrome_v8_context_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698