| OLD | NEW |
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (!extension()) | 132 if (!extension()) |
| 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::ONE_FRAME; |
| 143 |
| 144 // If a frame_id is given, use it. Otherwise, use the top-level frame (0). |
| 145 int frame_id = details_->frame_id.get() ? *details_->frame_id : 0; |
| 143 | 146 |
| 144 ScriptExecutor::MatchAboutBlank match_about_blank = | 147 ScriptExecutor::MatchAboutBlank match_about_blank = |
| 145 details_->match_about_blank.get() && *details_->match_about_blank | 148 details_->match_about_blank.get() && *details_->match_about_blank |
| 146 ? ScriptExecutor::MATCH_ABOUT_BLANK | 149 ? ScriptExecutor::MATCH_ABOUT_BLANK |
| 147 : ScriptExecutor::DONT_MATCH_ABOUT_BLANK; | 150 : ScriptExecutor::DONT_MATCH_ABOUT_BLANK; |
| 148 | 151 |
| 149 UserScript::RunLocation run_at = UserScript::UNDEFINED; | 152 UserScript::RunLocation run_at = UserScript::UNDEFINED; |
| 150 switch (details_->run_at) { | 153 switch (details_->run_at) { |
| 151 case InjectDetails::RUN_AT_NONE: | 154 case InjectDetails::RUN_AT_NONE: |
| 152 case InjectDetails::RUN_AT_DOCUMENT_IDLE: | 155 case InjectDetails::RUN_AT_DOCUMENT_IDLE: |
| 153 run_at = UserScript::DOCUMENT_IDLE; | 156 run_at = UserScript::DOCUMENT_IDLE; |
| 154 break; | 157 break; |
| 155 case InjectDetails::RUN_AT_DOCUMENT_START: | 158 case InjectDetails::RUN_AT_DOCUMENT_START: |
| 156 run_at = UserScript::DOCUMENT_START; | 159 run_at = UserScript::DOCUMENT_START; |
| 157 break; | 160 break; |
| 158 case InjectDetails::RUN_AT_DOCUMENT_END: | 161 case InjectDetails::RUN_AT_DOCUMENT_END: |
| 159 run_at = UserScript::DOCUMENT_END; | 162 run_at = UserScript::DOCUMENT_END; |
| 160 break; | 163 break; |
| 161 } | 164 } |
| 162 CHECK_NE(UserScript::UNDEFINED, run_at); | 165 CHECK_NE(UserScript::UNDEFINED, run_at); |
| 163 | 166 |
| 164 executor->ExecuteScript( | 167 executor->ExecuteScript( |
| 165 extension()->id(), | 168 extension()->id(), |
| 166 script_type, | 169 script_type, |
| 167 code_string, | 170 code_string, |
| 168 frame_scope, | 171 frame_scope, |
| 172 frame_id, |
| 169 match_about_blank, | 173 match_about_blank, |
| 170 run_at, | 174 run_at, |
| 171 ScriptExecutor::ISOLATED_WORLD, | 175 ScriptExecutor::ISOLATED_WORLD, |
| 172 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS | 176 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS |
| 173 : ScriptExecutor::DEFAULT_PROCESS, | 177 : ScriptExecutor::DEFAULT_PROCESS, |
| 174 GetWebViewSrc(), | 178 GetWebViewSrc(), |
| 175 file_url_, | 179 file_url_, |
| 176 user_gesture_, | 180 user_gesture_, |
| 177 has_callback() ? ScriptExecutor::JSON_SERIALIZED_RESULT | 181 has_callback() ? ScriptExecutor::JSON_SERIALIZED_RESULT |
| 178 : ScriptExecutor::NO_RESULT, | 182 : ScriptExecutor::NO_RESULT, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_ |
| OLD | NEW |