Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] - Revert SkusScript MethodIDs #27010

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class BraveSkusScriptHandler: TabContentScript {

return WKUserScript(
source: secureScript(
handlerNamesMap: ["$<message_handler>": messageHandlerName],
handlerNamesMap: ["$<message_handler>": messageHandlerName]
.merging(Method.map, uniquingKeysWith: { $1 }),
securityToken: scriptId,
script: script
),
Expand Down Expand Up @@ -68,7 +69,7 @@ class BraveSkusScriptHandler: TabContentScript {
return
}

guard let requestedMethod = response["method_id"] as? Int,
guard let requestedMethod = response["method_id"] as? String,
let method = Method(rawValue: requestedMethod)
else {
Logger.module.error("Brave skus request with invalid method-id")
Expand Down Expand Up @@ -139,12 +140,12 @@ class BraveSkusScriptHandler: TabContentScript {
}

extension BraveSkusScriptHandler {
private enum Method: Int, CaseIterable {
case refreshOrder = 1
case fetchOrderCredentials = 2
case prepareCredentialsPresentation = 3
case credentialsSummary = 4
case setLocalStorageReceipt = 5
private enum Method: String, CaseIterable {
case refreshOrder
case fetchOrderCredentials
case prepareCredentialsPresentation
case credentialsSummary
case setLocalStorageReceipt

static var map: [String: String] {
var jsDict = [String: String]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ window.__firefox__.includeOnce("BraveSkusScript", function($) {
}

// Request VPN Receipt
sendMessage($<setLocalStorageReceipt>, { "message": "vpn" })
sendMessage('$<setLocalStorageReceipt>', { "message": "vpn" })
.then(function(jsonData) {
if (jsonData) {
window.localStorage.setItem(jsonData["key"], jsonData["data"]);
Expand All @@ -31,7 +31,7 @@ window.__firefox__.includeOnce("BraveSkusScript", function($) {
});

// Request Leo Receipt
sendMessage($<setLocalStorageReceipt>, { "message": "leo" })
sendMessage('$<setLocalStorageReceipt>', { "message": "leo" })
.then(function(jsonData) {
if (jsonData) {
window.localStorage.setItem("braveLeo.orderId", jsonData["braveLeo.orderId"])
Expand All @@ -49,19 +49,19 @@ window.__firefox__.includeOnce("BraveSkusScript", function($) {
writable: false,
value: {
refresh_order(orderId) {
return sendMessage($<refreshOrder>, { orderId });
return sendMessage('$<refreshOrder>', { orderId });
},

fetch_order_credentials(orderId) {
return sendMessage($<fetchOrderCredentials>, { orderId });
return sendMessage('$<fetchOrderCredentials>', { orderId });
},

prepare_credentials_presentation(domain, path) {
return sendMessage($<prepareCredentialsPresentation>, { domain, path });
return sendMessage('$<prepareCredentialsPresentation>', { domain, path });
},

credential_summary(domain) {
return sendMessage($<credentialsSummary>, { domain });
return sendMessage('$<credentialsSummary>', { domain });
}
}
});
Expand Down
Loading