@@ -39,6 +39,7 @@ inline constexpr char kIntentParamTestValue[] = "connect-receipt-test";
39
39
inline constexpr char kProductParamName [] = " product" ;
40
40
inline constexpr char kProductVPNParamValue [] = " vpn" ;
41
41
inline constexpr char kProductLeoParamValue [] = " leo" ;
42
+ inline constexpr char kIntentParamValueLeo [] = " link-order" ;
42
43
43
44
} // namespace
44
45
@@ -61,8 +62,7 @@ bool SubscriptionRenderFrameObserver::EnsureConnected() {
61
62
}
62
63
#endif
63
64
#if BUILDFLAG(ENABLE_AI_CHAT)
64
- if (ai_chat::features::IsAIChatHistoryEnabled () &&
65
- product_ == Product::kLeo ) {
65
+ if (ai_chat::features::IsAIChatEnabled () && product_ == Product::kLeo ) {
66
66
if (!ai_chat_subscription_.is_bound ()) {
67
67
render_frame ()->GetBrowserInterfaceBroker ()->GetInterface (
68
68
ai_chat_subscription_.BindNewPipeAndPassReceiver ());
@@ -105,36 +105,59 @@ void SubscriptionRenderFrameObserver::DidCreateScriptContext(
105
105
} else if (product_ == Product::kLeo ) {
106
106
#if BUILDFLAG(ENABLE_AI_CHAT)
107
107
if (ai_chat_subscription_.is_bound ()) {
108
- ai_chat_subscription_->GetPurchaseToken (
109
- base::BindOnce ( &SubscriptionRenderFrameObserver::OnGetPurchaseToken ,
110
- weak_factory_.GetWeakPtr ()));
108
+ ai_chat_subscription_->GetPurchaseTokenOrderId ( base::BindOnce (
109
+ &SubscriptionRenderFrameObserver::OnGetPurchaseTokenOrderId ,
110
+ weak_factory_.GetWeakPtr ()));
111
111
}
112
112
#endif
113
113
}
114
114
}
115
115
116
+ std::string SubscriptionRenderFrameObserver::GetPurchaseTokenJSString (
117
+ const std::string& purchase_token) {
118
+ if (!IsValueAllowed (purchase_token)) {
119
+ return " " ;
120
+ }
121
+
122
+ std::string_view receipt_var_name;
123
+ if (product_ == Product::kVPN ) {
124
+ receipt_var_name = " braveVpn.receipt" ;
125
+ } else if (product_ == Product::kLeo ) {
126
+ receipt_var_name = " braveLeo.receipt" ;
127
+ }
128
+
129
+ return base::StrCat ({" window.localStorage.setItem(\" " , receipt_var_name,
130
+ " \" , \" " , purchase_token, " \" );" });
131
+ }
132
+
116
133
void SubscriptionRenderFrameObserver::OnGetPurchaseToken (
117
134
const std::string& purchase_token) {
118
135
if (!IsAllowed ()) {
119
136
return ;
120
137
}
121
138
auto * frame = render_frame ();
122
139
if (frame) {
123
- if (IsValueAllowed (purchase_token)) {
124
- std::string_view receipt_var_name;
125
- if (product_ == Product::kVPN ) {
126
- receipt_var_name = " braveVpn.receipt" ;
127
- } else if (product_ == Product::kLeo ) {
128
- receipt_var_name = " braveLeo.receipt" ;
129
- }
130
- std::u16string set_local_storage = base::UTF8ToUTF16 (
131
- base::StrCat ({" window.localStorage.setItem(\" " , receipt_var_name,
132
- " \" , \" " , purchase_token, " \" );" }));
133
- frame->ExecuteJavaScript (set_local_storage);
140
+ std::string set_local_storage = GetPurchaseTokenJSString (purchase_token);
141
+ if (!set_local_storage.empty ()) {
142
+ frame->ExecuteJavaScript (base::UTF8ToUTF16 (set_local_storage));
134
143
}
135
144
}
136
145
}
137
146
147
+ void SubscriptionRenderFrameObserver::OnGetPurchaseTokenOrderId (
148
+ const std::string& purchase_token,
149
+ const std::string& order_id) {
150
+ if (!IsAllowed ()) {
151
+ return ;
152
+ }
153
+ auto * frame = render_frame ();
154
+ if (frame && !order_id.empty () && !purchase_token.empty ()) {
155
+ frame->ExecuteJavaScript (base::UTF8ToUTF16 (base::StrCat (
156
+ {" window.localStorage.setItem(\" braveLeo.orderId\" , \" " , order_id,
157
+ " \" );" , GetPurchaseTokenJSString (purchase_token)})));
158
+ }
159
+ }
160
+
138
161
std::string SubscriptionRenderFrameObserver::ExtractParam (
139
162
const GURL& url,
140
163
const std::string& name) const {
@@ -182,7 +205,8 @@ bool SubscriptionRenderFrameObserver::IsAllowed() {
182
205
} else {
183
206
product_ = std::nullopt;
184
207
}
185
- return (intent == kIntentParamValue || intent == kIntentParamTestValue ) &&
208
+ return (intent == kIntentParamValue || intent == kIntentParamTestValue ||
209
+ intent == kIntentParamValueLeo ) &&
186
210
product_.has_value ();
187
211
}
188
212
0 commit comments