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"
|
|
|
|
#include "libcef/browser/browser_urlrequest_impl.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "libcef/common/content_client.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(
|
|
|
|
CefRefPtr<CefRequest> request,
|
2015-03-02 21:25:14 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-16 00:16:01 +02:00
|
|
|
if (!base::MessageLoop::current()) {
|
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.
|
|
|
|
CefRefPtr<CefBrowserURLRequest> impl =
|
2015-03-02 21:25:14 +01:00
|
|
|
new CefBrowserURLRequest(request, client, request_context);
|
2012-06-19 18:29:49 +02:00
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
|
|
|
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 =
|
|
|
|
new CefRenderURLRequest(request, client);
|
|
|
|
if (impl->Start())
|
|
|
|
return impl.get();
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
NOTREACHED() << "called in unsupported process";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|