| Index: ios/web/navigation/crw_session_entry.mm
|
| diff --git a/ios/web/navigation/crw_session_entry.mm b/ios/web/navigation/crw_session_entry.mm
|
| index c5bd035b0f852eff8350db39c3eaaab7293b9f96..2462bfc6cc481a509c70041ab2a52f07f8df2bb2 100644
|
| --- a/ios/web/navigation/crw_session_entry.mm
|
| +++ b/ios/web/navigation/crw_session_entry.mm
|
| @@ -13,52 +13,19 @@
|
| #import "ios/web/navigation/navigation_item_impl.h"
|
| #import "ios/web/navigation/nscoder_util.h"
|
| #import "ios/web/public/navigation_item.h"
|
| -#include "ios/web/public/web_state/page_display_state.h"
|
| +#import "ios/web/public/web_state/page_display_state.h"
|
| #import "net/base/mac/url_conversions.h"
|
|
|
| #if !defined(__has_feature) || !__has_feature(objc_arc)
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| -namespace web {
|
| -// Keys used to serialize web::PageScrollState properties.
|
| -NSString* const kSessionEntryPageScrollStateKey = @"state";
|
| -NSString* const kSessionEntryScrollOffsetXKey = @"scrollX";
|
| -NSString* const kSessionEntryScrollOffsetYKey = @"scrollY";
|
| -NSString* const kSessionEntryMinimumZoomScaleKey = @"minZoom";
|
| -NSString* const kSessionEntryMaximumZoomScaleKey = @"maxZoom";
|
| -NSString* const kSessionEntryZoomScaleKey = @"zoom";
|
| -
|
| -// Keys used to serialize navigation properties.
|
| -NSString* const kSessionEntryURLKey = @"virtualUrlString";
|
| -NSString* const kSessionEntryURLDeperecatedKey = @"virtualUrl";
|
| -NSString* const kSessionEntryReferrerURLKey = @"referrerUrlString";
|
| -NSString* const kSessionEntryReferrerURLDeprecatedKey = @"referrer";
|
| -NSString* const kSessionEntryReferrerPolicyKey = @"referrerPolicy";
|
| -NSString* const kSessionEntryTimestampKey = @"timestamp";
|
| -NSString* const kSessionEntryTitleKey = @"title";
|
| -NSString* const kSessionEntryPOSTDataKey = @"POSTData";
|
| -NSString* const kSessionEntryHTTPRequestHeadersKey = @"httpHeaders";
|
| -NSString* const kSessionEntrySkipRepostFormConfirmationKey =
|
| - @"skipResubmitDataConfirmation";
|
| -NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent";
|
| -}
|
| -
|
| @interface CRWSessionEntry () {
|
| // The NavigationItemImpl corresponding to this CRWSessionEntry.
|
| // TODO(stuartmorgan): Move ownership to NavigationManagerImpl.
|
| std::unique_ptr<web::NavigationItemImpl> _navigationItem;
|
| }
|
|
|
| -// Converts a serialized NSDictionary to a web::PageDisplayState.
|
| -+ (web::PageDisplayState)pageDisplayStateFromDictionary:
|
| - (NSDictionary*)dictionary;
|
| -// Serializes a web::PageDisplayState to an NSDictionary.
|
| -+ (NSDictionary*)dictionaryFromPageDisplayState:
|
| - (const web::PageDisplayState&)displayState;
|
| -// Returns a readable description of |displayState|.
|
| -+ (NSString*)descriptionForPageDisplayState:
|
| - (const web::PageDisplayState&)displayState;
|
| @end
|
|
|
| @implementation CRWSessionEntry
|
| @@ -73,93 +40,6 @@ - (instancetype)initWithNavigationItem:
|
| return self;
|
| }
|
|
|
| -- (instancetype)initWithCoder:(NSCoder*)aDecoder {
|
| - self = [super init];
|
| - if (self) {
|
| - _navigationItem.reset(new web::NavigationItemImpl());
|
| -
|
| - // Desktop chrome only persists virtualUrl_ and uses it to feed the url
|
| - // when creating a NavigationEntry.
|
| - GURL url;
|
| - if ([aDecoder containsValueForKey:web::kSessionEntryURLKey]) {
|
| - url = GURL(
|
| - web::nscoder_util::DecodeString(aDecoder, web::kSessionEntryURLKey));
|
| - } else {
|
| - // Backward compatibility.
|
| - url = net::GURLWithNSURL(
|
| - [aDecoder decodeObjectForKey:web::kSessionEntryURLDeperecatedKey]);
|
| - }
|
| - _navigationItem->SetOriginalRequestURL(url);
|
| - _navigationItem->SetURL(url);
|
| -
|
| - if ([aDecoder containsValueForKey:web::kSessionEntryReferrerURLKey]) {
|
| - const std::string referrerString(web::nscoder_util::DecodeString(
|
| - aDecoder, web::kSessionEntryReferrerURLKey));
|
| - web::ReferrerPolicy referrerPolicy = static_cast<web::ReferrerPolicy>(
|
| - [aDecoder decodeIntForKey:web::kSessionEntryReferrerPolicyKey]);
|
| - _navigationItem->SetReferrer(
|
| - web::Referrer(GURL(referrerString), referrerPolicy));
|
| - } else {
|
| - // Backward compatibility.
|
| - NSURL* referrer = [aDecoder
|
| - decodeObjectForKey:web::kSessionEntryReferrerURLDeprecatedKey];
|
| - _navigationItem->SetReferrer(web::Referrer(
|
| - net::GURLWithNSURL(referrer), web::ReferrerPolicyDefault));
|
| - }
|
| -
|
| - if ([aDecoder containsValueForKey:web::kSessionEntryTimestampKey]) {
|
| - int64_t us = [aDecoder decodeInt64ForKey:web::kSessionEntryTimestampKey];
|
| - _navigationItem->SetTimestamp(base::Time::FromInternalValue(us));
|
| - }
|
| -
|
| - NSString* title = [aDecoder decodeObjectForKey:web::kSessionEntryTitleKey];
|
| - // Use a transition type of reload so that we don't incorrectly increase
|
| - // the typed count. This is what desktop chrome does.
|
| - _navigationItem->SetTitle(base::SysNSStringToUTF16(title));
|
| - _navigationItem->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
|
| - _navigationItem->SetPageDisplayState([[self class]
|
| - pageDisplayStateFromDictionary:
|
| - [aDecoder
|
| - decodeObjectForKey:web::kSessionEntryPageScrollStateKey]]);
|
| - _navigationItem->SetShouldSkipRepostFormConfirmation([aDecoder
|
| - decodeBoolForKey:web::kSessionEntrySkipRepostFormConfirmationKey]);
|
| - _navigationItem->SetIsOverridingUserAgent(
|
| - [aDecoder decodeBoolForKey:web::kSessionEntryUseDesktopUserAgentKey]);
|
| - _navigationItem->SetPostData(
|
| - [aDecoder decodeObjectForKey:web::kSessionEntryPOSTDataKey]);
|
| - _navigationItem->AddHttpRequestHeaders(
|
| - [aDecoder decodeObjectForKey:web::kSessionEntryHTTPRequestHeadersKey]);
|
| - }
|
| - return self;
|
| -}
|
| -
|
| -- (void)encodeWithCoder:(NSCoder*)aCoder {
|
| - // Desktop Chrome doesn't persist |url_| or |originalUrl_|, only
|
| - // |virtualUrl_|.
|
| - web::nscoder_util::EncodeString(aCoder, web::kSessionEntryURLKey,
|
| - _navigationItem->GetVirtualURL().spec());
|
| - web::nscoder_util::EncodeString(aCoder, web::kSessionEntryReferrerURLKey,
|
| - _navigationItem->GetReferrer().url.spec());
|
| - [aCoder encodeInt:_navigationItem->GetReferrer().policy
|
| - forKey:web::kSessionEntryReferrerPolicyKey];
|
| - [aCoder encodeInt64:_navigationItem->GetTimestamp().ToInternalValue()
|
| - forKey:web::kSessionEntryTimestampKey];
|
| -
|
| - [aCoder encodeObject:base::SysUTF16ToNSString(_navigationItem->GetTitle())
|
| - forKey:web::kSessionEntryTitleKey];
|
| - [aCoder encodeObject:[[self class] dictionaryFromPageDisplayState:
|
| - _navigationItem->GetPageDisplayState()]
|
| - forKey:web::kSessionEntryPageScrollStateKey];
|
| - [aCoder encodeBool:_navigationItem->ShouldSkipRepostFormConfirmation()
|
| - forKey:web::kSessionEntrySkipRepostFormConfirmationKey];
|
| - [aCoder encodeBool:_navigationItem->IsOverridingUserAgent()
|
| - forKey:web::kSessionEntryUseDesktopUserAgentKey];
|
| - [aCoder encodeObject:_navigationItem->GetPostData()
|
| - forKey:web::kSessionEntryPOSTDataKey];
|
| - [aCoder encodeObject:_navigationItem->GetHttpRequestHeaders()
|
| - forKey:web::kSessionEntryHTTPRequestHeadersKey];
|
| -}
|
| -
|
| // TODO(ios): Shall we overwrite EqualTo:?
|
|
|
| - (instancetype)copyWithZone:(NSZone*)zone {
|
| @@ -179,9 +59,7 @@ - (NSString*)description {
|
| _navigationItem->GetOriginalRequestURL().spec()),
|
| base::SysUTF16ToNSString(_navigationItem->GetTitle()),
|
| _navigationItem->GetTransitionType(),
|
| - [[self class]
|
| - descriptionForPageDisplayState:_navigationItem
|
| - ->GetPageDisplayState()],
|
| + _navigationItem->GetPageDisplayState().GetDescription(),
|
| _navigationItem->IsOverridingUserAgent()];
|
| }
|
|
|
| @@ -193,54 +71,4 @@ - (NSString*)description {
|
| return _navigationItem.get();
|
| }
|
|
|
| -#pragma mark - Serialization helpers
|
| -
|
| -+ (web::PageDisplayState)pageDisplayStateFromDictionary:
|
| - (NSDictionary*)dictionary {
|
| - NSNumber* serializedValue = nil;
|
| - web::PageScrollState scrollState;
|
| - if ((serializedValue = dictionary[web::kSessionEntryScrollOffsetXKey]))
|
| - scrollState.set_offset_x([serializedValue doubleValue]);
|
| - if ((serializedValue = dictionary[web::kSessionEntryScrollOffsetYKey]))
|
| - scrollState.set_offset_y([serializedValue doubleValue]);
|
| - web::PageZoomState zoomState;
|
| - if ((serializedValue = dictionary[web::kSessionEntryMinimumZoomScaleKey]))
|
| - zoomState.set_minimum_zoom_scale([serializedValue doubleValue]);
|
| - if ((serializedValue = dictionary[web::kSessionEntryMaximumZoomScaleKey]))
|
| - zoomState.set_maximum_zoom_scale([serializedValue doubleValue]);
|
| - if ((serializedValue = dictionary[web::kSessionEntryZoomScaleKey]))
|
| - zoomState.set_zoom_scale([serializedValue doubleValue]);
|
| - return web::PageDisplayState(scrollState, zoomState);
|
| -}
|
| -
|
| -+ (NSDictionary*)dictionaryFromPageDisplayState:
|
| - (const web::PageDisplayState&)displayState {
|
| - return @{
|
| - web::kSessionEntryScrollOffsetXKey :
|
| - @(displayState.scroll_state().offset_x()),
|
| - web::kSessionEntryScrollOffsetYKey :
|
| - @(displayState.scroll_state().offset_y()),
|
| - web::kSessionEntryMinimumZoomScaleKey :
|
| - @(displayState.zoom_state().minimum_zoom_scale()),
|
| - web::kSessionEntryMaximumZoomScaleKey :
|
| - @(displayState.zoom_state().maximum_zoom_scale()),
|
| - web::kSessionEntryZoomScaleKey :
|
| - @(displayState.zoom_state().zoom_scale())
|
| - };
|
| -}
|
| -
|
| -+ (NSString*)descriptionForPageDisplayState:
|
| - (const web::PageDisplayState&)displayState {
|
| - NSString* const kPageScrollStateDescriptionFormat =
|
| - @"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), "
|
| - @"zoomScale:%0.2f }";
|
| - return
|
| - [NSString stringWithFormat:kPageScrollStateDescriptionFormat,
|
| - displayState.scroll_state().offset_x(),
|
| - displayState.scroll_state().offset_y(),
|
| - displayState.zoom_state().minimum_zoom_scale(),
|
| - displayState.zoom_state().maximum_zoom_scale(),
|
| - displayState.zoom_state().zoom_scale()];
|
| -}
|
| -
|
| @end
|
|
|