summaryrefslogtreecommitdiffstats
path: root/src/core/profile_qt.cpp
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2023-07-18 15:20:22 +0200
committerSzabolcs David <davidsz@inf.u-szeged.hu>2023-08-02 08:19:25 +0200
commit7af3d247a930baa3262654082c441f8a015889b6 (patch)
tree33a98131d43a1463a6bebbe1222e3b9063ff6a9b /src/core/profile_qt.cpp
parent6b46b4503d3672852b4bf590dd276ff4003b26c8 (diff)
Fix crashing PDF viewer after changing the storage path
Changing the storage path (and recreating PrefService) caused a crash in the extension system, because the pointer of the old PrefService was dangling in ExtensionPrefs. Recreating it as well seems to be the nicest way to update its dangling part. Pick-to: 6.5 6.6 Task-number: QTBUG-115188 Change-Id: I46321b1737432c7d1cd6ec41c76e7803e69f2011 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/core/profile_qt.cpp')
-rw-r--r--src/core/profile_qt.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/core/profile_qt.cpp b/src/core/profile_qt.cpp
index 410340fb8..c912c9898 100644
--- a/src/core/profile_qt.cpp
+++ b/src/core/profile_qt.cpp
@@ -46,7 +46,12 @@
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
+#include "base/command_line.h"
#include "components/guest_view/browser/guest_view_manager.h"
+#include "extensions/browser/extension_pref_value_map_factory.h"
+#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_prefs_factory.h"
+#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/pref_names.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
@@ -246,6 +251,7 @@ content::FileSystemAccessPermissionContext *ProfileQt::GetFileSystemAccessPermis
void ProfileQt::setupPrefService()
{
+ const bool recreation = m_prefServiceAdapter.prefService() != nullptr;
profile_metrics::SetBrowserProfileType(this,
IsOffTheRecord()
? profile_metrics::BrowserProfileType::kIncognito
@@ -253,12 +259,28 @@ void ProfileQt::setupPrefService()
// Remove previous handler before we set a new one or we will assert
// TODO: Remove in Qt6
- if (m_prefServiceAdapter.prefService() != nullptr) {
+ if (recreation) {
user_prefs::UserPrefs::Remove(this);
m_prefServiceAdapter.commit();
}
m_prefServiceAdapter.setup(*m_profileAdapter);
user_prefs::UserPrefs::Set(this, m_prefServiceAdapter.prefService());
+
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ if (recreation) {
+ // Recreate ExtensionPrefs to update its pointer to the new PrefService
+ extensions::ExtensionsBrowserClient *client = extensions::ExtensionsBrowserClient::Get();
+ std::vector<extensions::EarlyExtensionPrefsObserver *> prefsObservers;
+ client->GetEarlyExtensionPrefsObservers(this, &prefsObservers);
+ extensions::ExtensionPrefs *extensionPrefs = extensions::ExtensionPrefs::Create(
+ this, client->GetPrefServiceForContext(this),
+ this->GetPath().AppendASCII(extensions::kInstallDirectoryName),
+ ExtensionPrefValueMapFactory::GetForBrowserContext(this),
+ client->AreExtensionsDisabled(*base::CommandLine::ForCurrentProcess(), this),
+ prefsObservers);
+ extensions::ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(this, base::WrapUnique(extensionPrefs));
+ }
+#endif
}
PrefServiceAdapter &ProfileQt::prefServiceAdapter()