Skip to content

Truly independent web browser

2.7 KB
Raw Blame
/*
 * Copyright (c) 2022-2023, Linus Groh <[email protected]>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Forward.h>
#include <AK/Variant.h>
#include <LibGC/Ptr.h>
#include <LibJS/Forward.h>
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>

namespace JS {

class HostObject;

}

namespace Web::HTML {

enum class SecurityCheckType {
    Method,
    Getter,
    Setter,
};

JS::ThrowCompletionOr<void> perform_a_security_check(JS::VM&, JS::Value platform_object, Utf16View const& identifier, SecurityCheckType);

GC::Ptr<RemoteWindow> remote_window_from(JS::Value);

template<typename Callback>
decltype(auto) invoke_on_window(Window* window, RemoteWindow* remote_window, Callback&& callback)
{
    if (remote_window)
        return callback(*remote_window);
    return callback(*window);
}

Vector<CrossOriginProperty> cross_origin_properties(Variant<HTML::Location const*, HTML::Window const*, HTML::RemoteWindow const*> const&);
JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::VM&, JS::PropertyKey const&);
bool is_platform_object_same_origin(JS::Object const&);
bool is_platform_object_same_origin(Location const&);
bool is_platform_object_same_origin(Window const&);
bool is_platform_object_same_origin(RemoteWindow const&);

// The [[CrossOriginPropertyDescriptorMap]] internal slot of a Location or Window wrapper. It lives in a companion cell
// in the wrapper's host data, which is created on first use.
WEB_API CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map(JS::HostObject& location_or_window_wrapper);

// For a Window hosted by another process, O is the WindowProxy object and the RemoteWindow holds the map.
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(JS::HostObject& location_wrapper, HTML::Location const&, JS::PropertyKey const&);
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(JS::HostObject& window_wrapper, HTML::Window&, JS::PropertyKey const&);
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(JS::HostObject& window_proxy, HTML::RemoteWindow&, JS::PropertyKey const&);

JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::VM&, JS::Object const&, JS::PropertyKey const&, JS::Value receiver);
JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM&, JS::Object&, JS::PropertyKey const&, JS::Value, JS::Value receiver);
GC::RootVector<JS::Value> cross_origin_own_property_keys(HTML::Location const&);
GC::RootVector<JS::Value> cross_origin_own_property_keys(HTML::Window const&);
GC::RootVector<JS::Value> cross_origin_own_property_keys(HTML::RemoteWindow const&);

}