Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(916)

Side by Side Diff: content/renderer/pepper/pepper_file_io_host.cc

Issue 13508005: Allow RequestOSFileHandle if an app has unlimited storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert most of patch set 2 Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/pepper/pepper_file_io_host.h" 5 #include "content/renderer/pepper/pepper_file_io_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util_proxy.h" 10 #include "base/files/file_util_proxy.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { 84 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
85 callback_.Run(error_code); 85 callback_.Run(error_code);
86 } 86 }
87 87
88 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { 88 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
89 NOTREACHED(); 89 NOTREACHED();
90 } 90 }
91 91
92 virtual void DidOpenFile(base::PlatformFile file) OVERRIDE { 92 virtual void DidOpenFile(base::PlatformFile file,
93 quota::QuotaLimitType quota_policy) OVERRIDE {
93 NOTREACHED(); 94 NOTREACHED();
94 } 95 }
95 96
96 private: 97 private:
97 PlatformGeneralCallback callback_; 98 PlatformGeneralCallback callback_;
98 }; 99 };
99 100
100 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) { 101 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) {
101 // On the plugin side, some callbacks expect a parameter that means different 102 // On the plugin side, some callbacks expect a parameter that means different
102 // things depending on whether is negative or not. We translate for those 103 // things depending on whether is negative or not. We translate for those
103 // callbacks here. 104 // callbacks here.
104 return pp_error == PP_OK ? byte_number : pp_error; 105 return pp_error == PP_OK ? byte_number : pp_error;
105 } 106 }
106 107
107 } // namespace 108 } // namespace
108 109
109 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, 110 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host,
110 PP_Instance instance, 111 PP_Instance instance,
111 PP_Resource resource) 112 PP_Resource resource)
112 : ResourceHost(host->GetPpapiHost(), instance, resource), 113 : ResourceHost(host->GetPpapiHost(), instance, resource),
113 file_(base::kInvalidPlatformFileValue), 114 file_(base::kInvalidPlatformFileValue),
114 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 115 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
116 quota_policy_(quota::kQuotaLimitTypeUnknown),
115 is_running_in_process_(host->IsRunningInProcess()), 117 is_running_in_process_(host->IsRunningInProcess()),
116 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 118 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
117 // TODO(victorhsieh): eliminate plugin_delegate_ as it's no longer needed. 119 // TODO(victorhsieh): eliminate plugin_delegate_ as it's no longer needed.
118 webkit::ppapi::PluginInstance* plugin_instance = 120 webkit::ppapi::PluginInstance* plugin_instance =
119 webkit::ppapi::HostGlobals::Get()->GetInstance(instance); 121 webkit::ppapi::HostGlobals::Get()->GetInstance(instance);
120 plugin_delegate_ = plugin_instance ? plugin_instance->delegate() : NULL; 122 plugin_delegate_ = plugin_instance ? plugin_instance->delegate() : NULL;
121 } 123 }
122 124
123 PepperFileIOHost::~PepperFileIOHost() { 125 PepperFileIOHost::~PepperFileIOHost() {
124 OnHostMsgClose(NULL); 126 OnHostMsgClose(NULL);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 context->MakeReplyMessageContext()))) 449 context->MakeReplyMessageContext())))
448 return PP_ERROR_FAILED; 450 return PP_ERROR_FAILED;
449 451
450 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 452 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
451 return PP_OK_COMPLETIONPENDING; 453 return PP_OK_COMPLETIONPENDING;
452 } 454 }
453 455
454 int32_t PepperFileIOHost::OnHostMsgRequestOSFileHandle( 456 int32_t PepperFileIOHost::OnHostMsgRequestOSFileHandle(
455 ppapi::host::HostMessageContext* context) { 457 ppapi::host::HostMessageContext* context) {
456 if (!is_running_in_process_ && 458 if (!is_running_in_process_ &&
459 quota_policy_ != quota::kQuotaLimitTypeUnlimited &&
460 // TODO(hamaji): Remove the whitelist once it turned out the
461 // quota check is sufficient. http://crbug.com/226386
457 !GetContentClient()->renderer()->IsRequestOSFileHandleAllowedForURL( 462 !GetContentClient()->renderer()->IsRequestOSFileHandleAllowedForURL(
458 file_system_url_)) 463 file_system_url_))
459 return PP_ERROR_FAILED; 464 return PP_ERROR_FAILED;
460 465
461 // TODO(hamaji): Should fail if quota is not unlimited.
462 // http://crbug.com/224123
463
464 RendererPpapiHost* renderer_ppapi_host = 466 RendererPpapiHost* renderer_ppapi_host =
465 RendererPpapiHost::GetForPPInstance(pp_instance()); 467 RendererPpapiHost::GetForPPInstance(pp_instance());
466 468
467 IPC::PlatformFileForTransit file = 469 IPC::PlatformFileForTransit file =
468 renderer_ppapi_host->ShareHandleWithRemote(file_, false); 470 renderer_ppapi_host->ShareHandleWithRemote(file_, false);
469 if (file == IPC::InvalidPlatformFileForTransit()) 471 if (file == IPC::InvalidPlatformFileForTransit())
470 return PP_ERROR_FAILED; 472 return PP_ERROR_FAILED;
471 ppapi::host::ReplyMessageContext reply_context = 473 ppapi::host::ReplyMessageContext reply_context =
472 context->MakeReplyMessageContext(); 474 context->MakeReplyMessageContext();
473 reply_context.params.AppendHandle(ppapi::proxy::SerializedHandle( 475 reply_context.params.AppendHandle(ppapi::proxy::SerializedHandle(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 528
527 reply_context.params.set_result(pp_error); 529 reply_context.params.set_result(pp_error);
528 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply()); 530 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply());
529 state_manager_.SetOperationFinished(); 531 state_manager_.SetOperationFinished();
530 } 532 }
531 533
532 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback( 534 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback(
533 ppapi::host::ReplyMessageContext reply_context, 535 ppapi::host::ReplyMessageContext reply_context,
534 base::PlatformFileError error_code, 536 base::PlatformFileError error_code,
535 base::PassPlatformFile file, 537 base::PassPlatformFile file,
538 quota::QuotaLimitType quota_policy,
536 const PluginDelegate::NotifyCloseFileCallback& callback) { 539 const PluginDelegate::NotifyCloseFileCallback& callback) {
537 if (error_code == base::PLATFORM_FILE_OK) 540 if (error_code == base::PLATFORM_FILE_OK)
538 notify_close_file_callback_ = callback; 541 notify_close_file_callback_ = callback;
542 quota_policy_ = quota_policy;
539 ExecutePlatformOpenFileCallback(reply_context, error_code, file); 543 ExecutePlatformOpenFileCallback(reply_context, error_code, file);
540 } 544 }
541 545
542 void PepperFileIOHost::ExecutePlatformQueryCallback( 546 void PepperFileIOHost::ExecutePlatformQueryCallback(
543 ppapi::host::ReplyMessageContext reply_context, 547 ppapi::host::ReplyMessageContext reply_context,
544 base::PlatformFileError error_code, 548 base::PlatformFileError error_code,
545 const base::PlatformFileInfo& file_info) { 549 const base::PlatformFileInfo& file_info) {
546 PP_FileInfo pp_info; 550 PP_FileInfo pp_info;
547 pp_info.size = file_info.size; 551 pp_info.size = file_info.size;
548 pp_info.creation_time = TimeToPPTime(file_info.creation_time); 552 pp_info.creation_time = TimeToPPTime(file_info.creation_time);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // On the plugin side, the callback expects a parameter with different meaning 597 // On the plugin side, the callback expects a parameter with different meaning
594 // depends on whether is negative or not. It is the result here. We translate 598 // depends on whether is negative or not. It is the result here. We translate
595 // for the callback. 599 // for the callback.
596 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 600 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
597 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); 601 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
598 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 602 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
599 state_manager_.SetOperationFinished(); 603 state_manager_.SetOperationFinished();
600 } 604 }
601 605
602 } // namespace content 606 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698