Merge pull request from yurydelendik/Fx-getFindBar

Add getFindBar for Fx extension (redo)
This commit is contained in:
Yury Delendik 2014-05-08 09:14:32 -05:00
commit abc924b5af
2 changed files with 38 additions and 15 deletions
extensions/firefox/content
test/mozcentral

@ -53,12 +53,28 @@ XPCOMUtils.defineLazyServiceGetter(Svc, 'mime',
'@mozilla.org/mime;1',
'nsIMIMEService');
function getContainingBrowser(domWindow) {
return domWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
}
function getChromeWindow(domWindow) {
var containingBrowser = domWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
return containingBrowser.ownerDocument.defaultView;
return getContainingBrowser(domWindow).ownerDocument.defaultView;
}
function getFindBar(domWindow) {
var browser = getContainingBrowser(domWindow);
try {
var tabbrowser = browser.getTabBrowser();
var tab = tabbrowser._getTabForBrowser(browser);
return tabbrowser.getFindBar(tab);
} catch (e) {
// FF22 has no _getTabForBrowser, and FF24 has no getFindBar
var chromeWindow = browser.ownerDocument.defaultView;
return chromeWindow.gFindBar;
}
}
function setBoolPref(pref, value) {
@ -317,11 +333,13 @@ ChromeActions.prototype = {
return getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false);
},
supportsIntegratedFind: function() {
// Integrated find is only supported when we're not in a frame and when the
// new find events code exists.
return this.domWindow.frameElement === null &&
getChromeWindow(this.domWindow).gFindBar &&
'updateControlState' in getChromeWindow(this.domWindow).gFindBar;
// Integrated find is only supported when we're not in a frame
if (this.domWindow.frameElement !== null) {
return false;
}
// ... and when the new find events code exists.
var findBar = getFindBar(this.domWindow);
return findBar && ('updateControlState' in findBar);
},
supportsDocumentFonts: function() {
var prefBrowser = getIntPref('browser.display.use_document_fonts', 1);
@ -438,8 +456,7 @@ ChromeActions.prototype = {
(findPreviousType !== 'undefined' && findPreviousType !== 'boolean')) {
return;
}
getChromeWindow(this.domWindow).gFindBar
.updateControlState(result, findPrevious);
getFindBar(this.domWindow).updateControlState(result, findPrevious);
},
setPreferences: function(prefs, sendResponse) {
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + '.');
@ -917,7 +934,8 @@ PdfStreamConverter.prototype = {
}, false, true);
if (actions.supportsIntegratedFind()) {
var chromeWindow = getChromeWindow(domWindow);
var findEventManager = new FindEventManager(chromeWindow.gFindBar,
var findBar = getFindBar(domWindow);
var findEventManager = new FindEventManager(findBar,
domWindow,
chromeWindow);
findEventManager.bind();

@ -32,13 +32,13 @@ function test() {
// Runs tests after all 'load' event handlers have fired off
window.addEventListener("documentload", function() {
runTests(document, window, finish);
runTests(document, window, tab, finish);
}, false, true);
}, true);
}
function runTests(document, window, callback) {
function runTests(document, window, tab, callback) {
//
// Overall sanity tests
@ -46,6 +46,11 @@ function runTests(document, window, callback) {
ok(document.querySelector('div#viewer'), "document content has viewer UI");
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
//
// Browser Find
//
ok(gBrowser.isFindBarInitialized(tab), "Browser FindBar initialized!");
//
// Sidebar: open
//