Commit 8db52414 authored by dmazzoni@chromium.org's avatar dmazzoni@chromium.org

Expose "Chrome" as accessible product name.

Moves source of the various components of the user agent
product name and version to ChromeVersionInfo, and
exposes them in ChromeContentClient.

BUG=255053

Review URL: https://chromiumcodereview.appspot.com/18055008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209317 0039d316-1c4b-4281-b951-d872f2087c98
parent ad677770
...@@ -53,9 +53,9 @@ ...@@ -53,9 +53,9 @@
#include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
#include "chrome/browser/upgrade_detector.h" #include "chrome/browser/upgrade_detector.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h" #include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
...@@ -964,10 +964,13 @@ void ToggleRequestTabletSite(Browser* browser) { ...@@ -964,10 +964,13 @@ void ToggleRequestTabletSite(Browser* browser) {
entry->SetIsOverridingUserAgent(false); entry->SetIsOverridingUserAgent(false);
} else { } else {
entry->SetIsOverridingUserAgent(true); entry->SetIsOverridingUserAgent(true);
chrome::VersionInfo version_info;
std::string product;
if (version_info.is_valid())
product = version_info.ProductNameAndVersionForUserAgent();
current_tab->SetUserAgentOverride( current_tab->SetUserAgentOverride(
webkit_glue::BuildUserAgentFromOSAndProduct( webkit_glue::BuildUserAgentFromOSAndProduct(
kOsOverrideForTabletSite, kOsOverrideForTabletSite, product));
ChromeContentClient::GetProductImpl()));
} }
controller.ReloadOriginalRequestURL(true); controller.ReloadOriginalRequestURL(true);
} }
......
...@@ -387,13 +387,6 @@ bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { ...@@ -387,13 +387,6 @@ bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) {
namespace chrome { namespace chrome {
std::string ChromeContentClient::GetProductImpl() {
chrome::VersionInfo version_info;
std::string product("Chrome/");
product += version_info.is_valid() ? version_info.Version() : "0.0.0.0";
return product;
}
void ChromeContentClient::SetActiveURL(const GURL& url) { void ChromeContentClient::SetActiveURL(const GURL& url) {
child_process_logging::SetActiveURL(url); child_process_logging::SetActiveURL(url);
} }
...@@ -439,7 +432,9 @@ bool ChromeContentClient::CanHandleWhileSwappedOut( ...@@ -439,7 +432,9 @@ bool ChromeContentClient::CanHandleWhileSwappedOut(
} }
std::string ChromeContentClient::GetProduct() const { std::string ChromeContentClient::GetProduct() const {
return GetProductImpl(); chrome::VersionInfo version_info;
return version_info.is_valid() ?
version_info.ProductNameAndVersionForUserAgent() : std::string();
} }
std::string ChromeContentClient::GetUserAgent() const { std::string ChromeContentClient::GetUserAgent() const {
......
...@@ -19,9 +19,6 @@ class ChromeContentClient : public content::ContentClient { ...@@ -19,9 +19,6 @@ class ChromeContentClient : public content::ContentClient {
static const char* const kNaClPluginName; static const char* const kNaClPluginName;
static const char* const kNaClOldPluginName; static const char* const kNaClOldPluginName;
// This is what the ContentClient::GetProduct implementation calls.
static std::string GetProductImpl();
virtual void SetActiveURL(const GURL& url) OVERRIDE; virtual void SetActiveURL(const GURL& url) OVERRIDE;
virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) OVERRIDE; virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) OVERRIDE;
virtual void AddPepperPlugins( virtual void AddPepperPlugins(
......
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
namespace chrome { namespace chrome {
std::string VersionInfo::ProductNameAndVersionForUserAgent() const {
if (!is_valid())
return std::string();
return "Chrome/" + Version();
}
#if defined(OS_WIN) || defined(OS_MACOSX) #if defined(OS_WIN) || defined(OS_MACOSX)
// On Windows and Mac, we get the Chrome version info by querying // On Windows and Mac, we get the Chrome version info by querying
// FileVersionInfo for the current module. // FileVersionInfo for the current module.
......
...@@ -36,6 +36,9 @@ class VersionInfo { ...@@ -36,6 +36,9 @@ class VersionInfo {
// check is_valid(). // check is_valid().
bool is_valid() const; bool is_valid() const;
// E.g. "Chrome/a.b.c.d"
std::string ProductNameAndVersionForUserAgent() const;
// E.g. "Chromium" or "Google Chrome". // E.g. "Chromium" or "Google Chrome".
std::string Name() const; std::string Name() const;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <UIAutomationCoreApi.h> #include <UIAutomationCoreApi.h>
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/win/enum_variant.h" #include "base/win/enum_variant.h"
...@@ -867,8 +868,14 @@ STDMETHODIMP BrowserAccessibilityWin::get_appName(BSTR* app_name) { ...@@ -867,8 +868,14 @@ STDMETHODIMP BrowserAccessibilityWin::get_appName(BSTR* app_name) {
if (!app_name) if (!app_name)
return E_INVALIDARG; return E_INVALIDARG;
std::string product_name = GetContentClient()->GetProduct(); // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
*app_name = SysAllocString(UTF8ToUTF16(product_name).c_str()); // the part before the "/".
std::vector<std::string> product_components;
base::SplitString(GetContentClient()->GetProduct(), '/', &product_components);
DCHECK_EQ(2U, product_components.size());
if (product_components.size() != 2)
return E_FAIL;
*app_name = SysAllocString(UTF8ToUTF16(product_components[0]).c_str());
DCHECK(*app_name); DCHECK(*app_name);
return *app_name ? S_OK : E_FAIL; return *app_name ? S_OK : E_FAIL;
} }
...@@ -880,8 +887,14 @@ STDMETHODIMP BrowserAccessibilityWin::get_appVersion(BSTR* app_version) { ...@@ -880,8 +887,14 @@ STDMETHODIMP BrowserAccessibilityWin::get_appVersion(BSTR* app_version) {
if (!app_version) if (!app_version)
return E_INVALIDARG; return E_INVALIDARG;
std::string user_agent = GetContentClient()->GetUserAgent(); // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
*app_version = SysAllocString(UTF8ToUTF16(user_agent).c_str()); // the part after the "/".
std::vector<std::string> product_components;
base::SplitString(GetContentClient()->GetProduct(), '/', &product_components);
DCHECK_EQ(2U, product_components.size());
if (product_components.size() != 2)
return E_FAIL;
*app_version = SysAllocString(UTF8ToUTF16(product_components[1]).c_str());
DCHECK(*app_version); DCHECK(*app_version);
return *app_version ? S_OK : E_FAIL; return *app_version ? S_OK : E_FAIL;
} }
......
...@@ -125,8 +125,9 @@ class CONTENT_EXPORT ContentClient { ...@@ -125,8 +125,9 @@ class CONTENT_EXPORT ContentClient {
// behalf of a swapped out renderer. // behalf of a swapped out renderer.
virtual bool CanHandleWhileSwappedOut(const IPC::Message& message); virtual bool CanHandleWhileSwappedOut(const IPC::Message& message);
// Returns a string describing the embedder version. Used as part of the // Returns a string describing the embedder product name and version,
// user agent string. // of the form "productname/version", with no other slashes.
// Used as part of the user agent string.
virtual std::string GetProduct() const; virtual std::string GetProduct() const;
// Returns the user agent. // Returns the user agent.
......
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