Path: blob/trunk/cpp/iedriver/CommandHandlers/CloseWindowCommandHandler.cpp
2868 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6// You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS,12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13// See the License for the specific language governing permissions and14// limitations under the License.1516#include "CloseWindowCommandHandler.h"17#include "errorcodes.h"18#include "../Browser.h"19#include "../IECommandExecutor.h"2021namespace webdriver {2223CloseWindowCommandHandler::CloseWindowCommandHandler(void) {24}2526CloseWindowCommandHandler::~CloseWindowCommandHandler(void) {27}2829void CloseWindowCommandHandler::ExecuteInternal(30const IECommandExecutor& executor,31const ParametersMap& command_parameters,32Response* response) {33// The session should end if the user sends a quit command,34// or if the user sends a close command with exactly 1 window35// open, per spec. Removing the window from the managed browser36// list depends on events, which may be asynchronous, so cache37// the window count *before* closing the current window.38size_t current_window_count = executor.managed_window_count();3940// TODO: Check HRESULT values for errors.41BrowserHandle browser_wrapper;42int status_code = executor.GetCurrentBrowser(&browser_wrapper);43if (status_code != WD_SUCCESS) {44response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");45return;46}47browser_wrapper->Close();4849if (current_window_count == 1) {50IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);51mutable_executor.set_is_valid(false);52mutable_executor.set_is_quitting(true);53Json::Value handles(Json::arrayValue);54response->SetSuccessResponse(handles);55}56}5758} // namespace webdriver596061