|
| 1 | +window.cls || (window.cls = {}); |
| 2 | + |
| 3 | +/** |
| 4 | + * @constructor |
| 5 | + * @extends ViewBase |
| 6 | + */ |
| 7 | + |
| 8 | +cls.EventName = function(name) |
| 9 | +{ |
| 10 | + this.name = name; |
| 11 | + this.model = null; |
| 12 | + this.rt_listeners = null, |
| 13 | + this.expanded = null; |
| 14 | + this.rt_id = 0; |
| 15 | + this.obj_id = 0; |
| 16 | +}; |
| 17 | + |
| 18 | +cls.EvenetListeners = function(view) |
| 19 | +{ |
| 20 | + /* interface */ |
| 21 | + |
| 22 | + this.update = function() {}; |
| 23 | + this.get_data = function() {}; |
| 24 | + this.expand_listeners = function(rt_id, obj_id, ev_name, cb) {}; |
| 25 | + |
| 26 | + var SUCCESS = 0; |
| 27 | + var SEARCH_TYPE_EVENT = 5; |
| 28 | + |
| 29 | + /* |
| 30 | + data structure |
| 31 | + |
| 32 | + this._rts = |
| 33 | + [ |
| 34 | + { |
| 35 | + rt_id: <rt-id>, |
| 36 | + obj_id: <obj-id>, |
| 37 | + event_names: |
| 38 | + [ |
| 39 | + { |
| 40 | + name: <name>, |
| 41 | + expanded: <boolean>, |
| 42 | + }, |
| 43 | + ... |
| 44 | + ] |
| 45 | + }, |
| 46 | + ... |
| 47 | + ] |
| 48 | +
|
| 49 | + */ |
| 50 | + |
| 51 | + this._update_rt_list = function(rt_id_list) |
| 52 | + { |
| 53 | + var ctx = {rt_id_list: rt_id_list, rt_map: {}, win_id_map: {}}; |
| 54 | + rt_id_list.forEach(this._get_window_ids.bind(this, ctx)); |
| 55 | + }; |
| 56 | + |
| 57 | + this._get_window_ids = function(ctx, rt_id) |
| 58 | + { |
| 59 | + var sel_rt_id = window.runtimes.getSelectedRuntimeId(); |
| 60 | + var thread_id = window.stop_at.getThreadId(); |
| 61 | + var frame_index = window.stop_at.getSelectedFrameIndex(); |
| 62 | + if (sel_rt_id != rt_id || frame_index == -1) |
| 63 | + { |
| 64 | + thread_id = 0; |
| 65 | + frame_index = 0; |
| 66 | + } |
| 67 | + var tag = this._tagman.set_callback(this, this._handle_window_ids, [ctx, rt_id]); |
| 68 | + var msg = [rt_id, thread_id, frame_index, "window"]; |
| 69 | + this._esdb.requestEval(tag, msg); |
| 70 | + }; |
| 71 | + |
| 72 | + this._handle_window_ids = function(status, message, ctx, rt_id) |
| 73 | + { |
| 74 | + var STATUS = 0; |
| 75 | + var OBJECT_VALUE = 3; |
| 76 | + var OBJECT_ID = 0; |
| 77 | + if (status === SUCCESS && message[STATUS] == "completed" && message[OBJECT_VALUE]) |
| 78 | + { |
| 79 | + this._win_id_map[rt_id] = ctx.win_id_map[rt_id] = message[OBJECT_VALUE][OBJECT_ID]; |
| 80 | + if (ctx.rt_id_list.every(function(rt_id) { return ctx.win_id_map[rt_id]; })) |
| 81 | + ctx.rt_id_list.map(this._get_event_names.bind(this, ctx)); |
| 82 | + } |
| 83 | + else |
| 84 | + opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE + |
| 85 | + "failed to get the window object in cls.EvenetListeners.") |
| 86 | + }; |
| 87 | + |
| 88 | + this._get_event_names = function(ctx, rt_id) |
| 89 | + { |
| 90 | + var tag = this._tagman.set_callback(this, this._handle_get_event_names, [ctx, rt_id]); |
| 91 | + var msg = [rt_id]; |
| 92 | + this._esdb.requestGetEventNames(tag, msg); |
| 93 | + }; |
| 94 | + |
| 95 | + this._handle_get_event_names = function(status, message, ctx, rt_id) |
| 96 | + { |
| 97 | + if (status === SUCCESS) |
| 98 | + { |
| 99 | + var RUNTIME_ID = 0; |
| 100 | + var OBJECT_ID = 1; |
| 101 | + var EVENT_NAMES = 2; |
| 102 | + ctx.rt_map[message[RUNTIME_ID]] = null; |
| 103 | + if (message[EVENT_NAMES] && message[EVENT_NAMES].length) |
| 104 | + { |
| 105 | + ctx.rt_map[message[RUNTIME_ID]] = |
| 106 | + { |
| 107 | + rt_id: message[RUNTIME_ID], |
| 108 | + obj_id: message[OBJECT_ID], |
| 109 | + window_id: ctx.win_id_map[rt_id], |
| 110 | + event_names: message[EVENT_NAMES].map(function(name) |
| 111 | + { |
| 112 | + return new cls.EventName(name); |
| 113 | + }), |
| 114 | + }; |
| 115 | + } |
| 116 | + |
| 117 | + if (ctx.rt_id_list.every(function(rt_id) {return ctx.rt_map.hasOwnProperty(rt_id); })) |
| 118 | + { |
| 119 | + for (var i = 0, id; id = ctx.rt_id_list[i]; i++) |
| 120 | + { |
| 121 | + this._rts[this._get_rt_index(id)] = ctx.rt_map[id]; |
| 122 | + } |
| 123 | + this._view.update(); |
| 124 | + } |
| 125 | + } |
| 126 | + else |
| 127 | + opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE + |
| 128 | + "failed to retrieve the event names in cls.EvenetListeners.") |
| 129 | + }; |
| 130 | + |
| 131 | + this._handle_dom_search = function(ev_name_obj, cb) |
| 132 | + { |
| 133 | + var tag = this._tagman.set_callback(this, this._handle_obj_search, [ev_name_obj, cb]); |
| 134 | + var msg = [ev_name_obj.rt_id, [this._win_id_map[ev_name_obj.rt_id]]]; |
| 135 | + this._esdb.requestGetEventListeners(tag, msg); |
| 136 | + }; |
| 137 | + |
| 138 | + this._handle_obj_search = function(status, message, ev_name_obj, cb) |
| 139 | + { |
| 140 | + if (status === SUCCESS) |
| 141 | + { |
| 142 | + var TARGET_LIST = 1; |
| 143 | + var OBJECT_ID = 0; |
| 144 | + var EVENT_LISTENERS = 1; |
| 145 | + var ev_target = message[TARGET_LIST] && message[TARGET_LIST][0]; |
| 146 | + ev_name_obj.model.window_listeners = ev_target |
| 147 | + ? {win_id: ev_target[OBJECT_ID], |
| 148 | + listeners: ev_target[EVENT_LISTENERS]} |
| 149 | + : null; |
| 150 | + ev_name_obj.expanded = true; |
| 151 | + if (cb) |
| 152 | + cb(ev_name_obj); |
| 153 | + else |
| 154 | + this._view.update(); |
| 155 | + } |
| 156 | + else |
| 157 | + opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE + |
| 158 | + "requestGetEventListeners failed in cls.EvenetListeners.") |
| 159 | + }; |
| 160 | + |
| 161 | + this._get_ev_name_obj = function(rt_id, ev_name) |
| 162 | + { |
| 163 | + var rt = this._get_rt(rt_id); |
| 164 | + if (rt) |
| 165 | + { |
| 166 | + for (var i = 0, ev_n; ev_n = rt.event_names[i]; i++) |
| 167 | + { |
| 168 | + if (ev_n.name == ev_name) |
| 169 | + return ev_n; |
| 170 | + } |
| 171 | + } |
| 172 | + return null; |
| 173 | + }; |
| 174 | + |
| 175 | + this._get_rt = function(rt_id) |
| 176 | + { |
| 177 | + if (this._rts) |
| 178 | + { |
| 179 | + for (var i = 0, rt; rt = this._rts[i]; i++) |
| 180 | + { |
| 181 | + if (rt.rt_id == rt_id) |
| 182 | + return rt; |
| 183 | + } |
| 184 | + } |
| 185 | + return null; |
| 186 | + }; |
| 187 | + |
| 188 | + this._get_rt_index = function(rt_id) |
| 189 | + { |
| 190 | + for (var i = 0; i < this._rts.length && this._rts[i].rt_id !== rt_id; i++); |
| 191 | + return i; |
| 192 | + }; |
| 193 | + |
| 194 | + /* implementation */ |
| 195 | + |
| 196 | + this.update = function() |
| 197 | + { |
| 198 | + this._rts = []; |
| 199 | + this._win_id_map = {}; |
| 200 | + var rt_id_list = window.runtimes.get_runtime_ids(); |
| 201 | + if (rt_id_list.length) |
| 202 | + { |
| 203 | + window.messages.remove_listener('new-top-runtime', this._update_bound); |
| 204 | + this._update_rt_list(rt_id_list); |
| 205 | + } |
| 206 | + else |
| 207 | + window.messages.add_listener('new-top-runtime', this._update_bound); |
| 208 | + }; |
| 209 | + |
| 210 | + this.get_data = function() |
| 211 | + { |
| 212 | + if (this._rts) |
| 213 | + return this._rts; |
| 214 | + |
| 215 | + this.update(); |
| 216 | + return null; |
| 217 | + }; |
| 218 | + |
| 219 | + this.expand_listeners = function(rt_id, obj_id, ev_name, cb) |
| 220 | + { |
| 221 | + var ev_n = this._get_ev_name_obj(rt_id, ev_name); |
| 222 | + if (ev_n) |
| 223 | + { |
| 224 | + ev_n.rt_id = rt_id; |
| 225 | + ev_n.obj_id = obj_id; |
| 226 | + ev_n.model = new cls.InspectableDOMNode(rt_id, obj_id); |
| 227 | + var cb = this._handle_dom_search.bind(this, ev_n, cb); |
| 228 | + ev_n.model.search(ev_name, SEARCH_TYPE_EVENT, 0, 0, cb); |
| 229 | + } |
| 230 | + else |
| 231 | + opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE + |
| 232 | + "failed to find event names object in cls.EvenetListeners.") |
| 233 | + |
| 234 | + }; |
| 235 | + |
| 236 | + this._init = function(view) |
| 237 | + { |
| 238 | + this._view = view; |
| 239 | + this._tagman = window.tag_manager; |
| 240 | + this._esdb = window.services["ecmascript-debugger"]; |
| 241 | + this._update_bound = this.update.bind(this); |
| 242 | + } |
| 243 | + |
| 244 | + this._init(view); |
| 245 | +}; |
0 commit comments