diff --git a/DEPS b/DEPS index 306eac5..6e964e0 100644 --- a/DEPS +++ b/DEPS
@@ -44,7 +44,7 @@ # Three lines of non-changing comments so that # the commit queue can handle CLs rolling V8 # and whatever else without interference from each other. - 'v8_revision': 'f94282f11afd4ea36343128bc2d1b7bf9f01de0d', + 'v8_revision': '7b980824fe0fc9bcc507b6279fdae302831ed930', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling swarming_client # and whatever else without interference from each other.
diff --git a/content/browser/devtools/protocol/schema_handler.cc b/content/browser/devtools/protocol/schema_handler.cc index f4f862c..6cf5b21d 100644 --- a/content/browser/devtools/protocol/schema_handler.cc +++ b/content/browser/devtools/protocol/schema_handler.cc
@@ -22,37 +22,14 @@ std::unique_ptr<protocol::Array<Schema::Domain>>* domains) { // TODO(kozyatisnkiy): get this from the target instead of hardcoding a list. static const char kVersion[] = "1.2"; - static const char* kDomains[] = {"Inspector", - "Memory", - "Page", - "Emulation", - "Security", - "Network", - "Database", - "IndexedDB", - "CacheStorage", - "DOMStorage", - "CSS", - "ApplicationCache", - "DOM", - "IO", - "DOMDebugger", - "ServiceWorker", - "Input", - "LayerTree", - "DeviceOrientation", - "Tracing", - "Animation", - "Accessibility", - "Storage", - "Log", - "Runtime", - "Debugger", - "Profiler", - "HeapProfiler", - "Schema", - "Target", - "Overlay"}; + static const char* kDomains[] = { + "Inspector", "Memory", "Page", "Rendering", "Emulation", "Security", + "Network", "Database", "IndexedDB", "CacheStorage", "DOMStorage", "CSS", + "ApplicationCache", "DOM", "IO", "DOMDebugger", "ServiceWorker", + "Input", "LayerTree", "DeviceOrientation", "Tracing", "Animation", + "Accessibility", "Storage", "Log", "Runtime", "Debugger", + "Profiler", "HeapProfiler", "Schema", "Target" + }; *domains = protocol::Array<Schema::Domain>::create(); for (size_t i = 0; i < arraysize(kDomains); ++i) { (*domains)->addItem(Schema::Domain::Create()
diff --git a/headless/BUILD.gn b/headless/BUILD.gn index b3407de0..de78c61 100644 --- a/headless/BUILD.gn +++ b/headless/BUILD.gn
@@ -146,6 +146,7 @@ "network", "page", "profiler", + "rendering", "runtime", "security", "service_worker",
diff --git a/headless/lib/browser/headless_devtools_client_impl.cc b/headless/lib/browser/headless_devtools_client_impl.cc index 0b6cc969..9cb9de77 100644 --- a/headless/lib/browser/headless_devtools_client_impl.cc +++ b/headless/lib/browser/headless_devtools_client_impl.cc
@@ -59,6 +59,7 @@ network_domain_(this), page_domain_(this), profiler_domain_(this), + rendering_domain_(this), runtime_domain_(this), security_domain_(this), service_worker_domain_(this), @@ -328,6 +329,10 @@ return &profiler_domain_; } +rendering::Domain* HeadlessDevToolsClientImpl::GetRendering() { + return &rendering_domain_; +} + runtime::Domain* HeadlessDevToolsClientImpl::GetRuntime() { return &runtime_domain_; }
diff --git a/headless/lib/browser/headless_devtools_client_impl.h b/headless/lib/browser/headless_devtools_client_impl.h index 3accb438..1b17967 100644 --- a/headless/lib/browser/headless_devtools_client_impl.h +++ b/headless/lib/browser/headless_devtools_client_impl.h
@@ -34,6 +34,7 @@ #include "headless/public/devtools/domains/network.h" #include "headless/public/devtools/domains/page.h" #include "headless/public/devtools/domains/profiler.h" +#include "headless/public/devtools/domains/rendering.h" #include "headless/public/devtools/domains/runtime.h" #include "headless/public/devtools/domains/security.h" #include "headless/public/devtools/domains/service_worker.h" @@ -86,6 +87,7 @@ network::Domain* GetNetwork() override; page::Domain* GetPage() override; profiler::Domain* GetProfiler() override; + rendering::Domain* GetRendering() override; runtime::Domain* GetRuntime() override; security::Domain* GetSecurity() override; service_worker::Domain* GetServiceWorker() override; @@ -188,6 +190,7 @@ network::ExperimentalDomain network_domain_; page::ExperimentalDomain page_domain_; profiler::ExperimentalDomain profiler_domain_; + rendering::ExperimentalDomain rendering_domain_; runtime::ExperimentalDomain runtime_domain_; security::ExperimentalDomain security_domain_; service_worker::ExperimentalDomain service_worker_domain_;
diff --git a/headless/public/headless_devtools_client.h b/headless/public/headless_devtools_client.h index b3cea9482..7e7d979 100644 --- a/headless/public/headless_devtools_client.h +++ b/headless/public/headless_devtools_client.h
@@ -84,6 +84,9 @@ namespace profiler { class Domain; } +namespace rendering { +class Domain; +} namespace runtime { class Domain; } @@ -136,6 +139,7 @@ virtual network::Domain* GetNetwork() = 0; virtual page::Domain* GetPage() = 0; virtual profiler::Domain* GetProfiler() = 0; + virtual rendering::Domain* GetRendering() = 0; virtual runtime::Domain* GetRuntime() = 0; virtual security::Domain* GetSecurity() = 0; virtual service_worker::Domain* GetServiceWorker() = 0;
diff --git a/sql/connection.cc b/sql/connection.cc index 0511e11..c80758f 100644 --- a/sql/connection.cc +++ b/sql/connection.cc
@@ -1112,6 +1112,15 @@ // page_size" can be used to query such a database. ScopedWritableSchema writable_schema(db_); +#if defined(OS_WIN) + // On Windows, truncate silently fails when applied to memory-mapped files. + // Disable memory-mapping so that the truncate succeeds. Note that other + // connections may have memory-mapped the file, so this may not entirely + // prevent the problem. + // [Source: <https://sqlite.org/mmap.html> plus experiments.] + ignore_result(Execute("PRAGMA mmap_size = 0")); +#endif + const char* kMain = "main"; int rc = BackupDatabase(null_db.db_, db_, kMain); UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.RazeDatabase",rc);
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc index 6ac4f8b..4ee8b028 100644 --- a/sql/connection_unittest.cc +++ b/sql/connection_unittest.cc
@@ -854,6 +854,42 @@ // closely match real life. That would also allow testing // RazeWithTimeout(). +// On Windows, truncate silently fails against a memory-mapped file. One goal +// of Raze() is to truncate the file to remove blocks which generate I/O errors. +// Test that Raze() turns off memory mapping so that the file is truncated. +// [This would not cover the case of multiple connections where one of the other +// connections is memory-mapped. That is infrequent in Chromium.] +TEST_F(SQLConnectionTest, RazeTruncate) { + // The empty database has 0 or 1 pages. Raze() should leave it with exactly 1 + // page. Not checking directly because auto_vacuum on Android adds a freelist + // page. + ASSERT_TRUE(db().Raze()); + int64_t expected_size; + ASSERT_TRUE(base::GetFileSize(db_path(), &expected_size)); + ASSERT_GT(expected_size, 0); + + // Cause the database to take a few pages. + const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; + ASSERT_TRUE(db().Execute(kCreateSql)); + for (size_t i = 0; i < 24; ++i) { + ASSERT_TRUE( + db().Execute("INSERT INTO foo (value) VALUES (randomblob(1024))")); + } + int64_t db_size; + ASSERT_TRUE(base::GetFileSize(db_path(), &db_size)); + ASSERT_GT(db_size, expected_size); + + // Make a query covering most of the database file to make sure that the + // blocks are actually mapped into memory. Empirically, the truncate problem + // doesn't seem to happen if no blocks are mapped. + EXPECT_EQ("24576", + ExecuteWithResult(&db(), "SELECT SUM(LENGTH(value)) FROM foo")); + + ASSERT_TRUE(db().Raze()); + ASSERT_TRUE(base::GetFileSize(db_path(), &db_size)); + ASSERT_EQ(expected_size, db_size); +} + #if defined(OS_ANDROID) TEST_F(SQLConnectionTest, SetTempDirForSQL) {
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/elements-test.js b/third_party/WebKit/LayoutTests/http/tests/inspector/elements-test.js index d965cc1..495b94a 100644 --- a/third_party/WebKit/LayoutTests/http/tests/inspector/elements-test.js +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/elements-test.js
@@ -967,7 +967,7 @@ function nodeResolved(node) { - InspectorTest.OverlayAgent.getHighlightObjectForTest(node.id, report); + InspectorTest.DOMAgent.getHighlightObjectForTest(node.id, report); } function report(error, result)
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js b/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js index bee51ac1..27539da 100644 --- a/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js
@@ -978,7 +978,6 @@ InspectorTest.HeapProfilerAgent = target.heapProfilerAgent(); InspectorTest.InspectorAgent = target.inspectorAgent(); InspectorTest.NetworkAgent = target.networkAgent(); - InspectorTest.OverlayAgent = target.overlayAgent(); InspectorTest.PageAgent = target.pageAgent(); InspectorTest.ProfilerAgent = target.profilerAgent(); InspectorTest.RuntimeAgent = target.runtimeAgent(); @@ -993,7 +992,6 @@ InspectorTest.domDebuggerModel = target.model(SDK.DOMDebuggerModel); InspectorTest.cssModel = target.model(SDK.CSSModel); InspectorTest.cpuProfilerModel = target.model(SDK.CPUProfilerModel); - InspectorTest.overlayModel = target.model(SDK.OverlayModel); InspectorTest.serviceWorkerManager = target.model(SDK.ServiceWorkerManager); InspectorTest.tracingManager = target.model(SDK.TracingManager); InspectorTest.mainTarget = target;
diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/dom/dom-setInspectModeEnabled.html b/third_party/WebKit/LayoutTests/inspector-protocol/dom/dom-setInspectModeEnabled.html index f10e98e..24432f9 100644 --- a/third_party/WebKit/LayoutTests/inspector-protocol/dom/dom-setInspectModeEnabled.html +++ b/third_party/WebKit/LayoutTests/inspector-protocol/dom/dom-setInspectModeEnabled.html
@@ -7,10 +7,9 @@ { var nodeInfo = {}; InspectorTest.eventHandler["DOM.setChildNodes"] = setChildNodes; - InspectorTest.eventHandler["Overlay.inspectNodeRequested"] = inspectNodeRequested; + InspectorTest.eventHandler["DOM.inspectNodeRequested"] = inspectNodeRequested; InspectorTest.sendCommand("DOM.enable", {}); - InspectorTest.sendCommand("Overlay.enable", {}); - InspectorTest.sendCommand("Overlay.setInspectMode", { "mode": "searchForNode", highlightConfig: {} }, onSetModeEnabled); + InspectorTest.sendCommand("DOM.setInspectMode", { "mode": "searchForNode", highlightConfig: {} }, onSetModeEnabled); function onSetModeEnabled(message) {
diff --git a/third_party/WebKit/LayoutTests/inspector/agents-enable-disable-expected.txt b/third_party/WebKit/LayoutTests/inspector/agents-enable-disable-expected.txt index c9fe4a65..e9cbe18 100644 --- a/third_party/WebKit/LayoutTests/inspector/agents-enable-disable-expected.txt +++ b/third_party/WebKit/LayoutTests/inspector/agents-enable-disable-expected.txt
@@ -11,7 +11,6 @@ LayerTree.disable finished successfully Log.disable finished successfully Network.disable finished successfully -Overlay.disable finished successfully Page.disable finished successfully Profiler.disable finished successfully Runtime.disable finished successfully @@ -49,9 +48,6 @@ Network.enable finished successfully Network.disable finished successfully -Overlay.enable finished with error DOM should be enabled first -Overlay.disable finished successfully - Page.enable finished successfully Page.disable finished successfully
diff --git a/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-after-profiling.html b/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-after-profiling.html index cba03b6..8d40576 100644 --- a/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-after-profiling.html +++ b/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-after-profiling.html
@@ -18,7 +18,7 @@ { InspectorTest.cpuProfilerModel.startRecording(); InspectorTest.cpuProfilerModel.stopRecording(); - InspectorTest.overlayModel.setInspectMode(Protocol.Overlay.InspectMode.SearchForNode).then(clickAtInspected); + InspectorTest.domModel.setInspectMode(Protocol.DOM.InspectMode.SearchForNode, clickAtInspected); function clickAtInspected() {
diff --git a/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-shadow-text.html b/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-shadow-text.html index fb1e8d04..694383e 100644 --- a/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-shadow-text.html +++ b/third_party/WebKit/LayoutTests/inspector/elements/inspect-mode-shadow-text.html
@@ -19,7 +19,7 @@ function test() { - InspectorTest.overlayModel.setInspectMode(Protocol.Overlay.InspectMode.SearchForNode).then(step2); + InspectorTest.domModel.setInspectMode(Protocol.DOM.InspectMode.SearchForNode, step2); function step2() {
diff --git a/third_party/WebKit/LayoutTests/inspector/elements/inspect-pointer-events-none.html b/third_party/WebKit/LayoutTests/inspector/elements/inspect-pointer-events-none.html index ab0ee74..71505d93f 100644 --- a/third_party/WebKit/LayoutTests/inspector/elements/inspect-pointer-events-none.html +++ b/third_party/WebKit/LayoutTests/inspector/elements/inspect-pointer-events-none.html
@@ -59,7 +59,7 @@ function step1() { - InspectorTest.overlayModel.setInspectMode(Protocol.Overlay.InspectMode.SearchForNode).then(step2); + InspectorTest.domModel.setInspectMode(Protocol.DOM.InspectMode.SearchForNode, step2); } function step2() @@ -72,7 +72,7 @@ { InspectorTest.firstElementsTreeOutline().removeEventListener(Elements.ElementsTreeOutline.Events.SelectedNodeChanged, step3); expectSelectedNode("inner"); - InspectorTest.overlayModel.setInspectMode(Protocol.Overlay.InspectMode.SearchForNode).then(step4); + InspectorTest.domModel.setInspectMode(Protocol.DOM.InspectMode.SearchForNode, step4); } function step4()
diff --git a/third_party/WebKit/LayoutTests/inspector/elements/inspect-pseudo-element.html b/third_party/WebKit/LayoutTests/inspector/elements/inspect-pseudo-element.html index 2598996..5f34553 100644 --- a/third_party/WebKit/LayoutTests/inspector/elements/inspect-pseudo-element.html +++ b/third_party/WebKit/LayoutTests/inspector/elements/inspect-pseudo-element.html
@@ -16,7 +16,7 @@ function test() { - InspectorTest.overlayModel.setInspectMode(Protocol.Overlay.InspectMode.SearchForNode).then(inspectModeEnabled); + InspectorTest.domModel.setInspectMode(Protocol.DOM.InspectMode.SearchForNode, inspectModeEnabled); function inspectModeEnabled() {
diff --git a/third_party/WebKit/LayoutTests/inspector/layers/no-overlay-layers.html b/third_party/WebKit/LayoutTests/inspector/layers/no-overlay-layers.html index 8300cdb..0a82d716 100644 --- a/third_party/WebKit/LayoutTests/inspector/layers/no-overlay-layers.html +++ b/third_party/WebKit/LayoutTests/inspector/layers/no-overlay-layers.html
@@ -25,7 +25,7 @@ { // Assure layer objects are not re-created during updates. InspectorTest.layerTreeModel().layerTree().forEachLayer(function(layer) { layersBeforeHighlight.push(layer.id()); }); - InspectorTest.OverlayAgent.highlightRect(0, 0, 200, 200, {r:255, g:0, b:0}); + InspectorTest.DOMAgent.highlightRect(0, 0, 200, 200, {r:255, g:0, b:0}); InspectorTest.evaluateAndRunWhenTreeChanges("requestAnimationFrame(updateGeometry)", step2); }
diff --git a/third_party/WebKit/LayoutTests/inspector/profiler/agents-disabled-check-expected.txt b/third_party/WebKit/LayoutTests/inspector/profiler/agents-disabled-check-expected.txt index accaa67..0d62404 100644 --- a/third_party/WebKit/LayoutTests/inspector/profiler/agents-disabled-check-expected.txt +++ b/third_party/WebKit/LayoutTests/inspector/profiler/agents-disabled-check-expected.txt
@@ -1,22 +1,22 @@ Test that if a profiler is working all the agents are disabled. --> SDK.targetManager.suspendAllTargets(); +frontend: {"id":<number>,"method":"Page.configureOverlay","params":{"suspended":true}} frontend: {"id":<number>,"method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":false}} frontend: {"id":<number>,"method":"Debugger.disable"} frontend: {"id":<number>,"method":"Debugger.setAsyncCallStackDepth","params":{"maxDepth":0}} -frontend: {"id":<number>,"method":"Overlay.setPausedInDebuggerMessage"} +frontend: {"id":<number>,"method":"Page.configureOverlay","params":{"suspended":true}} frontend: {"id":<number>,"method":"DOM.disable"} frontend: {"id":<number>,"method":"CSS.disable"} -frontend: {"id":<number>,"method":"Overlay.setSuspended","params":{"suspended":true}} --> SDK.targetManager.resumeAllTargets(); +frontend: {"id":<number>,"method":"Page.configureOverlay","params":{"suspended":false}} frontend: {"id":<number>,"method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":true}} frontend: {"id":<number>,"method":"Debugger.enable"} frontend: {"id":<number>,"method":"Debugger.setPauseOnExceptions","params":{"state":"none"}} frontend: {"id":<number>,"method":"Debugger.setAsyncCallStackDepth","params":{"maxDepth":8}} frontend: {"id":<number>,"method":"DOM.enable"} frontend: {"id":<number>,"method":"CSS.enable"} -frontend: {"id":<number>,"method":"Overlay.setSuspended","params":{"suspended":false}} --> done
diff --git a/third_party/WebKit/Source/core/css/MediaList.cpp b/third_party/WebKit/Source/core/css/MediaList.cpp index 521ab14c..ee1d146 100644 --- a/third_party/WebKit/Source/core/css/MediaList.cpp +++ b/third_party/WebKit/Source/core/css/MediaList.cpp
@@ -67,11 +67,10 @@ bool MediaQuerySet::Set(const String& media_string) { MediaQuerySet* result = Create(media_string); -#if DCHECK_IS_ON() + // TODO(keishi) Changed DCHECK to CHECK for crbug.com/699269 diagnosis for (const auto& query : result->queries_) { - DCHECK(query); + CHECK(query); } -#endif queries_.Swap(result->queries_); return true; } @@ -87,7 +86,8 @@ return true; MediaQuery* new_query = result->queries_[0].Release(); - DCHECK(new_query); + // TODO(keishi) Changed DCHECK to CHECK for crbug.com/699269 diagnosis + CHECK(new_query); // If comparing with any of the media queries in the collection of media // queries returns true terminate these steps. @@ -112,7 +112,8 @@ return true; MediaQuery* new_query = result->queries_[0].Release(); - DCHECK(new_query); + // TODO(keishi) Changed DCHECK to CHECK for crbug.com/699269 diagnosis + CHECK(new_query); // Remove any media query from the collection of media queries for which // comparing with the media query returns true. @@ -130,7 +131,8 @@ } void MediaQuerySet::AddMediaQuery(MediaQuery* media_query) { - DCHECK(media_query); + // TODO(keishi) Changed DCHECK to CHECK for crbug.com/699269 diagnosis + CHECK(media_query); queries_.push_back(media_query); } @@ -209,12 +211,11 @@ } void MediaList::Reattach(MediaQuerySet* media_queries) { - DCHECK(media_queries); -#if DCHECK_IS_ON - for (const auto& query : mediaQueries->queryVector) { - DCHECK(query); + // TODO(keishi) Changed DCHECK to CHECK for crbug.com/699269 diagnosis + CHECK(media_queries); + for (const auto& query : media_queries->QueryVector()) { + CHECK(query); } -#endif media_queries_ = media_queries; }
diff --git a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp index bb422e0..33c9cc9 100644 --- a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp +++ b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
@@ -50,7 +50,12 @@ DocumentStyleSheetCollector& collector) { DocumentOrderedList::MutationForbiddenScope mutation_forbidden_( &style_sheet_candidate_nodes_); + // TODO(keishi) Check added for crbug.com/699269 diagnosis. Remove once done. + CHECK(HeapObjectHeader::FromPayload(this)->IsValid()); + CHECK(ThreadState::Current()->IsOnThreadHeap(this)); for (Node* n : style_sheet_candidate_nodes_) { + CHECK(HeapObjectHeader::FromPayload(n)->IsValid()); + CHECK(ThreadState::Current()->IsOnThreadHeap(n)); StyleSheetCandidate candidate(*n); DCHECK(!candidate.IsXSL());
diff --git a/third_party/WebKit/Source/core/inspector/BUILD.gn b/third_party/WebKit/Source/core/inspector/BUILD.gn index 66150a0..417c1c2 100644 --- a/third_party/WebKit/Source/core/inspector/BUILD.gn +++ b/third_party/WebKit/Source/core/inspector/BUILD.gn
@@ -148,12 +148,12 @@ "inspector/protocol/Memory.h", "inspector/protocol/Network.cpp", "inspector/protocol/Network.h", - "inspector/protocol/Overlay.cpp", - "inspector/protocol/Overlay.h", "inspector/protocol/Page.cpp", "inspector/protocol/Page.h", "inspector/protocol/Protocol.cpp", "inspector/protocol/Protocol.h", + "inspector/protocol/Rendering.cpp", + "inspector/protocol/Rendering.h", "inspector/protocol/Runtime.h", "inspector/protocol/Security.cpp", "inspector/protocol/Security.h",
diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp index 9a66426..a9a2e62 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp
@@ -77,7 +77,6 @@ #include "core/page/Page.h" #include "core/xml/DocumentXPathEvaluator.h" #include "core/xml/XPathResult.h" -#include "platform/graphics/Color.h" #include "platform/wtf/ListHashSet.h" #include "platform/wtf/PtrUtil.h" #include "platform/wtf/text/CString.h" @@ -98,6 +97,38 @@ const size_t kMaxTextSize = 10000; const UChar kEllipsisUChar[] = {0x2026, 0}; +Color ParseColor(protocol::DOM::RGBA* rgba) { + if (!rgba) + return Color::kTransparent; + + int r = rgba->getR(); + int g = rgba->getG(); + int b = rgba->getB(); + if (!rgba->hasA()) + return Color(r, g, b); + + double a = rgba->getA(1); + // Clamp alpha to the [0..1] range. + if (a < 0) + a = 0; + else if (a > 1) + a = 1; + + return Color(r, g, b, static_cast<int>(a * 255)); +} + +bool ParseQuad(std::unique_ptr<protocol::Array<double>> quad_array, + FloatQuad* quad) { + const size_t kCoordinatesInQuad = 8; + if (!quad_array || quad_array->length() != kCoordinatesInQuad) + return false; + quad->SetP1(FloatPoint(quad_array->get(0), quad_array->get(1))); + quad->SetP2(FloatPoint(quad_array->get(2), quad_array->get(3))); + quad->SetP3(FloatPoint(quad_array->get(4), quad_array->get(5))); + quad->SetP4(FloatPoint(quad_array->get(6), quad_array->get(7))); + return true; +} + } // namespace class InspectorRevalidateDOMTask final @@ -203,38 +234,20 @@ } } -// static -Color InspectorDOMAgent::ParseColor(protocol::DOM::RGBA* rgba) { - if (!rgba) - return Color::kTransparent; - - int r = rgba->getR(); - int g = rgba->getG(); - int b = rgba->getB(); - if (!rgba->hasA()) - return Color(r, g, b); - - double a = rgba->getA(1); - // Clamp alpha to the [0..1] range. - if (a < 0) - a = 0; - else if (a > 1) - a = 1; - - return Color(r, g, b, static_cast<int>(a * 255)); -} - InspectorDOMAgent::InspectorDOMAgent( v8::Isolate* isolate, InspectedFrames* inspected_frames, - v8_inspector::V8InspectorSession* v8_session) + v8_inspector::V8InspectorSession* v8_session, + Client* client) : isolate_(isolate), inspected_frames_(inspected_frames), v8_session_(v8_session), + client_(client), dom_listener_(nullptr), document_node_to_id_map_(new NodeToIdMap()), last_node_id_(1), - suppress_attribute_modified_event_(false) {} + suppress_attribute_modified_event_(false), + backend_node_id_to_inspect_(0) {} InspectorDOMAgent::~InspectorDOMAgent() {} @@ -425,6 +438,9 @@ dom_editor_ = new DOMEditor(history_.Get()); document_ = inspected_frames_->Root()->GetDocument(); instrumenting_agents_->addInspectorDOMAgent(this); + if (backend_node_id_to_inspect_) + GetFrontend()->inspectNodeRequested(backend_node_id_to_inspect_); + backend_node_id_to_inspect_ = 0; } Response InspectorDOMAgent::enable() { @@ -441,6 +457,7 @@ if (!Enabled()) return Response::Error("DOM agent hasn't been enabled"); state_->setBoolean(DOMAgentState::kDomAgentEnabled, false); + SetSearchingForNode(kNotSearching, Maybe<protocol::DOM::HighlightConfig>()); instrumenting_agents_->removeInspectorDOMAgent(this); history_.Clear(); dom_editor_.Clear(); @@ -1107,8 +1124,155 @@ return Response::OK(); } -Response InspectorDOMAgent::NodeForRemoteObjectId(const String& object_id, - Node*& node) { +void InspectorDOMAgent::Inspect(Node* inspected_node) { + if (!inspected_node) + return; + + Node* node = inspected_node; + while (node && !node->IsElementNode() && !node->IsDocumentNode() && + !node->IsDocumentFragment()) + node = node->ParentOrShadowHostNode(); + if (!node) + return; + + int backend_node_id = DOMNodeIds::IdForNode(node); + if (!GetFrontend() || !Enabled()) { + backend_node_id_to_inspect_ = backend_node_id; + return; + } + + GetFrontend()->inspectNodeRequested(backend_node_id); +} + +void InspectorDOMAgent::NodeHighlightedInOverlay(Node* node) { + if (!GetFrontend() || !Enabled()) + return; + + while (node && !node->IsElementNode() && !node->IsDocumentNode() && + !node->IsDocumentFragment()) + node = node->ParentOrShadowHostNode(); + + if (!node) + return; + + int node_id = PushNodePathToFrontend(node); + GetFrontend()->nodeHighlightRequested(node_id); +} + +Response InspectorDOMAgent::SetSearchingForNode( + SearchMode search_mode, + Maybe<protocol::DOM::HighlightConfig> highlight_inspector_object) { + if (!client_) + return Response::OK(); + if (search_mode == kNotSearching) { + client_->SetInspectMode(kNotSearching, nullptr); + return Response::OK(); + } + std::unique_ptr<InspectorHighlightConfig> config; + Response response = HighlightConfigFromInspectorObject( + std::move(highlight_inspector_object), &config); + if (!response.isSuccess()) + return response; + client_->SetInspectMode(search_mode, std::move(config)); + return Response::OK(); +} + +Response InspectorDOMAgent::HighlightConfigFromInspectorObject( + Maybe<protocol::DOM::HighlightConfig> highlight_inspector_object, + std::unique_ptr<InspectorHighlightConfig>* out_config) { + if (!highlight_inspector_object.isJust()) { + return Response::Error( + "Internal error: highlight configuration parameter is missing"); + } + + protocol::DOM::HighlightConfig* config = + highlight_inspector_object.fromJust(); + std::unique_ptr<InspectorHighlightConfig> highlight_config = + WTF::MakeUnique<InspectorHighlightConfig>(); + highlight_config->show_info = config->getShowInfo(false); + highlight_config->show_rulers = config->getShowRulers(false); + highlight_config->show_extension_lines = config->getShowExtensionLines(false); + highlight_config->display_as_material = config->getDisplayAsMaterial(false); + highlight_config->content = ParseColor(config->getContentColor(nullptr)); + highlight_config->padding = ParseColor(config->getPaddingColor(nullptr)); + highlight_config->border = ParseColor(config->getBorderColor(nullptr)); + highlight_config->margin = ParseColor(config->getMarginColor(nullptr)); + highlight_config->event_target = + ParseColor(config->getEventTargetColor(nullptr)); + highlight_config->shape = ParseColor(config->getShapeColor(nullptr)); + highlight_config->shape_margin = + ParseColor(config->getShapeMarginColor(nullptr)); + highlight_config->selector_list = config->getSelectorList(""); + + *out_config = std::move(highlight_config); + return Response::OK(); +} + +Response InspectorDOMAgent::setInspectMode( + const String& mode, + Maybe<protocol::DOM::HighlightConfig> highlight_config) { + SearchMode search_mode; + if (mode == protocol::DOM::InspectModeEnum::SearchForNode) { + search_mode = kSearchingForNormal; + } else if (mode == protocol::DOM::InspectModeEnum::SearchForUAShadowDOM) { + search_mode = kSearchingForUAShadow; + } else if (mode == protocol::DOM::InspectModeEnum::None) { + search_mode = kNotSearching; + } else { + return Response::Error( + String("Unknown mode \"" + mode + "\" was provided.")); + } + + if (search_mode != kNotSearching) { + Response response = PushDocumentUponHandlelessOperation(); + if (!response.isSuccess()) + return response; + } + + return SetSearchingForNode(search_mode, std::move(highlight_config)); +} + +Response InspectorDOMAgent::highlightRect( + int x, + int y, + int width, + int height, + Maybe<protocol::DOM::RGBA> color, + Maybe<protocol::DOM::RGBA> outline_color) { + std::unique_ptr<FloatQuad> quad = + WTF::WrapUnique(new FloatQuad(FloatRect(x, y, width, height))); + InnerHighlightQuad(std::move(quad), std::move(color), + std::move(outline_color)); + return Response::OK(); +} + +Response InspectorDOMAgent::highlightQuad( + std::unique_ptr<protocol::Array<double>> quad_array, + Maybe<protocol::DOM::RGBA> color, + Maybe<protocol::DOM::RGBA> outline_color) { + std::unique_ptr<FloatQuad> quad = WTF::MakeUnique<FloatQuad>(); + if (!ParseQuad(std::move(quad_array), quad.get())) + return Response::Error("Invalid Quad format"); + InnerHighlightQuad(std::move(quad), std::move(color), + std::move(outline_color)); + return Response::OK(); +} + +void InspectorDOMAgent::InnerHighlightQuad( + std::unique_ptr<FloatQuad> quad, + Maybe<protocol::DOM::RGBA> color, + Maybe<protocol::DOM::RGBA> outline_color) { + std::unique_ptr<InspectorHighlightConfig> highlight_config = + WTF::MakeUnique<InspectorHighlightConfig>(); + highlight_config->content = ParseColor(color.fromMaybe(nullptr)); + highlight_config->content_outline = + ParseColor(outline_color.fromMaybe(nullptr)); + if (client_) + client_->HighlightQuad(std::move(quad), *highlight_config); +} + +Response InspectorDOMAgent::NodeForRemoteId(const String& object_id, + Node*& node) { v8::HandleScope handles(isolate_); v8::Local<v8::Value> value; v8::Local<v8::Context> context; @@ -1126,6 +1290,66 @@ return Response::OK(); } +Response InspectorDOMAgent::highlightNode( + std::unique_ptr<protocol::DOM::HighlightConfig> highlight_inspector_object, + Maybe<int> node_id, + Maybe<int> backend_node_id, + Maybe<String> object_id) { + Node* node = nullptr; + Response response; + if (node_id.isJust()) { + response = AssertNode(node_id.fromJust(), node); + } else if (backend_node_id.isJust()) { + node = DOMNodeIds::NodeForId(backend_node_id.fromJust()); + response = !node ? Response::Error("No node found for given backend id") + : Response::OK(); + } else if (object_id.isJust()) { + response = NodeForRemoteId(object_id.fromJust(), node); + } else { + response = Response::Error("Either nodeId or objectId must be specified"); + } + + if (!response.isSuccess()) + return response; + + std::unique_ptr<InspectorHighlightConfig> highlight_config; + response = HighlightConfigFromInspectorObject( + std::move(highlight_inspector_object), &highlight_config); + if (!response.isSuccess()) + return response; + + if (client_) + client_->HighlightNode(node, *highlight_config, false); + return Response::OK(); +} + +Response InspectorDOMAgent::highlightFrame( + const String& frame_id, + Maybe<protocol::DOM::RGBA> color, + Maybe<protocol::DOM::RGBA> outline_color) { + LocalFrame* frame = + IdentifiersFactory::FrameById(inspected_frames_, frame_id); + // FIXME: Inspector doesn't currently work cross process. + if (frame && frame->DeprecatedLocalOwner()) { + std::unique_ptr<InspectorHighlightConfig> highlight_config = + WTF::MakeUnique<InspectorHighlightConfig>(); + highlight_config->show_info = true; // Always show tooltips for frames. + highlight_config->content = ParseColor(color.fromMaybe(nullptr)); + highlight_config->content_outline = + ParseColor(outline_color.fromMaybe(nullptr)); + if (client_) + client_->HighlightNode(frame->DeprecatedLocalOwner(), *highlight_config, + false); + } + return Response::OK(); +} + +Response InspectorDOMAgent::hideHighlight() { + if (client_) + client_->HideHighlight(); + return Response::OK(); +} + Response InspectorDOMAgent::copyTo(int node_id, int target_element_id, Maybe<int> anchor_node_id, @@ -1316,7 +1540,7 @@ Response InspectorDOMAgent::requestNode(const String& object_id, int* node_id) { Node* node = nullptr; - Response response = NodeForRemoteObjectId(object_id, node); + Response response = NodeForRemoteId(object_id, node); if (!response.isSuccess()) return response; *node_id = PushNodePathToFrontend(node); @@ -2130,6 +2354,18 @@ return Response::OK(); } +Response InspectorDOMAgent::getHighlightObjectForTest( + int node_id, + std::unique_ptr<protocol::DictionaryValue>* result) { + Node* node = nullptr; + Response response = AssertNode(node_id, node); + if (!response.isSuccess()) + return response; + InspectorHighlight highlight(node, InspectorHighlight::DefaultConfig(), true); + *result = highlight.AsProtocolValue(); + return Response::OK(); +} + std::unique_ptr<v8_inspector::protocol::Runtime::API::RemoteObject> InspectorDOMAgent::ResolveNode(Node* node, const String& object_group) { Document* document =
diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.h b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.h index 37b076c..1e1680f 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.h +++ b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.h
@@ -34,6 +34,7 @@ #include "core/CoreExport.h" #include "core/events/EventListenerMap.h" #include "core/inspector/InspectorBaseAgent.h" +#include "core/inspector/InspectorHighlight.h" #include "core/inspector/protocol/DOM.h" #include "core/style/ComputedStyleConstants.h" #include "platform/geometry/FloatQuad.h" @@ -47,7 +48,6 @@ namespace blink { class CharacterData; -class Color; class DOMEditor; class Document; class DocumentLoader; @@ -77,14 +77,33 @@ virtual void DidModifyDOMAttr(Element*) = 0; }; + enum SearchMode { + kNotSearching, + kSearchingForNormal, + kSearchingForUAShadow, + }; + + class Client { + public: + virtual ~Client() {} + virtual void HideHighlight() {} + virtual void HighlightNode(Node*, + const InspectorHighlightConfig&, + bool omit_tooltip) {} + virtual void HighlightQuad(std::unique_ptr<FloatQuad>, + const InspectorHighlightConfig&) {} + virtual void SetInspectMode(SearchMode search_mode, + std::unique_ptr<InspectorHighlightConfig>) {} + }; + static protocol::Response ToResponse(ExceptionState&); static bool GetPseudoElementType(PseudoId, String*); static ShadowRoot* UserAgentShadowRoot(Node*); - static Color ParseColor(protocol::DOM::RGBA*); InspectorDOMAgent(v8::Isolate*, InspectedFrames*, - v8_inspector::V8InspectorSession*); + v8_inspector::V8InspectorSession*, + Client*); ~InspectorDOMAgent() override; DECLARE_VIRTUAL_TRACE(); @@ -146,6 +165,30 @@ protocol::Response discardSearchResults(const String& search_id) override; protocol::Response requestNode(const String& object_id, int* out_node_id) override; + protocol::Response setInspectMode( + const String& mode, + protocol::Maybe<protocol::DOM::HighlightConfig>) override; + protocol::Response highlightRect( + int x, + int y, + int width, + int height, + protocol::Maybe<protocol::DOM::RGBA> color, + protocol::Maybe<protocol::DOM::RGBA> outline_color) override; + protocol::Response highlightQuad( + std::unique_ptr<protocol::Array<double>> quad, + protocol::Maybe<protocol::DOM::RGBA> color, + protocol::Maybe<protocol::DOM::RGBA> outline_color) override; + protocol::Response highlightNode( + std::unique_ptr<protocol::DOM::HighlightConfig>, + protocol::Maybe<int> node_id, + protocol::Maybe<int> backend_node_id, + protocol::Maybe<String> object_id) override; + protocol::Response hideHighlight() override; + protocol::Response highlightFrame( + const String& frame_id, + protocol::Maybe<protocol::DOM::RGBA> content_color, + protocol::Maybe<protocol::DOM::RGBA> content_outline_color) override; protocol::Response pushNodeByPathToFrontend(const String& path, int* out_node_id) override; protocol::Response pushNodesByBackendIdsToFrontend( @@ -185,6 +228,9 @@ int* out_node_id) override; protocol::Response getRelayoutBoundary(int node_id, int* out_node_id) override; + protocol::Response getHighlightObjectForTest( + int node_id, + std::unique_ptr<protocol::DictionaryValue>* highlight) override; bool Enabled() const; void ReleaseDanglingNodes(); @@ -215,10 +261,9 @@ Node* NodeForId(int node_id); int BoundNodeId(Node*); void SetDOMListener(DOMListener*); + void Inspect(Node*); + void NodeHighlightedInOverlay(Node*); int PushNodePathToFrontend(Node*); - protocol::Response PushDocumentUponHandlelessOperation(); - protocol::Response NodeForRemoteObjectId(const String& remote_object_id, - Node*&); static String DocumentURLString(Document*); @@ -251,6 +296,14 @@ void SetDocument(Document*); void InnerEnable(); + protocol::Response SetSearchingForNode( + SearchMode, + protocol::Maybe<protocol::DOM::HighlightConfig>); + protocol::Response HighlightConfigFromInspectorObject( + protocol::Maybe<protocol::DOM::HighlightConfig> + highlight_inspector_object, + std::unique_ptr<InspectorHighlightConfig>*); + // Node-related methods. typedef HeapHashMap<Member<Node>, int> NodeToIdMap; int Bind(Node*, NodeToIdMap*); @@ -292,14 +345,22 @@ BuildDistributedNodesForSlot(HTMLSlotElement*); Node* NodeForPath(const String& path); + protocol::Response NodeForRemoteId(const String& id, Node*&); void DiscardFrontendBindings(); + void InnerHighlightQuad(std::unique_ptr<FloatQuad>, + protocol::Maybe<protocol::DOM::RGBA> color, + protocol::Maybe<protocol::DOM::RGBA> outline_color); + + protocol::Response PushDocumentUponHandlelessOperation(); + InspectorRevalidateDOMTask* RevalidateTask(); v8::Isolate* isolate_; Member<InspectedFrames> inspected_frames_; v8_inspector::V8InspectorSession* v8_session_; + Client* client_; Member<DOMListener> dom_listener_; Member<NodeToIdMap> document_node_to_id_map_; // Owns node mappings for dangling nodes. @@ -317,6 +378,7 @@ Member<InspectorHistory> history_; Member<DOMEditor> dom_editor_; bool suppress_attribute_modified_event_; + int backend_node_id_to_inspect_; }; } // namespace blink
diff --git a/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.cpp b/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.cpp index 2db1b96..8054b7ba 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.cpp
@@ -30,8 +30,7 @@ namespace blink { -InspectorOverlayHost::InspectorOverlayHost(Listener* listener) - : listener_(listener) {} +InspectorOverlayHost::InspectorOverlayHost() : listener_(nullptr) {} void InspectorOverlayHost::resume() { if (listener_)
diff --git a/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.h b/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.h index 167833c..0d5d4be 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.h +++ b/third_party/WebKit/Source/core/inspector/InspectorOverlayHost.h
@@ -40,20 +40,23 @@ DEFINE_WRAPPERTYPEINFO(); public: + static InspectorOverlayHost* Create() { return new InspectorOverlayHost(); } + DECLARE_TRACE(); + + void resume(); + void stepOver(); + class Listener : public GarbageCollectedMixin { public: virtual ~Listener() {} virtual void OverlayResumed() = 0; virtual void OverlaySteppedOver() = 0; }; - - explicit InspectorOverlayHost(Listener*); - DECLARE_TRACE(); - - void resume(); - void stepOver(); + void SetListener(Listener* listener) { listener_ = listener; } private: + InspectorOverlayHost(); + Member<Listener> listener_; };
diff --git a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp index 2e2a503f..428dba6e 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
@@ -81,6 +81,8 @@ "pageAgentScriptsToEvaluateOnLoad"; static const char kScreencastEnabled[] = "screencastEnabled"; static const char kAutoAttachToCreatedPages[] = "autoAttachToCreatedPages"; +static const char kOverlaySuspended[] = "overlaySuspended"; +static const char kOverlayMessage[] = "overlayMessage"; } namespace { @@ -374,6 +376,13 @@ void InspectorPageAgent::Restore() { if (state_->booleanProperty(PageAgentState::kPageAgentEnabled, false)) enable(); + if (client_) { + String overlay_message; + state_->getString(PageAgentState::kOverlayMessage, &overlay_message); + client_->ConfigureOverlay( + state_->booleanProperty(PageAgentState::kOverlaySuspended, false), + overlay_message); + } } Response InspectorPageAgent::enable() { @@ -394,6 +403,7 @@ resource_content_loader_client_id_); stopScreencast(); + configureOverlay(false, String()); FinishReload(); return Response::OK(); @@ -854,6 +864,18 @@ return Response::OK(); } +Response InspectorPageAgent::configureOverlay(Maybe<bool> suspended, + Maybe<String> message) { + state_->setBoolean(PageAgentState::kOverlaySuspended, + suspended.fromMaybe(false)); + state_->setString(PageAgentState::kOverlaySuspended, + message.fromMaybe(String())); + if (client_) + client_->ConfigureOverlay(suspended.fromMaybe(false), + message.fromMaybe(String())); + return Response::OK(); +} + Response InspectorPageAgent::getLayoutMetrics( std::unique_ptr<protocol::Page::LayoutViewport>* out_layout_viewport, std::unique_ptr<protocol::Page::VisualViewport>* out_visual_viewport,
diff --git a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.h b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.h index 48ec089b..0080aa1 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.h +++ b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.h
@@ -66,6 +66,7 @@ public: virtual ~Client() {} virtual void PageLayoutInvalidated(bool resized) {} + virtual void ConfigureOverlay(bool suspended, const String& message) {} virtual void WaitForCreateWindow(LocalFrame*) {} }; @@ -138,6 +139,8 @@ Maybe<int> max_height, Maybe<int> every_nth_frame) override; protocol::Response stopScreencast() override; + protocol::Response configureOverlay(Maybe<bool> suspended, + Maybe<String> message) override; protocol::Response getLayoutMetrics( std::unique_ptr<protocol::Page::LayoutViewport>*, std::unique_ptr<protocol::Page::VisualViewport>*,
diff --git a/third_party/WebKit/Source/core/inspector/browser_protocol.json b/third_party/WebKit/Source/core/inspector/browser_protocol.json index ccc2d2b3b..cca3bc9 100644 --- a/third_party/WebKit/Source/core/inspector/browser_protocol.json +++ b/third_party/WebKit/Source/core/inspector/browser_protocol.json
@@ -469,6 +469,15 @@ ] }, { + "name": "configureOverlay", + "parameters": [ + { "name": "suspended", "type": "boolean", "optional": true, "description": "Whether overlay should be suspended and not consume any resources." }, + { "name": "message", "type": "string", "optional": true, "description": "Overlay message to display." } + ], + "experimental": true, + "description": "Configures overlay." + }, + { "name": "getAppManifest", "experimental": true, "returns": [ @@ -636,50 +645,11 @@ ] }, { - "domain": "Overlay", - "description": "This domain provides various functionality related to drawing atop the inspected page.", - "dependencies": ["DOM", "Page", "Runtime"], + "domain": "Rendering", + "description": "This domain allows to control rendering of the page.", "experimental": true, - "types": [ - { - "id": "HighlightConfig", - "type": "object", - "properties": [ - { "name": "showInfo", "type": "boolean", "optional": true, "description": "Whether the node info tooltip should be shown (default: false)." }, - { "name": "showRulers", "type": "boolean", "optional": true, "description": "Whether the rulers should be shown (default: false)." }, - { "name": "showExtensionLines", "type": "boolean", "optional": true, "description": "Whether the extension lines from node to the rulers should be shown (default: false)." }, - { "name": "displayAsMaterial", "type": "boolean", "optional": true}, - { "name": "contentColor", "$ref": "DOM.RGBA", "optional": true, "description": "The content box highlight fill color (default: transparent)." }, - { "name": "paddingColor", "$ref": "DOM.RGBA", "optional": true, "description": "The padding highlight fill color (default: transparent)." }, - { "name": "borderColor", "$ref": "DOM.RGBA", "optional": true, "description": "The border highlight fill color (default: transparent)." }, - { "name": "marginColor", "$ref": "DOM.RGBA", "optional": true, "description": "The margin highlight fill color (default: transparent)." }, - { "name": "eventTargetColor", "$ref": "DOM.RGBA", "optional": true, "description": "The event target element highlight fill color (default: transparent)." }, - { "name": "shapeColor", "$ref": "DOM.RGBA", "optional": true, "description": "The shape outside fill color (default: transparent)." }, - { "name": "shapeMarginColor", "$ref": "DOM.RGBA", "optional": true, "description": "The shape margin fill color (default: transparent)." }, - { "name": "selectorList", "type": "string", "optional": true, "description": "Selectors to highlight relevant nodes."} - ], - "description": "Configuration data for the highlighting of page elements." - }, - { - "id": "InspectMode", - "type": "string", - "enum": [ - "searchForNode", - "searchForUAShadowDOM", - "none" - ] - } - ], "commands": [ { - "name": "enable", - "description": "Enables domain notifications." - }, - { - "name": "disable", - "description": "Disables domain notifications." - }, - { "name": "setShowPaintRects", "description": "Requests that backend shows paint rectangles", "parameters": [ @@ -713,96 +683,6 @@ "parameters": [ { "name": "show", "type": "boolean", "description": "Whether to paint size or not." } ] - }, - { - "name": "setPausedInDebuggerMessage", - "parameters": [ - { "name": "message", "type": "string", "optional": true, "description": "The message to display, also triggers resume and step over controls." } - ] - }, - { - "name": "setSuspended", - "parameters": [ - { "name": "suspended", "type": "boolean", "description": "Whether overlay should be suspended and not consume any resources until resumed." } - ] - }, - { - "name": "setInspectMode", - "description": "Enters the 'inspect' mode. In this mode, elements that user is hovering over are highlighted. Backend then generates 'inspectNodeRequested' event upon element selection.", - "parameters": [ - { "name": "mode", "$ref": "InspectMode", "description": "Set an inspection mode." }, - { "name": "highlightConfig", "$ref": "HighlightConfig", "optional": true, "description": "A descriptor for the highlight appearance of hovered-over nodes. May be omitted if <code>enabled == false</code>." } - ] - }, - { - "name": "highlightRect", - "description": "Highlights given rectangle. Coordinates are absolute with respect to the main frame viewport.", - "parameters": [ - { "name": "x", "type": "integer", "description": "X coordinate" }, - { "name": "y", "type": "integer", "description": "Y coordinate" }, - { "name": "width", "type": "integer", "description": "Rectangle width" }, - { "name": "height", "type": "integer", "description": "Rectangle height" }, - { "name": "color", "$ref": "DOM.RGBA", "optional": true, "description": "The highlight fill color (default: transparent)." }, - { "name": "outlineColor", "$ref": "DOM.RGBA", "optional": true, "description": "The highlight outline color (default: transparent)." } - ] - }, - { - "name": "highlightQuad", - "description": "Highlights given quad. Coordinates are absolute with respect to the main frame viewport.", - "parameters": [ - { "name": "quad", "$ref": "DOM.Quad", "description": "Quad to highlight" }, - { "name": "color", "$ref": "DOM.RGBA", "optional": true, "description": "The highlight fill color (default: transparent)." }, - { "name": "outlineColor", "$ref": "DOM.RGBA", "optional": true, "description": "The highlight outline color (default: transparent)." } - ] - }, - { - "name": "highlightNode", - "description": "Highlights DOM node with given id or with the given JavaScript object wrapper. Either nodeId or objectId must be specified.", - "parameters": [ - { "name": "highlightConfig", "$ref": "HighlightConfig", "description": "A descriptor for the highlight appearance." }, - { "name": "nodeId", "$ref": "DOM.NodeId", "optional": true, "description": "Identifier of the node to highlight." }, - { "name": "backendNodeId", "$ref": "DOM.BackendNodeId", "optional": true, "description": "Identifier of the backend node to highlight." }, - { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "optional": true, "description": "JavaScript object id of the node to be highlighted." } - ] - }, - { - "name": "highlightFrame", - "description": "Highlights owner element of the frame with given id.", - "parameters": [ - { "name": "frameId", "$ref": "Page.FrameId", "description": "Identifier of the frame to highlight." }, - { "name": "contentColor", "$ref": "DOM.RGBA", "optional": true, "description": "The content box highlight fill color (default: transparent)." }, - { "name": "contentOutlineColor", "$ref": "DOM.RGBA", "optional": true, "description": "The content box highlight outline color (default: transparent)." } - ] - }, - { - "name": "hideHighlight", - "description": "Hides any highlight." - }, - { - "name": "getHighlightObjectForTest", - "description": "For testing.", - "parameters": [ - { "name": "nodeId", "$ref": "DOM.NodeId", "description": "Id of the node to get highlight object for." } - ], - "returns": [ - { "name": "highlight", "type": "object", "description": "Highlight data for the node." } - ] - } - ], - "events": [ - { - "name": "nodeHighlightRequested", - "description": "Fired when the node should be highlighted. This happens after call to <code>setInspectMode</code>.", - "parameters": [ - { "name": "nodeId", "$ref": "DOM.NodeId" } - ] - }, - { - "name": "inspectNodeRequested", - "description": "Fired when the node should be inspected. This happens after call to <code>setInspectMode</code> or when user manually inspects an element.", - "parameters": [ - { "name": "backendNodeId", "$ref": "DOM.BackendNodeId", "description": "Id of the node to inspect." } - ] } ] }, @@ -2258,6 +2138,35 @@ { "name": "height", "type": "number", "description": "Rectangle height" } ], "description": "Rectangle." + }, + { + "id": "HighlightConfig", + "type": "object", + "properties": [ + { "name": "showInfo", "type": "boolean", "optional": true, "description": "Whether the node info tooltip should be shown (default: false)." }, + { "name": "showRulers", "type": "boolean", "optional": true, "description": "Whether the rulers should be shown (default: false)." }, + { "name": "showExtensionLines", "type": "boolean", "optional": true, "description": "Whether the extension lines from node to the rulers should be shown (default: false)." }, + { "name": "displayAsMaterial", "type": "boolean", "optional": true, "experimental": true}, + { "name": "contentColor", "$ref": "RGBA", "optional": true, "description": "The content box highlight fill color (default: transparent)." }, + { "name": "paddingColor", "$ref": "RGBA", "optional": true, "description": "The padding highlight fill color (default: transparent)." }, + { "name": "borderColor", "$ref": "RGBA", "optional": true, "description": "The border highlight fill color (default: transparent)." }, + { "name": "marginColor", "$ref": "RGBA", "optional": true, "description": "The margin highlight fill color (default: transparent)." }, + { "name": "eventTargetColor", "$ref": "RGBA", "optional": true, "experimental": true, "description": "The event target element highlight fill color (default: transparent)." }, + { "name": "shapeColor", "$ref": "RGBA", "optional": true, "experimental": true, "description": "The shape outside fill color (default: transparent)." }, + { "name": "shapeMarginColor", "$ref": "RGBA", "optional": true, "experimental": true, "description": "The shape margin fill color (default: transparent)." }, + { "name": "selectorList", "type": "string", "optional": true, "description": "Selectors to highlight relevant nodes."} + ], + "description": "Configuration data for the highlighting of page elements." + }, + { + "id": "InspectMode", + "type": "string", + "experimental": true, + "enum": [ + "searchForNode", + "searchForUAShadowDOM", + "none" + ] } ], "commands": [ @@ -2448,19 +2357,59 @@ "description": "Requests that the node is sent to the caller given the JavaScript node object reference. All nodes that form the path from the node to the root are also sent to the client as a series of <code>setChildNodes</code> notifications." }, { + "name": "setInspectMode", + "experimental": true, + "parameters": [ + { "name": "mode", "$ref": "InspectMode", "description": "Set an inspection mode." }, + { "name": "highlightConfig", "$ref": "HighlightConfig", "optional": true, "description": "A descriptor for the highlight appearance of hovered-over nodes. May be omitted if <code>enabled == false</code>." } + ], + "description": "Enters the 'inspect' mode. In this mode, elements that user is hovering over are highlighted. Backend then generates 'inspectNodeRequested' event upon element selection." + }, + { "name": "highlightRect", - "description": "Highlights given rectangle.", - "redirect": "Overlay" + "parameters": [ + { "name": "x", "type": "integer", "description": "X coordinate" }, + { "name": "y", "type": "integer", "description": "Y coordinate" }, + { "name": "width", "type": "integer", "description": "Rectangle width" }, + { "name": "height", "type": "integer", "description": "Rectangle height" }, + { "name": "color", "$ref": "RGBA", "optional": true, "description": "The highlight fill color (default: transparent)." }, + { "name": "outlineColor", "$ref": "RGBA", "optional": true, "description": "The highlight outline color (default: transparent)." } + ], + "description": "Highlights given rectangle. Coordinates are absolute with respect to the main frame viewport." + }, + { + "name": "highlightQuad", + "parameters": [ + { "name": "quad", "$ref": "Quad", "description": "Quad to highlight" }, + { "name": "color", "$ref": "RGBA", "optional": true, "description": "The highlight fill color (default: transparent)." }, + { "name": "outlineColor", "$ref": "RGBA", "optional": true, "description": "The highlight outline color (default: transparent)." } + ], + "description": "Highlights given quad. Coordinates are absolute with respect to the main frame viewport.", + "experimental": true }, { "name": "highlightNode", - "description": "Highlights DOM node.", - "redirect": "Overlay" + "parameters": [ + { "name": "highlightConfig", "$ref": "HighlightConfig", "description": "A descriptor for the highlight appearance." }, + { "name": "nodeId", "$ref": "NodeId", "optional": true, "description": "Identifier of the node to highlight." }, + { "name": "backendNodeId", "$ref": "BackendNodeId", "optional": true, "description": "Identifier of the backend node to highlight." }, + { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "optional": true, "description": "JavaScript object id of the node to be highlighted.", "experimental": true } + ], + "description": "Highlights DOM node with given id or with the given JavaScript object wrapper. Either nodeId or objectId must be specified." }, { "name": "hideHighlight", - "description": "Hides any highlight.", - "redirect": "Overlay" + "description": "Hides DOM node highlight." + }, + { + "name": "highlightFrame", + "parameters": [ + { "name": "frameId", "$ref": "Page.FrameId", "description": "Identifier of the frame to highlight." }, + { "name": "contentColor", "$ref": "RGBA", "optional": true, "description": "The content box highlight fill color (default: transparent)." }, + { "name": "contentOutlineColor", "$ref": "RGBA", "optional": true, "description": "The content box highlight outline color (default: transparent)." } + ], + "description": "Highlights owner element of the frame with given id.", + "experimental": true }, { "name": "pushNodeByPathToFrontend", @@ -2604,6 +2553,17 @@ ], "description": "Returns the id of the nearest ancestor that is a relayout boundary.", "experimental": true + }, + { + "name": "getHighlightObjectForTest", + "parameters": [ + { "name": "nodeId", "$ref": "NodeId", "description": "Id of the node to get highlight object for." } + ], + "returns": [ + { "name": "highlight", "type": "object", "description": "Highlight data for the node." } + ], + "description": "For testing.", + "experimental": true } ], "events": [ @@ -2612,6 +2572,14 @@ "description": "Fired when <code>Document</code> has been totally updated. Node ids are no longer valid." }, { + "name": "inspectNodeRequested", + "parameters": [ + { "name": "backendNodeId", "$ref": "BackendNodeId", "description": "Id of the node to inspect." } + ], + "description": "Fired when the node should be inspected. This happens after call to <code>setInspectMode</code>.", + "experimental" : true + }, + { "name": "setChildNodes", "parameters": [ { "name": "parentId", "$ref": "NodeId", "description": "Parent node id to populate with children." }, @@ -2721,6 +2689,13 @@ ], "description": "Called when distrubution is changed.", "experimental": true + }, + { + "name": "nodeHighlightRequested", + "parameters": [ + {"name": "nodeId", "$ref": "NodeId"} + ], + "experimental": true } ] },
diff --git a/third_party/WebKit/Source/core/inspector/inspector_protocol_config.json b/third_party/WebKit/Source/core/inspector/inspector_protocol_config.json index 4fb3f5b6..21048f15 100644 --- a/third_party/WebKit/Source/core/inspector/inspector_protocol_config.json +++ b/third_party/WebKit/Source/core/inspector/inspector_protocol_config.json
@@ -51,7 +51,7 @@ "domain": "Log" }, { - "domain": "Overlay" + "domain": "Rendering" }, { "domain": "Input",
diff --git a/third_party/WebKit/Source/devtools/BUILD.gn b/third_party/WebKit/Source/devtools/BUILD.gn index dfc55fb5..382d6db 100644 --- a/third_party/WebKit/Source/devtools/BUILD.gn +++ b/third_party/WebKit/Source/devtools/BUILD.gn
@@ -295,6 +295,7 @@ "front_end/main/GCActionDelegate.js", "front_end/main/Main.js", "front_end/main/module.json", + "front_end/main/OverlayController.js", "front_end/main/remoteDebuggingTerminatedScreen.css", "front_end/main/renderingOptions.css", "front_end/main/RenderingOptions.js", @@ -476,7 +477,6 @@ "front_end/sdk/module.json", "front_end/sdk/NetworkManager.js", "front_end/sdk/NetworkRequest.js", - "front_end/sdk/OverlayModel.js", "front_end/sdk/PaintProfiler.js", "front_end/sdk/ProfileTreeModel.js", "front_end/sdk/RemoteObject.js",
diff --git a/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js b/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js index 884dd30..fc69390e 100644 --- a/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js +++ b/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js
@@ -157,7 +157,7 @@ if (!this.node()) return; // Highlight and scroll into view the currently inspected node. - this.node().domModel().overlayModel().nodeHighlightRequested(this.node().id); + this.node().domModel().nodeHighlightRequested(this.node().id); } }
diff --git a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js index 87dd668..5fe56b5 100644 --- a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js +++ b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js
@@ -156,7 +156,7 @@ this.deferredDOMNode().resolvePromise().then(node => { if (!node) return; - node.domModel().overlayModel().nodeHighlightRequested(node.id); + node.domModel().nodeHighlightRequested(node.id); }); }
diff --git a/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js b/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js index 1e369ace..679710f 100644 --- a/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js +++ b/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js
@@ -117,7 +117,7 @@ link.addEventListener('click', Common.Revealer.reveal.bind(Common.Revealer, node, undefined), false); link.addEventListener('mouseover', node.highlight.bind(node, undefined, undefined), false); - link.addEventListener('mouseleave', () => SDK.OverlayModel.hideDOMNodeHighlight(), false); + link.addEventListener('mouseleave', SDK.DOMModel.hideDOMNodeHighlight.bind(SDK.DOMModel), false); return root; };
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ElementsBreadcrumbs.js b/third_party/WebKit/Source/devtools/front_end/elements/ElementsBreadcrumbs.js index 24a45c6..67bca2f 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/ElementsBreadcrumbs.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/ElementsBreadcrumbs.js
@@ -56,7 +56,7 @@ _mouseMovedOutOfCrumbs(event) { if (this._currentDOMNode) - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); }
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js b/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js index 3f3c33d..aba07ef 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js
@@ -330,7 +330,7 @@ willHide() { UI.context.setFlavor(Elements.ElementsPanel, null); - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); for (var i = 0; i < this._treeOutlines.length; ++i) { var treeOutline = this._treeOutlines[i]; treeOutline.setVisible(false);
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElementHighlighter.js b/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElementHighlighter.js index 7b7e454..f8d7034 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElementHighlighter.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElementHighlighter.js
@@ -15,9 +15,8 @@ this._treeOutline.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._clearState, this); this._treeOutline.addEventListener(Elements.ElementsTreeOutline.Events.SelectedNodeChanged, this._clearState, this); SDK.targetManager.addModelListener( - SDK.OverlayModel, SDK.OverlayModel.Events.HighlightNodeRequested, this._highlightNode, this); - this._treeOutline.domModel().overlayModel().addEventListener( - SDK.OverlayModel.Events.InspectModeWillBeToggled, this._clearState, this); + SDK.DOMModel, SDK.DOMModel.Events.NodeHighlightedInOverlay, this._highlightNode, this); + this._treeOutline.domModel().addEventListener(SDK.DOMModel.Events.InspectModeWillBeToggled, this._clearState, this); } /**
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeOutline.js b/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeOutline.js index a0c0471..ad4fbca 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeOutline.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeOutline.js
@@ -620,20 +620,20 @@ this.setHoverEffect(element); if (element instanceof Elements.ElementsTreeElement) { - this._domModel.overlayModel().highlightDOMNodeWithConfig( + this._domModel.highlightDOMNodeWithConfig( element.node().id, {mode: 'all', showInfo: !UI.KeyboardShortcut.eventHasCtrlOrMeta(event)}); return; } if (element instanceof Elements.ElementsTreeOutline.ShortcutTreeElement) { - this._domModel.overlayModel().highlightDOMNodeWithConfig( + this._domModel.highlightDOMNodeWithConfig( undefined, {mode: 'all', showInfo: !UI.KeyboardShortcut.eventHasCtrlOrMeta(event)}, element.backendNodeId()); } } _onmouseleave(event) { this.setHoverEffect(null); - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); } _ondragstart(event) { @@ -653,7 +653,7 @@ event.dataTransfer.effectAllowed = 'copyMove'; this._treeElementBeingDragged = treeElement; - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); return true; } @@ -971,7 +971,7 @@ this.selectDOMNode(null, false); this._popoverHelper.hidePopover(); delete this._clipboardNodeData; - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); this._updateRecords.clear(); }
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/InspectElementModeController.js b/third_party/WebKit/Source/devtools/front_end/elements/InspectElementModeController.js index 0eee986..63fe1ce 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/InspectElementModeController.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/InspectElementModeController.js
@@ -26,46 +26,46 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * @implements {SDK.SDKModelObserver<!SDK.OverlayModel>} + * @implements {SDK.SDKModelObserver<!SDK.DOMModel>} * @unrestricted */ Elements.InspectElementModeController = class { constructor() { this._toggleSearchAction = UI.actionRegistry.action('elements.toggle-element-search'); - this._mode = Protocol.Overlay.InspectMode.None; + this._mode = Protocol.DOM.InspectMode.None; SDK.targetManager.addEventListener(SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this); - SDK.targetManager.observeModels(SDK.OverlayModel, this); + SDK.targetManager.observeModels(SDK.DOMModel, this); } /** * @override - * @param {!SDK.OverlayModel} overlayModel + * @param {!SDK.DOMModel} domModel */ - modelAdded(overlayModel) { + modelAdded(domModel) { // When DevTools are opening in the inspect element mode, the first target comes in // much later than the InspectorFrontendAPI.enterInspectElementMode event. - if (this._mode === Protocol.Overlay.InspectMode.None) + if (this._mode === Protocol.DOM.InspectMode.None) return; - overlayModel.setInspectMode(this._mode); + domModel.setInspectMode(this._mode); } /** * @override - * @param {!SDK.OverlayModel} overlayModel + * @param {!SDK.DOMModel} domModel */ - modelRemoved(overlayModel) { + modelRemoved(domModel) { } /** * @return {boolean} */ isInInspectElementMode() { - return this._mode === Protocol.Overlay.InspectMode.SearchForNode || - this._mode === Protocol.Overlay.InspectMode.SearchForUAShadowDOM; + return this._mode === Protocol.DOM.InspectMode.SearchForNode || + this._mode === Protocol.DOM.InspectMode.SearchForUAShadowDOM; } stopInspection() { - if (this._mode && this._mode !== Protocol.Overlay.InspectMode.None) + if (this._mode && this._mode !== Protocol.DOM.InspectMode.None) this._toggleInspectMode(); } @@ -75,22 +75,22 @@ var mode; if (this.isInInspectElementMode()) { - mode = Protocol.Overlay.InspectMode.None; + mode = Protocol.DOM.InspectMode.None; } else { - mode = Common.moduleSetting('showUAShadowDOM').get() ? Protocol.Overlay.InspectMode.SearchForUAShadowDOM : - Protocol.Overlay.InspectMode.SearchForNode; + mode = Common.moduleSetting('showUAShadowDOM').get() ? Protocol.DOM.InspectMode.SearchForUAShadowDOM : + Protocol.DOM.InspectMode.SearchForNode; } this._setMode(mode); } /** - * @param {!Protocol.Overlay.InspectMode} mode + * @param {!Protocol.DOM.InspectMode} mode */ _setMode(mode) { this._mode = mode; - for (var overlayModel of SDK.targetManager.models(SDK.OverlayModel)) - overlayModel.setInspectMode(mode); + for (var domModel of SDK.targetManager.models(SDK.DOMModel)) + domModel.setInspectMode(mode); this._toggleSearchAction.setToggled(this.isInInspectElementMode()); } @@ -98,7 +98,7 @@ if (!SDK.targetManager.allTargetsSuspended()) return; - this._mode = Protocol.Overlay.InspectMode.None; + this._mode = Protocol.DOM.InspectMode.None; this._toggleSearchAction.setToggled(false); } };
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/MetricsSidebarPane.js b/third_party/WebKit/Source/devtools/front_end/elements/MetricsSidebarPane.js index 8e3a2b2..d9cba702 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/MetricsSidebarPane.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/MetricsSidebarPane.js
@@ -124,7 +124,7 @@ this.node().highlight(mode); } else { delete this._highlightMode; - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); } for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) {
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js b/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js index a8b2810df..b8c5d73 100644 --- a/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js +++ b/third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js
@@ -836,7 +836,7 @@ _onMouseOutSelector() { if (this._hoverTimer) clearTimeout(this._hoverTimer); - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); } _onMouseEnterSelector() { @@ -846,11 +846,11 @@ } _highlight() { - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); var node = this._parentPane.node(); + var domModel = node.domModel(); var selectors = this._style.parentRule ? this._style.parentRule.selectorText() : undefined; - node.domModel().overlayModel().highlightDOMNodeWithConfig( - node.id, {mode: 'all', showInfo: undefined, selectors: selectors}); + domModel.highlightDOMNodeWithConfig(node.id, {mode: 'all', showInfo: undefined, selectors: selectors}); } /**
diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js index 4ae82272..dbd9b6d 100644 --- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js +++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
@@ -472,9 +472,8 @@ this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile, this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile); } - var overlayModel = this._target ? this._target.model(SDK.OverlayModel) : null; - if (overlayModel) - overlayModel.setShowViewportSizeOnResize(this._type === Emulation.DeviceModeModel.Type.None); + if (this._target) + this._target.renderingAgent().setShowViewportSizeOnResize(this._type === Emulation.DeviceModeModel.Type.None); this._updateCallback.call(null); }
diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js index d196701..e63753b 100644 --- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js +++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js
@@ -375,9 +375,9 @@ * @return {!Promise} */ async captureScreenshot() { - SDK.OverlayModel.muteHighlight(); + SDK.DOMModel.muteHighlight(); var screenshot = await this._model.captureScreenshot(false); - SDK.OverlayModel.unmuteHighlight(); + SDK.DOMModel.unmuteHighlight(); if (screenshot === null) return; @@ -410,9 +410,9 @@ * @return {!Promise} */ async captureFullSizeScreenshot() { - SDK.OverlayModel.muteHighlight(); + SDK.DOMModel.muteHighlight(); var screenshot = await this._model.captureScreenshot(true); - SDK.OverlayModel.unmuteHighlight(); + SDK.DOMModel.unmuteHighlight(); if (screenshot === null) return;
diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js b/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js index 883ccf6..ce997a4 100644 --- a/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js +++ b/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js
@@ -54,8 +54,8 @@ if (this._customTouchEnabled) current = {enabled: true, configuration: 'mobile'}; - var overlayModel = target.model(SDK.OverlayModel); - var inspectModeEnabled = overlayModel ? overlayModel.inspectModeEnabled() : false; + var domModel = target.model(SDK.DOMModel); + var inspectModeEnabled = domModel ? domModel.inspectModeEnabled() : false; if (inspectModeEnabled) current = {enabled: false, configuration: 'mobile'}; @@ -107,8 +107,8 @@ * @param {!Common.Event} event */ _inspectModeToggled(event) { - var overlayModel = /** @type {!SDK.OverlayModel} */ (event.data); - this._applyToTarget(overlayModel.target()); + var domModel = /** @type {!SDK.DOMModel} */ (event.data); + this._applyToTarget(domModel.target()); } /** @@ -116,9 +116,9 @@ * @param {!SDK.Target} target */ targetAdded(target) { - var overlayModel = target.model(SDK.OverlayModel); - if (overlayModel) - overlayModel.addEventListener(SDK.OverlayModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); + var domModel = target.model(SDK.DOMModel); + if (domModel) + domModel.addEventListener(SDK.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); this._applyToTarget(target); } @@ -127,11 +127,9 @@ * @param {!SDK.Target} target */ targetRemoved(target) { - var overlayModel = target.model(SDK.OverlayModel); - if (overlayModel) { - overlayModel.removeEventListener( - SDK.OverlayModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); - } + var domModel = target.model(SDK.DOMModel); + if (domModel) + domModel.removeEventListener(SDK.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); } };
diff --git a/third_party/WebKit/Source/devtools/front_end/layer_viewer/LayerViewHost.js b/third_party/WebKit/Source/devtools/front_end/layer_viewer/LayerViewHost.js index 7ea875e9..ff3ac68 100644 --- a/third_party/WebKit/Source/devtools/front_end/layer_viewer/LayerViewHost.js +++ b/third_party/WebKit/Source/devtools/front_end/layer_viewer/LayerViewHost.js
@@ -255,6 +255,6 @@ node.highlightForTwoSeconds(); return; } - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); } };
diff --git a/third_party/WebKit/Source/devtools/front_end/main/Main.js b/third_party/WebKit/Source/devtools/front_end/main/Main.js index 2aa82f7..840462f 100644 --- a/third_party/WebKit/Source/devtools/front_end/main/Main.js +++ b/third_party/WebKit/Source/devtools/front_end/main/Main.js
@@ -197,6 +197,7 @@ Persistence.persistence = new Persistence.Persistence(Workspace.workspace, Bindings.breakpointManager, Workspace.fileSystemMapping); + new Main.OverlayController(); new Main.ExecutionContextSelector(SDK.targetManager, UI.context); Bindings.blackboxManager = new Bindings.BlackboxManager(Bindings.debuggerWorkspaceBinding); @@ -796,8 +797,7 @@ */ Main.Main.InspectedNodeRevealer = class { constructor() { - SDK.targetManager.addModelListener( - SDK.OverlayModel, SDK.OverlayModel.Events.InspectNodeRequested, this._inspectNode, this); + SDK.targetManager.addModelListener(SDK.DOMModel, SDK.DOMModel.Events.NodeInspected, this._inspectNode, this); } /** @@ -933,6 +933,7 @@ */ targetAdded(target) { this._updateTarget(target); + target.renderingAgent().setShowViewportSizeOnResize(true); } /**
diff --git a/third_party/WebKit/Source/devtools/front_end/main/OverlayController.js b/third_party/WebKit/Source/devtools/front_end/main/OverlayController.js new file mode 100644 index 0000000..e6800ce --- /dev/null +++ b/third_party/WebKit/Source/devtools/front_end/main/OverlayController.js
@@ -0,0 +1,43 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +/** + * @unrestricted + */ +Main.OverlayController = class { + constructor() { + Common.moduleSetting('disablePausedStateOverlay').addChangeListener(this._updateAllOverlays, this); + SDK.targetManager.addModelListener( + SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._updateOverlay, this); + SDK.targetManager.addModelListener( + SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerResumed, this._updateOverlay, this); + // TODO(dgozman): we should get DebuggerResumed on navigations instead of listening to GlobalObjectCleared. + SDK.targetManager.addModelListener( + SDK.DebuggerModel, SDK.DebuggerModel.Events.GlobalObjectCleared, this._updateOverlay, this); + SDK.targetManager.addEventListener(SDK.TargetManager.Events.SuspendStateChanged, this._updateAllOverlays, this); + } + + _updateAllOverlays() { + for (var debuggerModel of SDK.targetManager.models(SDK.DebuggerModel)) + this._updateTargetOverlay(debuggerModel); + } + + /** + * @param {!Common.Event} event + */ + _updateOverlay(event) { + this._updateTargetOverlay(/** @type {!SDK.DebuggerModel} */ (event.data)); + } + + /** + * @param {!SDK.DebuggerModel} debuggerModel + */ + _updateTargetOverlay(debuggerModel) { + if (!debuggerModel.target().hasBrowserCapability()) + return; + var message = debuggerModel.isPaused() && !Common.moduleSetting('disablePausedStateOverlay').get() ? + Common.UIString('Paused in debugger') : + undefined; + debuggerModel.target().pageAgent().configureOverlay(SDK.targetManager.allTargetsSuspended(), message); + } +};
diff --git a/third_party/WebKit/Source/devtools/front_end/main/RenderingOptions.js b/third_party/WebKit/Source/devtools/front_end/main/RenderingOptions.js index 521a8a8..8613dec 100644 --- a/third_party/WebKit/Source/devtools/front_end/main/RenderingOptions.js +++ b/third_party/WebKit/Source/devtools/front_end/main/RenderingOptions.js
@@ -36,22 +36,35 @@ super(true); this.registerRequiredCSS('main/renderingOptions.css'); - this._appendCheckbox( - Common.UIString('Paint Flashing'), - Common.UIString('Highlights areas of the page (green) that need to be repainted'), - Common.moduleSetting('showPaintRects')); - this._appendCheckbox( - Common.UIString('Layer Borders'), Common.UIString('Shows layer borders (orange/olive) and tiles (cyan)'), - Common.moduleSetting('showDebugBorders')); - this._appendCheckbox( - Common.UIString('FPS Meter'), - Common.UIString('Plots frames per second, frame rate distribution, and GPU memory'), - Common.moduleSetting('showFPSCounter')); - this._appendCheckbox( - Common.UIString('Scrolling Performance Issues'), - Common.UIString( + /** @type {!Map.<string, !Element>} */ + this._settings = new Map(); + + var options = [ + { + label: Common.UIString('Paint Flashing'), + subtitle: Common.UIString('Highlights areas of the page (green) that need to be repainted'), + setterName: 'setShowPaintRects' + }, + { + label: Common.UIString('Layer Borders'), + subtitle: Common.UIString('Shows layer borders (orange/olive) and tiles (cyan)'), + setterName: 'setShowDebugBorders' + }, + { + label: Common.UIString('FPS Meter'), + subtitle: Common.UIString('Plots frames per second, frame rate distribution, and GPU memory'), + setterName: 'setShowFPSCounter' + }, + { + label: Common.UIString('Scrolling Performance Issues'), + subtitle: Common.UIString( 'Highlights elements (teal) that can slow down scrolling, including touch & wheel event handlers and other main-thread scrolling situations.'), - Common.moduleSetting('showScrollBottleneckRects')); + setterName: 'setShowScrollBottleneckRects' + } + ]; + for (var i = 0; i < options.length; i++) + this._appendCheckbox(options[i].label, options[i].setterName, options[i].subtitle); + this.contentElement.createChild('div').classList.add('panel-section-separator'); var cssMediaSubtitle = Common.UIString('Forces media type for testing print and screen styles'); @@ -67,7 +80,7 @@ this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this), false); this._mediaSelect.disabled = true; - SDK.targetManager.observeTargets(this); + SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser); } /** @@ -81,21 +94,35 @@ /** * @param {string} label - * @param {string} subtitle - * @param {!Common.Setting} setting + * @param {string} setterName + * @param {string=} subtitle */ - _appendCheckbox(label, subtitle, setting) { + _appendCheckbox(label, setterName, subtitle) { var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle); - UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting); + this._settings.set(setterName, checkboxLabel.checkboxElement); + checkboxLabel.checkboxElement.addEventListener('click', this._settingToggled.bind(this, setterName)); this.contentElement.appendChild(checkboxLabel); } /** + * @param {string} setterName + */ + _settingToggled(setterName) { + var enabled = this._settings.get(setterName).checked; + for (var target of SDK.targetManager.targets(SDK.Target.Capability.Browser)) + target.renderingAgent()[setterName](enabled); + } + + /** * @override * @param {!SDK.Target} target */ targetAdded(target) { - if (this._mediaCheckbox.checked && target.hasBrowserCapability()) + for (var setterName of this._settings.keysArray()) { + if (this._settings.get(setterName).checked) + target.renderingAgent()[setterName](true); + } + if (this._mediaCheckbox.checked) this._applyPrintMediaOverride(target); }
diff --git a/third_party/WebKit/Source/devtools/front_end/main/module.json b/third_party/WebKit/Source/devtools/front_end/main/module.json index c07180d6..9e5a909 100644 --- a/third_party/WebKit/Source/devtools/front_end/main/module.json +++ b/third_party/WebKit/Source/devtools/front_end/main/module.json
@@ -450,6 +450,7 @@ "scripts": [ "RenderingOptions.js", "SimpleApp.js", + "OverlayController.js", "GCActionDelegate.js", "RequestAppBannerActionDelegate.js", "ExecutionContextSelector.js",
diff --git a/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPopoverHelper.js b/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPopoverHelper.js index 40ed2d4..29c1533 100644 --- a/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPopoverHelper.js +++ b/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPopoverHelper.js
@@ -40,7 +40,7 @@ dispose() { if (this._resultHighlightedAsDOM) - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); if (this._linkifier) this._linkifier.dispose(); } @@ -131,7 +131,7 @@ var linkifier = null; var resultHighlightedAsDOM = false; if (result.subtype === 'node') { - SDK.OverlayModel.highlightObjectAsDOMNode(result); + SDK.DOMModel.highlightObjectAsDOMNode(result); resultHighlightedAsDOM = true; }
diff --git a/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPropertiesSection.js b/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPropertiesSection.js index c5fa5aa..4efb4dc 100644 --- a/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPropertiesSection.js +++ b/third_party/WebKit/Source/devtools/front_end/object_ui/ObjectPropertiesSection.js
@@ -306,8 +306,8 @@ Common.Revealer.reveal(value); event.consume(true); }, false); - valueElement.addEventListener('mousemove', () => SDK.OverlayModel.highlightObjectAsDOMNode(value), false); - valueElement.addEventListener('mouseleave', () => SDK.OverlayModel.hideDOMNodeHighlight(), false); + valueElement.addEventListener('mousemove', () => SDK.DOMModel.highlightObjectAsDOMNode(value), false); + valueElement.addEventListener('mouseleave', () => SDK.DOMModel.hideDOMNodeHighlight(), false); return valueElement; }
diff --git a/third_party/WebKit/Source/devtools/front_end/resources/ResourcesSection.js b/third_party/WebKit/Source/devtools/front_end/resources/ResourcesSection.js index 2ffe0362..047cb83 100644 --- a/third_party/WebKit/Source/devtools/front_end/resources/ResourcesSection.js +++ b/third_party/WebKit/Source/devtools/front_end/resources/ResourcesSection.js
@@ -155,17 +155,18 @@ this._panel.showCategoryView(this.titleAsText()); this.listItemElement.classList.remove('hovered'); - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); return false; } set hovered(hovered) { if (hovered) { this.listItemElement.classList.add('hovered'); - this._frame.resourceTreeModel().domModel().overlayModel().highlightFrame(this._frameId); + var domModel = this._frame.resourceTreeModel().domModel(); + domModel.highlightFrame(this._frameId); } else { this.listItemElement.classList.remove('hovered'); - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); } }
diff --git a/third_party/WebKit/Source/devtools/front_end/screencast/ScreencastView.js b/third_party/WebKit/Source/devtools/front_end/screencast/ScreencastView.js index a1250e9..91bbe66 100644 --- a/third_party/WebKit/Source/devtools/front_end/screencast/ScreencastView.js +++ b/third_party/WebKit/Source/devtools/front_end/screencast/ScreencastView.js
@@ -28,7 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * @implements {SDK.OverlayModel.Highlighter} + * @implements {SDK.DOMNodeHighlighter} * @unrestricted */ Screencast.ScreencastView = class extends UI.VBox { @@ -39,7 +39,6 @@ super(); this._screenCaptureModel = screenCaptureModel; this._domModel = screenCaptureModel.target().model(SDK.DOMModel); - this._overlayModel = screenCaptureModel.target().model(SDK.OverlayModel); this._resourceTreeModel = screenCaptureModel.target().model(SDK.ResourceTreeModel); this._networkManager = screenCaptureModel.target().model(SDK.NetworkManager); this._inputModel = screenCaptureModel.target().model(Screencast.InputModel); @@ -131,8 +130,8 @@ Math.floor(Math.min(maxImageDimension, dimensions.height)), undefined, this._screencastFrame.bind(this), this._screencastVisibilityChanged.bind(this)); Emulation.MultitargetTouchModel.instance().setCustomTouchEnabled(true); - if (this._overlayModel) - this._overlayModel.setHighlighter(this); + if (this._domModel) + this._domModel.setHighlighter(this); } _stopCasting() { @@ -141,8 +140,8 @@ this._isCasting = false; this._screenCaptureModel.stopScreencast(); Emulation.MultitargetTouchModel.instance().setCustomTouchEnabled(false); - if (this._overlayModel) - this._overlayModel.setHighlighter(null); + if (this._domModel) + this._domModel.setHighlighter(null); } /** @@ -246,7 +245,7 @@ return; if (event.type === 'mousemove') { this.highlightDOMNode(node, this._inspectModeConfig); - this._domModel.overlayModel().nodeHighlightRequested(node.id); + this._domModel.nodeHighlightRequested(node.id); } else if (event.type === 'click') { Common.Revealer.reveal(node); } @@ -317,7 +316,7 @@ /** * @override * @param {?SDK.DOMNode} node - * @param {?Protocol.Overlay.HighlightConfig} config + * @param {?Protocol.DOM.HighlightConfig} config * @param {!Protocol.DOM.BackendNodeId=} backendNodeId * @param {!Protocol.Runtime.RemoteObjectId=} objectId */ @@ -570,13 +569,14 @@ /** * @override - * @param {!Protocol.Overlay.InspectMode} mode - * @param {!Protocol.Overlay.HighlightConfig} config - * @return {!Promise} + * @param {!Protocol.DOM.InspectMode} mode + * @param {!Protocol.DOM.HighlightConfig} config + * @param {function(?Protocol.Error)=} callback */ - setInspectMode(mode, config) { - this._inspectModeConfig = mode !== Protocol.Overlay.InspectMode.None ? config : null; - return Promise.resolve(); + setInspectMode(mode, config, callback) { + this._inspectModeConfig = mode !== Protocol.DOM.InspectMode.None ? config : null; + if (callback) + callback(null); } /**
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js index 8457991..7780a00 100644 --- a/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js +++ b/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js
@@ -840,11 +840,11 @@ * @param {!Protocol.Runtime.RemoteObjectId=} objectId */ highlight(mode, objectId) { - this._domModel.overlayModel().highlightDOMNode(this.id, mode, undefined, objectId); + this._domModel.highlightDOMNode(this.id, mode, undefined, objectId); } highlightForTwoSeconds() { - this._domModel.overlayModel().highlightDOMNodeForTwoSeconds(this.id); + this._domModel.highlightDOMNodeForTwoSeconds(this.id); } /** @@ -1011,7 +1011,7 @@ highlight() { if (this._domModel) - this._domModel.overlayModel().highlightDOMNode(undefined, undefined, this._backendNodeId); + this._domModel.highlightDOMNode(undefined, undefined, this._backendNodeId); } }; @@ -1068,8 +1068,12 @@ this._attributeLoadNodeIds = {}; target.registerDOMDispatcher(new SDK.DOMDispatcher(this)); + this._inspectModeEnabled = false; this._runtimeModel = /** @type {!SDK.RuntimeModel} */ (target.model(SDK.RuntimeModel)); + this._defaultHighlighter = new SDK.DefaultDOMNodeHighlighter(this._agent); + this._highlighter = this._defaultHighlighter; + this._agent.enable(); } @@ -1088,10 +1092,26 @@ } /** - * @return {!SDK.OverlayModel} + * @param {!SDK.RemoteObject} object */ - overlayModel() { - return /** @type {!SDK.OverlayModel} */ (this.target().model(SDK.OverlayModel)); + static highlightObjectAsDOMNode(object) { + var domModel = object.runtimeModel().target().model(SDK.DOMModel); + if (domModel) + domModel.highlightDOMNode(undefined, undefined, undefined, object.objectId); + } + + static hideDOMNodeHighlight() { + for (var domModel of SDK.targetManager.models(SDK.DOMModel)) + domModel.highlightDOMNode(0); + } + + static muteHighlight() { + SDK.DOMModel.hideDOMNodeHighlight(); + SDK.DOMModel._highlightDisabled = true; + } + + static unmuteHighlight() { + SDK.DOMModel._highlightDisabled = false; } static cancelSearch() { @@ -1519,6 +1539,14 @@ } /** + * @param {!Protocol.DOM.BackendNodeId} backendNodeId + */ + _inspectNodeRequested(backendNodeId) { + var deferredNode = new SDK.DeferredDOMNode(this.target(), backendNodeId); + this.dispatchEventToListeners(SDK.DOMModel.Events.NodeInspected, deferredNode); + } + + /** * @param {string} query * @param {boolean} includeUserAgentShadowDOM * @param {function(number)} searchCallback @@ -1649,6 +1677,107 @@ } /** + * @param {!Protocol.DOM.NodeId=} nodeId + * @param {string=} mode + * @param {!Protocol.DOM.BackendNodeId=} backendNodeId + * @param {!Protocol.Runtime.RemoteObjectId=} objectId + */ + highlightDOMNode(nodeId, mode, backendNodeId, objectId) { + this.highlightDOMNodeWithConfig(nodeId, {mode: mode}, backendNodeId, objectId); + } + + /** + * @param {!Protocol.DOM.NodeId=} nodeId + * @param {!{mode: (string|undefined), showInfo: (boolean|undefined), selectors: (string|undefined)}=} config + * @param {!Protocol.DOM.BackendNodeId=} backendNodeId + * @param {!Protocol.Runtime.RemoteObjectId=} objectId + */ + highlightDOMNodeWithConfig(nodeId, config, backendNodeId, objectId) { + if (SDK.DOMModel._highlightDisabled) + return; + config = config || {mode: 'all', showInfo: undefined, selectors: undefined}; + if (this._hideDOMNodeHighlightTimeout) { + clearTimeout(this._hideDOMNodeHighlightTimeout); + delete this._hideDOMNodeHighlightTimeout; + } + var highlightConfig = this._buildHighlightConfig(config.mode); + if (typeof config.showInfo !== 'undefined') + highlightConfig.showInfo = config.showInfo; + if (typeof config.selectors !== 'undefined') + highlightConfig.selectorList = config.selectors; + this._highlighter.highlightDOMNode(this.nodeForId(nodeId || 0), highlightConfig, backendNodeId, objectId); + } + + /** + * @param {!Protocol.DOM.NodeId} nodeId + */ + highlightDOMNodeForTwoSeconds(nodeId) { + this.highlightDOMNode(nodeId); + this._hideDOMNodeHighlightTimeout = setTimeout(SDK.DOMModel.hideDOMNodeHighlight.bind(SDK.DOMModel), 2000); + } + + /** + * @param {!Protocol.Page.FrameId} frameId + */ + highlightFrame(frameId) { + if (SDK.DOMModel._highlightDisabled) + return; + this._highlighter.highlightFrame(frameId); + } + + /** + * @param {!Protocol.DOM.InspectMode} mode + * @param {function(?Protocol.Error)=} callback + */ + setInspectMode(mode, callback) { + /** + * @this {SDK.DOMModel} + */ + function onDocumentAvailable() { + this._inspectModeEnabled = mode !== Protocol.DOM.InspectMode.None; + this.dispatchEventToListeners(SDK.DOMModel.Events.InspectModeWillBeToggled, this); + this._highlighter.setInspectMode(mode, this._buildHighlightConfig(), callback); + } + this.requestDocument(onDocumentAvailable.bind(this)); + } + + /** + * @return {boolean} + */ + inspectModeEnabled() { + return this._inspectModeEnabled; + } + + /** + * @param {string=} mode + * @return {!Protocol.DOM.HighlightConfig} + */ + _buildHighlightConfig(mode) { + mode = mode || 'all'; + var showRulers = Common.moduleSetting('showMetricsRulers').get(); + var highlightConfig = {showInfo: mode === 'all', showRulers: showRulers, showExtensionLines: showRulers}; + if (mode === 'all' || mode === 'content') + highlightConfig.contentColor = Common.Color.PageHighlight.Content.toProtocolRGBA(); + + if (mode === 'all' || mode === 'padding') + highlightConfig.paddingColor = Common.Color.PageHighlight.Padding.toProtocolRGBA(); + + if (mode === 'all' || mode === 'border') + highlightConfig.borderColor = Common.Color.PageHighlight.Border.toProtocolRGBA(); + + if (mode === 'all' || mode === 'margin') + highlightConfig.marginColor = Common.Color.PageHighlight.Margin.toProtocolRGBA(); + + if (mode === 'all') { + highlightConfig.eventTargetColor = Common.Color.PageHighlight.EventTarget.toProtocolRGBA(); + highlightConfig.shapeColor = Common.Color.PageHighlight.Shape.toProtocolRGBA(); + highlightConfig.shapeMarginColor = Common.Color.PageHighlight.ShapeMargin.toProtocolRGBA(); + highlightConfig.displayAsMaterial = true; + } + return highlightConfig; + } + + /** * @param {!SDK.DOMNode} node * @param {function(?Protocol.Error, ...)=} callback * @return {function(...)} @@ -1688,6 +1817,13 @@ } /** + * @param {?SDK.DOMNodeHighlighter} highlighter + */ + setHighlighter(highlighter) { + this._highlighter = highlighter || this._defaultHighlighter; + } + + /** * @param {number} x * @param {number} y * @param {boolean} includeUserAgentShadowDOM @@ -1762,6 +1898,17 @@ this._agent.enable(fulfill); } } + + /** + * @param {!Protocol.DOM.NodeId} nodeId + */ + nodeHighlightRequested(nodeId) { + var node = this.nodeForId(nodeId); + if (!node) + return; + + this.dispatchEventToListeners(SDK.DOMModel.Events.NodeHighlightedInOverlay, node); + } }; SDK.SDKModel.register(SDK.DOMModel, SDK.Target.Capability.DOM, true); @@ -1773,10 +1920,13 @@ CharacterDataModified: Symbol('CharacterDataModified'), DOMMutated: Symbol('DOMMutated'), NodeInserted: Symbol('NodeInserted'), + NodeInspected: Symbol('NodeInspected'), + NodeHighlightedInOverlay: Symbol('NodeHighlightedInOverlay'), NodeRemoved: Symbol('NodeRemoved'), DocumentUpdated: Symbol('DocumentUpdated'), ChildNodeCountUpdated: Symbol('ChildNodeCountUpdated'), DistributedNodesChanged: Symbol('DistributedNodesChanged'), + InspectModeWillBeToggled: Symbol('InspectModeWillBeToggled'), MarkersChanged: Symbol('MarkersChanged') }; @@ -1803,6 +1953,14 @@ /** * @override * @param {!Protocol.DOM.NodeId} nodeId + */ + inspectNodeRequested(nodeId) { + this._domModel._inspectNodeRequested(nodeId); + } + + /** + * @override + * @param {!Protocol.DOM.NodeId} nodeId * @param {string} name * @param {string} value */ @@ -1917,4 +2075,86 @@ distributedNodesUpdated(insertionPointId, distributedNodes) { this._domModel._distributedNodesUpdated(insertionPointId, distributedNodes); } + + /** + * @override + * @param {!Protocol.DOM.NodeId} nodeId + */ + nodeHighlightRequested(nodeId) { + this._domModel.nodeHighlightRequested(nodeId); + } +}; + +/** + * @interface + */ +SDK.DOMNodeHighlighter = function() {}; + +SDK.DOMNodeHighlighter.prototype = { + /** + * @param {?SDK.DOMNode} node + * @param {!Protocol.DOM.HighlightConfig} config + * @param {!Protocol.DOM.BackendNodeId=} backendNodeId + * @param {!Protocol.Runtime.RemoteObjectId=} objectId + */ + highlightDOMNode(node, config, backendNodeId, objectId) {}, + + /** + * @param {!Protocol.DOM.InspectMode} mode + * @param {!Protocol.DOM.HighlightConfig} config + * @param {function(?Protocol.Error)=} callback + */ + setInspectMode(mode, config, callback) {}, + + /** + * @param {!Protocol.Page.FrameId} frameId + */ + highlightFrame(frameId) {} +}; + +/** + * @implements {SDK.DOMNodeHighlighter} + * @unrestricted + */ +SDK.DefaultDOMNodeHighlighter = class { + /** + * @param {!Protocol.DOMAgent} agent + */ + constructor(agent) { + this._agent = agent; + } + + /** + * @override + * @param {?SDK.DOMNode} node + * @param {!Protocol.DOM.HighlightConfig} config + * @param {!Protocol.DOM.BackendNodeId=} backendNodeId + * @param {!Protocol.Runtime.RemoteObjectId=} objectId + */ + highlightDOMNode(node, config, backendNodeId, objectId) { + if (objectId || node || backendNodeId) + this._agent.highlightNode(config, (objectId || backendNodeId) ? undefined : node.id, backendNodeId, objectId); + else + this._agent.hideHighlight(); + } + + /** + * @override + * @param {!Protocol.DOM.InspectMode} mode + * @param {!Protocol.DOM.HighlightConfig} config + * @param {function(?Protocol.Error)=} callback + */ + setInspectMode(mode, config, callback) { + this._agent.setInspectMode(mode, config, callback); + } + + /** + * @override + * @param {!Protocol.Page.FrameId} frameId + */ + highlightFrame(frameId) { + this._agent.highlightFrame( + frameId, Common.Color.PageHighlight.Content.toProtocolRGBA(), + Common.Color.PageHighlight.ContentOutline.toProtocolRGBA()); + } };
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/OverlayModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/OverlayModel.js deleted file mode 100644 index de8d729..0000000 --- a/third_party/WebKit/Source/devtools/front_end/sdk/OverlayModel.js +++ /dev/null
@@ -1,320 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @implements {Protocol.OverlayDispatcher} - */ -SDK.OverlayModel = class extends SDK.SDKModel { - /** - * @param {!SDK.Target} target - */ - constructor(target) { - super(target); - this._domModel = /** @type {!SDK.DOMModel} */ (target.model(SDK.DOMModel)); - - target.registerOverlayDispatcher(this); - this._overlayAgent = target.overlayAgent(); - this._overlayAgent.enable(); - this._overlayAgent.setShowViewportSizeOnResize(true); - - this._debuggerModel = target.model(SDK.DebuggerModel); - if (this._debuggerModel) { - Common.moduleSetting('disablePausedStateOverlay').addChangeListener(this._updatePausedInDebuggerMessage, this); - this._debuggerModel.addEventListener( - SDK.DebuggerModel.Events.DebuggerPaused, this._updatePausedInDebuggerMessage, this); - this._debuggerModel.addEventListener( - SDK.DebuggerModel.Events.DebuggerResumed, this._updatePausedInDebuggerMessage, this); - // TODO(dgozman): we should get DebuggerResumed on navigations instead of listening to GlobalObjectCleared. - this._debuggerModel.addEventListener( - SDK.DebuggerModel.Events.GlobalObjectCleared, this._updatePausedInDebuggerMessage, this); - } - - this._inspectModeEnabled = false; - this._hideHighlightTimeout = null; - this._defaultHighlighter = new SDK.OverlayModel.DefaultHighlighter(this); - this._highlighter = this._defaultHighlighter; - - this._showPaintRectsSetting = Common.moduleSetting('showPaintRects'); - this._showPaintRectsSetting.addChangeListener( - () => this._overlayAgent.setShowPaintRects(this._showPaintRectsSetting.get())); - if (this._showPaintRectsSetting.get()) - this._overlayAgent.setShowPaintRects(true); - - this._showDebugBordersSetting = Common.moduleSetting('showDebugBorders'); - this._showDebugBordersSetting.addChangeListener( - () => this._overlayAgent.setShowDebugBorders(this._showDebugBordersSetting.get())); - if (this._showDebugBordersSetting.get()) - this._overlayAgent.setShowDebugBorders(true); - - this._showFPSCounterSetting = Common.moduleSetting('showFPSCounter'); - this._showFPSCounterSetting.addChangeListener( - () => this._overlayAgent.setShowFPSCounter(this._showFPSCounterSetting.get())); - if (this._showFPSCounterSetting.get()) - this._overlayAgent.setShowFPSCounter(true); - - this._showScrollBottleneckRectsSetting = Common.moduleSetting('showScrollBottleneckRects'); - this._showScrollBottleneckRectsSetting.addChangeListener( - () => this._overlayAgent.setShowScrollBottleneckRects(this._showScrollBottleneckRectsSetting.get())); - if (this._showScrollBottleneckRectsSetting.get()) - this._overlayAgent.setShowScrollBottleneckRects(true); - } - - /** - * @param {!SDK.RemoteObject} object - */ - static highlightObjectAsDOMNode(object) { - var domModel = object.runtimeModel().target().model(SDK.DOMModel); - if (domModel) - domModel.overlayModel().highlightDOMNode(undefined, undefined, undefined, object.objectId); - } - - static hideDOMNodeHighlight() { - for (var overlayModel of SDK.targetManager.models(SDK.OverlayModel)) - overlayModel.highlightDOMNode(0); - } - - static muteHighlight() { - SDK.OverlayModel.hideDOMNodeHighlight(); - SDK.OverlayModel._highlightDisabled = true; - } - - static unmuteHighlight() { - SDK.OverlayModel._highlightDisabled = false; - } - - /** - * @override - * @return {!Promise} - */ - suspendModel() { - return this._overlayAgent.setSuspended(true); - } - - /** - * @override - * @return {!Promise} - */ - resumeModel() { - return this._overlayAgent.setSuspended(false); - } - - setShowViewportSizeOnResize(show) { - this._overlayAgent.setShowViewportSizeOnResize(show); - } - - _updatePausedInDebuggerMessage() { - var message = this._debuggerModel.isPaused() && !Common.moduleSetting('disablePausedStateOverlay').get() ? - Common.UIString('Paused in debugger') : - undefined; - this._overlayAgent.setPausedInDebuggerMessage(message); - } - - /** - * @param {?SDK.OverlayModel.Highlighter} highlighter - */ - setHighlighter(highlighter) { - this._highlighter = highlighter || this._defaultHighlighter; - } - - /** - * @param {!Protocol.Overlay.InspectMode} mode - * @return {!Promise} - */ - setInspectMode(mode) { - var requestDocumentPromise = new Promise(fulfill => this._domModel.requestDocument(fulfill)); - return requestDocumentPromise.then(() => { - this._inspectModeEnabled = mode !== Protocol.Overlay.InspectMode.None; - this.dispatchEventToListeners(SDK.OverlayModel.Events.InspectModeWillBeToggled, this); - return this._highlighter.setInspectMode(mode, this._buildHighlightConfig()); - }); - } - - /** - * @return {boolean} - */ - inspectModeEnabled() { - return this._inspectModeEnabled; - } - - /** - * @param {!Protocol.DOM.NodeId=} nodeId - * @param {string=} mode - * @param {!Protocol.DOM.BackendNodeId=} backendNodeId - * @param {!Protocol.Runtime.RemoteObjectId=} objectId - */ - highlightDOMNode(nodeId, mode, backendNodeId, objectId) { - this.highlightDOMNodeWithConfig(nodeId, {mode: mode}, backendNodeId, objectId); - } - - /** - * @param {!Protocol.DOM.NodeId=} nodeId - * @param {!{mode: (string|undefined), showInfo: (boolean|undefined), selectors: (string|undefined)}=} config - * @param {!Protocol.DOM.BackendNodeId=} backendNodeId - * @param {!Protocol.Runtime.RemoteObjectId=} objectId - */ - highlightDOMNodeWithConfig(nodeId, config, backendNodeId, objectId) { - if (SDK.OverlayModel._highlightDisabled) - return; - config = config || {mode: 'all', showInfo: undefined, selectors: undefined}; - if (this._hideHighlightTimeout) { - clearTimeout(this._hideHighlightTimeout); - this._hideHighlightTimeout = null; - } - var highlightConfig = this._buildHighlightConfig(config.mode); - if (typeof config.showInfo !== 'undefined') - highlightConfig.showInfo = config.showInfo; - if (typeof config.selectors !== 'undefined') - highlightConfig.selectorList = config.selectors; - this._highlighter.highlightDOMNode(this._domModel.nodeForId(nodeId || 0), highlightConfig, backendNodeId, objectId); - } - - /** - * @param {!Protocol.DOM.NodeId} nodeId - */ - highlightDOMNodeForTwoSeconds(nodeId) { - this.highlightDOMNode(nodeId); - this._hideHighlightTimeout = setTimeout(() => this.highlightDOMNode(0), 2000); - } - - /** - * @param {!Protocol.Page.FrameId} frameId - */ - highlightFrame(frameId) { - if (SDK.OverlayModel._highlightDisabled) - return; - this._highlighter.highlightFrame(frameId); - } - - /** - * @param {string=} mode - * @return {!Protocol.Overlay.HighlightConfig} - */ - _buildHighlightConfig(mode) { - mode = mode || 'all'; - var showRulers = Common.moduleSetting('showMetricsRulers').get(); - var highlightConfig = {showInfo: mode === 'all', showRulers: showRulers, showExtensionLines: showRulers}; - if (mode === 'all' || mode === 'content') - highlightConfig.contentColor = Common.Color.PageHighlight.Content.toProtocolRGBA(); - - if (mode === 'all' || mode === 'padding') - highlightConfig.paddingColor = Common.Color.PageHighlight.Padding.toProtocolRGBA(); - - if (mode === 'all' || mode === 'border') - highlightConfig.borderColor = Common.Color.PageHighlight.Border.toProtocolRGBA(); - - if (mode === 'all' || mode === 'margin') - highlightConfig.marginColor = Common.Color.PageHighlight.Margin.toProtocolRGBA(); - - if (mode === 'all') { - highlightConfig.eventTargetColor = Common.Color.PageHighlight.EventTarget.toProtocolRGBA(); - highlightConfig.shapeColor = Common.Color.PageHighlight.Shape.toProtocolRGBA(); - highlightConfig.shapeMarginColor = Common.Color.PageHighlight.ShapeMargin.toProtocolRGBA(); - highlightConfig.displayAsMaterial = true; - } - return highlightConfig; - } - - /** - * @override - * @param {!Protocol.DOM.NodeId} nodeId - */ - nodeHighlightRequested(nodeId) { - var node = this._domModel.nodeForId(nodeId); - if (node) - this.dispatchEventToListeners(SDK.OverlayModel.Events.HighlightNodeRequested, node); - } - - /** - * @override - * @param {!Protocol.DOM.BackendNodeId} backendNodeId - */ - inspectNodeRequested(backendNodeId) { - var deferredNode = new SDK.DeferredDOMNode(this.target(), backendNodeId); - this.dispatchEventToListeners(SDK.OverlayModel.Events.InspectNodeRequested, deferredNode); - } -}; - -SDK.SDKModel.register(SDK.OverlayModel, SDK.Target.Capability.DOM, true); - -/** @enum {symbol} */ -SDK.OverlayModel.Events = { - InspectModeWillBeToggled: Symbol('InspectModeWillBeToggled'), - HighlightNodeRequested: Symbol('HighlightNodeRequested'), - InspectNodeRequested: Symbol('InspectNodeRequested'), -}; - -/** - * @interface - */ -SDK.OverlayModel.Highlighter = function() {}; - -SDK.OverlayModel.Highlighter.prototype = { - /** - * @param {?SDK.DOMNode} node - * @param {!Protocol.Overlay.HighlightConfig} config - * @param {!Protocol.DOM.BackendNodeId=} backendNodeId - * @param {!Protocol.Runtime.RemoteObjectId=} objectId - */ - highlightDOMNode(node, config, backendNodeId, objectId) {}, - - /** - * @param {!Protocol.Overlay.InspectMode} mode - * @param {!Protocol.Overlay.HighlightConfig} config - * @return {!Promise} - */ - setInspectMode(mode, config) {}, - - /** - * @param {!Protocol.Page.FrameId} frameId - */ - highlightFrame(frameId) {} -}; - -/** - * @implements {SDK.OverlayModel.Highlighter} - */ -SDK.OverlayModel.DefaultHighlighter = class { - /** - * @param {!SDK.OverlayModel} model - */ - constructor(model) { - this._model = model; - } - - /** - * @override - * @param {?SDK.DOMNode} node - * @param {!Protocol.Overlay.HighlightConfig} config - * @param {!Protocol.DOM.BackendNodeId=} backendNodeId - * @param {!Protocol.Runtime.RemoteObjectId=} objectId - */ - highlightDOMNode(node, config, backendNodeId, objectId) { - if (objectId || node || backendNodeId) { - this._model._overlayAgent.highlightNode( - config, (objectId || backendNodeId) ? undefined : node.id, backendNodeId, objectId); - } else { - this._model._overlayAgent.hideHighlight(); - } - } - - /** - * @override - * @param {!Protocol.Overlay.InspectMode} mode - * @param {!Protocol.Overlay.HighlightConfig} config - * @return {!Promise} - */ - setInspectMode(mode, config) { - return this._model._overlayAgent.setInspectMode(mode, config); - } - - /** - * @override - * @param {!Protocol.Page.FrameId} frameId - */ - highlightFrame(frameId) { - this._model._overlayAgent.highlightFrame( - frameId, Common.Color.PageHighlight.Content.toProtocolRGBA(), - Common.Color.PageHighlight.ContentOutline.toProtocolRGBA()); - } -};
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/module.json b/third_party/WebKit/Source/devtools/front_end/sdk/module.json index e4c2be3..8bb5fab 100644 --- a/third_party/WebKit/Source/devtools/front_end/sdk/module.json +++ b/third_party/WebKit/Source/devtools/front_end/sdk/module.json
@@ -84,34 +84,6 @@ }, { "type": "setting", - "settingName": "showPaintRects", - "settingType": "boolean", - "storageType": "session", - "defaultValue": false - }, - { - "type": "setting", - "settingName": "showDebugBorders", - "settingType": "boolean", - "storageType": "session", - "defaultValue": false - }, - { - "type": "setting", - "settingName": "showFPSCounter", - "settingType": "boolean", - "storageType": "session", - "defaultValue": false - }, - { - "type": "setting", - "settingName": "showScrollBottleneckRects", - "settingType": "boolean", - "storageType": "session", - "defaultValue": false - }, - { - "type": "setting", "category": "Console", "title": "Enable custom formatters", "settingName": "customFormatters", @@ -165,7 +137,6 @@ "ServiceWorkerManager.js", "TracingManager.js", "TracingModel.js", - "OverlayModel.js", "RuntimeModel.js", "ScreenCaptureModel.js", "Script.js",
diff --git a/third_party/WebKit/Source/devtools/front_end/sources/NavigatorView.js b/third_party/WebKit/Source/devtools/front_end/sources/NavigatorView.js index 62a35a08..4862b79 100644 --- a/third_party/WebKit/Source/devtools/front_end/sources/NavigatorView.js +++ b/third_party/WebKit/Source/devtools/front_end/sources/NavigatorView.js
@@ -433,11 +433,11 @@ */ function hoverCallback(hovered) { if (hovered) { - var overlayModel = target.model(SDK.OverlayModel); - if (overlayModel) - overlayModel.highlightFrame(frame.id); + var domModel = target.model(SDK.DOMModel); + if (domModel) + domModel.highlightFrame(frame.id); } else { - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); } } return frameNode;
diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineFlameChartView.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineFlameChartView.js index 81d5220..8a1df75 100644 --- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineFlameChartView.js +++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineFlameChartView.js
@@ -154,7 +154,7 @@ * @param {!Common.Event} commonEvent */ _onEntryHighlighted(commonEvent) { - SDK.OverlayModel.hideDOMNodeHighlight(); + SDK.DOMModel.hideDOMNodeHighlight(); var entryIndex = /** @type {number} */ (commonEvent.data); var event = this._mainDataProvider.eventByIndex(entryIndex); if (!event)
diff --git a/third_party/WebKit/Source/platform/heap/HeapPage.h b/third_party/WebKit/Source/platform/heap/HeapPage.h index 43019c6..8b8e6e0e 100644 --- a/third_party/WebKit/Source/platform/heap/HeapPage.h +++ b/third_party/WebKit/Source/platform/heap/HeapPage.h
@@ -241,6 +241,9 @@ // understand, and is public. static void CheckFromPayload(const void*); + // Returns true if magic number is valid. + bool IsValid() const; + static const uint32_t kZappedMagic = 0xDEAD4321; protected: @@ -854,10 +857,17 @@ return result; } +NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::IsValid() const { +#if CPU(64BIT) + return GetMagic() == magic_; +#else + return true; +#endif +} + NO_SANITIZE_ADDRESS inline void HeapObjectHeader::CheckHeader() const { #if CPU(64BIT) - const bool good_magic = GetMagic() == magic_; - DCHECK(good_magic); + DCHECK(IsValid()); #endif }
diff --git a/third_party/WebKit/Source/web/BUILD.gn b/third_party/WebKit/Source/web/BUILD.gn index 6ee84e75..aecc65d9 100644 --- a/third_party/WebKit/Source/web/BUILD.gn +++ b/third_party/WebKit/Source/web/BUILD.gn
@@ -79,8 +79,10 @@ "IndexedDBClientImpl.h", "InspectorEmulationAgent.cpp", "InspectorEmulationAgent.h", - "InspectorOverlayAgent.cpp", - "InspectorOverlayAgent.h", + "InspectorOverlay.cpp", + "InspectorOverlay.h", + "InspectorRenderingAgent.cpp", + "InspectorRenderingAgent.h", "LinkHighlightImpl.cpp", "LinkHighlightImpl.h", "LocalFileSystemClient.cpp",
diff --git a/third_party/WebKit/Source/web/InspectorOverlay.cpp b/third_party/WebKit/Source/web/InspectorOverlay.cpp new file mode 100644 index 0000000..850d283 --- /dev/null +++ b/third_party/WebKit/Source/web/InspectorOverlay.cpp
@@ -0,0 +1,827 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "web/InspectorOverlay.h" + +#include <memory> + +#include "bindings/core/v8/ScriptController.h" +#include "bindings/core/v8/ScriptSourceCode.h" +#include "bindings/core/v8/V8Binding.h" +#include "bindings/core/v8/V8InspectorOverlayHost.h" +#include "core/dom/Node.h" +#include "core/dom/StaticNodeList.h" +#include "core/dom/TaskRunnerHelper.h" +#include "core/frame/FrameView.h" +#include "core/frame/LocalFrame.h" +#include "core/frame/LocalFrameClient.h" +#include "core/frame/Settings.h" +#include "core/frame/VisualViewport.h" +#include "core/html/HTMLFrameOwnerElement.h" +#include "core/input/EventHandler.h" +#include "core/inspector/InspectorOverlayHost.h" +#include "core/layout/api/LayoutViewItem.h" +#include "core/loader/EmptyClients.h" +#include "core/loader/FrameLoadRequest.h" +#include "core/page/ChromeClient.h" +#include "core/page/Page.h" +#include "platform/ScriptForbiddenScope.h" +#include "platform/graphics/Color.h" +#include "platform/graphics/GraphicsContext.h" +#include "platform/graphics/paint/CullRect.h" +#include "platform/wtf/AutoReset.h" +#include "public/platform/Platform.h" +#include "public/platform/WebData.h" +#include "v8/include/v8.h" +#include "web/ChromeClientImpl.h" +#include "web/PageOverlay.h" +#include "web/WebInputEventConversion.h" +#include "web/WebLocalFrameImpl.h" + +namespace blink { + +namespace { + +Node* HoveredNodeForPoint(LocalFrame* frame, + const IntPoint& point_in_root_frame, + bool ignore_pointer_events_none) { + HitTestRequest::HitTestRequestType hit_type = + HitTestRequest::kMove | HitTestRequest::kReadOnly | + HitTestRequest::kAllowChildFrameContent; + if (ignore_pointer_events_none) + hit_type |= HitTestRequest::kIgnorePointerEventsNone; + HitTestRequest request(hit_type); + HitTestResult result(request, + frame->View()->RootFrameToContents(point_in_root_frame)); + frame->ContentLayoutItem().HitTest(result); + Node* node = result.InnerPossiblyPseudoNode(); + while (node && node->getNodeType() == Node::kTextNode) + node = node->parentNode(); + return node; +} + +Node* HoveredNodeForEvent(LocalFrame* frame, + const WebGestureEvent& event, + bool ignore_pointer_events_none) { + return HoveredNodeForPoint(frame, + RoundedIntPoint(event.PositionInRootFrame()), + ignore_pointer_events_none); +} + +Node* HoveredNodeForEvent(LocalFrame* frame, + const WebMouseEvent& event, + bool ignore_pointer_events_none) { + return HoveredNodeForPoint(frame, + RoundedIntPoint(event.PositionInRootFrame()), + ignore_pointer_events_none); +} + +Node* HoveredNodeForEvent(LocalFrame* frame, + const WebTouchEvent& event, + bool ignore_pointer_events_none) { + if (!event.touches_length) + return nullptr; + WebTouchPoint transformed_point = event.TouchPointInRootFrame(0); + return HoveredNodeForPoint(frame, RoundedIntPoint(transformed_point.position), + ignore_pointer_events_none); +} +} // namespace + +class InspectorOverlay::InspectorPageOverlayDelegate final + : public PageOverlay::Delegate { + public: + explicit InspectorPageOverlayDelegate(InspectorOverlay& overlay) + : overlay_(&overlay) {} + + void PaintPageOverlay(const PageOverlay&, + GraphicsContext& graphics_context, + const WebSize& web_view_size) const override { + if (overlay_->IsEmpty()) + return; + + FrameView* view = overlay_->OverlayMainFrame()->View(); + DCHECK(!view->NeedsLayout()); + view->Paint(graphics_context, + CullRect(IntRect(0, 0, view->Width(), view->Height()))); + } + + private: + Persistent<InspectorOverlay> overlay_; +}; + +class InspectorOverlay::InspectorOverlayChromeClient final + : public EmptyChromeClient { + public: + static InspectorOverlayChromeClient* Create(ChromeClient& client, + InspectorOverlay& overlay) { + return new InspectorOverlayChromeClient(client, overlay); + } + + DEFINE_INLINE_VIRTUAL_TRACE() { + visitor->Trace(client_); + visitor->Trace(overlay_); + EmptyChromeClient::Trace(visitor); + } + + void SetCursor(const Cursor& cursor, LocalFrame* local_root) override { + ToChromeClientImpl(client_)->SetCursorOverridden(false); + ToChromeClientImpl(client_)->SetCursor(cursor, + overlay_->frame_impl_->GetFrame()); + ToChromeClientImpl(client_)->SetCursorOverridden(false); + } + + void SetToolTip(LocalFrame& frame, + const String& tooltip, + TextDirection direction) override { + DCHECK_EQ(&frame, overlay_->OverlayMainFrame()); + client_->SetToolTip(*overlay_->frame_impl_->GetFrame(), tooltip, direction); + } + + void InvalidateRect(const IntRect&) override { overlay_->Invalidate(); } + + void ScheduleAnimation(LocalFrame* frame) override { + if (overlay_->in_layout_) + return; + + client_->ScheduleAnimation(frame); + } + + private: + InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlay& overlay) + : client_(&client), overlay_(&overlay) {} + + Member<ChromeClient> client_; + Member<InspectorOverlay> overlay_; +}; + +InspectorOverlay::InspectorOverlay(WebLocalFrameImpl* frame_impl) + : frame_impl_(frame_impl), + overlay_host_(InspectorOverlayHost::Create()), + draw_view_size_(false), + resize_timer_active_(false), + omit_tooltip_(false), + timer_(TaskRunnerHelper::Get(TaskType::kUnspecedTimer, + frame_impl->GetFrame()), + this, + &InspectorOverlay::OnTimer), + suspended_(false), + show_reloading_blanket_(false), + in_layout_(false), + needs_update_(false), + swallow_next_mouse_up_(false), + inspect_mode_(InspectorDOMAgent::kNotSearching) {} + +InspectorOverlay::~InspectorOverlay() { + DCHECK(!overlay_page_); +} + +DEFINE_TRACE(InspectorOverlay) { + visitor->Trace(frame_impl_); + visitor->Trace(highlight_node_); + visitor->Trace(event_target_node_); + visitor->Trace(overlay_page_); + visitor->Trace(overlay_chrome_client_); + visitor->Trace(overlay_host_); + visitor->Trace(dom_agent_); + visitor->Trace(hovered_node_for_inspect_mode_); +} + +void InspectorOverlay::Init(v8_inspector::V8InspectorSession* v8_session, + InspectorDOMAgent* dom_agent) { + v8_session_ = v8_session; + dom_agent_ = dom_agent; + overlay_host_->SetListener(this); +} + +void InspectorOverlay::Invalidate() { + if (!page_overlay_) { + page_overlay_ = PageOverlay::Create( + frame_impl_, WTF::WrapUnique(new InspectorPageOverlayDelegate(*this))); + } + + page_overlay_->Update(); +} + +void InspectorOverlay::UpdateAllLifecyclePhases() { + if (IsEmpty()) + return; + + AutoReset<bool> scoped(&in_layout_, true); + if (needs_update_) { + needs_update_ = false; + RebuildOverlayPage(); + } + OverlayMainFrame()->View()->UpdateAllLifecyclePhases(); +} + +bool InspectorOverlay::HandleInputEvent(const WebInputEvent& input_event) { + bool handled = false; + + if (IsEmpty()) + return false; + + if (input_event.GetType() == WebInputEvent::kGestureTap) { + // We only have a use for gesture tap. + WebGestureEvent transformed_event = TransformWebGestureEvent( + frame_impl_->GetFrameView(), + static_cast<const WebGestureEvent&>(input_event)); + handled = HandleGestureEvent(transformed_event); + if (handled) + return true; + + OverlayMainFrame()->GetEventHandler().HandleGestureEvent(transformed_event); + } + if (WebInputEvent::IsMouseEventType(input_event.GetType())) { + WebMouseEvent mouse_event = + TransformWebMouseEvent(frame_impl_->GetFrameView(), + static_cast<const WebMouseEvent&>(input_event)); + + if (mouse_event.GetType() == WebInputEvent::kMouseMove) + handled = HandleMouseMove(mouse_event); + else if (mouse_event.GetType() == WebInputEvent::kMouseDown) + handled = HandleMouseDown(); + else if (mouse_event.GetType() == WebInputEvent::kMouseUp) + handled = HandleMouseUp(); + + if (handled) + return true; + + if (mouse_event.GetType() == WebInputEvent::kMouseMove) { + handled = OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( + mouse_event, TransformWebMouseEventVector( + frame_impl_->GetFrameView(), + std::vector<const WebInputEvent*>())) != + WebInputEventResult::kNotHandled; + } + if (mouse_event.GetType() == WebInputEvent::kMouseDown) + handled = OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( + mouse_event) != WebInputEventResult::kNotHandled; + if (mouse_event.GetType() == WebInputEvent::kMouseUp) + handled = OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( + mouse_event) != WebInputEventResult::kNotHandled; + } + + if (WebInputEvent::IsTouchEventType(input_event.GetType())) { + WebTouchEvent transformed_event = + TransformWebTouchEvent(frame_impl_->GetFrameView(), + static_cast<const WebTouchEvent&>(input_event)); + handled = HandleTouchEvent(transformed_event); + if (handled) + return true; + OverlayMainFrame()->GetEventHandler().HandleTouchEvent( + transformed_event, Vector<WebTouchEvent>()); + } + if (WebInputEvent::IsKeyboardEventType(input_event.GetType())) { + OverlayMainFrame()->GetEventHandler().KeyEvent( + static_cast<const WebKeyboardEvent&>(input_event)); + } + + if (input_event.GetType() == WebInputEvent::kMouseWheel) { + WebMouseWheelEvent transformed_event = TransformWebMouseWheelEvent( + frame_impl_->GetFrameView(), + static_cast<const WebMouseWheelEvent&>(input_event)); + handled = OverlayMainFrame()->GetEventHandler().HandleWheelEvent( + transformed_event) != WebInputEventResult::kNotHandled; + } + + return handled; +} + +void InspectorOverlay::SetPausedInDebuggerMessage(const String& message) { + paused_in_debugger_message_ = message; + ScheduleUpdate(); +} + +void InspectorOverlay::ShowReloadingBlanket() { + show_reloading_blanket_ = true; + ScheduleUpdate(); +} + +void InspectorOverlay::HideReloadingBlanket() { + if (!show_reloading_blanket_) + return; + show_reloading_blanket_ = false; + if (suspended_) + ClearInternal(); + else + ScheduleUpdate(); +} + +void InspectorOverlay::HideHighlight() { + highlight_node_.Clear(); + event_target_node_.Clear(); + highlight_quad_.reset(); + ScheduleUpdate(); +} + +void InspectorOverlay::HighlightNode( + Node* node, + const InspectorHighlightConfig& highlight_config, + bool omit_tooltip) { + HighlightNode(node, nullptr, highlight_config, omit_tooltip); +} + +void InspectorOverlay::HighlightNode( + Node* node, + Node* event_target, + const InspectorHighlightConfig& highlight_config, + bool omit_tooltip) { + node_highlight_config_ = highlight_config; + highlight_node_ = node; + event_target_node_ = event_target; + omit_tooltip_ = omit_tooltip; + ScheduleUpdate(); +} + +void InspectorOverlay::SetInspectMode( + InspectorDOMAgent::SearchMode search_mode, + std::unique_ptr<InspectorHighlightConfig> highlight_config) { + inspect_mode_ = search_mode; + ScheduleUpdate(); + + if (search_mode != InspectorDOMAgent::kNotSearching) { + inspect_mode_highlight_config_ = std::move(highlight_config); + } else { + hovered_node_for_inspect_mode_.Clear(); + HideHighlight(); + } +} + +void InspectorOverlay::HighlightQuad( + std::unique_ptr<FloatQuad> quad, + const InspectorHighlightConfig& highlight_config) { + quad_highlight_config_ = highlight_config; + highlight_quad_ = std::move(quad); + omit_tooltip_ = false; + ScheduleUpdate(); +} + +bool InspectorOverlay::IsEmpty() { + if (show_reloading_blanket_) + return false; + if (suspended_) + return true; + bool has_visible_elements = highlight_node_ || event_target_node_ || + highlight_quad_ || + (resize_timer_active_ && draw_view_size_) || + !paused_in_debugger_message_.IsNull(); + return !has_visible_elements && + inspect_mode_ == InspectorDOMAgent::kNotSearching; +} + +void InspectorOverlay::ScheduleUpdate() { + if (IsEmpty()) { + if (page_overlay_) + page_overlay_.reset(); + return; + } + needs_update_ = true; + LocalFrame* frame = frame_impl_->GetFrame(); + if (frame) { + frame->GetPage()->GetChromeClient().ScheduleAnimation(frame); + } +} + +void InspectorOverlay::RebuildOverlayPage() { + FrameView* view = frame_impl_->GetFrameView(); + LocalFrame* frame = frame_impl_->GetFrame(); + if (!view || !frame) + return; + + IntRect visible_rect_in_document = + view->GetScrollableArea()->VisibleContentRect(); + IntSize viewport_size = frame->GetPage()->GetVisualViewport().Size(); + OverlayMainFrame()->View()->Resize(viewport_size); + OverlayPage()->GetVisualViewport().SetSize(viewport_size); + OverlayMainFrame()->SetPageZoomFactor(WindowToViewportScale()); + + Reset(viewport_size, visible_rect_in_document.Location()); + + if (show_reloading_blanket_) { + EvaluateInOverlay("showReloadingBlanket", ""); + return; + } + DrawNodeHighlight(); + DrawQuadHighlight(); + DrawPausedInDebuggerMessage(); + DrawViewSize(); +} + +static std::unique_ptr<protocol::DictionaryValue> BuildObjectForSize( + const IntSize& size) { + std::unique_ptr<protocol::DictionaryValue> result = + protocol::DictionaryValue::create(); + result->setInteger("width", size.Width()); + result->setInteger("height", size.Height()); + return result; +} + +void InspectorOverlay::DrawNodeHighlight() { + if (!highlight_node_) + return; + + String selectors = node_highlight_config_.selector_list; + StaticElementList* elements = nullptr; + DummyExceptionStateForTesting exception_state; + ContainerNode* query_base = highlight_node_->ContainingShadowRoot(); + if (!query_base) + query_base = highlight_node_->ownerDocument(); + if (selectors.length()) + elements = + query_base->QuerySelectorAll(AtomicString(selectors), exception_state); + if (elements && !exception_state.HadException()) { + for (unsigned i = 0; i < elements->length(); ++i) { + Element* element = elements->item(i); + InspectorHighlight highlight(element, node_highlight_config_, false); + std::unique_ptr<protocol::DictionaryValue> highlight_json = + highlight.AsProtocolValue(); + EvaluateInOverlay("drawHighlight", std::move(highlight_json)); + } + } + + bool append_element_info = + highlight_node_->IsElementNode() && !omit_tooltip_ && + node_highlight_config_.show_info && highlight_node_->GetLayoutObject() && + highlight_node_->GetDocument().GetFrame(); + InspectorHighlight highlight(highlight_node_.Get(), node_highlight_config_, + append_element_info); + if (event_target_node_) + highlight.AppendEventTargetQuads(event_target_node_.Get(), + node_highlight_config_); + + std::unique_ptr<protocol::DictionaryValue> highlight_json = + highlight.AsProtocolValue(); + EvaluateInOverlay("drawHighlight", std::move(highlight_json)); +} + +void InspectorOverlay::DrawQuadHighlight() { + if (!highlight_quad_) + return; + + InspectorHighlight highlight(WindowToViewportScale()); + highlight.AppendQuad(*highlight_quad_, quad_highlight_config_.content, + quad_highlight_config_.content_outline); + EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); +} + +void InspectorOverlay::DrawPausedInDebuggerMessage() { + if (inspect_mode_ == InspectorDOMAgent::kNotSearching && + !paused_in_debugger_message_.IsNull()) + EvaluateInOverlay("drawPausedInDebuggerMessage", + paused_in_debugger_message_); +} + +void InspectorOverlay::DrawViewSize() { + if (resize_timer_active_ && draw_view_size_) + EvaluateInOverlay("drawViewSize", ""); +} + +float InspectorOverlay::WindowToViewportScale() const { + LocalFrame* frame = frame_impl_->GetFrame(); + if (!frame) + return 1.0f; + return frame->GetPage()->GetChromeClient().WindowToViewportScalar(1.0f); +} + +Page* InspectorOverlay::OverlayPage() { + if (overlay_page_) + return overlay_page_.Get(); + + ScriptForbiddenScope::AllowUserAgentScript allow_script; + + DEFINE_STATIC_LOCAL(LocalFrameClient, dummy_local_frame_client, + (EmptyLocalFrameClient::Create())); + Page::PageClients page_clients; + FillWithEmptyClients(page_clients); + DCHECK(!overlay_chrome_client_); + overlay_chrome_client_ = InspectorOverlayChromeClient::Create( + frame_impl_->GetFrame()->GetPage()->GetChromeClient(), *this); + page_clients.chrome_client = overlay_chrome_client_.Get(); + overlay_page_ = Page::Create(page_clients); + + Settings& settings = frame_impl_->GetFrame()->GetPage()->GetSettings(); + Settings& overlay_settings = overlay_page_->GetSettings(); + + overlay_settings.GetGenericFontFamilySettings().UpdateStandard( + settings.GetGenericFontFamilySettings().Standard()); + overlay_settings.GetGenericFontFamilySettings().UpdateSerif( + settings.GetGenericFontFamilySettings().Serif()); + overlay_settings.GetGenericFontFamilySettings().UpdateSansSerif( + settings.GetGenericFontFamilySettings().SansSerif()); + overlay_settings.GetGenericFontFamilySettings().UpdateCursive( + settings.GetGenericFontFamilySettings().Cursive()); + overlay_settings.GetGenericFontFamilySettings().UpdateFantasy( + settings.GetGenericFontFamilySettings().Fantasy()); + overlay_settings.GetGenericFontFamilySettings().UpdatePictograph( + settings.GetGenericFontFamilySettings().Pictograph()); + overlay_settings.SetMinimumFontSize(settings.GetMinimumFontSize()); + overlay_settings.SetMinimumLogicalFontSize( + settings.GetMinimumLogicalFontSize()); + overlay_settings.SetScriptEnabled(true); + overlay_settings.SetPluginsEnabled(false); + overlay_settings.SetLoadsImagesAutomatically(true); + // FIXME: http://crbug.com/363843. Inspector should probably create its + // own graphics layers and attach them to the tree rather than going + // through some non-composited paint function. + overlay_settings.SetAcceleratedCompositingEnabled(false); + + LocalFrame* frame = + LocalFrame::Create(&dummy_local_frame_client, *overlay_page_, 0); + frame->SetView(FrameView::Create(*frame)); + frame->Init(); + FrameLoader& loader = frame->Loader(); + frame->View()->SetCanHaveScrollbars(false); + frame->View()->SetBaseBackgroundColor(Color::kTransparent); + + const WebData& overlay_page_html_resource = + Platform::Current()->LoadResource("InspectorOverlayPage.html"); + loader.Load( + FrameLoadRequest(0, ResourceRequest(BlankURL()), + SubstituteData(overlay_page_html_resource, "text/html", + "UTF-8", KURL(), kForceSynchronousLoad))); + v8::Isolate* isolate = ToIsolate(frame); + ScriptState* script_state = ToScriptStateForMainWorld(frame); + DCHECK(script_state); + ScriptState::Scope scope(script_state); + v8::Local<v8::Object> global = script_state->GetContext()->Global(); + v8::Local<v8::Value> overlay_host_obj = + ToV8(overlay_host_.Get(), global, isolate); + DCHECK(!overlay_host_obj.IsEmpty()); + global + ->Set(script_state->GetContext(), + V8AtomicString(isolate, "InspectorOverlayHost"), overlay_host_obj) + .ToChecked(); + +#if OS(WIN) + EvaluateInOverlay("setPlatform", "windows"); +#elif OS(MACOSX) + EvaluateInOverlay("setPlatform", "mac"); +#elif OS(POSIX) + EvaluateInOverlay("setPlatform", "linux"); +#endif + + return overlay_page_.Get(); +} + +LocalFrame* InspectorOverlay::OverlayMainFrame() { + return ToLocalFrame(OverlayPage()->MainFrame()); +} + +void InspectorOverlay::Reset(const IntSize& viewport_size, + const IntPoint& document_scroll_offset) { + std::unique_ptr<protocol::DictionaryValue> reset_data = + protocol::DictionaryValue::create(); + reset_data->setDouble( + "deviceScaleFactor", + frame_impl_->GetFrame()->GetPage()->DeviceScaleFactorDeprecated()); + reset_data->setDouble( + "pageScaleFactor", + frame_impl_->GetFrame()->GetPage()->GetVisualViewport().Scale()); + + IntRect viewport_in_screen = + frame_impl_->GetFrame()->GetPage()->GetChromeClient().ViewportToScreen( + IntRect(IntPoint(), viewport_size), frame_impl_->GetFrame()->View()); + reset_data->setObject("viewportSize", + BuildObjectForSize(viewport_in_screen.Size())); + + // The zoom factor in the overlay frame already has been multiplied by the + // window to viewport scale (aka device scale factor), so cancel it. + reset_data->setDouble( + "pageZoomFactor", + frame_impl_->GetFrame()->PageZoomFactor() / WindowToViewportScale()); + + reset_data->setInteger("scrollX", document_scroll_offset.X()); + reset_data->setInteger("scrollY", document_scroll_offset.Y()); + EvaluateInOverlay("reset", std::move(reset_data)); +} + +void InspectorOverlay::EvaluateInOverlay(const String& method, + const String& argument) { + ScriptForbiddenScope::AllowUserAgentScript allow_script; + std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); + command->pushValue(protocol::StringValue::create(method)); + command->pushValue(protocol::StringValue::create(argument)); + ToLocalFrame(OverlayPage()->MainFrame()) + ->GetScriptController() + .ExecuteScriptInMainWorld( + "dispatch(" + command->serialize() + ")", + ScriptController::kExecuteScriptWhenScriptsDisabled); +} + +void InspectorOverlay::EvaluateInOverlay( + const String& method, + std::unique_ptr<protocol::Value> argument) { + ScriptForbiddenScope::AllowUserAgentScript allow_script; + std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); + command->pushValue(protocol::StringValue::create(method)); + command->pushValue(std::move(argument)); + ToLocalFrame(OverlayPage()->MainFrame()) + ->GetScriptController() + .ExecuteScriptInMainWorld( + "dispatch(" + command->serialize() + ")", + ScriptController::kExecuteScriptWhenScriptsDisabled); +} + +String InspectorOverlay::EvaluateInOverlayForTest(const String& script) { + ScriptForbiddenScope::AllowUserAgentScript allow_script; + v8::HandleScope handle_scope(ToIsolate(OverlayMainFrame())); + v8::Local<v8::Value> string = + ToLocalFrame(OverlayPage()->MainFrame()) + ->GetScriptController() + .ExecuteScriptInMainWorldAndReturnValue( + ScriptSourceCode(script), + ScriptController::kExecuteScriptWhenScriptsDisabled); + return ToCoreStringWithUndefinedOrNullCheck(string); +} + +void InspectorOverlay::OnTimer(TimerBase*) { + resize_timer_active_ = false; + ScheduleUpdate(); +} + +void InspectorOverlay::ClearInternal() { + if (overlay_page_) { + overlay_page_->WillBeDestroyed(); + overlay_page_.Clear(); + overlay_chrome_client_.Clear(); + } + resize_timer_active_ = false; + paused_in_debugger_message_ = String(); + inspect_mode_ = InspectorDOMAgent::kNotSearching; + timer_.Stop(); + HideHighlight(); +} + +void InspectorOverlay::Clear() { + ClearInternal(); + v8_session_ = nullptr; + dom_agent_.Clear(); + overlay_host_->SetListener(nullptr); +} + +void InspectorOverlay::OverlayResumed() { + if (v8_session_) + v8_session_->resume(); +} + +void InspectorOverlay::OverlaySteppedOver() { + if (v8_session_) + v8_session_->stepOver(); +} + +void InspectorOverlay::Suspend() { + if (!suspended_) { + suspended_ = true; + ClearInternal(); + } +} + +void InspectorOverlay::Resume() { + suspended_ = false; +} + +void InspectorOverlay::PageLayoutInvalidated(bool resized) { + if (resized && draw_view_size_) { + resize_timer_active_ = true; + timer_.StartOneShot(1, BLINK_FROM_HERE); + } + ScheduleUpdate(); +} + +void InspectorOverlay::SetShowViewportSizeOnResize(bool show) { + draw_view_size_ = show; +} + +bool InspectorOverlay::HandleMouseMove(const WebMouseEvent& event) { + if (!ShouldSearchForNode()) + return false; + + LocalFrame* frame = frame_impl_->GetFrame(); + if (!frame || !frame->View() || frame->ContentLayoutItem().IsNull()) + return false; + Node* node = HoveredNodeForEvent( + frame, event, event.GetModifiers() & WebInputEvent::kShiftKey); + + // Do not highlight within user agent shadow root unless requested. + if (inspect_mode_ != InspectorDOMAgent::kSearchingForUAShadow) { + ShadowRoot* shadow_root = InspectorDOMAgent::UserAgentShadowRoot(node); + if (shadow_root) + node = &shadow_root->host(); + } + + // Shadow roots don't have boxes - use host element instead. + if (node && node->IsShadowRoot()) + node = node->ParentOrShadowHostNode(); + + if (!node) + return true; + + if (node->IsFrameOwnerElement()) { + HTMLFrameOwnerElement* frame_owner = ToHTMLFrameOwnerElement(node); + if (frame_owner->ContentFrame() && + !frame_owner->ContentFrame()->IsLocalFrame()) { + // Do not consume event so that remote frame can handle it. + HideHighlight(); + hovered_node_for_inspect_mode_.Clear(); + return false; + } + } + + Node* event_target = (event.GetModifiers() & WebInputEvent::kShiftKey) + ? HoveredNodeForEvent(frame, event, false) + : nullptr; + if (event_target == node) + event_target = nullptr; + + if (node && inspect_mode_highlight_config_) { + hovered_node_for_inspect_mode_ = node; + if (dom_agent_) + dom_agent_->NodeHighlightedInOverlay(node); + HighlightNode(node, event_target, *inspect_mode_highlight_config_, + (event.GetModifiers() & + (WebInputEvent::kControlKey | WebInputEvent::kMetaKey))); + } + return true; +} + +bool InspectorOverlay::HandleMouseDown() { + swallow_next_mouse_up_ = false; + if (!ShouldSearchForNode()) + return false; + + if (hovered_node_for_inspect_mode_) { + swallow_next_mouse_up_ = true; + Inspect(hovered_node_for_inspect_mode_.Get()); + hovered_node_for_inspect_mode_.Clear(); + return true; + } + return false; +} + +bool InspectorOverlay::HandleMouseUp() { + if (swallow_next_mouse_up_) { + swallow_next_mouse_up_ = false; + return true; + } + return false; +} + +bool InspectorOverlay::HandleGestureEvent(const WebGestureEvent& event) { + if (!ShouldSearchForNode() || event.GetType() != WebInputEvent::kGestureTap) + return false; + Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); + if (node && inspect_mode_highlight_config_) { + HighlightNode(node, *inspect_mode_highlight_config_, false); + Inspect(node); + return true; + } + return false; +} + +bool InspectorOverlay::HandleTouchEvent(const WebTouchEvent& event) { + if (!ShouldSearchForNode()) + return false; + Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); + if (node && inspect_mode_highlight_config_) { + HighlightNode(node, *inspect_mode_highlight_config_, false); + Inspect(node); + return true; + } + return false; +} + +bool InspectorOverlay::ShouldSearchForNode() { + return inspect_mode_ != InspectorDOMAgent::kNotSearching; +} + +void InspectorOverlay::Inspect(Node* node) { + if (dom_agent_) + dom_agent_->Inspect(node); +} + +} // namespace blink
diff --git a/third_party/WebKit/Source/web/InspectorOverlay.h b/third_party/WebKit/Source/web/InspectorOverlay.h new file mode 100644 index 0000000..6cc0a65 --- /dev/null +++ b/third_party/WebKit/Source/web/InspectorOverlay.h
@@ -0,0 +1,171 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InspectorOverlay_h +#define InspectorOverlay_h + +#include <v8-inspector.h> +#include <memory> +#include "core/inspector/InspectorDOMAgent.h" +#include "core/inspector/InspectorOverlayHost.h" +#include "core/inspector/protocol/Forward.h" +#include "platform/Timer.h" +#include "platform/geometry/FloatQuad.h" +#include "platform/geometry/LayoutRect.h" +#include "platform/graphics/Color.h" +#include "platform/heap/Handle.h" +#include "platform/wtf/RefPtr.h" +#include "platform/wtf/text/WTFString.h" +#include "public/platform/WebInputEvent.h" + +namespace blink { + +class Color; +class LocalFrame; +class Node; +class Page; +class PageOverlay; +class WebGestureEvent; +class WebMouseEvent; +class WebLocalFrameImpl; +class WebTouchEvent; + +namespace protocol { +class Value; +} + +class InspectorOverlay final + : public GarbageCollectedFinalized<InspectorOverlay>, + public InspectorDOMAgent::Client, + public InspectorOverlayHost::Listener { + USING_GARBAGE_COLLECTED_MIXIN(InspectorOverlay); + + public: + explicit InspectorOverlay(WebLocalFrameImpl*); + ~InspectorOverlay() override; + DECLARE_TRACE(); + + void Init(v8_inspector::V8InspectorSession*, InspectorDOMAgent*); + + void Clear(); + void Suspend(); + void Resume(); + bool HandleInputEvent(const WebInputEvent&); + void PageLayoutInvalidated(bool resized); + void SetShowViewportSizeOnResize(bool); + void ShowReloadingBlanket(); + void HideReloadingBlanket(); + void SetPausedInDebuggerMessage(const String&); + + // Does not yet include paint. + void UpdateAllLifecyclePhases(); + + PageOverlay* GetPageOverlay() { return page_overlay_.get(); }; + String EvaluateInOverlayForTest(const String&); + + private: + class InspectorOverlayChromeClient; + class InspectorPageOverlayDelegate; + + // InspectorOverlayHost::Listener implementation. + void OverlayResumed() override; + void OverlaySteppedOver() override; + + // InspectorDOMAgent::Client implementation. + void HideHighlight() override; + void HighlightNode(Node*, + const InspectorHighlightConfig&, + bool omit_tooltip) override; + void HighlightQuad(std::unique_ptr<FloatQuad>, + const InspectorHighlightConfig&) override; + void SetInspectMode(InspectorDOMAgent::SearchMode, + std::unique_ptr<InspectorHighlightConfig>) override; + + void HighlightNode(Node*, + Node* event_target, + const InspectorHighlightConfig&, + bool omit_tooltip); + bool IsEmpty(); + void DrawNodeHighlight(); + void DrawQuadHighlight(); + void DrawPausedInDebuggerMessage(); + void DrawViewSize(); + + float WindowToViewportScale() const; + + Page* OverlayPage(); + LocalFrame* OverlayMainFrame(); + void Reset(const IntSize& viewport_size, + const IntPoint& document_scroll_offset); + void EvaluateInOverlay(const String& method, const String& argument); + void EvaluateInOverlay(const String& method, + std::unique_ptr<protocol::Value> argument); + void OnTimer(TimerBase*); + void RebuildOverlayPage(); + void Invalidate(); + void ScheduleUpdate(); + void ClearInternal(); + + bool HandleMouseDown(); + bool HandleMouseUp(); + bool HandleGestureEvent(const WebGestureEvent&); + bool HandleTouchEvent(const WebTouchEvent&); + bool HandleMouseMove(const WebMouseEvent&); + bool ShouldSearchForNode(); + void Inspect(Node*); + + Member<WebLocalFrameImpl> frame_impl_; + String paused_in_debugger_message_; + Member<Node> highlight_node_; + Member<Node> event_target_node_; + InspectorHighlightConfig node_highlight_config_; + std::unique_ptr<FloatQuad> highlight_quad_; + Member<Page> overlay_page_; + Member<InspectorOverlayChromeClient> overlay_chrome_client_; + Member<InspectorOverlayHost> overlay_host_; + InspectorHighlightConfig quad_highlight_config_; + bool draw_view_size_; + bool resize_timer_active_; + bool omit_tooltip_; + TaskRunnerTimer<InspectorOverlay> timer_; + bool suspended_; + bool show_reloading_blanket_; + bool in_layout_; + bool needs_update_; + v8_inspector::V8InspectorSession* v8_session_; + Member<InspectorDOMAgent> dom_agent_; + std::unique_ptr<PageOverlay> page_overlay_; + Member<Node> hovered_node_for_inspect_mode_; + bool swallow_next_mouse_up_; + InspectorDOMAgent::SearchMode inspect_mode_; + std::unique_ptr<InspectorHighlightConfig> inspect_mode_highlight_config_; +}; + +} // namespace blink + +#endif // InspectorOverlay_h
diff --git a/third_party/WebKit/Source/web/InspectorOverlayAgent.cpp b/third_party/WebKit/Source/web/InspectorOverlayAgent.cpp deleted file mode 100644 index e5ad62d..0000000 --- a/third_party/WebKit/Source/web/InspectorOverlayAgent.cpp +++ /dev/null
@@ -1,1162 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "web/InspectorOverlayAgent.h" - -#include <memory> - -#include "bindings/core/v8/ScriptController.h" -#include "bindings/core/v8/ScriptSourceCode.h" -#include "bindings/core/v8/V8Binding.h" -#include "bindings/core/v8/V8InspectorOverlayHost.h" -#include "core/dom/DOMNodeIds.h" -#include "core/dom/Node.h" -#include "core/dom/StaticNodeList.h" -#include "core/dom/TaskRunnerHelper.h" -#include "core/frame/FrameView.h" -#include "core/frame/LocalFrame.h" -#include "core/frame/LocalFrameClient.h" -#include "core/frame/Settings.h" -#include "core/frame/VisualViewport.h" -#include "core/html/HTMLFrameOwnerElement.h" -#include "core/input/EventHandler.h" -#include "core/inspector/IdentifiersFactory.h" -#include "core/inspector/InspectedFrames.h" -#include "core/inspector/InspectorDOMAgent.h" -#include "core/inspector/InspectorOverlayHost.h" -#include "core/layout/api/LayoutViewItem.h" -#include "core/loader/EmptyClients.h" -#include "core/loader/FrameLoadRequest.h" -#include "core/page/ChromeClient.h" -#include "core/page/Page.h" -#include "platform/ScriptForbiddenScope.h" -#include "platform/graphics/Color.h" -#include "platform/graphics/GraphicsContext.h" -#include "platform/graphics/paint/CullRect.h" -#include "platform/wtf/AutoReset.h" -#include "public/platform/Platform.h" -#include "public/platform/WebData.h" -#include "v8/include/v8.h" -#include "web/ChromeClientImpl.h" -#include "web/PageOverlay.h" -#include "web/WebInputEventConversion.h" -#include "web/WebLocalFrameImpl.h" -#include "web/WebViewImpl.h" - -namespace blink { - -using protocol::Maybe; -using protocol::Response; - -namespace { - -namespace OverlayAgentState { -static const char kEnabled[] = "enabled"; -static const char kShowDebugBorders[] = "showDebugBorders"; -static const char kShowFPSCounter[] = "showFPSCounter"; -static const char kShowPaintRects[] = "showPaintRects"; -static const char kShowScrollBottleneckRects[] = "showScrollBottleneckRects"; -static const char kShowSizeOnResize[] = "showSizeOnResize"; -static const char kSuspended[] = "suspended"; -static const char kPausedInDebuggerMessage[] = "pausedInDebuggerMessage"; -} - -Node* HoveredNodeForPoint(LocalFrame* frame, - const IntPoint& point_in_root_frame, - bool ignore_pointer_events_none) { - HitTestRequest::HitTestRequestType hit_type = - HitTestRequest::kMove | HitTestRequest::kReadOnly | - HitTestRequest::kAllowChildFrameContent; - if (ignore_pointer_events_none) - hit_type |= HitTestRequest::kIgnorePointerEventsNone; - HitTestRequest request(hit_type); - HitTestResult result(request, - frame->View()->RootFrameToContents(point_in_root_frame)); - frame->ContentLayoutItem().HitTest(result); - Node* node = result.InnerPossiblyPseudoNode(); - while (node && node->getNodeType() == Node::kTextNode) - node = node->parentNode(); - return node; -} - -Node* HoveredNodeForEvent(LocalFrame* frame, - const WebGestureEvent& event, - bool ignore_pointer_events_none) { - return HoveredNodeForPoint(frame, - RoundedIntPoint(event.PositionInRootFrame()), - ignore_pointer_events_none); -} - -Node* HoveredNodeForEvent(LocalFrame* frame, - const WebMouseEvent& event, - bool ignore_pointer_events_none) { - return HoveredNodeForPoint(frame, - RoundedIntPoint(event.PositionInRootFrame()), - ignore_pointer_events_none); -} - -Node* HoveredNodeForEvent(LocalFrame* frame, - const WebTouchEvent& event, - bool ignore_pointer_events_none) { - if (!event.touches_length) - return nullptr; - WebTouchPoint transformed_point = event.TouchPointInRootFrame(0); - return HoveredNodeForPoint(frame, RoundedIntPoint(transformed_point.position), - ignore_pointer_events_none); -} - -bool ParseQuad(std::unique_ptr<protocol::Array<double>> quad_array, - FloatQuad* quad) { - const size_t kCoordinatesInQuad = 8; - if (!quad_array || quad_array->length() != kCoordinatesInQuad) - return false; - quad->SetP1(FloatPoint(quad_array->get(0), quad_array->get(1))); - quad->SetP2(FloatPoint(quad_array->get(2), quad_array->get(3))); - quad->SetP3(FloatPoint(quad_array->get(4), quad_array->get(5))); - quad->SetP4(FloatPoint(quad_array->get(6), quad_array->get(7))); - return true; -} - -} // namespace - -class InspectorOverlayAgent::InspectorPageOverlayDelegate final - : public PageOverlay::Delegate { - public: - explicit InspectorPageOverlayDelegate(InspectorOverlayAgent& overlay) - : overlay_(&overlay) {} - - void PaintPageOverlay(const PageOverlay&, - GraphicsContext& graphics_context, - const WebSize& web_view_size) const override { - if (overlay_->IsEmpty()) - return; - - FrameView* view = overlay_->OverlayMainFrame()->View(); - DCHECK(!view->NeedsLayout()); - view->Paint(graphics_context, - CullRect(IntRect(0, 0, view->Width(), view->Height()))); - } - - private: - Persistent<InspectorOverlayAgent> overlay_; -}; - -class InspectorOverlayAgent::InspectorOverlayChromeClient final - : public EmptyChromeClient { - public: - static InspectorOverlayChromeClient* Create(ChromeClient& client, - InspectorOverlayAgent& overlay) { - return new InspectorOverlayChromeClient(client, overlay); - } - - DEFINE_INLINE_VIRTUAL_TRACE() { - visitor->Trace(client_); - visitor->Trace(overlay_); - EmptyChromeClient::Trace(visitor); - } - - void SetCursor(const Cursor& cursor, LocalFrame* local_root) override { - ToChromeClientImpl(client_)->SetCursorOverridden(false); - ToChromeClientImpl(client_)->SetCursor(cursor, - overlay_->frame_impl_->GetFrame()); - ToChromeClientImpl(client_)->SetCursorOverridden(false); - } - - void SetToolTip(LocalFrame& frame, - const String& tooltip, - TextDirection direction) override { - DCHECK_EQ(&frame, overlay_->OverlayMainFrame()); - client_->SetToolTip(*overlay_->frame_impl_->GetFrame(), tooltip, direction); - } - - void InvalidateRect(const IntRect&) override { overlay_->Invalidate(); } - - void ScheduleAnimation(LocalFrame* frame) override { - if (overlay_->in_layout_) - return; - - client_->ScheduleAnimation(frame); - } - - private: - InspectorOverlayChromeClient(ChromeClient& client, - InspectorOverlayAgent& overlay) - : client_(&client), overlay_(&overlay) {} - - Member<ChromeClient> client_; - Member<InspectorOverlayAgent> overlay_; -}; - -InspectorOverlayAgent::InspectorOverlayAgent( - WebLocalFrameImpl* frame_impl, - InspectedFrames* inspected_frames, - v8_inspector::V8InspectorSession* v8_session, - InspectorDOMAgent* dom_agent) - : frame_impl_(frame_impl), - inspected_frames_(inspected_frames), - enabled_(false), - overlay_host_(new InspectorOverlayHost(this)), - draw_view_size_(false), - resize_timer_active_(false), - omit_tooltip_(false), - timer_(TaskRunnerHelper::Get(TaskType::kUnspecedTimer, - frame_impl->GetFrame()), - this, - &InspectorOverlayAgent::OnTimer), - suspended_(false), - show_reloading_blanket_(false), - in_layout_(false), - needs_update_(false), - v8_session_(v8_session), - dom_agent_(dom_agent), - swallow_next_mouse_up_(false), - inspect_mode_(kNotSearching), - backend_node_id_to_inspect_(0) {} - -InspectorOverlayAgent::~InspectorOverlayAgent() { - DCHECK(!overlay_page_); -} - -DEFINE_TRACE(InspectorOverlayAgent) { - visitor->Trace(frame_impl_); - visitor->Trace(inspected_frames_); - visitor->Trace(highlight_node_); - visitor->Trace(event_target_node_); - visitor->Trace(overlay_page_); - visitor->Trace(overlay_chrome_client_); - visitor->Trace(overlay_host_); - visitor->Trace(dom_agent_); - visitor->Trace(hovered_node_for_inspect_mode_); - InspectorBaseAgent::Trace(visitor); -} - -void InspectorOverlayAgent::Restore() { - if (state_->booleanProperty(OverlayAgentState::kEnabled, false)) - enabled_ = true; - setShowDebugBorders( - state_->booleanProperty(OverlayAgentState::kShowDebugBorders, false)); - setShowFPSCounter( - state_->booleanProperty(OverlayAgentState::kShowFPSCounter, false)); - setShowPaintRects( - state_->booleanProperty(OverlayAgentState::kShowPaintRects, false)); - setShowScrollBottleneckRects(state_->booleanProperty( - OverlayAgentState::kShowScrollBottleneckRects, false)); - setShowViewportSizeOnResize( - state_->booleanProperty(OverlayAgentState::kShowSizeOnResize, false)); - String message; - state_->getString(OverlayAgentState::kPausedInDebuggerMessage, &message); - setPausedInDebuggerMessage(message); - setSuspended(state_->booleanProperty(OverlayAgentState::kSuspended, false)); -} - -void InspectorOverlayAgent::Dispose() { - show_reloading_blanket_ = false; - ClearInternal(); - InspectorBaseAgent::Dispose(); -} - -Response InspectorOverlayAgent::enable() { - if (!dom_agent_->Enabled()) - return Response::Error("DOM should be enabled first"); - state_->setBoolean(OverlayAgentState::kEnabled, true); - enabled_ = true; - if (backend_node_id_to_inspect_) - GetFrontend()->inspectNodeRequested(backend_node_id_to_inspect_); - backend_node_id_to_inspect_ = 0; - return Response::OK(); -} - -Response InspectorOverlayAgent::disable() { - state_->setBoolean(OverlayAgentState::kEnabled, false); - enabled_ = false; - setShowDebugBorders(false); - setShowFPSCounter(false); - setShowPaintRects(false); - setShowScrollBottleneckRects(false); - setShowViewportSizeOnResize(false); - setPausedInDebuggerMessage(String()); - setSuspended(false); - SetSearchingForNode(kNotSearching, - Maybe<protocol::Overlay::HighlightConfig>()); - return Response::OK(); -} - -Response InspectorOverlayAgent::setShowDebugBorders(bool show) { - state_->setBoolean(OverlayAgentState::kShowDebugBorders, show); - if (show) { - Response response = CompositingEnabled(); - if (!response.isSuccess()) - return response; - } - frame_impl_->ViewImpl()->SetShowDebugBorders(show); - return Response::OK(); -} - -Response InspectorOverlayAgent::setShowFPSCounter(bool show) { - state_->setBoolean(OverlayAgentState::kShowFPSCounter, show); - if (show) { - Response response = CompositingEnabled(); - if (!response.isSuccess()) - return response; - } - frame_impl_->ViewImpl()->SetShowFPSCounter(show); - return Response::OK(); -} - -Response InspectorOverlayAgent::setShowPaintRects(bool show) { - state_->setBoolean(OverlayAgentState::kShowPaintRects, show); - if (show) { - Response response = CompositingEnabled(); - if (!response.isSuccess()) - return response; - } - frame_impl_->ViewImpl()->SetShowPaintRects(show); - if (!show && frame_impl_->GetFrameView()) - frame_impl_->GetFrameView()->Invalidate(); - return Response::OK(); -} - -Response InspectorOverlayAgent::setShowScrollBottleneckRects(bool show) { - state_->setBoolean(OverlayAgentState::kShowScrollBottleneckRects, show); - if (show) { - Response response = CompositingEnabled(); - if (!response.isSuccess()) - return response; - } - frame_impl_->ViewImpl()->SetShowScrollBottleneckRects(show); - return Response::OK(); -} - -Response InspectorOverlayAgent::setShowViewportSizeOnResize(bool show) { - state_->setBoolean(OverlayAgentState::kShowSizeOnResize, show); - draw_view_size_ = show; - return Response::OK(); -} - -Response InspectorOverlayAgent::setPausedInDebuggerMessage( - Maybe<String> message) { - String just_message = message.fromMaybe(String()); - state_->setString(OverlayAgentState::kPausedInDebuggerMessage, just_message); - paused_in_debugger_message_ = just_message; - ScheduleUpdate(); - return Response::OK(); -} - -Response InspectorOverlayAgent::setSuspended(bool suspended) { - state_->setBoolean(OverlayAgentState::kSuspended, suspended); - if (suspended && !suspended_ && !show_reloading_blanket_) - ClearInternal(); - suspended_ = suspended; - return Response::OK(); -} - -Response InspectorOverlayAgent::setInspectMode( - const String& mode, - Maybe<protocol::Overlay::HighlightConfig> highlight_config) { - SearchMode search_mode; - if (mode == protocol::Overlay::InspectModeEnum::SearchForNode) { - search_mode = kSearchingForNormal; - } else if (mode == protocol::Overlay::InspectModeEnum::SearchForUAShadowDOM) { - search_mode = kSearchingForUAShadow; - } else if (mode == protocol::Overlay::InspectModeEnum::None) { - search_mode = kNotSearching; - } else { - return Response::Error( - String("Unknown mode \"" + mode + "\" was provided.")); - } - - if (search_mode != kNotSearching) { - Response response = dom_agent_->PushDocumentUponHandlelessOperation(); - if (!response.isSuccess()) - return response; - } - - return SetSearchingForNode(search_mode, std::move(highlight_config)); -} - -Response InspectorOverlayAgent::highlightRect( - int x, - int y, - int width, - int height, - Maybe<protocol::DOM::RGBA> color, - Maybe<protocol::DOM::RGBA> outline_color) { - std::unique_ptr<FloatQuad> quad = - WTF::WrapUnique(new FloatQuad(FloatRect(x, y, width, height))); - InnerHighlightQuad(std::move(quad), std::move(color), - std::move(outline_color)); - return Response::OK(); -} - -Response InspectorOverlayAgent::highlightQuad( - std::unique_ptr<protocol::Array<double>> quad_array, - Maybe<protocol::DOM::RGBA> color, - Maybe<protocol::DOM::RGBA> outline_color) { - std::unique_ptr<FloatQuad> quad = WTF::MakeUnique<FloatQuad>(); - if (!ParseQuad(std::move(quad_array), quad.get())) - return Response::Error("Invalid Quad format"); - InnerHighlightQuad(std::move(quad), std::move(color), - std::move(outline_color)); - return Response::OK(); -} - -Response InspectorOverlayAgent::highlightNode( - std::unique_ptr<protocol::Overlay::HighlightConfig> - highlight_inspector_object, - Maybe<int> node_id, - Maybe<int> backend_node_id, - Maybe<String> object_id) { - Node* node = nullptr; - Response response; - if (node_id.isJust()) { - response = dom_agent_->AssertNode(node_id.fromJust(), node); - } else if (backend_node_id.isJust()) { - node = DOMNodeIds::NodeForId(backend_node_id.fromJust()); - response = !node ? Response::Error("No node found for given backend id") - : Response::OK(); - } else if (object_id.isJust()) { - response = dom_agent_->NodeForRemoteObjectId(object_id.fromJust(), node); - } else { - response = Response::Error( - "Either nodeId, backendNodeId or objectId must be specified"); - } - - if (!response.isSuccess()) - return response; - - std::unique_ptr<InspectorHighlightConfig> highlight_config; - response = HighlightConfigFromInspectorObject( - std::move(highlight_inspector_object), &highlight_config); - if (!response.isSuccess()) - return response; - - InnerHighlightNode(node, nullptr, *highlight_config, false); - return Response::OK(); -} - -Response InspectorOverlayAgent::highlightFrame( - const String& frame_id, - Maybe<protocol::DOM::RGBA> color, - Maybe<protocol::DOM::RGBA> outline_color) { - LocalFrame* frame = - IdentifiersFactory::FrameById(inspected_frames_, frame_id); - // FIXME: Inspector doesn't currently work cross process. - if (frame && frame->DeprecatedLocalOwner()) { - std::unique_ptr<InspectorHighlightConfig> highlight_config = - WTF::MakeUnique<InspectorHighlightConfig>(); - highlight_config->show_info = true; // Always show tooltips for frames. - highlight_config->content = - InspectorDOMAgent::ParseColor(color.fromMaybe(nullptr)); - highlight_config->content_outline = - InspectorDOMAgent::ParseColor(outline_color.fromMaybe(nullptr)); - InnerHighlightNode(frame->DeprecatedLocalOwner(), nullptr, - *highlight_config, false); - } - return Response::OK(); -} - -Response InspectorOverlayAgent::hideHighlight() { - InnerHideHighlight(); - return Response::OK(); -} - -Response InspectorOverlayAgent::getHighlightObjectForTest( - int node_id, - std::unique_ptr<protocol::DictionaryValue>* result) { - Node* node = nullptr; - Response response = dom_agent_->AssertNode(node_id, node); - if (!response.isSuccess()) - return response; - InspectorHighlight highlight(node, InspectorHighlight::DefaultConfig(), true); - *result = highlight.AsProtocolValue(); - return Response::OK(); -} - -void InspectorOverlayAgent::Invalidate() { - if (!page_overlay_) { - page_overlay_ = PageOverlay::Create( - frame_impl_, WTF::WrapUnique(new InspectorPageOverlayDelegate(*this))); - } - - page_overlay_->Update(); -} - -void InspectorOverlayAgent::UpdateAllLifecyclePhases() { - if (IsEmpty()) - return; - - AutoReset<bool> scoped(&in_layout_, true); - if (needs_update_) { - needs_update_ = false; - RebuildOverlayPage(); - } - OverlayMainFrame()->View()->UpdateAllLifecyclePhases(); -} - -bool InspectorOverlayAgent::HandleInputEvent(const WebInputEvent& input_event) { - bool handled = false; - - if (IsEmpty()) - return false; - - if (input_event.GetType() == WebInputEvent::kGestureTap) { - // We only have a use for gesture tap. - WebGestureEvent transformed_event = TransformWebGestureEvent( - frame_impl_->GetFrameView(), - static_cast<const WebGestureEvent&>(input_event)); - handled = HandleGestureEvent(transformed_event); - if (handled) - return true; - - OverlayMainFrame()->GetEventHandler().HandleGestureEvent(transformed_event); - } - if (WebInputEvent::IsMouseEventType(input_event.GetType())) { - WebMouseEvent mouse_event = - TransformWebMouseEvent(frame_impl_->GetFrameView(), - static_cast<const WebMouseEvent&>(input_event)); - - if (mouse_event.GetType() == WebInputEvent::kMouseMove) - handled = HandleMouseMove(mouse_event); - else if (mouse_event.GetType() == WebInputEvent::kMouseDown) - handled = HandleMouseDown(); - else if (mouse_event.GetType() == WebInputEvent::kMouseUp) - handled = HandleMouseUp(); - - if (handled) - return true; - - if (mouse_event.GetType() == WebInputEvent::kMouseMove) { - handled = OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( - mouse_event, TransformWebMouseEventVector( - frame_impl_->GetFrameView(), - std::vector<const WebInputEvent*>())) != - WebInputEventResult::kNotHandled; - } - if (mouse_event.GetType() == WebInputEvent::kMouseDown) { - handled = OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( - mouse_event) != WebInputEventResult::kNotHandled; - } - if (mouse_event.GetType() == WebInputEvent::kMouseUp) { - handled = OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( - mouse_event) != WebInputEventResult::kNotHandled; - } - } - - if (WebInputEvent::IsTouchEventType(input_event.GetType())) { - WebTouchEvent transformed_event = - TransformWebTouchEvent(frame_impl_->GetFrameView(), - static_cast<const WebTouchEvent&>(input_event)); - handled = HandleTouchEvent(transformed_event); - if (handled) - return true; - OverlayMainFrame()->GetEventHandler().HandleTouchEvent( - transformed_event, Vector<WebTouchEvent>()); - } - if (WebInputEvent::IsKeyboardEventType(input_event.GetType())) { - OverlayMainFrame()->GetEventHandler().KeyEvent( - static_cast<const WebKeyboardEvent&>(input_event)); - } - - if (input_event.GetType() == WebInputEvent::kMouseWheel) { - WebMouseWheelEvent transformed_event = TransformWebMouseWheelEvent( - frame_impl_->GetFrameView(), - static_cast<const WebMouseWheelEvent&>(input_event)); - handled = OverlayMainFrame()->GetEventHandler().HandleWheelEvent( - transformed_event) != WebInputEventResult::kNotHandled; - } - - return handled; -} - -void InspectorOverlayAgent::ShowReloadingBlanket() { - show_reloading_blanket_ = true; - ScheduleUpdate(); -} - -void InspectorOverlayAgent::HideReloadingBlanket() { - if (!show_reloading_blanket_) - return; - show_reloading_blanket_ = false; - if (suspended_) - ClearInternal(); - else - ScheduleUpdate(); -} - -void InspectorOverlayAgent::InnerHideHighlight() { - highlight_node_.Clear(); - event_target_node_.Clear(); - highlight_quad_.reset(); - ScheduleUpdate(); -} - -void InspectorOverlayAgent::InnerHighlightNode( - Node* node, - Node* event_target, - const InspectorHighlightConfig& highlight_config, - bool omit_tooltip) { - node_highlight_config_ = highlight_config; - highlight_node_ = node; - event_target_node_ = event_target; - omit_tooltip_ = omit_tooltip; - ScheduleUpdate(); -} - -void InspectorOverlayAgent::InnerHighlightQuad( - std::unique_ptr<FloatQuad> quad, - Maybe<protocol::DOM::RGBA> color, - Maybe<protocol::DOM::RGBA> outline_color) { - quad_content_color_ = InspectorDOMAgent::ParseColor(color.fromMaybe(nullptr)); - quad_content_outline_color_ = - InspectorDOMAgent::ParseColor(outline_color.fromMaybe(nullptr)); - highlight_quad_ = std::move(quad); - omit_tooltip_ = false; - ScheduleUpdate(); -} - -bool InspectorOverlayAgent::IsEmpty() { - if (show_reloading_blanket_) - return false; - if (suspended_) - return true; - bool has_visible_elements = highlight_node_ || event_target_node_ || - highlight_quad_ || - (resize_timer_active_ && draw_view_size_) || - !paused_in_debugger_message_.IsNull(); - return !has_visible_elements && inspect_mode_ == kNotSearching; -} - -void InspectorOverlayAgent::ScheduleUpdate() { - if (IsEmpty()) { - if (page_overlay_) - page_overlay_.reset(); - return; - } - needs_update_ = true; - LocalFrame* frame = frame_impl_->GetFrame(); - if (frame) { - frame->GetPage()->GetChromeClient().ScheduleAnimation(frame); - } -} - -void InspectorOverlayAgent::RebuildOverlayPage() { - FrameView* view = frame_impl_->GetFrameView(); - LocalFrame* frame = frame_impl_->GetFrame(); - if (!view || !frame) - return; - - IntRect visible_rect_in_document = - view->GetScrollableArea()->VisibleContentRect(); - IntSize viewport_size = frame->GetPage()->GetVisualViewport().Size(); - OverlayMainFrame()->View()->Resize(viewport_size); - OverlayPage()->GetVisualViewport().SetSize(viewport_size); - OverlayMainFrame()->SetPageZoomFactor(WindowToViewportScale()); - - Reset(viewport_size, visible_rect_in_document.Location()); - - if (show_reloading_blanket_) { - EvaluateInOverlay("showReloadingBlanket", ""); - return; - } - DrawNodeHighlight(); - DrawQuadHighlight(); - DrawPausedInDebuggerMessage(); - DrawViewSize(); -} - -static std::unique_ptr<protocol::DictionaryValue> BuildObjectForSize( - const IntSize& size) { - std::unique_ptr<protocol::DictionaryValue> result = - protocol::DictionaryValue::create(); - result->setInteger("width", size.Width()); - result->setInteger("height", size.Height()); - return result; -} - -void InspectorOverlayAgent::DrawNodeHighlight() { - if (!highlight_node_) - return; - - String selectors = node_highlight_config_.selector_list; - StaticElementList* elements = nullptr; - DummyExceptionStateForTesting exception_state; - ContainerNode* query_base = highlight_node_->ContainingShadowRoot(); - if (!query_base) - query_base = highlight_node_->ownerDocument(); - if (selectors.length()) { - elements = - query_base->QuerySelectorAll(AtomicString(selectors), exception_state); - } - if (elements && !exception_state.HadException()) { - for (unsigned i = 0; i < elements->length(); ++i) { - Element* element = elements->item(i); - InspectorHighlight highlight(element, node_highlight_config_, false); - std::unique_ptr<protocol::DictionaryValue> highlight_json = - highlight.AsProtocolValue(); - EvaluateInOverlay("drawHighlight", std::move(highlight_json)); - } - } - - bool append_element_info = - highlight_node_->IsElementNode() && !omit_tooltip_ && - node_highlight_config_.show_info && highlight_node_->GetLayoutObject() && - highlight_node_->GetDocument().GetFrame(); - InspectorHighlight highlight(highlight_node_.Get(), node_highlight_config_, - append_element_info); - if (event_target_node_) { - highlight.AppendEventTargetQuads(event_target_node_.Get(), - node_highlight_config_); - } - - std::unique_ptr<protocol::DictionaryValue> highlight_json = - highlight.AsProtocolValue(); - EvaluateInOverlay("drawHighlight", std::move(highlight_json)); -} - -void InspectorOverlayAgent::DrawQuadHighlight() { - if (!highlight_quad_) - return; - - InspectorHighlight highlight(WindowToViewportScale()); - highlight.AppendQuad(*highlight_quad_, quad_content_color_, - quad_content_outline_color_); - EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); -} - -void InspectorOverlayAgent::DrawPausedInDebuggerMessage() { - if (inspect_mode_ == kNotSearching && !paused_in_debugger_message_.IsNull()) { - EvaluateInOverlay("drawPausedInDebuggerMessage", - paused_in_debugger_message_); - } -} - -void InspectorOverlayAgent::DrawViewSize() { - if (resize_timer_active_ && draw_view_size_) - EvaluateInOverlay("drawViewSize", ""); -} - -float InspectorOverlayAgent::WindowToViewportScale() const { - LocalFrame* frame = frame_impl_->GetFrame(); - if (!frame) - return 1.0f; - return frame->GetPage()->GetChromeClient().WindowToViewportScalar(1.0f); -} - -Page* InspectorOverlayAgent::OverlayPage() { - if (overlay_page_) - return overlay_page_.Get(); - - ScriptForbiddenScope::AllowUserAgentScript allow_script; - - DEFINE_STATIC_LOCAL(LocalFrameClient, dummy_local_frame_client, - (EmptyLocalFrameClient::Create())); - Page::PageClients page_clients; - FillWithEmptyClients(page_clients); - DCHECK(!overlay_chrome_client_); - overlay_chrome_client_ = InspectorOverlayChromeClient::Create( - frame_impl_->GetFrame()->GetPage()->GetChromeClient(), *this); - page_clients.chrome_client = overlay_chrome_client_.Get(); - overlay_page_ = Page::Create(page_clients); - - Settings& settings = frame_impl_->GetFrame()->GetPage()->GetSettings(); - Settings& overlay_settings = overlay_page_->GetSettings(); - - overlay_settings.GetGenericFontFamilySettings().UpdateStandard( - settings.GetGenericFontFamilySettings().Standard()); - overlay_settings.GetGenericFontFamilySettings().UpdateSerif( - settings.GetGenericFontFamilySettings().Serif()); - overlay_settings.GetGenericFontFamilySettings().UpdateSansSerif( - settings.GetGenericFontFamilySettings().SansSerif()); - overlay_settings.GetGenericFontFamilySettings().UpdateCursive( - settings.GetGenericFontFamilySettings().Cursive()); - overlay_settings.GetGenericFontFamilySettings().UpdateFantasy( - settings.GetGenericFontFamilySettings().Fantasy()); - overlay_settings.GetGenericFontFamilySettings().UpdatePictograph( - settings.GetGenericFontFamilySettings().Pictograph()); - overlay_settings.SetMinimumFontSize(settings.GetMinimumFontSize()); - overlay_settings.SetMinimumLogicalFontSize( - settings.GetMinimumLogicalFontSize()); - overlay_settings.SetScriptEnabled(true); - overlay_settings.SetPluginsEnabled(false); - overlay_settings.SetLoadsImagesAutomatically(true); - // FIXME: http://crbug.com/363843. Inspector should probably create its - // own graphics layers and attach them to the tree rather than going - // through some non-composited paint function. - overlay_settings.SetAcceleratedCompositingEnabled(false); - - LocalFrame* frame = - LocalFrame::Create(&dummy_local_frame_client, *overlay_page_, 0); - frame->SetView(FrameView::Create(*frame)); - frame->Init(); - FrameLoader& loader = frame->Loader(); - frame->View()->SetCanHaveScrollbars(false); - frame->View()->SetBaseBackgroundColor(Color::kTransparent); - - const WebData& overlay_page_html_resource = - Platform::Current()->LoadResource("InspectorOverlayPage.html"); - loader.Load( - FrameLoadRequest(0, ResourceRequest(BlankURL()), - SubstituteData(overlay_page_html_resource, "text/html", - "UTF-8", KURL(), kForceSynchronousLoad))); - v8::Isolate* isolate = ToIsolate(frame); - ScriptState* script_state = ToScriptStateForMainWorld(frame); - DCHECK(script_state); - ScriptState::Scope scope(script_state); - v8::Local<v8::Object> global = script_state->GetContext()->Global(); - v8::Local<v8::Value> overlay_host_obj = - ToV8(overlay_host_.Get(), global, isolate); - DCHECK(!overlay_host_obj.IsEmpty()); - global - ->Set(script_state->GetContext(), - V8AtomicString(isolate, "InspectorOverlayHost"), overlay_host_obj) - .ToChecked(); - -#if OS(WIN) - EvaluateInOverlay("setPlatform", "windows"); -#elif OS(MACOSX) - EvaluateInOverlay("setPlatform", "mac"); -#elif OS(POSIX) - EvaluateInOverlay("setPlatform", "linux"); -#endif - - return overlay_page_.Get(); -} - -LocalFrame* InspectorOverlayAgent::OverlayMainFrame() { - return ToLocalFrame(OverlayPage()->MainFrame()); -} - -void InspectorOverlayAgent::Reset(const IntSize& viewport_size, - const IntPoint& document_scroll_offset) { - std::unique_ptr<protocol::DictionaryValue> reset_data = - protocol::DictionaryValue::create(); - reset_data->setDouble( - "deviceScaleFactor", - frame_impl_->GetFrame()->GetPage()->DeviceScaleFactorDeprecated()); - reset_data->setDouble( - "pageScaleFactor", - frame_impl_->GetFrame()->GetPage()->GetVisualViewport().Scale()); - - IntRect viewport_in_screen = - frame_impl_->GetFrame()->GetPage()->GetChromeClient().ViewportToScreen( - IntRect(IntPoint(), viewport_size), frame_impl_->GetFrame()->View()); - reset_data->setObject("viewportSize", - BuildObjectForSize(viewport_in_screen.Size())); - - // The zoom factor in the overlay frame already has been multiplied by the - // window to viewport scale (aka device scale factor), so cancel it. - reset_data->setDouble( - "pageZoomFactor", - frame_impl_->GetFrame()->PageZoomFactor() / WindowToViewportScale()); - - reset_data->setInteger("scrollX", document_scroll_offset.X()); - reset_data->setInteger("scrollY", document_scroll_offset.Y()); - EvaluateInOverlay("reset", std::move(reset_data)); -} - -void InspectorOverlayAgent::EvaluateInOverlay(const String& method, - const String& argument) { - ScriptForbiddenScope::AllowUserAgentScript allow_script; - std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); - command->pushValue(protocol::StringValue::create(method)); - command->pushValue(protocol::StringValue::create(argument)); - ToLocalFrame(OverlayPage()->MainFrame()) - ->GetScriptController() - .ExecuteScriptInMainWorld( - "dispatch(" + command->serialize() + ")", - ScriptController::kExecuteScriptWhenScriptsDisabled); -} - -void InspectorOverlayAgent::EvaluateInOverlay( - const String& method, - std::unique_ptr<protocol::Value> argument) { - ScriptForbiddenScope::AllowUserAgentScript allow_script; - std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); - command->pushValue(protocol::StringValue::create(method)); - command->pushValue(std::move(argument)); - ToLocalFrame(OverlayPage()->MainFrame()) - ->GetScriptController() - .ExecuteScriptInMainWorld( - "dispatch(" + command->serialize() + ")", - ScriptController::kExecuteScriptWhenScriptsDisabled); -} - -String InspectorOverlayAgent::EvaluateInOverlayForTest(const String& script) { - ScriptForbiddenScope::AllowUserAgentScript allow_script; - v8::HandleScope handle_scope(ToIsolate(OverlayMainFrame())); - v8::Local<v8::Value> string = - ToLocalFrame(OverlayPage()->MainFrame()) - ->GetScriptController() - .ExecuteScriptInMainWorldAndReturnValue( - ScriptSourceCode(script), - ScriptController::kExecuteScriptWhenScriptsDisabled); - return ToCoreStringWithUndefinedOrNullCheck(string); -} - -void InspectorOverlayAgent::OnTimer(TimerBase*) { - resize_timer_active_ = false; - ScheduleUpdate(); -} - -void InspectorOverlayAgent::ClearInternal() { - if (overlay_page_) { - overlay_page_->WillBeDestroyed(); - overlay_page_.Clear(); - overlay_chrome_client_.Clear(); - } - resize_timer_active_ = false; - paused_in_debugger_message_ = String(); - inspect_mode_ = kNotSearching; - timer_.Stop(); - InnerHideHighlight(); -} - -void InspectorOverlayAgent::OverlayResumed() { - if (v8_session_) - v8_session_->resume(); -} - -void InspectorOverlayAgent::OverlaySteppedOver() { - if (v8_session_) - v8_session_->stepOver(); -} - -void InspectorOverlayAgent::PageLayoutInvalidated(bool resized) { - if (resized && draw_view_size_) { - resize_timer_active_ = true; - timer_.StartOneShot(1, BLINK_FROM_HERE); - } - ScheduleUpdate(); -} - -bool InspectorOverlayAgent::HandleMouseMove(const WebMouseEvent& event) { - if (!ShouldSearchForNode()) - return false; - - LocalFrame* frame = frame_impl_->GetFrame(); - if (!frame || !frame->View() || frame->ContentLayoutItem().IsNull()) - return false; - Node* node = HoveredNodeForEvent( - frame, event, event.GetModifiers() & WebInputEvent::kShiftKey); - - // Do not highlight within user agent shadow root unless requested. - if (inspect_mode_ != kSearchingForUAShadow) { - ShadowRoot* shadow_root = InspectorDOMAgent::UserAgentShadowRoot(node); - if (shadow_root) - node = &shadow_root->host(); - } - - // Shadow roots don't have boxes - use host element instead. - if (node && node->IsShadowRoot()) - node = node->ParentOrShadowHostNode(); - - if (!node) - return true; - - if (node->IsFrameOwnerElement()) { - HTMLFrameOwnerElement* frame_owner = ToHTMLFrameOwnerElement(node); - if (frame_owner->ContentFrame() && - !frame_owner->ContentFrame()->IsLocalFrame()) { - // Do not consume event so that remote frame can handle it. - InnerHideHighlight(); - hovered_node_for_inspect_mode_.Clear(); - return false; - } - } - - Node* event_target = (event.GetModifiers() & WebInputEvent::kShiftKey) - ? HoveredNodeForEvent(frame, event, false) - : nullptr; - if (event_target == node) - event_target = nullptr; - - if (node && inspect_mode_highlight_config_) { - hovered_node_for_inspect_mode_ = node; - NodeHighlightRequested(node); - bool omit_tooltip = event.GetModifiers() & - (WebInputEvent::kControlKey | WebInputEvent::kMetaKey); - InnerHighlightNode(node, event_target, *inspect_mode_highlight_config_, - omit_tooltip); - } - return true; -} - -bool InspectorOverlayAgent::HandleMouseDown() { - swallow_next_mouse_up_ = false; - if (!ShouldSearchForNode()) - return false; - - if (hovered_node_for_inspect_mode_) { - swallow_next_mouse_up_ = true; - Inspect(hovered_node_for_inspect_mode_.Get()); - hovered_node_for_inspect_mode_.Clear(); - return true; - } - return false; -} - -bool InspectorOverlayAgent::HandleMouseUp() { - if (swallow_next_mouse_up_) { - swallow_next_mouse_up_ = false; - return true; - } - return false; -} - -bool InspectorOverlayAgent::HandleGestureEvent(const WebGestureEvent& event) { - if (!ShouldSearchForNode() || event.GetType() != WebInputEvent::kGestureTap) - return false; - Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); - if (node && inspect_mode_highlight_config_) { - InnerHighlightNode(node, nullptr, *inspect_mode_highlight_config_, false); - Inspect(node); - return true; - } - return false; -} - -bool InspectorOverlayAgent::HandleTouchEvent(const WebTouchEvent& event) { - if (!ShouldSearchForNode()) - return false; - Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); - if (node && inspect_mode_highlight_config_) { - InnerHighlightNode(node, nullptr, *inspect_mode_highlight_config_, false); - Inspect(node); - return true; - } - return false; -} - -Response InspectorOverlayAgent::CompositingEnabled() { - bool main_frame = frame_impl_->ViewImpl() && !frame_impl_->Parent(); - if (!main_frame || !frame_impl_->ViewImpl() - ->GetPage() - ->GetSettings() - .GetAcceleratedCompositingEnabled()) - return Response::Error("Compositing mode is not supported"); - return Response::OK(); -} - -bool InspectorOverlayAgent::ShouldSearchForNode() { - return inspect_mode_ != kNotSearching; -} - -void InspectorOverlayAgent::Inspect(Node* inspected_node) { - if (!inspected_node) - return; - - Node* node = inspected_node; - while (node && !node->IsElementNode() && !node->IsDocumentNode() && - !node->IsDocumentFragment()) - node = node->ParentOrShadowHostNode(); - if (!node) - return; - - int backend_node_id = DOMNodeIds::IdForNode(node); - if (!enabled_) { - backend_node_id_to_inspect_ = backend_node_id; - return; - } - - GetFrontend()->inspectNodeRequested(backend_node_id); -} - -void InspectorOverlayAgent::NodeHighlightRequested(Node* node) { - if (!enabled_) - return; - - while (node && !node->IsElementNode() && !node->IsDocumentNode() && - !node->IsDocumentFragment()) - node = node->ParentOrShadowHostNode(); - - if (!node) - return; - - int node_id = dom_agent_->PushNodePathToFrontend(node); - GetFrontend()->nodeHighlightRequested(node_id); -} - -Response InspectorOverlayAgent::SetSearchingForNode( - SearchMode search_mode, - Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object) { - if (search_mode == kNotSearching) { - inspect_mode_ = search_mode; - ScheduleUpdate(); - hovered_node_for_inspect_mode_.Clear(); - InnerHideHighlight(); - return Response::OK(); - } - - std::unique_ptr<InspectorHighlightConfig> config; - Response response = HighlightConfigFromInspectorObject( - std::move(highlight_inspector_object), &config); - if (!response.isSuccess()) - return response; - inspect_mode_ = search_mode; - inspect_mode_highlight_config_ = std::move(config); - ScheduleUpdate(); - return Response::OK(); -} - -Response InspectorOverlayAgent::HighlightConfigFromInspectorObject( - Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object, - std::unique_ptr<InspectorHighlightConfig>* out_config) { - if (!highlight_inspector_object.isJust()) { - return Response::Error( - "Internal error: highlight configuration parameter is missing"); - } - - protocol::Overlay::HighlightConfig* config = - highlight_inspector_object.fromJust(); - std::unique_ptr<InspectorHighlightConfig> highlight_config = - WTF::MakeUnique<InspectorHighlightConfig>(); - highlight_config->show_info = config->getShowInfo(false); - highlight_config->show_rulers = config->getShowRulers(false); - highlight_config->show_extension_lines = config->getShowExtensionLines(false); - highlight_config->display_as_material = config->getDisplayAsMaterial(false); - highlight_config->content = - InspectorDOMAgent::ParseColor(config->getContentColor(nullptr)); - highlight_config->padding = - InspectorDOMAgent::ParseColor(config->getPaddingColor(nullptr)); - highlight_config->border = - InspectorDOMAgent::ParseColor(config->getBorderColor(nullptr)); - highlight_config->margin = - InspectorDOMAgent::ParseColor(config->getMarginColor(nullptr)); - highlight_config->event_target = - InspectorDOMAgent::ParseColor(config->getEventTargetColor(nullptr)); - highlight_config->shape = - InspectorDOMAgent::ParseColor(config->getShapeColor(nullptr)); - highlight_config->shape_margin = - InspectorDOMAgent::ParseColor(config->getShapeMarginColor(nullptr)); - highlight_config->selector_list = config->getSelectorList(""); - - *out_config = std::move(highlight_config); - return Response::OK(); -} - -} // namespace blink
diff --git a/third_party/WebKit/Source/web/InspectorOverlayAgent.h b/third_party/WebKit/Source/web/InspectorOverlayAgent.h deleted file mode 100644 index b61ccd5..0000000 --- a/third_party/WebKit/Source/web/InspectorOverlayAgent.h +++ /dev/null
@@ -1,222 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef InspectorOverlayAgent_h -#define InspectorOverlayAgent_h - -#include <v8-inspector.h> -#include <memory> -#include "core/inspector/InspectorBaseAgent.h" -#include "core/inspector/InspectorHighlight.h" -#include "core/inspector/InspectorOverlayHost.h" -#include "core/inspector/protocol/Overlay.h" -#include "platform/Timer.h" -#include "platform/geometry/FloatQuad.h" -#include "platform/geometry/LayoutRect.h" -#include "platform/graphics/Color.h" -#include "platform/heap/Handle.h" -#include "platform/wtf/RefPtr.h" -#include "platform/wtf/text/WTFString.h" -#include "public/platform/WebInputEvent.h" - -namespace blink { - -class Color; -class InspectedFrames; -class InspectorDOMAgent; -class LocalFrame; -class Node; -class Page; -class PageOverlay; -class WebGestureEvent; -class WebMouseEvent; -class WebLocalFrameImpl; -class WebTouchEvent; - -class InspectorOverlayAgent final - : public InspectorBaseAgent<protocol::Overlay::Metainfo>, - public InspectorOverlayHost::Listener { - WTF_MAKE_NONCOPYABLE(InspectorOverlayAgent); - USING_GARBAGE_COLLECTED_MIXIN(InspectorOverlayAgent); - - public: - InspectorOverlayAgent(WebLocalFrameImpl*, - InspectedFrames*, - v8_inspector::V8InspectorSession*, - InspectorDOMAgent*); - ~InspectorOverlayAgent() override; - DECLARE_TRACE(); - - // protocol::Dispatcher::OverlayCommandHandler implementation. - protocol::Response enable() override; - protocol::Response disable() override; - protocol::Response setShowPaintRects(bool) override; - protocol::Response setShowDebugBorders(bool) override; - protocol::Response setShowFPSCounter(bool) override; - protocol::Response setShowScrollBottleneckRects(bool) override; - protocol::Response setShowViewportSizeOnResize(bool) override; - protocol::Response setPausedInDebuggerMessage( - protocol::Maybe<String>) override; - protocol::Response setSuspended(bool) override; - protocol::Response setInspectMode( - const String& mode, - protocol::Maybe<protocol::Overlay::HighlightConfig>) override; - protocol::Response highlightRect( - int x, - int y, - int width, - int height, - protocol::Maybe<protocol::DOM::RGBA> color, - protocol::Maybe<protocol::DOM::RGBA> outline_color) override; - protocol::Response highlightQuad( - std::unique_ptr<protocol::Array<double>> quad, - protocol::Maybe<protocol::DOM::RGBA> color, - protocol::Maybe<protocol::DOM::RGBA> outline_color) override; - protocol::Response highlightNode( - std::unique_ptr<protocol::Overlay::HighlightConfig>, - protocol::Maybe<int> node_id, - protocol::Maybe<int> backend_node_id, - protocol::Maybe<String> object_id) override; - protocol::Response hideHighlight() override; - protocol::Response highlightFrame( - const String& frame_id, - protocol::Maybe<protocol::DOM::RGBA> content_color, - protocol::Maybe<protocol::DOM::RGBA> content_outline_color) override; - protocol::Response getHighlightObjectForTest( - int node_id, - std::unique_ptr<protocol::DictionaryValue>* highlight) override; - - // InspectorBaseAgent overrides. - void Restore() override; - void Dispose() override; - - void Inspect(Node*); - bool HandleInputEvent(const WebInputEvent&); - void PageLayoutInvalidated(bool resized); - void ShowReloadingBlanket(); - void HideReloadingBlanket(); - // Does not yet include paint. - void UpdateAllLifecyclePhases(); - PageOverlay* GetPageOverlay() { return page_overlay_.get(); }; - String EvaluateInOverlayForTest(const String&); - - private: - class InspectorOverlayChromeClient; - class InspectorPageOverlayDelegate; - - enum SearchMode { - kNotSearching, - kSearchingForNormal, - kSearchingForUAShadow, - }; - - // InspectorOverlayHost::Listener implementation. - void OverlayResumed() override; - void OverlaySteppedOver() override; - - bool IsEmpty(); - void DrawNodeHighlight(); - void DrawQuadHighlight(); - void DrawPausedInDebuggerMessage(); - void DrawViewSize(); - - float WindowToViewportScale() const; - - Page* OverlayPage(); - LocalFrame* OverlayMainFrame(); - void Reset(const IntSize& viewport_size, - const IntPoint& document_scroll_offset); - void EvaluateInOverlay(const String& method, const String& argument); - void EvaluateInOverlay(const String& method, - std::unique_ptr<protocol::Value> argument); - void OnTimer(TimerBase*); - void RebuildOverlayPage(); - void Invalidate(); - void ScheduleUpdate(); - void ClearInternal(); - - bool HandleMouseDown(); - bool HandleMouseUp(); - bool HandleGestureEvent(const WebGestureEvent&); - bool HandleTouchEvent(const WebTouchEvent&); - bool HandleMouseMove(const WebMouseEvent&); - - protocol::Response CompositingEnabled(); - - bool ShouldSearchForNode(); - void NodeHighlightRequested(Node*); - protocol::Response SetSearchingForNode( - SearchMode, - protocol::Maybe<protocol::Overlay::HighlightConfig>); - protocol::Response HighlightConfigFromInspectorObject( - protocol::Maybe<protocol::Overlay::HighlightConfig> - highlight_inspector_object, - std::unique_ptr<InspectorHighlightConfig>*); - void InnerHighlightQuad(std::unique_ptr<FloatQuad>, - protocol::Maybe<protocol::DOM::RGBA> color, - protocol::Maybe<protocol::DOM::RGBA> outline_color); - void InnerHighlightNode(Node*, - Node* event_target, - const InspectorHighlightConfig&, - bool omit_tooltip); - void InnerHideHighlight(); - - Member<WebLocalFrameImpl> frame_impl_; - Member<InspectedFrames> inspected_frames_; - bool enabled_; - String paused_in_debugger_message_; - Member<Node> highlight_node_; - Member<Node> event_target_node_; - InspectorHighlightConfig node_highlight_config_; - std::unique_ptr<FloatQuad> highlight_quad_; - Member<Page> overlay_page_; - Member<InspectorOverlayChromeClient> overlay_chrome_client_; - Member<InspectorOverlayHost> overlay_host_; - Color quad_content_color_; - Color quad_content_outline_color_; - bool draw_view_size_; - bool resize_timer_active_; - bool omit_tooltip_; - TaskRunnerTimer<InspectorOverlayAgent> timer_; - bool suspended_; - bool show_reloading_blanket_; - bool in_layout_; - bool needs_update_; - v8_inspector::V8InspectorSession* v8_session_; - Member<InspectorDOMAgent> dom_agent_; - std::unique_ptr<PageOverlay> page_overlay_; - Member<Node> hovered_node_for_inspect_mode_; - bool swallow_next_mouse_up_; - SearchMode inspect_mode_; - std::unique_ptr<InspectorHighlightConfig> inspect_mode_highlight_config_; - int backend_node_id_to_inspect_; -}; - -} // namespace blink - -#endif // InspectorOverlayAgent_h
diff --git a/third_party/WebKit/Source/web/InspectorRenderingAgent.cpp b/third_party/WebKit/Source/web/InspectorRenderingAgent.cpp new file mode 100644 index 0000000..75ef216 --- /dev/null +++ b/third_party/WebKit/Source/web/InspectorRenderingAgent.cpp
@@ -0,0 +1,126 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "web/InspectorRenderingAgent.h" + +#include "core/frame/FrameView.h" +#include "core/frame/Settings.h" +#include "core/page/Page.h" +#include "web/InspectorOverlay.h" +#include "web/WebLocalFrameImpl.h" +#include "web/WebViewImpl.h" + +namespace blink { + +using protocol::Response; + +namespace RenderingAgentState { +static const char kShowDebugBorders[] = "showDebugBorders"; +static const char kShowFPSCounter[] = "showFPSCounter"; +static const char kShowPaintRects[] = "showPaintRects"; +static const char kShowScrollBottleneckRects[] = "showScrollBottleneckRects"; +static const char kShowSizeOnResize[] = "showSizeOnResize"; +} + +InspectorRenderingAgent* InspectorRenderingAgent::Create( + WebLocalFrameImpl* web_local_frame_impl, + InspectorOverlay* overlay) { + return new InspectorRenderingAgent(web_local_frame_impl, overlay); +} + +InspectorRenderingAgent::InspectorRenderingAgent( + WebLocalFrameImpl* web_local_frame_impl, + InspectorOverlay* overlay) + : web_local_frame_impl_(web_local_frame_impl), overlay_(overlay) {} + +WebViewImpl* InspectorRenderingAgent::GetWebViewImpl() { + return web_local_frame_impl_->ViewImpl(); +} + +void InspectorRenderingAgent::Restore() { + setShowDebugBorders( + state_->booleanProperty(RenderingAgentState::kShowDebugBorders, false)); + setShowFPSCounter( + state_->booleanProperty(RenderingAgentState::kShowFPSCounter, false)); + setShowPaintRects( + state_->booleanProperty(RenderingAgentState::kShowPaintRects, false)); + setShowScrollBottleneckRects(state_->booleanProperty( + RenderingAgentState::kShowScrollBottleneckRects, false)); + setShowViewportSizeOnResize( + state_->booleanProperty(RenderingAgentState::kShowSizeOnResize, false)); +} + +Response InspectorRenderingAgent::disable() { + setShowDebugBorders(false); + setShowFPSCounter(false); + setShowPaintRects(false); + setShowScrollBottleneckRects(false); + setShowViewportSizeOnResize(false); + return Response::OK(); +} + +Response InspectorRenderingAgent::setShowDebugBorders(bool show) { + state_->setBoolean(RenderingAgentState::kShowDebugBorders, show); + if (show) { + Response response = CompositingEnabled(); + if (!response.isSuccess()) + return response; + } + GetWebViewImpl()->SetShowDebugBorders(show); + return Response::OK(); +} + +Response InspectorRenderingAgent::setShowFPSCounter(bool show) { + state_->setBoolean(RenderingAgentState::kShowFPSCounter, show); + if (show) { + Response response = CompositingEnabled(); + if (!response.isSuccess()) + return response; + } + GetWebViewImpl()->SetShowFPSCounter(show); + return Response::OK(); +} + +Response InspectorRenderingAgent::setShowPaintRects(bool show) { + state_->setBoolean(RenderingAgentState::kShowPaintRects, show); + GetWebViewImpl()->SetShowPaintRects(show); + if (!show && web_local_frame_impl_->GetFrameView()) + web_local_frame_impl_->GetFrameView()->Invalidate(); + return Response::OK(); +} + +Response InspectorRenderingAgent::setShowScrollBottleneckRects(bool show) { + state_->setBoolean(RenderingAgentState::kShowScrollBottleneckRects, show); + if (show) { + Response response = CompositingEnabled(); + if (!response.isSuccess()) + return response; + } + GetWebViewImpl()->SetShowScrollBottleneckRects(show); + return Response::OK(); +} + +Response InspectorRenderingAgent::setShowViewportSizeOnResize(bool show) { + state_->setBoolean(RenderingAgentState::kShowSizeOnResize, show); + if (overlay_) + overlay_->SetShowViewportSizeOnResize(show); + return Response::OK(); +} + +Response InspectorRenderingAgent::CompositingEnabled() { + if (!GetWebViewImpl() + ->GetPage() + ->GetSettings() + .GetAcceleratedCompositingEnabled()) + return Response::Error("Compositing mode is not supported"); + return Response::OK(); +} + +DEFINE_TRACE(InspectorRenderingAgent) { + visitor->Trace(web_local_frame_impl_); + visitor->Trace(overlay_); + InspectorBaseAgent::Trace(visitor); +} + +} // namespace blink
diff --git a/third_party/WebKit/Source/web/InspectorRenderingAgent.h b/third_party/WebKit/Source/web/InspectorRenderingAgent.h new file mode 100644 index 0000000..a22ba79 --- /dev/null +++ b/third_party/WebKit/Source/web/InspectorRenderingAgent.h
@@ -0,0 +1,48 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef InspectorRenderingAgent_h +#define InspectorRenderingAgent_h + +#include "core/inspector/InspectorBaseAgent.h" +#include "core/inspector/protocol/Rendering.h" + +namespace blink { + +class InspectorOverlay; +class WebLocalFrameImpl; +class WebViewImpl; + +class InspectorRenderingAgent final + : public InspectorBaseAgent<protocol::Rendering::Metainfo> { + WTF_MAKE_NONCOPYABLE(InspectorRenderingAgent); + + public: + static InspectorRenderingAgent* Create(WebLocalFrameImpl*, InspectorOverlay*); + + // protocol::Dispatcher::PageCommandHandler implementation. + protocol::Response setShowPaintRects(bool) override; + protocol::Response setShowDebugBorders(bool) override; + protocol::Response setShowFPSCounter(bool) override; + protocol::Response setShowScrollBottleneckRects(bool) override; + protocol::Response setShowViewportSizeOnResize(bool) override; + + // InspectorBaseAgent overrides. + protocol::Response disable() override; + void Restore() override; + + DECLARE_VIRTUAL_TRACE(); + + private: + InspectorRenderingAgent(WebLocalFrameImpl*, InspectorOverlay*); + protocol::Response CompositingEnabled(); + WebViewImpl* GetWebViewImpl(); + + Member<WebLocalFrameImpl> web_local_frame_impl_; + Member<InspectorOverlay> overlay_; +}; + +} // namespace blink + +#endif // !defined(InspectorRenderingAgent_h)
diff --git a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp index b2577a4..3609203 100644 --- a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp +++ b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp
@@ -84,7 +84,8 @@ #include "public/web/WebSettings.h" #include "web/DevToolsEmulator.h" #include "web/InspectorEmulationAgent.h" -#include "web/InspectorOverlayAgent.h" +#include "web/InspectorOverlay.h" +#include "web/InspectorRenderingAgent.h" #include "web/WebFrameWidgetImpl.h" #include "web/WebInputEventConversion.h" #include "web/WebLocalFrameImpl.h" @@ -232,9 +233,11 @@ WebDevToolsAgentImpl* WebDevToolsAgentImpl::Create( WebLocalFrameImpl* frame, WebDevToolsAgentClient* client) { + InspectorOverlay* overlay = new InspectorOverlay(frame); + if (!IsMainFrame(frame)) { WebDevToolsAgentImpl* agent = - new WebDevToolsAgentImpl(frame, client, false); + new WebDevToolsAgentImpl(frame, client, overlay, false); if (frame->FrameWidget()) agent->LayerTreeViewChanged( ToWebFrameWidgetImpl(frame->FrameWidget())->LayerTreeView()); @@ -242,7 +245,8 @@ } WebViewImpl* view = frame->ViewImpl(); - WebDevToolsAgentImpl* agent = new WebDevToolsAgentImpl(frame, client, true); + WebDevToolsAgentImpl* agent = + new WebDevToolsAgentImpl(frame, client, overlay, true); agent->LayerTreeViewChanged(view->LayerTreeView()); return agent; } @@ -250,6 +254,7 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl( WebLocalFrameImpl* web_local_frame_impl, WebDevToolsAgentClient* client, + InspectorOverlay* overlay, bool include_view_agents) : client_(client), web_local_frame_impl_(web_local_frame_impl), @@ -257,15 +262,16 @@ web_local_frame_impl_->GetFrame()->InstrumentingAgents()), resource_content_loader_(InspectorResourceContentLoader::Create( web_local_frame_impl_->GetFrame())), + overlay_(overlay), inspected_frames_( InspectedFrames::Create(web_local_frame_impl_->GetFrame())), resource_container_(new InspectorResourceContainer(inspected_frames_)), + dom_agent_(nullptr), page_agent_(nullptr), network_agent_(nullptr), layer_tree_agent_(nullptr), tracing_agent_(nullptr), trace_events_agent_(new InspectorTraceEvents()), - overlay_agent_(nullptr), include_view_agents_(include_view_agents), layer_tree_id_(0) { DCHECK(IsMainThread()); @@ -281,14 +287,15 @@ visitor->Trace(web_local_frame_impl_); visitor->Trace(instrumenting_agents_); visitor->Trace(resource_content_loader_); + visitor->Trace(overlay_); visitor->Trace(inspected_frames_); visitor->Trace(resource_container_); + visitor->Trace(dom_agent_); visitor->Trace(page_agent_); visitor->Trace(network_agent_); visitor->Trace(layer_tree_agent_); visitor->Trace(tracing_agent_); visitor->Trace(trace_events_agent_); - visitor->Trace(overlay_agent_); visitor->Trace(session_); } @@ -316,7 +323,8 @@ main_thread_debugger->ContextGroupId(inspected_frames_->Root()), state); InspectorDOMAgent* dom_agent = new InspectorDOMAgent( - isolate, inspected_frames_.Get(), session_->V8Session()); + isolate, inspected_frames_.Get(), session_->V8Session(), overlay_.Get()); + dom_agent_ = dom_agent; session_->Append(dom_agent); InspectorLayerTreeAgent* layer_tree_agent = @@ -330,7 +338,7 @@ session_->Append(network_agent); InspectorCSSAgent* css_agent = InspectorCSSAgent::Create( - dom_agent, inspected_frames_.Get(), network_agent_, + dom_agent_, inspected_frames_.Get(), network_agent_, resource_content_loader_.Get(), resource_container_.Get()); session_->Append(css_agent); @@ -354,8 +362,8 @@ tracing_agent_ = tracing_agent; session_->Append(tracing_agent); - session_->Append( - new InspectorDOMDebuggerAgent(isolate, dom_agent, session_->V8Session())); + session_->Append(new InspectorDOMDebuggerAgent(isolate, dom_agent_, + session_->V8Session())); session_->Append(InspectorInputAgent::Create(inspected_frames_.Get())); @@ -372,12 +380,6 @@ session_->Append( new DeviceOrientationInspectorAgent(inspected_frames_.Get())); - InspectorOverlayAgent* overlay_agent = - new InspectorOverlayAgent(web_local_frame_impl_, inspected_frames_.Get(), - session_->V8Session(), dom_agent); - overlay_agent_ = overlay_agent; - session_->Append(overlay_agent); - tracing_agent_->SetLayerTreeId(layer_tree_id_); network_agent_->SetHostId(host_id); @@ -386,25 +388,33 @@ // during remote->local transition we cannot access mainFrameImpl() yet, so // we have to store the frame which will become the main frame later. session_->Append( + InspectorRenderingAgent::Create(web_local_frame_impl_, overlay_.Get())); + session_->Append( InspectorEmulationAgent::Create(web_local_frame_impl_, this)); // TODO(dgozman): migrate each of the following agents to frame once module // is ready. Page* page = web_local_frame_impl_->ViewImpl()->GetPage(); session_->Append(InspectorDatabaseAgent::Create(page)); - session_->Append(new InspectorAccessibilityAgent(page, dom_agent)); + session_->Append(new InspectorAccessibilityAgent(page, dom_agent_)); session_->Append(InspectorDOMStorageAgent::Create(page)); session_->Append(InspectorCacheStorageAgent::Create()); } + if (overlay_) + overlay_->Init(session_->V8Session(), dom_agent_); + Platform::Current()->CurrentThread()->AddTaskObserver(this); } void WebDevToolsAgentImpl::DestroySession() { - overlay_agent_.Clear(); + if (overlay_) + overlay_->Clear(); + tracing_agent_.Clear(); layer_tree_agent_.Clear(); network_agent_.Clear(); page_agent_.Clear(); + dom_agent_.Clear(); session_->Dispose(); session_.Clear(); @@ -487,13 +497,13 @@ } void WebDevToolsAgentImpl::ShowReloadingBlanket() { - if (overlay_agent_) - overlay_agent_->ShowReloadingBlanket(); + if (overlay_) + overlay_->ShowReloadingBlanket(); } void WebDevToolsAgentImpl::HideReloadingBlanket() { - if (overlay_agent_) - overlay_agent_->HideReloadingBlanket(); + if (overlay_) + overlay_->HideReloadingBlanket(); } void WebDevToolsAgentImpl::SetCPUThrottlingRate(double rate) { @@ -527,7 +537,7 @@ void WebDevToolsAgentImpl::InspectElementAt( int session_id, const WebPoint& point_in_root_frame) { - if (!overlay_agent_ || !session_ || session_->SessionId() != session_id) + if (!dom_agent_ || !session_ || session_->SessionId() != session_id) return; HitTestRequest::HitTestRequestType hit_type = HitTestRequest::kMove | HitTestRequest::kReadOnly | @@ -547,7 +557,7 @@ Node* node = result.InnerNode(); if (!node && web_local_frame_impl_->GetFrame()->GetDocument()) node = web_local_frame_impl_->GetFrame()->GetDocument()->documentElement(); - overlay_agent_->Inspect(node); + dom_agent_->Inspect(node); } void WebDevToolsAgentImpl::FailedToRequestDevTools() { @@ -564,8 +574,19 @@ } void WebDevToolsAgentImpl::PageLayoutInvalidated(bool resized) { - if (overlay_agent_) - overlay_agent_->PageLayoutInvalidated(resized); + if (overlay_) + overlay_->PageLayoutInvalidated(resized); +} + +void WebDevToolsAgentImpl::ConfigureOverlay(bool suspended, + const String& message) { + if (!overlay_) + return; + overlay_->SetPausedInDebuggerMessage(message); + if (suspended) + overlay_->Suspend(); + else + overlay_->Resume(); } void WebDevToolsAgentImpl::WaitForCreateWindow(LocalFrame* frame) { @@ -578,10 +599,10 @@ WebString WebDevToolsAgentImpl::EvaluateInWebInspectorOverlay( const WebString& script) { - if (!overlay_agent_) + if (!overlay_) return WebString(); - return overlay_agent_->EvaluateInOverlayForTest(script); + return overlay_->EvaluateInOverlayForTest(script); } bool WebDevToolsAgentImpl::CacheDisabled() {
diff --git a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.h b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.h index a42daf4..d37a8e413 100644 --- a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.h +++ b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.h
@@ -48,7 +48,7 @@ class GraphicsLayer; class InspectedFrames; -class InspectorOverlayAgent; +class InspectorOverlay; class InspectorResourceContainer; class InspectorResourceContentLoader; class InspectorTraceEvents; @@ -74,7 +74,7 @@ void WillBeDestroyed(); WebDevToolsAgentClient* Client() { return client_; } - InspectorOverlayAgent* OverlayAgent() const { return overlay_agent_.Get(); } + InspectorOverlay* Overlay() const { return overlay_.Get(); } void FlushProtocolNotifications(); // Instrumentation from web/ layer. @@ -105,6 +105,7 @@ private: WebDevToolsAgentImpl(WebLocalFrameImpl*, WebDevToolsAgentClient*, + InspectorOverlay*, bool include_view_agents); // InspectorTracingAgent::Client implementation. @@ -118,6 +119,7 @@ // InspectorPageAgent::Client implementation. void PageLayoutInvalidated(bool resized) override; + void ConfigureOverlay(bool suspended, const String& message) override; void WaitForCreateWindow(LocalFrame*) override; // InspectorSession::Client implementation. @@ -148,15 +150,16 @@ Member<CoreProbeSink> instrumenting_agents_; Member<InspectorResourceContentLoader> resource_content_loader_; + Member<InspectorOverlay> overlay_; Member<InspectedFrames> inspected_frames_; Member<InspectorResourceContainer> resource_container_; + Member<InspectorDOMAgent> dom_agent_; Member<InspectorPageAgent> page_agent_; Member<InspectorNetworkAgent> network_agent_; Member<InspectorLayerTreeAgent> layer_tree_agent_; Member<InspectorTracingAgent> tracing_agent_; Member<InspectorTraceEvents> trace_events_agent_; - Member<InspectorOverlayAgent> overlay_agent_; Member<InspectorSession> session_; bool include_view_agents_;
diff --git a/third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp b/third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp index 90915e7..fe97646 100644 --- a/third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp +++ b/third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp
@@ -67,7 +67,7 @@ #include "web/CompositorMutatorImpl.h" #include "web/CompositorWorkerProxyClientImpl.h" #include "web/ContextMenuAllowedScope.h" -#include "web/InspectorOverlayAgent.h" +#include "web/InspectorOverlay.h" #include "web/PageOverlay.h" #include "web/WebDevToolsAgentImpl.h" #include "web/WebInputEventConversion.h" @@ -251,7 +251,7 @@ if (!local_root_) return; - if (InspectorOverlayAgent* overlay = GetInspectorOverlay()) { + if (InspectorOverlay* overlay = GetInspectorOverlay()) { overlay->UpdateAllLifecyclePhases(); // TODO(chrishtr): integrate paint into the overlay's lifecycle. if (overlay->GetPageOverlay() && @@ -363,7 +363,7 @@ if (!GetPage()) return WebInputEventResult::kNotHandled; - if (InspectorOverlayAgent* overlay = GetInspectorOverlay()) { + if (InspectorOverlay* overlay = GetInspectorOverlay()) { if (overlay->HandleInputEvent(input_event)) return WebInputEventResult::kHandledSuppressed; } @@ -1181,11 +1181,11 @@ return result; } -InspectorOverlayAgent* WebFrameWidgetImpl::GetInspectorOverlay() { +InspectorOverlay* WebFrameWidgetImpl::GetInspectorOverlay() { if (!local_root_) return nullptr; if (WebDevToolsAgentImpl* devtools = local_root_->DevToolsAgentImpl()) - return devtools->OverlayAgent(); + return devtools->Overlay(); return nullptr; }
diff --git a/third_party/WebKit/Source/web/WebFrameWidgetImpl.h b/third_party/WebKit/Source/web/WebFrameWidgetImpl.h index 3bd30608..ac28f742 100644 --- a/third_party/WebKit/Source/web/WebFrameWidgetImpl.h +++ b/third_party/WebKit/Source/web/WebFrameWidgetImpl.h
@@ -51,7 +51,7 @@ class CompositorAnimationHost; class Frame; class Element; -class InspectorOverlayAgent; +class InspectorOverlay; class LocalFrame; class PaintLayerCompositor; class UserGestureToken; @@ -184,7 +184,7 @@ WebInputEventResult HandleKeyEvent(const WebKeyboardEvent&) override; WebInputEventResult HandleCharEvent(const WebKeyboardEvent&) override; - InspectorOverlayAgent* GetInspectorOverlay(); + InspectorOverlay* GetInspectorOverlay(); // This method returns the focused frame belonging to this WebWidget, that // is, a focused frame with the same local root as the one corresponding
diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp index aa3ad81..bb2303f4c 100644 --- a/third_party/WebKit/Source/web/WebViewImpl.cpp +++ b/third_party/WebKit/Source/web/WebViewImpl.cpp
@@ -162,7 +162,7 @@ #include "web/DedicatedWorkerMessagingProxyProviderImpl.h" #include "web/DevToolsEmulator.h" #include "web/FullscreenController.h" -#include "web/InspectorOverlayAgent.h" +#include "web/InspectorOverlay.h" #include "web/LinkHighlightImpl.h" #include "web/PageOverlay.h" #include "web/PrerendererClientImpl.h" @@ -432,9 +432,9 @@ return main_frame ? main_frame->DevToolsAgentImpl() : nullptr; } -InspectorOverlayAgent* WebViewImpl::GetInspectorOverlay() { +InspectorOverlay* WebViewImpl::GetInspectorOverlay() { if (WebDevToolsAgentImpl* devtools = MainFrameDevToolsAgentImpl()) - return devtools->OverlayAgent(); + return devtools->Overlay(); return nullptr; } @@ -2026,7 +2026,7 @@ PageWidgetDelegate::UpdateAllLifecyclePhases(*page_, *MainFrameImpl()->GetFrame()); - if (InspectorOverlayAgent* overlay = GetInspectorOverlay()) { + if (InspectorOverlay* overlay = GetInspectorOverlay()) { overlay->UpdateAllLifecyclePhases(); // TODO(chrishtr): integrate paint into the overlay's lifecycle. if (overlay->GetPageOverlay() && @@ -2169,7 +2169,7 @@ if (dev_tools_emulator_->HandleInputEvent(input_event)) return WebInputEventResult::kHandledSuppressed; - if (InspectorOverlayAgent* overlay = GetInspectorOverlay()) { + if (InspectorOverlay* overlay = GetInspectorOverlay()) { if (overlay->HandleInputEvent(input_event)) return WebInputEventResult::kHandledSuppressed; } @@ -4132,7 +4132,7 @@ void WebViewImpl::UpdatePageOverlays() { if (page_color_overlay_) page_color_overlay_->Update(); - if (InspectorOverlayAgent* overlay = GetInspectorOverlay()) { + if (InspectorOverlay* overlay = GetInspectorOverlay()) { PageOverlay* inspector_page_overlay = overlay->GetPageOverlay(); if (inspector_page_overlay) inspector_page_overlay->Update();
diff --git a/third_party/WebKit/Source/web/WebViewImpl.h b/third_party/WebKit/Source/web/WebViewImpl.h index 61b1a3b..3473323 100644 --- a/third_party/WebKit/Source/web/WebViewImpl.h +++ b/third_party/WebKit/Source/web/WebViewImpl.h
@@ -77,7 +77,7 @@ class DevToolsEmulator; class Frame; class FullscreenController; -class InspectorOverlayAgent; +class InspectorOverlay; class LinkHighlightImpl; class PageOverlay; class PageScaleConstraintsSet; @@ -504,7 +504,7 @@ } private: - InspectorOverlayAgent* GetInspectorOverlay(); + InspectorOverlay* GetInspectorOverlay(); void SetPageScaleFactorAndLocation(float, const FloatPoint&); void PropagateZoomFactorToLocalFrameRoots(Frame*, float);