2023-02-28 00:23:53 +00:00
/*
* Copyright ( c ) 2023 , Luke Wilde < lukew @ serenityos . org >
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# include <LibWeb/Bindings/Intrinsics.h>
2024-04-27 12:09:58 +12:00
# include <LibWeb/Bindings/PluginArrayPrototype.h>
2023-02-28 00:23:53 +00:00
# include <LibWeb/HTML/PluginArray.h>
# include <LibWeb/HTML/Scripting/Environments.h>
# include <LibWeb/HTML/Window.h>
# include <LibWeb/Page/Page.h>
namespace Web : : HTML {
2024-11-15 04:01:23 +13:00
GC_DEFINE_ALLOCATOR ( PluginArray ) ;
2023-11-19 19:47:52 +01:00
2023-02-28 00:23:53 +00:00
PluginArray : : PluginArray ( JS : : Realm & realm )
2024-01-09 16:05:03 -07:00
: Bindings : : PlatformObject ( realm )
2023-02-28 00:23:53 +00:00
{
2024-01-09 16:05:03 -07:00
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
. supports_indexed_properties = true ,
. supports_named_properties = true ,
. has_legacy_unenumerable_named_properties_interface_extended_attribute = true ,
} ;
2023-02-28 00:23:53 +00:00
}
PluginArray : : ~ PluginArray ( ) = default ;
2023-08-07 08:41:28 +02:00
void PluginArray : : initialize ( JS : : Realm & realm )
2023-02-28 00:23:53 +00:00
{
2023-08-07 08:41:28 +02:00
Base : : initialize ( realm ) ;
2024-03-16 13:13:08 +01:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( PluginArray ) ;
2023-02-28 00:23:53 +00:00
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-refresh
void PluginArray : : refresh ( ) const
{
// The PluginArray interface's refresh() method steps are to do nothing.
}
// https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewing-support:support-named-properties
2023-12-24 20:59:00 +01:00
Vector < FlyString > PluginArray : : supported_property_names ( ) const
2023-02-28 00:23:53 +00:00
{
// The PluginArray interface supports named properties. If the user agent's PDF viewer supported is true, then they are the PDF viewer plugin names. Otherwise, they are the empty list.
auto const & window = verify_cast < HTML : : Window > ( HTML : : relevant_global_object ( * this ) ) ;
2023-12-15 20:33:16 +01:00
if ( ! window . page ( ) . pdf_viewer_supported ( ) )
2023-02-28 00:23:53 +00:00
return { } ;
// https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-plugin-names
2023-12-24 20:59:00 +01:00
static Vector < FlyString > const plugin_names = {
" PDF Viewer " _fly_string ,
" Chrome PDF Viewer " _fly_string ,
" Chromium PDF Viewer " _fly_string ,
" Microsoft Edge PDF Viewer " _fly_string ,
" WebKit built-in PDF " _fly_string ,
2023-02-28 00:23:53 +00:00
} ;
return plugin_names ;
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-length
size_t PluginArray : : length ( ) const
{
// The PluginArray interface's length getter steps are to return this's relevant global object's PDF viewer plugin objects's size.
auto & window = verify_cast < HTML : : Window > ( HTML : : relevant_global_object ( * this ) ) ;
return window . pdf_viewer_plugin_objects ( ) . size ( ) ;
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-item
2024-11-15 04:01:23 +13:00
GC : : Ptr < Plugin > PluginArray : : item ( u32 index ) const
2023-02-28 00:23:53 +00:00
{
// 1. Let plugins be this's relevant global object's PDF viewer plugin objects.
auto & window = verify_cast < HTML : : Window > ( HTML : : relevant_global_object ( * this ) ) ;
auto plugins = window . pdf_viewer_plugin_objects ( ) ;
// 2. If index < plugins's size, then return plugins[index].
if ( index < plugins . size ( ) )
return plugins [ index ] ;
// 3. Return null.
return nullptr ;
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-pluginarray-nameditem
2024-11-15 04:01:23 +13:00
GC : : Ptr < Plugin > PluginArray : : named_item ( FlyString const & name ) const
2023-02-28 00:23:53 +00:00
{
// 1. For each Plugin plugin of this's relevant global object's PDF viewer plugin objects: if plugin's name is name, then return plugin.
auto & window = verify_cast < HTML : : Window > ( HTML : : relevant_global_object ( * this ) ) ;
auto plugins = window . pdf_viewer_plugin_objects ( ) ;
for ( auto & plugin : plugins ) {
if ( plugin - > name ( ) = = name )
return plugin ;
}
// 2. Return null.
return nullptr ;
}
2024-07-25 18:15:51 +12:00
Optional < JS : : Value > PluginArray : : item_value ( size_t index ) const
2023-02-28 00:23:53 +00:00
{
auto return_value = item ( index ) ;
if ( ! return_value )
2024-07-25 18:15:51 +12:00
return { } ;
2023-02-28 00:23:53 +00:00
return return_value . ptr ( ) ;
}
2024-07-25 17:36:10 +12:00
JS : : Value PluginArray : : named_item_value ( FlyString const & name ) const
2023-02-28 00:23:53 +00:00
{
2023-10-08 13:16:50 +13:00
auto return_value = named_item ( name ) ;
2023-02-28 00:23:53 +00:00
if ( ! return_value )
return JS : : js_null ( ) ;
return return_value . ptr ( ) ;
}
}