| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "ios/web/web_state/navigation_context_impl.h" | 5 #import "ios/web/web_state/navigation_context_impl.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| 11 | 11 |
| 12 namespace web { | 12 namespace web { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 std::unique_ptr<NavigationContextImpl> | 15 std::unique_ptr<NavigationContextImpl> |
| 16 NavigationContextImpl::CreateNavigationContext(WebState* web_state, | 16 NavigationContextImpl::CreateNavigationContext(WebState* web_state, |
| 17 const GURL& url) { | 17 const GURL& url) { |
| 18 std::unique_ptr<NavigationContextImpl> result(new NavigationContextImpl( | 18 std::unique_ptr<NavigationContextImpl> result( |
| 19 web_state, url, false /* is_same_document */, false /* is_error_page */, | 19 new NavigationContextImpl(web_state, url)); |
| 20 nullptr /* response_headers */)); | |
| 21 return result; | 20 return result; |
| 22 } | 21 } |
| 23 | 22 |
| 24 #ifndef NDEBUG | 23 #ifndef NDEBUG |
| 25 NSString* NavigationContextImpl::GetDescription() const { | 24 NSString* NavigationContextImpl::GetDescription() const { |
| 26 return [NSString stringWithFormat:@"web::WebState: %ld, url: %s, " | 25 return [NSString |
| 27 "is_same_document: %@, is_error_page_: %@", | 26 stringWithFormat:@"web::WebState: %ld, url: %s, " |
| 28 reinterpret_cast<long>(web_state_), | 27 "is_same_document: %@, error: %@", |
| 29 url_.spec().c_str(), | 28 reinterpret_cast<long>(web_state_), url_.spec().c_str(), |
| 30 is_same_document_ ? @"true" : @"false", | 29 is_same_document_ ? @"true" : @"false", error_.get()]; |
| 31 is_error_page_ ? @"true" : @"false"]; | |
| 32 } | 30 } |
| 33 #endif // NDEBUG | 31 #endif // NDEBUG |
| 34 | 32 |
| 35 WebState* NavigationContextImpl::GetWebState() { | 33 WebState* NavigationContextImpl::GetWebState() { |
| 36 return web_state_; | 34 return web_state_; |
| 37 } | 35 } |
| 38 | 36 |
| 39 const GURL& NavigationContextImpl::GetUrl() const { | 37 const GURL& NavigationContextImpl::GetUrl() const { |
| 40 return url_; | 38 return url_; |
| 41 } | 39 } |
| 42 | 40 |
| 43 bool NavigationContextImpl::IsSameDocument() const { | 41 bool NavigationContextImpl::IsSameDocument() const { |
| 44 return is_same_document_; | 42 return is_same_document_; |
| 45 } | 43 } |
| 46 | 44 |
| 47 bool NavigationContextImpl::IsErrorPage() const { | 45 NSError* NavigationContextImpl::GetError() const { |
| 48 return is_error_page_; | 46 return error_; |
| 49 } | 47 } |
| 50 | 48 |
| 51 net::HttpResponseHeaders* NavigationContextImpl::GetResponseHeaders() const { | 49 net::HttpResponseHeaders* NavigationContextImpl::GetResponseHeaders() const { |
| 52 return response_headers_.get(); | 50 return response_headers_.get(); |
| 53 } | 51 } |
| 54 | 52 |
| 55 void NavigationContextImpl::SetIsSameDocument(bool is_same_document) { | 53 void NavigationContextImpl::SetIsSameDocument(bool is_same_document) { |
| 56 is_same_document_ = is_same_document; | 54 is_same_document_ = is_same_document; |
| 57 } | 55 } |
| 58 | 56 |
| 59 void NavigationContextImpl::SetIsErrorPage(bool is_error_page) { | 57 void NavigationContextImpl::SetError(NSError* error) { |
| 60 is_error_page_ = is_error_page; | 58 error_.reset(error); |
| 61 } | 59 } |
| 62 | 60 |
| 63 void NavigationContextImpl::SetResponseHeaders( | 61 void NavigationContextImpl::SetResponseHeaders( |
| 64 const scoped_refptr<net::HttpResponseHeaders>& response_headers) { | 62 const scoped_refptr<net::HttpResponseHeaders>& response_headers) { |
| 65 response_headers_ = response_headers; | 63 response_headers_ = response_headers; |
| 66 } | 64 } |
| 67 | 65 |
| 68 int NavigationContextImpl::GetNavigationItemUniqueID() const { | 66 int NavigationContextImpl::GetNavigationItemUniqueID() const { |
| 69 return navigation_item_unique_id_; | 67 return navigation_item_unique_id_; |
| 70 } | 68 } |
| 71 | 69 |
| 72 void NavigationContextImpl::SetNavigationItemUniqueID(int unique_id) { | 70 void NavigationContextImpl::SetNavigationItemUniqueID(int unique_id) { |
| 73 navigation_item_unique_id_ = unique_id; | 71 navigation_item_unique_id_ = unique_id; |
| 74 } | 72 } |
| 75 | 73 |
| 76 NavigationContextImpl::NavigationContextImpl( | 74 NavigationContextImpl::NavigationContextImpl(WebState* web_state, |
| 77 WebState* web_state, | 75 const GURL& url) |
| 78 const GURL& url, | |
| 79 bool is_same_document, | |
| 80 bool is_error_page, | |
| 81 const scoped_refptr<net::HttpResponseHeaders>& response_headers) | |
| 82 : web_state_(web_state), | 76 : web_state_(web_state), |
| 83 url_(url), | 77 url_(url), |
| 84 is_same_document_(is_same_document), | 78 is_same_document_(false), |
| 85 is_error_page_(is_error_page), | 79 error_(nil), |
| 86 response_headers_(response_headers) {} | 80 response_headers_(nullptr) {} |
| 87 | 81 |
| 88 NavigationContextImpl::~NavigationContextImpl() = default; | 82 NavigationContextImpl::~NavigationContextImpl() = default; |
| 89 | 83 |
| 90 } // namespace web | 84 } // namespace web |
| OLD | NEW |