Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / web / public / navigation_item.h
blob2dd8a269c97c8385cb6b613ae9156694e1164b49
1 // Copyright 2014 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.
5 #ifndef IOS_WEB_PUBLIC_NAVIGATION_ITEM_H_
6 #define IOS_WEB_PUBLIC_NAVIGATION_ITEM_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "base/supports_user_data.h"
11 #include "base/time/time.h"
12 #include "ios/web/public/web_state/page_display_state.h"
13 #include "ui/base/page_transition_types.h"
15 class GURL;
17 #if defined(__OBJC__)
18 @class NSDictionary;
19 #else
20 class NSDictionary;
21 #endif // __OBJC__
23 namespace web {
24 struct FaviconStatus;
25 struct Referrer;
26 struct SSLStatus;
28 // A NavigationItem is a data structure that captures all the information
29 // required to recreate a browsing state. It represents one point in the
30 // chain of navigation managed by a NavigationManager.
31 class NavigationItem : public base::SupportsUserData {
32 public:
33 // Creates a new NavigationItem.
34 static scoped_ptr<NavigationItem> Create();
36 // Page-related stuff --------------------------------------------------------
38 // A unique ID is preserved across commits and redirects, which means that
39 // sometimes a NavigationEntry's unique ID needs to be set (e.g. when
40 // creating a committed entry to correspond to a to-be-deleted pending entry,
41 // the pending entry's ID must be copied).
42 virtual int GetUniqueID() const = 0;
44 // The actual URL of the page. For some about pages, this may be a scary
45 // data: URL or something like that. Use GetVirtualURL() below for showing to
46 // the user.
47 virtual void SetURL(const GURL& url) = 0;
48 virtual const GURL& GetURL() const = 0;
50 // The referring URL. Can be empty.
51 virtual void SetReferrer(const Referrer& referrer) = 0;
52 virtual const Referrer& GetReferrer() const = 0;
54 // The virtual URL, when nonempty, will override the actual URL of the page
55 // when we display it to the user. This allows us to have nice and friendly
56 // URLs that the user sees for things like about: URLs, but actually feed
57 // the renderer a data URL that results in the content loading.
59 // GetVirtualURL() will return the URL to display to the user in all cases, so
60 // if there is no overridden display URL, it will return the actual one.
61 virtual void SetVirtualURL(const GURL& url) = 0;
62 virtual const GURL& GetVirtualURL() const = 0;
64 // The title as set by the page. This will be empty if there is no title set.
65 // The caller is responsible for detecting when there is no title and
66 // displaying the appropriate "Untitled" label if this is being displayed to
67 // the user.
68 virtual void SetTitle(const base::string16& title) = 0;
69 virtual const base::string16& GetTitle() const = 0;
71 // Stores the NavigationItem's last recorded scroll offset and zoom scale.
72 virtual void SetPageDisplayState(const PageDisplayState& page_state) = 0;
73 virtual const PageDisplayState& GetPageDisplayState() const = 0;
75 // Page-related helpers ------------------------------------------------------
77 // Returns the title to be displayed on the tab. This could be the title of
78 // the page if it is available or the URL. |languages| is the list of
79 // accepted languages (e.g., prefs::kAcceptLanguages) or empty if proper
80 // URL formatting isn't needed (e.g., unit tests).
81 virtual const base::string16& GetTitleForDisplay(
82 const std::string& languages) const = 0;
84 // Tracking stuff ------------------------------------------------------------
86 // The transition type indicates what the user did to move to this page from
87 // the previous page.
88 virtual void SetTransitionType(ui::PageTransition transition_type) = 0;
89 virtual ui::PageTransition GetTransitionType() const = 0;
91 // The favicon data and tracking information. See web::FaviconStatus.
92 virtual const FaviconStatus& GetFavicon() const = 0;
93 virtual FaviconStatus& GetFavicon() = 0;
95 // All the SSL flags and state. See web::SSLStatus.
96 virtual const SSLStatus& GetSSL() const = 0;
97 virtual SSLStatus& GetSSL() = 0;
99 // The time at which the last known local navigation has
100 // completed. (A navigation can be completed more than once if the
101 // page is reloaded.)
103 // If GetTimestamp() returns a null time, that means that either:
105 // - this navigation hasn't completed yet;
106 // - this navigation was restored and for some reason the
107 // timestamp wasn't available;
108 // - or this navigation was copied from a foreign session.
109 virtual void SetTimestamp(base::Time timestamp) = 0;
110 virtual base::Time GetTimestamp() const = 0;
112 // |true| if this item contains unsafe resources and will be removed. This
113 // property doesn't get serialized.
114 virtual void SetUnsafe(bool is_unsafe) = 0;
115 virtual bool IsUnsafe() const = 0;
117 // |true| if this item uses a desktop user agent in HTTP requests and
118 // UIWebView.
119 virtual void SetIsOverridingUserAgent(bool is_overriding_user_agent) = 0;
120 virtual bool IsOverridingUserAgent() const = 0;
122 // |true| if this item is the result of a POST request with data.
123 virtual bool HasPostData() const = 0;
125 // Returns the item's current http request headers.
126 virtual NSDictionary* GetHttpRequestHeaders() const = 0;
128 // Adds headers from |additional_headers| to the item's http request headers.
129 // Existing headers with the same key will be overridden.
130 virtual void AddHttpRequestHeaders(NSDictionary* additional_headers) = 0;
133 } // namespace web
135 #endif // IOS_WEB_PUBLIC_NAVIGATION_ITEM_H_