| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/glue/plugins/pepper_url_response_info.h" | 5 #include "webkit/glue/plugins/pepper_url_response_info.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/ppapi/c/pp_var.h" | 8 #include "third_party/ppapi/c/pp_var.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 std::string buffer_; | 38 std::string buffer_; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 bool IsURLResponseInfo(PP_Resource resource) { | 41 bool IsURLResponseInfo(PP_Resource resource) { |
| 42 return !!Resource::GetAs<URLResponseInfo>(resource); | 42 return !!Resource::GetAs<URLResponseInfo>(resource); |
| 43 } | 43 } |
| 44 | 44 |
| 45 PP_Var GetProperty(PP_Resource response_id, | 45 PP_Var GetProperty(PP_Resource response_id, |
| 46 PP_URLResponseProperty property) { | 46 PP_URLResponseProperty_Dev property) { |
| 47 scoped_refptr<URLResponseInfo> response( | 47 scoped_refptr<URLResponseInfo> response( |
| 48 Resource::GetAs<URLResponseInfo>(response_id)); | 48 Resource::GetAs<URLResponseInfo>(response_id)); |
| 49 if (!response) | 49 if (!response) |
| 50 return PP_MakeVoid(); | 50 return PP_MakeVoid(); |
| 51 | 51 |
| 52 return response->GetProperty(property); | 52 return response->GetProperty(property); |
| 53 } | 53 } |
| 54 | 54 |
| 55 PP_Resource GetBody(PP_Resource response_id) { | 55 PP_Resource GetBody(PP_Resource response_id) { |
| 56 scoped_refptr<URLResponseInfo> response( | 56 scoped_refptr<URLResponseInfo> response( |
| 57 Resource::GetAs<URLResponseInfo>(response_id)); | 57 Resource::GetAs<URLResponseInfo>(response_id)); |
| 58 if (!response.get()) | 58 if (!response.get()) |
| 59 return 0; | 59 return 0; |
| 60 | 60 |
| 61 FileRef* body = response->body(); | 61 FileRef* body = response->body(); |
| 62 if (!body) | 62 if (!body) |
| 63 return 0; | 63 return 0; |
| 64 body->AddRef(); // AddRef for the caller. | 64 body->AddRef(); // AddRef for the caller. |
| 65 | 65 |
| 66 return body->GetReference(); | 66 return body->GetReference(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 const PPB_URLResponseInfo ppb_urlresponseinfo = { | 69 const PPB_URLResponseInfo_Dev ppb_urlresponseinfo = { |
| 70 &IsURLResponseInfo, | 70 &IsURLResponseInfo, |
| 71 &GetProperty, | 71 &GetProperty, |
| 72 &GetBody | 72 &GetBody |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 URLResponseInfo::URLResponseInfo(PluginModule* module) | 77 URLResponseInfo::URLResponseInfo(PluginModule* module) |
| 78 : Resource(module), | 78 : Resource(module), |
| 79 status_code_(-1) { | 79 status_code_(-1) { |
| 80 } | 80 } |
| 81 | 81 |
| 82 URLResponseInfo::~URLResponseInfo() { | 82 URLResponseInfo::~URLResponseInfo() { |
| 83 } | 83 } |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 const PPB_URLResponseInfo* URLResponseInfo::GetInterface() { | 86 const PPB_URLResponseInfo_Dev* URLResponseInfo::GetInterface() { |
| 87 return &ppb_urlresponseinfo; | 87 return &ppb_urlresponseinfo; |
| 88 } | 88 } |
| 89 | 89 |
| 90 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { | 90 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty_Dev property) { |
| 91 switch (property) { | 91 switch (property) { |
| 92 case PP_URLRESPONSEPROPERTY_URL: | 92 case PP_URLRESPONSEPROPERTY_URL: |
| 93 return StringToPPVar(url_); | 93 return StringToPPVar(url_); |
| 94 case PP_URLRESPONSEPROPERTY_STATUSCODE: | 94 case PP_URLRESPONSEPROPERTY_STATUSCODE: |
| 95 return PP_MakeInt32(status_code_); | 95 return PP_MakeInt32(status_code_); |
| 96 case PP_URLRESPONSEPROPERTY_HEADERS: | 96 case PP_URLRESPONSEPROPERTY_HEADERS: |
| 97 return StringToPPVar(headers_); | 97 return StringToPPVar(headers_); |
| 98 default: | 98 default: |
| 99 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 99 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 100 return PP_MakeVoid(); | 100 return PP_MakeVoid(); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool URLResponseInfo::Initialize(const WebURLResponse& response) { | 104 bool URLResponseInfo::Initialize(const WebURLResponse& response) { |
| 105 url_ = response.url().spec(); | 105 url_ = response.url().spec(); |
| 106 status_code_ = response.httpStatusCode(); | 106 status_code_ = response.httpStatusCode(); |
| 107 | 107 |
| 108 HeaderFlattener flattener; | 108 HeaderFlattener flattener; |
| 109 response.visitHTTPHeaderFields(&flattener); | 109 response.visitHTTPHeaderFields(&flattener); |
| 110 headers_ = flattener.buffer(); | 110 headers_ = flattener.buffer(); |
| 111 | 111 |
| 112 WebString file_path = response.downloadFilePath(); | 112 WebString file_path = response.downloadFilePath(); |
| 113 if (!file_path.isEmpty()) | 113 if (!file_path.isEmpty()) |
| 114 body_ = new FileRef(module(), webkit_glue::WebStringToFilePath(file_path)); | 114 body_ = new FileRef(module(), webkit_glue::WebStringToFilePath(file_path)); |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace pepper | 118 } // namespace pepper |
| OLD | NEW |