Chromium Code Reviews| Index: chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.cc |
| diff --git a/chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..37a6a6a7c5b57f6f63742745311b674ee71f59d7 |
| --- /dev/null |
| +++ b/chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
macourteau
2012/03/01 14:06:23
2011 -> 2012
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h" |
| + |
| +#include <string> |
| + |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| +#include "chrome/browser/ui/gtk/gtk_util.h" |
|
macourteau
2012/03/01 14:06:23
Includes should be in alphabetical order.
|
| +#include "grit/generated_resources.h" |
| +#include "ui/base/gtk/gtk_hig_constants.h" |
| +#include "ui/base/gtk/gtk_signal_registrar.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +MediaStreamInfoBarGtk::MediaStreamInfoBarGtk( |
| + InfoBarTabHelper* owner, |
| + MediaStreamInfoBarDelegate* delegate) |
| + : InfoBarGtk(owner, delegate), |
| + delegate_(delegate) { |
| + devices_menu_model_ = new MediaStreamDevicesMenuModel(delegate_); |
| + Init(); |
| +} |
| + |
| +MediaStreamInfoBarGtk::~MediaStreamInfoBarGtk() { |
| +} |
| + |
| +void MediaStreamInfoBarGtk::Init() { |
| + GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| + gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0); |
| + size_t offset = 0; |
| + |
| + int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO; |
| + if (!delegate_->has_audio()) { |
| + message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| + } else if (!delegate_->has_video()) { |
| + message_id = IDS_MEDIA_CAPTURE_MIC_ONLY; |
| + } |
| + string16 security_origin = UTF8ToUTF16(delegate_->GetSecurityOrigin()); |
| + string16 text(l10n_util::GetStringFUTF16(message_id, |
| + security_origin, &offset)); |
| + |
| + gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(text)), |
| + FALSE, FALSE, 0); |
| + |
| + GtkWidget* button = gtk_button_new_with_label( |
| + l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_ALLOW).c_str()); |
| + Signals()->Connect(button, "clicked", |
| + G_CALLBACK(&OnAllowButtonThunk), this); |
| + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| + |
| + button = gtk_button_new_with_label( |
| + l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DENY).c_str()); |
| + Signals()->Connect(button, "clicked", |
| + G_CALLBACK(&OnDenyButtonThunk), this); |
| + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
| + |
| + // The devices button |
| + GtkWidget* devices_menu_button = BuildDevicesMenuButton(); |
| + Signals()->Connect(devices_menu_button, "clicked", |
| + G_CALLBACK(&OnDevicesClickedThunk), this); |
| + gtk_widget_show_all(devices_menu_button); |
| + gtk_util::CenterWidgetInHBox(hbox_, devices_menu_button, true, 0); |
| +} |
| + |
| +// static |
| +GtkWidget* MediaStreamInfoBarGtk::BuildDevicesMenuButton() { |
| + GtkWidget* button = gtk_button_new(); |
| + GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); |
| + if (former_child) |
| + gtk_container_remove(GTK_CONTAINER(button), former_child); |
| + |
| + GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
| + |
| + GtkWidget* label = gtk_label_new( |
| + l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DEVICES_MENU_TITLE).c_str()); |
| + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
| + |
| + GtkWidget* arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); |
| + gtk_box_pack_start(GTK_BOX(hbox), arrow, FALSE, FALSE, 0); |
| + |
| + gtk_container_add(GTK_CONTAINER(button), hbox); |
| + |
| + return button; |
| +} |
| + |
| +void MediaStreamInfoBarGtk::OnDevicesClicked(GtkWidget* sender) { |
| + ShowMenuWithModel(sender, NULL, devices_menu_model_); |
| +} |
| + |
| +void MediaStreamInfoBarGtk::OnAllowButton(GtkWidget* widget) { |
| + std::string audio_id, video_id; |
| + devices_menu_model_->GetSelectedDeviceId( |
| + content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id); |
| + devices_menu_model_->GetSelectedDeviceId( |
| + content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id); |
| + delegate_->Accept(audio_id, video_id); |
| + RemoveSelf(); |
| +} |
| + |
| +void MediaStreamInfoBarGtk::OnDenyButton(GtkWidget* widget) { |
| + delegate_->Deny(); |
| + RemoveSelf(); |
| +} |