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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp

Issue 2640123006: Use the current context as the creation context for cross-origin objects. (Closed)
Patch Set: Per-world NewRemoteInstance Created 3 years, 11 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: third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp
index 2134492acdd163242964c52f0d597abadc66f88b..c915cd2ad97e7be37dc71ce73245fa174da77abd 100644
--- a/third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp
@@ -50,6 +50,7 @@
#include "core/frame/ImageBitmap.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
+#include "core/frame/Location.h"
#include "core/frame/Settings.h"
#include "core/frame/UseCounter.h"
#include "core/frame/csp/ContentSecurityPolicy.h"
@@ -64,6 +65,53 @@
namespace blink {
+void V8Window::locationAttributeGetterCustom(
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Object> holder = info.Holder();
+
+ DOMWindow* window = V8Window::toImpl(holder);
+ Location* location = window->location();
+ DCHECK(location);
+
+ // Keep the wrapper object for the return value alive as long as |this|
+ // object is alive in order to save creation time of the wrapper object.
+ if (DOMDataStore::setReturnValue(info.GetReturnValue(), location))
dcheng 2017/01/24 23:12:11 Now that a Location object only exposes a consiste
haraken 2017/01/25 03:24:12 Can we add some dcheck to check that we're returni
dcheng 2017/01/26 02:12:03 Can you elaborate what you mean here? Do you mean
haraken 2017/01/26 05:59:57 Ah, sorry. I realized my comment doesn't make sens
+ return;
+
+ v8::Local<v8::Value> wrapper;
+
+ // Note that this check is gated on whether or not |window| is remote, not
+ // whether or not |window| is cross-origin. If |window| is local, the
+ // |location| property must always return the same wrapper, even if the
+ // cross-origin status changes by changing properties like |document.domain|.
+ if (window->isRemoteDOMWindow()) {
+ DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
+ const auto* wrapperTypeInfo = location->wrapperTypeInfo();
+ v8::Local<v8::Object> newWrapper =
+ wrapperTypeInfo->domTemplate(isolate, world)
+ ->NewRemoteInstance()
+ .ToLocalChecked();
+
+ DCHECK(!DOMDataStore::containsWrapper(location, isolate));
+ wrapper = V8DOMWrapper::associateObjectWithWrapper(
+ isolate, location, wrapperTypeInfo, newWrapper);
+ } else {
+ wrapper = ToV8(location, holder, isolate);
+
+ // Keep the wrapper object for the return value alive as long as |this|
+ // object is alive in order to save creation time of the wrapper object.
dcheng 2017/01/24 23:12:11 I'm not 100% sure about this, but we could try cac
haraken 2017/01/25 03:24:12 Actually this caching is already wrong in many way
dcheng 2017/01/26 02:12:03 I'm trying to understand why this is important. If
haraken 2017/01/26 05:59:57 Imagine that a user sets window.location.foo="aaa"
dcheng 2017/01/26 06:30:19 Ah-ha, I understand now. So the interesting part h
haraken 2017/01/26 09:27:09 It might still be observable when the remote Locat
Yuki 2017/01/26 10:41:53 I'd argue on this point. IIUC, the spec doesn't r
+ const char kKeepAliveKey[] = "KeepAlive#Window#location";
+ V8HiddenValue::setHiddenValue(
+ ScriptState::current(isolate), holder,
+ v8AtomicString(isolate,
+ StringView(kKeepAliveKey, sizeof kKeepAliveKey)),
+ wrapper);
+ }
+
+ v8SetReturnValue(info, wrapper);
+}
+
void V8Window::eventAttributeGetterCustom(
const v8::FunctionCallbackInfo<v8::Value>& info) {
LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder()));

Powered by Google App Engine
This is Rietveld 408576698