Merge pull request #4756 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

View File

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

View File

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