From 164f3839cc24d14590e11f898a39d4b05b90ce51 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Mon, 2 Dec 2013 18:04:25 +0100 Subject: Use ContentMainDelegateQt also for child processes This will be necessary in order for the render process to load localized strings among other things. Change-Id: Ibb75e49f0bc583c158af61817e5b350f3534ec16 Reviewed-by: Andras Becsi --- src/core/content_main_delegate_qt.cpp | 94 +++++++++++++++++++++++++++++++++++ src/core/content_main_delegate_qt.h | 69 +++++++++++++++++++++++++ src/core/core_gyp_generator.pro | 2 + src/core/process_main.cpp | 4 +- src/core/web_engine_context.cpp | 51 +------------------ 5 files changed, 169 insertions(+), 51 deletions(-) create mode 100644 src/core/content_main_delegate_qt.cpp create mode 100644 src/core/content_main_delegate_qt.h diff --git a/src/core/content_main_delegate_qt.cpp b/src/core/content_main_delegate_qt.cpp new file mode 100644 index 000000000..9798d6f70 --- /dev/null +++ b/src/core/content_main_delegate_qt.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "content_main_delegate_qt.h" + +#include "base/path_service.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/ui_base_paths.h" +#include "ui/base/resource/resource_bundle.h" +#include +#include +#include + +#include "content_client_qt.h" +#include "type_conversion.h" + +static QByteArray subProcessPath() { + static bool initialized = false; +#ifdef QTWEBENGINEPROCESS_PATH + static QByteArray processPath(QTWEBENGINEPROCESS_PATH); +#else + static QByteArray processPath; +#endif + if (initialized) + return processPath; + // Allow overriding at runtime for the time being. + const QByteArray fromEnv = qgetenv("QTWEBENGINEPROCESS_PATH"); + if (!fromEnv.isEmpty()) + processPath = fromEnv; + if (processPath.isEmpty()) + qFatal("QTWEBENGINEPROCESS_PATH environment variable not set or empty."); + initialized = true; + return processPath; +} + +void ContentMainDelegateQt::PreSandboxStartup() +{ + PathService::Override(base::FILE_EXE, base::FilePath(toFilePathString(subProcessPath()))); + const QString localesPath(QLibraryInfo::location(QLibraryInfo::TranslationsPath) % QStringLiteral("/qtwebengine_locales")); + PathService::Override(ui::DIR_LOCALES, base::FilePath(toFilePathString(localesPath))); + + ui::ResourceBundle::InitSharedInstanceWithLocale(l10n_util::GetApplicationLocale(std::string("en-US")), 0); +} + +content::ContentBrowserClient *ContentMainDelegateQt::CreateContentBrowserClient() +{ + m_browserClient.reset(new ContentBrowserClientQt); + return m_browserClient.get(); +} + +bool ContentMainDelegateQt::BasicStartupComplete(int *exit_code) +{ + SetContentClient(new ContentClientQt); + return false; +} + diff --git a/src/core/content_main_delegate_qt.h b/src/core/content_main_delegate_qt.h new file mode 100644 index 000000000..af58bc323 --- /dev/null +++ b/src/core/content_main_delegate_qt.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONTENT_MAIN_DELEGATE_QT_H +#define CONTENT_MAIN_DELEGATE_QT_H + +#include "content/public/app/content_main_delegate.h" + +#include "base/memory/scoped_ptr.h" +#include + +#include "content_browser_client_qt.h" + + +class ContentMainDelegateQt : public content::ContentMainDelegate +{ +public: + + // This is where the embedder puts all of its startup code that needs to run + // before the sandbox is engaged. + void PreSandboxStartup() Q_DECL_OVERRIDE; + + content::ContentBrowserClient* CreateContentBrowserClient() Q_DECL_OVERRIDE; + + bool BasicStartupComplete(int* /*exit_code*/) Q_DECL_OVERRIDE; + +private: + scoped_ptr m_browserClient; +}; + +#endif // CONTENT_MAIN_DELEGATE_QT_H diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index a4128fc72..d145f7b07 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -44,6 +44,7 @@ SOURCES = \ chromium_overrides.cpp \ content_client_qt.cpp \ content_browser_client_qt.cpp \ + content_main_delegate_qt.cpp \ delegated_frame_node.cpp \ dev_tools_http_handler_delegate_qt.cpp \ download_manager_delegate_qt.cpp \ @@ -67,6 +68,7 @@ HEADERS = \ chromium_overrides.h \ content_client_qt.h \ content_browser_client_qt.h \ + content_main_delegate_qt.h \ delegated_frame_node.h \ dev_tools_http_handler_delegate_qt.h \ download_manager_delegate_qt.h \ diff --git a/src/core/process_main.cpp b/src/core/process_main.cpp index af44ba600..a8c1b3ad5 100644 --- a/src/core/process_main.cpp +++ b/src/core/process_main.cpp @@ -40,13 +40,15 @@ ****************************************************************************/ #include "process_main.h" + +#include "content_main_delegate_qt.h" #include "content/public/app/content_main.h" namespace QtWebEngine { int processMain(int argc, const char **argv) { - return content::ContentMain(argc, argv, 0); + return content::ContentMain(argc, argv, new ContentMainDelegateQt); } } diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index e26027207..dbaa948bf 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -45,10 +45,8 @@ #include "base/command_line.h" #include "base/files/file_path.h" -#include "base/path_service.h" #include "base/run_loop.h" #include "base/threading/thread_restrictions.h" -#include "content/public/app/content_main_delegate.h" #include "content/public/app/content_main_runner.h" #include "content/public/browser/browser_main_runner.h" #include "content/public/common/content_paths.h" @@ -59,6 +57,7 @@ #include "content_browser_client_qt.h" #include "content_client_qt.h" +#include "content_main_delegate_qt.h" #include "type_conversion.h" #include #include @@ -68,55 +67,8 @@ namespace { scoped_refptr sContext; -static QByteArray subProcessPath() { - static bool initialized = false; -#ifdef QTWEBENGINEPROCESS_PATH - static QByteArray processPath(QTWEBENGINEPROCESS_PATH); -#else - static QByteArray processPath; -#endif - if (initialized) - return processPath; - // Allow overriding at runtime for the time being. - const QByteArray fromEnv = qgetenv("QTWEBENGINEPROCESS_PATH"); - if (!fromEnv.isEmpty()) - processPath = fromEnv; - if (processPath.isEmpty()) - qFatal("QTWEBENGINEPROCESS_PATH environment variable not set or empty."); - initialized = true; - return processPath; -} - } // namespace -class ContentMainDelegateQt : public content::ContentMainDelegate -{ -public: - - // This is where the embedder puts all of its startup code that needs to run - // before the sandbox is engaged. - void PreSandboxStartup() Q_DECL_OVERRIDE - { - PathService::Override(base::FILE_EXE, base::FilePath(toFilePathString(subProcessPath()))); - } - - content::ContentBrowserClient* CreateContentBrowserClient() Q_DECL_OVERRIDE - { - m_browserClient.reset(new ContentBrowserClientQt); - return m_browserClient.get(); - } - - bool BasicStartupComplete(int* exit_code) Q_DECL_OVERRIDE - { - SetContentClient(new ContentClientQt); - return false; - } - -private: - scoped_ptr m_browserClient; -}; - - WebEngineContext::~WebEngineContext() { m_runLoop->AfterRun(); @@ -161,7 +113,6 @@ WebEngineContext::WebEngineContext(WebContentsAdapterClient::RenderingMode rende CommandLine* parsedCommandLine = CommandLine::ForCurrentProcess(); parsedCommandLine->AppendSwitchASCII(switches::kUserAgent, webkit_glue::BuildUserAgentFromProduct("QtWebEngine/0.1")); - parsedCommandLine->AppendSwitchASCII(switches::kBrowserSubprocessPath, subProcessPath().constData()); parsedCommandLine->AppendSwitch(switches::kNoSandbox); parsedCommandLine->AppendSwitch(switches::kDisablePlugins); -- cgit v1.2.3