| OLD | NEW |
| 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/offline_pages/request_coordinator_factory.h" | 16 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" |
| 17 #include "chrome/browser/android/tab_android.h" | 17 #include "chrome/browser/android/tab_android.h" |
| 18 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
| 18 #include "components/offline_pages/background/request_coordinator.h" | 19 #include "components/offline_pages/background/request_coordinator.h" |
| 19 #include "components/offline_pages/background/save_page_request.h" | 20 #include "components/offline_pages/background/save_page_request.h" |
| 20 #include "components/offline_pages/client_namespace_constants.h" | 21 #include "components/offline_pages/client_namespace_constants.h" |
| 21 #include "components/offline_pages/client_policy_controller.h" | 22 #include "components/offline_pages/client_policy_controller.h" |
| 22 #include "components/offline_pages/offline_page_feature.h" | 23 #include "components/offline_pages/offline_page_feature.h" |
| 23 #include "components/offline_pages/offline_page_item.h" | 24 #include "components/offline_pages/offline_page_item.h" |
| 24 #include "components/offline_pages/offline_page_model.h" | 25 #include "components/offline_pages/offline_page_model.h" |
| 25 #include "components/offline_pages/request_header/offline_page_header.h" | 26 #include "components/offline_pages/request_header/offline_page_header.h" |
| 26 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 GURL web_contents_url = | 99 GURL web_contents_url = |
| 99 web_contents->GetVisibleURL().ReplaceComponents(remove_params); | 100 web_contents->GetVisibleURL().ReplaceComponents(remove_params); |
| 100 return offline_url == web_contents_url ? offline_page : nullptr; | 101 return offline_url == web_contents_url ? offline_page : nullptr; |
| 101 } | 102 } |
| 102 | 103 |
| 103 // static | 104 // static |
| 104 const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents( | 105 const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents( |
| 105 content::WebContents* web_contents) { | 106 content::WebContents* web_contents) { |
| 106 OfflinePageTabHelper* tab_helper = | 107 OfflinePageTabHelper* tab_helper = |
| 107 OfflinePageTabHelper::FromWebContents(web_contents); | 108 OfflinePageTabHelper::FromWebContents(web_contents); |
| 108 return tab_helper ? &(tab_helper->offline_header()) : nullptr; | 109 return tab_helper ? tab_helper->offline_header() : nullptr; |
| 110 } |
| 111 |
| 112 // static |
| 113 bool OfflinePageUtils::IsShowingOfflinePreview( |
| 114 content::WebContents* web_contents) { |
| 115 PreviewsInfoBarTabHelper* previews_tab_helper = |
| 116 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
| 117 return previews_tab_helper && |
| 118 previews_tab_helper->is_showing_offline_preview(); |
| 109 } | 119 } |
| 110 | 120 |
| 111 // static | 121 // static |
| 112 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents, | 122 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents, |
| 113 int* tab_id) { | 123 int* tab_id) { |
| 114 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents); | 124 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents); |
| 115 if (!tab_android) | 125 if (!tab_android) |
| 116 return false; | 126 return false; |
| 117 *tab_id = tab_android->GetAndroidId(); | 127 *tab_id = tab_android->GetAndroidId(); |
| 118 return true; | 128 return true; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 GURL::Replacements remove_params; | 187 GURL::Replacements remove_params; |
| 178 remove_params.ClearRef(); | 188 remove_params.ClearRef(); |
| 179 | 189 |
| 180 GURL lhs_stripped = lhs.ReplaceComponents(remove_params); | 190 GURL lhs_stripped = lhs.ReplaceComponents(remove_params); |
| 181 GURL rhs_stripped = lhs.ReplaceComponents(remove_params); | 191 GURL rhs_stripped = lhs.ReplaceComponents(remove_params); |
| 182 | 192 |
| 183 return lhs_stripped == rhs_stripped; | 193 return lhs_stripped == rhs_stripped; |
| 184 } | 194 } |
| 185 | 195 |
| 186 } // namespace offline_pages | 196 } // namespace offline_pages |
| OLD | NEW |