diff --git a/data/mofo_logo.SVG b/data/mofo_logo.SVG new file mode 100644 index 000000000..0c84f07f5 --- /dev/null +++ b/data/mofo_logo.SVG @@ -0,0 +1,49 @@ + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/sdk/widget.js b/lib/sdk/widget.js index f1236aa54..56bb22d11 100644 --- a/lib/sdk/widget.js +++ b/lib/sdk/widget.js @@ -573,32 +573,31 @@ function BrowserWindow(window) { } BrowserWindow.prototype = { - // Adds an array of items to the window. addItems: function BW_addItems(items) { items.forEach(this._addItemToWindow, this); }, - + _addItemToWindow: function BW__addItemToWindow(baseWidget) { // Create a WidgetView instance let widget = baseWidget._createView(); - + // Create a WidgetChrome instance let item = new WidgetChrome({ widget: widget, doc: this.doc, window: this.window }); - + widget._chrome = item; - + this._insertNodeInToolbar(item.node); - + // We need to insert Widget DOM Node before finishing widget view creation // (because fill creates an iframe and tries to access its docShell) item.fill(); }, - + _insertNodeInToolbar: function BW__insertNodeInToolbar(node) { // Add to the customization palette let toolbox = this.doc.getElementById("navigator-toolbox"); @@ -762,7 +761,7 @@ WidgetChrome.prototype.fill = function WC_fill() { WidgetChrome.prototype.getContentType = function WC_getContentType() { if (this._widget.content) return CONTENT_TYPE_HTML; - return (this._widget.contentURL && /\.(jpg|gif|png|ico)$/.test(this._widget.contentURL)) + return (this._widget.contentURL && /\.(jpg|gif|png|ico|svg)$/i.test(this._widget.contentURL)) ? CONTENT_TYPE_IMAGE : CONTENT_TYPE_URI; } @@ -826,7 +825,7 @@ WidgetChrome.prototype.setContent = function WC_setContent() { // Detect if document consists of a single image. WidgetChrome._isImageDoc = function WC__isImageDoc(doc) { - return doc.body.childNodes.length == 1 && + return /*doc.body &&*/ doc.body.childNodes.length == 1 && doc.body.firstElementChild && doc.body.firstElementChild.tagName == "IMG"; } @@ -875,8 +874,9 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() { // We may have had an unload event before that cleaned up the symbiont if (!self._symbiont) self.setContent(); - + let doc = e.target; + if (contentType == CONTENT_TYPE_IMAGE || WidgetChrome._isImageDoc(doc)) { // Force image content to size. // Add-on authors must size their images correctly. @@ -893,9 +893,10 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() { // Allow all content to fill the box by default. doc.body.style.margin = "0"; } + iframe.addEventListener("load", loadListener, true); this.eventListeners["load"] = loadListener; - + // Register a listener to unload symbiont if the toolbaritem is moved // on user toolbars customization function unloadListener(e) { @@ -910,7 +911,7 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() { } catch(e) {} } - + iframe.addEventListener("unload", unloadListener, true); this.eventListeners["unload"] = unloadListener; } diff --git a/test/test-panel.js b/test/test-panel.js index 0659af504..2b9d3b7e3 100644 --- a/test/test-panel.js +++ b/test/test-panel.js @@ -5,6 +5,7 @@ let { Cc, Ci } = require("chrome"); const { Loader } = require('sdk/test/loader'); const timer = require("sdk/timers"); +const self = require('self'); exports["test Panel"] = function(assert, done) { const { Panel } = require('sdk/panel'); @@ -453,6 +454,20 @@ exports["test Content URL Option"] = function(assert) { "Panel throws an exception if contentURL is not a URL."); }; +exports.testSVGDocument = function(assert) { + let SVG_URL = self.data.url("mofo_logo.SVG"); + + let panel = require("sdk/panel").Panel({ contentURL: SVG_URL }); + + panel.show(); + panel.hide(); + panel.destroy(); + + assert.pass("contentURL accepts a svg document"); + assert.equal(panel.contentURL, SVG_URL, + "contentURL is the string to which it was set."); +}; + exports["test ContentScriptOptions Option"] = function(assert, done) { let loader = Loader(module); let panel = loader.require("sdk/panel").Panel({ diff --git a/test/test-widget.js b/test/test-widget.js index 6f08430e5..5dce2a723 100644 --- a/test/test-widget.js +++ b/test/test-widget.js @@ -8,6 +8,7 @@ const { Cc, Ci } = require("chrome"); const { Loader } = require('sdk/test/loader'); const url = require("sdk/url"); const timer = require("sdk/timers"); +const self = require("self"); const windowUtils = require("sdk/deprecated/window-utils"); exports.testConstructor = function(test) { @@ -1029,6 +1030,26 @@ exports.testPostMessageOnLocationChange = function(test) { }); }; +exports.testSVGWidget = function(test) { + test.waitUntilDone(); + + // use of capital SVG here is intended, that was failing.. + let SVG_URL = self.data.url("mofo_logo.SVG"); + + let widget = require("widget").Widget({ + id: "mozilla-svg-logo", + label: "moz foundation logo", + contentURL: SVG_URL, + contentScript: "self.postMessage({count: window.document.images.length, src: window.document.images[0].src});", + onMessage: function(data) { + widget.destroy(); + test.assertEqual(data.count, 1, 'only one image'); + test.assertEqual(data.src, SVG_URL, 'only one image'); + test.done(); + } + }); +}; + exports.testNavigationBarWidgets = function testNavigationBarWidgets(test) { test.waitUntilDone();