• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "tests/cefsimple/simple_handler.h"
6 
7 #if defined(CEF_X11)
8 #include <X11/Xatom.h>
9 #include <X11/Xlib.h>
10 #endif
11 
12 #include <string>
13 
14 #include "include/base/cef_logging.h"
15 #include "include/cef_browser.h"
16 
PlatformTitleChange(CefRefPtr<CefBrowser> browser,const CefString & title)17 void SimpleHandler::PlatformTitleChange(CefRefPtr<CefBrowser> browser,
18                                         const CefString& title) {
19   std::string titleStr(title);
20 
21 #if defined(CEF_X11)
22   // Retrieve the X11 display shared with Chromium.
23   ::Display* display = cef_get_xdisplay();
24   DCHECK(display);
25 
26   // Retrieve the X11 window handle for the browser.
27   ::Window window = browser->GetHost()->GetWindowHandle();
28   if (window == kNullWindowHandle)
29     return;
30 
31   // Retrieve the atoms required by the below XChangeProperty call.
32   const char* kAtoms[] = {"_NET_WM_NAME", "UTF8_STRING"};
33   Atom atoms[2];
34   int result =
35       XInternAtoms(display, const_cast<char**>(kAtoms), 2, false, atoms);
36   if (!result)
37     NOTREACHED();
38 
39   // Set the window title.
40   XChangeProperty(display, window, atoms[0], atoms[1], 8, PropModeReplace,
41                   reinterpret_cast<const unsigned char*>(titleStr.c_str()),
42                   titleStr.size());
43 
44   // TODO(erg): This is technically wrong. So XStoreName and friends expect
45   // this in Host Portable Character Encoding instead of UTF-8, which I believe
46   // is Compound Text. This shouldn't matter 90% of the time since this is the
47   // fallback to the UTF8 property above.
48   XStoreName(display, browser->GetHost()->GetWindowHandle(), titleStr.c_str());
49 #endif  // defined(CEF_X11)
50 }
51