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_service/browser_urlrequest_impl.h"
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/common/alloy/alloy_content_client.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";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 13:57:40 +02:00
|
|
|
if (!CefTaskRunnerImpl::GetCurrentTaskRunner()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
if (AlloyContentClient::Get()->browser()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
// In the browser process.
|
2019-07-29 23:27:12 +02:00
|
|
|
CefRefPtr<CefBrowserURLRequest> impl =
|
|
|
|
new CefBrowserURLRequest(nullptr, request, client, request_context);
|
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2020-06-28 20:29:44 +02:00
|
|
|
} else if (AlloyContentClient::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();
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED() << "called in unsupported process";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
}
|