diff options
author | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 09:27:49 +0000 |
---|---|---|
committer | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 09:27:49 +0000 |
commit | c1ff9e859ef08ebafddc1efdbf953fb95b87b5ec (patch) | |
tree | cc6fa3137a9a43d480e74518d692d12b51b0a78d | |
parent | a3a8b3869ee91443c91c2d42cb87e5f365011ffe (diff) | |
download | chromium_src-c1ff9e859ef08ebafddc1efdbf953fb95b87b5ec.zip chromium_src-c1ff9e859ef08ebafddc1efdbf953fb95b87b5ec.tar.gz chromium_src-c1ff9e859ef08ebafddc1efdbf953fb95b87b5ec.tar.bz2 |
Add a dialog for getting user consent in the echo redeem flow.
The dialog should have different content depending on whether the echo flow is
enabled or not.
BUG=175070,176979
TEST=none (the code utilizing the dialog hasn't landed yet)
(tested the dialog is shown properly with few local changes)
Review URL: https://chromiumcodereview.appspot.com/12317109
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188957 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chromeos_strings.grdp | 13 | ||||
-rw-r--r-- | chrome/browser/chromeos/ui/echo_dialog_listener.h | 32 | ||||
-rw-r--r-- | chrome/browser/chromeos/ui/echo_dialog_view.cc | 166 | ||||
-rw-r--r-- | chrome/browser/chromeos/ui/echo_dialog_view.h | 83 | ||||
-rw-r--r-- | chrome/chrome_browser_chromeos.gypi | 3 | ||||
-rw-r--r-- | ui/views/controls/styled_label_listener.h | 2 |
6 files changed, 294 insertions, 5 deletions
diff --git a/chrome/app/chromeos_strings.grdp b/chrome/app/chromeos_strings.grdp index 3952ab88..045cc24 100644 --- a/chrome/app/chromeos_strings.grdp +++ b/chrome/app/chromeos_strings.grdp @@ -129,13 +129,16 @@ Press any key to continue exploring. </message> <!-- Chrome OS Strings --> - <message name="IDS_OFFERS_CONSENT_INFOBAR_LABEL_ALT" desc="Butter bar text when prompting user for sending coupon code. Prefixed with the site name."> - wants to confirm you are browsing on a Chrome OS device by requesting Google to verify your coupon code. + <message name="IDS_ECHO_CONSENT_DIALOG_TEXT" desc="Dialog text shown when user is asked to give consent to proceed with redeeming ECHO offer."> + <ph name="SERVICE_NAME">$1<ex>Google Drive</ex></ph> wants to verify that you are using an eligible Chrome OS device. <ph name="MORE_INFO_LINK">$2<ex>More info</ex></ph> </message> - <message name="IDS_OFFERS_CONSENT_INFOBAR_LABEL" desc="Butter bar text when prompting user for sending coupon code. Prefixed with the site name."> - wants to confirm you are browsing on a Chrome OS device. + <message name="IDS_ECHO_DISABLED_CONSENT_DIALOG_TEXT" desc="Dialog text shown when user is informed that redeeming offers is disabled for the device."> + Your IT administrator has disabled Chrome Goodies for your device. <ph name="MORE_INFO_LINK">$1<ex>More info</ex></ph> </message> - <message name="IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE" desc="Text of the Learn More link on the offer butter bar."> + <message name="IDS_ECHO_CONSENT_DISMISS_BUTTON" desc="Dismiss dialog button label for disabled echo dialog."> + Dismiss + </message> + <message name="IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE" desc="Text of the Learn More link in the echo dialog."> Learn More </message> <message name="IDS_OFFERS_CONSENT_INFOBAR_ENABLE_BUTTON" desc="Enable button label."> diff --git a/chrome/browser/chromeos/ui/echo_dialog_listener.h b/chrome/browser/chromeos/ui/echo_dialog_listener.h new file mode 100644 index 0000000..b2bdb08 --- /dev/null +++ b/chrome/browser/chromeos/ui/echo_dialog_listener.h @@ -0,0 +1,32 @@ +// Copyright 2013 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_CHROMEOS_UI_ECHO_DIALOG_LISTENER_H_ +#define CHROME_BROWSER_CHROMEOS_UI_ECHO_DIALOG_LISTENER_H_ + +namespace chromeos { + +// A listener interface for the EchoDialog, so an interested party can be +// notified about changes to the dialog. It is provided during EchoDialog +// construction. +class EchoDialogListener { + public: + // Called when the EchoDialog is accepted. After call to this method, the + // listener will not be invoked again. + virtual void OnAccept() = 0; + + // Called when the EchoDialog is canceled. After call to this method, the + // listener will not be invoked again. + virtual void OnCancel() = 0; + + // Called when a link in the EchoDialog is clicked. + virtual void OnMoreInfoLinkClicked() = 0; + + protected: + virtual ~EchoDialogListener() {} +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_UI_ECHO_DIALOG_LISTENER_H_ diff --git a/chrome/browser/chromeos/ui/echo_dialog_view.cc b/chrome/browser/chromeos/ui/echo_dialog_view.cc new file mode 100644 index 0000000..4e1af74 --- /dev/null +++ b/chrome/browser/chromeos/ui/echo_dialog_view.cc @@ -0,0 +1,166 @@ +// Copyright 2013 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/chromeos/ui/echo_dialog_view.h" + +#include "chrome/browser/chromeos/ui/echo_dialog_listener.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/styled_label.h" +#include "ui/views/widget/widget.h" +#include "ui/views/window/dialog_client_view.h" + +namespace { + +const int kDialogLabelTopInset = 20; +const int kDialogLabelLeftInset = 20; +const int kDialogLabelBottomInset = 20; +const int kDialogLabelRightInset = 100; + +const int kDialogLabelPreferredWidth = + 350 + kDialogLabelLeftInset + kDialogLabelRightInset; + +} // namespace + +namespace chromeos { + +EchoDialogView::EchoDialogView(EchoDialogListener* listener) + : label_(NULL), + listener_(listener), + ok_button_label_id_(0), + cancel_button_label_id_(0) { +} + +EchoDialogView::~EchoDialogView() {} + +void EchoDialogView::InitForEnabledEcho(const string16& service_name, + const string16& origin) { + ok_button_label_id_ = IDS_OFFERS_CONSENT_INFOBAR_ENABLE_BUTTON; + cancel_button_label_id_ = IDS_OFFERS_CONSENT_INFOBAR_DISABLE_BUTTON; + + string16 link = + l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE); + + std::vector<size_t> offsets; + string16 text = l10n_util::GetStringFUTF16(IDS_ECHO_CONSENT_DIALOG_TEXT, + service_name, + link, + &offsets); + + // TODO(tbarzic): Set style for service_name substring. + + label_ = new views::StyledLabel(text, this); + label_->AddLink(ui::Range(offsets[1], offsets[1] + link.length())); + + SetLabelBorderAndBounds(); + + AddChildView(label_); +} + +void EchoDialogView::InitForDisabledEcho() { + ok_button_label_id_ = 0; + cancel_button_label_id_ = IDS_ECHO_CONSENT_DISMISS_BUTTON; + + string16 link = + l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE); + + size_t offset; + string16 text = l10n_util::GetStringFUTF16( + IDS_ECHO_DISABLED_CONSENT_DIALOG_TEXT, link, &offset); + + label_ = new views::StyledLabel(text, this); + label_->AddLink(ui::Range(offset, offset + link.length())); + + SetLabelBorderAndBounds(); + + AddChildView(label_); +} + +void EchoDialogView::Show(gfx::NativeWindow parent) { + DCHECK(cancel_button_label_id_); + + views::DialogDelegateView::CreateDialogWidget(this, parent, parent); + GetWidget()->SetSize(GetWidget()->GetRootView()->GetPreferredSize()); + GetWidget()->Show(); +} + +int EchoDialogView::GetDefaultDialogButton() const { + return ui::DIALOG_BUTTON_NONE; +} + +int EchoDialogView::GetDialogButtons() const { + int buttons = ui::DIALOG_BUTTON_NONE; + if (ok_button_label_id_) + buttons |= ui::DIALOG_BUTTON_OK; + if (cancel_button_label_id_) + buttons |= ui::DIALOG_BUTTON_CANCEL; + return buttons; +} + +bool EchoDialogView::Accept() { + if (listener_) { + listener_->OnAccept(); + listener_ = NULL; + } + return true; +} + +bool EchoDialogView::Cancel() { + if (listener_) { + listener_->OnCancel(); + listener_ = NULL; + } + return true; +} + +string16 EchoDialogView::GetDialogButtonLabel(ui::DialogButton button) const { + if (button == ui::DIALOG_BUTTON_OK && ok_button_label_id_) + return l10n_util::GetStringUTF16(ok_button_label_id_); + if (button == ui::DIALOG_BUTTON_CANCEL && cancel_button_label_id_) + return l10n_util::GetStringUTF16(cancel_button_label_id_); + return string16(); +} + +ui::ModalType EchoDialogView::GetModalType() const { + return ui::MODAL_TYPE_WINDOW; +} + +bool EchoDialogView::ShouldShowWindowTitle() const { + return false; +} + +bool EchoDialogView::ShouldShowWindowIcon() const { + return false; +} + +void EchoDialogView::StyledLabelLinkClicked(const ui::Range& range, + int event_flags) { + if (!listener_) + return; + listener_->OnMoreInfoLinkClicked(); +} + +gfx::Size EchoDialogView::GetPreferredSize() { + gfx::Size size = + gfx::Size(kDialogLabelPreferredWidth, + label_->GetHeightForWidth(kDialogLabelPreferredWidth)); + gfx::Insets insets = GetInsets(); + size.Enlarge(insets.width(), insets.height()); + return size; +} + +void EchoDialogView::SetLabelBorderAndBounds() { + label_->set_border(views::Border::CreateEmptyBorder( + kDialogLabelTopInset, + kDialogLabelLeftInset, + kDialogLabelBottomInset, + kDialogLabelRightInset)); + + label_->SetBounds(label_->x(), + label_->y(), + kDialogLabelPreferredWidth, + label_->GetHeightForWidth(kDialogLabelPreferredWidth)); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/ui/echo_dialog_view.h b/chrome/browser/chromeos/ui/echo_dialog_view.h new file mode 100644 index 0000000..9dc7aa3 --- /dev/null +++ b/chrome/browser/chromeos/ui/echo_dialog_view.h @@ -0,0 +1,83 @@ +// Copyright 2013 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_CHROMEOS_UI_ECHO_DIALOG_VIEW_H_ +#define CHROME_BROWSER_CHROMEOS_UI_ECHO_DIALOG_VIEW_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/views/controls/styled_label_listener.h" +#include "ui/views/window/dialog_delegate.h" + +namespace views { +class StyledLabel; +} + +namespace chromeos { + +class EchoDialogListener; + +// Dialog shown by echoPrivate extension API when getUserConsent function is +// called. The API is used by echo extension when an offer from a service is +// being redeemed. The dialog is shown to get an user consent. If the echo +// extension is not allowed by policy to redeem offers, the dialog informs user +// about this. +class EchoDialogView : public views::DialogDelegateView, + public views::StyledLabelListener { + public: + explicit EchoDialogView(EchoDialogListener* listener); + virtual ~EchoDialogView(); + + // Initializes dialog layout that will be showed when echo extension is + // allowed to redeem offers. |service_name| is the name of the service that + // requests user consent to redeem an offer. |origin| is the service's origin + // url. Service name should be underlined in the dialog, and hovering over its + // label should display tooltip containing |origin|. + // The dialog will have both OK and Cancel buttons. + void InitForEnabledEcho(const string16& service_name, const string16& origin); + + // Initializes dialog layout that will be shown when echo extension is not + // allowed to redeem offers. The dialog will be showing a message that the + // offer redeeming is disabled by policy. + // The dialog will have only Cancel button. + void InitForDisabledEcho(); + + // Shows the dialog. + void Show(gfx::NativeWindow parent); + + private: + // views::DialogDelegate overrides. + virtual int GetDialogButtons() const OVERRIDE; + virtual int GetDefaultDialogButton() const OVERRIDE; + virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; + virtual bool Cancel() OVERRIDE; + virtual bool Accept() OVERRIDE; + + // views::WidgetDelegate overrides. + virtual ui::ModalType GetModalType() const OVERRIDE; + virtual bool ShouldShowWindowTitle() const OVERRIDE; + virtual bool ShouldShowWindowIcon() const OVERRIDE; + + // views::LinkListener override. + virtual void StyledLabelLinkClicked(const ui::Range& range, + int event_flags) OVERRIDE; + + // views::View override. + virtual gfx::Size GetPreferredSize() OVERRIDE; + + // Sets the border and bounds for the styled label containing the dialog + // text. + void SetLabelBorderAndBounds(); + + views::StyledLabel* label_; + EchoDialogListener* listener_; + int ok_button_label_id_; + int cancel_button_label_id_; + + DISALLOW_COPY_AND_ASSIGN(EchoDialogView); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_UI_ECHO_DIALOG_VIEW_H_ diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index e42101d..18051431 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -707,6 +707,9 @@ 'browser/chromeos/system_logs/touch_log_source.h', 'browser/chromeos/ui/app_launch_view.cc', 'browser/chromeos/ui/app_launch_view.h', + 'browser/chromeos/ui/echo_dialog_listener.h', + 'browser/chromeos/ui/echo_dialog_view.cc', + 'browser/chromeos/ui/echo_dialog_view.h', 'browser/chromeos/ui/idle_logout_dialog_view.cc', 'browser/chromeos/ui/idle_logout_dialog_view.h', 'browser/chromeos/upgrade_detector_chromeos.cc', diff --git a/ui/views/controls/styled_label_listener.h b/ui/views/controls/styled_label_listener.h index e04c299..390865c 100644 --- a/ui/views/controls/styled_label_listener.h +++ b/ui/views/controls/styled_label_listener.h @@ -5,6 +5,8 @@ #ifndef UI_VIEWS_CONTROLS_STYLED_LABEL_LISTENER_H_ #define UI_VIEWS_CONTROLS_STYLED_LABEL_LISTENER_H_ +#include "ui/views/views_export.h" + namespace ui { class Range; } |