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

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

Powered by Google App Engine
This is Rietveld 408576698