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

Side by Side Diff: chrome/browser/ui/views/infobars/media_stream_infobar.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
« no previous file with comments | « chrome/browser/ui/views/infobars/media_stream_infobar.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/infobars/infobar_tab_helper.h" 9 #include "chrome/browser/infobars/infobar_tab_helper.h"
10 #include "chrome/browser/ui/media_stream_infobar_delegate.h" 10 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
11 #include "chrome/browser/ui/views/infobars/media_stream_infobar.h" 11 #include "chrome/browser/ui/views/infobars/media_stream_infobar.h"
12 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/views/controls/button/menu_button.h" 14 #include "ui/views/controls/button/menu_button.h"
15 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
16 16
17 InfoBar* MediaStreamInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { 17 InfoBar* MediaStreamInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) {
18 DCHECK(owner); 18 DCHECK(owner);
19 return new MediaStreamInfoBar(owner, this); 19 return new MediaStreamInfoBar(owner, this);
20 } 20 }
21 21
22 MediaStreamInfoBar::MediaStreamInfoBar( 22 MediaStreamInfoBar::MediaStreamInfoBar(
23 InfoBarTabHelper* owner, 23 InfoBarTabHelper* owner,
24 MediaStreamInfoBarDelegate* delegate) 24 MediaStreamInfoBarDelegate* delegate)
25 : InfoBarView(owner, delegate), 25 : InfoBarView(owner, delegate),
26 delegate_(delegate),
27 label_(NULL), 26 label_(NULL),
28 allow_button_(NULL), 27 allow_button_(NULL),
29 deny_button_(NULL), 28 deny_button_(NULL),
30 devices_menu_button_(NULL), 29 devices_menu_button_(NULL),
31 devices_menu_model_(delegate) { 30 devices_menu_model_(delegate) {
32 } 31 }
33 32
34 MediaStreamInfoBar::~MediaStreamInfoBar() { 33 MediaStreamInfoBar::~MediaStreamInfoBar() {
35 } 34 }
36 35
(...skipping 20 matching lines...) Expand all
57 gfx::Size devices_size = devices_menu_button_->GetPreferredSize(); 56 gfx::Size devices_size = devices_menu_button_->GetPreferredSize();
58 devices_menu_button_->SetBounds(EndX() - devices_size.width(), 57 devices_menu_button_->SetBounds(EndX() - devices_size.width(),
59 OffsetY(devices_size), devices_size.width(), devices_size.height()); 58 OffsetY(devices_size), devices_size.width(), devices_size.height());
60 } 59 }
61 60
62 void MediaStreamInfoBar::ViewHierarchyChanged(bool is_add, 61 void MediaStreamInfoBar::ViewHierarchyChanged(bool is_add,
63 views::View* parent, 62 views::View* parent,
64 views::View* child) { 63 views::View* child) {
65 if (is_add && child == this && (label_ == NULL)) { 64 if (is_add && child == this && (label_ == NULL)) {
66 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO; 65 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO;
67 DCHECK(delegate_->has_audio() || delegate_->has_video()); 66 DCHECK(GetDelegate()->has_audio() || GetDelegate()->has_video());
68 if (!delegate_->has_audio()) 67 if (!GetDelegate()->has_audio())
69 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; 68 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
70 else if (!delegate_->has_video()) 69 else if (!GetDelegate()->has_video())
71 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY; 70 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY;
72 71
73 label_ = CreateLabel(l10n_util::GetStringFUTF16(message_id, 72 label_ = CreateLabel(l10n_util::GetStringFUTF16(message_id,
74 UTF8ToUTF16(delegate_->GetSecurityOrigin()))); 73 UTF8ToUTF16(GetDelegate()->GetSecurityOrigin())));
75 AddChildView(label_); 74 AddChildView(label_);
76 75
77 allow_button_ = CreateTextButton(this, 76 allow_button_ = CreateTextButton(this,
78 l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_ALLOW), false); 77 l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_ALLOW), false);
79 AddChildView(allow_button_); 78 AddChildView(allow_button_);
80 79
81 deny_button_ = CreateTextButton(this, 80 deny_button_ = CreateTextButton(this,
82 l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_DENY), false); 81 l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_DENY), false);
83 AddChildView(deny_button_); 82 AddChildView(deny_button_);
84 83
(...skipping 10 matching lines...) Expand all
95 void MediaStreamInfoBar::ButtonPressed(views::Button* sender, 94 void MediaStreamInfoBar::ButtonPressed(views::Button* sender,
96 const views::Event& event) { 95 const views::Event& event) {
97 if (!owned()) 96 if (!owned())
98 return; // We're closing; don't call anything, it might access the owner. 97 return; // We're closing; don't call anything, it might access the owner.
99 if (sender == allow_button_) { 98 if (sender == allow_button_) {
100 std::string audio_id, video_id; 99 std::string audio_id, video_id;
101 devices_menu_model_.GetSelectedDeviceId( 100 devices_menu_model_.GetSelectedDeviceId(
102 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id); 101 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id);
103 devices_menu_model_.GetSelectedDeviceId( 102 devices_menu_model_.GetSelectedDeviceId(
104 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id); 103 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id);
105 delegate_->Accept(audio_id, video_id); 104 GetDelegate()->Accept(audio_id, video_id);
106 RemoveSelf(); 105 RemoveSelf();
107 } else if (sender == deny_button_) { 106 } else if (sender == deny_button_) {
108 delegate_->Deny(); 107 GetDelegate()->Deny();
109 RemoveSelf(); 108 RemoveSelf();
110 } else { 109 } else {
111 InfoBarView::ButtonPressed(sender, event); 110 InfoBarView::ButtonPressed(sender, event);
112 } 111 }
113 } 112 }
114 113
115 int MediaStreamInfoBar::ContentMinimumWidth() const { 114 int MediaStreamInfoBar::ContentMinimumWidth() const {
116 return 115 return
117 kEndOfLabelSpacing + 116 kEndOfLabelSpacing +
118 (allow_button_->GetPreferredSize().width() + kButtonButtonSpacing + 117 (allow_button_->GetPreferredSize().width() + kButtonButtonSpacing +
119 deny_button_->GetPreferredSize().width()) + 118 deny_button_->GetPreferredSize().width()) +
120 (kButtonButtonSpacing + devices_menu_button_->GetPreferredSize().width()); 119 (kButtonButtonSpacing + devices_menu_button_->GetPreferredSize().width());
121 } 120 }
122 121
123 void MediaStreamInfoBar::OnMenuButtonClicked(views::View* source, 122 void MediaStreamInfoBar::OnMenuButtonClicked(views::View* source,
124 const gfx::Point& point) { 123 const gfx::Point& point) {
125 if (!owned()) 124 if (!owned())
126 return; // We're closing; don't call anything, it might access the owner. 125 return; // We're closing; don't call anything, it might access the owner.
127 DCHECK_EQ(devices_menu_button_, source); 126 DCHECK_EQ(devices_menu_button_, source);
128 RunMenuAt(&devices_menu_model_, devices_menu_button_, 127 RunMenuAt(&devices_menu_model_, devices_menu_button_,
129 views::MenuItemView::TOPRIGHT); 128 views::MenuItemView::TOPRIGHT);
130 } 129 }
130
131 MediaStreamInfoBarDelegate* MediaStreamInfoBar::GetDelegate() {
132 return delegate()->AsMediaStreamInfoBarDelegate();
133 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/media_stream_infobar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698