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

Side by Side Diff: third_party/WebKit/Source/core/inspector/MainThreadDebugger.cpp

Issue 1983423002: [DevTools] Move CommandLineAPI querySelector and querySelectorAll to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pass-bind-remote-object
Patch Set: Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 Google Inc. All rights reserved. 2 * Copyright (c) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/inspector/MainThreadDebugger.h" 31 #include "core/inspector/MainThreadDebugger.h"
32 32
33 #include "bindings/core/v8/BindingSecurity.h" 33 #include "bindings/core/v8/BindingSecurity.h"
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScriptController.h" 35 #include "bindings/core/v8/ScriptController.h"
36 #include "bindings/core/v8/V8Node.h"
36 #include "bindings/core/v8/V8Window.h" 37 #include "bindings/core/v8/V8Window.h"
38 #include "core/dom/ContainerNode.h"
39 #include "core/dom/Document.h"
40 #include "core/dom/Element.h"
37 #include "core/dom/ExecutionContext.h" 41 #include "core/dom/ExecutionContext.h"
42 #include "core/dom/StaticNodeList.h"
38 #include "core/frame/FrameConsole.h" 43 #include "core/frame/FrameConsole.h"
39 #include "core/frame/LocalDOMWindow.h" 44 #include "core/frame/LocalDOMWindow.h"
40 #include "core/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
41 #include "core/frame/UseCounter.h" 46 #include "core/frame/UseCounter.h"
42 #include "core/inspector/IdentifiersFactory.h" 47 #include "core/inspector/IdentifiersFactory.h"
43 #include "core/inspector/InspectedFrames.h" 48 #include "core/inspector/InspectedFrames.h"
44 #include "core/inspector/InspectorTaskRunner.h" 49 #include "core/inspector/InspectorTaskRunner.h"
45 #include "core/timing/MemoryInfo.h" 50 #include "core/timing/MemoryInfo.h"
46 #include "core/workers/MainThreadWorkletGlobalScope.h" 51 #include "core/workers/MainThreadWorkletGlobalScope.h"
47 #include "platform/UserGestureIndicator.h" 52 #include "platform/UserGestureIndicator.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 232 }
228 233
229 v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v 8::Local<v8::Context> context, v8::Local<v8::Object> creationContext) 234 v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v 8::Local<v8::Context> context, v8::Local<v8::Object> creationContext)
230 { 235 {
231 ExecutionContext* executionContext = toExecutionContext(context); 236 ExecutionContext* executionContext = toExecutionContext(context);
232 ASSERT_UNUSED(executionContext, executionContext); 237 ASSERT_UNUSED(executionContext, executionContext);
233 ASSERT(executionContext->isDocument()); 238 ASSERT(executionContext->isDocument());
234 return toV8(MemoryInfo::create(), creationContext, isolate); 239 return toV8(MemoryInfo::create(), creationContext, isolate);
235 } 240 }
236 241
242 static void createFunctionProperty(v8::Local<v8::Context> context, v8::Local<v8: :Object> object, const char* name, v8::FunctionCallback callback)
243 {
244 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name);
245 v8::Local<v8::Function> func;
246 if (!v8::Function::New(context, callback).ToLocal(&func))
247 return;
248 func->SetName(funcName);
249 if (!object->Set(context, funcName, func).FromMaybe(false))
250 return;
251 }
252
253 void MainThreadDebugger::willInstallCommandLineAPI(v8::Local<v8::Context> contex t, v8::Local<v8::Object> object)
254 {
255 createFunctionProperty(context, object, "$", MainThreadDebugger::querySelect orCallback);
256 createFunctionProperty(context, object, "$$", MainThreadDebugger::querySelec torAllCallback);
257 }
258
259 static Node* secondArgumentAsNode(const v8::FunctionCallbackInfo<v8::Value>& inf o)
260 {
261 if (info.Length() < 2) {
262 ExecutionContext* executionContext = toExecutionContext(info.GetIsolate( )->GetCurrentContext());
263 if (executionContext->isDocument())
264 return toDocument(executionContext);
265 } else {
266 return V8Node::toImplWithTypeCheck(info.GetIsolate(), info[1]);
267 }
268 return nullptr;
269 }
270
271 void MainThreadDebugger::querySelectorCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info)
272 {
273 if (info.Length() < 1)
274 return;
275 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]);
276 if (selector.isEmpty())
277 return;
278 Node* node = secondArgumentAsNode(info);
279 if (!node || !node->isContainerNode())
280 return;
281 if (Element* element = toContainerNode(node)->querySelector(AtomicString(sel ector), IGNORE_EXCEPTION))
282 info.GetReturnValue().Set(toV8(static_cast<Node*>(element), info.Holder( ), info.GetIsolate()));
dgozman 2016/05/18 01:51:26 I think static_cast is redundant.
kozy 2016/05/18 02:18:56 Removed.
283 }
284
285 void MainThreadDebugger::querySelectorAllCallback(const v8::FunctionCallbackInfo <v8::Value>& info)
286 {
287 if (info.Length() < 1)
288 return;
289 String selector = toCoreStringWithUndefinedOrNullCheck(info[0]);
290 if (selector.isEmpty())
291 return;
292 Node* node = secondArgumentAsNode(info);
293 if (!node || !node->isContainerNode())
294 return;
295 StaticElementList* elementList = toContainerNode(node)->querySelectorAll(Ato micString(selector), IGNORE_EXCEPTION);
dgozman 2016/05/18 01:51:26 // toV8(elementList) doesn't work here, since we n
kozy 2016/05/18 02:18:56 Done.
296 v8::Isolate* isolate = info.GetIsolate();
297 v8::Local<v8::Context> context = isolate->GetCurrentContext();
298 v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length());
299 for (size_t i = 0; i < elementList->length(); ++i) {
300 Element* element = elementList->item(i);
301 if (!nodes->Set(context, i, toV8(static_cast<Node*>(element), info.Holde r(), info.GetIsolate())).FromMaybe(false))
302 return;
303 }
304 info.GetReturnValue().Set(nodes);
305 }
306
237 } // namespace blink 307 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698