Path: blob/trunk/cpp/iedriver/CommandHandlers/CreateNewWindowCommandHandler.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 "CreateNewWindowCommandHandler.h"17#include "errorcodes.h"18#include "../Browser.h"19#include "../IECommandExecutor.h"20#include "../WebDriverConstants.h"2122namespace webdriver {2324CreateNewWindowCommandHandler::CreateNewWindowCommandHandler(void) {25}2627CreateNewWindowCommandHandler::~CreateNewWindowCommandHandler(void) {28}2930void CreateNewWindowCommandHandler::ExecuteInternal(31const IECommandExecutor& executor,32const ParametersMap& command_parameters,33Response* response) {34ParametersMap::const_iterator type_parameter_iterator = command_parameters.find("type");35if (type_parameter_iterator == command_parameters.end()) {36response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: type");37return;38}39if (!type_parameter_iterator->second.isString() &&40!type_parameter_iterator->second.isNull()) {41response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "type parameter must be a string or null");42return;43}4445std::string window_type = WINDOW_WINDOW_TYPE;46if (type_parameter_iterator->second.isString()) {47std::string parameter_value = type_parameter_iterator->second.asString();48if (parameter_value == TAB_WINDOW_TYPE) {49window_type = TAB_WINDOW_TYPE;50}51}5253BrowserHandle browser_wrapper;54int status_code = executor.GetCurrentBrowser(&browser_wrapper);55if (status_code != WD_SUCCESS) {56response->SetErrorResponse(ERROR_NO_SUCH_WINDOW,57"Error retrieving current window");58return;59}6061IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);62std::string new_window_handle = mutable_executor.OpenNewBrowsingContext(window_type);63if (new_window_handle.size() == 0) {64response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "New window not created");65return;66}67if (window_type == WINDOW_WINDOW_TYPE) {68BrowserHandle tmp_browser;69executor.GetManagedBrowser(new_window_handle, &tmp_browser);70std::string error_message = "";71tmp_browser->NavigateToUrl("about:blank", &error_message);72}73Json::Value result;74result["handle"] = new_window_handle;75result["type"] = window_type;76response->SetSuccessResponse(result);77}7879} // namespace webdriver808182