OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugins/ppapi/ppb_url_response_info_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 #include "ppapi/shared_impl/var.h" | 9 #include "ppapi/shared_impl/var.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHTTPHeaderVisitor.
h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHTTPHeaderVisitor.
h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
14 #include "webkit/plugins/ppapi/common.h" | 14 #include "webkit/plugins/ppapi/common.h" |
15 #include "webkit/plugins/ppapi/plugin_module.h" | 15 #include "webkit/plugins/ppapi/plugin_module.h" |
16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
17 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 17 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 18 #include "webkit/plugins/ppapi/resource_helper.h" |
18 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
19 | 20 |
20 using ppapi::StringVar; | 21 using ppapi::StringVar; |
21 using ppapi::thunk::PPB_URLResponseInfo_API; | 22 using ppapi::thunk::PPB_URLResponseInfo_API; |
22 using WebKit::WebHTTPHeaderVisitor; | 23 using WebKit::WebHTTPHeaderVisitor; |
23 using WebKit::WebString; | 24 using WebKit::WebString; |
24 using WebKit::WebURLResponse; | 25 using WebKit::WebURLResponse; |
25 | 26 |
26 namespace webkit { | 27 namespace webkit { |
27 namespace ppapi { | 28 namespace ppapi { |
(...skipping 15 matching lines...) Expand all Loading... |
43 private: | 44 private: |
44 std::string buffer_; | 45 std::string buffer_; |
45 }; | 46 }; |
46 | 47 |
47 bool IsRedirect(int32_t status) { | 48 bool IsRedirect(int32_t status) { |
48 return status >= 300 && status <= 399; | 49 return status >= 300 && status <= 399; |
49 } | 50 } |
50 | 51 |
51 } // namespace | 52 } // namespace |
52 | 53 |
53 PPB_URLResponseInfo_Impl::PPB_URLResponseInfo_Impl(PluginInstance* instance) | 54 PPB_URLResponseInfo_Impl::PPB_URLResponseInfo_Impl(PP_Instance instance) |
54 : Resource(instance), | 55 : Resource(instance), |
55 status_code_(-1) { | 56 status_code_(-1) { |
56 } | 57 } |
57 | 58 |
58 PPB_URLResponseInfo_Impl::~PPB_URLResponseInfo_Impl() { | 59 PPB_URLResponseInfo_Impl::~PPB_URLResponseInfo_Impl() { |
59 } | 60 } |
60 | 61 |
61 bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) { | 62 bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) { |
62 url_ = response.url().spec(); | 63 url_ = response.url().spec(); |
63 status_code_ = response.httpStatusCode(); | 64 status_code_ = response.httpStatusCode(); |
64 status_text_ = response.httpStatusText().utf8(); | 65 status_text_ = response.httpStatusText().utf8(); |
65 if (IsRedirect(status_code_)) { | 66 if (IsRedirect(status_code_)) { |
66 redirect_url_ = response.httpHeaderField( | 67 redirect_url_ = response.httpHeaderField( |
67 WebString::fromUTF8("Location")).utf8(); | 68 WebString::fromUTF8("Location")).utf8(); |
68 } | 69 } |
69 | 70 |
70 HeaderFlattener flattener; | 71 HeaderFlattener flattener; |
71 response.visitHTTPHeaderFields(&flattener); | 72 response.visitHTTPHeaderFields(&flattener); |
72 headers_ = flattener.buffer(); | 73 headers_ = flattener.buffer(); |
73 | 74 |
74 WebString file_path = response.downloadFilePath(); | 75 WebString file_path = response.downloadFilePath(); |
75 if (!file_path.isEmpty()) { | 76 if (!file_path.isEmpty()) { |
76 body_ = new PPB_FileRef_Impl(instance(), | 77 body_ = new PPB_FileRef_Impl(pp_instance(), |
77 webkit_glue::WebStringToFilePath(file_path)); | 78 webkit_glue::WebStringToFilePath(file_path)); |
78 } | 79 } |
79 return true; | 80 return true; |
80 } | 81 } |
81 | 82 |
82 PPB_URLResponseInfo_API* PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_API() { | 83 PPB_URLResponseInfo_API* PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_API() { |
83 return this; | 84 return this; |
84 } | 85 } |
85 | 86 |
86 PP_Var PPB_URLResponseInfo_Impl::GetProperty(PP_URLResponseProperty property) { | 87 PP_Var PPB_URLResponseInfo_Impl::GetProperty(PP_URLResponseProperty property) { |
87 PP_Module pp_module = instance()->module()->pp_module(); | 88 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 89 if (!plugin_module) |
| 90 return PP_MakeUndefined(); |
| 91 PP_Module pp_module = plugin_module->pp_module(); |
88 switch (property) { | 92 switch (property) { |
89 case PP_URLRESPONSEPROPERTY_URL: | 93 case PP_URLRESPONSEPROPERTY_URL: |
90 return StringVar::StringToPPVar(pp_module, url_); | 94 return StringVar::StringToPPVar(pp_module, url_); |
91 case PP_URLRESPONSEPROPERTY_REDIRECTURL: | 95 case PP_URLRESPONSEPROPERTY_REDIRECTURL: |
92 if (IsRedirect(status_code_)) | 96 if (IsRedirect(status_code_)) |
93 return StringVar::StringToPPVar(pp_module, redirect_url_); | 97 return StringVar::StringToPPVar(pp_module, redirect_url_); |
94 break; | 98 break; |
95 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD: | 99 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD: |
96 if (IsRedirect(status_code_)) | 100 if (IsRedirect(status_code_)) |
97 return StringVar::StringToPPVar(pp_module, status_text_); | 101 return StringVar::StringToPPVar(pp_module, status_text_); |
(...skipping 12 matching lines...) Expand all Loading... |
110 PP_Resource PPB_URLResponseInfo_Impl::GetBodyAsFileRef() { | 114 PP_Resource PPB_URLResponseInfo_Impl::GetBodyAsFileRef() { |
111 if (!body_.get()) | 115 if (!body_.get()) |
112 return 0; | 116 return 0; |
113 body_->AddRef(); // AddRef for the caller. | 117 body_->AddRef(); // AddRef for the caller. |
114 return body_->GetReference(); | 118 return body_->GetReference(); |
115 } | 119 } |
116 | 120 |
117 } // namespace ppapi | 121 } // namespace ppapi |
118 } // namespace webkit | 122 } // namespace webkit |
119 | 123 |
OLD | NEW |