blob: a846d96aa8145596d3f379632e1188ead010ce59 (
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
|
// Copyright (c) 2009 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 "chrome/browser/extensions/extension_function.h"
#include "base/json_reader.h"
#include "base/json_writer.h"
#include "base/logging.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
void AsyncExtensionFunction::SetArgs(const std::string& args) {
DCHECK(!args_); // Should only be called once.
if (!args.empty()) {
JSONReader reader;
args_ = reader.JsonToValue(args, false, false);
// Since we do the serialization in the v8 extension, we should always get
// valid JSON.
if (!args_) {
DCHECK(false);
return;
}
}
}
const std::string AsyncExtensionFunction::GetResult() {
std::string json;
// Some functions might not need to return any results.
if (result_.get())
JSONWriter::Write(result_.get(), false, &json);
return json;
}
void AsyncExtensionFunction::SendResponse(bool success) {
if (bad_message_) {
dispatcher_->HandleBadMessage(this);
} else {
dispatcher_->SendResponse(this, success);
}
}
std::string AsyncExtensionFunction::extension_id() {
return dispatcher_->extension_id();
}
Profile* AsyncExtensionFunction::profile() {
return dispatcher_->profile();
}
|