1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-2017 eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @fileOverview Code responsible for showing and hiding object tabs.
*/
let {Prefs} = require("prefs");
let {Utils} = require("utils");
let {port} = require("messaging");
/**
* Random element class, to be used for object tabs displayed on top of the
* plugin content.
* @type string
*/
let classVisibleTop = null;
/**
* Random element class, to be used for object tabs displayed at the bottom of
* the plugin content.
* @type string
*/
let classVisibleBottom = null;
/**
* Random element class, to be used for object tabs that are hidden.
* @type string
*/
let classHidden = null;
port.on("getObjectTabsStatus", function(message, sender)
{
let {UI} = require("ui");
return !!(Prefs.enabled && Prefs.frameobjects && UI.overlay && classHidden);
});
port.on("getObjectTabsTexts", function(message, sender)
{
let {UI} = require("ui");
return {
label: UI.overlay.attributes.objtabtext,
tooltip: UI.overlay.attributes.objtabtooltip,
classVisibleTop, classVisibleBottom, classHidden
};
});
port.on("blockItem", function({request, nodesID}, sender)
{
let {UI} = require("ui");
UI.blockItem(UI.currentWindow, nodesID, request);
});
function init()
{
function processCSSData(event)
{
if (onShutdown.done)
return;
let data = event.target.responseText;
let rnd = [];
let offset = "a".charCodeAt(0);
for (let i = 0; i < 60; i++)
rnd.push(offset + Math.random() * 26);
classVisibleTop = String.fromCharCode.apply(String, rnd.slice(0, 20));
classVisibleBottom = String.fromCharCode.apply(String, rnd.slice(20, 40));
classHidden = String.fromCharCode.apply(String, rnd.slice(40, 60));
let url = Utils.makeURI("data:text/css," + encodeURIComponent(data.replace(/%%CLASSVISIBLETOP%%/g, classVisibleTop)
.replace(/%%CLASSVISIBLEBOTTOM%%/g, classVisibleBottom)
.replace(/%%CLASSHIDDEN%%/g, classHidden)));
Utils.styleService.loadAndRegisterSheet(url, Ci.nsIStyleSheetService.USER_SHEET);
onShutdown.add(function()
{
Utils.styleService.unregisterSheet(url, Ci.nsIStyleSheetService.USER_SHEET);
});
}
// Load CSS asynchronously
try
{
let request = new XMLHttpRequest();
request.mozBackgroundRequest = true;
request.open("GET", "chrome://adblockplus/content/objtabs.css");
request.overrideMimeType("text/plain");
request.addEventListener("load", processCSSData, false);
request.send(null);
}
catch (e)
{
Cu.reportError(e);
}
}
init();
|