| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ |
| 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ | 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "base/weak_ptr.h" | 14 #include "base/weak_ptr.h" |
| 15 #include "chrome/test/automation/javascript_message_utils.h" | 15 #include "chrome/test/automation/javascript_message_utils.h" |
| 16 | 16 |
| 17 class JavaScriptObjectProxy; | 17 class JavaScriptObjectProxy; |
| 18 | 18 |
| 19 // This class handles the execution of arbitrary JavaScript, preparing it for | 19 // This class handles the execution of arbitrary JavaScript, preparing it for |
| 20 // execution, and parsing its result (in JSON). It keeps track of all returned | 20 // execution, and parsing its result (in JSON). It keeps track of all returned |
| 21 // JavaScript objects. | 21 // JavaScript objects. |
| 22 class JavaScriptExecutionController | 22 class JavaScriptExecutionController |
| 23 : public base::SupportsWeakPtr<JavaScriptExecutionController> { | 23 : public base::SupportsWeakPtr<JavaScriptExecutionController> { |
| 24 public: | 24 public: |
| 25 JavaScriptExecutionController() {} | 25 JavaScriptExecutionController(); |
| 26 virtual ~JavaScriptExecutionController() {} | 26 virtual ~JavaScriptExecutionController(); |
| 27 | 27 |
| 28 // Executes |script| and parse the return value. Returns whether the | 28 // Executes |script| and parse the return value. Returns whether the |
| 29 // execution and parsing succeeded. | 29 // execution and parsing succeeded. |
| 30 template <typename T> | 30 template <typename T> |
| 31 bool ExecuteJavaScriptAndGetReturn(const std::string& script, T* result) { | 31 bool ExecuteJavaScriptAndGetReturn(const std::string& script, T* result) { |
| 32 scoped_ptr<Value> returnValue; | 32 scoped_ptr<Value> returnValue; |
| 33 if (!ExecuteAndParseHelper(WrapJavaScript(script), &returnValue)) | 33 if (!ExecuteAndParseHelper(WrapJavaScript(script), &returnValue)) |
| 34 return false; | 34 return false; |
| 35 return ValueConversionTraits<T>::SetFromValue(returnValue.get(), result); | 35 return ValueConversionTraits<T>::SetFromValue(returnValue.get(), result); |
| 36 } | 36 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // Timeout to use for all asynchronous methods. | 113 // Timeout to use for all asynchronous methods. |
| 114 static int timeout_ms_; | 114 static int timeout_ms_; |
| 115 | 115 |
| 116 // Weak pointer to all the object proxies that we create. | 116 // Weak pointer to all the object proxies that we create. |
| 117 HandleToObjectMap handle_to_object_; | 117 HandleToObjectMap handle_to_object_; |
| 118 | 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(JavaScriptExecutionController); | 119 DISALLOW_COPY_AND_ASSIGN(JavaScriptExecutionController); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ | 122 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ |
| OLD | NEW |