Commit c96587a6 authored by mlamouri@chromium.org's avatar mlamouri@chromium.org
parent d67b580c
...@@ -12,6 +12,7 @@ navigator.getStorageUpdates() is OK ...@@ -12,6 +12,7 @@ navigator.getStorageUpdates() is OK
navigator.isProtocolHandlerRegistered() threw err TypeError: Failed to execute 'isProtocolHandlerRegistered' on 'Navigator': 2 arguments required, but only 0 present. navigator.isProtocolHandlerRegistered() threw err TypeError: Failed to execute 'isProtocolHandlerRegistered' on 'Navigator': 2 arguments required, but only 0 present.
navigator.javaEnabled() is OK navigator.javaEnabled() is OK
navigator.language is OK navigator.language is OK
navigator.languages is OK
navigator.maxTouchPoints is OK navigator.maxTouchPoints is OK
navigator.mimeTypes is OK navigator.mimeTypes is OK
navigator.onLine is OK navigator.onLine is OK
...@@ -44,6 +45,7 @@ navigator.getStorageUpdates() is OK ...@@ -44,6 +45,7 @@ navigator.getStorageUpdates() is OK
navigator.isProtocolHandlerRegistered() threw err TypeError: Failed to execute 'isProtocolHandlerRegistered' on 'Navigator': 2 arguments required, but only 0 present. navigator.isProtocolHandlerRegistered() threw err TypeError: Failed to execute 'isProtocolHandlerRegistered' on 'Navigator': 2 arguments required, but only 0 present.
navigator.javaEnabled() is OK navigator.javaEnabled() is OK
navigator.language is OK navigator.language is OK
navigator.languages is OK
navigator.maxTouchPoints is OK navigator.maxTouchPoints is OK
navigator.mimeTypes is OK navigator.mimeTypes is OK
navigator.onLine is OK navigator.onLine is OK
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
test(function() { test(function() {
assert_true('language' in window.navigator); assert_true('language' in window.navigator);
assert_false('languages' in window.navigator); assert_true('languages' in window.navigator);
assert_true('onlanguagechange' in window); assert_true('onlanguagechange' in window);
}, "Test that NavigatorLanguage API is present in window"); }, "Test that NavigatorLanguage API is present in window");
...@@ -86,6 +86,48 @@ test(function() { ...@@ -86,6 +86,48 @@ test(function() {
window.testRunner.setAcceptLanguages('klingon'); window.testRunner.setAcceptLanguages('klingon');
}, "Test properties of the fired event."); }, "Test properties of the fired event.");
test(function() {
var testValues = [
{ accept_languages: 'foo', language: 'foo', languages: ['foo'] },
{ accept_languages: '', language: '', languages: [] },
{ accept_languages: 'foo,bar', language: 'foo', languages: [ 'foo', 'bar' ] },
{ accept_languages: ' foo , bar ', language: 'foo', languages: [ 'foo', 'bar' ] },
{ accept_languages: ' foo ; bar ', language: 'foo ; bar', languages: [ 'foo ; bar' ] },
{ accept_languages: '_foo_', language: '_foo_', languages: ['_foo_'] },
{ accept_languages: 'en_', language: 'en-', languages: ['en-'] },
{ accept_languages: 'en__', language: 'en-_', languages: ['en-_'] },
{ accept_languages: 'en_US, fr_FR', language: 'en-US', languages: ['en-US', 'fr-FR'] },
{ accept_languages: 'en_US_CA', language: 'en-US_CA', languages: ['en-US_CA'] },
];
var eventsCount = 0;
window.onlanguagechange = function() {
eventsCount++;
}
for (var i = 0; i < testValues.length; ++i) {
var data = testValues[i];
window.testRunner.setAcceptLanguages(data.accept_languages);
assert_equals(eventsCount, i + 1);
assert_equals(navigator.languages.length, data.languages.length);
// FIXME: test navigator.language
for (var j = 0; j < navigator.languages.length; ++j) {
assert_equals(navigator.languages[j], data.languages[j]);
}
}
}, "Test that navigator.languages reflects the accept languages value.");
test(function() {
var previous = navigator.languages;
assert_equals(navigator.languages, navigator.languages);
assert_equals(navigator.languages, previous);
window.testRunner.setAcceptLanguages('fr-FR');
assert_not_equals(navigator.languages, previous);
}, "Test that navigator.languages caching behaviour.");
</script> </script>
</body> </body>
</html> </html>
...@@ -363,6 +363,14 @@ void DOMWindow::clearEventQueue() ...@@ -363,6 +363,14 @@ void DOMWindow::clearEventQueue()
m_eventQueue.clear(); m_eventQueue.clear();
} }
void DOMWindow::acceptLanguagesChanged()
{
if (m_navigator)
m_navigator->setLanguagesChanged();
dispatchEvent(Event::create(EventTypeNames::languagechange));
}
PassRefPtrWillBeRawPtr<Document> DOMWindow::createDocument(const String& mimeType, const DocumentInit& init, bool forceXHTML) PassRefPtrWillBeRawPtr<Document> DOMWindow::createDocument(const String& mimeType, const DocumentInit& init, bool forceXHTML)
{ {
RefPtrWillBeRawPtr<Document> document = nullptr; RefPtrWillBeRawPtr<Document> document = nullptr;
......
...@@ -326,6 +326,8 @@ enum PageshowEventPersistence { ...@@ -326,6 +326,8 @@ enum PageshowEventPersistence {
// FIXME: This shouldn't be public once DOMWindow becomes ExecutionContext. // FIXME: This shouldn't be public once DOMWindow becomes ExecutionContext.
void clearEventQueue(); void clearEventQueue();
void acceptLanguagesChanged();
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
protected: protected:
......
...@@ -25,13 +25,17 @@ ...@@ -25,13 +25,17 @@
#include "bindings/v8/ScriptController.h" #include "bindings/v8/ScriptController.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/frame/FrameHost.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/frame/NavigatorID.h" #include "core/frame/NavigatorID.h"
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/loader/CookieJar.h" #include "core/loader/CookieJar.h"
#include "core/loader/FrameLoader.h" #include "core/loader/FrameLoader.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
#include "core/plugins/DOMMimeTypeArray.h" #include "core/plugins/DOMMimeTypeArray.h"
#include "core/plugins/DOMPluginArray.h" #include "core/plugins/DOMPluginArray.h"
#include "platform/Language.h"
#ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB #ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
#define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107" #define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
...@@ -123,6 +127,31 @@ void Navigator::getStorageUpdates() ...@@ -123,6 +127,31 @@ void Navigator::getStorageUpdates()
// FIXME: Remove this method or rename to yieldForStorageUpdates. // 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) void Navigator::trace(Visitor* visitor)
{ {
visitor->trace(m_plugins); visitor->trace(m_plugins);
......
...@@ -65,6 +65,9 @@ public: ...@@ -65,6 +65,9 @@ public:
// Relinquishes the storage lock, if one exists. // Relinquishes the storage lock, if one exists.
void getStorageUpdates(); void getStorageUpdates();
// NavigatorLanguage
virtual Vector<String> languages() OVERRIDE;
virtual void trace(Visitor*); virtual void trace(Visitor*);
private: private:
......
...@@ -9,10 +9,29 @@ ...@@ -9,10 +9,29 @@
namespace WebCore { namespace WebCore {
NavigatorLanguage::NavigatorLanguage()
: m_languagesChanged(true)
{
}
AtomicString NavigatorLanguage::language(bool& isNull) AtomicString NavigatorLanguage::language(bool& isNull)
{ {
isNull = false; isNull = false;
return defaultLanguage(); return defaultLanguage();
} }
bool NavigatorLanguage::hasLanguagesChanged()
{
if (!m_languagesChanged)
return false;
m_languagesChanged = false;
return true;
}
void NavigatorLanguage::setLanguagesChanged()
{
m_languagesChanged = true;
}
} // namespace WebCore } // namespace WebCore
...@@ -11,7 +11,15 @@ namespace WebCore { ...@@ -11,7 +11,15 @@ namespace WebCore {
class NavigatorLanguage { class NavigatorLanguage {
public: public:
NavigatorLanguage();
AtomicString language(bool&); AtomicString language(bool&);
virtual Vector<String> languages() = 0;
bool hasLanguagesChanged();
void setLanguagesChanged();
private:
bool m_languagesChanged;
}; };
} // namespace WebCore } // namespace WebCore
......
...@@ -6,6 +6,5 @@ ...@@ -6,6 +6,5 @@
NoInterfaceObject, NoInterfaceObject,
] interface NavigatorLanguage { ] interface NavigatorLanguage {
readonly attribute DOMString? language; readonly attribute DOMString? language;
// TODO(mlamouri), implement this as part of bug 365123. [CachedAttribute=hasLanguagesChanged] readonly attribute DOMString[] languages;
// readonly attribute DOMString[] languages;
}; };
...@@ -535,11 +535,13 @@ void Page::acceptLanguagesChanged() ...@@ -535,11 +535,13 @@ void Page::acceptLanguagesChanged()
{ {
Vector< RefPtr<LocalFrame> > frames; Vector< RefPtr<LocalFrame> > frames;
// Even though we don't fire an event from here, the DOMWindow's will fire
// an event so we keep the frames alive until we are done.
for (LocalFrame* frame = mainFrame(); frame; frame = frame->tree().traverseNext()) for (LocalFrame* frame = mainFrame(); frame; frame = frame->tree().traverseNext())
frames.append(frame); frames.append(frame);
for (unsigned i = 0; i < frames.size(); ++i) for (unsigned i = 0; i < frames.size(); ++i)
frames[i]->domWindow()->dispatchEvent(Event::create(EventTypeNames::languagechange)); frames[i]->domWindow()->acceptLanguagesChanged();
} }
PageLifecycleNotifier& Page::lifecycleNotifier() PageLifecycleNotifier& Page::lifecycleNotifier()
......
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