| 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" | |
| 37 #include "bindings/core/v8/V8Binding.h" | 36 #include "bindings/core/v8/V8Binding.h" |
| 38 #include "bindings/core/v8/V8DOMActivityLogger.h" | 37 #include "bindings/core/v8/V8DOMActivityLogger.h" |
| 39 #include "bindings/core/v8/V8Document.h" | 38 #include "bindings/core/v8/V8Document.h" |
| 40 #include "bindings/core/v8/V8GCForContextDispose.h" | 39 #include "bindings/core/v8/V8GCForContextDispose.h" |
| 41 #include "bindings/core/v8/V8HTMLCollection.h" | 40 #include "bindings/core/v8/V8HTMLCollection.h" |
| 42 #include "bindings/core/v8/V8HTMLDocument.h" | 41 #include "bindings/core/v8/V8HTMLDocument.h" |
| 43 #include "bindings/core/v8/V8HiddenValue.h" | 42 #include "bindings/core/v8/V8HiddenValue.h" |
| 44 #include "bindings/core/v8/V8Initializer.h" | 43 #include "bindings/core/v8/V8Initializer.h" |
| 45 #include "bindings/core/v8/V8ObjectConstructor.h" | 44 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 46 #include "bindings/core/v8/V8PagePopupControllerBinding.h" | 45 #include "bindings/core/v8/V8PagePopupControllerBinding.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 #include "wtf/Assertions.h" | 66 #include "wtf/Assertions.h" |
| 68 #include "wtf/StringExtras.h" | 67 #include "wtf/StringExtras.h" |
| 69 #include "wtf/text/CString.h" | 68 #include "wtf/text/CString.h" |
| 70 #include <algorithm> | 69 #include <algorithm> |
| 71 #include <utility> | 70 #include <utility> |
| 72 #include <v8-debug.h> | 71 #include <v8-debug.h> |
| 73 #include <v8.h> | 72 #include <v8.h> |
| 74 | 73 |
| 75 namespace blink { | 74 namespace blink { |
| 76 | 75 |
| 76 static void checkDocumentWrapper(v8::Local<v8::Object> wrapper, |
| 77 Document* document) { |
| 78 ASSERT(V8Document::toImpl(wrapper) == document); |
| 79 } |
| 80 |
| 77 WindowProxy* WindowProxy::create(v8::Isolate* isolate, | 81 WindowProxy* WindowProxy::create(v8::Isolate* isolate, |
| 78 Frame* frame, | 82 Frame* frame, |
| 79 DOMWrapperWorld& world) { | 83 DOMWrapperWorld& world) { |
| 80 return new WindowProxy(frame, &world, isolate); | 84 return new WindowProxy(frame, &world, isolate); |
| 81 } | 85 } |
| 82 | 86 |
| 83 WindowProxy::WindowProxy(Frame* frame, | 87 WindowProxy::WindowProxy(Frame* frame, |
| 84 PassRefPtr<DOMWrapperWorld> world, | 88 PassRefPtr<DOMWrapperWorld> world, |
| 85 v8::Isolate* isolate) | 89 v8::Isolate* isolate) |
| 86 : m_frame(frame), m_isolate(isolate), m_world(world) {} | 90 : m_frame(frame), m_isolate(isolate), m_world(world) {} |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, | 410 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, |
| 407 window); | 411 window); |
| 408 | 412 |
| 409 // TODO(keishi): Remove installPagePopupController and implement | 413 // TODO(keishi): Remove installPagePopupController and implement |
| 410 // PagePopupController in another way. | 414 // PagePopupController in another way. |
| 411 V8PagePopupControllerBinding::installPagePopupController(context, | 415 V8PagePopupControllerBinding::installPagePopupController(context, |
| 412 windowWrapper); | 416 windowWrapper); |
| 413 return true; | 417 return true; |
| 414 } | 418 } |
| 415 | 419 |
| 420 void WindowProxy::updateDocumentWrapper(v8::Local<v8::Object> wrapper) { |
| 421 ASSERT(m_world->isMainWorld()); |
| 422 m_document.set(m_isolate, wrapper); |
| 423 } |
| 424 |
| 416 void WindowProxy::updateDocumentProperty() { | 425 void WindowProxy::updateDocumentProperty() { |
| 417 DCHECK(m_world->isMainWorld()); | 426 if (!m_world->isMainWorld()) |
| 427 return; |
| 418 | 428 |
| 419 if (m_frame->isRemoteFrame()) | 429 if (m_frame->isRemoteFrame()) { |
| 420 return; | 430 return; |
| 431 } |
| 421 | 432 |
| 422 ScriptState::Scope scope(m_scriptState.get()); | 433 ScriptState::Scope scope(m_scriptState.get()); |
| 423 v8::Local<v8::Context> context = m_scriptState->context(); | 434 v8::Local<v8::Context> context = m_scriptState->context(); |
| 424 LocalFrame* frame = toLocalFrame(m_frame); | 435 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()); | |
| 430 v8::Local<v8::Value> documentWrapper = | 436 v8::Local<v8::Value> documentWrapper = |
| 431 toV8(frame->document(), context->Global(), m_isolate); | 437 toV8(frame->document(), context->Global(), context->GetIsolate()); |
| 432 DCHECK(documentWrapper->IsObject()); | 438 if (documentWrapper.IsEmpty()) |
| 433 m_document.set(m_isolate, documentWrapper.As<v8::Object>()); | 439 return; |
| 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()); |
| 434 | 447 |
| 435 // Update cached accessor. | 448 // Update cached accessor. |
| 436 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set( | 449 CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set( |
| 437 context, context->Global(), documentWrapper)); | 450 context, context->Global(), documentWrapper)); |
| 438 } | 451 } |
| 439 | 452 |
| 440 void WindowProxy::updateActivityLogger() { | 453 void WindowProxy::updateActivityLogger() { |
| 441 m_scriptState->perContextData()->setActivityLogger( | 454 m_scriptState->perContextData()->setActivityLogger( |
| 442 V8DOMActivityLogger::activityLogger( | 455 V8DOMActivityLogger::activityLogger( |
| 443 m_world->worldId(), | 456 m_world->worldId(), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 504 } |
| 492 token = frameSecurityToken + token; | 505 token = frameSecurityToken + token; |
| 493 } | 506 } |
| 494 | 507 |
| 495 // NOTE: V8 does identity comparison in fast path, must use a symbol | 508 // NOTE: V8 does identity comparison in fast path, must use a symbol |
| 496 // as the security token. | 509 // as the security token. |
| 497 context->SetSecurityToken(v8AtomicString(m_isolate, token)); | 510 context->SetSecurityToken(v8AtomicString(m_isolate, token)); |
| 498 } | 511 } |
| 499 | 512 |
| 500 void WindowProxy::updateDocument() { | 513 void WindowProxy::updateDocument() { |
| 501 DCHECK(m_world->isMainWorld()); | 514 ASSERT(m_world->isMainWorld()); |
| 502 if (!isGlobalInitialized()) | 515 if (!isGlobalInitialized()) |
| 503 return; | 516 return; |
| 504 if (!isContextInitialized()) | 517 if (!isContextInitialized()) |
| 505 return; | 518 return; |
| 506 updateActivityLogger(); | 519 updateActivityLogger(); |
| 507 updateDocumentProperty(); | 520 updateDocumentProperty(); |
| 508 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); | 521 updateSecurityOrigin(m_frame->securityContext()->getSecurityOrigin()); |
| 509 } | 522 } |
| 510 | 523 |
| 511 static v8::Local<v8::Value> getNamedProperty( | 524 static v8::Local<v8::Value> getNamedProperty( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 return; | 561 return; |
| 549 } | 562 } |
| 550 v8::Local<v8::Value> value; | 563 v8::Local<v8::Value> value; |
| 551 if (info.Holder() | 564 if (info.Holder() |
| 552 ->GetRealNamedPropertyInPrototypeChain( | 565 ->GetRealNamedPropertyInPrototypeChain( |
| 553 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>()) | 566 info.GetIsolate()->GetCurrentContext(), property.As<v8::String>()) |
| 554 .ToLocal(&value)) | 567 .ToLocal(&value)) |
| 555 v8SetReturnValue(info, value); | 568 v8SetReturnValue(info, value); |
| 556 } | 569 } |
| 557 | 570 |
| 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 | |
| 566 void WindowProxy::namedItemAdded(HTMLDocument* document, | 571 void WindowProxy::namedItemAdded(HTMLDocument* document, |
| 567 const AtomicString& name) { | 572 const AtomicString& name) { |
| 568 DCHECK(m_world->isMainWorld()); | 573 ASSERT(m_world->isMainWorld()); |
| 569 | 574 |
| 570 if (!isContextInitialized() || !m_scriptState->contextIsValid()) | 575 if (!isContextInitialized() || !m_scriptState->contextIsValid()) |
| 571 return; | 576 return; |
| 572 | 577 |
| 573 ScriptState::Scope scope(m_scriptState.get()); | 578 ScriptState::Scope scope(m_scriptState.get()); |
| 574 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate); | 579 ASSERT(!m_document.isEmpty()); |
| 575 checkDocumentWrapper(documentWrapper, document); | 580 v8::Local<v8::Context> context = m_scriptState->context(); |
| 576 documentWrapper->SetAccessor(m_isolate->GetCurrentContext(), | 581 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); |
| 577 v8String(m_isolate, name), getter); | 582 checkDocumentWrapper(documentHandle, document); |
| 583 documentHandle->SetAccessor(context, v8String(m_isolate, name), getter); |
| 578 } | 584 } |
| 579 | 585 |
| 580 void WindowProxy::namedItemRemoved(HTMLDocument* document, | 586 void WindowProxy::namedItemRemoved(HTMLDocument* document, |
| 581 const AtomicString& name) { | 587 const AtomicString& name) { |
| 582 DCHECK(m_world->isMainWorld()); | 588 ASSERT(m_world->isMainWorld()); |
| 583 | 589 |
| 584 if (!isContextInitialized()) | 590 if (!isContextInitialized()) |
| 585 return; | 591 return; |
| 586 | 592 |
| 587 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) | 593 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) |
| 588 return; | 594 return; |
| 589 | 595 |
| 590 ScriptState::Scope scope(m_scriptState.get()); | 596 ScriptState::Scope scope(m_scriptState.get()); |
| 591 v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate); | 597 ASSERT(!m_document.isEmpty()); |
| 592 checkDocumentWrapper(documentWrapper, document); | 598 v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate); |
| 593 documentWrapper->Delete(m_isolate->GetCurrentContext(), | 599 checkDocumentWrapper(documentHandle, document); |
| 594 v8String(m_isolate, name)); | 600 documentHandle->Delete(m_isolate->GetCurrentContext(), |
| 601 v8String(m_isolate, name)); |
| 595 } | 602 } |
| 596 | 603 |
| 597 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { | 604 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { |
| 598 if (!isContextInitialized()) | 605 if (!isContextInitialized()) |
| 599 return; | 606 return; |
| 600 setSecurityToken(origin); | 607 setSecurityToken(origin); |
| 601 } | 608 } |
| 602 | 609 |
| 603 } // namespace blink | 610 } // namespace blink |
| OLD | NEW |