| Index: chrome/browser/wake_lock/wake_lock_infobar_delegate.cc
|
| diff --git a/chrome/browser/wake_lock/wake_lock_infobar_delegate.cc b/chrome/browser/wake_lock/wake_lock_infobar_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b08001d2ed300fb65ff950a76846f91109a13b76
|
| --- /dev/null
|
| +++ b/chrome/browser/wake_lock/wake_lock_infobar_delegate.cc
|
| @@ -0,0 +1,98 @@
|
| +// Copyright (c) 2014 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/wake_lock/wake_lock_infobar_delegate.h"
|
| +
|
| +#include "chrome/browser/infobars/infobar_service.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/tab_contents/tab_util.h"
|
| +#include "chrome/browser/wake_lock/wake_lock_preference.h"
|
| +#include "components/infobars/core/infobar.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "grit/theme_resources.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +
|
| +// static
|
| +infobars::InfoBar* WakeLockInfoBarDelegate::Create(
|
| + InfoBarService* infobar_service,
|
| + int render_process_id,
|
| + int routed_id,
|
| + WakeLockCallback callback) {
|
| + std::string url = infobar_service->web_contents()->GetURL().spec();
|
| +
|
| + WakeLockInfoBarDelegate* const delegate =
|
| + new WakeLockInfoBarDelegate(render_process_id,
|
| + routed_id,
|
| + url,
|
| + callback);
|
| +
|
| + infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar(
|
| + scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release();
|
| + return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar));
|
| +}
|
| +
|
| +WakeLockInfoBarDelegate::WakeLockInfoBarDelegate(
|
| + int render_process_id,
|
| + int routed_id,
|
| + const std::string& url,
|
| + WakeLockCallback callback)
|
| + : ConfirmInfoBarDelegate(),
|
| + user_has_interacted_(false),
|
| + render_process_id_(render_process_id),
|
| + routed_id_(routed_id),
|
| + url_(url),
|
| + callback_(callback) {
|
| +}
|
| +
|
| +WakeLockInfoBarDelegate::~WakeLockInfoBarDelegate() {
|
| + if (!user_has_interacted_)
|
| + SetPermission(false, false);
|
| +}
|
| +
|
| +bool WakeLockInfoBarDelegate::Accept() {
|
| + set_user_has_interacted();
|
| + SetPermission(true, true);
|
| + return true;
|
| +}
|
| +
|
| +bool WakeLockInfoBarDelegate::Cancel() {
|
| + set_user_has_interacted();
|
| + SetPermission(true, false);
|
| + return true;
|
| +}
|
| +
|
| +void WakeLockInfoBarDelegate::InfoBarDismissed() {
|
| + set_user_has_interacted();
|
| + SetPermission(false, false);
|
| +}
|
| +
|
| +int WakeLockInfoBarDelegate::GetIconID() const {
|
| + return IDR_INFOBAR_GEOLOCATION;
|
| +}
|
| +
|
| +infobars::InfoBarDelegate::Type WakeLockInfoBarDelegate::GetInfoBarType()
|
| + const {
|
| + return PAGE_ACTION_TYPE;
|
| +}
|
| +
|
| +base::string16 WakeLockInfoBarDelegate::GetButtonLabel(
|
| + InfoBarButton button) const {
|
| + return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
|
| + IDS_WAKE_LOCK_OK_BUTTON : IDS_WAKE_LOCK_CANCEL_BUTTON);
|
| +}
|
| +
|
| +base::string16 WakeLockInfoBarDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(IDS_WAKE_LOCK_INFOBAR_QUESTION);
|
| +}
|
| +
|
| +void WakeLockInfoBarDelegate::SetPermission(bool update_content_setting,
|
| + bool allowed) {
|
| + if (update_content_setting /*&& remember_value()*/) {
|
| + scoped_ptr<WakeLockPreference> pref =
|
| + WakeLockPreference::createWakeLockPreference(
|
| + render_process_id_, routed_id_);
|
| + pref->setAllowed(url_, allowed);
|
| + }
|
| + callback_.Run(allowed);
|
| +}
|
|
|