| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 #include "public/platform/WebScreenInfo.h" | 76 #include "public/platform/WebScreenInfo.h" |
| 77 | 77 |
| 78 namespace blink { | 78 namespace blink { |
| 79 | 79 |
| 80 LocalDOMWindow::WindowFrameObserver::WindowFrameObserver(LocalDOMWindow* window,
LocalFrame& frame) | 80 LocalDOMWindow::WindowFrameObserver::WindowFrameObserver(LocalDOMWindow* window,
LocalFrame& frame) |
| 81 : LocalFrameLifecycleObserver(&frame) | 81 : LocalFrameLifecycleObserver(&frame) |
| 82 , m_window(window) | 82 , m_window(window) |
| 83 { | 83 { |
| 84 } | 84 } |
| 85 | 85 |
| 86 PassOwnPtrWillBeRawPtr<LocalDOMWindow::WindowFrameObserver> LocalDOMWindow::Wind
owFrameObserver::create(LocalDOMWindow* window, LocalFrame& frame) | 86 RawPtr<LocalDOMWindow::WindowFrameObserver> LocalDOMWindow::WindowFrameObserver:
:create(LocalDOMWindow* window, LocalFrame& frame) |
| 87 { | 87 { |
| 88 return adoptPtrWillBeNoop(new WindowFrameObserver(window, frame)); | 88 return (new WindowFrameObserver(window, frame)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 #if !ENABLE(OILPAN) | 91 #if !ENABLE(OILPAN) |
| 92 LocalDOMWindow::WindowFrameObserver::~WindowFrameObserver() | 92 LocalDOMWindow::WindowFrameObserver::~WindowFrameObserver() |
| 93 { | 93 { |
| 94 } | 94 } |
| 95 #endif | 95 #endif |
| 96 | 96 |
| 97 DEFINE_TRACE(LocalDOMWindow::WindowFrameObserver) | 97 DEFINE_TRACE(LocalDOMWindow::WindowFrameObserver) |
| 98 { | 98 { |
| 99 visitor->trace(m_window); | 99 visitor->trace(m_window); |
| 100 LocalFrameLifecycleObserver::trace(visitor); | 100 LocalFrameLifecycleObserver::trace(visitor); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void LocalDOMWindow::WindowFrameObserver::willDetachFrameHost() | 103 void LocalDOMWindow::WindowFrameObserver::willDetachFrameHost() |
| 104 { | 104 { |
| 105 m_window->willDetachFrameHost(); | 105 m_window->willDetachFrameHost(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void LocalDOMWindow::WindowFrameObserver::contextDestroyed() | 108 void LocalDOMWindow::WindowFrameObserver::contextDestroyed() |
| 109 { | 109 { |
| 110 m_window->frameDestroyed(); | 110 m_window->frameDestroyed(); |
| 111 LocalFrameLifecycleObserver::contextDestroyed(); | 111 LocalFrameLifecycleObserver::contextDestroyed(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 class PostMessageTimer final : public NoBaseWillBeGarbageCollectedFinalized<Post
MessageTimer>, public SuspendableTimer { | 114 class PostMessageTimer final : public GarbageCollectedFinalized<PostMessageTimer
>, public SuspendableTimer { |
| 115 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer); | 115 USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer); |
| 116 public: | 116 public: |
| 117 PostMessageTimer(LocalDOMWindow& window, PassRefPtrWillBeRawPtr<MessageEvent
> event, PassRefPtrWillBeRawPtr<LocalDOMWindow> source, SecurityOrigin* targetOr
igin, PassRefPtr<ScriptCallStack> stackTrace, UserGestureToken* userGestureToken
) | 117 PostMessageTimer(LocalDOMWindow& window, RawPtr<MessageEvent> event, RawPtr<
LocalDOMWindow> source, SecurityOrigin* targetOrigin, PassRefPtr<ScriptCallStack
> stackTrace, UserGestureToken* userGestureToken) |
| 118 : SuspendableTimer(window.document()) | 118 : SuspendableTimer(window.document()) |
| 119 , m_event(event) | 119 , m_event(event) |
| 120 , m_window(&window) | 120 , m_window(&window) |
| 121 , m_targetOrigin(targetOrigin) | 121 , m_targetOrigin(targetOrigin) |
| 122 , m_stackTrace(stackTrace) | 122 , m_stackTrace(stackTrace) |
| 123 , m_userGestureToken(userGestureToken) | 123 , m_userGestureToken(userGestureToken) |
| 124 , m_preventDestruction(false) | 124 , m_preventDestruction(false) |
| 125 { | 125 { |
| 126 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti
ng(executionContext(), "postMessage"); | 126 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti
ng(executionContext(), "postMessage"); |
| 127 } | 127 } |
| 128 | 128 |
| 129 PassRefPtrWillBeRawPtr<MessageEvent> event() const { return m_event.get(); } | 129 RawPtr<MessageEvent> event() const { return m_event.get(); } |
| 130 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } | 130 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } |
| 131 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); } | 131 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); } |
| 132 UserGestureToken* userGestureToken() const { return m_userGestureToken.get()
; } | 132 UserGestureToken* userGestureToken() const { return m_userGestureToken.get()
; } |
| 133 void stop() override | 133 void stop() override |
| 134 { | 134 { |
| 135 SuspendableTimer::stop(); | 135 SuspendableTimer::stop(); |
| 136 | 136 |
| 137 if (!m_preventDestruction) { | 137 if (!m_preventDestruction) { |
| 138 // Will destroy this object | 138 // Will destroy this object |
| 139 m_window->removePostMessageTimer(this); | 139 m_window->removePostMessageTimer(this); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 158 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA
syncOperationCompletedCallbackStarting(executionContext(), m_asyncOperationId); | 158 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA
syncOperationCompletedCallbackStarting(executionContext(), m_asyncOperationId); |
| 159 // Prevent calls to stop triggered from the event handler to | 159 // Prevent calls to stop triggered from the event handler to |
| 160 // kill this object. | 160 // kill this object. |
| 161 m_preventDestruction = true; | 161 m_preventDestruction = true; |
| 162 m_window->postMessageTimerFired(this); | 162 m_window->postMessageTimerFired(this); |
| 163 // Will destroy this object | 163 // Will destroy this object |
| 164 m_window->removePostMessageTimer(this); | 164 m_window->removePostMessageTimer(this); |
| 165 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | 165 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); |
| 166 } | 166 } |
| 167 | 167 |
| 168 RefPtrWillBeMember<MessageEvent> m_event; | 168 Member<MessageEvent> m_event; |
| 169 RawPtrWillBeMember<LocalDOMWindow> m_window; | 169 Member<LocalDOMWindow> m_window; |
| 170 RefPtr<SecurityOrigin> m_targetOrigin; | 170 RefPtr<SecurityOrigin> m_targetOrigin; |
| 171 RefPtr<ScriptCallStack> m_stackTrace; | 171 RefPtr<ScriptCallStack> m_stackTrace; |
| 172 RefPtr<UserGestureToken> m_userGestureToken; | 172 RefPtr<UserGestureToken> m_userGestureToken; |
| 173 int m_asyncOperationId; | 173 int m_asyncOperationId; |
| 174 bool m_preventDestruction; | 174 bool m_preventDestruction; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 static void updateSuddenTerminationStatus(LocalDOMWindow* domWindow, bool addedL
istener, FrameLoaderClient::SuddenTerminationDisablerType disablerType) | 177 static void updateSuddenTerminationStatus(LocalDOMWindow* domWindow, bool addedL
istener, FrameLoaderClient::SuddenTerminationDisablerType disablerType) |
| 178 { | 178 { |
| 179 Platform::current()->suddenTerminationChanged(!addedListener); | 179 Platform::current()->suddenTerminationChanged(!addedListener); |
| 180 if (domWindow->frame() && domWindow->frame()->loader().client()) | 180 if (domWindow->frame() && domWindow->frame()->loader().client()) |
| 181 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
addedListener, disablerType); | 181 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
addedListener, disablerType); |
| 182 } | 182 } |
| 183 | 183 |
| 184 using DOMWindowSet = WillBePersistentHeapHashCountedSet<RawPtrWillBeWeakMember<L
ocalDOMWindow>>; | 184 using DOMWindowSet = PersistentHeapHashCountedSet<WeakMember<LocalDOMWindow>>; |
| 185 | 185 |
| 186 static DOMWindowSet& windowsWithUnloadEventListeners() | 186 static DOMWindowSet& windowsWithUnloadEventListeners() |
| 187 { | 187 { |
| 188 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithUnloadEventListeners, ()); | 188 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithUnloadEventListeners, ()); |
| 189 return windowsWithUnloadEventListeners; | 189 return windowsWithUnloadEventListeners; |
| 190 } | 190 } |
| 191 | 191 |
| 192 static DOMWindowSet& windowsWithBeforeUnloadEventListeners() | 192 static DOMWindowSet& windowsWithBeforeUnloadEventListeners() |
| 193 { | 193 { |
| 194 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithBeforeUnloadEventListeners, ())
; | 194 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithBeforeUnloadEventListeners, ())
; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 320 } |
| 321 | 321 |
| 322 void LocalDOMWindow::acceptLanguagesChanged() | 322 void LocalDOMWindow::acceptLanguagesChanged() |
| 323 { | 323 { |
| 324 if (m_navigator) | 324 if (m_navigator) |
| 325 m_navigator->setLanguagesChanged(); | 325 m_navigator->setLanguagesChanged(); |
| 326 | 326 |
| 327 dispatchEvent(Event::create(EventTypeNames::languagechange)); | 327 dispatchEvent(Event::create(EventTypeNames::languagechange)); |
| 328 } | 328 } |
| 329 | 329 |
| 330 PassRefPtrWillBeRawPtr<Document> LocalDOMWindow::createDocument(const String& mi
meType, const DocumentInit& init, bool forceXHTML) | 330 RawPtr<Document> LocalDOMWindow::createDocument(const String& mimeType, const Do
cumentInit& init, bool forceXHTML) |
| 331 { | 331 { |
| 332 RefPtrWillBeRawPtr<Document> document = nullptr; | 332 RawPtr<Document> document = nullptr; |
| 333 if (forceXHTML) { | 333 if (forceXHTML) { |
| 334 // This is a hack for XSLTProcessor. See XSLTProcessor::createDocumentFr
omSource(). | 334 // This is a hack for XSLTProcessor. See XSLTProcessor::createDocumentFr
omSource(). |
| 335 document = Document::create(init); | 335 document = Document::create(init); |
| 336 } else { | 336 } else { |
| 337 document = DOMImplementation::createDocument(mimeType, init, init.frame(
) ? init.frame()->inViewSourceMode() : false); | 337 document = DOMImplementation::createDocument(mimeType, init, init.frame(
) ? init.frame()->inViewSourceMode() : false); |
| 338 if (document->isPluginDocument() && document->isSandboxed(SandboxPlugins
)) | 338 if (document->isPluginDocument() && document->isSandboxed(SandboxPlugins
)) |
| 339 document = SinkDocument::create(init); | 339 document = SinkDocument::create(init); |
| 340 } | 340 } |
| 341 | 341 |
| 342 return document.release(); | 342 return document.release(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 PassRefPtrWillBeRawPtr<Document> LocalDOMWindow::installNewDocument(const String
& mimeType, const DocumentInit& init, bool forceXHTML) | 345 RawPtr<Document> LocalDOMWindow::installNewDocument(const String& mimeType, cons
t DocumentInit& init, bool forceXHTML) |
| 346 { | 346 { |
| 347 ASSERT(init.frame() == frame()); | 347 ASSERT(init.frame() == frame()); |
| 348 | 348 |
| 349 clearDocument(); | 349 clearDocument(); |
| 350 | 350 |
| 351 m_document = createDocument(mimeType, init, forceXHTML); | 351 m_document = createDocument(mimeType, init, forceXHTML); |
| 352 m_eventQueue = DOMWindowEventQueue::create(m_document.get()); | 352 m_eventQueue = DOMWindowEventQueue::create(m_document.get()); |
| 353 m_document->attach(); | 353 m_document->attach(); |
| 354 | 354 |
| 355 if (!frame()) | 355 if (!frame()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 368 | 368 |
| 369 frame()->selection().updateSecureKeyboardEntryIfActive(); | 369 frame()->selection().updateSecureKeyboardEntryIfActive(); |
| 370 return m_document; | 370 return m_document; |
| 371 } | 371 } |
| 372 | 372 |
| 373 EventQueue* LocalDOMWindow::eventQueue() const | 373 EventQueue* LocalDOMWindow::eventQueue() const |
| 374 { | 374 { |
| 375 return m_eventQueue.get(); | 375 return m_eventQueue.get(); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void LocalDOMWindow::enqueueWindowEvent(PassRefPtrWillBeRawPtr<Event> event) | 378 void LocalDOMWindow::enqueueWindowEvent(RawPtr<Event> event) |
| 379 { | 379 { |
| 380 if (!m_eventQueue) | 380 if (!m_eventQueue) |
| 381 return; | 381 return; |
| 382 event->setTarget(this); | 382 event->setTarget(this); |
| 383 m_eventQueue->enqueueEvent(event); | 383 m_eventQueue->enqueueEvent(event); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void LocalDOMWindow::enqueueDocumentEvent(PassRefPtrWillBeRawPtr<Event> event) | 386 void LocalDOMWindow::enqueueDocumentEvent(RawPtr<Event> event) |
| 387 { | 387 { |
| 388 if (!m_eventQueue) | 388 if (!m_eventQueue) |
| 389 return; | 389 return; |
| 390 event->setTarget(m_document.get()); | 390 event->setTarget(m_document.get()); |
| 391 m_eventQueue->enqueueEvent(event); | 391 m_eventQueue->enqueueEvent(event); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void LocalDOMWindow::dispatchWindowLoadEvent() | 394 void LocalDOMWindow::dispatchWindowLoadEvent() |
| 395 { | 395 { |
| 396 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); | 396 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); |
| 397 // Delay 'load' event if we are in EventQueueScope. This is a short-term | 397 // Delay 'load' event if we are in EventQueueScope. This is a short-term |
| 398 // workaround to avoid Editing code crashes. We should always dispatch | 398 // workaround to avoid Editing code crashes. We should always dispatch |
| 399 // 'load' event asynchronously. crbug.com/569511. | 399 // 'load' event asynchronously. crbug.com/569511. |
| 400 if (ScopedEventQueue::instance()->shouldQueueEvents() && m_document) { | 400 if (ScopedEventQueue::instance()->shouldQueueEvents() && m_document) { |
| 401 m_document->postTask(BLINK_FROM_HERE, createSameThreadTask(&LocalDOMWind
ow::dispatchLoadEvent, PassRefPtrWillBeRawPtr<LocalDOMWindow>(this))); | 401 m_document->postTask(BLINK_FROM_HERE, createSameThreadTask(&LocalDOMWind
ow::dispatchLoadEvent, RawPtr<LocalDOMWindow>(this))); |
| 402 return; | 402 return; |
| 403 } | 403 } |
| 404 dispatchLoadEvent(); | 404 dispatchLoadEvent(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void LocalDOMWindow::documentWasClosed() | 407 void LocalDOMWindow::documentWasClosed() |
| 408 { | 408 { |
| 409 dispatchWindowLoadEvent(); | 409 dispatchWindowLoadEvent(); |
| 410 enqueuePageshowEvent(PageshowEventNotPersisted); | 410 enqueuePageshowEvent(PageshowEventNotPersisted); |
| 411 if (m_pendingStateObject) | 411 if (m_pendingStateObject) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 const LocalDOMWindow* LocalDOMWindow::toDOMWindow() const | 482 const LocalDOMWindow* LocalDOMWindow::toDOMWindow() const |
| 483 { | 483 { |
| 484 return this; | 484 return this; |
| 485 } | 485 } |
| 486 | 486 |
| 487 LocalDOMWindow* LocalDOMWindow::toDOMWindow() | 487 LocalDOMWindow* LocalDOMWindow::toDOMWindow() |
| 488 { | 488 { |
| 489 return this; | 489 return this; |
| 490 } | 490 } |
| 491 | 491 |
| 492 PassRefPtrWillBeRawPtr<MediaQueryList> LocalDOMWindow::matchMedia(const String&
media) | 492 RawPtr<MediaQueryList> LocalDOMWindow::matchMedia(const String& media) |
| 493 { | 493 { |
| 494 return document() ? document()->mediaQueryMatcher().matchMedia(media) : null
ptr; | 494 return document() ? document()->mediaQueryMatcher().matchMedia(media) : null
ptr; |
| 495 } | 495 } |
| 496 | 496 |
| 497 void LocalDOMWindow::willDetachFrameHost() | 497 void LocalDOMWindow::willDetachFrameHost() |
| 498 { | 498 { |
| 499 frame()->host()->eventHandlerRegistry().didRemoveAllEventHandlers(*this); | 499 frame()->host()->eventHandlerRegistry().didRemoveAllEventHandlers(*this); |
| 500 frame()->host()->consoleMessageStorage().frameWindowDiscarded(this); | 500 frame()->host()->consoleMessageStorage().frameWindowDiscarded(this); |
| 501 LocalDOMWindow::notifyContextDestroyed(); | 501 LocalDOMWindow::notifyContextDestroyed(); |
| 502 } | 502 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 } | 555 } |
| 556 | 556 |
| 557 void LocalDOMWindow::sendOrientationChangeEvent() | 557 void LocalDOMWindow::sendOrientationChangeEvent() |
| 558 { | 558 { |
| 559 ASSERT(RuntimeEnabledFeatures::orientationEventEnabled()); | 559 ASSERT(RuntimeEnabledFeatures::orientationEventEnabled()); |
| 560 ASSERT(frame()->isMainFrame()); | 560 ASSERT(frame()->isMainFrame()); |
| 561 | 561 |
| 562 // Before dispatching the event, build a list of all frames in the page | 562 // Before dispatching the event, build a list of all frames in the page |
| 563 // to send the event to, to mitigate side effects from event handlers | 563 // to send the event to, to mitigate side effects from event handlers |
| 564 // potentially interfering with others. | 564 // potentially interfering with others. |
| 565 WillBeHeapVector<RefPtrWillBeMember<Frame>> frames; | 565 HeapVector<Member<Frame>> frames; |
| 566 for (Frame* f = frame(); f; f = f->tree().traverseNext()) | 566 for (Frame* f = frame(); f; f = f->tree().traverseNext()) |
| 567 frames.append(f); | 567 frames.append(f); |
| 568 | 568 |
| 569 for (size_t i = 0; i < frames.size(); ++i) { | 569 for (size_t i = 0; i < frames.size(); ++i) { |
| 570 if (!frames[i]->isLocalFrame()) | 570 if (!frames[i]->isLocalFrame()) |
| 571 continue; | 571 continue; |
| 572 toLocalFrame(frames[i].get())->localDOMWindow()->dispatchEvent(Event::cr
eate(EventTypeNames::orientationchange)); | 572 toLocalFrame(frames[i].get())->localDOMWindow()->dispatchEvent(Event::cr
eate(EventTypeNames::orientationchange)); |
| 573 } | 573 } |
| 574 } | 574 } |
| 575 | 575 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 return m_applicationCache.get(); | 668 return m_applicationCache.get(); |
| 669 } | 669 } |
| 670 | 670 |
| 671 Navigator* LocalDOMWindow::navigator() const | 671 Navigator* LocalDOMWindow::navigator() const |
| 672 { | 672 { |
| 673 if (!m_navigator) | 673 if (!m_navigator) |
| 674 m_navigator = Navigator::create(frame()); | 674 m_navigator = Navigator::create(frame()); |
| 675 return m_navigator.get(); | 675 return m_navigator.get(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 void LocalDOMWindow::schedulePostMessage(PassRefPtrWillBeRawPtr<MessageEvent> ev
ent, LocalDOMWindow* source, SecurityOrigin* target, PassRefPtr<ScriptCallStack>
stackTrace) | 678 void LocalDOMWindow::schedulePostMessage(RawPtr<MessageEvent> event, LocalDOMWin
dow* source, SecurityOrigin* target, PassRefPtr<ScriptCallStack> stackTrace) |
| 679 { | 679 { |
| 680 // Schedule the message. | 680 // Schedule the message. |
| 681 OwnPtrWillBeRawPtr<PostMessageTimer> timer = adoptPtrWillBeNoop(new PostMess
ageTimer(*this, event, source, target, stackTrace, UserGestureIndicator::current
Token())); | 681 RawPtr<PostMessageTimer> timer = (new PostMessageTimer(*this, event, source,
target, stackTrace, UserGestureIndicator::currentToken())); |
| 682 timer->startOneShot(0, BLINK_FROM_HERE); | 682 timer->startOneShot(0, BLINK_FROM_HERE); |
| 683 timer->suspendIfNeeded(); | 683 timer->suspendIfNeeded(); |
| 684 m_postMessageTimers.add(timer.release()); | 684 m_postMessageTimers.add(timer.release()); |
| 685 } | 685 } |
| 686 | 686 |
| 687 void LocalDOMWindow::postMessageTimerFired(PostMessageTimer* timer) | 687 void LocalDOMWindow::postMessageTimerFired(PostMessageTimer* timer) |
| 688 { | 688 { |
| 689 if (!isCurrentlyDisplayedInFrame()) { | 689 if (!isCurrentlyDisplayedInFrame()) { |
| 690 return; | 690 return; |
| 691 } | 691 } |
| 692 | 692 |
| 693 RefPtrWillBeRawPtr<MessageEvent> event = timer->event(); | 693 RawPtr<MessageEvent> event = timer->event(); |
| 694 | 694 |
| 695 UserGestureIndicator gestureIndicator(timer->userGestureToken()); | 695 UserGestureIndicator gestureIndicator(timer->userGestureToken()); |
| 696 | 696 |
| 697 event->entangleMessagePorts(document()); | 697 event->entangleMessagePorts(document()); |
| 698 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta
ckTrace()); | 698 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta
ckTrace()); |
| 699 } | 699 } |
| 700 | 700 |
| 701 void LocalDOMWindow::removePostMessageTimer(PostMessageTimer* timer) | 701 void LocalDOMWindow::removePostMessageTimer(PostMessageTimer* timer) |
| 702 { | 702 { |
| 703 m_postMessageTimers.remove(timer); | 703 m_postMessageTimers.remove(timer); |
| 704 } | 704 } |
| 705 | 705 |
| 706 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende
dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtr<ScriptCallStack>
stackTrace) | 706 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende
dTargetOrigin, RawPtr<Event> event, PassRefPtr<ScriptCallStack> stackTrace) |
| 707 { | 707 { |
| 708 if (intendedTargetOrigin) { | 708 if (intendedTargetOrigin) { |
| 709 // Check target origin now since the target document may have changed si
nce the timer was scheduled. | 709 // Check target origin now since the target document may have changed si
nce the timer was scheduled. |
| 710 if (!intendedTargetOrigin->isSameSchemeHostPortAndSuborigin(document()->
securityOrigin())) { | 710 if (!intendedTargetOrigin->isSameSchemeHostPortAndSuborigin(document()->
securityOrigin())) { |
| 711 String message = ExceptionMessages::failedToExecute("postMessage", "
DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() +
"') does not match the recipient window's origin ('" + document()->securityOrig
in()->toString() + "')."); | 711 String message = ExceptionMessages::failedToExecute("postMessage", "
DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() +
"') does not match the recipient window's origin ('" + document()->securityOrig
in()->toString() + "')."); |
| 712 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(SecurityMessageSource, ErrorMessageLevel, message); | 712 RawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(Secur
ityMessageSource, ErrorMessageLevel, message); |
| 713 consoleMessage->setCallStack(stackTrace); | 713 consoleMessage->setCallStack(stackTrace); |
| 714 frameConsole()->addMessage(consoleMessage.release()); | 714 frameConsole()->addMessage(consoleMessage.release()); |
| 715 return; | 715 return; |
| 716 } | 716 } |
| 717 } | 717 } |
| 718 | 718 |
| 719 dispatchEvent(event); | 719 dispatchEvent(event); |
| 720 } | 720 } |
| 721 | 721 |
| 722 DOMSelection* LocalDOMWindow::getSelection() | 722 DOMSelection* LocalDOMWindow::getSelection() |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 return String(); | 841 return String(); |
| 842 } | 842 } |
| 843 | 843 |
| 844 bool LocalDOMWindow::find(const String& string, bool caseSensitive, bool backwar
ds, bool wrap, bool wholeWord, bool /*searchInFrames*/, bool /*showDialog*/) con
st | 844 bool LocalDOMWindow::find(const String& string, bool caseSensitive, bool backwar
ds, bool wrap, bool wholeWord, bool /*searchInFrames*/, bool /*showDialog*/) con
st |
| 845 { | 845 { |
| 846 if (!isCurrentlyDisplayedInFrame()) | 846 if (!isCurrentlyDisplayedInFrame()) |
| 847 return false; | 847 return false; |
| 848 | 848 |
| 849 // |frame()| can be destructed during |Editor::findString()| via | 849 // |frame()| can be destructed during |Editor::findString()| via |
| 850 // |Document::updateLayout()|, e.g. event handler removes a frame. | 850 // |Document::updateLayout()|, e.g. event handler removes a frame. |
| 851 RefPtrWillBeRawPtr<LocalFrame> protectFrame(frame()); | 851 RawPtr<LocalFrame> protectFrame(frame()); |
| 852 | 852 |
| 853 // FIXME (13016): Support searchInFrames and showDialog | 853 // FIXME (13016): Support searchInFrames and showDialog |
| 854 FindOptions options = (backwards ? Backwards : 0) | (caseSensitive ? 0 : Cas
eInsensitive) | (wrap ? WrapAround : 0) | (wholeWord ? WholeWord | AtWordStarts
: 0); | 854 FindOptions options = (backwards ? Backwards : 0) | (caseSensitive ? 0 : Cas
eInsensitive) | (wrap ? WrapAround : 0) | (wholeWord ? WholeWord | AtWordStarts
: 0); |
| 855 return frame()->editor().findString(string, options); | 855 return frame()->editor().findString(string, options); |
| 856 } | 856 } |
| 857 | 857 |
| 858 bool LocalDOMWindow::offscreenBuffering() const | 858 bool LocalDOMWindow::offscreenBuffering() const |
| 859 { | 859 { |
| 860 return true; | 860 return true; |
| 861 } | 861 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 return m_document.get(); | 1055 return m_document.get(); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 StyleMedia* LocalDOMWindow::styleMedia() const | 1058 StyleMedia* LocalDOMWindow::styleMedia() const |
| 1059 { | 1059 { |
| 1060 if (!m_media) | 1060 if (!m_media) |
| 1061 m_media = StyleMedia::create(frame()); | 1061 m_media = StyleMedia::create(frame()); |
| 1062 return m_media.get(); | 1062 return m_media.get(); |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 PassRefPtrWillBeRawPtr<CSSStyleDeclaration> LocalDOMWindow::getComputedStyle(Ele
ment* elt, const String& pseudoElt) const | 1065 RawPtr<CSSStyleDeclaration> LocalDOMWindow::getComputedStyle(Element* elt, const
String& pseudoElt) const |
| 1066 { | 1066 { |
| 1067 ASSERT(elt); | 1067 ASSERT(elt); |
| 1068 return CSSComputedStyleDeclaration::create(elt, false, pseudoElt); | 1068 return CSSComputedStyleDeclaration::create(elt, false, pseudoElt); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 PassRefPtrWillBeRawPtr<CSSRuleList> LocalDOMWindow::getMatchedCSSRules(Element*
element, const String& pseudoElement) const | 1071 RawPtr<CSSRuleList> LocalDOMWindow::getMatchedCSSRules(Element* element, const S
tring& pseudoElement) const |
| 1072 { | 1072 { |
| 1073 if (!element) | 1073 if (!element) |
| 1074 return nullptr; | 1074 return nullptr; |
| 1075 | 1075 |
| 1076 if (!isCurrentlyDisplayedInFrame()) | 1076 if (!isCurrentlyDisplayedInFrame()) |
| 1077 return nullptr; | 1077 return nullptr; |
| 1078 | 1078 |
| 1079 unsigned colonStart = pseudoElement[0] == ':' ? (pseudoElement[1] == ':' ? 2
: 1) : 0; | 1079 unsigned colonStart = pseudoElement[0] == ':' ? (pseudoElement[1] == ':' ? 2
: 1) : 0; |
| 1080 CSSSelector::PseudoType pseudoType = CSSSelector::parsePseudoType(AtomicStri
ng(pseudoElement.substring(colonStart)), false); | 1080 CSSSelector::PseudoType pseudoType = CSSSelector::parsePseudoType(AtomicStri
ng(pseudoElement.substring(colonStart)), false); |
| 1081 if (pseudoType == CSSSelector::PseudoUnknown && !pseudoElement.isEmpty()) | 1081 if (pseudoType == CSSSelector::PseudoUnknown && !pseudoElement.isEmpty()) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 return document->requestIdleCallback(callback, options); | 1291 return document->requestIdleCallback(callback, options); |
| 1292 return 0; | 1292 return 0; |
| 1293 } | 1293 } |
| 1294 | 1294 |
| 1295 void LocalDOMWindow::cancelIdleCallback(int id) | 1295 void LocalDOMWindow::cancelIdleCallback(int id) |
| 1296 { | 1296 { |
| 1297 if (Document* document = this->document()) | 1297 if (Document* document = this->document()) |
| 1298 document->cancelIdleCallback(id); | 1298 document->cancelIdleCallback(id); |
| 1299 } | 1299 } |
| 1300 | 1300 |
| 1301 bool LocalDOMWindow::addEventListenerInternal(const AtomicString& eventType, Pas
sRefPtrWillBeRawPtr<EventListener> prpListener, const EventListenerOptions& opti
ons) | 1301 bool LocalDOMWindow::addEventListenerInternal(const AtomicString& eventType, Raw
Ptr<EventListener> prpListener, const EventListenerOptions& options) |
| 1302 { | 1302 { |
| 1303 RefPtrWillBeRawPtr<EventListener> listener = prpListener; | 1303 RawPtr<EventListener> listener = prpListener; |
| 1304 if (!EventTarget::addEventListenerInternal(eventType, listener, options)) | 1304 if (!EventTarget::addEventListenerInternal(eventType, listener, options)) |
| 1305 return false; | 1305 return false; |
| 1306 | 1306 |
| 1307 if (frame() && frame()->host()) | 1307 if (frame() && frame()->host()) |
| 1308 frame()->host()->eventHandlerRegistry().didAddEventHandler(*this, eventT
ype, options); | 1308 frame()->host()->eventHandlerRegistry().didAddEventHandler(*this, eventT
ype, options); |
| 1309 | 1309 |
| 1310 if (Document* document = this->document()) { | 1310 if (Document* document = this->document()) { |
| 1311 document->addListenerTypeIfNeeded(eventType); | 1311 document->addListenerTypeIfNeeded(eventType); |
| 1312 } | 1312 } |
| 1313 | 1313 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1325 addBeforeUnloadEventListener(this); | 1325 addBeforeUnloadEventListener(this); |
| 1326 } else { | 1326 } else { |
| 1327 // Subframes return false from allowsBeforeUnloadListeners. | 1327 // Subframes return false from allowsBeforeUnloadListeners. |
| 1328 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegist
ered); | 1328 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegist
ered); |
| 1329 } | 1329 } |
| 1330 } | 1330 } |
| 1331 | 1331 |
| 1332 return true; | 1332 return true; |
| 1333 } | 1333 } |
| 1334 | 1334 |
| 1335 bool LocalDOMWindow::removeEventListenerInternal(const AtomicString& eventType,
PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions& opti
ons) | 1335 bool LocalDOMWindow::removeEventListenerInternal(const AtomicString& eventType,
RawPtr<EventListener> listener, const EventListenerOptions& options) |
| 1336 { | 1336 { |
| 1337 if (!EventTarget::removeEventListenerInternal(eventType, listener, options)) | 1337 if (!EventTarget::removeEventListenerInternal(eventType, listener, options)) |
| 1338 return false; | 1338 return false; |
| 1339 | 1339 |
| 1340 if (frame() && frame()->host()) | 1340 if (frame() && frame()->host()) |
| 1341 frame()->host()->eventHandlerRegistry().didRemoveEventHandler(*this, eve
ntType, options); | 1341 frame()->host()->eventHandlerRegistry().didRemoveEventHandler(*this, eve
ntType, options); |
| 1342 | 1342 |
| 1343 notifyRemoveEventListener(this, eventType); | 1343 notifyRemoveEventListener(this, eventType); |
| 1344 | 1344 |
| 1345 if (eventType == EventTypeNames::unload) { | 1345 if (eventType == EventTypeNames::unload) { |
| 1346 removeUnloadEventListener(this); | 1346 removeUnloadEventListener(this); |
| 1347 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi
steners(this)) { | 1347 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi
steners(this)) { |
| 1348 removeBeforeUnloadEventListener(this); | 1348 removeBeforeUnloadEventListener(this); |
| 1349 } | 1349 } |
| 1350 | 1350 |
| 1351 return true; | 1351 return true; |
| 1352 } | 1352 } |
| 1353 | 1353 |
| 1354 void LocalDOMWindow::dispatchLoadEvent() | 1354 void LocalDOMWindow::dispatchLoadEvent() |
| 1355 { | 1355 { |
| 1356 RefPtrWillBeRawPtr<Event> loadEvent(Event::create(EventTypeNames::load)); | 1356 RawPtr<Event> loadEvent(Event::create(EventTypeNames::load)); |
| 1357 if (frame() && frame()->loader().documentLoader() && !frame()->loader().docu
mentLoader()->timing().loadEventStart()) { | 1357 if (frame() && frame()->loader().documentLoader() && !frame()->loader().docu
mentLoader()->timing().loadEventStart()) { |
| 1358 // The DocumentLoader (and thus its DocumentLoadTiming) might get destro
yed while dispatching | 1358 // The DocumentLoader (and thus its DocumentLoadTiming) might get destro
yed while dispatching |
| 1359 // the event, so protect it to prevent writing the end time into freed m
emory. | 1359 // the event, so protect it to prevent writing the end time into freed m
emory. |
| 1360 RefPtrWillBeRawPtr<DocumentLoader> documentLoader = frame()->loader().do
cumentLoader(); | 1360 RawPtr<DocumentLoader> documentLoader = frame()->loader().documentLoader
(); |
| 1361 DocumentLoadTiming& timing = documentLoader->timing(); | 1361 DocumentLoadTiming& timing = documentLoader->timing(); |
| 1362 timing.markLoadEventStart(); | 1362 timing.markLoadEventStart(); |
| 1363 dispatchEvent(loadEvent, document()); | 1363 dispatchEvent(loadEvent, document()); |
| 1364 timing.markLoadEventEnd(); | 1364 timing.markLoadEventEnd(); |
| 1365 } else { | 1365 } else { |
| 1366 dispatchEvent(loadEvent, document()); | 1366 dispatchEvent(loadEvent, document()); |
| 1367 } | 1367 } |
| 1368 | 1368 |
| 1369 // For load events, send a separate load event to the enclosing frame only. | 1369 // For load events, send a separate load event to the enclosing frame only. |
| 1370 // This is a DOM extension and is independent of bubbling/capturing rules of | 1370 // This is a DOM extension and is independent of bubbling/capturing rules of |
| 1371 // the DOM. | 1371 // the DOM. |
| 1372 FrameOwner* owner = frame() ? frame()->owner() : nullptr; | 1372 FrameOwner* owner = frame() ? frame()->owner() : nullptr; |
| 1373 if (owner) | 1373 if (owner) |
| 1374 owner->dispatchLoad(); | 1374 owner->dispatchLoad(); |
| 1375 | 1375 |
| 1376 TRACE_EVENT_INSTANT1("devtools.timeline", "MarkLoad", TRACE_EVENT_SCOPE_THRE
AD, "data", InspectorMarkLoadEvent::data(frame())); | 1376 TRACE_EVENT_INSTANT1("devtools.timeline", "MarkLoad", TRACE_EVENT_SCOPE_THRE
AD, "data", InspectorMarkLoadEvent::data(frame())); |
| 1377 InspectorInstrumentation::loadEventFired(frame()); | 1377 InspectorInstrumentation::loadEventFired(frame()); |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 bool LocalDOMWindow::dispatchEvent(PassRefPtrWillBeRawPtr<Event> prpEvent, PassR
efPtrWillBeRawPtr<EventTarget> prpTarget) | 1380 bool LocalDOMWindow::dispatchEvent(RawPtr<Event> prpEvent, RawPtr<EventTarget> p
rpTarget) |
| 1381 { | 1381 { |
| 1382 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); | 1382 ASSERT(!EventDispatchForbiddenScope::isEventDispatchForbidden()); |
| 1383 | 1383 |
| 1384 RefPtrWillBeRawPtr<EventTarget> protect(this); | 1384 RawPtr<EventTarget> protect(this); |
| 1385 RefPtrWillBeRawPtr<Event> event = prpEvent; | 1385 RawPtr<Event> event = prpEvent; |
| 1386 | 1386 |
| 1387 event->setTrusted(true); | 1387 event->setTrusted(true); |
| 1388 event->setTarget(prpTarget ? prpTarget : this); | 1388 event->setTarget(prpTarget ? prpTarget : this); |
| 1389 event->setCurrentTarget(this); | 1389 event->setCurrentTarget(this); |
| 1390 event->setEventPhase(Event::AT_TARGET); | 1390 event->setEventPhase(Event::AT_TARGET); |
| 1391 | 1391 |
| 1392 TRACE_EVENT1("devtools.timeline", "EventDispatch", "data", InspectorEventDis
patchEvent::data(*event)); | 1392 TRACE_EVENT1("devtools.timeline", "EventDispatch", "data", InspectorEventDis
patchEvent::data(*event)); |
| 1393 return fireEventListeners(event.get()); | 1393 return fireEventListeners(event.get()); |
| 1394 } | 1394 } |
| 1395 | 1395 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1417 { | 1417 { |
| 1418 if (!isCurrentlyDisplayedInFrame()) | 1418 if (!isCurrentlyDisplayedInFrame()) |
| 1419 return; | 1419 return; |
| 1420 | 1420 |
| 1421 if (message.isEmpty()) | 1421 if (message.isEmpty()) |
| 1422 return; | 1422 return; |
| 1423 | 1423 |
| 1424 frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, ErrorMess
ageLevel, message)); | 1424 frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, ErrorMess
ageLevel, message)); |
| 1425 } | 1425 } |
| 1426 | 1426 |
| 1427 PassRefPtrWillBeRawPtr<DOMWindow> LocalDOMWindow::open(const String& urlString,
const AtomicString& frameName, const String& windowFeaturesString, | 1427 RawPtr<DOMWindow> LocalDOMWindow::open(const String& urlString, const AtomicStri
ng& frameName, const String& windowFeaturesString, |
| 1428 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow) | 1428 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow) |
| 1429 { | 1429 { |
| 1430 if (!isCurrentlyDisplayedInFrame()) | 1430 if (!isCurrentlyDisplayedInFrame()) |
| 1431 return nullptr; | 1431 return nullptr; |
| 1432 Document* activeDocument = callingWindow->document(); | 1432 Document* activeDocument = callingWindow->document(); |
| 1433 if (!activeDocument) | 1433 if (!activeDocument) |
| 1434 return nullptr; | 1434 return nullptr; |
| 1435 LocalFrame* firstFrame = enteredWindow->frame(); | 1435 LocalFrame* firstFrame = enteredWindow->frame(); |
| 1436 if (!firstFrame) | 1436 if (!firstFrame) |
| 1437 return nullptr; | 1437 return nullptr; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 return targetFrame->domWindow(); | 1469 return targetFrame->domWindow(); |
| 1470 | 1470 |
| 1471 if (urlString.isEmpty()) | 1471 if (urlString.isEmpty()) |
| 1472 return targetFrame->domWindow(); | 1472 return targetFrame->domWindow(); |
| 1473 | 1473 |
| 1474 targetFrame->navigate(*activeDocument, completedURL, false, UserGestureS
tatus::None); | 1474 targetFrame->navigate(*activeDocument, completedURL, false, UserGestureS
tatus::None); |
| 1475 return targetFrame->domWindow(); | 1475 return targetFrame->domWindow(); |
| 1476 } | 1476 } |
| 1477 | 1477 |
| 1478 WindowFeatures features(windowFeaturesString); | 1478 WindowFeatures features(windowFeaturesString); |
| 1479 RefPtrWillBeRawPtr<DOMWindow> newWindow = createWindow(urlString, frameName,
features, *callingWindow, *firstFrame, *frame()); | 1479 RawPtr<DOMWindow> newWindow = createWindow(urlString, frameName, features, *
callingWindow, *firstFrame, *frame()); |
| 1480 return features.noopener ? nullptr : newWindow; | 1480 return features.noopener ? nullptr : newWindow; |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 DEFINE_TRACE(LocalDOMWindow) | 1483 DEFINE_TRACE(LocalDOMWindow) |
| 1484 { | 1484 { |
| 1485 #if ENABLE(OILPAN) | 1485 #if ENABLE(OILPAN) |
| 1486 visitor->trace(m_frameObserver); | 1486 visitor->trace(m_frameObserver); |
| 1487 visitor->trace(m_document); | 1487 visitor->trace(m_document); |
| 1488 visitor->trace(m_properties); | 1488 visitor->trace(m_properties); |
| 1489 visitor->trace(m_screen); | 1489 visitor->trace(m_screen); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1510 { | 1510 { |
| 1511 // If the LocalDOMWindow still has a frame reference, that frame must point | 1511 // If the LocalDOMWindow still has a frame reference, that frame must point |
| 1512 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation | 1512 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation |
| 1513 // where script execution leaks between different LocalDOMWindows. | 1513 // where script execution leaks between different LocalDOMWindows. |
| 1514 if (m_frameObserver->frame()) | 1514 if (m_frameObserver->frame()) |
| 1515 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() =
= this); | 1515 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() =
= this); |
| 1516 return m_frameObserver->frame(); | 1516 return m_frameObserver->frame(); |
| 1517 } | 1517 } |
| 1518 | 1518 |
| 1519 } // namespace blink | 1519 } // namespace blink |
| OLD | NEW |