OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/glue/plugins/pepper_url_request_info.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/ppapi/c/pp_var.h" |
| 9 #include "webkit/glue/plugins/pepper_plugin_module.h" |
| 10 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
| 11 #include "webkit/glue/plugins/pepper_string.h" |
| 12 #include "webkit/glue/plugins/pepper_var.h" |
| 13 |
| 14 namespace pepper { |
| 15 |
| 16 namespace { |
| 17 |
| 18 PP_Resource Create(PP_Module module_id) { |
| 19 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 20 if (!module) |
| 21 return 0; |
| 22 |
| 23 URLRequestInfo* request = new URLRequestInfo(module); |
| 24 request->AddRef(); // AddRef for the caller. |
| 25 |
| 26 return request->GetResource(); |
| 27 } |
| 28 |
| 29 bool IsURLRequestInfo(PP_Resource resource) { |
| 30 return !!ResourceTracker::Get()->GetAsURLRequestInfo(resource).get(); |
| 31 } |
| 32 |
| 33 bool SetProperty(PP_Resource request_id, |
| 34 PP_URLRequestProperty property, |
| 35 PP_Var var) { |
| 36 scoped_refptr<URLRequestInfo> request( |
| 37 ResourceTracker::Get()->GetAsURLRequestInfo(request_id)); |
| 38 if (!request.get()) |
| 39 return false; |
| 40 |
| 41 if (var.type == PP_VarType_Bool) |
| 42 return request->SetBooleanProperty(property, var.value.as_bool); |
| 43 |
| 44 if (var.type == PP_VarType_String) |
| 45 return request->SetStringProperty(property, GetString(var)->value()); |
| 46 |
| 47 return false; |
| 48 } |
| 49 |
| 50 bool AppendDataToBody(PP_Resource request_id, PP_Var var) { |
| 51 scoped_refptr<URLRequestInfo> request( |
| 52 ResourceTracker::Get()->GetAsURLRequestInfo(request_id)); |
| 53 if (!request.get()) |
| 54 return false; |
| 55 |
| 56 String* data = GetString(var); |
| 57 if (!data) |
| 58 return false; |
| 59 |
| 60 return request->AppendDataToBody(data->value()); |
| 61 } |
| 62 |
| 63 bool AppendFileToBody(PP_Resource request_id, |
| 64 PP_Resource file_ref_id, |
| 65 int64_t start_offset, |
| 66 int64_t number_of_bytes, |
| 67 PP_Time expected_last_modified_time) { |
| 68 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 69 return false; |
| 70 } |
| 71 |
| 72 const PPB_URLRequestInfo ppb_urlrequestinfo = { |
| 73 &Create, |
| 74 &IsURLRequestInfo, |
| 75 &SetProperty, |
| 76 &AppendDataToBody, |
| 77 &AppendFileToBody |
| 78 }; |
| 79 |
| 80 } // namespace |
| 81 |
| 82 URLRequestInfo::URLRequestInfo(PluginModule* module) |
| 83 : Resource(module) { |
| 84 } |
| 85 |
| 86 URLRequestInfo::~URLRequestInfo() { |
| 87 } |
| 88 |
| 89 // static |
| 90 const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { |
| 91 return &ppb_urlrequestinfo; |
| 92 } |
| 93 |
| 94 bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, |
| 95 bool value) { |
| 96 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 97 return false; |
| 98 } |
| 99 |
| 100 bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, |
| 101 const std::string& value) { |
| 102 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 103 return false; |
| 104 } |
| 105 |
| 106 bool URLRequestInfo::AppendDataToBody(const std::string& data) { |
| 107 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 108 return false; |
| 109 } |
| 110 |
| 111 } // namespace pepper |
OLD | NEW |