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

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

Issue 2251343003: [DevTools] Generate separate copies of inspector_protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 20 matching lines...) Expand all
31 #include "core/inspector/InspectorDOMDebuggerAgent.h" 31 #include "core/inspector/InspectorDOMDebuggerAgent.h"
32 32
33 #include "bindings/core/v8/ScriptEventListener.h" 33 #include "bindings/core/v8/ScriptEventListener.h"
34 #include "bindings/core/v8/V8EventTarget.h" 34 #include "bindings/core/v8/V8EventTarget.h"
35 #include "core/dom/Element.h" 35 #include "core/dom/Element.h"
36 #include "core/dom/Node.h" 36 #include "core/dom/Node.h"
37 #include "core/events/Event.h" 37 #include "core/events/Event.h"
38 #include "core/events/EventTarget.h" 38 #include "core/events/EventTarget.h"
39 #include "core/frame/LocalDOMWindow.h" 39 #include "core/frame/LocalDOMWindow.h"
40 #include "core/inspector/InspectorDOMAgent.h" 40 #include "core/inspector/InspectorDOMAgent.h"
41 #include "core/inspector/V8InspectorStringConversion.h"
41 #include "platform/v8_inspector/public/V8InspectorSession.h" 42 #include "platform/v8_inspector/public/V8InspectorSession.h"
42 43
43 namespace { 44 namespace {
44 45
45 enum DOMBreakpointType { 46 enum DOMBreakpointType {
46 SubtreeModified = 0, 47 SubtreeModified = 0,
47 AttributeModified, 48 AttributeModified,
48 NodeRemoved, 49 NodeRemoved,
49 DOMBreakpointTypesCount 50 DOMBreakpointTypesCount
50 }; 51 };
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 else 303 else
303 breakpointsByTarget->remove(targetName.lower()); 304 breakpointsByTarget->remove(targetName.lower());
304 didRemoveBreakpoint(); 305 didRemoveBreakpoint();
305 } 306 }
306 307
307 void InspectorDOMDebuggerAgent::didInvalidateStyleAttr(Node* node) 308 void InspectorDOMDebuggerAgent::didInvalidateStyleAttr(Node* node)
308 { 309 {
309 if (hasBreakpoint(node, AttributeModified)) { 310 if (hasBreakpoint(node, AttributeModified)) {
310 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create(); 311 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create();
311 descriptionForDOMEvent(node, AttributeModified, false, eventData.get()); 312 descriptionForDOMEvent(node, AttributeModified, false, eventData.get());
312 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::D OM, eventData->toJSONString()); 313 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused: :ReasonEnum::DOM, toV8InspectorString(eventData->toJSONString()));
313 } 314 }
314 } 315 }
315 316
316 void InspectorDOMDebuggerAgent::didInsertDOMNode(Node* node) 317 void InspectorDOMDebuggerAgent::didInsertDOMNode(Node* node)
317 { 318 {
318 if (m_domBreakpoints.size()) { 319 if (m_domBreakpoints.size()) {
319 uint32_t mask = m_domBreakpoints.get(InspectorDOMAgent::innerParentNode( node)); 320 uint32_t mask = m_domBreakpoints.get(InspectorDOMAgent::innerParentNode( node));
320 uint32_t inheritableTypesMask = (mask | (mask >> domBreakpointDerivedTyp eShift)) & inheritableDOMBreakpointTypesMask; 321 uint32_t inheritableTypesMask = (mask | (mask >> domBreakpointDerivedTyp eShift)) & inheritableDOMBreakpointTypesMask;
321 if (inheritableTypesMask) 322 if (inheritableTypesMask)
322 updateSubtreeBreakpoints(node, inheritableTypesMask, true); 323 updateSubtreeBreakpoints(node, inheritableTypesMask, true);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 updateSubtreeBreakpoints(child, rootBit, false); 405 updateSubtreeBreakpoints(child, rootBit, false);
405 } 406 }
406 didRemoveBreakpoint(); 407 didRemoveBreakpoint();
407 } 408 }
408 409
409 void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, cons t String& objectId, std::unique_ptr<protocol::Array<protocol::DOMDebugger::Event Listener>>* listenersArray) 410 void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, cons t String& objectId, std::unique_ptr<protocol::Array<protocol::DOMDebugger::Event Listener>>* listenersArray)
410 { 411 {
411 v8::HandleScope handles(m_isolate); 412 v8::HandleScope handles(m_isolate);
412 v8::Local<v8::Value> value; 413 v8::Local<v8::Value> value;
413 v8::Local<v8::Context> context; 414 v8::Local<v8::Context> context;
414 String16 objectGroup; 415 v8_inspector::String16 objectGroup;
415 if (!m_v8Session->unwrapObject(errorString, objectId, &value, &context, &obj ectGroup)) 416 v8_inspector::String16 error;
417 if (!m_v8Session->unwrapObject(&error, toV8InspectorString(objectId), &value , &context, &objectGroup)) {
418 *errorString = toCoreString(error);
416 return; 419 return;
420 }
417 v8::Context::Scope scope(context); 421 v8::Context::Scope scope(context);
418 *listenersArray = protocol::Array<protocol::DOMDebugger::EventListener>::cre ate(); 422 *listenersArray = protocol::Array<protocol::DOMDebugger::EventListener>::cre ate();
419 eventListeners(context, value, objectGroup, listenersArray->get()); 423 eventListeners(context, value, toCoreString(objectGroup), listenersArray->ge t());
420 } 424 }
421 425
422 void InspectorDOMDebuggerAgent::eventListeners(v8::Local<v8::Context> context, v 8::Local<v8::Value> object, const String16& objectGroup, protocol::Array<protoco l::DOMDebugger::EventListener>* listenersArray) 426 void InspectorDOMDebuggerAgent::eventListeners(v8::Local<v8::Context> context, v 8::Local<v8::Value> object, const String& objectGroup, protocol::Array<protocol: :DOMDebugger::EventListener>* listenersArray)
423 { 427 {
424 V8EventListenerInfoList eventInformation; 428 V8EventListenerInfoList eventInformation;
425 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(context->GetIsolate() , object, eventInformation); 429 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(context->GetIsolate() , object, eventInformation);
426 for (const auto& info : eventInformation) { 430 for (const auto& info : eventInformation) {
427 if (!info.useCapture) 431 if (!info.useCapture)
428 continue; 432 continue;
429 std::unique_ptr<protocol::DOMDebugger::EventListener> listenerObject = b uildObjectForEventListener(context, info, objectGroup); 433 std::unique_ptr<protocol::DOMDebugger::EventListener> listenerObject = b uildObjectForEventListener(context, info, objectGroup);
430 if (listenerObject) 434 if (listenerObject)
431 listenersArray->addItem(std::move(listenerObject)); 435 listenersArray->addItem(std::move(listenerObject));
432 } 436 }
433 for (const auto& info : eventInformation) { 437 for (const auto& info : eventInformation) {
434 if (info.useCapture) 438 if (info.useCapture)
435 continue; 439 continue;
436 std::unique_ptr<protocol::DOMDebugger::EventListener> listenerObject = b uildObjectForEventListener(context, info, objectGroup); 440 std::unique_ptr<protocol::DOMDebugger::EventListener> listenerObject = b uildObjectForEventListener(context, info, objectGroup);
437 if (listenerObject) 441 if (listenerObject)
438 listenersArray->addItem(std::move(listenerObject)); 442 listenersArray->addItem(std::move(listenerObject));
439 } 443 }
440 } 444 }
441 445
442 std::unique_ptr<protocol::DOMDebugger::EventListener> InspectorDOMDebuggerAgent: :buildObjectForEventListener(v8::Local<v8::Context> context, const V8EventListen erInfo& info, const String16& objectGroupId) 446 std::unique_ptr<protocol::DOMDebugger::EventListener> InspectorDOMDebuggerAgent: :buildObjectForEventListener(v8::Local<v8::Context> context, const V8EventListen erInfo& info, const String& objectGroupId)
443 { 447 {
444 if (info.handler.IsEmpty()) 448 if (info.handler.IsEmpty())
445 return nullptr; 449 return nullptr;
446 450
447 v8::Isolate* isolate = context->GetIsolate(); 451 v8::Isolate* isolate = context->GetIsolate();
448 v8::Local<v8::Function> function = eventListenerEffectiveFunction(isolate, i nfo.handler); 452 v8::Local<v8::Function> function = eventListenerEffectiveFunction(isolate, i nfo.handler);
449 if (function.IsEmpty()) 453 if (function.IsEmpty())
450 return nullptr; 454 return nullptr;
451 455
452 String scriptId; 456 String scriptId;
453 int lineNumber; 457 int lineNumber;
454 int columnNumber; 458 int columnNumber;
455 getFunctionLocation(function, scriptId, lineNumber, columnNumber); 459 getFunctionLocation(function, scriptId, lineNumber, columnNumber);
456 460
457 std::unique_ptr<protocol::DOMDebugger::EventListener> value = protocol::DOMD ebugger::EventListener::create() 461 std::unique_ptr<protocol::DOMDebugger::EventListener> value = protocol::DOMD ebugger::EventListener::create()
458 .setType(info.eventType) 462 .setType(info.eventType)
459 .setUseCapture(info.useCapture) 463 .setUseCapture(info.useCapture)
460 .setPassive(info.passive) 464 .setPassive(info.passive)
461 .setScriptId(scriptId) 465 .setScriptId(scriptId)
462 .setLineNumber(lineNumber) 466 .setLineNumber(lineNumber)
463 .setColumnNumber(columnNumber).build(); 467 .setColumnNumber(columnNumber).build();
464 if (!objectGroupId.isEmpty()) { 468 if (!objectGroupId.isEmpty()) {
465 value->setHandler(m_v8Session->wrapObject(context, function, objectGroup Id)); 469 value->setHandler(m_v8Session->wrapObject(context, function, toV8Inspect orString(objectGroupId)));
466 value->setOriginalHandler(m_v8Session->wrapObject(context, info.handler, objectGroupId)); 470 value->setOriginalHandler(m_v8Session->wrapObject(context, info.handler, toV8InspectorString(objectGroupId)));
467 v8::Local<v8::Function> removeFunction; 471 v8::Local<v8::Function> removeFunction;
468 if (info.removeFunction.ToLocal(&removeFunction)) 472 if (info.removeFunction.ToLocal(&removeFunction))
469 value->setRemoveFunction(m_v8Session->wrapObject(context, removeFunc tion, objectGroupId)); 473 value->setRemoveFunction(m_v8Session->wrapObject(context, removeFunc tion, toV8InspectorString(objectGroupId)));
470 } 474 }
471 return value; 475 return value;
472 } 476 }
473 477
474 void InspectorDOMDebuggerAgent::allowNativeBreakpoint(const String& breakpointNa me, const String* targetName, bool sync) 478 void InspectorDOMDebuggerAgent::allowNativeBreakpoint(const String& breakpointNa me, const String* targetName, bool sync)
475 { 479 {
476 pauseOnNativeEventIfNeeded(preparePauseOnNativeEventData(breakpointName, tar getName), sync); 480 pauseOnNativeEventIfNeeded(preparePauseOnNativeEventData(breakpointName, tar getName), sync);
477 } 481 }
478 482
479 void InspectorDOMDebuggerAgent::willInsertDOMNode(Node* parent) 483 void InspectorDOMDebuggerAgent::willInsertDOMNode(Node* parent)
480 { 484 {
481 if (hasBreakpoint(parent, SubtreeModified)) { 485 if (hasBreakpoint(parent, SubtreeModified)) {
482 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create(); 486 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create();
483 descriptionForDOMEvent(parent, SubtreeModified, true, eventData.get()); 487 descriptionForDOMEvent(parent, SubtreeModified, true, eventData.get());
484 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::D OM, eventData->toJSONString()); 488 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused: :ReasonEnum::DOM, toV8InspectorString(eventData->toJSONString()));
485 } 489 }
486 } 490 }
487 491
488 void InspectorDOMDebuggerAgent::willRemoveDOMNode(Node* node) 492 void InspectorDOMDebuggerAgent::willRemoveDOMNode(Node* node)
489 { 493 {
490 Node* parentNode = InspectorDOMAgent::innerParentNode(node); 494 Node* parentNode = InspectorDOMAgent::innerParentNode(node);
491 if (hasBreakpoint(node, NodeRemoved)) { 495 if (hasBreakpoint(node, NodeRemoved)) {
492 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create(); 496 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create();
493 descriptionForDOMEvent(node, NodeRemoved, false, eventData.get()); 497 descriptionForDOMEvent(node, NodeRemoved, false, eventData.get());
494 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::D OM, eventData->toJSONString()); 498 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused: :ReasonEnum::DOM, toV8InspectorString(eventData->toJSONString()));
495 } else if (parentNode && hasBreakpoint(parentNode, SubtreeModified)) { 499 } else if (parentNode && hasBreakpoint(parentNode, SubtreeModified)) {
496 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create(); 500 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create();
497 descriptionForDOMEvent(node, SubtreeModified, false, eventData.get()); 501 descriptionForDOMEvent(node, SubtreeModified, false, eventData.get());
498 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::D OM, eventData->toJSONString()); 502 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused: :ReasonEnum::DOM, toV8InspectorString(eventData->toJSONString()));
499 } 503 }
500 didRemoveDOMNode(node); 504 didRemoveDOMNode(node);
501 } 505 }
502 506
503 void InspectorDOMDebuggerAgent::willModifyDOMAttr(Element* element, const Atomic String&, const AtomicString&) 507 void InspectorDOMDebuggerAgent::willModifyDOMAttr(Element* element, const Atomic String&, const AtomicString&)
504 { 508 {
505 if (hasBreakpoint(element, AttributeModified)) { 509 if (hasBreakpoint(element, AttributeModified)) {
506 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create(); 510 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::Diction aryValue::create();
507 descriptionForDOMEvent(element, AttributeModified, false, eventData.get( )); 511 descriptionForDOMEvent(element, AttributeModified, false, eventData.get( ));
508 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::D OM, eventData->toJSONString()); 512 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused: :ReasonEnum::DOM, toV8InspectorString(eventData->toJSONString()));
509 } 513 }
510 } 514 }
511 515
512 void InspectorDOMDebuggerAgent::descriptionForDOMEvent(Node* target, int breakpo intType, bool insertion, protocol::DictionaryValue* description) 516 void InspectorDOMDebuggerAgent::descriptionForDOMEvent(Node* target, int breakpo intType, bool insertion, protocol::DictionaryValue* description)
513 { 517 {
514 ASSERT(hasBreakpoint(target, breakpointType)); 518 ASSERT(hasBreakpoint(target, breakpointType));
515 519
516 Node* breakpointOwner = target; 520 Node* breakpointOwner = target;
517 if ((1 << breakpointType) & inheritableDOMBreakpointTypesMask) { 521 if ((1 << breakpointType) & inheritableDOMBreakpointTypesMask) {
518 // For inheritable breakpoint types, target node isn't always the same a s the node that owns a breakpoint. 522 // For inheritable breakpoint types, target node isn't always the same a s the node that owns a breakpoint.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 569
566 for (Node* child = InspectorDOMAgent::innerFirstChild(node); child; child = InspectorDOMAgent::innerNextSibling(child)) 570 for (Node* child = InspectorDOMAgent::innerFirstChild(node); child; child = InspectorDOMAgent::innerNextSibling(child))
567 updateSubtreeBreakpoints(child, newRootMask, set); 571 updateSubtreeBreakpoints(child, newRootMask, set);
568 } 572 }
569 573
570 void InspectorDOMDebuggerAgent::pauseOnNativeEventIfNeeded(std::unique_ptr<proto col::DictionaryValue> eventData, bool synchronous) 574 void InspectorDOMDebuggerAgent::pauseOnNativeEventIfNeeded(std::unique_ptr<proto col::DictionaryValue> eventData, bool synchronous)
571 { 575 {
572 if (!eventData) 576 if (!eventData)
573 return; 577 return;
574 if (synchronous) 578 if (synchronous)
575 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::E ventListener, eventData->toJSONString()); 579 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused: :ReasonEnum::EventListener, toV8InspectorString(eventData->toJSONString()));
576 else 580 else
577 m_v8Session->schedulePauseOnNextStatement(protocol::Debugger::API::Pause d::ReasonEnum::EventListener, eventData->toJSONString()); 581 m_v8Session->schedulePauseOnNextStatement(v8_inspector::protocol::Debugg er::API::Paused::ReasonEnum::EventListener, toV8InspectorString(eventData->toJSO NString()));
578 } 582 }
579 583
580 std::unique_ptr<protocol::DictionaryValue> InspectorDOMDebuggerAgent::preparePau seOnNativeEventData(const String& eventName, const String* targetName) 584 std::unique_ptr<protocol::DictionaryValue> InspectorDOMDebuggerAgent::preparePau seOnNativeEventData(const String& eventName, const String* targetName)
581 { 585 {
582 String fullEventName = (targetName ? listenerEventCategoryType : instrumenta tionEventCategoryType) + eventName; 586 String fullEventName = (targetName ? listenerEventCategoryType : instrumenta tionEventCategoryType) + eventName;
583 protocol::DictionaryValue* breakpoints = eventListenerBreakpoints(); 587 protocol::DictionaryValue* breakpoints = eventListenerBreakpoints();
584 protocol::Value* value = breakpoints->get(fullEventName); 588 protocol::Value* value = breakpoints->get(fullEventName);
585 if (!value) 589 if (!value)
586 return nullptr; 590 return nullptr;
587 bool match = false; 591 bool match = false;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 673 }
670 } 674 }
671 } 675 }
672 676
673 if (breakpointURL.isNull()) 677 if (breakpointURL.isNull())
674 return; 678 return;
675 679
676 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::DictionaryV alue::create(); 680 std::unique_ptr<protocol::DictionaryValue> eventData = protocol::DictionaryV alue::create();
677 eventData->setString("breakpointURL", breakpointURL); 681 eventData->setString("breakpointURL", breakpointURL);
678 eventData->setString("url", url); 682 eventData->setString("url", url);
679 m_v8Session->breakProgram(protocol::Debugger::API::Paused::ReasonEnum::XHR, eventData->toJSONString()); 683 m_v8Session->breakProgram(v8_inspector::protocol::Debugger::API::Paused::Rea sonEnum::XHR, toV8InspectorString(eventData->toJSONString()));
caseq 2016/08/19 02:50:36 It's seventh time we're invoking breakProgram here
680 } 684 }
681 685
682 void InspectorDOMDebuggerAgent::didAddBreakpoint() 686 void InspectorDOMDebuggerAgent::didAddBreakpoint()
683 { 687 {
684 if (m_state->booleanProperty(DOMDebuggerAgentState::enabled, false)) 688 if (m_state->booleanProperty(DOMDebuggerAgentState::enabled, false))
685 return; 689 return;
686 setEnabled(true); 690 setEnabled(true);
687 } 691 }
688 692
689 void InspectorDOMDebuggerAgent::didRemoveBreakpoint() 693 void InspectorDOMDebuggerAgent::didRemoveBreakpoint()
(...skipping 19 matching lines...) Expand all
709 m_instrumentingAgents->removeInspectorDOMDebuggerAgent(this); 713 m_instrumentingAgents->removeInspectorDOMDebuggerAgent(this);
710 } 714 }
711 } 715 }
712 716
713 void InspectorDOMDebuggerAgent::didCommitLoadForLocalFrame(LocalFrame*) 717 void InspectorDOMDebuggerAgent::didCommitLoadForLocalFrame(LocalFrame*)
714 { 718 {
715 m_domBreakpoints.clear(); 719 m_domBreakpoints.clear();
716 } 720 }
717 721
718 } // namespace blink 722 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698