Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Unified Diff: Source/web/WebFrameImpl.cpp

Issue 19861006: Allow binding a getter+setter for window object property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Allow binding a getter+setter for window object property. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/web/WebFrameImpl.cpp
diff --git a/Source/web/WebFrameImpl.cpp b/Source/web/WebFrameImpl.cpp
index 095498ecac6391866cc9b81aef2c9634231bd73d..02954a6ec4100cabb559a0bf123a356c7600e623 100644
--- a/Source/web/WebFrameImpl.cpp
+++ b/Source/web/WebFrameImpl.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2013 Opera Software ASA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -81,6 +82,7 @@
#include "V8DOMFileSystem.h"
#include "V8DirectoryEntry.h"
#include "V8FileEntry.h"
+#include "WebBindings.h"
#include "WebConsoleMessage.h"
#include "WebDOMEvent.h"
#include "WebDOMEventListener.h"
@@ -108,6 +110,7 @@
#include "bindings/v8/ScriptSourceCode.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8GCController.h"
+#include "bindings/v8/V8NPUtils.h"
#include "core/dom/Document.h"
#include "core/dom/DocumentMarker.h"
#include "core/dom/DocumentMarkerController.h"
@@ -189,6 +192,7 @@
#include "public/platform/WebSize.h"
#include "public/platform/WebURLError.h"
#include "public/platform/WebVector.h"
+#include "public/web/WebWindowPropertyCallback.h"
#include "weborigin/KURL.h"
#include "weborigin/SchemeRegistry.h"
#include "weborigin/SecurityPolicy.h"
@@ -753,6 +757,38 @@ void WebFrameImpl::bindToWindowObject(const WebString& name, NPObject* object, v
frame()->script()->bindToWindowObject(frame(), String(name), object);
}
+namespace {
+v8::Handle<v8::Value> windowPropertyGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info)
+{
+ v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(info.Data());
+ v8::Isolate* isolate = info.GetIsolate();
+ WebWindowPropertyCallback* callback = static_cast<WebWindowPropertyCallback*>(wrap->Value());
+ NPVariant variantValue;
+ if (!callback->GetValue(&variantValue))
+ return v8::Undefined();
+ v8::Handle<v8::Value> v8Value = WebCore::convertNPVariantToV8Object(&variantValue, 0, isolate);
+ WebBindings::releaseVariantValue(&variantValue);
+ return v8Value;
+}
+
+void windowPropertySetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+{
+ v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(info.Data());
+ WebWindowPropertyCallback* callback = static_cast<WebWindowPropertyCallback*>(wrap->Value());
+ NPVariant variantValue;
+ WebCore::convertV8ObjectToNPVariant(value, 0, &variantValue);
+ callback->SetValue(variantValue);
+ WebBindings::releaseVariantValue(&variantValue);
+}
+} // namespace
+
+void WebFrameImpl::bindToWindowObject(const WebString& name, WebWindowPropertyCallback* callback)
+{
+ if (!frame() || !frame()->script()->canExecuteScripts(NotAboutToExecuteScript))
+ return;
+ frame()->script()->bindToWindowObject(frame(), String(name), windowPropertyGetter, windowPropertySetter, v8::External::New(callback));
+}
+
void WebFrameImpl::executeScript(const WebScriptSource& source)
{
ASSERT(frame());

Powered by Google App Engine
This is Rietveld 408576698