| 1 | /* |
| 2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "JSRemoteDOMWindow.h" |
| 28 | |
| 29 | #include "JSDOMWindowCustom.h" |
| 30 | #include "WebCoreJSClientData.h" |
| 31 | |
| 32 | namespace WebCore { |
| 33 | using namespace JSC; |
| 34 | |
| 35 | bool JSRemoteDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
| 36 | { |
| 37 | if (Optional<unsigned> index = parseIndex(propertyName)) |
| 38 | return getOwnPropertySlotByIndex(object, state, index.value(), slot); |
| 39 | |
| 40 | auto* thisObject = jsCast<JSRemoteDOMWindow*>(object); |
| 41 | return jsDOMWindowGetOwnPropertySlotRestrictedAccess<DOMWindowType::Remote>(thisObject, thisObject->wrapped(), *state, propertyName, slot, String()); |
| 42 | } |
| 43 | |
| 44 | bool JSRemoteDOMWindow::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
| 45 | { |
| 46 | auto* thisObject = jsCast<JSRemoteDOMWindow*>(object); |
| 47 | |
| 48 | // Indexed getters take precendence over regular properties, so caching would be invalid. |
| 49 | slot.disableCaching(); |
| 50 | |
| 51 | // FIXME: Add support for indexed properties. |
| 52 | |
| 53 | return jsDOMWindowGetOwnPropertySlotRestrictedAccess<DOMWindowType::Remote>(thisObject, thisObject->wrapped(), *state, Identifier::from(state, index), slot, String()); |
| 54 | } |
| 55 | |
| 56 | bool JSRemoteDOMWindow::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& slot) |
| 57 | { |
| 58 | VM& vm = state->vm(); |
| 59 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 60 | |
| 61 | auto* thisObject = jsCast<JSRemoteDOMWindow*>(cell); |
| 62 | if (!thisObject->wrapped().frame()) |
| 63 | return false; |
| 64 | |
| 65 | String errorMessage; |
| 66 | |
| 67 | // We only allow setting "location" attribute cross-origin. |
| 68 | if (propertyName == static_cast<JSVMClientData*>(vm.clientData)->builtinNames().locationPublicName()) { |
| 69 | bool putResult = false; |
| 70 | if (lookupPut(state, propertyName, thisObject, value, *s_info.staticPropHashTable, slot, putResult)) |
| 71 | return putResult; |
| 72 | return false; |
| 73 | } |
| 74 | throwSecurityError(*state, scope, errorMessage); |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | bool JSRemoteDOMWindow::putByIndex(JSCell*, ExecState*, unsigned, JSValue, bool) |
| 79 | { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | bool JSRemoteDOMWindow::deleteProperty(JSCell*, ExecState* state, PropertyName) |
| 84 | { |
| 85 | VM& vm = state->vm(); |
| 86 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 87 | |
| 88 | throwSecurityError(*state, scope, String()); |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | bool JSRemoteDOMWindow::deletePropertyByIndex(JSCell*, ExecState* state, unsigned) |
| 93 | { |
| 94 | VM& vm = state->vm(); |
| 95 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 96 | |
| 97 | throwSecurityError(*state, scope, String()); |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | void JSRemoteDOMWindow::getOwnPropertyNames(JSObject*, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) |
| 102 | { |
| 103 | // FIXME: Add scoped children indexes. |
| 104 | |
| 105 | if (mode.includeDontEnumProperties()) |
| 106 | addCrossOriginOwnPropertyNames<CrossOriginObject::Window>(*exec, propertyNames); |
| 107 | } |
| 108 | |
| 109 | bool JSRemoteDOMWindow::defineOwnProperty(JSC::JSObject*, JSC::ExecState* state, JSC::PropertyName, const JSC::PropertyDescriptor&, bool) |
| 110 | { |
| 111 | VM& vm = state->vm(); |
| 112 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 113 | |
| 114 | throwSecurityError(*state, scope, String()); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | JSValue JSRemoteDOMWindow::getPrototype(JSObject*, ExecState*) |
| 119 | { |
| 120 | return jsNull(); |
| 121 | } |
| 122 | |
| 123 | bool JSRemoteDOMWindow::preventExtensions(JSObject*, ExecState* exec) |
| 124 | { |
| 125 | auto scope = DECLARE_THROW_SCOPE(exec->vm()); |
| 126 | throwTypeError(exec, scope, "Cannot prevent extensions on this object"_s ); |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | String JSRemoteDOMWindow::toStringName(const JSObject*, ExecState*) |
| 131 | { |
| 132 | return "Object"_s ; |
| 133 | } |
| 134 | |
| 135 | } // namepace WebCore |
| 136 | |