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

Side by Side Diff: chrome/renderer/resources/event_bindings.js

Issue 262016: Implement chrome.extension.connectExternal and fix various API inconsistencies. (Closed)
Patch Set: addressed comments Created 11 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect.
8 // -----------------------------------------------------------------------------
9
10 var chrome = chrome || {}; 5 var chrome = chrome || {};
11 (function () { 6 (function () {
12 native function GetChromeHidden(); 7 native function GetChromeHidden();
13 native function AttachEvent(eventName); 8 native function AttachEvent(eventName);
14 native function DetachEvent(eventName); 9 native function DetachEvent(eventName);
15 10
16 var chromeHidden = GetChromeHidden(); 11 var chromeHidden = GetChromeHidden();
17 12
18 // Event object. If opt_eventName is provided, this object represents 13 // Event object. If opt_eventName is provided, this object represents
19 // the unique instance of that named event, and dispatching an event 14 // the unique instance of that named event, and dispatching an event
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (this.listeners_.length == 0) { 93 if (this.listeners_.length == 0) {
99 this.detach_(); 94 this.detach_();
100 } 95 }
101 }; 96 };
102 97
103 // Test if the given callback is registered for this event. 98 // Test if the given callback is registered for this event.
104 chrome.Event.prototype.hasListener = function(cb) { 99 chrome.Event.prototype.hasListener = function(cb) {
105 return this.findListeners_(cb) > -1; 100 return this.findListeners_(cb) > -1;
106 }; 101 };
107 102
103 // Test if any callbacks are registered for this event.
104 chrome.Event.prototype.hasListeners = function(cb) {
105 return this.listeners_.length > 0;
106 };
107
108 // Returns the index of the given callback if registered, or -1 if not 108 // Returns the index of the given callback if registered, or -1 if not
109 // found. 109 // found.
110 chrome.Event.prototype.findListener_ = function(cb) { 110 chrome.Event.prototype.findListener_ = function(cb) {
111 for (var i = 0; i < this.listeners_.length; i++) { 111 for (var i = 0; i < this.listeners_.length; i++) {
112 if (this.listeners_[i] == cb) { 112 if (this.listeners_[i] == cb) {
113 return i; 113 return i;
114 } 114 }
115 } 115 }
116 116
117 return -1; 117 return -1;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 chromeHidden.dispatchOnUnload = function() { 182 chromeHidden.dispatchOnUnload = function() {
183 chromeHidden.onUnload.dispatch(); 183 chromeHidden.onUnload.dispatch();
184 for (var i in allAttachedEvents) 184 for (var i in allAttachedEvents)
185 allAttachedEvents[i].detach_(); 185 allAttachedEvents[i].detach_();
186 } 186 }
187 187
188 chromeHidden.dispatchError = function(msg) { 188 chromeHidden.dispatchError = function(msg) {
189 console.error(msg); 189 console.error(msg);
190 } 190 }
191 })(); 191 })();
OLDNEW
« no previous file with comments | « chrome/renderer/mock_render_thread.cc ('k') | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698