| OLD | NEW |
| 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_chooser_host.h" | 5 #include "content/renderer/pepper/pepper_file_chooser_host.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/renderer/pepper/pepper_instance_state_accessor.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
| 10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
| 11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/host/dispatch_host_message.h" | 12 #include "ppapi/host/dispatch_host_message.h" |
| 13 #include "ppapi/host/host_message_context.h" | 13 #include "ppapi/host/host_message_context.h" |
| 14 #include "ppapi/host/ppapi_host.h" | 14 #include "ppapi/host/ppapi_host.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "ppapi/proxy/ppb_file_ref_proxy.h" | 16 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet
ion.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet
ion.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.
h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.
h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 PepperFileChooserHost::ChosenFileInfo::ChosenFileInfo( | 71 PepperFileChooserHost::ChosenFileInfo::ChosenFileInfo( |
| 72 const std::string& path, | 72 const std::string& path, |
| 73 const std::string& display_name) | 73 const std::string& display_name) |
| 74 : path(path), | 74 : path(path), |
| 75 display_name(display_name) { | 75 display_name(display_name) { |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 PepperFileChooserHost::PepperFileChooserHost( | 79 PepperFileChooserHost::PepperFileChooserHost( |
| 80 ppapi::host::PpapiHost* host, | 80 RendererPpapiHost* host, |
| 81 PP_Instance instance, | 81 PP_Instance instance, |
| 82 PP_Resource resource, | 82 PP_Resource resource) |
| 83 RenderViewImpl* render_view, | 83 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 84 PepperInstanceStateAccessor* state) | 84 renderer_ppapi_host_(host), |
| 85 : ResourceHost(host, instance, resource), | |
| 86 render_view_(render_view), | |
| 87 instance_state_(state), | |
| 88 handler_(NULL) { | 85 handler_(NULL) { |
| 89 } | 86 } |
| 90 | 87 |
| 91 PepperFileChooserHost::~PepperFileChooserHost() { | 88 PepperFileChooserHost::~PepperFileChooserHost() { |
| 92 } | 89 } |
| 93 | 90 |
| 94 int32_t PepperFileChooserHost::OnResourceMessageReceived( | 91 int32_t PepperFileChooserHost::OnResourceMessageReceived( |
| 95 const IPC::Message& msg, | 92 const IPC::Message& msg, |
| 96 ppapi::host::HostMessageContext* context) { | 93 ppapi::host::HostMessageContext* context) { |
| 97 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) | 94 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 ppapi::host::HostMessageContext* context, | 130 ppapi::host::HostMessageContext* context, |
| 134 bool save_as, | 131 bool save_as, |
| 135 bool open_multiple, | 132 bool open_multiple, |
| 136 const std::string& suggested_file_name, | 133 const std::string& suggested_file_name, |
| 137 const std::vector<std::string>& accept_mime_types) { | 134 const std::vector<std::string>& accept_mime_types) { |
| 138 if (handler_) | 135 if (handler_) |
| 139 return PP_ERROR_INPROGRESS; // Already pending. | 136 return PP_ERROR_INPROGRESS; // Already pending. |
| 140 | 137 |
| 141 if (!host()->permissions().HasPermission( | 138 if (!host()->permissions().HasPermission( |
| 142 ppapi::PERMISSION_BYPASS_USER_GESTURE) && | 139 ppapi::PERMISSION_BYPASS_USER_GESTURE) && |
| 143 !instance_state_->HasUserGesture(pp_instance())) { | 140 !renderer_ppapi_host_->HasUserGesture(pp_instance())) { |
| 144 return PP_ERROR_NO_USER_GESTURE; | 141 return PP_ERROR_NO_USER_GESTURE; |
| 145 } | 142 } |
| 146 | 143 |
| 147 WebKit::WebFileChooserParams params; | 144 WebKit::WebFileChooserParams params; |
| 148 if (save_as) { | 145 if (save_as) { |
| 149 params.saveAs = true; | 146 params.saveAs = true; |
| 150 params.initialValue = WebKit::WebString::fromUTF8( | 147 params.initialValue = WebKit::WebString::fromUTF8( |
| 151 suggested_file_name.data(), suggested_file_name.size()); | 148 suggested_file_name.data(), suggested_file_name.size()); |
| 152 } else { | 149 } else { |
| 153 params.multiSelect = open_multiple; | 150 params.multiSelect = open_multiple; |
| 154 } | 151 } |
| 155 std::vector<WebKit::WebString> mine_types(accept_mime_types.size()); | 152 std::vector<WebKit::WebString> mine_types(accept_mime_types.size()); |
| 156 for (size_t i = 0; i < accept_mime_types.size(); i++) { | 153 for (size_t i = 0; i < accept_mime_types.size(); i++) { |
| 157 mine_types[i] = WebKit::WebString::fromUTF8( | 154 mine_types[i] = WebKit::WebString::fromUTF8( |
| 158 accept_mime_types[i].data(), accept_mime_types[i].size()); | 155 accept_mime_types[i].data(), accept_mime_types[i].size()); |
| 159 } | 156 } |
| 160 params.acceptTypes = mine_types; | 157 params.acceptTypes = mine_types; |
| 161 params.directory = false; | 158 params.directory = false; |
| 162 | 159 |
| 163 handler_ = new CompletionHandler(AsWeakPtr()); | 160 handler_ = new CompletionHandler(AsWeakPtr()); |
| 164 if (!render_view_->runFileChooser(params, handler_)) { | 161 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( |
| 162 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); |
| 163 if (!render_view || !render_view->runFileChooser(params, handler_)) { |
| 165 delete handler_; | 164 delete handler_; |
| 166 handler_ = NULL; | 165 handler_ = NULL; |
| 167 return PP_ERROR_NOACCESS; | 166 return PP_ERROR_NOACCESS; |
| 168 } | 167 } |
| 169 | 168 |
| 170 reply_params_ = ppapi::proxy::ResourceMessageReplyParams( | 169 reply_params_ = ppapi::proxy::ResourceMessageReplyParams( |
| 171 context->params.pp_resource(), | 170 context->params.pp_resource(), |
| 172 context->params.sequence()); | 171 context->params.sequence()); |
| 173 return PP_OK_COMPLETIONPENDING; | 172 return PP_OK_COMPLETIONPENDING; |
| 174 } | 173 } |
| 175 | 174 |
| 176 } // namespace content | 175 } // namespace content |
| OLD | NEW |