summaryrefslogtreecommitdiffstats
path: root/ios/web/public/navigation_item.h
blob: 6148e6c09aba24d4da877d6844622653d9480411 (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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2014 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.

#ifndef IOS_WEB_PUBLIC_NAVIGATION_ITEM_H_
#define IOS_WEB_PUBLIC_NAVIGATION_ITEM_H_

#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "ios/web/public/web_state/page_scroll_state.h"
#include "ui/base/page_transition_types.h"

class GURL;

#if defined(__OBJC__)
@class NSDictionary;
#else
class NSDictionary;
#endif  // __OBJC__

namespace web {
struct FaviconStatus;
struct Referrer;
struct SSLStatus;

// A NavigationItem is a data structure that captures all the information
// required to recreate a browsing state. It represents one point in the
// chain of navigation managed by a NavigationManager.
class NavigationItem {
 public:
  virtual ~NavigationItem() {}

  // Creates a new NavigationItem.
  static scoped_ptr<NavigationItem> Create();

  // Page-related stuff --------------------------------------------------------

  // A unique ID is preserved across commits and redirects, which means that
  // sometimes a NavigationEntry's unique ID needs to be set (e.g. when
  // creating a committed entry to correspond to a to-be-deleted pending entry,
  // the pending entry's ID must be copied).
  virtual int GetUniqueID() const = 0;

  // The actual URL of the page. For some about pages, this may be a scary
  // data: URL or something like that. Use GetVirtualURL() below for showing to
  // the user.
  virtual void SetURL(const GURL& url) = 0;
  virtual const GURL& GetURL() const = 0;

  // The referring URL. Can be empty.
  virtual void SetReferrer(const Referrer& referrer) = 0;
  virtual const Referrer& GetReferrer() const = 0;

  // The virtual URL, when nonempty, will override the actual URL of the page
  // when we display it to the user. This allows us to have nice and friendly
  // URLs that the user sees for things like about: URLs, but actually feed
  // the renderer a data URL that results in the content loading.
  //
  // GetVirtualURL() will return the URL to display to the user in all cases, so
  // if there is no overridden display URL, it will return the actual one.
  virtual void SetVirtualURL(const GURL& url) = 0;
  virtual const GURL& GetVirtualURL() const = 0;

  // The title as set by the page. This will be empty if there is no title set.
  // The caller is responsible for detecting when there is no title and
  // displaying the appropriate "Untitled" label if this is being displayed to
  // the user.
  virtual void SetTitle(const base::string16& title) = 0;
  virtual const base::string16& GetTitle() const = 0;

  // Describes the current page that the tab represents. This is the ID that the
  // renderer generated for the page and is how we can tell new versus
  // renavigations.
  virtual void SetPageID(int page_id) = 0;
  virtual int32 GetPageID() const = 0;

  // Stores the NavigationItem's last recorded scroll offset and zoom scale.
  virtual void SetPageScrollState(const PageScrollState& scroll_state) = 0;
  virtual const PageScrollState& GetPageScrollState() const = 0;

  // Page-related helpers ------------------------------------------------------

  // Returns the title to be displayed on the tab. This could be the title of
  // the page if it is available or the URL. |languages| is the list of
  // accepted languages (e.g., prefs::kAcceptLanguages) or empty if proper
  // URL formatting isn't needed (e.g., unit tests).
  virtual const base::string16& GetTitleForDisplay(
      const std::string& languages) const = 0;

  // Tracking stuff ------------------------------------------------------------

  // The transition type indicates what the user did to move to this page from
  // the previous page.
  virtual void SetTransitionType(ui::PageTransition transition_type) = 0;
  virtual ui::PageTransition GetTransitionType() const = 0;

  // The favicon data and tracking information. See web::FaviconStatus.
  virtual const FaviconStatus& GetFavicon() const = 0;
  virtual FaviconStatus& GetFavicon() = 0;

  // All the SSL flags and state. See web::SSLStatus.
  virtual const SSLStatus& GetSSL() const = 0;
  virtual SSLStatus& GetSSL() = 0;

  // The time at which the last known local navigation has
  // completed. (A navigation can be completed more than once if the
  // page is reloaded.)
  //
  // If GetTimestamp() returns a null time, that means that either:
  //
  //   - this navigation hasn't completed yet;
  //   - this navigation was restored and for some reason the
  //     timestamp wasn't available;
  //   - or this navigation was copied from a foreign session.
  virtual void SetTimestamp(base::Time timestamp) = 0;
  virtual base::Time GetTimestamp() const = 0;

  // |true| if this item contains unsafe resources and will be removed. This
  // property doesn't get serialized.
  virtual void SetUnsafe(bool is_unsafe) = 0;
  virtual bool IsUnsafe() const = 0;

  // |true| if this item uses a desktop user agent in HTTP requests and
  // UIWebView.
  virtual void SetIsOverridingUserAgent(bool is_overriding_user_agent) = 0;
  virtual bool IsOverridingUserAgent() const = 0;

  // |true| if this item is the result of a POST request with data.
  virtual bool HasPostData() const = 0;

  // Returns the item's current http request headers.
  virtual NSDictionary* GetHttpRequestHeaders() const = 0;

  // Adds headers from |additional_headers| to the item's http request headers.
  // Existing headers with the same key will be overridden.
  virtual void AddHttpRequestHeaders(NSDictionary* additional_headers) = 0;
};

}  // namespace web

#endif  // IOS_WEB_PUBLIC_NAVIGATION_ITEM_H_