PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/prebuilt/extension/chrome/content/pdfplugin.js

http://firefox-mac-pdf.googlecode.com/
JavaScript | 75 lines | 42 code | 8 blank | 25 comment | 10 complexity | 14c4aab0fd2c8c0f79ede40352bd88ac MD5 | raw file
 1/*
 2 * Copyright (c) 2008 Samuel Gross.
 3 *
 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
 5 * of this software and associated documentation files (the "Software"), to deal
 6 * in the Software without restriction, including without limitation the rights
 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 8 * copies of the Software, and to permit persons to whom the Software is
 9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22(function() {
23
24var browser;
25var cmdFind;
26var cmdFindAgain;
27var cmdFindPrevious;
28
29var mimeTypes = {
30 "application/pdf" : true,
31 "text/pdf" : true
32};
33
34function init() {
35  browser = document.getElementById('content');
36  cmdFind = document.getElementById('cmd_find');
37  cmdFindAgain = document.getElementById('cmd_findAgain');
38  cmdFindPrevious = document.getElementById('cmd_findPrevious');
39
40  // enable/disable find menu items correctly
41  // this needs to be set before the plugin is loaded
42  XULBrowserWindow.onStateChange = 
43      createStateChangeHandler(XULBrowserWindow.onStateChange);
44}
45
46function getPluginElement() {
47  // Check if the page contains the plugin instance
48  var doc = browser.contentWindow.document;
49  var body = doc.body;
50  if (!(body && body.tagName == 'BODY' && body.childNodes.length == 1)) {
51    return null;
52  }
53   var embed = body.firstChild;
54  if (!(embed && embed.tagName == 'EMBED' && mimeTypes[embed.type])) {
55    return null;
56  }
57  return embed;
58}
59
60function createStateChangeHandler(o) {
61  return function(aWebProgress, aRequest, aStateFlags, aStatus) {
62    // remove the attribute to force a change if disabled is set
63    document.getElementById('isImage').removeAttribute('disabled');
64    o.call(this, aWebProgress, aRequest, aStateFlags, aStatus);
65    if (getPluginElement()) {
66      cmdFind.removeAttribute('disabled');
67      cmdFindAgain.removeAttribute('disabled');
68      cmdFindPrevious.removeAttribute('disabled');
69    }
70  }
71}
72
73addEventListener('load', init, false);
74
75})();