OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ |
6 #define EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ | 6 #define EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ |
7 | 7 |
8 #include "extensions/browser/api/execute_code_function.h" | 8 #include "extensions/browser/api/execute_code_function.h" |
9 | 9 |
10 #include "extensions/browser/component_extension_resource_manager.h" | 10 #include "extensions/browser/component_extension_resource_manager.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 namespace extensions { | 34 namespace extensions { |
35 | 35 |
36 using core_api::extension_types::InjectDetails; | 36 using core_api::extension_types::InjectDetails; |
37 | 37 |
38 ExecuteCodeFunction::ExecuteCodeFunction() { | 38 ExecuteCodeFunction::ExecuteCodeFunction() { |
39 } | 39 } |
40 | 40 |
41 ExecuteCodeFunction::~ExecuteCodeFunction() { | 41 ExecuteCodeFunction::~ExecuteCodeFunction() { |
42 } | 42 } |
43 | 43 |
44 bool ExecuteCodeFunction::LoadFileForWebUI( | |
45 const std::string& file_src, | |
46 const WebUILoadFileCallback& callback) { | |
47 callback.Run(false, std::string()); | |
48 return false; | |
49 } | |
50 | |
44 void ExecuteCodeFunction::DidLoadFile(bool success, const std::string& data) { | 51 void ExecuteCodeFunction::DidLoadFile(bool success, const std::string& data) { |
45 if (!success || !details_->file) { | 52 if (!success || !details_->file) { |
46 DidLoadAndLocalizeFile(success, data); | 53 DidLoadAndLocalizeFile(success, data); |
47 return; | 54 return; |
48 } | 55 } |
49 | 56 |
50 ScriptExecutor::ScriptType script_type = | 57 ScriptExecutor::ScriptType script_type = |
51 ShouldInsertCSS() ? ScriptExecutor::CSS : ScriptExecutor::JAVASCRIPT; | 58 ShouldInsertCSS() ? ScriptExecutor::CSS : ScriptExecutor::JAVASCRIPT; |
52 | 59 |
53 std::string extension_id; | 60 std::string extension_id; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 SendResponse(false); | 124 SendResponse(false); |
118 } else { | 125 } else { |
119 // TODO(viettrungluu): bug: there's no particular reason the path should be | 126 // TODO(viettrungluu): bug: there's no particular reason the path should be |
120 // UTF-8, in which case this may fail. | 127 // UTF-8, in which case this may fail. |
121 error_ = ErrorUtils::FormatErrorMessage( | 128 error_ = ErrorUtils::FormatErrorMessage( |
122 kLoadFileError, resource_.relative_path().AsUTF8Unsafe()); | 129 kLoadFileError, resource_.relative_path().AsUTF8Unsafe()); |
123 SendResponse(false); | 130 SendResponse(false); |
124 } | 131 } |
125 } | 132 } |
126 | 133 |
134 void ExecuteCodeFunction::DidLoadFileForWebUI(bool success, | |
135 const std::string& data) { | |
136 if (success) { | |
137 if (!base::IsStringUTF8(data)) | |
138 SendResponse(false); | |
139 else if (!Execute(data)) | |
140 SendResponse(false); | |
141 } else { | |
142 SendResponse(false); | |
143 } | |
144 } | |
145 | |
127 bool ExecuteCodeFunction::Execute(const std::string& code_string) { | 146 bool ExecuteCodeFunction::Execute(const std::string& code_string) { |
128 ScriptExecutor* executor = GetScriptExecutor(); | 147 ScriptExecutor* executor = GetScriptExecutor(); |
129 if (!executor) | 148 if (!executor) |
130 return false; | 149 return false; |
131 | 150 |
132 if (!extension() && !IsWebView()) | 151 if (!extension() && !IsWebView()) |
133 return false; | 152 return false; |
134 | 153 |
135 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; | 154 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; |
136 if (ShouldInsertCSS()) | 155 if (ShouldInsertCSS()) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 | 217 |
199 if (!CanExecuteScriptOnPage()) | 218 if (!CanExecuteScriptOnPage()) |
200 return false; | 219 return false; |
201 | 220 |
202 if (details_->code.get()) | 221 if (details_->code.get()) |
203 return Execute(*details_->code); | 222 return Execute(*details_->code); |
204 | 223 |
205 if (!details_->file.get()) | 224 if (!details_->file.get()) |
206 return false; | 225 return false; |
207 | 226 |
208 if (!extension()) | 227 if (!extension()) { |
asargent_no_longer_on_chrome
2015/03/17 21:41:14
should this test be "if (IsWebView())" instead of
Xi Han
2015/03/17 22:28:21
This is for webUI, which we have to use different
| |
209 return false; | 228 bool is_success = false; |
229 is_success = LoadFileForWebUI( | |
230 *details_->file, | |
231 base::Bind(&ExecuteCodeFunction::DidLoadFileForWebUI, this)); | |
232 if (!is_success) { | |
233 SendResponse(false); | |
234 return false; | |
235 } | |
236 // Will finish asynchronously. | |
237 return true; | |
238 } | |
asargent_no_longer_on_chrome
2015/03/17 21:41:14
Also, can you explain why this code is here in thi
Xi Han
2015/03/17 22:28:21
That is fair. Move them back to web_view_internal_
| |
210 | 239 |
211 resource_ = extension()->GetResource(*details_->file); | 240 resource_ = extension()->GetResource(*details_->file); |
212 | 241 |
213 if (resource_.extension_root().empty() || resource_.relative_path().empty()) { | 242 if (resource_.extension_root().empty() || resource_.relative_path().empty()) { |
214 error_ = kNoCodeOrFileToExecuteError; | 243 error_ = kNoCodeOrFileToExecuteError; |
215 return false; | 244 return false; |
216 } | 245 } |
217 | 246 |
218 int resource_id; | 247 int resource_id; |
219 const ComponentExtensionResourceManager* | 248 const ComponentExtensionResourceManager* |
(...skipping 21 matching lines...) Expand all Loading... | |
241 const base::ListValue& result) { | 270 const base::ListValue& result) { |
242 if (!error.empty()) | 271 if (!error.empty()) |
243 SetError(error); | 272 SetError(error); |
244 | 273 |
245 SendResponse(error.empty()); | 274 SendResponse(error.empty()); |
246 } | 275 } |
247 | 276 |
248 } // namespace extensions | 277 } // namespace extensions |
249 | 278 |
250 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ | 279 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ |
OLD | NEW |