2012-06-19 18:29:49 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "include/cef_urlrequest.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "libcef/browser/net/browser_urlrequest_old_impl.h"
|
|
|
|
#include "libcef/browser/net_service/browser_urlrequest_impl.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "libcef/common/net_service/util.h"
|
2017-09-21 13:57:40 +02:00
|
|
|
#include "libcef/common/task_runner_impl.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "libcef/renderer/render_urlrequest_impl.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "base/message_loop/message_loop.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "content/public/common/content_client.h"
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefURLRequest> CefURLRequest::Create(
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client,
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!request.get() || !client.get()) {
|
|
|
|
NOTREACHED() << "called with invalid parameters";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-21 13:57:40 +02:00
|
|
|
if (!CefTaskRunnerImpl::GetCurrentTaskRunner()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-16 00:16:01 +02:00
|
|
|
if (CefContentClient::Get()->browser()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
// In the browser process.
|
2019-05-11 00:14:48 +02:00
|
|
|
if (net_service::IsEnabled()) {
|
|
|
|
CefRefPtr<CefBrowserURLRequest> impl =
|
|
|
|
new CefBrowserURLRequest(nullptr, request, client, request_context);
|
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
|
|
|
} else {
|
|
|
|
CefRefPtr<CefBrowserURLRequestOld> impl =
|
|
|
|
new CefBrowserURLRequestOld(request, client, request_context);
|
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
return NULL;
|
2013-04-16 00:16:01 +02:00
|
|
|
} else if (CefContentClient::Get()->renderer()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
// In the render process.
|
|
|
|
CefRefPtr<CefRenderURLRequest> impl =
|
2019-05-11 00:14:48 +02:00
|
|
|
new CefRenderURLRequest(nullptr, request, client);
|
2012-06-19 18:29:49 +02:00
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
NOTREACHED() << "called in unsupported process";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|