Merge pull request #726 from atom/dbus-checking-menu

Fix detecting global menu bar on Ubuntu
This commit is contained in:
Cheng Zhao 2014-10-21 16:35:11 +08:00
commit b09252f13e
5 changed files with 43 additions and 11 deletions

View file

@ -561,6 +561,10 @@
'-rpath \$$ORIGIN', '-rpath \$$ORIGIN',
# Make native module dynamic loading work. # Make native module dynamic loading work.
'-rdynamic', '-rdynamic',
'<!@(pkg-config --libs-only-L --libs-only-other dbus-1)',
],
'libraries': [
'<!@(pkg-config --libs-only-l dbus-1)',
], ],
}, },
# Required settings of using breakpad. # Required settings of using breakpad.
@ -568,8 +572,10 @@
'vendor/breakpad/src', 'vendor/breakpad/src',
], ],
'cflags': [ 'cflags': [
'<!@(pkg-config --cflags dbus-1)',
'-Wno-deprecated-register', '-Wno-deprecated-register',
'-Wno-empty-body', '-Wno-empty-body',
'-Wno-reserved-user-defined-literal',
], ],
'dependencies': [ 'dependencies': [
'vendor/breakpad/breakpad.gyp:breakpad_client', 'vendor/breakpad/breakpad.gyp:breakpad_client',

View file

@ -37,6 +37,9 @@
#include "base/nix/xdg_util.h" #include "base/nix/xdg_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/ui/libgtk2ui/unity_service.h" #include "chrome/browser/ui/libgtk2ui/unity_service.h"
#include "dbus/bus.h"
#include "dbus/object_proxy.h"
#include "dbus/message.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/views/window/native_frame_view.h" #include "ui/views/window/native_frame_view.h"
@ -64,16 +67,38 @@ const int kMenuBarHeight = 25;
// window role for X11. // window role for X11.
int kWindowsCreated = 0; int kWindowsCreated = 0;
// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available.
bool ShouldUseGlobalMenuBar() { bool ShouldUseGlobalMenuBar() {
// Some DE would pretend to be Unity but don't have global application menu, dbus::Bus::Options options;
// so we can not trust unity::IsRunning(). scoped_refptr<dbus::Bus> bus(new dbus::Bus(options));
scoped_ptr<base::Environment> env(base::Environment::Create());
bool is_unity = unity::IsRunning() && dbus::ObjectProxy* object_proxy =
base::nix::GetDesktopEnvironment(env.get()) == bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS));
base::nix::DESKTOP_ENVIRONMENT_UNITY; dbus::MethodCall method_call(DBUS_INTERFACE_DBUS, "ListNames");
std::string menu_proxy; scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
return is_unity && env->GetVar("UBUNTU_MENUPROXY", &menu_proxy) && &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
menu_proxy.length() > 1; if (!response) {
bus->ShutdownAndBlock();
return false;
}
dbus::MessageReader reader(response.get());
dbus::MessageReader array_reader(NULL);
if (!reader.PopArray(&array_reader)) {
bus->ShutdownAndBlock();
return false;
}
while (array_reader.HasMoreData()) {
std::string name;
if (array_reader.PopString(&name) &&
name == "com.canonical.AppMenu.Registrar") {
bus->ShutdownAndBlock();
return true;
}
}
bus->ShutdownAndBlock();
return false;
} }
#endif #endif

View file

@ -8,7 +8,7 @@
On Ubuntu you could install the libraries via: On Ubuntu you could install the libraries via:
```bash ```bash
$ sudo apt-get install build-essential clang libgtk2.0-dev libnotify-dev gcc-multilib g++-multilib $ sudo apt-get install build-essential clang libdbus-1-dev libgtk2.0-dev libnotify-dev gcc-multilib g++-multilib
``` ```
Latest Node.js could be installed via ppa: Latest Node.js could be installed via ppa:

View file

@ -10,6 +10,7 @@ from lib.util import execute, rm_rf, scoped_env
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
LINUX_DEPS = [ LINUX_DEPS = [
'libdbus-1-dev',
'libgnome-keyring-dev', 'libgnome-keyring-dev',
'libgtk2.0-dev', 'libgtk2.0-dev',
'libnotify-dev', 'libnotify-dev',

View file

@ -4,7 +4,7 @@ import platform
import sys import sys
BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent' BASE_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = '9f5271d31e0f32eac5a20ef6f543e3f1d43ad645' LIBCHROMIUMCONTENT_COMMIT = '56984fa0e4c3c745652510f342c0fb2724d846c2'
ARCH = { ARCH = {
'cygwin': '32bit', 'cygwin': '32bit',