summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/pepper_url_request_info.cc
blob: 0f48a7b5fa82e19e9c34814e334677fc1da59a1e (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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/plugins/pepper_url_request_info.h"

#include "base/logging.h"
#include "third_party/ppapi/c/pp_var.h"
#include "webkit/glue/plugins/pepper_plugin_module.h"
#include "webkit/glue/plugins/pepper_string.h"
#include "webkit/glue/plugins/pepper_var.h"

namespace pepper {

namespace {

PP_Resource Create(PP_Module module_id) {
  PluginModule* module = PluginModule::FromPPModule(module_id);
  if (!module)
    return 0;

  URLRequestInfo* request = new URLRequestInfo(module);
  request->AddRef();  // AddRef for the caller.

  return request->GetResource();
}

bool IsURLRequestInfo(PP_Resource resource) {
  return !!Resource::GetAs<URLRequestInfo>(resource).get();
}

bool SetProperty(PP_Resource request_id,
                 PP_URLRequestProperty property,
                 PP_Var var) {
  scoped_refptr<URLRequestInfo> request(
      Resource::GetAs<URLRequestInfo>(request_id));
  if (!request.get())
    return false;

  if (var.type == PP_VarType_Bool)
    return request->SetBooleanProperty(property, var.value.as_bool);

  if (var.type == PP_VarType_String)
    return request->SetStringProperty(property, GetString(var)->value());

  return false;
}

bool AppendDataToBody(PP_Resource request_id, PP_Var var) {
  scoped_refptr<URLRequestInfo> request(
      Resource::GetAs<URLRequestInfo>(request_id));
  if (!request.get())
    return false;

  String* data = GetString(var);
  if (!data)
    return false;

  return request->AppendDataToBody(data->value());
}

bool AppendFileToBody(PP_Resource request_id,
                      PP_Resource file_ref_id,
                      int64_t start_offset,
                      int64_t number_of_bytes,
                      PP_Time expected_last_modified_time) {
  NOTIMPLEMENTED();  // TODO(darin): Implement me!
  return false;
}

const PPB_URLRequestInfo ppb_urlrequestinfo = {
  &Create,
  &IsURLRequestInfo,
  &SetProperty,
  &AppendDataToBody,
  &AppendFileToBody
};

}  // namespace

URLRequestInfo::URLRequestInfo(PluginModule* module)
    : Resource(module) {
}

URLRequestInfo::~URLRequestInfo() {
}

// static
const PPB_URLRequestInfo* URLRequestInfo::GetInterface() {
  return &ppb_urlrequestinfo;
}

bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property,
                                        bool value) {
  NOTIMPLEMENTED();  // TODO(darin): Implement me!
  return false;
}

bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property,
                                       const std::string& value) {
  NOTIMPLEMENTED();  // TODO(darin): Implement me!
  return false;
}

bool URLRequestInfo::AppendDataToBody(const std::string& data) {
  NOTIMPLEMENTED();  // TODO(darin): Implement me!
  return false;
}

}  // namespace pepper