Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/CommandHandlers/DeleteAllCookiesCommandHandler.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 "DeleteAllCookiesCommandHandler.h"
18
#include "errorcodes.h"
19
#include "../Browser.h"
20
#include "../BrowserCookie.h"
21
#include "../CookieManager.h"
22
#include "../IECommandExecutor.h"
23
24
namespace webdriver {
25
26
DeleteAllCookiesCommandHandler::DeleteAllCookiesCommandHandler(void) {
27
}
28
29
DeleteAllCookiesCommandHandler::~DeleteAllCookiesCommandHandler(void) {
30
}
31
32
void DeleteAllCookiesCommandHandler::ExecuteInternal(
33
const IECommandExecutor& executor,
34
const ParametersMap& command_parameters,
35
Response* response) {
36
BrowserHandle browser_wrapper;
37
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
38
if (status_code != WD_SUCCESS) {
39
response->SetErrorResponse(status_code, "Unable to get browser");
40
return;
41
}
42
43
std::vector<BrowserCookie> cookies;
44
browser_wrapper->cookie_manager()->GetCookies(
45
browser_wrapper->GetCurrentUrl(),
46
&cookies);
47
std::vector<BrowserCookie>::const_iterator it = cookies.begin();
48
for (; it != cookies.end(); ++it) {
49
browser_wrapper->cookie_manager()->DeleteCookie(
50
browser_wrapper->GetCurrentUrl(),
51
*it);
52
if (status_code != WD_SUCCESS) {
53
response->SetErrorResponse(status_code,
54
"Unable to delete cookie with name '" + it->name() + "'");
55
return;
56
}
57
}
58
59
response->SetSuccessResponse(Json::Value::null);
60
}
61
62
} // namespace webdriver
63
64