-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26849 from brave/news-direct-feed-https
Upgrade News direct feed requests to HTTPS when possible
- Loading branch information
Showing
19 changed files
with
249 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/browser/brave_news/direct_feed_fetcher_delegate_impl.h" | ||
|
||
#include "brave/browser/brave_browser_process.h" | ||
#include "brave/components/brave_shields/content/browser/brave_shields_util.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
namespace brave_news { | ||
|
||
DirectFeedFetcherDelegateImpl::DirectFeedFetcherDelegateImpl( | ||
HostContentSettingsMap* host_content_settings_map) | ||
: host_content_settings_map_(host_content_settings_map), | ||
https_upgrade_exceptions_service_( | ||
g_brave_browser_process->https_upgrade_exceptions_service()) {} | ||
|
||
DirectFeedFetcherDelegateImpl::~DirectFeedFetcherDelegateImpl() = default; | ||
|
||
bool DirectFeedFetcherDelegateImpl::ShouldUpgradeToHttps(const GURL& url) { | ||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
if (!host_content_settings_map_ || !https_upgrade_exceptions_service_) { | ||
return true; | ||
} | ||
return brave_shields::ShouldUpgradeToHttps(host_content_settings_map_, url, | ||
https_upgrade_exceptions_service_); | ||
} | ||
|
||
base::WeakPtr<DirectFeedFetcher::Delegate> | ||
DirectFeedFetcherDelegateImpl::AsWeakPtr() { | ||
return weak_ptr_factory_.GetWeakPtr(); | ||
} | ||
|
||
} // namespace brave_news |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_NEWS_DIRECT_FEED_FETCHER_DELEGATE_IMPL_H_ | ||
#define BRAVE_BROWSER_BRAVE_NEWS_DIRECT_FEED_FETCHER_DELEGATE_IMPL_H_ | ||
|
||
#include "brave/components/brave_news/browser/direct_feed_fetcher.h" | ||
#include "url/gurl.h" | ||
|
||
namespace https_upgrade_exceptions { | ||
class HttpsUpgradeExceptionsService; | ||
} // namespace https_upgrade_exceptions | ||
|
||
class HostContentSettingsMap; | ||
|
||
namespace brave_news { | ||
|
||
class DirectFeedFetcherDelegateImpl : public DirectFeedFetcher::Delegate { | ||
public: | ||
explicit DirectFeedFetcherDelegateImpl( | ||
HostContentSettingsMap* host_content_settings_map); | ||
~DirectFeedFetcherDelegateImpl() override; | ||
|
||
DirectFeedFetcherDelegateImpl(const DirectFeedFetcherDelegateImpl&) = delete; | ||
DirectFeedFetcherDelegateImpl& operator=( | ||
const DirectFeedFetcherDelegateImpl&) = delete; | ||
|
||
// Must be called on UI thread | ||
bool ShouldUpgradeToHttps(const GURL& url) override; | ||
|
||
base::WeakPtr<DirectFeedFetcher::Delegate> AsWeakPtr() override; | ||
|
||
private: | ||
raw_ptr<HostContentSettingsMap> host_content_settings_map_; | ||
raw_ptr<https_upgrade_exceptions::HttpsUpgradeExceptionsService> | ||
https_upgrade_exceptions_service_; | ||
|
||
base::WeakPtrFactory<DirectFeedFetcherDelegateImpl> weak_ptr_factory_{this}; | ||
}; | ||
|
||
} // namespace brave_news | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_NEWS_DIRECT_FEED_FETCHER_DELEGATE_IMPL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.