2013-06-04 19:41:37 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-10-08 19:47:37 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/scheme_handler.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/chrome_scheme_handler.h"
|
|
|
|
#include "libcef/browser/net/devtools_scheme_handler.h"
|
|
|
|
#include "libcef/common/net/scheme_registration.h"
|
2012-10-08 19:47:37 +02:00
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2018-08-09 22:18:24 +02:00
|
|
|
#include "base/task/post_task.h"
|
2013-09-03 23:48:12 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "net/net_buildflags.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
#include "net/url_request/data_protocol_handler.h"
|
|
|
|
#include "net/url_request/file_protocol_handler.h"
|
2013-06-24 20:57:05 +02:00
|
|
|
#include "net/url_request/ftp_protocol_handler.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "net/url_request/url_request_job_factory_impl.h"
|
2014-06-12 22:28:58 +02:00
|
|
|
#include "url/url_constants.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
namespace scheme {
|
|
|
|
|
2013-03-12 21:23:24 +01:00
|
|
|
void InstallInternalProtectedHandlers(
|
|
|
|
net::URLRequestJobFactoryImpl* job_factory,
|
2015-03-02 21:25:14 +01:00
|
|
|
CefURLRequestManager* request_manager,
|
2013-06-24 20:57:05 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2016-11-23 21:54:29 +01:00
|
|
|
net::HostResolver* host_resolver) {
|
2017-05-17 11:29:28 +02:00
|
|
|
protocol_handlers->insert(std::make_pair(
|
2018-04-19 17:44:42 +02:00
|
|
|
url::kDataScheme, std::make_unique<net::DataProtocolHandler>()));
|
2017-05-17 11:29:28 +02:00
|
|
|
protocol_handlers->insert(std::make_pair(
|
|
|
|
url::kFileScheme,
|
2018-04-19 17:44:42 +02:00
|
|
|
std::make_unique<net::FileProtocolHandler>(
|
|
|
|
base::CreateTaskRunnerWithTraits(
|
2018-03-20 21:15:08 +01:00
|
|
|
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
|
2018-04-19 17:44:42 +02:00
|
|
|
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}))));
|
2016-11-23 21:54:29 +01:00
|
|
|
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
|
2017-05-17 11:29:28 +02:00
|
|
|
protocol_handlers->insert(std::make_pair(
|
2018-04-19 17:44:42 +02:00
|
|
|
url::kFtpScheme, net::FtpProtocolHandler::Create(host_resolver)));
|
2013-06-24 20:57:05 +02:00
|
|
|
#endif
|
2013-06-04 19:41:37 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
for (content::ProtocolHandlerMap::iterator it = protocol_handlers->begin();
|
|
|
|
it != protocol_handlers->end(); ++it) {
|
2013-03-12 21:23:24 +01:00
|
|
|
const std::string& scheme = it->first;
|
2017-05-17 11:29:28 +02:00
|
|
|
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
protocol_handler;
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2014-02-19 17:27:54 +01:00
|
|
|
if (scheme == content::kChromeDevToolsScheme) {
|
2013-03-12 21:23:24 +01:00
|
|
|
// Don't use the default "chrome-devtools" handler.
|
|
|
|
continue;
|
2014-02-19 17:27:54 +01:00
|
|
|
} else if (scheme == content::kChromeUIScheme) {
|
2013-03-12 21:23:24 +01:00
|
|
|
// Filter the URLs that are passed to the default "chrome" handler so as
|
|
|
|
// not to interfere with CEF's "chrome" handler.
|
|
|
|
protocol_handler.reset(
|
|
|
|
scheme::WrapChromeProtocolHandler(
|
2017-05-17 11:29:28 +02:00
|
|
|
request_manager, base::WrapUnique(it->second.release()))
|
|
|
|
.release());
|
2013-03-12 21:23:24 +01:00
|
|
|
} else {
|
|
|
|
protocol_handler.reset(it->second.release());
|
|
|
|
}
|
|
|
|
|
2013-06-04 19:41:37 +02:00
|
|
|
// Make sure IsInternalProtectedScheme() stays synchronized with what
|
|
|
|
// Chromium is actually giving us.
|
2013-03-12 21:23:24 +01:00
|
|
|
DCHECK(IsInternalProtectedScheme(scheme));
|
|
|
|
|
|
|
|
bool set_protocol = job_factory->SetProtocolHandler(
|
2016-05-25 01:35:43 +02:00
|
|
|
scheme, base::WrapUnique(protocol_handler.release()));
|
2013-03-12 21:23:24 +01:00
|
|
|
DCHECK(set_protocol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void RegisterInternalHandlers(CefURLRequestManager* request_manager) {
|
|
|
|
scheme::RegisterChromeHandler(request_manager);
|
|
|
|
scheme::RegisterChromeDevToolsHandler(request_manager);
|
2012-10-08 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url) {
|
2014-02-19 17:27:54 +01:00
|
|
|
if (validated_url.scheme() == content::kChromeUIScheme)
|
2012-10-08 19:47:37 +02:00
|
|
|
scheme::DidFinishChromeLoad(frame, validated_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace scheme
|