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

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: nits 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..394d0dd5deec884a97350d817891956367b516ef 100644
--- a/extensions/browser/api/execute_code_function.cc
+++ b/extensions/browser/api/execute_code_function.cc
@@ -41,6 +41,13 @@ ExecuteCodeFunction::ExecuteCodeFunction() {
ExecuteCodeFunction::~ExecuteCodeFunction() {
}
+bool ExecuteCodeFunction::LoadFileForWebUI(
+ const std::string& file_src,
+ const WebUILoadFileCallback& callback) {
+ callback.Run(false, std::string());
+ return false;
+}
+
void ExecuteCodeFunction::DidLoadFile(bool success, const std::string& data) {
if (!success || !details_->file) {
DidLoadAndLocalizeFile(success, data);
@@ -124,6 +131,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 +224,18 @@ bool ExecuteCodeFunction::RunAsync() {
if (!details_->file.get())
return false;
- if (!extension())
- return false;
+ if (!extension()) {
+ bool is_success = false;
+ is_success = LoadFileForWebUI(
+ *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