1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// found in the LICENSE file.
4b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H_
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H_
7b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <set>
9b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include <string>
10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
11b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/files/file_path.h"
12b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ppapi/c/pp_instance.h"
13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ppapi/c/pp_resource.h"
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ppapi/c/private/ppb_isolated_file_system_private.h"
15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ppapi/host/resource_host.h"
16b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ppapi/host/resource_message_filter.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
18b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class Profile;
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace content {
22b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class BrowserPpapiHost;
23b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
24b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
25b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace ppapi {
26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace host {
27b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)struct HostMessageContext;
28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace host
29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace ppapi
30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
31b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace chrome {
32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class PepperIsolatedFileSystemMessageFilter
34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    : public ppapi::host::ResourceMessageFilter {
35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public:
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static PepperIsolatedFileSystemMessageFilter* Create(
37b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      PP_Instance instance,
38b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      content::BrowserPpapiHost* host);
39b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
40b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // ppapi::host::ResourceMessageFilter implementation.
41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      const IPC::Message& msg) OVERRIDE;
43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual int32_t OnResourceMessageReceived(
44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      const IPC::Message& msg,
45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      ppapi::host::HostMessageContext* context) OVERRIDE;
46b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
47b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) private:
48a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  PepperIsolatedFileSystemMessageFilter(int render_process_id,
49a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                        const base::FilePath& profile_directory,
50a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                        const GURL& document_url,
51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                        ppapi::host::PpapiHost* ppapi_host_);
52b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ~PepperIsolatedFileSystemMessageFilter();
54b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Profile* GetProfile();
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
57b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Returns filesystem id of isolated filesystem if valid, or empty string
58b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // otherwise.  This must run on the UI thread because ProfileManager only
59b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // allows access on that thread.
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  std::string CreateCrxFileSystem(Profile* profile);
61b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int32_t OnOpenFileSystem(ppapi::host::HostMessageContext* context,
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                           PP_IsolatedFileSystemType_Private type);
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int32_t OpenCrxFileSystem(ppapi::host::HostMessageContext* context);
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int32_t OpenPluginPrivateFileSystem(ppapi::host::HostMessageContext* context);
66b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
67b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  const int render_process_id_;
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Keep a copy from original thread.
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::FilePath profile_directory_;
70b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  const GURL document_url_;
71b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Not owned by this object.
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ppapi::host::PpapiHost* ppapi_host_;
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set of origins that can use CrxFs private APIs from NaCl.
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  std::set<std::string> allowed_crxfs_origins_;
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PepperIsolatedFileSystemMessageFilter);
79b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)};
80b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
81b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace chrome
82b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif  // CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H_
84