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

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: Fix tfarina's comments 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) 2012 The Chromium Authors. All rights reserved.
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/media/media_stream_devices_menu_model.h"
11 #include "chrome/browser/ui/gtk/gtk_util.h"
12 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/gtk/gtk_hig_constants.h"
15 #include "ui/base/gtk/gtk_signal_registrar.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 InfoBar* MediaStreamInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) {
19 DCHECK(owner);
20 return new MediaStreamInfoBarGtk(owner, this);
21 }
22
23 MediaStreamInfoBarGtk::MediaStreamInfoBarGtk(
24 InfoBarTabHelper* owner,
25 MediaStreamInfoBarDelegate* delegate)
26 : InfoBarGtk(owner, delegate),
27 delegate_(delegate) {
28 devices_menu_model_ = new MediaStreamDevicesMenuModel(delegate);
29 Init();
30 }
31
32 MediaStreamInfoBarGtk::~MediaStreamInfoBarGtk() {
33 }
34
35 void MediaStreamInfoBarGtk::Init() {
36 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
37 gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0);
38 size_t offset = 0;
39
40 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO;
41 DCHECK(delegate_->has_audio() || delegate_->has_video());
42 if (!delegate_->has_audio())
43 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
44 else if (!delegate_->has_video())
45 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY;
46
47 string16 security_origin = UTF8ToUTF16(delegate_->GetSecurityOrigin());
48 string16 text(l10n_util::GetStringFUTF16(message_id,
49 security_origin, &offset));
50
51 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(text)),
52 FALSE, FALSE, 0);
53
54 GtkWidget* button = gtk_button_new_with_label(
55 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_ALLOW).c_str());
56 Signals()->Connect(button, "clicked",
57 G_CALLBACK(&OnAllowButtonThunk), this);
58 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
59
60 button = gtk_button_new_with_label(
61 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DENY).c_str());
62 Signals()->Connect(button, "clicked",
63 G_CALLBACK(&OnDenyButtonThunk), this);
64 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
65
66 // The devices button.
67 GtkWidget* devices_menu_button = CreateMenuButton(
68 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DEVICES_MENU_TITLE).c_str());
69 Signals()->Connect(devices_menu_button, "clicked",
70 G_CALLBACK(&OnDevicesClickedThunk), this);
71 gtk_widget_show_all(devices_menu_button);
72 gtk_util::CenterWidgetInHBox(hbox_, devices_menu_button, true, 0);
73 }
74
75 void MediaStreamInfoBarGtk::OnDevicesClicked(GtkWidget* sender) {
76 ShowMenuWithModel(sender, NULL, devices_menu_model_);
77 }
78
79 void MediaStreamInfoBarGtk::OnAllowButton(GtkWidget* widget) {
80 std::string audio_id, video_id;
81 devices_menu_model_->GetSelectedDeviceId(
82 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id);
83 devices_menu_model_->GetSelectedDeviceId(
84 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id);
85 delegate_->Accept(audio_id, video_id);
86 RemoveSelf();
87 }
88
89 void MediaStreamInfoBarGtk::OnDenyButton(GtkWidget* widget) {
90 delegate_->Deny();
91 RemoveSelf();
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698