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

Unified 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: Add a test. 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/execute_code_function.cc
diff --git a/extensions/browser/api/execute_code_function.cc b/extensions/browser/api/execute_code_function.cc
index aebf61f46b4dd9dcec948e8cfa5326fea796cef3..ce4b29cfc2c9f68c070d35c3754cd639de4c2230 100644
--- a/extensions/browser/api/execute_code_function.cc
+++ b/extensions/browser/api/execute_code_function.cc
@@ -124,6 +124,18 @@ void ExecuteCodeFunction::DidLoadAndLocalizeFile(bool success,
}
}
+void ExecuteCodeFunction::DidLoadFileForWebUI(bool success,
+ const std::string& data) {
+ if (success) {
+ if (!base::IsStringUTF8(data))
+ SendResponse(false);
+ else if (!Execute(data))
+ SendResponse(false);
+ } else {
+ SendResponse(false);
+ }
+}
+
bool ExecuteCodeFunction::Execute(const std::string& code_string) {
ScriptExecutor* executor = GetScriptExecutor();
if (!executor)
@@ -205,8 +217,18 @@ bool ExecuteCodeFunction::RunAsync() {
if (!details_->file.get())
return false;
- if (!extension())
- return false;
+ if (!extension()) {
+ bool is_success = false;
+ is_success = LoadFileForWebUI(
Devlin 2015/03/18 16:52:27 Can we abstract this and the logic to get a file f
Xi Han 2015/03/18 20:36:26 It is a good suggestion, but the logic of LoadFile
+ *details_->file,
+ base::Bind(&ExecuteCodeFunction::DidLoadFileForWebUI, this));
+ if (!is_success) {
+ SendResponse(false);
+ return false;
+ }
+ // Will finish asynchronously.
+ return true;
+ }
resource_ = extension()->GetResource(*details_->file);

Powered by Google App Engine
This is Rietveld 408576698