OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "chromecast/browser/cast_media_blocker.h" |
| 6 |
| 7 #include "base/threading/thread_checker.h" |
| 8 #include "content/public/browser/web_contents.h" |
| 9 |
| 10 namespace chromecast { |
| 11 namespace shell { |
| 12 |
| 13 CastMediaBlocker::CastMediaBlocker(content::WebContents* web_contents) |
| 14 : content::WebContentsObserver(web_contents), |
| 15 controllable_(false), |
| 16 suspended_(false), |
| 17 state_(UNBLOCKED) {} |
| 18 |
| 19 CastMediaBlocker::~CastMediaBlocker() {} |
| 20 |
| 21 void CastMediaBlocker::BlockMediaLoading(bool blocked) { |
| 22 if (blocked) { |
| 23 state_ = BLOCKED; |
| 24 } else if (state_ == BLOCKED) { |
| 25 state_ = suspended_ ? UNBLOCKING : UNBLOCKED; |
| 26 } else { |
| 27 return; |
| 28 } |
| 29 |
| 30 UpdateMediaBlockedState(); |
| 31 } |
| 32 |
| 33 void CastMediaBlocker::UpdateMediaBlockedState() { |
| 34 if (!web_contents()) { |
| 35 return; |
| 36 } |
| 37 |
| 38 if (!controllable_) { |
| 39 return; |
| 40 } |
| 41 |
| 42 if (state_ == BLOCKED && !suspended_) { |
| 43 web_contents()->SuspendMediaSession(); |
| 44 } else if (state_ == UNBLOCKING && suspended_) { |
| 45 web_contents()->ResumeMediaSession(); |
| 46 state_ = UNBLOCKED; |
| 47 } |
| 48 } |
| 49 |
| 50 void CastMediaBlocker::MediaSessionStateChanged( |
| 51 bool is_controllable, |
| 52 bool is_suspended, |
| 53 const base::Optional<content::MediaMetadata>& metadata) { |
| 54 controllable_ = is_controllable; |
| 55 suspended_ = is_suspended; |
| 56 UpdateMediaBlockedState(); |
| 57 } |
| 58 |
| 59 } // namespace shell |
| 60 } // namespace chromecast |
OLD | NEW |