summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webkit/glue/devtools/debugger_agent_impl.cc27
-rw-r--r--webkit/glue/devtools/debugger_agent_impl.h13
-rw-r--r--webkit/glue/devtools/js/devtools.js2
-rw-r--r--webkit/glue/devtools/js/inject.js579
-rw-r--r--webkit/glue/devtools/js/inject_dispatch.js66
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc14
-rw-r--r--webkit/glue/webdevtoolsagent_impl.h2
7 files changed, 361 insertions, 342 deletions
diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc
index b486cdc..f8d99ec 100644
--- a/webkit/glue/devtools/debugger_agent_impl.cc
+++ b/webkit/glue/devtools/debugger_agent_impl.cc
@@ -61,13 +61,13 @@ void DebuggerAgentImpl::DebuggerOutput(const std::string& command) {
webdevtools_agent_->ForceRepaint();
}
-void DebuggerAgentImpl::SetDocument(Document* document) {
- v8::HandleScope scope;
-
- if (!document) {
- context_.Dispose();
- return;
+void DebuggerAgentImpl::CreateUtilityContext(
+ Document* document,
+ v8::Persistent<v8::Context>* context) {
+ if (!context->IsEmpty()) {
+ context->Dispose();
}
+ v8::HandleScope scope;
// TODO(pfeldman): Validate against Soeren.
// Set up the DOM window as the prototype of the new global object.
@@ -91,12 +91,12 @@ void DebuggerAgentImpl::SetDocument(Document* document) {
V8Custom::v8DOMWindowIndexedSecurityCheck,
v8::Integer::New(V8ClassIndex::DOMWINDOW));
- context_ = v8::Context::New(
+ *context = v8::Context::New(
NULL /* no extensions */,
global_template,
v8::Handle<v8::Object>());
- v8::Context::Scope context_scope(context_);
- v8::Handle<v8::Object> global = context_->Global();
+ v8::Context::Scope context_scope(*context);
+ v8::Handle<v8::Object> global = (*context)->Global();
v8::Handle<v8::String> implicit_proto_string = v8::String::New("__proto__");
global->Set(implicit_proto_string, window_wrapper);
@@ -119,15 +119,16 @@ void DebuggerAgentImpl::SetDocument(Document* document) {
}
String DebuggerAgentImpl::ExecuteUtilityFunction(
+ v8::Handle<v8::Context> context,
const String &function_name,
Node* node,
const String& json_args,
String* exception) {
v8::HandleScope scope;
- ASSERT(!context_.IsEmpty());
- v8::Context::Scope context_scope(context_);
+ ASSERT(!context.IsEmpty());
+ v8::Context::Scope context_scope(context);
v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast(
- context_->Global()->Get(v8::String::New("devtools$$dispatch")));
+ context->Global()->Get(v8::String::New("devtools$$dispatch")));
v8::Handle<v8::Value> node_wrapper =
V8Proxy::ToV8Object(V8ClassIndex::NODE, node);
@@ -142,7 +143,7 @@ String DebuggerAgentImpl::ExecuteUtilityFunction(
};
v8::TryCatch try_catch;
- v8::Handle<v8::Value> res_obj = function->Call(context_->Global(), 3, args);
+ v8::Handle<v8::Value> res_obj = function->Call(context->Global(), 3, args);
if (try_catch.HasCaught()) {
*exception = WebCore::ToWebCoreString(try_catch.Message()->Get());
return "";
diff --git a/webkit/glue/devtools/debugger_agent_impl.h b/webkit/glue/devtools/debugger_agent_impl.h
index 5718d83..2f9b2b8 100644
--- a/webkit/glue/devtools/debugger_agent_impl.h
+++ b/webkit/glue/devtools/debugger_agent_impl.h
@@ -28,18 +28,20 @@ class DebuggerAgentImpl : public DebuggerAgent {
WebDevToolsAgentImpl* webdevtools_agent);
virtual ~DebuggerAgentImpl();
- // Initializes dom agent with the given document.
- void SetDocument(WebCore::Document* document);
+ // Creates utility context with injected js agent.
+ void CreateUtilityContext(WebCore::Document* document,
+ v8::Persistent<v8::Context>* context);
// DebuggerAgent implementation.
virtual void DebugBreak();
void DebuggerOutput(const std::string& out);
- // Executes utility function with the given node and json
- // args as parameters. These functions must be implemented in
- // the inject.js file.
+ // Executes function with the given name in the utility context. Passes node
+ // and json args as parameters. Note that the function called must be
+ // implemented in the inject.js file.
WebCore::String ExecuteUtilityFunction(
+ v8::Handle<v8::Context> context,
const WebCore::String& function_name,
WebCore::Node* node,
const WebCore::String& json_args,
@@ -55,7 +57,6 @@ class DebuggerAgentImpl : public DebuggerAgent {
WebViewImpl* web_view() { return web_view_impl_; }
private:
- v8::Persistent<v8::Context> context_;
WebViewImpl* web_view_impl_;
DebuggerAgentDelegate* delegate_;
WebDevToolsAgentImpl* webdevtools_agent_;
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js
index 53581d1..972ca02 100644
--- a/webkit/glue/devtools/js/devtools.js
+++ b/webkit/glue/devtools/js/devtools.js
@@ -289,7 +289,6 @@ WebInspector.ElementsPanel.prototype.updateStyles = function(forceUpdate) {
stylesSidebarPane.needsUpdate = false;
node.clearStyles();
};
-
devtools.tools.getDomAgent().getNodeStylesAsync(
node,
!Preferences.showUserAgentStyles,
@@ -570,6 +569,7 @@ WebInspector.StylePropertyTreeElement.prototype.toggleEnabled =
devtools.tools.getDomAgent().toggleNodeStyleAsync(this.style, !disabled,
this.name,
function() {
+ WebInspector.panels.elements.sidebarPanes.styles.needsUpdate = true;
WebInspector.panels.elements.updateStyles(true);
});
};
diff --git a/webkit/glue/devtools/js/inject.js b/webkit/glue/devtools/js/inject.js
index f19e470..1ef97b0 100644
--- a/webkit/glue/devtools/js/inject.js
+++ b/webkit/glue/devtools/js/inject.js
@@ -1,285 +1,294 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/**
- * @fileoverview Javascript that is being injected into the inspectable page
- * while debugging.
- */
-goog.require('goog.json');
-goog.provide('devtools.Injected');
-
-
-/**
- * Main injected object.
- * @constructor.
- */
-devtools.Injected = function() {
- /**
- * Unique style id generator.
- * @type {number}
- * @private
- */
- this.lastStyleId_ = 1;
-};
-
-
-/**
- * Returns array of properties for a given node on a given path.
- * @param {Node} node Node to get property value for.
- * @param {Array.<string>} path Path to the nested object.
- * @param {number} protoDepth Depth of the actual proto to inspect.
- * @return {Array.<Object>} Array where each property is represented
- * by the tree entries [{string} type, {string} name, {Object} value].
- */
-devtools.Injected.prototype.getProperties = function(node, path, protoDepth) {
- var result = [];
- var obj = node;
-
- // Follow the path.
- for (var i = 0; obj && i < path.length; ++i) {
- obj = obj[path[i]];
- }
-
- if (!obj) {
- return [];
- }
-
- // Get to the necessary proto layer.
- for (var i = 0; obj && i < protoDepth; ++i) {
- obj = obj.__proto__;
- }
-
- if (!obj) {
- return [];
- }
-
- // Go over properties, prepare results.
- for (var name in obj) {
- if (protoDepth != -1 && 'hasOwnProperty' in obj &&
- !obj.hasOwnProperty(name)) {
- continue;
- }
- var type = typeof obj[name];
- result.push(type);
- result.push(name);
- if (type == 'string') {
- var str = obj[name];
- result.push(str.length > 99 ? str.substr(0, 99) + '...' : str);
- } else if (type != 'object' && type != 'array' &&
- type != 'function') {
- result.push(obj[name]);
- } else {
- result.push(undefined);
- }
- }
- return result;
-};
-
-
-/**
- * Returns array of prototypes for a given node.
- * @param {Node} node Node to get prorotypes for.
- * @return {Array<string>} Array of proto names.
- */
-devtools.Injected.prototype.getPrototypes = function(node) {
- var result = [];
- for (var prototype = node; prototype; prototype = prototype.__proto__) {
- var description = Object.prototype.toString.call(prototype);
- result.push(description.replace(/^\[object (.*)\]$/i, '$1'));
- }
- return result;
-};
-
-
-/**
- * Returns style information that is used in devtools.js.
- * @param {Node} node Node to get prorotypes for.
- * @param {boolean} authorOnly Determines whether only author styles need to
- * be added.
- * @return {string} Style collection descriptor.
- */
-devtools.Injected.prototype.getStyles = function(node, authorOnly) {
- if (!node.nodeType == Node.ELEMENT_NODE) {
- return {};
- }
- var matchedRules = window.getMatchedCSSRules(node, '', authorOnly);
- var matchedCSSRulesObj = [];
- for (var i = 0; matchedRules && i < matchedRules.length; ++i) {
- var rule = matchedRules[i];
- var style = this.serializeStyle_(rule.style);
- var ruleValue = {
- 'selector' : rule.selectorText,
- 'style' : style
- };
- if (rule.parentStyleSheet) {
- ruleValue['parentStyleSheet'] = {
- 'href' : rule.parentStyleSheet.href,
- 'ownerNodeName' : rule.parentStyleSheet.ownerNode ?
- rule.parentStyleSheet.ownerNode.name : null
- };
- }
- var parentStyleSheetHref = (rule.parentStyleSheet ?
- rule.parentStyleSheet.href : undefined);
- var parentStyleSheetOwnerNodeName;
- if (rule.parentStyleSheet && rule.parentStyleSheet.ownerNode) {
- parentStyleSheetOwnerNodeName = rule.parentStyleSheet.ownerNode.name;
- }
- matchedCSSRulesObj.push(ruleValue);
- }
-
- var attributeStyles = {};
- var attributes = node.attributes;
- for (var i = 0; attributes && i < attributes.length; ++i) {
- if (attributes[i].style) {
- attributeStyles[attributes[i].name] =
- this.serializeStyle_(attributes[i].style);
- }
- }
-
- var result = {
- 'inlineStyle' : this.serializeStyle_(node.style),
- 'computedStyle' : this.serializeStyle_(
- window.getComputedStyle(node, '')),
- 'matchedCSSRules' : matchedCSSRulesObj,
- 'styleAttributes' : attributeStyles
- };
- return result;
-};
-
-
-/**
- * Returns style decoration object for given id.
- * @param {Node} node Node to get prorotypes for.
- * @param {number} id Style id.
- * @return {Object} Style object.
- * @private
- */
-devtools.Injected.prototype.getStyleForId_ = function(node, id) {
- var matchedRules = window.getMatchedCSSRules(node, '', false);
- for (var i = 0; matchedRules && i < matchedRules.length; ++i) {
- var rule = matchedRules[i];
- if (rule.style.__id == id) {
- return rule.style;
- }
- }
- var attributes = node.attributes;
- for (var i = 0; attributes && i < attributes.length; ++i) {
- if (attributes[i].style && attributes[i].style.__id == id) {
- return attributes[i].style;
- }
- }
- if (node.style.__id == id) {
- return node.style;
- }
- return null;
-};
-
-
-
-
-/**
- * Converts given style into serializable object.
- * @param {CSSStyleDeclaration} style Style to serialize.
- * @return {Array<Object>} Serializable object.
- * @private
- */
-devtools.Injected.prototype.serializeStyle_ = function(style) {
- if (!style) {
- return [];
- }
- if (!style.__id) {
- style.__id = this.lastStyleId_++;
- }
- var result = [
- style.__id,
- style.__disabledProperties,
- style.__disabledPropertyValues,
- style.__disabledPropertyPriorities
- ];
- for (var i = 0; i < style.length; ++i) {
- var name = style[i];
- result.push([
- name,
- style.getPropertyPriority(name),
- style.isPropertyImplicit(name),
- style.getPropertyShorthand(name),
- style.getPropertyValue(name)
- ]);
- }
- return result;
-};
-
-
-/**
- * Toggles style with given id on/off.
- * @param {Node} node Node to get prorotypes for.
- * @param {number} styleId Id of style to toggle.
- * @param {boolean} enabled Determines value to toggle to,
- * @param {string} name Name of the property.
- */
-devtools.Injected.prototype.toggleNodeStyle = function(node, styleId, enabled,
- name) {
- var style = this.getStyleForId_(node, styleId);
- if (!style) {
- return false;
- }
-
- if (!enabled) {
- if (!style.__disabledPropertyValues ||
- !style.__disabledPropertyPriorities) {
- style.__disabledProperties = {};
- style.__disabledPropertyValues = {};
- style.__disabledPropertyPriorities = {};
- }
-
- style.__disabledPropertyValues[name] = style.getPropertyValue(name);
- style.__disabledPropertyPriorities[name] = style.getPropertyPriority(name);
-
- if (style.getPropertyShorthand(name)) {
- var longhandProperties = this.getLonghandProperties_(style, name);
- for (var i = 0; i < longhandProperties.length; ++i) {
- style.__disabledProperties[longhandProperties[i]] = true;
- style.removeProperty(longhandProperties[i]);
- }
- } else {
- style.__disabledProperties[name] = true;
- style.removeProperty(name);
- }
- } else if (style.__disabledProperties &&
- style.__disabledProperties[name]) {
- var value = style.__disabledPropertyValues[name];
- var priority = style.__disabledPropertyPriorities[name];
- style.setProperty(name, value, priority);
-
- delete style.__disabledProperties[name];
- delete style.__disabledPropertyValues[name];
- delete style.__disabledPropertyPriorities[name];
- }
- return true;
-};
-
-
-/**
- * Returns longhand proeprties for a given shorthand one.
- * @param {CSSStyleDeclaration} style Style declaration to use for lookup.
- * @param {string} shorthandProperty Shorthand property to get longhands for.
- * @return {Array.<string>} Array with longhand properties.
- * @private
- */
-devtools.Injected.prototype.getLonghandProperties_ = function(style,
- shorthandProperty) {
- var properties = [];
- var foundProperties = {};
-
- for (var i = 0; i < style.length; ++i) {
- var individualProperty = style[i];
- if (individualProperty in foundProperties ||
- style.getPropertyShorthand(individualProperty) != shorthandProperty) {
- continue;
- }
- foundProperties[individualProperty] = true;
- properties.push(individualProperty);
- }
- return properties;
-};
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview Javascript that is being injected into the inspectable page
+ * while debugging.
+ */
+goog.require('goog.json');
+goog.provide('devtools.Injected');
+
+
+/**
+ * Main injected object.
+ * @constructor.
+ */
+devtools.Injected = function() {
+ /**
+ * Unique style id generator.
+ * @type {number}
+ * @private
+ */
+ this.lastStyleId_ = 1;
+
+ /**
+ * This array is not unused as it may seem. It stores references to the
+ * styles so that they could be found for future editing.
+ * @type {Array<CSSStyleDeclaration>}
+ * @private
+ */
+ this.styles_ = [];
+};
+
+
+/**
+ * Returns array of properties for a given node on a given path.
+ * @param {Node} node Node to get property value for.
+ * @param {Array.<string>} path Path to the nested object.
+ * @param {number} protoDepth Depth of the actual proto to inspect.
+ * @return {Array.<Object>} Array where each property is represented
+ * by the tree entries [{string} type, {string} name, {Object} value].
+ */
+devtools.Injected.prototype.getProperties = function(node, path, protoDepth) {
+ var result = [];
+ var obj = node;
+
+ // Follow the path.
+ for (var i = 0; obj && i < path.length; ++i) {
+ obj = obj[path[i]];
+ }
+
+ if (!obj) {
+ return [];
+ }
+
+ // Get to the necessary proto layer.
+ for (var i = 0; obj && i < protoDepth; ++i) {
+ obj = obj.__proto__;
+ }
+
+ if (!obj) {
+ return [];
+ }
+
+ // Go over properties, prepare results.
+ for (var name in obj) {
+ if (protoDepth != -1 && 'hasOwnProperty' in obj &&
+ !obj.hasOwnProperty(name)) {
+ continue;
+ }
+ var type = typeof obj[name];
+ result.push(type);
+ result.push(name);
+ if (type == 'string') {
+ var str = obj[name];
+ result.push(str.length > 99 ? str.substr(0, 99) + '...' : str);
+ } else if (type != 'object' && type != 'array' &&
+ type != 'function') {
+ result.push(obj[name]);
+ } else {
+ result.push(undefined);
+ }
+ }
+ return result;
+};
+
+
+/**
+ * Returns array of prototypes for a given node.
+ * @param {Node} node Node to get prorotypes for.
+ * @return {Array<string>} Array of proto names.
+ */
+devtools.Injected.prototype.getPrototypes = function(node) {
+ var result = [];
+ for (var prototype = node; prototype; prototype = prototype.__proto__) {
+ var description = Object.prototype.toString.call(prototype);
+ result.push(description.replace(/^\[object (.*)\]$/i, '$1'));
+ }
+ return result;
+};
+
+
+/**
+ * Returns style information that is used in devtools.js.
+ * @param {Node} node Node to get prorotypes for.
+ * @param {boolean} authorOnly Determines whether only author styles need to
+ * be added.
+ * @return {string} Style collection descriptor.
+ */
+devtools.Injected.prototype.getStyles = function(node, authorOnly) {
+ if (!node.nodeType == Node.ELEMENT_NODE) {
+ return {};
+ }
+ var matchedRules = window.getMatchedCSSRules(node, '', authorOnly);
+ var matchedCSSRulesObj = [];
+ for (var i = 0; matchedRules && i < matchedRules.length; ++i) {
+ var rule = matchedRules[i];
+ var style = this.serializeStyle_(rule.style);
+ var ruleValue = {
+ 'selector' : rule.selectorText,
+ 'style' : style
+ };
+ if (rule.parentStyleSheet) {
+ ruleValue['parentStyleSheet'] = {
+ 'href' : rule.parentStyleSheet.href,
+ 'ownerNodeName' : rule.parentStyleSheet.ownerNode ?
+ rule.parentStyleSheet.ownerNode.name : null
+ };
+ }
+ var parentStyleSheetHref = (rule.parentStyleSheet ?
+ rule.parentStyleSheet.href : undefined);
+ var parentStyleSheetOwnerNodeName;
+ if (rule.parentStyleSheet && rule.parentStyleSheet.ownerNode) {
+ parentStyleSheetOwnerNodeName = rule.parentStyleSheet.ownerNode.name;
+ }
+ matchedCSSRulesObj.push(ruleValue);
+ }
+
+ var attributeStyles = {};
+ var attributes = node.attributes;
+ for (var i = 0; attributes && i < attributes.length; ++i) {
+ if (attributes[i].style) {
+ attributeStyles[attributes[i].name] =
+ this.serializeStyle_(attributes[i].style);
+ }
+ }
+
+ var result = {
+ 'inlineStyle' : this.serializeStyle_(node.style),
+ 'computedStyle' : this.serializeStyle_(
+ window.getComputedStyle(node, '')),
+ 'matchedCSSRules' : matchedCSSRulesObj,
+ 'styleAttributes' : attributeStyles
+ };
+ return result;
+};
+
+
+/**
+ * Returns style decoration object for given id.
+ * @param {Node} node Node to get prorotypes for.
+ * @param {number} id Style id.
+ * @return {Object} Style object.
+ * @private
+ */
+devtools.Injected.prototype.getStyleForId_ = function(node, id) {
+ var matchedRules = window.getMatchedCSSRules(node, '', false);
+ for (var i = 0; matchedRules && i < matchedRules.length; ++i) {
+ var rule = matchedRules[i];
+ if (rule.style.__id == id) {
+ return rule.style;
+ }
+ }
+ var attributes = node.attributes;
+ for (var i = 0; attributes && i < attributes.length; ++i) {
+ if (attributes[i].style && attributes[i].style.__id == id) {
+ return attributes[i].style;
+ }
+ }
+ if (node.style.__id == id) {
+ return node.style;
+ }
+ return null;
+};
+
+
+
+
+/**
+ * Converts given style into serializable object.
+ * @param {CSSStyleDeclaration} style Style to serialize.
+ * @return {Array<Object>} Serializable object.
+ * @private
+ */
+devtools.Injected.prototype.serializeStyle_ = function(style) {
+ if (!style) {
+ return [];
+ }
+ if (!style.__id) {
+ style.__id = this.lastStyleId_++;
+ this.styles_.push(style);
+ }
+ var result = [
+ style.__id,
+ style.__disabledProperties,
+ style.__disabledPropertyValues,
+ style.__disabledPropertyPriorities
+ ];
+ for (var i = 0; i < style.length; ++i) {
+ var name = style[i];
+ result.push([
+ name,
+ style.getPropertyPriority(name),
+ style.isPropertyImplicit(name),
+ style.getPropertyShorthand(name),
+ style.getPropertyValue(name)
+ ]);
+ }
+ return result;
+};
+
+
+/**
+ * Toggles style with given id on/off.
+ * @param {Node} node Node to get prorotypes for.
+ * @param {number} styleId Id of style to toggle.
+ * @param {boolean} enabled Determines value to toggle to,
+ * @param {string} name Name of the property.
+ */
+devtools.Injected.prototype.toggleNodeStyle = function(node, styleId, enabled,
+ name) {
+ var style = this.getStyleForId_(node, styleId);
+ if (!style) {
+ return false;
+ }
+
+ if (!enabled) {
+ if (!style.__disabledPropertyValues ||
+ !style.__disabledPropertyPriorities) {
+ style.__disabledProperties = {};
+ style.__disabledPropertyValues = {};
+ style.__disabledPropertyPriorities = {};
+ }
+
+ style.__disabledPropertyValues[name] = style.getPropertyValue(name);
+ style.__disabledPropertyPriorities[name] = style.getPropertyPriority(name);
+
+ if (style.getPropertyShorthand(name)) {
+ var longhandProperties = this.getLonghandProperties_(style, name);
+ for (var i = 0; i < longhandProperties.length; ++i) {
+ style.__disabledProperties[longhandProperties[i]] = true;
+ style.removeProperty(longhandProperties[i]);
+ }
+ } else {
+ style.__disabledProperties[name] = true;
+ style.removeProperty(name);
+ }
+ } else if (style.__disabledProperties &&
+ style.__disabledProperties[name]) {
+ var value = style.__disabledPropertyValues[name];
+ var priority = style.__disabledPropertyPriorities[name];
+ style.setProperty(name, value, priority);
+
+ delete style.__disabledProperties[name];
+ delete style.__disabledPropertyValues[name];
+ delete style.__disabledPropertyPriorities[name];
+ }
+ return true;
+};
+
+
+/**
+ * Returns longhand proeprties for a given shorthand one.
+ * @param {CSSStyleDeclaration} style Style declaration to use for lookup.
+ * @param {string} shorthandProperty Shorthand property to get longhands for.
+ * @return {Array.<string>} Array with longhand properties.
+ * @private
+ */
+devtools.Injected.prototype.getLonghandProperties_ = function(style,
+ shorthandProperty) {
+ var properties = [];
+ var foundProperties = {};
+
+ for (var i = 0; i < style.length; ++i) {
+ var individualProperty = style[i];
+ if (individualProperty in foundProperties ||
+ style.getPropertyShorthand(individualProperty) != shorthandProperty) {
+ continue;
+ }
+ foundProperties[individualProperty] = true;
+ properties.push(individualProperty);
+ }
+ return properties;
+};
diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js
index 0b5df80..c9a7a24 100644
--- a/webkit/glue/devtools/js/inject_dispatch.js
+++ b/webkit/glue/devtools/js/inject_dispatch.js
@@ -1,33 +1,33 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/**
- * @fileoverview Injects 'injected' object into the inspectable page.
- */
-
-/**
- * Dispatches host calls into the injected function calls.
- */
-goog.require('devtools.Injected');
-
-
-/**
- * Injected singleton.
- */
-var devtools$$obj = new devtools.Injected();
-
-
-/**
- * Main dispatch method, all calls from the host go through this one.
- * @param {string} functionName Function to call
- * @param {Node} node Node context of the call.
- * @param {string} json_args JSON-serialized call parameters.
- * @return {string} JSON-serialized result of the dispatched call.
- */
-function devtools$$dispatch(functionName, node, json_args) {
- var params = goog.json.parse(json_args);
- params.splice(0, 0, node);
- var result = devtools$$obj[functionName].apply(devtools$$obj, params);
- return goog.json.serialize(result);
-};
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview Injects 'injected' object into the inspectable page.
+ */
+
+/**
+ * Dispatches host calls into the injected function calls.
+ */
+goog.require('devtools.Injected');
+
+
+/**
+ * Injected singleton.
+ */
+var devtools$$obj = new devtools.Injected();
+
+
+/**
+ * Main dispatch method, all calls from the host go through this one.
+ * @param {string} functionName Function to call
+ * @param {Node} node Node context of the call.
+ * @param {string} json_args JSON-serialized call parameters.
+ * @return {string} JSON-serialized result of the dispatched call.
+ */
+function devtools$$dispatch(functionName, node, json_args) {
+ var params = goog.json.parse(json_args);
+ params.splice(0, 0, node);
+ var result = devtools$$obj[functionName].apply(devtools$$obj, params);
+ return goog.json.serialize(result);
+};
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 6faba5b..49f457b 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -56,6 +56,9 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl(
}
WebDevToolsAgentImpl::~WebDevToolsAgentImpl() {
+ if (!utility_context_.IsEmpty()) {
+ utility_context_.Dispose();
+ }
}
void WebDevToolsAgentImpl::Attach() {
@@ -73,7 +76,10 @@ void WebDevToolsAgentImpl::Attach() {
Page* page = web_view_impl_->page();
Document* doc = page->mainFrame()->document();
if (doc) {
- debugger_agent_impl_->SetDocument(doc);
+ // Reuse existing context in case detached/attached.
+ if (utility_context_.IsEmpty()) {
+ debugger_agent_impl_->CreateUtilityContext(doc, &utility_context_);
+ }
dom_agent_impl_->SetDocument(doc);
net_agent_impl_->SetDocument(doc);
}
@@ -110,7 +116,7 @@ void WebDevToolsAgentImpl::SetMainFrameDocumentReady(bool ready) {
} else {
doc = NULL;
}
- debugger_agent_impl_->SetDocument(doc);
+ debugger_agent_impl_->CreateUtilityContext(doc, &utility_context_);
dom_agent_impl_->SetDocument(doc);
net_agent_impl_->SetDocument(doc);
}
@@ -197,8 +203,8 @@ void WebDevToolsAgentImpl::ExecuteUtilityFunction(
String result;
String exception;
if (node) {
- result = debugger_agent_impl_->ExecuteUtilityFunction(function_name, node,
- json_args, &exception);
+ result = debugger_agent_impl_->ExecuteUtilityFunction(utility_context_,
+ function_name, node, json_args, &exception);
}
tools_agent_delegate_stub_->DidExecuteUtilityFunction(call_id,
result, exception);
diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h
index a966e28..b6ade47 100644
--- a/webkit/glue/webdevtoolsagent_impl.h
+++ b/webkit/glue/webdevtoolsagent_impl.h
@@ -10,6 +10,7 @@
#include <wtf/OwnPtr.h>
#include <wtf/Vector.h>
+#include "v8.h"
#include "webkit/glue/devtools/devtools_rpc.h"
#include "webkit/glue/devtools/dom_agent.h"
#include "webkit/glue/devtools/net_agent.h"
@@ -110,6 +111,7 @@ class WebDevToolsAgentImpl
OwnPtr<NetAgentImpl> net_agent_impl_;
Vector<ConsoleMessage> console_log_;
bool attached_;
+ v8::Persistent<v8::Context> utility_context_;
DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentImpl);
};