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

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 dump("### PluginHelper.js loaded\n");
michael@0 7
michael@0 8 /**
michael@0 9 * Handle events generated by plugin click-to-play code.
michael@0 10 *
michael@0 11 * This "PluginBindingAttached" fires when a "pluginProblem" XBL binding is
michael@0 12 * created. This binding overlays plugin content when the plugin is missing,
michael@0 13 * blocked, click-to-play, or replaced by a "preview" extension plugin like
michael@0 14 * Shumway or PDF.js.
michael@0 15 */
michael@0 16 var PluginHelper = {
michael@0 17 init: function () {
michael@0 18 addEventListener("PluginBindingAttached", this, true, true);
michael@0 19 },
michael@0 20
michael@0 21 handleEvent: function handleEvent(aEvent) {
michael@0 22 switch (aEvent.type) {
michael@0 23 case "PluginBindingAttached":
michael@0 24 this.handlePluginBindingAttached(aEvent);
michael@0 25 break;
michael@0 26 }
michael@0 27 },
michael@0 28
michael@0 29 getPluginMimeType: function (plugin) {
michael@0 30 var tagMimetype = plugin.actualType;
michael@0 31
michael@0 32 if (tagMimetype == "") {
michael@0 33 tagMimetype = plugin.type;
michael@0 34 }
michael@0 35 return tagMimetype;
michael@0 36 },
michael@0 37
michael@0 38 handlePluginBindingAttached: function (aEvent) {
michael@0 39 let plugin = aEvent.target;
michael@0 40 let doc = plugin.ownerDocument;
michael@0 41 let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 42 if (!overlay || overlay._bindingHandled) {
michael@0 43 return;
michael@0 44 }
michael@0 45 overlay._bindingHandled = true;
michael@0 46
michael@0 47 let eventType = PluginHelper._getBindingType(plugin);
michael@0 48 if (!eventType) {
michael@0 49 return;
michael@0 50 }
michael@0 51
michael@0 52 switch (eventType) {
michael@0 53 case "PluginPlayPreview": {
michael@0 54 // Load the "preview" handler (an extension plugin like Shumway or PDF.js).
michael@0 55 let previewContent = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent");
michael@0 56 let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
michael@0 57 let mimeType = PluginHelper.getPluginMimeType(plugin);
michael@0 58 let playPreviewInfo = pluginHost.getPlayPreviewInfo(mimeType);
michael@0 59
michael@0 60 let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0];
michael@0 61 if (!iframe) {
michael@0 62 // lazy initialization of the iframe
michael@0 63 iframe = doc.createElementNS("http://www.w3.org/1999/xhtml", "iframe");
michael@0 64 iframe.className = "previewPluginContentFrame";
michael@0 65 previewContent.appendChild(iframe);
michael@0 66 }
michael@0 67 iframe.src = playPreviewInfo.redirectURL;
michael@0 68 break;
michael@0 69 }
michael@0 70
michael@0 71 case "PluginNotFound": {
michael@0 72 // TODO: Display a message about missing plugins (bug 936907)
michael@0 73 break;
michael@0 74 }
michael@0 75 }
michael@0 76 },
michael@0 77
michael@0 78 // Helper to get the binding handler type from a plugin object
michael@0 79 _getBindingType: function(plugin) {
michael@0 80 if (!(plugin instanceof Ci.nsIObjectLoadingContent))
michael@0 81 return null;
michael@0 82
michael@0 83 switch (plugin.pluginFallbackType) {
michael@0 84 case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED:
michael@0 85 return "PluginNotFound";
michael@0 86 case Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW:
michael@0 87 return "PluginPlayPreview";
michael@0 88 default:
michael@0 89 // Metro Firefox does not yet support other fallback types.
michael@0 90 return null;
michael@0 91 }
michael@0 92 },
michael@0 93 };
michael@0 94
michael@0 95 PluginHelper.init();

mercurial