| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/file_system/file_system_dispatcher_host.h" | 5 #include "chrome/browser/file_system/file_system_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/thread.h" | 7 #include "base/thread.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/browser/file_system/file_system_host_context.h" |
| 11 #include "chrome/browser/host_content_settings_map.h" | 12 #include "chrome/browser/host_content_settings_map.h" |
| 12 #include "chrome/browser/renderer_host/browser_render_process_host.h" | 13 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
| 13 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/common/render_messages_params.h" | 15 #include "chrome/common/render_messages_params.h" |
| 15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebFileError.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebFileError.h" |
| 18 #include "webkit/glue/webkit_glue.h" |
| 17 | 19 |
| 18 FileSystemDispatcherHost::FileSystemDispatcherHost( | 20 FileSystemDispatcherHost::FileSystemDispatcherHost( |
| 19 IPC::Message::Sender* sender, | 21 IPC::Message::Sender* sender, |
| 22 FileSystemHostContext* file_system_host_context, |
| 20 HostContentSettingsMap* host_content_settings_map) | 23 HostContentSettingsMap* host_content_settings_map) |
| 21 : message_sender_(sender), | 24 : message_sender_(sender), |
| 22 process_handle_(0), | 25 process_handle_(0), |
| 23 shutdown_(false), | 26 shutdown_(false), |
| 27 context_(file_system_host_context), |
| 24 host_content_settings_map_(host_content_settings_map) { | 28 host_content_settings_map_(host_content_settings_map) { |
| 25 DCHECK(message_sender_); | 29 DCHECK(message_sender_); |
| 26 } | 30 } |
| 27 | 31 |
| 28 void FileSystemDispatcherHost::Init(base::ProcessHandle process_handle) { | 32 void FileSystemDispatcherHost::Init(base::ProcessHandle process_handle) { |
| 29 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 33 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 30 DCHECK(!shutdown_); | 34 DCHECK(!shutdown_); |
| 31 DCHECK(!process_handle_); | 35 DCHECK(!process_handle_); |
| 32 DCHECK(process_handle); | 36 DCHECK(process_handle); |
| 33 process_handle_ = process_handle; | 37 process_handle_ = process_handle; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) | 51 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) |
| 48 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) | 52 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) |
| 49 // TODO(kinuko): add more. | 53 // TODO(kinuko): add more. |
| 50 IPC_MESSAGE_UNHANDLED(handled = false) | 54 IPC_MESSAGE_UNHANDLED(handled = false) |
| 51 IPC_END_MESSAGE_MAP_EX() | 55 IPC_END_MESSAGE_MAP_EX() |
| 52 return handled; | 56 return handled; |
| 53 } | 57 } |
| 54 | 58 |
| 55 void FileSystemDispatcherHost::OnOpenFileSystem( | 59 void FileSystemDispatcherHost::OnOpenFileSystem( |
| 56 const ViewHostMsg_OpenFileSystemRequest_Params& params) { | 60 const ViewHostMsg_OpenFileSystemRequest_Params& params) { |
| 57 string16 name; | |
| 58 string16 root_path; | |
| 59 | 61 |
| 60 // TODO(kinuko): not implemented yet. | 62 // TODO(kinuko): hook up ContentSettings cookies type checks. |
| 63 |
| 64 FilePath root_path; |
| 65 std::string name; |
| 66 |
| 67 if (!context_->GetFileSystemRootPath(params.origin_url, |
| 68 params.type, |
| 69 &root_path, |
| 70 &name)) { |
| 71 Send(new ViewMsg_OpenFileSystemRequest_Complete( |
| 72 params.routing_id, |
| 73 params.request_id, |
| 74 false, |
| 75 string16(), |
| 76 string16())); |
| 77 return; |
| 78 } |
| 79 |
| 80 // TODO(kinuko): creates the root directory and if it succeeds. |
| 61 | 81 |
| 62 Send(new ViewMsg_OpenFileSystemRequest_Complete( | 82 Send(new ViewMsg_OpenFileSystemRequest_Complete( |
| 63 params.routing_id, | 83 params.routing_id, |
| 64 params.request_id, | 84 params.request_id, |
| 65 false, | 85 true, |
| 66 name, root_path)); | 86 UTF8ToUTF16(name), |
| 87 webkit_glue::FilePathToWebString(root_path))); |
| 67 } | 88 } |
| 68 | 89 |
| 69 void FileSystemDispatcherHost::OnMove( | 90 void FileSystemDispatcherHost::OnMove( |
| 70 int request_id, const string16& src_path, const string16& dest_path) { | 91 int request_id, const string16& src_path, const string16& dest_path) { |
| 92 if (!context_->CheckValidFileSystemPath( |
| 93 webkit_glue::WebStringToFilePath(src_path)) || |
| 94 !context_->CheckValidFileSystemPath( |
| 95 webkit_glue::WebStringToFilePath(dest_path))) { |
| 96 Send(new ViewMsg_FileSystem_Failed( |
| 97 request_id, WebKit::WebFileErrorSecurity)); |
| 98 return; |
| 99 } |
| 100 |
| 71 // TODO(kinuko): not implemented yet. | 101 // TODO(kinuko): not implemented yet. |
| 72 | 102 |
| 73 Send(new ViewMsg_FileSystem_Failed( | 103 Send(new ViewMsg_FileSystem_Failed( |
| 74 request_id, WebKit::WebFileErrorAbort)); | 104 request_id, WebKit::WebFileErrorAbort)); |
| 75 } | 105 } |
| 76 | 106 |
| 77 void FileSystemDispatcherHost::Send(IPC::Message* message) { | 107 void FileSystemDispatcherHost::Send(IPC::Message* message) { |
| 78 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 108 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 79 if (!ChromeThread::PostTask( | 109 if (!ChromeThread::PostTask( |
| 80 ChromeThread::IO, FROM_HERE, | 110 ChromeThread::IO, FROM_HERE, |
| 81 NewRunnableMethod(this, | 111 NewRunnableMethod(this, |
| 82 &FileSystemDispatcherHost::Send, | 112 &FileSystemDispatcherHost::Send, |
| 83 message))) | 113 message))) |
| 84 delete message; | 114 delete message; |
| 85 return; | 115 return; |
| 86 } | 116 } |
| 87 | 117 |
| 88 if (!shutdown_ && message_sender_) | 118 if (!shutdown_ && message_sender_) |
| 89 message_sender_->Send(message); | 119 message_sender_->Send(message); |
| 90 else | 120 else |
| 91 delete message; | 121 delete message; |
| 92 } | 122 } |
| OLD | NEW |