summaryrefslogtreecommitdiffstats
path: root/content/renderer
diff options
context:
space:
mode:
authorrsesek <rsesek@chromium.org>2015-09-29 08:39:50 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-29 15:40:43 +0000
commit1efb3c33b5c9e89ccee83f0838998504d5ec8c7d (patch)
tree6515ec75e0550ba9c965ba15a77bf70b59468c86 /content/renderer
parente4a3e5c043e0057fccab54d6ff0145a878d7f2d9 (diff)
downloadchromium_src-1efb3c33b5c9e89ccee83f0838998504d5ec8c7d.zip
chromium_src-1efb3c33b5c9e89ccee83f0838998504d5ec8c7d.tar.gz
chromium_src-1efb3c33b5c9e89ccee83f0838998504d5ec8c7d.tar.bz2
Send additional NSUserDefaults over IPC to renderers.
This sends AppleAquaColorVariant, AppleHighlightedTextColor, and AppleHighlightColor when system colors change. BUG=534650 R=avi@chromium.org Review URL: https://codereview.chromium.org/1372243003 Cr-Commit-Position: refs/heads/master@{#351324}
Diffstat (limited to 'content/renderer')
-rw-r--r--content/renderer/render_thread_impl.cc10
-rw-r--r--content/renderer/render_thread_impl.h3
-rw-r--r--content/renderer/theme_helper_mac.h20
-rw-r--r--content/renderer/theme_helper_mac.mm55
4 files changed, 88 insertions, 0 deletions
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 9266eeb..b9c9e1b 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -163,6 +163,7 @@
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
+#include "content/renderer/theme_helper_mac.h"
#include "content/renderer/webscrollbarbehavior_impl_mac.h"
#endif
@@ -1622,6 +1623,7 @@ bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
#endif
#if defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(ViewMsg_UpdateScrollbarTheme, OnUpdateScrollbarTheme)
+ IPC_MESSAGE_HANDLER(ViewMsg_SystemColorsChanged, OnSystemColorsChanged)
#endif
#if defined(ENABLE_PLUGINS)
IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
@@ -1817,6 +1819,14 @@ void RenderThreadImpl::OnUpdateScrollbarTheme(
params.preferred_scroller_style, params.redraw,
params.scroll_animation_enabled, params.button_placement);
}
+
+void RenderThreadImpl::OnSystemColorsChanged(
+ int aqua_color_variant,
+ const std::string& highlight_text_color,
+ const std::string& highlight_color) {
+ SystemColorsDidChange(aqua_color_variant, highlight_text_color,
+ highlight_color);
+}
#endif
void RenderThreadImpl::OnCreateNewSharedWorker(
diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h
index eef203b..190d557 100644
--- a/content/renderer/render_thread_impl.h
+++ b/content/renderer/render_thread_impl.h
@@ -476,6 +476,9 @@ class CONTENT_EXPORT RenderThreadImpl
#if defined(OS_MACOSX)
void OnUpdateScrollbarTheme(
const ViewMsg_UpdateScrollbarTheme_Params& params);
+ void OnSystemColorsChanged(int aqua_color_variant,
+ const std::string& highlight_text_color,
+ const std::string& highlight_color);
#endif
void OnCreateNewSharedWorker(
const WorkerProcessMsg_CreateWorker_Params& params);
diff --git a/content/renderer/theme_helper_mac.h b/content/renderer/theme_helper_mac.h
new file mode 100644
index 0000000..98e6949
--- /dev/null
+++ b/content/renderer/theme_helper_mac.h
@@ -0,0 +1,20 @@
+// Copyright 2015 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_RENDERER_THEME_HELPER_MAC_H_
+#define CONTENT_RENDERER_THEME_HELPER_MAC_H_
+
+#include <string>
+
+namespace content {
+
+// Updates the process-wide preferences for system theme colors, by setting
+// the respective NSUserDefaults and posting notifications.
+void SystemColorsDidChange(int aqua_color_variant,
+ const std::string& highlight_text_color,
+ const std::string& highlight_color);
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_THEME_HELPER_MAC_H_
diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
new file mode 100644
index 0000000..7fbc6ba
--- /dev/null
+++ b/content/renderer/theme_helper_mac.mm
@@ -0,0 +1,55 @@
+// Copyright 2015 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/renderer/theme_helper_mac.h"
+
+#include <Cocoa/Cocoa.h>
+
+#include "base/strings/sys_string_conversions.h"
+
+namespace content {
+
+void SystemColorsDidChange(int aqua_color_variant,
+ const std::string& highlight_text_color,
+ const std::string& highlight_color) {
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+
+ // Register the defaults in the NSArgumentDomain, which is considered
+ // volatile. Registering in the normal application domain fails from within
+ // the sandbox on 10.10+.
+ [defaults removeVolatileDomainForName:NSArgumentDomain];
+
+ NSDictionary* domain_values = @{
+ @"AppleAquaColorVariant" : @(aqua_color_variant),
+ @"AppleHighlightedTextColor" :
+ base::SysUTF8ToNSString(highlight_text_color),
+ @"AppleHighlightColor" : base::SysUTF8ToNSString(highlight_color)
+ };
+ [defaults setVolatileDomain:domain_values forName:NSArgumentDomain];
+
+ // CoreUI expects two distributed notifications to be posted as a result of
+ // the Aqua color variant being changed: AppleAquaColorVariantChanged and
+ // AppleColorPreferencesChangedNotification. These cannot be posted from
+ // within the sandbox, as distributed notifications are always delivered
+ // from the distnoted server, not directly from the posting app. As a result,
+ // the Aqua control color will not change as it should.
+
+ // However, the highlight color variant can be updated as a result of
+ // posting local notifications. Post the notifications required to make that
+ // change visible.
+ NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
+
+ // Trigger a NSDynamicSystemColorStore recache. Both Will and Did
+ // must be posted.
+ [center postNotificationName:@"NSSystemColorsWillChangeNotification"
+ object:nil];
+ [center postNotificationName:NSSystemColorsDidChangeNotification
+ object:nil];
+ // Post the notification that CoreUI would trigger as a result of the Aqua
+ // color change.
+ [center postNotificationName:NSControlTintDidChangeNotification
+ object:nil];
+}
+
+} // namespace content