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

Side by Side Diff: extensions/browser/api/execute_code_function.cc

Issue 1004253002: Enable <webview>.executeScript outside of Apps and Extensions [2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 SendResponse(false); 117 SendResponse(false);
118 } else { 118 } else {
119 // TODO(viettrungluu): bug: there's no particular reason the path should be 119 // TODO(viettrungluu): bug: there's no particular reason the path should be
120 // UTF-8, in which case this may fail. 120 // UTF-8, in which case this may fail.
121 error_ = ErrorUtils::FormatErrorMessage( 121 error_ = ErrorUtils::FormatErrorMessage(
122 kLoadFileError, resource_.relative_path().AsUTF8Unsafe()); 122 kLoadFileError, resource_.relative_path().AsUTF8Unsafe());
123 SendResponse(false); 123 SendResponse(false);
124 } 124 }
125 } 125 }
126 126
127 void ExecuteCodeFunction::DidLoadFileForWebUI(bool success,
128 const std::string& data) {
129 if (success) {
130 if (!base::IsStringUTF8(data))
131 SendResponse(false);
132 else if (!Execute(data))
133 SendResponse(false);
134 } else {
135 SendResponse(false);
136 }
137 }
138
127 bool ExecuteCodeFunction::Execute(const std::string& code_string) { 139 bool ExecuteCodeFunction::Execute(const std::string& code_string) {
128 ScriptExecutor* executor = GetScriptExecutor(); 140 ScriptExecutor* executor = GetScriptExecutor();
129 if (!executor) 141 if (!executor)
130 return false; 142 return false;
131 143
132 if (!extension() && !IsWebView()) 144 if (!extension() && !IsWebView())
133 return false; 145 return false;
134 146
135 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; 147 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT;
136 if (ShouldInsertCSS()) 148 if (ShouldInsertCSS())
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 210
199 if (!CanExecuteScriptOnPage()) 211 if (!CanExecuteScriptOnPage())
200 return false; 212 return false;
201 213
202 if (details_->code.get()) 214 if (details_->code.get())
203 return Execute(*details_->code); 215 return Execute(*details_->code);
204 216
205 if (!details_->file.get()) 217 if (!details_->file.get())
206 return false; 218 return false;
207 219
208 if (!extension()) 220 if (!extension()) {
209 return false; 221 bool is_success = false;
222 is_success = LoadFileForWebUI(
223 *details_->file,
224 base::Bind(&ExecuteCodeFunction::DidLoadFileForWebUI, this));
225 if (!is_success) {
226 SendResponse(false);
227 return false;
228 }
229 // Will finish asynchronously.
230 return true;
231 }
210 232
211 resource_ = extension()->GetResource(*details_->file); 233 resource_ = extension()->GetResource(*details_->file);
212 234
213 if (resource_.extension_root().empty() || resource_.relative_path().empty()) { 235 if (resource_.extension_root().empty() || resource_.relative_path().empty()) {
214 error_ = kNoCodeOrFileToExecuteError; 236 error_ = kNoCodeOrFileToExecuteError;
215 return false; 237 return false;
216 } 238 }
217 239
218 int resource_id; 240 int resource_id;
219 const ComponentExtensionResourceManager* 241 const ComponentExtensionResourceManager*
(...skipping 21 matching lines...) Expand all
241 const base::ListValue& result) { 263 const base::ListValue& result) {
242 if (!error.empty()) 264 if (!error.empty())
243 SetError(error); 265 SetError(error);
244 266
245 SendResponse(error.empty()); 267 SendResponse(error.empty());
246 } 268 }
247 269
248 } // namespace extensions 270 } // namespace extensions
249 271
250 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ 272 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698