Changeset 207522 in webkit
- Timestamp:
- Oct 19, 2016 12:00:10 AM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207521 r207522 1 2016-10-18 Darin Adler <darin@apple.com> 2 3 Move many miscellaneous classes from ExceptionCode to Exception 4 https://bugs.webkit.org/show_bug.cgi?id=163645 5 6 Reviewed by Ryosuke Niwa. 7 8 * bindings/js/JSCryptoCustom.cpp: 9 (WebCore::JSCrypto::getRandomValues): Use propagateException. 10 * bindings/js/JSDOMWindowCustom.cpp: 11 (WebCore::handlePostMessage): Ditto. 12 (WebCore::JSDOMWindow::setTimeout): Use toJSNumber. 13 (WebCore::JSDOMWindow::setInterval): Ditto. 14 * bindings/js/JSStorageCustom.cpp: 15 (WebCore::JSStorage::nameGetter): Use propagateException. 16 (WebCore::JSStorage::deleteProperty): Ditto. 17 (WebCore::JSStorage::getOwnPropertyNames): Ditto. 18 (WebCore::JSStorage::putDelegate): Ditto. 19 20 * loader/appcache/DOMApplicationCache.cpp: 21 (WebCore::DOMApplicationCache::update): Use ExceptionOr. 22 (WebCore::DOMApplicationCache::swapCache): Ditto. 23 * loader/appcache/DOMApplicationCache.h: Update for above changes. 24 * loader/appcache/DOMApplicationCache.idl: Use non-legacy exceptions. 25 26 * page/Crypto.cpp: 27 (WebCore::Crypto::getRandomValues): Use ExceptionOr. 28 (WebCore::Crypto::webkitSubtle): Ditto. 29 * page/Crypto.h: Updated for above changes. 30 * page/Crypto.idl: Use non-legacy exceptions. 31 32 * page/DOMWindow.cpp: 33 (WebCore::DOMWindow::DOMWindow): Initialize many data members in 34 the class definition instead of here. 35 (WebCore::DOMWindow::page): Use nullptr. 36 (WebCore::DOMWindow::screen): Ditto. 37 (WebCore::DOMWindow::crypto): Ditto. 38 (WebCore::DOMWindow::locationbar): Ditto. 39 (WebCore::DOMWindow::menubar): Ditto. 40 (WebCore::DOMWindow::personalbar): Ditto. 41 (WebCore::DOMWindow::scrollbars): Ditto. 42 (WebCore::DOMWindow::statusbar): Ditto. 43 (WebCore::DOMWindow::toolbar): Ditto. 44 (WebCore::DOMWindow::applicationCache): Ditto. 45 (WebCore::DOMWindow::sessionStorage): Use ExceptionOr. 46 (WebCore::DOMWindow::localStorage): Ditto. 47 (WebCore::DOMWindow::postMessage): Ditto. 48 (WebCore::DOMWindow::frameElement): Use nullptr. 49 (WebCore::DOMWindow::self): Ditto. 50 (WebCore::DOMWindow::opener): Ditto. 51 (WebCore::DOMWindow::parent): Ditto. 52 (WebCore::DOMWindow::top): Ditto. 53 (WebCore::DOMWindow::getComputedStyle): Use Ref. 54 (WebCore::DOMWindow::setTimeout): Use ExceptionOr. 55 (WebCore::DOMWindow::setInterval): Ditto. 56 (WebCore::didAddStorageEventListener): Use a reference instead of a 57 pointer, and ignore return value instead of using IGNORE_EXCEPTION. 58 (WebCore::DOMWindow::addEventListener): Pass reference to function above. 59 (WebCore::DOMWindow::dispatchEvent): Use enum class version of PageStatus. 60 * page/DOMWindow.h: Updated for changes above. Also changed indentatation. 61 * page/DOMWindow.idl: Use non-legacy exceptions. 62 63 * page/EventSource.cpp: 64 (WebCore::EventSource::create): Use ExceptionOr. 65 * page/EventSource.h: Updated for change above. 66 * page/EventSource.idl: Use non-legacy exception. 67 68 * page/Location.cpp: 69 (WebCore::Location::setProtocol): Use ExceptionOr. 70 * page/Location.h: Updated for change above. 71 * page/Location.idl: Use non-legacy exception. 72 73 * page/Performance.cpp: 74 (WebCore::Performance::Performance): Remove unnecessary initialization of 75 smart pointer to null, and moved initialization of m_resourceTimingBufferSize 76 to the header. 77 (WebCore::Performance::navigation): Made non-const and return a reference. 78 (WebCore::Performance::timing): Ditto. 79 (WebCore::Performance::addResourceTiming): Change LoadTiming argument to use 80 a const& instead of passing in a copy. 81 (WebCore::Performance::webkitMark): Use ExceptionOr and make_unique. 82 (WebCore::Performance::webkitClearMarks): Ditto. 83 (WebCore::Performance::webkitMeasure): Ditto. 84 (WebCore::Performance::webkitClearMeasures): Ditto. 85 (WebCore::Performance::reduceTimeResolution): Use std::floor. 86 * page/Performance.h: Updated for above changes. Removed unneeded includes. 87 Made more things private. Removed unneeded reference counting of UserTiming. 88 * page/Performance.idl: Use non-legacy exceptions. 89 90 * page/PerformanceUserTiming.cpp: 91 (WebCore::restrictedMarkFunction): Removed unneeded class name. 92 (WebCore::UserTiming::UserTiming): Take a reference instead of a pointer. 93 (WebCore::UserTiming::mark): Use ExceptionOr. 94 (WebCore::UserTiming::findExistingMarkStartTime): Ditto. 95 (WebCore::UserTiming::measure): Ditto. 96 (WebCore::getEntrySequenceByName): Simplified code using HashMap::get. 97 * page/PerformanceUserTiming.h: Updated for above changes. Removed reference 98 counting since this is a single-owner object. 99 100 * page/UserMessageHandler.cpp: 101 (WebCore::UserMessageHandler::postMessage): Use ExceptionOr. 102 * page/UserMessageHandler.h: Updated for above change. 103 * page/UserMessageHandler.idl: Use non-legacy exception. 104 105 * storage/Storage.cpp: 106 (WebCore::Storage::length): Use ExceptionOr. 107 (WebCore::Storage::key): Ditto. 108 (WebCore::Storage::getItem): Ditto. 109 (WebCore::Storage::setItem): Ditto. 110 (WebCore::Storage::removeItem): Ditto. 111 (WebCore::Storage::clear): Ditto. 112 (WebCore::Storage::contains): Ditto. 113 * storage/Storage.h: Updated for above change. 114 * storage/Storage.idl: Use non-legacy exceptions. 115 116 * storage/StorageEventDispatcher.cpp: 117 (WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames): 118 Updated for ExceptionOr. 119 (WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames): Ditto. 120 1 121 2016-10-18 Darin Adler <darin@apple.com> 2 122 -
trunk/Source/WebCore/bindings/js/JSCryptoCustom.cpp
r205198 r207522 46 46 47 47 JSValue buffer = state.argument(0); 48 RefPtr<ArrayBufferView>arrayBufferView = toArrayBufferView(buffer);48 auto arrayBufferView = toArrayBufferView(buffer); 49 49 if (!arrayBufferView) 50 50 return throwTypeError(&state, scope); 51 51 52 ExceptionCode ec = 0; 53 wrapped().getRandomValues(arrayBufferView.get(), ec); 54 55 if (ec) { 56 setDOMException(&state, ec); 57 return jsUndefined(); 58 } 52 propagateException(state, scope, wrapped().getRandomValues(*arrayBufferView)); 59 53 60 54 return buffer; -
trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
r207505 r207522 527 527 528 528 auto message = SerializedScriptValue::create(state, state.uncheckedArgument(0), messagePorts, WTFMove(arrayBuffers)); 529 530 529 RETURN_IF_EXCEPTION(scope, JSValue()); 531 530 … … 533 532 RETURN_IF_EXCEPTION(scope, JSValue()); 534 533 535 ExceptionCode ec = 0; 536 impl.postMessage(WTFMove(message), WTFMove(messagePorts), targetOrigin, callerDOMWindow(&state), ec); 537 setDOMException(&state, ec); 534 propagateException(state, scope, impl.postMessage(message.releaseNonNull(), WTFMove(messagePorts), targetOrigin, callerDOMWindow(&state))); 538 535 539 536 return jsUndefined(); … … 553 550 return throwException(&state, scope, createNotEnoughArgumentsError(&state)); 554 551 555 ContentSecurityPolicy* contentSecurityPolicy = wrapped().document() ? wrapped().document()->contentSecurityPolicy() : nullptr; 556 std::unique_ptr<ScheduledAction> action = ScheduledAction::create(&state, globalObject()->world(), contentSecurityPolicy); 557 RETURN_IF_EXCEPTION(scope, JSValue()); 558 552 auto* contentSecurityPolicy = wrapped().document() ? wrapped().document()->contentSecurityPolicy() : nullptr; 553 auto action = ScheduledAction::create(&state, globalObject()->world(), contentSecurityPolicy); 554 RETURN_IF_EXCEPTION(scope, JSValue()); 559 555 if (!action) 560 556 return jsNumber(0); 561 557 562 558 int delay = state.argument(1).toInt32(&state); 563 564 ExceptionCode ec = 0; 565 int result = wrapped().setTimeout(WTFMove(action), delay, ec); 566 setDOMException(&state, ec); 567 568 return jsNumber(result); 559 return toJSNumber(state, scope, wrapped().setTimeout(WTFMove(action), delay)); 569 560 } 570 561 … … 577 568 return throwException(&state, scope, createNotEnoughArgumentsError(&state)); 578 569 579 ContentSecurityPolicy* contentSecurityPolicy = wrapped().document() ? wrapped().document()->contentSecurityPolicy() : nullptr; 580 std::unique_ptr<ScheduledAction> action = ScheduledAction::create(&state, globalObject()->world(), contentSecurityPolicy); 581 RETURN_IF_EXCEPTION(scope, JSValue()); 582 int delay = state.argument(1).toInt32(&state); 583 570 auto* contentSecurityPolicy = wrapped().document() ? wrapped().document()->contentSecurityPolicy() : nullptr; 571 auto action = ScheduledAction::create(&state, globalObject()->world(), contentSecurityPolicy); 572 RETURN_IF_EXCEPTION(scope, JSValue()); 584 573 if (!action) 585 574 return jsNumber(0); 586 575 587 ExceptionCode ec = 0; 588 int result = wrapped().setInterval(WTFMove(action), delay, ec); 589 setDOMException(&state, ec); 590 591 return jsNumber(result); 576 int delay = state.argument(1).toInt32(&state); 577 return toJSNumber(state, scope, wrapped().setInterval(WTFMove(action), delay)); 592 578 } 593 579 -
trunk/Source/WebCore/bindings/js/JSStorageCustom.cpp
r206386 r207522 36 36 namespace WebCore { 37 37 38 bool JSStorage::nameGetter(ExecState* exec, PropertyName propertyName, JSValue& value)38 bool JSStorage::nameGetter(ExecState* state, PropertyName propertyName, JSValue& value) 39 39 { 40 40 if (propertyName.isSymbol()) 41 41 return false; 42 42 43 ExceptionCode ec = 0;44 String item = wrapped().getItem(propertyNameToString(propertyName), ec);45 setDOMException(exec, ec);43 auto item = wrapped().getItem(propertyNameToString(propertyName)); 44 if (item.hasException()) 45 propagateException(*state, item.releaseException()); 46 46 47 if (item.isNull()) 47 auto string = item.releaseReturnValue(); 48 if (string.isNull()) 48 49 return false; 49 50 50 value = jsStringWithCache( exec, item);51 value = jsStringWithCache(state, string); 51 52 return true; 52 53 } 53 54 54 bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)55 bool JSStorage::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName) 55 56 { 56 JSStorage* thisObject = jsCast<JSStorage*>(cell); 57 auto& thisObject = *jsCast<JSStorage*>(cell); 58 57 59 // Only perform the custom delete if the object doesn't have a native property by this name. 58 60 // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check 59 61 // the native property slots manually. 60 PropertySlot slot( thisObject, PropertySlot::InternalMethodType::GetOwnProperty);62 PropertySlot slot(&thisObject, PropertySlot::InternalMethodType::GetOwnProperty); 61 63 62 JSValue prototype = thisObject ->getPrototypeDirect();63 if (prototype.isObject() && asObject(prototype)->getPropertySlot( exec, propertyName, slot))64 return Base::deleteProperty( thisObject, exec, propertyName);64 JSValue prototype = thisObject.getPrototypeDirect(); 65 if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot)) 66 return Base::deleteProperty(&thisObject, state, propertyName); 65 67 66 68 if (propertyName.isSymbol()) 67 return Base::deleteProperty( thisObject, exec, propertyName);69 return Base::deleteProperty(&thisObject, state, propertyName); 68 70 69 ExceptionCode ec = 0;70 thisObject->wrapped().removeItem(propertyNameToString(propertyName), ec);71 setDOMException(exec, ec);71 VM& vm = state->vm(); 72 auto scope = DECLARE_THROW_SCOPE(vm); 73 propagateException(*state, scope, thisObject.wrapped().removeItem(propertyNameToString(propertyName))); 72 74 return true; 73 75 } … … 78 80 } 79 81 80 void JSStorage::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)82 void JSStorage::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) 81 83 { 82 VM& vm = exec->vm();84 VM& vm = state->vm(); 83 85 auto scope = DECLARE_THROW_SCOPE(vm); 84 86 85 JSStorage* thisObject = jsCast<JSStorage*>(object); 86 ExceptionCode ec = 0; 87 unsigned length = thisObject->wrapped().length(ec); 88 setDOMException(exec, ec); 89 RETURN_IF_EXCEPTION(scope, void()); 87 auto& thisObject = *jsCast<JSStorage*>(object); 88 auto lengthResult = thisObject.wrapped().length(); 89 if (lengthResult.hasException()) { 90 propagateException(*state, scope, lengthResult.releaseException()); 91 return; 92 } 93 unsigned length = lengthResult.releaseReturnValue(); 90 94 for (unsigned i = 0; i < length; ++i) { 91 propertyNames.add(Identifier::fromString(exec, thisObject->wrapped().key(i, ec))); 92 setDOMException(exec, ec); 93 RETURN_IF_EXCEPTION(scope, void()); 95 auto keyResult = thisObject.wrapped().key(i); 96 if (keyResult.hasException()) { 97 propagateException(*state, scope, lengthResult.releaseException()); 98 return; 99 } 100 propertyNames.add(Identifier::fromString(state, keyResult.releaseReturnValue())); 94 101 } 95 102 96 Base::getOwnPropertyNames( thisObject, exec, propertyNames, mode);103 Base::getOwnPropertyNames(&thisObject, state, propertyNames, mode); 97 104 } 98 105 99 bool JSStorage::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)106 bool JSStorage::putDelegate(ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult) 100 107 { 101 VM& vm = exec->vm();108 VM& vm = state->vm(); 102 109 auto scope = DECLARE_THROW_SCOPE(vm); 103 110 … … 108 115 109 116 JSValue prototype = this->getPrototypeDirect(); 110 if (prototype.isObject() && asObject(prototype)->getPropertySlot( exec, propertyName, slot))117 if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot)) 111 118 return false; 112 119 … … 114 121 return false; 115 122 116 String stringValue = value.toString( exec)->value(exec);123 String stringValue = value.toString(state)->value(state); 117 124 if (UNLIKELY(scope.exception())) { 118 125 // The return value indicates whether putDelegate() should handle the put operation (which … … 124 131 } 125 132 126 ExceptionCode ec = 0; 127 wrapped().setItem(propertyNameToString(propertyName), stringValue, ec); 128 setDOMException(exec, ec); 129 putResult = !ec; 133 auto setItemResult = wrapped().setItem(propertyNameToString(propertyName), stringValue); 134 putResult = !setItemResult.hasException(); 135 propagateException(*state, scope, WTFMove(setItemResult)); 130 136 return true; 131 137 } -
trunk/Source/WebCore/loader/appcache/DOMApplicationCache.cpp
r192848 r207522 83 83 } 84 84 85 void DOMApplicationCache::update(ExceptionCode& ec)85 ExceptionOr<void> DOMApplicationCache::update() 86 86 { 87 ApplicationCacheHost* cacheHost = applicationCacheHost();87 auto* cacheHost = applicationCacheHost(); 88 88 if (!cacheHost || !cacheHost->update()) 89 ec = INVALID_STATE_ERR; 89 return Exception { INVALID_STATE_ERR }; 90 return { }; 90 91 } 91 92 92 void DOMApplicationCache::swapCache(ExceptionCode& ec)93 ExceptionOr<void> DOMApplicationCache::swapCache() 93 94 { 94 ApplicationCacheHost* cacheHost = applicationCacheHost();95 auto* cacheHost = applicationCacheHost(); 95 96 if (!cacheHost || !cacheHost->swapCache()) 96 ec = INVALID_STATE_ERR; 97 return Exception { INVALID_STATE_ERR }; 98 return { }; 97 99 } 98 100 -
trunk/Source/WebCore/loader/appcache/DOMApplicationCache.h
r204466 r207522 24 24 */ 25 25 26 #ifndef DOMApplicationCache_h 27 #define DOMApplicationCache_h 26 #pragma once 28 27 29 28 #include "ApplicationCacheHost.h" 30 29 #include "DOMWindowProperty.h" 31 30 #include "EventTarget.h" 31 #include "ExceptionOr.h" 32 32 #include "ScriptWrappable.h" 33 #include <wtf/Forward.h>34 33 #include <wtf/HashMap.h> 35 #include <wtf/RefCounted.h>36 34 #include <wtf/text/AtomicStringHash.h> 37 35 … … 51 49 52 50 unsigned short status() const; 53 void update(ExceptionCode&);54 void swapCache(ExceptionCode&);51 ExceptionOr<void> update(); 52 ExceptionOr<void> swapCache(); 55 53 void abort(); 56 54 … … 73 71 74 72 } // namespace WebCore 75 76 #endif // DOMApplicationCache_h -
trunk/Source/WebCore/loader/appcache/DOMApplicationCache.idl
r206723 r207522 38 38 readonly attribute unsigned short status; 39 39 40 [MayThrow LegacyException] void update();41 [MayThrow LegacyException] void swapCache();40 [MayThrowException] void update(); 41 [MayThrowException] void swapCache(); 42 42 void abort(); 43 43 -
trunk/Source/WebCore/page/Crypto.cpp
r206883 r207522 53 53 } 54 54 55 void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)55 ExceptionOr<void> Crypto::getRandomValues(ArrayBufferView& array) 56 56 { 57 if (!array || !JSC::isInt(array->getType())) { 58 ec = TYPE_MISMATCH_ERR; 59 return; 60 } 61 if (array->byteLength() > 65536) { 62 ec = QUOTA_EXCEEDED_ERR; 63 return; 64 } 65 cryptographicallyRandomValues(array->baseAddress(), array->byteLength()); 57 if (!isInt(array.getType())) 58 return Exception { TYPE_MISMATCH_ERR }; 59 if (array.byteLength() > 65536) 60 return Exception { QUOTA_EXCEEDED_ERR }; 61 cryptographicallyRandomValues(array.baseAddress(), array.byteLength()); 62 return { }; 66 63 } 67 64 68 65 #if ENABLE(SUBTLE_CRYPTO) 66 69 67 SubtleCrypto& Crypto::subtle() 70 68 { … … 72 70 } 73 71 74 WebKitSubtleCrypto* Crypto::webkitSubtle(ExceptionCode& ec)72 ExceptionOr<WebKitSubtleCrypto*> Crypto::webkitSubtle() 75 73 { 76 if (!isMainThread()) { 77 ec = NOT_SUPPORTED_ERR; 78 return 0; 79 } 74 if (!isMainThread()) 75 return Exception { NOT_SUPPORTED_ERR }; 80 76 81 77 if (!m_webkitSubtle) … … 84 80 return m_webkitSubtle.get(); 85 81 } 82 86 83 #endif 87 84 -
trunk/Source/WebCore/page/Crypto.h
r206883 r207522 28 28 */ 29 29 30 #ifndef Crypto_h 31 #define Crypto_h 30 #pragma once 32 31 33 32 #include "ContextDestructionObserver.h" 34 #include <wtf/Forward.h> 35 #include <wtf/RefCounted.h> 36 #include <wtf/RefPtr.h> 33 #include "ExceptionOr.h" 37 34 38 35 namespace JSC { … … 42 39 namespace WebCore { 43 40 44 typedef int ExceptionCode; 45 46 class Document; 41 class SubtleCrypto; 47 42 class WebKitSubtleCrypto; 48 class SubtleCrypto;49 43 50 44 class Crypto : public ContextDestructionObserver, public RefCounted<Crypto> { … … 53 47 virtual ~Crypto(); 54 48 55 void getRandomValues(JSC::ArrayBufferView*, ExceptionCode&);49 ExceptionOr<void> getRandomValues(JSC::ArrayBufferView&); 56 50 57 51 #if ENABLE(SUBTLE_CRYPTO) … … 59 53 60 54 // Will be deprecated. 61 WebKitSubtleCrypto* webkitSubtle(ExceptionCode&);55 ExceptionOr<WebKitSubtleCrypto*> webkitSubtle(); 62 56 #endif 63 57 … … 74 68 75 69 } 76 77 #endif -
trunk/Source/WebCore/page/Crypto.idl
r206883 r207522 33 33 ] interface Crypto { 34 34 [Conditional=SUBTLE_CRYPTO] readonly attribute SubtleCrypto subtle; 35 [Custom, MayThrow LegacyException] ArrayBufferView getRandomValues(ArrayBufferView array);35 [Custom, MayThrowException] ArrayBufferView getRandomValues(ArrayBufferView array); 36 36 37 37 // Will be deprecated. 38 [Conditional=SUBTLE_CRYPTO, GetterMayThrow LegacyException] readonly attribute WebKitSubtleCrypto webkitSubtle;38 [Conditional=SUBTLE_CRYPTO, GetterMayThrowException] readonly attribute WebKitSubtleCrypto webkitSubtle; 39 39 }; -
trunk/Source/WebCore/page/DOMWindow.cpp
r207505 r207522 407 407 : ContextDestructionObserver(document) 408 408 , FrameDestructionObserver(document->frame()) 409 , m_shouldPrintWhenFinishedLoading(false)410 , m_suspendedForDocumentSuspension(false)411 , m_lastPageStatus(PageStatusNone)412 409 , m_weakPtrFactory(this) 413 #if PLATFORM(IOS)414 , m_scrollEventListenerCount(0)415 #endif416 #if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(IOS_GESTURE_EVENTS)417 , m_touchEventListenerCount(0)418 #endif419 #if ENABLE(GAMEPAD)420 , m_gamepadEventListenerCount(0)421 #endif422 410 { 423 411 ASSERT(frame()); … … 489 477 Page* DOMWindow::page() 490 478 { 491 return frame() ? frame()->page() : 0;479 return frame() ? frame()->page() : nullptr; 492 480 } 493 481 … … 538 526 539 527 #if ENABLE(GAMEPAD) 528 540 529 void DOMWindow::incrementGamepadEventListenerCount() 541 530 { … … 551 540 GamepadManager::singleton().unregisterDOMWindow(this); 552 541 } 542 553 543 #endif 554 544 … … 636 626 637 627 #if ENABLE(CUSTOM_ELEMENTS) 628 638 629 CustomElementRegistry& DOMWindow::ensureCustomElementRegistry() 639 630 { … … 642 633 return *m_customElementRegistry; 643 634 } 635 644 636 #endif 645 637 646 638 #if ENABLE(ORIENTATION_EVENTS) 639 647 640 int DOMWindow::orientation() const 648 641 { … … 652 645 return m_frame->orientation(); 653 646 } 647 654 648 #endif 655 649 … … 657 651 { 658 652 if (!isCurrentlyDisplayedInFrame()) 659 return 0;653 return nullptr; 660 654 if (!m_screen) 661 655 m_screen = Screen::create(m_frame); … … 676 670 // FIXME: Why is crypto not available when the window is not currently displayed in a frame? 677 671 if (!isCurrentlyDisplayedInFrame()) 678 return 0;672 return nullptr; 679 673 if (!m_crypto) 680 674 m_crypto = Crypto::create(*document()); … … 685 679 { 686 680 if (!isCurrentlyDisplayedInFrame()) 687 return 0;681 return nullptr; 688 682 if (!m_locationbar) 689 683 m_locationbar = BarProp::create(m_frame, BarProp::Locationbar); … … 694 688 { 695 689 if (!isCurrentlyDisplayedInFrame()) 696 return 0;690 return nullptr; 697 691 if (!m_menubar) 698 692 m_menubar = BarProp::create(m_frame, BarProp::Menubar); … … 703 697 { 704 698 if (!isCurrentlyDisplayedInFrame()) 705 return 0;699 return nullptr; 706 700 if (!m_personalbar) 707 701 m_personalbar = BarProp::create(m_frame, BarProp::Personalbar); … … 712 706 { 713 707 if (!isCurrentlyDisplayedInFrame()) 714 return 0;708 return nullptr; 715 709 if (!m_scrollbars) 716 710 m_scrollbars = BarProp::create(m_frame, BarProp::Scrollbars); … … 721 715 { 722 716 if (!isCurrentlyDisplayedInFrame()) 723 return 0;717 return nullptr; 724 718 if (!m_statusbar) 725 719 m_statusbar = BarProp::create(m_frame, BarProp::Statusbar); … … 730 724 { 731 725 if (!isCurrentlyDisplayedInFrame()) 732 return 0;726 return nullptr; 733 727 if (!m_toolbar) 734 728 m_toolbar = BarProp::create(m_frame, BarProp::Toolbar); … … 746 740 { 747 741 if (!isCurrentlyDisplayedInFrame()) 748 return 0;742 return nullptr; 749 743 if (!m_applicationCache) 750 744 m_applicationCache = DOMApplicationCache::create(m_frame); … … 762 756 763 757 #if ENABLE(WEB_TIMING) 758 764 759 Performance* DOMWindow::performance() const 765 760 { … … 770 765 return m_performance.get(); 771 766 } 767 772 768 #endif 773 769 … … 791 787 792 788 #if ENABLE(USER_MESSAGE_HANDLERS) 789 793 790 bool DOMWindow::shouldHaveWebKitNamespaceForWorld(DOMWrapperWorld& world) 794 791 { … … 822 819 return m_webkitNamespace.get(); 823 820 } 824 #endif 825 826 Storage* DOMWindow::sessionStorage(ExceptionCode& ec) const 827 { 828 if (!isCurrentlyDisplayedInFrame()) 829 return 0; 830 831 Document* document = this->document(); 821 822 #endif 823 824 ExceptionOr<Storage*> DOMWindow::sessionStorage() const 825 { 826 if (!isCurrentlyDisplayedInFrame()) 827 return nullptr; 828 829 auto* document = this->document(); 832 830 if (!document) 833 return 0; 834 835 if (!document->securityOrigin()->canAccessSessionStorage(document->topOrigin())) { 836 ec = SECURITY_ERR; 837 return 0; 838 } 831 return nullptr; 832 833 if (!document->securityOrigin()->canAccessSessionStorage(document->topOrigin())) 834 return Exception { SECURITY_ERR }; 839 835 840 836 if (m_sessionStorage) { 841 if (!m_sessionStorage->area().canAccessStorage(m_frame)) { 842 ec = SECURITY_ERR; 843 return 0; 844 } 837 if (!m_sessionStorage->area().canAccessStorage(m_frame)) 838 return Exception { SECURITY_ERR }; 845 839 return m_sessionStorage.get(); 846 840 } 847 841 848 Page* page = document->page();842 auto* page = document->page(); 849 843 if (!page) 850 return 0;844 return nullptr; 851 845 852 846 auto storageArea = page->sessionStorage()->storageArea(document->securityOrigin()); 853 if (!storageArea->canAccessStorage(m_frame)) { 854 ec = SECURITY_ERR; 855 return 0; 856 } 847 if (!storageArea->canAccessStorage(m_frame)) 848 return Exception { SECURITY_ERR }; 857 849 858 850 m_sessionStorage = Storage::create(m_frame, WTFMove(storageArea)); … … 860 852 } 861 853 862 Storage* DOMWindow::localStorage(ExceptionCode& ec) const863 { 864 if (!isCurrentlyDisplayedInFrame()) 865 return nullptr; 866 867 Document* document = this->document();854 ExceptionOr<Storage*> DOMWindow::localStorage() const 855 { 856 if (!isCurrentlyDisplayedInFrame()) 857 return nullptr; 858 859 auto* document = this->document(); 868 860 if (!document) 869 861 return nullptr; 870 862 871 if (!document->securityOrigin()->canAccessLocalStorage(nullptr)) { 872 ec = SECURITY_ERR; 873 return nullptr; 874 } 875 876 Page* page = document->page(); 863 if (!document->securityOrigin()->canAccessLocalStorage(nullptr)) 864 return Exception { SECURITY_ERR }; 865 866 auto* page = document->page(); 877 867 // FIXME: We should consider supporting access/modification to local storage 878 868 // after calling window.close(). See <https://bugs.webkit.org/show_bug.cgi?id=135330>. 879 869 if (!page || !page->isClosing()) { 880 870 if (m_localStorage) { 881 if (!m_localStorage->area().canAccessStorage(m_frame)) { 882 ec = SECURITY_ERR; 883 return nullptr; 884 } 871 if (!m_localStorage->area().canAccessStorage(m_frame)) 872 return Exception { SECURITY_ERR }; 885 873 return m_localStorage.get(); 886 874 } … … 898 886 auto storageArea = page->storageNamespaceProvider().localStorageArea(*document); 899 887 900 if (!storageArea->canAccessStorage(m_frame)) { 901 ec = SECURITY_ERR; 902 return nullptr; 903 } 888 if (!storageArea->canAccessStorage(m_frame)) 889 return Exception { SECURITY_ERR }; 904 890 905 891 m_localStorage = Storage::create(m_frame, WTFMove(storageArea)); … … 907 893 } 908 894 909 void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, Vector<RefPtr<MessagePort>>&& ports, const String& targetOrigin, DOMWindow& source, ExceptionCode& ec)910 { 911 if (!isCurrentlyDisplayedInFrame()) 912 return ;895 ExceptionOr<void> DOMWindow::postMessage(Ref<SerializedScriptValue>&& message, Vector<RefPtr<MessagePort>>&& ports, const String& targetOrigin, DOMWindow& source) 896 { 897 if (!isCurrentlyDisplayedInFrame()) 898 return { }; 913 899 914 900 Document* sourceDocument = source.document(); … … 919 905 if (targetOrigin == "/") { 920 906 if (!sourceDocument) 921 return ;907 return { }; 922 908 target = sourceDocument->securityOrigin(); 923 909 } else if (targetOrigin != "*") { … … 925 911 // It doesn't make sense target a postMessage at a unique origin 926 912 // because there's no way to represent a unique origin in a string. 927 if (target->isUnique()) { 928 ec = SYNTAX_ERR; 929 return; 930 } 931 } 932 913 if (target->isUnique()) 914 return Exception { SYNTAX_ERR }; 915 } 916 917 ExceptionCode ec = 0; 933 918 auto channels = MessagePort::disentanglePorts(WTFMove(ports), ec); 934 919 if (ec) 935 return ;920 return Exception { ec }; 936 921 937 922 // Capture the source of the message. We need to do this synchronously 938 923 // in order to capture the source of the message correctly. 939 924 if (!sourceDocument) 940 return ;941 StringsourceOrigin = sourceDocument->securityOrigin()->toString();925 return { }; 926 auto sourceOrigin = sourceDocument->securityOrigin()->toString(); 942 927 943 928 // Capture stack trace only when inspector front-end is loaded as it may be time consuming. … … 947 932 948 933 // Schedule the message. 949 PostMessageTimer* timer = new PostMessageTimer(*this, message, sourceOrigin, source, WTFMove(channels), WTFMove(target), WTFMove(stackTrace));934 auto* timer = new PostMessageTimer(*this, PassRefPtr<SerializedScriptValue> { WTFMove(message) }, sourceOrigin, source, WTFMove(channels), WTFMove(target), WTFMove(stackTrace)); 950 935 timer->startOneShot(0); 936 937 return { }; 951 938 } 952 939 … … 987 974 { 988 975 if (!m_frame) 989 return 0;976 return nullptr; 990 977 991 978 return m_frame->ownerElement(); … … 1362 1349 { 1363 1350 if (!m_frame) 1364 return 0;1351 return nullptr; 1365 1352 1366 1353 return m_frame->document()->domWindow(); … … 1370 1357 { 1371 1358 if (!m_frame) 1372 return 0;1359 return nullptr; 1373 1360 1374 1361 Frame* opener = m_frame->loader().opener(); 1375 1362 if (!opener) 1376 return 0;1363 return nullptr; 1377 1364 1378 1365 return opener->document()->domWindow(); … … 1382 1369 { 1383 1370 if (!m_frame) 1384 return 0;1371 return nullptr; 1385 1372 1386 1373 Frame* parent = m_frame->tree().parent(); … … 1394 1381 { 1395 1382 if (!m_frame) 1396 return 0;1383 return nullptr; 1397 1384 1398 1385 Page* page = m_frame->page(); 1399 1386 if (!page) 1400 return 0;1387 return nullptr; 1401 1388 1402 1389 return m_frame->tree().top().document()->domWindow(); … … 1418 1405 } 1419 1406 1420 Ref Ptr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element& element, const String& pseudoElt) const1407 Ref<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element& element, const String& pseudoElt) const 1421 1408 { 1422 1409 return CSSComputedStyleDeclaration::create(element, false, pseudoElt); … … 1424 1411 1425 1412 // FIXME: Drop this overload once <rdar://problem/28016778> has been fixed. 1426 RefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Document&, const String&, ExceptionCode& ec)1413 ExceptionOr<RefPtr<CSSStyleDeclaration>> DOMWindow::getComputedStyle(Document&, const String&) 1427 1414 { 1428 1415 #if PLATFORM(MAC) … … 1432 1419 } 1433 1420 #endif 1434 ec = TypeError; 1435 return nullptr; 1421 return Exception { TypeError }; 1436 1422 } 1437 1423 … … 1632 1618 } 1633 1619 1634 int DOMWindow::setTimeout(std::unique_ptr<ScheduledAction> action, int timeout, ExceptionCode& ec) 1635 { 1636 ScriptExecutionContext* context = scriptExecutionContext(); 1637 if (!context) { 1638 ec = INVALID_ACCESS_ERR; 1639 return -1; 1640 } 1620 ExceptionOr<int> DOMWindow::setTimeout(std::unique_ptr<ScheduledAction> action, int timeout) 1621 { 1622 auto* context = scriptExecutionContext(); 1623 if (!context) 1624 return ExceptionCode { INVALID_ACCESS_ERR }; 1641 1625 return DOMTimer::install(*context, WTFMove(action), std::chrono::milliseconds(timeout), true); 1642 1626 } … … 1666 1650 } 1667 1651 1668 int DOMWindow::setInterval(std::unique_ptr<ScheduledAction> action, int timeout, ExceptionCode& ec) 1669 { 1670 ScriptExecutionContext* context = scriptExecutionContext(); 1671 if (!context) { 1672 ec = INVALID_ACCESS_ERR; 1673 return -1; 1674 } 1652 ExceptionOr<int> DOMWindow::setInterval(std::unique_ptr<ScheduledAction> action, int timeout) 1653 { 1654 auto* context = scriptExecutionContext(); 1655 if (!context) 1656 return ExceptionCode { INVALID_ACCESS_ERR }; 1675 1657 return DOMTimer::install(*context, WTFMove(action), std::chrono::milliseconds(timeout), false); 1676 1658 } … … 1685 1667 1686 1668 #if ENABLE(REQUEST_ANIMATION_FRAME) 1669 1687 1670 int DOMWindow::requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback> callback) 1688 1671 { … … 1706 1689 d->cancelAnimationFrame(id); 1707 1690 } 1708 #endif 1709 1710 static void didAddStorageEventListener(DOMWindow* window) 1691 1692 #endif 1693 1694 static void didAddStorageEventListener(DOMWindow& window) 1711 1695 { 1712 1696 // Creating these WebCore::Storage objects informs the system that we'd like to receive … … 1714 1698 // than subscribe to these notifications explicitly, we subscribe to them implicitly to 1715 1699 // simplify the work done by the system. 1716 window ->localStorage(IGNORE_EXCEPTION);1717 window ->sessionStorage(IGNORE_EXCEPTION);1700 window.localStorage(); 1701 window.sessionStorage(); 1718 1702 } 1719 1703 … … 1746 1730 document->didAddTouchEventHandler(*document); 1747 1731 else if (eventType == eventNames().storageEvent) 1748 didAddStorageEventListener( this);1732 didAddStorageEventListener(*this); 1749 1733 } 1750 1734 … … 1807 1791 1808 1792 #if PLATFORM(IOS) 1793 1809 1794 void DOMWindow::incrementScrollEventListenersCount() 1810 1795 { … … 1826 1811 } 1827 1812 } 1813 1828 1814 #endif 1829 1815 … … 1939 1925 if (event.eventInterface() == PageTransitionEventInterfaceType) { 1940 1926 if (event.type() == eventNames().pageshowEvent) { 1941 if (m_lastPageStatus == PageStatus Shown)1927 if (m_lastPageStatus == PageStatus::Shown) 1942 1928 return true; // Event was previously dispatched; do not fire a duplicate event. 1943 m_lastPageStatus = PageStatus Shown;1929 m_lastPageStatus = PageStatus::Shown; 1944 1930 } else if (event.type() == eventNames().pagehideEvent) { 1945 if (m_lastPageStatus == PageStatus Hidden)1931 if (m_lastPageStatus == PageStatus::Hidden) 1946 1932 return true; // Event was previously dispatched; do not fire a duplicate event. 1947 m_lastPageStatus = PageStatus Hidden;1933 m_lastPageStatus = PageStatus::Hidden; 1948 1934 } 1949 1935 } -
trunk/Source/WebCore/page/DOMWindow.h
r207505 r207522 30 30 #include "ContextDestructionObserver.h" 31 31 #include "EventTarget.h" 32 #include "ExceptionOr.h" 32 33 #include "FrameDestructionObserver.h" 33 34 #include "ScrollToOptions.h" … … 46 47 namespace WebCore { 47 48 48 class BarProp; 49 class CSSRuleList; 50 class CSSStyleDeclaration; 51 class Crypto; 52 class CustomElementRegistry; 53 class DOMApplicationCache; 54 class DOMSelection; 55 class DOMURL; 56 class DOMWindowProperty; 57 class DOMWrapperWorld; 58 class Database; 59 class DatabaseCallback; 60 class Document; 61 class Element; 62 class EventListener; 63 class FloatRect; 64 class Frame; 65 class History; 66 class IDBFactory; 67 class Location; 68 class MediaQueryList; 69 class MessageEvent; 70 class Navigator; 71 class Node; 72 class Page; 73 class PageConsoleClient; 74 class Performance; 75 class PostMessageTimer; 76 class ScheduledAction; 77 class Screen; 78 class SecurityOrigin; 79 class SerializedScriptValue; 80 class Storage; 81 class StyleMedia; 82 class WebKitNamespace; 83 class WebKitPoint; 84 49 class BarProp; 50 class CSSRuleList; 51 class CSSStyleDeclaration; 52 class Crypto; 53 class CustomElementRegistry; 54 class DOMApplicationCache; 55 class DOMSelection; 56 class DOMURL; 57 class DOMWindowProperty; 58 class DOMWrapperWorld; 59 class Database; 60 class DatabaseCallback; 61 class Document; 62 class Element; 63 class EventListener; 64 class FloatRect; 65 class Frame; 66 class History; 67 class IDBFactory; 68 class Location; 69 class MediaQueryList; 70 class MessageEvent; 71 class Navigator; 72 class Node; 73 class Page; 74 class PageConsoleClient; 75 class Performance; 76 class PostMessageTimer; 77 class RequestAnimationFrameCallback; 78 class ScheduledAction; 79 class Screen; 80 class SecurityOrigin; 81 class SerializedScriptValue; 82 class Storage; 83 class StyleMedia; 84 class WebKitNamespace; 85 class WebKitPoint; 86 87 struct WindowFeatures; 88 89 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList }; 90 91 // FIXME: DOMWindow shouldn't subclass FrameDestructionObserver and instead should get to Frame via its Document. 92 class DOMWindow final 93 : public RefCounted<DOMWindow> 94 , public EventTargetWithInlineData 95 , public ContextDestructionObserver 96 , public FrameDestructionObserver 97 , public Base64Utilities 98 , public Supplementable<DOMWindow> { 99 public: 100 static Ref<DOMWindow> create(Document* document) { return adoptRef(*new DOMWindow(document)); } 101 WEBCORE_EXPORT virtual ~DOMWindow(); 102 103 // In some rare cases, we'll reuse a DOMWindow for a new Document. For example, 104 // when a script calls window.open("..."), the browser gives JavaScript a window 105 // synchronously but kicks off the load in the window asynchronously. Web sites 106 // expect that modifications that they make to the window object synchronously 107 // won't be blown away when the network load commits. To make that happen, we 108 // "securely transition" the existing DOMWindow to the Document that results from 109 // the network load. See also SecurityContext::isSecureTransitionTo. 110 void didSecureTransitionTo(Document*); 111 112 EventTargetInterface eventTargetInterface() const override { return DOMWindowEventTargetInterfaceType; } 113 ScriptExecutionContext* scriptExecutionContext() const override { return ContextDestructionObserver::scriptExecutionContext(); } 114 115 DOMWindow* toDOMWindow() override; 116 117 void registerProperty(DOMWindowProperty*); 118 void unregisterProperty(DOMWindowProperty*); 119 120 void resetUnlessSuspendedForDocumentSuspension(); 121 void suspendForDocumentSuspension(); 122 void resumeFromDocumentSuspension(); 123 124 RefPtr<MediaQueryList> matchMedia(const String&); 125 126 WEBCORE_EXPORT unsigned pendingUnloadEventListeners() const; 127 128 WEBCORE_EXPORT static bool dispatchAllPendingBeforeUnloadEvents(); 129 WEBCORE_EXPORT static void dispatchAllPendingUnloadEvents(); 130 131 static FloatRect adjustWindowRect(Page*, const FloatRect& pendingChanges); 132 133 bool allowPopUp(); // Call on first window, not target window. 134 static bool allowPopUp(Frame* firstFrame); 135 static bool canShowModalDialog(const Frame*); 136 WEBCORE_EXPORT void setCanShowModalDialogOverride(bool); 137 138 Screen* screen() const; 139 History* history() const; 140 Crypto* crypto() const; 141 BarProp* locationbar() const; 142 BarProp* menubar() const; 143 BarProp* personalbar() const; 144 BarProp* scrollbars() const; 145 BarProp* statusbar() const; 146 BarProp* toolbar() const; 147 Navigator* navigator() const; 148 Navigator* clientInformation() const { return navigator(); } 149 150 Location* location() const; 151 void setLocation(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& location, SetLocationLocking = LockHistoryBasedOnGestureState); 152 153 DOMSelection* getSelection(); 154 155 Element* frameElement() const; 156 157 WEBCORE_EXPORT void focus(bool allowFocus = false); 158 void focus(DOMWindow& callerWindow); 159 void blur(); 160 WEBCORE_EXPORT void close(); 161 void close(Document&); 162 void print(); 163 void stop(); 164 165 WEBCORE_EXPORT RefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString, DOMWindow& activeWindow, DOMWindow& firstWindow); 166 167 void showModalDialog(const String& urlString, const String& dialogFeaturesString, DOMWindow& activeWindow, DOMWindow& firstWindow, std::function<void(DOMWindow&)> prepareDialogFunction); 168 169 void alert(const String& message = emptyString()); 170 bool confirm(const String& message); 171 String prompt(const String& message, const String& defaultValue); 172 173 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const; 174 175 bool offscreenBuffering() const; 176 177 int outerHeight() const; 178 int outerWidth() const; 179 int innerHeight() const; 180 int innerWidth() const; 181 int screenX() const; 182 int screenY() const; 183 int screenLeft() const { return screenX(); } 184 int screenTop() const { return screenY(); } 185 int scrollX() const; 186 int scrollY() const; 187 188 bool closed() const; 189 190 unsigned length() const; 191 192 String name() const; 193 void setName(const String&); 194 195 String status() const; 196 void setStatus(const String&); 197 String defaultStatus() const; 198 void setDefaultStatus(const String&); 199 200 // Self-referential attributes 201 202 DOMWindow* self() const; 203 DOMWindow* window() const { return self(); } 204 DOMWindow* frames() const { return self(); } 205 206 DOMWindow* opener() const; 207 DOMWindow* parent() const; 208 DOMWindow* top() const; 209 210 // DOM Level 2 AbstractView Interface 211 212 WEBCORE_EXPORT Document* document() const; 213 214 // CSSOM View Module 215 216 RefPtr<StyleMedia> styleMedia() const; 217 218 // DOM Level 2 Style Interface 219 220 WEBCORE_EXPORT Ref<CSSStyleDeclaration> getComputedStyle(Element&, const String& pseudoElt) const; 221 ExceptionOr<RefPtr<CSSStyleDeclaration>> getComputedStyle(Document&, const String& pseudoElt); 222 223 // WebKit extensions 224 225 WEBCORE_EXPORT RefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const; 226 double devicePixelRatio() const; 227 228 RefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node*, const WebKitPoint*) const; 229 RefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node*, const WebKitPoint*) const; 230 231 PageConsoleClient* console() const; 232 233 void printErrorMessage(const String&); 234 String crossDomainAccessErrorMessage(const DOMWindow& activeWindow); 235 236 ExceptionOr<void> postMessage(Ref<SerializedScriptValue>&& message, Vector<RefPtr<MessagePort>>&&, const String& targetOrigin, DOMWindow& source); 237 void postMessageTimerFired(PostMessageTimer&); 238 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event&, PassRefPtr<Inspector::ScriptCallStack>); 239 240 void languagesChanged(); 241 242 void scrollBy(const ScrollToOptions&) const; 243 void scrollBy(double x, double y) const; 244 void scrollTo(const ScrollToOptions&) const; 245 void scrollTo(double x, double y) const; 246 247 void moveBy(float x, float y) const; 248 void moveTo(float x, float y) const; 249 250 void resizeBy(float x, float y) const; 251 void resizeTo(float width, float height) const; 252 253 // Timers 254 ExceptionOr<int> setTimeout(std::unique_ptr<ScheduledAction>, int timeout); 255 void clearTimeout(int timeoutId); 256 ExceptionOr<int> setInterval(std::unique_ptr<ScheduledAction>, int timeout); 257 void clearInterval(int timeoutId); 258 259 // WebKit animation extensions 85 260 #if ENABLE(REQUEST_ANIMATION_FRAME) 86 class RequestAnimationFrameCallback; 87 #endif 88 89 struct WindowFeatures; 90 91 typedef int ExceptionCode; 92 93 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList }; 94 95 // FIXME: DOMWindow shouldn't subclass FrameDestructionObserver and instead should get to Frame via its Document. 96 class DOMWindow final 97 : public RefCounted<DOMWindow> 98 , public EventTargetWithInlineData 99 , public ContextDestructionObserver 100 , public FrameDestructionObserver 101 , public Base64Utilities 102 , public Supplementable<DOMWindow> { 103 public: 104 static Ref<DOMWindow> create(Document* document) { return adoptRef(*new DOMWindow(document)); } 105 WEBCORE_EXPORT virtual ~DOMWindow(); 106 107 // In some rare cases, we'll re-used a DOMWindow for a new Document. For example, 108 // when a script calls window.open("..."), the browser gives JavaScript a window 109 // synchronously but kicks off the load in the window asynchronously. Web sites 110 // expect that modifications that they make to the window object synchronously 111 // won't be blown away when the network load commits. To make that happen, we 112 // "securely transition" the existing DOMWindow to the Document that results from 113 // the network load. See also SecurityContext::isSecureTransitionTo. 114 void didSecureTransitionTo(Document*); 115 116 EventTargetInterface eventTargetInterface() const override { return DOMWindowEventTargetInterfaceType; } 117 ScriptExecutionContext* scriptExecutionContext() const override { return ContextDestructionObserver::scriptExecutionContext(); } 118 119 DOMWindow* toDOMWindow() override; 120 121 void registerProperty(DOMWindowProperty*); 122 void unregisterProperty(DOMWindowProperty*); 123 124 void resetUnlessSuspendedForDocumentSuspension(); 125 void suspendForDocumentSuspension(); 126 void resumeFromDocumentSuspension(); 127 128 RefPtr<MediaQueryList> matchMedia(const String&); 129 130 WEBCORE_EXPORT unsigned pendingUnloadEventListeners() const; 131 132 WEBCORE_EXPORT static bool dispatchAllPendingBeforeUnloadEvents(); 133 WEBCORE_EXPORT static void dispatchAllPendingUnloadEvents(); 134 135 static FloatRect adjustWindowRect(Page*, const FloatRect& pendingChanges); 136 137 bool allowPopUp(); // Call on first window, not target window. 138 static bool allowPopUp(Frame* firstFrame); 139 static bool canShowModalDialog(const Frame*); 140 WEBCORE_EXPORT void setCanShowModalDialogOverride(bool); 141 142 Screen* screen() const; 143 History* history() const; 144 Crypto* crypto() const; 145 BarProp* locationbar() const; 146 BarProp* menubar() const; 147 BarProp* personalbar() const; 148 BarProp* scrollbars() const; 149 BarProp* statusbar() const; 150 BarProp* toolbar() const; 151 Navigator* navigator() const; 152 Navigator* clientInformation() const { return navigator(); } 153 154 Location* location() const; 155 void setLocation(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& location, 156 SetLocationLocking = LockHistoryBasedOnGestureState); 157 158 DOMSelection* getSelection(); 159 160 Element* frameElement() const; 161 162 WEBCORE_EXPORT void focus(bool allowFocus = false); 163 void focus(DOMWindow& callerWindow); 164 void blur(); 165 WEBCORE_EXPORT void close(); 166 void close(Document&); 167 void print(); 168 void stop(); 169 170 WEBCORE_EXPORT RefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString, 171 DOMWindow& activeWindow, DOMWindow& firstWindow); 172 173 void showModalDialog(const String& urlString, const String& dialogFeaturesString, DOMWindow& activeWindow, DOMWindow& firstWindow, std::function<void (DOMWindow&)> prepareDialogFunction); 174 175 void alert(const String& message = emptyString()); 176 bool confirm(const String& message); 177 String prompt(const String& message, const String& defaultValue); 178 179 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const; 180 181 bool offscreenBuffering() const; 182 183 int outerHeight() const; 184 int outerWidth() const; 185 int innerHeight() const; 186 int innerWidth() const; 187 int screenX() const; 188 int screenY() const; 189 int screenLeft() const { return screenX(); } 190 int screenTop() const { return screenY(); } 191 int scrollX() const; 192 int scrollY() const; 193 194 bool closed() const; 195 196 unsigned length() const; 197 198 String name() const; 199 void setName(const String&); 200 201 String status() const; 202 void setStatus(const String&); 203 String defaultStatus() const; 204 void setDefaultStatus(const String&); 205 206 // Self-referential attributes 207 208 DOMWindow* self() const; 209 DOMWindow* window() const { return self(); } 210 DOMWindow* frames() const { return self(); } 211 212 DOMWindow* opener() const; 213 DOMWindow* parent() const; 214 DOMWindow* top() const; 215 216 // DOM Level 2 AbstractView Interface 217 218 WEBCORE_EXPORT Document* document() const; 219 220 // CSSOM View Module 221 222 RefPtr<StyleMedia> styleMedia() const; 223 224 // DOM Level 2 Style Interface 225 226 WEBCORE_EXPORT RefPtr<CSSStyleDeclaration> getComputedStyle(Element&, const String& pseudoElt) const; 227 RefPtr<CSSStyleDeclaration> getComputedStyle(Document&, const String& pseudoElt, ExceptionCode&); 228 229 // WebKit extensions 230 231 WEBCORE_EXPORT RefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const; 232 double devicePixelRatio() const; 233 234 RefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node*, const WebKitPoint*) const; 235 RefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node*, const WebKitPoint*) const; 236 237 PageConsoleClient* console() const; 238 239 void printErrorMessage(const String&); 240 String crossDomainAccessErrorMessage(const DOMWindow& activeWindow); 241 242 void postMessage(PassRefPtr<SerializedScriptValue> message, Vector<RefPtr<MessagePort>>&&, const String& targetOrigin, DOMWindow& source, ExceptionCode&); 243 void postMessageTimerFired(PostMessageTimer&); 244 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event&, PassRefPtr<Inspector::ScriptCallStack>); 245 246 void languagesChanged(); 247 248 void scrollBy(const ScrollToOptions&) const; 249 void scrollBy(double x, double y) const; 250 void scrollTo(const ScrollToOptions&) const; 251 void scrollTo(double x, double y) const; 252 253 void moveBy(float x, float y) const; 254 void moveTo(float x, float y) const; 255 256 void resizeBy(float x, float y) const; 257 void resizeTo(float width, float height) const; 258 259 // Timers 260 int setTimeout(std::unique_ptr<ScheduledAction>, int timeout, ExceptionCode&); 261 void clearTimeout(int timeoutId); 262 int setInterval(std::unique_ptr<ScheduledAction>, int timeout, ExceptionCode&); 263 void clearInterval(int timeoutId); 264 265 // WebKit animation extensions 266 #if ENABLE(REQUEST_ANIMATION_FRAME) 267 int requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>); 268 int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>); 269 void cancelAnimationFrame(int id); 270 #endif 271 272 // Events 273 // EventTarget API 274 bool addEventListener(const AtomicString& eventType, Ref<EventListener>&&, const AddEventListenerOptions&) override; 275 bool removeEventListener(const AtomicString& eventType, EventListener&, const ListenerOptions&) override; 276 void removeAllEventListeners() override; 277 278 using EventTarget::dispatchEvent; 279 bool dispatchEvent(Event&, EventTarget*); 280 281 void dispatchLoadEvent(); 282 283 void captureEvents(); 284 void releaseEvents(); 285 286 void finishedLoading(); 287 288 using RefCounted<DOMWindow>::ref; 289 using RefCounted<DOMWindow>::deref; 290 291 // HTML 5 key/value storage 292 Storage* sessionStorage(ExceptionCode&) const; 293 Storage* localStorage(ExceptionCode&) const; 294 Storage* optionalSessionStorage() const { return m_sessionStorage.get(); } 295 Storage* optionalLocalStorage() const { return m_localStorage.get(); } 296 297 DOMApplicationCache* applicationCache() const; 298 DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); } 261 int requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>); 262 int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>); 263 void cancelAnimationFrame(int id); 264 #endif 265 266 // Events 267 // EventTarget API 268 bool addEventListener(const AtomicString& eventType, Ref<EventListener>&&, const AddEventListenerOptions&) override; 269 bool removeEventListener(const AtomicString& eventType, EventListener&, const ListenerOptions&) override; 270 void removeAllEventListeners() override; 271 272 using EventTarget::dispatchEvent; 273 bool dispatchEvent(Event&, EventTarget*); 274 275 void dispatchLoadEvent(); 276 277 void captureEvents(); 278 void releaseEvents(); 279 280 void finishedLoading(); 281 282 using RefCounted<DOMWindow>::ref; 283 using RefCounted<DOMWindow>::deref; 284 285 // HTML 5 key/value storage 286 ExceptionOr<Storage*> sessionStorage() const; 287 ExceptionOr<Storage*> localStorage() const; 288 Storage* optionalSessionStorage() const { return m_sessionStorage.get(); } 289 Storage* optionalLocalStorage() const { return m_localStorage.get(); } 290 291 DOMApplicationCache* applicationCache() const; 292 DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); } 299 293 300 294 #if ENABLE(CUSTOM_ELEMENTS) 301 302 295 CustomElementRegistry* customElementRegistry() { return m_customElementRegistry.get(); } 296 CustomElementRegistry& ensureCustomElementRegistry(); 303 297 #endif 304 298 305 299 #if ENABLE(ORIENTATION_EVENTS) 306 307 308 309 300 // This is the interface orientation in degrees. Some examples are: 301 // 0 is straight up; -90 is when the device is rotated 90 clockwise; 302 // 90 is when rotated counter clockwise. 303 int orientation() const; 310 304 #endif 311 305 312 306 #if ENABLE(WEB_TIMING) 313 314 #endif 315 307 Performance* performance() const; 308 #endif 309 double nowTimestamp() const; 316 310 317 311 #if PLATFORM(IOS) 318 319 320 321 #endif 322 323 312 void incrementScrollEventListenersCount(); 313 void decrementScrollEventListenersCount(); 314 unsigned scrollEventListenerCount() const { return m_scrollEventListenerCount; } 315 #endif 316 317 void resetAllGeolocationPermission(); 324 318 325 319 #if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(IOS_GESTURE_EVENTS) 326 320 bool hasTouchEventListeners() const { return m_touchEventListenerCount > 0; } 327 321 #endif 328 322 329 323 #if ENABLE(USER_MESSAGE_HANDLERS) 330 331 332 #endif 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 static RefPtr<Frame> createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures&, DOMWindow& activeWindow, Frame& firstFrame, Frame& openerFrame, std::function<void(DOMWindow&)> prepareDialogFunction = nullptr);361 362 363 364 365 366 367 368 324 bool shouldHaveWebKitNamespaceForWorld(DOMWrapperWorld&); 325 WebKitNamespace* webkitNamespace() const; 326 #endif 327 328 // FIXME: When this DOMWindow is no longer the active DOMWindow (i.e., 329 // when its document is no longer the document that is displayed in its 330 // frame), we would like to zero out m_frame to avoid being confused 331 // by the document that is currently active in m_frame. 332 bool isCurrentlyDisplayedInFrame() const; 333 334 void willDetachDocumentFromFrame(); 335 void willDestroyCachedFrame(); 336 337 void enableSuddenTermination(); 338 void disableSuddenTermination(); 339 340 WeakPtr<DOMWindow> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); } 341 342 private: 343 explicit DOMWindow(Document*); 344 345 Page* page(); 346 bool allowedToChangeWindowGeometry() const; 347 348 void frameDestroyed() override; 349 void willDetachPage() override; 350 351 void refEventTarget() override { ref(); } 352 void derefEventTarget() override { deref(); } 353 354 static RefPtr<Frame> createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures&, DOMWindow& activeWindow, Frame& firstFrame, Frame& openerFrame, std::function<void(DOMWindow&)> prepareDialogFunction = nullptr); 355 bool isInsecureScriptAccess(DOMWindow& activeWindow, const String& urlString); 356 357 void resetDOMWindowProperties(); 358 void disconnectDOMWindowProperties(); 359 void reconnectDOMWindowProperties(); 360 void willDestroyDocumentInFrame(); 361 362 bool isSameSecurityOriginAsMainFrame() const; 369 363 370 364 #if ENABLE(GAMEPAD) 371 372 373 #endif 374 375 bool m_shouldPrintWhenFinishedLoading;376 bool m_suspendedForDocumentSuspension;377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 enum PageStatus { PageStatusNone, PageStatusShown, PageStatusHidden };399 PageStatus m_lastPageStatus;400 401 365 void incrementGamepadEventListenerCount(); 366 void decrementGamepadEventListenerCount(); 367 #endif 368 369 bool m_shouldPrintWhenFinishedLoading { false }; 370 bool m_suspendedForDocumentSuspension { false }; 371 Optional<bool> m_canShowModalDialogOverride; 372 373 HashSet<DOMWindowProperty*> m_properties; 374 375 mutable RefPtr<Crypto> m_crypto; 376 mutable RefPtr<History> m_history; 377 mutable RefPtr<BarProp> m_locationbar; 378 mutable RefPtr<StyleMedia> m_media; 379 mutable RefPtr<BarProp> m_menubar; 380 mutable RefPtr<Navigator> m_navigator; 381 mutable RefPtr<BarProp> m_personalbar; 382 mutable RefPtr<Screen> m_screen; 383 mutable RefPtr<BarProp> m_scrollbars; 384 mutable RefPtr<DOMSelection> m_selection; 385 mutable RefPtr<BarProp> m_statusbar; 386 mutable RefPtr<BarProp> m_toolbar; 387 mutable RefPtr<Location> m_location; 388 389 String m_status; 390 String m_defaultStatus; 391 392 enum class PageStatus { None, Shown, Hidden }; 393 PageStatus m_lastPageStatus { PageStatus::None }; 394 395 WeakPtrFactory<DOMWindow> m_weakPtrFactory; 402 396 403 397 #if PLATFORM(IOS) 404 unsigned m_scrollEventListenerCount;398 unsigned m_scrollEventListenerCount { 0 }; 405 399 #endif 406 400 407 401 #if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(IOS_GESTURE_EVENTS) 408 unsigned m_touchEventListenerCount;402 unsigned m_touchEventListenerCount { 0 }; 409 403 #endif 410 404 411 405 #if ENABLE(GAMEPAD) 412 unsigned m_gamepadEventListenerCount; 413 #endif 414 mutable RefPtr<Storage> m_sessionStorage; 415 mutable RefPtr<Storage> m_localStorage; 416 mutable RefPtr<DOMApplicationCache> m_applicationCache; 406 unsigned m_gamepadEventListenerCount { 0 }; 407 #endif 408 409 mutable RefPtr<Storage> m_sessionStorage; 410 mutable RefPtr<Storage> m_localStorage; 411 mutable RefPtr<DOMApplicationCache> m_applicationCache; 417 412 418 413 #if ENABLE(CUSTOM_ELEMENTS) 419 414 RefPtr<CustomElementRegistry> m_customElementRegistry; 420 415 #endif 421 416 422 417 #if ENABLE(WEB_TIMING) 423 418 mutable RefPtr<Performance> m_performance; 424 419 #endif 425 420 426 421 #if ENABLE(USER_MESSAGE_HANDLERS) 427 428 #endif 429 430 431 432 433 434 435 436 437 438 439 422 mutable RefPtr<WebKitNamespace> m_webkitNamespace; 423 #endif 424 }; 425 426 inline String DOMWindow::status() const 427 { 428 return m_status; 429 } 430 431 inline String DOMWindow::defaultStatus() const 432 { 433 return m_defaultStatus; 434 } 440 435 441 436 } // namespace WebCore -
trunk/Source/WebCore/page/DOMWindow.idl
r207384 r207522 134 134 135 135 // FIXME: Drop the following overload of getComputedStyle once <rdar://problem/28020681> has been fixed. 136 [NewObject, MayThrow LegacyException] CSSStyleDeclarationgetComputedStyle(Document document, optional DOMString? pseudoElement = null);136 [NewObject, MayThrowException] CSSStyleDeclaration? getComputedStyle(Document document, optional DOMString? pseudoElement = null); 137 137 138 138 CSSRuleList getMatchedCSSRules(optional Element? element = null, optional DOMString? pseudoElement = null); … … 145 145 readonly attribute DOMApplicationCache applicationCache; 146 146 147 [GetterMayThrow LegacyException] readonly attribute Storage sessionStorage;148 [GetterMayThrow LegacyException] readonly attribute Storage localStorage;147 [GetterMayThrowException] readonly attribute Storage sessionStorage; 148 [GetterMayThrowException] readonly attribute Storage localStorage; 149 149 150 150 // This is the interface orientation in degrees. Some examples: … … 152 152 [Conditional=ORIENTATION_EVENTS] readonly attribute long orientation; 153 153 154 [DoNotCheckSecurity, Custom, MayThrow LegacyException, ForwardDeclareInHeader] void postMessage(SerializedScriptValue message, USVString targetOrigin, optional Array messagePorts);154 [DoNotCheckSecurity, Custom, MayThrowException, ForwardDeclareInHeader] void postMessage(SerializedScriptValue message, USVString targetOrigin, optional Array messagePorts); 155 155 156 156 [Conditional=WEB_TIMING, Replaceable] readonly attribute Performance performance; -
trunk/Source/WebCore/page/EventSource.cpp
r207086 r207522 59 59 } 60 60 61 RefPtr<EventSource> EventSource::create(ScriptExecutionContext& context, const String& url, const Init& eventSourceInit, ExceptionCode& ec) 62 { 63 if (url.isEmpty()) { 64 ec = SYNTAX_ERR; 65 return nullptr; 66 } 61 ExceptionOr<Ref<EventSource>> EventSource::create(ScriptExecutionContext& context, const String& url, const Init& eventSourceInit) 62 { 63 if (url.isEmpty()) 64 return Exception { SYNTAX_ERR }; 67 65 68 66 URL fullURL = context.completeURL(url); 69 if (!fullURL.isValid()) { 70 ec = SYNTAX_ERR; 71 return nullptr; 72 } 73 74 // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved. 67 if (!fullURL.isValid()) 68 return Exception { SYNTAX_ERR }; 69 70 // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is resolved. 75 71 if (!context.shouldBypassMainWorldContentSecurityPolicy() && !context.contentSecurityPolicy()->allowConnectToSource(fullURL)) { 76 72 // FIXME: Should this be throwing an exception? 77 ec = SECURITY_ERR; 78 return nullptr; 73 return Exception { SECURITY_ERR }; 79 74 } 80 75 -
trunk/Source/WebCore/page/EventSource.h
r202542 r207522 34 34 #include "ActiveDOMObject.h" 35 35 #include "EventTarget.h" 36 #include "ExceptionOr.h" 36 37 #include "URL.h" 37 38 #include "ThreadableLoaderClient.h" … … 51 52 bool withCredentials; 52 53 }; 53 static RefPtr<EventSource> create(ScriptExecutionContext&, const String& url, const Init&, ExceptionCode&);54 static ExceptionOr<Ref<EventSource>> create(ScriptExecutionContext&, const String& url, const Init&); 54 55 virtual ~EventSource(); 55 56 … … 57 58 bool withCredentials() const; 58 59 59 typedef short State;60 using State = short; 60 61 static const State CONNECTING = 0; 61 62 static const State OPEN = 1; -
trunk/Source/WebCore/page/EventSource.idl
r206723 r207522 35 35 Constructor(USVString url, optional EventSourceInit eventSourceInitDict), 36 36 ConstructorCallWith=ScriptExecutionContext, 37 ConstructorMayThrow LegacyException,37 ConstructorMayThrowException, 38 38 ] interface EventSource : EventTarget { 39 39 readonly attribute USVString URL; // Lowercased .url is the one in the spec, but leaving .URL for compatibility reasons. -
trunk/Source/WebCore/page/Location.cpp
r204679 r207522 159 159 } 160 160 161 void Location::setProtocol(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& protocol, ExceptionCode& ec) 162 { 163 if (!m_frame) 164 return; 165 URL url = m_frame->document()->url(); 166 if (!url.setProtocol(protocol)) { 167 ec = SYNTAX_ERR; 168 return; 169 } 170 setLocation(activeWindow, firstWindow, url.string()); 161 ExceptionOr<void> Location::setProtocol(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& protocol) 162 { 163 if (!m_frame) 164 return { }; 165 URL url = m_frame->document()->url(); 166 if (!url.setProtocol(protocol)) 167 return Exception { SYNTAX_ERR }; 168 setLocation(activeWindow, firstWindow, url.string()); 169 return { }; 171 170 } 172 171 -
trunk/Source/WebCore/page/Location.h
r204679 r207522 27 27 */ 28 28 29 #ifndef Location_h 30 #define Location_h 29 #pragma once 31 30 32 31 #include "DOMStringList.h" 33 32 #include "DOMWindowProperty.h" 33 #include "ExceptionOr.h" 34 34 #include "ScriptWrappable.h" 35 #include <wtf/RefCounted.h>36 #include <wtf/text/WTFString.h>37 35 38 36 namespace WebCore { … … 55 53 void reload(DOMWindow& activeWindow); 56 54 57 void setProtocol(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&, ExceptionCode&);55 ExceptionOr<void> setProtocol(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&); 58 56 String protocol() const; 59 57 void setHost(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&); … … 84 82 85 83 } // namespace WebCore 86 87 #endif // Location_h -
trunk/Source/WebCore/page/Location.idl
r207355 r207522 49 49 50 50 // URI decomposition attributes 51 [SetterCallWith=ActiveWindow&FirstWindow, SetterMayThrow LegacyException] attribute USVString protocol;51 [SetterCallWith=ActiveWindow&FirstWindow, SetterMayThrowException] attribute USVString protocol; 52 52 [SetterCallWith=ActiveWindow&FirstWindow] attribute USVString host; 53 53 [SetterCallWith=ActiveWindow&FirstWindow] attribute USVString hostname; -
trunk/Source/WebCore/page/Performance.cpp
r204976 r207522 32 32 33 33 #include "config.h" 34 #include "Performance.h" 34 35 35 36 #if ENABLE(WEB_TIMING) 36 #include "Performance.h"37 37 38 38 #include "Document.h" … … 50 50 namespace WebCore { 51 51 52 static const size_t defaultResourceTimingBufferSize = 150;53 54 52 Performance::Performance(Frame& frame) 55 53 : DOMWindowProperty(&frame) 56 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize)57 54 , m_referenceTime(frame.document()->loader() ? frame.document()->loader()->timing().referenceMonotonicTime() : monotonicallyIncreasingTime()) 58 #if ENABLE(USER_TIMING)59 , m_userTiming(nullptr)60 #endif // ENABLE(USER_TIMING)61 55 { 62 56 ASSERT(m_referenceTime); … … 74 68 } 75 69 76 PerformanceNavigation * Performance::navigation() const70 PerformanceNavigation& Performance::navigation() 77 71 { 78 72 if (!m_navigation) 79 73 m_navigation = PerformanceNavigation::create(m_frame); 80 81 return m_navigation.get(); 82 } 83 84 PerformanceTiming* Performance::timing() const 74 return *m_navigation; 75 } 76 77 PerformanceTiming& Performance::timing() 85 78 { 86 79 if (!m_timing) 87 80 m_timing = PerformanceTiming::create(m_frame); 88 89 return m_timing.get(); 81 return *m_timing; 90 82 } 91 83 … … 165 157 } 166 158 167 void Performance::addResourceTiming(const String& initiatorName, Document* initiatorDocument, const URL& originalURL, const ResourceResponse& response, LoadTimingloadTiming)159 void Performance::addResourceTiming(const String& initiatorName, Document* initiatorDocument, const URL& originalURL, const ResourceResponse& response, const LoadTiming& loadTiming) 168 160 { 169 161 if (isResourceTimingBufferFull()) … … 184 176 185 177 #if ENABLE(USER_TIMING) 186 void Performance::webkitMark(const String& markName, ExceptionCode& ec) 187 { 188 ec = 0; 189 if (!m_userTiming) 190 m_userTiming = UserTiming::create(this);191 m_userTiming->mark(markName, ec);178 179 ExceptionOr<void> Performance::webkitMark(const String& markName) 180 { 181 if (!m_userTiming) 182 m_userTiming = std::make_unique<UserTiming>(*this); 183 return m_userTiming->mark(markName); 192 184 } 193 185 … … 195 187 { 196 188 if (!m_userTiming) 197 m_userTiming = UserTiming::create(this);189 m_userTiming = std::make_unique<UserTiming>(*this); 198 190 m_userTiming->clearMarks(markName); 199 191 } 200 192 201 void Performance::webkitMeasure(const String& measureName, const String& startMark, const String& endMark, ExceptionCode& ec) 202 { 203 ec = 0; 204 if (!m_userTiming) 205 m_userTiming = UserTiming::create(this); 206 m_userTiming->measure(measureName, startMark, endMark, ec); 193 ExceptionOr<void> Performance::webkitMeasure(const String& measureName, const String& startMark, const String& endMark) 194 { 195 if (!m_userTiming) 196 m_userTiming = std::make_unique<UserTiming>(*this); 197 return m_userTiming->measure(measureName, startMark, endMark); 207 198 } 208 199 … … 210 201 { 211 202 if (!m_userTiming) 212 m_userTiming = UserTiming::create(this);203 m_userTiming = std::make_unique<UserTiming>(*this); 213 204 m_userTiming->clearMeasures(measureName); 214 205 } … … 225 216 { 226 217 const double resolutionSeconds = 0.000005; 227 return floor(seconds / resolutionSeconds) * resolutionSeconds;218 return std::floor(seconds / resolutionSeconds) * resolutionSeconds; 228 219 } 229 220 -
trunk/Source/WebCore/page/Performance.h
r204976 r207522 37 37 #include "DOMWindowProperty.h" 38 38 #include "EventTarget.h" 39 #include "PerformanceNavigation.h" 40 #include "PerformanceTiming.h" 41 #include "ScriptWrappable.h" 42 #include <wtf/RefCounted.h> 43 #include <wtf/RefPtr.h> 44 #include <wtf/text/WTFString.h> 39 #include "ExceptionOr.h" 45 40 46 41 namespace WebCore { … … 49 44 class LoadTiming; 50 45 class PerformanceEntry; 51 class ResourceRequest; 46 class PerformanceNavigation; 47 class PerformanceTiming; 52 48 class ResourceResponse; 49 class URL; 53 50 class UserTiming; 54 class URL;55 51 56 52 class Performance final : public RefCounted<Performance>, public DOMWindowProperty, public EventTargetWithInlineData { … … 59 55 ~Performance(); 60 56 61 EventTargetInterface eventTargetInterface() const override { return PerformanceEventTargetInterfaceType; } 62 ScriptExecutionContext* scriptExecutionContext() const override; 63 64 PerformanceNavigation* navigation() const; 65 PerformanceTiming* timing() const; 57 PerformanceNavigation& navigation(); 58 PerformanceTiming& timing(); 66 59 double now() const; 67 60 … … 73 66 void setResourceTimingBufferSize(unsigned); 74 67 75 void addResourceTiming(const String& initiatorName, Document*, const URL& originalURL, const ResourceResponse&, LoadTiming);68 void addResourceTiming(const String& initiatorName, Document*, const URL& originalURL, const ResourceResponse&, const LoadTiming&); 76 69 77 using RefCounted <Performance>::ref;78 using RefCounted <Performance>::deref;70 using RefCounted::ref; 71 using RefCounted::deref; 79 72 80 73 #if ENABLE(USER_TIMING) 81 void webkitMark(const String& markName, ExceptionCode&);74 ExceptionOr<void> webkitMark(const String& markName); 82 75 void webkitClearMarks(const String& markName); 83 76 84 void webkitMeasure(const String& measureName, const String& startMark, const String& endMark, ExceptionCode&);77 ExceptionOr<void> webkitMeasure(const String& measureName, const String& startMark, const String& endMark); 85 78 void webkitClearMeasures(const String& measureName); 86 #endif // ENABLE(USER_TIMING)79 #endif 87 80 88 81 static double reduceTimeResolution(double seconds); … … 91 84 explicit Performance(Frame&); 92 85 93 void refEventTarget() override { ref(); } 94 void derefEventTarget() override { deref(); } 86 EventTargetInterface eventTargetInterface() const final { return PerformanceEventTargetInterfaceType; } 87 ScriptExecutionContext* scriptExecutionContext() const final; 88 89 void refEventTarget() final { ref(); } 90 void derefEventTarget() final { deref(); } 91 95 92 bool isResourceTimingBufferFull(); 96 93 … … 98 95 mutable RefPtr<PerformanceTiming> m_timing; 99 96 97 // https://w3c.github.io/resource-timing/#extensions-performance-interface recommends size of 150. 100 98 Vector<RefPtr<PerformanceEntry>> m_resourceTimingBuffer; 101 unsigned m_resourceTimingBufferSize ;99 unsigned m_resourceTimingBufferSize { 150 }; 102 100 103 101 double m_referenceTime; 104 102 105 103 #if ENABLE(USER_TIMING) 106 RefPtr<UserTiming> m_userTiming;107 #endif // ENABLE(USER_TIMING)104 std::unique_ptr<UserTiming> m_userTiming; 105 #endif 108 106 }; 109 107 -
trunk/Source/WebCore/page/Performance.idl
r206723 r207522 42 42 [EnabledAtRuntime=ResourceTiming] PerformanceEntryList getEntriesByName(DOMString name, optional DOMString entryType); 43 43 44 45 44 [EnabledAtRuntime=ResourceTiming] void clearResourceTimings(); 46 45 [EnabledAtRuntime=ResourceTiming] void setResourceTimingBufferSize(unsigned long maxSize); … … 50 49 // See http://www.w3.org/TR/2012/CR-user-timing-20120726/ 51 50 #if defined(ENABLE_USER_TIMING) && ENABLE_USER_TIMING 52 [MayThrow LegacyException] void webkitMark(DOMString markName);53 void webkitClearMarks(optional 51 [MayThrowException] void webkitMark(DOMString markName); 52 void webkitClearMarks(optional DOMString markName); 54 53 55 [MayThrow LegacyException] void webkitMeasure(DOMString measureName, optional DOMString startMark, optional DOMString endMark);54 [MayThrowException] void webkitMeasure(DOMString measureName, optional DOMString startMark, optional DOMString endMark); 56 55 void webkitClearMeasures(optional DOMString measureName); 57 56 #endif -
trunk/Source/WebCore/page/PerformanceUserTiming.cpp
r194578 r207522 29 29 #if ENABLE(USER_TIMING) 30 30 31 #include "ExceptionCode.h" 31 32 #include "Performance.h" 33 #include "PerformanceEntry.h" 32 34 #include "PerformanceMark.h" 33 35 #include "PerformanceMeasure.h" 36 #include <array> 34 37 #include <wtf/NeverDestroyed.h> 35 38 #include <wtf/dtoa/utils.h> 36 #include <wtf/text/WTFString.h>37 39 38 40 namespace WebCore { 39 41 40 42 namespace { 43 44 typedef unsigned long long (PerformanceTiming::*NavigationTimingFunction)() const; 41 45 42 46 static NavigationTimingFunction restrictedMarkFunction(const String& markName) … … 44 48 using MapPair = std::pair<ASCIILiteral, NavigationTimingFunction>; 45 49 static const std::array<MapPair, 21> pairs = { { 46 MapPair{ ASCIILiteral("navigationStart"), &PerformanceTiming::navigationStart },47 MapPair{ ASCIILiteral("unloadEventStart"), &PerformanceTiming::unloadEventStart },48 MapPair{ ASCIILiteral("unloadEventEnd"), &PerformanceTiming::unloadEventEnd },49 MapPair{ ASCIILiteral("redirectStart"), &PerformanceTiming::redirectStart },50 MapPair{ ASCIILiteral("redirectEnd"), &PerformanceTiming::redirectEnd },51 MapPair{ ASCIILiteral("fetchStart"), &PerformanceTiming::fetchStart },52 MapPair{ ASCIILiteral("domainLookupStart"), &PerformanceTiming::domainLookupStart },53 MapPair{ ASCIILiteral("domainLookupEnd"), &PerformanceTiming::domainLookupEnd },54 MapPair{ ASCIILiteral("connectStart"), &PerformanceTiming::connectStart },55 MapPair{ ASCIILiteral("connectEnd"), &PerformanceTiming::connectEnd },56 MapPair{ ASCIILiteral("secureConnectionStart"), &PerformanceTiming::secureConnectionStart },57 MapPair{ ASCIILiteral("requestStart"), &PerformanceTiming::requestStart },58 MapPair{ ASCIILiteral("responseStart"), &PerformanceTiming::responseStart },59 MapPair{ ASCIILiteral("responseEnd"), &PerformanceTiming::responseEnd },60 MapPair{ ASCIILiteral("domLoading"), &PerformanceTiming::domLoading },61 MapPair{ ASCIILiteral("domInteractive"), &PerformanceTiming::domInteractive },62 MapPair{ ASCIILiteral("domContentLoadedEventStart"), &PerformanceTiming::domContentLoadedEventStart },63 MapPair{ ASCIILiteral("domContentLoadedEventEnd"), &PerformanceTiming::domContentLoadedEventEnd },64 MapPair{ ASCIILiteral("domComplete"), &PerformanceTiming::domComplete },65 MapPair{ ASCIILiteral("loadEventStart"), &PerformanceTiming::loadEventStart },66 MapPair{ ASCIILiteral("loadEventEnd"), &PerformanceTiming::loadEventEnd },50 { ASCIILiteral("navigationStart"), &PerformanceTiming::navigationStart }, 51 { ASCIILiteral("unloadEventStart"), &PerformanceTiming::unloadEventStart }, 52 { ASCIILiteral("unloadEventEnd"), &PerformanceTiming::unloadEventEnd }, 53 { ASCIILiteral("redirectStart"), &PerformanceTiming::redirectStart }, 54 { ASCIILiteral("redirectEnd"), &PerformanceTiming::redirectEnd }, 55 { ASCIILiteral("fetchStart"), &PerformanceTiming::fetchStart }, 56 { ASCIILiteral("domainLookupStart"), &PerformanceTiming::domainLookupStart }, 57 { ASCIILiteral("domainLookupEnd"), &PerformanceTiming::domainLookupEnd }, 58 { ASCIILiteral("connectStart"), &PerformanceTiming::connectStart }, 59 { ASCIILiteral("connectEnd"), &PerformanceTiming::connectEnd }, 60 { ASCIILiteral("secureConnectionStart"), &PerformanceTiming::secureConnectionStart }, 61 { ASCIILiteral("requestStart"), &PerformanceTiming::requestStart }, 62 { ASCIILiteral("responseStart"), &PerformanceTiming::responseStart }, 63 { ASCIILiteral("responseEnd"), &PerformanceTiming::responseEnd }, 64 { ASCIILiteral("domLoading"), &PerformanceTiming::domLoading }, 65 { ASCIILiteral("domInteractive"), &PerformanceTiming::domInteractive }, 66 { ASCIILiteral("domContentLoadedEventStart"), &PerformanceTiming::domContentLoadedEventStart }, 67 { ASCIILiteral("domContentLoadedEventEnd"), &PerformanceTiming::domContentLoadedEventEnd }, 68 { ASCIILiteral("domComplete"), &PerformanceTiming::domComplete }, 69 { ASCIILiteral("loadEventStart"), &PerformanceTiming::loadEventStart }, 70 { ASCIILiteral("loadEventEnd"), &PerformanceTiming::loadEventEnd }, 67 71 } }; 68 72 … … 78 82 } // namespace anonymous 79 83 80 UserTiming::UserTiming(Performance *performance)84 UserTiming::UserTiming(Performance& performance) 81 85 : m_performance(performance) 82 86 { … … 103 107 } 104 108 105 void UserTiming::mark(const String& markName, ExceptionCode& ec) 106 { 107 ec = 0; 108 if (restrictedMarkFunction(markName)) { 109 ec = SYNTAX_ERR; 110 return; 111 } 112 113 double startTime = m_performance->now(); 114 insertPerformanceEntry(m_marksMap, PerformanceMark::create(markName, startTime)); 109 ExceptionOr<void> UserTiming::mark(const String& markName) 110 { 111 if (restrictedMarkFunction(markName)) 112 return Exception { SYNTAX_ERR }; 113 114 insertPerformanceEntry(m_marksMap, PerformanceMark::create(markName, m_performance.now())); 115 return { }; 115 116 } 116 117 … … 120 121 } 121 122 122 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionCode& ec) 123 { 124 ec = 0; 125 123 ExceptionOr<double> UserTiming::findExistingMarkStartTime(const String& markName) 124 { 126 125 if (m_marksMap.contains(markName)) 127 126 return m_marksMap.get(markName).last()->startTime(); 128 127 129 128 if (auto function = restrictedMarkFunction(markName)) { 130 double value = static_cast<double>((m_performance->timing()->*(function))()); 131 if (!value) { 132 ec = INVALID_ACCESS_ERR; 133 return 0.0; 134 } 135 return value - m_performance->timing()->navigationStart(); 136 } 137 138 ec = SYNTAX_ERR; 139 return 0.0; 140 } 141 142 void UserTiming::measure(const String& measureName, const String& startMark, const String& endMark, ExceptionCode& ec) 129 double value = static_cast<double>((m_performance.timing().*(function))()); 130 if (!value) 131 return Exception { INVALID_ACCESS_ERR }; 132 return value - m_performance.timing().navigationStart(); 133 } 134 135 return Exception { SYNTAX_ERR }; 136 } 137 138 ExceptionOr<void> UserTiming::measure(const String& measureName, const String& startMark, const String& endMark) 143 139 { 144 140 double startTime = 0.0; … … 146 142 147 143 if (startMark.isNull()) 148 endTime = m_performance ->now();144 endTime = m_performance.now(); 149 145 else if (endMark.isNull()) { 150 endTime = m_performance->now(); 151 startTime = findExistingMarkStartTime(startMark, ec); 152 if (ec) 153 return; 146 endTime = m_performance.now(); 147 auto startMarkResult = findExistingMarkStartTime(startMark); 148 if (startMarkResult.hasException()) 149 return startMarkResult.releaseException(); 150 endTime = startMarkResult.releaseReturnValue(); 154 151 } else { 155 endTime = findExistingMarkStartTime(endMark, ec); 156 if (ec) 157 return; 158 startTime = findExistingMarkStartTime(startMark, ec); 159 if (ec) 160 return; 152 auto endMarkResult = findExistingMarkStartTime(endMark); 153 if (endMarkResult.hasException()) 154 return endMarkResult.releaseException(); 155 auto startMarkResult = findExistingMarkStartTime(startMark); 156 if (startMarkResult.hasException()) 157 return startMarkResult.releaseException(); 158 startTime = startMarkResult.releaseReturnValue(); 159 endTime = endMarkResult.releaseReturnValue(); 161 160 } 162 161 163 162 insertPerformanceEntry(m_measuresMap, PerformanceMeasure::create(measureName, startTime, endTime)); 163 return { }; 164 164 } 165 165 … … 169 169 } 170 170 171 static Vector<RefPtr<PerformanceEntry> > convertToEntrySequence(const PerformanceEntryMap& performanceEntryMap) 172 { 173 Vector<RefPtr<PerformanceEntry> > entries; 174 171 static Vector<RefPtr<PerformanceEntry>> convertToEntrySequence(const PerformanceEntryMap& performanceEntryMap) 172 { 173 Vector<RefPtr<PerformanceEntry>> entries; 175 174 for (auto& entry : performanceEntryMap.values()) 176 175 entries.appendVector(entry); 177 178 176 return entries; 179 177 } 180 178 181 static Vector<RefPtr<PerformanceEntry> > getEntrySequenceByName(const PerformanceEntryMap& performanceEntryMap, const String& name) 182 { 183 Vector<RefPtr<PerformanceEntry> > entries; 184 185 PerformanceEntryMap::const_iterator it = performanceEntryMap.find(name); 186 if (it != performanceEntryMap.end()) 187 entries.appendVector(it->value); 188 189 return entries; 190 } 191 192 Vector<RefPtr<PerformanceEntry> > UserTiming::getMarks() const 179 static Vector<RefPtr<PerformanceEntry>> getEntrySequenceByName(const PerformanceEntryMap& performanceEntryMap, const String& name) 180 { 181 return performanceEntryMap.get(name); 182 } 183 184 Vector<RefPtr<PerformanceEntry>> UserTiming::getMarks() const 193 185 { 194 186 return convertToEntrySequence(m_marksMap); 195 187 } 196 188 197 Vector<RefPtr<PerformanceEntry> 189 Vector<RefPtr<PerformanceEntry>> UserTiming::getMarks(const String& name) const 198 190 { 199 191 return getEntrySequenceByName(m_marksMap, name); 200 192 } 201 193 202 Vector<RefPtr<PerformanceEntry> 194 Vector<RefPtr<PerformanceEntry>> UserTiming::getMeasures() const 203 195 { 204 196 return convertToEntrySequence(m_measuresMap); 205 197 } 206 198 207 Vector<RefPtr<PerformanceEntry> 199 Vector<RefPtr<PerformanceEntry>> UserTiming::getMeasures(const String& name) const 208 200 { 209 201 return getEntrySequenceByName(m_measuresMap, name); -
trunk/Source/WebCore/page/PerformanceUserTiming.h
r204466 r207522 24 24 */ 25 25 26 #ifndef PerformanceUserTiming_h 27 #define PerformanceUserTiming_h 26 #pragma once 28 27 29 28 #if ENABLE(USER_TIMING) 30 29 31 #include "ExceptionCode.h" 32 #include "Performance.h" 33 #include "PerformanceTiming.h" 30 #include "ExceptionOr.h" 34 31 #include <wtf/HashMap.h> 35 #include <wtf/RefCounted.h>36 32 #include <wtf/text/StringHash.h> 37 #include <wtf/text/WTFString.h>38 33 39 34 namespace WebCore { … … 42 37 class PerformanceEntry; 43 38 44 typedef unsigned long long (PerformanceTiming::*NavigationTimingFunction)() const; 45 typedef HashMap<String, Vector<RefPtr<PerformanceEntry> > > PerformanceEntryMap; 39 using PerformanceEntryMap = HashMap<String, Vector<RefPtr<PerformanceEntry>>>; 46 40 47 class UserTiming : public RefCounted<UserTiming>{41 class UserTiming { 48 42 public: 49 static Ref<UserTiming> create(Performance* performance) { return adoptRef(*new UserTiming(performance)); }43 explicit UserTiming(Performance&); 50 44 51 void mark(const String& markName, ExceptionCode&);45 ExceptionOr<void> mark(const String& markName); 52 46 void clearMarks(const String& markName); 53 47 54 void measure(const String& measureName, const String& startMark, const String& endMark, ExceptionCode&);48 ExceptionOr<void> measure(const String& measureName, const String& startMark, const String& endMark); 55 49 void clearMeasures(const String& measureName); 56 50 57 Vector<RefPtr<PerformanceEntry> 58 Vector<RefPtr<PerformanceEntry> 51 Vector<RefPtr<PerformanceEntry>> getMarks() const; 52 Vector<RefPtr<PerformanceEntry>> getMeasures() const; 59 53 60 Vector<RefPtr<PerformanceEntry> 61 Vector<RefPtr<PerformanceEntry> 54 Vector<RefPtr<PerformanceEntry>> getMarks(const String& name) const; 55 Vector<RefPtr<PerformanceEntry>> getMeasures(const String& name) const; 62 56 63 57 private: 64 explicit UserTiming(Performance*);58 ExceptionOr<double> findExistingMarkStartTime(const String& markName); 65 59 66 double findExistingMarkStartTime(const String& markName, ExceptionCode&); 67 Performance* m_performance; 60 Performance& m_performance; 68 61 PerformanceEntryMap m_marksMap; 69 62 PerformanceEntryMap m_measuresMap; … … 73 66 74 67 #endif // ENABLE(USER_TIMING) 75 76 #endif // !defined(PerformanceUserTiming_h) -
trunk/Source/WebCore/page/UserMessageHandler.cpp
r199020 r207522 45 45 } 46 46 47 void UserMessageHandler::postMessage(PassRefPtr<SerializedScriptValue> value, ExceptionCode& ec)47 ExceptionOr<void> UserMessageHandler::postMessage(RefPtr<SerializedScriptValue>&& value) 48 48 { 49 49 // Check to see if the descriptor has been removed. This can happen if the host application has 50 50 // removed the named message handler at the WebKit2 API level. 51 if (!m_descriptor) { 52 ec = INVALID_ACCESS_ERR; 53 return; 54 } 51 if (!m_descriptor) 52 return Exception { INVALID_ACCESS_ERR }; 55 53 56 54 m_descriptor->didPostMessage(*this, value.get()); 55 return { }; 57 56 } 58 57 -
trunk/Source/WebCore/page/UserMessageHandler.h
r199020 r207522 24 24 */ 25 25 26 #ifndef UserMessageHandler_h 27 #define UserMessageHandler_h 26 #pragma once 28 27 29 28 #if ENABLE(USER_MESSAGE_HANDLERS) 30 29 30 #include "ExceptionOr.h" 31 31 #include "FrameDestructionObserver.h" 32 32 #include "UserMessageHandlerDescriptor.h" 33 33 34 34 namespace WebCore { 35 36 typedef int ExceptionCode;37 35 38 36 class UserMessageHandler : public RefCounted<UserMessageHandler>, public FrameDestructionObserver { … … 44 42 virtual ~UserMessageHandler(); 45 43 46 void postMessage(PassRefPtr<SerializedScriptValue>, ExceptionCode&);44 ExceptionOr<void> postMessage(RefPtr<SerializedScriptValue>&&); 47 45 48 46 UserMessageHandlerDescriptor* descriptor() { return m_descriptor.get(); } … … 58 56 59 57 #endif // ENABLE(USER_MESSAGE_HANDLERS) 60 #endif // UserMessageHandler_h -
trunk/Source/WebCore/page/UserMessageHandler.idl
r206723 r207522 27 27 Conditional=USER_MESSAGE_HANDLERS 28 28 ] interface UserMessageHandler { 29 [MayThrow LegacyException] void postMessage(SerializedScriptValue message);29 [MayThrowException] void postMessage(SerializedScriptValue message); 30 30 }; -
trunk/Source/WebCore/storage/Storage.cpp
r194496 r207522 58 58 } 59 59 60 unsigned Storage::length(ExceptionCode& ec) const60 ExceptionOr<unsigned> Storage::length() const 61 61 { 62 ec = 0; 63 if (!m_storageArea->canAccessStorage(m_frame)) { 64 ec = SECURITY_ERR; 65 return 0; 66 } 62 if (!m_storageArea->canAccessStorage(m_frame)) 63 return Exception { SECURITY_ERR }; 67 64 68 65 if (isDisabledByPrivateBrowsing()) … … 72 69 } 73 70 74 String Storage::key(unsigned index, ExceptionCode& ec) const71 ExceptionOr<String> Storage::key(unsigned index) const 75 72 { 76 if (!m_storageArea->canAccessStorage(m_frame)) { 77 ec = SECURITY_ERR; 78 return String(); 79 } 73 if (!m_storageArea->canAccessStorage(m_frame)) 74 return Exception { SECURITY_ERR }; 80 75 81 76 if (isDisabledByPrivateBrowsing()) … … 85 80 } 86 81 87 String Storage::getItem(const String& key, ExceptionCode& ec) const82 ExceptionOr<String> Storage::getItem(const String& key) const 88 83 { 89 if (!m_storageArea->canAccessStorage(m_frame)) { 90 ec = SECURITY_ERR; 91 return String(); 92 } 84 if (!m_storageArea->canAccessStorage(m_frame)) 85 return Exception { SECURITY_ERR }; 93 86 94 87 if (isDisabledByPrivateBrowsing()) … … 98 91 } 99 92 100 void Storage::setItem(const String& key, const String& value, ExceptionCode& ec)93 ExceptionOr<void> Storage::setItem(const String& key, const String& value) 101 94 { 102 if (!m_storageArea->canAccessStorage(m_frame)) { 103 ec = SECURITY_ERR; 104 return; 105 } 95 if (!m_storageArea->canAccessStorage(m_frame)) 96 return Exception { SECURITY_ERR }; 106 97 107 if (isDisabledByPrivateBrowsing()) { 108 ec = QUOTA_EXCEEDED_ERR; 109 return; 110 } 98 if (isDisabledByPrivateBrowsing()) 99 return Exception { QUOTA_EXCEEDED_ERR }; 111 100 112 101 bool quotaException = false; 113 102 m_storageArea->setItem(m_frame, key, value, quotaException); 114 115 103 if (quotaException) 116 ec = QUOTA_EXCEEDED_ERR; 104 return Exception { QUOTA_EXCEEDED_ERR }; 105 return { }; 117 106 } 118 107 119 void Storage::removeItem(const String& key, ExceptionCode& ec)108 ExceptionOr<void> Storage::removeItem(const String& key) 120 109 { 121 if (!m_storageArea->canAccessStorage(m_frame)) { 122 ec = SECURITY_ERR; 123 return; 124 } 110 if (!m_storageArea->canAccessStorage(m_frame)) 111 return Exception { SECURITY_ERR }; 125 112 126 113 if (isDisabledByPrivateBrowsing()) 127 return ;114 return { }; 128 115 129 116 m_storageArea->removeItem(m_frame, key); 117 return { }; 130 118 } 131 119 132 void Storage::clear(ExceptionCode& ec)120 ExceptionOr<void> Storage::clear() 133 121 { 134 if (!m_storageArea->canAccessStorage(m_frame)) { 135 ec = SECURITY_ERR; 136 return; 137 } 122 if (!m_storageArea->canAccessStorage(m_frame)) 123 return Exception { SECURITY_ERR }; 138 124 139 125 if (isDisabledByPrivateBrowsing()) 140 return ;126 return { }; 141 127 142 128 m_storageArea->clear(m_frame); 129 return { }; 143 130 } 144 131 145 bool Storage::contains(const String& key, ExceptionCode& ec) const132 ExceptionOr<bool> Storage::contains(const String& key) const 146 133 { 147 if (!m_storageArea->canAccessStorage(m_frame)) { 148 ec = SECURITY_ERR; 149 return false; 150 } 134 if (!m_storageArea->canAccessStorage(m_frame)) 135 return Exception { SECURITY_ERR }; 151 136 152 137 if (isDisabledByPrivateBrowsing()) -
trunk/Source/WebCore/storage/Storage.h
r189675 r207522 24 24 */ 25 25 26 #ifndef Storage_h 27 #define Storage_h 26 #pragma once 28 27 29 28 #include "DOMWindowProperty.h" 29 #include "ExceptionOr.h" 30 30 #include "ScriptWrappable.h" 31 #include <wtf/Forward.h>32 #include <wtf/RefCounted.h>33 #include <wtf/RefPtr.h>34 31 35 32 namespace WebCore { … … 38 35 class StorageArea; 39 36 40 typedef int ExceptionCode;41 42 37 class Storage : public ScriptWrappable, public RefCounted<Storage>, public DOMWindowProperty { 43 38 public: … … 45 40 ~Storage(); 46 41 47 unsigned length(ExceptionCode&) const;48 String key(unsigned index, ExceptionCode&) const;49 String getItem(const String& key, ExceptionCode&) const;50 void setItem(const String& key, const String& value, ExceptionCode&);51 void removeItem(const String& key, ExceptionCode&);52 void clear(ExceptionCode&);53 bool contains(const String& key, ExceptionCode&) const;42 ExceptionOr<unsigned> length() const; 43 ExceptionOr<String> key(unsigned index) const; 44 ExceptionOr<String> getItem(const String& key) const; 45 ExceptionOr<void> setItem(const String& key, const String& value); 46 ExceptionOr<void> removeItem(const String& key); 47 ExceptionOr<void> clear(); 48 ExceptionOr<bool> contains(const String& key) const; 54 49 55 50 StorageArea& area() const { return *m_storageArea; } … … 64 59 65 60 } // namespace WebCore 66 67 #endif // Storage_h -
trunk/Source/WebCore/storage/Storage.idl
r206723 r207522 31 31 SkipVTableValidation, 32 32 ] interface Storage { 33 [GetterMayThrow LegacyException] readonly attribute unsigned long length;34 [MayThrow LegacyException] DOMString? key(unsigned long index);35 [MayThrow LegacyException] getter DOMString? getItem(DOMString key);36 [MayThrow LegacyException] void setItem(DOMString key, DOMString data);37 [MayThrow LegacyException] void removeItem(DOMString key);38 [MayThrow LegacyException] void clear();33 [GetterMayThrowException] readonly attribute unsigned long length; 34 [MayThrowException] DOMString? key(unsigned long index); 35 [MayThrowException] getter DOMString? getItem(DOMString key); 36 [MayThrowException] void setItem(DOMString key, DOMString data); 37 [MayThrowException] void removeItem(DOMString key); 38 [MayThrowException] void clear(); 39 39 }; 40 40 -
trunk/Source/WebCore/storage/StorageEventDispatcher.cpp
r184990 r207522 80 80 81 81 for (auto& frame : frames) { 82 ExceptionCode ec = 0; 83 Storage* storage = frame->document()->domWindow()->sessionStorage(ec); 84 if (!ec) 85 frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, storage)); 82 auto result = frame->document()->domWindow()->sessionStorage(); 83 if (!result.hasException()) 84 frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, result.releaseReturnValue())); 86 85 } 87 86 } … … 93 92 94 93 for (auto& frame : frames) { 95 ExceptionCode ec = 0; 96 Storage* storage = frame->document()->domWindow()->localStorage(ec); 97 if (!ec) 98 frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, storage)); 94 auto result = frame->document()->domWindow()->localStorage(); 95 if (!result.hasException()) 96 frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, result.releaseReturnValue())); 99 97 } 100 98 } -
trunk/Source/WebKit/win/ChangeLog
r207495 r207522 1 2016-10-18 Darin Adler <darin@apple.com> 2 3 Move many miscellaneous classes from ExceptionCode to Exception 4 https://bugs.webkit.org/show_bug.cgi?id=163645 5 6 Reviewed by Ryosuke Niwa. 7 8 * DOMCoreClasses.cpp: 9 (DOMDocument::getComputedStyle): Use ptr instead of get since the return 10 value is now Ref instead of RefPtr. 11 1 12 2016-10-18 Anders Carlsson <andersca@apple.com> 2 13 -
trunk/Source/WebKit/win/DOMCoreClasses.cpp
r203651 r207522 804 804 return E_FAIL; 805 805 806 *result = DOMCSSStyleDeclaration::createInstance(dv->getComputedStyle(*element, pseudoEltString.impl()). get());806 *result = DOMCSSStyleDeclaration::createInstance(dv->getComputedStyle(*element, pseudoEltString.impl()).ptr()); 807 807 return *result ? S_OK : E_FAIL; 808 808 }
Note: See TracChangeset
for help on using the changeset viewer.