MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / ExecuteInternal

Method ExecuteInternal

cpp/iedriver/CommandHandlers/GoToUrlCommandHandler.cpp:32–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32void GoToUrlCommandHandler::ExecuteInternal(
33 const IECommandExecutor& executor,
34 const ParametersMap& command_parameters,
35 Response* response) {
36 ParametersMap::const_iterator url_parameter_iterator = command_parameters.find("url");
37 if (url_parameter_iterator == command_parameters.end()) {
38 response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: url");
39 return;
40 } else {
41 BrowserHandle browser_wrapper;
42 int status_code = executor.GetCurrentBrowser(&browser_wrapper);
43 if (status_code != WD_SUCCESS) {
44 response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");
45 return;
46 }
47
48 // TODO: PathIsURL isn't quite the right thing. We need to
49 // find the correct API that will parse the URL to tell
50 // us whether the URL is valid according to the URL spec.
51 std::string url = url_parameter_iterator->second.asString();
52 std::wstring wide_url = StringUtilities::ToWString(url);
53 BOOL is_valid = ::PathIsURL(wide_url.c_str());
54 if (is_valid != TRUE) {
55 response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Specified URL (" + url + ") is not valid.");
56 return;
57 }
58
59 bool is_file_url = ::UrlIsFileUrl(wide_url.c_str()) == TRUE;
60 if (is_file_url) {
61 DWORD path_length = MAX_PATH;
62 std::vector<wchar_t> buffer(path_length);
63 HRESULT hr = ::PathCreateFromUrl(wide_url.c_str(), &buffer[0], &path_length, 0);
64 if (FAILED(hr)) {
65 response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
66 "Specified URL (" + url + ") is a file, " +
67 "but the path was not valid.");
68 return;
69 } else {
70 std::wstring file_path(&buffer[0]);
71 if (file_path.size() == 0) {
72 response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
73 "Specified URL (" + url + ") is a file, " +
74 "but the path was not valid.");
75 return;
76 } else {
77 if (::PathIsDirectory(file_path.c_str())) {
78 response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
79 "Specified URL (" + url + ") is a directory, " +
80 "and the browser opens directories outside the browser window.");
81 return;
82 }
83 }
84 }
85 }
86
87 if (browser_wrapper->IsCrossZoneUrl(url)) {
88 browser_wrapper->InitiateBrowserReattach();
89 }

Callers

nothing calls this directly

Calls 11

findMethod · 0.80
endMethod · 0.80
SetErrorResponseMethod · 0.80
GetCurrentBrowserMethod · 0.80
asStringMethod · 0.80
IsCrossZoneUrlMethod · 0.80
SetSuccessResponseMethod · 0.80
sizeMethod · 0.45
NavigateToUrlMethod · 0.45

Tested by

no test coverage detected