summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/plugin_data_stream.cc
blob: da5f2d5721cba5c888a3feb322040329e684491a (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
// Copyright (c) 2006-2008 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/plugins/plugin_data_stream.h"

#include "base/logging.h"

namespace NPAPI {

PluginDataStream::PluginDataStream(PluginInstance *instance, 
                                   const std::string& url,
                                   const std::string& mime_type,
                                   const std::string& headers,
                                   uint32 expected_length,
                                   uint32 last_modified)
    : PluginStream(instance, url.c_str(), false, 0),
      mime_type_(mime_type),
      headers_(headers),
      expected_length_(expected_length),
      last_modified_(last_modified),
      stream_open_failed_(false) {
}

PluginDataStream::~PluginDataStream() {
}

void PluginDataStream::SendToPlugin(const char* buffer, int length) {
  if (stream_open_failed_)
    return;

  if (!open()) {
    if (!Open(mime_type_, headers_, expected_length_, last_modified_)) {
      stream_open_failed_ = true;
      return;
    }
  }

  // TODO(iyengar) - check if it was not fully sent, and figure out a 
  // backup plan.
  int written = Write(buffer, length);
  DCHECK(written == length);
}

} // namespace NPAPI