Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions webext/app/credential_manager_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from enum import Enum
import json
import logging
import os
from pathlib import Path
import re
import secrets
import signal
Expand Down Expand Up @@ -473,25 +475,45 @@ async def get_passkey(interface, options, origin, top_origin):
return response_json


def discover_app_id():
desktop_file_name = os.environ.get("GIO_LAUNCHED_DESKTOP_FILE")
if not desktop_file_name:
logging.debug("Browser was not launched from a desktop entry.")
return None

browser_pid = os.getppid()
launched_pid = os.environ.get("GIO_LAUNCHED_DESKTOP_FILE_PID")
if launched_pid != str(browser_pid):
logging.debug(
f"Ignoring {desktop_file_name} from GIO_LAUNCHED_DESKTOP_FILE environment,"
f"it comes from process {launched_pid}, not the browser at {browser_pid}."
)
return None
Comment on lines +484 to +491

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding this correctly, I think this would break if the browser uses a separate process to launch the native messaging binaries than the main process? I think we can probably skip the PID matching check and just read from the desktop file entry.


return Path(desktop_file_name).stem


async def get_interface():
global INTERFACE
if INTERFACE and INTERFACE.bus.connected:
return INTERFACE

bus = await MessageBus().connect()
logging.debug("Connected to bus")
import os

logging.info(os.getcwd())

app_id = discover_app_id() or APP_ID
logging.info(f"Registering with the portal as {app_id}")

msg = Message(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.host.portal.Registry",
"Register",
signature="sa{sv}",
body=[
APP_ID,
app_id,
{},
],
)
Expand Down