michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: dump("### PluginHelper.js loaded\n"); michael@0: michael@0: /** michael@0: * Handle events generated by plugin click-to-play code. michael@0: * michael@0: * This "PluginBindingAttached" fires when a "pluginProblem" XBL binding is michael@0: * created. This binding overlays plugin content when the plugin is missing, michael@0: * blocked, click-to-play, or replaced by a "preview" extension plugin like michael@0: * Shumway or PDF.js. michael@0: */ michael@0: var PluginHelper = { michael@0: init: function () { michael@0: addEventListener("PluginBindingAttached", this, true, true); michael@0: }, michael@0: michael@0: handleEvent: function handleEvent(aEvent) { michael@0: switch (aEvent.type) { michael@0: case "PluginBindingAttached": michael@0: this.handlePluginBindingAttached(aEvent); michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: getPluginMimeType: function (plugin) { michael@0: var tagMimetype = plugin.actualType; michael@0: michael@0: if (tagMimetype == "") { michael@0: tagMimetype = plugin.type; michael@0: } michael@0: return tagMimetype; michael@0: }, michael@0: michael@0: handlePluginBindingAttached: function (aEvent) { michael@0: let plugin = aEvent.target; michael@0: let doc = plugin.ownerDocument; michael@0: let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); michael@0: if (!overlay || overlay._bindingHandled) { michael@0: return; michael@0: } michael@0: overlay._bindingHandled = true; michael@0: michael@0: let eventType = PluginHelper._getBindingType(plugin); michael@0: if (!eventType) { michael@0: return; michael@0: } michael@0: michael@0: switch (eventType) { michael@0: case "PluginPlayPreview": { michael@0: // Load the "preview" handler (an extension plugin like Shumway or PDF.js). michael@0: let previewContent = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent"); michael@0: let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); michael@0: let mimeType = PluginHelper.getPluginMimeType(plugin); michael@0: let playPreviewInfo = pluginHost.getPlayPreviewInfo(mimeType); michael@0: michael@0: let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0]; michael@0: if (!iframe) { michael@0: // lazy initialization of the iframe michael@0: iframe = doc.createElementNS("http://www.w3.org/1999/xhtml", "iframe"); michael@0: iframe.className = "previewPluginContentFrame"; michael@0: previewContent.appendChild(iframe); michael@0: } michael@0: iframe.src = playPreviewInfo.redirectURL; michael@0: break; michael@0: } michael@0: michael@0: case "PluginNotFound": { michael@0: // TODO: Display a message about missing plugins (bug 936907) michael@0: break; michael@0: } michael@0: } michael@0: }, michael@0: michael@0: // Helper to get the binding handler type from a plugin object michael@0: _getBindingType: function(plugin) { michael@0: if (!(plugin instanceof Ci.nsIObjectLoadingContent)) michael@0: return null; michael@0: michael@0: switch (plugin.pluginFallbackType) { michael@0: case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED: michael@0: return "PluginNotFound"; michael@0: case Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW: michael@0: return "PluginPlayPreview"; michael@0: default: michael@0: // Metro Firefox does not yet support other fallback types. michael@0: return null; michael@0: } michael@0: }, michael@0: }; michael@0: michael@0: PluginHelper.init();