Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Bug 810658: Using a svg image for the contentURL of a widget dnw #655

Merged
merged 4 commits into from Dec 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions data/mofo_logo.SVG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 13 additions & 12 deletions lib/sdk/widget.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -910,7 +911,7 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() {
} catch(e) {}

}

iframe.addEventListener("unload", unloadListener, true);
this.eventListeners["unload"] = unloadListener;
}
Expand Down