| 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" |
| 11 #include "extensions/browser/extension_api_frame_id_map.h" |
| 11 #include "extensions/browser/extensions_browser_client.h" | 12 #include "extensions/browser/extensions_browser_client.h" |
| 12 #include "extensions/browser/file_reader.h" | 13 #include "extensions/browser/file_reader.h" |
| 13 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
| 14 #include "extensions/common/extension_messages.h" | 15 #include "extensions/common/extension_messages.h" |
| 15 #include "extensions/common/file_util.h" | 16 #include "extensions/common/file_util.h" |
| 16 #include "extensions/common/manifest_constants.h" | 17 #include "extensions/common/manifest_constants.h" |
| 17 #include "extensions/common/message_bundle.h" | 18 #include "extensions/common/message_bundle.h" |
| 18 #include "net/base/filename_util.h" | 19 #include "net/base/filename_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 | 21 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 133 |
| 133 if (!extension() && !IsWebView()) | 134 if (!extension() && !IsWebView()) |
| 134 return false; | 135 return false; |
| 135 | 136 |
| 136 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; | 137 ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT; |
| 137 if (ShouldInsertCSS()) | 138 if (ShouldInsertCSS()) |
| 138 script_type = ScriptExecutor::CSS; | 139 script_type = ScriptExecutor::CSS; |
| 139 | 140 |
| 140 ScriptExecutor::FrameScope frame_scope = | 141 ScriptExecutor::FrameScope frame_scope = |
| 141 details_->all_frames.get() && *details_->all_frames | 142 details_->all_frames.get() && *details_->all_frames |
| 142 ? ScriptExecutor::ALL_FRAMES | 143 ? ScriptExecutor::INCLUDE_SUB_FRAMES |
| 143 : ScriptExecutor::TOP_FRAME; | 144 : ScriptExecutor::SINGLE_FRAME; |
| 145 |
| 146 int frame_id = details_->frame_id.get() ? *details_->frame_id |
| 147 : ExtensionApiFrameIdMap::kTopFrameId; |
| 144 | 148 |
| 145 ScriptExecutor::MatchAboutBlank match_about_blank = | 149 ScriptExecutor::MatchAboutBlank match_about_blank = |
| 146 details_->match_about_blank.get() && *details_->match_about_blank | 150 details_->match_about_blank.get() && *details_->match_about_blank |
| 147 ? ScriptExecutor::MATCH_ABOUT_BLANK | 151 ? ScriptExecutor::MATCH_ABOUT_BLANK |
| 148 : ScriptExecutor::DONT_MATCH_ABOUT_BLANK; | 152 : ScriptExecutor::DONT_MATCH_ABOUT_BLANK; |
| 149 | 153 |
| 150 UserScript::RunLocation run_at = UserScript::UNDEFINED; | 154 UserScript::RunLocation run_at = UserScript::UNDEFINED; |
| 151 switch (details_->run_at) { | 155 switch (details_->run_at) { |
| 152 case api::extension_types::RUN_AT_NONE: | 156 case api::extension_types::RUN_AT_NONE: |
| 153 case api::extension_types::RUN_AT_DOCUMENT_IDLE: | 157 case api::extension_types::RUN_AT_DOCUMENT_IDLE: |
| 154 run_at = UserScript::DOCUMENT_IDLE; | 158 run_at = UserScript::DOCUMENT_IDLE; |
| 155 break; | 159 break; |
| 156 case api::extension_types::RUN_AT_DOCUMENT_START: | 160 case api::extension_types::RUN_AT_DOCUMENT_START: |
| 157 run_at = UserScript::DOCUMENT_START; | 161 run_at = UserScript::DOCUMENT_START; |
| 158 break; | 162 break; |
| 159 case api::extension_types::RUN_AT_DOCUMENT_END: | 163 case api::extension_types::RUN_AT_DOCUMENT_END: |
| 160 run_at = UserScript::DOCUMENT_END; | 164 run_at = UserScript::DOCUMENT_END; |
| 161 break; | 165 break; |
| 162 } | 166 } |
| 163 CHECK_NE(UserScript::UNDEFINED, run_at); | 167 CHECK_NE(UserScript::UNDEFINED, run_at); |
| 164 | 168 |
| 165 executor->ExecuteScript( | 169 executor->ExecuteScript( |
| 166 host_id_, | 170 host_id_, script_type, code_string, frame_scope, frame_id, |
| 167 script_type, | 171 match_about_blank, run_at, ScriptExecutor::ISOLATED_WORLD, |
| 168 code_string, | |
| 169 frame_scope, | |
| 170 match_about_blank, | |
| 171 run_at, | |
| 172 ScriptExecutor::ISOLATED_WORLD, | |
| 173 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS | 172 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS |
| 174 : ScriptExecutor::DEFAULT_PROCESS, | 173 : ScriptExecutor::DEFAULT_PROCESS, |
| 175 GetWebViewSrc(), | 174 GetWebViewSrc(), file_url_, user_gesture_, |
| 176 file_url_, | |
| 177 user_gesture_, | |
| 178 has_callback() ? ScriptExecutor::JSON_SERIALIZED_RESULT | 175 has_callback() ? ScriptExecutor::JSON_SERIALIZED_RESULT |
| 179 : ScriptExecutor::NO_RESULT, | 176 : ScriptExecutor::NO_RESULT, |
| 180 base::Bind(&ExecuteCodeFunction::OnExecuteCodeFinished, this)); | 177 base::Bind(&ExecuteCodeFunction::OnExecuteCodeFinished, this)); |
| 181 return true; | 178 return true; |
| 182 } | 179 } |
| 183 | 180 |
| 184 bool ExecuteCodeFunction::HasPermission() { | 181 bool ExecuteCodeFunction::HasPermission() { |
| 185 return true; | 182 return true; |
| 186 } | 183 } |
| 187 | 184 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 const base::ListValue& result) { | 240 const base::ListValue& result) { |
| 244 if (!error.empty()) | 241 if (!error.empty()) |
| 245 SetError(error); | 242 SetError(error); |
| 246 | 243 |
| 247 SendResponse(error.empty()); | 244 SendResponse(error.empty()); |
| 248 } | 245 } |
| 249 | 246 |
| 250 } // namespace extensions | 247 } // namespace extensions |
| 251 | 248 |
| 252 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ | 249 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_IMPL_H_ |
| OLD | NEW |