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

Unified Diff: lib/child/objectTabs.js

Issue 29329839: Issue 3228 - Unbreak object tabs (Closed)
Patch Set: Added comments Created Nov. 25, 2015, 10:49 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/child/contentPolicy.js ('k') | lib/child/requestNotifier.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/child/objectTabs.js
===================================================================
copy from lib/objectTabs.js
copy to lib/child/objectTabs.js
--- a/lib/objectTabs.js
+++ b/lib/child/objectTabs.js
@@ -27,52 +27,16 @@ var objTabs =
{
/**
* Number of milliseconds to wait until hiding tab after the mouse moves away.
* @type Integer
*/
HIDE_DELAY: 1000,
/**
- * Flag used to trigger object tabs initialization first time object tabs are
- * used.
- * @type Boolean
- */
- initialized: false,
-
- /**
- * Will be set to true while initialization is in progress.
- * @type Boolean
- */
- initializing: false,
-
- /**
- * Parameters for _showTab, to be called once initialization is complete.
- */
- delayedShowParams: null,
-
- /**
- * Randomly generated class to be used for visible object tabs on top of object.
- * @type String
- */
- objTabClassVisibleTop: null,
-
- /**
- * Randomly generated class to be used for visible object tabs at the bottom of the object.
- * @type String
- */
- objTabClassVisibleBottom: null,
-
- /**
- * Randomly generated class to be used for invisible object tabs.
- * @type String
- */
- objTabClassHidden: null,
-
- /**
* Document element the object tab is currently being displayed for.
* @type Element
*/
currentElement: null,
/**
* Windows that the window event handler is currently registered for.
* @type Window[]
@@ -105,115 +69,52 @@ var objTabs =
/**
* Used when hideTimer is running, time when the tab should be hidden.
* @type Integer
*/
hideTargetTime: 0,
/**
- * Initializes object tabs (generates random classes and registers stylesheet).
+ * Localized texts and class names to be used for the tab.
+ * @type Object
*/
- _initCSS: function()
- {
- function processCSSData(request)
- {
- if (onShutdown.done)
- return;
-
- let data = request.responseText;
-
- let rnd = [];
- let offset = "a".charCodeAt(0);
- for (let i = 0; i < 60; i++)
- rnd.push(offset + Math.random() * 26);
-
- this.objTabClassVisibleTop = String.fromCharCode.apply(String, rnd.slice(0, 20));
- this.objTabClassVisibleBottom = String.fromCharCode.apply(String, rnd.slice(20, 40));
- this.objTabClassHidden = String.fromCharCode.apply(String, rnd.slice(40, 60));
-
- let {Utils} = require("utils");
- let url = Utils.makeURI("data:text/css," + encodeURIComponent(data.replace(/%%CLASSVISIBLETOP%%/g, this.objTabClassVisibleTop)
- .replace(/%%CLASSVISIBLEBOTTOM%%/g, this.objTabClassVisibleBottom)
- .replace(/%%CLASSHIDDEN%%/g, this.objTabClassHidden)));
- Utils.styleService.loadAndRegisterSheet(url, Ci.nsIStyleSheetService.USER_SHEET);
- onShutdown.add(function()
- {
- Utils.styleService.unregisterSheet(url, Ci.nsIStyleSheetService.USER_SHEET);
- });
-
- this.initializing = false;
- this.initialized = true;
-
- if (this.delayedShowParams)
- this._showTab.apply(this, this.delayedShowParams);
- }
-
- this.delayedShowParams = arguments;
-
- if (!this.initializing)
- {
- this.initializing = true;
-
- // 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.bind(this, request), false);
- request.send(null);
- }
- catch (e)
- {
- Cu.reportError(e);
- this.initializing = false;
- }
- }
- },
+ texts: null,
/**
* Called to show object tab for an element.
*/
showTabFor: function(/**Element*/ element)
{
// Object tabs aren't usable in Fennec
let {application} = require("info");
if (application == "fennec" || application == "fennec2" ||
application == "adblockbrowser")
return;
- let {Prefs} = require("prefs");
- if (!Prefs.frameobjects)
+ if (!sendSyncMessage("AdblockPlus:GetObjectTabsStatus"))
return;
if (this.hideTimer)
{
this.hideTimer.cancel();
this.hideTimer = null;
}
if (this.objtabElement)
this.objtabElement.style.setProperty("opacity", "1", "important");
if (this.currentElement != element)
{
this._hideTab();
- let {Policy} = require("contentPolicy");
- let {RequestNotifier} = require("requestNotifier");
+ let {RequestNotifier} = require("child/requestNotifier");
let data = RequestNotifier.getDataForNode(element, true, "OBJECT");
if (data)
- {
- if (this.initialized)
- this._showTab(element, data[1]);
- else
- this._initCSS(element, data[1]);
- }
+ this._showTab(element, data[1]);
}
},
/**
* Called to hide object tab for an element (actual hiding happens delayed).
*/
hideTabFor: function(/**Element*/ element)
{
@@ -227,27 +128,26 @@ var objTabs =
/**
* Makes the tab element visible.
* @param {Element} element
* @param {RequestEntry} data
*/
_showTab: function(element, data)
{
- let {UI} = require("ui");
- if (!UI.overlay)
- return;
+ if (!this.texts)
+ this.texts = sendSyncMessage("AdblockPlus:GetObjectTabsTexts");
let doc = element.ownerDocument.defaultView.top.document;
this.objtabElement = doc.createElementNS("http://www.w3.org/1999/xhtml", "a");
- this.objtabElement.textContent = UI.overlay.attributes.objtabtext;
- this.objtabElement.setAttribute("title", UI.overlay.attributes.objtabtooltip);
+ this.objtabElement.textContent = this.texts.label;
+ this.objtabElement.setAttribute("title", this.texts.tooltip);
this.objtabElement.setAttribute("href", data.location);
- this.objtabElement.setAttribute("class", this.objTabClassHidden);
+ this.objtabElement.setAttribute("class", this.texts.classHidden);
this.objtabElement.style.setProperty("opacity", "1", "important");
this.objtabElement.nodeData = data;
this.currentElement = element;
// Register paint listeners for the relevant windows
this.windowListeners = [];
let wnd = element.ownerDocument.defaultView;
@@ -273,18 +173,16 @@ var objTabs =
this._positionTab();
},
/**
* Hides the tab element.
*/
_hideTab: function()
{
- this.delayedShowParams = null;
-
if (this.objtabElement)
{
// Prevent recursive calls via popuphidden handler
let objtab = this.objtabElement;
this.objtabElement = null;
this.currentElement = null;
if (this.hideTimer)
@@ -327,23 +225,23 @@ var objTabs =
!elementDoc.defaultView || !elementDoc.documentElement)
{
this._hideTab();
return;
}
let objRect = this._getElementPosition(this.currentElement);
- let className = this.objTabClassVisibleTop;
+ let className = this.texts.classVisibleTop;
let left = objRect.right - this.objtabElement.offsetWidth;
let top = objRect.top - this.objtabElement.offsetHeight;
if (top < 0)
{
top = objRect.bottom;
- className = this.objTabClassVisibleBottom;
+ className = this.texts.classVisibleBottom;
}
if (this.objtabElement.style.left != left + "px")
this.objtabElement.style.setProperty("left", left + "px", "important");
if (this.objtabElement.style.top != top + "px")
this.objtabElement.style.setProperty("top", top + "px", "important");
if (this.objtabElement.getAttribute("class") != className)
@@ -410,20 +308,18 @@ var objTabs =
rect.bottom += relTop;
}
return rect;
},
doBlock: function()
{
- let {UI} = require("ui");
- let {Utils} = require("utils");
- let chromeWindow = Utils.getChromeWindow(this.currentElement.ownerDocument.defaultView);
- UI.blockItem(chromeWindow, this.currentElement, this.objtabElement.nodeData);
+ // TODO: Store this.currentElement for the filter assistant
+ sendAsyncMessage("AdblockPlus:BlockItem", this.objtabElement.nodeData);
},
/**
* Called whenever a timer fires.
* @param {nsISupport} subject
* @param {string} topic
* @param {string} data
*/
« no previous file with comments | « lib/child/contentPolicy.js ('k') | lib/child/requestNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld