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

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

Issue 2762853004: Check WebContentsObservers before showing Previews InfoBars (Closed)
Patch Set: rebase Created 3 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_delegate.h" 5 #include "chrome/browser/previews/previews_infobar_delegate.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "chrome/browser/android/android_theme_resources.h" 8 #include "chrome/browser/android/android_theme_resources.h"
9 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 // static 54 // static
55 void PreviewsInfoBarDelegate::Create( 55 void PreviewsInfoBarDelegate::Create(
56 content::WebContents* web_contents, 56 content::WebContents* web_contents,
57 PreviewsInfoBarType infobar_type, 57 PreviewsInfoBarType infobar_type,
58 bool is_data_saver_user, 58 bool is_data_saver_user,
59 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { 59 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) {
60 PreviewsInfoBarTabHelper* infobar_tab_helper = 60 PreviewsInfoBarTabHelper* infobar_tab_helper =
61 PreviewsInfoBarTabHelper::FromWebContents(web_contents); 61 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
62 InfoBarService* infobar_service =
63 InfoBarService::FromWebContents(web_contents);
64
65 // The WebContents may not have TabHelpers set. If TabHelpers are not set,
66 // don't show Previews infobars.
67 if (!infobar_tab_helper || !infobar_service)
68 return;
62 if (infobar_tab_helper->displayed_preview_infobar()) 69 if (infobar_tab_helper->displayed_preview_infobar())
63 return; 70 return;
64 71
65 InfoBarService* infobar_service =
66 InfoBarService::FromWebContents(web_contents);
67
68 infobars::InfoBar* infobar = 72 infobars::InfoBar* infobar =
69 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( 73 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
70 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate( 74 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate(
71 web_contents, infobar_type, is_data_saver_user, 75 web_contents, infobar_type, is_data_saver_user,
72 on_dismiss_callback)))); 76 on_dismiss_callback))));
73 77
74 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { 78 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) {
75 auto* data_reduction_proxy_settings = 79 auto* data_reduction_proxy_settings =
76 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 80 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
77 web_contents->GetBrowserContext()); 81 web_contents->GetBrowserContext());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 auto* data_reduction_proxy_settings = 153 auto* data_reduction_proxy_settings =
150 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 154 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
151 web_contents->GetBrowserContext()); 155 web_contents->GetBrowserContext());
152 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); 156 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
153 } else if (infobar_type_ == OFFLINE) { 157 } else if (infobar_type_ == OFFLINE) {
154 web_contents->GetController().Reload(content::ReloadType::NORMAL, true); 158 web_contents->GetController().Reload(content::ReloadType::NORMAL, true);
155 } 159 }
156 160
157 return true; 161 return true;
158 } 162 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698