File: navigation_state.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (116 lines) | stat: -rw-r--r-- 4,782 bytes parent folder | download | duplicates (9)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/navigation_state.h"

#include <memory>
#include <utility>

#include "base/memory/ptr_util.h"
#include "content/common/frame_messages.mojom.h"
#include "third_party/blink/public/common/navigation/navigation_params.h"
#include "third_party/blink/public/mojom/commit_result/commit_result.mojom.h"

namespace content {

NavigationState::~NavigationState() {
  navigation_client_.reset();
  // If `commit_same_document_callback_` was set but hasn't run yet, run it now.
  // This will only happen if the navigation is being aborted before commit,
  // either due to frame detach or a new navigation preempting this one.
  // If `commit_same_document_callback_` was already run, this will not do
  // anything.
  RunCommitSameDocumentNavigationCallback(blink::mojom::CommitResult::Aborted);
}

// static
std::unique_ptr<NavigationState> NavigationState::CreateForCrossDocumentCommit(
    blink::mojom::CommonNavigationParamsPtr common_params,
    blink::mojom::CommitNavigationParamsPtr commit_params,
    mojom::NavigationClient::CommitNavigationCallback commit_callback,
    std::unique_ptr<NavigationClient> navigation_client,
    bool was_initiated_in_this_frame) {
  return base::WrapUnique(new NavigationState(
      std::move(common_params), std::move(commit_params),
      /*is_for_synchronous_commit=*/false, std::move(commit_callback),
      std::move(navigation_client),
      mojom::Frame::CommitSameDocumentNavigationCallback(),
      was_initiated_in_this_frame));
}

std::unique_ptr<NavigationState>
NavigationState::CreateForSameDocumentCommitFromBrowser(
    blink::mojom::CommonNavigationParamsPtr common_params,
    blink::mojom::CommitNavigationParamsPtr commit_params,
    mojom::Frame::CommitSameDocumentNavigationCallback
        commit_same_document_callback) {
  // This is a same-document navigation coming from the browser process (as
  // opposed to a fragment link click, which would have gone through
  // CreateForSynchronousCommit()), therefore |was_initiated_in_this_frame| must
  // be false.
  return base::WrapUnique(
      new NavigationState(std::move(common_params), std::move(commit_params),
                          /*is_for_synchronous_commit=*/false,
                          mojom::NavigationClient::CommitNavigationCallback(),
                          nullptr, std::move(commit_same_document_callback),
                          false /* was_initiated_in_this_frame */));
}

// static
std::unique_ptr<NavigationState> NavigationState::CreateForSynchronousCommit() {
  return base::WrapUnique(new NavigationState(
      blink::CreateCommonNavigationParams(),
      blink::CreateCommitNavigationParams(),
      /*is_for_synchronous_commit=*/true,
      content::mojom::NavigationClient::CommitNavigationCallback(),
      /*navigation_client=*/nullptr,
      mojom::Frame::CommitSameDocumentNavigationCallback(),
      /*was_initiated_in_this_frame=*/true));
}

bool NavigationState::WasWithinSameDocument() {
  return was_within_same_document_;
}

bool NavigationState::IsForSynchronousCommit() {
  return is_for_synchronous_commit_;
}

void NavigationState::RunCommitNavigationCallback(
    mojom::DidCommitProvisionalLoadParamsPtr params,
    mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params) {
  if (commit_callback_) {
    std::move(commit_callback_)
        .Run(std::move(params), std::move(interface_params));
  }
  navigation_client_.reset();
}

void NavigationState::RunCommitSameDocumentNavigationCallback(
    blink::mojom::CommitResult commit_result) {
  if (commit_same_document_callback_) {
    std::move(commit_same_document_callback_).Run(commit_result);
  }
}

NavigationState::NavigationState(
    blink::mojom::CommonNavigationParamsPtr common_params,
    blink::mojom::CommitNavigationParamsPtr commit_params,
    bool is_for_synchronous_commit,
    mojom::NavigationClient::CommitNavigationCallback commit_callback,
    std::unique_ptr<NavigationClient> navigation_client,
    mojom::Frame::CommitSameDocumentNavigationCallback
        commit_same_document_callback,
    bool was_initiated_in_this_frame)
    : commit_start_time_(base::TimeTicks::Now()),
      was_within_same_document_(false),
      was_initiated_in_this_frame_(was_initiated_in_this_frame),
      is_for_synchronous_commit_(is_for_synchronous_commit),
      common_params_(std::move(common_params)),
      commit_params_(std::move(commit_params)),
      navigation_client_(std::move(navigation_client)),
      commit_callback_(std::move(commit_callback)),
      commit_same_document_callback_(std::move(commit_same_document_callback)) {
}
}  // namespace content