summaryrefslogtreecommitdiffstats
path: root/webkit/glue/media/media_resource_loader_bridge_factory.cc
blob: 9d8d5475340a6d272ef7b04ea800534ee458264d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/glue/media/media_resource_loader_bridge_factory.h"

#include "base/format_macros.h"
#include "base/string_util.h"
#include "base/stringprintf.h"

namespace {

// A constant for an unknown position.
const int64 kPositionNotSpecified = -1;

}  // namespace

namespace webkit_glue {

MediaResourceLoaderBridgeFactory::MediaResourceLoaderBridgeFactory(
    const GURL& referrer,
    const std::string& frame_origin,
    const std::string& main_frame_origin,
    int origin_pid,
    int appcache_host_id,
    int32 routing_id)
    : referrer_(referrer),
      frame_origin_(frame_origin),
      main_frame_origin_(main_frame_origin),
      origin_pid_(origin_pid),
      appcache_host_id_(appcache_host_id),
      routing_id_(routing_id) {
}

ResourceLoaderBridge* MediaResourceLoaderBridgeFactory::CreateBridge(
        const GURL& url,
        int load_flags,
        int64 first_byte_position,
        int64 last_byte_position) {
  webkit_glue::ResourceLoaderBridge::RequestInfo request_info;
  request_info.method = "GET";
  request_info.url = url;
  request_info.first_party_for_cookies = url;
  request_info.referrer = referrer_;
  request_info.frame_origin = frame_origin_;
  request_info.main_frame_origin = main_frame_origin_;
  request_info.headers = GenerateHeaders(first_byte_position,
                                         last_byte_position);
  request_info.load_flags = load_flags;
  request_info.requestor_pid = origin_pid_;
  request_info.request_type = ResourceType::MEDIA;
  request_info.appcache_host_id = appcache_host_id_;
  request_info.routing_id = routing_id_;
  return webkit_glue::ResourceLoaderBridge::Create(request_info);
}

// static
const std::string MediaResourceLoaderBridgeFactory::GenerateHeaders (
    int64 first_byte_position, int64 last_byte_position) {
  // Construct the range header.
  std::string header;
  if (first_byte_position > kPositionNotSpecified &&
      last_byte_position > kPositionNotSpecified) {
    if (first_byte_position <= last_byte_position) {
      header = base::StringPrintf("Range: bytes=%" PRId64 "-%" PRId64,
                                  first_byte_position,
                                  last_byte_position);
    }
  } else if (first_byte_position > kPositionNotSpecified) {
    header = base::StringPrintf("Range: bytes=%" PRId64 "-",
                                first_byte_position);
  } else if (last_byte_position > kPositionNotSpecified) {
    NOTIMPLEMENTED() << "Suffix range not implemented";
  }
  return header;
}

}  // namespace webkit_glue