1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/url_response_info_util.h"
9 #include "ppapi/shared_impl/url_response_info_data.h"
10 #include "third_party/blink/public/platform/web_http_header_visitor.h"
11 #include "third_party/blink/public/platform/web_string.h"
12 #include "third_party/blink/public/platform/web_url.h"
13 #include "third_party/blink/public/platform/web_url_response.h"
15 using blink::WebHTTPHeaderVisitor;
16 using blink::WebString;
17 using blink::WebURLResponse;
23 class HeadersToString : public WebHTTPHeaderVisitor {
26 ~HeadersToString() override {}
28 const std::string& buffer() const { return buffer_; }
30 void VisitHeader(const WebString& name, const WebString& value) override {
33 buffer_.append(name.Utf8());
35 buffer_.append(value.Utf8());
42 bool IsRedirect(int32_t status) { return status >= 300 && status <= 399; }
46 ppapi::URLResponseInfoData DataFromWebURLResponse(
47 const WebURLResponse& response) {
48 ppapi::URLResponseInfoData data;
49 data.url = response.CurrentRequestUrl().GetString().Utf8();
50 data.status_code = response.HttpStatusCode();
51 #if BUILDFLAG(IS_TIZEN_TV)
52 // Tizen API responses code 0 instead of HTTP 200 indicating OK, when file
53 // is loaded using file:// protocol.
54 GURL url = response.CurrentRequestUrl();
55 if (url.SchemeIsFile()) {
56 if (data.status_code == 0)
57 data.status_code = 200;
60 data.status_text = response.HttpStatusText().Utf8();
61 if (IsRedirect(data.status_code)) {
63 response.HttpHeaderField(WebString::FromUTF8("Location")).Utf8();
66 HeadersToString headers_to_string;
67 response.VisitHttpHeaderFields(&headers_to_string);
68 data.headers = headers_to_string.buffer();
72 } // namespace content