refactor: eliminate brightray::ContentClient (#15303)
This commit is contained in:
parent
9262731f2c
commit
e8e7edf017
10 changed files with 30 additions and 122 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "electron/buildflags/buildflags.h"
|
||||
#include "ppapi/shared_impl/ppapi_permissions.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "url/url_constants.h"
|
||||
// In SHARED_INTERMEDIATE_DIR.
|
||||
#include "widevine_cdm_version.h" // NOLINT(build/include)
|
||||
|
@ -193,6 +194,24 @@ base::string16 AtomContentClient::GetLocalizedString(int message_id) const {
|
|||
return l10n_util::GetStringUTF16(message_id);
|
||||
}
|
||||
|
||||
base::StringPiece AtomContentClient::GetDataResource(
|
||||
int resource_id,
|
||||
ui::ScaleFactor scale_factor) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
||||
resource_id, scale_factor);
|
||||
}
|
||||
|
||||
gfx::Image& AtomContentClient::GetNativeImageNamed(int resource_id) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
||||
resource_id);
|
||||
}
|
||||
|
||||
base::RefCountedMemory* AtomContentClient::GetDataResourceBytes(
|
||||
int resource_id) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
||||
resource_id);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
||||
schemes->standard_schemes.push_back("chrome-extension");
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "brightray/common/content_client.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomContentClient : public brightray::ContentClient {
|
||||
class AtomContentClient : public content::ContentClient {
|
||||
public:
|
||||
AtomContentClient();
|
||||
~AtomContentClient() override;
|
||||
|
@ -23,6 +23,10 @@ class AtomContentClient : public brightray::ContentClient {
|
|||
std::string GetProduct() const override;
|
||||
std::string GetUserAgent() const override;
|
||||
base::string16 GetLocalizedString(int message_id) const override;
|
||||
base::StringPiece GetDataResource(int resource_id,
|
||||
ui::ScaleFactor) const override;
|
||||
gfx::Image& GetNativeImageNamed(int resource_id) const override;
|
||||
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override;
|
||||
void AddAdditionalSchemes(Schemes* schemes) override;
|
||||
void AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) override;
|
||||
|
|
|
@ -129,6 +129,9 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
|||
base::win::DisableHandleVerifier();
|
||||
#endif
|
||||
|
||||
content_client_ = std::make_unique<AtomContentClient>();
|
||||
SetContentClient(content_client_.get());
|
||||
|
||||
return brightray::MainDelegate::BasicStartupComplete(exit_code);
|
||||
}
|
||||
|
||||
|
@ -212,9 +215,4 @@ bool AtomMainDelegate::DelaySandboxInitialization(
|
|||
}
|
||||
#endif
|
||||
|
||||
std::unique_ptr<brightray::ContentClient>
|
||||
AtomMainDelegate::CreateContentClient() {
|
||||
return std::make_unique<AtomContentClient>();
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "brightray/common/content_client.h"
|
||||
#include "brightray/common/main_delegate.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -35,7 +35,6 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
|||
#endif
|
||||
|
||||
// brightray::MainDelegate:
|
||||
std::unique_ptr<brightray::ContentClient> CreateContentClient() override;
|
||||
#if defined(OS_MACOSX)
|
||||
void OverrideChildProcessPath() override;
|
||||
void OverrideFrameworkBundlePath() override;
|
||||
|
@ -47,6 +46,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
|||
#endif
|
||||
|
||||
std::unique_ptr<content::ContentBrowserClient> browser_client_;
|
||||
std::unique_ptr<content::ContentClient> content_client_;
|
||||
std::unique_ptr<content::ContentRendererClient> renderer_client_;
|
||||
std::unique_ptr<content::ContentUtilityClient> utility_client_;
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/common/content_client.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/devtools_frontend_host.h"
|
||||
#include "content/public/browser/devtools_socket_factory.h"
|
||||
|
|
|
@ -30,8 +30,6 @@ static_library("brightray") {
|
|||
"common/application_info.h",
|
||||
"common/application_info_mac.mm",
|
||||
"common/application_info_win.cc",
|
||||
"common/content_client.cc",
|
||||
"common/content_client.h",
|
||||
"common/mac/main_application_bundle.h",
|
||||
"common/mac/main_application_bundle.mm",
|
||||
"common/main_delegate.cc",
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#include "brightray/common/content_client.h"
|
||||
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
std::string GetProductInternal() {
|
||||
auto name = GetApplicationName();
|
||||
base::RemoveChars(name, base::kWhitespaceASCII, &name);
|
||||
return base::StringPrintf("%s/%s", name.c_str(),
|
||||
GetApplicationVersion().c_str());
|
||||
}
|
||||
|
||||
std::string GetBrightrayUserAgent() {
|
||||
return content::BuildUserAgentFromProduct(GetProductInternal());
|
||||
}
|
||||
|
||||
ContentClient::ContentClient() {}
|
||||
|
||||
ContentClient::~ContentClient() {}
|
||||
|
||||
std::string ContentClient::GetProduct() const {
|
||||
return GetProductInternal();
|
||||
}
|
||||
|
||||
std::string ContentClient::GetUserAgent() const {
|
||||
return GetBrightrayUserAgent();
|
||||
}
|
||||
|
||||
base::string16 ContentClient::GetLocalizedString(int message_id) const {
|
||||
return l10n_util::GetStringUTF16(message_id);
|
||||
}
|
||||
|
||||
base::StringPiece ContentClient::GetDataResource(
|
||||
int resource_id,
|
||||
ui::ScaleFactor scale_factor) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
||||
resource_id, scale_factor);
|
||||
}
|
||||
|
||||
gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
||||
resource_id);
|
||||
}
|
||||
|
||||
base::RefCountedMemory* ContentClient::GetDataResourceBytes(
|
||||
int resource_id) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
||||
resource_id);
|
||||
}
|
||||
|
||||
} // namespace brightray
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#ifndef BRIGHTRAY_COMMON_CONTENT_CLIENT_H_
|
||||
#define BRIGHTRAY_COMMON_CONTENT_CLIENT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
std::string GetBrightrayUserAgent();
|
||||
|
||||
class ContentClient : public content::ContentClient {
|
||||
public:
|
||||
ContentClient();
|
||||
~ContentClient() override;
|
||||
|
||||
private:
|
||||
std::string GetProduct() const override;
|
||||
std::string GetUserAgent() const override;
|
||||
base::string16 GetLocalizedString(int message_id) const override;
|
||||
base::StringPiece GetDataResource(int resource_id,
|
||||
ui::ScaleFactor) const override;
|
||||
gfx::Image& GetNativeImageNamed(int resource_id) const override;
|
||||
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ContentClient);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BRIGHTRAY_COMMON_CONTENT_CLIENT_H_
|
|
@ -10,7 +10,6 @@
|
|||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/path_service.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "brightray/common/content_client.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "services/service_manager/embedder/switches.h"
|
||||
|
@ -77,13 +76,7 @@ MainDelegate::MainDelegate() {}
|
|||
|
||||
MainDelegate::~MainDelegate() {}
|
||||
|
||||
std::unique_ptr<ContentClient> MainDelegate::CreateContentClient() {
|
||||
return std::unique_ptr<ContentClient>(new ContentClient);
|
||||
}
|
||||
|
||||
bool MainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
content_client_ = CreateContentClient();
|
||||
SetContentClient(content_client_.get());
|
||||
#if defined(OS_MACOSX)
|
||||
OverrideChildProcessPath();
|
||||
OverrideFrameworkBundlePath();
|
||||
|
|
|
@ -22,7 +22,6 @@ class ResourceBundle;
|
|||
namespace brightray {
|
||||
|
||||
class BrowserClient;
|
||||
class ContentClient;
|
||||
|
||||
void LoadResourceBundle(const std::string& locale);
|
||||
void LoadCommonResources();
|
||||
|
@ -33,10 +32,6 @@ class MainDelegate : public content::ContentMainDelegate {
|
|||
~MainDelegate() override;
|
||||
|
||||
protected:
|
||||
// Subclasses can override this to provide their own ContentClient
|
||||
// implementation.
|
||||
virtual std::unique_ptr<ContentClient> CreateContentClient();
|
||||
|
||||
// Subclasses can override this to provide their own BrowserClient
|
||||
// implementation.
|
||||
virtual std::unique_ptr<BrowserClient> CreateBrowserClient();
|
||||
|
@ -54,7 +49,6 @@ class MainDelegate : public content::ContentMainDelegate {
|
|||
private:
|
||||
content::ContentBrowserClient* CreateContentBrowserClient() override;
|
||||
|
||||
std::unique_ptr<ContentClient> content_client_;
|
||||
std::unique_ptr<BrowserClient> browser_client_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MainDelegate);
|
||||
|
|
Loading…
Reference in a new issue