Shaka Player Embedded
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
shaka::js::XMLHttpRequest Class Reference

#include <xml_http_request.h>

Inheritance diagram for shaka::js::XMLHttpRequest:
shaka::js::events::EventTarget shaka::BackingObject shaka::memory::Traceable

Public Types

enum  ReadyState {
  ReadyState::Unsent = 0, ReadyState::Opened = 1, ReadyState::HeadersReceived = 2, ReadyState::Loading = 3,
  ReadyState::Done = 4
}
 
- Public Types inherited from shaka::js::events::EventTarget
using Listener = optional< Callback >
 

Public Member Functions

 XMLHttpRequest ()
 
void Trace (memory::HeapTracer *tracer) const override
 
bool IsShortLived () const override
 
void Abort ()
 
std::string GetAllResponseHeaders () const
 
optional< std::string > GetResponseHeader (const std::string &name) const
 
ExceptionOr< void > Open (const std::string &method, const std::string &url, optional< bool > async, optional< std::string > user, optional< std::string > password)
 
ExceptionOr< void > Send (optional< variant< ByteBuffer, ByteString >> maybe_data)
 
ExceptionOr< void > SetRequestHeader (const std::string &key, const std::string &value)
 
bool WithCredentials () const
 
ExceptionOr< void > SetWithCredentials (bool with_credentials)
 
void OnDataReceived (uint8_t *buffer, size_t length)
 
void OnHeaderReceived (const uint8_t *buffer, size_t length)
 
size_t OnUpload (uint8_t *buffer, size_t length)
 
- Public Member Functions inherited from shaka::js::events::EventTarget
 EventTarget ()
 
void AddEventListener (const std::string &type, Listener callback)
 
void SetCppEventListener (EventType type, std::function< void()> callback)
 
void RemoveEventListener (const std::string &type, Listener callback)
 
void UnsetCppEventListener (EventType type)
 
ExceptionOr< bool > DispatchEvent (RefPtr< Event > event)
 
ExceptionOr< bool > DispatchEventInternal (RefPtr< Event > event, bool *did_listeners_throw)
 
template<typename EventType , typename... Args>
std::shared_ptr< ThreadEvent< bool > > ScheduleEvent (Args &&... args)
 
template<typename EventType , typename... Args>
ExceptionOr< bool > RaiseEvent (Args... args)
 
- Public Member Functions inherited from shaka::BackingObject
 BackingObject ()
 
void Trace (memory::HeapTracer *tracer) const override
 
bool IsRootedAlive () const override
 
std::string name () const
 
virtual BackingObjectFactoryBasefactory () const =0
 
bool DerivedFrom (const std::string &base)
 
ReturnVal< JsValue > JsThis () const
 
void SetJsThis (Handle< JsObject > this_)
 
- Public Member Functions inherited from shaka::memory::Traceable
virtual ~Traceable ()
 

Static Public Member Functions

static XMLHttpRequestCreate ()
 
- Static Public Member Functions inherited from shaka::BackingObject
static void * operator new[] (size_t size)=delete
 
static void operator delete[] (void *)=delete
 

Public Attributes

Listener on_abort
 
Listener on_error
 
Listener on_load
 
Listener on_load_start
 
Listener on_progress
 
Listener on_ready_state_change
 
Listener on_timeout
 
Listener on_load_end
 
ReadyState ready_state
 
ByteBuffer response
 
std::string response_text
 
std::string response_type
 
std::string response_url
 
int status
 
std::string status_text
 
uint64_t timeout_ms
 

Additional Inherited Members

- Static Public Attributes inherited from shaka::BackingObject
static constexpr const size_t kInternalFieldCount = 2
 
- Static Public Attributes inherited from shaka::memory::Traceable
static constexpr const uint64_t kShortLiveDurationMs = 5000
 
- Protected Member Functions inherited from shaka::js::events::EventTarget
void AddListenerField (EventType type, Listener *on_field)
 
- Protected Member Functions inherited from shaka::BackingObject
 ~BackingObject () override
 

Detailed Description

An implementation of JavaScript XMLHttpRequest. This handles network requests using CURL.

Notes:

IMPORTANT:

Definition at line 58 of file xml_http_request.h.

Member Enumeration Documentation

§ ReadyState

Enumerator
Unsent 
Opened 
HeadersReceived 
Loading 
Done 

Definition at line 62 of file xml_http_request.h.

Constructor & Destructor Documentation

§ XMLHttpRequest()

shaka::js::XMLHttpRequest::XMLHttpRequest ( )

Definition at line 128 of file xml_http_request.cc.

Member Function Documentation

§ Abort()

void shaka::js::XMLHttpRequest::Abort ( )

Definition at line 171 of file xml_http_request.cc.

§ Create()

static XMLHttpRequest* shaka::js::XMLHttpRequest::Create ( )
inlinestatic

Definition at line 71 of file xml_http_request.h.

§ GetAllResponseHeaders()

std::string shaka::js::XMLHttpRequest::GetAllResponseHeaders ( ) const

Definition at line 197 of file xml_http_request.cc.

§ GetResponseHeader()

shaka::optional< std::string > shaka::js::XMLHttpRequest::GetResponseHeader ( const std::string &  name) const

Definition at line 206 of file xml_http_request.cc.

§ IsShortLived()

bool shaka::js::XMLHttpRequest::IsShortLived ( ) const
overridevirtual

Gets whether the object is considered short-lived. This means that once the C++ ref-count is zero, the object won't remain alive for long. It is important to only set this if the JavaScript object won't be used for long.

This exists for JSC which doesn't offer a way for us to track whether a JavaScript object is still alive. If the JavaScript object is used after the backing object is destroyed, then a JavaScript exception will be thrown.

Reimplemented from shaka::memory::Traceable.

Definition at line 167 of file xml_http_request.cc.

§ OnDataReceived()

void shaka::js::XMLHttpRequest::OnDataReceived ( uint8_t *  buffer,
size_t  length 
)

Called from a CURL callback when (part of) the body data is received.

Definition at line 343 of file xml_http_request.cc.

§ OnHeaderReceived()

void shaka::js::XMLHttpRequest::OnHeaderReceived ( const uint8_t *  buffer,
size_t  length 
)

Called from a CURL callback for each header that is received.

Parameters
bufferA buffer containing exactly one header.
lengthThe length of |buffer|.

Definition at line 361 of file xml_http_request.cc.

§ OnUpload()

size_t shaka::js::XMLHttpRequest::OnUpload ( uint8_t *  buffer,
size_t  length 
)

Called from a CURL callback when uploading data.

Definition at line 419 of file xml_http_request.cc.

§ Open()

ExceptionOr< void > shaka::js::XMLHttpRequest::Open ( const std::string &  method,
const std::string &  url,
optional< bool >  async,
optional< std::string >  user,
optional< std::string >  password 
)

Definition at line 215 of file xml_http_request.cc.

§ Send()

ExceptionOr< void > shaka::js::XMLHttpRequest::Send ( optional< variant< ByteBuffer, ByteString >>  maybe_data)

Definition at line 246 of file xml_http_request.cc.

§ SetRequestHeader()

ExceptionOr< void > shaka::js::XMLHttpRequest::SetRequestHeader ( const std::string &  key,
const std::string &  value 
)

Definition at line 293 of file xml_http_request.cc.

§ SetWithCredentials()

ExceptionOr< void > shaka::js::XMLHttpRequest::SetWithCredentials ( bool  with_credentials)

Definition at line 309 of file xml_http_request.cc.

§ Trace()

Doxygen_Skip void shaka::js::XMLHttpRequest::Trace ( memory::HeapTracer tracer) const
overridevirtual

Called during a GC run. This should call HeapTracer::Trace on all Traceable members. Be sure to call the base method when overriding.

Reimplemented from shaka::js::events::EventTarget.

Definition at line 159 of file xml_http_request.cc.

§ WithCredentials()

bool shaka::js::XMLHttpRequest::WithCredentials ( ) const

Definition at line 305 of file xml_http_request.cc.

Member Data Documentation

§ on_abort

Listener shaka::js::XMLHttpRequest::on_abort

Definition at line 105 of file xml_http_request.h.

§ on_error

Listener shaka::js::XMLHttpRequest::on_error

Definition at line 106 of file xml_http_request.h.

§ on_load

Listener shaka::js::XMLHttpRequest::on_load

Definition at line 107 of file xml_http_request.h.

§ on_load_end

Listener shaka::js::XMLHttpRequest::on_load_end

Definition at line 112 of file xml_http_request.h.

§ on_load_start

Listener shaka::js::XMLHttpRequest::on_load_start

Definition at line 108 of file xml_http_request.h.

§ on_progress

Listener shaka::js::XMLHttpRequest::on_progress

Definition at line 109 of file xml_http_request.h.

§ on_ready_state_change

Listener shaka::js::XMLHttpRequest::on_ready_state_change

Definition at line 110 of file xml_http_request.h.

§ on_timeout

Listener shaka::js::XMLHttpRequest::on_timeout

Definition at line 111 of file xml_http_request.h.

§ ready_state

ReadyState shaka::js::XMLHttpRequest::ready_state

Definition at line 114 of file xml_http_request.h.

§ response

ByteBuffer shaka::js::XMLHttpRequest::response

Definition at line 115 of file xml_http_request.h.

§ response_text

std::string shaka::js::XMLHttpRequest::response_text

Definition at line 116 of file xml_http_request.h.

§ response_type

std::string shaka::js::XMLHttpRequest::response_type

Definition at line 117 of file xml_http_request.h.

§ response_url

std::string shaka::js::XMLHttpRequest::response_url

Definition at line 118 of file xml_http_request.h.

§ status

int shaka::js::XMLHttpRequest::status

Definition at line 119 of file xml_http_request.h.

§ status_text

std::string shaka::js::XMLHttpRequest::status_text

Definition at line 120 of file xml_http_request.h.

§ timeout_ms

uint64_t shaka::js::XMLHttpRequest::timeout_ms

Definition at line 121 of file xml_http_request.h.


The documentation for this class was generated from the following files: