Last active
December 12, 2015 09:38
-
-
Save vivekgalatage/4752724 to your computer and use it in GitHub Desktop.
Notifying inspector front-end when the script execution state has been changed (due to browser wide "JavaScript" disable option).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Source/WebCore/inspector/Inspector.json b/Source/WebCore/inspector/Inspector.json | |
index 1414f64..b9575fb 100644 | |
--- a/Source/WebCore/inspector/Inspector.json | |
+++ b/Source/WebCore/inspector/Inspector.json | |
@@ -559,6 +559,14 @@ | |
"name": "javascriptDialogClosed", | |
"description": "Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) has been closed.", | |
"hidden": true | |
+ }, | |
+ { | |
+ "name": "scriptExecutionStateChanged", | |
+ "description": "Fired when the JavaScript is enabled/disabled on the page", | |
+ "parameters": [ | |
+ { "name": "state", "type": "boolean", "description": "Whether script execution was enabled or disabled in the page." } | |
+ ], | |
+ "hidden": true | |
} | |
] | |
}, | |
diff --git a/Source/WebCore/inspector/InspectorInstrumentation.cpp b/Source/WebCore/inspector/InspectorInstrumentation.cpp | |
index a1f501d..5cc071f 100644 | |
--- a/Source/WebCore/inspector/InspectorInstrumentation.cpp | |
+++ b/Source/WebCore/inspector/InspectorInstrumentation.cpp | |
@@ -447,6 +447,12 @@ void InspectorInstrumentation::didEvaluateScriptImpl(const InspectorInstrumentat | |
timelineAgent->didEvaluateScript(); | |
} | |
+void InspectorInstrumentation::didScriptExecutionStateChangeImpl(InstrumentingAgents* instrumentingAgents, bool isEnabled) | |
+{ | |
+ if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) | |
+ pageAgent->didScriptExecutionStateChange(isEnabled); | |
+} | |
+ | |
void InspectorInstrumentation::didCreateIsolatedContextImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, ScriptState* scriptState, SecurityOrigin* origin) | |
{ | |
if (PageRuntimeAgent* runtimeAgent = instrumentingAgents->pageRuntimeAgent()) | |
diff --git a/Source/WebCore/inspector/InspectorInstrumentation.h b/Source/WebCore/inspector/InspectorInstrumentation.h | |
index 1fa8dfb..cd445ad 100644 | |
--- a/Source/WebCore/inspector/InspectorInstrumentation.h | |
+++ b/Source/WebCore/inspector/InspectorInstrumentation.h | |
@@ -151,6 +151,7 @@ public: | |
static void didDispatchEventOnWindow(const InspectorInstrumentationCookie&); | |
static InspectorInstrumentationCookie willEvaluateScript(Frame*, const String& url, int lineNumber); | |
static void didEvaluateScript(const InspectorInstrumentationCookie&); | |
+ static void didScriptExecutionStateChange(Page*, bool isEnabled); | |
static void didCreateIsolatedContext(Frame*, ScriptState*, SecurityOrigin*); | |
static InspectorInstrumentationCookie willFireTimer(ScriptExecutionContext*, int timerId); | |
static void didFireTimer(const InspectorInstrumentationCookie&); | |
@@ -355,6 +356,7 @@ private: | |
static void didDispatchEventOnWindowImpl(const InspectorInstrumentationCookie&); | |
static InspectorInstrumentationCookie willEvaluateScriptImpl(InstrumentingAgents*, const String& url, int lineNumber, Frame*); | |
static void didEvaluateScriptImpl(const InspectorInstrumentationCookie&); | |
+ static void didScriptExecutionStateChangeImpl(InstrumentingAgents*, bool isEnabled); | |
static void didCreateIsolatedContextImpl(InstrumentingAgents*, Frame*, ScriptState*, SecurityOrigin*); | |
static InspectorInstrumentationCookie willFireTimerImpl(InstrumentingAgents*, int timerId, ScriptExecutionContext*); | |
static void didFireTimerImpl(const InspectorInstrumentationCookie&); | |
@@ -965,6 +967,13 @@ inline void InspectorInstrumentation::didEvaluateScript(const InspectorInstrumen | |
#endif | |
} | |
+inline void InspectorInstrumentation::didScriptExecutionStateChange(Page* page, bool isEnabled) | |
+{ | |
+ FAST_RETURN_IF_NO_FRONTENDS(void()); | |
+ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page)) | |
+ return didScriptExecutionStateChangeImpl(instrumentingAgents, isEnabled); | |
+} | |
+ | |
inline void InspectorInstrumentation::didCreateIsolatedContext(Frame* frame, ScriptState* scriptState, SecurityOrigin* origin) | |
{ | |
#if ENABLE(INSPECTOR) | |
diff --git a/Source/WebCore/inspector/InspectorPageAgent.cpp b/Source/WebCore/inspector/InspectorPageAgent.cpp | |
index 1583beb..427c7e2 100644 | |
--- a/Source/WebCore/inspector/InspectorPageAgent.cpp | |
+++ b/Source/WebCore/inspector/InspectorPageAgent.cpp | |
@@ -1029,6 +1029,14 @@ void InspectorPageAgent::didRecalculateStyle() | |
m_overlay->update(); | |
} | |
+void InspectorPageAgent::didScriptExecutionStateChange(bool isEnabled) | |
+{ | |
+ if (!m_frontend) | |
+ return; | |
+ | |
+ m_frontend->scriptExecutionStateChanged(isEnabled); | |
+} | |
+ | |
PassRefPtr<TypeBuilder::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame) | |
{ | |
RefPtr<TypeBuilder::Page::Frame> frameObject = TypeBuilder::Page::Frame::create() | |
diff --git a/Source/WebCore/inspector/InspectorPageAgent.h b/Source/WebCore/inspector/InspectorPageAgent.h | |
index 077f0c7..8f27450 100644 | |
--- a/Source/WebCore/inspector/InspectorPageAgent.h | |
+++ b/Source/WebCore/inspector/InspectorPageAgent.h | |
@@ -156,6 +156,7 @@ public: | |
void didLayout(); | |
void didScroll(); | |
void didRecalculateStyle(); | |
+ void didScriptExecutionStateChange(bool isEnabled); | |
// Inspector Controller API | |
virtual void setFrontend(InspectorFrontend*); | |
diff --git a/Source/WebCore/inspector/front-end/ResourceTreeModel.js b/Source/WebCore/inspector/front-end/ResourceTreeModel.js | |
index d3e61eb..9fedbe0 100644 | |
--- a/Source/WebCore/inspector/front-end/ResourceTreeModel.js | |
+++ b/Source/WebCore/inspector/front-end/ResourceTreeModel.js | |
@@ -625,6 +625,11 @@ WebInspector.PageDispatcher.prototype = { | |
javascriptDialogClosed: function() | |
{ | |
+ }, | |
+ | |
+ scriptExecutionStateChanged: function(isEnabled) | |
+ { | |
+ WebInspector.settings.javaScriptDisabled.set(!isEnabled); | |
} | |
} | |
diff --git a/Source/WebCore/page/Settings.cpp b/Source/WebCore/page/Settings.cpp | |
index 301b36b..061dd7c 100644 | |
--- a/Source/WebCore/page/Settings.cpp | |
+++ b/Source/WebCore/page/Settings.cpp | |
@@ -37,6 +37,7 @@ | |
#include "FrameView.h" | |
#include "HTMLMediaElement.h" | |
#include "HistoryItem.h" | |
+#include "InspectorInstrumentation.h" | |
#include "Page.h" | |
#include "PageCache.h" | |
#include "ResourceHandle.h" | |
@@ -415,6 +416,7 @@ void Settings::imageLoadingSettingsTimerFired(Timer<Settings>*) | |
void Settings::setScriptEnabled(bool isScriptEnabled) | |
{ | |
m_isScriptEnabled = isScriptEnabled; | |
+ InspectorInstrumentation::didScriptExecutionStateChange(m_page, m_isScriptEnabled); | |
} | |
void Settings::setJavaEnabled(bool isJavaEnabled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment