Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | The selector locates elements that are suitable for annotation and enables |
michael@0 | 7 | the user to select them. |
michael@0 | 8 | |
michael@0 | 9 | On 'mouseenter' events associated with <p> elements: |
michael@0 | 10 | - if the selector is active and the element is not already annotated |
michael@0 | 11 | - find the nearest ancestor which has an id attribute: this is supposed to |
michael@0 | 12 | make identification of this element more accurate |
michael@0 | 13 | - highlight the element |
michael@0 | 14 | - bind 'click' for the element to send a message back to the add-on, including |
michael@0 | 15 | all the information associated with the anchor. |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | var matchedElement = null; |
michael@0 | 19 | var originalBgColor = null; |
michael@0 | 20 | var active = false; |
michael@0 | 21 | |
michael@0 | 22 | function resetMatchedElement() { |
michael@0 | 23 | if (matchedElement) { |
michael@0 | 24 | matchedElement.css('background-color', originalBgColor); |
michael@0 | 25 | matchedElement.unbind('click.annotator'); |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | self.on('message', function onMessage(activation) { |
michael@0 | 30 | active = activation; |
michael@0 | 31 | if (!active) { |
michael@0 | 32 | resetMatchedElement(); |
michael@0 | 33 | } |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | function getInnerText(element) { |
michael@0 | 37 | // jQuery.text() returns content of <script> tags, we need to ignore those |
michael@0 | 38 | var list = []; |
michael@0 | 39 | element.find("*").andSelf().contents() |
michael@0 | 40 | .filter(function () { |
michael@0 | 41 | return this.nodeType == 3 && this.parentNode.tagName != "SCRIPT"; |
michael@0 | 42 | }) |
michael@0 | 43 | .each(function () { |
michael@0 | 44 | list.push(this.nodeValue); |
michael@0 | 45 | }); |
michael@0 | 46 | return list.join(""); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | $('*').mouseenter(function() { |
michael@0 | 50 | if (!active || $(this).hasClass('annotated')) { |
michael@0 | 51 | return; |
michael@0 | 52 | } |
michael@0 | 53 | resetMatchedElement(); |
michael@0 | 54 | ancestor = $(this).closest("[id]"); |
michael@0 | 55 | matchedElement = $(this).first(); |
michael@0 | 56 | originalBgColor = matchedElement.css('background-color'); |
michael@0 | 57 | matchedElement.css('background-color', 'yellow'); |
michael@0 | 58 | matchedElement.bind('click.annotator', function(event) { |
michael@0 | 59 | event.stopPropagation(); |
michael@0 | 60 | event.preventDefault(); |
michael@0 | 61 | self.port.emit('show', |
michael@0 | 62 | [ |
michael@0 | 63 | document.location.toString(), |
michael@0 | 64 | ancestor.attr("id"), |
michael@0 | 65 | getInnerText(matchedElement) |
michael@0 | 66 | ] |
michael@0 | 67 | ); |
michael@0 | 68 | }); |
michael@0 | 69 | }); |
michael@0 | 70 | |
michael@0 | 71 | $('*').mouseout(function() { |
michael@0 | 72 | resetMatchedElement(); |
michael@0 | 73 | }); |