From 9836cd607fe17c56f4ef2d5d5ebce26c2340f64e Mon Sep 17 00:00:00 2001 From: Pete Miller Date: Wed, 5 Feb 2020 16:16:36 -0800 Subject: [PATCH] Merge pull request #4514 from brave/maxk-fix-rewards-image Fixes rewards-image handler post C80 bump. --- browser/ui/webui/brave_rewards_source.cc | 17 +++++++++++------ .../browser/ntp_sponsored_image_source.cc | 7 +------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/browser/ui/webui/brave_rewards_source.cc b/browser/ui/webui/brave_rewards_source.cc index 17d1622dd0e0..1a882951aabf 100644 --- a/browser/ui/webui/brave_rewards_source.cc +++ b/browser/ui/webui/brave_rewards_source.cc @@ -72,15 +72,20 @@ void BraveRewardsSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, content::URLDataSource::GotDataCallback got_data_callback) { - if (!url.is_valid()) { + // URL here comes in the form of + // chrome://rewards-image/https://rewards.brave.com/... + // We need to take the path and make it into a URL. + GURL actual_url(URLDataSource::URLToRequestPath(url)); + if (!actual_url.is_valid()) { std::move(got_data_callback).Run(nullptr); return; } - auto it = find(resource_fetchers_.begin(), resource_fetchers_.end(), url); + auto it = + find(resource_fetchers_.begin(), resource_fetchers_.end(), actual_url); if (it != resource_fetchers_.end()) { LOG(WARNING) << "Already fetching specified Brave Rewards resource, url: " - << url; + << actual_url; return; } @@ -106,12 +111,12 @@ void BraveRewardsSource::StartDataRequest( policy_exception_justification: "Not implemented." })"); - resource_fetchers_.emplace_back(url); + resource_fetchers_.emplace_back(actual_url); request_ids_.push_back(image_service->RequestImage( - url, + actual_url, // Image Service takes ownership of the observer. new RewardsResourceFetcherObserver( - url, base::BindOnce(&BraveRewardsSource::OnBitmapFetched, + actual_url, base::BindOnce(&BraveRewardsSource::OnBitmapFetched, base::Unretained(this), std::move(got_data_callback))), traffic_annotation)); diff --git a/components/ntp_sponsored_images/browser/ntp_sponsored_image_source.cc b/components/ntp_sponsored_images/browser/ntp_sponsored_image_source.cc index d04900f6bf29..497a6cc0feba 100644 --- a/components/ntp_sponsored_images/browser/ntp_sponsored_image_source.cc +++ b/components/ntp_sponsored_images/browser/ntp_sponsored_image_source.cc @@ -49,12 +49,7 @@ void NTPSponsoredImageSource::StartDataRequest( GotDataCallback callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - // GURL::path() returns path with the leading slash, which we don't want. - std::string path = url.path(); - if (!path.empty()) { - path.erase(0, 1); - } - + const std::string path = URLDataSource::URLToRequestPath(url); if (!IsValidPath(path)) { scoped_refptr bytes; std::move(callback).Run(std::move(bytes));