2019-07-24 23:12:00 +02:00
|
|
|
// Copyright 2018 The Chromium 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 "libcef/renderer/url_loader_throttle_provider_impl.h"
|
|
|
|
|
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2019-09-25 15:59:51 +02:00
|
|
|
#include "libcef/renderer/render_thread_observer.h"
|
2019-07-24 23:12:00 +02:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "base/feature_list.h"
|
2019-09-25 15:59:51 +02:00
|
|
|
#include "chrome/common/google_url_loader_throttle.h"
|
2019-07-24 23:12:00 +02:00
|
|
|
#include "content/public/common/content_features.h"
|
|
|
|
#include "content/public/renderer/render_frame.h"
|
|
|
|
#include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h"
|
|
|
|
#include "services/network/public/cpp/features.h"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "third_party/blink/public/common/loader/resource_type_util.h"
|
2019-07-24 23:12:00 +02:00
|
|
|
#include "third_party/blink/public/platform/web_url.h"
|
|
|
|
|
|
|
|
CefURLLoaderThrottleProviderImpl::CefURLLoaderThrottleProviderImpl(
|
|
|
|
content::URLLoaderThrottleProviderType type)
|
|
|
|
: type_(type) {
|
|
|
|
DETACH_FROM_THREAD(thread_checker_);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLLoaderThrottleProviderImpl::~CefURLLoaderThrottleProviderImpl() {
|
|
|
|
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLLoaderThrottleProviderImpl::CefURLLoaderThrottleProviderImpl(
|
|
|
|
const CefURLLoaderThrottleProviderImpl& other)
|
|
|
|
: type_(other.type_) {
|
|
|
|
DETACH_FROM_THREAD(thread_checker_);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<content::URLLoaderThrottleProvider>
|
|
|
|
CefURLLoaderThrottleProviderImpl::Clone() {
|
|
|
|
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
|
|
|
return base::WrapUnique(new CefURLLoaderThrottleProviderImpl(*this));
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
|
2019-07-24 23:12:00 +02:00
|
|
|
CefURLLoaderThrottleProviderImpl::CreateThrottles(
|
|
|
|
int render_frame_id,
|
2020-03-30 22:13:42 +02:00
|
|
|
const blink::WebURLRequest& request) {
|
2019-07-24 23:12:00 +02:00
|
|
|
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles;
|
2019-07-24 23:12:00 +02:00
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
const network::mojom::RequestDestination request_destination =
|
|
|
|
request.GetRequestDestination();
|
|
|
|
|
2019-07-24 23:12:00 +02:00
|
|
|
// Some throttles have already been added in the browser for frame resources.
|
|
|
|
// Don't add them for frame requests.
|
2020-03-30 22:13:42 +02:00
|
|
|
bool is_frame_resource =
|
|
|
|
blink::IsRequestDestinationFrame(request_destination);
|
2019-07-24 23:12:00 +02:00
|
|
|
|
|
|
|
DCHECK(!is_frame_resource ||
|
|
|
|
type_ == content::URLLoaderThrottleProviderType::kFrame);
|
|
|
|
|
2019-07-29 23:27:12 +02:00
|
|
|
if (extensions::ExtensionsEnabled() &&
|
2019-07-24 23:12:00 +02:00
|
|
|
type_ == content::URLLoaderThrottleProviderType::kFrame &&
|
2020-03-30 22:13:42 +02:00
|
|
|
request_destination == network::mojom::RequestDestination::kObject) {
|
2019-07-24 23:12:00 +02:00
|
|
|
content::RenderFrame* render_frame =
|
|
|
|
content::RenderFrame::FromRoutingID(render_frame_id);
|
|
|
|
auto mime_handlers =
|
|
|
|
extensions::MimeHandlerViewContainer::FromRenderFrame(render_frame);
|
|
|
|
GURL gurl(request.Url());
|
|
|
|
for (auto* handler : mime_handlers) {
|
|
|
|
auto throttle = handler->MaybeCreatePluginThrottle(gurl);
|
|
|
|
if (throttle) {
|
|
|
|
throttles.push_back(std::move(throttle));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 15:59:51 +02:00
|
|
|
throttles.push_back(std::make_unique<GoogleURLLoaderThrottle>(
|
|
|
|
CefRenderThreadObserver::GetDynamicParams()));
|
|
|
|
|
2019-07-24 23:12:00 +02:00
|
|
|
return throttles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLLoaderThrottleProviderImpl::SetOnline(bool is_online) {}
|