Skip to content

Commit

Permalink
Merge pull request #4756 from yurydelendik/Fx-getFindBar
Browse files Browse the repository at this point in the history
Add getFindBar for Fx extension (redo)
  • Loading branch information
yurydelendik committed May 8, 2014
2 parents 6ea118b + 9f9454d commit abc924b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
44 changes: 31 additions & 13 deletions extensions/firefox/content/PdfStreamConverter.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 + '.');
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions test/mozcentral/browser_pdfjs_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@ 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
//
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
//
Expand Down

0 comments on commit abc924b

Please sign in to comment.