summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/plugin_stream_url.cc
blob: 15be976ab6d28157a8baa0e9a48134567f6a1202 (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
79
80
81
82
83
84
85
86
87
88
89
// 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 "config.h"

#include "webkit/glue/plugins/plugin_stream_url.h"

#include "webkit/glue/glue_util.h"
#include "webkit/glue/webplugin.h"
#include "webkit/glue/plugins/plugin_host.h"
#include "webkit/glue/plugins/plugin_instance.h"

namespace NPAPI {

PluginStreamUrl::PluginStreamUrl(
    int resource_id,
    const GURL &url,
    PluginInstance *instance,
    bool notify_needed,
    void *notify_data)
    : PluginStream(instance, url.spec().c_str(), notify_needed, notify_data),
      url_(url),
      id_(resource_id) {
}

PluginStreamUrl::~PluginStreamUrl() {
}

bool PluginStreamUrl::Close(NPReason reason) {
  CancelRequest();
  bool result = PluginStream::Close(reason);
  instance()->RemoveStream(this);
  return result;
}

void PluginStreamUrl::WillSendRequest(const GURL& url) {
  url_ = url;
  UpdateUrl(url.spec().c_str());
}

void PluginStreamUrl::DidReceiveResponse(const std::string& mime_type,
                                         const std::string& headers,
                                         uint32 expected_length,
                                         uint32 last_modified,
                                         bool request_is_seekable,
                                         bool* cancel) {
  bool opened = Open(mime_type,
                     headers,
                     expected_length,
                     last_modified,
                     request_is_seekable);
  if (!opened) {
    instance()->RemoveStream(this);
    *cancel = true;
  }
}

void PluginStreamUrl::DidReceiveData(const char* buffer, int length,
                                     int data_offset) {
  if (!open())
    return;

  if (length > 0)
    Write(const_cast<char*>(buffer), length, data_offset);
}

void PluginStreamUrl::DidFinishLoading() {
  if (!seekable()) {
    Close(NPRES_DONE);
  }
}

void PluginStreamUrl::DidFail() {
  Close(NPRES_NETWORK_ERR);
}

void PluginStreamUrl::CancelRequest() {
  if (id_ > 0) {
    if (instance()->webplugin()) {
      instance()->webplugin()->CancelResource(id_);
    }
    id_ = 0;
  }
}

} // namespace NPAPI