Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: safari/ext/common.js

Issue 6346177440120832: Added abstraction for frames, to fix domain-based rules, whitelisting and ad counter on Safari (Closed)
Patch Set: Addressed another comment Created Jan. 20, 2014, 8:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « safari/ext/background.js ('k') | safari/ext/content.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 this._wrappedListeners[idx], 52 this._wrappedListeners[idx],
53 this._capture 53 this._capture
54 ); 54 );
55 55
56 this._listeners.splice(idx, 1); 56 this._listeners.splice(idx, 1);
57 this._wrappedListeners.splice(idx, 1); 57 this._wrappedListeners.splice(idx, 1);
58 } 58 }
59 } 59 }
60 }; 60 };
61 61
62
63 MessageEventTarget = function(target) 62 MessageEventTarget = function(target)
64 { 63 {
65 WrappedEventTarget.call(this, target, "message", false); 64 WrappedEventTarget.call(this, target, "message", false);
66 }; 65 };
67 MessageEventTarget.prototype = { 66 MessageEventTarget.prototype = {
68 __proto__: WrappedEventTarget.prototype, 67 __proto__: WrappedEventTarget.prototype,
69 _wrapListener: function(listener) 68 _wrapListener: function(listener)
70 { 69 {
71 return function(event) 70 return function(event)
72 { 71 {
73 if (event.name.indexOf("request-") != 0) 72 if (event.name == "request")
74 return; 73 listener(event.message.payload, this._getSenderDetails(event), functio n(message)
75 74 {
76 var sender = {}; 75 this._getResponseDispatcher(event).dispatchMessage("response",
77 var dispatcher; 76 {
78 77 requestId: event.message.requestId,
79 if ("Tab" in window && "SafariBrowserTab" in window && event.target inst anceof SafariBrowserTab) 78 payload: message
80 { 79 });
81 dispatcher = event.target.page; 80 }.bind(this));
82 sender.tab = new Tab(event.target); 81 }.bind(this);
83 }
84 else
85 {
86 dispatcher = event.target.tab;
87 sender.tab = null;
88 }
89
90 listener(event.message, sender, function(message)
91 {
92 dispatcher.dispatchMessage("response-" + event.name.substr(8), message );
93 });
94 };
95 } 82 }
96 }; 83 };
97 84
98 85
99 /* Message passing */ 86 /* Message passing */
100 87
101 var requestCounter = 0; 88 var requestCounter = 0;
102 89
103 sendMessage = function(message, responseCallback) 90 _sendMessage = function(message, responseCallback, messageDispatcher, response EventTarget, extra)
104 { 91 {
105 var requestId = ++requestCounter; 92 var requestId = ++requestCounter;
106 93
107 if (responseCallback) 94 if (responseCallback)
108 { 95 {
109 var eventTarget = this._eventTarget;
110 var responseListener = function(event) 96 var responseListener = function(event)
111 { 97 {
112 if (event.name == "response-" + requestId) 98 if (event.name == "response" && event.message.requestId == requestId)
113 { 99 {
114 eventTarget.removeEventListener("message", responseListener, false); 100 responseEventTarget.removeEventListener("message", responseListener, f alse);
115 responseCallback(event.message); 101 responseCallback(event.message.payload);
116 } 102 }
117 }; 103 };
118 eventTarget.addEventListener("message", responseListener, false); 104 responseEventTarget.addEventListener("message", responseListener, false);
119 } 105 }
120 106
121 this._messageDispatcher.dispatchMessage("request-" + requestId, message); 107 var rawMessage = {requestId: requestId, payload: message};
108 for (var k in extra)
109 rawMessage[k] = extra[k];
110 messageDispatcher.dispatchMessage("request", rawMessage);
122 }; 111 };
123 112
124 113
125 /* I18n */ 114 /* I18n */
126 115
127 var I18n = function() 116 var I18n = function()
128 { 117 {
129 this._localeCandidates = this._getLocaleCandidates(); 118 this._localeCandidates = this._getLocaleCandidates();
130 this._uiLocale = this._localeCandidates[0]; 119 this._uiLocale = this._localeCandidates[0];
131 }; 120 };
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 /* API */ 209 /* API */
221 210
222 ext = { 211 ext = {
223 getURL: function(path) 212 getURL: function(path)
224 { 213 {
225 return safari.extension.baseURI + path; 214 return safari.extension.baseURI + path;
226 }, 215 },
227 i18n: new I18n() 216 i18n: new I18n()
228 }; 217 };
229 })(); 218 })();
OLDNEW
« no previous file with comments | « safari/ext/background.js ('k') | safari/ext/content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld