Path: blob/trunk/cpp/iedriver/CommandHandlers/DeleteAllCookiesCommandHandler.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 "DeleteAllCookiesCommandHandler.h"17#include "errorcodes.h"18#include "../Browser.h"19#include "../BrowserCookie.h"20#include "../CookieManager.h"21#include "../IECommandExecutor.h"2223namespace webdriver {2425DeleteAllCookiesCommandHandler::DeleteAllCookiesCommandHandler(void) {26}2728DeleteAllCookiesCommandHandler::~DeleteAllCookiesCommandHandler(void) {29}3031void DeleteAllCookiesCommandHandler::ExecuteInternal(32const IECommandExecutor& executor,33const ParametersMap& command_parameters,34Response* response) {35BrowserHandle browser_wrapper;36int status_code = executor.GetCurrentBrowser(&browser_wrapper);37if (status_code != WD_SUCCESS) {38response->SetErrorResponse(status_code, "Unable to get browser");39return;40}4142std::vector<BrowserCookie> cookies;43browser_wrapper->cookie_manager()->GetCookies(44browser_wrapper->GetCurrentUrl(),45&cookies);46std::vector<BrowserCookie>::const_iterator it = cookies.begin();47for (; it != cookies.end(); ++it) {48browser_wrapper->cookie_manager()->DeleteCookie(49browser_wrapper->GetCurrentUrl(),50*it);51if (status_code != WD_SUCCESS) {52response->SetErrorResponse(status_code,53"Unable to delete cookie with name '" + it->name() + "'");54return;55}56}5758response->SetSuccessResponse(Json::Value::null);59}6061} // namespace webdriver626364