Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.cc

Issue 9570012: Implement Linux Media Stream Infobar (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
macourteau 2012/03/01 14:06:23 2011 -> 2012
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h"
6
7 #include <string>
8
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
11 #include "chrome/browser/ui/gtk/gtk_util.h"
macourteau 2012/03/01 14:06:23 Includes should be in alphabetical order.
12 #include "grit/generated_resources.h"
13 #include "ui/base/gtk/gtk_hig_constants.h"
14 #include "ui/base/gtk/gtk_signal_registrar.h"
15 #include "ui/base/l10n/l10n_util.h"
16
17 MediaStreamInfoBarGtk::MediaStreamInfoBarGtk(
18 InfoBarTabHelper* owner,
19 MediaStreamInfoBarDelegate* delegate)
20 : InfoBarGtk(owner, delegate),
21 delegate_(delegate) {
22 devices_menu_model_ = new MediaStreamDevicesMenuModel(delegate_);
23 Init();
24 }
25
26 MediaStreamInfoBarGtk::~MediaStreamInfoBarGtk() {
27 }
28
29 void MediaStreamInfoBarGtk::Init() {
30 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
31 gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0);
32 size_t offset = 0;
33
34 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO;
35 if (!delegate_->has_audio()) {
36 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
37 } else if (!delegate_->has_video()) {
38 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY;
39 }
40 string16 security_origin = UTF8ToUTF16(delegate_->GetSecurityOrigin());
41 string16 text(l10n_util::GetStringFUTF16(message_id,
42 security_origin, &offset));
43
44 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(text)),
45 FALSE, FALSE, 0);
46
47 GtkWidget* button = gtk_button_new_with_label(
48 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_ALLOW).c_str());
49 Signals()->Connect(button, "clicked",
50 G_CALLBACK(&OnAllowButtonThunk), this);
51 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
52
53 button = gtk_button_new_with_label(
54 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DENY).c_str());
55 Signals()->Connect(button, "clicked",
56 G_CALLBACK(&OnDenyButtonThunk), this);
57 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
58
59 // The devices button
60 GtkWidget* devices_menu_button = BuildDevicesMenuButton();
61 Signals()->Connect(devices_menu_button, "clicked",
62 G_CALLBACK(&OnDevicesClickedThunk), this);
63 gtk_widget_show_all(devices_menu_button);
64 gtk_util::CenterWidgetInHBox(hbox_, devices_menu_button, true, 0);
65 }
66
67 // static
68 GtkWidget* MediaStreamInfoBarGtk::BuildDevicesMenuButton() {
69 GtkWidget* button = gtk_button_new();
70 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button));
71 if (former_child)
72 gtk_container_remove(GTK_CONTAINER(button), former_child);
73
74 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
75
76 GtkWidget* label = gtk_label_new(
77 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DEVICES_MENU_TITLE).c_str());
78 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
79
80 GtkWidget* arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE);
81 gtk_box_pack_start(GTK_BOX(hbox), arrow, FALSE, FALSE, 0);
82
83 gtk_container_add(GTK_CONTAINER(button), hbox);
84
85 return button;
86 }
87
88 void MediaStreamInfoBarGtk::OnDevicesClicked(GtkWidget* sender) {
89 ShowMenuWithModel(sender, NULL, devices_menu_model_);
90 }
91
92 void MediaStreamInfoBarGtk::OnAllowButton(GtkWidget* widget) {
93 std::string audio_id, video_id;
94 devices_menu_model_->GetSelectedDeviceId(
95 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id);
96 devices_menu_model_->GetSelectedDeviceId(
97 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id);
98 delegate_->Accept(audio_id, video_id);
99 RemoveSelf();
100 }
101
102 void MediaStreamInfoBarGtk::OnDenyButton(GtkWidget* widget) {
103 delegate_->Deny();
104 RemoveSelf();
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698