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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp

Issue 2525313004: binding: Removes Document::wrap that must be equivalent to Node::wrap. (Closed)
Patch Set: . Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "bindings/core/v8/WindowProxy.h" 31 #include "bindings/core/v8/WindowProxy.h"
32 32
33 #include "bindings/core/v8/ConditionalFeatures.h" 33 #include "bindings/core/v8/ConditionalFeatures.h"
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScriptController.h" 35 #include "bindings/core/v8/ScriptController.h"
36 #include "bindings/core/v8/ToV8.h"
36 #include "bindings/core/v8/V8Binding.h" 37 #include "bindings/core/v8/V8Binding.h"
37 #include "bindings/core/v8/V8DOMActivityLogger.h" 38 #include "bindings/core/v8/V8DOMActivityLogger.h"
38 #include "bindings/core/v8/V8Document.h" 39 #include "bindings/core/v8/V8Document.h"
39 #include "bindings/core/v8/V8GCForContextDispose.h" 40 #include "bindings/core/v8/V8GCForContextDispose.h"
40 #include "bindings/core/v8/V8HTMLCollection.h" 41 #include "bindings/core/v8/V8HTMLCollection.h"
41 #include "bindings/core/v8/V8HTMLDocument.h" 42 #include "bindings/core/v8/V8HTMLDocument.h"
42 #include "bindings/core/v8/V8HiddenValue.h" 43 #include "bindings/core/v8/V8HiddenValue.h"
43 #include "bindings/core/v8/V8Initializer.h" 44 #include "bindings/core/v8/V8Initializer.h"
44 #include "bindings/core/v8/V8ObjectConstructor.h" 45 #include "bindings/core/v8/V8ObjectConstructor.h"
45 #include "bindings/core/v8/V8PagePopupControllerBinding.h" 46 #include "bindings/core/v8/V8PagePopupControllerBinding.h"
(...skipping 20 matching lines...) Expand all
66 #include "wtf/Assertions.h" 67 #include "wtf/Assertions.h"
67 #include "wtf/StringExtras.h" 68 #include "wtf/StringExtras.h"
68 #include "wtf/text/CString.h" 69 #include "wtf/text/CString.h"
69 #include <algorithm> 70 #include <algorithm>
70 #include <utility> 71 #include <utility>
71 #include <v8-debug.h> 72 #include <v8-debug.h>
72 #include <v8.h> 73 #include <v8.h>
73 74
74 namespace blink { 75 namespace blink {
75 76
76 static void checkDocumentWrapper(v8::Local<v8::Object> wrapper,
77 Document* document) {
78 ASSERT(V8Document::toImpl(wrapper) == document);
79 }
80
81 WindowProxy* WindowProxy::create(v8::Isolate* isolate, 77 WindowProxy* WindowProxy::create(v8::Isolate* isolate,
82 Frame* frame, 78 Frame* frame,
83 DOMWrapperWorld& world) { 79 DOMWrapperWorld& world) {
84 return new WindowProxy(frame, &world, isolate); 80 return new WindowProxy(frame, &world, isolate);
85 } 81 }
86 82
87 WindowProxy::WindowProxy(Frame* frame, 83 WindowProxy::WindowProxy(Frame* frame,
88 PassRefPtr<DOMWrapperWorld> world, 84 PassRefPtr<DOMWrapperWorld> world,
89 v8::Isolate* isolate) 85 v8::Isolate* isolate)
90 : m_frame(frame), m_isolate(isolate), m_world(world) {} 86 : m_frame(frame), m_isolate(isolate), m_world(world) {}
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, 406 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo,
411 window); 407 window);
412 408
413 // TODO(keishi): Remove installPagePopupController and implement 409 // TODO(keishi): Remove installPagePopupController and implement
414 // PagePopupController in another way. 410 // PagePopupController in another way.
415 V8PagePopupControllerBinding::installPagePopupController(context, 411 V8PagePopupControllerBinding::installPagePopupController(context,
416 windowWrapper); 412 windowWrapper);
417 return true; 413 return true;
418 } 414 }
419 415
420 void WindowProxy::updateDocumentWrapper(v8::Local<v8::Object> wrapper) { 416 void WindowProxy::updateDocumentProperty() {
421 ASSERT(m_world->isMainWorld()); 417 DCHECK(m_world->isMainWorld());
422 m_document.set(m_isolate, wrapper);
423 }
424 418
425 void WindowProxy::updateDocumentProperty() { 419 if (m_frame->isRemoteFrame())
426 if (!m_world->isMainWorld())
427 return; 420 return;
428 421
429 if (m_frame->isRemoteFrame()) {
430 return;
431 }
432
433 ScriptState::Scope scope(m_scriptState.get()); 422 ScriptState::Scope scope(m_scriptState.get());
434 v8::Local<v8::Context> context = m_scriptState->context(); 423 v8::Local<v8::Context> context = m_scriptState->context();
435 LocalFrame* frame = toLocalFrame(m_frame); 424 LocalFrame* frame = toLocalFrame(m_frame);
436 v8::Local<v8::Value> documentWrapper = 425 v8::Local<v8::Value> documentWrapper =
437 toV8(frame->document(), context->Global(), context->GetIsolate()); 426 toV8(frame->document(), context->Global(), m_isolate);
haraken 2016/11/25 15:52:30 Just to confirm: If someone calls toV8(document) b
Yuki 2016/11/28 06:35:52 Yes, it shouldn't happen for the main world.
438 if (documentWrapper.IsEmpty()) 427 DCHECK(documentWrapper->IsObject());
haraken 2016/11/25 15:52:30 Shall we call checkDocumentWrapper?
Yuki 2016/11/28 06:35:52 It's meaningless, I think? documentWrapper =
439 return; 428 m_document.set(m_isolate, documentWrapper.As<v8::Object>());
440 ASSERT(documentWrapper == m_document.newLocal(m_isolate) ||
441 m_document.isEmpty());
442 if (m_document.isEmpty())
443 updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper));
444 checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document());
445
446 ASSERT(documentWrapper->IsObject());
447 429
448 // Update cached accessor. 430 // Update cached accessor.
449 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set( 431 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set(
450 context, context->Global(), documentWrapper)); 432 context, context->Global(), documentWrapper));
451 } 433 }
452 434
453 void WindowProxy::updateActivityLogger() { 435 void WindowProxy::updateActivityLogger() {
454 m_scriptState->perContextData()->setActivityLogger( 436 m_scriptState->perContextData()->setActivityLogger(
455 V8DOMActivityLogger::activityLogger( 437 V8DOMActivityLogger::activityLogger(
456 m_world->worldId(), 438 m_world->worldId(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 486 }
505 token = frameSecurityToken + token; 487 token = frameSecurityToken + token;
506 } 488 }
507 489
508 // NOTE: V8 does identity comparison in fast path, must use a symbol 490 // NOTE: V8 does identity comparison in fast path, must use a symbol
509 // as the security token. 491 // as the security token.
510 context->SetSecurityToken(v8AtomicString(m_isolate, token)); 492 context->SetSecurityToken(v8AtomicString(m_isolate, token));
511 } 493 }
512 494
513 void WindowProxy::updateDocument() { 495 void WindowProxy::updateDocument() {
514 ASSERT(m_world->isMainWorld()); 496 DCHECK(m_world->isMainWorld());
515 if (!isGlobalInitialized()) 497 if (!isGlobalInitialized())
516 return; 498 return;
517 if (!isContextInitialized()) 499 if (!isContextInitialized())
518 return; 500 return;
519 updateActivityLogger(); 501 updateActivityLogger();
520 updateDocumentProperty(); 502 updateDocumentProperty();
521 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); 503 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin());
522 } 504 }
523 505
524 static v8::Local<v8::Value> getNamedProperty( 506 static v8::Local<v8::Value> getNamedProperty(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return; 543 return;
562 } 544 }
563 v8::Local<v8::Value> value; 545 v8::Local<v8::Value> value;
564 if (info.Holder() 546 if (info.Holder()
565 ->GetRealNamedPropertyInPrototypeChain( 547 ->GetRealNamedPropertyInPrototypeChain(
566 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>()) 548 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>())
567 .ToLocal(&value)) 549 .ToLocal(&value))
568 v8SetReturnValue(info, value); 550 v8SetReturnValue(info, value);
569 } 551 }
570 552
553 void WindowProxy::checkDocumentWrapper(v8::Local<v8::Object> wrapper,
554 Document* document) const {
555 DCHECK(!wrapper.IsEmpty());
556 DCHECK_EQ(V8Document::toImpl(wrapper), document);
557 DCHECK(wrapper ==
558 toV8(document, m_globalProxy.newLocal(m_isolate), m_isolate));
559 }
560
571 void WindowProxy::namedItemAdded(HTMLDocument* document, 561 void WindowProxy::namedItemAdded(HTMLDocument* document,
572 const AtomicString& name) { 562 const AtomicString& name) {
573 ASSERT(m_world->isMainWorld()); 563 DCHECK(m_world->isMainWorld());
574 564
575 if (!isContextInitialized() || !m_scriptState->contextIsValid()) 565 if (!isContextInitialized() || !m_scriptState->contextIsValid())
576 return; 566 return;
577 567
578 ScriptState::Scope scope(m_scriptState.get()); 568 ScriptState::Scope scope(m_scriptState.get());
579 ASSERT(!m_document.isEmpty()); 569 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate);
580 v8::Local<v8::Context> context = m_scriptState->context(); 570 checkDocumentWrapper(documentWrapper, document);
581 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); 571 documentWrapper->SetAccessor(m_isolate->GetCurrentContext(),
582 checkDocumentWrapper(documentHandle, document); 572 v8String(m_isolate, name), getter);
583 documentHandle->SetAccessor(context, v8String(m_isolate, name), getter);
584 } 573 }
585 574
586 void WindowProxy::namedItemRemoved(HTMLDocument* document, 575 void WindowProxy::namedItemRemoved(HTMLDocument* document,
587 const AtomicString& name) { 576 const AtomicString& name) {
588 ASSERT(m_world->isMainWorld()); 577 DCHECK(m_world->isMainWorld());
589 578
590 if (!isContextInitialized()) 579 if (!isContextInitialized())
591 return; 580 return;
592 581
593 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) 582 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name))
594 return; 583 return;
595 584
596 ScriptState::Scope scope(m_scriptState.get()); 585 ScriptState::Scope scope(m_scriptState.get());
597 ASSERT(!m_document.isEmpty()); 586 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate);
598 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); 587 checkDocumentWrapper(documentWrapper, document);
599 checkDocumentWrapper(documentHandle, document); 588 documentWrapper->Delete(m_isolate->GetCurrentContext(),
600 documentHandle->Delete(m_isolate->GetCurrentContext(), 589 v8String(m_isolate, name));
601 v8String(m_isolate, name));
602 } 590 }
603 591
604 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { 592 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) {
605 if (!isContextInitialized()) 593 if (!isContextInitialized())
606 return; 594 return;
607 setSecurityToken(origin); 595 setSecurityToken(origin);
608 } 596 }
609 597
610 } // namespace blink 598 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/WindowProxy.h ('k') | third_party/WebKit/Source/core/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698