summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/pepper/pepper_file_ref_host.h
blob: d850504d1750a360237846ca5ca947a810ba1cca (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
111
112
// 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_RENDERER_HOST_PEPPER_PEPPER_FILE_REF_HOST_H_
#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_REF_HOST_H_

#include <string>

#include "base/memory/weak_ptr.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "ppapi/c/pp_file_info.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_time.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
#include "webkit/browser/fileapi/file_system_url.h"

namespace content {
class PepperFileRefHost;
class PepperFileSystemBrowserHost;

// Internal and external filesystems have very different codepaths for
// performing FileRef operations. The logic is split into separate classes
// to make it easier to read.
class PepperFileRefBackend {
 public:
  virtual ~PepperFileRefBackend();

  virtual int32_t MakeDirectory(ppapi::host::ReplyMessageContext context,
                                int32_t make_directory_flags) = 0;
  virtual int32_t Touch(ppapi::host::ReplyMessageContext context,
                        PP_Time last_accessed_time,
                        PP_Time last_modified_time) = 0;
  virtual int32_t Delete(ppapi::host::ReplyMessageContext context) = 0;
  virtual int32_t Rename(ppapi::host::ReplyMessageContext context,
                         PepperFileRefHost* new_file_ref) = 0;
  virtual int32_t Query(ppapi::host::ReplyMessageContext context) = 0;
  virtual int32_t ReadDirectoryEntries(
      ppapi::host::ReplyMessageContext context) = 0;
  virtual int32_t GetAbsolutePath(ppapi::host::ReplyMessageContext context) = 0;
  virtual fileapi::FileSystemURL GetFileSystemURL() const = 0;
  virtual base::FilePath GetExternalFilePath() const = 0;

  // Returns an error from the pp_errors.h enum.
  virtual int32_t CanRead() const = 0;
  virtual int32_t CanWrite() const = 0;
  virtual int32_t CanCreate() const = 0;
  virtual int32_t CanReadWrite() const = 0;
};

class CONTENT_EXPORT PepperFileRefHost
    : public ppapi::host::ResourceHost,
      public base::SupportsWeakPtr<PepperFileRefHost> {
 public:
  PepperFileRefHost(BrowserPpapiHost* host,
                    PP_Instance instance,
                    PP_Resource resource,
                    PP_Resource file_system,
                    const std::string& internal_path);

  PepperFileRefHost(BrowserPpapiHost* host,
                    PP_Instance instance,
                    PP_Resource resource,
                    const base::FilePath& external_path);

  virtual ~PepperFileRefHost();

  // ResourceHost overrides.
  virtual int32_t OnResourceMessageReceived(
      const IPC::Message& msg,
      ppapi::host::HostMessageContext* context) OVERRIDE;
  virtual bool IsFileRefHost() OVERRIDE;

  // Required to support Rename().
  PP_FileSystemType GetFileSystemType() const;
  fileapi::FileSystemURL GetFileSystemURL() const;

  // Required to support FileIO.
  base::FilePath GetExternalFilePath() const;
  base::WeakPtr<PepperFileSystemBrowserHost> GetFileSystemHost() const;

  int32_t CanRead() const;
  int32_t CanWrite() const;
  int32_t CanCreate() const;
  int32_t CanReadWrite() const;

 private:
  int32_t OnMakeDirectory(ppapi::host::HostMessageContext* context,
                          int32_t make_directory_flags);
  int32_t OnTouch(ppapi::host::HostMessageContext* context,
                  PP_Time last_access_time,
                  PP_Time last_modified_time);
  int32_t OnDelete(ppapi::host::HostMessageContext* context);
  int32_t OnRename(ppapi::host::HostMessageContext* context,
                   PP_Resource new_file_ref);
  int32_t OnQuery(ppapi::host::HostMessageContext* context);
  int32_t OnReadDirectoryEntries(ppapi::host::HostMessageContext* context);
  int32_t OnGetAbsolutePath(ppapi::host::HostMessageContext* context);

  BrowserPpapiHost* host_;
  scoped_ptr<PepperFileRefBackend> backend_;
  base::WeakPtr<PepperFileSystemBrowserHost> file_system_host_;
  PP_FileSystemType fs_type_;

  DISALLOW_COPY_AND_ASSIGN(PepperFileRefHost);
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_REF_HOST_H_