Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(961)

Unified Diff: Source/core/frame/Navigator.cpp

Issue 288393002: Implement navigator.languages. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@language_change_tests
Patch Set: error 500 Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/frame/Navigator.h ('k') | Source/core/frame/NavigatorLanguage.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/frame/Navigator.cpp
diff --git a/Source/core/frame/Navigator.cpp b/Source/core/frame/Navigator.cpp
index cae5b5bde8454b00e27bf973d44e784f8e6b84e8..08059baa407eec424127b85e2eee6d702785f049 100644
--- a/Source/core/frame/Navigator.cpp
+++ b/Source/core/frame/Navigator.cpp
@@ -25,13 +25,17 @@
#include "bindings/v8/ScriptController.h"
#include "core/dom/Document.h"
+#include "core/frame/FrameHost.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/NavigatorID.h"
#include "core/frame/Settings.h"
#include "core/loader/CookieJar.h"
#include "core/loader/FrameLoader.h"
+#include "core/page/Chrome.h"
+#include "core/page/ChromeClient.h"
#include "core/plugins/DOMMimeTypeArray.h"
#include "core/plugins/DOMPluginArray.h"
+#include "platform/Language.h"
#ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
#define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
@@ -123,6 +127,31 @@ void Navigator::getStorageUpdates()
// FIXME: Remove this method or rename to yieldForStorageUpdates.
}
+Vector<String> Navigator::languages()
+{
+ Vector<String> languages;
+
+ if (!m_frame || !m_frame->host()) {
+ languages.append(defaultLanguage());
+ return languages;
+ }
+
+ String acceptLanguages = m_frame->host()->chrome().client().acceptLanguages();
+ acceptLanguages.split(",", languages);
+
+ // Sanitizing tokens. We could do that more extensively but we should assume
+ // that the accept languages are already sane and support BCP47. It is
+ // likely a waste of time to make sure the tokens matches that spec here.
+ for (size_t i = 0; i < languages.size(); ++i) {
+ String& token = languages[i];
+ token = token.stripWhiteSpace();
+ if (token.length() >= 3 && token[2] == '_')
+ token.replace(2, 1, "-");
+ }
+
+ return languages;
+}
+
void Navigator::trace(Visitor* visitor)
{
visitor->trace(m_plugins);
« no previous file with comments | « Source/core/frame/Navigator.h ('k') | Source/core/frame/NavigatorLanguage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698