| Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc
|
| diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc
|
| index a0a5bb102dadd66c23368dcd71aeae6e3b36c3a0..e18d3e34181fe6e64d6dd29f3233fe021e21e5dd 100644
|
| --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc
|
| +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc
|
| @@ -10,6 +10,7 @@
|
| #include "ash/shell.h"
|
| #include "ash/wm/window_util.h"
|
| #include "base/command_line.h"
|
| +#include "base/string_number_conversions.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/defaults.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| @@ -44,6 +45,7 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "extensions/common/url_pattern.h"
|
| #include "grit/theme_resources.h"
|
| +#include "ui/aura/root_window.h"
|
| #include "ui/aura/window.h"
|
|
|
| using content::WebContents;
|
| @@ -119,12 +121,58 @@ class AppShortcutLauncherItemController : public LauncherItemController {
|
| DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController);
|
| };
|
|
|
| +std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) {
|
| + if (!root_window)
|
| + return std::string();
|
| +
|
| + gfx::Display display = gfx::Screen::GetScreenFor(
|
| + root_window)->GetDisplayNearestWindow(root_window);
|
| + if (!display.is_valid())
|
| + return std::string();
|
| +
|
| + return base::Int64ToString(display.id());
|
| +}
|
| +
|
| +void UpdatePerDisplayPref(PrefService* pref_service,
|
| + aura::RootWindow* root_window,
|
| + const char* pref_key,
|
| + const std::string& value) {
|
| + std::string key = GetPrefKeyForRootWindow(root_window);
|
| + if (key.empty())
|
| + return;
|
| +
|
| + DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences);
|
| + base::DictionaryValue* shelf_prefs = update.Get();
|
| + base::DictionaryValue* prefs = NULL;
|
| + if (!shelf_prefs->GetDictionary(key, &prefs)) {
|
| + prefs = new base::DictionaryValue();
|
| + shelf_prefs->Set(key, prefs);
|
| + }
|
| + prefs->SetStringWithoutPathExpansion(pref_key, value);
|
| +}
|
| +
|
| // If the value of the pref at |local_path is not empty, it is returned
|
| // otherwise the value of the pref at |synced_path| is returned.
|
| std::string GetLocalOrRemotePref(PrefService* pref_service,
|
| + aura::RootWindow* root_window,
|
| const char* local_path,
|
| const char* synced_path) {
|
| const std::string value(pref_service->GetString(local_path));
|
| + if (pref_service->FindPreference(local_path)->IsRecommended())
|
| + return value;
|
| +
|
| + std::string pref_key = GetPrefKeyForRootWindow(root_window);
|
| + if (!pref_key.empty()) {
|
| + const base::DictionaryValue* shelf_prefs = pref_service->GetDictionary(
|
| + prefs::kShelfPreferences);
|
| + const base::DictionaryValue* display_pref = NULL;
|
| + std::string per_display_value;
|
| + if (shelf_prefs->GetDictionary(pref_key, &display_pref) &&
|
| + display_pref->GetString(synced_path, &per_display_value)) {
|
| + return per_display_value;
|
| + }
|
| + }
|
| +
|
| return value.empty() ? pref_service->GetString(synced_path) : value;
|
| }
|
|
|
| @@ -570,11 +618,10 @@ bool ChromeLauncherControllerPerBrowser::CanPin() const {
|
| ash::ShelfAutoHideBehavior
|
| ChromeLauncherControllerPerBrowser::GetShelfAutoHideBehavior(
|
| aura::RootWindow* root_window) const {
|
| - // TODO(oshima): Support multiple launchers.
|
| -
|
| // See comment in |kShelfAlignment| as to why we consider two prefs.
|
| const std::string behavior_value(
|
| GetLocalOrRemotePref(profile_->GetPrefs(),
|
| + root_window,
|
| prefs::kShelfAutoHideBehaviorLocal,
|
| prefs::kShelfAutoHideBehavior));
|
|
|
| @@ -589,7 +636,6 @@ ash::ShelfAutoHideBehavior
|
|
|
| bool ChromeLauncherControllerPerBrowser::CanUserModifyShelfAutoHideBehavior(
|
| aura::RootWindow* root_window) const {
|
| - // TODO(oshima): Support multiple launchers.
|
| return profile_->GetPrefs()->
|
| FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable();
|
| }
|
| @@ -805,11 +851,10 @@ void ChromeLauncherControllerPerBrowser::Observe(
|
| }
|
| }
|
|
|
| -void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged() {
|
| +void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged(
|
| + aura::RootWindow* root_window) {
|
| const char* pref_value = NULL;
|
| - // TODO(oshima): Support multiple displays.
|
| - switch (ash::Shell::GetInstance()->GetShelfAlignment(
|
| - ash::Shell::GetPrimaryRootWindow())) {
|
| + switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) {
|
| case ash::SHELF_ALIGNMENT_BOTTOM:
|
| pref_value = ash::kShelfAlignmentBottom;
|
| break;
|
| @@ -820,9 +865,15 @@ void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged() {
|
| pref_value = ash::kShelfAlignmentRight;
|
| break;
|
| }
|
| - // See comment in |kShelfAlignment| about why we have two prefs here.
|
| - profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value);
|
| - profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value);
|
| +
|
| + UpdatePerDisplayPref(
|
| + profile_->GetPrefs(), root_window, prefs::kShelfAlignment, pref_value);
|
| +
|
| + if (root_window == ash::Shell::GetPrimaryRootWindow()) {
|
| + // See comment in |kShelfAlignment| about why we have two prefs here.
|
| + profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value);
|
| + profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value);
|
| + }
|
| }
|
|
|
| void ChromeLauncherControllerPerBrowser::OnIsSyncingChanged() {
|
| @@ -999,10 +1050,6 @@ void ChromeLauncherControllerPerBrowser::UpdateAppLaunchersFromPref() {
|
| void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorPrefs(
|
| ash::ShelfAutoHideBehavior behavior,
|
| aura::RootWindow* root_window) {
|
| - // TODO(oshima): Support multiple launchers.
|
| - if (root_window != ash::Shell::GetPrimaryRootWindow())
|
| - return;
|
| -
|
| const char* value = NULL;
|
| switch (behavior) {
|
| case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
|
| @@ -1012,16 +1059,24 @@ void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorPrefs(
|
| value = ash::kShelfAutoHideBehaviorNever;
|
| break;
|
| }
|
| - // See comment in |kShelfAlignment| about why we have two prefs here.
|
| - profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
|
| - profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
|
| +
|
| + UpdatePerDisplayPref(
|
| + profile_->GetPrefs(), root_window, prefs::kShelfAutoHideBehavior, value);
|
| +
|
| + if (root_window != ash::Shell::GetPrimaryRootWindow()) {
|
| + // See comment in |kShelfAlignment| about why we have two prefs here.
|
| + profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
|
| + profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
|
| + }
|
| }
|
|
|
| void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorFromPrefs() {
|
| - // TODO(oshima): Support multiple displays.
|
| - aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
|
| - ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
|
| - GetShelfAutoHideBehavior(root_window), root_window);
|
| + ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows();
|
| + for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin();
|
| + iter != root_windows.end(); ++iter) {
|
| + ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
|
| + GetShelfAutoHideBehavior(*iter), *iter);
|
| + }
|
| }
|
|
|
| void ChromeLauncherControllerPerBrowser::SetShelfAlignmentFromPrefs() {
|
| @@ -1029,19 +1084,22 @@ void ChromeLauncherControllerPerBrowser::SetShelfAlignmentFromPrefs() {
|
| switches::kShowLauncherAlignmentMenu))
|
| return;
|
|
|
| - // See comment in |kShelfAlignment| as to why we consider two prefs.
|
| - const std::string alignment_value(
|
| - GetLocalOrRemotePref(profile_->GetPrefs(),
|
| - prefs::kShelfAlignmentLocal,
|
| - prefs::kShelfAlignment));
|
| - ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM;
|
| - if (alignment_value == ash::kShelfAlignmentLeft)
|
| - alignment = ash::SHELF_ALIGNMENT_LEFT;
|
| - else if (alignment_value == ash::kShelfAlignmentRight)
|
| - alignment = ash::SHELF_ALIGNMENT_RIGHT;
|
| - // TODO(oshima): Support multiple displays.
|
| - ash::Shell::GetInstance()->SetShelfAlignment(
|
| - alignment, ash::Shell::GetPrimaryRootWindow());
|
| + ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows();
|
| + for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin();
|
| + iter != root_windows.end(); ++iter) {
|
| + // See comment in |kShelfAlignment| as to why we consider two prefs.
|
| + const std::string alignment_value(
|
| + GetLocalOrRemotePref(profile_->GetPrefs(),
|
| + *iter,
|
| + prefs::kShelfAlignmentLocal,
|
| + prefs::kShelfAlignment));
|
| + ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM;
|
| + if (alignment_value == ash::kShelfAlignmentLeft)
|
| + alignment = ash::SHELF_ALIGNMENT_LEFT;
|
| + else if (alignment_value == ash::kShelfAlignmentRight)
|
| + alignment = ash::SHELF_ALIGNMENT_RIGHT;
|
| + ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter);
|
| + }
|
| }
|
|
|
| WebContents* ChromeLauncherControllerPerBrowser::GetLastActiveWebContents(
|
|
|