Disable content detection tests on Android
[chromium-blink-merge.git] / webkit / plugins / ppapi / url_response_info_util.cc
blobd03a9cae25b8d08b5d56fae276d340f926cd33ac
1 // Copyright (c) 2012 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.
5 #include "webkit/plugins/ppapi/url_response_info_util.h"
7 #include "base/logging.h"
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPHeaderVisitor.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h"
12 #include "webkit/base/file_path_string_conversions.h"
13 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
14 #include "webkit/glue/webkit_glue.h"
16 using WebKit::WebHTTPHeaderVisitor;
17 using WebKit::WebString;
18 using WebKit::WebURLResponse;
20 namespace webkit {
21 namespace ppapi {
23 namespace {
25 class HeaderFlattener : public WebHTTPHeaderVisitor {
26 public:
27 const std::string& buffer() const { return buffer_; }
29 virtual void visitHeader(const WebString& name, const WebString& value) {
30 if (!buffer_.empty())
31 buffer_.append("\n");
32 buffer_.append(name.utf8());
33 buffer_.append(": ");
34 buffer_.append(value.utf8());
37 private:
38 std::string buffer_;
41 bool IsRedirect(int32_t status) {
42 return status >= 300 && status <= 399;
45 } // namespace
47 ::ppapi::URLResponseInfoData DataFromWebURLResponse(
48 PP_Instance pp_instance,
49 const WebURLResponse& response) {
50 ::ppapi::URLResponseInfoData data;
52 data.url = response.url().spec();
53 data.status_code = response.httpStatusCode();
54 data.status_text = response.httpStatusText().utf8();
55 if (IsRedirect(data.status_code)) {
56 data.redirect_url = response.httpHeaderField(
57 WebString::fromUTF8("Location")).utf8();
60 HeaderFlattener flattener;
61 response.visitHTTPHeaderFields(&flattener);
62 data.headers = flattener.buffer();
64 WebString file_path = response.downloadFilePath();
65 if (!file_path.isEmpty()) {
66 scoped_refptr<PPB_FileRef_Impl> file_ref(
67 PPB_FileRef_Impl::CreateExternal(
68 pp_instance,
69 webkit_base::WebStringToFilePath(file_path),
70 std::string()));
71 data.body_as_file_ref = file_ref->GetCreateInfo();
72 file_ref->GetReference(); // The returned data has one ref for the plugin.
74 return data;
77 } // namespace ppapi
78 } // namespace webkit