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