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

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

Issue 10209022: Refactor media stream infobar delegate code and also fix a typo (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h" 5 #include "chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/media/media_stream_devices_menu_model.h" 10 #include "chrome/browser/media/media_stream_devices_menu_model.h"
11 #include "chrome/browser/ui/gtk/gtk_util.h" 11 #include "chrome/browser/ui/gtk/gtk_util.h"
12 #include "chrome/browser/ui/media_stream_infobar_delegate.h" 12 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "ui/base/gtk/gtk_hig_constants.h" 14 #include "ui/base/gtk/gtk_hig_constants.h"
15 #include "ui/base/gtk/gtk_signal_registrar.h" 15 #include "ui/base/gtk/gtk_signal_registrar.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 InfoBar* MediaStreamInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { 18 InfoBar* MediaStreamInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) {
19 DCHECK(owner); 19 DCHECK(owner);
20 return new MediaStreamInfoBarGtk(owner, this); 20 return new MediaStreamInfoBarGtk(owner, this);
21 } 21 }
22 22
23 MediaStreamInfoBarGtk::MediaStreamInfoBarGtk( 23 MediaStreamInfoBarGtk::MediaStreamInfoBarGtk(
24 InfoBarTabHelper* owner, 24 InfoBarTabHelper* owner,
25 MediaStreamInfoBarDelegate* delegate) 25 MediaStreamInfoBarDelegate* delegate)
26 : InfoBarGtk(owner, delegate), 26 : InfoBarGtk(owner, delegate) {
27 delegate_(delegate) {
28 devices_menu_model_ = new MediaStreamDevicesMenuModel(delegate); 27 devices_menu_model_ = new MediaStreamDevicesMenuModel(delegate);
29 Init(); 28 Init();
30 } 29 }
31 30
32 MediaStreamInfoBarGtk::~MediaStreamInfoBarGtk() { 31 MediaStreamInfoBarGtk::~MediaStreamInfoBarGtk() {
33 } 32 }
34 33
35 void MediaStreamInfoBarGtk::Init() { 34 void MediaStreamInfoBarGtk::Init() {
36 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); 35 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
37 gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0); 36 gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0);
38 size_t offset = 0; 37 size_t offset = 0;
39 38
40 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO; 39 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO;
41 DCHECK(delegate_->has_audio() || delegate_->has_video()); 40 DCHECK(GetDelegate()->has_audio() || GetDelegate()->has_video());
42 if (!delegate_->has_audio()) 41 if (!GetDelegate()->has_audio())
43 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; 42 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
44 else if (!delegate_->has_video()) 43 else if (!GetDelegate()->has_video())
45 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY; 44 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY;
46 45
47 string16 security_origin = UTF8ToUTF16(delegate_->GetSecurityOrigin()); 46 string16 security_origin = UTF8ToUTF16(GetDelegate()->GetSecurityOrigin());
48 string16 text(l10n_util::GetStringFUTF16(message_id, 47 string16 text(l10n_util::GetStringFUTF16(message_id,
49 security_origin, &offset)); 48 security_origin, &offset));
50 49
51 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(text)), 50 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(text)),
52 FALSE, FALSE, 0); 51 FALSE, FALSE, 0);
53 52
54 GtkWidget* button = gtk_button_new_with_label( 53 GtkWidget* button = gtk_button_new_with_label(
55 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_ALLOW).c_str()); 54 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_ALLOW).c_str());
56 Signals()->Connect(button, "clicked", 55 Signals()->Connect(button, "clicked",
57 G_CALLBACK(&OnAllowButtonThunk), this); 56 G_CALLBACK(&OnAllowButtonThunk), this);
(...skipping 17 matching lines...) Expand all
75 void MediaStreamInfoBarGtk::OnDevicesClicked(GtkWidget* sender) { 74 void MediaStreamInfoBarGtk::OnDevicesClicked(GtkWidget* sender) {
76 ShowMenuWithModel(sender, NULL, devices_menu_model_); 75 ShowMenuWithModel(sender, NULL, devices_menu_model_);
77 } 76 }
78 77
79 void MediaStreamInfoBarGtk::OnAllowButton(GtkWidget* widget) { 78 void MediaStreamInfoBarGtk::OnAllowButton(GtkWidget* widget) {
80 std::string audio_id, video_id; 79 std::string audio_id, video_id;
81 devices_menu_model_->GetSelectedDeviceId( 80 devices_menu_model_->GetSelectedDeviceId(
82 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id); 81 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id);
83 devices_menu_model_->GetSelectedDeviceId( 82 devices_menu_model_->GetSelectedDeviceId(
84 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id); 83 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id);
85 delegate_->Accept(audio_id, video_id); 84 GetDelegate()->Accept(audio_id, video_id);
86 RemoveSelf(); 85 RemoveSelf();
87 } 86 }
88 87
89 void MediaStreamInfoBarGtk::OnDenyButton(GtkWidget* widget) { 88 void MediaStreamInfoBarGtk::OnDenyButton(GtkWidget* widget) {
90 delegate_->Deny(); 89 GetDelegate()->Deny();
91 RemoveSelf(); 90 RemoveSelf();
92 } 91 }
92
93 MediaStreamInfoBarDelegate* MediaStreamInfoBarGtk::GetDelegate() {
94 return delegate()->AsMediaStreamInfoBarDelegate();
95 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h ('k') | chrome/browser/ui/media_stream_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698