Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Side by Side Diff: webkit/glue/webdevtoolsclient_impl.cc

Issue 264077: Convert devtools interfaces over to using WebString.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webdevtoolsclient_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "DOMWindow.h" 10 #include "DOMWindow.h"
(...skipping 23 matching lines...) Expand all
34 #include "webkit/glue/glue_util.h" 34 #include "webkit/glue/glue_util.h"
35 #include "webkit/glue/webdevtoolsclient_delegate.h" 35 #include "webkit/glue/webdevtoolsclient_delegate.h"
36 #include "webkit/glue/webdevtoolsclient_impl.h" 36 #include "webkit/glue/webdevtoolsclient_impl.h"
37 #include "webkit/glue/webview_impl.h" 37 #include "webkit/glue/webview_impl.h"
38 38
39 using namespace WebCore; 39 using namespace WebCore;
40 using WebKit::WebFrame; 40 using WebKit::WebFrame;
41 using WebKit::WebScriptSource; 41 using WebKit::WebScriptSource;
42 using WebKit::WebString; 42 using WebKit::WebString;
43 43
44 static v8::Local<v8::String> ToV8String(const String& s) {
45 if (s.isNull())
46 return v8::Local<v8::String>();
47
48 return v8::String::New(reinterpret_cast<const uint16_t*>(s.characters()),
49 s.length());
50 }
51
44 DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT, 52 DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT,
45 DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) 53 DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT)
46 DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT, 54 DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT,
47 ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) 55 ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT)
48 56
49 class ToolsAgentNativeDelegateImpl : public ToolsAgentNativeDelegate { 57 class ToolsAgentNativeDelegateImpl : public ToolsAgentNativeDelegate {
50 public: 58 public:
51 struct ResourceContentRequestData { 59 struct ResourceContentRequestData {
52 String mime_type; 60 String mime_type;
53 RefPtr<Node> frame; 61 RefPtr<Node> frame;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 private: 101 private:
94 WebFrameImpl* frame_; 102 WebFrameImpl* frame_;
95 HashMap<int, ResourceContentRequestData> resource_content_requests_; 103 HashMap<int, ResourceContentRequestData> resource_content_requests_;
96 DISALLOW_COPY_AND_ASSIGN(ToolsAgentNativeDelegateImpl); 104 DISALLOW_COPY_AND_ASSIGN(ToolsAgentNativeDelegateImpl);
97 }; 105 };
98 106
99 // static 107 // static
100 WebDevToolsClient* WebDevToolsClient::Create( 108 WebDevToolsClient* WebDevToolsClient::Create(
101 WebView* view, 109 WebView* view,
102 WebDevToolsClientDelegate* delegate, 110 WebDevToolsClientDelegate* delegate,
103 const std::string& application_locale) { 111 const WebString& application_locale) {
104 return new WebDevToolsClientImpl(static_cast<WebViewImpl*>(view), 112 return new WebDevToolsClientImpl(
105 delegate, 113 static_cast<WebViewImpl*>(view),
106 application_locale); 114 delegate,
115 webkit_glue::WebStringToString(application_locale));
107 } 116 }
108 117
109 WebDevToolsClientImpl::WebDevToolsClientImpl( 118 WebDevToolsClientImpl::WebDevToolsClientImpl(
110 WebViewImpl* web_view_impl, 119 WebViewImpl* web_view_impl,
111 WebDevToolsClientDelegate* delegate, 120 WebDevToolsClientDelegate* delegate,
112 const std::string& application_locale) 121 const String& application_locale)
113 : web_view_impl_(web_view_impl), 122 : web_view_impl_(web_view_impl),
114 delegate_(delegate), 123 delegate_(delegate),
115 application_locale_(application_locale.c_str()), 124 application_locale_(application_locale),
116 loaded_(false) { 125 loaded_(false) {
117 WebFrameImpl* frame = web_view_impl_->main_frame(); 126 WebFrameImpl* frame = web_view_impl_->main_frame();
118 v8::HandleScope scope; 127 v8::HandleScope scope;
119 v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame()); 128 v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame());
120 129
121 debugger_agent_obj_.set(new JsDebuggerAgentBoundObj( 130 debugger_agent_obj_.set(new JsDebuggerAgentBoundObj(
122 this, frame_context, "RemoteDebuggerAgent")); 131 this, frame_context, "RemoteDebuggerAgent"));
123 tools_agent_obj_.set( 132 tools_agent_obj_.set(
124 new JsToolsAgentBoundObj(this, frame_context, "RemoteToolsAgent")); 133 new JsToolsAgentBoundObj(this, frame_context, "RemoteToolsAgent"));
125 134
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 dev_tools_host_->AddProtoFunction( 180 dev_tools_host_->AddProtoFunction(
172 "hiddenPanels", 181 "hiddenPanels",
173 WebDevToolsClientImpl::JsHiddenPanels); 182 WebDevToolsClientImpl::JsHiddenPanels);
174 dev_tools_host_->Build(); 183 dev_tools_host_->Build();
175 } 184 }
176 185
177 WebDevToolsClientImpl::~WebDevToolsClientImpl() { 186 WebDevToolsClientImpl::~WebDevToolsClientImpl() {
178 } 187 }
179 188
180 void WebDevToolsClientImpl::DispatchMessageFromAgent( 189 void WebDevToolsClientImpl::DispatchMessageFromAgent(
181 const std::string& class_name, 190 const WebString& class_name,
182 const std::string& method_name, 191 const WebString& method_name,
183 const std::string& param1, 192 const WebString& param1,
184 const std::string& param2, 193 const WebString& param2,
185 const std::string& param3) { 194 const WebString& param3) {
186 if (ToolsAgentNativeDelegateDispatch::Dispatch( 195 if (ToolsAgentNativeDelegateDispatch::Dispatch(
187 tools_agent_native_delegate_impl_.get(), 196 tools_agent_native_delegate_impl_.get(),
188 class_name, 197 webkit_glue::WebStringToString(class_name),
189 method_name, 198 webkit_glue::WebStringToString(method_name),
190 param1, 199 webkit_glue::WebStringToString(param1),
191 param2, 200 webkit_glue::WebStringToString(param2),
192 param3)) { 201 webkit_glue::WebStringToString(param3))) {
193 return; 202 return;
194 } 203 }
195 204
196 Vector<std::string> v; 205 Vector<String> v;
197 v.append(class_name); 206 v.append(webkit_glue::WebStringToString(class_name));
198 v.append(method_name); 207 v.append(webkit_glue::WebStringToString(method_name));
199 v.append(param1); 208 v.append(webkit_glue::WebStringToString(param1));
200 v.append(param2); 209 v.append(webkit_glue::WebStringToString(param2));
201 v.append(param3); 210 v.append(webkit_glue::WebStringToString(param3));
202 if (!loaded_) { 211 if (!loaded_) {
203 pending_incoming_messages_.append(v); 212 pending_incoming_messages_.append(v);
204 return; 213 return;
205 } 214 }
206 ExecuteScript(v); 215 ExecuteScript(v);
207 } 216 }
208 217
209 void WebDevToolsClientImpl::AddResourceSourceToFrame(int resource_id, 218 void WebDevToolsClientImpl::AddResourceSourceToFrame(int resource_id,
210 String mime_type, 219 String mime_type,
211 Node* frame) { 220 Node* frame) {
212 if (tools_agent_native_delegate_impl_->WaitingForResponse(resource_id, 221 if (tools_agent_native_delegate_impl_->WaitingForResponse(resource_id,
213 frame)) { 222 frame)) {
214 return; 223 return;
215 } 224 }
216 tools_agent_obj_->GetResourceContent(resource_id, resource_id); 225 tools_agent_obj_->GetResourceContent(resource_id, resource_id);
217 tools_agent_native_delegate_impl_->RequestSent(resource_id, mime_type, frame); 226 tools_agent_native_delegate_impl_->RequestSent(resource_id, mime_type, frame);
218 } 227 }
219 228
220 void WebDevToolsClientImpl::ExecuteScript(const Vector<std::string>& v) { 229 void WebDevToolsClientImpl::ExecuteScript(const Vector<String>& v) {
221 WebFrameImpl* frame = web_view_impl_->main_frame(); 230 WebFrameImpl* frame = web_view_impl_->main_frame();
222 v8::HandleScope scope; 231 v8::HandleScope scope;
223 v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame()); 232 v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame());
224 v8::Context::Scope context_scope(frame_context); 233 v8::Context::Scope context_scope(frame_context);
225 v8::Handle<v8::Value> dispatch_function = 234 v8::Handle<v8::Value> dispatch_function =
226 frame_context->Global()->Get(v8::String::New("devtools$$dispatch")); 235 frame_context->Global()->Get(v8::String::New("devtools$$dispatch"));
227 ASSERT(dispatch_function->IsFunction()); 236 ASSERT(dispatch_function->IsFunction());
228 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatch_fu nction); 237 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatch_fu nction);
229 v8::Handle<v8::Value> args[] = { 238 v8::Handle<v8::Value> args[] = {
230 v8::String::New(v.at(0).c_str()), 239 ToV8String(v.at(0)),
231 v8::String::New(v.at(1).c_str()), 240 ToV8String(v.at(1)),
232 v8::String::New(v.at(2).c_str()), 241 ToV8String(v.at(2)),
233 v8::String::New(v.at(3).c_str()), 242 ToV8String(v.at(3)),
234 v8::String::New(v.at(4).c_str()) 243 ToV8String(v.at(4)),
235 }; 244 };
236 function->Call(frame_context->Global(), 5, args); 245 function->Call(frame_context->Global(), 5, args);
237 } 246 }
238 247
239 void WebDevToolsClientImpl::SendRpcMessage(const std::string& class_name, 248 void WebDevToolsClientImpl::SendRpcMessage(const String& class_name,
240 const std::string& method_name, 249 const String& method_name,
241 const std::string& param1, 250 const String& param1,
242 const std::string& param2, 251 const String& param2,
243 const std::string& param3) { 252 const String& param3) {
244 delegate_->SendMessageToAgent(class_name, method_name, param1, param2, 253 delegate_->SendMessageToAgent(
245 param3); 254 webkit_glue::StringToWebString(class_name),
255 webkit_glue::StringToWebString(method_name),
256 webkit_glue::StringToWebString(param1),
257 webkit_glue::StringToWebString(param2),
258 webkit_glue::StringToWebString(param3));
246 } 259 }
247 260
248 // static 261 // static
249 v8::Handle<v8::Value> WebDevToolsClientImpl::JsReset( 262 v8::Handle<v8::Value> WebDevToolsClientImpl::JsReset(
250 const v8::Arguments& args) { 263 const v8::Arguments& args) {
251 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( 264 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>(
252 v8::External::Cast(*args.Data())->Value()); 265 v8::External::Cast(*args.Data())->Value());
253 WebFrameImpl* frame = client->web_view_impl_->main_frame(); 266 WebFrameImpl* frame = client->web_view_impl_->main_frame();
254 client->tools_agent_native_delegate_impl_.set( 267 client->tools_agent_native_delegate_impl_.set(
255 new ToolsAgentNativeDelegateImpl(frame)); 268 new ToolsAgentNativeDelegateImpl(frame));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 const v8::Arguments& args) { 319 const v8::Arguments& args) {
307 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( 320 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>(
308 v8::External::Cast(*args.Data())->Value()); 321 v8::External::Cast(*args.Data())->Value());
309 client->loaded_ = true; 322 client->loaded_ = true;
310 323
311 // Grant the devtools page the ability to have source view iframes. 324 // Grant the devtools page the ability to have source view iframes.
312 Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); 325 Page* page = V8Proxy::retrieveFrameForEnteredContext()->page();
313 SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin(); 326 SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin();
314 origin->grantUniversalAccess(); 327 origin->grantUniversalAccess();
315 328
316 for (Vector<Vector<std::string> >::iterator it = 329 for (Vector<Vector<String> >::iterator it =
317 client->pending_incoming_messages_.begin(); 330 client->pending_incoming_messages_.begin();
318 it != client->pending_incoming_messages_.end(); 331 it != client->pending_incoming_messages_.end();
319 ++it) { 332 ++it) {
320 client->ExecuteScript(*it); 333 client->ExecuteScript(*it);
321 } 334 }
322 client->pending_incoming_messages_.clear(); 335 client->pending_incoming_messages_.clear();
323 return v8::Undefined(); 336 return v8::Undefined();
324 } 337 }
325 338
326 // static 339 // static
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); 408 Page* page = V8Proxy::retrieveFrameForEnteredContext()->page();
396 return v8String(page->settings()->databasesEnabled() ? "" : "databases"); 409 return v8String(page->settings()->databasesEnabled() ? "" : "databases");
397 } 410 }
398 411
399 // static 412 // static
400 v8::Handle<v8::Value> WebDevToolsClientImpl::JsDebuggerCommand( 413 v8::Handle<v8::Value> WebDevToolsClientImpl::JsDebuggerCommand(
401 const v8::Arguments& args) { 414 const v8::Arguments& args) {
402 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( 415 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>(
403 v8::External::Cast(*args.Data())->Value()); 416 v8::External::Cast(*args.Data())->Value());
404 String command = WebCore::toWebCoreStringWithNullCheck(args[0]); 417 String command = WebCore::toWebCoreStringWithNullCheck(args[0]);
405 std::string std_command = webkit_glue::StringToStdString(command); 418 WebString std_command = webkit_glue::StringToWebString(command);
406 client->delegate_->SendDebuggerCommandToAgent(std_command); 419 client->delegate_->SendDebuggerCommandToAgent(std_command);
407 return v8::Undefined(); 420 return v8::Undefined();
408 } 421 }
OLDNEW
« no previous file with comments | « webkit/glue/webdevtoolsclient_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698