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 #ifndef CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ | |
6 #define CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "content/public/browser/web_contents_observer.h" | |
10 | |
11 namespace content { | |
12 class WebContents; | |
13 } // namespace content | |
14 | |
15 namespace chromecast { | |
16 namespace shell { | |
17 | |
18 // This class implements a blocking mode for web applications and is used in | |
19 // Chromecast internal code. | |
20 class CastMediaBlocker : public content::WebContentsObserver { | |
21 public: | |
22 explicit CastMediaBlocker(content::WebContents* web_contents); | |
23 ~CastMediaBlocker() override; | |
24 | |
25 // Sets if the web contents is allowed to play media or not. If media is | |
26 // unblocked, previously suspended elements should begin playing again. | |
27 void BlockMediaLoading(bool blocked); | |
28 | |
29 protected: | |
30 bool media_loading_blocked() const { return state_ == BLOCKED; } | |
31 | |
32 // Blocks or unblocks the render process from loading new media | |
33 // according to |media_loading_blocked_|. | |
34 virtual void UpdateMediaBlockedState(); | |
35 | |
36 private: | |
37 enum BlockState { | |
38 BLOCKED, // All media playback should be blocked. | |
39 UNBLOCKING, // Media playback should be resumed at next oppurtunity. | |
40 UNBLOCKED, // Media playback should not be blocked. | |
41 }; | |
42 | |
43 // content::WebContentsObserver implementation: | |
44 void MediaSessionStateChanged( | |
45 bool is_controllable, | |
46 bool is_suspended, | |
47 const base::Optional<content::MediaMetadata>& metadata) override; | |
48 | |
49 // Whether or not media in the app can be controlled and if media is currently | |
50 // suspended. These variables cache arguments from MediaSessionStateChanged(). | |
51 bool controllable_; | |
52 bool suspended_; | |
53 | |
54 BlockState state_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(CastMediaBlocker); | |
57 }; | |
58 | |
59 } // namespace shell | |
60 } // namespace chromecast | |
61 | |
62 #endif // CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ | |
OLD | NEW |