summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 09:53:27 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 09:53:27 +0000
commitb004209b94e258e9ca5a2356e4bd108f8443e142 (patch)
tree5f0170dfafbaa7b3a7e0fc48e502396e6e09004e /webkit/glue
parentbc296f37929b762850ce2c3b317f8542bdace2a1 (diff)
downloadchromium_src-b004209b94e258e9ca5a2356e4bd108f8443e142.zip
chromium_src-b004209b94e258e9ca5a2356e4bd108f8443e142.tar.gz
chromium_src-b004209b94e258e9ca5a2356e4bd108f8443e142.tar.bz2
DevTools: Migrate to InspectorController for network and console events.
- introduced bound object on the agent side; - established remote dispatch of WebInspector calls - using fake InspectorFrontend for serializing events and sending them over the ipc - removed net agents from both sides - moved GetResource stuff to tools agent Assumes following is landed: https://bugs.webkit.org/show_bug.cgi?id=26010 Review URL: http://codereview.chromium.org/113836 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/chrome_client_impl.cc7
-rw-r--r--webkit/glue/devtools/bound_object.cc61
-rw-r--r--webkit/glue/devtools/bound_object.h31
-rw-r--r--webkit/glue/devtools/js/devtools.html1
-rw-r--r--webkit/glue/devtools/js/devtools.js80
-rw-r--r--webkit/glue/devtools/js/devtools_host_stub.js8
-rw-r--r--webkit/glue/devtools/js/dom_agent.js35
-rw-r--r--webkit/glue/devtools/js/inject_dispatch.js16
-rw-r--r--webkit/glue/devtools/js/net_agent.js126
-rw-r--r--webkit/glue/devtools/net_agent.h39
-rw-r--r--webkit/glue/devtools/net_agent_impl.cc325
-rw-r--r--webkit/glue/devtools/net_agent_impl.h143
-rw-r--r--webkit/glue/devtools/tools_agent.h12
-rw-r--r--webkit/glue/inspector_client_impl.cc12
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc111
-rw-r--r--webkit/glue/webdevtoolsagent_impl.h35
-rw-r--r--webkit/glue/webdevtoolsclient_impl.cc61
-rw-r--r--webkit/glue/webdevtoolsclient_impl.h8
-rw-r--r--webkit/glue/webframeloaderclient_impl.cc54
-rw-r--r--webkit/glue/webframeloaderclient_impl.h4
-rw-r--r--webkit/glue/webview_impl.cc4
21 files changed, 291 insertions, 882 deletions
diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc
index ae74e3c..6e8b817 100644
--- a/webkit/glue/chrome_client_impl.cc
+++ b/webkit/glue/chrome_client_impl.cc
@@ -34,11 +34,11 @@ MSVC_POP_WARNING();
#include "webkit/glue/chrome_client_impl.h"
#include "base/gfx/rect.h"
+#include "base/logging.h"
#include "googleurl/src/gurl.h"
#include "webkit/api/public/WebInputEvent.h"
#include "webkit/api/public/WebKit.h"
#include "webkit/glue/glue_util.h"
-#include "webkit/glue/webdevtoolsagent_impl.h"
#include "webkit/glue/webframe_impl.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/weburlrequest_impl.h"
@@ -318,11 +318,6 @@ void ChromeClientImpl::addMessageToConsole(WebCore::MessageSource source,
delegate->AddMessageToConsole(webview_, wstr_message,
line_no, wstr_source_id);
}
- WebDevToolsAgentImpl* devtools_agent = webview_->GetWebDevToolsAgentImpl();
- if (devtools_agent) {
- devtools_agent->AddMessageToConsole(source, level, message, line_no,
- source_id);
- }
}
bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel() {
diff --git a/webkit/glue/devtools/bound_object.cc b/webkit/glue/devtools/bound_object.cc
new file mode 100644
index 0000000..e786b7fb
--- /dev/null
+++ b/webkit/glue/devtools/bound_object.cc
@@ -0,0 +1,61 @@
+// 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.
+
+#include "config.h"
+
+#include <string>
+
+#include "v8_proxy.h"
+#include "webkit/glue/devtools/bound_object.h"
+
+using namespace WebCore;
+
+BoundObject::BoundObject(
+ v8::Handle<v8::Context> context,
+ void* v8_this,
+ const char* object_name)
+ : context_(context),
+ object_name_(object_name) {
+ v8::HandleScope scope;
+ v8::Context::Scope context_scope(context);
+ v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(v8_this));
+
+ v8::Local<v8::FunctionTemplate> local_template =
+ v8::FunctionTemplate::New(V8Proxy::CheckNewLegal);
+ host_template_ = v8::Persistent<v8::FunctionTemplate>::New(local_template);
+ host_template_->SetClassName(v8::String::New(object_name));
+}
+
+BoundObject::~BoundObject() {
+ bound_object_.Dispose();
+ host_template_.Dispose();
+ v8_this_.Dispose();
+}
+
+void BoundObject::AddProtoFunction(
+ const char* name,
+ v8::InvocationCallback callback) {
+ v8::HandleScope scope;
+ v8::Local<v8::Signature> signature = v8::Signature::New(host_template_);
+ v8::Local<v8::ObjectTemplate> proto = host_template_->PrototypeTemplate();
+ proto->Set(
+ v8::String::New(name),
+ v8::FunctionTemplate::New(
+ callback,
+ v8_this_,
+ signature),
+ static_cast<v8::PropertyAttribute>(v8::DontDelete));
+}
+
+void BoundObject::Build() {
+ v8::HandleScope scope;
+ v8::Context::Scope frame_scope(context_);
+
+ v8::Local<v8::Function> constructor = host_template_->GetFunction();
+ bound_object_ = v8::Persistent<v8::Object>::New(
+ SafeAllocation::NewInstance(constructor));
+
+ v8::Handle<v8::Object> global = context_->Global();
+ global->Set(v8::String::New(object_name_), bound_object_);
+}
diff --git a/webkit/glue/devtools/bound_object.h b/webkit/glue/devtools/bound_object.h
new file mode 100644
index 0000000..9aa8757
--- /dev/null
+++ b/webkit/glue/devtools/bound_object.h
@@ -0,0 +1,31 @@
+// 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.
+
+#ifndef WEBKIT_GLUE_DEVTOOLS_BOUND_OBJECT_H_
+#define WEBKIT_GLUE_DEVTOOLS_BOUND_OBJECT_H_
+
+#include "v8.h"
+
+// BoundObject lets you map JavaScript method calls and property accesses
+// directly to C++ method calls and V8 variable access.
+class BoundObject {
+ public:
+ BoundObject(v8::Handle<v8::Context> context,
+ void* v8_this,
+ const char* object_name);
+ virtual ~BoundObject();
+
+ void AddProtoFunction(const char* name, v8::InvocationCallback callback);
+ void Build();
+
+ private:
+ const char* object_name_;
+ v8::Handle<v8::Context> context_;
+ v8::Persistent<v8::FunctionTemplate> host_template_;
+ v8::Persistent<v8::External> v8_this_;
+ v8::Persistent<v8::Object> bound_object_;
+ DISALLOW_COPY_AND_ASSIGN(BoundObject);
+};
+
+#endif // WEBKIT_GLUE_DEVTOOLS_BOUND_OBJECT_H_
diff --git a/webkit/glue/devtools/js/devtools.html b/webkit/glue/devtools/js/devtools.html
index 5fd2c60..d01eb39 100644
--- a/webkit/glue/devtools/js/devtools.html
+++ b/webkit/glue/devtools/js/devtools.html
@@ -50,7 +50,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script type="text/javascript" src="devtools_callback.js"></script>
<script type="text/javascript" src="debugger_agent.js"></script>
<script type="text/javascript" src="dom_agent.js"></script>
- <script type="text/javascript" src="net_agent.js"></script>
<script type="text/javascript" src="inspector_controller.js"></script>
<script type="text/javascript" src="inspector_controller_impl.js"></script>
<script type="text/javascript" src="inspector.js"></script>
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js
index 3b2a6e1..e4096d9 100644
--- a/webkit/glue/devtools/js/devtools.js
+++ b/webkit/glue/devtools/js/devtools.js
@@ -11,7 +11,6 @@ goog.provide('devtools.Tools');
goog.require('devtools.DebuggerAgent');
goog.require('devtools.DomAgent');
-goog.require('devtools.NetAgent');
/**
@@ -41,14 +40,17 @@ devtools.ToolsAgent = function() {
RemoteToolsAgent.DidExecuteUtilityFunction =
devtools.Callback.processCallback;
RemoteToolsAgent.UpdateFocusedNode =
- goog.bind(this.updateFocusedNode, this);
+ goog.bind(this.updateFocusedNode_, this);
RemoteToolsAgent.FrameNavigate =
- goog.bind(this.frameNavigate, this);
+ goog.bind(this.frameNavigate_, this);
RemoteToolsAgent.AddMessageToConsole =
- goog.bind(this.addMessageToConsole, this);
+ goog.bind(this.addMessageToConsole_, this);
+ RemoteToolsAgent.DispatchOnClient =
+ goog.bind(this.dispatchOnClient_, this);
+ RemoteToolsAgent.DidGetResourceContent =
+ devtools.Callback.processCallback;
this.debuggerAgent_ = new devtools.DebuggerAgent();
this.domAgent_ = new devtools.DomAgent();
- this.netAgent_ = new devtools.NetAgent();
};
@@ -57,7 +59,6 @@ devtools.ToolsAgent = function() {
*/
devtools.ToolsAgent.prototype.reset = function() {
this.domAgent_.reset();
- this.netAgent_.reset();
this.debuggerAgent_.reset();
this.domAgent_.getDocumentElementAsync();
@@ -93,18 +94,10 @@ devtools.ToolsAgent.prototype.getDomAgent = function() {
/**
- * NetAgent accessor.
- * @return {devtools.NetAgent} Net agent instance.
- */
-devtools.ToolsAgent.prototype.getNetAgent = function() {
- return this.netAgent_;
-};
-
-
-/**
* @see tools_agent.h
+ * @private
*/
-devtools.ToolsAgent.prototype.updateFocusedNode = function(nodeId) {
+devtools.ToolsAgent.prototype.updateFocusedNode_ = function(nodeId) {
var node = this.domAgent_.getNodeForId(nodeId);
WebInspector.updateFocusedNode(node);
};
@@ -114,8 +107,9 @@ devtools.ToolsAgent.prototype.updateFocusedNode = function(nodeId) {
* @param {string} url Url frame navigated to.
* @param {bool} topLevel True iff top level navigation occurred.
* @see tools_agent.h
+ * @private
*/
-devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) {
+devtools.ToolsAgent.prototype.frameNavigate_ = function(url, topLevel) {
if (topLevel) {
this.reset();
WebInspector.reset();
@@ -126,8 +120,9 @@ devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) {
/**
* @param {Object} message Message object to add.
* @see tools_agent.h
+ * @private
*/
-devtools.ToolsAgent.prototype.addMessageToConsole = function(message) {
+devtools.ToolsAgent.prototype.addMessageToConsole_ = function(message) {
var console = WebInspector.console;
if (console) {
console.addMessage(new WebInspector.ConsoleMessage(
@@ -138,6 +133,16 @@ devtools.ToolsAgent.prototype.addMessageToConsole = function(message) {
/**
+ * @param {string} message Serialized call to be dispatched on WebInspector.
+ * @private
+ */
+devtools.ToolsAgent.prototype.dispatchOnClient_ = function(message) {
+ var messageObj = JSON.parse(message);
+ WebInspector.dispatch.apply(WebInspector, messageObj);
+};
+
+
+/**
* Evaluates js expression.
* @param {string} expr
*/
@@ -147,6 +152,23 @@ devtools.ToolsAgent.prototype.evaluate = function(expr) {
/**
+ * Asynchronously queries for the resource content.
+ * @param {number} identifier Resource identifier.
+ * @param {function(string):undefined} opt_callback Callback to call when
+ * result is available.
+ */
+devtools.ToolsAgent.prototype.getResourceContentAsync = function(identifier,
+ opt_callback) {
+ var resource = WebInspector.resources[identifier];
+ if (!resource) {
+ return;
+ }
+ RemoteToolsAgent.GetResourceContent(
+ devtools.Callback.wrap(opt_callback), identifier);
+};
+
+
+/**
* Prints string to the inspector console or shows alert if the console doesn't
* exist.
* @param {string} text
@@ -499,9 +521,8 @@ WebInspector.SourceView.prototype.setupSourceFrameIfNeeded = function() {
var self = this;
var identifier = this.resource.identifier;
var element = this.sourceFrame.element;
- var netAgent = devtools.tools.getNetAgent();
- netAgent.getResourceContentAsync(identifier, function(source) {
+ devtools.tools.getResourceContentAsync(identifier, function(source) {
var resource = WebInspector.resources[identifier];
if (InspectorController.addSourceToFrame(resource.mimeType, source,
element)) {
@@ -904,7 +925,20 @@ WebInspector.ProfileDataGridNode.prototype._populate = function(event) {
* @override
* TODO(pfeldman): Add l10n.
*/
-WebInspector.UIString = function(string)
-{
+WebInspector.UIString = function(string) {
return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
-}
+};
+
+
+// There is no clear way of setting frame title yet. So sniffing main resource
+// load.
+(function OverrideUpdateResource() {
+ var originalUpdateResource = WebInspector.updateResource;
+ WebInspector.updateResource = function(identifier, payload) {
+ originalUpdateResource.call(this, identifier, payload);
+ var resource = this.resources[identifier];
+ if (resource && resource.mainResource && resource.finished) {
+ document.title = 'Developer Tools - ' + resource.url;
+ }
+ };
+})();
diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js
index 801d42e..ff52d26 100644
--- a/webkit/glue/devtools/js/devtools_host_stub.js
+++ b/webkit/glue/devtools/js/devtools_host_stub.js
@@ -257,13 +257,6 @@ RemoteDebuggerCommandExecutorStub.prototype.DebuggerCommand = function(cmd) {
/**
* @constructor
*/
-RemoteNetAgentStub = function() {
-};
-
-
-/**
- * @constructor
- */
DevToolsHostStub = function() {
};
@@ -282,7 +275,6 @@ if (!window['DevToolsHost']) {
window['RemoteDebuggerCommandExecutor'] =
new RemoteDebuggerCommandExecutorStub();
window['RemoteDomAgent'] = new RemoteDomAgentStub();
- window['RemoteNetAgent'] = new RemoteNetAgentStub();
window['RemoteToolsAgent'] = new RemoteToolsAgentStub();
window['DevToolsHost'] = new DevToolsHostStub();
}
diff --git a/webkit/glue/devtools/js/dom_agent.js b/webkit/glue/devtools/js/dom_agent.js
index 2cf8904..3ab2017 100644
--- a/webkit/glue/devtools/js/dom_agent.js
+++ b/webkit/glue/devtools/js/dom_agent.js
@@ -483,17 +483,17 @@ devtools.DomAgent = function() {
RemoteDomAgent.DidSetTextNodeValue =
devtools.Callback.processCallback;
RemoteDomAgent.AttributesUpdated =
- goog.bind(this.attributesUpdated, this);
+ goog.bind(this.attributesUpdated_, this);
RemoteDomAgent.SetDocumentElement =
- goog.bind(this.setDocumentElement, this);
+ goog.bind(this.setDocumentElement_, this);
RemoteDomAgent.SetChildNodes =
- goog.bind(this.setChildNodes, this);
+ goog.bind(this.setChildNodes_, this);
RemoteDomAgent.HasChildrenUpdated =
- goog.bind(this.hasChildrenUpdated, this);
+ goog.bind(this.hasChildrenUpdated_, this);
RemoteDomAgent.ChildNodeInserted =
- goog.bind(this.childNodeInserted, this);
+ goog.bind(this.childNodeInserted_, this);
RemoteDomAgent.ChildNodeRemoved =
- goog.bind(this.childNodeRemoved, this);
+ goog.bind(this.childNodeRemoved_, this);
/**
* Top-level (and the only) document.
@@ -625,6 +625,7 @@ devtools.DomAgent.prototype.setTextNodeValueAsync = function(node, text,
* @param {devtools.DomNode} node Node to apply local changes on.
* @param {Function} callback Post-operation call.
* @param {boolean} success True iff operation has completed successfully.
+ * @private
*/
devtools.DomAgent.prototype.didApplyDomChange_ = function(node,
callback, success) {
@@ -642,8 +643,9 @@ devtools.DomAgent.prototype.didApplyDomChange_ = function(node,
/**
* @see DomAgentDelegate.
* {@inheritDoc}.
+ * @private
*/
-devtools.DomAgent.prototype.attributesUpdated = function(nodeId, attrsArray) {
+devtools.DomAgent.prototype.attributesUpdated_ = function(nodeId, attrsArray) {
var node = this.idToDomNode_[nodeId];
node.setAttributesPayload_(attrsArray);
};
@@ -662,14 +664,15 @@ devtools.DomAgent.prototype.getNodeForId = function(nodeId) {
/**
* @see DomAgentDelegate.
* {@inheritDoc}.
+ * @private
*/
-devtools.DomAgent.prototype.setDocumentElement = function(payload) {
+devtools.DomAgent.prototype.setDocumentElement_ = function(payload) {
var doc = this.getDocument();
if (doc.documentElement) {
this.reset();
doc = this.getDocument();
}
- this.setChildNodes(0, [payload]);
+ this.setChildNodes_(0, [payload]);
doc.documentElement = doc.firstChild;
doc.documentElement.ownerDocument = doc;
WebInspector.panels.elements.reset();
@@ -679,8 +682,9 @@ devtools.DomAgent.prototype.setDocumentElement = function(payload) {
/**
* @see DomAgentDelegate.
* {@inheritDoc}.
+ * @private
*/
-devtools.DomAgent.prototype.setChildNodes = function(parentId, payloads) {
+devtools.DomAgent.prototype.setChildNodes_ = function(parentId, payloads) {
var parent = this.idToDomNode_[parentId];
if (parent.children) {
return;
@@ -693,6 +697,7 @@ devtools.DomAgent.prototype.setChildNodes = function(parentId, payloads) {
/**
* Binds nodes to ids recursively.
* @param {Array.<devtools.DomNode>} children Nodes to bind.
+ * @private
*/
devtools.DomAgent.prototype.bindNodes_ = function(children) {
for (var i = 0; i < children.length; ++i) {
@@ -708,8 +713,9 @@ devtools.DomAgent.prototype.bindNodes_ = function(children) {
/**
* @see DomAgentDelegate.
* {@inheritDoc}.
+ * @private
*/
-devtools.DomAgent.prototype.hasChildrenUpdated = function(nodeId, newValue) {
+devtools.DomAgent.prototype.hasChildrenUpdated_ = function(nodeId, newValue) {
var node = this.idToDomNode_[nodeId];
var outline = WebInspector.panels.elements.treeOutline;
var treeElement = outline.findTreeElement(node);
@@ -723,8 +729,9 @@ devtools.DomAgent.prototype.hasChildrenUpdated = function(nodeId, newValue) {
/**
* @see DomAgentDelegate.
* {@inheritDoc}.
+ * @private
*/
-devtools.DomAgent.prototype.childNodeInserted = function(
+devtools.DomAgent.prototype.childNodeInserted_ = function(
parentId, prevId, payload) {
var parent = this.idToDomNode_[parentId];
var prev = this.idToDomNode_[prevId];
@@ -738,8 +745,9 @@ devtools.DomAgent.prototype.childNodeInserted = function(
/**
* @see DomAgentDelegate.
* {@inheritDoc}.
+ * @private
*/
-devtools.DomAgent.prototype.childNodeRemoved = function(
+devtools.DomAgent.prototype.childNodeRemoved_ = function(
parentId, nodeId) {
var parent = this.idToDomNode_[parentId];
var node = this.idToDomNode_[nodeId];
@@ -789,6 +797,7 @@ devtools.DomAgent.prototype.searchCanceled = function(callback) {
* @param {function(Array.<devtools.DomNode>)} callback to accept the result.
* @param {Array.<number>} searchResults to be populated.
* @param {Array.<number>} nodeIds Ids to highlight.
+ * @private
*/
devtools.DomAgent.prototype.performSearchCallback_ = function(callback,
searchResults, nodeIds) {
diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js
index 83cdb71..404779a 100644
--- a/webkit/glue/devtools/js/inject_dispatch.js
+++ b/webkit/glue/devtools/js/inject_dispatch.js
@@ -31,3 +31,19 @@ function devtools$$dispatch(functionName, node, json_args) {
var result = devtools$$obj[functionName].apply(devtools$$obj, params);
return JSON.stringify(result);
};
+
+
+/**
+ * This is called by the InspectorFrontend for serialization.
+ * We serialize the call and send it to the client over the IPC
+ * using dispatchOut bound method.
+ */
+var dispatch = function(method, var_args) {
+ // Handle all messages with non-primitieve arguments here.
+ // TODO(pfeldman): Add more.
+ if (method == 'inspectedWindowCleared') {
+ return;
+ }
+ var call = JSON.stringify(Array.prototype.slice.call(arguments));
+ RemoteWebInspector.dispatch(call);
+};
diff --git a/webkit/glue/devtools/js/net_agent.js b/webkit/glue/devtools/js/net_agent.js
deleted file mode 100644
index 957e119..0000000
--- a/webkit/glue/devtools/js/net_agent.js
+++ /dev/null
@@ -1,126 +0,0 @@
-// 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 'Net' manages resources along with the corresponding
- * HTTP requests and responses.
- * web inspector.
- */
-goog.provide('devtools.NetAgent');
-
-devtools.NetAgent = function() {
- this.id_for_url_ = {};
-
- RemoteNetAgent.GetResourceContentResult =
- devtools.Callback.processCallback;
- RemoteNetAgent.WillSendRequest =
- goog.bind(this.willSendRequest, this);
- RemoteNetAgent.DidReceiveResponse =
- goog.bind(this.didReceiveResponse, this);
- RemoteNetAgent.DidFinishLoading =
- goog.bind(this.didFinishLoading, this);
-};
-
-
-/**
- * Resets dom agent to its initial state.
- */
-devtools.NetAgent.prototype.reset = function() {
- this.id_for_url_ = {};
-};
-
-
-/**
- * Asynchronously queries for the resource content.
- * @param {number} identifier Resource identifier.
- * @param {function(string):undefined} opt_callback Callback to call when
- * result is available.
- */
-devtools.NetAgent.prototype.getResourceContentAsync = function(identifier,
- opt_callback) {
- var resource = WebInspector.resources[identifier];
- if (!resource) {
- return;
- }
- var mycallback = function(content) {
- if (opt_callback) {
- opt_callback(content);
- }
- };
- RemoteNetAgent.GetResourceContent(
- devtools.Callback.wrap(mycallback), identifier, resource.url);
-};
-
-
-/**
- * @see NetAgentDelegate.
- * {@inheritDoc}.
- */
-devtools.NetAgent.prototype.willSendRequest = function(identifier, request) {
- // Resource object is already created.
- var resource = WebInspector.resources[identifier];
- if (resource) {
- return;
- }
-
- WebInspector.addResource(identifier, request);
- var resource = WebInspector.resources[identifier];
- resource.startTime = request.startTime;
- this.id_for_url_[resource.url] = identifier;
-};
-
-
-/**
- * @see NetAgentDelegate.
- * {@inheritDoc}.
- */
-devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response) {
- var resource = WebInspector.resources[identifier];
- if (!resource) {
- return;
- }
-
- 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) {
- resource.type = WebInspector.Resource.Type.Image;
- } else if (mimeType.indexOf('text/html') == 0) {
- resource.type = WebInspector.Resource.Type.Document;
- } 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;
- }
- resource.responseReceivedTime = response.responseReceivedTime;
-};
-
-
-/**
- * @see NetAgentDelegate.
- * {@inheritDoc}.
- */
-devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) {
- // When loading main resource we are only getting the didFinishLoading
- // that is happening after the reset. Replay previous commands here.
- this.willSendRequest(identifier, value);
- this.didReceiveResponse(identifier, value);
-
- var resource = WebInspector.resources[identifier];
- if (!resource) {
- return;
- }
- resource.endTime = value.endTime;
- resource.finished = true;
- resource.failed = !!value.errorCode;
- if (resource.mainResource) {
- document.title = 'Developer Tools - ' + resource.url;
- }
-};
diff --git a/webkit/glue/devtools/net_agent.h b/webkit/glue/devtools/net_agent.h
deleted file mode 100644
index 38db57d..0000000
--- a/webkit/glue/devtools/net_agent.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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.
-
-#ifndef WEBKIT_GLUE_DEVTOOLS_NET_AGENT_H_
-#define WEBKIT_GLUE_DEVTOOLS_NET_AGENT_H_
-
-#include "webkit/glue/devtools/devtools_rpc.h"
-
-// NetAgent is a utility object that covers network-related functionality of the
-// WebDevToolsAgent. It is capable of sniffing network calls and passing the
-// HTTPRequest-related data to the client.
-// NetAgent's environment is represented with the NetAgentDelegate interface.
-#define NET_AGENT_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, METHOD4) \
- /* Requests that the agent sends content of the resource with given id to the
- delegate. */ \
- METHOD3(GetResourceContent, int /* call_id */, int /* identifier */, \
- String /* url */)
-
-DEFINE_RPC_CLASS(NetAgent, NET_AGENT_STRUCT)
-
-#define NET_AGENT_DELEGATE_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, \
- METHOD4) \
- /* Notifies the delegate that a request is about to be sent out. */ \
- METHOD2(WillSendRequest, int, Value) \
- \
- /* Notifies the delegate that response has been received. */ \
- METHOD2(DidReceiveResponse, int /* identifier */, Value /* request */) \
- \
- /* Notifies the delegate that resource loading has been finished with no
- errors */ \
- METHOD2(DidFinishLoading, int /* identifier */, Value /* response */) \
- \
- /* Response to the async call. */ \
- METHOD2(GetResourceContentResult, int /* call_id */, std::string /* content */)
-
-DEFINE_RPC_CLASS(NetAgentDelegate, NET_AGENT_DELEGATE_STRUCT)
-
-#endif // WEBKIT_GLUE_DEVTOOLS_NET_AGENT_H_
diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc
deleted file mode 100644
index e1c0e84..0000000
--- a/webkit/glue/devtools/net_agent_impl.cc
+++ /dev/null
@@ -1,325 +0,0 @@
-// 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.
-
-#include "config.h"
-
-#include "CachedCSSStyleSheet.h"
-#include "CachedResource.h"
-#include "CachedScript.h"
-#include "CachedXSLStyleSheet.h"
-#include "DocLoader.h"
-#include "Document.h"
-#include "DocumentLoader.h"
-#include "FrameLoader.h"
-#include "PlatformString.h"
-#include "ResourceError.h"
-#include "ResourceRequest.h"
-#include "ResourceResponse.h"
-#include "ScriptString.h"
-#include "TextEncoding.h"
-#include <wtf/CurrentTime.h>
-#undef LOG
-
-#include "base/basictypes.h"
-#include "base/values.h"
-#include "googleurl/src/gurl.h"
-#include "webkit/glue/devtools/net_agent_impl.h"
-#include "webkit/glue/glue_util.h"
-
-using namespace WebCore;
-
-NetAgentImpl::NetAgentImpl(NetAgentDelegate* delegate)
- : delegate_(delegate),
- document_(NULL),
- main_loader_(NULL),
- last_cached_identifier_(-2),
- attached_(false) {
-}
-
-NetAgentImpl::~NetAgentImpl() {
- SetDocument(NULL);
- DidCommitMainResourceLoad();
- deleteAllValues(pending_resources_);
- pending_resources_.clear();
-}
-
-void NetAgentImpl::SetDocument(Document* doc) {
- document_ = doc;
-}
-
-void NetAgentImpl::Attach() {
- for (FinishedResources::iterator it = finished_resources_.begin();
- it != finished_resources_.end(); ++it) {
- DictionaryValue value;
- Serialize(*it->second, &value);
- delegate_->DidFinishLoading(it->first, value);
- }
- attached_ = true;
-}
-
-void NetAgentImpl::Detach() {
- attached_ = false;
- xml_http_sources_.clear();
- ExpireFinishedResourcesCache();
-}
-
-void NetAgentImpl::DidCommitMainResourceLoad() {
- for (FinishedResources::iterator it = finished_resources_.begin();
- it != finished_resources_.end(); ++it) {
- delete it->second;
- }
- finished_resources_.clear();
- main_loader_ = NULL;
-}
-
-void NetAgentImpl::AssignIdentifierToRequest(
- DocumentLoader* loader,
- int identifier,
- const ResourceRequest& request) {
-}
-
-void NetAgentImpl::WillSendRequest(
- DocumentLoader* loader,
- int identifier,
- const ResourceRequest& request) {
- if (pending_resources_.contains(identifier)) {
- // We are going through redirect, nuke old resource.
- delete pending_resources_.get(identifier);
- }
-
- Resource* resource = new Resource();
- pending_resources_.set(identifier, resource);
- KURL url = request.url();
- resource->start_time = WTF::currentTime();
- resource->url = request.url();
- resource->request_headers = request.httpHeaderFields();
-
- if (attached_) {
- DictionaryValue value;
- Serialize(*resource, &value);
- delegate_->WillSendRequest(identifier, value);
- }
-}
-
-void NetAgentImpl::DidReceiveResponse(
- DocumentLoader* loader,
- int identifier,
- const ResourceResponse &response) {
- if (!pending_resources_.contains(identifier)) {
- return;
- }
-
- KURL url = response.url();
- Resource* resource = pending_resources_.get(identifier);
- resource->response_received_time = WTF::currentTime();
- resource->expected_content_length =
- static_cast<int>(response.expectedContentLength());
- resource->http_status_code = response.httpStatusCode();
- resource->mime_type = response.mimeType();
- resource->suggested_filename = response.suggestedFilename();
- resource->response_headers = response.httpHeaderFields();
-
- if (attached_) {
- DictionaryValue value;
- Serialize(*resource, &value);
- delegate_->DidReceiveResponse(identifier, value);
- }
-}
-
-void NetAgentImpl::DidReceiveContentLength(
- DocumentLoader* loader,
- int identifier,
- int length) {
-}
-
-void NetAgentImpl::DidFinishLoading(
- DocumentLoader* loader,
- int identifier) {
- if (!pending_resources_.contains(identifier)) {
- return;
- }
-
- Resource* resource = pending_resources_.get(identifier);
- resource->end_time = WTF::currentTime();
-
- // This is the first command being dispatched after
- // DidCommitMainResourceLoad, we know that the first resource to be reported
- // as loaded is main resource.
- if (!main_loader_.get()) {
- main_loader_ = loader;
- resource->main_resource = true;
- }
-
- pending_resources_.remove(identifier);
- finished_resources_.append(std::make_pair(identifier, resource));
-
- if (attached_) {
- DictionaryValue value;
- Serialize(*resource, &value);
- delegate_->DidFinishLoading(identifier, value);
- } else {
- ExpireFinishedResourcesCache();
- }
-}
-
-void NetAgentImpl::DidFailLoading(
- DocumentLoader* loader,
- int identifier,
- const ResourceError& error) {
- if (!pending_resources_.contains(identifier)) {
- return;
- }
- Resource* resource = pending_resources_.get(identifier);
- resource->error_code = error.errorCode();
- resource->error_description = error.localizedDescription();
- DidFinishLoading(loader, identifier);
-}
-
-void NetAgentImpl::DidLoadResourceFromMemoryCache(
- DocumentLoader* loader,
- const ResourceRequest& request,
- const ResourceResponse& response,
- int length) {
- int identifier = last_cached_identifier_--;
-}
-
-void NetAgentImpl::DidLoadResourceByXMLHttpRequest(
- int identifier,
- const WebCore::ScriptString& source) {
- if (attached_) {
- // Only store XmlHttpRequests data when client is attached.
- xml_http_sources_.set(identifier, source);
- }
-}
-
-void NetAgentImpl::GetResourceContent(
- int call_id,
- int identifier,
- const String& url) {
- if (!document_) {
- return;
- }
-
- String source;
-
- WebCore::ScriptString script = xml_http_sources_.get(identifier);
- if (!script.isNull()) {
- source = String(script);
- } else if (main_loader_.get() && main_loader_->requestURL() == url) {
- RefPtr<SharedBuffer> buffer = main_loader_->mainResourceData();
- String text_encoding_name = document_->inputEncoding();
- if (buffer) {
- WebCore::TextEncoding encoding(text_encoding_name);
- if (!encoding.isValid())
- encoding = WindowsLatin1Encoding();
- source = encoding.decode(buffer->data(), buffer->size());
- }
- } else {
- CachedResource* cached_resource = document_->
- docLoader()->cachedResource(url);
- 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 (cached_resource->type()) {
- case CachedResource::CSSStyleSheet: {
- CachedCSSStyleSheet *sheet =
- reinterpret_cast<CachedCSSStyleSheet*>(cached_resource);
- source = sheet->sheetText();
- break;
- }
- case CachedResource::Script: {
- CachedScript *script =
- reinterpret_cast<CachedScript*>(cached_resource);
- source = script->script();
- break;
- }
-#if ENABLE(XSLT)
- case CachedResource::XSLStyleSheet: {
- CachedXSLStyleSheet *sheet =
- reinterpret_cast<CachedXSLStyleSheet*>(cached_resource);
- source = sheet->sheet();
- break;
- }
-#endif
- default:
- break;
- }
- }
- delegate_->GetResourceContentResult(call_id,
- webkit_glue::StringToStdString(source));
-}
-
-// static
-Value* NetAgentImpl::BuildValueForHeaders(const HTTPHeaderMap& headers) {
- OwnPtr<DictionaryValue> value(new DictionaryValue());
- HTTPHeaderMap::const_iterator end = headers.end();
- for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) {
- value->SetString(webkit_glue::StringToStdWString(it->first),
- webkit_glue::StringToStdString(it->second));
- }
- return value.release();
-}
-
-// static
-void NetAgentImpl::Serialize(const Resource& resource,
- DictionaryValue* value) {
- value->SetReal(L"startTime", resource.start_time);
- value->SetReal(L"responseReceivedTime", resource.response_received_time);
- value->SetReal(L"endTime", resource.end_time);
-
- value->SetString(L"requestURL",
- webkit_glue::StringToStdString(resource.url.string()));
- value->SetString(L"host",
- webkit_glue::StringToStdString(resource.url.host()));
- value->SetString(L"path",
- webkit_glue::StringToStdString(resource.url.path()));
- value->SetString(
- L"lastPathComponent",
- webkit_glue::StringToStdString(resource.url.lastPathComponent()));
-
- value->SetString(L"mimeType",
- webkit_glue::StringToStdWString(resource.mime_type));
- value->SetString(L"suggestedFilename",
- webkit_glue::StringToStdWString(resource.suggested_filename));
-
- value->SetInteger(L"expectedContentLength",
- resource.expected_content_length);
- value->SetInteger(L"responseStatusCode", resource.http_status_code);
-
- value->Set(L"requestHeaders",
- BuildValueForHeaders(resource.request_headers));
- value->Set(L"responseHeaders",
- BuildValueForHeaders(resource.response_headers));
-
- value->SetBoolean(L"isMainResource", resource.main_resource);
- value->SetBoolean(L"cached", false);
-
- if (resource.error_code) {
- value->SetInteger(L"errorCode", resource.error_code);
- value->SetString(L"localizedDescription",
- webkit_glue::StringToStdString(resource.error_description));
- }
-}
-
-void NetAgentImpl::ExpireFinishedResourcesCache() {
- if (finished_resources_.size() > 100) {
- // Preserve main resource.
- for (int i = 1; i < 21; ++i) {
- delete finished_resources_[i].second;
- }
- finished_resources_.remove(1, 21);
- }
-}
diff --git a/webkit/glue/devtools/net_agent_impl.h b/webkit/glue/devtools/net_agent_impl.h
deleted file mode 100644
index a308167..0000000
--- a/webkit/glue/devtools/net_agent_impl.h
+++ /dev/null
@@ -1,143 +0,0 @@
-// 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.
-
-#ifndef WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_
-#define WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_
-
-#include <utility>
-
-#include "HTTPHeaderMap.h"
-#include "KURL.h"
-#include <wtf/HashMap.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-
-#include "webkit/glue/devtools/net_agent.h"
-
-namespace WebCore {
-class Document;
-class DocumentLoader;
-class HTTPHeaderMap;
-class ResourceError;
-class ResourceResponse;
-class ScriptString;
-class String;
-struct ResourceRequest;
-}
-
-class Value;
-
-// NetAgent is a utility object that covers network-related functionality of the
-// WebDevToolsAgent. It is capable of sniffing network calls and passing the
-// HttpRequest-related data to the client.
-// NetAgent's environment is represented with the NetAgentDelegate interface.
-class NetAgentImpl : public NetAgent {
- public:
- explicit NetAgentImpl(NetAgentDelegate* delegate);
- virtual ~NetAgentImpl();
-
- // Initializes net agent with the given document.
- void SetDocument(WebCore::Document* document);
-
- // Tells agent it has attached client.
- void Attach();
-
- // Tells agent it has no attached client.
- void Detach();
-
- // Tells agent that new load has been committed.
- void DidCommitMainResourceLoad();
-
- // NetAgent implementation.
- void GetResourceContent(int call_id, int identifier,
- const WebCore::String& request_url);
- void AssignIdentifierToRequest(
- WebCore::DocumentLoader* loader,
- int identifier,
- const WebCore::ResourceRequest& request);
- void WillSendRequest(
- WebCore::DocumentLoader* loader,
- int identifier,
- const WebCore::ResourceRequest& request);
- void DidReceiveResponse(
- WebCore::DocumentLoader* loader,
- int identifier,
- const WebCore::ResourceResponse &response);
- void DidReceiveContentLength(
- WebCore::DocumentLoader* loader,
- int identifier,
- int length);
- void DidFinishLoading(
- WebCore::DocumentLoader* loader,
- int identifier);
- void DidFailLoading(
- WebCore::DocumentLoader* loader,
- int identifier,
- const WebCore::ResourceError& error);
- void DidLoadResourceFromMemoryCache(
- WebCore::DocumentLoader* loader,
- const WebCore::ResourceRequest& request,
- const WebCore::ResourceResponse& response,
- int length);
- void DidLoadResourceByXMLHttpRequest(
- int identifier,
- const WebCore::ScriptString& source);
-
- private:
- struct Resource {
- Resource()
- : main_resource(false),
- start_time(0),
- response_received_time(0),
- end_time(0),
- expected_content_length(0),
- http_status_code(0),
- error_code(0) {
- }
- bool main_resource;
-
- double start_time;
- double response_received_time;
- double end_time;
-
- WebCore::KURL url;
- WebCore::String mime_type;
- WebCore::String suggested_filename;
-
- int expected_content_length;
- int http_status_code;
-
- WebCore::HTTPHeaderMap request_headers;
- WebCore::HTTPHeaderMap response_headers;
-
- int error_code;
- WebCore::String error_description;
- };
-
- static void Serialize(const Resource& resource, DictionaryValue* value);
-
- // Serializes headers map into a value.
- static Value* BuildValueForHeaders(const WebCore::HTTPHeaderMap& headers);
-
- void ExpireFinishedResourcesCache();
-
- NetAgentDelegate* delegate_;
- WebCore::Document* document_;
- RefPtr<WebCore::DocumentLoader> main_loader_;
- typedef HashMap<int, Resource*, DefaultHash<int>::Hash,
- WTF::UnsignedWithZeroKeyHashTraits<int> > ResourcesMap;
- typedef Vector<std::pair<int, Resource*> > FinishedResources;
- typedef HashMap<int, WebCore::ScriptString, DefaultHash<int>::Hash,
- WTF::UnsignedWithZeroKeyHashTraits<int> > XmlHttpSources;
-
- ResourcesMap pending_resources_;
- FinishedResources finished_resources_;
- XmlHttpSources xml_http_sources_;
- int last_cached_identifier_;
- bool attached_;
- DISALLOW_COPY_AND_ASSIGN(NetAgentImpl);
-};
-
-#endif // WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_
diff --git a/webkit/glue/devtools/tools_agent.h b/webkit/glue/devtools/tools_agent.h
index 1ac2413..83e4fe7 100644
--- a/webkit/glue/devtools/tools_agent.h
+++ b/webkit/glue/devtools/tools_agent.h
@@ -25,7 +25,10 @@
String /* json_args */) \
\
/* Clears cached console messages. */ \
- METHOD0(ClearConsoleMessages)
+ METHOD0(ClearConsoleMessages) \
+ /* Requests that the agent sends content of the resource with given id to the
+ delegate. */ \
+ METHOD2(GetResourceContent, int /* call_id */, int /* identifier */)
DEFINE_RPC_CLASS(ToolsAgent, TOOLS_AGENT_STRUCT)
@@ -44,8 +47,11 @@ DEFINE_RPC_CLASS(ToolsAgent, TOOLS_AGENT_STRUCT)
METHOD3(DidExecuteUtilityFunction, int /* call_id */, String /* result */, \
String /* exception */) \
\
- /* Adds message to console. */ \
- METHOD1(AddMessageToConsole, Value /* message */)
+ /* Sends InspectorFrontend message to be dispatched on client. */ \
+ METHOD1(DispatchOnClient, String /* data */) \
+ \
+ /* Response to the async call. */ \
+ METHOD2(DidGetResourceContent, int /* call_id */, String /* content */)
DEFINE_RPC_CLASS(ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT)
diff --git a/webkit/glue/inspector_client_impl.cc b/webkit/glue/inspector_client_impl.cc
index 6fd7b88..f78810c 100644
--- a/webkit/glue/inspector_client_impl.cc
+++ b/webkit/glue/inspector_client_impl.cc
@@ -49,6 +49,9 @@ void WebInspectorClient::inspectorDestroyed() {
}
Page* WebInspectorClient::createPage() {
+ if (inspected_web_view_->GetWebDevToolsAgentImpl())
+ return NULL;
+
WebCore::Page* page;
if (inspector_web_view_ != NULL) {
@@ -98,6 +101,9 @@ Page* WebInspectorClient::createPage() {
}
void WebInspectorClient::showWindow() {
+ if (inspected_web_view_->GetWebDevToolsAgentImpl())
+ return;
+
InspectorController* inspector = inspected_web_view_->page()->inspectorController();
inspector->setWindowVisible(true);
@@ -108,6 +114,9 @@ void WebInspectorClient::showWindow() {
}
void WebInspectorClient::closeWindow() {
+ if (inspected_web_view_->GetWebDevToolsAgentImpl())
+ return;
+
inspector_web_view_ = NULL;
hideHighlight();
@@ -117,6 +126,9 @@ void WebInspectorClient::closeWindow() {
}
bool WebInspectorClient::windowVisible() {
+ if (inspected_web_view_->GetWebDevToolsAgentImpl())
+ return false;
+
if (inspector_web_view_ != NULL) {
Page* page = inspector_web_view_->page();
ASSERT(page != NULL);
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 793ca5d..50c676f 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -9,19 +9,24 @@
#include "Document.h"
#include "EventListener.h"
#include "InspectorController.h"
+#include "InspectorFrontend.h"
+#include "InspectorResource.h"
#include "Node.h"
#include "Page.h"
#include "PlatformString.h"
+#include "ScriptObject.h"
+#include "ScriptState.h"
#include "ScriptValue.h"
#include "v8_proxy.h"
#include <wtf/OwnPtr.h>
#undef LOG
+#include "V8Binding.h"
#include "base/values.h"
+#include "webkit/glue/devtools/bound_object.h"
#include "webkit/glue/devtools/debugger_agent_impl.h"
#include "webkit/glue/devtools/debugger_agent_manager.h"
#include "webkit/glue/devtools/dom_agent_impl.h"
-#include "webkit/glue/devtools/net_agent_impl.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webdatasource.h"
#include "webkit/glue/webdevtoolsagent_delegate.h"
@@ -31,14 +36,13 @@
using WebCore::Document;
using WebCore::InspectorController;
+using WebCore::InspectorFrontend;
+using WebCore::InspectorResource;
using WebCore::Node;
using WebCore::Page;
using WebCore::ScriptValue;
using WebCore::String;
-// Maximum size of the console message cache.
-static const size_t kMaxConsoleMessages = 200;
-
WebDevToolsAgentImpl::WebDevToolsAgentImpl(
WebViewImpl* web_view_impl,
WebDevToolsAgentDelegate* delegate)
@@ -49,11 +53,7 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl(
attached_(false) {
debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this));
dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this));
- net_agent_delegate_stub_.set(new NetAgentDelegateStub(this));
tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this));
-
- // Sniff for requests from the beginning, do not wait for attach.
- net_agent_impl_.set(new NetAgentImpl(net_agent_delegate_stub_.get()));
}
WebDevToolsAgentImpl::~WebDevToolsAgentImpl() {
@@ -84,26 +84,32 @@ void WebDevToolsAgentImpl::Attach() {
debugger_agent_impl_->ResetUtilityContext(doc, &utility_context_);
}
dom_agent_impl_->SetDocument(doc);
- net_agent_impl_->SetDocument(doc);
- }
-
- // Populate console.
- for (Vector<ConsoleMessage>::iterator it = console_log_.begin();
- it != console_log_.end(); ++it) {
- DictionaryValue message;
- Serialize(*it, &message);
- tools_agent_delegate_stub_->AddMessageToConsole(message);
+ web_inspector_stub_.set(
+ new BoundObject(utility_context_, this, "RemoteWebInspector"));
+ web_inspector_stub_->AddProtoFunction(
+ "dispatch",
+ WebDevToolsAgentImpl::JsDispatchOnClient);
+ web_inspector_stub_->Build();
+
+ InspectorController* ic = web_view_impl_->page()->inspectorController();
+ v8::HandleScope scope;
+ ic->setFrontendProxyObject(
+ scriptStateFromPage(web_view_impl_->page()),
+ utility_context_->Global());
+ // Allow controller to send messages to the frontend.
+ ic->setWindowVisible(true, false);
}
-
- net_agent_impl_->Attach();
attached_ = true;
}
void WebDevToolsAgentImpl::Detach() {
+ // Prevent controller from sending messages to the frontend.
+ InspectorController* ic = web_view_impl_->page()->inspectorController();
+ ic->setWindowVisible(false, false);
HideDOMNodeHighlight();
+ web_inspector_stub_.set(NULL);
debugger_agent_impl_.set(NULL);
dom_agent_impl_.set(NULL);
- net_agent_impl_->Detach();
attached_ = false;
}
@@ -122,16 +128,12 @@ void WebDevToolsAgentImpl::SetMainFrameDocumentReady(bool ready) {
}
debugger_agent_impl_->ResetUtilityContext(doc, &utility_context_);
dom_agent_impl_->SetDocument(doc);
- net_agent_impl_->SetDocument(doc);
}
void WebDevToolsAgentImpl::DidCommitLoadForFrame(
WebViewImpl* webview,
WebFrame* frame,
bool is_new_navigation) {
- if (webview->GetMainFrame() == frame) {
- net_agent_impl_->DidCommitMainResourceLoad();
- }
if (!attached_) {
return;
}
@@ -145,25 +147,6 @@ void WebDevToolsAgentImpl::DidCommitLoadForFrame(
webview->GetMainFrame() == frame);
}
-void WebDevToolsAgentImpl::AddMessageToConsole(
- int source,
- int level,
- const String& text,
- unsigned int line_no,
- const String& source_id) {
- ConsoleMessage cm(source, level, text, line_no, source_id);
- console_log_.append(cm);
- if (console_log_.size() >= kMaxConsoleMessages) {
- // Batch shifts to save ticks.
- console_log_.remove(0, kMaxConsoleMessages / 5);
- }
- if (attached_) {
- DictionaryValue message;
- Serialize(cm, &message);
- tools_agent_delegate_stub_->AddMessageToConsole(message);
- }
-}
-
void WebDevToolsAgentImpl::WindowObjectCleared(WebFrameImpl* webframe) {
DebuggerAgentManager::SetHostId(webframe, host_id_);
}
@@ -226,7 +209,25 @@ void WebDevToolsAgentImpl::ExecuteUtilityFunction(
}
void WebDevToolsAgentImpl::ClearConsoleMessages() {
- console_log_.clear();
+ Page* page = web_view_impl_->page();
+ if (page) {
+ page->inspectorController()->clearConsoleMessages();
+ }
+}
+
+void WebDevToolsAgentImpl::GetResourceContent(
+ int call_id,
+ int identifier) {
+ Page* page = web_view_impl_->page();
+ if (!page) {
+ return;
+ }
+ RefPtr<InspectorResource> resource =
+ page->inspectorController()->resources().get(identifier);
+ if (resource.get()) {
+ tools_agent_delegate_stub_->DidGetResourceContent(call_id,
+ resource->sourceString());
+ }
}
void WebDevToolsAgentImpl::DispatchMessageFromClient(
@@ -251,9 +252,6 @@ void WebDevToolsAgentImpl::DispatchMessageFromClient(
if (DomAgentDispatch::Dispatch(dom_agent_impl_.get(), *message.get())) {
return;
}
- if (NetAgentDispatch::Dispatch(net_agent_impl_.get(), *message.get())) {
- return;
- }
}
void WebDevToolsAgentImpl::InspectElement(int x, int y) {
@@ -271,14 +269,17 @@ void WebDevToolsAgentImpl::SendRpcMessage(const std::string& raw_msg) {
}
// static
-void WebDevToolsAgentImpl::Serialize(const ConsoleMessage& message,
- DictionaryValue* value) {
- value->SetInteger(L"source", message.source);
- value->SetInteger(L"level", message.level);
- value->SetString(L"text", webkit_glue::StringToStdString(message.text));
- value->SetString(L"sourceId",
- webkit_glue::StringToStdString(message.source_id));
- value->SetInteger(L"line", message.line_no);
+v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchOnClient(
+ const v8::Arguments& args) {
+ v8::TryCatch exception_catcher;
+ String message = WebCore::toWebCoreStringWithNullCheck(args[0]);
+ if (message.isEmpty() || exception_catcher.HasCaught()) {
+ return v8::Undefined();
+ }
+ WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(
+ v8::External::Cast(*args.Data())->Value());
+ agent->tools_agent_delegate_stub_->DispatchOnClient(message);
+ return v8::Undefined();
}
// static
diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h
index 2c5051c7..9b89514 100644
--- a/webkit/glue/webdevtoolsagent_impl.h
+++ b/webkit/glue/webdevtoolsagent_impl.h
@@ -8,12 +8,10 @@
#include <string>
#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"
#include "webkit/glue/devtools/tools_agent.h"
#include "webkit/glue/webdevtoolsagent.h"
@@ -23,6 +21,7 @@ class Node;
class String;
}
+class BoundObject;
class DebuggerAgentDelegateStub;
class DebuggerAgentImpl;
class DomAgentImpl;
@@ -52,6 +51,9 @@ class WebDevToolsAgentImpl
int node_id,
const WebCore::String& json_args);
virtual void ClearConsoleMessages();
+ virtual void GetResourceContent(
+ int call_id,
+ int identifier);
// WebDevToolsAgent implementation.
virtual void Attach();
@@ -67,38 +69,15 @@ class WebDevToolsAgentImpl
void DidCommitLoadForFrame(WebViewImpl* webview,
WebFrame* frame,
bool is_new_navigation);
- void AddMessageToConsole(
- int source,
- int level,
- const WebCore::String& message,
- unsigned int line_no,
- const WebCore::String& source_id);
void WindowObjectCleared(WebFrameImpl* webframe);
void ForceRepaint();
int host_id() { return host_id_; }
- NetAgentImpl* net_agent_impl() { return net_agent_impl_.get(); }
private:
- struct ConsoleMessage {
- ConsoleMessage(
- int src, int lvl, const String& m, unsigned li, const String& sid)
- : source(src),
- level(lvl),
- text(m),
- line_no(li),
- source_id(sid) {
- }
- int source;
- int level;
- WebCore::String text;
- WebCore::String source_id;
- unsigned int line_no;
- };
-
- static void Serialize(const ConsoleMessage& message, DictionaryValue* value);
+ static v8::Handle<v8::Value> JsDispatchOnClient(const v8::Arguments& args);
int host_id_;
WebDevToolsAgentDelegate* delegate_;
@@ -106,16 +85,14 @@ class WebDevToolsAgentImpl
WebCore::Document* document_;
OwnPtr<DebuggerAgentDelegateStub> debugger_agent_delegate_stub_;
OwnPtr<DomAgentDelegateStub> dom_agent_delegate_stub_;
- OwnPtr<NetAgentDelegateStub> net_agent_delegate_stub_;
OwnPtr<ToolsAgentDelegateStub> tools_agent_delegate_stub_;
OwnPtr<DebuggerAgentImpl> debugger_agent_impl_;
OwnPtr<DomAgentImpl> dom_agent_impl_;
- OwnPtr<NetAgentImpl> net_agent_impl_;
- Vector<ConsoleMessage> console_log_;
bool attached_;
// TODO(pfeldman): This should not be needed once GC styles issue is fixed
// for matching rules.
v8::Persistent<v8::Context> utility_context_;
+ OwnPtr<BoundObject> web_inspector_stub_;
DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentImpl);
};
diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc
index d4f1f00..182bc58 100644
--- a/webkit/glue/webdevtoolsclient_impl.cc
+++ b/webkit/glue/webdevtoolsclient_impl.cc
@@ -25,10 +25,10 @@
#include "base/string_util.h"
#include "base/values.h"
#include "webkit/api/public/WebScriptSource.h"
+#include "webkit/glue/devtools/bound_object.h"
#include "webkit/glue/devtools/debugger_agent.h"
#include "webkit/glue/devtools/devtools_rpc_js.h"
#include "webkit/glue/devtools/dom_agent.h"
-#include "webkit/glue/devtools/net_agent.h"
#include "webkit/glue/devtools/tools_agent.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webdevtoolsclient_delegate.h"
@@ -44,8 +44,6 @@ DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT,
DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT)
DEFINE_RPC_JS_BOUND_OBJ(DomAgent, DOM_AGENT_STRUCT,
DomAgentDelegate, DOM_AGENT_DELEGATE_STRUCT)
-DEFINE_RPC_JS_BOUND_OBJ(NetAgent, NET_AGENT_STRUCT,
- NetAgentDelegate, NET_AGENT_DELEGATE_STRUCT)
DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT,
ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT)
@@ -99,57 +97,28 @@ WebDevToolsClientImpl::WebDevToolsClientImpl(
debugger_agent_obj_.set(new JsDebuggerAgentBoundObj(
this, frame, L"RemoteDebuggerAgent"));
dom_agent_obj_.set(new JsDomAgentBoundObj(this, frame, L"RemoteDomAgent"));
- net_agent_obj_.set(new JsNetAgentBoundObj(this, frame, L"RemoteNetAgent"));
tools_agent_obj_.set(
new JsToolsAgentBoundObj(this, frame, L"RemoteToolsAgent"));
- WebDevToolsClientImpl::InitBoundObject();
v8::HandleScope scope;
v8::Handle<v8::Context> frame_context = V8Proxy::GetContext(frame->frame());
- v8::Context::Scope frame_scope(frame_context);
-
- v8::Local<v8::Function> constructor = host_template_->GetFunction();
- v8::Local<v8::Object> host_obj = SafeAllocation::NewInstance(constructor);
-
- v8::Handle<v8::Object> global = frame_context->Global();
- global->Set(v8::String::New("DevToolsHost"), host_obj);
+ dev_tools_host_.set(new BoundObject(frame_context, this, "DevToolsHost"));
+ dev_tools_host_->AddProtoFunction(
+ "addSourceToFrame",
+ WebDevToolsClientImpl::JsAddSourceToFrame);
+ dev_tools_host_->AddProtoFunction(
+ "loaded",
+ WebDevToolsClientImpl::JsLoaded);
+ dev_tools_host_->AddProtoFunction(
+ "search",
+ WebCore::V8Custom::v8InspectorControllerSearchCallback);
+ dev_tools_host_->AddProtoFunction(
+ "activateWindow",
+ WebDevToolsClientImpl::JsActivateWindow);
+ dev_tools_host_->Build();
}
WebDevToolsClientImpl::~WebDevToolsClientImpl() {
- host_template_.Dispose();
- v8_this_.Dispose();
-}
-
-void WebDevToolsClientImpl::InitBoundObject() {
- v8::HandleScope scope;
- v8::Local<v8::FunctionTemplate> local_template =
- v8::FunctionTemplate::New(V8Proxy::CheckNewLegal);
- host_template_ = v8::Persistent<v8::FunctionTemplate>::New(local_template);
- v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(this));
-
- InitProtoFunction("addSourceToFrame",
- WebDevToolsClientImpl::JsAddSourceToFrame);
- InitProtoFunction("loaded",
- WebDevToolsClientImpl::JsLoaded);
- InitProtoFunction("search",
- WebCore::V8Custom::v8InspectorControllerSearchCallback);
- InitProtoFunction("activateWindow",
- WebDevToolsClientImpl::JsActivateWindow);
- host_template_->SetClassName(v8::String::New("DevToolsHost"));
-}
-
-void WebDevToolsClientImpl::InitProtoFunction(
- const char* name,
- v8::InvocationCallback callback) {
- v8::Local<v8::Signature> signature = v8::Signature::New(host_template_);
- v8::Local<v8::ObjectTemplate> proto = host_template_->PrototypeTemplate();
- proto->Set(
- v8::String::New(name),
- v8::FunctionTemplate::New(
- callback,
- v8_this_,
- signature),
- static_cast<v8::PropertyAttribute>(v8::DontDelete));
}
void WebDevToolsClientImpl::DispatchMessageFromAgent(
diff --git a/webkit/glue/webdevtoolsclient_impl.h b/webkit/glue/webdevtoolsclient_impl.h
index 6a9e1ce..a7ae71f5 100644
--- a/webkit/glue/webdevtoolsclient_impl.h
+++ b/webkit/glue/webdevtoolsclient_impl.h
@@ -20,6 +20,7 @@ class Page;
class String;
}
+class BoundObject;
class JsDebuggerAgentBoundObj;
class JsDomAgentBoundObj;
class JsNetAgentBoundObj;
@@ -47,20 +48,15 @@ class WebDevToolsClientImpl : public WebDevToolsClient,
static v8::Handle<v8::Value> JsLoaded(const v8::Arguments& args);
static v8::Handle<v8::Value> JsActivateWindow(const v8::Arguments& args);
- void InitBoundObject();
- void InitProtoFunction(const char* name, v8::InvocationCallback callback);
-
WebViewImpl* web_view_impl_;
WebDevToolsClientDelegate* delegate_;
OwnPtr<CppBoundClass> debugger_command_executor_obj_;
OwnPtr<JsDebuggerAgentBoundObj> debugger_agent_obj_;
OwnPtr<JsDomAgentBoundObj> dom_agent_obj_;
- OwnPtr<JsNetAgentBoundObj> net_agent_obj_;
OwnPtr<JsToolsAgentBoundObj> tools_agent_obj_;
bool loaded_;
Vector<std::string> pending_incoming_messages_;
- v8::Persistent<v8::FunctionTemplate> host_template_;
- v8::Persistent<v8::External> v8_this_;
+ OwnPtr<BoundObject> dev_tools_host_;
DISALLOW_COPY_AND_ASSIGN(WebDevToolsClientImpl);
};
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index 749d659..718c91c 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -46,7 +46,6 @@ MSVC_POP_WARNING();
#endif
#include "webkit/glue/autofill_form.h"
#include "webkit/glue/alt_404_page_resource_fetcher.h"
-#include "webkit/glue/devtools/net_agent_impl.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/password_form_dom_manager.h"
#include "webkit/glue/plugins/plugin_list.h"
@@ -181,10 +180,6 @@ void WebFrameLoaderClient::assignIdentifierToInitialRequest(
WebRequestImpl webreq(request);
d->AssignIdentifierToRequest(webview, identifier, webreq);
}
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->AssignIdentifierToRequest(loader, identifier, request);
- }
}
// Determines whether the request being loaded by |loader| is a frame or a
@@ -233,10 +228,6 @@ void WebFrameLoaderClient::dispatchWillSendRequest(
d->WillSendRequest(webview, identifier, &webreq);
request = webreq.resource_request();
}
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->WillSendRequest(loader, identifier, request);
- }
request.setAppCacheContextID(
webframe_->GetAppCacheContext()->GetContextID());
@@ -304,21 +295,12 @@ void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader,
// Cancel any pending loads.
alt_404_page_fetcher_.reset(NULL);
-
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->DidReceiveResponse(loader, identifier, response);
- }
}
void WebFrameLoaderClient::dispatchDidReceiveContentLength(
DocumentLoader* loader,
unsigned long identifier,
int length_received) {
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->DidReceiveContentLength(loader, identifier, length_received);
- }
}
// Called when a particular resource load completes
@@ -338,11 +320,6 @@ void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader,
WebViewDelegate* d = webview->delegate();
if (d)
d->DidFinishLoading(webview, identifier);
-
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->DidFinishLoading(loader, identifier);
- }
}
GURL WebFrameLoaderClient::GetAlt404PageUrl(DocumentLoader* loader) {
@@ -384,10 +361,6 @@ void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader,
webview->delegate()->DidFailLoadingWithError(webview, identifier,
WebErrorImpl(error));
}
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->DidFailLoading(loader, identifier, error);
- }
}
void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() {
@@ -451,26 +424,12 @@ bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(
result = d->DidLoadResourceFromMemoryCache(webview, webreq, webresp,
webframe_);
}
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->DidLoadResourceFromMemoryCache(
- loader,
- request,
- response,
- length);
- }
return result;
}
void WebFrameLoaderClient::dispatchDidLoadResourceByXMLHttpRequest(
unsigned long identifier,
const ScriptString& source) {
- NetAgentImpl* net_agent = GetNetAgentImpl();
- if (net_agent) {
- net_agent->DidLoadResourceByXMLHttpRequest(
- identifier,
- source);
- }
}
void WebFrameLoaderClient::dispatchDidHandleOnloadEvents() {
@@ -1643,16 +1602,3 @@ void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) {
if (d)
d->NavigateBackForwardSoon(offset);
}
-
-NetAgentImpl* WebFrameLoaderClient::GetNetAgentImpl() {
- WebViewImpl* web_view = webframe_->GetWebViewImpl();
- if (!web_view) {
- return NULL;
- }
- WebDevToolsAgentImpl* tools_agent = web_view->GetWebDevToolsAgentImpl();
- if (tools_agent) {
- return tools_agent->net_agent_impl();
- } else {
- return NULL;
- }
-}
diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h
index f616aee..e49dc41 100644
--- a/webkit/glue/webframeloaderclient_impl.h
+++ b/webkit/glue/webframeloaderclient_impl.h
@@ -26,7 +26,6 @@ class Widget;
}
class Alt404PageResourceFetcher;
-class NetAgentImpl;
class WebFrameImpl;
class WebPluginContainer;
@@ -223,9 +222,6 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
// Called when a dummy back-forward navigation is intercepted.
void HandleBackForwardNavigation(const GURL&);
- // Returns NetAgent instance if network tracking is enabled.
- NetAgentImpl* GetNetAgentImpl();
-
// The WebFrame that owns this object and manages its lifetime. Therefore,
// the web frame object is guaranteed to exist.
WebFrameImpl* webframe_;
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index f26db01..53569ad 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -906,7 +906,6 @@ void WebViewImpl::Close() {
// Do this first to prevent reentrant notifications from being sent to the
// initiator of the close.
delegate_ = NULL;
- devtools_agent_.reset(NULL);
if (page_.get()) {
// Initiate shutdown for the entire frameset. This will cause a lot of
@@ -915,6 +914,9 @@ void WebViewImpl::Close() {
page_->mainFrame()->loader()->frameDetached();
page_.reset();
}
+
+ // Should happen after page_.reset().
+ devtools_agent_.reset(NULL);
Release(); // Balances AddRef from WebView::Create
}