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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/offline_pages/offline_page_utils.cc
diff --git a/chrome/browser/android/offline_pages/offline_page_utils.cc b/chrome/browser/android/offline_pages/offline_page_utils.cc
index 1f06a44459557725bfa8bf96ba82a262bb5b5766..d6cbffe2923dcdde80726881a4b9c3f839c09c1d 100644
--- a/chrome/browser/android/offline_pages/offline_page_utils.cc
+++ b/chrome/browser/android/offline_pages/offline_page_utils.cc
@@ -18,6 +18,7 @@
#include "components/offline_pages/offline_page_feature.h"
#include "components/offline_pages/offline_page_item.h"
#include "components/offline_pages/offline_page_model.h"
+#include "components/offline_pages/request_header/offline_page_header.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"
@@ -152,11 +153,35 @@ void OfflinePageUtils::MarkPageAccessed(
offline_page_model->MarkPageAccessed(offline_page->offline_id);
}
+// static
const OfflinePageItem* OfflinePageUtils::GetOfflinePageFromWebContents(
content::WebContents* web_contents) {
OfflinePageTabHelper* tab_helper =
OfflinePageTabHelper::FromWebContents(web_contents);
- return tab_helper ? tab_helper->offline_page() : nullptr;
+ if (!tab_helper)
+ return nullptr;
+ const OfflinePageItem* offline_page = tab_helper->offline_page();
+ if (!offline_page)
+ return nullptr;
+
+ // Returns the cached offline page only if the offline URL matches with
+ // current tab URL (skipping fragment identifier part). This is to prevent
+ // from returning the wrong offline page if DidStartNavigation is never called
+ // to clear it up.
+ GURL::Replacements remove_params;
+ remove_params.ClearRef();
+ GURL offline_url = offline_page->url.ReplaceComponents(remove_params);
+ GURL web_contents_url =
+ web_contents->GetVisibleURL().ReplaceComponents(remove_params);
+ return offline_url == web_contents_url ? offline_page : nullptr;
+}
+
+// static
+const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents(
+ content::WebContents* web_contents) {
+ OfflinePageTabHelper* tab_helper =
+ OfflinePageTabHelper::FromWebContents(web_contents);
+ return tab_helper ? &(tab_helper->offline_header()) : nullptr;
}
// static
« 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