diff options
| -rw-r--r-- | chrome/browser/file_system/file_system_dispatcher_host.cc | 81 | ||||
| -rw-r--r-- | chrome/browser/file_system/file_system_dispatcher_host.h | 46 | ||||
| -rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 13 | ||||
| -rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 4 | ||||
| -rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
| -rw-r--r-- | chrome/common/render_messages.h | 50 | ||||
| -rw-r--r-- | chrome/common/render_messages_internal.h | 15 | ||||
| -rw-r--r-- | chrome/common/webkit_param_traits.h | 6 | ||||
| -rw-r--r-- | chrome/renderer/render_view.cc | 53 | ||||
| -rw-r--r-- | chrome/renderer/render_view.h | 16 |
10 files changed, 284 insertions, 2 deletions
diff --git a/chrome/browser/file_system/file_system_dispatcher_host.cc b/chrome/browser/file_system/file_system_dispatcher_host.cc new file mode 100644 index 0000000..496a623 --- /dev/null +++ b/chrome/browser/file_system/file_system_dispatcher_host.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2010 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. + +#include "chrome/browser/file_system/file_system_dispatcher_host.h" + +#include "base/thread.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/host_content_settings_map.h" +#include "chrome/browser/renderer_host/browser_render_process_host.h" +#include "chrome/common/render_messages.h" +#include "googleurl/src/gurl.h" + +FileSystemDispatcherHost::FileSystemDispatcherHost( + IPC::Message::Sender* sender, + HostContentSettingsMap* host_content_settings_map) + : message_sender_(sender), + process_handle_(0), + shutdown_(false), + host_content_settings_map_(host_content_settings_map) { + DCHECK(message_sender_); +} + +void FileSystemDispatcherHost::Init(base::ProcessHandle process_handle) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + DCHECK(!shutdown_); + DCHECK(!process_handle_); + DCHECK(process_handle); + process_handle_ = process_handle; +} + +void FileSystemDispatcherHost::Shutdown() { + message_sender_ = NULL; + shutdown_ = true; +} + +bool FileSystemDispatcherHost::OnMessageReceived( + const IPC::Message& message, bool* message_was_ok) { + DCHECK(!shutdown_); + *message_was_ok = true; + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) + IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) + // TODO(kinuko): add more. + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP_EX() + return handled; +} + +void FileSystemDispatcherHost::OnOpenFileSystem( + const ViewHostMsg_OpenFileSystemRequest_Params& params) { + string16 name; + string16 root_path; + + // TODO(kinuko): not implemented yet. + + Send(new ViewMsg_OpenFileSystemRequest_Complete( + params.routing_id, + params.request_id, + false, + name, root_path)); +} + +void FileSystemDispatcherHost::Send(IPC::Message* message) { + if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { + if (!ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, + &FileSystemDispatcherHost::Send, + message))) + delete message; + return; + } + + if (!shutdown_ && message_sender_) + message_sender_->Send(message); + else + delete message; +} diff --git a/chrome/browser/file_system/file_system_dispatcher_host.h b/chrome/browser/file_system/file_system_dispatcher_host.h new file mode 100644 index 0000000..dbe18a8 --- /dev/null +++ b/chrome/browser/file_system/file_system_dispatcher_host.h @@ -0,0 +1,46 @@ +// Copyright (c) 2010 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 CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ +#define CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ + +#include "base/basictypes.h" +#include "base/nullable_string16.h" +#include "base/process.h" +#include "base/ref_counted.h" +#include "chrome/common/render_messages.h" + +class HostContentSettingsMap; +class Receiver; +class ResourceMessageFilter; + +class FileSystemDispatcherHost + : public base::RefCountedThreadSafe<FileSystemDispatcherHost> { + public: + FileSystemDispatcherHost(IPC::Message::Sender* sender, + HostContentSettingsMap* host_content_settings_map); + void Init(base::ProcessHandle process_handle); + void Shutdown(); + + bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); + + void OnOpenFileSystem(const ViewHostMsg_OpenFileSystemRequest_Params&); + // TODO(kinuko): add more methods. + + void Send(IPC::Message* message); + + private: + // The sender to be used for sending out IPC messages. + IPC::Message::Sender* message_sender_; + + // The handle of this process. + base::ProcessHandle process_handle_; + + bool shutdown_; + + // Used to look up permissions. + scoped_refptr<HostContentSettingsMap> host_content_settings_map_; +}; + +#endif // CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index b6bf854..471d3ba 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -30,6 +30,7 @@ #include "chrome/browser/device_orientation/dispatcher_host.h" #include "chrome/browser/download/download_file.h" #include "chrome/browser/extensions/extension_message_service.h" +#include "chrome/browser/file_system/file_system_dispatcher_host.h" #include "chrome/browser/geolocation/geolocation_permission_context.h" #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" #include "chrome/browser/gpu_process_host.h" @@ -244,7 +245,10 @@ ResourceMessageFilter::ResourceMessageFilter( GeolocationDispatcherHost::New( this->id(), profile->GetGeolocationPermissionContext()))), ALLOW_THIS_IN_INITIALIZER_LIST(device_orientation_dispatcher_host_( - new device_orientation::DispatcherHost(this->id()))) { + new device_orientation::DispatcherHost(this->id()))), + ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( + new FileSystemDispatcherHost(this, + profile->GetHostContentSettingsMap()))) { request_context_ = profile_->GetRequestContext(); DCHECK(request_context_); DCHECK(media_request_context_); @@ -274,6 +278,9 @@ ResourceMessageFilter::~ResourceMessageFilter() { // Shut down the database dispatcher host. db_dispatcher_host_->Shutdown(); + // Shut down the async file_system dispatcher host. + file_system_dispatcher_host_->Shutdown(); + // Let interested observers know we are being deleted. NotificationService::current()->Notify( NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, @@ -309,6 +316,7 @@ void ResourceMessageFilter::OnChannelConnected(int32 peer_pid) { dom_storage_dispatcher_host_->Init(id(), handle()); indexed_db_dispatcher_host_->Init(id(), handle()); db_dispatcher_host_->Init(handle()); + file_system_dispatcher_host_->Init(handle()); } void ResourceMessageFilter::OnChannelError() { @@ -345,7 +353,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { msg, this, next_route_id_callback(), &msg_is_ok) || geolocation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || speech_input_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || - device_orientation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok); + device_orientation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) || + file_system_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok); if (!handled) { DCHECK(msg_is_ok); // It should have been marked handled if it wasn't OK. diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 6f47917..83d4985 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -35,6 +35,7 @@ class AudioRendererHost; class ChromeURLRequestContext; class DatabaseDispatcherHost; class DOMStorageDispatcherHost; +class FileSystemDispatcherHost; struct FontDescriptor; class GeolocationDispatcherHost; class HostZoomMap; @@ -472,6 +473,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, scoped_refptr<device_orientation::DispatcherHost> device_orientation_dispatcher_host_; + // Handles FileSystem API related messages + scoped_refptr<FileSystemDispatcherHost> file_system_dispatcher_host_; + DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 93feece..23bd6ed 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1459,6 +1459,8 @@ 'browser/file_path_watcher_inotify.cc', 'browser/file_path_watcher_mac.cc', 'browser/file_path_watcher_win.cc', + 'browser/file_system/file_system_dispatcher_host.cc', + 'browser/file_system/file_system_dispatcher_host.h', 'browser/find_bar.h', 'browser/find_bar_controller.cc', 'browser/find_bar_controller.h', diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 8f6c8ad..8e6f862 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -889,6 +889,23 @@ struct ViewHostMsg_DomMessage_Params { bool user_gesture; }; +struct ViewHostMsg_OpenFileSystemRequest_Params { + // The routing ID of the view initiating the request. + int routing_id; + + // The response should have this id. + int request_id; + + // The origin doing the initiating. + GURL origin_url; + + // The requested FileSystem type. + WebKit::WebFileSystem::Type type; + + // Indicates how much storage space (in bytes) the caller expects to need. + int64 requested_size; +}; + namespace IPC { template <> @@ -2771,6 +2788,39 @@ struct ParamTraits<ViewHostMsg_DomMessage_Params> { } }; +template <> +struct ParamTraits<ViewHostMsg_OpenFileSystemRequest_Params> { + typedef ViewHostMsg_OpenFileSystemRequest_Params param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.routing_id); + WriteParam(m, p.request_id); + WriteParam(m, p.origin_url); + WriteParam(m, p.type); + WriteParam(m, p.requested_size); + } + static bool Read(const Message* m, void** iter, param_type* p) { + return + ReadParam(m, iter, &p->routing_id) && + ReadParam(m, iter, &p->request_id) && + ReadParam(m, iter, &p->origin_url) && + ReadParam(m, iter, &p->type) && + ReadParam(m, iter, &p->requested_size); + } + static void Log(const param_type& p, std::string* l) { + l->append("("); + LogParam(p.routing_id, l); + l->append(", "); + LogParam(p.request_id, l); + l->append(", "); + LogParam(p.origin_url, l); + l->append(", "); + LogParam(p.type, l); + l->append(", "); + LogParam(p.requested_size, l); + l->append(")"); + } +}; + } // namespace IPC #define MESSAGES_INTERNAL_FILE "chrome/common/render_messages_internal.h" diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 5c445c8..4a15201 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -998,6 +998,13 @@ IPC_BEGIN_MESSAGES(View) IPC_MESSAGE_ROUTED1(ViewMsg_DeviceOrientationUpdated, ViewMsg_DeviceOrientationUpdated_Params) + // WebFrameClient::openFileSystem response messages. + IPC_MESSAGE_ROUTED4(ViewMsg_OpenFileSystemRequest_Complete, + int /* request_id */, + bool /* accepted */, + string16 /* name */, + string16 /* root_path */) + IPC_END_MESSAGES(View) @@ -2650,4 +2657,12 @@ IPC_BEGIN_MESSAGES(ViewHost) IPC_MESSAGE_CONTROL1(ViewHostMsg_DeviceOrientation_StopUpdating, int /* render_view_id */) +//----------------------------------------------------------------------------- + // FileSystem API messages + // These are messages sent from the renderer to the browser process. + + // WebFrameClient::openFileSystem() message. + IPC_MESSAGE_CONTROL1(ViewHostMsg_OpenFileSystemRequest, + ViewHostMsg_OpenFileSystemRequest_Params) + IPC_END_MESSAGES(ViewHost) diff --git a/chrome/common/webkit_param_traits.h b/chrome/common/webkit_param_traits.h index 5310a4d..b45655f 100644 --- a/chrome/common/webkit_param_traits.h +++ b/chrome/common/webkit_param_traits.h @@ -29,6 +29,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" @@ -327,6 +328,11 @@ struct ParamTraits<WebKit::WebTextInputType> { } }; +template <> +struct SimilarTypeTraits<WebKit::WebFileSystem::Type> { + typedef int Type; +}; + } // namespace IPC #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 34a0cdb..2e66fc7 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -98,6 +98,8 @@ #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" @@ -192,6 +194,8 @@ using WebKit::WebDragOperation; using WebKit::WebDragOperationsMask; using WebKit::WebEditingAction; using WebKit::WebFileChooserCompletion; +using WebKit::WebFileSystem; +using WebKit::WebFileSystemCallbacks; using WebKit::WebFindOptions; using WebKit::WebFormControlElement; using WebKit::WebFormElement; @@ -406,6 +410,17 @@ static std::string DetermineTextLanguage(const string16& text) { return language; } +// Holds pending openFileSystem callbacks. +struct RenderView::PendingOpenFileSystem { + explicit PendingOpenFileSystem(WebFileSystemCallbacks* c) : callbacks(c) { + } + ~PendingOpenFileSystem() { + if (callbacks) + callbacks->didFail(WebKit::WebFileErrorAbort); + } + WebFileSystemCallbacks* callbacks; +}; + /////////////////////////////////////////////////////////////////////////////// int32 RenderView::next_page_id_ = 1; @@ -780,6 +795,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, OnAccessibilityDoDefaultAction) + IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete, + OnOpenFileSystemRequestComplete) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) @@ -3366,6 +3383,28 @@ void RenderView::reportFindInPageSelection(int request_id, false)); } +void RenderView::openFileSystem( + WebFrame* frame, + WebFileSystem::Type type, + long long size, + WebFileSystemCallbacks* callbacks) { + scoped_ptr<PendingOpenFileSystem> request( + new PendingOpenFileSystem(callbacks)); + + WebSecurityOrigin origin = frame->securityOrigin(); + if (origin.isEmpty()) + return; // Uninitialized document? + + ViewHostMsg_OpenFileSystemRequest_Params params; + params.routing_id = routing_id_; + params.request_id = pending_file_system_requests_.Add(request.release()); + params.origin_url = GURL(origin.toString()); + params.type = type; + params.requested_size = size; + + Send(new ViewHostMsg_OpenFileSystemRequest(params)); +} + // webkit_glue::WebPluginPageDelegate ----------------------------------------- webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( @@ -5503,3 +5542,17 @@ bool RenderView::IsNonLocalTopLevelNavigation( } return false; } + +void RenderView::OnOpenFileSystemRequestComplete( + int request_id, bool accepted, const string16& name, + const string16& root_path) { + PendingOpenFileSystem* request = pending_file_system_requests_.Lookup( + request_id); + DCHECK(request); + if (accepted) + request->callbacks->didOpenFileSystem(name, root_path); + else + request->callbacks->didFail(WebKit::WebFileErrorSecurity); + request->callbacks = NULL; + pending_file_system_requests_.Remove(request_id); +} diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index fb4aa71..7000d2a 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -16,6 +16,7 @@ #include "app/surface/transport_dib.h" #include "base/basictypes.h" #include "base/gtest_prod_util.h" +#include "base/id_map.h" #include "base/linked_ptr.h" #include "base/timer.h" #include "base/weak_ptr.h" @@ -37,6 +38,7 @@ #include "chrome/renderer/renderer_webcookiejar_impl.h" #include "chrome/renderer/translate_helper.h" #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrameClient.h" #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializerClient.h" @@ -544,6 +546,11 @@ class RenderView : public RenderWidget, int active_match_ordinal, const WebKit::WebRect& sel); + virtual void openFileSystem(WebKit::WebFrame* frame, + WebKit::WebFileSystem::Type, + long long size, + WebKit::WebFileSystemCallbacks* callbacks); + // WebKit::WebPageSerializerClient implementation ---------------------------- virtual void didSerializeDataForFrame(const WebKit::WebURL& frame_url, @@ -780,6 +787,10 @@ class RenderView : public RenderWidget, void OnNotifyRendererViewType(ViewType::Type view_type); void OnFillPasswordForm( const webkit_glue::PasswordFormFillData& form_data); + void OnOpenFileSystemRequestComplete(int request_id, + bool accepted, + const string16& name, + const string16& root_path); void OnPaste(); void OnPrintingDone(int document_cookie, bool success); void OnPrintPages(); @@ -1288,6 +1299,11 @@ class RenderView : public RenderWidget, // External host exposed through automation controller. ExternalHostBindings external_host_bindings_; + // Pending openFileSystem completion objects. + struct PendingOpenFileSystem; + IDMap<PendingOpenFileSystem, IDMapOwnPointer> + pending_file_system_requests_; + // --------------------------------------------------------------------------- // ADDING NEW DATA? Please see if it fits appropriately in one of the above // sections rather than throwing it randomly at the end. If you're adding a |
