Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 void OfflinePageTabHelper::DidStartNavigation( | 34 void OfflinePageTabHelper::DidStartNavigation( |
| 35 content::NavigationHandle* navigation_handle) { | 35 content::NavigationHandle* navigation_handle) { |
| 36 // Skips non-main frame. | 36 // Skips non-main frame. |
| 37 if (!navigation_handle->IsInMainFrame()) | 37 if (!navigation_handle->IsInMainFrame()) |
| 38 return; | 38 return; |
| 39 | 39 |
| 40 // This is a new navigation so we can invalidate any previously scheduled | 40 // This is a new navigation so we can invalidate any previously scheduled |
| 41 // operations. | 41 // operations. |
| 42 weak_ptr_factory_.InvalidateWeakPtrs(); | 42 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 43 | 43 |
| 44 new_offline_page_ = nullptr; | |
|
dewittj
2016/09/15 23:17:40
s/new/provisional?
Dmitry Titov
2016/09/16 02:01:25
Done.
| |
| 45 | |
| 44 // Since this is a new navigation, we will reset the cached offline page, | 46 // Since this is a new navigation, we will reset the cached offline page, |
| 45 offline_page_ = nullptr; | |
| 46 is_offline_preview_ = false; | 47 is_offline_preview_ = false; |
| 47 | |
| 48 reloading_url_on_net_error_ = false; | 48 reloading_url_on_net_error_ = false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void OfflinePageTabHelper::DidFinishNavigation( | 51 void OfflinePageTabHelper::DidFinishNavigation( |
| 52 content::NavigationHandle* navigation_handle) { | 52 content::NavigationHandle* navigation_handle) { |
| 53 // Skips non-main frame. | 53 // Skips non-main frame. |
| 54 if (!navigation_handle->IsInMainFrame()) | 54 if (!navigation_handle->IsInMainFrame()) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 if (!navigation_handle->HasCommitted()) | |
| 58 return; | |
| 59 | |
| 60 if (navigation_handle->IsSamePage()) { | |
| 61 return; | |
| 62 } | |
| 63 | |
| 64 offline_page_ = std::move(new_offline_page_); | |
|
dewittj
2016/09/15 23:17:39
new_offline_page_ could be in indeterminate state?
Dmitry Titov
2016/09/16 02:01:25
Done. Explicitly assigned nullptr. Not sure this i
| |
| 65 | |
| 57 // We might be reloading the URL in order to fetch the offline page. | 66 // We might be reloading the URL in order to fetch the offline page. |
| 58 // * If successful, nothing to do. | 67 // * If successful, nothing to do. |
| 59 // * Otherwise, we're hitting error again. Bail out to avoid loop. | 68 // * Otherwise, we're hitting error again. Bail out to avoid loop. |
| 60 if (reloading_url_on_net_error_) | 69 if (reloading_url_on_net_error_) |
| 61 return; | 70 return; |
| 62 | 71 |
| 63 // When the navigation starts, the request might be intercepted to serve the | 72 // When the navigation starts, the request might be intercepted to serve the |
| 64 // offline content if the network is detected to be in disconnected or poor | 73 // offline content if the network is detected to be in disconnected or poor |
| 65 // conditions. This detection might not work for some cases, i.e., connected | 74 // conditions. This detection might not work for some cases, i.e., connected |
| 66 // to a hotspot or proxy that does not have network, and the navigation will | 75 // to a hotspot or proxy that does not have network, and the navigation will |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 content::NavigationController::LoadURLParams load_params(offline_page->url); | 123 content::NavigationController::LoadURLParams load_params(offline_page->url); |
| 115 load_params.transition_type = ui::PAGE_TRANSITION_RELOAD; | 124 load_params.transition_type = ui::PAGE_TRANSITION_RELOAD; |
| 116 load_params.extra_headers = kOfflinePageHeader; | 125 load_params.extra_headers = kOfflinePageHeader; |
| 117 load_params.extra_headers += ":"; | 126 load_params.extra_headers += ":"; |
| 118 load_params.extra_headers += kOfflinePageHeaderReasonKey; | 127 load_params.extra_headers += kOfflinePageHeaderReasonKey; |
| 119 load_params.extra_headers += "="; | 128 load_params.extra_headers += "="; |
| 120 load_params.extra_headers += kOfflinePageHeaderReasonValueDueToNetError; | 129 load_params.extra_headers += kOfflinePageHeaderReasonValueDueToNetError; |
| 121 web_contents()->GetController().LoadURLWithParams(load_params); | 130 web_contents()->GetController().LoadURLWithParams(load_params); |
| 122 } | 131 } |
| 123 | 132 |
| 133 // This is a callback from network request interceptor. It happens between | |
| 134 // DidStartNavigation and DidFinishNavigation calls on this tab helper. | |
| 124 void OfflinePageTabHelper::SetOfflinePage(const OfflinePageItem& offline_page, | 135 void OfflinePageTabHelper::SetOfflinePage(const OfflinePageItem& offline_page, |
| 125 bool is_offline_preview) { | 136 bool is_offline_preview) { |
| 126 offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page); | 137 new_offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page); |
| 127 is_offline_preview_ = is_offline_preview; | 138 is_offline_preview_ = is_offline_preview; |
| 128 } | 139 } |
| 129 | 140 |
| 130 } // namespace offline_pages | 141 } // namespace offline_pages |
| OLD | NEW |