2015-04-13 12:09:26 -04:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the "License");
|
2013-05-01 13:12:27 -04:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
2018-10-01 10:10:49 -07:00
|
|
|
#ifndef WEBDRIVER_IE_ASYNCSCRIPTEXECUTOR_H_
|
|
|
|
|
#define WEBDRIVER_IE_ASYNCSCRIPTEXECUTOR_H_
|
2013-05-01 13:12:27 -04:00
|
|
|
|
|
|
|
|
#include <vector>
|
2017-02-14 09:48:56 -08:00
|
|
|
|
2018-02-07 12:04:43 -08:00
|
|
|
#include "IElementManager.h"
|
2013-05-01 13:12:27 -04:00
|
|
|
#include "messages.h"
|
2018-02-07 12:04:43 -08:00
|
|
|
#include "json.h"
|
2013-05-01 13:12:27 -04:00
|
|
|
|
|
|
|
|
namespace webdriver {
|
|
|
|
|
|
|
|
|
|
// Structure to be used for comunication between threads
|
|
|
|
|
struct AsyncScriptExecutorThreadContext {
|
|
|
|
|
HWND hwnd;
|
|
|
|
|
LPCTSTR script_source;
|
|
|
|
|
int script_argument_count;
|
2018-02-07 12:04:43 -08:00
|
|
|
HWND main_element_repository_handle;
|
|
|
|
|
LPCTSTR serialized_script_args;
|
2013-05-01 13:12:27 -04:00
|
|
|
};
|
|
|
|
|
|
2018-02-07 12:04:43 -08:00
|
|
|
class ElementRepository;
|
|
|
|
|
|
2013-05-01 13:12:27 -04:00
|
|
|
// We use a CWindowImpl (creating a hidden window) here because we
|
|
|
|
|
// want to synchronize access to the command handler. For that we
|
|
|
|
|
// use SendMessage() most of the time, and SendMessage() requires
|
|
|
|
|
// a window handle.
|
2018-02-07 12:04:43 -08:00
|
|
|
class AsyncScriptExecutor : public CWindowImpl<AsyncScriptExecutor>, public IElementManager {
|
2013-05-01 13:12:27 -04:00
|
|
|
public:
|
|
|
|
|
DECLARE_WND_CLASS(L"WebDriverAsyncAtomWndClass")
|
|
|
|
|
|
|
|
|
|
BEGIN_MSG_MAP(Session)
|
|
|
|
|
MESSAGE_HANDLER(WM_CREATE, OnCreate)
|
|
|
|
|
MESSAGE_HANDLER(WM_CLOSE, OnClose)
|
|
|
|
|
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
|
|
|
|
|
MESSAGE_HANDLER(WD_INIT, OnInit)
|
|
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_SET_DOCUMENT, OnSetDocument)
|
2018-02-07 12:04:43 -08:00
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_SET_ELEMENT_ARGUMENT, OnSetElementArgument)
|
|
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_IS_EXECUTION_READY, OnIsExecutionReady)
|
2013-05-23 16:52:54 -04:00
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_EXECUTE, OnExecuteScript)
|
2013-05-01 13:12:27 -04:00
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_IS_EXECUTION_COMPLETE, OnIsExecutionComplete)
|
|
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_DETACH_LISTENTER, OnDetachListener)
|
|
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_GET_RESULT, OnGetResult)
|
2018-02-07 12:04:43 -08:00
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_NOTIFY_ELEMENT_TRANSFERRED, OnNotifyElementTransferred)
|
|
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_SET_POLLING_SCRIPT, OnSetPollingScript)
|
|
|
|
|
MESSAGE_HANDLER(WD_ASYNC_SCRIPT_GET_REQUIRED_ELEMENT_LIST, OnGetRequiredElementList)
|
2013-05-01 13:12:27 -04:00
|
|
|
END_MSG_MAP()
|
|
|
|
|
|
|
|
|
|
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnInit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnSetDocument(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
2018-02-07 12:04:43 -08:00
|
|
|
LRESULT OnSetElementArgument(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnIsExecutionReady(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
2013-05-01 13:12:27 -04:00
|
|
|
LRESULT OnExecuteScript(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnIsExecutionComplete(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnDetachListener(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnGetResult(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
2018-02-07 12:04:43 -08:00
|
|
|
LRESULT OnNotifyElementTransferred(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnSetPollingScript(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
LRESULT OnGetRequiredElementList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
|
|
|
|
|
|
|
|
int GetManagedElement(const std::string& element_id,
|
|
|
|
|
ElementHandle* element_wrapper) const;
|
|
|
|
|
bool AddManagedElement(IHTMLElement* element,
|
|
|
|
|
ElementHandle* element_wrapper);
|
|
|
|
|
void RemoveManagedElement(const std::string& element_id);
|
2013-05-01 13:12:27 -04:00
|
|
|
|
|
|
|
|
static unsigned int WINAPI ThreadProc(LPVOID lpParameter);
|
|
|
|
|
|
|
|
|
|
private:
|
2018-02-07 12:04:43 -08:00
|
|
|
void GetElementIdList(const Json::Value& json_object);
|
|
|
|
|
bool WaitForPollingScript(void);
|
|
|
|
|
void TransferReturnedElements(void);
|
2018-02-21 05:49:29 -08:00
|
|
|
void ReplaceTransferredElementResult(std::string original_element_id,
|
|
|
|
|
std::string element_id,
|
|
|
|
|
Json::Value* result);
|
2018-02-07 12:04:43 -08:00
|
|
|
|
|
|
|
|
ElementRepository* element_repository_;
|
|
|
|
|
HWND main_element_repository_handle_;
|
2013-05-01 13:12:27 -04:00
|
|
|
CComPtr<IHTMLDocument2> script_host_;
|
|
|
|
|
std::vector<CComVariant> script_arguments_;
|
2018-02-07 12:04:43 -08:00
|
|
|
std::vector<std::string> element_id_list_;
|
2013-05-01 13:12:27 -04:00
|
|
|
std::wstring script_source_code_;
|
2018-02-07 12:04:43 -08:00
|
|
|
std::wstring polling_script_source_code_;
|
|
|
|
|
Json::Value script_args_;
|
|
|
|
|
Json::Value script_result_;
|
2013-05-01 13:12:27 -04:00
|
|
|
int script_argument_count_;
|
|
|
|
|
int script_argument_index_;
|
|
|
|
|
int status_code_;
|
|
|
|
|
bool is_execution_completed_;
|
|
|
|
|
bool is_listener_attached_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webdriver
|
|
|
|
|
|
2018-10-01 10:10:49 -07:00
|
|
|
#endif // WEBDRIVER_IE_ASYNCSCRIPTEXECUTOR_H_
|
2013-05-01 13:12:27 -04:00
|
|
|
|