Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Side by Side Diff: ios/web/navigation/navigation_item_impl.mm

Issue 678483003: Adds web::NavigationItemImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ios/web/navigation/navigation_item_impl.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "net/base/net_util.h"
10 #include "ui/base/page_transition_types.h"
11 #include "ui/gfx/text_elider.h"
12
13 namespace {
14
15 // Returns a new unique ID for use in NavigationItem during construction. The
16 // returned ID is guaranteed to be nonzero (which is the "no ID" indicator).
17 static int GetUniqueIDInConstructor() {
18 static int unique_id_counter = 0;
19 return ++unique_id_counter;
20 }
21
22 } // namespace
23
24 namespace web {
25
26 // static
27 scoped_ptr<NavigationItem> NavigationItem::Create() {
28 return scoped_ptr<NavigationItem>(new NavigationItemImpl());
29 }
30
31 NavigationItemImpl::NavigationItemImpl()
32 : unique_id_(GetUniqueIDInConstructor()),
33 page_id_(-1),
34 transition_type_(ui::PAGE_TRANSITION_LINK) {
35 }
36
37 NavigationItemImpl::~NavigationItemImpl() {
38 }
39
40 int NavigationItemImpl::GetUniqueID() const {
41 return unique_id_;
42 }
43
44 void NavigationItemImpl::SetURL(const GURL& url) {
45 url_ = url;
46 cached_display_title_.clear();
47 }
48
49 const GURL& NavigationItemImpl::GetURL() const {
50 return url_;
51 }
52
53 void NavigationItemImpl::SetReferrer(const web::Referrer& referrer) {
54 referrer_ = referrer;
55 }
56
57 const web::Referrer& NavigationItemImpl::GetReferrer() const {
58 return referrer_;
59 }
60
61 void NavigationItemImpl::SetVirtualURL(const GURL& url) {
62 virtual_url_ = (url == url_) ? GURL() : url;
63 cached_display_title_.clear();
64 }
65
66 const GURL& NavigationItemImpl::GetVirtualURL() const {
67 return virtual_url_.is_empty() ? url_ : virtual_url_;
68 }
69
70 void NavigationItemImpl::SetTitle(const base::string16& title) {
71 title_ = title;
72 cached_display_title_.clear();
73 }
74
75 const base::string16& NavigationItemImpl::GetTitle() const {
76 return title_;
77 }
78
79 void NavigationItemImpl::SetPageID(int page_id) {
80 page_id_ = page_id;
81 }
82
83 int32 NavigationItemImpl::GetPageID() const {
84 return page_id_;
85 }
86
87 const base::string16& NavigationItemImpl::GetTitleForDisplay(
88 const std::string& languages) const {
89 // Most pages have real titles. Don't even bother caching anything if this is
90 // the case.
91 if (!title_.empty())
92 return title_;
93
94 // More complicated cases will use the URLs as the title. This result we will
95 // cache since it's more complicated to compute.
96 if (!cached_display_title_.empty())
97 return cached_display_title_;
98
99 // Use the virtual URL first if any, and fall back on using the real URL.
100 base::string16 title;
101 if (!virtual_url_.is_empty()) {
102 title = net::FormatUrl(virtual_url_, languages);
103 } else if (!url_.is_empty()) {
104 title = net::FormatUrl(url_, languages);
105 }
106
107 // For file:// URLs use the filename as the title, not the full path.
108 if (url_.SchemeIsFile()) {
109 base::string16::size_type slashpos = title.rfind('/');
110 if (slashpos != base::string16::npos)
111 title = title.substr(slashpos + 1);
112 }
113
114 const int kMaxTitleChars = 4 * 1024;
115 gfx::ElideString(title, kMaxTitleChars, &cached_display_title_);
116 return cached_display_title_;
117 }
118
119 void NavigationItemImpl::SetTransitionType(ui::PageTransition transition_type) {
120 transition_type_ = transition_type;
121 }
122
123 ui::PageTransition NavigationItemImpl::GetTransitionType() const {
124 return transition_type_;
125 }
126
127 const FaviconStatus& NavigationItemImpl::GetFavicon() const {
128 return favicon_;
129 }
130
131 FaviconStatus& NavigationItemImpl::GetFavicon() {
132 return favicon_;
133 }
134
135 const SSLStatus& NavigationItemImpl::GetSSL() const {
136 return ssl_;
137 }
138
139 SSLStatus& NavigationItemImpl::GetSSL() {
140 return ssl_;
141 }
142
143 void NavigationItemImpl::SetTimestamp(base::Time timestamp) {
144 timestamp_ = timestamp;
145 }
146
147 base::Time NavigationItemImpl::GetTimestamp() const {
148 return timestamp_;
149 }
150
151 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/navigation/navigation_item_impl.h ('k') | ios/web/navigation/navigation_item_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698