OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "core/input/EventHandler.h" | 40 #include "core/input/EventHandler.h" |
41 #include "core/inspector/InspectorCSSAgent.h" | 41 #include "core/inspector/InspectorCSSAgent.h" |
42 #include "core/inspector/InspectorDebuggerAgent.h" | 42 #include "core/inspector/InspectorDebuggerAgent.h" |
43 #include "core/inspector/InspectorOverlayHost.h" | 43 #include "core/inspector/InspectorOverlayHost.h" |
44 #include "core/inspector/LayoutEditor.h" | 44 #include "core/inspector/LayoutEditor.h" |
45 #include "core/layout/LayoutView.h" | 45 #include "core/layout/LayoutView.h" |
46 #include "core/loader/EmptyClients.h" | 46 #include "core/loader/EmptyClients.h" |
47 #include "core/loader/FrameLoadRequest.h" | 47 #include "core/loader/FrameLoadRequest.h" |
48 #include "core/page/ChromeClient.h" | 48 #include "core/page/ChromeClient.h" |
49 #include "core/page/Page.h" | 49 #include "core/page/Page.h" |
50 #include "platform/JSONValues.h" | |
51 #include "platform/ScriptForbiddenScope.h" | 50 #include "platform/ScriptForbiddenScope.h" |
52 #include "platform/graphics/GraphicsContext.h" | 51 #include "platform/graphics/GraphicsContext.h" |
53 #include "platform/graphics/paint/CullRect.h" | 52 #include "platform/graphics/paint/CullRect.h" |
54 #include "platform/graphics/paint/DisplayItemCacheSkipper.h" | 53 #include "platform/graphics/paint/DisplayItemCacheSkipper.h" |
| 54 #include "platform/inspector_protocol/Values.h" |
55 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
56 #include "public/platform/WebData.h" | 56 #include "public/platform/WebData.h" |
57 #include "web/PageOverlay.h" | 57 #include "web/PageOverlay.h" |
58 #include "web/WebInputEventConversion.h" | 58 #include "web/WebInputEventConversion.h" |
59 #include "web/WebLocalFrameImpl.h" | 59 #include "web/WebLocalFrameImpl.h" |
60 #include "web/WebViewImpl.h" | 60 #include "web/WebViewImpl.h" |
61 #include <v8.h> | 61 #include <v8.h> |
62 | 62 |
63 namespace blink { | 63 namespace blink { |
64 | 64 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 reset(viewportSize, visibleRectInDocument.location()); | 393 reset(viewportSize, visibleRectInDocument.location()); |
394 | 394 |
395 drawNodeHighlight(); | 395 drawNodeHighlight(); |
396 drawQuadHighlight(); | 396 drawQuadHighlight(); |
397 drawPausedInDebuggerMessage(); | 397 drawPausedInDebuggerMessage(); |
398 drawViewSize(); | 398 drawViewSize(); |
399 if (m_layoutEditor && !m_highlightNode) | 399 if (m_layoutEditor && !m_highlightNode) |
400 m_layoutEditor->rebuild(); | 400 m_layoutEditor->rebuild(); |
401 } | 401 } |
402 | 402 |
403 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) | 403 static PassRefPtr<protocol::DictionaryValue> buildObjectForSize(const IntSize& s
ize) |
404 { | 404 { |
405 RefPtr<JSONObject> result = JSONObject::create(); | 405 RefPtr<protocol::DictionaryValue> result = protocol::DictionaryValue::create
(); |
406 result->setNumber("width", size.width()); | 406 result->setNumber("width", size.width()); |
407 result->setNumber("height", size.height()); | 407 result->setNumber("height", size.height()); |
408 return result.release(); | 408 return result.release(); |
409 } | 409 } |
410 | 410 |
411 void InspectorOverlay::drawNodeHighlight() | 411 void InspectorOverlay::drawNodeHighlight() |
412 { | 412 { |
413 if (!m_highlightNode) | 413 if (!m_highlightNode) |
414 return; | 414 return; |
415 | 415 |
416 String selectors = m_nodeHighlightConfig.selectorList; | 416 String selectors = m_nodeHighlightConfig.selectorList; |
417 RefPtrWillBeRawPtr<StaticElementList> elements = nullptr; | 417 RefPtrWillBeRawPtr<StaticElementList> elements = nullptr; |
418 TrackExceptionState exceptionState; | 418 TrackExceptionState exceptionState; |
419 ContainerNode* queryBase = m_highlightNode->containingShadowRoot(); | 419 ContainerNode* queryBase = m_highlightNode->containingShadowRoot(); |
420 if (!queryBase) | 420 if (!queryBase) |
421 queryBase = m_highlightNode->ownerDocument(); | 421 queryBase = m_highlightNode->ownerDocument(); |
422 if (selectors.length()) | 422 if (selectors.length()) |
423 elements = queryBase->querySelectorAll(AtomicString(selectors), exceptio
nState); | 423 elements = queryBase->querySelectorAll(AtomicString(selectors), exceptio
nState); |
424 if (elements && !exceptionState.hadException()) { | 424 if (elements && !exceptionState.hadException()) { |
425 for (unsigned i = 0; i < elements->length(); ++i) { | 425 for (unsigned i = 0; i < elements->length(); ++i) { |
426 Element* element = elements->item(i); | 426 Element* element = elements->item(i); |
427 InspectorHighlight highlight(element, m_nodeHighlightConfig, false); | 427 InspectorHighlight highlight(element, m_nodeHighlightConfig, false); |
428 RefPtr<JSONObject> highlightJSON = highlight.asJSONObject(); | 428 RefPtr<protocol::DictionaryValue> highlightJSON = highlight.asProtoc
olValue(); |
429 evaluateInOverlay("drawHighlight", highlightJSON.release()); | 429 evaluateInOverlay("drawHighlight", highlightJSON.release()); |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 bool appendElementInfo = m_highlightNode->isElementNode() && !m_omitTooltip
&& m_nodeHighlightConfig.showInfo && m_highlightNode->layoutObject() && m_highli
ghtNode->document().frame(); | 433 bool appendElementInfo = m_highlightNode->isElementNode() && !m_omitTooltip
&& m_nodeHighlightConfig.showInfo && m_highlightNode->layoutObject() && m_highli
ghtNode->document().frame(); |
434 InspectorHighlight highlight(m_highlightNode.get(), m_nodeHighlightConfig, a
ppendElementInfo); | 434 InspectorHighlight highlight(m_highlightNode.get(), m_nodeHighlightConfig, a
ppendElementInfo); |
435 if (m_eventTargetNode) | 435 if (m_eventTargetNode) |
436 highlight.appendEventTargetQuads(m_eventTargetNode.get(), m_nodeHighligh
tConfig); | 436 highlight.appendEventTargetQuads(m_eventTargetNode.get(), m_nodeHighligh
tConfig); |
437 | 437 |
438 RefPtr<JSONObject> highlightJSON = highlight.asJSONObject(); | 438 RefPtr<protocol::DictionaryValue> highlightJSON = highlight.asProtocolValue(
); |
439 evaluateInOverlay("drawHighlight", highlightJSON.release()); | 439 evaluateInOverlay("drawHighlight", highlightJSON.release()); |
440 } | 440 } |
441 | 441 |
442 void InspectorOverlay::drawQuadHighlight() | 442 void InspectorOverlay::drawQuadHighlight() |
443 { | 443 { |
444 if (!m_highlightQuad) | 444 if (!m_highlightQuad) |
445 return; | 445 return; |
446 | 446 |
447 InspectorHighlight highlight; | 447 InspectorHighlight highlight; |
448 highlight.appendQuad(*m_highlightQuad, m_quadHighlightConfig.content, m_quad
HighlightConfig.contentOutline); | 448 highlight.appendQuad(*m_highlightQuad, m_quadHighlightConfig.content, m_quad
HighlightConfig.contentOutline); |
449 evaluateInOverlay("drawHighlight", highlight.asJSONObject()); | 449 evaluateInOverlay("drawHighlight", highlight.asProtocolValue()); |
450 } | 450 } |
451 | 451 |
452 void InspectorOverlay::drawPausedInDebuggerMessage() | 452 void InspectorOverlay::drawPausedInDebuggerMessage() |
453 { | 453 { |
454 if (m_inspectMode == InspectorDOMAgent::NotSearching && !m_pausedInDebuggerM
essage.isNull()) | 454 if (m_inspectMode == InspectorDOMAgent::NotSearching && !m_pausedInDebuggerM
essage.isNull()) |
455 evaluateInOverlay("drawPausedInDebuggerMessage", m_pausedInDebuggerMessa
ge); | 455 evaluateInOverlay("drawPausedInDebuggerMessage", m_pausedInDebuggerMessa
ge); |
456 } | 456 } |
457 | 457 |
458 void InspectorOverlay::drawViewSize() | 458 void InspectorOverlay::drawViewSize() |
459 { | 459 { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 return m_overlayPage.get(); | 525 return m_overlayPage.get(); |
526 } | 526 } |
527 | 527 |
528 LocalFrame* InspectorOverlay::overlayMainFrame() | 528 LocalFrame* InspectorOverlay::overlayMainFrame() |
529 { | 529 { |
530 return toLocalFrame(overlayPage()->mainFrame()); | 530 return toLocalFrame(overlayPage()->mainFrame()); |
531 } | 531 } |
532 | 532 |
533 void InspectorOverlay::reset(const IntSize& viewportSize, const IntPoint& docume
ntScrollOffset) | 533 void InspectorOverlay::reset(const IntSize& viewportSize, const IntPoint& docume
ntScrollOffset) |
534 { | 534 { |
535 RefPtr<JSONObject> resetData = JSONObject::create(); | 535 RefPtr<protocol::DictionaryValue> resetData = protocol::DictionaryValue::cre
ate(); |
536 resetData->setNumber("deviceScaleFactor", m_webViewImpl->page()->deviceScale
Factor()); | 536 resetData->setNumber("deviceScaleFactor", m_webViewImpl->page()->deviceScale
Factor()); |
537 resetData->setNumber("pageScaleFactor", m_webViewImpl->page()->pageScaleFact
or()); | 537 resetData->setNumber("pageScaleFactor", m_webViewImpl->page()->pageScaleFact
or()); |
538 resetData->setObject("viewportSize", buildObjectForSize(viewportSize)); | 538 resetData->setObject("viewportSize", buildObjectForSize(viewportSize)); |
539 resetData->setNumber("pageZoomFactor", m_webViewImpl->mainFrameImpl()->frame
()->pageZoomFactor()); | 539 resetData->setNumber("pageZoomFactor", m_webViewImpl->mainFrameImpl()->frame
()->pageZoomFactor()); |
540 resetData->setNumber("scrollX", documentScrollOffset.x()); | 540 resetData->setNumber("scrollX", documentScrollOffset.x()); |
541 resetData->setNumber("scrollY", documentScrollOffset.y()); | 541 resetData->setNumber("scrollY", documentScrollOffset.y()); |
542 evaluateInOverlay("reset", resetData.release()); | 542 evaluateInOverlay("reset", resetData.release()); |
543 } | 543 } |
544 | 544 |
545 void InspectorOverlay::evaluateInOverlay(const String& method, const String& arg
ument) | 545 void InspectorOverlay::evaluateInOverlay(const String& method, const String& arg
ument) |
546 { | 546 { |
547 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 547 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
548 RefPtr<JSONArray> command = JSONArray::create(); | 548 RefPtr<protocol::ListValue> command = protocol::ListValue::create(); |
549 command->pushString(method); | 549 command->pushValue(protocol::StringValue::create(method)); |
550 command->pushString(argument); | 550 command->pushValue(protocol::StringValue::create(argument)); |
551 toLocalFrame(overlayPage()->mainFrame())->script().executeScriptInMainWorld(
"dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhen
ScriptsDisabled); | 551 toLocalFrame(overlayPage()->mainFrame())->script().executeScriptInMainWorld(
"dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhen
ScriptsDisabled); |
552 } | 552 } |
553 | 553 |
554 void InspectorOverlay::evaluateInOverlay(const String& method, PassRefPtr<JSONVa
lue> argument) | 554 void InspectorOverlay::evaluateInOverlay(const String& method, PassRefPtr<protoc
ol::Value> argument) |
555 { | 555 { |
556 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 556 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
557 RefPtr<JSONArray> command = JSONArray::create(); | 557 RefPtr<protocol::ListValue> command = protocol::ListValue::create(); |
558 command->pushString(method); | 558 command->pushValue(protocol::StringValue::create(method)); |
559 command->pushValue(argument); | 559 command->pushValue(argument); |
560 toLocalFrame(overlayPage()->mainFrame())->script().executeScriptInMainWorld(
"dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhen
ScriptsDisabled); | 560 toLocalFrame(overlayPage()->mainFrame())->script().executeScriptInMainWorld(
"dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhen
ScriptsDisabled); |
561 } | 561 } |
562 | 562 |
563 String InspectorOverlay::evaluateInOverlayForTest(const String& script) | 563 String InspectorOverlay::evaluateInOverlayForTest(const String& script) |
564 { | 564 { |
565 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 565 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
566 v8::HandleScope handleScope(toIsolate(overlayMainFrame())); | 566 v8::HandleScope handleScope(toIsolate(overlayMainFrame())); |
567 v8::Local<v8::Value> string = toLocalFrame(overlayPage()->mainFrame())->scri
pt().executeScriptInMainWorldAndReturnValue(ScriptSourceCode(script), ScriptCont
roller::ExecuteScriptWhenScriptsDisabled); | 567 v8::Local<v8::Value> string = toLocalFrame(overlayPage()->mainFrame())->scri
pt().executeScriptInMainWorldAndReturnValue(ScriptSourceCode(script), ScriptCont
roller::ExecuteScriptWhenScriptsDisabled); |
568 return toCoreStringWithUndefinedOrNullCheck(string); | 568 return toCoreStringWithUndefinedOrNullCheck(string); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 | 774 |
775 void InspectorOverlay::initializeLayoutEditorIfNeeded(Node* node) | 775 void InspectorOverlay::initializeLayoutEditorIfNeeded(Node* node) |
776 { | 776 { |
777 if (m_inspectMode != InspectorDOMAgent::ShowLayoutEditor || !node || !node->
isElementNode() || !node->ownerDocument()->isActive()) | 777 if (m_inspectMode != InspectorDOMAgent::ShowLayoutEditor || !node || !node->
isElementNode() || !node->ownerDocument()->isActive()) |
778 return; | 778 return; |
779 m_layoutEditor = LayoutEditor::create(toElement(node), m_cssAgent, m_domAgen
t, &overlayMainFrame()->script()); | 779 m_layoutEditor = LayoutEditor::create(toElement(node), m_cssAgent, m_domAgen
t, &overlayMainFrame()->script()); |
780 toChromeClientImpl(m_webViewImpl->page()->chromeClient()).setCursorOverridde
n(true); | 780 toChromeClientImpl(m_webViewImpl->page()->chromeClient()).setCursorOverridde
n(true); |
781 } | 781 } |
782 | 782 |
783 } // namespace blink | 783 } // namespace blink |
OLD | NEW |