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 "chrome/browser/extensions/chrome_extension_function.h" | 5 #include "chrome/browser/extensions/chrome_extension_function.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "chrome/browser/extensions/chrome_extension_function_details.h" | 9 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
10 #include "chrome/browser/extensions/window_controller.h" | 10 #include "chrome/browser/extensions/window_controller.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 extensions::WindowController* | 35 extensions::WindowController* |
36 ChromeUIThreadExtensionFunction::GetExtensionWindowController() { | 36 ChromeUIThreadExtensionFunction::GetExtensionWindowController() { |
37 return chrome_details_.GetExtensionWindowController(); | 37 return chrome_details_.GetExtensionWindowController(); |
38 } | 38 } |
39 | 39 |
40 content::WebContents* | 40 content::WebContents* |
41 ChromeUIThreadExtensionFunction::GetAssociatedWebContents() { | 41 ChromeUIThreadExtensionFunction::GetAssociatedWebContents() { |
42 return chrome_details_.GetAssociatedWebContents(); | 42 return chrome_details_.GetAssociatedWebContents(); |
43 } | 43 } |
44 | 44 |
| 45 void ChromeUIThreadExtensionFunction::SetError(const std::string& error) { |
| 46 error_ = error; |
| 47 } |
| 48 |
| 49 const std::string& ChromeUIThreadExtensionFunction::GetError() const { |
| 50 return error_.empty() ? UIThreadExtensionFunction::GetError() : error_; |
| 51 } |
| 52 |
45 void ChromeUIThreadExtensionFunction::SendResponse(bool success) { | 53 void ChromeUIThreadExtensionFunction::SendResponse(bool success) { |
46 Respond(success ? ArgumentList(std::move(results_)) : Error(error_)); | 54 ResponseValue response; |
| 55 if (success) { |
| 56 response = ArgumentList(std::move(results_)); |
| 57 } else { |
| 58 response = results_ ? ErrorWithArguments(std::move(results_), error_) |
| 59 : Error(error_); |
| 60 } |
| 61 Respond(std::move(response)); |
| 62 } |
| 63 |
| 64 void ChromeUIThreadExtensionFunction::SetResult( |
| 65 std::unique_ptr<base::Value> result) { |
| 66 results_.reset(new base::ListValue()); |
| 67 results_->Append(std::move(result)); |
| 68 } |
| 69 |
| 70 void ChromeUIThreadExtensionFunction::SetResultList( |
| 71 std::unique_ptr<base::ListValue> results) { |
| 72 results_ = std::move(results); |
47 } | 73 } |
48 | 74 |
49 ChromeUIThreadExtensionFunction::~ChromeUIThreadExtensionFunction() { | 75 ChromeUIThreadExtensionFunction::~ChromeUIThreadExtensionFunction() { |
50 } | 76 } |
51 | 77 |
52 ChromeAsyncExtensionFunction::ChromeAsyncExtensionFunction() { | 78 ChromeAsyncExtensionFunction::ChromeAsyncExtensionFunction() { |
53 } | 79 } |
54 | 80 |
55 ChromeAsyncExtensionFunction::~ChromeAsyncExtensionFunction() {} | 81 ChromeAsyncExtensionFunction::~ChromeAsyncExtensionFunction() {} |
56 | 82 |
57 ExtensionFunction::ResponseAction ChromeAsyncExtensionFunction::Run() { | 83 ExtensionFunction::ResponseAction ChromeAsyncExtensionFunction::Run() { |
58 return RunAsync() ? RespondLater() : RespondNow(Error(error_)); | 84 if (RunAsync()) |
| 85 return RespondLater(); |
| 86 // TODO(devlin): Track these down and eliminate them if possible. We |
| 87 // shouldn't return results and an error. |
| 88 if (results_) |
| 89 return RespondNow(ErrorWithArguments(std::move(results_), error_)); |
| 90 return RespondNow(Error(error_)); |
59 } | 91 } |
60 | 92 |
61 // static | 93 // static |
62 bool ChromeAsyncExtensionFunction::ValidationFailure( | 94 bool ChromeAsyncExtensionFunction::ValidationFailure( |
63 ChromeAsyncExtensionFunction* function) { | 95 ChromeAsyncExtensionFunction* function) { |
64 return false; | 96 return false; |
65 } | 97 } |
66 | 98 |
67 ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() { | 99 ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() { |
68 } | 100 } |
69 | 101 |
70 ChromeSyncExtensionFunction::~ChromeSyncExtensionFunction() {} | 102 ChromeSyncExtensionFunction::~ChromeSyncExtensionFunction() {} |
71 | 103 |
72 ExtensionFunction::ResponseAction ChromeSyncExtensionFunction::Run() { | 104 ExtensionFunction::ResponseAction ChromeSyncExtensionFunction::Run() { |
73 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) | 105 if (!RunSync()) { |
74 : Error(error_)); | 106 DCHECK(!results_); |
| 107 return RespondNow(Error(error_)); |
| 108 } |
| 109 return RespondNow(ArgumentList(std::move(results_))); |
75 } | 110 } |
76 | 111 |
77 // static | 112 // static |
78 bool ChromeSyncExtensionFunction::ValidationFailure( | 113 bool ChromeSyncExtensionFunction::ValidationFailure( |
79 ChromeSyncExtensionFunction* function) { | 114 ChromeSyncExtensionFunction* function) { |
80 return false; | 115 return false; |
81 } | 116 } |
OLD | NEW |