summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 16:56:09 +0000
committeryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 16:56:09 +0000
commitd0924cb339decdcc5d9924bae3550e2531d48207 (patch)
tree264b19ca050b454ff4890f5f06f1d007e76386a6
parentb0ddd14c6fef8a42cd922ff62dce62fb3e89439e (diff)
downloadchromium_src-d0924cb339decdcc5d9924bae3550e2531d48207.zip
chromium_src-d0924cb339decdcc5d9924bae3550e2531d48207.tar.gz
chromium_src-d0924cb339decdcc5d9924bae3550e2531d48207.tar.bz2
Upstream most of the user agent code for Android.
Brought along most of the command-line start-up switches. As for requiring the InitUserAgent (and not just having the logic in webkit/glue/user_agent), that's because currently unit tests can't access Java code directly. Using pseudo dependency-injection allows this to work for prod and test. Once apk-based tests are online, we can remove this. Review URL: https://chromiumcodereview.appspot.com/10473002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142974 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/android/chrome_startup_flags.cc53
-rw-r--r--chrome/browser/android/chrome_startup_flags.h16
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc7
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/chrome_content_client.cc7
-rw-r--r--chrome/common/chrome_switches.cc5
-rw-r--r--chrome/common/chrome_switches.h4
-rw-r--r--content/app/android/content_jni_registrar.cc2
-rw-r--r--content/app/android/content_main.cc10
-rw-r--r--content/app/android/user_agent.cc30
-rw-r--r--content/app/android/user_agent.h22
-rw-r--r--content/content_app.gypi2
-rw-r--r--content/content_jni.gypi2
-rw-r--r--content/public/android/java/org/chromium/content/app/UserAgent.java50
-rw-r--r--webkit/glue/user_agent.cc25
-rw-r--r--webkit/glue/user_agent.h11
16 files changed, 230 insertions, 18 deletions
diff --git a/chrome/browser/android/chrome_startup_flags.cc b/chrome/browser/android/chrome_startup_flags.cc
new file mode 100644
index 0000000..340514a
--- /dev/null
+++ b/chrome/browser/android/chrome_startup_flags.cc
@@ -0,0 +1,53 @@
+// 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 file.
+
+#include <jni.h>
+
+#include "chrome/browser/android/chrome_startup_flags.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "chrome/common/chrome_switches.h"
+
+namespace {
+
+void SetCommandLineSwitch(const std::string& switch_string) {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (!command_line->HasSwitch(switch_string))
+ command_line->AppendSwitch(switch_string);
+}
+
+bool IsTabletUi() {
+ NOTIMPLEMENTED() << "TODO(yfriedman): Upstream this";
+ return false;
+}
+} // namespace
+
+void SetChromeSpecificCommandLineFlags() {
+ CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
+
+ // Always enable SPDY
+ parsed_command_line->AppendSwitch(switches::kEnableNpn);
+
+ // Turn on autofill
+ SetCommandLineSwitch(switches::kExternalAutofillPopup);
+
+ // Tablet UI switch (used for using correct version of NTP HTML).
+ if (IsTabletUi())
+ parsed_command_line->AppendSwitch(switches::kTabletUi);
+
+ // TODO(jcivelli): Enable the History Quick Provider and figure out
+ // why it reports the wrong results for some pages.
+ parsed_command_line->AppendSwitch(switches::kDisableHistoryQuickProvider);
+
+ // Enable prerender for the omnibox.
+ parsed_command_line->AppendSwitchASCII(
+ switches::kPrerenderMode, switches::kPrerenderModeSwitchValueEnabled);
+ parsed_command_line->AppendSwitchASCII(
+ switches::kPrerenderFromOmnibox,
+ switches::kPrerenderFromOmniboxSwitchValueEnabled);
+}
diff --git a/chrome/browser/android/chrome_startup_flags.h b/chrome/browser/android/chrome_startup_flags.h
new file mode 100644
index 0000000..1e8b6f8
--- /dev/null
+++ b/chrome/browser/android/chrome_startup_flags.h
@@ -0,0 +1,16 @@
+// 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 file.
+
+#ifndef CHROME_BROWSER_ANDROID_CHROME_STARTUP_FLAGS_H_
+#define CHROME_BROWSER_ANDROID_CHROME_STARTUP_FLAGS_H_
+#pragma once
+
+#include <string>
+
+// Force-appends flags to the Chrome command line turning on Android-specific
+// features owned by Chrome. This is called as soon as possible during
+// initialization to make sure code sees the new flags.
+void SetChromeSpecificCommandLineFlags();
+
+#endif // CHROME_BROWSER_ANDROID_CHROME_STARTUP_FLAGS_H_
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 8e7672f..be6a202 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -19,13 +19,13 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/common/content_client.h"
#include "content/public/test/test_browser_thread.h"
#include "sync/js/js_arg_list.h"
#include "sync/js/js_event_details.h"
#include "sync/js/js_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/user_agent.h"
#include "webkit/glue/webkit_glue.h"
// TODO(akalin): Add tests here that exercise the whole
@@ -61,10 +61,7 @@ class ProfileSyncServiceTest : public testing::Test {
// We need to set the user agent before the backend host can call
// webkit_glue::GetUserAgent().
- chrome::VersionInfo version_info;
- std::string product("Chrome/");
- product += version_info.is_valid() ? version_info.Version() : "0.0.0.0";
- webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct(product),
+ webkit_glue::SetUserAgent(content::GetContentClient()->GetUserAgent(),
false);
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index d49244ba..cc3904c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -100,6 +100,8 @@
'browser/accessibility/accessibility_events.h',
'browser/accessibility/invert_bubble_prefs.cc',
'browser/accessibility/invert_bubble_prefs.h',
+ 'browser/android/chrome_startup_flags.cc',
+ 'browser/android/chrome_startup_flags.h',
'browser/alternate_nav_url_fetcher.cc',
'browser/alternate_nav_url_fetcher.h',
'browser/app_controller_mac.h',
diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc
index 9533418b..53030d5 100644
--- a/chrome/common/chrome_content_client.cc
+++ b/chrome/common/chrome_content_client.cc
@@ -20,6 +20,7 @@
#include "chrome/common/pepper_flash.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/pepper_plugin_info.h"
#include "content/public/common/url_constants.h"
#include "grit/common_resources.h"
@@ -402,6 +403,12 @@ std::string ChromeContentClient::GetUserAgent() const {
chrome::VersionInfo version_info;
std::string product("Chrome/");
product += version_info.is_valid() ? version_info.Version() : "0.0.0.0";
+#if defined(OS_ANDROID)
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (!command_line->HasSwitch(switches::kTabletUi)) {
+ product += " Mobile";
+ }
+#endif
return webkit_glue::BuildUserAgentFromProduct(product);
}
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 4aa9159..0c107b3 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -1287,6 +1287,11 @@ const char kWindowSize[] = "window-size";
// use Chromium's network stack to fetch, and V8 to evaluate.
const char kWinHttpProxyResolver[] = "winhttp-proxy-resolver";
+#if defined(OS_ANDROID)
+// Use the tablet specific UI components when available.
+const char kTabletUi[] = "tablet-ui";
+#endif
+
#if defined(OS_CHROMEOS)
// Disables gdata content provider.
const char kDisableGData[] = "disable-gdata";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index d91fda4..8061a1d 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -347,6 +347,10 @@ extern const char kWindowPosition[];
extern const char kWindowSize[];
extern const char kWinHttpProxyResolver[];
+#if defined(OS_ANDROID)
+extern const char kTabletUi[];
+#endif
+
#if defined(OS_CHROMEOS)
// Keep switches in alphabetical order.
extern const char kDisableGData[];
diff --git a/content/app/android/content_jni_registrar.cc b/content/app/android/content_jni_registrar.cc
index 9f858b9..61f2192 100644
--- a/content/app/android/content_jni_registrar.cc
+++ b/content/app/android/content_jni_registrar.cc
@@ -8,6 +8,7 @@
#include "base/android/jni_registrar.h"
#include "content/app/android/content_main.h"
#include "content/app/android/sandboxed_process_service.h"
+#include "content/app/android/user_agent.h"
#include "content/browser/android/android_browser_process.h"
#include "content/browser/android/content_view_client.h"
#include "content/browser/android/content_view_impl.h"
@@ -35,6 +36,7 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = {
{ "SurfaceCallback", content::RegisterSurfaceCallback },
{ "TouchPoint", content::RegisterTouchPoint },
{ "TraceEvent", RegisterTraceEvent },
+ { "UserAgent", content::RegisterUserAgent },
};
bool RegisterJni(JNIEnv* env) {
diff --git a/content/app/android/content_main.cc b/content/app/android/content_main.cc
index 53692c5..bdfd975 100644
--- a/content/app/android/content_main.cc
+++ b/content/app/android/content_main.cc
@@ -8,16 +8,12 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
-#if !defined(ANDROID_UPSTREAM_BRINGUP)
-#include "content/common/android/user_agent.h"
-#endif
+#include "content/app/android/user_agent.h"
#include "content/public/app/content_main_delegate.h"
#include "content/public/app/content_main_runner.h"
#include "content/public/common/content_switches.h"
#include "jni/content_main_jni.h"
-#if !defined(ANDROID_UPSTREAM_BRINGUP)
#include "webkit/glue/user_agent.h"
-#endif
using base::LazyInstance;
using content::ContentMainRunner;
@@ -51,9 +47,7 @@ static jint Start(JNIEnv* env, jclass clazz) {
base::debug::WaitForDebugger(24*60*60, false);
}
-#if !defined(ANDROID_UPSTREAM_BRINGUP)
- webkit_glue::InitUserAgent(GetUserAgentOSInfo());
-#endif
+ webkit_glue::SetUserAgentOSInfo(content::GetUserAgentOSInfo());
DCHECK(!g_content_runner.Get().get());
g_content_runner.Get().reset(ContentMainRunner::Create());
diff --git a/content/app/android/user_agent.cc b/content/app/android/user_agent.cc
new file mode 100644
index 0000000..aa284e5
--- /dev/null
+++ b/content/app/android/user_agent.cc
@@ -0,0 +1,30 @@
+// 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 file.
+
+#include "content/app/android/user_agent.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/scoped_java_ref.h"
+#include "jni/user_agent_jni.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ScopedJavaLocalRef;
+using base::android::ConvertJavaStringToUTF8;
+using base::android::GetApplicationContext;
+
+namespace content {
+
+std::string GetUserAgentOSInfo() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> os_info =
+ Java_UserAgent_getUserAgentOSInfo(env);
+ return ConvertJavaStringToUTF8(os_info);
+}
+
+bool RegisterUserAgent(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace content
diff --git a/content/app/android/user_agent.h b/content/app/android/user_agent.h
new file mode 100644
index 0000000..cc0dcce
--- /dev/null
+++ b/content/app/android/user_agent.h
@@ -0,0 +1,22 @@
+// 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 file.
+
+#ifndef CONTENT_APP_ANDROID_USER_AGENT_H_
+#define CONTENT_APP_ANDROID_USER_AGENT_H_
+#pragma once
+
+#include <jni.h>
+#include <string>
+
+namespace content {
+
+// Returns the OS information component required by user agent composition.
+std::string GetUserAgentOSInfo();
+
+// Register JNI method.
+bool RegisterUserAgent(JNIEnv* env);
+
+} // namespace content
+
+#endif // CONTENT_APP_ANDROID_USER_AGENT_H_
diff --git a/content/content_app.gypi b/content/content_app.gypi
index dcd5392..11f4f28 100644
--- a/content/content_app.gypi
+++ b/content/content_app.gypi
@@ -20,6 +20,8 @@
'app/android/library_loader_hooks.cc',
'app/android/sandboxed_process_service.cc',
'app/android/sandboxed_process_service.h',
+ 'app/android/user_agent.cc',
+ 'app/android/user_agent.h',
'app/content_main.cc',
'app/content_main_runner.cc',
'app/startup_helper_win.cc',
diff --git a/content/content_jni.gypi b/content/content_jni.gypi
index 0ab5255..21acb5a 100644
--- a/content/content_jni.gypi
+++ b/content/content_jni.gypi
@@ -12,6 +12,7 @@
'public/android/java/org/chromium/content/app/ContentMain.java',
'public/android/java/org/chromium/content/app/LibraryLoader.java',
'public/android/java/org/chromium/content/app/SandboxedProcessService.java',
+ 'public/android/java/org/chromium/content/app/UserAgent.java',
'public/android/java/org/chromium/content/browser/AndroidBrowserProcess.java',
'public/android/java/org/chromium/content/browser/ContentView.java',
'public/android/java/org/chromium/content/browser/ContentViewClient.java',
@@ -29,6 +30,7 @@
'<(SHARED_INTERMEDIATE_DIR)/content/jni/content_main_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/library_loader_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/sandboxed_process_service_jni.h',
+ '<(SHARED_INTERMEDIATE_DIR)/content/jni/user_agent_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/android_browser_process_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/content_view_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/content_view_client_jni.h',
diff --git a/content/public/android/java/org/chromium/content/app/UserAgent.java b/content/public/android/java/org/chromium/content/app/UserAgent.java
new file mode 100644
index 0000000..36d328d
--- /dev/null
+++ b/content/public/android/java/org/chromium/content/app/UserAgent.java
@@ -0,0 +1,50 @@
+// 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 file.
+
+package org.chromium.content.app;
+
+import android.os.Build;
+
+import org.chromium.base.CalledByNative;
+
+/**
+ * Provides necessary information for building the user agent string.
+ */
+class UserAgent {
+ // TODO(yfriedman): Keep this reasonably up to date.
+ private static final String PREVIOUS_VERSION = "4.0.3";
+
+ @CalledByNative
+ static String getUserAgentOSInfo() {
+ String osInfo = "";
+ final String version = Build.VERSION.RELEASE;
+ if (version.length() > 0) {
+ if (Character.isDigit(version.charAt(0))) {
+ // Release is a version, eg "3.1"
+ osInfo += version;
+ } else {
+ // Release doesn't have a version number yet, eg "Honeycomb"
+ // In this case, use the previous release's version
+ osInfo += PREVIOUS_VERSION;
+ }
+ } else {
+ // default to "1.0"
+ osInfo += "1.0";
+ }
+ osInfo += ";";
+
+ if ("REL".equals(Build.VERSION.CODENAME)) {
+ final String model = Build.MODEL;
+ if (model.length() > 0) {
+ osInfo += " " + model;
+ }
+ }
+ final String id = Build.ID;
+ if (id.length() > 0) {
+ osInfo += " Build/" + id;
+ }
+
+ return osInfo;
+ }
+}
diff --git a/webkit/glue/user_agent.cc b/webkit/glue/user_agent.cc
index 416e088..5165040 100644
--- a/webkit/glue/user_agent.cc
+++ b/webkit/glue/user_agent.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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 file.
@@ -8,6 +8,7 @@
#include <sys/utsname.h>
#endif
+#include "base/lazy_instance.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/sys_info.h"
@@ -19,6 +20,14 @@
// Generated
#include "webkit_version.h" // NOLINT
+#if defined(OS_ANDROID)
+namespace {
+
+base::LazyInstance<std::string>::Leaky g_os_info = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+#endif
+
namespace webkit_glue {
std::string GetWebKitVersion() {
@@ -43,7 +52,7 @@ std::string BuildOSCpuInfo() {
&os_minor_version,
&os_bugfix_version);
#endif
-#if defined(OS_POSIX) && !defined(OS_MACOSX)
+#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
// Should work on any Posix system.
struct utsname unixinfo;
uname(&unixinfo);
@@ -92,6 +101,9 @@ std::string BuildOSCpuInfo() {
os_major_version,
os_minor_version,
os_bugfix_version
+#elif defined(OS_ANDROID)
+ "Android %s",
+ g_os_info.Get().c_str()
#else
"%s %s",
unixinfo.sysname, // e.g. Linux
@@ -118,6 +130,8 @@ std::string BuildUserAgentFromProduct(const std::string& product) {
"Macintosh; ";
#elif defined(USE_X11)
"X11; "; // strange, but that's what Firefox uses
+#elif defined(OS_ANDROID)
+ "Linux; ";
#else
"Unknown; ";
#endif
@@ -142,5 +156,10 @@ std::string BuildUserAgentFromProduct(const std::string& product) {
return user_agent;
}
-} // namespace webkit_glue
+#if defined(OS_ANDROID)
+void SetUserAgentOSInfo(const std::string& os_info) {
+ g_os_info.Get() = os_info;
+}
+#endif
+} // namespace webkit_glue
diff --git a/webkit/glue/user_agent.h b/webkit/glue/user_agent.h
index 9f34c28..60f6e53 100644
--- a/webkit/glue/user_agent.h
+++ b/webkit/glue/user_agent.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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 file.
@@ -21,10 +21,17 @@ std::string GetWebKitVersion();
int GetWebKitMajorVersion();
int GetWebKitMinorVersion();
+#if defined(OS_ANDROID)
+// Sets the OS component of the user agent (e.g. "4.0.4; Galaxy Nexus
+// BUILD/IMM76K")
+// TODO(yfriedman): Remove this ASAP (http://crbug.com/131312)
+void SetUserAgentOSInfo(const std::string& os_info);
+#endif
+
// Helper function to generate a full user agent string from a short
// product name.
std::string BuildUserAgentFromProduct(const std::string& product);
+
} // namespace webkit_glue
#endif // WEBKIT_GLUE_USER_AGENT_H_
-