| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // This file has been auto-generated by code_generator_v8.py. |
| // DO NOT MODIFY! |
| |
| // This file has been generated from the Jinja2 template in |
| // third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl |
| |
| // clang-format off |
| #include "V8PaymentRequest.h" |
| |
| #include "bindings/core/v8/ExceptionState.h" |
| #include "bindings/core/v8/IDLTypes.h" |
| #include "bindings/core/v8/NativeValueTraitsImpl.h" |
| #include "bindings/core/v8/ScriptPromise.h" |
| #include "bindings/core/v8/ScriptState.h" |
| #include "bindings/core/v8/V8AbstractEventListener.h" |
| #include "bindings/core/v8/V8DOMConfiguration.h" |
| #include "bindings/core/v8/V8EventListenerHelper.h" |
| #include "bindings/core/v8/V8ObjectConstructor.h" |
| #include "bindings/core/v8/V8PrivateProperty.h" |
| #include "bindings/modules/v8/V8PaymentAddress.h" |
| #include "bindings/modules/v8/V8PaymentDetailsInit.h" |
| #include "bindings/modules/v8/V8PaymentMethodData.h" |
| #include "bindings/modules/v8/V8PaymentOptions.h" |
| #include "core/dom/ExecutionContext.h" |
| #include "core/frame/LocalDOMWindow.h" |
| #include "core/inspector/ConsoleMessage.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| #include "platform/wtf/GetPtr.h" |
| #include "platform/wtf/RefPtr.h" |
| |
| namespace blink { |
| |
| // Suppress warning: global constructors, because struct WrapperTypeInfo is trivial |
| // and does not depend on another global objects. |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| const WrapperTypeInfo V8PaymentRequest::wrapperTypeInfo = { gin::kEmbedderBlink, V8PaymentRequest::domTemplate, V8PaymentRequest::Trace, V8PaymentRequest::TraceWrappers, nullptr, "PaymentRequest", &V8EventTarget::wrapperTypeInfo, WrapperTypeInfo::kWrapperTypeObjectPrototype, WrapperTypeInfo::kObjectClassId, WrapperTypeInfo::kInheritFromActiveScriptWrappable, WrapperTypeInfo::kDependent }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic pop |
| #endif |
| |
| // This static member must be declared by DEFINE_WRAPPERTYPEINFO in PaymentRequest.h. |
| // For details, see the comment of DEFINE_WRAPPERTYPEINFO in |
| // bindings/core/v8/ScriptWrappable.h. |
| const WrapperTypeInfo& PaymentRequest::wrapper_type_info_ = V8PaymentRequest::wrapperTypeInfo; |
| |
| // [ActiveScriptWrappable] |
| static_assert( |
| std::is_base_of<ActiveScriptWrappableBase, PaymentRequest>::value, |
| "PaymentRequest does not inherit from ActiveScriptWrappable<>, but specifying " |
| "[ActiveScriptWrappable] extended attribute in the IDL file. " |
| "Be consistent."); |
| static_assert( |
| !std::is_same<decltype(&PaymentRequest::HasPendingActivity), |
| decltype(&ScriptWrappable::HasPendingActivity)>::value, |
| "PaymentRequest is not overriding hasPendingActivity(), but is specifying " |
| "[ActiveScriptWrappable] extended attribute in the IDL file. " |
| "Be consistent."); |
| |
| namespace PaymentRequestV8Internal { |
| |
| static void idAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Object> holder = info.Holder(); |
| |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| V8SetReturnValueString(info, impl->id(), info.GetIsolate()); |
| } |
| |
| static void shippingAddressAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Object> holder = info.Holder(); |
| |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| PaymentAddress* cppValue(WTF::GetPtr(impl->getShippingAddress())); |
| |
| // Keep the wrapper object for the return value alive as long as |this| |
| // object is alive in order to save creation time of the wrapper object. |
| if (cppValue && DOMDataStore::SetReturnValue(info.GetReturnValue(), cppValue)) |
| return; |
| v8::Local<v8::Value> v8Value(ToV8(cppValue, holder, info.GetIsolate())); |
| V8PrivateProperty::GetSymbol( |
| info.GetIsolate(), "KeepAlive#PaymentRequest#shippingAddress") |
| .Set(holder, v8Value); |
| |
| V8SetReturnValue(info, v8Value); |
| } |
| |
| static void shippingOptionAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Object> holder = info.Holder(); |
| |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| V8SetReturnValueStringOrNull(info, impl->shippingOption(), info.GetIsolate()); |
| } |
| |
| static void shippingTypeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Object> holder = info.Holder(); |
| |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| V8SetReturnValueStringOrNull(info, impl->shippingType(), info.GetIsolate()); |
| } |
| |
| static void onshippingaddresschangeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Object> holder = info.Holder(); |
| |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| EventListener* cppValue(WTF::GetPtr(impl->onshippingaddresschange())); |
| |
| V8SetReturnValue(info, cppValue ? V8AbstractEventListener::Cast(cppValue)->GetListenerOrNull(info.GetIsolate(), impl->GetExecutionContext()) : v8::Null(info.GetIsolate()).As<v8::Value>()); |
| } |
| |
| static void onshippingaddresschangeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Isolate* isolate = info.GetIsolate(); |
| ALLOW_UNUSED_LOCAL(isolate); |
| |
| v8::Local<v8::Object> holder = info.Holder(); |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| // Prepare the value to be set. |
| MoveEventListenerToNewWrapper(isolate, holder, impl->onshippingaddresschange(), v8Value, V8PaymentRequest::eventListenerCacheIndex); |
| |
| impl->setOnshippingaddresschange(V8EventListenerHelper::GetEventListener(ScriptState::ForReceiverObject(info), v8Value, true, kListenerFindOrCreate)); |
| } |
| |
| static void onshippingoptionchangeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Object> holder = info.Holder(); |
| |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| EventListener* cppValue(WTF::GetPtr(impl->onshippingoptionchange())); |
| |
| V8SetReturnValue(info, cppValue ? V8AbstractEventListener::Cast(cppValue)->GetListenerOrNull(info.GetIsolate(), impl->GetExecutionContext()) : v8::Null(info.GetIsolate()).As<v8::Value>()); |
| } |
| |
| static void onshippingoptionchangeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Isolate* isolate = info.GetIsolate(); |
| ALLOW_UNUSED_LOCAL(isolate); |
| |
| v8::Local<v8::Object> holder = info.Holder(); |
| PaymentRequest* impl = V8PaymentRequest::toImpl(holder); |
| |
| // Prepare the value to be set. |
| MoveEventListenerToNewWrapper(isolate, holder, impl->onshippingoptionchange(), v8Value, V8PaymentRequest::eventListenerCacheIndex); |
| |
| impl->setOnshippingoptionchange(V8EventListenerHelper::GetEventListener(ScriptState::ForReceiverObject(info), v8Value, true, kListenerFindOrCreate)); |
| } |
| |
| static void showMethod(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionContext, "PaymentRequest", "show"); |
| ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); |
| |
| // V8DOMConfiguration::kDoNotCheckHolder |
| // Make sure that info.Holder() really points to an instance of the type. |
| if (!V8PaymentRequest::hasInstance(info.Holder(), info.GetIsolate())) { |
| exceptionState.ThrowTypeError("Illegal invocation"); |
| return; |
| } |
| PaymentRequest* impl = V8PaymentRequest::toImpl(info.Holder()); |
| |
| ScriptState* scriptState = ScriptState::ForReceiverObject(info); |
| |
| ScriptPromise result = impl->show(scriptState); |
| V8SetReturnValue(info, result.V8Value()); |
| } |
| |
| static void abortMethod(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionContext, "PaymentRequest", "abort"); |
| ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); |
| |
| // V8DOMConfiguration::kDoNotCheckHolder |
| // Make sure that info.Holder() really points to an instance of the type. |
| if (!V8PaymentRequest::hasInstance(info.Holder(), info.GetIsolate())) { |
| exceptionState.ThrowTypeError("Illegal invocation"); |
| return; |
| } |
| PaymentRequest* impl = V8PaymentRequest::toImpl(info.Holder()); |
| |
| ScriptState* scriptState = ScriptState::ForReceiverObject(info); |
| |
| ScriptPromise result = impl->abort(scriptState); |
| V8SetReturnValue(info, result.V8Value()); |
| } |
| |
| static void canMakePaymentMethod(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionContext, "PaymentRequest", "canMakePayment"); |
| ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); |
| |
| // V8DOMConfiguration::kDoNotCheckHolder |
| // Make sure that info.Holder() really points to an instance of the type. |
| if (!V8PaymentRequest::hasInstance(info.Holder(), info.GetIsolate())) { |
| exceptionState.ThrowTypeError("Illegal invocation"); |
| return; |
| } |
| PaymentRequest* impl = V8PaymentRequest::toImpl(info.Holder()); |
| |
| ScriptState* scriptState = ScriptState::ForReceiverObject(info); |
| |
| ScriptPromise result = impl->canMakePayment(scriptState); |
| V8SetReturnValue(info, result.V8Value()); |
| } |
| |
| static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kConstructionContext, "PaymentRequest"); |
| |
| if (UNLIKELY(info.Length() < 2)) { |
| exceptionState.ThrowTypeError(ExceptionMessages::NotEnoughArguments(2, info.Length())); |
| return; |
| } |
| |
| HeapVector<PaymentMethodData> methodData; |
| PaymentDetailsInit details; |
| PaymentOptions options; |
| methodData = NativeValueTraits<IDLSequence<PaymentMethodData>>::NativeValue(info.GetIsolate(), info[0], exceptionState); |
| if (exceptionState.HadException()) |
| return; |
| |
| if (!IsUndefinedOrNull(info[1]) && !info[1]->IsObject()) { |
| exceptionState.ThrowTypeError("parameter 2 ('details') is not an object."); |
| |
| return; |
| } |
| V8PaymentDetailsInit::toImpl(info.GetIsolate(), info[1], details, exceptionState); |
| if (exceptionState.HadException()) |
| return; |
| |
| if (!IsUndefinedOrNull(info[2]) && !info[2]->IsObject()) { |
| exceptionState.ThrowTypeError("parameter 3 ('options') is not an object."); |
| |
| return; |
| } |
| V8PaymentOptions::toImpl(info.GetIsolate(), info[2], options, exceptionState); |
| if (exceptionState.HadException()) |
| return; |
| |
| ExecutionContext* executionContext = CurrentExecutionContext(info.GetIsolate()); |
| PaymentRequest* impl = PaymentRequest::Create(executionContext, methodData, details, options, exceptionState); |
| if (exceptionState.HadException()) { |
| return; |
| } |
| v8::Local<v8::Object> wrapper = info.Holder(); |
| wrapper = impl->AssociateWithWrapper(info.GetIsolate(), &V8PaymentRequest::wrapperTypeInfo, wrapper); |
| V8SetReturnValue(info, wrapper); |
| } |
| |
| } // namespace PaymentRequestV8Internal |
| |
| void V8PaymentRequest::idAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::idAttributeGetter(info); |
| } |
| |
| void V8PaymentRequest::shippingAddressAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::shippingAddressAttributeGetter(info); |
| } |
| |
| void V8PaymentRequest::shippingOptionAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::shippingOptionAttributeGetter(info); |
| } |
| |
| void V8PaymentRequest::shippingTypeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::shippingTypeAttributeGetter(info); |
| } |
| |
| void V8PaymentRequest::onshippingaddresschangeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::onshippingaddresschangeAttributeGetter(info); |
| } |
| |
| void V8PaymentRequest::onshippingaddresschangeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Value> v8Value = info[0]; |
| |
| PaymentRequestV8Internal::onshippingaddresschangeAttributeSetter(v8Value, info); |
| } |
| |
| void V8PaymentRequest::onshippingoptionchangeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::onshippingoptionchangeAttributeGetter(info); |
| } |
| |
| void V8PaymentRequest::onshippingoptionchangeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Local<v8::Value> v8Value = info[0]; |
| |
| PaymentRequestV8Internal::onshippingoptionchangeAttributeSetter(v8Value, info); |
| } |
| |
| void V8PaymentRequest::showMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::showMethod(info); |
| } |
| |
| void V8PaymentRequest::abortMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::abortMethod(info); |
| } |
| |
| void V8PaymentRequest::canMakePaymentMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| PaymentRequestV8Internal::canMakePaymentMethod(info); |
| } |
| |
| static const V8DOMConfiguration::AccessorConfiguration V8PaymentRequestAccessors[] = { |
| {"id", V8PaymentRequest::idAttributeGetterCallback, nullptr, nullptr, nullptr, static_cast<v8::PropertyAttribute>(v8::ReadOnly), V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kAllWorlds}, |
| {"shippingAddress", V8PaymentRequest::shippingAddressAttributeGetterCallback, nullptr, nullptr, nullptr, static_cast<v8::PropertyAttribute>(v8::ReadOnly), V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kAllWorlds}, |
| {"shippingOption", V8PaymentRequest::shippingOptionAttributeGetterCallback, nullptr, nullptr, nullptr, static_cast<v8::PropertyAttribute>(v8::ReadOnly), V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kAllWorlds}, |
| {"shippingType", V8PaymentRequest::shippingTypeAttributeGetterCallback, nullptr, nullptr, nullptr, static_cast<v8::PropertyAttribute>(v8::ReadOnly), V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kAllWorlds}, |
| {"onshippingaddresschange", V8PaymentRequest::onshippingaddresschangeAttributeGetterCallback, V8PaymentRequest::onshippingaddresschangeAttributeSetterCallback, nullptr, nullptr, static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kAllWorlds}, |
| {"onshippingoptionchange", V8PaymentRequest::onshippingoptionchangeAttributeGetterCallback, V8PaymentRequest::onshippingoptionchangeAttributeSetterCallback, nullptr, nullptr, static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kCheckHolder, V8DOMConfiguration::kAllWorlds}, |
| }; |
| |
| static const V8DOMConfiguration::MethodConfiguration V8PaymentRequestMethods[] = { |
| {"show", V8PaymentRequest::showMethodCallback, 0, v8::None, V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kDoNotCheckHolder, V8DOMConfiguration::kDoNotCheckAccess, V8DOMConfiguration::kAllWorlds}, |
| {"abort", V8PaymentRequest::abortMethodCallback, 0, v8::None, V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kDoNotCheckHolder, V8DOMConfiguration::kDoNotCheckAccess, V8DOMConfiguration::kAllWorlds}, |
| }; |
| |
| void V8PaymentRequest::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| if (!info.IsConstructCall()) { |
| V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::ConstructorNotCallableAsFunction("PaymentRequest")); |
| return; |
| } |
| |
| if (ConstructorMode::Current(info.GetIsolate()) == ConstructorMode::kWrapExistingObject) { |
| V8SetReturnValue(info, info.Holder()); |
| return; |
| } |
| |
| PaymentRequestV8Internal::constructor(info); |
| } |
| |
| static void installV8PaymentRequestTemplate(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) { |
| // Initialize the interface object's template. |
| V8DOMConfiguration::InitializeDOMInterfaceTemplate(isolate, interfaceTemplate, V8PaymentRequest::wrapperTypeInfo.interface_name, V8EventTarget::domTemplate(isolate, world), V8PaymentRequest::internalFieldCount); |
| interfaceTemplate->SetCallHandler(V8PaymentRequest::constructorCallback); |
| interfaceTemplate->SetLength(2); |
| |
| if (!RuntimeEnabledFeatures::paymentRequestEnabled()) { |
| return; |
| } |
| |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemplate); |
| ALLOW_UNUSED_LOCAL(signature); |
| v8::Local<v8::ObjectTemplate> instanceTemplate = interfaceTemplate->InstanceTemplate(); |
| ALLOW_UNUSED_LOCAL(instanceTemplate); |
| v8::Local<v8::ObjectTemplate> prototypeTemplate = interfaceTemplate->PrototypeTemplate(); |
| ALLOW_UNUSED_LOCAL(prototypeTemplate); |
| |
| // Register DOM constants, attributes and operations. |
| V8DOMConfiguration::InstallAccessors(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, V8PaymentRequestAccessors, WTF_ARRAY_LENGTH(V8PaymentRequestAccessors)); |
| V8DOMConfiguration::InstallMethods(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, V8PaymentRequestMethods, WTF_ARRAY_LENGTH(V8PaymentRequestMethods)); |
| |
| if (RuntimeEnabledFeatures::canMakePaymentEnabled()) { |
| const V8DOMConfiguration::MethodConfiguration canMakePaymentMethodConfiguration[] = { |
| {"canMakePayment", V8PaymentRequest::canMakePaymentMethodCallback, 0, v8::None, V8DOMConfiguration::kOnPrototype, V8DOMConfiguration::kDoNotCheckHolder, V8DOMConfiguration::kDoNotCheckAccess, V8DOMConfiguration::kAllWorlds} |
| }; |
| for (const auto& methodConfig : canMakePaymentMethodConfiguration) |
| V8DOMConfiguration::InstallMethod(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, methodConfig); |
| } |
| } |
| |
| v8::Local<v8::FunctionTemplate> V8PaymentRequest::domTemplate(v8::Isolate* isolate, const DOMWrapperWorld& world) { |
| return V8DOMConfiguration::DomClassTemplate(isolate, world, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8PaymentRequestTemplate); |
| } |
| |
| bool V8PaymentRequest::hasInstance(v8::Local<v8::Value> v8Value, v8::Isolate* isolate) { |
| return V8PerIsolateData::From(isolate)->HasInstance(&wrapperTypeInfo, v8Value); |
| } |
| |
| v8::Local<v8::Object> V8PaymentRequest::findInstanceInPrototypeChain(v8::Local<v8::Value> v8Value, v8::Isolate* isolate) { |
| return V8PerIsolateData::From(isolate)->FindInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); |
| } |
| |
| PaymentRequest* V8PaymentRequest::toImplWithTypeCheck(v8::Isolate* isolate, v8::Local<v8::Value> value) { |
| return hasInstance(value, isolate) ? toImpl(v8::Local<v8::Object>::Cast(value)) : nullptr; |
| } |
| |
| PaymentRequest* NativeValueTraits<PaymentRequest>::NativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState) { |
| PaymentRequest* nativeValue = V8PaymentRequest::toImplWithTypeCheck(isolate, value); |
| if (!nativeValue) { |
| exceptionState.ThrowTypeError(ExceptionMessages::FailedToConvertJSValue( |
| "PaymentRequest")); |
| } |
| return nativeValue; |
| } |
| |
| } // namespace blink |