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 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.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"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/features/runtime_checks.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
#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) {
|
2020-06-28 23:05:36 +02:00
|
|
|
// TODO(chrome-runtime): Add support for this method.
|
|
|
|
REQUIRE_ALLOY_RUNTIME();
|
|
|
|
|
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 23:05:36 +02:00
|
|
|
auto content_client = CefAppManager::Get()->GetContentClient();
|
|
|
|
if (content_client->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 23:05:36 +02:00
|
|
|
} else if (content_client->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
|
|
|
}
|
|
|
|
}
|