| 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/tab_android.h" | 16 #include "chrome/browser/android/tab_android.h" |
| 17 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
| 17 #include "components/offline_pages/client_namespace_constants.h" | 18 #include "components/offline_pages/client_namespace_constants.h" |
| 18 #include "components/offline_pages/offline_page_feature.h" | 19 #include "components/offline_pages/offline_page_feature.h" |
| 19 #include "components/offline_pages/offline_page_item.h" | 20 #include "components/offline_pages/offline_page_item.h" |
| 20 #include "components/offline_pages/offline_page_model.h" | 21 #include "components/offline_pages/offline_page_model.h" |
| 21 #include "components/offline_pages/request_header/offline_page_header.h" | 22 #include "components/offline_pages/request_header/offline_page_header.h" |
| 22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace offline_pages { | 27 namespace offline_pages { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 GURL web_contents_url = | 175 GURL web_contents_url = |
| 175 web_contents->GetVisibleURL().ReplaceComponents(remove_params); | 176 web_contents->GetVisibleURL().ReplaceComponents(remove_params); |
| 176 return offline_url == web_contents_url ? offline_page : nullptr; | 177 return offline_url == web_contents_url ? offline_page : nullptr; |
| 177 } | 178 } |
| 178 | 179 |
| 179 // static | 180 // static |
| 180 const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents( | 181 const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents( |
| 181 content::WebContents* web_contents) { | 182 content::WebContents* web_contents) { |
| 182 OfflinePageTabHelper* tab_helper = | 183 OfflinePageTabHelper* tab_helper = |
| 183 OfflinePageTabHelper::FromWebContents(web_contents); | 184 OfflinePageTabHelper::FromWebContents(web_contents); |
| 184 return tab_helper ? &(tab_helper->offline_header()) : nullptr; | 185 return tab_helper ? tab_helper->offline_header() : nullptr; |
| 186 } |
| 187 |
| 188 // static |
| 189 bool OfflinePageUtils::IsShowingOfflinePreview( |
| 190 content::WebContents* web_contents) { |
| 191 PreviewsInfoBarTabHelper* previews_tab_helper = |
| 192 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
| 193 return previews_tab_helper && |
| 194 previews_tab_helper->is_showing_offline_preview(); |
| 185 } | 195 } |
| 186 | 196 |
| 187 // static | 197 // static |
| 188 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents, | 198 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents, |
| 189 int* tab_id) { | 199 int* tab_id) { |
| 190 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents); | 200 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents); |
| 191 if (!tab_android) | 201 if (!tab_android) |
| 192 return false; | 202 return false; |
| 193 *tab_id = tab_android->GetAndroidId(); | 203 *tab_id = tab_android->GetAndroidId(); |
| 194 return true; | 204 return true; |
| 195 } | 205 } |
| 196 | 206 |
| 197 } // namespace offline_pages | 207 } // namespace offline_pages |
| OLD | NEW |