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

Side by Side Diff: chrome/browser/previews/previews_infobar_tab_helper.cc

Issue 2472863002: Adding offline navigations to the previews blacklist (Closed)
Patch Set: megjablon comments Created 4 years, 1 month 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
OLDNEW
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/previews/previews_infobar_tab_helper.h" 5 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "chrome/browser/previews/previews_infobar_delegate.h" 9 #include "chrome/browser/previews/previews_infobar_delegate.h"
10 #include "chrome/browser/previews/previews_service.h"
11 #include "chrome/browser/previews/previews_service_factory.h"
12 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/features.h" 13 #include "chrome/common/features.h"
9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
15 #include "components/previews/core/previews_experiments.h"
16 #include "components/previews/core/previews_ui_service.h"
17 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/navigation_handle.h" 19 #include "content/public/browser/navigation_handle.h"
12 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
14 #include "net/http/http_response_headers.h" 22 #include "net/http/http_response_headers.h"
15 #include "url/gurl.h" 23 #include "url/gurl.h"
16 24
17 #if BUILDFLAG(ANDROID_JAVA_UI) 25 #if BUILDFLAG(ANDROID_JAVA_UI)
18 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" 26 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
27
28 namespace {
29
30 // Adds the preview navigation to the black list. This method is only used on
31 // android currently.
32 void AddPreviewNavigationCallback(content::BrowserContext* browser_context,
33 const GURL& url,
34 previews::PreviewsType type,
35 bool opt_out) {
36 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
37 Profile::FromBrowserContext(browser_context));
38 if (previews_service && previews_service->previews_ui_service()) {
39 previews_service->previews_ui_service()->AddPreviewNavigation(url, type,
40 opt_out);
41 }
42 }
43
44 } // namespace
45
19 #endif // BUILDFLAG(ANDROID_JAVA_UI) 46 #endif // BUILDFLAG(ANDROID_JAVA_UI)
20 47
21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); 48 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper);
22 49
23 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} 50 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {}
24 51
25 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( 52 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper(
26 content::WebContents* web_contents) 53 content::WebContents* web_contents)
27 : content::WebContentsObserver(web_contents), 54 : content::WebContentsObserver(web_contents),
28 displayed_preview_infobar_(false), 55 displayed_preview_infobar_(false),
(...skipping 13 matching lines...) Expand all
42 #if BUILDFLAG(ANDROID_JAVA_UI) 69 #if BUILDFLAG(ANDROID_JAVA_UI)
43 offline_pages::OfflinePageTabHelper* tab_helper = 70 offline_pages::OfflinePageTabHelper* tab_helper =
44 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); 71 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents());
45 72
46 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { 73 if (tab_helper && tab_helper->IsShowingOfflinePreview()) {
47 if (navigation_handle->IsErrorPage()) { 74 if (navigation_handle->IsErrorPage()) {
48 // TODO(ryansturm): Add UMA for errors. 75 // TODO(ryansturm): Add UMA for errors.
49 return; 76 return;
50 } 77 }
51 is_showing_offline_preview_ = true; 78 is_showing_offline_preview_ = true;
52 PreviewsInfoBarDelegate::Create(web_contents(), 79 PreviewsInfoBarDelegate::Create(
53 PreviewsInfoBarDelegate::OFFLINE); 80 web_contents(), PreviewsInfoBarDelegate::OFFLINE,
81 base::Bind(
82 &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(),
83 navigation_handle->GetURL(), previews::PreviewsType::OFFLINE));
megjablon 2016/11/09 19:35:05 Can you add a test to previews_infobar_tab_helper_
RyanSturm 2016/11/09 20:45:47 I wanted to avoid it due to the nature of KeyedSer
megjablon 2016/11/09 22:17:54 Ok sounds reasonable.
54 // Don't try to show other infobars if this is an offline preview. 84 // Don't try to show other infobars if this is an offline preview.
55 return; 85 return;
56 } 86 }
57 #endif // BUILDFLAG(ANDROID_JAVA_UI) 87 #endif // BUILDFLAG(ANDROID_JAVA_UI)
58 88
59 const net::HttpResponseHeaders* headers = 89 const net::HttpResponseHeaders* headers =
60 navigation_handle->GetResponseHeaders(); 90 navigation_handle->GetResponseHeaders();
61 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { 91 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) {
62 PreviewsInfoBarDelegate::Create(web_contents(), 92 PreviewsInfoBarDelegate::Create(
63 PreviewsInfoBarDelegate::LITE_PAGE); 93 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE,
94 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
64 } 95 }
65 } 96 }
66 97
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698