summaryrefslogtreecommitdiff
path: root/chromium/content/browser/loader_delegate_impl.cc
blob: c2415c4f4bac53b8e822ccea986e067d2310923d (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2016 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 "content/browser/loader_delegate_impl.h"

#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_thread.h"

namespace content {

namespace {

void DidGetResourceResponseStartOnUI(
    const ResourceRequestInfo::WebContentsGetter& web_contents_getter,
    std::unique_ptr<ResourceRequestDetails> details) {
  WebContentsImpl* web_contents =
      static_cast<WebContentsImpl*>(web_contents_getter.Run());
  if (web_contents)
    web_contents->DidGetResourceResponseStart(*details.get());
}

void DidGetRedirectForResourceRequestOnUI(
    const ResourceRequestInfo::WebContentsGetter& web_contents_getter,
    std::unique_ptr<ResourceRedirectDetails> details) {
  WebContentsImpl* web_contents =
      static_cast<WebContentsImpl*>(web_contents_getter.Run());
  if (!web_contents)
    return;
  web_contents->DidGetRedirectForResourceRequest(*details.get());
}

}  // namespace

LoaderDelegateImpl::~LoaderDelegateImpl() {}

void LoaderDelegateImpl::LoadStateChanged(
    WebContents* web_contents,
    const GURL& url,
    const net::LoadStateWithParam& load_state,
    uint64_t upload_position,
    uint64_t upload_size) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  static_cast<WebContentsImpl*>(web_contents)->LoadStateChanged(
      url, load_state, upload_position, upload_size);
}

void LoaderDelegateImpl::DidGetResourceResponseStart(
    const ResourceRequestInfo::WebContentsGetter& web_contents_getter,
    std::unique_ptr<ResourceRequestDetails> details) {
  DCHECK_CURRENTLY_ON(BrowserThread::IO);
  BrowserThread::PostTask(
      BrowserThread::UI, FROM_HERE,
      base::Bind(&DidGetResourceResponseStartOnUI, web_contents_getter,
                 base::Passed(std::move(details))));
}

void LoaderDelegateImpl::DidGetRedirectForResourceRequest(
    const ResourceRequestInfo::WebContentsGetter& web_contents_getter,
    std::unique_ptr<ResourceRedirectDetails> details) {
  DCHECK_CURRENTLY_ON(BrowserThread::IO);
  BrowserThread::PostTask(
      BrowserThread::UI, FROM_HERE,
      base::Bind(&DidGetRedirectForResourceRequestOnUI, web_contents_getter,
                 base::Passed(std::move(details))));
}

}  // namespace content