Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/CommandHandlers/GetAllCookiesCommandHandler.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 "GetAllCookiesCommandHandler.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
GetAllCookiesCommandHandler::GetAllCookiesCommandHandler(void) {
27
}
28
29
GetAllCookiesCommandHandler::~GetAllCookiesCommandHandler(void) {
30
}
31
32
void GetAllCookiesCommandHandler::ExecuteInternal(
33
const IECommandExecutor& executor,
34
const ParametersMap& command_parameters,
35
Response* response) {
36
Json::Value response_value(Json::arrayValue);
37
BrowserHandle browser_wrapper;
38
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
39
if (status_code != WD_SUCCESS) {
40
response->SetErrorResponse(status_code, "Unable to get browser");
41
return;
42
}
43
44
std::vector<BrowserCookie> cookies;
45
status_code = browser_wrapper->cookie_manager()->GetCookies(
46
browser_wrapper->GetCurrentUrl(),
47
&cookies);
48
if (status_code == EUNHANDLEDERROR) {
49
std::string error = "Could not retrieve cookies. The most common cause ";
50
error.append("of this error is a mismatch in the bitness between the ");
51
error.append("driver and browser. In particular, be sure you are not ");
52
error.append("attempting to use a 64-bit IEDriverServer.exe against ");
53
error.append("IE 10 or 11, even on 64-bit Windows.");
54
response->SetErrorResponse(status_code, error);
55
return;
56
}
57
std::vector<BrowserCookie>::iterator it = cookies.begin();
58
for (; it != cookies.end(); ++it) {
59
response_value.append(it->ToJson());
60
}
61
62
response->SetSuccessResponse(response_value);
63
}
64
65
} // namespace webdriver
66
67