summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/webmediaplayer_delegate_impl.h
blob: 8da1889e1699da7be794f0ae345200b26fefc633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2008 The Chromium Authors. All rights reserved.  Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
//
// Delegate calls from WebCore::MediaPlayerPrivate to google's video player.
// It is a friend of VideoStackMediaPlayer, which is the actual media player
// VideoStackMediaPlayer will use WebMediaPlayer to create a resource loader
// and bridges the WebCore::ResourceHandle and media::DataSource, so that
// VideoStackMediaPlayer would have no knowledge of WebCore::ResourceHandle.

#ifndef CHROME_RENDERER_WEBMEDIAPLAYER_DELEGATE_IMPL_H_
#define CHROME_RENDERER_WEBMEDIAPLAYER_DELEGATE_IMPL_H_

#include "webkit/glue/webmediaplayer_delegate.h"

namespace media {
class VideoStackMediaPlayer;
}

class WebMediaPlayerDelegateImpl : public webkit_glue::WebMediaPlayerDelegate {
 public:
  WebMediaPlayerDelegateImpl();
  virtual ~WebMediaPlayerDelegateImpl();

  virtual void Initialize(webkit_glue::WebMediaPlayer* media_player);

  virtual void Load(const GURL& url);
  virtual void CancelLoad();

  // Playback controls.
  virtual void Play();
  virtual void Pause();
  virtual void Stop();
  virtual void Seek(float time);
  virtual void SetEndTime(float time);
  virtual void SetPlaybackRate(float rate);
  virtual void SetVolume(float volume);
  virtual void SetVisible(bool visible);
  virtual bool IsTotalBytesKnown();

  // Methods for painting.
  virtual void SetRect(const gfx::Rect& rect);

  virtual void Paint(skia::PlatformCanvas *canvas, const gfx::Rect& rect);

  // True if a video is loaded.
  virtual bool IsVideo() const { return video_; }

  // Dimension of the video.
  virtual size_t GetWidth() const { return width_; }
  virtual size_t GetHeight() const { return height_; }

  // Getters fo playback state.
  virtual bool IsPaused() const { return paused_; }
  virtual bool IsSeeking() const { return seeking_; }
  virtual float GetDuration() const { return duration_; }
  virtual float GetCurrentTime() const { return current_time_; }
  virtual float GetPlayBackRate() const { return playback_rate_; }
  virtual float GetVolume() const { return volume_; }
  virtual float GetMaxTimeBuffered() const;
  virtual float GetMaxTimeSeekable() const;

  // Get rate of loading the resource.
  virtual int32 GetDataRate() const { return data_rate_; }

  // Internal states of loading and network.
  virtual webkit_glue::WebMediaPlayer::NetworkState GetNetworkState() const {
    return network_state_;
  }
  virtual webkit_glue::WebMediaPlayer::ReadyState GetReadyState() const {
    return ready_state_;
  }

  virtual int64 GetBytesLoaded() const { return bytes_loaded_; }
  virtual int64 GetTotalBytes() const { return total_bytes_; }

  // Data handlers.
  virtual void WillSendRequest(WebRequest& request,
               const WebResponse& response);
  virtual void DidReceiveResponse(const WebResponse& response);
  virtual void DidReceiveData(const char* buf, size_t size);
  virtual void DidFinishLoading();
  virtual void DidFail(const WebError& error);

  // Inline getters.
  webkit_glue::WebMediaPlayer* web_media_player() { return web_media_player_; }

 private:
  int64 bytes_loaded_;
  float current_time_;
  int32 data_rate_;
  float duration_;
  size_t height_;
  webkit_glue::WebMediaPlayer::NetworkState network_state_;
  bool paused_;
  float playback_rate_;
  webkit_glue::WebMediaPlayer::ReadyState ready_state_;
  bool seeking_;
  int64 total_bytes_;
  bool video_;
  media::VideoStackMediaPlayer* video_stack_media_player_;
  bool visible_;
  float volume_;
  webkit_glue::WebMediaPlayer* web_media_player_;
  size_t width_;

  DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerDelegateImpl);
};

#endif  // ifndef CHROME_RENDERER_WEBMEDIAPLAYER_DELEGATE_IMPL_H_