InspectorFrontend.cpp revision 643ca7872b450ea4efacab6188849e5aac2ba161
1/* 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#include "config.h" 31#include "InspectorFrontend.h" 32 33#if ENABLE(INSPECTOR) 34 35#include "ConsoleMessage.h" 36#include "Frame.h" 37#include "InspectorController.h" 38#include "Node.h" 39#include "ScriptFunctionCall.h" 40#include "ScriptObject.h" 41#include "ScriptState.h" 42#include "ScriptString.h" 43#include <wtf/OwnPtr.h> 44 45#if ENABLE(JAVASCRIPT_DEBUGGER) 46#include <parser/SourceCode.h> 47#include <runtime/JSValue.h> 48#include <runtime/UString.h> 49#endif 50 51namespace WebCore { 52 53InspectorFrontend::InspectorFrontend(InspectorController* inspectorController, ScriptState* scriptState, ScriptObject webInspector) 54 : m_inspectorController(inspectorController) 55 , m_scriptState(scriptState) 56 , m_webInspector(webInspector) 57{ 58} 59 60InspectorFrontend::~InspectorFrontend() 61{ 62 m_webInspector = ScriptObject(); 63} 64 65ScriptArray InspectorFrontend::newScriptArray() 66{ 67 return ScriptArray::createNew(m_scriptState); 68} 69 70ScriptObject InspectorFrontend::newScriptObject() 71{ 72 return ScriptObject::createNew(m_scriptState); 73} 74 75void InspectorFrontend::didCommitLoad() 76{ 77 callSimpleFunction("didCommitLoad"); 78} 79 80void InspectorFrontend::addConsoleMessage(const ScriptObject& messageObj, const Vector<ScriptString>& frames, const Vector<ScriptValue> wrappedArguments, const String& message) 81{ 82 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 83 function.appendArgument("addConsoleMessage"); 84 function.appendArgument(messageObj); 85 if (!frames.isEmpty()) { 86 for (unsigned i = 0; i < frames.size(); ++i) 87 function.appendArgument(frames[i]); 88 } else if (!wrappedArguments.isEmpty()) { 89 for (unsigned i = 0; i < wrappedArguments.size(); ++i) 90 function.appendArgument(m_inspectorController->wrapObject(wrappedArguments[i], "console")); 91 } else 92 function.appendArgument(message); 93 function.call(); 94} 95 96void InspectorFrontend::updateConsoleMessageRepeatCount(const int count) 97{ 98 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 99 function.appendArgument("updateConsoleMessageRepeatCount"); 100 function.appendArgument(count); 101 function.call(); 102} 103 104void InspectorFrontend::clearConsoleMessages() 105{ 106 callSimpleFunction("clearConsoleMessages"); 107} 108 109bool InspectorFrontend::addResource(unsigned long identifier, const ScriptObject& resourceObj) 110{ 111 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 112 function.appendArgument("addResource"); 113 function.appendArgument(identifier); 114 function.appendArgument(resourceObj); 115 bool hadException = false; 116 function.call(hadException); 117 return !hadException; 118} 119 120bool InspectorFrontend::updateResource(unsigned long identifier, const ScriptObject& resourceObj) 121{ 122 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 123 function.appendArgument("updateResource"); 124 function.appendArgument(identifier); 125 function.appendArgument(resourceObj); 126 bool hadException = false; 127 function.call(hadException); 128 return !hadException; 129} 130 131void InspectorFrontend::removeResource(unsigned long identifier) 132{ 133 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 134 function.appendArgument("removeResource"); 135 function.appendArgument(identifier); 136 function.call(); 137} 138 139void InspectorFrontend::updateFocusedNode(long nodeId) 140{ 141 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 142 function.appendArgument("updateFocusedNode"); 143 function.appendArgument(nodeId); 144 function.call(); 145} 146 147void InspectorFrontend::setAttachedWindow(bool attached) 148{ 149 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 150 function.appendArgument("setAttachedWindow"); 151 function.appendArgument(attached); 152 function.call(); 153} 154 155void InspectorFrontend::showPanel(int panel) 156{ 157 const char* showFunctionName; 158 switch (panel) { 159 case InspectorController::ConsolePanel: 160 showFunctionName = "showConsolePanel"; 161 break; 162 case InspectorController::ElementsPanel: 163 showFunctionName = "showElementsPanel"; 164 break; 165 case InspectorController::ResourcesPanel: 166 showFunctionName = "showResourcesPanel"; 167 break; 168 case InspectorController::ScriptsPanel: 169 showFunctionName = "showScriptsPanel"; 170 break; 171 case InspectorController::TimelinePanel: 172 showFunctionName = "showTimelinePanel"; 173 break; 174 case InspectorController::ProfilesPanel: 175 showFunctionName = "showProfilesPanel"; 176 break; 177 case InspectorController::StoragePanel: 178 showFunctionName = "showStoragePanel"; 179 break; 180 default: 181 ASSERT_NOT_REACHED(); 182 showFunctionName = 0; 183 } 184 185 if (showFunctionName) 186 callSimpleFunction(showFunctionName); 187} 188 189void InspectorFrontend::populateInterface() 190{ 191 callSimpleFunction("populateInterface"); 192} 193 194void InspectorFrontend::reset() 195{ 196 callSimpleFunction("reset"); 197} 198 199void InspectorFrontend::resourceTrackingWasEnabled() 200{ 201 callSimpleFunction("resourceTrackingWasEnabled"); 202} 203 204void InspectorFrontend::resourceTrackingWasDisabled() 205{ 206 callSimpleFunction("resourceTrackingWasDisabled"); 207} 208 209void InspectorFrontend::timelineProfilerWasStarted() 210{ 211 callSimpleFunction("timelineProfilerWasStarted"); 212} 213 214void InspectorFrontend::timelineProfilerWasStopped() 215{ 216 callSimpleFunction("timelineProfilerWasStopped"); 217} 218 219void InspectorFrontend::addRecordToTimeline(const ScriptObject& record) 220{ 221 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 222 function.appendArgument("addRecordToTimeline"); 223 function.appendArgument(record); 224 function.call(); 225} 226 227#if ENABLE(JAVASCRIPT_DEBUGGER) 228void InspectorFrontend::attachDebuggerWhenShown() 229{ 230 callSimpleFunction("attachDebuggerWhenShown"); 231} 232 233void InspectorFrontend::debuggerWasEnabled() 234{ 235 callSimpleFunction("debuggerWasEnabled"); 236} 237 238void InspectorFrontend::debuggerWasDisabled() 239{ 240 callSimpleFunction("debuggerWasDisabled"); 241} 242 243void InspectorFrontend::profilerWasEnabled() 244{ 245 callSimpleFunction("profilerWasEnabled"); 246} 247 248void InspectorFrontend::profilerWasDisabled() 249{ 250 callSimpleFunction("profilerWasDisabled"); 251} 252 253void InspectorFrontend::parsedScriptSource(const JSC::SourceCode& source) 254{ 255 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 256 function.appendArgument("parsedScriptSource"); 257 function.appendArgument(JSC::UString(JSC::UString::from(source.provider()->asID()))); 258 function.appendArgument(source.provider()->url()); 259 function.appendArgument(JSC::UString(source.data(), source.length())); 260 function.appendArgument(source.firstLine()); 261 function.call(); 262} 263 264void InspectorFrontend::failedToParseScriptSource(const JSC::SourceCode& source, int errorLine, const JSC::UString& errorMessage) 265{ 266 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 267 function.appendArgument("failedToParseScriptSource"); 268 function.appendArgument(source.provider()->url()); 269 function.appendArgument(JSC::UString(source.data(), source.length())); 270 function.appendArgument(source.firstLine()); 271 function.appendArgument(errorLine); 272 function.appendArgument(errorMessage); 273 function.call(); 274} 275 276void InspectorFrontend::addProfileHeader(const ScriptValue& profile) 277{ 278 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 279 function.appendArgument("addProfileHeader"); 280 function.appendArgument(profile); 281 function.call(); 282} 283 284void InspectorFrontend::setRecordingProfile(bool isProfiling) 285{ 286 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 287 function.appendArgument("setRecordingProfile"); 288 function.appendArgument(isProfiling); 289 function.call(); 290} 291 292void InspectorFrontend::didGetProfileHeaders(int callId, const ScriptArray& headers) 293{ 294 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 295 function.appendArgument("didGetProfileHeaders"); 296 function.appendArgument(callId); 297 function.appendArgument(headers); 298 function.call(); 299} 300 301void InspectorFrontend::didGetProfile(int callId, const ScriptValue& profile) 302{ 303 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 304 function.appendArgument("didGetProfile"); 305 function.appendArgument(callId); 306 function.appendArgument(profile); 307 function.call(); 308} 309 310void InspectorFrontend::pausedScript(const ScriptValue& callFrames) 311{ 312 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 313 function.appendArgument("pausedScript"); 314 function.appendArgument(callFrames); 315 function.call(); 316} 317 318void InspectorFrontend::resumedScript() 319{ 320 callSimpleFunction("resumedScript"); 321} 322#endif 323 324void InspectorFrontend::setDocument(const ScriptObject& root) 325{ 326 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 327 function.appendArgument("setDocument"); 328 function.appendArgument(root); 329 function.call(); 330} 331 332void InspectorFrontend::setDetachedRoot(const ScriptObject& root) 333{ 334 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 335 function.appendArgument("setDetachedRoot"); 336 function.appendArgument(root); 337 function.call(); 338} 339 340void InspectorFrontend::setChildNodes(int parentId, const ScriptArray& nodes) 341{ 342 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 343 function.appendArgument("setChildNodes"); 344 function.appendArgument(parentId); 345 function.appendArgument(nodes); 346 function.call(); 347} 348 349void InspectorFrontend::childNodeCountUpdated(int id, int newValue) 350{ 351 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 352 function.appendArgument("childNodeCountUpdated"); 353 function.appendArgument(id); 354 function.appendArgument(newValue); 355 function.call(); 356} 357 358void InspectorFrontend::childNodeInserted(int parentId, int prevId, const ScriptObject& node) 359{ 360 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 361 function.appendArgument("childNodeInserted"); 362 function.appendArgument(parentId); 363 function.appendArgument(prevId); 364 function.appendArgument(node); 365 function.call(); 366} 367 368void InspectorFrontend::childNodeRemoved(int parentId, int id) 369{ 370 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 371 function.appendArgument("childNodeRemoved"); 372 function.appendArgument(parentId); 373 function.appendArgument(id); 374 function.call(); 375} 376 377void InspectorFrontend::attributesUpdated(int id, const ScriptArray& attributes) 378{ 379 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 380 function.appendArgument("attributesUpdated"); 381 function.appendArgument(id); 382 function.appendArgument(attributes); 383 function.call(); 384} 385 386void InspectorFrontend::didRemoveNode(int callId, int nodeId) 387{ 388 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 389 function.appendArgument("didRemoveNode"); 390 function.appendArgument(callId); 391 function.appendArgument(nodeId); 392 function.call(); 393} 394 395void InspectorFrontend::didGetChildNodes(int callId) 396{ 397 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 398 function.appendArgument("didGetChildNodes"); 399 function.appendArgument(callId); 400 function.call(); 401} 402 403void InspectorFrontend::didApplyDomChange(int callId, bool success) 404{ 405 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 406 function.appendArgument("didApplyDomChange"); 407 function.appendArgument(callId); 408 function.appendArgument(success); 409 function.call(); 410} 411 412void InspectorFrontend::didGetEventListenersForNode(int callId, int nodeId, ScriptArray& listenersArray) 413{ 414 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 415 function.appendArgument("didGetEventListenersForNode"); 416 function.appendArgument(callId); 417 function.appendArgument(nodeId); 418 function.appendArgument(listenersArray); 419 function.call(); 420} 421 422void InspectorFrontend::didGetCookies(int callId, const ScriptArray& cookies, const String& cookiesString) 423{ 424 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 425 function.appendArgument("didGetCookies"); 426 function.appendArgument(callId); 427 function.appendArgument(cookies); 428 function.appendArgument(cookiesString); 429 function.call(); 430} 431 432void InspectorFrontend::didDispatchOnInjectedScript(int callId, const String& result, bool isException) 433{ 434 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 435 function.appendArgument("didDispatchOnInjectedScript"); 436 function.appendArgument(callId); 437 function.appendArgument(result); 438 function.appendArgument(isException); 439 function.call(); 440} 441 442#if ENABLE(DATABASE) 443bool InspectorFrontend::addDatabase(const ScriptObject& dbObject) 444{ 445 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 446 function.appendArgument("addDatabase"); 447 function.appendArgument(dbObject); 448 bool hadException = false; 449 function.call(hadException); 450 return !hadException; 451} 452 453void InspectorFrontend::selectDatabase(int databaseId) 454{ 455 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 456 function.appendArgument("selectDatabase"); 457 function.appendArgument(databaseId); 458 function.call(); 459} 460void InspectorFrontend::didGetDatabaseTableNames(int callId, const ScriptArray& tableNames) 461{ 462 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 463 function.appendArgument("didGetDatabaseTableNames"); 464 function.appendArgument(callId); 465 function.appendArgument(tableNames); 466 function.call(); 467} 468#endif 469 470#if ENABLE(DOM_STORAGE) 471bool InspectorFrontend::addDOMStorage(const ScriptObject& domStorageObj) 472{ 473 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 474 function.appendArgument("addDOMStorage"); 475 function.appendArgument(domStorageObj); 476 bool hadException = false; 477 function.call(hadException); 478 return !hadException; 479} 480 481void InspectorFrontend::selectDOMStorage(int storageId) 482{ 483 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 484 function.appendArgument("selectDOMStorage"); 485 function.appendArgument(storageId); 486 function.call(); 487} 488 489void InspectorFrontend::didGetDOMStorageEntries(int callId, const ScriptArray& entries) 490{ 491 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 492 function.appendArgument("didGetDOMStorageEntries"); 493 function.appendArgument(callId); 494 function.appendArgument(entries); 495 function.call(); 496} 497 498void InspectorFrontend::didSetDOMStorageItem(int callId, bool success) 499{ 500 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 501 function.appendArgument("didSetDOMStorageItem"); 502 function.appendArgument(callId); 503 function.appendArgument(success); 504 function.call(); 505} 506 507void InspectorFrontend::didRemoveDOMStorageItem(int callId, bool success) 508{ 509 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 510 function.appendArgument("didRemoveDOMStorageItem"); 511 function.appendArgument(callId); 512 function.appendArgument(success); 513 function.call(); 514} 515 516void InspectorFrontend::updateDOMStorage(int storageId) 517{ 518 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 519 function.appendArgument("updateDOMStorage"); 520 function.appendArgument(storageId); 521 function.call(); 522} 523#endif 524 525void InspectorFrontend::addNodesToSearchResult(const String& nodeIds) 526{ 527 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 528 function.appendArgument("addNodesToSearchResult"); 529 function.appendArgument(nodeIds); 530 function.call(); 531} 532 533void InspectorFrontend::contextMenuItemSelected(int itemId) 534{ 535 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 536 function.appendArgument("contextMenuItemSelected"); 537 function.appendArgument(itemId); 538 function.call(); 539} 540 541void InspectorFrontend::contextMenuCleared() 542{ 543 callSimpleFunction("contextMenuCleared"); 544} 545 546void InspectorFrontend::evaluateForTestInFrontend(int callId, const String& script) 547{ 548 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 549 function.appendArgument("evaluateForTestInFrontend"); 550 function.appendArgument(callId); 551 function.appendArgument(script); 552 function.call(); 553} 554 555void InspectorFrontend::callSimpleFunction(const String& functionName) 556{ 557 ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch"); 558 function.appendArgument(functionName); 559 function.call(); 560} 561 562} // namespace WebCore 563 564#endif // ENABLE(INSPECTOR) 565