Skip to content

Commit

Permalink
Merge pull request #4514 from brave/maxk-fix-rewards-image
Browse files Browse the repository at this point in the history
Fixes rewards-image handler post C80 bump.
  • Loading branch information
petemill authored and mkarolin committed Feb 6, 2020
1 parent 54402e9 commit 9836cd6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 11 additions & 6 deletions browser/ui/webui/brave_rewards_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<base::RefCountedMemory> bytes;
std::move(callback).Run(std::move(bytes));
Expand Down

0 comments on commit 9836cd6

Please sign in to comment.