Skip to content

Commit

Permalink
Remove submit_receipt method from window.chrome.braveSkus
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Jul 5, 2022
1 parent 7aca3b4 commit 641462c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 61 deletions.
11 changes: 7 additions & 4 deletions components/skus/browser/skus_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,16 @@ void SkusServiceImpl::OnCredentialSummary(
}
}

void SkusServiceImpl::SubmitReceipt(const std::string& order_id,
const std::string& receipt,
skus::mojom::SkusService::SubmitReceiptCallback callback) {
void SkusServiceImpl::SubmitReceipt(
const std::string& domain,
const std::string& order_id,
const std::string& receipt,
skus::mojom::SkusService::SubmitReceiptCallback callback) {
std::unique_ptr<skus::SubmitReceiptCallbackState> cbs(
new skus::SubmitReceiptCallbackState);
cbs->cb = std::move(callback);
sdk_->submit_receipt(OnSubmitReceipt, std::move(cbs), order_id, receipt);
GetOrCreateSDK(domain)->submit_receipt(OnSubmitReceipt, std::move(cbs),
order_id, receipt);
}

} // namespace skus
1 change: 1 addition & 0 deletions components/skus/browser/skus_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SkusServiceImpl : public KeyedService, public mojom::SkusService {
const std::string& domain,
skus::mojom::SkusService::CredentialSummaryCallback callback) override;
void SubmitReceipt(
const std::string& domain,
const std::string& order_id,
const std::string& receipt,
skus::mojom::SkusService::SubmitReceiptCallback callback) override;
Expand Down
2 changes: 1 addition & 1 deletion components/skus/common/skus_sdk.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface SkusService {
FetchOrderCredentials(string domain, string order_id) => (string response);
PrepareCredentialsPresentation(string domain, string path) => (string response);
CredentialSummary(string domain) => (string response);
SubmitReceipt(string order_id, string receipt) => (string response);
SubmitReceipt(string domain, string order_id, string receipt) => (string response);
};
48 changes: 1 addition & 47 deletions components/skus/renderer/skus_js_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,51 +325,6 @@ void SkusJSHandler::OnCredentialSummary(
std::ignore = resolver->Resolve(context, local_result);
}

// window.chrome.braveSkus.submit_receipt
v8::Local<v8::Promise> SkusJSHandler::SubmitReceipt(v8::Isolate* isolate,
std::string order_id,
std::string receipt) {
if (!EnsureConnected())
return v8::Local<v8::Promise>();

v8::MaybeLocal<v8::Promise::Resolver> resolver =
v8::Promise::Resolver::New(isolate->GetCurrentContext());
if (resolver.IsEmpty()) {
return v8::Local<v8::Promise>();
}

auto promise_resolver(
v8::Global<v8::Promise::Resolver>(isolate, resolver.ToLocalChecked()));
auto context_old(
v8::Global<v8::Context>(isolate, isolate->GetCurrentContext()));

skus_service_->SubmitReceipt(
order_id, receipt,
base::BindOnce(&SkusJSHandler::OnSubmitReceipt, base::Unretained(this),
std::move(promise_resolver), isolate,
std::move(context_old)));

return resolver.ToLocalChecked()->GetPromise();
}
void SkusJSHandler::OnSubmitReceipt(
v8::Global<v8::Promise::Resolver> promise_resolver,
v8::Isolate* isolate,
v8::Global<v8::Context> context_old,
const std::string& response) {
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = context_old.Get(isolate);
v8::Context::Scope context_scope(context);
v8::MicrotasksScope microtasks(isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);

v8::Local<v8::Promise::Resolver> resolver = promise_resolver.Get(isolate);
v8::Local<v8::String> result;
result =
v8::String::NewFromUtf8(isolate, response.c_str()).ToLocalChecked();

std::ignore = resolver->Resolve(context, result);
}

gin::ObjectTemplateBuilder SkusJSHandler::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<SkusJSHandler>::GetObjectTemplateBuilder(isolate)
Expand All @@ -378,8 +333,7 @@ gin::ObjectTemplateBuilder SkusJSHandler::GetObjectTemplateBuilder(
&SkusJSHandler::FetchOrderCredentials)
.SetMethod("prepare_credentials_presentation",
&SkusJSHandler::PrepareCredentialsPresentation)
.SetMethod("credential_summary", &SkusJSHandler::CredentialSummary)
.SetMethod("submit_receipt", &SkusJSHandler::SubmitReceipt);
.SetMethod("credential_summary", &SkusJSHandler::CredentialSummary);
}

} // namespace skus
9 changes: 0 additions & 9 deletions components/skus/renderer/skus_js_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ class SkusJSHandler : public gin::Wrappable<SkusJSHandler> {
v8::Global<v8::Context> context_old,
const std::string& response);

// window.chrome.braveSkus.submit_receipt
v8::Local<v8::Promise> SubmitReceipt(v8::Isolate* isolate,
std::string order_id,
std::string receipt);
void OnSubmitReceipt(v8::Global<v8::Promise::Resolver> promise_resolver,
v8::Isolate* isolate,
v8::Global<v8::Context> context_old,
const std::string& response);

content::RenderFrame* render_frame_;
mojo::Remote<skus::mojom::SkusService> skus_service_;
mojo::Remote<brave_vpn::mojom::ServiceHandler> vpn_service_;
Expand Down

0 comments on commit 641462c

Please sign in to comment.