summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2014-12-29 16:21:47 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-30 00:22:22 +0000
commitb49f5514bdad980a8ed39da8cad0f85809f23d92 (patch)
tree0a76556a8e93e67175940b1b17b2991ce6d1ed2b /components
parentc9c0300cbbcca64114bbf20d0ff03007d84e7086 (diff)
downloadchromium_src-b49f5514bdad980a8ed39da8cad0f85809f23d92.zip
chromium_src-b49f5514bdad980a8ed39da8cad0f85809f23d92.tar.gz
chromium_src-b49f5514bdad980a8ed39da8cad0f85809f23d92.tar.bz2
Componentize SimpleAlertInfoBarDelegate
Move SimpleAlertInfoBarDelegate into //components/infobar/core since it only depends on //base and //components/infobar/core and we want to share the code with iOS. BUG=438238 TBR=bauerb@chromium.org TBR=felt@chromium.org TBR=dtseng@chromium.org Review URL: https://codereview.chromium.org/824033002 Cr-Commit-Position: refs/heads/master@{#309734}
Diffstat (limited to 'components')
-rw-r--r--components/infobars.gypi2
-rw-r--r--components/infobars/core/BUILD.gn2
-rw-r--r--components/infobars/core/simple_alert_infobar_delegate.cc50
-rw-r--r--components/infobars/core/simple_alert_infobar_delegate.h45
4 files changed, 99 insertions, 0 deletions
diff --git a/components/infobars.gypi b/components/infobars.gypi
index e2066e1..449082c 100644
--- a/components/infobars.gypi
+++ b/components/infobars.gypi
@@ -35,6 +35,8 @@
'infobars/core/infobar_manager.h',
'infobars/core/infobars_switches.cc',
'infobars/core/infobars_switches.h',
+ 'infobars/core/simple_alert_infobar_delegate.cc',
+ 'infobars/core/simple_alert_infobar_delegate.h',
],
},
],
diff --git a/components/infobars/core/BUILD.gn b/components/infobars/core/BUILD.gn
index 2959e0d..79e658f 100644
--- a/components/infobars/core/BUILD.gn
+++ b/components/infobars/core/BUILD.gn
@@ -16,6 +16,8 @@ static_library("core") {
"infobar_manager.h",
"infobars_switches.cc",
"infobars_switches.h",
+ "simple_alert_infobar_delegate.cc",
+ "simple_alert_infobar_delegate.h",
]
public_deps = [
diff --git a/components/infobars/core/simple_alert_infobar_delegate.cc b/components/infobars/core/simple_alert_infobar_delegate.cc
new file mode 100644
index 0000000..9262d05
--- /dev/null
+++ b/components/infobars/core/simple_alert_infobar_delegate.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2012 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 "components/infobars/core/simple_alert_infobar_delegate.h"
+
+#include "components/infobars/core/infobar.h"
+#include "components/infobars/core/infobar_manager.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+// static
+void SimpleAlertInfoBarDelegate::Create(
+ infobars::InfoBarManager* infobar_manager,
+ int icon_id,
+ const base::string16& message,
+ bool auto_expire) {
+ infobar_manager->AddInfoBar(
+ infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
+ new SimpleAlertInfoBarDelegate(icon_id, message, auto_expire))));
+}
+
+SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate(
+ int icon_id,
+ const base::string16& message,
+ bool auto_expire)
+ : ConfirmInfoBarDelegate(),
+ icon_id_(icon_id),
+ message_(message),
+ auto_expire_(auto_expire) {
+}
+
+SimpleAlertInfoBarDelegate::~SimpleAlertInfoBarDelegate() {
+}
+
+int SimpleAlertInfoBarDelegate::GetIconID() const {
+ return icon_id_;
+}
+
+base::string16 SimpleAlertInfoBarDelegate::GetMessageText() const {
+ return message_;
+}
+
+int SimpleAlertInfoBarDelegate::GetButtons() const {
+ return BUTTON_NONE;
+}
+
+bool SimpleAlertInfoBarDelegate::ShouldExpireInternal(
+ const NavigationDetails& details) const {
+ return auto_expire_ && ConfirmInfoBarDelegate::ShouldExpireInternal(details);
+}
diff --git a/components/infobars/core/simple_alert_infobar_delegate.h b/components/infobars/core/simple_alert_infobar_delegate.h
new file mode 100644
index 0000000..4ec42d6
--- /dev/null
+++ b/components/infobars/core/simple_alert_infobar_delegate.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 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 COMPONENTS_INFOBARS_CORE_SIMPLE_ALERT_INFOBAR_DELEGATE_H_
+#define COMPONENTS_INFOBARS_CORE_SIMPLE_ALERT_INFOBAR_DELEGATE_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/strings/string16.h"
+#include "components/infobars/core/confirm_infobar_delegate.h"
+
+namespace infobars {
+class InfoBarManager;
+}
+
+class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ // Creates a simple alert infobar and delegate and adds the infobar to
+ // |infobar_manager|. |icon_id| may be kNoIconID if no icon is shown.
+ static void Create(infobars::InfoBarManager* infobar_manager,
+ int icon_id,
+ const base::string16& message,
+ bool auto_expire);
+
+ private:
+ SimpleAlertInfoBarDelegate(int icon_id,
+ const base::string16& message,
+ bool auto_expire);
+ ~SimpleAlertInfoBarDelegate() override;
+
+ // ConfirmInfoBarDelegate:
+ int GetIconID() const override;
+ base::string16 GetMessageText() const override;
+ int GetButtons() const override;
+ bool ShouldExpireInternal(const NavigationDetails& details) const override;
+
+ const int icon_id_;
+ base::string16 message_;
+ bool auto_expire_; // Should it expire automatically on navigation?
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate);
+};
+
+#endif // COMPONENTS_INFOBARS_CORE_SIMPLE_ALERT_INFOBAR_DELEGATE_H_