Skip to content

Commit

Permalink
Merge pull request #771 from brave/fetch-media
Browse files Browse the repository at this point in the history
Fixes favicon for media publishers
  • Loading branch information
Jason Sadler authored and NejcZdovc committed Oct 31, 2018
1 parent f9e3279 commit fde5583
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps = {
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/omaha": "https://github.com/brave/omaha.git@5c633e867efafb9013c57ca830212d1ff6ea5076",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@e5e7586ed94a36f2f8aab285aacfe040cc224b1c",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@dd88d2192d6db435ab15f48fc2443564d1472552",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace brave_rewards {
using OnImageChangedCallback = base::Callback<void(
const std::string& publisher_key_,
const std::string& favicon_key_,
const GURL& url,
const BitmapFetcherService::RequestId& request_id,
const SkBitmap &answers_image)>;
Expand Down
33 changes: 19 additions & 14 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,9 @@ double RewardsServiceImpl::GetContributionAmount() {
return ledger_->GetContributionAmount();
}

void RewardsServiceImpl::FetchFavIcon(const std::string& url, const std::string& favicon_key) {
void RewardsServiceImpl::FetchFavIcon(const std::string& url,
const std::string& favicon_key,
ledger::FetchIconCallback callback) {
GURL parsedUrl(url);

if (!parsedUrl.is_valid()) {
Expand Down Expand Up @@ -1345,23 +1347,26 @@ void RewardsServiceImpl::FetchFavIcon(const std::string& url, const std::string&
new RewardsFetcherServiceObserver(
favicon_key,
parsedUrl,
base::Bind(&RewardsServiceImpl::OnFetchFavIconCompleted, base::Unretained(this))),
base::Bind(&RewardsServiceImpl::OnFetchFavIconCompleted, base::Unretained(this), callback)),
traffic_annotation));
}
}

void RewardsServiceImpl::OnFetchFavIconCompleted(const std::string& favicon_key,
const GURL& url,
const BitmapFetcherService::RequestId& request_id,
const SkBitmap& image) {
GURL publisher_url(favicon_key);
void RewardsServiceImpl::OnFetchFavIconCompleted(ledger::FetchIconCallback callback,
const std::string& favicon_key,
const GURL& url,
const BitmapFetcherService::RequestId& request_id,
const SkBitmap& image) {
GURL favicon_url(favicon_key);
gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(image);
favicon::FaviconService* favicon_service =
FaviconServiceFactory::GetForProfile(profile_, ServiceAccessType::EXPLICIT_ACCESS);
favicon_service->SetOnDemandFavicons(
publisher_url,
url, favicon_base::IconType::kFavicon, gfx_image,
base::BindOnce(&RewardsServiceImpl::OnSetOnDemandFaviconComplete, AsWeakPtr()));
favicon_url,
url,
favicon_base::IconType::kFavicon,
gfx_image,
base::BindOnce(&RewardsServiceImpl::OnSetOnDemandFaviconComplete, AsWeakPtr(), favicon_url.spec(), callback));

std::vector<std::string>::iterator it_url;
it_url = find(current_media_fetchers_.begin(), current_media_fetchers_.end(), url.spec());
Expand All @@ -1376,10 +1381,10 @@ void RewardsServiceImpl::OnFetchFavIconCompleted(const std::string& favicon_key,
}
}

void RewardsServiceImpl::OnSetOnDemandFaviconComplete(bool success) {
if (success) {
// TODO reload settings page brave/brave-browser#1521
}
void RewardsServiceImpl::OnSetOnDemandFaviconComplete(const std::string& favicon_url,
ledger::FetchIconCallback callback,
bool success) {
callback(success, favicon_url);
}

brave_rewards::PublisherBanner RewardsServiceImpl::GetPublisherBanner(const std::string& publisher_id) {
Expand Down
11 changes: 8 additions & 3 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,17 @@ class RewardsServiceImpl : public RewardsService,
void OnPublisherActivity(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info,
uint64_t windowId) override;
void FetchFavIcon(const std::string& url, const std::string& favicon_key) override;
void OnFetchFavIconCompleted(const std::string& favicon_key,
void FetchFavIcon(const std::string& url,
const std::string& favicon_key,
ledger::FetchIconCallback callback) override;
void OnFetchFavIconCompleted(ledger::FetchIconCallback callback,
const std::string& favicon_key,
const GURL& url,
const BitmapFetcherService::RequestId& request_id,
const SkBitmap& image);
void OnSetOnDemandFaviconComplete(bool success);
void OnSetOnDemandFaviconComplete(const std::string& favicon_url,
ledger::FetchIconCallback callback,
bool success);
void SaveContributionInfo(const std::string& probi,
const int month,
const int year,
Expand Down

0 comments on commit fde5583

Please sign in to comment.