Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_utils.cc

Issue 2337363002: Load live version when reloading an offline page on connected network (Closed)
Patch Set: Update BUILD.gn Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_utils.h ('k') | components/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_utils.h" 5 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
15 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" 15 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
16 #include "chrome/browser/android/tab_android.h" 16 #include "chrome/browser/android/tab_android.h"
17 #include "components/offline_pages/client_namespace_constants.h" 17 #include "components/offline_pages/client_namespace_constants.h"
18 #include "components/offline_pages/offline_page_feature.h" 18 #include "components/offline_pages/offline_page_feature.h"
19 #include "components/offline_pages/offline_page_item.h" 19 #include "components/offline_pages/offline_page_item.h"
20 #include "components/offline_pages/offline_page_model.h" 20 #include "components/offline_pages/offline_page_model.h"
21 #include "components/offline_pages/request_header/offline_page_header.h"
21 #include "content/public/browser/browser_context.h" 22 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 namespace offline_pages { 26 namespace offline_pages {
26 namespace { 27 namespace {
27 28
28 // Returns an offline page that is stored as the |offline_url|. 29 // Returns an offline page that is stored as the |offline_url|.
29 const OfflinePageItem* GetOfflinePageForOfflineURL( 30 const OfflinePageItem* GetOfflinePageForOfflineURL(
30 content::BrowserContext* browser_context, 31 content::BrowserContext* browser_context,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 GetOfflinePageForOfflineURL(browser_context, offline_url); 146 GetOfflinePageForOfflineURL(browser_context, offline_url);
146 if (!offline_page) 147 if (!offline_page)
147 return; 148 return;
148 149
149 OfflinePageModel* offline_page_model = 150 OfflinePageModel* offline_page_model =
150 OfflinePageModelFactory::GetForBrowserContext(browser_context); 151 OfflinePageModelFactory::GetForBrowserContext(browser_context);
151 DCHECK(offline_page_model); 152 DCHECK(offline_page_model);
152 offline_page_model->MarkPageAccessed(offline_page->offline_id); 153 offline_page_model->MarkPageAccessed(offline_page->offline_id);
153 } 154 }
154 155
156 // static
155 const OfflinePageItem* OfflinePageUtils::GetOfflinePageFromWebContents( 157 const OfflinePageItem* OfflinePageUtils::GetOfflinePageFromWebContents(
156 content::WebContents* web_contents) { 158 content::WebContents* web_contents) {
157 OfflinePageTabHelper* tab_helper = 159 OfflinePageTabHelper* tab_helper =
158 OfflinePageTabHelper::FromWebContents(web_contents); 160 OfflinePageTabHelper::FromWebContents(web_contents);
159 return tab_helper ? tab_helper->offline_page() : nullptr; 161 if (!tab_helper)
162 return nullptr;
163 const OfflinePageItem* offline_page = tab_helper->offline_page();
164 if (!offline_page)
165 return nullptr;
166
167 // Returns the cached offline page only if the offline URL matches with
168 // current tab URL (skipping fragment identifier part). This is to prevent
169 // from returning the wrong offline page if DidStartNavigation is never called
170 // to clear it up.
171 GURL::Replacements remove_params;
172 remove_params.ClearRef();
173 GURL offline_url = offline_page->url.ReplaceComponents(remove_params);
174 GURL web_contents_url =
175 web_contents->GetVisibleURL().ReplaceComponents(remove_params);
176 return offline_url == web_contents_url ? offline_page : nullptr;
160 } 177 }
161 178
162 // static 179 // static
180 const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents(
181 content::WebContents* web_contents) {
182 OfflinePageTabHelper* tab_helper =
183 OfflinePageTabHelper::FromWebContents(web_contents);
184 return tab_helper ? &(tab_helper->offline_header()) : nullptr;
185 }
186
187 // static
163 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents, 188 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents,
164 int* tab_id) { 189 int* tab_id) {
165 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents); 190 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents);
166 if (!tab_android) 191 if (!tab_android)
167 return false; 192 return false;
168 *tab_id = tab_android->GetAndroidId(); 193 *tab_id = tab_android->GetAndroidId();
169 return true; 194 return true;
170 } 195 }
171 196
172 } // namespace offline_pages 197 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_utils.h ('k') | components/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698