OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/navigation/crw_session_entry.h" | 5 #import "ios/web/navigation/crw_session_entry.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 NSString* const kSessionEntryTimestampKey = @"timestamp"; | 38 NSString* const kSessionEntryTimestampKey = @"timestamp"; |
39 NSString* const kSessionEntryTitleKey = @"title"; | 39 NSString* const kSessionEntryTitleKey = @"title"; |
40 NSString* const kSessionEntryPOSTDataKey = @"POSTData"; | 40 NSString* const kSessionEntryPOSTDataKey = @"POSTData"; |
41 NSString* const kSessionEntryHTTPRequestHeadersKey = @"httpHeaders"; | 41 NSString* const kSessionEntryHTTPRequestHeadersKey = @"httpHeaders"; |
42 NSString* const kSessionEntrySkipRepostFormConfirmationKey = | 42 NSString* const kSessionEntrySkipRepostFormConfirmationKey = |
43 @"skipResubmitDataConfirmation"; | 43 @"skipResubmitDataConfirmation"; |
44 NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent"; | 44 NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent"; |
45 } | 45 } |
46 | 46 |
47 @interface CRWSessionEntry () { | 47 @interface CRWSessionEntry () { |
48 // The NavigationItemImpl corresponding to this CRWSessionEntry. | 48 // The NavigationItem passed on initialization. |
49 // TODO(stuartmorgan): Move ownership to NavigationManagerImpl. | 49 web::NavigationItemImpl* _item; |
50 std::unique_ptr<web::NavigationItemImpl> _navigationItem; | |
51 } | 50 } |
52 | 51 |
53 // Returns a readable description of |displayState|. | 52 // Returns a readable description of |displayState|. |
54 + (NSString*)descriptionForPageDisplayState: | 53 + (NSString*)descriptionForPageDisplayState: |
55 (const web::PageDisplayState&)displayState; | 54 (const web::PageDisplayState&)displayState; |
56 @end | 55 @end |
57 | 56 |
58 @implementation CRWSessionEntry | 57 @implementation CRWSessionEntry |
59 | 58 |
60 - (instancetype)initWithNavigationItem: | 59 - (instancetype)initWithNavigationItem:(web::NavigationItemImpl*)item { |
61 (std::unique_ptr<web::NavigationItem>)item { | 60 if ((self = [super init])) { |
62 self = [super init]; | 61 DCHECK(item); |
63 if (self) { | 62 _item = item; |
64 _navigationItem.reset( | |
65 static_cast<web::NavigationItemImpl*>(item.release())); | |
66 } | 63 } |
67 return self; | 64 return self; |
68 } | 65 } |
69 | 66 |
70 // TODO(ios): Shall we overwrite EqualTo:? | 67 #pragma mark - Accessors |
71 | 68 |
72 - (instancetype)copyWithZone:(NSZone*)zone { | 69 - (web::NavigationItem*)navigationItem { |
73 CRWSessionEntry* copy = [[[self class] alloc] init]; | 70 return _item; |
74 copy->_navigationItem.reset( | |
75 new web::NavigationItemImpl(*_navigationItem.get())); | |
76 return copy; | |
77 } | 71 } |
78 | 72 |
| 73 - (web::NavigationItemImpl*)navigationItemImpl { |
| 74 return _item; |
| 75 } |
| 76 |
| 77 #pragma mark - NSObject |
| 78 |
79 - (NSString*)description { | 79 - (NSString*)description { |
80 return [NSString | 80 return [NSString |
81 stringWithFormat: | 81 stringWithFormat: |
82 @"url:%@ originalurl:%@ title:%@ transition:%d displayState:%@ " | 82 @"url:%@ originalurl:%@ title:%@ transition:%d displayState:%@ " |
83 @"desktopUA:%d", | 83 @"desktopUA:%d", |
84 base::SysUTF8ToNSString(_navigationItem->GetURL().spec()), | 84 base::SysUTF8ToNSString(_item->GetURL().spec()), |
85 base::SysUTF8ToNSString( | 85 base::SysUTF8ToNSString(_item->GetOriginalRequestURL().spec()), |
86 _navigationItem->GetOriginalRequestURL().spec()), | 86 base::SysUTF16ToNSString(_item->GetTitle()), |
87 base::SysUTF16ToNSString(_navigationItem->GetTitle()), | 87 _item->GetTransitionType(), |
88 _navigationItem->GetTransitionType(), | |
89 [[self class] | 88 [[self class] |
90 descriptionForPageDisplayState:_navigationItem | 89 descriptionForPageDisplayState:_item->GetPageDisplayState()], |
91 ->GetPageDisplayState()], | 90 _item->IsOverridingUserAgent()]; |
92 _navigationItem->IsOverridingUserAgent()]; | |
93 } | |
94 | |
95 - (web::NavigationItem*)navigationItem { | |
96 return _navigationItem.get(); | |
97 } | |
98 | |
99 - (web::NavigationItemImpl*)navigationItemImpl { | |
100 return _navigationItem.get(); | |
101 } | 91 } |
102 | 92 |
103 #pragma mark - | 93 #pragma mark - |
104 | 94 |
105 + (NSString*)descriptionForPageDisplayState: | 95 + (NSString*)descriptionForPageDisplayState: |
106 (const web::PageDisplayState&)displayState { | 96 (const web::PageDisplayState&)displayState { |
107 NSString* const kPageScrollStateDescriptionFormat = | 97 NSString* const kPageScrollStateDescriptionFormat = |
108 @"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), " | 98 @"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), " |
109 @"zoomScale:%0.2f }"; | 99 @"zoomScale:%0.2f }"; |
110 return | 100 return |
111 [NSString stringWithFormat:kPageScrollStateDescriptionFormat, | 101 [NSString stringWithFormat:kPageScrollStateDescriptionFormat, |
112 displayState.scroll_state().offset_x(), | 102 displayState.scroll_state().offset_x(), |
113 displayState.scroll_state().offset_y(), | 103 displayState.scroll_state().offset_y(), |
114 displayState.zoom_state().minimum_zoom_scale(), | 104 displayState.zoom_state().minimum_zoom_scale(), |
115 displayState.zoom_state().maximum_zoom_scale(), | 105 displayState.zoom_state().maximum_zoom_scale(), |
116 displayState.zoom_state().zoom_scale()]; | 106 displayState.zoom_state().zoom_scale()]; |
117 } | 107 } |
118 | 108 |
119 @end | 109 @end |
OLD | NEW |