2013-06-04 17:41:37 +00:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-10-08 17:47:37 +00:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2015-11-25 21:53:12 -05:00
|
|
|
#include "libcef/browser/net/scheme_handler.h"
|
2013-06-04 17:41:37 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2015-11-25 21:53:12 -05: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 17:47:37 +00:00
|
|
|
|
2016-05-24 19:35:43 -04:00
|
|
|
#include "base/memory/ptr_util.h"
|
2013-09-04 19:05:48 +00:00
|
|
|
#include "base/threading/sequenced_worker_pool.h"
|
2013-09-03 21:48:12 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
#include "content/public/common/url_constants.h"
|
2013-06-04 17:41:37 +00:00
|
|
|
#include "net/url_request/data_protocol_handler.h"
|
|
|
|
#include "net/url_request/file_protocol_handler.h"
|
2013-06-24 18:57:05 +00:00
|
|
|
#include "net/url_request/ftp_protocol_handler.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
#include "net/url_request/url_request_job_factory_impl.h"
|
2014-06-12 20:28:58 +00:00
|
|
|
#include "url/url_constants.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
|
2012-10-08 17:47:37 +00:00
|
|
|
namespace scheme {
|
|
|
|
|
2013-03-12 20:23:24 +00:00
|
|
|
void InstallInternalProtectedHandlers(
|
|
|
|
net::URLRequestJobFactoryImpl* job_factory,
|
2015-03-02 20:25:14 +00:00
|
|
|
CefURLRequestManager* request_manager,
|
2013-06-24 18:57:05 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
|
|
|
net::FtpTransactionFactory* ftp_transaction_factory) {
|
2013-06-04 17:41:37 +00:00
|
|
|
protocol_handlers->insert(
|
2014-06-12 20:28:58 +00:00
|
|
|
std::make_pair(url::kDataScheme,
|
2013-10-18 17:27:17 +00:00
|
|
|
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
|
|
|
|
new net::DataProtocolHandler)));
|
2013-06-04 17:41:37 +00:00
|
|
|
protocol_handlers->insert(
|
2014-06-12 20:28:58 +00:00
|
|
|
std::make_pair(url::kFileScheme,
|
2013-10-18 17:27:17 +00:00
|
|
|
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
|
|
|
|
new net::FileProtocolHandler(
|
|
|
|
content::BrowserThread::GetBlockingPool()->
|
|
|
|
GetTaskRunnerWithShutdownBehavior(
|
|
|
|
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))));
|
2013-06-24 18:57:05 +00:00
|
|
|
#if !defined(DISABLE_FTP_SUPPORT)
|
|
|
|
protocol_handlers->insert(
|
2014-06-12 20:28:58 +00:00
|
|
|
std::make_pair(url::kFtpScheme,
|
2013-10-18 17:27:17 +00:00
|
|
|
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
|
|
|
|
new net::FtpProtocolHandler(ftp_transaction_factory))));
|
2013-06-24 18:57:05 +00:00
|
|
|
#endif
|
2013-06-04 17:41:37 +00:00
|
|
|
|
2013-03-12 20:23:24 +00:00
|
|
|
for (content::ProtocolHandlerMap::iterator it =
|
|
|
|
protocol_handlers->begin();
|
|
|
|
it != protocol_handlers->end();
|
|
|
|
++it) {
|
|
|
|
const std::string& scheme = it->first;
|
2016-04-27 16:38:52 -04:00
|
|
|
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler> protocol_handler;
|
2013-03-12 20:23:24 +00:00
|
|
|
|
2014-02-19 16:27:54 +00:00
|
|
|
if (scheme == content::kChromeDevToolsScheme) {
|
2013-03-12 20:23:24 +00:00
|
|
|
// Don't use the default "chrome-devtools" handler.
|
|
|
|
continue;
|
2014-02-19 16:27:54 +00:00
|
|
|
} else if (scheme == content::kChromeUIScheme) {
|
2013-03-12 20:23:24 +00: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(
|
2015-03-02 20:25:14 +00:00
|
|
|
request_manager,
|
2016-05-24 19:35:43 -04:00
|
|
|
base::WrapUnique(it->second.release())).release());
|
2013-03-12 20:23:24 +00:00
|
|
|
} else {
|
|
|
|
protocol_handler.reset(it->second.release());
|
|
|
|
}
|
|
|
|
|
2013-06-04 17:41:37 +00:00
|
|
|
// Make sure IsInternalProtectedScheme() stays synchronized with what
|
|
|
|
// Chromium is actually giving us.
|
2013-03-12 20:23:24 +00:00
|
|
|
DCHECK(IsInternalProtectedScheme(scheme));
|
|
|
|
|
|
|
|
bool set_protocol = job_factory->SetProtocolHandler(
|
2016-05-24 19:35:43 -04:00
|
|
|
scheme, base::WrapUnique(protocol_handler.release()));
|
2013-03-12 20:23:24 +00:00
|
|
|
DCHECK(set_protocol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 20:25:14 +00:00
|
|
|
void RegisterInternalHandlers(CefURLRequestManager* request_manager) {
|
|
|
|
scheme::RegisterChromeHandler(request_manager);
|
|
|
|
scheme::RegisterChromeDevToolsHandler(request_manager);
|
2012-10-08 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url) {
|
2014-02-19 16:27:54 +00:00
|
|
|
if (validated_url.scheme() == content::kChromeUIScheme)
|
2012-10-08 17:47:37 +00:00
|
|
|
scheme::DidFinishChromeLoad(frame, validated_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace scheme
|