merge #7546: [cookies] add support for Zen Browser
This commit is contained in:
@@ -26,7 +26,9 @@ from . import aes, text, util
|
|||||||
|
|
||||||
SUPPORTED_BROWSERS_CHROMIUM = {
|
SUPPORTED_BROWSERS_CHROMIUM = {
|
||||||
"brave", "chrome", "chromium", "edge", "opera", "thorium", "vivaldi"}
|
"brave", "chrome", "chromium", "edge", "opera", "thorium", "vivaldi"}
|
||||||
SUPPORTED_BROWSERS = SUPPORTED_BROWSERS_CHROMIUM | {"firefox", "safari"}
|
SUPPORTED_BROWSERS_FIREFOX = {"firefox", "zen"}
|
||||||
|
SUPPORTED_BROWSERS = \
|
||||||
|
SUPPORTED_BROWSERS_CHROMIUM | SUPPORTED_BROWSERS_FIREFOX | {"safari"}
|
||||||
|
|
||||||
logger = logging.getLogger("cookies")
|
logger = logging.getLogger("cookies")
|
||||||
|
|
||||||
@@ -34,8 +36,8 @@ logger = logging.getLogger("cookies")
|
|||||||
def load_cookies(browser_specification):
|
def load_cookies(browser_specification):
|
||||||
browser_name, profile, keyring, container, domain = \
|
browser_name, profile, keyring, container, domain = \
|
||||||
_parse_browser_specification(*browser_specification)
|
_parse_browser_specification(*browser_specification)
|
||||||
if browser_name == "firefox":
|
if browser_name in SUPPORTED_BROWSERS_FIREFOX:
|
||||||
return load_cookies_firefox(profile, container, domain)
|
return load_cookies_firefox(browser_name, profile, container, domain)
|
||||||
elif browser_name == "safari":
|
elif browser_name == "safari":
|
||||||
return load_cookies_safari(profile, domain)
|
return load_cookies_safari(profile, domain)
|
||||||
elif browser_name in SUPPORTED_BROWSERS_CHROMIUM:
|
elif browser_name in SUPPORTED_BROWSERS_CHROMIUM:
|
||||||
@@ -44,8 +46,10 @@ def load_cookies(browser_specification):
|
|||||||
raise ValueError("unknown browser '{}'".format(browser_name))
|
raise ValueError("unknown browser '{}'".format(browser_name))
|
||||||
|
|
||||||
|
|
||||||
def load_cookies_firefox(profile=None, container=None, domain=None):
|
def load_cookies_firefox(browser_name, profile=None,
|
||||||
path, container_id = _firefox_cookies_database(profile, container)
|
container=None, domain=None):
|
||||||
|
path, container_id = _firefox_cookies_database(browser_name,
|
||||||
|
profile, container)
|
||||||
|
|
||||||
sql = ("SELECT name, value, host, path, isSecure, expiry "
|
sql = ("SELECT name, value, host, path, isSecure, expiry "
|
||||||
"FROM moz_cookies")
|
"FROM moz_cookies")
|
||||||
@@ -83,7 +87,8 @@ def load_cookies_firefox(profile=None, container=None, domain=None):
|
|||||||
sql, parameters)
|
sql, parameters)
|
||||||
]
|
]
|
||||||
|
|
||||||
_log_info("Extracted %s cookies from Firefox", len(cookies))
|
_log_info("Extracted %s cookies from %s",
|
||||||
|
len(cookies), browser_name.capitalize())
|
||||||
return cookies
|
return cookies
|
||||||
|
|
||||||
|
|
||||||
@@ -196,13 +201,14 @@ def load_cookies_chromium(browser_name, profile=None,
|
|||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# firefox
|
# firefox
|
||||||
|
|
||||||
def _firefox_cookies_database(profile=None, container=None):
|
def _firefox_cookies_database(browser_name, profile=None, container=None):
|
||||||
if not profile:
|
if not profile:
|
||||||
search_root = _firefox_browser_directory()
|
search_root = _firefox_browser_directory(browser_name)
|
||||||
elif _is_path(profile):
|
elif _is_path(profile):
|
||||||
search_root = profile
|
search_root = profile
|
||||||
else:
|
else:
|
||||||
search_root = os.path.join(_firefox_browser_directory(), profile)
|
search_root = os.path.join(
|
||||||
|
_firefox_browser_directory(browser_name), profile)
|
||||||
|
|
||||||
path = _find_most_recently_used_file(search_root, "cookies.sqlite")
|
path = _find_most_recently_used_file(search_root, "cookies.sqlite")
|
||||||
if path is None:
|
if path is None:
|
||||||
@@ -245,14 +251,27 @@ def _firefox_cookies_database(profile=None, container=None):
|
|||||||
return path, container_id
|
return path, container_id
|
||||||
|
|
||||||
|
|
||||||
def _firefox_browser_directory():
|
def _firefox_browser_directory(browser_name):
|
||||||
|
join = os.path.join
|
||||||
|
|
||||||
if sys.platform in ("win32", "cygwin"):
|
if sys.platform in ("win32", "cygwin"):
|
||||||
return os.path.expandvars(
|
appdata = os.path.expandvars("%APPDATA%")
|
||||||
r"%APPDATA%\Mozilla\Firefox\Profiles")
|
return {
|
||||||
if sys.platform == "darwin":
|
"firefox": join(appdata, R"Mozilla\Firefox\Profiles"),
|
||||||
return os.path.expanduser(
|
"zen" : join(appdata, R"zen\Profiles")
|
||||||
"~/Library/Application Support/Firefox/Profiles")
|
}[browser_name]
|
||||||
return os.path.expanduser("~/.mozilla/firefox")
|
elif sys.platform == "darwin":
|
||||||
|
appdata = os.path.expanduser("~/Library/Application Support")
|
||||||
|
return {
|
||||||
|
"firefox": join(appdata, R"Firefox/Profiles"),
|
||||||
|
"zen" : join(appdata, R"zen/Profiles")
|
||||||
|
}[browser_name]
|
||||||
|
else:
|
||||||
|
home = os.path.expanduser("~")
|
||||||
|
return {
|
||||||
|
"firefox": join(home, R".mozilla/firefox"),
|
||||||
|
"zen" : join(home, R".zen")
|
||||||
|
}[browser_name]
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user