page_transition_types.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_PAGE_TRANSITION_TYPES_H_
  5. #define UI_BASE_PAGE_TRANSITION_TYPES_H_
  6. #include <stdint.h>
  7. #include "base/component_export.h"
  8. namespace ui {
  9. // Types of transitions between pages. These are stored in the history
  10. // database to separate visits, and are reported by the renderer for page
  11. // navigations.
  12. //
  13. // WARNING: don't change these numbers. They are written directly into the
  14. // history database, so future versions will need the same values to match
  15. // the enums.
  16. //
  17. // A type is made of a core value and a set of qualifiers. A type has one
  18. // core value and 0 or or more qualifiers.
  19. //
  20. // A Java counterpart will be generated for this enum.
  21. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.base
  22. enum PageTransition {
  23. PAGE_TRANSITION_FIRST = 0,
  24. // User got to this page by clicking a link on another page.
  25. PAGE_TRANSITION_LINK = PAGE_TRANSITION_FIRST,
  26. // User got this page by typing the URL in the URL bar. This should not be
  27. // used for cases where the user selected a choice that didn't look at all
  28. // like a URL; see GENERATED below.
  29. //
  30. // We also use this for other "explicit" navigation actions.
  31. PAGE_TRANSITION_TYPED = 1,
  32. // User got to this page through a suggestion in the UI, for example)
  33. // through the destinations page.
  34. PAGE_TRANSITION_AUTO_BOOKMARK = 2,
  35. // This is a subframe navigation. This is any content that is automatically
  36. // loaded in a non-toplevel frame. For example, if a page consists of
  37. // several frames containing ads, those ad URLs will have this transition
  38. // type. The user may not even realize the content in these pages is a
  39. // separate frame, so may not care about the URL (see MANUAL below). All
  40. // Fenced Frame navigations will be of this type because they are considered
  41. // a non-toplevel navigation that does not generate new navigation entries
  42. // in the back/forward list.
  43. PAGE_TRANSITION_AUTO_SUBFRAME = 3,
  44. // For subframe navigations that are explicitly requested by the user and
  45. // generate new navigation entries in the back/forward list. These are
  46. // probably more important than frames that were automatically loaded in
  47. // the background because the user probably cares about the fact that this
  48. // link was loaded.
  49. PAGE_TRANSITION_MANUAL_SUBFRAME = 4,
  50. // User got to this page by typing in the URL bar and selecting an entry
  51. // that did not look like a URL. For example, a match might have the URL
  52. // of a Google search result page, but appear like "Search Google for ...".
  53. // These are not quite the same as TYPED navigations because the user
  54. // didn't type or see the destination URL.
  55. // See also KEYWORD.
  56. PAGE_TRANSITION_GENERATED = 5,
  57. // This is a toplevel navigation. This is any content that is automatically
  58. // loaded in a toplevel frame. For example, opening a tab to show the ASH
  59. // screen saver, opening the devtools window, opening the NTP after the safe
  60. // browsing warning, opening web-based dialog boxes are examples of
  61. // AUTO_TOPLEVEL navigations.
  62. PAGE_TRANSITION_AUTO_TOPLEVEL = 6,
  63. // The user filled out values in a form and submitted it. NOTE that in
  64. // some situations submitting a form does not result in this transition
  65. // type. This can happen if the form uses script to submit the contents.
  66. PAGE_TRANSITION_FORM_SUBMIT = 7,
  67. // The user "reloaded" the page, either by hitting the reload button or by
  68. // hitting enter in the address bar. NOTE: This is distinct from the
  69. // concept of whether a particular load uses "reload semantics" (i.e.
  70. // bypasses cached data). For this reason, lots of code needs to pass
  71. // around the concept of whether a load should be treated as a "reload"
  72. // separately from their tracking of this transition type, which is mainly
  73. // used for proper scoring for consumers who care about how frequently a
  74. // user typed/visited a particular URL.
  75. //
  76. // SessionRestore and undo tab close use this transition type too.
  77. PAGE_TRANSITION_RELOAD = 8,
  78. // The url was generated from a replaceable keyword other than the default
  79. // search provider. If the user types a keyword (which also applies to
  80. // tab-to-search) in the omnibox this qualifier is applied to the transition
  81. // type of the generated url. TemplateURLModel then may generate an
  82. // additional visit with a transition type of KEYWORD_GENERATED against the
  83. // url 'http://' + keyword. For example, if you do a tab-to-search against
  84. // wikipedia the generated url has a transition qualifer of KEYWORD, and
  85. // TemplateURLModel generates a visit for 'wikipedia.org' with a transition
  86. // type of KEYWORD_GENERATED.
  87. PAGE_TRANSITION_KEYWORD = 9,
  88. // Corresponds to a visit generated for a keyword. See description of
  89. // KEYWORD for more details.
  90. PAGE_TRANSITION_KEYWORD_GENERATED = 10,
  91. // ADDING NEW CORE VALUE? Be sure to update the LAST_CORE and CORE_MASK
  92. // values below. Also update CoreTransitionString().
  93. PAGE_TRANSITION_LAST_CORE = PAGE_TRANSITION_KEYWORD_GENERATED,
  94. PAGE_TRANSITION_CORE_MASK = 0xFF,
  95. // Qualifiers
  96. // Any of the core values above can be augmented by one or more qualifiers.
  97. // These qualifiers further define the transition.
  98. // The values 0x00200000 (PAGE_TRANSITION_FROM_API_3) and 0x00400000
  99. // (PAGE_TRANSITION_FROM_API_2) were used for experiments and were removed
  100. // around 6/2021. The experiments ended well before 6/2021, but it's possible
  101. // some databases still have the values. See https://crbug.com/1141501 for
  102. // more.
  103. // A managed user attempted to visit a URL but was blocked.
  104. PAGE_TRANSITION_BLOCKED = 0x00800000,
  105. // User used the Forward or Back button to navigate among browsing history.
  106. PAGE_TRANSITION_FORWARD_BACK = 0x01000000,
  107. // User used the address bar to trigger this navigation.
  108. PAGE_TRANSITION_FROM_ADDRESS_BAR = 0x02000000,
  109. // User is navigating to the home page.
  110. PAGE_TRANSITION_HOME_PAGE = 0x04000000,
  111. // The transition originated from an external application; the exact
  112. // definition of this is embedder dependent.
  113. PAGE_TRANSITION_FROM_API = 0x08000000,
  114. // The beginning of a navigation chain.
  115. PAGE_TRANSITION_CHAIN_START = 0x10000000,
  116. // The last transition in a redirect chain.
  117. PAGE_TRANSITION_CHAIN_END = 0x20000000,
  118. // Redirects caused by JavaScript or a meta refresh tag on the page.
  119. PAGE_TRANSITION_CLIENT_REDIRECT = 0x40000000,
  120. // Redirects sent from the server by HTTP headers. It might be nice to
  121. // break this out into 2 types in the future, permanent or temporary, if we
  122. // can get that information from WebKit.
  123. // TODO(https://crbug.com/1291237): Remove this as it's inaccurate.
  124. // NavigationHandle::WasServerRedirect() should be used instead.
  125. PAGE_TRANSITION_SERVER_REDIRECT = 0x80000000,
  126. // Used to test whether a transition involves a redirect.
  127. PAGE_TRANSITION_IS_REDIRECT_MASK = 0xC0000000,
  128. // General mask defining the bits used for the qualifiers.
  129. PAGE_TRANSITION_QUALIFIER_MASK = 0xFFFFFF00,
  130. };
  131. // Compares two PageTransition types ignoring qualifiers. |rhs| is taken to
  132. // be a compile time constant, and hence must not contain any qualifiers.
  133. COMPONENT_EXPORT(UI_BASE)
  134. bool PageTransitionCoreTypeIs(PageTransition lhs, PageTransition rhs);
  135. // Compares two PageTransition types including qualifiers. Rarely useful,
  136. // PageTransitionCoreTypeIs() is more likely what you need.
  137. COMPONENT_EXPORT(UI_BASE)
  138. bool PageTransitionTypeIncludingQualifiersIs(PageTransition lhs,
  139. PageTransition rhs);
  140. // Simplifies the provided transition by removing any qualifier
  141. COMPONENT_EXPORT(UI_BASE)
  142. PageTransition PageTransitionStripQualifier(PageTransition type);
  143. COMPONENT_EXPORT(UI_BASE) bool PageTransitionIsValidType(int32_t type);
  144. COMPONENT_EXPORT(UI_BASE) PageTransition PageTransitionFromInt(int32_t type);
  145. // Returns true if the given transition is a top-level frame transition, or
  146. // false if the transition was for a subframe.
  147. COMPONENT_EXPORT(UI_BASE) bool PageTransitionIsMainFrame(PageTransition type);
  148. // Returns whether a transition involves a redirection
  149. COMPONENT_EXPORT(UI_BASE) bool PageTransitionIsRedirect(PageTransition type);
  150. // Returns whether a transition is a new navigation (rather than a return
  151. // to a previously committed navigation).
  152. COMPONENT_EXPORT(UI_BASE)
  153. bool PageTransitionIsNewNavigation(PageTransition type);
  154. // Return the qualifier
  155. COMPONENT_EXPORT(UI_BASE)
  156. int32_t PageTransitionGetQualifier(PageTransition type);
  157. // Returns true if the transition can be triggered by the web instead of
  158. // through UI or similar.
  159. COMPONENT_EXPORT(UI_BASE)
  160. bool PageTransitionIsWebTriggerable(PageTransition type);
  161. // Return a string version of the core type values.
  162. COMPONENT_EXPORT(UI_BASE)
  163. const char* PageTransitionGetCoreTransitionString(PageTransition type);
  164. // Declare a dummy class that is intentionally never defined.
  165. class DontUseOperatorEquals;
  166. // Ban operator== and operator!= as it's way too easy to forget to strip the
  167. // qualifiers. Use PageTransitionCoreTypeIs() instead or, in rare cases,
  168. // PageTransitionTypeIncludingQualifiersIs().
  169. DontUseOperatorEquals operator==(PageTransition, PageTransition);
  170. DontUseOperatorEquals operator==(PageTransition, int);
  171. DontUseOperatorEquals operator==(int, PageTransition);
  172. DontUseOperatorEquals operator!=(PageTransition, PageTransition);
  173. DontUseOperatorEquals operator!=(PageTransition, int);
  174. DontUseOperatorEquals operator!=(int, PageTransition);
  175. } // namespace ui
  176. #endif // UI_BASE_PAGE_TRANSITION_TYPES_H_