diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-31 23:25:33 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-31 23:25:33 +0000 |
commit | f1a63d5f6bef794c761447e7dc7b1415b133bdb3 (patch) | |
tree | 297e66d439d262c54a22b0360aa6241082018d2e /chrome/renderer | |
parent | c1443d84cafab2dc81650715b102afe4d28cb27b (diff) | |
download | chromium_src-f1a63d5f6bef794c761447e7dc7b1415b133bdb3.zip chromium_src-f1a63d5f6bef794c761447e7dc7b1415b133bdb3.tar.gz chromium_src-f1a63d5f6bef794c761447e7dc7b1415b133bdb3.tar.bz2 |
Revert "First steps towards webRequest extension API."
Seems to have broken the sync_integration_tests.
This reverts commit d6f8d16cd6a5ebdf019c4755e7d42aee8136abf1.
TBR=aa
BUG=60101
TEST=no
Review URL: http://codereview.chromium.org/6287029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73219 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 55 | ||||
-rw-r--r-- | chrome/renderer/resources/event_bindings.js | 67 |
2 files changed, 3 insertions, 119 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index f1b66ab..49f2fea 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -6,7 +6,6 @@ #include "base/basictypes.h" #include "base/lazy_instance.h" -#include "base/string_number_conversions.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" @@ -60,8 +59,6 @@ typedef std::map<std::string, int> EventListenerCounts; struct SingletonData { // A map of extension IDs to listener counts for that extension. std::map<std::string, EventListenerCounts> listener_counts_; - // @@@MP - int unique_event_counter_; }; static base::LazyInstance<SingletonData> g_singleton_data( @@ -84,10 +81,6 @@ class ExtensionImpl : public ExtensionBase { v8::Handle<v8::String> name) { if (name->Equals(v8::String::New("AttachEvent"))) { return v8::FunctionTemplate::New(AttachEvent); - } else if (name->Equals(v8::String::New("GetUniqueComplexEventName"))) { - return v8::FunctionTemplate::New(GetUniqueComplexEventName); - } else if (name->Equals(v8::String::New("AttachComplexEvent"))) { - return v8::FunctionTemplate::New(AttachComplexEvent); } else if (name->Equals(v8::String::New("DetachEvent"))) { return v8::FunctionTemplate::New(DetachEvent); } @@ -127,54 +120,6 @@ class ExtensionImpl : public ExtensionBase { return v8::Undefined(); } - // Attach an event name to an object. - static v8::Handle<v8::Value> GetUniqueComplexEventName( - const v8::Arguments& args) { - DCHECK(args.Length() == 1); - DCHECK(args[0]->IsString()); - std::string event_name(*v8::String::AsciiValue(args[0])); - int unique_event_id = ++g_singleton_data.Get().unique_event_counter_; - std::string unique_event_name = - event_name + base::IntToString(unique_event_id); - return v8::String::New(unique_event_name.c_str()); - } - - // Attach an event name to an object. - static v8::Handle<v8::Value> AttachComplexEvent(const v8::Arguments& args) { - DCHECK(args.Length() == 4); - DCHECK(args[0]->IsString()); - DCHECK(args[1]->IsString()); - DCHECK(args[2]->IsString() || args[2]->IsUndefined()); - DCHECK(args[3]->IsString() || args[3]->IsUndefined()); - - std::string event_name(*v8::String::AsciiValue(args[0])); - std::string sub_event_name(*v8::String::AsciiValue(args[1])); - std::string filter_str = *v8::String::Utf8Value(args[2]); - std::string extra_info_str = *v8::String::Utf8Value(args[3]); - - ContextInfo* context_info = GetInfoForCurrentContext(); - EventListenerCounts& listener_counts = - GetListenerCounts(context_info->extension_id); - bool has_permission = - ExtensionProcessBindings::CurrentContextHasPermission(event_name); - - if (!has_permission) { - return ExtensionProcessBindings::ThrowPermissionDeniedException( - event_name); - } - - if (++listener_counts[event_name] == 1) { - EventBindings::GetRenderThread()->Send( - new ViewHostMsg_ExtensionAddListener(context_info->extension_id, - event_name)); - } - - if (++context_info->num_connected_events == 1) - context_info->context.ClearWeak(); - - return v8::Undefined(); - } - static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { DCHECK(args.Length() == 1); // TODO(erikkay) should enforce that event name is a string in the bindings diff --git a/chrome/renderer/resources/event_bindings.js b/chrome/renderer/resources/event_bindings.js index 9d82800..2b8cce8 100644 --- a/chrome/renderer/resources/event_bindings.js +++ b/chrome/renderer/resources/event_bindings.js @@ -6,8 +6,6 @@ var chrome = chrome || {}; (function () { native function GetChromeHidden(); native function AttachEvent(eventName); - native function AttachComplexEvent(eventName, subEventName, - filter, extraInfo); native function DetachEvent(eventName); var chromeHidden = GetChromeHidden(); @@ -55,9 +53,8 @@ var chrome = chrome || {}; // chrome.tabs.onChanged.addListener(function(data) { alert(data); }); // chromeHidden.Event.dispatch("tab-changed", "hi"); // will result in an alert dialog that says 'hi'. - chrome.Event = function(opt_eventName, opt_argSchemas, opt_isSubEvent) { + chrome.Event = function(opt_eventName, opt_argSchemas) { this.eventName_ = opt_eventName; - this.isSubEvent_ = opt_isSubEvent; this.listeners_ = []; // Validate event parameters if we are in debug. @@ -112,7 +109,7 @@ var chrome = chrome || {}; } // Registers a callback to be called when this event is dispatched. - chrome.Event.prototype.addListener = function(cb, opt_filter, opt_extraInfo) { + chrome.Event.prototype.addListener = function(cb) { if (this.listeners_.length == 0) { this.attach_(); } @@ -176,8 +173,7 @@ var chrome = chrome || {}; // Attaches this event object to its name. Only one object can have a given // name. chrome.Event.prototype.attach_ = function() { - if (!this.isSubEvent_) - AttachEvent(this.eventName_); + AttachEvent(this.eventName_); allAttachedEvents[allAttachedEvents.length] = this; if (!this.eventName_) return; @@ -207,63 +203,6 @@ var chrome = chrome || {}; delete attachedNamedEvents[this.eventName_]; }; - // ComplexEvent object. This is used for special events with extra parameters. - // Each invocation of addListener creates a new named sub-event. That - // sub-event is associated with the extra parameters in the browser process, - // so that only it is dispatched when the main event occurs matching the extra - // parameters. - // - // Example: - // chrome.webRequest.onBeforeRequest.addListener( - // callback, {urls: "http://*.google.com/*"}); - // ^ callback will only be called for onBeforeRequests matching the filter. - chrome.ComplexEvent = function(eventName, opt_argSchemas) { - if (typeof eventName != "string") - throw new Error("chrome.ComplexEvent requires an event name."); - - this.eventName_ = eventName; - this.argSchemas_ = opt_argSchemas; - this.subEvents_ = []; - }; - - // Registers a callback to be called when this event is dispatched. If - // opt_filter is specified, then the callback is only called for events that - // match the given filters. If opt_extraInfo is specified, the given optional - // info is sent to the callback. - chrome.ComplexEvent.prototype.addListener = - function(cb, opt_filter, opt_extraInfo) { - var subevent = new chrome.Event(this.eventName_ + this.subEvents_.length, - this.argSchemas_, true); - this.subEvents_[this.subEvents_.length] = subevent; - subevent.addListener(cb, opt_filter, opt_extraInfo); - AttachComplexEvent(this.eventName_, subevent.eventName_, - chromeHidden.JSON.stringify(opt_filter), - chromeHidden.JSON.stringify(opt_extraInfo)); - }; - - // Unregisters a callback. - chrome.ComplexEvent.prototype.removeListener = function(cb) { - var idx = this.findListener_(cb); - if (!idx) { - return; - } - - this.subEvents_[idx].removeListener(cb); - if (!this.subEvents_[idx].hasListeners()) - delete this.subEvents_[idx]; - }; - - chrome.ComplexEvent.prototype.findListener_ = function(cb) { - for (var i = 0; i < this.subEvents_.length; i++) { - if (this.subEvents_[i].findListener_(cb) > -1) - return i; - } - - return -1; - }; - - chrome.ch = chromeHidden; - // Special load events: we don't use the DOM unload because that slows // down tab shutdown. On the other hand, onUnload might not always fire, // since Chrome will terminate renderers on shutdown (SuddenTermination). |