Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/CommandHandlers/CloseWindowCommandHandler.cpp
2868 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 "CloseWindowCommandHandler.h"
18
#include "errorcodes.h"
19
#include "../Browser.h"
20
#include "../IECommandExecutor.h"
21
22
namespace webdriver {
23
24
CloseWindowCommandHandler::CloseWindowCommandHandler(void) {
25
}
26
27
CloseWindowCommandHandler::~CloseWindowCommandHandler(void) {
28
}
29
30
void CloseWindowCommandHandler::ExecuteInternal(
31
const IECommandExecutor& executor,
32
const ParametersMap& command_parameters,
33
Response* response) {
34
// The session should end if the user sends a quit command,
35
// or if the user sends a close command with exactly 1 window
36
// open, per spec. Removing the window from the managed browser
37
// list depends on events, which may be asynchronous, so cache
38
// the window count *before* closing the current window.
39
size_t current_window_count = executor.managed_window_count();
40
41
// TODO: Check HRESULT values for errors.
42
BrowserHandle browser_wrapper;
43
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
44
if (status_code != WD_SUCCESS) {
45
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");
46
return;
47
}
48
browser_wrapper->Close();
49
50
if (current_window_count == 1) {
51
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
52
mutable_executor.set_is_valid(false);
53
mutable_executor.set_is_quitting(true);
54
Json::Value handles(Json::arrayValue);
55
response->SetSuccessResponse(handles);
56
}
57
}
58
59
} // namespace webdriver
60
61