| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/plugin/chrome_plugin_host.h" | 5 #include "chrome/plugin/chrome_plugin_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/process_util.h" |
| 11 #include "chrome/common/child_process.h" | 12 #include "chrome/common/child_process.h" |
| 12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/chrome_plugin_lib.h" | 14 #include "chrome/common/chrome_plugin_lib.h" |
| 14 #include "chrome/common/chrome_plugin_util.h" | 15 #include "chrome/common/chrome_plugin_util.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/plugin_messages.h" | 17 #include "chrome/common/plugin_messages.h" |
| 17 #include "chrome/plugin/plugin_thread.h" | 18 #include "chrome/plugin/plugin_thread.h" |
| 18 #include "chrome/plugin/webplugin_proxy.h" | 19 #include "chrome/plugin/webplugin_proxy.h" |
| 19 #include "net/base/data_url.h" | 20 #include "net/base/data_url.h" |
| 20 #include "net/base/upload_data.h" | 21 #include "net/base/upload_data.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 // NOTE: All methods must be called on the Plugin thread. | 36 // NOTE: All methods must be called on the Plugin thread. |
| 36 class PluginRequestHandlerProxy | 37 class PluginRequestHandlerProxy |
| 37 : public PluginHelper, public ResourceLoaderBridge::Peer { | 38 : public PluginHelper, public ResourceLoaderBridge::Peer { |
| 38 public: | 39 public: |
| 39 static PluginRequestHandlerProxy* FromCPRequest(CPRequest* request) { | 40 static PluginRequestHandlerProxy* FromCPRequest(CPRequest* request) { |
| 40 return ScopableCPRequest::GetData<PluginRequestHandlerProxy*>(request); | 41 return ScopableCPRequest::GetData<PluginRequestHandlerProxy*>(request); |
| 41 } | 42 } |
| 42 | 43 |
| 43 PluginRequestHandlerProxy(ChromePluginLib* plugin, | 44 PluginRequestHandlerProxy(ChromePluginLib* plugin, |
| 44 ScopableCPRequest* cprequest) | 45 ScopableCPRequest* cprequest) |
| 45 : PluginHelper(plugin), cprequest_(cprequest), response_data_offset_(0), | 46 : PluginHelper(plugin), cprequest_(cprequest), sync_(false), |
| 46 completed_(false), sync_(false), read_buffer_(NULL) { | 47 response_data_offset_(0), completed_(false), read_buffer_(NULL) { |
| 47 load_flags_ = PluginResponseUtils::CPLoadFlagsToNetFlags(0); | 48 load_flags_ = PluginResponseUtils::CPLoadFlagsToNetFlags(0); |
| 48 cprequest_->data = this; // see FromCPRequest(). | 49 cprequest_->data = this; // see FromCPRequest(). |
| 49 } | 50 } |
| 50 | 51 |
| 51 ~PluginRequestHandlerProxy() { | 52 ~PluginRequestHandlerProxy() { |
| 52 if (bridge_.get() && !completed_) { | 53 if (bridge_.get() && !completed_) { |
| 53 bridge_->Cancel(); | 54 bridge_->Cancel(); |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 bridge_.reset( | 144 bridge_.reset( |
| 144 PluginThread::current()->resource_dispatcher()->CreateBridge( | 145 PluginThread::current()->resource_dispatcher()->CreateBridge( |
| 145 cprequest_->method, | 146 cprequest_->method, |
| 146 GURL(cprequest_->url), | 147 GURL(cprequest_->url), |
| 147 GURL(cprequest_->url), // TODO(jackson): policy url? | 148 GURL(cprequest_->url), // TODO(jackson): policy url? |
| 148 GURL(), // TODO(mpcomplete): referrer? | 149 GURL(), // TODO(mpcomplete): referrer? |
| 149 "null", // frame_origin | 150 "null", // frame_origin |
| 150 "null", // main_frame_origin | 151 "null", // main_frame_origin |
| 151 extra_headers_, | 152 extra_headers_, |
| 152 load_flags_, | 153 load_flags_, |
| 153 GetCurrentProcessId(), | 154 base::GetCurrentProcId(), |
| 154 ResourceType::OBJECT, | 155 ResourceType::OBJECT, |
| 155 cprequest_->context, | 156 cprequest_->context, |
| 156 WebAppCacheContext::kNoAppCacheContextId, | 157 WebAppCacheContext::kNoAppCacheContextId, |
| 157 MSG_ROUTING_CONTROL)); | 158 MSG_ROUTING_CONTROL)); |
| 158 if (!bridge_.get()) | 159 if (!bridge_.get()) |
| 159 return CPERR_FAILURE; | 160 return CPERR_FAILURE; |
| 160 | 161 |
| 161 for (size_t i = 0; i < upload_content_.size(); ++i) { | 162 for (size_t i = 0; i < upload_content_.size(); ++i) { |
| 162 switch (upload_content_[i].type()) { | 163 switch (upload_content_[i].type()) { |
| 163 case net::UploadData::TYPE_BYTES: { | 164 case net::UploadData::TYPE_BYTES: { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 response_headers_, type, buf, buf_size); | 201 response_headers_, type, buf, buf_size); |
| 201 } | 202 } |
| 202 | 203 |
| 203 int Read(void* buf, uint32 buf_size) { | 204 int Read(void* buf, uint32 buf_size) { |
| 204 uint32 avail = | 205 uint32 avail = |
| 205 static_cast<uint32>(response_data_.size()) - response_data_offset_; | 206 static_cast<uint32>(response_data_.size()) - response_data_offset_; |
| 206 uint32 count = buf_size; | 207 uint32 count = buf_size; |
| 207 if (count > avail) | 208 if (count > avail) |
| 208 count = avail; | 209 count = avail; |
| 209 | 210 |
| 210 int rv = CPERR_FAILURE; | |
| 211 if (count) { | 211 if (count) { |
| 212 // Data is ready now. | 212 // Data is ready now. |
| 213 memcpy(buf, &response_data_[0] + response_data_offset_, count); | 213 memcpy(buf, &response_data_[0] + response_data_offset_, count); |
| 214 response_data_offset_ += count; | 214 response_data_offset_ += count; |
| 215 } else if (!completed_) { | 215 } else if (!completed_) { |
| 216 read_buffer_ = buf; | 216 read_buffer_ = buf; |
| 217 read_buffer_size_ = buf_size; | 217 read_buffer_size_ = buf_size; |
| 218 DCHECK(!sync_); | 218 DCHECK(!sync_); |
| 219 return CPERR_IO_PENDING; | 219 return CPERR_IO_PENDING; |
| 220 } | 220 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 234 private: | 234 private: |
| 235 scoped_ptr<ScopableCPRequest> cprequest_; | 235 scoped_ptr<ScopableCPRequest> cprequest_; |
| 236 scoped_ptr<ResourceLoaderBridge> bridge_; | 236 scoped_ptr<ResourceLoaderBridge> bridge_; |
| 237 std::vector<net::UploadData::Element> upload_content_; | 237 std::vector<net::UploadData::Element> upload_content_; |
| 238 std::string extra_headers_; | 238 std::string extra_headers_; |
| 239 uint32 load_flags_; | 239 uint32 load_flags_; |
| 240 bool sync_; | 240 bool sync_; |
| 241 | 241 |
| 242 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 242 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 243 std::string response_data_; | 243 std::string response_data_; |
| 244 int response_data_offset_; | 244 size_t response_data_offset_; |
| 245 bool completed_; | 245 bool completed_; |
| 246 void* read_buffer_; | 246 void* read_buffer_; |
| 247 uint32 read_buffer_size_; | 247 uint32 read_buffer_size_; |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 // | 250 // |
| 251 // Generic functions | 251 // Generic functions |
| 252 // | 252 // |
| 253 | 253 |
| 254 void STDCALL CPB_SetKeepProcessAlive(CPID id, CPBool keep_alive) { | 254 void STDCALL CPB_SetKeepProcessAlive(CPID id, CPBool keep_alive) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 // | 407 // |
| 408 | 408 |
| 409 CPError STDCALL CPB_CreateRequest(CPID id, CPBrowsingContext context, | 409 CPError STDCALL CPB_CreateRequest(CPID id, CPBrowsingContext context, |
| 410 const char* method, const char* url, | 410 const char* method, const char* url, |
| 411 CPRequest** request) { | 411 CPRequest** request) { |
| 412 CHECK(ChromePluginLib::IsPluginThread()); | 412 CHECK(ChromePluginLib::IsPluginThread()); |
| 413 ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); | 413 ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); |
| 414 CHECK(plugin); | 414 CHECK(plugin); |
| 415 | 415 |
| 416 ScopableCPRequest* cprequest = new ScopableCPRequest(url, method, context); | 416 ScopableCPRequest* cprequest = new ScopableCPRequest(url, method, context); |
| 417 PluginRequestHandlerProxy* handler = | 417 new PluginRequestHandlerProxy(plugin, cprequest); |
| 418 new PluginRequestHandlerProxy(plugin, cprequest); | |
| 419 | 418 |
| 420 *request = cprequest; | 419 *request = cprequest; |
| 421 return CPERR_SUCCESS; | 420 return CPERR_SUCCESS; |
| 422 } | 421 } |
| 423 | 422 |
| 424 CPError STDCALL CPR_StartRequest(CPRequest* request) { | 423 CPError STDCALL CPR_StartRequest(CPRequest* request) { |
| 425 CHECK(ChromePluginLib::IsPluginThread()); | 424 CHECK(ChromePluginLib::IsPluginThread()); |
| 426 PluginRequestHandlerProxy* handler = | 425 PluginRequestHandlerProxy* handler = |
| 427 PluginRequestHandlerProxy::FromCPRequest(request); | 426 PluginRequestHandlerProxy::FromCPRequest(request); |
| 428 CHECK(handler); | 427 CHECK(handler); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 613 |
| 615 response_funcs.size = sizeof(response_funcs); | 614 response_funcs.size = sizeof(response_funcs); |
| 616 response_funcs.received_redirect = CPRR_ReceivedRedirect; | 615 response_funcs.received_redirect = CPRR_ReceivedRedirect; |
| 617 response_funcs.start_completed = CPRR_StartCompleted; | 616 response_funcs.start_completed = CPRR_StartCompleted; |
| 618 response_funcs.read_completed = CPRR_ReadCompleted; | 617 response_funcs.read_completed = CPRR_ReadCompleted; |
| 619 response_funcs.upload_progress = CPRR_UploadProgress; | 618 response_funcs.upload_progress = CPRR_UploadProgress; |
| 620 } | 619 } |
| 621 | 620 |
| 622 return &browser_funcs; | 621 return &browser_funcs; |
| 623 } | 622 } |
| OLD | NEW |