summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 08:34:00 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 08:34:00 +0000
commit55d70673337a2346cb7e203b5934a56e380f0073 (patch)
treea239c8b32b8d5ed2ea1330a6223d7c129b23bae1 /webkit
parenta8c3d9236906ef90b183ed65df9ae848acf3eab5 (diff)
downloadchromium_src-55d70673337a2346cb7e203b5934a56e380f0073.zip
chromium_src-55d70673337a2346cb7e203b5934a56e380f0073.tar.gz
chromium_src-55d70673337a2346cb7e203b5934a56e380f0073.tar.bz2
DevTools: fixes for crashes / bugs while debugging calendar.google.com.
Review URL: http://codereview.chromium.org/60051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/devtools/dom_agent_impl.cc162
-rw-r--r--webkit/glue/devtools/dom_agent_impl.h13
-rw-r--r--webkit/glue/devtools/js/devtools.js65
-rw-r--r--webkit/glue/devtools/js/dom_agent.js6
-rw-r--r--webkit/glue/devtools/js/inspector_controller_impl.js15
-rw-r--r--webkit/glue/devtools/js/net_agent.js11
-rw-r--r--webkit/glue/devtools/net_agent_impl.cc22
7 files changed, 180 insertions, 114 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.cc b/webkit/glue/devtools/dom_agent_impl.cc
index 0e83054..54e4445 100644
--- a/webkit/glue/devtools/dom_agent_impl.cc
+++ b/webkit/glue/devtools/dom_agent_impl.cc
@@ -445,89 +445,36 @@ void DomAgentImpl::GetNodeStyles(int call_id,
int element_id,
bool author_only) {
// TODO (serya): Currently styles are serialized as cssText.
- // It could be not enough.
- String computed_style;
- String inline_style;
- OwnPtr<DictionaryValue> style_attributes(new DictionaryValue());
- OwnPtr<ListValue> matched_css_rules(new ListValue());
+ // It could be not enough.
+
+ DictionaryValue result;
Node* node = GetNodeForId(element_id);
DCHECK(!node || node->nodeType() == Node::ELEMENT_NODE);
- if (node && node->nodeType() == Node::ELEMENT_NODE) {
- Element* element = static_cast<Element*>(node);
- inline_style = element->style()->cssText();
- DOMWindow* window = element->document()->defaultView();
- computed_style = window->getComputedStyle(element, "")->cssText();
- BuildValueForCSSRules(*window->getMatchedCSSRules(element, "",
- author_only), *matched_css_rules);
- BuildValueForAttributeStyles(*element->attributes(),
- *style_attributes);
+ if (!node) {
+ delegate_->DidGetNodeStyles(call_id, result);
+ return;
}
- DictionaryValue styles;
-
- styles.SetString(L"computedStyle",
- webkit_glue::StringToStdString(computed_style));
- styles.SetString(L"inlineStyle",
+ Element* element = static_cast<Element*>(node);
+ String inline_style = element->style()->cssText();
+ result.SetString(L"inlineStyle",
webkit_glue::StringToStdString(inline_style));
- styles.Set(L"styleAttributes", style_attributes.release());
- styles.Set(L"matchedCSSRules", matched_css_rules.release());
-
- delegate_->DidGetNodeStyles(call_id, styles);
-}
-
-void DomAgentImpl::BuildValueForCSSRules(CSSRuleList& matched,
- ListValue& descriptionList) {
- for (unsigned i = 0; i < matched.length(); ++i) {
- if (!matched.item(i)->isStyleRule()) {
- continue;
- }
-
- CSSStyleRule* rule = static_cast<CSSStyleRule*>(matched.item(i));
- String selector_text = rule->selectorText();
- String css_text;
-
- CSSMutableStyleDeclaration* style = rule->style();
- if (style) {
- css_text = style->cssText();
- }
- OwnPtr<DictionaryValue> description(new DictionaryValue());
- description->SetString(L"selector",
- webkit_glue::StringToStdString(selector_text));
- description->SetString(L"cssText",
- webkit_glue::StringToStdString(css_text));
-
- CSSStyleSheet* parent_style_sheet = rule->parentStyleSheet();
- if (parent_style_sheet) {
- description->SetString(L"parentStyleSheetHref",
- webkit_glue::StringToStdString(parent_style_sheet->href()));
-
- Node* owner_node = parent_style_sheet->ownerNode();
- if (owner_node) {
- description->SetString(L"parentStyleSheetOwnerNodeName",
- webkit_glue::StringToStdString(owner_node->nodeName()));
- }
- }
+ DOMWindow* window = element->document()->defaultView();
+ String computed_style = window->getComputedStyle(element, "")->cssText();
+ result.SetString(L"computedStyle",
+ webkit_glue::StringToStdString(computed_style));
- descriptionList.Append(description.release());
+ RefPtr<CSSRuleList> rule_list = window->getMatchedCSSRules(element, "",
+ author_only);
+ if (rule_list) {
+ result.Set(L"matchedCSSRules", BuildValueForCSSRules(*rule_list));
}
-}
+ result.Set(L"styleAttributes",
+ BuildValueForAttributeStyles(*element->attributes()));
-void DomAgentImpl::BuildValueForAttributeStyles(const NamedNodeMap& attributes,
- DictionaryValue& description) {
- for (size_t i = 0; i < attributes.length(); ++i) {
- Attribute* attr = attributes.attributeItem(i);
-
- if (CSSStyleDeclaration* style = attr->style()) {
- std::wstring name =
- webkit_glue::StringToStdWString(attr->name().toString());
- std::string css_text =
- webkit_glue::StringToStdString(style->cssText());
-
- description.SetString(name, css_text);
- }
- }
+ delegate_->DidGetNodeStyles(call_id, result);
}
ListValue* DomAgentImpl::BuildValueForNode(Node* node, int depth) {
@@ -617,24 +564,79 @@ ListValue* DomAgentImpl::BuildValueForElementChildren(
return children.release();
}
+ListValue* DomAgentImpl::BuildValueForCSSRules(CSSRuleList& matched) {
+ OwnPtr<ListValue> description_list(new ListValue());
+ for (unsigned i = 0; i < matched.length(); ++i) {
+ if (!matched.item(i)->isStyleRule()) {
+ continue;
+ }
+ CSSStyleRule* rule = static_cast<CSSStyleRule*>(matched.item(i));
+ OwnPtr<DictionaryValue> description(new DictionaryValue());
+
+ description->SetString(L"selector",
+ webkit_glue::StringToStdString(rule->selectorText()));
+
+ CSSMutableStyleDeclaration* style = rule->style();
+ description->SetString(L"cssText",
+ webkit_glue::StringToStdString(style ? style->cssText() : ""));
+
+ CSSStyleSheet* parent_style_sheet = rule->parentStyleSheet();
+ if (parent_style_sheet) {
+ description->SetString(L"parentStyleSheetHref",
+ webkit_glue::StringToStdString(parent_style_sheet->href()));
+
+ Node* owner_node = parent_style_sheet->ownerNode();
+ if (owner_node) {
+ description->SetString(L"parentStyleSheetOwnerNodeName",
+ webkit_glue::StringToStdString(owner_node->nodeName()));
+ }
+ }
+ description_list->Append(description.release());
+ }
+ return description_list.release();
+}
+
+DictionaryValue* DomAgentImpl::BuildValueForAttributeStyles(
+ const NamedNodeMap& attributes) {
+ OwnPtr<DictionaryValue> description(new DictionaryValue());
+ for (size_t i = 0; i < attributes.length(); ++i) {
+ Attribute* attr = attributes.attributeItem(i);
+
+ if (CSSStyleDeclaration* style = attr->style()) {
+ std::wstring name =
+ webkit_glue::StringToStdWString(attr->name().toString());
+ std::string css_text =
+ webkit_glue::StringToStdString(style->cssText());
+
+ description->SetString(name, css_text);
+ }
+ }
+ return description.release();
+}
+
Node* DomAgentImpl::InnerFirstChild(Node* node) {
if (node->isFrameOwnerElement()) {
HTMLFrameOwnerElement* frame_owner =
static_cast<HTMLFrameOwnerElement*>(node);
Document* doc = frame_owner->contentDocument();
- StartListening(doc);
- return doc->firstChild();
- } else {
- return node->firstChild();
+ if (doc) {
+ StartListening(doc);
+ return doc->firstChild();
+ }
}
+ return node->firstChild();
}
int DomAgentImpl::InnerChildNodeCount(Node* node) {
if (node->isFrameOwnerElement()) {
- return 1;
- } else {
- return node->childNodeCount();
+ HTMLFrameOwnerElement* frame_owner =
+ static_cast<HTMLFrameOwnerElement*>(node);
+ Document* doc = frame_owner->contentDocument();
+ if (doc) {
+ return 1;
+ }
}
+ return node->childNodeCount();
}
Element* DomAgentImpl::InnerParentElement(Node* node) {
diff --git a/webkit/glue/devtools/dom_agent_impl.h b/webkit/glue/devtools/dom_agent_impl.h
index 9fa011c..5a959eb 100644
--- a/webkit/glue/devtools/dom_agent_impl.h
+++ b/webkit/glue/devtools/dom_agent_impl.h
@@ -121,6 +121,13 @@ class DomAgentImpl : public DomAgent {
WebCore::Element* element,
int depth);
+ // Serializes CSS rule list into the list value.
+ ListValue* BuildValueForCSSRules(WebCore::CSSRuleList& matched);
+
+ // Serializes attribute styles into the dictionary value.
+ DictionaryValue* BuildValueForAttributeStyles(
+ const WebCore::NamedNodeMap& attributes);
+
// We represent embedded doms as a part of the same hierarchy. Hence we
// treat children of frame owners differently. Following two methods
// encapsulate frame owner specifics.
@@ -128,12 +135,6 @@ class DomAgentImpl : public DomAgent {
int InnerChildNodeCount(WebCore::Node* node);
WebCore::Element* InnerParentElement(WebCore::Node* node);
- // Helpers for GetNodeStyles
- void BuildValueForCSSRules(WebCore::CSSRuleList& matched,
- ListValue& descriptionList);
- void BuildValueForAttributeStyles(const WebCore::NamedNodeMap& attributes,
- DictionaryValue& description);
-
DomAgentDelegate* delegate_;
HashMap<WebCore::Node*, int> node_to_id_;
HashMap<int, WebCore::Node*> id_to_node_;
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js
index e0be852..1cc682d 100644
--- a/webkit/glue/devtools/js/devtools.js
+++ b/webkit/glue/devtools/js/devtools.js
@@ -181,6 +181,9 @@ var webkitUpdateChildren =
WebInspector.ElementsTreeElement.prototype.updateChildren;
+/**
+ * @override
+ */
WebInspector.ElementsTreeElement.prototype.updateChildren = function() {
var self = this;
devtools.tools.getDomAgent().getChildNodesAsync(this.representedObject,
@@ -190,6 +193,9 @@ WebInspector.ElementsTreeElement.prototype.updateChildren = function() {
};
+/**
+ * @override
+ */
WebInspector.ElementsPanel.prototype.performSearch = function(query) {
this.searchCanceled();
var self = this;
@@ -201,6 +207,9 @@ WebInspector.ElementsPanel.prototype.performSearch = function(query) {
};
+/**
+ * @override
+ */
WebInspector.ElementsPanel.prototype.searchCanceled = function() {
var self = this;
devtools.tools.getDomAgent().searchCanceled(function(node) {
@@ -211,19 +220,31 @@ WebInspector.ElementsPanel.prototype.searchCanceled = function() {
};
+/**
+ * @override
+ */
WebInspector.ElementsPanel.prototype.jumpToNextSearchResult = function() {
};
+/**
+ * @override
+ */
WebInspector.ElementsPanel.prototype.jumpToPreviousSearchResult = function() {
};
+/**
+ * @override
+ */
WebInspector.Console.prototype._evalInInspectedWindow = function(expr) {
return devtools.tools.evaluate(expr);
};
+/**
+ * @override
+ */
WebInspector.ElementsPanel.prototype.updateStyles = function(forceUpdate) {
var stylesSidebarPane = this.sidebarPanes.styles;
if (!stylesSidebarPane.expanded || !stylesSidebarPane.needsUpdate)
@@ -248,6 +269,9 @@ WebInspector.ElementsPanel.prototype.updateStyles = function(forceUpdate) {
};
+/**
+ * @override
+ */
WebInspector.PropertiesSidebarPane.prototype.update = function(object) {
var body = this.bodyElement;
body.removeChildren();
@@ -275,6 +299,9 @@ WebInspector.PropertiesSidebarPane.prototype.update = function(object) {
};
+/**
+ * @override
+ */
WebInspector.ObjectPropertiesSection.prototype.onpopulate = function() {
var nodeId = this.object.id_;
var protoDepth = this.object.protoDepth_;
@@ -288,6 +315,9 @@ WebInspector.ObjectPropertiesSection.prototype.onpopulate = function() {
};
+/**
+ * @override
+ */
WebInspector.ObjectPropertyTreeElement.prototype.onpopulate = function() {
var nodeId = this.parentObject.devtools$$nodeId_;
var path = this.parentObject.devtools$$path_.slice(0);
@@ -301,6 +331,41 @@ WebInspector.ObjectPropertyTreeElement.prototype.onpopulate = function() {
/**
+ * This override is necessary for starting highlighting after the resource
+ * was added into the frame.
+ * @override
+ */
+WebInspector.SourceView.prototype.setupSourceFrameIfNeeded = function() {
+ if (!this._frameNeedsSetup) {
+ return;
+ }
+
+ this.attach();
+
+ var self = this;
+ var identifier = this.resource.identifier;
+ var element = this.sourceFrame.element;
+ var netAgent = devtools.tools.getNetAgent();
+
+ netAgent.getResourceContentAsync(identifier, function(source) {
+ var resource = netAgent.getResource(identifier);
+ if (InspectorController.addSourceToFrame(resource.mimeType, source,
+ element)) {
+ delete self._frameNeedsSetup;
+ if (resource.type === WebInspector.Resource.Type.Script) {
+ self.sourceFrame.addEventListener("syntax highlighting complete",
+ self._syntaxHighlightingComplete, self);
+ self.sourceFrame.syntaxHighlightJavascript();
+ }
+ } else {
+ self._sourceFrameSetupFinished();
+ }
+ });
+ return true;
+};
+
+
+/**
* Dummy object used during properties inspection.
* @see WebInspector.didGetNodePropertiesAsync_
*/
diff --git a/webkit/glue/devtools/js/dom_agent.js b/webkit/glue/devtools/js/dom_agent.js
index eabdff6..12330b2 100644
--- a/webkit/glue/devtools/js/dom_agent.js
+++ b/webkit/glue/devtools/js/dom_agent.js
@@ -836,8 +836,10 @@ devtools.DomAgent.prototype.getNodeStylesAsync = function(node,
devtools.DomAgent.prototype.getNodeStylesCallback_ = function(node,
callback, styles) {
- node.setStyles_(styles.computedStyle, styles.inlineStyle,
- styles.styleAttributes, styles.matchedCSSRules);
+ if (styles.computedStyle) {
+ node.setStyles_(styles.computedStyle, styles.inlineStyle,
+ styles.styleAttributes, styles.matchedCSSRules);
+ }
callback();
diff --git a/webkit/glue/devtools/js/inspector_controller_impl.js b/webkit/glue/devtools/js/inspector_controller_impl.js
index 087ff2d..2e88115 100644
--- a/webkit/glue/devtools/js/inspector_controller_impl.js
+++ b/webkit/glue/devtools/js/inspector_controller_impl.js
@@ -40,21 +40,6 @@ devtools.InspectorControllerImpl.prototype.addSourceToFrame =
/**
* {@inheritDoc}.
*/
-devtools.InspectorControllerImpl.prototype.addResourceSourceToFrame =
- function(identifier, element) {
- var self = this;
- var netAgent = devtools.tools.getNetAgent();
- netAgent.getResourceContentAsync(identifier, function(source) {
- var resource = netAgent.getResource(identifier);
- self.addSourceToFrame(resource.mimeType, source, element);
- });
- return false;
-};
-
-
-/**
- * {@inheritDoc}.
- */
devtools.InspectorControllerImpl.prototype.hideDOMNodeHighlight = function() {
RemoteToolsAgent.HideDOMNodeHighlight();
};
diff --git a/webkit/glue/devtools/js/net_agent.js b/webkit/glue/devtools/js/net_agent.js
index 2e54f58..00b511c 100644
--- a/webkit/glue/devtools/js/net_agent.js
+++ b/webkit/glue/devtools/js/net_agent.js
@@ -102,16 +102,19 @@ devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response)
resource.expectedContentLength = response.expectedContentLength;
resource.responseStatusCode = response.responseStatusCode;
+ resource.responseHeaders = response.responseHeaders;
resource.mimeType = response.mimeType;
resource.suggestedFilename = response.suggestedFilename;
var mimeType = response.mimeType;
- if (mimeType.indexOf("image/") == 0) {
+ if (mimeType.indexOf('image/') == 0) {
resource.type = WebInspector.Resource.Type.Image;
- } else if (mimeType.indexOf("text/html") == 0) {
+ } else if (mimeType.indexOf('text/html') == 0) {
resource.type = WebInspector.Resource.Type.Document;
- } else if (mimeType.indexOf("script") != -1 ||
- response.url.indexOf(".js") != -1) {
+ } else if (mimeType.indexOf('script') != -1 ||
+ resource.url.indexOf('.js') == resource.url.length - 3) {
resource.type = WebInspector.Resource.Type.Script;
+ } else if (mimeType.indexOf('text/css') == 0) {
+ resource.type = WebInspector.Resource.Type.Stylesheet;
} else {
resource.type = WebInspector.Resource.Type.Other;
}
diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc
index d4c1cd7..a34667f 100644
--- a/webkit/glue/devtools/net_agent_impl.cc
+++ b/webkit/glue/devtools/net_agent_impl.cc
@@ -171,32 +171,40 @@ void NetAgentImpl::GetResourceContent(
source = encoding.decode(buffer->data(), buffer->size());
}
} else {
- CachedResource* cachedResource = document_->
+ CachedResource* cached_resource = document_->
docLoader()->cachedResource(url);
- if (!cachedResource->isPurgeable()) {
- // TODO(pfeldman): Try making unpurgeable.
+ if (!cached_resource) {
+ delegate_->GetResourceContentResult(call_id, "");
return;
}
+ if (cached_resource->isPurgeable()) {
+ // If the resource is purgeable then make it unpurgeable to get its data.
+ // This might fail, in which case we return an empty string.
+ if (!cached_resource->makePurgeable(false)) {
+ delegate_->GetResourceContentResult(call_id, "");
+ return;
+ }
+ }
// Try to get the decoded source. Only applies to some CachedResource
// types.
- switch (cachedResource->type()) {
+ switch (cached_resource->type()) {
case CachedResource::CSSStyleSheet: {
CachedCSSStyleSheet *sheet =
- reinterpret_cast<CachedCSSStyleSheet*>(cachedResource);
+ reinterpret_cast<CachedCSSStyleSheet*>(cached_resource);
source = sheet->sheetText();
break;
}
case CachedResource::Script: {
CachedScript *script =
- reinterpret_cast<CachedScript*>(cachedResource);
+ reinterpret_cast<CachedScript*>(cached_resource);
source = script->script();
break;
}
#if ENABLE(XSLT)
case CachedResource::XSLStyleSheet: {
CachedXSLStyleSheet *sheet =
- reinterpret_cast<CachedXSLStyleSheet*>(cachedResource);
+ reinterpret_cast<CachedXSLStyleSheet*>(cached_resource);
source = sheet->sheet();
break;
}