summaryrefslogtreecommitdiffstats
path: root/content/browser/media/android/media_resource_getter_impl.h
blob: 9a55fcb7c2c5f7b3389b8d75965d29d70a45cf83 (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
// Copyright 2013 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.

#ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_
#define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_

#include <jni.h>
#include <string>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "media/base/android/media_resource_getter.h"
#include "media/base/android/media_url_interceptor.h"
#include "net/base/auth.h"
#include "net/cookies/canonical_cookie.h"

namespace storage {
class FileSystemContext;
}

namespace net {
class URLRequestContextGetter;
}

namespace content {

class BrowserContext;
class ResourceContext;

// This class implements media::MediaResourceGetter to retrieve resources
// asynchronously on the UI thread.
class MediaResourceGetterImpl : public media::MediaResourceGetter {
 public:
  // Construct a MediaResourceGetterImpl object. |browser_context| and
  // |render_process_id| are passed to retrieve the CookieStore.
  // |file_system_context| are used to get the platform path.
  MediaResourceGetterImpl(BrowserContext* browser_context,
                          storage::FileSystemContext* file_system_context,
                          int render_process_id,
                          int render_frame_id);
  ~MediaResourceGetterImpl() override;

  // media::MediaResourceGetter implementation.
  // Must be called on the UI thread.
  void GetAuthCredentials(const GURL& url,
                          const GetAuthCredentialsCB& callback) override;
  void GetCookies(const GURL& url,
                  const GURL& first_party_for_cookies,
                  const GetCookieCB& callback) override;
  void GetPlatformPathFromURL(const GURL& url,
                              const GetPlatformPathCB& callback) override;
  void ExtractMediaMetadata(const std::string& url,
                            const std::string& cookies,
                            const std::string& user_agent,
                            const ExtractMediaMetadataCB& callback) override;
  void ExtractMediaMetadata(const int fd,
                            const int64 offset,
                            const int64 size,
                            const ExtractMediaMetadataCB& callback) override;

  static bool RegisterMediaResourceGetter(JNIEnv* env);

 private:
  // Called when GetAuthCredentials() finishes.
  void GetAuthCredentialsCallback(
      const GetAuthCredentialsCB& callback,
      const net::AuthCredentials& credentials);

  // Called when GetCookies() finishes.
  void GetCookiesCallback(
      const GetCookieCB& callback, const std::string& cookies);

  // Called when GetPlatformPathFromFileSystemURL() finishes.
  void GetPlatformPathCallback(
      const GetPlatformPathCB& callback, const std::string& platform_path);

  // BrowserContext to retrieve URLRequestContext and ResourceContext.
  BrowserContext* browser_context_;

  // FileSystemContext to be used on FILE thread.
  storage::FileSystemContext* file_system_context_;

  // Render process id, used to check whether the process can access cookies.
  int render_process_id_;

  // Render frame id, used to check tab specific cookie policy.
  int render_frame_id_;

  // NOTE: Weak pointers must be invalidated before all other member variables.
  base::WeakPtrFactory<MediaResourceGetterImpl> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(MediaResourceGetterImpl);
};

}  // namespace content

#endif  // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_