browser/metro/base/content/contenthandlers/PluginHelper.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/content/contenthandlers/PluginHelper.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +"use strict";
     1.8 +
     1.9 +dump("### PluginHelper.js loaded\n");
    1.10 +
    1.11 +/**
    1.12 + * Handle events generated by plugin click-to-play code.
    1.13 + *
    1.14 + * This "PluginBindingAttached" fires when a "pluginProblem" XBL binding is
    1.15 + * created.  This binding overlays plugin content when the plugin is missing,
    1.16 + * blocked, click-to-play, or replaced by a "preview" extension plugin like
    1.17 + * Shumway or PDF.js.
    1.18 + */
    1.19 +var PluginHelper = {
    1.20 +  init: function () {
    1.21 +    addEventListener("PluginBindingAttached", this, true, true);
    1.22 +  },
    1.23 +
    1.24 +  handleEvent: function handleEvent(aEvent) {
    1.25 +    switch (aEvent.type) {
    1.26 +      case "PluginBindingAttached":
    1.27 +        this.handlePluginBindingAttached(aEvent);
    1.28 +        break;
    1.29 +    }
    1.30 +  },
    1.31 +
    1.32 +  getPluginMimeType: function (plugin) {
    1.33 +    var tagMimetype = plugin.actualType;
    1.34 +
    1.35 +    if (tagMimetype == "") {
    1.36 +      tagMimetype = plugin.type;
    1.37 +    }
    1.38 +    return tagMimetype;
    1.39 +  },
    1.40 +
    1.41 +  handlePluginBindingAttached: function (aEvent) {
    1.42 +    let plugin = aEvent.target;
    1.43 +    let doc = plugin.ownerDocument;
    1.44 +    let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    1.45 +    if (!overlay || overlay._bindingHandled) {
    1.46 +      return;
    1.47 +    }
    1.48 +    overlay._bindingHandled = true;
    1.49 +
    1.50 +    let eventType = PluginHelper._getBindingType(plugin);
    1.51 +    if (!eventType) {
    1.52 +      return;
    1.53 +    }
    1.54 +
    1.55 +    switch  (eventType) {
    1.56 +      case "PluginPlayPreview": {
    1.57 +        // Load the "preview" handler (an extension plugin like Shumway or PDF.js).
    1.58 +        let previewContent = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent");
    1.59 +        let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
    1.60 +        let mimeType = PluginHelper.getPluginMimeType(plugin);
    1.61 +        let playPreviewInfo = pluginHost.getPlayPreviewInfo(mimeType);
    1.62 +
    1.63 +        let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0];
    1.64 +        if (!iframe) {
    1.65 +          // lazy initialization of the iframe
    1.66 +          iframe = doc.createElementNS("http://www.w3.org/1999/xhtml", "iframe");
    1.67 +          iframe.className = "previewPluginContentFrame";
    1.68 +          previewContent.appendChild(iframe);
    1.69 +        }
    1.70 +        iframe.src = playPreviewInfo.redirectURL;
    1.71 +        break;
    1.72 +      }
    1.73 +
    1.74 +      case "PluginNotFound": {
    1.75 +        // TODO: Display a message about missing plugins (bug 936907)
    1.76 +        break;
    1.77 +      }
    1.78 +    }
    1.79 +  },
    1.80 +
    1.81 +  // Helper to get the binding handler type from a plugin object
    1.82 +  _getBindingType: function(plugin) {
    1.83 +    if (!(plugin instanceof Ci.nsIObjectLoadingContent))
    1.84 +      return null;
    1.85 +
    1.86 +    switch (plugin.pluginFallbackType) {
    1.87 +      case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED:
    1.88 +        return "PluginNotFound";
    1.89 +      case Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW:
    1.90 +        return "PluginPlayPreview";
    1.91 +      default:
    1.92 +        // Metro Firefox does not yet support other fallback types.
    1.93 +        return null;
    1.94 +    }
    1.95 +  },
    1.96 +};
    1.97 +
    1.98 +PluginHelper.init();

mercurial