Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/extensions/extension_function.cc

Issue 251093: Modify extension request IPC messages to pass a ListValue instead of a string. (Closed)
Patch Set: notreached messages Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_function.h" 5 #include "chrome/browser/extensions/extension_function.h"
6 6
7 #include "base/json_reader.h"
8 #include "base/json_writer.h" 7 #include "base/json_writer.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" 9 #include "chrome/browser/extensions/extension_function_dispatcher.h"
11 10
12 void AsyncExtensionFunction::SetArgs(const std::string& args) { 11 void AsyncExtensionFunction::SetArgs(const Value* args) {
13 DCHECK(!args_); // Should only be called once. 12 DCHECK(!args_); // Should only be called once.
14 if (!args.empty()) { 13 args_ = args->DeepCopy();
15 JSONReader reader;
16 args_ = reader.JsonToValue(args, false, false);
17
18 // Since we do the serialization in the v8 extension, we should always get
19 // valid JSON.
20 if (!args_) {
21 DCHECK(false);
22 return;
23 }
24 }
25 } 14 }
26 15
27 const std::string AsyncExtensionFunction::GetResult() { 16 const std::string AsyncExtensionFunction::GetResult() {
28 std::string json; 17 std::string json;
29 // Some functions might not need to return any results. 18 // Some functions might not need to return any results.
30 if (result_.get()) 19 if (result_.get())
31 JSONWriter::Write(result_.get(), false, &json); 20 JSONWriter::Write(result_.get(), false, &json);
32 return json; 21 return json;
33 } 22 }
34 23
35 void AsyncExtensionFunction::SendResponse(bool success) { 24 void AsyncExtensionFunction::SendResponse(bool success) {
36 if (!dispatcher()) 25 if (!dispatcher())
37 return; 26 return;
38 if (bad_message_) { 27 if (bad_message_) {
39 dispatcher()->HandleBadMessage(this); 28 dispatcher()->HandleBadMessage(this);
40 } else { 29 } else {
41 dispatcher()->SendResponse(this, success); 30 dispatcher()->SendResponse(this, success);
42 } 31 }
43 } 32 }
44 33
45 std::string AsyncExtensionFunction::extension_id() { 34 std::string AsyncExtensionFunction::extension_id() {
46 DCHECK(dispatcher()); 35 DCHECK(dispatcher());
47 return dispatcher()->extension_id(); 36 return dispatcher()->extension_id();
48 } 37 }
49 38
50 Profile* AsyncExtensionFunction::profile() { 39 Profile* AsyncExtensionFunction::profile() {
51 DCHECK(dispatcher()); 40 DCHECK(dispatcher());
52 return dispatcher()->profile(); 41 return dispatcher()->profile();
53 } 42 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function.h ('k') | chrome/browser/extensions/extension_function_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698