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

Delta Between Two Patch Sets: files/background.js

Issue 8493027: Acquired Opera AdBlock code (Closed)
Left Patch Set: Created Oct. 2, 2012, 1:15 p.m.
Right Patch Set: Created Oct. 8, 2012, 5:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « design/notify.css ('k') | files/button.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /*opera.extension.windows.addEventListener( "focus", function(){ 1 /*opera.extension.windows.addEventListener( "focus", function(){
2 opera.postError('Focus: ' + opera.extension.tabs.getSelected().url); 2 opera.postError('Focus: ' + opera.extension.tabs.getSelected().url);
3 }); 3 });
4 opera.extension.windows.addEventListener( "change", function(){ 4 opera.extension.windows.addEventListener( "change", function(){
5 opera.postError('Change: ' + opera.extension.tabs.getSelected()); 5 opera.postError('Change: ' + opera.extension.tabs.getSelected());
6 }); 6 });
7 opera.extension.windows.addEventListener( "create", function(){ 7 opera.extension.windows.addEventListener( "create", function(){
8 opera.postError('Create: ' + opera.extension.tabs.getSelected()); 8 opera.postError('Create: ' + opera.extension.tabs.getSelected());
9 }); 9 });
10 opera.extension.windows.addEventListener( "update", function(){ 10 opera.extension.windows.addEventListener( "update", function(){
11 opera.postError('Update: ' + opera.extension.tabs.getSelected()); 11 opera.postError('Update: ' + opera.extension.tabs.getSelected());
12 });*/ 12 });*/
13 13
14 opera.extension.onmessage = function (event) { 14 opera.extension.onmessage = function (event) {
15 button.update(); 15 button.update();
16 //opera.postError('BACKGROUND: got a ' + event.data.request + ' request' ); 16 //opera.postError('BACKGROUND: got a ' + event.data.request + ' request' );
17 switch(event.data.request) { 17 switch(event.data.request) {
18 case 'css': 18 case 'css':
19 //opera.postError('BACKGROUND: got reply from ' + event. data.url); 19 //opera.postError('BACKGROUND: got reply from ' + event. data.url);
20 if(whitelist.check(event.data.url)) 20 if(whitelist.check(event.data.url))
Felix Dahlke 2012/10/05 15:47:16 In all postMessage invocations, just the reply is
21 event.source.postMessage({request: event.data.re quest, reply: css.personal().join("\n"), id: 'OAB_Perso'}); 21 event.source.postMessage({request: event.data.re quest, reply: css.personal().join("\n"), id: 'OAB_Perso'});
22 else 22 else
23 event.source.postMessage({request: event.data.re quest, reply: '', id: 'OAB_Perso'}); 23 event.source.postMessage({request: event.data.re quest, reply: '', id: 'OAB_Perso'});
24 24
25 for(key in sources.css) { //Sends them one by one to avo id contamination in cases where one is corrupted 25 for(key in sources.css) { //Sends them one by one to avo id contamination in cases where one is corrupted
26 if(css.status(key) && whitelist.check(event.data .url)) 26 if(css.status(key) && whitelist.check(event.data .url))
Felix Dahlke 2012/10/05 15:47:16 whitelist.check(event.data.url) should be stored i
27 event.source.postMessage({request: event .data.request, reply: css.get(key).join("\n"), id: 'OAB_' + key}); 27 event.source.postMessage({request: event .data.request, reply: css.get(key).join("\n"), id: 'OAB_' + key});
28 else 28 else
29 event.source.postMessage({request: event .data.request, reply: '', id: 'OAB_' + key}); 29 event.source.postMessage({request: event .data.request, reply: '', id: 'OAB_' + key});
30 } 30 }
31 break; 31 break;
32 case 'ping': 32 case 'ping':
33 //opera.postError('BACKGROUND: ping received'); 33 //opera.postError('BACKGROUND: ping received');
34 opera.extension.broadcastMessage({request: 'ping', type: event.data.type}); 34 opera.extension.broadcastMessage({request: 'ping', type: event.data.type});
35 break; 35 break;
36 case 'list': 36 case 'list':
37 if(event.data.enable) 37 if(event.data.enable)
38 lists.enable(event.data.key); 38 lists.enable(event.data.key);
39 else 39 else
40 lists.disable(event.data.key); 40 lists.disable(event.data.key);
41 break; 41 break;
42 case 'whitelist': //request: whitelist // type: add | remove // rule: RULE 42 case 'whitelist': //request: whitelist // type: add | remove // rule: RULE
43 if(event.data.type == 'add') 43 if(event.data.type == 'add')
44 opera.extension.urlfilter.allow.add(event.data.r ule); 44 opera.extension.urlfilter.allow.add(event.data.r ule);
Felix Dahlke 2012/10/05 15:47:16 See comment in parse.js on urlfilter.allow.
45 else if(event.data.type == 'remove') 45 else if(event.data.type == 'remove')
46 opera.extension.urlfilter.allow.remove(event.dat a.rule); 46 opera.extension.urlfilter.allow.remove(event.dat a.rule);
47 break; 47 break;
48 » » case 'button': 48 » » /*case 'button':
49 if(event.data.enable) 49 if(event.data.enable)
50 button.enable(); 50 button.enable();
51 else 51 else
52 » » » » button.disable(); 52 » » » » button.disable();*/
53 } 53 }
54 } 54 }
55 55
56 if(window.widget.version != preferences.string('version')) { //New install 56 if(window.widget.version != preferences.string('version')) {
57 » //Enables Russian lists for new installs on Russian computers 57 » if(!preferences.exist('version')) { // New install
58 » if(window.navigator.language.substring(0,2).toLowerCase() == 'ru') { 58 » » lists.enable('easy');
Felix Dahlke 2012/10/05 15:47:16 This is something we'll want to do for all locales
59 » » preferences.bool('fanboy-ru', true);
60 » » preferences.bool('easy-ru-css', true);
61 } 59 }
62 » 60 » else { //Update from previous versions
61 » » if(preferences.float('version') < 0.60) { //Updating from versi ons before Next, only enabled lists are ported
62 » » » var enabledLists = new Array();
63 » » » for(key in sources.all()) { //Notes all enabled lists
64 » » » » if(preferences.bool(key))
65 » » » » » enabledLists.push(key);
66 » » » }
67 » » » var enabledCss = new Array();
68 » » » for(key in sources.css) { //Notes all enabled lists
69 » » » » if(preferences.bool(key))
70 » » » » » enabledCss.push(key);
71 » » » }
72 » » » var whitelist = lists.whitelist.get();
73 » » »
74 » » » widget.preferences.clear(); //Removes all old preference s
75 » » »
76 » » » for(i in enabledLists) { //Enable all previously enabled lists
77 » » » » lists.enable(enabledLists[i]);
78 » » » }
79 » » » for(i in enabledCss) { //Enable all previously enabled l ists
80 » » » » css.enable(enabledCss[i], false);
81 » » » }
82 » » » lists.whitelist.set(whitelist);
83 » » }
84 » » else if(preferences.float('version') <= 0.71) { //Updating from versions before lists merge and change
85 » » » widget.preferences.clear(); //Removes all old preference s
86 » » » // As no stable version exist between 0.52 and 0.71, the settings are not ported and simply removed from the extension
87 » » }
88 » »
89 » }
63 //Updates the version 90 //Updates the version
64 preferences.string('version', window.widget.version); 91 preferences.string('version', window.widget.version);
65 } 92 }
66 93
67 function updateAll() { 94 function updateAll() {
68 //opera.postError('updateAll() called'); 95 //opera.postError('updateAll() called');
69 for(key in sources.css) { 96 for(key in sources.css) {
70 if(css.status(key) && getTime() - css.time(key) > preferences.in t('interval')) { //If the list is enabled 97 if(css.status(key) && getTime() - css.time(key) > preferences.in t('interval')) { //If the list is enabled
Felix Dahlke 2012/10/05 15:47:16 getTime() and preferences.int('interval') should b
71 css.update(key); 98 css.update(key);
72 //opera.postError(key + ' updated'); 99 //opera.postError(key + ' updated');
73 } 100 }
74 } 101 }
75 for(key in sources.all()) { 102 for(key in sources.all()) {
76 if(lists.status(key) && getTime() - lists.time(key) > preference s.int('interval')) { //If the list is enabled 103 if(lists.status(key) && getTime() - lists.time(key) > preference s.int('interval')) { //If the list is enabled
77 lists.update(key); 104 lists.update(key);
78 //opera.postError(key + ' updated'); 105 //opera.postError(key + ' updated');
79 } 106 }
80 } 107 }
81 window.setTimeout('updateAll()', preferences.int('interval') / 12); //Ve rifies required updates every 1/12 of the update interval 108 window.setTimeout('updateAll()', preferences.int('interval') / 12); //Ve rifies required updates every 1/12 of the update interval
Felix Dahlke 2012/10/05 15:47:16 Better use window.setTimeout(updateAll, ...), pass
82 } 109 }
83 110
84 lists.setup(); //Enables all lists 111 lists.setup(); //Enables all lists
85 updateAll(); //Sets update intervals 112 updateAll(); //Sets update intervals
LEFTRIGHT

Powered by Google App Engine
This is Rietveld