summaryrefslogtreecommitdiffstats
path: root/src/core/content_browser_client_qt.cpp
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2019-09-13 13:48:14 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-10-11 10:15:08 +0200
commita3b6dfc0989227b3519daae817ec4fc420cd7016 (patch)
treee15d92cbd0740dd4b4827892e0ba754676e37d86 /src/core/content_browser_client_qt.cpp
parent320a7a8522ccff5155cbb9563428b26071266ebc (diff)
Use ProtocolHandlerRegistry with network service
Change-Id: Ia7448fb1406536822dd245cfdb6fe7c1cf19e211 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/content_browser_client_qt.cpp')
-rw-r--r--src/core/content_browser_client_qt.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index 5816749c8..71ba33957 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -45,6 +45,7 @@
#include "base/message_loop/message_loop.h"
#include "base/task/post_task.h"
#include "base/threading/thread_restrictions.h"
+#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#if QT_CONFIG(webengine_spellchecker)
#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h"
#endif
@@ -768,6 +769,71 @@ bool ContentBrowserClientQt::HandleExternalProtocol(
return true;
}
+namespace {
+// Copied from chrome/browser/chrome_content_browser_client.cc
+template<class HandlerRegistry>
+class ProtocolHandlerThrottle : public content::URLLoaderThrottle
+{
+public:
+ explicit ProtocolHandlerThrottle(const HandlerRegistry &protocol_handler_registry)
+ : protocol_handler_registry_(protocol_handler_registry)
+ {
+ }
+ ~ProtocolHandlerThrottle() override = default;
+
+ void WillStartRequest(network::ResourceRequest *request, bool *defer) override
+ {
+ TranslateUrl(&request->url);
+ }
+
+ void WillRedirectRequest(net::RedirectInfo *redirect_info,
+ const network::ResourceResponseHead &response_head, bool *defer,
+ std::vector<std::string> *to_be_removed_headers,
+ net::HttpRequestHeaders *modified_headers) override
+ {
+ TranslateUrl(&redirect_info->new_url);
+ }
+
+private:
+ void TranslateUrl(GURL *url)
+ {
+ if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
+ return;
+ GURL translated_url = protocol_handler_registry_->Translate(*url);
+ if (!translated_url.is_empty())
+ *url = translated_url;
+ }
+
+ HandlerRegistry protocol_handler_registry_;
+};
+} // namespace
+
+std::vector<std::unique_ptr<content::URLLoaderThrottle>>
+ContentBrowserClientQt::CreateURLLoaderThrottlesOnIO(
+ const network::ResourceRequest & /*request*/, content::ResourceContext *resource_context,
+ const base::RepeatingCallback<content::WebContents *()> & /*wc_getter*/,
+ content::NavigationUIData * /*navigation_ui_data*/, int /*frame_tree_node_id*/)
+{
+ std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
+ ProfileIODataQt *ioData = ProfileIODataQt::FromResourceContext(resource_context);
+ result.push_back(std::make_unique<ProtocolHandlerThrottle<
+ scoped_refptr<ProtocolHandlerRegistry::IOThreadDelegate>>>(
+ ioData->protocolHandlerRegistryIOThreadDelegate()));
+ return result;
+}
+
+std::vector<std::unique_ptr<content::URLLoaderThrottle>>
+ContentBrowserClientQt::CreateURLLoaderThrottles(
+ const network::ResourceRequest &request, content::BrowserContext *browser_context,
+ const base::RepeatingCallback<content::WebContents *()> &wc_getter,
+ content::NavigationUIData *navigation_ui_data, int frame_tree_node_id)
+{
+ std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
+ result.push_back(std::make_unique<ProtocolHandlerThrottle<ProtocolHandlerRegistry *>>(
+ ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
+ return result;
+}
+
std::unique_ptr<content::LoginDelegate> ContentBrowserClientQt::CreateLoginDelegate(
const net::AuthChallengeInfo &authInfo,
content::WebContents *web_contents,