OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/extension_function.h" | 5 #include "extensions/browser/extension_function.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/public/browser/notification_source.h" | 8 #include "content/public/browser/notification_source.h" |
9 #include "content/public/browser/notification_types.h" | 9 #include "content/public/browser/notification_types.h" |
10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
14 #include "extensions/browser/extension_function_dispatcher.h" | 14 #include "extensions/browser/extension_function_dispatcher.h" |
15 #include "extensions/browser/extension_message_filter.h" | 15 #include "extensions/browser/extension_message_filter.h" |
| 16 #include "extensions/common/error_utils.h" |
16 #include "extensions/common/extension_api.h" | 17 #include "extensions/common/extension_api.h" |
17 #include "extensions/common/extension_messages.h" | 18 #include "extensions/common/extension_messages.h" |
18 | 19 |
19 using content::BrowserThread; | 20 using content::BrowserThread; |
20 using content::RenderViewHost; | 21 using content::RenderViewHost; |
21 using content::WebContents; | 22 using content::WebContents; |
| 23 using extensions::ErrorUtils; |
22 using extensions::ExtensionAPI; | 24 using extensions::ExtensionAPI; |
23 using extensions::Feature; | 25 using extensions::Feature; |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 class ArgumentListResponseValue | 29 class ArgumentListResponseValue |
28 : public ExtensionFunction::ResponseValueObject { | 30 : public ExtensionFunction::ResponseValueObject { |
29 public: | 31 public: |
30 ArgumentListResponseValue(const std::string& function_name, | 32 ArgumentListResponseValue(const std::string& function_name, |
31 const char* title, | 33 const char* title, |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 scoped_ptr<base::ListValue> args) { | 250 scoped_ptr<base::ListValue> args) { |
249 return ResponseValue( | 251 return ResponseValue( |
250 new ArgumentListResponseValue(name(), "ArgumentList", this, args.Pass())); | 252 new ArgumentListResponseValue(name(), "ArgumentList", this, args.Pass())); |
251 } | 253 } |
252 | 254 |
253 ExtensionFunction::ResponseValue ExtensionFunction::Error( | 255 ExtensionFunction::ResponseValue ExtensionFunction::Error( |
254 const std::string& error) { | 256 const std::string& error) { |
255 return ResponseValue(new ErrorResponseValue(this, error)); | 257 return ResponseValue(new ErrorResponseValue(this, error)); |
256 } | 258 } |
257 | 259 |
| 260 ExtensionFunction::ResponseValue ExtensionFunction::Error( |
| 261 const std::string& format, |
| 262 const std::string& s1) { |
| 263 return ResponseValue( |
| 264 new ErrorResponseValue(this, ErrorUtils::FormatErrorMessage(format, s1))); |
| 265 } |
| 266 |
| 267 ExtensionFunction::ResponseValue ExtensionFunction::Error( |
| 268 const std::string& format, |
| 269 const std::string& s1, |
| 270 const std::string& s2) { |
| 271 return ResponseValue(new ErrorResponseValue( |
| 272 this, ErrorUtils::FormatErrorMessage(format, s1, s2))); |
| 273 } |
| 274 |
| 275 ExtensionFunction::ResponseValue ExtensionFunction::Error( |
| 276 const std::string& format, |
| 277 const std::string& s1, |
| 278 const std::string& s2, |
| 279 const std::string& s3) { |
| 280 return ResponseValue(new ErrorResponseValue( |
| 281 this, ErrorUtils::FormatErrorMessage(format, s1, s2, s3))); |
| 282 } |
| 283 |
258 ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() { | 284 ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() { |
259 return ResponseValue(new BadMessageResponseValue(this)); | 285 return ResponseValue(new BadMessageResponseValue(this)); |
260 } | 286 } |
261 | 287 |
262 ExtensionFunction::ResponseAction ExtensionFunction::RespondNow( | 288 ExtensionFunction::ResponseAction ExtensionFunction::RespondNow( |
263 ResponseValue result) { | 289 ResponseValue result) { |
264 return ResponseAction(new RespondNowAction( | 290 return ResponseAction(new RespondNowAction( |
265 result.Pass(), base::Bind(&ExtensionFunction::SendResponse, this))); | 291 result.Pass(), base::Bind(&ExtensionFunction::SendResponse, this))); |
266 } | 292 } |
267 | 293 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 459 |
434 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { | 460 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { |
435 return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_)); | 461 return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_)); |
436 } | 462 } |
437 | 463 |
438 // static | 464 // static |
439 bool SyncIOThreadExtensionFunction::ValidationFailure( | 465 bool SyncIOThreadExtensionFunction::ValidationFailure( |
440 SyncIOThreadExtensionFunction* function) { | 466 SyncIOThreadExtensionFunction* function) { |
441 return false; | 467 return false; |
442 } | 468 } |
OLD | NEW |