Bug 157756 - WTF should know about Language
Summary: WTF should know about Language
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Filip Pizlo
URL:
Keywords:
Depends on:
Blocks: 157804 157755
  Show dependency treegraph
 
Reported: 2016-05-16 14:22 PDT by Filip Pizlo
Modified: 2016-05-17 13:02 PDT (History)
10 users (show)

See Also:


Attachments
something like this maybe (39.28 KB, patch)
2016-05-16 14:33 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
or maybe this (65.45 KB, patch)
2016-05-16 19:37 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
less wrong (81.74 KB, patch)
2016-05-16 19:51 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
more of it compiles than ever before (91.36 KB, patch)
2016-05-16 21:31 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
the patch (104.60 KB, patch)
2016-05-16 22:06 PDT, Filip Pizlo
ggaren: review+
Details | Formatted Diff | Diff
patch for landing (105.21 KB, patch)
2016-05-17 11:48 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Pizlo 2016-05-16 14:22:35 PDT
Patch forthcoming.
Comment 1 Filip Pizlo 2016-05-16 14:33:19 PDT
Created attachment 279047 [details]
something like this maybe
Comment 2 Filip Pizlo 2016-05-16 19:37:18 PDT
Created attachment 279081 [details]
or maybe this
Comment 3 Filip Pizlo 2016-05-16 19:51:34 PDT
Created attachment 279084 [details]
less wrong
Comment 4 Filip Pizlo 2016-05-16 21:31:15 PDT
Created attachment 279100 [details]
more of it compiles than ever before
Comment 5 Filip Pizlo 2016-05-16 22:06:35 PDT
Created attachment 279102 [details]
the patch
Comment 6 WebKit Commit Bot 2016-05-16 22:09:14 PDT
Attachment 279102 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm:43:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/WTF/wtf/PlatformGTK.cmake:10:  Alphabetical sorting problem. "PlatformUserPreferredLanguagesUnix.cpp" should be before "glib/RunLoopGLib.cpp".  [list/order] [5]
ERROR: Source/WTF/wtf/spi/cf/CFBundleSPI.h:40:  The parameter name "stringEncoding" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WTF/wtf/spi/cf/CFBundleSPI.h:41:  The parameter name "stringEncoding" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:52:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 5 in 65 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Filip Pizlo 2016-05-16 22:12:18 PDT
I CC'd a bunch of people because this touches port-specific things in pretty much every port.
Comment 8 Alex Christensen 2016-05-16 23:30:01 PDT
Is something motivating this change?
Comment 9 Alex Christensen 2016-05-16 23:48:33 PDT
Comment on attachment 279102 [details]
the patch

View in context: https://bugs.webkit.org/attachment.cgi?id=279102&action=review

> Source/WebCore/platform/Language.cpp:41
> +static void registerLanguageDidChangeCallbackIfNecessary()

What's this all about?
Comment 10 Filip Pizlo 2016-05-17 07:33:16 PDT
(In reply to comment #8)
> Is something motivating this change?

https://bugs.webkit.org/show_bug.cgi?id=157755
Comment 11 Filip Pizlo 2016-05-17 07:36:00 PDT
(In reply to comment #9)
> Comment on attachment 279102 [details]
> the patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=279102&action=review
> 
> > Source/WebCore/platform/Language.cpp:41
> > +static void registerLanguageDidChangeCallbackIfNecessary()
> 
> What's this all about?

The changelog has more details but basically, when the platform preferred language was detected in WebCore, languageDidChange would get called by that code. Now that code is in WTF but languageDidChane is still in WebCore so we need a callback mechanism.
Comment 12 Geoffrey Garen 2016-05-17 10:52:40 PDT
Comment on attachment 279102 [details]
the patch

r=me
Comment 13 Alexey Proskuryakov 2016-05-17 11:19:11 PDT
Comment on attachment 279102 [details]
the patch

View in context: https://bugs.webkit.org/attachment.cgi?id=279102&action=review

Looks fine to me.

> Source/WTF/ChangeLog:13
> +        - Move WebCore::platformUserPreferredLanguages() to WTF::platformUserPreferredLanguages().

One question that I'm not sure how to answer is whether sandboxed apps using JSC still work. AppSandboxed ones hopefully do (still could be worth testing), but Apple ones with custom sandboxes are more concerning.

> Source/WTF/ChangeLog:20
> +        Moving platformUserPreferredLanguages() is mostly easy except for the weird callback.
> +        That function would call languageDidChange(), which needs to stay in WebCore. So, this
> +        gives WebCore the ability to register a languageDidChange callback. Other than this new

So other JSC clients will not dynamically adapt to system language change?

Note that I'm not entirely sure if they should, or even if Safari should.

> Source/WTF/wtf/BlockObjCExceptions.mm:34
> +    NSLog(@"*** WebKit discarding exception: <%@> %@", [exception name], [exception reason]);

I guess we can still say WebKit here, although it would confuse pure JSC users.
Comment 14 Filip Pizlo 2016-05-17 11:42:44 PDT
(In reply to comment #13)
> Comment on attachment 279102 [details]
> the patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=279102&action=review
> 
> Looks fine to me.
> 
> > Source/WTF/ChangeLog:13
> > +        - Move WebCore::platformUserPreferredLanguages() to WTF::platformUserPreferredLanguages().
> 
> One question that I'm not sure how to answer is whether sandboxed apps using
> JSC still work. AppSandboxed ones hopefully do (still could be worth
> testing), but Apple ones with custom sandboxes are more concerning.

Is there a way to defend against sandboxing so that this returns some sensible default (heck, even en_us) when the sandbox doesn't allow us to do anything smarter?

> 
> > Source/WTF/ChangeLog:20
> > +        Moving platformUserPreferredLanguages() is mostly easy except for the weird callback.
> > +        That function would call languageDidChange(), which needs to stay in WebCore. So, this
> > +        gives WebCore the ability to register a languageDidChange callback. Other than this new
> 
> So other JSC clients will not dynamically adapt to system language change?

They will, but they don't need a callback to do it.

The current JSC implementation in trunk will ask WebCore for the "default language" every time a global object's code asks for the default locale for the first time.  So, if you change the platform settings, they will take effect no later than the next time JSC creates a global object.

Once I finish https://bugs.webkit.org/show_bug.cgi?id=157755, it will ask either WTF (via platformUserPreferredLanguages()) or WebCore (the same way it does now).  It will still ask WebCore when the global object is a DOM global object, since WebCore adds its own abilities to override this setting.

> 
> Note that I'm not entirely sure if they should, or even if Safari should.

Yeah, it's all a bit funky.  I wonder if removing that functionality would break anything at all.

> 
> > Source/WTF/wtf/BlockObjCExceptions.mm:34
> > +    NSLog(@"*** WebKit discarding exception: <%@> %@", [exception name], [exception reason]);
> 
> I guess we can still say WebKit here, although it would confuse pure JSC
> users.

Oh, that's funny.  I added a FIXME and filed https://bugs.webkit.org/show_bug.cgi?id=157804.
Comment 15 Filip Pizlo 2016-05-17 11:48:29 PDT
Created attachment 279142 [details]
patch for landing
Comment 16 WebKit Commit Bot 2016-05-17 11:50:11 PDT
Attachment 279142 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm:43:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/WTF/wtf/PlatformGTK.cmake:10:  Alphabetical sorting problem. "PlatformUserPreferredLanguagesUnix.cpp" should be before "glib/RunLoopGLib.cpp".  [list/order] [5]
ERROR: Source/WTF/wtf/spi/cf/CFBundleSPI.h:40:  The parameter name "stringEncoding" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WTF/wtf/spi/cf/CFBundleSPI.h:41:  The parameter name "stringEncoding" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:52:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 5 in 65 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 17 Filip Pizlo 2016-05-17 11:52:03 PDT
Comment on attachment 279142 [details]
patch for landing

I'll let CQ worry about this beast.
Comment 18 Alexey Proskuryakov 2016-05-17 12:34:23 PDT
> Is there a way to defend against sandboxing so that this returns some sensible default (heck, even en_us) when the sandbox doesn't allow us to do anything smarter?

It may happen to work that way - library calls below us will fail (e.g. CFPreferences), and ideally, we'll just hit all the right fallback paths.

The cost will of course be that sandbox violation logs will be generated, which is far from free.
Comment 19 Filip Pizlo 2016-05-17 12:35:43 PDT
(In reply to comment #18)
> > Is there a way to defend against sandboxing so that this returns some sensible default (heck, even en_us) when the sandbox doesn't allow us to do anything smarter?
> 
> It may happen to work that way - library calls below us will fail (e.g.
> CFPreferences), and ideally, we'll just hit all the right fallback paths.
> 
> The cost will of course be that sandbox violation logs will be generated,
> which is far from free.

That's probably pretty good.  Hopefully our caching causes us to remember the failure, so that we do this only once per process.
Comment 20 WebKit Commit Bot 2016-05-17 12:37:56 PDT
Comment on attachment 279142 [details]
patch for landing

Clearing flags on attachment: 279142

Committed r201038: <http://trac.webkit.org/changeset/201038>
Comment 21 WebKit Commit Bot 2016-05-17 12:38:04 PDT
All reviewed patches have been landed.  Closing bug.
Comment 22 Alexey Proskuryakov 2016-05-17 12:57:14 PDT
> > Note that I'm not entirely sure if they should, or even if Safari should.

> Yeah, it's all a bit funky.  I wonder if removing that functionality would break anything at all.

Well, it would definitely change the behavior - once you change the language, new tabs will pick it, but old tabs will keep the old one.

What I don't know is what the expectation for user experience when changing languages is. The pref pane says that running applications will need to be restarted, but in personal experience, that may not be quite right, and may not match actual user expectations. I may have the wrong impression though.
Comment 23 Filip Pizlo 2016-05-17 13:02:43 PDT
(In reply to comment #22)
> > > Note that I'm not entirely sure if they should, or even if Safari should.
> 
> > Yeah, it's all a bit funky.  I wonder if removing that functionality would break anything at all.
> 
> Well, it would definitely change the behavior - once you change the
> language, new tabs will pick it, but old tabs will keep the old one.

Right.  It's a behavior change for sure, but I'm not sure if it's a bad one or a benign one.

> 
> What I don't know is what the expectation for user experience when changing
> languages is. The pref pane says that running applications will need to be
> restarted, but in personal experience, that may not be quite right, and may
> not match actual user expectations. I may have the wrong impression though.

My impression has always been that you need to restart an app for the changes to fully take effect, but that the changes may take partial effect in some apps immediately.