Web Inspector: [Canvas] support 2D canvas instrumentation from the inspector C++...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Sep 2012 13:01:29 +0000 (13:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Sep 2012 13:01:29 +0000 (13:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97203

Patch by Andrey Adaikin <aandrey@chromium.org> on 2012-09-24
Reviewed by Yury Semikhatsky.

Implements wrapping a 2D canvas context through the injected canvas module script facility.

* bindings/js/JSHTMLCanvasElementCustom.cpp:
(WebCore::JSHTMLCanvasElement::getContext):
* bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
(WebCore::V8HTMLCanvasElement::getContextCallback):
* inspector/InjectedScriptCanvasModule.cpp:
(WebCore::InjectedScriptCanvasModule::wrapCanvas2DContext):
(WebCore):
(WebCore::InjectedScriptCanvasModule::wrapWebGLContext):
(WebCore::InjectedScriptCanvasModule::callWrapContextFunction):
* inspector/InjectedScriptCanvasModule.h:
(InjectedScriptCanvasModule):
* inspector/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::wrapCanvas2DRenderingContextForInstrumentation):
(WebCore):
* inspector/InspectorCanvasAgent.h:
(InspectorCanvasAgent):
* inspector/InspectorCanvasInstrumentation.h:
(WebCore::InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation):
(WebCore):
* inspector/InspectorInstrumentation.h:
(InspectorInstrumentation):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129353 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp
Source/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
Source/WebCore/inspector/InjectedScriptCanvasModule.cpp
Source/WebCore/inspector/InjectedScriptCanvasModule.h
Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js
Source/WebCore/inspector/InspectorCanvasAgent.cpp
Source/WebCore/inspector/InspectorCanvasAgent.h
Source/WebCore/inspector/InspectorCanvasInstrumentation.h
Source/WebCore/inspector/InspectorInstrumentation.h

index 33db5ef..be5987a 100644 (file)
@@ -1,3 +1,34 @@
+2012-09-24  Andrey Adaikin  <aandrey@chromium.org>
+
+        Web Inspector: [Canvas] support 2D canvas instrumentation from the inspector C++ code
+        https://bugs.webkit.org/show_bug.cgi?id=97203
+
+        Reviewed by Yury Semikhatsky.
+
+        Implements wrapping a 2D canvas context through the injected canvas module script facility.
+
+        * bindings/js/JSHTMLCanvasElementCustom.cpp:
+        (WebCore::JSHTMLCanvasElement::getContext):
+        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
+        (WebCore::V8HTMLCanvasElement::getContextCallback):
+        * inspector/InjectedScriptCanvasModule.cpp:
+        (WebCore::InjectedScriptCanvasModule::wrapCanvas2DContext):
+        (WebCore):
+        (WebCore::InjectedScriptCanvasModule::wrapWebGLContext):
+        (WebCore::InjectedScriptCanvasModule::callWrapContextFunction):
+        * inspector/InjectedScriptCanvasModule.h:
+        (InjectedScriptCanvasModule):
+        * inspector/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::wrapCanvas2DRenderingContextForInstrumentation):
+        (WebCore):
+        * inspector/InspectorCanvasAgent.h:
+        (InspectorCanvasAgent):
+        * inspector/InspectorCanvasInstrumentation.h:
+        (WebCore::InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation):
+        (WebCore):
+        * inspector/InspectorInstrumentation.h:
+        (InspectorInstrumentation):
+
 2012-09-24  Pavel Feldman  <pfeldman@chromium.org>
 
         Web Inspector:EXC_BAD_ACCESS upon closing page with node highlighted
index 556bdf7..72bf386 100644 (file)
 
 #include "CanvasContextAttributes.h"
 #include "HTMLCanvasElement.h"
+#include "InspectorCanvasInstrumentation.h"
 #include "JSCanvasRenderingContext2D.h"
+#include "ScriptObject.h"
 #if ENABLE(WEBGL)
-#include "InspectorCanvasInstrumentation.h"
 #include "JSWebGLRenderingContext.h"
-#include "ScriptObject.h"
 #include "WebGLContextAttributes.h"
 #endif
 #include <wtf/GetPtr.h>
@@ -78,14 +78,18 @@ JSValue JSHTMLCanvasElement::getContext(ExecState* exec)
     if (!context)
         return jsNull();
     JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context));
+    if (InspectorInstrumentation::hasFrontends()) {
+        ScriptObject contextObject(exec, jsValue.getObject());
+        ScriptObject wrapped;
+        if (context->is2d())
+            wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(canvas->document(), contextObject);
 #if ENABLE(WEBGL)
-    if (context->is3d() && InspectorInstrumentation::hasFrontends()) {
-        ScriptObject glContext(exec, jsValue.getObject());
-        ScriptObject wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(canvas->document(), glContext);
+        else if (context->is3d())
+            wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(canvas->document(), contextObject);
+#endif
         if (!wrapped.hasNoValue())
             return wrapped.jsValue();
     }
-#endif
     return jsValue;
 }
 
index 0b15727..a6fb22a 100644 (file)
 #include "CanvasContextAttributes.h"
 #include "CanvasRenderingContext.h"
 #include "HTMLCanvasElement.h"
+#include "InspectorCanvasInstrumentation.h"
 #include "WebGLContextAttributes.h"
 #include "V8Binding.h"
 #include "V8CanvasRenderingContext2D.h"
 #include "V8Node.h"
 #if ENABLE(WEBGL)
-#include "InspectorCanvasInstrumentation.h"
 #include "V8WebGLRenderingContext.h"
 #endif
 #include <wtf/MathExtras.h>
@@ -85,9 +85,17 @@ v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Argument
     CanvasRenderingContext* result = imp->getContext(contextId, attrs.get());
     if (!result)
         return v8::Null(args.GetIsolate());
-
-    if (result->is2d())
-        return toV8(static_cast<CanvasRenderingContext2D*>(result), args.Holder(), args.GetIsolate());
+    else if (result->is2d()) {
+        v8::Handle<v8::Value> v8Result = toV8(static_cast<CanvasRenderingContext2D*>(result), args.Holder(), args.GetIsolate());
+        if (InspectorInstrumentation::hasFrontends()) {
+            ScriptState* scriptState = ScriptState::forContext(v8::Context::GetCurrent());
+            ScriptObject context(scriptState, v8::Handle<v8::Object>::Cast(v8Result));
+            ScriptObject wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(imp->document(), context);
+            if (!wrapped.hasNoValue())
+                return wrapped.v8Value();
+        }
+        return v8Result;
+    }
 #if ENABLE(WEBGL)
     else if (result->is3d()) {
         // 3D canvas contexts can hold on to lots of GPU resources, and we want to take an
index db278d9..b1f1dca 100644 (file)
@@ -59,20 +59,30 @@ String InjectedScriptCanvasModule::source() const
     return String(reinterpret_cast<const char*>(InjectedScriptCanvasModuleSource_js), sizeof(InjectedScriptCanvasModuleSource_js));
 }
 
+ScriptObject InjectedScriptCanvasModule::wrapCanvas2DContext(const ScriptObject& context)
+{
+    return callWrapContextFunction("wrapCanvas2DContext", context);
+}
+
 #if ENABLE(WEBGL)
 ScriptObject InjectedScriptCanvasModule::wrapWebGLContext(const ScriptObject& glContext)
 {
-    ScriptFunctionCall function(injectedScriptObject(), "wrapWebGLContext");
-    function.appendArgument(glContext);
+    return callWrapContextFunction("wrapWebGLContext", glContext);
+}
+#endif // ENABLE(WEBGL)
+
+ScriptObject InjectedScriptCanvasModule::callWrapContextFunction(const String& functionName, const ScriptObject& context)
+{
+    ScriptFunctionCall function(injectedScriptObject(), functionName);
+    function.appendArgument(context);
     bool hadException = false;
     ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
     if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
         ASSERT_NOT_REACHED();
         return ScriptObject();
     }
-    return ScriptObject(glContext.scriptState(), resultValue);
+    return ScriptObject(context.scriptState(), resultValue);
 }
-#endif // ENABLE(WEBGL)
 
 void InjectedScriptCanvasModule::captureFrame(ErrorString* errorString, String* traceLogId)
 {
index 4de2236..2e960aa 100644 (file)
@@ -50,14 +50,18 @@ public:
 
     static InjectedScriptCanvasModule moduleForState(InjectedScriptManager*, ScriptState*);
 
+    ScriptObject wrapCanvas2DContext(const ScriptObject&);
 #if ENABLE(WEBGL)
-    ScriptObject wrapWebGLContext(const ScriptObject& glContext);
+    ScriptObject wrapWebGLContext(const ScriptObject&);
 #endif
 
     void captureFrame(ErrorString*, String*);
     void dropTraceLog(ErrorString*, const String&);
     void traceLog(ErrorString*, const String&, RefPtr<TypeBuilder::Canvas::TraceLog>*);
     void replayTraceLog(ErrorString*, const String&, int, String*);
+
+private:
+    ScriptObject callWrapContextFunction(const String&, const ScriptObject&);
 };
 
 #endif
index 6780af3..61150be 100644 (file)
@@ -1992,6 +1992,16 @@ InjectedScript.prototype = {
         return proxy;
     },
 
+    /**
+     * @param {CanvasRenderingContext2D} context
+     * @return {Object}
+     */
+    wrapCanvas2DContext: function(context)
+    {
+        // FIXME: Implement wrapping 2D context.
+        return context;
+    },    
+
     captureFrame: function()
     {
         var id = this._makeTraceLogId();
index dff2938..5e3ffcb 100644 (file)
@@ -130,6 +130,20 @@ void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String
         module.replayTraceLog(errorString, traceLogId, stepNo, result);
 }
 
+ScriptObject InspectorCanvasAgent::wrapCanvas2DRenderingContextForInstrumentation(const ScriptObject& context)
+{
+    if (context.hasNoValue()) {
+        ASSERT_NOT_REACHED();
+        return ScriptObject();
+    }
+    InjectedScriptCanvasModule module = InjectedScriptCanvasModule::moduleForState(m_injectedScriptManager, context.scriptState());
+    if (module.hasNoValue()) {
+        ASSERT_NOT_REACHED();
+        return ScriptObject();
+    }
+    return module.wrapCanvas2DContext(context);
+}
+
 #if ENABLE(WEBGL)
 ScriptObject InspectorCanvasAgent::wrapWebGLRenderingContextForInstrumentation(const ScriptObject& glContext)
 {
index f460c64..e868619 100644 (file)
@@ -66,6 +66,7 @@ public:
 
     bool enabled() { return m_enabled; }
 
+    ScriptObject wrapCanvas2DRenderingContextForInstrumentation(const ScriptObject&);
 #if ENABLE(WEBGL)
     ScriptObject wrapWebGLRenderingContextForInstrumentation(const ScriptObject&);
 #endif
index 5904b87..783a146 100644 (file)
 
 namespace WebCore {
 
+ScriptObject InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(Document* document, const ScriptObject& context)
+{
+#if ENABLE(INSPECTOR)
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document)) {
+        InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent();
+        if (canvasAgent && canvasAgent->enabled())
+            return canvasAgent->wrapCanvas2DRenderingContextForInstrumentation(context);
+    }
+#endif
+    return ScriptObject();
+}
+
 #if ENABLE(WEBGL)
 ScriptObject InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(Document* document, const ScriptObject& glContext)
 {
index 217d98d..400c443 100644 (file)
@@ -251,6 +251,7 @@ public:
     static void didReceiveWebSocketFrameError(Document*, unsigned long identifier, const String& errorMessage);
 #endif
 
+    static ScriptObject wrapCanvas2DRenderingContextForInstrumentation(Document*, const ScriptObject&);
 #if ENABLE(WEBGL)
     static ScriptObject wrapWebGLRenderingContextForInstrumentation(Document*, const ScriptObject&);
 #endif