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

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

Issue 10694106: Added support for multiple parameters to Extension API callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review fixes. Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" 9 #include "chrome/browser/extensions/extension_function_dispatcher.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 void ExtensionFunction::OnQuotaExceeded() { 86 void ExtensionFunction::OnQuotaExceeded() {
87 error_ = QuotaLimitHeuristic::kGenericOverQuotaError; 87 error_ = QuotaLimitHeuristic::kGenericOverQuotaError;
88 SendResponse(false); 88 SendResponse(false);
89 } 89 }
90 90
91 void ExtensionFunction::SetArgs(const base::ListValue* args) { 91 void ExtensionFunction::SetArgs(const base::ListValue* args) {
92 DCHECK(!args_.get()); // Should only be called once. 92 DCHECK(!args_.get()); // Should only be called once.
93 args_.reset(args->DeepCopy()); 93 args_.reset(args->DeepCopy());
94 } 94 }
95 95
96 const Value* ExtensionFunction::GetResultValue() { 96 void ExtensionFunction::SetSingleResult(base::Value* result) {
97 return result_.get(); 97 results_.reset(new base::ListValue());
98 results_->Append(result);
99 }
100
101 const ListValue* ExtensionFunction::GetResults() {
102 return results_.get();
98 } 103 }
99 104
100 const std::string ExtensionFunction::GetError() { 105 const std::string ExtensionFunction::GetError() {
101 return error_; 106 return error_;
102 } 107 }
103 108
104 void ExtensionFunction::SetError(const std::string& error) { 109 void ExtensionFunction::SetError(const std::string& error) {
105 error_ = error; 110 error_ = error;
106 } 111 }
107 112
(...skipping 13 matching lines...) Expand all
121 126
122 void ExtensionFunction::SendResponseImpl(base::ProcessHandle process, 127 void ExtensionFunction::SendResponseImpl(base::ProcessHandle process,
123 IPC::Sender* ipc_sender, 128 IPC::Sender* ipc_sender,
124 bool success) { 129 bool success) {
125 DCHECK(ipc_sender); 130 DCHECK(ipc_sender);
126 if (bad_message_) { 131 if (bad_message_) {
127 HandleBadMessage(process); 132 HandleBadMessage(process);
128 return; 133 return;
129 } 134 }
130 135
131 // Value objects can't be directly serialized in our IPC code, so we wrap the 136 // If results were never set, we send an empty argument list.
132 // result_ Value with a ListValue (also transferring ownership of result_). 137 if (!results_.get())
133 base::ListValue result_wrapper; 138 results_.reset(new ListValue());
134 if (result_.get())
135 result_wrapper.Append(result_.release());
136 139
137 ipc_sender->Send(new ExtensionMsg_Response( 140 ipc_sender->Send(new ExtensionMsg_Response(
138 request_id_, success, result_wrapper, GetError())); 141 request_id_, success, *results_.release(), GetError()));
139 } 142 }
140 143
141 void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) { 144 void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) {
142 LOG(ERROR) << "bad extension message " << name_ << " : terminating renderer."; 145 LOG(ERROR) << "bad extension message " << name_ << " : terminating renderer.";
143 if (content::RenderProcessHost::run_renderer_in_process()) { 146 if (content::RenderProcessHost::run_renderer_in_process()) {
144 // In single process mode it is better if we don't suicide but just crash. 147 // In single process mode it is better if we don't suicide but just crash.
145 CHECK(false); 148 CHECK(false);
146 } else { 149 } else {
147 NOTREACHED(); 150 NOTREACHED();
148 content::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); 151 content::RecordAction(UserMetricsAction("BadMessageTerminate_EFD"));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 294
292 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { 295 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() {
293 } 296 }
294 297
295 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { 298 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() {
296 } 299 }
297 300
298 void SyncIOThreadExtensionFunction::Run() { 301 void SyncIOThreadExtensionFunction::Run() {
299 SendResponse(RunImpl()); 302 SendResponse(RunImpl());
300 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698