function openHelpViewPage(path, parent, csh_size, csh_location)
%OPENHELPVIEWPAGE Open a helpview page.

%   Copyright 2020-2021 The MathWorks, Inc.

    if matlab.internal.doc.ui.useCshWebWindow
        % Add query parameters for F1help and csh.
        uri = matlab.net.URI(path);
        uri.Query = [uri.Query matlab.net.QueryParameter('browser','F1help') matlab.net.QueryParameter('linkclickhandle','csh')];
    
        if matlab.internal.doc.services.isOnline
            matlab.internal.doc.java.initializeLoginServices;

            releaseVersion = strcat("R", version('-release'));
            uri.Query = [uri.Query ...
                         matlab.net.QueryParameter('docviewer','helpbrowser') ...
                         matlab.net.QueryParameter('docrelease',releaseVersion)];

            loginUrl = getLoginUrl;
            if ~isempty(loginUrl)
                uri.Query = [uri.Query matlab.net.QueryParameter('loginurl',loginUrl)];
            end

            nonce = matlab.internal.doc.java.getConnectorDocRootNonce;
            if ~isempty(nonce)
                uri.Query = [uri.Query matlab.net.QueryParameter('snc',nonce)];
            end
        end
            
        matlab.internal.doc.ui.cshWebWindow(uri.string, 'size', csh_size, 'location', csh_location, 'title', getString(message('MATLAB:helpview:Title')));
    else
        matlab.internal.doc.csh.java.displayCshFile(path, parent, csh_size, csh_location);
    end
end

function loginUrl = getLoginUrl
    try
        loginUrl = connector.getUrl(string(matlab.internal.doc.java.getLoginURLToBeLoadedInIFrame));
    catch
        loginUrl = '';
    end
end