[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.18-1-697-g2f78b87
yurys at chromium.org
yurys at chromium.org
Wed Jan 20 22:20:42 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 7ccc3303fe868354363c912c03160a4890848abb
Author: yurys at chromium.org <yurys at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Jan 12 12:41:42 2010 +0000
2010-01-12 Yury Semikhatsky <yurys at chromium.org>
Reviewed by Pavel Feldman.
Support injection of inspector scripts into the inspected context.
https://bugs.webkit.org/show_bug.cgi?id=33523
* bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
(WebCore::WeakReferenceCallback):
(WebCore::createInjectedScriptHostV8Wrapper):
(WebCore::createInjectedScript):
(WebCore::InjectedScriptHost::injectedScriptFor):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53135 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c8bbb80..edfe4dd 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,17 @@
+2010-01-12 Yury Semikhatsky <yurys at chromium.org>
+
+ Reviewed by Pavel Feldman.
+
+ Support injection of inspector scripts into the inspected context.
+
+ https://bugs.webkit.org/show_bug.cgi?id=33523
+
+ * bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
+ (WebCore::WeakReferenceCallback):
+ (WebCore::createInjectedScriptHostV8Wrapper):
+ (WebCore::createInjectedScript):
+ (WebCore::InjectedScriptHost::injectedScriptFor):
+
2010-01-12 Ben Murdoch <benm at google.com>
Reviewed by Darin Adler.
diff --git a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
index 36c32c8..a98d299 100644
--- a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
+++ b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
@@ -31,8 +31,8 @@
#include "config.h"
#include "V8InjectedScriptHost.h"
-#include "Database.h"
#include "DOMWindow.h"
+#include "Database.h"
#include "Frame.h"
#include "InjectedScriptHost.h"
#include "InspectorController.h"
@@ -45,6 +45,72 @@
namespace WebCore {
+static void WeakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter)
+{
+ InjectedScriptHost* nativeObject = static_cast<InjectedScriptHost*>(parameter);
+ nativeObject->deref();
+ object.Dispose();
+}
+
+static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHost* host)
+{
+ V8ClassIndex::V8WrapperType descriptorType = V8ClassIndex::INJECTEDSCRIPTHOST;
+ v8::Local<v8::Function> function = V8DOMWrapper::getTemplate(descriptorType)->GetFunction();
+ if (function.IsEmpty()) {
+ // Return if allocation failed.
+ return v8::Local<v8::Object>();
+ }
+ v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+ if (instance.IsEmpty()) {
+ // Avoid setting the wrapper if allocation failed.
+ return v8::Local<v8::Object>();
+ }
+ V8DOMWrapper::setDOMWrapper(instance, V8ClassIndex::ToInt(descriptorType), host);
+ // Create a weak reference to the v8 wrapper of InspectorBackend to deref
+ // InspectorBackend when the wrapper is garbage collected.
+ host->ref();
+ v8::Persistent<v8::Object> weakHandle = v8::Persistent<v8::Object>::New(instance);
+ weakHandle.MakeWeak(host, &WeakReferenceCallback);
+ return instance;
+}
+
+static ScriptObject createInjectedScript(const String& scriptSource, InjectedScriptHost* injectedScriptHost, ScriptState* inspectedScriptState, long id)
+{
+ v8::HandleScope scope;
+
+ v8::Local<v8::Context> inspectedContext = inspectedScriptState->context();
+ v8::Context::Scope contextScope(inspectedContext);
+
+ // Call custom code to create InjectedScripHost wrapper specific for the context
+ // instead of calling V8DOMWrapper::convertToV8Object that would create the
+ // wrapper in the current context.
+ // FIXME: make it possible to use generic bindings factory for InjectedScriptHost.
+ v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(injectedScriptHost);
+ if (scriptHostWrapper.IsEmpty())
+ return ScriptObject();
+
+ v8::Local<v8::Object> windowGlobal = inspectedContext->Global();
+
+ // Inject javascript into the context. The compiled script is supposed to evaluate into
+ // a single anonymous function(it's anonymous to avoid cluttering the global object with
+ // inspector's stuff) the function is called a few lines below with InjectedScriptHost wrapper,
+ // injected script id and explicit reference to the inspected global object. The function is expected
+ // to create and configure InjectedScript instance that is going to be used by the inspector.
+ v8::Local<v8::Script> script = v8::Script::Compile(v8String(scriptSource));
+ v8::Local<v8::Value> v = script->Run();
+ ASSERT(!v.IsEmpty());
+ ASSERT(v->IsFunction());
+
+ v8::Handle<v8::Value> args[] = {
+ scriptHostWrapper,
+ windowGlobal,
+ v8::Number::New(id)
+ };
+ v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 3, args);
+ v8::Local<v8::Object> injectedScript(v8::Object::Cast(*injectedScriptValue));
+ return ScriptObject(inspectedScriptState, injectedScript);
+}
+
v8::Handle<v8::Value> V8InjectedScriptHost::inspectedWindowCallback(const v8::Arguments& args)
{
INC_STATS("InjectedScriptHost.inspectedWindow()");
@@ -162,4 +228,28 @@ v8::Handle<v8::Value> V8InjectedScriptHost::selectDOMStorageCallback(const v8::A
}
#endif
+ScriptObject InjectedScriptHost::injectedScriptFor(ScriptState* inspectedScriptState)
+{
+ v8::HandleScope handleScope;
+ v8::Local<v8::Context> context = inspectedScriptState->context();
+ v8::Context::Scope contextScope(context);
+
+ v8::Local<v8::Object> global = context->Global();
+ // Skip proxy object. The proxy object will survive page navigation while we need
+ // an object whose lifetime consides with that of the inspected context.
+ global = v8::Local<v8::Object>::Cast(global->GetPrototype());
+
+ v8::Local<v8::String> key = v8::String::New("Devtools_InjectedScript");
+ v8::Local<v8::Value> val = global->GetHiddenValue(key);
+ if (!val.IsEmpty() && val->IsObject())
+ return ScriptObject(inspectedScriptState, v8::Local<v8::Object>::Cast(val));
+
+ ASSERT(!m_injectedScriptSource.isEmpty());
+ ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSource, this, inspectedScriptState, m_nextInjectedScriptId);
+ m_idToInjectedScript.set(m_nextInjectedScriptId, injectedScriptObject);
+ ++m_nextInjectedScriptId;
+ global->SetHiddenValue(key, injectedScriptObject.v8Object());
+ return injectedScriptObject;
+}
+
} // namespace WebCore
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list