WebInspector.ExtensionView = function(id, parent, src, className)
{
WebInspector.View.call(this);
this._id = id;
this._iframe = document.createElement("iframe");
this._iframe.addEventListener("load", this._onLoad.bind(this), false);
this._iframe.src = src;
this._iframe.className = className;
this.element.appendChild(this._iframe);
this.show(parent);
}
WebInspector.ExtensionView.prototype = {
wasShown: function()
{
if (typeof this._frameIndex === "number")
WebInspector.extensionServer.notifyViewShown(this._id, this._frameIndex);
},
willHide: function()
{
if (typeof this._frameIndex === "number")
WebInspector.extensionServer.notifyViewHidden(this._id);
},
_onLoad: function()
{
this._frameIndex = Array.prototype.indexOf.call(window.frames, this._iframe.contentWindow);
if (this.isShowing())
WebInspector.extensionServer.notifyViewShown(this._id, this._frameIndex);
}
}
WebInspector.ExtensionView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.ExtensionNotifierView = function(id)
{
WebInspector.View.call(this);
this._id = id;
}
WebInspector.ExtensionNotifierView.prototype = {
wasShown: function()
{
WebInspector.extensionServer.notifyViewShown(this._id);
},
willHide: function()
{
WebInspector.extensionServer.notifyViewHidden(this._id);
}
}
WebInspector.ExtensionNotifierView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.ExtensionPanel = function(id, label, pageURL, iconURL)
{
WebInspector.Panel.call(this, id);
this.setHideOnDetach();
this._toolbarItemLabel = label;
this._statusBarItems = [];
if (iconURL) {
this._addStyleRule(".toolbar-item." + id + " .toolbar-icon", "background-image: url(" + iconURL + ");");
this._addStyleRule(".toolbar-small .toolbar-item." + id + " .toolbar-icon", "background-position-x: -32px;");
}
new WebInspector.ExtensionView(id, this.element, pageURL, "extension panel");
}
WebInspector.ExtensionPanel.prototype = {
get toolbarItemLabel()
{
return this._toolbarItemLabel;
},
defaultFocusedElement: function()
{
return this.sidebarTreeElement || this.element;
},
get statusBarItems()
{
return this._statusBarItems;
},
addStatusBarItem: function(element)
{
this._statusBarItems.push(element);
},
searchCanceled: function(startingNewSearch)
{
WebInspector.extensionServer.notifySearchAction(this._id, "cancelSearch");
WebInspector.Panel.prototype.searchCanceled.apply(this, arguments);
},
performSearch: function(query)
{
WebInspector.extensionServer.notifySearchAction(this._id, "performSearch", query);
WebInspector.Panel.prototype.performSearch.apply(this, arguments);
},
jumpToNextSearchResult: function()
{
WebInspector.extensionServer.notifySearchAction(this._id, "nextSearchResult");
WebInspector.Panel.prototype.jumpToNextSearchResult.call(this);
},
jumpToPreviousSearchResult: function()
{
WebInspector.extensionServer.notifySearchAction(this._id, "previousSearchResult");
WebInspector.Panel.prototype.jumpToPreviousSearchResult.call(this);
},
_addStyleRule: function(selector, body)
{
var style = document.createElement("style");
style.textContent = selector + " { " + body + " }";
document.head.appendChild(style);
}
}
WebInspector.ExtensionPanel.prototype.__proto__ = WebInspector.Panel.prototype;
WebInspector.ExtensionButton = function(id, iconURL, tooltip, disabled)
{
this._id = id;
this.element = document.createElement("button");
this.element.className = "status-bar-item extension";
this.element.addEventListener("click", this._onClicked.bind(this), false);
this.update(iconURL, tooltip, disabled);
}
WebInspector.ExtensionButton.prototype = {
update: function(iconURL, tooltip, disabled)
{
if (typeof iconURL === "string")
this.element.style.backgroundImage = "url(" + iconURL + ")";
if (typeof tooltip === "string")
this.element.title = tooltip;
if (typeof disabled === "boolean")
this.element.disabled = disabled;
},
_onClicked: function()
{
WebInspector.extensionServer.notifyButtonClicked(this._id);
}
}
WebInspector.ExtensionSidebarPane = function(title, id)
{
WebInspector.SidebarPane.call(this, title);
this._id = id;
}
WebInspector.ExtensionSidebarPane.prototype = {
setObject: function(object, title, callback)
{
this._createObjectPropertiesView();
this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title, callback);
},
setExpression: function(expression, title, callback)
{
this._createObjectPropertiesView();
RuntimeAgent.evaluate(expression, "extension-watch", true, undefined, undefined, undefined, this._onEvaluate.bind(this, title, callback));
},
setPage: function(url)
{
if (this._objectPropertiesView) {
this._objectPropertiesView.detach();
delete this._objectPropertiesView;
}
if (this._extensionView)
this._extensionView.detach(true);
this._extensionView = new WebInspector.ExtensionView(this._id, this.bodyElement, url, "extension");
},
setHeight: function(height)
{
this.bodyElement.style.height = height;
},
_onEvaluate: function(title, callback, error, result, wasThrown)
{
if (error)
callback(error.toString());
else
this._setObject(WebInspector.RemoteObject.fromPayload(result), title, callback);
},
_createObjectPropertiesView: function()
{
if (this._objectPropertiesView)
return;
if (this._extensionView) {
this._extensionView.detach(true);
delete this._extensionView;
}
this._objectPropertiesView = new WebInspector.ExtensionNotifierView(this._id);
this._objectPropertiesView.show(this.bodyElement);
},
_setObject: function(object, title, callback)
{
if (!this._objectPropertiesView) {
callback("operation cancelled");
return;
}
this._objectPropertiesView.element.removeChildren();
var section = new WebInspector.ObjectPropertiesSection(object, title);
if (!title)
section.headerElement.addStyleClass("hidden");
section.expanded = true;
section.editable = false;
this._objectPropertiesView.element.appendChild(section.element);
callback();
}
}
WebInspector.ExtensionSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;