Path: blob/trunk/cpp/iedriver/CommandHandlers/DeleteCookieCommandHandler.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 "DeleteCookieCommandHandler.h"17#include "errorcodes.h"18#include "../Browser.h"19#include "../BrowserCookie.h"20#include "../CookieManager.h"21#include "../IECommandExecutor.h"2223namespace webdriver {2425DeleteCookieCommandHandler::DeleteCookieCommandHandler(void) {26}2728DeleteCookieCommandHandler::~DeleteCookieCommandHandler(void) {29}3031void DeleteCookieCommandHandler::ExecuteInternal(32const IECommandExecutor& executor,33const ParametersMap& command_parameters,34Response* response) {35ParametersMap::const_iterator name_parameter_iterator = command_parameters.find("name");36if (name_parameter_iterator == command_parameters.end()) {37response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: name");38return;39}4041std::string cookie_name = name_parameter_iterator->second.asString();42BrowserHandle browser_wrapper;43int status_code = executor.GetCurrentBrowser(&browser_wrapper);44if (status_code != WD_SUCCESS) {45response->SetErrorResponse(status_code, "Unable to get browser");46return;47}4849BrowserCookie cookie;50cookie.set_name(cookie_name);51browser_wrapper->cookie_manager()->DeleteCookie(52browser_wrapper->GetCurrentUrl(),53cookie);54if (status_code != WD_SUCCESS) {55response->SetErrorResponse(status_code, "Unable to delete cookie");56return;57}5859response->SetSuccessResponse(Json::Value::null);60}6162} // namespace webdriver636465