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

Side by Side Diff: Source/core/inspector/InspectorDOMAgent.cpp

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 { 496 {
497 m_backendIdToNode.clear(); 497 m_backendIdToNode.clear();
498 m_nodeGroupToBackendIdMap.clear(); 498 m_nodeGroupToBackendIdMap.clear();
499 } 499 }
500 500
501 int InspectorDOMAgent::pushNodeToFrontend(ErrorString* errorString, int document NodeId, Node* nodeToPush) 501 int InspectorDOMAgent::pushNodeToFrontend(ErrorString* errorString, int document NodeId, Node* nodeToPush)
502 { 502 {
503 Document* document = assertDocument(errorString, documentNodeId); 503 Document* document = assertDocument(errorString, documentNodeId);
504 if (!document) 504 if (!document)
505 return 0; 505 return 0;
506 if (nodeToPush->document() != document) { 506 if (&nodeToPush->document() != document) {
507 *errorString = "Node is not part of the document with given id"; 507 *errorString = "Node is not part of the document with given id";
508 return 0; 508 return 0;
509 } 509 }
510 510
511 return pushNodePathToFrontend(nodeToPush); 511 return pushNodePathToFrontend(nodeToPush);
512 } 512 }
513 513
514 Node* InspectorDOMAgent::nodeForId(int id) 514 Node* InspectorDOMAgent::nodeForId(int id)
515 { 515 {
516 if (!id) 516 if (!id)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 m_domEditor->setAttribute(element, name, value, errorString); 669 m_domEditor->setAttribute(element, name, value, errorString);
670 } 670 }
671 671
672 void InspectorDOMAgent::setAttributesAsText(ErrorString* errorString, int elemen tId, const String& text, const String* const name) 672 void InspectorDOMAgent::setAttributesAsText(ErrorString* errorString, int elemen tId, const String& text, const String* const name)
673 { 673 {
674 Element* element = assertEditableElement(errorString, elementId); 674 Element* element = assertEditableElement(errorString, elementId);
675 if (!element) 675 if (!element)
676 return; 676 return;
677 677
678 String markup = "<span " + text + "></span>"; 678 String markup = "<span " + text + "></span>";
679 RefPtr<DocumentFragment> fragment = element->document()->createDocumentFragm ent(); 679 RefPtr<DocumentFragment> fragment = element->document().createDocumentFragme nt();
680 680
681 bool shouldIgnoreCase = element->document()->isHTMLDocument() && element->is HTMLElement(); 681 bool shouldIgnoreCase = element->document().isHTMLDocument() && element->isH TMLElement();
682 // Not all elements can represent the context (i.e. IFRAME), hence using doc ument.body. 682 // Not all elements can represent the context (i.e. IFRAME), hence using doc ument.body.
683 if (shouldIgnoreCase && element->document()->body()) 683 if (shouldIgnoreCase && element->document().body())
684 fragment->parseHTML(markup, element->document()->body(), DisallowScripti ngContent); 684 fragment->parseHTML(markup, element->document().body(), DisallowScriptin gContent);
685 else 685 else
686 fragment->parseXML(markup, 0, DisallowScriptingContent); 686 fragment->parseXML(markup, 0, DisallowScriptingContent);
687 687
688 Element* parsedElement = fragment->firstChild() && fragment->firstChild()->i sElementNode() ? toElement(fragment->firstChild()) : 0; 688 Element* parsedElement = fragment->firstChild() && fragment->firstChild()->i sElementNode() ? toElement(fragment->firstChild()) : 0;
689 if (!parsedElement) { 689 if (!parsedElement) {
690 *errorString = "Could not parse value as attributes"; 690 *errorString = "Could not parse value as attributes";
691 return; 691 return;
692 } 692 }
693 693
694 String caseAdjustedName = name ? (shouldIgnoreCase ? name->lower() : *name) : String(); 694 String caseAdjustedName = name ? (shouldIgnoreCase ? name->lower() : *name) : String();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 741
742 void InspectorDOMAgent::setNodeName(ErrorString* errorString, int nodeId, const String& tagName, int* newId) 742 void InspectorDOMAgent::setNodeName(ErrorString* errorString, int nodeId, const String& tagName, int* newId)
743 { 743 {
744 *newId = 0; 744 *newId = 0;
745 745
746 Node* oldNode = nodeForId(nodeId); 746 Node* oldNode = nodeForId(nodeId);
747 if (!oldNode || !oldNode->isElementNode()) 747 if (!oldNode || !oldNode->isElementNode())
748 return; 748 return;
749 749
750 TrackExceptionState es; 750 TrackExceptionState es;
751 RefPtr<Element> newElem = oldNode->document()->createElement(tagName, es); 751 RefPtr<Element> newElem = oldNode->document().createElement(tagName, es);
752 if (es.hadException()) 752 if (es.hadException())
753 return; 753 return;
754 754
755 // Copy over the original node's attributes. 755 // Copy over the original node's attributes.
756 newElem->cloneAttributesFromElement(*toElement(oldNode)); 756 newElem->cloneAttributesFromElement(*toElement(oldNode));
757 757
758 // Copy over the original node's children. 758 // Copy over the original node's children.
759 Node* child; 759 Node* child;
760 while ((child = oldNode->firstChild())) { 760 while ((child = oldNode->firstChild())) {
761 if (!m_domEditor->insertBefore(newElem.get(), child, 0, errorString)) 761 if (!m_domEditor->insertBefore(newElem.get(), child, 0, errorString))
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 return; 1330 return;
1331 1331
1332 Vector<FloatQuad> quads; 1332 Vector<FloatQuad> quads;
1333 bool isInlineOrBox = m_overlay->getBoxModel(node, &quads); 1333 bool isInlineOrBox = m_overlay->getBoxModel(node, &quads);
1334 if (!isInlineOrBox) { 1334 if (!isInlineOrBox) {
1335 *errorString = "Could not compute box model."; 1335 *errorString = "Could not compute box model.";
1336 return; 1336 return;
1337 } 1337 }
1338 1338
1339 RenderObject* renderer = node->renderer(); 1339 RenderObject* renderer = node->renderer();
1340 Frame* frame = node->document()->frame(); 1340 Frame* frame = node->document().frame();
1341 FrameView* view = frame->view(); 1341 FrameView* view = frame->view();
1342 1342
1343 IntRect boundingBox = pixelSnappedIntRect(view->contentsToRootView(renderer- >absoluteBoundingBoxRect())); 1343 IntRect boundingBox = pixelSnappedIntRect(view->contentsToRootView(renderer- >absoluteBoundingBoxRect()));
1344 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; 1344 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0;
1345 1345
1346 model = TypeBuilder::DOM::BoxModel::create() 1346 model = TypeBuilder::DOM::BoxModel::create()
1347 .setContent(buildArrayForQuad(quads.at(3))) 1347 .setContent(buildArrayForQuad(quads.at(3)))
1348 .setPadding(buildArrayForQuad(quads.at(2))) 1348 .setPadding(buildArrayForQuad(quads.at(2)))
1349 .setBorder(buildArrayForQuad(quads.at(1))) 1349 .setBorder(buildArrayForQuad(quads.at(1)))
1350 .setMargin(buildArrayForQuad(quads.at(0))) 1350 .setMargin(buildArrayForQuad(quads.at(0)))
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 while (child) { 1526 while (child) {
1527 children->addItem(buildObjectForNode(child, depth, nodesMap)); 1527 children->addItem(buildObjectForNode(child, depth, nodesMap));
1528 child = innerNextSibling(child); 1528 child = innerNextSibling(child);
1529 } 1529 }
1530 return children.release(); 1530 return children.release();
1531 } 1531 }
1532 1532
1533 PassRefPtr<TypeBuilder::DOM::EventListener> InspectorDOMAgent::buildObjectForEve ntListener(const RegisteredEventListener& registeredEventListener, const AtomicS tring& eventType, Node* node, const String* objectGroupId) 1533 PassRefPtr<TypeBuilder::DOM::EventListener> InspectorDOMAgent::buildObjectForEve ntListener(const RegisteredEventListener& registeredEventListener, const AtomicS tring& eventType, Node* node, const String* objectGroupId)
1534 { 1534 {
1535 RefPtr<EventListener> eventListener = registeredEventListener.listener; 1535 RefPtr<EventListener> eventListener = registeredEventListener.listener;
1536 Document* document = node->document(); 1536 Document& document = node->document();
1537 RefPtr<TypeBuilder::DOM::EventListener> value = TypeBuilder::DOM::EventListe ner::create() 1537 RefPtr<TypeBuilder::DOM::EventListener> value = TypeBuilder::DOM::EventListe ner::create()
1538 .setType(eventType) 1538 .setType(eventType)
1539 .setUseCapture(registeredEventListener.useCapture) 1539 .setUseCapture(registeredEventListener.useCapture)
1540 .setIsAttribute(eventListener->isAttribute()) 1540 .setIsAttribute(eventListener->isAttribute())
1541 .setNodeId(pushNodePathToFrontend(node)) 1541 .setNodeId(pushNodePathToFrontend(node))
1542 .setHandlerBody(eventListenerHandlerBody(document, eventListener.get())) ; 1542 .setHandlerBody(eventListenerHandlerBody(&document, eventListener.get()) );
1543 if (objectGroupId) { 1543 if (objectGroupId) {
1544 ScriptValue functionValue = eventListenerHandler(document, eventListener .get()); 1544 ScriptValue functionValue = eventListenerHandler(&document, eventListene r.get());
1545 if (!functionValue.hasNoValue()) { 1545 if (!functionValue.hasNoValue()) {
1546 Frame* frame = document->frame(); 1546 Frame* frame = document.frame();
1547 if (frame) { 1547 if (frame) {
1548 ScriptState* scriptState = eventListenerHandlerScriptState(frame , eventListener.get()); 1548 ScriptState* scriptState = eventListenerHandlerScriptState(frame , eventListener.get());
1549 if (scriptState) { 1549 if (scriptState) {
1550 InjectedScript injectedScript = m_injectedScriptManager->inj ectedScriptFor(scriptState); 1550 InjectedScript injectedScript = m_injectedScriptManager->inj ectedScriptFor(scriptState);
1551 if (!injectedScript.hasNoValue()) { 1551 if (!injectedScript.hasNoValue()) {
1552 RefPtr<TypeBuilder::Runtime::RemoteObject> valueJson = i njectedScript.wrapObject(functionValue, *objectGroupId); 1552 RefPtr<TypeBuilder::Runtime::RemoteObject> valueJson = i njectedScript.wrapObject(functionValue, *objectGroupId);
1553 value->setHandler(valueJson); 1553 value->setHandler(valueJson);
1554 } 1554 }
1555 } 1555 }
1556 } 1556 }
1557 } 1557 }
1558 } 1558 }
1559 String sourceName; 1559 String sourceName;
1560 String scriptId; 1560 String scriptId;
1561 int lineNumber; 1561 int lineNumber;
1562 if (eventListenerHandlerLocation(node->document(), eventListener.get(), sour ceName, scriptId, lineNumber)) { 1562 if (eventListenerHandlerLocation(&node->document(), eventListener.get(), sou rceName, scriptId, lineNumber)) {
1563 RefPtr<TypeBuilder::Debugger::Location> location = TypeBuilder::Debugger ::Location::create() 1563 RefPtr<TypeBuilder::Debugger::Location> location = TypeBuilder::Debugger ::Location::create()
1564 .setScriptId(scriptId) 1564 .setScriptId(scriptId)
1565 .setLineNumber(lineNumber); 1565 .setLineNumber(lineNumber);
1566 value->setLocation(location); 1566 value->setLocation(location);
1567 if (!sourceName.isEmpty()) 1567 if (!sourceName.isEmpty())
1568 value->setSourceName(sourceName); 1568 value->setSourceName(sourceName);
1569 } 1569 }
1570 return value.release(); 1570 return value.release();
1571 } 1571 }
1572 1572
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 *nodeId = pushNodePathToFrontend(node); 1876 *nodeId = pushNodePathToFrontend(node);
1877 1877
1878 if (nodeGroup == "") { 1878 if (nodeGroup == "") {
1879 m_backendIdToNode.remove(backendNodeId); 1879 m_backendIdToNode.remove(backendNodeId);
1880 m_nodeGroupToBackendIdMap.find(nodeGroup)->value.remove(node); 1880 m_nodeGroupToBackendIdMap.find(nodeGroup)->value.remove(node);
1881 } 1881 }
1882 } 1882 }
1883 1883
1884 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InspectorDOMAgent::resolveNode(No de* node, const String& objectGroup) 1884 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InspectorDOMAgent::resolveNode(No de* node, const String& objectGroup)
1885 { 1885 {
1886 Document* document = node->isDocumentNode() ? node->document() : node->owner Document(); 1886 Document* document = node->isDocumentNode() ? &node->document() : node->owne rDocument();
1887 Frame* frame = document ? document->frame() : 0; 1887 Frame* frame = document ? document->frame() : 0;
1888 if (!frame) 1888 if (!frame)
1889 return 0; 1889 return 0;
1890 1890
1891 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m ainWorldScriptState(frame)); 1891 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(m ainWorldScriptState(frame));
1892 if (injectedScript.hasNoValue()) 1892 if (injectedScript.hasNoValue())
1893 return 0; 1893 return 0;
1894 1894
1895 return injectedScript.wrapNode(node, objectGroup); 1895 return injectedScript.wrapNode(node, objectGroup);
1896 } 1896 }
1897 1897
1898 } // namespace WebCore 1898 } // namespace WebCore
1899 1899
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorCanvasAgent.cpp ('k') | Source/core/inspector/InspectorInstrumentation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698