From e7fd5c3a43aed07cf0a1561c408b631090be8374 Mon Sep 17 00:00:00 2001
From: Ryan Gonzalez <rymg19@gmail.com>
Date: Tue, 25 Aug 2020 19:26:07 -0500
Subject: [PATCH] flatpak: Adjust paths for the sandbox

---
 chrome/common/BUILD.gn        |  4 ++++
 chrome/common/chrome_paths.cc | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn
index 40e1d1c431dd0..e4a19c80e1afc 100644
--- a/chrome/common/BUILD.gn
+++ b/chrome/common/BUILD.gn
@@ -621,6 +621,10 @@ static_library("constants") {
       "//third_party/widevine/cdm:headers",
     ]
   }
+
+  if (is_linux) {
+    deps += [ "//sandbox/linux:sandbox_services" ]
+  }
 }
 
 # Use a static library here because many test binaries depend on this but don't
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc
index 6476c59ba6378..9f1b950b14adc 100644
--- a/chrome/common/chrome_paths.cc
+++ b/chrome/common/chrome_paths.cc
@@ -38,6 +38,10 @@
 #include "base/win/registry.h"
 #endif
 
+#if BUILDFLAG(IS_LINUX)
+#include "sandbox/linux/services/flatpak_sandbox.h"
+#endif
+
 #if BUILDFLAG(ENABLE_WIDEVINE)
 #include "third_party/widevine/cdm/widevine_cdm_common.h"  // nogncheck
 #endif
@@ -502,6 +506,14 @@ bool PathProvider(int key, base::FilePath* result) {
 #endif
 #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_OPENBSD)
     case chrome::DIR_POLICY_FILES: {
+#if defined(OS_LINUX)
+      if (sandbox::FlatpakSandbox::GetInstance()->GetSandboxLevel() >
+          sandbox::FlatpakSandbox::SandboxLevel::kNone) {
+        cur = base::FilePath(
+            FILE_PATH_LITERAL("/app/chromium/extensions/policies"));
+        break;
+      }
+#endif
       cur = base::FilePath(policy::kPolicyPath);
       break;
     }
@@ -518,7 +530,13 @@ bool PathProvider(int key, base::FilePath* result) {
 #endif
 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
     case chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS: {
-      cur = base::FilePath(kFilepathSinglePrefExtensions);
+      if (sandbox::FlatpakSandbox::GetInstance()->GetSandboxLevel() >
+          sandbox::FlatpakSandbox::SandboxLevel::kNone) {
+        cur = base::FilePath(
+            FILE_PATH_LITERAL("/app/chromium/extensions/extensions"));
+      } else {
+        cur = base::FilePath(kFilepathSinglePrefExtensions);
+      }
       break;
     }
 #endif
@@ -565,6 +583,12 @@ bool PathProvider(int key, base::FilePath* result) {
           "/Library/Application Support/Chromium/NativeMessagingHosts"));
 #endif
 #else  // BUILDFLAG(IS_MAC)
+      if (sandbox::FlatpakSandbox::GetInstance()->GetSandboxLevel() >
+          sandbox::FlatpakSandbox::SandboxLevel::kNone) {
+        cur = base::FilePath(FILE_PATH_LITERAL(
+            "/app/chromium/extensions/native-messaging-hosts"));
+        break;
+      }
 #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
       cur = base::FilePath(
           FILE_PATH_LITERAL("/etc/opt/chrome/native-messaging-hosts"));
-- 
2.47.1