Commit e91cfbaf authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Feedback API: Get user agent from ExtensionsClient

Add ExtensionsClient::GetUserAgent() for extension related
classes to use instead of querying the ChromeContentClient directly.

Bug: 446329
Change-Id: I3416a14d359ba50bec22d376410a0674d620b67f
Reviewed-on: https://chromium-review.googlesource.com/587403
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491352}
parent 43e4ffc6
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/browser/feedback/system_logs/chrome_system_logs_fetcher.h" #include "chrome/browser/feedback/system_logs/chrome_system_logs_fetcher.h"
#include "chrome/common/chrome_content_client.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/browser/blob_reader.h" #include "extensions/browser/blob_reader.h"
#include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/extensions_browser_client.h"
#include "extensions/common/extensions_client.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -33,7 +33,7 @@ void FeedbackService::SendFeedback(content::BrowserContext* browser_context, ...@@ -33,7 +33,7 @@ void FeedbackService::SendFeedback(content::BrowserContext* browser_context,
const SendFeedbackCallback& callback) { const SendFeedbackCallback& callback) {
feedback_data->set_locale( feedback_data->set_locale(
ExtensionsBrowserClient::Get()->GetApplicationLocale()); ExtensionsBrowserClient::Get()->GetApplicationLocale());
feedback_data->set_user_agent(GetUserAgent()); feedback_data->set_user_agent(ExtensionsClient::Get()->GetUserAgent());
if (!feedback_data->attached_file_uuid().empty()) { if (!feedback_data->attached_file_uuid().empty()) {
// Self-deleting object. // Self-deleting object.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/api_features.h" #include "chrome/common/extensions/api/api_features.h"
#include "chrome/common/extensions/api/behavior_features.h" #include "chrome/common/extensions/api/behavior_features.h"
...@@ -336,6 +337,10 @@ bool ChromeExtensionsClient::ExtensionAPIEnabledInExtensionServiceWorkers() ...@@ -336,6 +337,10 @@ bool ChromeExtensionsClient::ExtensionAPIEnabledInExtensionServiceWorkers()
return GetCurrentChannel() == version_info::Channel::UNKNOWN; return GetCurrentChannel() == version_info::Channel::UNKNOWN;
} }
std::string ChromeExtensionsClient::GetUserAgent() const {
return ::GetUserAgent();
}
// static // static
ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() { ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() {
return g_client.Pointer(); return g_client.Pointer();
......
...@@ -53,6 +53,7 @@ class ChromeExtensionsClient : public ExtensionsClient { ...@@ -53,6 +53,7 @@ class ChromeExtensionsClient : public ExtensionsClient {
std::set<base::FilePath> GetBrowserImagePaths( std::set<base::FilePath> GetBrowserImagePaths(
const Extension* extension) override; const Extension* extension) override;
bool ExtensionAPIEnabledInExtensionServiceWorkers() const override; bool ExtensionAPIEnabledInExtensionServiceWorkers() const override;
std::string GetUserAgent() const override;
// Get the LazyInstance for ChromeExtensionsClient. // Get the LazyInstance for ChromeExtensionsClient.
static ChromeExtensionsClient* GetInstance(); static ChromeExtensionsClient* GetInstance();
......
...@@ -32,6 +32,10 @@ bool ExtensionsClient::ExtensionAPIEnabledInExtensionServiceWorkers() const { ...@@ -32,6 +32,10 @@ bool ExtensionsClient::ExtensionAPIEnabledInExtensionServiceWorkers() const {
return false; return false;
} }
std::string ExtensionsClient::GetUserAgent() const {
return std::string();
}
void ExtensionsClient::Set(ExtensionsClient* client) { void ExtensionsClient::Set(ExtensionsClient* client) {
// This can happen in unit tests, where the utility thread runs in-process. // This can happen in unit tests, where the utility thread runs in-process.
if (g_client) if (g_client)
......
...@@ -128,6 +128,9 @@ class ExtensionsClient { ...@@ -128,6 +128,9 @@ class ExtensionsClient {
// Can be overridden in tests. // Can be overridden in tests.
virtual bool ExtensionAPIEnabledInExtensionServiceWorkers() const; virtual bool ExtensionAPIEnabledInExtensionServiceWorkers() const;
// Returns the user agent used by the content module.
virtual std::string GetUserAgent() const;
// Return the extensions client. // Return the extensions client.
static ExtensionsClient* Get(); static ExtensionsClient* Get();
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/version_info/version_info.h"
#include "content/public/common/user_agent.h"
#include "extensions/common/api/generated_schemas.h" #include "extensions/common/api/generated_schemas.h"
#include "extensions/common/common_manifest_handlers.h" #include "extensions/common/common_manifest_handlers.h"
#include "extensions/common/extension_urls.h" #include "extensions/common/extension_urls.h"
...@@ -190,4 +192,9 @@ bool ShellExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const { ...@@ -190,4 +192,9 @@ bool ShellExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
return true; return true;
} }
std::string ShellExtensionsClient::GetUserAgent() const {
return content::BuildUserAgentFromProduct(
version_info::GetProductNameAndVersionForUserAgent());
}
} // namespace extensions } // namespace extensions
...@@ -44,6 +44,7 @@ class ShellExtensionsClient : public ExtensionsClient { ...@@ -44,6 +44,7 @@ class ShellExtensionsClient : public ExtensionsClient {
const GURL& GetWebstoreBaseURL() const override; const GURL& GetWebstoreBaseURL() const override;
const GURL& GetWebstoreUpdateURL() const override; const GURL& GetWebstoreUpdateURL() const override;
bool IsBlacklistUpdateURL(const GURL& url) const override; bool IsBlacklistUpdateURL(const GURL& url) const override;
std::string GetUserAgent() const override;
private: private:
const ExtensionsAPIPermissions extensions_api_permissions_; const ExtensionsAPIPermissions extensions_api_permissions_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment