| 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/media/media_resource_loader_bridge_factory.h" | |
| 6 | |
| 7 #include "base/format_macros.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "base/stringprintf.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // A constant for an unknown position. | |
| 14 const int64 kPositionNotSpecified = -1; | |
| 15 | |
| 16 } // namespace | |
| 17 | |
| 18 namespace webkit_glue { | |
| 19 | |
| 20 MediaResourceLoaderBridgeFactory::MediaResourceLoaderBridgeFactory( | |
| 21 const GURL& referrer, | |
| 22 const std::string& frame_origin, | |
| 23 const std::string& main_frame_origin, | |
| 24 int origin_pid, | |
| 25 int appcache_host_id, | |
| 26 int32 routing_id) | |
| 27 : referrer_(referrer), | |
| 28 frame_origin_(frame_origin), | |
| 29 main_frame_origin_(main_frame_origin), | |
| 30 origin_pid_(origin_pid), | |
| 31 appcache_host_id_(appcache_host_id), | |
| 32 routing_id_(routing_id) { | |
| 33 } | |
| 34 | |
| 35 MediaResourceLoaderBridgeFactory::~MediaResourceLoaderBridgeFactory() {} | |
| 36 | |
| 37 ResourceLoaderBridge* MediaResourceLoaderBridgeFactory::CreateBridge( | |
| 38 const GURL& url, | |
| 39 int load_flags, | |
| 40 int64 first_byte_position, | |
| 41 int64 last_byte_position) { | |
| 42 webkit_glue::ResourceLoaderBridge::RequestInfo request_info; | |
| 43 request_info.method = "GET"; | |
| 44 request_info.url = url; | |
| 45 request_info.first_party_for_cookies = url; | |
| 46 request_info.referrer = referrer_; | |
| 47 request_info.frame_origin = frame_origin_; | |
| 48 request_info.main_frame_origin = main_frame_origin_; | |
| 49 request_info.headers = GenerateHeaders(first_byte_position, | |
| 50 last_byte_position); | |
| 51 request_info.load_flags = load_flags; | |
| 52 request_info.requestor_pid = origin_pid_; | |
| 53 request_info.request_type = ResourceType::MEDIA; | |
| 54 request_info.appcache_host_id = appcache_host_id_; | |
| 55 request_info.routing_id = routing_id_; | |
| 56 return webkit_glue::ResourceLoaderBridge::Create(request_info); | |
| 57 } | |
| 58 | |
| 59 MediaResourceLoaderBridgeFactory::MediaResourceLoaderBridgeFactory() {} | |
| 60 | |
| 61 // static | |
| 62 const std::string MediaResourceLoaderBridgeFactory::GenerateHeaders ( | |
| 63 int64 first_byte_position, int64 last_byte_position) { | |
| 64 // Construct the range header. | |
| 65 std::string header; | |
| 66 if (first_byte_position > kPositionNotSpecified && | |
| 67 last_byte_position > kPositionNotSpecified) { | |
| 68 if (first_byte_position <= last_byte_position) { | |
| 69 header = base::StringPrintf("Range: bytes=%" PRId64 "-%" PRId64, | |
| 70 first_byte_position, | |
| 71 last_byte_position); | |
| 72 } | |
| 73 } else if (first_byte_position > kPositionNotSpecified) { | |
| 74 header = base::StringPrintf("Range: bytes=%" PRId64 "-", | |
| 75 first_byte_position); | |
| 76 } else if (last_byte_position > kPositionNotSpecified) { | |
| 77 NOTIMPLEMENTED() << "Suffix range not implemented"; | |
| 78 } | |
| 79 return header; | |
| 80 } | |
| 81 | |
| 82 } // namespace webkit_glue | |
| OLD | NEW |