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

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: Devlin's comments. 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..a1c2599cdfe4cce564808e4695a49c7434daaf8e 100644
--- a/extensions/browser/api/execute_code_function.cc
+++ b/extensions/browser/api/execute_code_function.cc
@@ -108,18 +108,22 @@ void ExecuteCodeFunction::GetFileURLAndLocalizeCSS(
void ExecuteCodeFunction::DidLoadAndLocalizeFile(bool success,
const std::string& data) {
+ DidLoadFileForHost(resource_.relative_path().AsUTF8Unsafe(), success, data);
+}
+
+void ExecuteCodeFunction::DidLoadFileForHost(const std::string& file,
Devlin 2015/03/25 17:55:15 Why not just make DidLoadAndLocalizeFile() take in
Xi Han 2015/03/25 20:49:21 That is much simpler! Thanks!
+ bool success,
+ const std::string& data) {
if (success) {
if (!base::IsStringUTF8(data)) {
- error_ = ErrorUtils::FormatErrorMessage(
- kBadFileEncodingError, resource_.relative_path().AsUTF8Unsafe());
+ error_ = ErrorUtils::FormatErrorMessage(kBadFileEncodingError, file);
SendResponse(false);
} else if (!Execute(data))
SendResponse(false);
} else {
// TODO(viettrungluu): bug: there's no particular reason the path should be
// UTF-8, in which case this may fail.
- error_ = ErrorUtils::FormatErrorMessage(
- kLoadFileError, resource_.relative_path().AsUTF8Unsafe());
+ error_ = ErrorUtils::FormatErrorMessage(kLoadFileError, file);
SendResponse(false);
}
}
@@ -205,10 +209,11 @@ bool ExecuteCodeFunction::RunAsync() {
if (!details_->file.get())
return false;
- if (!extension())
- return false;
+ return LoadFile(*details_->file);
+}
- resource_ = extension()->GetResource(*details_->file);
+bool ExecuteCodeFunction::LoadFile(const std::string& file) {
+ resource_ = extension()->GetResource(file);
if (resource_.extension_root().empty() || resource_.relative_path().empty()) {
error_ = kNoCodeOrFileToExecuteError;

Powered by Google App Engine
This is Rietveld 408576698