summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/loader/previews_resource_loading_hints_receiver_impl.cc
blob: 656866d0c57b74ffbe2baaf32f31ba0ffb1fc21b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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 "third_party/blink/renderer/core/loader/previews_resource_loading_hints_receiver_impl.h"

#include <vector>

#include "base/metrics/histogram_macros.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/previews_resource_loading_hints.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

PreviewsResourceLoadingHintsReceiverImpl::
    PreviewsResourceLoadingHintsReceiverImpl(
        mojom::blink::PreviewsResourceLoadingHintsReceiverRequest request,
        Document* document)
    : binding_(this, std::move(request)), document_(document) {}

PreviewsResourceLoadingHintsReceiverImpl::
    ~PreviewsResourceLoadingHintsReceiverImpl() {}

void PreviewsResourceLoadingHintsReceiverImpl::SetResourceLoadingHints(
    mojom::blink::PreviewsResourceLoadingHintsPtr resource_loading_hints) {
  // TODO(tbansal): https://crbug.com/856247. Block loading of resources based
  // on |resource_loading_hints|.
  UMA_HISTOGRAM_COUNTS_100(
      "ResourceLoadingHints.CountBlockedSubresourcePatterns",
      resource_loading_hints->subresources_to_block.size());

  std::vector<WTF::String> subresource_patterns_to_block;
  for (const auto& subresource :
       resource_loading_hints->subresources_to_block) {
    subresource_patterns_to_block.push_back(subresource);
  }

  document_->Loader()->SetPreviewsResourceLoadingHints(
      PreviewsResourceLoadingHints::Create(
          *(document_.Get()), resource_loading_hints->ukm_source_id,
          subresource_patterns_to_block));
}

}  // namespace blink