From 259a5ada2f774c0cc89304f49b28c653ba30e9e9 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Thu, 26 Mar 2020 10:55:44 +0000 Subject: [PATCH] Send platform, build channel and country code as part of ad confirmation calls where it meets privacy standards --- browser/brave_stats_updater.cc | 1 + browser/brave_stats_updater_util.cc | 8 - browser/brave_stats_updater_util.h | 2 - common/BUILD.gn | 2 + common/brave_channel_info.cc | 25 + common/brave_channel_info.h | 18 + .../brave_rewards/browser/android_util.cc | 2 + .../browser/rewards_service_impl.cc | 3 + components/p3a/BUILD.gn | 1 + components/p3a/brave_p3a_service.cc | 1 + test/BUILD.gn | 1 + .../bat-native-ads/include/bat/ads/ad_info.h | 1 + vendor/bat-native-ads/src/bat/ads/ad_info.cc | 7 + .../src/bat/ads/ad_notification_info.cc | 3 + .../src/bat/ads/internal/ad_notifications.cc | 11 + .../src/bat/ads/internal/ad_notifications.h | 3 + .../src/bat/ads/internal/ads_impl.cc | 1 + .../src/bat/ads/internal/static_values.h | 5 + vendor/bat-native-confirmations/BUILD.gn | 31 + .../include/bat/confirmations/ad_info.h | 1 + .../internal/confirmation_info.h | 1 + ...ns_create_confirmation_request_unittest.cc | 160 +++++- .../internal/confirmations_impl.cc | 5 + .../internal/confirmations_impl.h | 2 + .../internal/create_confirmation_request.cc | 48 +- .../internal/create_confirmation_request.h | 18 +- .../confirmations/internal/platform_info.h | 17 + .../internal/platform_info_android.cc | 14 + .../internal/platform_info_ios.mm | 14 + .../internal/platform_info_linux.cc | 14 + .../internal/platform_info_mac.mm | 14 + .../internal/platform_info_win.cc | 14 + .../confirmations/internal/redeem_token.cc | 36 +- .../confirmations/internal/static_values.h | 530 ++++++++++++++++++ .../bat/ledger/public/interfaces/ledger.mojom | 1 + .../src/bat/ledger/internal/ledger_impl.cc | 1 + vendor/brave-ios/Ads/BATAdNotification.h | 1 + vendor/brave-ios/Ads/BATAdNotification.mm | 2 + 38 files changed, 985 insertions(+), 34 deletions(-) create mode 100644 common/brave_channel_info.cc create mode 100644 common/brave_channel_info.h create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info.h create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_android.cc create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_ios.mm create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_linux.cc create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_mac.mm create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_win.cc diff --git a/browser/brave_stats_updater.cc b/browser/brave_stats_updater.cc index c29cda7e79af..9d724afc1880 100644 --- a/browser/brave_stats_updater.cc +++ b/browser/brave_stats_updater.cc @@ -12,6 +12,7 @@ #include "brave/browser/brave_stats_updater_params.h" #include "brave/browser/brave_stats_updater_util.h" #include "brave/browser/version_info.h" +#include "brave/common/brave_channel_info.h" #include "brave/common/pref_names.h" #include "brave/components/brave_referrals/buildflags/buildflags.h" #include "chrome/browser/browser_process.h" diff --git a/browser/brave_stats_updater_util.cc b/browser/brave_stats_updater_util.cc index 584a5edca412..3ebcb06c2d6d 100644 --- a/browser/brave_stats_updater_util.cc +++ b/browser/brave_stats_updater_util.cc @@ -11,7 +11,6 @@ #include "base/strings/string_piece.h" #include "base/strings/string_split.h" #include "base/strings/stringprintf.h" -#include "chrome/common/channel_info.h" namespace brave { @@ -22,13 +21,6 @@ std::string GetDateAsYMD(const base::Time& time) { exploded.day_of_month); } -std::string GetChannelName() { - std::string channel = chrome::GetChannelName(); - if (channel.empty()) - channel = "release"; - return channel; -} - std::string GetPlatformIdentifier() { #if defined(OS_WIN) if (base::SysInfo::OperatingSystemArchitecture() == "x86") diff --git a/browser/brave_stats_updater_util.h b/browser/brave_stats_updater_util.h index 2a66ee68f32e..d3830ee49d9e 100644 --- a/browser/brave_stats_updater_util.h +++ b/browser/brave_stats_updater_util.h @@ -15,8 +15,6 @@ namespace brave { std::string GetDateAsYMD(const base::Time& time); -std::string GetChannelName(); - std::string GetPlatformIdentifier(); int GetIsoWeekNumber(const base::Time& time); diff --git a/common/BUILD.gn b/common/BUILD.gn index af38dc651bd1..724893bf0485 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -47,6 +47,8 @@ source_set("switches") { source_set("common") { sources = [ + "brave_channel_info.cc", + "brave_channel_info.h", "brave_content_client.cc", "brave_content_client.h", "brave_features.cc", diff --git a/common/brave_channel_info.cc b/common/brave_channel_info.cc new file mode 100644 index 000000000000..67a7d975655d --- /dev/null +++ b/common/brave_channel_info.cc @@ -0,0 +1,25 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/common/brave_channel_info.h" + +#include "chrome/common/channel_info.h" + +namespace brave { + +std::string GetChannelName() { +#if defined(OFFICIAL_BUILD) + std::string channel_name = chrome::GetChannelName(); + if (channel_name.empty()) { + channel_name = "release"; + } + + return channel_name; +#else // OFFICIAL_BUILD + return "developer"; +#endif // !OFFICIAL_BUILD +} + +} // namespace brave diff --git a/common/brave_channel_info.h b/common/brave_channel_info.h new file mode 100644 index 000000000000..73e49b170afd --- /dev/null +++ b/common/brave_channel_info.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_ +#define BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_ + +#include + +namespace brave { + +std::string GetChannelName(); + +} + +#endif // BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_ + diff --git a/components/brave_rewards/browser/android_util.cc b/components/brave_rewards/browser/android_util.cc index b9dde3cbd726..02abf7397b45 100644 --- a/components/brave_rewards/browser/android_util.cc +++ b/components/brave_rewards/browser/android_util.cc @@ -5,6 +5,7 @@ #include "base/json/json_reader.h" #include "brave/components/brave_rewards/browser/android_util.h" +#include "brave/common/brave_channel_info.h" namespace android_util { @@ -12,6 +13,7 @@ ledger::ClientInfoPtr GetAndroidClientInfo() { auto info = ledger::ClientInfo::New(); info->platform = ledger::Platform::ANDROID_R; info->os = ledger::OperatingSystem::UNDEFINED; + info->channel = brave::GetChannelName(); return info; } diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 3c53ecc33b52..36ef1c64b331 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -38,6 +38,7 @@ #include "brave/base/containers/utils.h" #include "brave/browser/ui/webui/brave_rewards_source.h" #include "brave/components/brave_rewards/common/pref_names.h" +#include "brave/common/brave_channel_info.h" #include "brave/common/pref_names.h" #include "brave/components/brave_ads/browser/ads_service.h" #include "brave/components/brave_ads/browser/ads_service_factory.h" @@ -3273,6 +3274,8 @@ ledger::ClientInfoPtr GetDesktopClientInfo() { info->os = ledger::OperatingSystem::UNDEFINED; #endif + info->channel = brave::GetChannelName(); + return info; } diff --git a/components/p3a/BUILD.gn b/components/p3a/BUILD.gn index 601d86c63f6a..e0cbfbaa3cf6 100644 --- a/components/p3a/BUILD.gn +++ b/components/p3a/BUILD.gn @@ -26,6 +26,7 @@ source_set("p3a") { ] deps = [ + "//brave/common", "//brave/components/p3a:buildflags", "//brave/components/brave_prochlo", "//brave/components/brave_prochlo:prochlo_proto", diff --git a/components/p3a/brave_p3a_service.cc b/components/p3a/brave_p3a_service.cc index 51163191d903..74a533e640db 100644 --- a/components/p3a/brave_p3a_service.cc +++ b/components/p3a/brave_p3a_service.cc @@ -19,6 +19,7 @@ #include "base/trace_event/trace_event.h" #include "brave/browser/brave_stats_updater_util.h" #include "brave/browser/version_info.h" +#include "brave/common/brave_channel_info.h" #include "brave/common/pref_names.h" #include "brave/components/brave_prochlo/prochlo_message.pb.h" #include "brave/components/p3a/brave_p3a_log_store.h" diff --git a/test/BUILD.gn b/test/BUILD.gn index 63f59e0e74bb..8dfd8011fff4 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -366,6 +366,7 @@ test("brave_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_is_mobile_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h", + "//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_helper_mock.h", "//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/ad_grants_unittest.cc", "//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/payments_unittest.cc", "//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_create_confirmation_request_unittest.cc", diff --git a/vendor/bat-native-ads/include/bat/ads/ad_info.h b/vendor/bat-native-ads/include/bat/ads/ad_info.h index b17be63dd652..11695f58b9a1 100644 --- a/vendor/bat-native-ads/include/bat/ads/ad_info.h +++ b/vendor/bat-native-ads/include/bat/ads/ad_info.h @@ -29,6 +29,7 @@ struct ADS_EXPORT AdInfo { std::string creative_set_id; std::string category; std::string target_url; + std::string geo_target; }; } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/ad_info.cc b/vendor/bat-native-ads/src/bat/ads/ad_info.cc index f4d72ad14a39..182124816ae2 100644 --- a/vendor/bat-native-ads/src/bat/ads/ad_info.cc +++ b/vendor/bat-native-ads/src/bat/ads/ad_info.cc @@ -51,6 +51,10 @@ Result AdInfo::FromJson( target_url = document["url"].GetString(); } + if (document.HasMember("geo_target")) { + geo_target = document["geo_target"].GetString(); + } + return SUCCESS; } @@ -71,6 +75,9 @@ void SaveToJson( writer->String("url"); writer->String(info.target_url.c_str()); + writer->String("geo_target"); + writer->String(info.geo_target.c_str()); + writer->EndObject(); } diff --git a/vendor/bat-native-ads/src/bat/ads/ad_notification_info.cc b/vendor/bat-native-ads/src/bat/ads/ad_notification_info.cc index 75262583d112..36fcada53322 100644 --- a/vendor/bat-native-ads/src/bat/ads/ad_notification_info.cc +++ b/vendor/bat-native-ads/src/bat/ads/ad_notification_info.cc @@ -101,6 +101,9 @@ void SaveToJson( writer->String("url"); writer->String(info.target_url.c_str()); + writer->String("geo_target"); + writer->String(info.geo_target.c_str()); + writer->EndObject(); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.cc index 2d851aa9f769..78d22e291565 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.cc @@ -31,6 +31,7 @@ const char kNotificationCategoryKey[] = "category"; const char kNotificationTitleKey[] = "advertiser"; const char kNotificationBodyKey[] = "text"; const char kNotificationTargetUrlKey[] = "url"; +const char kNotificationGeoTargetKey[] = "geo_target"; AdNotifications::AdNotifications( AdsImpl* ads, @@ -214,6 +215,10 @@ bool AdNotifications::GetNotificationFromDictionary( return false; } + if (!GetGeoTargetFromDictionary(dictionary, ¬ification_info.geo_target)) { + return false; + } + *info = notification_info; return true; @@ -269,6 +274,12 @@ bool AdNotifications::GetTargetUrlFromDictionary( return GetStringFromDictionary(kNotificationTargetUrlKey, dictionary, value); } +bool AdNotifications::GetGeoTargetFromDictionary( + base::DictionaryValue* dictionary, + std::string* value) const { + return GetStringFromDictionary(kNotificationGeoTargetKey, dictionary, value); +} + bool AdNotifications::GetStringFromDictionary( const std::string& key, base::DictionaryValue* dictionary, diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.h b/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.h index 4f9cb9e69a39..cd302ed5ed1b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.h @@ -87,6 +87,9 @@ class AdNotifications { bool GetTargetUrlFromDictionary( base::DictionaryValue* dictionary, std::string* value) const; + bool GetGeoTargetFromDictionary( + base::DictionaryValue* dictionary, + std::string* value) const; bool GetStringFromDictionary( const std::string& key, diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc index 6682067d850f..bd05b65dcfb3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc @@ -1295,6 +1295,7 @@ bool AdsImpl::ShowAdNotification( ad_notification->title = info.title; ad_notification->body = info.body; ad_notification->target_url = helper::Uri::GetUri(info.target_url); + ad_notification->geo_target = info.geo_targets.at(0); BLOG(INFO) << "Ad notification shown:" << std::endl << " uuid: " << ad_notification->uuid diff --git a/vendor/bat-native-ads/src/bat/ads/internal/static_values.h b/vendor/bat-native-ads/src/bat/ads/internal/static_values.h index 37887573d133..aeb1297afb78 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/static_values.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/static_values.h @@ -65,6 +65,11 @@ const uint64_t kRetryDownloadingCatalogAfterSeconds = const std::map> kSupportedRegionsSchemas = { // Append newly supported regions with a new schema version and update // |kSupportedRegionsSchemaVersionNumber| to match the new version + + // |kLargeAnonymityCountryCodes| and |kOtherCountryCodes| in + // bat-native-confirmations/src/bat/confirmations/internal/static_values.h + // must be updated to reflect newly supported regions + // // Format: { schema_version : { region... } } { diff --git a/vendor/bat-native-confirmations/BUILD.gn b/vendor/bat-native-confirmations/BUILD.gn index 059688429e09..7b802b3b16b9 100644 --- a/vendor/bat-native-confirmations/BUILD.gn +++ b/vendor/bat-native-confirmations/BUILD.gn @@ -75,6 +75,7 @@ source_set("bat-native-confirmations") { "src/bat/confirmations/internal/grant_rewards_serve_helper.cc", "src/bat/confirmations/internal/grant_rewards_serve_helper.h", "src/bat/confirmations/internal/logging.h", + "src/bat/confirmations/internal/platform_info.h", "src/bat/confirmations/internal/payment_info.h", "src/bat/confirmations/internal/payments.cc", "src/bat/confirmations/internal/payments.h", @@ -104,6 +105,36 @@ source_set("bat-native-confirmations") { "src/bat/confirmations/internal/unblinded_tokens.h", ] + if (is_android) { + sources += [ + "src/bat/confirmations/internal/platform_info_android.cc", + ] + } + + if (is_linux) { + sources += [ + "src/bat/confirmations/internal/platform_info_linux.cc", + ] + } + + if (is_mac) { + sources += [ + "src/bat/confirmations/internal/platform_info_mac.mm", + ] + } + + if (is_ios) { + sources += [ + "src/bat/confirmations/internal/platform_info_ios.mm", + ] + } + + if (is_win) { + sources += [ + "src/bat/confirmations/internal/platform_info_win.cc", + ] + } + public_deps = [ ":challenge_bypass_libs", ] diff --git a/vendor/bat-native-confirmations/include/bat/confirmations/ad_info.h b/vendor/bat-native-confirmations/include/bat/confirmations/ad_info.h index 3acc8c10e3f5..c457c73633b1 100644 --- a/vendor/bat-native-confirmations/include/bat/confirmations/ad_info.h +++ b/vendor/bat-native-confirmations/include/bat/confirmations/ad_info.h @@ -23,6 +23,7 @@ struct CONFIRMATIONS_EXPORT AdInfo { std::string creative_set_id; std::string category; std::string target_url; + std::string geo_target; }; } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h index 02574e594114..bd613db514c8 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h @@ -34,6 +34,7 @@ struct ConfirmationInfo { BlindedToken blinded_payment_token; std::string credential; uint64_t timestamp_in_seconds; + std::string country_code; bool created; }; diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_create_confirmation_request_unittest.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_create_confirmation_request_unittest.cc index ba5fdf652b5e..d6a12e67c1cd 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_create_confirmation_request_unittest.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_create_confirmation_request_unittest.cc @@ -12,6 +12,8 @@ #include "bat/confirmations/internal/confirmations_impl.h" #include "bat/confirmations/internal/create_confirmation_request.h" #include "bat/confirmations/internal/security_helper.h" +#include "bat/confirmations/internal/platform_info.h" +#include "base/strings/stringprintf.h" #include "testing/gtest/include/gtest/gtest.h" @@ -32,7 +34,8 @@ class ConfirmationsCreateConfirmationRequestTest : public ::testing::Test { mock_confirmations_client_(std::make_unique()), confirmations_(std::make_unique( mock_confirmations_client_.get())), - request_(std::make_unique()) { + request_(std::make_unique( + confirmations_.get())) { // You can do set-up work for each test here } @@ -96,15 +99,19 @@ TEST_F(ConfirmationsCreateConfirmationRequestTest, BuildBody_Viewed) { ConfirmationInfo info; info.creative_instance_id = creative_instance_id; - info.blinded_payment_token = blinded_token; info.type = ConfirmationType::kViewed; - auto payload = request_->CreateConfirmationRequestDTO(info); + info.blinded_payment_token = blinded_token; + info.country_code = "US"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "release", platform); // Act auto body = request_->BuildBody(payload); // Assert - std::string expected_body = R"({"blindedPaymentToken":"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=","creativeInstanceId":"546fe7b0-5047-4f28-a11c-81f14edcf0f6","payload":{},"type":"view"})"; // NOLINT + std::string expected_body = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"release\",\"countryCode\":\"US\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT EXPECT_EQ(expected_body, body); } @@ -152,12 +159,16 @@ TEST_F( // Act ConfirmationInfo info; info.creative_instance_id = creative_instance_id; - info.blinded_payment_token = blinded_token; info.type = ConfirmationType::kViewed; - auto payload = request_->CreateConfirmationRequestDTO(info); + info.blinded_payment_token = blinded_token; + info.country_code = "US"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "release", platform); // Assert - std::string expected_payload = R"({"blindedPaymentToken":"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=","creativeInstanceId":"546fe7b0-5047-4f28-a11c-81f14edcf0f6","payload":{},"type":"view"})"; // NOLINT + std::string expected_payload = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"release\",\"countryCode\":\"US\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT EXPECT_EQ(expected_payload, payload); } @@ -178,16 +189,145 @@ TEST_F(ConfirmationsCreateConfirmationRequestTest, CreateCredential_Viewed) { ConfirmationInfo info; info.creative_instance_id = creative_instance_id; - info.blinded_payment_token = blinded_token; info.type = ConfirmationType::kViewed; - auto payload = request_->CreateConfirmationRequestDTO(info); + info.blinded_payment_token = blinded_token; + info.country_code = "US"; + + auto payload = + request_->CreateConfirmationRequestDTO(info, "release", "platform"); // Act auto credential = request_->CreateCredential(token_info, payload); // Assert - std::string expected_credential = "eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiUEkzbEZxcEdWRkt6NFRINXlFd1hJM1IvUW50bVRwVWdlQmFLK1NUaUJ4OD1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTQ2ZmU3YjAtNTA0Ny00ZjI4LWExMWMtODFmMTRlZGNmMGY2XCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoibGRWYWxyb2hqNWFIWW1FdWMvUmpIYTAweFdMdFJWY0hGMS9XWnl4ZGJYMnhkQ1ByMFgyMVg3cWtKVUxRdUw4U2JWWHJUT3lEbTJJNkFrT0R0SHYxR2c9PSIsInQiOiJQTG93ejJXRjJlR0Q1emZ3WmprOXA3NkhYQkxES01xLzNFQVpIZUcvZkUyWEdRNDhqeXRlK1ZlNTBabGFzT3VZTDVtd0E4Q1UyYUZNbEpydDNERGdDdz09In0="; // NOLINT + std::string expected_credential = "eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiUEkzbEZxcEdWRkt6NFRINXlFd1hJM1IvUW50bVRwVWdlQmFLK1NUaUJ4OD1cIixcImJ1aWxkQ2hhbm5lbFwiOlwicmVsZWFzZVwiLFwiY291bnRyeUNvZGVcIjpcIlVTXCIsXCJjcmVhdGl2ZUluc3RhbmNlSWRcIjpcIjU0NmZlN2IwLTUwNDctNGYyOC1hMTFjLTgxZjE0ZWRjZjBmNlwiLFwicGF5bG9hZFwiOnt9LFwicGxhdGZvcm1cIjpcInBsYXRmb3JtXCIsXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoiWE1UbElublhHSlYrRVp3REVtSFFIQWYzTVJSYXJ1LzdhZ1IrUE5CSWF6K2J2YkJPVWlCWjRvQkdaMlNrL1hLaWM1dTJwNERqZWN3TTUwZFNGUC8wS0E9PSIsInQiOiJQTG93ejJXRjJlR0Q1emZ3WmprOXA3NkhYQkxES01xLzNFQVpIZUcvZkUyWEdRNDhqeXRlK1ZlNTBabGFzT3VZTDVtd0E4Q1UyYUZNbEpydDNERGdDdz09In0="; // NOLINT EXPECT_EQ(expected_credential, credential); } +TEST_F(ConfirmationsCreateConfirmationRequestTest, + CreateConfirmationRequestDTO_LargeAnonymityCountry) { + // Arrange + std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6"; + + std::string blinded_token_base64 = + "PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8="; + auto blinded_token = BlindedToken::decode_base64(blinded_token_base64); + + // Act + ConfirmationInfo info; + info.creative_instance_id = creative_instance_id; + info.type = ConfirmationType::kViewed; + info.blinded_payment_token = blinded_token; + info.country_code = "US"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "release", platform); + + // Assert + std::string expected_payload = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"release\",\"countryCode\":\"US\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT + EXPECT_EQ(expected_payload, payload); +} + +TEST_F(ConfirmationsCreateConfirmationRequestTest, + CreateConfirmationRequestDTO_OtherCountryCode) { + // Arrange + std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6"; + + std::string blinded_token_base64 = + "PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8="; + auto blinded_token = BlindedToken::decode_base64(blinded_token_base64); + + // Act + ConfirmationInfo info; + info.creative_instance_id = creative_instance_id; + info.type = ConfirmationType::kViewed; + info.blinded_payment_token = blinded_token; + info.country_code = "AS"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "release", platform); + + // Assert + std::string expected_payload = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"release\",\"countryCode\":\"??\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT + EXPECT_EQ(expected_payload, payload); +} + +TEST_F(ConfirmationsCreateConfirmationRequestTest, + CreateConfirmationRequestDTO_SmallAnonymityCountryAndNotOtherCountryCode) { + // Arrange + std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6"; + + std::string blinded_token_base64 = + "PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8="; + auto blinded_token = BlindedToken::decode_base64(blinded_token_base64); + + // Act + ConfirmationInfo info; + info.creative_instance_id = creative_instance_id; + info.type = ConfirmationType::kViewed; + info.blinded_payment_token = blinded_token; + info.country_code = "KY"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "release", platform); + + // Assert + std::string expected_payload = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"release\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT + EXPECT_EQ(expected_payload, payload); +} + + +TEST_F(ConfirmationsCreateConfirmationRequestTest, + CreateConfirmationRequestDTO_LargeAnonymityCountryForNonReleaseChannel) { + // Arrange + std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6"; + + std::string blinded_token_base64 = + "PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8="; + auto blinded_token = BlindedToken::decode_base64(blinded_token_base64); + + // Act + ConfirmationInfo info; + info.creative_instance_id = creative_instance_id; + info.type = ConfirmationType::kViewed; + info.blinded_payment_token = blinded_token; + info.country_code = "US"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "non-release", platform); + + // Assert + std::string expected_payload = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"non-release\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT + EXPECT_EQ(expected_payload, payload); +} + +TEST_F(ConfirmationsCreateConfirmationRequestTest, + CreateConfirmationRequestDTO_OtherCountryCodeForNonReleaseChannel) { + // Arrange + std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6"; + + std::string blinded_token_base64 = + "PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8="; + auto blinded_token = BlindedToken::decode_base64(blinded_token_base64); + + // Act + ConfirmationInfo info; + info.creative_instance_id = creative_instance_id; + info.type = ConfirmationType::kViewed; + info.blinded_payment_token = blinded_token; + info.country_code = "AS"; + + const std::string platform = GetPlatformName(); + auto payload = + request_->CreateConfirmationRequestDTO(info, "non-release", platform); + + // Assert + std::string expected_payload = base::StringPrintf("{\"blindedPaymentToken\":\"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=\",\"buildChannel\":\"non-release\",\"creativeInstanceId\":\"546fe7b0-5047-4f28-a11c-81f14edcf0f6\",\"payload\":{},\"platform\":\"%s\",\"type\":\"view\"}", platform.c_str()); // NOLINT + EXPECT_EQ(expected_payload, payload); +} + } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc index d010db66c246..bcde44a509ed 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc @@ -48,6 +48,10 @@ ConfirmationsImpl::ConfirmationsImpl( ConfirmationsImpl::~ConfirmationsImpl() = default; +ConfirmationsClient* ConfirmationsImpl::get_client() const { + return confirmations_client_; +} + void ConfirmationsImpl::Initialize( OnInitializeCallback callback) { BLOG(INFO) << "Initializing confirmations"; @@ -1134,6 +1138,7 @@ void ConfirmationsImpl::ConfirmAd( << std::endl << " creativeSetId: " << info.creative_set_id << std::endl << " category: " << info.category << std::endl << " targetUrl: " << info.target_url + << std::endl << " geoTarget: " << info.geo_target << std::endl << " confirmationType: " << std::string(confirmation_type); redeem_token_->Redeem(info, confirmation_type); diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h index eb3485dc1708..840e4b64dd00 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h @@ -33,6 +33,8 @@ class ConfirmationsImpl : public Confirmations { explicit ConfirmationsImpl(ConfirmationsClient* confirmations_client); ~ConfirmationsImpl() override; + ConfirmationsClient* get_client() const; + void Initialize(OnInitializeCallback callback) override; // Wallet diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc index 60cde1ac87f1..44060bb1f8d9 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc @@ -4,18 +4,25 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "bat/confirmations/confirmation_type.h" +#include "bat/confirmations/internal/confirmations_impl.h" #include "bat/confirmations/internal/confirmation_info.h" #include "bat/confirmations/internal/token_info.h" #include "bat/confirmations/internal/create_confirmation_request.h" #include "bat/confirmations/internal/ads_serve_helper.h" +#include "bat/confirmations/internal/platform_info.h" #include "bat/confirmations/internal/security_helper.h" +#include "bat/confirmations/internal/static_values.h" #include "base/logging.h" #include "base/json/json_writer.h" #include "base/values.h" namespace confirmations { -CreateConfirmationRequest::CreateConfirmationRequest() = default; +CreateConfirmationRequest::CreateConfirmationRequest( + ConfirmationsImpl* confirmations) + : confirmations_(confirmations) { + DCHECK(confirmations_); +} CreateConfirmationRequest::~CreateConfirmationRequest() = default; @@ -64,8 +71,11 @@ std::string CreateConfirmationRequest::GetContentType() const { } std::string CreateConfirmationRequest::CreateConfirmationRequestDTO( - const ConfirmationInfo& info) const { + const ConfirmationInfo& info, + const std::string& build_channel, + const std::string& platform) const { DCHECK(!info.creative_instance_id.empty()); + DCHECK(!build_channel.empty()); base::Value payload(base::Value::Type::DICTIONARY); @@ -79,6 +89,20 @@ std::string CreateConfirmationRequest::CreateConfirmationRequestDTO( auto type = std::string(info.type); payload.SetKey("type", base::Value(type)); + if (build_channel == "release") { + if (IsLargeAnonymityCountryCode(info.country_code)) { + payload.SetKey("countryCode", base::Value(info.country_code)); + } else { + if (IsOtherCountryCode(info.country_code)) { + payload.SetKey("countryCode", base::Value("??")); + } + } + } + + payload.SetKey("platform", base::Value(platform)); + + payload.SetKey("buildChannel", base::Value(build_channel)); + std::string json; base::JSONWriter::Write(payload, &json); @@ -112,4 +136,24 @@ std::string CreateConfirmationRequest::CreateCredential( return credential_base64; } +bool CreateConfirmationRequest::IsLargeAnonymityCountryCode( + const std::string& country_code) const { + const auto iter = kLargeAnonymityCountryCodes.find(country_code); + if (iter == kLargeAnonymityCountryCodes.end()) { + return false; + } + + return iter->second; +} + +bool CreateConfirmationRequest::IsOtherCountryCode( + const std::string& country_code) const { + const auto iter = kOtherCountryCodes.find(country_code); + if (iter == kOtherCountryCodes.end()) { + return false; + } + + return iter->second; +} + } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.h index 5d8e4dc56447..69f700ac8d74 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.h @@ -18,12 +18,15 @@ using challenge_bypass_ristretto::BlindedToken; namespace confirmations { +class ConfirmationsImpl; struct ConfirmationInfo; struct TokenInfo; class CreateConfirmationRequest { public: - CreateConfirmationRequest(); + CreateConfirmationRequest( + ConfirmationsImpl* confirmations); + ~CreateConfirmationRequest(); std::string BuildUrl( @@ -41,11 +44,22 @@ class CreateConfirmationRequest { std::string GetContentType() const; std::string CreateConfirmationRequestDTO( - const ConfirmationInfo& info) const; + const ConfirmationInfo& info, + const std::string& build_channel, + const std::string& platform) const; std::string CreateCredential( const TokenInfo& token_info, const std::string& payload) const; + + private: + bool IsLargeAnonymityCountryCode( + const std::string& country_code) const; + + bool IsOtherCountryCode( + const std::string& country_code) const; + + ConfirmationsImpl* confirmations_; // NOT OWNED }; } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info.h new file mode 100644 index 000000000000..bbc4f621fad6 --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BAT_CONFIRMATIONS_INTERNAL_PLATFORM_INFO_H_ +#define BAT_CONFIRMATIONS_INTERNAL_PLATFORM_INFO_H_ + +#include + +namespace confirmations { + +std::string GetPlatformName(); + +} // namespace confirmations + +#endif // BAT_CONFIRMATIONS_INTERNAL_PLATFORM_INFO_H_ diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_android.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_android.cc new file mode 100644 index 000000000000..80d8d82c5221 --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_android.cc @@ -0,0 +1,14 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/confirmations/internal/platform_info.h" + +namespace confirmations { + +std::string GetPlatformName() { + return "android"; +} + +} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_ios.mm b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_ios.mm new file mode 100644 index 000000000000..01dfab0efd59 --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_ios.mm @@ -0,0 +1,14 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/confirmations/internal/platform_info.h" + +namespace confirmations { + +std::string GetPlatformName() { + return "ios"; +} + +} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_linux.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_linux.cc new file mode 100644 index 000000000000..fb9f3a77f1d6 --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_linux.cc @@ -0,0 +1,14 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/confirmations/internal/platform_info.h" + +namespace confirmations { + +std::string GetPlatformName() { + return "linux"; +} + +} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_mac.mm b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_mac.mm new file mode 100644 index 000000000000..cbdca319b960 --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_mac.mm @@ -0,0 +1,14 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/confirmations/internal/platform_info.h" + +namespace confirmations { + +std::string GetPlatformName() { + return "macos"; +} + +} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_win.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_win.cc new file mode 100644 index 000000000000..5223bcc78d3c --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_info_win.cc @@ -0,0 +1,14 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/confirmations/internal/platform_info.h" + +namespace confirmations { + +std::string GetPlatformName() { + return "windows"; +} + +} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc index 7f01e3571342..b37c53ff5d55 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc @@ -14,6 +14,7 @@ #include "bat/confirmations/internal/unblinded_tokens.h" #include "bat/confirmations/internal/create_confirmation_request.h" #include "bat/confirmations/internal/fetch_payment_token_request.h" +#include "bat/confirmations/internal/platform_info.h" #include "bat/confirmations/internal/time.h" #include "bat/confirmations/internal/token_info.h" #include "bat/confirmations/internal/confirmation_info.h" @@ -107,7 +108,7 @@ void RedeemToken::CreateConfirmation( BLOG(INFO) << "CreateConfirmation"; BLOG(INFO) << "POST /v1/confirmation/{confirmation_id}/{credential}"; - CreateConfirmationRequest request; + CreateConfirmationRequest request(confirmations_); BLOG(INFO) << "URL Request:"; @@ -116,8 +117,12 @@ void RedeemToken::CreateConfirmation( auto method = request.GetMethod(); - auto confirmation_request_dto = - request.CreateConfirmationRequestDTO(confirmation); + const auto client_info = confirmations_->get_client()->GetClientInfo(); + const std::string build_channel = client_info->channel; + const std::string platform = GetPlatformName(); + + auto confirmation_request_dto = request.CreateConfirmationRequestDTO( + confirmation, build_channel, platform); auto body = request.BuildBody(confirmation_request_dto); BLOG(INFO) << " Body: " << body; @@ -461,8 +466,14 @@ ConfirmationInfo RedeemToken::CreateConfirmationInfo( auto blinded_payment_token = blinded_payment_tokens.front(); confirmation.blinded_payment_token = blinded_payment_token; - CreateConfirmationRequest request; - auto payload = request.CreateConfirmationRequestDTO(confirmation); + const auto client_info = confirmations_->get_client()->GetClientInfo(); + const std::string build_channel = client_info->channel; + const std::string platform = GetPlatformName(); + + CreateConfirmationRequest request(confirmations_); + auto payload = request.CreateConfirmationRequestDTO(confirmation, + build_channel, platform); + confirmation.credential = request.CreateCredential(token, payload); confirmation.timestamp_in_seconds = Time::NowInSeconds(); @@ -470,9 +481,9 @@ ConfirmationInfo RedeemToken::CreateConfirmationInfo( } bool RedeemToken::Verify( - const ConfirmationInfo& info) const { + const ConfirmationInfo& confirmation) const { std::string credential; - base::Base64Decode(info.credential, &credential); + base::Base64Decode(confirmation.credential, &credential); base::Optional value = base::JSONReader::Read(credential); if (!value || !value->is_dict()) { @@ -492,10 +503,15 @@ bool RedeemToken::Verify( auto signature = signature_value->GetString(); auto verification_signature = VerificationSignature::decode_base64(signature); - CreateConfirmationRequest request; - auto payload = request.CreateConfirmationRequestDTO(info); + const auto client_info = confirmations_->get_client()->GetClientInfo(); + const std::string build_channel = client_info->channel; + const std::string platform = GetPlatformName(); + + CreateConfirmationRequest request(confirmations_); + auto payload = request.CreateConfirmationRequestDTO(confirmation, + build_channel, platform); - auto unblinded_token = info.token_info.unblinded_token; + auto unblinded_token = confirmation.token_info.unblinded_token; auto verification_key = unblinded_token.derive_verification_key(); return verification_key.verify(verification_signature, payload); diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h index 69d28ccdd664..dd60f5942918 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h @@ -7,6 +7,8 @@ #define BAT_CONFIRMATIONS_INTERNAL_STATIC_VALUES_H_ #include +#include +#include #include "base/time/time.h" @@ -41,6 +43,534 @@ const uint64_t kRetryAdsRewardsAfterSeconds = const uint64_t kRetryFailedConfirmationsAfterSeconds = 5 * base::Time::kSecondsPerMinute; +const std::map kLargeAnonymityCountryCodes = { + { "US", true }, // United States of America + { "CA", true }, // Canada + { "GB", true }, // United Kingdom (Great Britain and Northern Ireland) + { "DE", true }, // Germany + { "FR", true }, // France + { "AU", true }, // Australia + { "NZ", true }, // New Zealand + { "IE", true }, // Ireland + { "AR", true }, // Argentina + { "AT", true }, // Austria + { "BR", true }, // Brazil + { "CH", true }, // Switzerland + { "CL", true }, // Chile + { "CO", true }, // Colombia + { "DK", true }, // Denmark + { "EC", true }, // Ecuador + { "IL", true }, // Israel + { "IN", true }, // India + { "IT", true }, // Italy + { "JP", true }, // Japan + { "KR", true }, // Korea + { "MX", true }, // Mexico + { "NL", true }, // Netherlands + { "PE", true }, // Peru + { "PH", true }, // Philippines + { "PL", true }, // Poland + { "SE", true }, // Sweden + { "SG", true }, // Singapore + { "VE", true }, // Venezuela + { "ZA", true }, // South Africa + { "KY", false }, // Cayman Islands + { "AE", true }, // United Arab Emirates + { "AL", true }, // Albania + { "AZ", true }, // Azerbaijan + { "BD", true }, // Bangladesh + { "BE", true }, // Belgium + { "BG", true }, // Bulgaria + { "CN", true }, // China + { "CZ", true }, // Czechia + { "DZ", true }, // Algeria + { "EG", true }, // Egypt + { "ES", true }, // Spain + { "FI", true }, // Finland + { "GR", true }, // Greece + { "HK", true }, // Hong Kong + { "HR", true }, // Croatia + { "HU", true }, // Hungary + { "ID", true }, // Indonesia + { "IQ", true }, // Iraq + { "KH", true }, // Cambodia + { "LT", true }, // Lithuania + { "MA", true }, // Morocco + { "MY", true }, // Malaysia + { "NG", true }, // Nigeria + { "NO", true }, // Norway + { "PK", true }, // Pakistan + { "PT", true }, // Portugal + { "RO", true }, // Romania + { "RS", true }, // Serbia + { "RU", true }, // Russian Federation + { "SA", true }, // Saudi Arabia + { "SI", true }, // Slovenia + { "SK", true }, // Slovakia + { "TH", true }, // Thailand + { "TR", true }, // Turkey + { "TW", true }, // Taiwan + { "UA", true }, // Ukraine + { "VN", true }, // Vietnam + { "AF", true }, // Afghanistan + { "AS", false }, // American Samoa + { "AD", false }, // Andorra + { "AO", false }, // Angola + { "AI", false }, // Anguilla + { "AQ", false }, // Antarctica + { "AG", false }, // Antigua and Barbuda + { "AM", true }, // Armenia + { "AW", false }, // Aruba + { "BS", true }, // Bahamas + { "BH", true }, // Bahrain + { "BB", true }, // Barbados + { "BY", true }, // Belarus + { "BZ", false }, // Belize + { "BJ", true }, // Benin + { "BM", false }, // Bermuda + { "BT", false }, // Bhutan + { "BO", true }, // Bolivia + { "BQ", false }, // Bonaire + { "BA", true }, // Bosnia and Herzegovina + { "BW", true }, // Botswana + { "BV", false }, // Bouvet Island + { "IO", false }, // British Indian Ocean Territory + { "BN", true }, // Brunei Darussalam + { "BF", false }, // Burkina Faso + { "BI", false }, // Burundi + { "CM", true }, // Cameroon + { "CV", false }, // Cape Verde + { "TD", false }, // Chad + { "CX", false }, // Christmas Island + { "CC", false }, // Cocos (Keeling) Islands + { "KM", false }, // Comoros + { "CG", false }, // Republic of the Congo + { "CD", true }, // Democratic Republic of the Congo + { "CK", false }, // Cook Islands + { "CR", true }, // Costa Rica + { "CW", false }, // Curacao + { "CY", true }, // Cyprus + { "CI", true }, // Cote d'Ivoire + { "DJ", false }, // Djibouti + { "DM", false }, // Dominica + { "DO", true }, // Dominican Republic + { "SV", true }, // El Salvador + { "GQ", false }, // Equatorial Guinea + { "ER", false }, // Eritrea + { "EE", true }, // Estonia + { "ET", true }, // Ethiopia + { "FK", false }, // Falkland Islands + { "FO", false }, // Faroe Islands + { "FJ", false }, // Fiji + { "GF", false }, // French Guiana + { "PF", false }, // French Polynesia + { "TF", false }, // French and Antarctic Lands + { "GA", false }, // Gabon + { "GM", false }, // Gambia + { "GE", true }, // Georgia + { "GH", true }, // Ghana + { "GI", false }, // Gibraltar + { "GL", false }, // Greenland + { "GD", false }, // Grenada + { "GP", false }, // Guadeloupe + { "GU", false }, // Guam + { "GT", true }, // Guatemala + { "GG", false }, // Guernsey + { "GN", false }, // Guinea + { "GW", false }, // Guinea-Bissau + { "GY", false }, // Guyana + { "HT", false }, // Haiti + { "HM", false }, // Heard Island and McDonald Islands + { "VA", false }, // Vatican City + { "HN", true }, // Honduras + { "IS", true }, // Iceland + { "IM", false }, // Isle of Man + { "JM", true }, // Jamaica + { "JE", false }, // Jersey + { "JO", true }, // Jordan + { "KZ", true }, // Kazakhstan + { "KE", true }, // Kenya + { "KI", false }, // Kiribati + { "KW", true }, // Kuwait + { "KG", true }, // Kyrgyzstan + { "LA", false }, // Lao People's Democratic Republic + { "LV", true }, // Latvia + { "LB", true }, // Lebanon + { "LS", false }, // Lesotho + { "LR", false }, // Liberia + { "LI", false }, // Liechtenstein + { "LU", true }, // Luxembourg + { "MO", false }, // Macao + { "MK", true }, // Macedonia + { "MG", true }, // Madagascar + { "MW", false }, // Malawi + { "MV", false }, // Maldives + { "ML", false }, // Mali + { "MT", true }, // Malta + { "MH", false }, // Marshall Islands + { "MQ", false }, // Martinique + { "MR", false }, // Mauritania + { "MU", true }, // Mauritius + { "YT", false }, // Mayotte + { "FM", false }, // Micronesia, Federated States of + { "MD", true }, // Moldova + { "MC", false }, // Monaco + { "MN", true }, // Mongolia + { "ME", true }, // Montenegro + { "MS", false }, // Montserrat + { "MZ", false }, // Mozambique + { "MM", true }, // Myanmar + { "NA", true }, // Namibia + { "NR", false }, // Nauru + { "NP", true }, // Nepal + { "NC", false }, // New Caledonia + { "NI", true }, // Nicaragua + { "NE", false }, // Niger + { "NU", false }, // Niue + { "NF", false }, // Norfolk Island + { "MP", false }, // Northern Mariana Islands + { "NO", false }, // Norway + { "OM", true }, // Oman + { "PW", false }, // Palau + { "PS", true }, // Palestine + { "PA", true }, // Panama + { "PG", false }, // Papua New Guinea + { "PY", true }, // Paraguay + { "PN", false }, // Pitcairn + { "PR", true }, // Puerto Rico + { "QA", true }, // Qatar + { "RW", true }, // Rwanda + { "RE", true }, // Reunion + { "BL", false }, // Saint Barthelemy + { "SH", false }, // Saint Helena + { "KN", false }, // Saint Kitts and Nevis + { "LC", false }, // Saint Lucia + { "MF", false }, // Saint Martin + { "PM", false }, // Saint Pierre and Miquelon + { "VC", false }, // Saint Vincent and the Grenadines + { "WS", false }, // Samoa + { "SM", false }, // San Marino + { "ST", false }, // São Tomé and Príncipe + { "SN", true }, // Senegal + { "SC", false }, // Seychelles + { "SL", false }, // Sierra Leone + { "SX", false }, // Sint Maarten + { "SB", false }, // Solomon Islands + { "GS", false }, // South Georgia and the South Sandwich Islands + { "SS", false }, // South Sudan + { "LK", true }, // Sri Lanka + { "SR", false }, // Suriname + { "SJ", false }, // Svalbard and Jan Mayen + { "SZ", false }, // Swaziland + { "TJ", false }, // Tajikistan + { "TZ", true }, // United Republic of Tanzania + { "TL", false }, // Timor-Leste + { "TG", false }, // Togo + { "TK", false }, // Tokelau + { "TO", false }, // Tonga + { "TT", true }, // Trinidad and Tobago + { "TN", true }, // Tunisia + { "TM", false }, // Turkmenistan + { "TC", false }, // Turks and Caicos Islands + { "TV", false }, // Tuvalu + { "UG", true }, // Uganda + { "UM", false }, // United States Minor Outlying Islands + { "UY", true }, // Uruguay + { "UZ", true }, // Uzbekistan + { "VU", false }, // Vanuatu + { "VG", false }, // British Virgin Islands + { "VI", false }, // US Virgin Islands + { "WF", false }, // Wallis and Futuna + { "EH", false }, // Western Sahara + { "YE", false }, // Yemen + { "ZM", true }, // Zambia + { "ZW", true }, // Zimbabwe + { "202", false }, // Sub-Saharan Africa + { "014", false }, // Eastern Africa + { "017", false }, // Middle Africa + { "018", false }, // Southern Africa + { "011", false }, // Western Africa + { "013", false }, // Central America + { "005", false }, // South America + { "021", false }, // Northern America + { "143", false }, // Central Asia + { "035", false }, // South-eastern Asia + { "150", false }, // Europe + { "151", false }, // Eastern Europe + { "154", false }, // Northern Europe + { "039", false }, // Southern Europe + { "155", false }, // Western Europe + { "009", false }, // Oceania + { "053", false }, // Australia and New Zealand + { "054", false }, // Melanesia + { "057", false }, // Micronesia + { "061", false } // Polynesia +}; + +const std::map kOtherCountryCodes = { + { "US", false }, // United States of America + { "CA", false }, // Canada + { "GB", false }, // United Kingdom (Great Britain and Northern Ireland) + { "DE", false }, // Germany + { "FR", false }, // France + { "AU", false }, // Australia + { "NZ", false }, // New Zealand + { "IE", false }, // Ireland + { "AR", false }, // Argentina + { "AT", false }, // Austria + { "BR", false }, // Brazil + { "CH", false }, // Switzerland + { "CL", false }, // Chile + { "CO", false }, // Colombia + { "DK", false }, // Denmark + { "EC", false }, // Ecuador + { "IL", false }, // Israel + { "IN", false }, // India + { "IT", false }, // Italy + { "JP", false }, // Japan + { "KR", false }, // Korea + { "MX", false }, // Mexico + { "NL", false }, // Netherlands + { "PE", false }, // Peru + { "PH", false }, // Philippines + { "PL", false }, // Poland + { "SE", false }, // Sweden + { "SG", false }, // Singapore + { "VE", false }, // Venezuela + { "ZA", false }, // South Africa + { "KY", false }, // Cayman Islands + { "AE", false }, // United Arab Emirates + { "AL", false }, // Albania + { "AZ", false }, // Azerbaijan + { "BD", false }, // Bangladesh + { "BE", false }, // Belgium + { "BG", false }, // Bulgaria + { "CN", false }, // China + { "CZ", false }, // Czechia + { "DZ", false }, // Algeria + { "EG", false }, // Egypt + { "ES", false }, // Spain + { "FI", false }, // Finland + { "GR", false }, // Greece + { "HK", false }, // Hong Kong + { "HR", false }, // Croatia + { "HU", false }, // Hungary + { "ID", false }, // Indonesia + { "IQ", false }, // Iraq + { "KH", false }, // Cambodia + { "LT", false }, // Lithuania + { "MA", false }, // Morocco + { "MY", false }, // Malaysia + { "NG", false }, // Nigeria + { "NO", false }, // Norway + { "PK", false }, // Pakistan + { "PT", false }, // Portugal + { "RO", false }, // Romania + { "RS", false }, // Serbia + { "RU", false }, // Russian Federation + { "SA", false }, // Saudi Arabia + { "SI", false }, // Slovenia + { "SK", false }, // Slovakia + { "TH", false }, // Thailand + { "TR", false }, // Turkey + { "TW", false }, // Taiwan + { "UA", false }, // Ukraine + { "VN", false }, // Vietnam + { "AF", false }, // Afghanistan + { "AS", true }, // American Samoa + { "AD", false }, // Andorra + { "AO", false }, // Angola + { "AI", true }, // Anguilla + { "AQ", true }, // Antarctica + { "AG", true }, // Antigua and Barbuda + { "AM", false }, // Armenia + { "AW", false }, // Aruba + { "BS", false }, // Bahamas + { "BH", false }, // Bahrain + { "BB", false }, // Barbados + { "BY", false }, // Belarus + { "BZ", false }, // Belize + { "BJ", false }, // Benin + { "BM", false }, // Bermuda + { "BT", false }, // Bhutan + { "BO", false }, // Bolivia + { "BQ", true }, // Bonaire + { "BA", false }, // Bosnia and Herzegovina + { "BW", false }, // Botswana + { "BV", true }, // Bouvet Island + { "IO", true }, // British Indian Ocean Territory + { "BN", false }, // Brunei Darussalam + { "BF", false }, // Burkina Faso + { "BI", false }, // Burundi + { "CM", false }, // Cameroon + { "CV", false }, // Cape Verde + { "TD", true }, // Chad + { "CX", true }, // Christmas Island + { "CC", true }, // Cocos (Keeling) Islands + { "KM", true }, // Comoros + { "CG", false }, // Republic of the Congo + { "CD", false }, // Democratic Republic of the Congo + { "CK", true }, // Cook Islands + { "CR", false }, // Costa Rica + { "CW", false }, // Curacao + { "CY", false }, // Cyprus + { "CI", false }, // Cote d'Ivoire + { "DJ", false }, // Djibouti + { "DM", false }, // Dominica + { "DO", false }, // Dominican Republic + { "SV", false }, // El Salvador + { "GQ", true }, // Equatorial Guinea + { "ER", true }, // Eritrea + { "EE", false }, // Estonia + { "ET", false }, // Ethiopia + { "FK", true }, // Falkland Islands + { "FO", false }, // Faroe Islands + { "FJ", false }, // Fiji + { "GF", false }, // French Guiana + { "PF", false }, // French Polynesia + { "TF", true }, // French and Antarctic Lands + { "GA", false }, // Gabon + { "GM", false }, // Gambia + { "GE", false }, // Georgia + { "GH", false }, // Ghana + { "GI", false }, // Gibraltar + { "GL", true }, // Greenland + { "GD", false }, // Grenada + { "GP", false }, // Guadeloupe + { "GU", false }, // Guam + { "GT", false }, // Guatemala + { "GG", false }, // Guernsey + { "GN", false }, // Guinea + { "GW", true }, // Guinea-Bissau + { "GY", false }, // Guyana + { "HT", false }, // Haiti + { "HM", true }, // Heard Island and McDonald Islands + { "VA", true }, // Vatican City + { "HN", false }, // Honduras + { "IS", false }, // Iceland + { "IM", false }, // Isle of Man + { "JM", false }, // Jamaica + { "JE", false }, // Jersey + { "JO", false }, // Jordan + { "KZ", false }, // Kazakhstan + { "KE", false }, // Kenya + { "KI", true }, // Kiribati + { "KW", false }, // Kuwait + { "KG", false }, // Kyrgyzstan + { "LA", false }, // Lao People's Democratic Republic + { "LV", false }, // Latvia + { "LB", false }, // Lebanon + { "LS", false }, // Lesotho + { "LR", true }, // Liberia + { "LI", false }, // Liechtenstein + { "LU", false }, // Luxembourg + { "MO", false }, // Macao + { "MK", false }, // Macedonia + { "MG", false }, // Madagascar + { "MW", false }, // Malawi + { "MV", false }, // Maldives + { "ML", false }, // Mali + { "MT", false }, // Malta + { "MH", true }, // Marshall Islands + { "MQ", false }, // Martinique + { "MR", false }, // Mauritania + { "MU", false }, // Mauritius + { "YT", true }, // Mayotte + { "FM", true }, // Micronesia, Federated States of + { "MD", false }, // Moldova + { "MC", false }, // Monaco + { "MN", false }, // Mongolia + { "ME", false }, // Montenegro + { "MS", true }, // Montserrat + { "MZ", false }, // Mozambique + { "MM", false }, // Myanmar + { "NA", false }, // Namibia + { "NR", true }, // Nauru + { "NP", false }, // Nepal + { "NC", false }, // New Caledonia + { "NI", false }, // Nicaragua + { "NE", false }, // Niger + { "NU", true }, // Niue + { "NF", true }, // Norfolk Island + { "MP", true }, // Northern Mariana Islands + { "NO", false }, // Norway + { "OM", false }, // Oman + { "PW", true }, // Palau + { "PS", false }, // Palestine + { "PA", false }, // Panama + { "PG", false }, // Papua New Guinea + { "PY", false }, // Paraguay + { "PN", true }, // Pitcairn + { "PR", false }, // Puerto Rico + { "QA", false }, // Qatar + { "RW", false }, // Rwanda + { "RE", false }, // Reunion + { "BL", true }, // Saint Barthelemy + { "SH", true }, // Saint Helena + { "KN", true }, // Saint Kitts and Nevis + { "LC", false }, // Saint Lucia + { "MF", true }, // Saint Martin + { "PM", true }, // Saint Pierre and Miquelon + { "VC", false }, // Saint Vincent and the Grenadines + { "WS", true }, // Samoa + { "SM", true }, // San Marino + { "ST", true }, // São Tomé and Príncipe + { "SN", false }, // Senegal + { "SC", false }, // Seychelles + { "SL", false }, // Sierra Leone + { "SX", true }, // Sint Maarten + { "SB", true }, // Solomon Islands + { "GS", true }, // South Georgia and the South Sandwich Islands + { "SS", true }, // South Sudan + { "LK", false }, // Sri Lanka + { "SR", false }, // Suriname + { "SJ", true }, // Svalbard and Jan Mayen + { "SZ", false }, // Swaziland + { "TJ", true }, // Tajikistan + { "TZ", false }, // United Republic of Tanzania + { "TL", true }, // Timor-Leste + { "TG", false }, // Togo + { "TK", true }, // Tokelau + { "TO", false }, // Tonga + { "TT", false }, // Trinidad and Tobago + { "TN", false }, // Tunisia + { "TM", true }, // Turkmenistan + { "TC", true }, // Turks and Caicos Islands + { "TV", true }, // Tuvalu + { "UG", false }, // Uganda + { "UM", true }, // United States Minor Outlying Islands + { "UY", false }, // Uruguay + { "UZ", false }, // Uzbekistan + { "VU", true }, // Vanuatu + { "VG", true }, // British Virgin Islands + { "VI", false }, // US Virgin Islands + { "WF", true }, // Wallis and Futuna + { "EH", true }, // Western Sahara + { "YE", false }, // Yemen + { "ZM", false }, // Zambia + { "ZW", false }, // Zimbabwe + { "202", false }, // Sub-Saharan Africa + { "014", false }, // Eastern Africa + { "017", false }, // Middle Africa + { "018", false }, // Southern Africa + { "011", false }, // Western Africa + { "013", false }, // Central America + { "005", false }, // South America + { "021", false }, // Northern America + { "143", false }, // Central Asia + { "035", false }, // South-eastern Asia + { "150", false }, // Europe + { "151", false }, // Eastern Europe + { "154", false }, // Northern Europe + { "039", false }, // Southern Europe + { "155", false }, // Western Europe + { "009", false }, // Oceania + { "053", false }, // Australia and New Zealand + { "054", false }, // Melanesia + { "057", false }, // Micronesia + { "061", false } // Polynesia +}; + } // namespace confirmations #endif // BAT_CONFIRMATIONS_INTERNAL_STATIC_VALUES_H_ diff --git a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom index 5d9276b145c8..b07969ee06f5 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom +++ b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom @@ -399,6 +399,7 @@ enum OperatingSystem { struct ClientInfo { Platform platform; OperatingSystem os; + string channel; }; struct RecurringTip { diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc index b35bf415b0e0..e58770272cdf 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc @@ -1242,6 +1242,7 @@ void LedgerImpl::ConfirmAd( confirmations_ad_info.creative_set_id = ad_info.creative_set_id; confirmations_ad_info.category = ad_info.category; confirmations_ad_info.target_url = ad_info.target_url; + confirmations_ad_info.geo_target = ad_info.geo_target; bat_confirmations_->ConfirmAd(confirmations_ad_info, confirmations::ConfirmationType(confirmation_type)); diff --git a/vendor/brave-ios/Ads/BATAdNotification.h b/vendor/brave-ios/Ads/BATAdNotification.h index 1a6c12578c40..aca50d7b7436 100644 --- a/vendor/brave-ios/Ads/BATAdNotification.h +++ b/vendor/brave-ios/Ads/BATAdNotification.h @@ -28,6 +28,7 @@ NS_SWIFT_NAME(AdsNotification) @property (nonatomic, readonly, copy) NSString *title; @property (nonatomic, readonly, copy) NSString *body; @property (nonatomic, readonly, copy) NSURL *targetURL; +@property (nonatomic, readonly, copy) NSString *geoTarget; @end @interface BATAdNotification (MyFirstAd) diff --git a/vendor/brave-ios/Ads/BATAdNotification.mm b/vendor/brave-ios/Ads/BATAdNotification.mm index 6ec9998a17d0..bf332aa918dd 100644 --- a/vendor/brave-ios/Ads/BATAdNotification.mm +++ b/vendor/brave-ios/Ads/BATAdNotification.mm @@ -15,6 +15,7 @@ @interface BATAdNotification () @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *body; @property (nonatomic, copy) NSURL *targetURL; +@property (nonatomic, copy) NSString *geoTarget; @end @implementation BATAdNotification @@ -30,6 +31,7 @@ - (instancetype)initWithNotificationInfo:(const ads::AdNotificationInfo&)info self.title = [NSString stringWithUTF8String:info.title.c_str()]; self.body = [NSString stringWithUTF8String:info.body.c_str()]; self.targetURL = [NSURL URLWithString:[NSString stringWithUTF8String:info.target_url.c_str()]]; + self.geoTarget = [NSString stringWithUTF8String:info.geo_target.c_str()]; } return self; }