| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h" | 5 #include "chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/api/tabs/tabs.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/extensions/extension_tab_helper.h" | 14 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 15 #include "chrome/browser/extensions/file_reader.h" | 15 #include "chrome/browser/extensions/file_reader.h" |
| 16 #include "chrome/browser/extensions/script_executor.h" | 16 #include "chrome/browser/extensions/script_executor.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 22 #include "chrome/common/extensions/extension_error_utils.h" | 22 #include "chrome/common/extensions/extension_error_utils.h" |
| 23 #include "chrome/common/extensions/extension_file_util.h" | 23 #include "chrome/common/extensions/extension_file_util.h" |
| 24 #include "chrome/common/extensions/extension_l10n_util.h" | 24 #include "chrome/common/extensions/extension_l10n_util.h" |
| 25 #include "chrome/common/extensions/extension_manifest_constants.h" | 25 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 26 #include "chrome/common/extensions/extension_message_bundle.h" | 26 #include "chrome/common/extensions/extension_message_bundle.h" |
| 27 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
| 28 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 55 error_ = keys::kMoreThanOneValuesError; | 55 error_ = keys::kMoreThanOneValuesError; |
| 56 return false; | 56 return false; |
| 57 } else if (!has_code && !has_file) { | 57 } else if (!has_code && !has_file) { |
| 58 error_ = keys::kNoCodeOrFileToExecuteError; | 58 error_ = keys::kNoCodeOrFileToExecuteError; |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 execute_tab_id_ = -1; | 63 execute_tab_id_ = -1; |
| 64 Browser* browser = NULL; | 64 Browser* browser = NULL; |
| 65 TabContentsWrapper* contents = NULL; | 65 TabContents* contents = NULL; |
| 66 | 66 |
| 67 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 67 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
| 68 // in the current window. | 68 // in the current window. |
| 69 Value* tab_value = NULL; | 69 Value* tab_value = NULL; |
| 70 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 70 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 71 if (tab_value->IsType(Value::TYPE_NULL)) { | 71 if (tab_value->IsType(Value::TYPE_NULL)) { |
| 72 browser = GetCurrentBrowser(); | 72 browser = GetCurrentBrowser(); |
| 73 if (!browser) { | 73 if (!browser) { |
| 74 error_ = keys::kNoCurrentWindowError; | 74 error_ = keys::kNoCurrentWindowError; |
| 75 return false; | 75 return false; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 resource_.relative_path().value()); | 213 resource_.relative_path().value()); |
| 214 #elif defined(OS_WIN) | 214 #elif defined(OS_WIN) |
| 215 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kLoadFileError, | 215 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kLoadFileError, |
| 216 WideToUTF8(resource_.relative_path().value())); | 216 WideToUTF8(resource_.relative_path().value())); |
| 217 #endif // OS_WIN | 217 #endif // OS_WIN |
| 218 SendResponse(false); | 218 SendResponse(false); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool ExecuteCodeInTabFunction::Execute(const std::string& code_string) { | 222 bool ExecuteCodeInTabFunction::Execute(const std::string& code_string) { |
| 223 TabContentsWrapper* contents = NULL; | 223 TabContents* contents = NULL; |
| 224 Browser* browser = NULL; | 224 Browser* browser = NULL; |
| 225 | 225 |
| 226 bool success = ExtensionTabUtil::GetTabById( | 226 bool success = ExtensionTabUtil::GetTabById( |
| 227 execute_tab_id_, profile(), include_incognito(), &browser, NULL, | 227 execute_tab_id_, profile(), include_incognito(), &browser, NULL, |
| 228 &contents, NULL) && contents && browser; | 228 &contents, NULL) && contents && browser; |
| 229 | 229 |
| 230 if (!success) { | 230 if (!success) { |
| 231 SendResponse(false); | 231 SendResponse(false); |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 249 contents->extension_tab_helper()->script_executor()->ExecuteScript( | 249 contents->extension_tab_helper()->script_executor()->ExecuteScript( |
| 250 extension->id(), | 250 extension->id(), |
| 251 script_type, | 251 script_type, |
| 252 code_string, | 252 code_string, |
| 253 all_frames_ ? ScriptExecutor::ALL_FRAMES : ScriptExecutor::TOP_FRAME, | 253 all_frames_ ? ScriptExecutor::ALL_FRAMES : ScriptExecutor::TOP_FRAME, |
| 254 run_at_, | 254 run_at_, |
| 255 ScriptExecutor::ISOLATED_WORLD, | 255 ScriptExecutor::ISOLATED_WORLD, |
| 256 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); | 256 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| OLD | NEW |