Commit 628fa785 authored by koz@chromium.org's avatar koz@chromium.org

Revert "Make EventBindings use static routed methods." (r145634)

The crashes that it was hoped this patch would prevent didn't stop, and the actual bug was fixed in r145842.

BUG=136232
TBR=kalman@chomium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146012 0039d316-1c4b-4281-b951-d872f2087c98
parent 21e096c7
...@@ -64,40 +64,46 @@ typedef std::map<std::string, linked_ptr<extensions::ValueCounter> > ...@@ -64,40 +64,46 @@ typedef std::map<std::string, linked_ptr<extensions::ValueCounter> >
base::LazyInstance<std::map<std::string, FilteredEventListenerCounts> > base::LazyInstance<std::map<std::string, FilteredEventListenerCounts> >
g_filtered_listener_counts = LAZY_INSTANCE_INITIALIZER; g_filtered_listener_counts = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<extensions::EventFilter> g_event_filter =
LAZY_INSTANCE_INITIALIZER;
// TODO(koz): Merge this into EventBindings. // TODO(koz): Merge this into EventBindings.
class ExtensionImpl : public ChromeV8Extension { class ExtensionImpl : public ChromeV8Extension {
public: public:
explicit ExtensionImpl(ExtensionDispatcher* dispatcher) ExtensionImpl(ExtensionDispatcher* dispatcher,
: ChromeV8Extension(dispatcher) { extensions::EventFilter* event_filter)
RouteStaticFunction("AttachEvent", &AttachEvent); : ChromeV8Extension(dispatcher),
RouteStaticFunction("DetachEvent", &DetachEvent); event_filter_(event_filter) {
RouteStaticFunction("AttachFilteredEvent", &AttachFilteredEvent); RouteFunction("AttachEvent",
RouteStaticFunction("DetachFilteredEvent", &DetachFilteredEvent); base::Bind(&ExtensionImpl::AttachEvent,
RouteStaticFunction("MatchAgainstEventFilter", &MatchAgainstEventFilter); base::Unretained(this)));
RouteFunction("DetachEvent",
base::Bind(&ExtensionImpl::DetachEvent,
base::Unretained(this)));
RouteFunction("AttachFilteredEvent",
base::Bind(&ExtensionImpl::AttachFilteredEvent,
base::Unretained(this)));
RouteFunction("DetachFilteredEvent",
base::Bind(&ExtensionImpl::DetachFilteredEvent,
base::Unretained(this)));
RouteFunction("MatchAgainstEventFilter",
base::Bind(&ExtensionImpl::MatchAgainstEventFilter,
base::Unretained(this)));
} }
~ExtensionImpl() {} ~ExtensionImpl() {}
// Attach an event name to an object. // Attach an event name to an object.
static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) {
DCHECK(args.Length() == 1); DCHECK(args.Length() == 1);
// TODO(erikkay) should enforce that event name is a string in the bindings // TODO(erikkay) should enforce that event name is a string in the bindings
DCHECK(args[0]->IsString() || args[0]->IsUndefined()); DCHECK(args[0]->IsString() || args[0]->IsUndefined());
if (args[0]->IsString()) { if (args[0]->IsString()) {
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
std::string event_name = *v8::String::AsciiValue(args[0]->ToString()); std::string event_name = *v8::String::AsciiValue(args[0]->ToString());
ExtensionDispatcher* extension_dispatcher = self->extension_dispatcher();
const ChromeV8ContextSet& context_set = const ChromeV8ContextSet& context_set =
extension_dispatcher->v8_context_set(); extension_dispatcher()->v8_context_set();
ChromeV8Context* context = context_set.GetCurrent(); ChromeV8Context* context = context_set.GetCurrent();
CHECK(context); CHECK(context);
if (!extension_dispatcher->CheckCurrentContextAccessToExtensionAPI( if (!extension_dispatcher()->CheckCurrentContextAccessToExtensionAPI(
event_name)) event_name))
return v8::Undefined(); return v8::Undefined();
...@@ -120,7 +126,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -120,7 +126,7 @@ class ExtensionImpl : public ChromeV8Extension {
return v8::Undefined(); return v8::Undefined();
} }
static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) {
DCHECK(args.Length() == 2); DCHECK(args.Length() == 2);
// TODO(erikkay) should enforce that event name is a string in the bindings // TODO(erikkay) should enforce that event name is a string in the bindings
DCHECK(args[0]->IsString() || args[0]->IsUndefined()); DCHECK(args[0]->IsString() || args[0]->IsUndefined());
...@@ -129,10 +135,8 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -129,10 +135,8 @@ class ExtensionImpl : public ChromeV8Extension {
std::string event_name = *v8::String::AsciiValue(args[0]->ToString()); std::string event_name = *v8::String::AsciiValue(args[0]->ToString());
bool is_manual = args[1]->BooleanValue(); bool is_manual = args[1]->BooleanValue();
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
ExtensionDispatcher* extension_dispatcher = self->extension_dispatcher();
const ChromeV8ContextSet& context_set = const ChromeV8ContextSet& context_set =
extension_dispatcher->v8_context_set(); extension_dispatcher()->v8_context_set();
ChromeV8Context* context = context_set.GetCurrent(); ChromeV8Context* context = context_set.GetCurrent();
if (!context) if (!context)
return v8::Undefined(); return v8::Undefined();
...@@ -163,15 +167,13 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -163,15 +167,13 @@ class ExtensionImpl : public ChromeV8Extension {
// filter - Which instances of the named event are we interested in. // filter - Which instances of the named event are we interested in.
// returns the id assigned to the listener, which will be returned from calls // returns the id assigned to the listener, which will be returned from calls
// to MatchAgainstEventFilter where this listener matches. // to MatchAgainstEventFilter where this listener matches.
static v8::Handle<v8::Value> AttachFilteredEvent(const v8::Arguments& args) { v8::Handle<v8::Value> AttachFilteredEvent(const v8::Arguments& args) {
DCHECK_EQ(2, args.Length()); DCHECK_EQ(2, args.Length());
DCHECK(args[0]->IsString()); DCHECK(args[0]->IsString());
DCHECK(args[1]->IsObject()); DCHECK(args[1]->IsObject());
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
ExtensionDispatcher* extension_dispatcher = self->extension_dispatcher();
const ChromeV8ContextSet& context_set = const ChromeV8ContextSet& context_set =
extension_dispatcher->v8_context_set(); extension_dispatcher()->v8_context_set();
ChromeV8Context* context = context_set.GetCurrent(); ChromeV8Context* context = context_set.GetCurrent();
DCHECK(context); DCHECK(context);
if (!context) if (!context)
...@@ -179,7 +181,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -179,7 +181,7 @@ class ExtensionImpl : public ChromeV8Extension {
std::string event_name = *v8::String::AsciiValue(args[0]); std::string event_name = *v8::String::AsciiValue(args[0]);
// This method throws an exception if it returns false. // This method throws an exception if it returns false.
if (!extension_dispatcher->CheckCurrentContextAccessToExtensionAPI( if (!extension_dispatcher()->CheckCurrentContextAccessToExtensionAPI(
event_name)) event_name))
return v8::Undefined(); return v8::Undefined();
...@@ -200,8 +202,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -200,8 +202,7 @@ class ExtensionImpl : public ChromeV8Extension {
} }
filter.reset(filter_dict); filter.reset(filter_dict);
extensions::EventFilter& event_filter = g_event_filter.Get(); int id = event_filter_->AddEventMatcher(event_name, ParseEventMatcher(
int id = event_filter.AddEventMatcher(event_name, ParseEventMatcher(
filter.get())); filter.get()));
// Only send IPCs the first time a filter gets added. // Only send IPCs the first time a filter gets added.
...@@ -217,7 +218,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -217,7 +218,7 @@ class ExtensionImpl : public ChromeV8Extension {
// Add a filter to |event_name| in |extension_id|, returning true if it // Add a filter to |event_name| in |extension_id|, returning true if it
// was the first filter for that event in that extension. // was the first filter for that event in that extension.
static bool AddFilter(const std::string& event_name, bool AddFilter(const std::string& event_name,
const std::string& extension_id, const std::string& extension_id,
base::DictionaryValue* filter) { base::DictionaryValue* filter) {
FilteredEventListenerCounts& counts = FilteredEventListenerCounts& counts =
...@@ -232,7 +233,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -232,7 +233,7 @@ class ExtensionImpl : public ChromeV8Extension {
// Remove a filter from |event_name| in |extension_id|, returning true if it // Remove a filter from |event_name| in |extension_id|, returning true if it
// was the last filter for that event in that extension. // was the last filter for that event in that extension.
static bool RemoveFilter(const std::string& event_name, bool RemoveFilter(const std::string& event_name,
const std::string& extension_id, const std::string& extension_id,
base::DictionaryValue* filter) { base::DictionaryValue* filter) {
FilteredEventListenerCounts& counts = FilteredEventListenerCounts& counts =
...@@ -247,15 +248,13 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -247,15 +248,13 @@ class ExtensionImpl : public ChromeV8Extension {
// id - Id of the event to detach. // id - Id of the event to detach.
// manual - false if this is part of the extension unload process where all // manual - false if this is part of the extension unload process where all
// listeners are automatically detached. // listeners are automatically detached.
static v8::Handle<v8::Value> DetachFilteredEvent(const v8::Arguments& args) { v8::Handle<v8::Value> DetachFilteredEvent(const v8::Arguments& args) {
DCHECK_EQ(2, args.Length()); DCHECK_EQ(2, args.Length());
DCHECK(args[0]->IsInt32()); DCHECK(args[0]->IsInt32());
DCHECK(args[1]->IsBoolean()); DCHECK(args[1]->IsBoolean());
bool is_manual = args[1]->BooleanValue(); bool is_manual = args[1]->BooleanValue();
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
ExtensionDispatcher* extension_dispatcher = self->extension_dispatcher();
const ChromeV8ContextSet& context_set = const ChromeV8ContextSet& context_set =
extension_dispatcher->v8_context_set(); extension_dispatcher()->v8_context_set();
ChromeV8Context* context = context_set.GetCurrent(); ChromeV8Context* context = context_set.GetCurrent();
if (!context) if (!context)
return v8::Undefined(); return v8::Undefined();
...@@ -265,11 +264,10 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -265,11 +264,10 @@ class ExtensionImpl : public ChromeV8Extension {
return v8::Undefined(); return v8::Undefined();
int matcher_id = args[0]->Int32Value(); int matcher_id = args[0]->Int32Value();
extensions::EventFilter& event_filter = g_event_filter.Get();
extensions::EventMatcher* event_matcher = extensions::EventMatcher* event_matcher =
event_filter.GetEventMatcher(matcher_id); event_filter_->GetEventMatcher(matcher_id);
const std::string& event_name = event_filter.GetEventName(matcher_id); const std::string& event_name = event_filter_->GetEventName(matcher_id);
// Only send IPCs the last time a filter gets removed. // Only send IPCs the last time a filter gets removed.
if (RemoveFilter(event_name, extension_id, event_matcher->value())) { if (RemoveFilter(event_name, extension_id, event_matcher->value())) {
...@@ -280,19 +278,17 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -280,19 +278,17 @@ class ExtensionImpl : public ChromeV8Extension {
lazy)); lazy));
} }
event_filter.RemoveEventMatcher(matcher_id); event_filter_->RemoveEventMatcher(matcher_id);
return v8::Undefined(); return v8::Undefined();
} }
static v8::Handle<v8::Value> MatchAgainstEventFilter( v8::Handle<v8::Value> MatchAgainstEventFilter(const v8::Arguments& args) {
const v8::Arguments& args) {
typedef std::set<extensions::EventFilter::MatcherID> MatcherIDs; typedef std::set<extensions::EventFilter::MatcherID> MatcherIDs;
extensions::EventFilter& event_filter = g_event_filter.Get();
std::string event_name = *v8::String::AsciiValue(args[0]->ToString()); std::string event_name = *v8::String::AsciiValue(args[0]->ToString());
extensions::EventFilteringInfo info = ParseFromObject(args[1]->ToObject()); extensions::EventFilteringInfo info = ParseFromObject(args[1]->ToObject());
MatcherIDs matched_event_filters = event_filter.MatchEvent( MatcherIDs matched_event_filters = event_filter_->MatchEvent(
event_name, info); event_name, info);
v8::Handle<v8::Array> array(v8::Array::New(matched_event_filters.size())); v8::Handle<v8::Array> array(v8::Array::New(matched_event_filters.size()));
int i = 0; int i = 0;
...@@ -303,7 +299,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -303,7 +299,7 @@ class ExtensionImpl : public ChromeV8Extension {
return array; return array;
} }
static extensions::EventFilteringInfo ParseFromObject( extensions::EventFilteringInfo ParseFromObject(
v8::Handle<v8::Object> object) { v8::Handle<v8::Object> object) {
extensions::EventFilteringInfo info; extensions::EventFilteringInfo info;
v8::Handle<v8::String> url(v8::String::New("url")); v8::Handle<v8::String> url(v8::String::New("url"));
...@@ -315,7 +311,8 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -315,7 +311,8 @@ class ExtensionImpl : public ChromeV8Extension {
} }
private: private:
static bool IsLazyBackgroundPage(const Extension* extension) { extensions::EventFilter* event_filter_;
bool IsLazyBackgroundPage(const Extension* extension) {
content::RenderView* render_view = GetCurrentRenderView(); content::RenderView* render_view = GetCurrentRenderView();
if (!render_view) if (!render_view)
return false; return false;
...@@ -325,7 +322,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -325,7 +322,7 @@ class ExtensionImpl : public ChromeV8Extension {
helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
} }
static scoped_ptr<extensions::EventMatcher> ParseEventMatcher( scoped_ptr<extensions::EventMatcher> ParseEventMatcher(
base::DictionaryValue* filter_dict) { base::DictionaryValue* filter_dict) {
return scoped_ptr<extensions::EventMatcher>(new extensions::EventMatcher( return scoped_ptr<extensions::EventMatcher>(new extensions::EventMatcher(
scoped_ptr<base::DictionaryValue>(filter_dict->DeepCopy()))); scoped_ptr<base::DictionaryValue>(filter_dict->DeepCopy())));
...@@ -335,6 +332,7 @@ class ExtensionImpl : public ChromeV8Extension { ...@@ -335,6 +332,7 @@ class ExtensionImpl : public ChromeV8Extension {
} // namespace } // namespace
// static // static
ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher,
return new ExtensionImpl(dispatcher); extensions::EventFilter* event_filter) {
return new ExtensionImpl(dispatcher, event_filter);
} }
...@@ -20,7 +20,8 @@ class Extension; ...@@ -20,7 +20,8 @@ class Extension;
// This class deals with the javascript bindings related to Event objects. // This class deals with the javascript bindings related to Event objects.
class EventBindings { class EventBindings {
public: public:
static ChromeV8Extension* Get(ExtensionDispatcher* dispatcher); static ChromeV8Extension* Get(ExtensionDispatcher* dispatcher,
extensions::EventFilter* event_filter);
}; };
#endif // CHROME_RENDERER_EXTENSIONS_EVENT_BINDINGS_H_ #endif // CHROME_RENDERER_EXTENSIONS_EVENT_BINDINGS_H_
...@@ -237,7 +237,8 @@ ExtensionDispatcher::ExtensionDispatcher() ...@@ -237,7 +237,8 @@ ExtensionDispatcher::ExtensionDispatcher()
webrequest_adblock_plus_(false), webrequest_adblock_plus_(false),
webrequest_other_(false), webrequest_other_(false),
source_map_(&ResourceBundle::GetSharedInstance()), source_map_(&ResourceBundle::GetSharedInstance()),
chrome_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { chrome_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN),
event_filter_(new extensions::EventFilter) {
const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
is_extension_process_ = is_extension_process_ =
command_line.HasSwitch(switches::kExtensionProcess) || command_line.HasSwitch(switches::kExtensionProcess) ||
...@@ -494,7 +495,7 @@ bool ExtensionDispatcher::AllowScriptExtension( ...@@ -494,7 +495,7 @@ bool ExtensionDispatcher::AllowScriptExtension(
void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
ChromeV8Context* context) { ChromeV8Context* context) {
module_system->RegisterNativeHandler("event_bindings", module_system->RegisterNativeHandler("event_bindings",
scoped_ptr<NativeHandler>(EventBindings::Get(this))); scoped_ptr<NativeHandler>(EventBindings::Get(this, event_filter_.get())));
module_system->RegisterNativeHandler("miscellaneous_bindings", module_system->RegisterNativeHandler("miscellaneous_bindings",
scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this)));
module_system->RegisterNativeHandler("apiDefinitions", module_system->RegisterNativeHandler("apiDefinitions",
......
...@@ -263,6 +263,10 @@ class ExtensionDispatcher : public content::RenderProcessObserver { ...@@ -263,6 +263,10 @@ class ExtensionDispatcher : public content::RenderProcessObserver {
// TODO(aa): Remove when we can restrict non-permission APIs to dev-only. // TODO(aa): Remove when we can restrict non-permission APIs to dev-only.
int chrome_channel_; int chrome_channel_;
// Routes events to the appropriate listener taking into consideration event
// filters.
scoped_ptr<extensions::EventFilter> event_filter_;
DISALLOW_COPY_AND_ASSIGN(ExtensionDispatcher); DISALLOW_COPY_AND_ASSIGN(ExtensionDispatcher);
}; };
......
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