| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/android/offline_pages/offline_page_request_job.h" | 10 #include "chrome/browser/android/offline_pages/offline_page_request_job.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace offline_pages { | 23 namespace offline_pages { |
| 24 | 24 |
| 25 OfflinePageTabHelper::LoadedOfflinePageInfo::LoadedOfflinePageInfo() {} | 25 OfflinePageTabHelper::LoadedOfflinePageInfo::LoadedOfflinePageInfo() {} |
| 26 | 26 |
| 27 OfflinePageTabHelper::LoadedOfflinePageInfo::~LoadedOfflinePageInfo() {} | 27 OfflinePageTabHelper::LoadedOfflinePageInfo::~LoadedOfflinePageInfo() {} |
| 28 | 28 |
| 29 void OfflinePageTabHelper::LoadedOfflinePageInfo::Clear() { | 29 void OfflinePageTabHelper::LoadedOfflinePageInfo::Clear() { |
| 30 offline_page.reset(); | 30 offline_page.reset(); |
| 31 offline_header.Clear(); | 31 offline_header.Clear(); |
| 32 is_offline_preview = false; | 32 is_showing_offline_preview = false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 OfflinePageTabHelper::OfflinePageTabHelper(content::WebContents* web_contents) | 35 OfflinePageTabHelper::OfflinePageTabHelper(content::WebContents* web_contents) |
| 36 : content::WebContentsObserver(web_contents), | 36 : content::WebContentsObserver(web_contents), |
| 37 weak_ptr_factory_(this) { | 37 weak_ptr_factory_(this) { |
| 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 OfflinePageTabHelper::~OfflinePageTabHelper() {} | 41 OfflinePageTabHelper::~OfflinePageTabHelper() {} |
| 42 | 42 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } else { | 80 } else { |
| 81 // The provisional offline info can now be committed if the navigation is | 81 // The provisional offline info can now be committed if the navigation is |
| 82 // done without error. | 82 // done without error. |
| 83 DCHECK(!provisional_offline_info_.offline_page || | 83 DCHECK(!provisional_offline_info_.offline_page || |
| 84 OfflinePageUtils::EqualsIgnoringFragment( | 84 OfflinePageUtils::EqualsIgnoringFragment( |
| 85 navigated_url, | 85 navigated_url, |
| 86 provisional_offline_info_.offline_page->url)); | 86 provisional_offline_info_.offline_page->url)); |
| 87 offline_info_.offline_page = | 87 offline_info_.offline_page = |
| 88 std::move(provisional_offline_info_.offline_page); | 88 std::move(provisional_offline_info_.offline_page); |
| 89 offline_info_.offline_header = provisional_offline_info_.offline_header; | 89 offline_info_.offline_header = provisional_offline_info_.offline_header; |
| 90 offline_info_.is_offline_preview = | 90 offline_info_.is_showing_offline_preview = |
| 91 provisional_offline_info_.is_offline_preview; | 91 provisional_offline_info_.is_showing_offline_preview; |
| 92 } | 92 } |
| 93 provisional_offline_info_.Clear(); | 93 provisional_offline_info_.Clear(); |
| 94 | 94 |
| 95 // If the offline page has been loaded successfully, nothing more to do. | 95 // If the offline page has been loaded successfully, nothing more to do. |
| 96 net::Error error_code = navigation_handle->GetNetErrorCode(); | 96 net::Error error_code = navigation_handle->GetNetErrorCode(); |
| 97 if (error_code == net::OK) | 97 if (error_code == net::OK) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 // We might be reloading the URL in order to fetch the offline page. | 100 // We might be reloading the URL in order to fetch the offline page. |
| 101 // * If successful, nothing to do. | 101 // * If successful, nothing to do. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 // This is a callback from network request interceptor. It happens between | 164 // This is a callback from network request interceptor. It happens between |
| 165 // DidStartNavigation and DidFinishNavigation calls on this tab helper. | 165 // DidStartNavigation and DidFinishNavigation calls on this tab helper. |
| 166 void OfflinePageTabHelper::SetOfflinePage( | 166 void OfflinePageTabHelper::SetOfflinePage( |
| 167 const OfflinePageItem& offline_page, | 167 const OfflinePageItem& offline_page, |
| 168 const OfflinePageHeader& offline_header, | 168 const OfflinePageHeader& offline_header, |
| 169 bool is_offline_preview) { | 169 bool is_offline_preview) { |
| 170 provisional_offline_info_.offline_page = | 170 provisional_offline_info_.offline_page = |
| 171 base::MakeUnique<OfflinePageItem>(offline_page); | 171 base::MakeUnique<OfflinePageItem>(offline_page); |
| 172 provisional_offline_info_.offline_header = offline_header; | 172 provisional_offline_info_.offline_header = offline_header; |
| 173 provisional_offline_info_.is_offline_preview = is_offline_preview; | 173 provisional_offline_info_.is_showing_offline_preview = is_offline_preview; |
| 174 } | 174 } |
| 175 | 175 |
| 176 const OfflinePageItem* OfflinePageTabHelper::GetOfflinePageForTest() const { | 176 const OfflinePageItem* OfflinePageTabHelper::GetOfflinePageForTest() const { |
| 177 return provisional_offline_info_.offline_page.get(); | 177 return provisional_offline_info_.offline_page.get(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool OfflinePageTabHelper::IsShowingOfflinePreview() const { |
| 181 // TODO: Change this once offline pages infrastructure uses NavigationHandle |
| 182 // instead of a back channel. crbug.com/658899 |
| 183 return provisional_offline_info_.is_showing_offline_preview || |
| 184 offline_info_.is_showing_offline_preview; |
| 185 } |
| 186 |
| 180 } // namespace offline_pages | 187 } // namespace offline_pages |
| OLD | NEW |