forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PreviewsInfoBarDelegate to show an infobar when a preview page has been loaded. Also add the corresponding resources. BUG=615566 Review-Url: https://codereview.chromium.org/2250223002 Cr-Commit-Position: refs/heads/master@{#418413}
- Loading branch information
megjablon
authored and
Commit bot
committed
Sep 13, 2016
1 parent
f47b481
commit 82aba52
Showing
28 changed files
with
235 additions
and
135 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/previews/previews_infobar_delegate.h" | ||
|
||
#include "chrome/browser/android/android_theme_resources.h" | ||
#include "chrome/browser/infobars/infobar_service.h" | ||
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | ||
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h" | ||
#include "chrome/grit/generated_resources.h" | ||
#include "components/infobars/core/infobar.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
|
||
PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {} | ||
|
||
// static | ||
void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, | ||
PreviewsInfoBarType infobar_type) { | ||
// TODO(megjablon): Check that the infobar was not already shown. | ||
|
||
InfoBarService* infobar_service = | ||
InfoBarService::FromWebContents(web_contents); | ||
|
||
infobars::InfoBar* infobar = | ||
infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | ||
std::unique_ptr<ConfirmInfoBarDelegate>( | ||
new PreviewsInfoBarDelegate(web_contents, infobar_type)))); | ||
|
||
if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { | ||
auto* data_reduction_proxy_settings = | ||
DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | ||
web_contents->GetBrowserContext()); | ||
data_reduction_proxy_settings->IncrementLoFiUIShown(); | ||
} | ||
} | ||
|
||
PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( | ||
content::WebContents* web_contents, | ||
PreviewsInfoBarType infobar_type) | ||
: ConfirmInfoBarDelegate(), | ||
infobar_type_(infobar_type) {} | ||
|
||
infobars::InfoBarDelegate::InfoBarIdentifier | ||
PreviewsInfoBarDelegate::GetIdentifier() const { | ||
return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; | ||
} | ||
|
||
int PreviewsInfoBarDelegate::GetIconId() const { | ||
#if defined(OS_ANDROID) | ||
return IDR_ANDROID_INFOBAR_PREVIEWS; | ||
#else | ||
return kNoIconID; | ||
#endif | ||
} | ||
|
||
bool PreviewsInfoBarDelegate::ShouldExpire( | ||
const NavigationDetails& details) const { | ||
// TODO(megjablon): Record UMA data. | ||
return InfoBarDelegate::ShouldExpire(details); | ||
} | ||
|
||
base::string16 PreviewsInfoBarDelegate::GetMessageText() const { | ||
return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE) | ||
? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE | ||
: IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE); | ||
} | ||
|
||
int PreviewsInfoBarDelegate::GetButtons() const { | ||
return BUTTON_NONE; | ||
} | ||
|
||
base::string16 PreviewsInfoBarDelegate::GetLinkText() const { | ||
return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); | ||
} | ||
|
||
bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | ||
// TODO(megjablon): Record UMA data. | ||
if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { | ||
auto* web_contents = | ||
InfoBarService::WebContentsFromInfoBar(infobar()); | ||
|
||
if (infobar_type_ == LITE_PAGE) | ||
web_contents->GetController().ReloadDisableLoFi(true); | ||
else if (infobar_type_ == LOFI) | ||
web_contents->ReloadLoFiImages(); | ||
|
||
auto* data_reduction_proxy_settings = | ||
DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | ||
web_contents->GetBrowserContext()); | ||
data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_DELEGATE_H_ | ||
#define CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_DELEGATE_H_ | ||
|
||
#include "components/infobars/core/confirm_infobar_delegate.h" | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
// Shows an infobar that lets the user know that a preview page has been loaded, | ||
// and gives the user a link to reload the original page. This infobar will only | ||
// be shown once per page load. Records UMA data for user interactions with the | ||
// infobar. | ||
class PreviewsInfoBarDelegate : public ConfirmInfoBarDelegate { | ||
public: | ||
// The type of the infobar. It controls the strings and what UMA data is | ||
// recorded for the infobar. | ||
enum PreviewsInfoBarType { | ||
LOFI, // Server-side image replacement. | ||
LITE_PAGE, // Server-side page rewrite. | ||
OFFLINE, // Offline copy of the page. | ||
}; | ||
|
||
~PreviewsInfoBarDelegate() override; | ||
|
||
// Creates a preview infobar and corresponding delegate and adds the infobar | ||
// to InfoBarService. | ||
static void Create(content::WebContents* web_contents, | ||
PreviewsInfoBarType infobar_type); | ||
|
||
private: | ||
PreviewsInfoBarDelegate(content::WebContents* web_contents, | ||
PreviewsInfoBarType infobar_type); | ||
|
||
// ConfirmInfoBarDelegate overrides: | ||
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | ||
int GetIconId() const override; | ||
bool ShouldExpire(const NavigationDetails& details) const override; | ||
base::string16 GetMessageText() const override; | ||
int GetButtons() const override; | ||
base::string16 GetLinkText() const override; | ||
bool LinkClicked(WindowOpenDisposition disposition) override; | ||
|
||
PreviewsInfoBarType infobar_type_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PreviewsInfoBarDelegate); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_DELEGATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.