Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_file_io_host.h
blob1c5cfcda8e57676162bca478031c289f32b3f5b8
1 // Copyright 2013 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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h"
14 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "ppapi/c/pp_file_info.h"
18 #include "ppapi/c/pp_time.h"
19 #include "ppapi/host/host_message_context.h"
20 #include "ppapi/host/resource_host.h"
21 #include "ppapi/shared_impl/file_io_state_manager.h"
22 #include "url/gurl.h"
23 #include "webkit/browser/fileapi/file_system_context.h"
24 #include "webkit/common/quota/quota_types.h"
26 namespace content {
27 class PepperFileSystemBrowserHost;
29 class PepperFileIOHost : public ppapi::host::ResourceHost,
30 public base::SupportsWeakPtr<PepperFileIOHost> {
31 public:
32 typedef base::Callback<void (base::PlatformFileError)>
33 NotifyCloseFileCallback;
35 PepperFileIOHost(BrowserPpapiHostImpl* host,
36 PP_Instance instance,
37 PP_Resource resource);
38 virtual ~PepperFileIOHost();
40 // ppapi::host::ResourceHost override.
41 virtual int32_t OnResourceMessageReceived(
42 const IPC::Message& msg,
43 ppapi::host::HostMessageContext* context) OVERRIDE;
45 // Direct access for PepperFileSystemBrowserHost.
46 int64_t max_written_offset() const { return max_written_offset_; }
47 void set_max_written_offset(int64_t max_written_offset) {
48 max_written_offset_ = max_written_offset;
51 struct UIThreadStuff {
52 UIThreadStuff();
53 ~UIThreadStuff();
54 base::ProcessId resolved_render_process_id;
55 scoped_refptr<fileapi::FileSystemContext> file_system_context;
57 private:
58 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
59 PP_Resource file_ref_resource,
60 int32_t open_flags);
61 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context,
62 PP_Time last_access_time,
63 PP_Time last_modified_time);
64 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context,
65 int64_t offset,
66 const std::string& buffer);
67 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context,
68 int64_t length);
69 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
70 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context);
71 int32_t OnHostMsgRequestOSFileHandle(
72 ppapi::host::HostMessageContext* context);
74 void GotPluginAllowedToCallRequestOSFileHandle(
75 ppapi::host::ReplyMessageContext reply_context,
76 bool plugin_allowed);
78 // Callback handlers. These mostly convert the PlatformFileError to the
79 // PP_Error code and send back the reply. Note that the argument
80 // ReplyMessageContext is copied so that we have a closure containing all
81 // necessary information to reply.
82 void ExecutePlatformGeneralCallback(
83 ppapi::host::ReplyMessageContext reply_context,
84 base::PlatformFileError error_code);
85 void ExecutePlatformOpenFileCallback(
86 ppapi::host::ReplyMessageContext reply_context,
87 base::PlatformFileError error_code,
88 base::PassPlatformFile file,
89 bool unused_created);
90 void ExecutePlatformWriteCallback(
91 ppapi::host::ReplyMessageContext reply_context,
92 base::PlatformFileError error_code,
93 int bytes_written);
95 void GotUIThreadStuffForInternalFileSystems(
96 ppapi::host::ReplyMessageContext reply_context,
97 int platform_file_flags,
98 UIThreadStuff ui_thread_stuff);
99 void DidOpenInternalFile(
100 ppapi::host::ReplyMessageContext reply_context,
101 base::PlatformFileError result,
102 base::PlatformFile file,
103 const base::Closure& on_close_callback);
104 void GotResolvedRenderProcessId(
105 ppapi::host::ReplyMessageContext reply_context,
106 base::FilePath path,
107 int platform_file_flags,
108 base::ProcessId resolved_render_process_id);
110 void DidOpenQuotaFile(ppapi::host::ReplyMessageContext reply_context,
111 base::PlatformFile file,
112 int64_t max_written_offset);
113 void GotWriteQuota(ppapi::host::ReplyMessageContext reply_context,
114 int64_t offset,
115 const std::string& buffer,
116 int32_t granted);
117 void GotSetLengthQuota(ppapi::host::ReplyMessageContext reply_context,
118 int64_t length,
119 int32_t granted);
120 bool CallWrite(ppapi::host::ReplyMessageContext reply_context,
121 int64_t offset,
122 const std::string& buffer);
123 bool CallSetLength(ppapi::host::ReplyMessageContext reply_context,
124 int64_t length);
126 void DidCloseFile(base::PlatformFileError error);
128 // Adds file_ to |reply_context| with the specified |open_flags|.
129 bool AddFileToReplyContext(
130 int32_t open_flags,
131 ppapi::host::ReplyMessageContext* reply_context) const;
133 BrowserPpapiHostImpl* browser_ppapi_host_;
135 RenderProcessHost* render_process_host_;
136 int render_process_id_;
137 base::ProcessId resolved_render_process_id_;
139 base::PlatformFile file_;
140 int32_t open_flags_;
142 // The file system type specified in the Open() call. This will be
143 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
144 // indicate that the open command actually succeeded.
145 PP_FileSystemType file_system_type_;
146 base::WeakPtr<PepperFileSystemBrowserHost> file_system_host_;
148 // Used to check if we can pass file handle to plugins.
149 quota::QuotaLimitType quota_policy_;
151 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
152 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
153 fileapi::FileSystemURL file_system_url_;
154 base::Closure on_close_callback_;
155 int64_t max_written_offset_;
156 bool check_quota_;
158 ppapi::FileIOStateManager state_manager_;
160 scoped_refptr<base::MessageLoopProxy> file_message_loop_;
162 base::WeakPtrFactory<PepperFileIOHost> weak_factory_;
164 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost);
167 } // namespace content
169 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_