Support for retreiving the monitor color space on X11.

BUG=622133

Review-Url: https://codereview.chromium.org/2115103002
Cr-Commit-Position: refs/heads/master@{#403958}
diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
index 6bf8211..c12812f 100644
--- a/ui/gfx/BUILD.gn
+++ b/ui/gfx/BUILD.gn
@@ -66,6 +66,7 @@
     "color_space.h",
     "color_space_mac.mm",
     "color_space_win.cc",
+    "color_space_x11.cc",
     "color_utils.cc",
     "color_utils.h",
     "favicon_size.cc",
@@ -400,7 +401,10 @@
     deps += [ "//ui/gfx/x" ]
     configs += [ "//build/config/linux:x11" ]
   } else {
-    sources -= [ "path_x11.cc" ]
+    sources -= [
+      "color_space_x11.cc",
+      "path_x11.cc",
+    ]
   }
 
   if (use_cairo) {
diff --git a/ui/gfx/color_space.cc b/ui/gfx/color_space.cc
index 37cc0e27..7650b1e 100644
--- a/ui/gfx/color_space.cc
+++ b/ui/gfx/color_space.cc
@@ -29,7 +29,7 @@
   return color_space;
 }
 
-#if !defined(OS_WIN) && !defined(OS_MACOSX)
+#if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11)
 // static
 ColorSpace ColorSpace::FromBestMonitor() {
   return ColorSpace();
diff --git a/ui/gfx/color_space_x11.cc b/ui/gfx/color_space_x11.cc
new file mode 100644
index 0000000..7dacae2
--- /dev/null
+++ b/ui/gfx/color_space_x11.cc
@@ -0,0 +1,40 @@
+// Copyright 2016 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 <stddef.h>
+
+extern "C" {
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+}
+
+#include "ui/gfx/color_space.h"
+
+#include "ui/gfx/x/x11_types.h"
+
+namespace gfx {
+
+// static
+ColorSpace ColorSpace::FromBestMonitor() {
+  ColorSpace color_space;
+  Atom property = XInternAtom(GetXDisplay(), "_ICC_PROFILE", true);
+  if (property != None) {
+    Atom prop_type = None;
+    int prop_format = 0;
+    unsigned long nitems = 0;
+    unsigned long nbytes = 0;
+    char* property_data = NULL;
+    if (XGetWindowProperty(
+            GetXDisplay(), DefaultRootWindow(GetXDisplay()), property, 0,
+            0x1FFFFFFF /* MAXINT32 / 4 */, False, AnyPropertyType, &prop_type,
+            &prop_format, &nitems, &nbytes,
+            reinterpret_cast<unsigned char**>(&property_data)) == Success) {
+      color_space.icc_profile_.assign(property_data, property_data + nitems);
+      XFree(property_data);
+    }
+  }
+  return color_space;
+}
+
+}  // namespace gfx
diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp
index b36eb93..2114029 100644
--- a/ui/gfx/gfx.gyp
+++ b/ui/gfx/gfx.gyp
@@ -200,6 +200,7 @@
         'color_space.h',
         'color_space_mac.mm',
         'color_space_win.cc',
+        'color_space_x11.cc',
         'color_utils.cc',
         'color_utils.h',
         'favicon_size.cc',