| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using extensions::ScriptExecutor; | 32 using extensions::ScriptExecutor; |
| 33 | 33 |
| 34 namespace keys = extensions::tabs_constants; | 34 namespace keys = extensions::tabs_constants; |
| 35 | 35 |
| 36 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() | 36 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() |
| 37 : execute_tab_id_(-1), | 37 : execute_tab_id_(-1), |
| 38 all_frames_(false), | 38 all_frames_(false), |
| 39 run_at_(UserScript::DOCUMENT_IDLE) { | 39 run_at_(extensions::UserScript::DOCUMENT_IDLE) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} | 42 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} |
| 43 | 43 |
| 44 bool ExecuteCodeInTabFunction::RunImpl() { | 44 bool ExecuteCodeInTabFunction::RunImpl() { |
| 45 DictionaryValue* script_info; | 45 DictionaryValue* script_info; |
| 46 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info)); | 46 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info)); |
| 47 size_t number_of_value = script_info->size(); | 47 size_t number_of_value = script_info->size(); |
| 48 if (number_of_value == 0) { | 48 if (number_of_value == 0) { |
| 49 error_ = keys::kNoCodeOrFileToExecuteError; | 49 error_ = keys::kNoCodeOrFileToExecuteError; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (!script_info->GetBoolean(keys::kAllFramesKey, &all_frames_)) | 98 if (!script_info->GetBoolean(keys::kAllFramesKey, &all_frames_)) |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 if (script_info->HasKey(keys::kRunAtKey)) { | 102 if (script_info->HasKey(keys::kRunAtKey)) { |
| 103 std::string run_string; | 103 std::string run_string; |
| 104 EXTENSION_FUNCTION_VALIDATE(script_info->GetString( | 104 EXTENSION_FUNCTION_VALIDATE(script_info->GetString( |
| 105 keys::kRunAtKey, &run_string)); | 105 keys::kRunAtKey, &run_string)); |
| 106 | 106 |
| 107 if (run_string == extension_manifest_values::kRunAtDocumentStart) | 107 if (run_string == extension_manifest_values::kRunAtDocumentStart) |
| 108 run_at_ = UserScript::DOCUMENT_START; | 108 run_at_ = extensions::UserScript::DOCUMENT_START; |
| 109 else if (run_string == extension_manifest_values::kRunAtDocumentEnd) | 109 else if (run_string == extension_manifest_values::kRunAtDocumentEnd) |
| 110 run_at_ = UserScript::DOCUMENT_END; | 110 run_at_ = extensions::UserScript::DOCUMENT_END; |
| 111 else if (run_string == extension_manifest_values::kRunAtDocumentIdle) | 111 else if (run_string == extension_manifest_values::kRunAtDocumentIdle) |
| 112 run_at_ = UserScript::DOCUMENT_IDLE; | 112 run_at_ = extensions::UserScript::DOCUMENT_IDLE; |
| 113 else | 113 else |
| 114 EXTENSION_FUNCTION_VALIDATE(false); | 114 EXTENSION_FUNCTION_VALIDATE(false); |
| 115 } | 115 } |
| 116 | 116 |
| 117 std::string code_string; | 117 std::string code_string; |
| 118 if (script_info->HasKey(keys::kCodeKey)) { | 118 if (script_info->HasKey(keys::kCodeKey)) { |
| 119 if (!script_info->GetString(keys::kCodeKey, &code_string)) | 119 if (!script_info->GetString(keys::kCodeKey, &code_string)) |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 | 122 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 contents->extension_tab_helper()->script_executor()->ExecuteScript( | 243 contents->extension_tab_helper()->script_executor()->ExecuteScript( |
| 244 extension->id(), | 244 extension->id(), |
| 245 script_type, | 245 script_type, |
| 246 code_string, | 246 code_string, |
| 247 all_frames_ ? ScriptExecutor::ALL_FRAMES : ScriptExecutor::TOP_FRAME, | 247 all_frames_ ? ScriptExecutor::ALL_FRAMES : ScriptExecutor::TOP_FRAME, |
| 248 run_at_, | 248 run_at_, |
| 249 ScriptExecutor::ISOLATED_WORLD, | 249 ScriptExecutor::ISOLATED_WORLD, |
| 250 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); | 250 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); |
| 251 return true; | 251 return true; |
| 252 } | 252 } |
| OLD | NEW |