Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes rewards-image handler post C80 bump (1.3.x). #4522

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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