Path: blob/trunk/cpp/iedriver/CommandHandlers/GetAllCookiesCommandHandler.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 "GetAllCookiesCommandHandler.h"17#include "errorcodes.h"18#include "../Browser.h"19#include "../BrowserCookie.h"20#include "../CookieManager.h"21#include "../IECommandExecutor.h"2223namespace webdriver {2425GetAllCookiesCommandHandler::GetAllCookiesCommandHandler(void) {26}2728GetAllCookiesCommandHandler::~GetAllCookiesCommandHandler(void) {29}3031void GetAllCookiesCommandHandler::ExecuteInternal(32const IECommandExecutor& executor,33const ParametersMap& command_parameters,34Response* response) {35Json::Value response_value(Json::arrayValue);36BrowserHandle browser_wrapper;37int status_code = executor.GetCurrentBrowser(&browser_wrapper);38if (status_code != WD_SUCCESS) {39response->SetErrorResponse(status_code, "Unable to get browser");40return;41}4243std::vector<BrowserCookie> cookies;44status_code = browser_wrapper->cookie_manager()->GetCookies(45browser_wrapper->GetCurrentUrl(),46&cookies);47if (status_code == EUNHANDLEDERROR) {48std::string error = "Could not retrieve cookies. The most common cause ";49error.append("of this error is a mismatch in the bitness between the ");50error.append("driver and browser. In particular, be sure you are not ");51error.append("attempting to use a 64-bit IEDriverServer.exe against ");52error.append("IE 10 or 11, even on 64-bit Windows.");53response->SetErrorResponse(status_code, error);54return;55}56std::vector<BrowserCookie>::iterator it = cookies.begin();57for (; it != cookies.end(); ++it) {58response_value.append(it->ToJson());59}6061response->SetSuccessResponse(response_value);62}6364} // namespace webdriver656667