| 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_ = UNBLOCKING; | |
| 26 } | |
| 27 | |
| 28 UpdateMediaBlockedState(); | |
| 29 } | |
| 30 | |
| 31 void CastMediaBlocker::UpdateMediaBlockedState() { | |
| 32 if (!web_contents()) { | |
| 33 return; | |
| 34 } | |
| 35 | |
| 36 if (!controllable_) { | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 if (state_ == BLOCKED && !suspended_) { | |
| 41 web_contents()->SuspendMediaSession(); | |
| 42 } else if (state_ == UNBLOCKING && suspended_) { | |
| 43 web_contents()->ResumeMediaSession(); | |
| 44 state_ = UNBLOCKED; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 void CastMediaBlocker::MediaSessionStateChanged( | |
| 49 bool is_controllable, | |
| 50 bool is_suspended, | |
| 51 const base::Optional<content::MediaMetadata>& metadata) { | |
| 52 controllable_ = is_controllable; | |
| 53 suspended_ = is_suspended; | |
| 54 UpdateMediaBlockedState(); | |
| 55 } | |
| 56 | |
| 57 } // namespace shell | |
| 58 } // namespace chromecast | |
| OLD | NEW |