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

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: Synced. 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);
425 // In the main world, the window.document attribute must be set right after
426 // the initialization of the Window or right after the installation of a new
427 // document, thus this must be the first time of the wrapper instantiation of
428 // the document.
429 CHECK(!frame->document()->containsWrapper());
436 v8::Local<v8::Value> documentWrapper = 430 v8::Local<v8::Value> documentWrapper =
437 toV8(frame->document(), context->Global(), context->GetIsolate()); 431 toV8(frame->document(), context->Global(), m_isolate);
438 if (documentWrapper.IsEmpty()) 432 DCHECK(documentWrapper->IsObject());
439 return; 433 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 434
448 // Update cached accessor. 435 // Update cached accessor.
449 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set( 436 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set(
450 context, context->Global(), documentWrapper)); 437 context, context->Global(), documentWrapper));
451 } 438 }
452 439
453 void WindowProxy::updateActivityLogger() { 440 void WindowProxy::updateActivityLogger() {
454 m_scriptState->perContextData()->setActivityLogger( 441 m_scriptState->perContextData()->setActivityLogger(
455 V8DOMActivityLogger::activityLogger( 442 V8DOMActivityLogger::activityLogger(
456 m_world->worldId(), 443 m_world->worldId(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 491 }
505 token = frameSecurityToken + token; 492 token = frameSecurityToken + token;
506 } 493 }
507 494
508 // NOTE: V8 does identity comparison in fast path, must use a symbol 495 // NOTE: V8 does identity comparison in fast path, must use a symbol
509 // as the security token. 496 // as the security token.
510 context->SetSecurityToken(v8AtomicString(m_isolate, token)); 497 context->SetSecurityToken(v8AtomicString(m_isolate, token));
511 } 498 }
512 499
513 void WindowProxy::updateDocument() { 500 void WindowProxy::updateDocument() {
514 ASSERT(m_world->isMainWorld()); 501 DCHECK(m_world->isMainWorld());
515 if (!isGlobalInitialized()) 502 if (!isGlobalInitialized())
516 return; 503 return;
517 if (!isContextInitialized()) 504 if (!isContextInitialized())
518 return; 505 return;
519 updateActivityLogger(); 506 updateActivityLogger();
520 updateDocumentProperty(); 507 updateDocumentProperty();
521 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); 508 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin());
522 } 509 }
523 510
524 static v8::Local<v8::Value> getNamedProperty( 511 static v8::Local<v8::Value> getNamedProperty(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return; 548 return;
562 } 549 }
563 v8::Local<v8::Value> value; 550 v8::Local<v8::Value> value;
564 if (info.Holder() 551 if (info.Holder()
565 ->GetRealNamedPropertyInPrototypeChain( 552 ->GetRealNamedPropertyInPrototypeChain(
566 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>()) 553 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>())
567 .ToLocal(&value)) 554 .ToLocal(&value))
568 v8SetReturnValue(info, value); 555 v8SetReturnValue(info, value);
569 } 556 }
570 557
558 void WindowProxy::checkDocumentWrapper(v8::Local<v8::Object> wrapper,
559 Document* document) const {
560 DCHECK(!wrapper.IsEmpty());
561 DCHECK_EQ(V8Document::toImpl(wrapper), document);
562 DCHECK(wrapper ==
563 toV8(document, m_globalProxy.newLocal(m_isolate), m_isolate));
564 }
565
571 void WindowProxy::namedItemAdded(HTMLDocument* document, 566 void WindowProxy::namedItemAdded(HTMLDocument* document,
572 const AtomicString& name) { 567 const AtomicString& name) {
573 ASSERT(m_world->isMainWorld()); 568 DCHECK(m_world->isMainWorld());
574 569
575 if (!isContextInitialized() || !m_scriptState->contextIsValid()) 570 if (!isContextInitialized() || !m_scriptState->contextIsValid())
576 return; 571 return;
577 572
578 ScriptState::Scope scope(m_scriptState.get()); 573 ScriptState::Scope scope(m_scriptState.get());
579 ASSERT(!m_document.isEmpty()); 574 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate);
580 v8::Local<v8::Context> context = m_scriptState->context(); 575 checkDocumentWrapper(documentWrapper, document);
581 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); 576 documentWrapper->SetAccessor(m_isolate->GetCurrentContext(),
582 checkDocumentWrapper(documentHandle, document); 577 v8String(m_isolate, name), getter);
583 documentHandle->SetAccessor(context, v8String(m_isolate, name), getter);
584 } 578 }
585 579
586 void WindowProxy::namedItemRemoved(HTMLDocument* document, 580 void WindowProxy::namedItemRemoved(HTMLDocument* document,
587 const AtomicString& name) { 581 const AtomicString& name) {
588 ASSERT(m_world->isMainWorld()); 582 DCHECK(m_world->isMainWorld());
589 583
590 if (!isContextInitialized()) 584 if (!isContextInitialized())
591 return; 585 return;
592 586
593 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) 587 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name))
594 return; 588 return;
595 589
596 ScriptState::Scope scope(m_scriptState.get()); 590 ScriptState::Scope scope(m_scriptState.get());
597 ASSERT(!m_document.isEmpty()); 591 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate);
598 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); 592 checkDocumentWrapper(documentWrapper, document);
599 checkDocumentWrapper(documentHandle, document); 593 documentWrapper->Delete(m_isolate->GetCurrentContext(),
600 documentHandle->Delete(m_isolate->GetCurrentContext(), 594 v8String(m_isolate, name));
601 v8String(m_isolate, name));
602 } 595 }
603 596
604 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { 597 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) {
605 if (!isContextInitialized()) 598 if (!isContextInitialized())
606 return; 599 return;
607 setSecurityToken(origin); 600 setSecurityToken(origin);
608 } 601 }
609 602
610 } // namespace blink 603 } // 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