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-01-11 22:18:32 +01: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.
|
|
|
|
|
|
|
|
|
|
#include "IEServer.h"
|
2017-02-14 09:48:56 -08:00
|
|
|
|
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
2013-01-11 22:18:32 +01:00
|
|
|
#include "IESession.h"
|
2015-07-30 14:55:24 -07:00
|
|
|
#include "FileUtilities.h"
|
2013-01-11 22:18:32 +01:00
|
|
|
|
|
|
|
|
namespace webdriver {
|
|
|
|
|
|
|
|
|
|
IEServer::IEServer(int port,
|
|
|
|
|
const std::string& host,
|
|
|
|
|
const std::string& log_level,
|
|
|
|
|
const std::string& log_file,
|
2014-09-05 02:00:00 +00:00
|
|
|
const std::string& version,
|
2015-10-30 15:47:54 -04:00
|
|
|
const std::string& acl) : Server(port, host, log_level, log_file, acl) {
|
2013-04-10 00:02:15 +04:00
|
|
|
LOG(TRACE) << "Entering IEServer::IEServer";
|
2015-10-30 15:47:54 -04:00
|
|
|
LOG(INFO) << "Driver version: " << version;
|
2013-01-11 22:18:32 +01:00
|
|
|
this->version_ = version;
|
2017-02-22 14:13:25 -08:00
|
|
|
this->AddCommand("/session/:sessionid/ie/script/background", "POST", "executeBackgroundScript");
|
2013-01-11 22:18:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEServer::~IEServer(void) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SessionHandle IEServer::InitializeSession() {
|
2013-04-10 00:02:15 +04:00
|
|
|
LOG(TRACE) << "Entering IEServer::InitializeSession";
|
2013-01-11 22:18:32 +01:00
|
|
|
SessionHandle session_handle(new IESession());
|
2013-04-10 00:02:15 +04:00
|
|
|
SessionParameters params;
|
|
|
|
|
params.port = this->port();
|
|
|
|
|
session_handle->Initialize(reinterpret_cast<void*>(¶ms));
|
2013-01-11 22:18:32 +01:00
|
|
|
return session_handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string IEServer::GetStatus() {
|
2013-04-10 00:02:15 +04:00
|
|
|
LOG(TRACE) << "Entering IEServer::GetStatus";
|
2013-01-11 22:18:32 +01:00
|
|
|
SYSTEM_INFO system_info;
|
|
|
|
|
::ZeroMemory(&system_info, sizeof(SYSTEM_INFO));
|
|
|
|
|
::GetNativeSystemInfo(&system_info);
|
|
|
|
|
|
2015-07-30 14:55:24 -07:00
|
|
|
std::string os_version = FileUtilities::GetFileVersion("kernel32.dll");
|
2013-01-11 22:18:32 +01:00
|
|
|
|
|
|
|
|
std::string arch = "x86";
|
|
|
|
|
if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
|
|
|
|
|
arch = "x64";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Json::Value build;
|
|
|
|
|
build["version"] = this->version_;
|
|
|
|
|
|
|
|
|
|
Json::Value os;
|
|
|
|
|
os["arch"] = arch;
|
|
|
|
|
os["name"] = "windows";
|
|
|
|
|
os["version"] = os_version;
|
2017-08-31 09:41:44 -07:00
|
|
|
|
|
|
|
|
bool is_ready = this->session_count() < 1;
|
|
|
|
|
std::string message = "Ready to create session";
|
|
|
|
|
if (!is_ready) {
|
|
|
|
|
message = "Maximum number of sessions already created";
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 22:18:32 +01:00
|
|
|
Json::Value status;
|
|
|
|
|
status["build"] = build;
|
|
|
|
|
status["os"] = os;
|
2017-08-31 09:41:44 -07:00
|
|
|
status["ready"] = is_ready;
|
|
|
|
|
status["message"] = message;
|
2013-01-11 22:18:32 +01:00
|
|
|
Response response;
|
|
|
|
|
response.SetSuccessResponse(status);
|
|
|
|
|
return response.Serialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IEServer::ShutDown() {
|
2013-04-10 00:02:15 +04:00
|
|
|
LOG(TRACE) << "Entering IEServer::ShutDown";
|
2013-01-11 22:18:32 +01:00
|
|
|
DWORD process_id = ::GetCurrentProcessId();
|
2013-07-30 17:06:02 -04:00
|
|
|
std::wstring process_id_string = std::to_wstring(static_cast<long long>(process_id));
|
2013-01-11 22:18:32 +01:00
|
|
|
std::wstring event_name = IESERVER_SHUTDOWN_EVENT_NAME + process_id_string;
|
|
|
|
|
HANDLE event_handle = ::OpenEvent(EVENT_MODIFY_STATE,
|
|
|
|
|
FALSE,
|
|
|
|
|
event_name.c_str());
|
|
|
|
|
if (event_handle) {
|
|
|
|
|
::SetEvent(event_handle);
|
|
|
|
|
::CloseHandle(event_handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace webdriver
|