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.

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

mercurial