| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "Document.h" | 9 #include "Document.h" |
| 10 #include "EventListener.h" | 10 #include "EventListener.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "webkit/glue/weburlrequest.h" | 28 #include "webkit/glue/weburlrequest.h" |
| 29 #include "webkit/glue/webview_impl.h" | 29 #include "webkit/glue/webview_impl.h" |
| 30 | 30 |
| 31 using WebCore::Document; | 31 using WebCore::Document; |
| 32 using WebCore::InspectorController; | 32 using WebCore::InspectorController; |
| 33 using WebCore::Node; | 33 using WebCore::Node; |
| 34 using WebCore::Page; | 34 using WebCore::Page; |
| 35 using WebCore::ScriptValue; | 35 using WebCore::ScriptValue; |
| 36 using WebCore::String; | 36 using WebCore::String; |
| 37 | 37 |
| 38 // Maximum size of the console message cache. |
| 39 static const size_t kMaxConsoleMessages = 200; |
| 40 |
| 38 WebDevToolsAgentImpl::WebDevToolsAgentImpl( | 41 WebDevToolsAgentImpl::WebDevToolsAgentImpl( |
| 39 WebViewImpl* web_view_impl, | 42 WebViewImpl* web_view_impl, |
| 40 WebDevToolsAgentDelegate* delegate) | 43 WebDevToolsAgentDelegate* delegate) |
| 41 : delegate_(delegate), | 44 : delegate_(delegate), |
| 42 web_view_impl_(web_view_impl), | 45 web_view_impl_(web_view_impl), |
| 43 document_(NULL), | 46 document_(NULL), |
| 44 attached_(false) { | 47 attached_(false) { |
| 45 debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this)); | 48 debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this)); |
| 46 dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this)); | 49 dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this)); |
| 47 net_agent_delegate_stub_.set(new NetAgentDelegateStub(this)); | 50 net_agent_delegate_stub_.set(new NetAgentDelegateStub(this)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 | 65 |
| 63 // We are potentially attaching to the running page -> init agents with | 66 // We are potentially attaching to the running page -> init agents with |
| 64 // Document if any. | 67 // Document if any. |
| 65 Page* page = web_view_impl_->page(); | 68 Page* page = web_view_impl_->page(); |
| 66 Document* doc = page->mainFrame()->document(); | 69 Document* doc = page->mainFrame()->document(); |
| 67 if (doc) { | 70 if (doc) { |
| 68 debugger_agent_impl_->SetDocument(doc); | 71 debugger_agent_impl_->SetDocument(doc); |
| 69 dom_agent_impl_->SetDocument(doc, true); | 72 dom_agent_impl_->SetDocument(doc, true); |
| 70 net_agent_impl_->SetDocument(doc); | 73 net_agent_impl_->SetDocument(doc); |
| 71 } | 74 } |
| 75 |
| 76 // Populate console. |
| 77 for (Vector<ConsoleMessage>::iterator it = console_log_.begin(); |
| 78 it != console_log_.end(); ++it) { |
| 79 tools_agent_delegate_stub_->AddMessageToConsole( |
| 80 it->message, |
| 81 it->source_id, |
| 82 it->line_no); |
| 83 } |
| 84 |
| 72 attached_ = true; | 85 attached_ = true; |
| 73 } | 86 } |
| 74 | 87 |
| 75 void WebDevToolsAgentImpl::Detach() { | 88 void WebDevToolsAgentImpl::Detach() { |
| 76 debugger_agent_impl_.set(NULL); | 89 debugger_agent_impl_.set(NULL); |
| 77 dom_agent_impl_.set(NULL); | 90 dom_agent_impl_.set(NULL); |
| 78 net_agent_impl_.set(NULL); | 91 net_agent_impl_.set(NULL); |
| 79 attached_ = false; | 92 attached_ = false; |
| 80 } | 93 } |
| 81 | 94 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 107 WebDataSource* ds = frame->GetDataSource(); | 120 WebDataSource* ds = frame->GetDataSource(); |
| 108 const WebRequest& request = ds->GetRequest(); | 121 const WebRequest& request = ds->GetRequest(); |
| 109 GURL url = ds->HasUnreachableURL() ? | 122 GURL url = ds->HasUnreachableURL() ? |
| 110 ds->GetUnreachableURL() : | 123 ds->GetUnreachableURL() : |
| 111 request.GetURL(); | 124 request.GetURL(); |
| 112 tools_agent_delegate_stub_->FrameNavigate( | 125 tools_agent_delegate_stub_->FrameNavigate( |
| 113 url.possibly_invalid_spec(), | 126 url.possibly_invalid_spec(), |
| 114 webview->GetMainFrame() == frame); | 127 webview->GetMainFrame() == frame); |
| 115 } | 128 } |
| 116 | 129 |
| 130 void WebDevToolsAgentImpl::AddMessageToConsole( |
| 131 const String& message, |
| 132 const String& source_id, |
| 133 unsigned int line_no) { |
| 134 ConsoleMessage cm(message, source_id, line_no); |
| 135 console_log_.append(cm); |
| 136 if (console_log_.size() >= kMaxConsoleMessages) { |
| 137 // Batch shifts to save ticks. |
| 138 console_log_.remove(0, kMaxConsoleMessages / 5); |
| 139 } |
| 140 if (attached_) { |
| 141 tools_agent_delegate_stub_->AddMessageToConsole( |
| 142 message, |
| 143 source_id, |
| 144 line_no); |
| 145 } |
| 146 } |
| 147 |
| 117 void WebDevToolsAgentImpl::HighlightDOMNode(int node_id) { | 148 void WebDevToolsAgentImpl::HighlightDOMNode(int node_id) { |
| 118 if (!attached_) { | 149 if (!attached_) { |
| 119 return; | 150 return; |
| 120 } | 151 } |
| 121 Node* node = dom_agent_impl_->GetNodeForId(node_id); | 152 Node* node = dom_agent_impl_->GetNodeForId(node_id); |
| 122 if (!node) { | 153 if (!node) { |
| 123 return; | 154 return; |
| 124 } | 155 } |
| 125 Page* page = web_view_impl_->page(); | 156 Page* page = web_view_impl_->page(); |
| 126 page->inspectorController()->highlight(node); | 157 page->inspectorController()->highlight(node); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 152 Node* node = dom_agent_impl_->GetNodeForId(node_id); | 183 Node* node = dom_agent_impl_->GetNodeForId(node_id); |
| 153 String result; | 184 String result; |
| 154 if (node) { | 185 if (node) { |
| 155 result = debugger_agent_impl_->ExecuteUtilityFunction(function_name, node, | 186 result = debugger_agent_impl_->ExecuteUtilityFunction(function_name, node, |
| 156 json_args); | 187 json_args); |
| 157 } | 188 } |
| 158 tools_agent_delegate_stub_->DidExecuteUtilityFunction(call_id, | 189 tools_agent_delegate_stub_->DidExecuteUtilityFunction(call_id, |
| 159 result); | 190 result); |
| 160 } | 191 } |
| 161 | 192 |
| 193 void WebDevToolsAgentImpl::ClearConsoleMessages() { |
| 194 console_log_.clear(); |
| 195 } |
| 196 |
| 162 void WebDevToolsAgentImpl::DispatchMessageFromClient( | 197 void WebDevToolsAgentImpl::DispatchMessageFromClient( |
| 163 const std::string& raw_msg) { | 198 const std::string& raw_msg) { |
| 164 OwnPtr<ListValue> message( | 199 OwnPtr<ListValue> message( |
| 165 static_cast<ListValue*>(DevToolsRpc::ParseMessage(raw_msg))); | 200 static_cast<ListValue*>(DevToolsRpc::ParseMessage(raw_msg))); |
| 166 if (ToolsAgentDispatch::Dispatch(this, *message.get())) { | 201 if (ToolsAgentDispatch::Dispatch(this, *message.get())) { |
| 167 return; | 202 return; |
| 168 } | 203 } |
| 169 | 204 |
| 170 if (!attached_) { | 205 if (!attached_) { |
| 171 return; | 206 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 197 } | 232 } |
| 198 | 233 |
| 199 void WebDevToolsAgentImpl::SendRpcMessage(const std::string& raw_msg) { | 234 void WebDevToolsAgentImpl::SendRpcMessage(const std::string& raw_msg) { |
| 200 delegate_->SendMessageToClient(raw_msg); | 235 delegate_->SendMessageToClient(raw_msg); |
| 201 } | 236 } |
| 202 | 237 |
| 203 // static | 238 // static |
| 204 void WebDevToolsAgent::ExecuteDebuggerCommand(const std::string& command) { | 239 void WebDevToolsAgent::ExecuteDebuggerCommand(const std::string& command) { |
| 205 DebuggerAgentManager::ExecuteDebuggerCommand(command); | 240 DebuggerAgentManager::ExecuteDebuggerCommand(command); |
| 206 } | 241 } |
| OLD | NEW |