toolkit/content/findUtils.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 8
michael@0 9 var gFindBundle;
michael@0 10
michael@0 11 function nsFindInstData() {}
michael@0 12 nsFindInstData.prototype =
michael@0 13 {
michael@0 14 // set the next three attributes on your object to override the defaults
michael@0 15 browser : null,
michael@0 16
michael@0 17 get rootSearchWindow() { return this._root || this.window.content; },
michael@0 18 set rootSearchWindow(val) { this._root = val; },
michael@0 19
michael@0 20 get currentSearchWindow() {
michael@0 21 if (this._current)
michael@0 22 return this._current;
michael@0 23
michael@0 24 var focusedWindow = this.window.document.commandDispatcher.focusedWindow;
michael@0 25 if (!focusedWindow || focusedWindow == this.window)
michael@0 26 focusedWindow = this.window.content;
michael@0 27
michael@0 28 return focusedWindow;
michael@0 29 },
michael@0 30 set currentSearchWindow(val) { this._current = val; },
michael@0 31
michael@0 32 get webBrowserFind() { return this.browser.webBrowserFind; },
michael@0 33
michael@0 34 init : function() {
michael@0 35 var findInst = this.webBrowserFind;
michael@0 36 // set up the find to search the focussedWindow, bounded by the content window.
michael@0 37 var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
michael@0 38 findInFrames.rootSearchFrame = this.rootSearchWindow;
michael@0 39 findInFrames.currentSearchFrame = this.currentSearchWindow;
michael@0 40
michael@0 41 // always search in frames for now. We could add a checkbox to the dialog for this.
michael@0 42 findInst.searchFrames = true;
michael@0 43 },
michael@0 44
michael@0 45 window : window,
michael@0 46 _root : null,
michael@0 47 _current : null
michael@0 48 }
michael@0 49
michael@0 50 // browser is the <browser> element
michael@0 51 // rootSearchWindow is the window to constrain the search to (normally window.content)
michael@0 52 // currentSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
michael@0 53 function findInPage(findInstData)
michael@0 54 {
michael@0 55 // is the dialog up already?
michael@0 56 if ("findDialog" in window && window.findDialog)
michael@0 57 window.findDialog.focus();
michael@0 58 else
michael@0 59 {
michael@0 60 findInstData.init();
michael@0 61 window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInstData);
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 function findAgainInPage(findInstData, reverse)
michael@0 66 {
michael@0 67 if ("findDialog" in window && window.findDialog)
michael@0 68 window.findDialog.focus();
michael@0 69 else
michael@0 70 {
michael@0 71 // get the find service, which stores global find state, and init the
michael@0 72 // nsIWebBrowser find with it. We don't assume that there was a previous
michael@0 73 // Find that set this up.
michael@0 74 var findService = Components.classes["@mozilla.org/find/find_service;1"]
michael@0 75 .getService(Components.interfaces.nsIFindService);
michael@0 76
michael@0 77 var searchString = findService.searchString;
michael@0 78 if (searchString.length == 0) {
michael@0 79 // no previous find text
michael@0 80 findInPage(findInstData);
michael@0 81 return;
michael@0 82 }
michael@0 83
michael@0 84 findInstData.init();
michael@0 85 var findInst = findInstData.webBrowserFind;
michael@0 86 findInst.searchString = searchString;
michael@0 87 findInst.matchCase = findService.matchCase;
michael@0 88 findInst.wrapFind = findService.wrapFind;
michael@0 89 findInst.entireWord = findService.entireWord;
michael@0 90 findInst.findBackwards = findService.findBackwards ^ reverse;
michael@0 91
michael@0 92 var found = findInst.findNext();
michael@0 93 if (!found) {
michael@0 94 if (!gFindBundle)
michael@0 95 gFindBundle = document.getElementById("findBundle");
michael@0 96
michael@0 97 Services.prompt.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
michael@0 98 }
michael@0 99
michael@0 100 // Reset to normal value, otherwise setting can get changed in find dialog
michael@0 101 findInst.findBackwards = findService.findBackwards;
michael@0 102 }
michael@0 103 }
michael@0 104
michael@0 105 function canFindAgainInPage()
michael@0 106 {
michael@0 107 var findService = Components.classes["@mozilla.org/find/find_service;1"]
michael@0 108 .getService(Components.interfaces.nsIFindService);
michael@0 109 return (findService.searchString.length > 0);
michael@0 110 }
michael@0 111

mercurial