InspectorInstrumentation.cpp 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  1. /*
  2. * Copyright (C) 2011 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  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.
  29. */
  30. #include "config.h"
  31. #if ENABLE(INSPECTOR)
  32. #include "InspectorInstrumentation.h"
  33. #include "CSSRule.h"
  34. #include "CSSStyleRule.h"
  35. #include "ConsoleAPITypes.h"
  36. #include "ConsoleTypes.h"
  37. #include "DOMWindow.h"
  38. #include "DOMWrapperWorld.h"
  39. #include "Database.h"
  40. #include "DeviceOrientationData.h"
  41. #include "DocumentLoader.h"
  42. #include "Event.h"
  43. #include "EventContext.h"
  44. #include "InspectorAgent.h"
  45. #include "InspectorApplicationCacheAgent.h"
  46. #include "InspectorCSSAgent.h"
  47. #include "InspectorCanvasAgent.h"
  48. #include "InspectorConsoleAgent.h"
  49. #include "InspectorController.h"
  50. #include "InspectorDOMAgent.h"
  51. #include "InspectorDOMDebuggerAgent.h"
  52. #include "InspectorDOMStorageAgent.h"
  53. #include "InspectorDatabaseAgent.h"
  54. #include "InspectorDebuggerAgent.h"
  55. #include "InspectorHeapProfilerAgent.h"
  56. #include "InspectorLayerTreeAgent.h"
  57. #include "InspectorPageAgent.h"
  58. #include "InspectorProfilerAgent.h"
  59. #include "InspectorResourceAgent.h"
  60. #include "InspectorTimelineAgent.h"
  61. #include "InspectorWorkerAgent.h"
  62. #include "InstrumentingAgents.h"
  63. #include "PageDebuggerAgent.h"
  64. #include "PageRuntimeAgent.h"
  65. #include "RenderObject.h"
  66. #include "ScriptArguments.h"
  67. #include "ScriptCallStack.h"
  68. #include "ScriptController.h"
  69. #include "ScriptProfile.h"
  70. #include "StyleResolver.h"
  71. #include "StyleRule.h"
  72. #include "WorkerContext.h"
  73. #include "WorkerInspectorController.h"
  74. #include "WorkerRuntimeAgent.h"
  75. #include "WorkerThread.h"
  76. #include "XMLHttpRequest.h"
  77. #include <wtf/StdLibExtras.h>
  78. #include <wtf/text/CString.h>
  79. namespace WebCore {
  80. static const char* const requestAnimationFrameEventName = "requestAnimationFrame";
  81. static const char* const cancelAnimationFrameEventName = "cancelAnimationFrame";
  82. static const char* const animationFrameFiredEventName = "animationFrameFired";
  83. static const char* const setTimerEventName = "setTimer";
  84. static const char* const clearTimerEventName = "clearTimer";
  85. static const char* const timerFiredEventName = "timerFired";
  86. namespace {
  87. static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0;
  88. }
  89. int InspectorInstrumentation::s_frontendCounter = 0;
  90. static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const EventPath& eventPath)
  91. {
  92. if (window && window->hasEventListeners(eventType))
  93. return true;
  94. if (node->hasEventListeners(eventType))
  95. return true;
  96. for (size_t i = 0; i < eventPath.size(); i++) {
  97. if (eventPath[i]->node()->hasEventListeners(eventType))
  98. return true;
  99. }
  100. return false;
  101. }
  102. static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
  103. {
  104. Frame* frame = 0;
  105. if (context->isDocument())
  106. frame = toDocument(context)->frame();
  107. return frame;
  108. }
  109. InspectorInstrumentationCookie::InspectorInstrumentationCookie()
  110. : m_instrumentingAgents(0)
  111. , m_timelineAgentId(0)
  112. {
  113. }
  114. InspectorInstrumentationCookie::InspectorInstrumentationCookie(InstrumentingAgents* agents, int timelineAgentId)
  115. : m_instrumentingAgents(agents)
  116. , m_timelineAgentId(timelineAgentId)
  117. {
  118. }
  119. InspectorInstrumentationCookie::InspectorInstrumentationCookie(const InspectorInstrumentationCookie& other)
  120. : m_instrumentingAgents(other.m_instrumentingAgents)
  121. , m_timelineAgentId(other.m_timelineAgentId)
  122. {
  123. }
  124. InspectorInstrumentationCookie& InspectorInstrumentationCookie::operator=(const InspectorInstrumentationCookie& other)
  125. {
  126. if (this != &other) {
  127. m_instrumentingAgents = other.m_instrumentingAgents;
  128. m_timelineAgentId = other.m_timelineAgentId;
  129. }
  130. return *this;
  131. }
  132. InspectorInstrumentationCookie::~InspectorInstrumentationCookie()
  133. {
  134. }
  135. void InspectorInstrumentation::didClearWindowObjectInWorldImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, DOMWrapperWorld* world)
  136. {
  137. InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent();
  138. if (pageAgent)
  139. pageAgent->didClearWindowObjectInWorld(frame, world);
  140. if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
  141. inspectorAgent->didClearWindowObjectInWorld(frame, world);
  142. #if ENABLE(JAVASCRIPT_DEBUGGER)
  143. if (PageDebuggerAgent* debuggerAgent = instrumentingAgents->pageDebuggerAgent()) {
  144. if (pageAgent && world == mainThreadNormalWorld() && frame == pageAgent->mainFrame())
  145. debuggerAgent->didClearMainFrameWindowObject();
  146. }
  147. #endif
  148. if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents->pageRuntimeAgent()) {
  149. if (world == mainThreadNormalWorld())
  150. pageRuntimeAgent->didCreateMainWorldContext(frame);
  151. }
  152. }
  153. bool InspectorInstrumentation::isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents)
  154. {
  155. #if ENABLE(JAVASCRIPT_DEBUGGER)
  156. if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
  157. return debuggerAgent->isPaused();
  158. #endif
  159. return false;
  160. }
  161. void InspectorInstrumentation::willInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* parent)
  162. {
  163. #if ENABLE(JAVASCRIPT_DEBUGGER)
  164. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  165. domDebuggerAgent->willInsertDOMNode(parent);
  166. #endif
  167. }
  168. void InspectorInstrumentation::didInsertDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
  169. {
  170. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  171. domAgent->didInsertDOMNode(node);
  172. #if ENABLE(JAVASCRIPT_DEBUGGER)
  173. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  174. domDebuggerAgent->didInsertDOMNode(node);
  175. #endif
  176. }
  177. void InspectorInstrumentation::willRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
  178. {
  179. #if ENABLE(JAVASCRIPT_DEBUGGER)
  180. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  181. domDebuggerAgent->willRemoveDOMNode(node);
  182. #endif
  183. }
  184. void InspectorInstrumentation::didRemoveDOMNodeImpl(InstrumentingAgents* instrumentingAgents, Node* node)
  185. {
  186. #if ENABLE(JAVASCRIPT_DEBUGGER)
  187. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  188. domDebuggerAgent->didRemoveDOMNode(node);
  189. #endif
  190. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  191. domAgent->didRemoveDOMNode(node);
  192. }
  193. void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& oldValue, const AtomicString& newValue)
  194. {
  195. #if ENABLE(JAVASCRIPT_DEBUGGER)
  196. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  197. domDebuggerAgent->willModifyDOMAttr(element);
  198. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  199. domAgent->willModifyDOMAttr(element, oldValue, newValue);
  200. #endif
  201. }
  202. void InspectorInstrumentation::didModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name, const AtomicString& value)
  203. {
  204. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  205. domAgent->didModifyDOMAttr(element, name, value);
  206. }
  207. void InspectorInstrumentation::didRemoveDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& name)
  208. {
  209. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  210. domAgent->didRemoveDOMAttr(element, name);
  211. }
  212. void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents* instrumentingAgents, Node* node)
  213. {
  214. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  215. domAgent->didInvalidateStyleAttr(node);
  216. #if ENABLE(JAVASCRIPT_DEBUGGER)
  217. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  218. domDebuggerAgent->didInvalidateStyleAttr(node);
  219. #endif
  220. }
  221. void InspectorInstrumentation::frameWindowDiscardedImpl(InstrumentingAgents* instrumentingAgents, DOMWindow* window)
  222. {
  223. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  224. consoleAgent->frameWindowDiscarded(window);
  225. }
  226. void InspectorInstrumentation::mediaQueryResultChangedImpl(InstrumentingAgents* instrumentingAgents)
  227. {
  228. if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
  229. cssAgent->mediaQueryResultChanged();
  230. }
  231. void InspectorInstrumentation::didPushShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
  232. {
  233. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  234. domAgent->didPushShadowRoot(host, root);
  235. }
  236. void InspectorInstrumentation::willPopShadowRootImpl(InstrumentingAgents* instrumentingAgents, Element* host, ShadowRoot* root)
  237. {
  238. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  239. domAgent->willPopShadowRoot(host, root);
  240. }
  241. void InspectorInstrumentation::didCreateNamedFlowImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
  242. {
  243. if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
  244. cssAgent->didCreateNamedFlow(document, namedFlow);
  245. }
  246. void InspectorInstrumentation::willRemoveNamedFlowImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
  247. {
  248. if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
  249. cssAgent->willRemoveNamedFlow(document, namedFlow);
  250. }
  251. void InspectorInstrumentation::didUpdateRegionLayoutImpl(InstrumentingAgents* instrumentingAgents, Document* document, WebKitNamedFlow* namedFlow)
  252. {
  253. if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
  254. cssAgent->didUpdateRegionLayout(document, namedFlow);
  255. }
  256. void InspectorInstrumentation::mouseDidMoveOverElementImpl(InstrumentingAgents* instrumentingAgents, const HitTestResult& result, unsigned modifierFlags)
  257. {
  258. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  259. domAgent->mouseDidMoveOverElement(result, modifierFlags);
  260. }
  261. void InspectorInstrumentation::didScrollImpl(InstrumentingAgents* instrumentingAgents)
  262. {
  263. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  264. pageAgent->didScroll();
  265. }
  266. bool InspectorInstrumentation::handleTouchEventImpl(InstrumentingAgents* instrumentingAgents, Node* node)
  267. {
  268. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  269. return domAgent->handleTouchEvent(node);
  270. return false;
  271. }
  272. bool InspectorInstrumentation::handleMousePressImpl(InstrumentingAgents* instrumentingAgents)
  273. {
  274. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  275. return domAgent->handleMousePress();
  276. return false;
  277. }
  278. bool InspectorInstrumentation::forcePseudoStateImpl(InstrumentingAgents* instrumentingAgents, Element* element, CSSSelector::PseudoType pseudoState)
  279. {
  280. if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
  281. return cssAgent->forcePseudoState(element, pseudoState);
  282. return false;
  283. }
  284. void InspectorInstrumentation::characterDataModifiedImpl(InstrumentingAgents* instrumentingAgents, CharacterData* characterData)
  285. {
  286. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  287. domAgent->characterDataModified(characterData);
  288. }
  289. void InspectorInstrumentation::willSendXMLHttpRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url)
  290. {
  291. #if ENABLE(JAVASCRIPT_DEBUGGER)
  292. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  293. domDebuggerAgent->willSendXMLHttpRequest(url);
  294. #endif
  295. }
  296. void InspectorInstrumentation::didScheduleResourceRequestImpl(InstrumentingAgents* instrumentingAgents, const String& url, Frame* frame)
  297. {
  298. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  299. timelineAgent->didScheduleResourceRequest(url, frame);
  300. }
  301. void InspectorInstrumentation::didInstallTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, int timeout, bool singleShot, ScriptExecutionContext* context)
  302. {
  303. pauseOnNativeEventIfNeeded(instrumentingAgents, false, setTimerEventName, true);
  304. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  305. timelineAgent->didInstallTimer(timerId, timeout, singleShot, frameForScriptExecutionContext(context));
  306. }
  307. void InspectorInstrumentation::didRemoveTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
  308. {
  309. pauseOnNativeEventIfNeeded(instrumentingAgents, false, clearTimerEventName, true);
  310. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  311. timelineAgent->didRemoveTimer(timerId, frameForScriptExecutionContext(context));
  312. }
  313. InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents* instrumentingAgents, const String& scriptName, int scriptLine, ScriptExecutionContext* context)
  314. {
  315. int timelineAgentId = 0;
  316. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  317. timelineAgent->willCallFunction(scriptName, scriptLine, frameForScriptExecutionContext(context));
  318. timelineAgentId = timelineAgent->id();
  319. }
  320. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  321. }
  322. void InspectorInstrumentation::didCallFunctionImpl(const InspectorInstrumentationCookie& cookie)
  323. {
  324. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  325. timelineAgent->didCallFunction();
  326. }
  327. InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRReadyStateChangeEventImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
  328. {
  329. int timelineAgentId = 0;
  330. InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
  331. if (timelineAgent && request->hasEventListeners(eventNames().readystatechangeEvent)) {
  332. timelineAgent->willDispatchXHRReadyStateChangeEvent(request->url().string(), request->readyState(), frameForScriptExecutionContext(context));
  333. timelineAgentId = timelineAgent->id();
  334. }
  335. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  336. }
  337. void InspectorInstrumentation::didDispatchXHRReadyStateChangeEventImpl(const InspectorInstrumentationCookie& cookie)
  338. {
  339. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  340. timelineAgent->didDispatchXHRReadyStateChangeEvent();
  341. }
  342. InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window, Node* node, const EventPath& eventPath, Document* document)
  343. {
  344. int timelineAgentId = 0;
  345. InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
  346. if (timelineAgent && eventHasListeners(event.type(), window, node, eventPath)) {
  347. timelineAgent->willDispatchEvent(event, document->frame());
  348. timelineAgentId = timelineAgent->id();
  349. }
  350. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  351. }
  352. InspectorInstrumentationCookie InspectorInstrumentation::willHandleEventImpl(InstrumentingAgents* instrumentingAgents, Event* event)
  353. {
  354. pauseOnNativeEventIfNeeded(instrumentingAgents, true, event->type(), false);
  355. return InspectorInstrumentationCookie(instrumentingAgents, 0);
  356. }
  357. void InspectorInstrumentation::didHandleEventImpl(const InspectorInstrumentationCookie& cookie)
  358. {
  359. cancelPauseOnNativeEvent(cookie.instrumentingAgents());
  360. }
  361. void InspectorInstrumentation::didDispatchEventImpl(const InspectorInstrumentationCookie& cookie)
  362. {
  363. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  364. timelineAgent->didDispatchEvent();
  365. }
  366. InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InstrumentingAgents* instrumentingAgents, const Event& event, DOMWindow* window)
  367. {
  368. int timelineAgentId = 0;
  369. InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
  370. if (timelineAgent && window->hasEventListeners(event.type())) {
  371. timelineAgent->willDispatchEvent(event, window ? window->frame() : 0);
  372. timelineAgentId = timelineAgent->id();
  373. }
  374. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  375. }
  376. void InspectorInstrumentation::didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie& cookie)
  377. {
  378. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  379. timelineAgent->didDispatchEvent();
  380. }
  381. InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InstrumentingAgents* instrumentingAgents, const String& url, int lineNumber, Frame* frame)
  382. {
  383. int timelineAgentId = 0;
  384. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  385. timelineAgent->willEvaluateScript(url, lineNumber, frame);
  386. timelineAgentId = timelineAgent->id();
  387. }
  388. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  389. }
  390. void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentationCookie& cookie)
  391. {
  392. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  393. timelineAgent->didEvaluateScript();
  394. }
  395. void InspectorInstrumentation::scriptsEnabledImpl(InstrumentingAgents* instrumentingAgents, bool isEnabled)
  396. {
  397. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  398. pageAgent->scriptsEnabled(isEnabled);
  399. }
  400. void InspectorInstrumentation::didCreateIsolatedContextImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, ScriptState* scriptState, SecurityOrigin* origin)
  401. {
  402. if (PageRuntimeAgent* runtimeAgent = instrumentingAgents->pageRuntimeAgent())
  403. runtimeAgent->didCreateIsolatedContext(frame, scriptState, origin);
  404. }
  405. InspectorInstrumentationCookie InspectorInstrumentation::willFireTimerImpl(InstrumentingAgents* instrumentingAgents, int timerId, ScriptExecutionContext* context)
  406. {
  407. pauseOnNativeEventIfNeeded(instrumentingAgents, false, timerFiredEventName, false);
  408. int timelineAgentId = 0;
  409. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  410. timelineAgent->willFireTimer(timerId, frameForScriptExecutionContext(context));
  411. timelineAgentId = timelineAgent->id();
  412. }
  413. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  414. }
  415. void InspectorInstrumentation::didFireTimerImpl(const InspectorInstrumentationCookie& cookie)
  416. {
  417. cancelPauseOnNativeEvent(cookie.instrumentingAgents());
  418. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  419. timelineAgent->didFireTimer();
  420. }
  421. void InspectorInstrumentation::didInvalidateLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  422. {
  423. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  424. timelineAgent->didInvalidateLayout(frame);
  425. }
  426. InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  427. {
  428. int timelineAgentId = 0;
  429. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  430. timelineAgent->willLayout(frame);
  431. timelineAgentId = timelineAgent->id();
  432. }
  433. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  434. }
  435. void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie, RenderObject* root)
  436. {
  437. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  438. timelineAgent->didLayout(root);
  439. if (InspectorPageAgent* pageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
  440. pageAgent->didLayout();
  441. }
  442. InspectorInstrumentationCookie InspectorInstrumentation::willDispatchXHRLoadEventImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request, ScriptExecutionContext* context)
  443. {
  444. int timelineAgentId = 0;
  445. InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
  446. if (timelineAgent && request->hasEventListeners(eventNames().loadEvent)) {
  447. timelineAgent->willDispatchXHRLoadEvent(request->url(), frameForScriptExecutionContext(context));
  448. timelineAgentId = timelineAgent->id();
  449. }
  450. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  451. }
  452. void InspectorInstrumentation::didDispatchXHRLoadEventImpl(const InspectorInstrumentationCookie& cookie)
  453. {
  454. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  455. timelineAgent->didDispatchXHRLoadEvent();
  456. }
  457. void InspectorInstrumentation::willPaintImpl(InstrumentingAgents* instrumentingAgents, RenderObject* renderer)
  458. {
  459. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  460. timelineAgent->willPaint(renderer->frame());
  461. }
  462. void InspectorInstrumentation::didPaintImpl(InstrumentingAgents* instrumentingAgents, RenderObject* renderer, GraphicsContext* context, const LayoutRect& rect)
  463. {
  464. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  465. timelineAgent->didPaint(renderer, rect);
  466. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  467. pageAgent->didPaint(context, rect);
  468. }
  469. void InspectorInstrumentation::willScrollLayerImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  470. {
  471. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  472. timelineAgent->willScroll(frame);
  473. }
  474. void InspectorInstrumentation::didScrollLayerImpl(InstrumentingAgents* instrumentingAgents)
  475. {
  476. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  477. timelineAgent->didScroll();
  478. }
  479. InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  480. {
  481. int timelineAgentId = 0;
  482. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  483. timelineAgent->willRecalculateStyle(frame);
  484. timelineAgentId = timelineAgent->id();
  485. }
  486. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  487. resourceAgent->willRecalculateStyle();
  488. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  489. }
  490. void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrumentationCookie& cookie)
  491. {
  492. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  493. timelineAgent->didRecalculateStyle();
  494. InstrumentingAgents* instrumentingAgents = cookie.instrumentingAgents();
  495. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  496. resourceAgent->didRecalculateStyle();
  497. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  498. pageAgent->didRecalculateStyle();
  499. }
  500. void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents* instrumentingAgents, Document* document)
  501. {
  502. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  503. timelineAgent->didScheduleStyleRecalculation(document->frame());
  504. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  505. resourceAgent->didScheduleStyleRecalculation(document);
  506. }
  507. InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* sheetCollection)
  508. {
  509. InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
  510. if (cssAgent) {
  511. cssAgent->willMatchRule(rule, inspectorCSSOMWrappers, sheetCollection);
  512. return InspectorInstrumentationCookie(instrumentingAgents, 1);
  513. }
  514. return InspectorInstrumentationCookie();
  515. }
  516. void InspectorInstrumentation::didMatchRuleImpl(const InspectorInstrumentationCookie& cookie, bool matched)
  517. {
  518. InspectorCSSAgent* cssAgent = cookie.instrumentingAgents()->inspectorCSSAgent();
  519. if (cssAgent)
  520. cssAgent->didMatchRule(matched);
  521. }
  522. InspectorInstrumentationCookie InspectorInstrumentation::willProcessRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, StyleResolver* styleResolver)
  523. {
  524. InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
  525. if (cssAgent) {
  526. cssAgent->willProcessRule(rule, styleResolver);
  527. return InspectorInstrumentationCookie(instrumentingAgents, 1);
  528. }
  529. return InspectorInstrumentationCookie();
  530. }
  531. void InspectorInstrumentation::didProcessRuleImpl(const InspectorInstrumentationCookie& cookie)
  532. {
  533. InspectorCSSAgent* cssAgent = cookie.instrumentingAgents()->inspectorCSSAgent();
  534. if (cssAgent)
  535. cssAgent->didProcessRule();
  536. }
  537. void InspectorInstrumentation::applyUserAgentOverrideImpl(InstrumentingAgents* instrumentingAgents, String* userAgent)
  538. {
  539. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  540. resourceAgent->applyUserAgentOverride(userAgent);
  541. }
  542. void InspectorInstrumentation::applyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents, long* width)
  543. {
  544. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  545. pageAgent->applyScreenWidthOverride(width);
  546. }
  547. void InspectorInstrumentation::applyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents, long* height)
  548. {
  549. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  550. pageAgent->applyScreenHeightOverride(height);
  551. }
  552. bool InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents)
  553. {
  554. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
  555. long width = 0;
  556. pageAgent->applyScreenWidthOverride(&width);
  557. return !!width;
  558. }
  559. return false;
  560. }
  561. bool InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents)
  562. {
  563. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
  564. long height = 0;
  565. pageAgent->applyScreenHeightOverride(&height);
  566. return !!height;
  567. }
  568. return false;
  569. }
  570. void InspectorInstrumentation::applyEmulatedMediaImpl(InstrumentingAgents* instrumentingAgents, String* media)
  571. {
  572. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  573. pageAgent->applyEmulatedMedia(media);
  574. }
  575. void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
  576. {
  577. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  578. timelineAgent->willSendResourceRequest(identifier, request, loader->frame());
  579. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  580. resourceAgent->willSendRequest(identifier, loader, request, redirectResponse);
  581. }
  582. void InspectorInstrumentation::continueAfterPingLoaderImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& response)
  583. {
  584. willSendRequestImpl(instrumentingAgents, identifier, loader, request, response);
  585. }
  586. void InspectorInstrumentation::markResourceAsCachedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
  587. {
  588. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  589. resourceAgent->markResourceAsCached(identifier);
  590. }
  591. void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
  592. {
  593. InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
  594. if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
  595. return;
  596. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  597. resourceAgent->didLoadResourceFromMemoryCache(loader, cachedResource);
  598. }
  599. InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, Frame* frame, int length)
  600. {
  601. int timelineAgentId = 0;
  602. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  603. timelineAgent->willReceiveResourceData(identifier, frame, length);
  604. timelineAgentId = timelineAgent->id();
  605. }
  606. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  607. }
  608. void InspectorInstrumentation::didReceiveResourceDataImpl(const InspectorInstrumentationCookie& cookie)
  609. {
  610. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  611. timelineAgent->didReceiveResourceData();
  612. }
  613. InspectorInstrumentationCookie InspectorInstrumentation::willReceiveResourceResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Frame* frame)
  614. {
  615. int timelineAgentId = 0;
  616. InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
  617. if (timelineAgent) {
  618. timelineAgent->willReceiveResourceResponse(identifier, response, frame);
  619. timelineAgentId = timelineAgent->id();
  620. }
  621. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  622. }
  623. void InspectorInstrumentation::didReceiveResourceResponseImpl(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
  624. {
  625. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  626. timelineAgent->didReceiveResourceResponse();
  627. if (!loader)
  628. return;
  629. InstrumentingAgents* instrumentingAgents = cookie.instrumentingAgents();
  630. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  631. resourceAgent->didReceiveResponse(identifier, loader, response, resourceLoader);
  632. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  633. consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
  634. }
  635. void InspectorInstrumentation::didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
  636. {
  637. InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(frame, identifier, r);
  638. InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r, 0);
  639. }
  640. void InspectorInstrumentation::continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
  641. {
  642. didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
  643. }
  644. void InspectorInstrumentation::continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
  645. {
  646. didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
  647. }
  648. void InspectorInstrumentation::continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
  649. {
  650. didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
  651. }
  652. void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
  653. {
  654. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  655. resourceAgent->didReceiveData(identifier, data, dataLength, encodedDataLength);
  656. }
  657. void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, double monotonicFinishTime)
  658. {
  659. InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent();
  660. InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent();
  661. if (!timelineAgent && !resourceAgent)
  662. return;
  663. double finishTime = 0.0;
  664. // FIXME: Expose all of the timing details to inspector and have it calculate finishTime.
  665. if (monotonicFinishTime)
  666. finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFinishTime);
  667. if (timelineAgent)
  668. timelineAgent->didFinishLoadingResource(identifier, false, finishTime, loader->frame());
  669. if (resourceAgent)
  670. resourceAgent->didFinishLoading(identifier, loader, finishTime);
  671. }
  672. void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
  673. {
  674. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  675. timelineAgent->didFinishLoadingResource(identifier, true, 0, loader->frame());
  676. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  677. resourceAgent->didFailLoading(identifier, loader, error);
  678. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  679. consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
  680. }
  681. void InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClientImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, ThreadableLoaderClient* client)
  682. {
  683. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  684. resourceAgent->documentThreadableLoaderStartedLoadingForClient(identifier, client);
  685. }
  686. void InspectorInstrumentation::willLoadXHRImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client, const String& method, const KURL& url, bool async, PassRefPtr<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials)
  687. {
  688. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  689. resourceAgent->willLoadXHR(client, method, url, async, formData, headers, includeCredentials);
  690. }
  691. void InspectorInstrumentation::didFailXHRLoadingImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client)
  692. {
  693. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  694. resourceAgent->didFailXHRLoading(client);
  695. }
  696. void InspectorInstrumentation::didFinishXHRLoadingImpl(InstrumentingAgents* instrumentingAgents, ThreadableLoaderClient* client, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber)
  697. {
  698. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  699. consoleAgent->didFinishXHRLoading(identifier, url, sendURL, sendLineNumber);
  700. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  701. resourceAgent->didFinishXHRLoading(client, identifier, sourceString);
  702. }
  703. void InspectorInstrumentation::didReceiveXHRResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
  704. {
  705. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  706. resourceAgent->didReceiveXHRResponse(identifier);
  707. }
  708. void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
  709. {
  710. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  711. resourceAgent->willLoadXHRSynchronously();
  712. }
  713. void InspectorInstrumentation::didLoadXHRSynchronouslyImpl(InstrumentingAgents* instrumentingAgents)
  714. {
  715. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  716. resourceAgent->didLoadXHRSynchronously();
  717. }
  718. void InspectorInstrumentation::scriptImportedImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& sourceString)
  719. {
  720. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  721. resourceAgent->setInitialScriptContent(identifier, sourceString);
  722. }
  723. void InspectorInstrumentation::scriptExecutionBlockedByCSPImpl(InstrumentingAgents* instrumentingAgents, const String& directiveText)
  724. {
  725. #if ENABLE(JAVASCRIPT_DEBUGGER)
  726. if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
  727. debuggerAgent->scriptExecutionBlockedByCSP(directiveText);
  728. #endif
  729. }
  730. void InspectorInstrumentation::didReceiveScriptResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
  731. {
  732. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  733. resourceAgent->didReceiveScriptResponse(identifier);
  734. }
  735. void InspectorInstrumentation::domContentLoadedEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  736. {
  737. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  738. timelineAgent->didMarkDOMContentEvent(frame);
  739. if (frame->page()->mainFrame() != frame)
  740. return;
  741. if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
  742. inspectorAgent->domContentLoadedEventFired();
  743. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  744. domAgent->mainFrameDOMContentLoaded();
  745. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  746. pageAgent->domContentEventFired();
  747. }
  748. void InspectorInstrumentation::loadEventFiredImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  749. {
  750. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  751. domAgent->loadEventFired(frame->document());
  752. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  753. timelineAgent->didMarkLoadEvent(frame);
  754. if (frame->page()->mainFrame() != frame)
  755. return;
  756. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  757. pageAgent->loadEventFired();
  758. }
  759. void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  760. {
  761. if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
  762. canvasAgent->frameDetached(frame);
  763. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  764. pageAgent->frameDetached(frame);
  765. }
  766. void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents* instrumentingAgents, Page* page, DocumentLoader* loader)
  767. {
  768. InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
  769. if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
  770. return;
  771. Frame* mainFrame = page->mainFrame();
  772. if (loader->frame() == mainFrame) {
  773. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  774. consoleAgent->reset();
  775. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  776. resourceAgent->mainFrameNavigated(loader);
  777. #if ENABLE(JAVASCRIPT_DEBUGGER)
  778. if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
  779. profilerAgent->resetState();
  780. if (InspectorHeapProfilerAgent* heapProfilerAgent = instrumentingAgents->inspectorHeapProfilerAgent())
  781. heapProfilerAgent->resetState();
  782. #endif
  783. if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
  784. cssAgent->reset();
  785. #if ENABLE(SQL_DATABASE)
  786. if (InspectorDatabaseAgent* databaseAgent = instrumentingAgents->inspectorDatabaseAgent())
  787. databaseAgent->clearResources();
  788. #endif
  789. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  790. domAgent->setDocument(mainFrame->document());
  791. #if USE(ACCELERATED_COMPOSITING)
  792. if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
  793. layerTreeAgent->reset();
  794. #endif
  795. inspectorAgent->didCommitLoad();
  796. }
  797. if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
  798. canvasAgent->frameNavigated(loader->frame());
  799. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  800. pageAgent->frameNavigated(loader);
  801. }
  802. void InspectorInstrumentation::frameDocumentUpdatedImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  803. {
  804. InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
  805. if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
  806. return;
  807. if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
  808. domAgent->frameDocumentUpdated(frame);
  809. }
  810. void InspectorInstrumentation::loaderDetachedFromFrameImpl(InstrumentingAgents* instrumentingAgents, DocumentLoader* loader)
  811. {
  812. if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
  813. inspectorPageAgent->loaderDetachedFromFrame(loader);
  814. }
  815. void InspectorInstrumentation::frameStartedLoadingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  816. {
  817. if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
  818. inspectorPageAgent->frameStartedLoading(frame);
  819. }
  820. void InspectorInstrumentation::frameStoppedLoadingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  821. {
  822. if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
  823. inspectorPageAgent->frameStoppedLoading(frame);
  824. }
  825. void InspectorInstrumentation::frameScheduledNavigationImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, double delay)
  826. {
  827. if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
  828. inspectorPageAgent->frameScheduledNavigation(frame, delay);
  829. }
  830. void InspectorInstrumentation::frameClearedScheduledNavigationImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  831. {
  832. if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
  833. inspectorPageAgent->frameClearedScheduledNavigation(frame);
  834. }
  835. InspectorInstrumentationCookie InspectorInstrumentation::willRunJavaScriptDialogImpl(InstrumentingAgents* instrumentingAgents, const String& message)
  836. {
  837. if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
  838. inspectorPageAgent->willRunJavaScriptDialog(message);
  839. return InspectorInstrumentationCookie(instrumentingAgents, 0);
  840. }
  841. void InspectorInstrumentation::didRunJavaScriptDialogImpl(const InspectorInstrumentationCookie& cookie)
  842. {
  843. if (InspectorPageAgent* inspectorPageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
  844. inspectorPageAgent->didRunJavaScriptDialog();
  845. }
  846. void InspectorInstrumentation::willDestroyCachedResourceImpl(CachedResource* cachedResource)
  847. {
  848. if (!instrumentingAgentsSet)
  849. return;
  850. HashSet<InstrumentingAgents*>::iterator end = instrumentingAgentsSet->end();
  851. for (HashSet<InstrumentingAgents*>::iterator it = instrumentingAgentsSet->begin(); it != end; ++it) {
  852. InstrumentingAgents* instrumentingAgents = *it;
  853. if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgents->inspectorResourceAgent())
  854. inspectorResourceAgent->willDestroyCachedResource(cachedResource);
  855. }
  856. }
  857. InspectorInstrumentationCookie InspectorInstrumentation::willWriteHTMLImpl(InstrumentingAgents* instrumentingAgents, unsigned startLine, Frame* frame)
  858. {
  859. int timelineAgentId = 0;
  860. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  861. timelineAgent->willWriteHTML(startLine, frame);
  862. timelineAgentId = timelineAgent->id();
  863. }
  864. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  865. }
  866. void InspectorInstrumentation::didWriteHTMLImpl(const InspectorInstrumentationCookie& cookie, unsigned endLine)
  867. {
  868. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  869. timelineAgent->didWriteHTML(endLine);
  870. }
  871. // FIXME: Drop this once we no longer generate stacks outside of Inspector.
  872. void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptCallStack> callStack, unsigned long requestIdentifier)
  873. {
  874. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  875. consoleAgent->addMessageToConsole(source, type, level, message, callStack, requestIdentifier);
  876. #if ENABLE(JAVASCRIPT_DEBUGGER)
  877. if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
  878. debuggerAgent->addMessageToConsole(source, type);
  879. #endif
  880. }
  881. void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, ScriptState* state, PassRefPtr<ScriptArguments> arguments, unsigned long requestIdentifier)
  882. {
  883. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  884. consoleAgent->addMessageToConsole(source, type, level, message, state, arguments, requestIdentifier);
  885. #if ENABLE(JAVASCRIPT_DEBUGGER)
  886. if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
  887. debuggerAgent->addMessageToConsole(source, type);
  888. #endif
  889. }
  890. void InspectorInstrumentation::addMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, MessageSource source, MessageType type, MessageLevel level, const String& message, const String& scriptId, unsigned lineNumber, unsigned columnNumber, ScriptState* state, unsigned long requestIdentifier)
  891. {
  892. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  893. consoleAgent->addMessageToConsole(source, type, level, message, scriptId, lineNumber, columnNumber, state, requestIdentifier);
  894. }
  895. void InspectorInstrumentation::consoleCountImpl(InstrumentingAgents* instrumentingAgents, ScriptState* state, PassRefPtr<ScriptArguments> arguments)
  896. {
  897. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  898. consoleAgent->count(state, arguments);
  899. }
  900. void InspectorInstrumentation::startConsoleTimingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, const String& title)
  901. {
  902. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  903. timelineAgent->time(frame, title);
  904. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  905. consoleAgent->startTiming(title);
  906. }
  907. void InspectorInstrumentation::stopConsoleTimingImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, const String& title, PassRefPtr<ScriptCallStack> stack)
  908. {
  909. if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
  910. consoleAgent->stopTiming(title, stack);
  911. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  912. timelineAgent->timeEnd(frame, title);
  913. }
  914. void InspectorInstrumentation::consoleTimeStampImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, PassRefPtr<ScriptArguments> arguments)
  915. {
  916. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  917. String message;
  918. arguments->getFirstArgumentAsString(message);
  919. timelineAgent->didTimeStamp(frame, message);
  920. }
  921. }
  922. #if ENABLE(JAVASCRIPT_DEBUGGER)
  923. void InspectorInstrumentation::addStartProfilingMessageToConsoleImpl(InstrumentingAgents* instrumentingAgents, const String& title, unsigned lineNumber, unsigned columnNumber, const String& sourceURL)
  924. {
  925. if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
  926. profilerAgent->addStartProfilingMessageToConsole(title, lineNumber, columnNumber, sourceURL);
  927. }
  928. void InspectorInstrumentation::addProfileImpl(InstrumentingAgents* instrumentingAgents, RefPtr<ScriptProfile> profile, PassRefPtr<ScriptCallStack> callStack)
  929. {
  930. if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent()) {
  931. const ScriptCallFrame& lastCaller = callStack->at(0);
  932. profilerAgent->addProfile(profile, lastCaller.lineNumber(), lastCaller.columnNumber(), lastCaller.sourceURL());
  933. }
  934. }
  935. String InspectorInstrumentation::getCurrentUserInitiatedProfileNameImpl(InstrumentingAgents* instrumentingAgents, bool incrementProfileNumber)
  936. {
  937. if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
  938. return profilerAgent->getCurrentUserInitiatedProfileName(incrementProfileNumber);
  939. return "";
  940. }
  941. bool InspectorInstrumentation::profilerEnabledImpl(InstrumentingAgents* instrumentingAgents)
  942. {
  943. if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
  944. return profilerAgent->enabled();
  945. return false;
  946. }
  947. #endif
  948. #if ENABLE(SQL_DATABASE)
  949. void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents* instrumentingAgents, PassRefPtr<Database> database, const String& domain, const String& name, const String& version)
  950. {
  951. InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
  952. if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
  953. return;
  954. if (InspectorDatabaseAgent* dbAgent = instrumentingAgents->inspectorDatabaseAgent())
  955. dbAgent->didOpenDatabase(database, domain, name, version);
  956. }
  957. #endif
  958. void InspectorInstrumentation::didDispatchDOMStorageEventImpl(InstrumentingAgents* instrumentingAgents, const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Page* page)
  959. {
  960. if (InspectorDOMStorageAgent* domStorageAgent = instrumentingAgents->inspectorDOMStorageAgent())
  961. domStorageAgent->didDispatchDOMStorageEvent(key, oldValue, newValue, storageType, securityOrigin, page);
  962. }
  963. #if ENABLE(WORKERS)
  964. bool InspectorInstrumentation::shouldPauseDedicatedWorkerOnStartImpl(InstrumentingAgents* instrumentingAgents)
  965. {
  966. if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
  967. return workerAgent->shouldPauseDedicatedWorkerOnStart();
  968. return false;
  969. }
  970. void InspectorInstrumentation::didStartWorkerContextImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* workerContextProxy, const KURL& url)
  971. {
  972. if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
  973. workerAgent->didStartWorkerContext(workerContextProxy, url);
  974. }
  975. void InspectorInstrumentation::willEvaluateWorkerScript(WorkerContext* workerContext, int workerThreadStartMode)
  976. {
  977. if (workerThreadStartMode != PauseWorkerContextOnStart)
  978. return;
  979. InstrumentingAgents* instrumentingAgents = instrumentationForWorkerContext(workerContext);
  980. if (!instrumentingAgents)
  981. return;
  982. #if ENABLE(JAVASCRIPT_DEBUGGER)
  983. if (WorkerRuntimeAgent* runtimeAgent = instrumentingAgents->workerRuntimeAgent())
  984. runtimeAgent->pauseWorkerContext(workerContext);
  985. #endif
  986. }
  987. void InspectorInstrumentation::workerContextTerminatedImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* proxy)
  988. {
  989. if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
  990. workerAgent->workerContextTerminated(proxy);
  991. }
  992. #endif
  993. #if ENABLE(WEB_SOCKETS)
  994. void InspectorInstrumentation::didCreateWebSocketImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const KURL& requestURL, const KURL&, const String& protocol, Document* document)
  995. {
  996. InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent();
  997. if (!inspectorAgent || !inspectorAgent->developerExtrasEnabled())
  998. return;
  999. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1000. resourceAgent->didCreateWebSocket(identifier, requestURL);
  1001. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  1002. timelineAgent->didCreateWebSocket(identifier, requestURL, protocol, document->frame());
  1003. }
  1004. void InspectorInstrumentation::willSendWebSocketHandshakeRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceRequest& request, Document* document)
  1005. {
  1006. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1007. resourceAgent->willSendWebSocketHandshakeRequest(identifier, request);
  1008. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  1009. timelineAgent->willSendWebSocketHandshakeRequest(identifier, document->frame());
  1010. }
  1011. void InspectorInstrumentation::didReceiveWebSocketHandshakeResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const ResourceResponse& response, Document* document)
  1012. {
  1013. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1014. resourceAgent->didReceiveWebSocketHandshakeResponse(identifier, response);
  1015. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  1016. timelineAgent->didReceiveWebSocketHandshakeResponse(identifier, document->frame());
  1017. }
  1018. void InspectorInstrumentation::didCloseWebSocketImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, Document* document)
  1019. {
  1020. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1021. resourceAgent->didCloseWebSocket(identifier);
  1022. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  1023. timelineAgent->didDestroyWebSocket(identifier, document->frame());
  1024. }
  1025. void InspectorInstrumentation::didReceiveWebSocketFrameImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
  1026. {
  1027. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1028. resourceAgent->didReceiveWebSocketFrame(identifier, frame);
  1029. }
  1030. void InspectorInstrumentation::didReceiveWebSocketFrameErrorImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& errorMessage)
  1031. {
  1032. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1033. resourceAgent->didReceiveWebSocketFrameError(identifier, errorMessage);
  1034. }
  1035. void InspectorInstrumentation::didSendWebSocketFrameImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const WebSocketFrame& frame)
  1036. {
  1037. if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
  1038. resourceAgent->didSendWebSocketFrame(identifier, frame);
  1039. }
  1040. #endif
  1041. void InspectorInstrumentation::networkStateChangedImpl(InstrumentingAgents* instrumentingAgents)
  1042. {
  1043. if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents->inspectorApplicationCacheAgent())
  1044. applicationCacheAgent->networkStateChanged();
  1045. }
  1046. void InspectorInstrumentation::updateApplicationCacheStatusImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
  1047. {
  1048. if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents->inspectorApplicationCacheAgent())
  1049. applicationCacheAgent->updateApplicationCacheStatus(frame);
  1050. }
  1051. bool InspectorInstrumentation::collectingHTMLParseErrors(InstrumentingAgents* instrumentingAgents)
  1052. {
  1053. if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent())
  1054. return inspectorAgent->hasFrontend();
  1055. return false;
  1056. }
  1057. bool InspectorInstrumentation::canvasAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
  1058. {
  1059. InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
  1060. return instrumentingAgents && instrumentingAgents->inspectorCanvasAgent();
  1061. }
  1062. bool InspectorInstrumentation::consoleAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
  1063. {
  1064. InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
  1065. InspectorConsoleAgent* consoleAgent = instrumentingAgents ? instrumentingAgents->inspectorConsoleAgent() : 0;
  1066. return consoleAgent && consoleAgent->enabled();
  1067. }
  1068. bool InspectorInstrumentation::timelineAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
  1069. {
  1070. InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext);
  1071. return instrumentingAgents && instrumentingAgents->inspectorTimelineAgent();
  1072. }
  1073. void InspectorInstrumentation::pauseOnNativeEventIfNeeded(InstrumentingAgents* instrumentingAgents, bool isDOMEvent, const String& eventName, bool synchronous)
  1074. {
  1075. #if ENABLE(JAVASCRIPT_DEBUGGER)
  1076. if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
  1077. domDebuggerAgent->pauseOnNativeEventIfNeeded(isDOMEvent, eventName, synchronous);
  1078. #endif
  1079. }
  1080. void InspectorInstrumentation::cancelPauseOnNativeEvent(InstrumentingAgents* instrumentingAgents)
  1081. {
  1082. #if ENABLE(JAVASCRIPT_DEBUGGER)
  1083. if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
  1084. debuggerAgent->cancelPauseOnNextStatement();
  1085. #endif
  1086. }
  1087. void InspectorInstrumentation::didRequestAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
  1088. {
  1089. pauseOnNativeEventIfNeeded(instrumentingAgents, false, requestAnimationFrameEventName, true);
  1090. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  1091. timelineAgent->didRequestAnimationFrame(callbackId, frame);
  1092. }
  1093. void InspectorInstrumentation::didCancelAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
  1094. {
  1095. pauseOnNativeEventIfNeeded(instrumentingAgents, false, cancelAnimationFrameEventName, true);
  1096. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
  1097. timelineAgent->didCancelAnimationFrame(callbackId, frame);
  1098. }
  1099. InspectorInstrumentationCookie InspectorInstrumentation::willFireAnimationFrameImpl(InstrumentingAgents* instrumentingAgents, int callbackId, Frame* frame)
  1100. {
  1101. pauseOnNativeEventIfNeeded(instrumentingAgents, false, animationFrameFiredEventName, false);
  1102. int timelineAgentId = 0;
  1103. if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent()) {
  1104. timelineAgent->willFireAnimationFrame(callbackId, frame);
  1105. timelineAgentId = timelineAgent->id();
  1106. }
  1107. return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
  1108. }
  1109. void InspectorInstrumentation::didFireAnimationFrameImpl(const InspectorInstrumentationCookie& cookie)
  1110. {
  1111. if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
  1112. timelineAgent->didFireAnimationFrame();
  1113. }
  1114. void InspectorInstrumentation::registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
  1115. {
  1116. if (!instrumentingAgentsSet)
  1117. instrumentingAgentsSet = new HashSet<InstrumentingAgents*>();
  1118. instrumentingAgentsSet->add(instrumentingAgents);
  1119. }
  1120. void InspectorInstrumentation::unregisterInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
  1121. {
  1122. if (!instrumentingAgentsSet)
  1123. return;
  1124. instrumentingAgentsSet->remove(instrumentingAgents);
  1125. if (instrumentingAgentsSet->isEmpty()) {
  1126. delete instrumentingAgentsSet;
  1127. instrumentingAgentsSet = 0;
  1128. }
  1129. }
  1130. InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
  1131. {
  1132. if (!cookie.instrumentingAgents())
  1133. return 0;
  1134. InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent();
  1135. if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id()))
  1136. return timelineAgent;
  1137. return 0;
  1138. }
  1139. InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForPage(Page* page)
  1140. {
  1141. if (!page)
  1142. return 0;
  1143. return instrumentationForPage(page);
  1144. }
  1145. InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForRenderer(RenderObject* renderer)
  1146. {
  1147. return instrumentingAgentsForFrame(renderer->frame());
  1148. }
  1149. #if ENABLE(WORKERS)
  1150. InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForWorkerContext(WorkerContext* workerContext)
  1151. {
  1152. if (!workerContext)
  1153. return 0;
  1154. return instrumentationForWorkerContext(workerContext);
  1155. }
  1156. InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context)
  1157. {
  1158. if (context->isWorkerContext())
  1159. return instrumentationForWorkerContext(static_cast<WorkerContext*>(context));
  1160. return 0;
  1161. }
  1162. #endif
  1163. #if ENABLE(GEOLOCATION)
  1164. GeolocationPosition* InspectorInstrumentation::overrideGeolocationPositionImpl(InstrumentingAgents* instrumentingAgents, GeolocationPosition* position)
  1165. {
  1166. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  1167. position = pageAgent->overrideGeolocationPosition(position);
  1168. return position;
  1169. }
  1170. #endif
  1171. DeviceOrientationData* InspectorInstrumentation::overrideDeviceOrientationImpl(InstrumentingAgents* instrumentingAgents, DeviceOrientationData* deviceOrientation)
  1172. {
  1173. if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
  1174. deviceOrientation = pageAgent->overrideDeviceOrientation(deviceOrientation);
  1175. return deviceOrientation;
  1176. }
  1177. #if USE(ACCELERATED_COMPOSITING)
  1178. void InspectorInstrumentation::layerTreeDidChangeImpl(InstrumentingAgents* instrumentingAgents)
  1179. {
  1180. if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
  1181. layerTreeAgent->layerTreeDidChange();
  1182. }
  1183. void InspectorInstrumentation::renderLayerDestroyedImpl(InstrumentingAgents* instrumentingAgents, const RenderLayer* renderLayer)
  1184. {
  1185. if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
  1186. layerTreeAgent->renderLayerDestroyed(renderLayer);
  1187. }
  1188. void InspectorInstrumentation::pseudoElementDestroyedImpl(InstrumentingAgents* instrumentingAgents, PseudoElement* pseudoElement)
  1189. {
  1190. if (InspectorLayerTreeAgent* layerTreeAgent = instrumentingAgents->inspectorLayerTreeAgent())
  1191. layerTreeAgent->pseudoElementDestroyed(pseudoElement);
  1192. }
  1193. #endif
  1194. namespace InstrumentationEvents {
  1195. const char PaintLayer[] = "PaintLayer";
  1196. const char RasterTask[] = "RasterTask";
  1197. const char Paint[] = "Paint";
  1198. const char Layer[] = "Layer";
  1199. const char BeginFrame[] = "BeginFrame";
  1200. };
  1201. namespace InstrumentationEventArguments {
  1202. const char LayerId[] = "layerId";
  1203. const char PageId[] = "pageId";
  1204. };
  1205. } // namespace WebCore
  1206. #endif // !ENABLE(INSPECTOR)