Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/IECommandHandler.cpp
2867 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#include "IECommandHandler.h"
18
19
#include "command_handler.h"
20
#include "errorcodes.h"
21
#include "logging.h"
22
23
#include "DocumentHost.h"
24
#include "Element.h"
25
#include "IECommandExecutor.h"
26
27
namespace webdriver {
28
29
IECommandHandler::IECommandHandler() {
30
}
31
32
IECommandHandler::~IECommandHandler() {
33
}
34
35
void IECommandHandler::ExecuteInternal(const IECommandExecutor& executor,
36
const ParametersMap& command_parameters,
37
Response* response) {
38
LOG(TRACE) << "Entering IECommandHandler::ExecuteInternal";
39
response->SetErrorResponse(501, "Command not implemented");
40
}
41
42
int IECommandHandler::GetElement(const IECommandExecutor& executor,
43
const std::string& element_id,
44
ElementHandle* element_wrapper) {
45
LOG(TRACE) << "Entering IECommandHandler::GetElement";
46
ElementHandle candidate_wrapper;
47
int result = executor.GetManagedElement(element_id, &candidate_wrapper);
48
if (result != WD_SUCCESS) {
49
LOG(WARN) << "Unable to get managed element, element not found";
50
return result;
51
} else {
52
if (!candidate_wrapper->IsAttachedToDom()) {
53
LOG(WARN) << "Found managed element is no longer valid";
54
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
55
mutable_executor.RemoveManagedElement(element_id);
56
return EOBSOLETEELEMENT;
57
} else {
58
// If the element is attached to the DOM, validate that its document
59
// is the currently-focused document (via frames).
60
BrowserHandle current_browser;
61
executor.GetCurrentBrowser(&current_browser);
62
CComPtr<IHTMLDocument2> focused_doc;
63
current_browser->GetDocument(&focused_doc);
64
65
if (candidate_wrapper->IsDocumentFocused(focused_doc)) {
66
*element_wrapper = candidate_wrapper;
67
return WD_SUCCESS;
68
} else {
69
LOG(WARN) << "Found managed element's document is not currently focused";
70
}
71
}
72
}
73
74
return EOBSOLETEELEMENT;
75
}
76
77
Json::Value IECommandHandler::RecreateJsonParameterObject(const ParametersMap& command_parameters) {
78
Json::Value result;
79
ParametersMap::const_iterator param_iterator = command_parameters.begin();
80
for (; param_iterator != command_parameters.end(); ++param_iterator) {
81
std::string key = param_iterator->first;
82
Json::Value value = param_iterator->second;
83
result[key] = value;
84
}
85
return result;
86
}
87
88
} // namespace webdriver
89
90