# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.browser
from cdp.browser import (
    Bounds,
    Bucket,
    Histogram,
    PermissionType,
    WindowID,
    WindowState
)


async def close() -> None:
    '''
    Close browser gracefully.
    '''
    session = get_session_context('browser.close')
    return await session.execute(cdp.browser.close())


async def crash() -> None:
    '''
    Crashes browser on the main thread.

    **EXPERIMENTAL**
    '''
    session = get_session_context('browser.crash')
    return await session.execute(cdp.browser.crash())


async def crash_gpu_process() -> None:
    '''
    Crashes GPU process.

    **EXPERIMENTAL**
    '''
    session = get_session_context('browser.crash_gpu_process')
    return await session.execute(cdp.browser.crash_gpu_process())


async def get_browser_command_line() -> typing.List[str]:
    '''
    Returns the command line switches for the browser process if, and only if
    --enable-automation is on the commandline.

    **EXPERIMENTAL**

    :returns: Commandline parameters
    '''
    session = get_session_context('browser.get_browser_command_line')
    return await session.execute(cdp.browser.get_browser_command_line())


async def get_histogram(
        name: str,
        delta: typing.Optional[bool] = None
    ) -> Histogram:
    '''
    Get a Chrome histogram by name.

    **EXPERIMENTAL**

    :param name: Requested histogram name.
    :param delta: *(Optional)* If true, retrieve delta since last call.
    :returns: Histogram.
    '''
    session = get_session_context('browser.get_histogram')
    return await session.execute(cdp.browser.get_histogram(name, delta))


async def get_histograms(
        query: typing.Optional[str] = None,
        delta: typing.Optional[bool] = None
    ) -> typing.List[Histogram]:
    '''
    Get Chrome histograms.

    **EXPERIMENTAL**

    :param query: *(Optional)* Requested substring in name. Only histograms which have query as a substring in their name are extracted. An empty or absent query returns all histograms.
    :param delta: *(Optional)* If true, retrieve delta since last call.
    :returns: Histograms.
    '''
    session = get_session_context('browser.get_histograms')
    return await session.execute(cdp.browser.get_histograms(query, delta))


async def get_version() -> typing.Tuple[str, str, str, str, str]:
    '''
    Returns version information.

    :returns: A tuple with the following items:

        0. **protocolVersion** – Protocol version.
        1. **product** – Product name.
        2. **revision** – Product revision.
        3. **userAgent** – User-Agent.
        4. **jsVersion** – V8 version.
    '''
    session = get_session_context('browser.get_version')
    return await session.execute(cdp.browser.get_version())


async def get_window_bounds(
        window_id: WindowID
    ) -> Bounds:
    '''
    Get position and size of the browser window.

    **EXPERIMENTAL**

    :param window_id: Browser window id.
    :returns: Bounds information of the window. When window state is 'minimized', the restored window position and size are returned.
    '''
    session = get_session_context('browser.get_window_bounds')
    return await session.execute(cdp.browser.get_window_bounds(window_id))


async def get_window_for_target(
        target_id: typing.Optional[cdp.target.TargetID] = None
    ) -> typing.Tuple[WindowID, Bounds]:
    '''
    Get the browser window that contains the devtools target.

    **EXPERIMENTAL**

    :param target_id: *(Optional)* Devtools agent host id. If called as a part of the session, associated targetId is used.
    :returns: A tuple with the following items:

        0. **windowId** – Browser window id.
        1. **bounds** – Bounds information of the window. When window state is 'minimized', the restored window position and size are returned.
    '''
    session = get_session_context('browser.get_window_for_target')
    return await session.execute(cdp.browser.get_window_for_target(target_id))


async def grant_permissions(
        origin: str,
        permissions: typing.List[PermissionType],
        browser_context_id: typing.Optional[cdp.target.BrowserContextID] = None
    ) -> None:
    '''
    Grant specific permissions to the given origin and reject all others.

    **EXPERIMENTAL**

    :param origin:
    :param permissions:
    :param browser_context_id: *(Optional)* BrowserContext to override permissions. When omitted, default browser context is used.
    '''
    session = get_session_context('browser.grant_permissions')
    return await session.execute(cdp.browser.grant_permissions(origin, permissions, browser_context_id))


async def reset_permissions(
        browser_context_id: typing.Optional[cdp.target.BrowserContextID] = None
    ) -> None:
    '''
    Reset all permission management for all origins.

    **EXPERIMENTAL**

    :param browser_context_id: *(Optional)* BrowserContext to reset permissions. When omitted, default browser context is used.
    '''
    session = get_session_context('browser.reset_permissions')
    return await session.execute(cdp.browser.reset_permissions(browser_context_id))


async def set_dock_tile(
        badge_label: typing.Optional[str] = None,
        image: typing.Optional[str] = None
    ) -> None:
    '''
    Set dock tile details, platform-specific.

    **EXPERIMENTAL**

    :param badge_label: *(Optional)*
    :param image: *(Optional)* Png encoded image.
    '''
    session = get_session_context('browser.set_dock_tile')
    return await session.execute(cdp.browser.set_dock_tile(badge_label, image))


async def set_window_bounds(
        window_id: WindowID,
        bounds: Bounds
    ) -> None:
    '''
    Set position and/or size of the browser window.

    **EXPERIMENTAL**

    :param window_id: Browser window id.
    :param bounds: New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
    '''
    session = get_session_context('browser.set_window_bounds')
    return await session.execute(cdp.browser.set_window_bounds(window_id, bounds))
