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

Unified Diff: lib/child/objectTabs.js

Issue 29338421: Issue 3499 - Use the new messaging API for object tabs (Closed)
Patch Set: Created March 16, 2016, 12:33 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 | « no previous file | lib/objectTabs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/child/objectTabs.js
===================================================================
--- a/lib/child/objectTabs.js
+++ b/lib/child/objectTabs.js
@@ -14,16 +14,18 @@
* 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 {port} = require("messaging");
+
/**
* Class responsible for showing and hiding object tabs.
* @class
*/
var objTabs =
{
/**
* Number of milliseconds to wait until hiding tab after the mouse moves away.
@@ -69,53 +71,61 @@ var objTabs =
/**
* Used when hideTimer is running, time when the tab should be hidden.
* @type Integer
*/
hideTargetTime: 0,
/**
- * Localized texts and class names to be used for the tab.
+ * Localized texts and class names to be used for the tab. This will be set
+ * when showTabFor is called for the first time.
* @type Object
*/
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;
- if (!sendSyncMessage("AdblockPlus:GetObjectTabsStatus"))
- return;
+ if (!this.texts)
+ this.texts = port.emitWithResponse("getObjectTabsTexts");
+ Promise.all([port.emitWithResponse("getObjectTabsStatus"), this.texts])
+ .then(([status, texts]) =>
+ {
+ this.texts = texts;
+ if (!status)
+ return;
- if (this.hideTimer)
- {
- this.hideTimer.cancel();
- this.hideTimer = null;
- }
+ if (this.hideTimer)
+ {
+ this.hideTimer.cancel();
+ this.hideTimer = null;
+ }
- if (this.objtabElement)
- this.objtabElement.style.setProperty("opacity", "1", "important");
+ if (this.objtabElement)
+ this.objtabElement.style.setProperty("opacity", "1", "important");
- if (this.currentElement != element)
- {
- this._hideTab();
+ if (this.currentElement != element)
+ {
+ this._hideTab();
- let {RequestNotifier} = require("child/requestNotifier");
- let data = RequestNotifier.getDataForNode(element, true, "OBJECT");
- if (data)
- this._showTab(element, data[1]);
- }
+ let {RequestNotifier} = require("child/requestNotifier");
+ let data = RequestNotifier.getDataForNode(element, true, "OBJECT");
+ if (data)
+ this._showTab(element, data[1]);
+ }
+ });
},
/**
* Called to hide object tab for an element (actual hiding happens delayed).
*/
hideTabFor: function(/**Element*/ element)
{
if (element != this.currentElement || this.hideTimer)
@@ -128,19 +138,16 @@ var objTabs =
/**
* Makes the tab element visible.
* @param {Element} element
* @param {RequestEntry} data
*/
_showTab: function(element, data)
{
- 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 = this.texts.label;
this.objtabElement.setAttribute("title", this.texts.tooltip);
this.objtabElement.setAttribute("href", data.location);
this.objtabElement.setAttribute("class", this.texts.classHidden);
this.objtabElement.style.setProperty("opacity", "1", "important");
@@ -310,17 +317,17 @@ var objTabs =
return rect;
},
doBlock: function()
{
let {storeNodes} = require("child/contentPolicy");
let nodesID = storeNodes([this.currentElement]);
- sendAsyncMessage("AdblockPlus:BlockItem", {
+ port.emit("blockItem", {
request: this.objtabElement.nodeData,
nodesID
});
},
/**
* Called whenever a timer fires.
* @param {nsISupport} subject
« no previous file with comments | « no previous file | lib/objectTabs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld