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

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: nits. Created 5 years, 10 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 17 matching lines...) Expand all
28 const char kBadFileEncodingError[] = 28 const char kBadFileEncodingError[] =
29 "Could not load file '*' for content script. It isn't UTF-8 encoded."; 29 "Could not load file '*' for content script. It isn't UTF-8 encoded.";
30 const char kLoadFileError[] = "Failed to load file: \"*\". "; 30 const char kLoadFileError[] = "Failed to load file: \"*\". ";
31 31
32 } 32 }
33 33
34 namespace extensions { 34 namespace extensions {
35 35
36 using core_api::extension_types::InjectDetails; 36 using core_api::extension_types::InjectDetails;
37 37
38 ExecuteCodeFunction::ExecuteCodeFunction() { 38 ExecuteCodeFunction::ExecuteCodeFunction()
39 : host_id_(new HostID()) {
Devlin 2015/02/25 17:22:36 Why is this is a scoped ptr if it's never null?
Xi Han 2015/02/26 15:13:45 Because we want to set its value in the init() fun
Devlin 2015/02/26 17:35:24 But we can just do host_id_ = HostId(foo, bar), ri
Xi Han 2015/02/26 19:58:00 You are right:) Sorry I was in the old memory that
39 } 40 }
40 41
41 ExecuteCodeFunction::~ExecuteCodeFunction() { 42 ExecuteCodeFunction::~ExecuteCodeFunction() {
42 } 43 }
43 44
44 void ExecuteCodeFunction::DidLoadFile(bool success, const std::string& data) { 45 void ExecuteCodeFunction::DidLoadFile(bool success, const std::string& data) {
45 if (!success || !details_->file) { 46 if (!success || !details_->file) {
46 DidLoadAndLocalizeFile(success, data); 47 DidLoadAndLocalizeFile(success, data);
47 return; 48 return;
48 } 49 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 kLoadFileError, resource_.relative_path().AsUTF8Unsafe()); 123 kLoadFileError, resource_.relative_path().AsUTF8Unsafe());
123 SendResponse(false); 124 SendResponse(false);
124 } 125 }
125 } 126 }
126 127
127 bool ExecuteCodeFunction::Execute(const std::string& code_string) { 128 bool ExecuteCodeFunction::Execute(const std::string& code_string) {
128 ScriptExecutor* executor = GetScriptExecutor(); 129 ScriptExecutor* executor = GetScriptExecutor();
129 if (!executor) 130 if (!executor)
130 return false; 131 return false;
131 132
132 if (!extension()) 133 if (!extension() && !IsWebView())
133 return false; 134 return false;
134 135
135 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; 136 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT;
136 if (ShouldInsertCSS()) 137 if (ShouldInsertCSS())
137 script_type = ScriptExecutor::CSS; 138 script_type = ScriptExecutor::CSS;
138 139
139 ScriptExecutor::FrameScope frame_scope = 140 ScriptExecutor::FrameScope frame_scope =
140 details_->all_frames.get() && *details_->all_frames 141 details_->all_frames.get() && *details_->all_frames
141 ? ScriptExecutor::ALL_FRAMES 142 ? ScriptExecutor::ALL_FRAMES
142 : ScriptExecutor::TOP_FRAME; 143 : ScriptExecutor::TOP_FRAME;
(...skipping 12 matching lines...) Expand all
155 case InjectDetails::RUN_AT_DOCUMENT_START: 156 case InjectDetails::RUN_AT_DOCUMENT_START:
156 run_at = UserScript::DOCUMENT_START; 157 run_at = UserScript::DOCUMENT_START;
157 break; 158 break;
158 case InjectDetails::RUN_AT_DOCUMENT_END: 159 case InjectDetails::RUN_AT_DOCUMENT_END:
159 run_at = UserScript::DOCUMENT_END; 160 run_at = UserScript::DOCUMENT_END;
160 break; 161 break;
161 } 162 }
162 CHECK_NE(UserScript::UNDEFINED, run_at); 163 CHECK_NE(UserScript::UNDEFINED, run_at);
163 164
164 executor->ExecuteScript( 165 executor->ExecuteScript(
165 extension()->id(), 166 host_id_->type(),
167 host_id_->id(),
166 script_type, 168 script_type,
167 code_string, 169 code_string,
168 frame_scope, 170 frame_scope,
169 match_about_blank, 171 match_about_blank,
170 run_at, 172 run_at,
171 ScriptExecutor::ISOLATED_WORLD, 173 ScriptExecutor::ISOLATED_WORLD,
172 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS 174 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS
173 : ScriptExecutor::DEFAULT_PROCESS, 175 : ScriptExecutor::DEFAULT_PROCESS,
174 GetWebViewSrc(), 176 GetWebViewSrc(),
175 file_url_, 177 file_url_,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const base::ListValue& result) { 239 const base::ListValue& result) {
238 if (!error.empty()) 240 if (!error.empty())
239 SetError(error); 241 SetError(error);
240 242
241 SendResponse(error.empty()); 243 SendResponse(error.empty());
242 } 244 }
243 245
244 } // namespace extensions 246 } // namespace extensions
245 247
246 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ 248 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698