Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, | 413 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, | 
| 418 window); | 414 window); | 
| 419 | 415 | 
| 420 // TODO(keishi): Remove installPagePopupController and implement | 416 // TODO(keishi): Remove installPagePopupController and implement | 
| 421 // PagePopupController in another way. | 417 // PagePopupController in another way. | 
| 422 V8PagePopupControllerBinding::installPagePopupController(context, | 418 V8PagePopupControllerBinding::installPagePopupController(context, | 
| 423 windowWrapper); | 419 windowWrapper); | 
| 424 return true; | 420 return true; | 
| 425 } | 421 } | 
| 426 | 422 | 
| 427 void WindowProxy::updateDocumentWrapper(v8::Local<v8::Object> wrapper) { | 423 void WindowProxy::updateDocumentProperty() { | 
| 428 ASSERT(m_world->isMainWorld()); | 424 DCHECK(m_world->isMainWorld()); | 
| 429 m_document.set(m_isolate, wrapper); | |
| 430 } | |
| 431 | 425 | 
| 432 void WindowProxy::updateDocumentProperty() { | 426 if (m_frame->isRemoteFrame()) | 
| 433 if (!m_world->isMainWorld()) | |
| 434 return; | 427 return; | 
| 435 | 428 | 
| 436 if (m_frame->isRemoteFrame()) { | |
| 437 return; | |
| 438 } | |
| 439 | |
| 440 ScriptState::Scope scope(m_scriptState.get()); | 429 ScriptState::Scope scope(m_scriptState.get()); | 
| 441 v8::Local<v8::Context> context = m_scriptState->context(); | 430 v8::Local<v8::Context> context = m_scriptState->context(); | 
| 442 LocalFrame* frame = toLocalFrame(m_frame); | 431 LocalFrame* frame = toLocalFrame(m_frame); | 
| 432 // In the main world, the window.document attribute must be set right after | |
| 433 // the initialization of the Window or right after the installation of a new | |
| 434 // document, thus this must be the first time of the wrapper instantiation of | |
| 435 // the document. | |
| 436 CHECK(!frame->document()->containsWrapper()); | |
| 
 
Yuki
2016/12/02 09:08:06
This CHECK and comment are wrong.  We can create a
 
 | |
| 443 v8::Local<v8::Value> documentWrapper = | 437 v8::Local<v8::Value> documentWrapper = | 
| 444 toV8(frame->document(), context->Global(), context->GetIsolate()); | 438 toV8(frame->document(), context->Global(), m_isolate); | 
| 445 if (documentWrapper.IsEmpty()) | 439 DCHECK(documentWrapper->IsObject()); | 
| 446 return; | 440 m_document.set(m_isolate, documentWrapper.As<v8::Object>()); | 
| 447 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || | |
| 448 m_document.isEmpty()); | |
| 449 if (m_document.isEmpty()) | |
| 450 updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper)); | |
| 451 checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document()); | |
| 452 | |
| 453 ASSERT(documentWrapper->IsObject()); | |
| 454 | 441 | 
| 455 // Update cached accessor. | 442 // Update cached accessor. | 
| 456 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set( | 443 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set( | 
| 457 context, context->Global(), documentWrapper)); | 444 context, context->Global(), documentWrapper)); | 
| 458 } | 445 } | 
| 459 | 446 | 
| 460 void WindowProxy::updateActivityLogger() { | 447 void WindowProxy::updateActivityLogger() { | 
| 461 m_scriptState->perContextData()->setActivityLogger( | 448 m_scriptState->perContextData()->setActivityLogger( | 
| 462 V8DOMActivityLogger::activityLogger( | 449 V8DOMActivityLogger::activityLogger( | 
| 463 m_world->worldId(), | 450 m_world->worldId(), | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 } | 498 } | 
| 512 token = frameSecurityToken + token; | 499 token = frameSecurityToken + token; | 
| 513 } | 500 } | 
| 514 | 501 | 
| 515 // NOTE: V8 does identity comparison in fast path, must use a symbol | 502 // NOTE: V8 does identity comparison in fast path, must use a symbol | 
| 516 // as the security token. | 503 // as the security token. | 
| 517 context->SetSecurityToken(v8AtomicString(m_isolate, token)); | 504 context->SetSecurityToken(v8AtomicString(m_isolate, token)); | 
| 518 } | 505 } | 
| 519 | 506 | 
| 520 void WindowProxy::updateDocument() { | 507 void WindowProxy::updateDocument() { | 
| 521 ASSERT(m_world->isMainWorld()); | 508 DCHECK(m_world->isMainWorld()); | 
| 522 if (!isGlobalInitialized()) | 509 if (!isGlobalInitialized()) | 
| 523 return; | 510 return; | 
| 524 if (!isContextInitialized()) | 511 if (!isContextInitialized()) | 
| 525 return; | 512 return; | 
| 526 updateActivityLogger(); | 513 updateActivityLogger(); | 
| 527 updateDocumentProperty(); | 514 updateDocumentProperty(); | 
| 528 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); | 515 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); | 
| 529 } | 516 } | 
| 530 | 517 | 
| 531 static v8::Local<v8::Value> getNamedProperty( | 518 static v8::Local<v8::Value> getNamedProperty( | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 return; | 555 return; | 
| 569 } | 556 } | 
| 570 v8::Local<v8::Value> value; | 557 v8::Local<v8::Value> value; | 
| 571 if (info.Holder() | 558 if (info.Holder() | 
| 572 ->GetRealNamedPropertyInPrototypeChain( | 559 ->GetRealNamedPropertyInPrototypeChain( | 
| 573 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>()) | 560 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>()) | 
| 574 .ToLocal(&value)) | 561 .ToLocal(&value)) | 
| 575 v8SetReturnValue(info, value); | 562 v8SetReturnValue(info, value); | 
| 576 } | 563 } | 
| 577 | 564 | 
| 565 void WindowProxy::checkDocumentWrapper(v8::Local<v8::Object> wrapper, | |
| 566 Document* document) const { | |
| 567 DCHECK(!wrapper.IsEmpty()); | |
| 568 DCHECK_EQ(V8Document::toImpl(wrapper), document); | |
| 569 DCHECK(wrapper == | |
| 570 toV8(document, m_globalProxy.newLocal(m_isolate), m_isolate)); | |
| 571 } | |
| 572 | |
| 578 void WindowProxy::namedItemAdded(HTMLDocument* document, | 573 void WindowProxy::namedItemAdded(HTMLDocument* document, | 
| 579 const AtomicString& name) { | 574 const AtomicString& name) { | 
| 580 ASSERT(m_world->isMainWorld()); | 575 DCHECK(m_world->isMainWorld()); | 
| 581 | 576 | 
| 582 if (!isContextInitialized() || !m_scriptState->contextIsValid()) | 577 if (!isContextInitialized() || !m_scriptState->contextIsValid()) | 
| 583 return; | 578 return; | 
| 584 | 579 | 
| 585 ScriptState::Scope scope(m_scriptState.get()); | 580 ScriptState::Scope scope(m_scriptState.get()); | 
| 586 ASSERT(!m_document.isEmpty()); | 581 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate); | 
| 587 v8::Local<v8::Context> context = m_scriptState->context(); | 582 checkDocumentWrapper(documentWrapper, document); | 
| 588 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); | 583 documentWrapper->SetAccessor(m_isolate->GetCurrentContext(), | 
| 589 checkDocumentWrapper(documentHandle, document); | 584 v8String(m_isolate, name), getter); | 
| 590 documentHandle->SetAccessor(context, v8String(m_isolate, name), getter); | |
| 591 } | 585 } | 
| 592 | 586 | 
| 593 void WindowProxy::namedItemRemoved(HTMLDocument* document, | 587 void WindowProxy::namedItemRemoved(HTMLDocument* document, | 
| 594 const AtomicString& name) { | 588 const AtomicString& name) { | 
| 595 ASSERT(m_world->isMainWorld()); | 589 DCHECK(m_world->isMainWorld()); | 
| 596 | 590 | 
| 597 if (!isContextInitialized()) | 591 if (!isContextInitialized()) | 
| 598 return; | 592 return; | 
| 599 | 593 | 
| 600 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) | 594 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) | 
| 601 return; | 595 return; | 
| 602 | 596 | 
| 603 ScriptState::Scope scope(m_scriptState.get()); | 597 ScriptState::Scope scope(m_scriptState.get()); | 
| 604 ASSERT(!m_document.isEmpty()); | 598 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate); | 
| 605 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); | 599 checkDocumentWrapper(documentWrapper, document); | 
| 606 checkDocumentWrapper(documentHandle, document); | 600 documentWrapper->Delete(m_isolate->GetCurrentContext(), | 
| 607 documentHandle->Delete(m_isolate->GetCurrentContext(), | 601 v8String(m_isolate, name)); | 
| 608 v8String(m_isolate, name)); | |
| 609 } | 602 } | 
| 610 | 603 | 
| 611 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { | 604 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { | 
| 612 if (!isContextInitialized()) | 605 if (!isContextInitialized()) | 
| 613 return; | 606 return; | 
| 614 setSecurityToken(origin); | 607 setSecurityToken(origin); | 
| 615 } | 608 } | 
| 616 | 609 | 
| 617 } // namespace blink | 610 } // namespace blink | 
| OLD | NEW |