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

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

Issue 942533003: Enable <webview>.executeScript outside of Apps and Extensions [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_routingid_user_script_UserScriptSet_non_hostset_2
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 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool ExecuteCodeFunction::Execute(const std::string& code_string) { 127 bool ExecuteCodeFunction::Execute(const std::string& code_string) {
128 ScriptExecutor* executor = GetScriptExecutor(); 128 ScriptExecutor* executor = GetScriptExecutor();
129 if (!executor) 129 if (!executor)
130 return false; 130 return false;
131 131
132 if (!extension()) 132 if (!extension() && !IsWebView())
133 return false; 133 return false;
134 134
135 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; 135 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT;
136 if (ShouldInsertCSS()) 136 if (ShouldInsertCSS())
137 script_type = ScriptExecutor::CSS; 137 script_type = ScriptExecutor::CSS;
138 138
139 ScriptExecutor::FrameScope frame_scope = 139 ScriptExecutor::FrameScope frame_scope =
140 details_->all_frames.get() && *details_->all_frames 140 details_->all_frames.get() && *details_->all_frames
141 ? ScriptExecutor::ALL_FRAMES 141 ? ScriptExecutor::ALL_FRAMES
142 : ScriptExecutor::TOP_FRAME; 142 : ScriptExecutor::TOP_FRAME;
(...skipping 12 matching lines...) Expand all
155 case InjectDetails::RUN_AT_DOCUMENT_START: 155 case InjectDetails::RUN_AT_DOCUMENT_START:
156 run_at = UserScript::DOCUMENT_START; 156 run_at = UserScript::DOCUMENT_START;
157 break; 157 break;
158 case InjectDetails::RUN_AT_DOCUMENT_END: 158 case InjectDetails::RUN_AT_DOCUMENT_END:
159 run_at = UserScript::DOCUMENT_END; 159 run_at = UserScript::DOCUMENT_END;
160 break; 160 break;
161 } 161 }
162 CHECK_NE(UserScript::UNDEFINED, run_at); 162 CHECK_NE(UserScript::UNDEFINED, run_at);
163 163
164 executor->ExecuteScript( 164 executor->ExecuteScript(
165 extension()->id(), 165 host_id_,
166 script_type, 166 script_type,
167 code_string, 167 code_string,
168 frame_scope, 168 frame_scope,
169 match_about_blank, 169 match_about_blank,
170 run_at, 170 run_at,
171 ScriptExecutor::ISOLATED_WORLD, 171 ScriptExecutor::ISOLATED_WORLD,
172 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS 172 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS
173 : ScriptExecutor::DEFAULT_PROCESS, 173 : ScriptExecutor::DEFAULT_PROCESS,
174 GetWebViewSrc(), 174 GetWebViewSrc(),
175 file_url_, 175 file_url_,
(...skipping 21 matching lines...) Expand all
197 } 197 }
198 198
199 if (!CanExecuteScriptOnPage()) 199 if (!CanExecuteScriptOnPage())
200 return false; 200 return false;
201 201
202 if (details_->code.get()) 202 if (details_->code.get())
203 return Execute(*details_->code); 203 return Execute(*details_->code);
204 204
205 if (!details_->file.get()) 205 if (!details_->file.get())
206 return false; 206 return false;
207
208 if (!extension())
209 return false;
210
207 resource_ = extension()->GetResource(*details_->file); 211 resource_ = extension()->GetResource(*details_->file);
208 212
209 if (resource_.extension_root().empty() || resource_.relative_path().empty()) { 213 if (resource_.extension_root().empty() || resource_.relative_path().empty()) {
210 error_ = kNoCodeOrFileToExecuteError; 214 error_ = kNoCodeOrFileToExecuteError;
211 return false; 215 return false;
212 } 216 }
213 217
214 int resource_id; 218 int resource_id;
215 const ComponentExtensionResourceManager* 219 const ComponentExtensionResourceManager*
216 component_extension_resource_manager = 220 component_extension_resource_manager =
(...skipping 20 matching lines...) Expand all
237 const base::ListValue& result) { 241 const base::ListValue& result) {
238 if (!error.empty()) 242 if (!error.empty())
239 SetError(error); 243 SetError(error);
240 244
241 SendResponse(error.empty()); 245 SendResponse(error.empty());
242 } 246 }
243 247
244 } // namespace extensions 248 } // namespace extensions
245 249
246 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ 250 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698