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

Side by Side Diff: ash/system/cast/tray_cast.cc

Issue 1145833003: Allow the cast tray to function as expected when the installed extension is missing API methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add bug to comment Created 5 years, 7 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 | « ash/cast_config_delegate.h ('k') | chrome/browser/ui/ash/cast_config_delegate_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ash/system/cast/tray_cast.h" 5 #include "ash/system/cast/tray_cast.h"
6 6
7 #include "ash/cast_config_delegate.h" 7 #include "ash/cast_config_delegate.h"
8 #include "ash/session/session_state_delegate.h" 8 #include "ash/session/session_state_delegate.h"
9 #include "ash/shelf/shelf_types.h" 9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 20 matching lines...) Expand all
31 #include "ui/views/controls/button/button.h" 31 #include "ui/views/controls/button/button.h"
32 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
33 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
34 #include "ui/views/layout/box_layout.h" 34 #include "ui/views/layout/box_layout.h"
35 #include "ui/views/layout/fill_layout.h" 35 #include "ui/views/layout/fill_layout.h"
36 36
37 namespace ash { 37 namespace ash {
38 38
39 namespace { 39 namespace {
40 const int kStopButtonRightPadding = 18; 40 const int kStopButtonRightPadding = 18;
41
42 // Callback helper for StopCast().
43 void StopCastCallback(
44 CastConfigDelegate* cast_config,
45 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) {
46 for (auto& item : receivers_activities) {
47 CastConfigDelegate::Activity activity = item.second.activity;
48 if (activity.allow_stop && activity.id.empty() == false)
49 cast_config->StopCasting(activity.id);
50 }
51 }
52
53 // Stops currently casting device.
54 void StopCast() {
55 CastConfigDelegate* cast_config =
56 Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate();
57 if (cast_config && cast_config->HasCastExtension()) {
58 cast_config->GetReceiversAndActivities(
59 base::Bind(&StopCastCallback, cast_config));
60 }
61 }
62
63 } // namespace 41 } // namespace
64 42
65 namespace tray { 43 namespace tray {
66 44
67 // This view is displayed in the system tray when the cast extension is active. 45 // This view is displayed in the system tray when the cast extension is active.
68 // It asks the user if they want to cast the desktop. If they click on the 46 // It asks the user if they want to cast the desktop. If they click on the
69 // chevron, then a detail view will replace this view where the user will 47 // chevron, then a detail view will replace this view where the user will
70 // actually pick the cast receiver. 48 // actually pick the cast receiver.
71 class CastSelectDefaultView : public TrayItemMore { 49 class CastSelectDefaultView : public TrayItemMore {
72 public: 50 public:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // The view has two labels, one above the other. The top label (|title_|) 153 // The view has two labels, one above the other. The top label (|title_|)
176 // specifies that we are, say, "Casting desktop". The bottom label 154 // specifies that we are, say, "Casting desktop". The bottom label
177 // (|details_|) specifies where we are casting to, ie, "SomeRandom cast" 155 // (|details_|) specifies where we are casting to, ie, "SomeRandom cast"
178 label_container_ = new views::View; 156 label_container_ = new views::View;
179 label_container_->SetLayoutManager( 157 label_container_->SetLayoutManager(
180 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 158 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
181 159
182 title_ = new views::Label; 160 title_ = new views::Label;
183 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 161 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
184 title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); 162 title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont));
163 title_->SetText(
164 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_UNKNOWN_CAST_TYPE));
185 label_container_->AddChildView(title_); 165 label_container_->AddChildView(title_);
186 166
187 details_ = new views::Label; 167 details_ = new views::Label;
188 details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 168 details_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
189 details_->SetMultiLine(false); 169 details_->SetMultiLine(false);
190 details_->SetEnabledColor(kHeaderTextColorNormal); 170 details_->SetEnabledColor(kHeaderTextColorNormal);
171 details_->SetText(
172 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_UNKNOWN_RECEIVER));
191 label_container_->AddChildView(details_); 173 label_container_->AddChildView(details_);
192 174
193 AddChildView(label_container_); 175 AddChildView(label_container_);
194 176
195 // Add the stop bottom on the far-right. We customize how this stop button is 177 // Add the stop bottom on the far-right. We customize how this stop button is
196 // displayed inside of |Layout()|. 178 // displayed inside of |Layout()|.
197 base::string16 stop_button_text = 179 base::string16 stop_button_text =
198 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 180 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
199 IDS_ASH_STATUS_TRAY_CAST_STOP); 181 IDS_ASH_STATUS_TRAY_CAST_STOP);
200 stop_button_ = new TrayPopupLabelButton(this, stop_button_text); 182 stop_button_ = new TrayPopupLabelButton(this, stop_button_text);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 details_->SetText(receiver.name); 245 details_->SetText(receiver.name);
264 Layout(); 246 Layout();
265 break; 247 break;
266 } 248 }
267 } 249 }
268 } 250 }
269 251
270 void CastCastView::ButtonPressed(views::Button* sender, 252 void CastCastView::ButtonPressed(views::Button* sender,
271 const ui::Event& event) { 253 const ui::Event& event) {
272 DCHECK(sender == stop_button_); 254 DCHECK(sender == stop_button_);
273 StopCast(); 255 cast_config_delegate_->StopCasting();
274 } 256 }
275 257
276 // This view by itself does very little. It acts as a front-end for managing 258 // This view by itself does very little. It acts as a front-end for managing
277 // which of the two child views (|CastSelectDefaultView| and |CastCastView|) 259 // which of the two child views (|CastSelectDefaultView| and |CastCastView|)
278 // is active. 260 // is active.
279 class CastDuplexView : public views::View { 261 class CastDuplexView : public views::View {
280 public: 262 public:
281 CastDuplexView(SystemTrayItem* owner, 263 CastDuplexView(SystemTrayItem* owner,
282 CastConfigDelegate* config_delegate, 264 CastConfigDelegate* config_delegate,
283 bool show_more); 265 bool show_more);
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 is_casting_ = started; 600 is_casting_ = started;
619 UpdatePrimaryView(); 601 UpdatePrimaryView();
620 } 602 }
621 603
622 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 604 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
623 if (tray_) 605 if (tray_)
624 tray_->UpdateAlignment(alignment); 606 tray_->UpdateAlignment(alignment);
625 } 607 }
626 608
627 } // namespace ash 609 } // namespace ash
OLDNEW
« no previous file with comments | « ash/cast_config_delegate.h ('k') | chrome/browser/ui/ash/cast_config_delegate_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698