OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/chrome_views_delegate.h" | 5 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/browser/ui/views/accessibility_event_router_views.h" | 13 #include "chrome/browser/ui/views/accessibility_event_router_views.h" |
12 #include "chrome/browser/ui/window_sizer.h" | 14 #include "chrome/browser/ui/window_sizer.h" |
13 #include "gfx/rect.h" | 15 #include "gfx/rect.h" |
14 #include "ui/base/clipboard/clipboard.h" | 16 #include "ui/base/clipboard/clipboard.h" |
15 | 17 |
16 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
17 #include "chrome/browser/app_icon_win.h" | 19 #include "chrome/browser/app_icon_win.h" |
18 #endif | 20 #endif |
19 | 21 |
| 22 namespace { |
| 23 |
| 24 // The browser window placement data is stored by profile; all other window |
| 25 // data is stored in Local State. |
| 26 PrefService* GetPrefService(const std::wstring& window_name) { |
| 27 if (StartsWith(window_name, L"browser", true)) { |
| 28 return g_browser_process->profile_manager() ? |
| 29 g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs() : |
| 30 NULL; |
| 31 } else { |
| 32 return g_browser_process->local_state() ? |
| 33 g_browser_process->local_state() : NULL; |
| 34 } |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
20 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
21 // ChromeViewsDelegate, views::ViewsDelegate implementation: | 40 // ChromeViewsDelegate, views::ViewsDelegate implementation: |
22 | 41 |
23 ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { | 42 ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { |
24 return g_browser_process->clipboard(); | 43 return g_browser_process->clipboard(); |
25 } | 44 } |
26 | 45 |
27 void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, | 46 void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, |
28 const gfx::Rect& bounds, | 47 const gfx::Rect& bounds, |
29 bool maximized) { | 48 bool maximized) { |
30 if (!g_browser_process->local_state()) | 49 PrefService* pref_service = GetPrefService(window_name); |
| 50 if (!pref_service) |
31 return; | 51 return; |
32 | 52 |
33 DictionaryValue* window_preferences = | 53 DictionaryValue* window_preferences = pref_service-> |
34 g_browser_process->local_state()->GetMutableDictionary( | 54 GetMutableDictionary(WideToUTF8(window_name).c_str()); |
35 WideToUTF8(window_name).c_str()); | |
36 window_preferences->SetInteger("left", bounds.x()); | 55 window_preferences->SetInteger("left", bounds.x()); |
37 window_preferences->SetInteger("top", bounds.y()); | 56 window_preferences->SetInteger("top", bounds.y()); |
38 window_preferences->SetInteger("right", bounds.right()); | 57 window_preferences->SetInteger("right", bounds.right()); |
39 window_preferences->SetInteger("bottom", bounds.bottom()); | 58 window_preferences->SetInteger("bottom", bounds.bottom()); |
40 window_preferences->SetBoolean("maximized", maximized); | 59 window_preferences->SetBoolean("maximized", maximized); |
41 | 60 |
42 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( | 61 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( |
43 WindowSizer::CreateDefaultMonitorInfoProvider()); | 62 WindowSizer::CreateDefaultMonitorInfoProvider()); |
44 gfx::Rect work_area( | 63 gfx::Rect work_area( |
45 monitor_info_provider->GetMonitorWorkAreaMatching(bounds)); | 64 monitor_info_provider->GetMonitorWorkAreaMatching(bounds)); |
46 window_preferences->SetInteger("work_area_left", work_area.x()); | 65 window_preferences->SetInteger("work_area_left", work_area.x()); |
47 window_preferences->SetInteger("work_area_top", work_area.y()); | 66 window_preferences->SetInteger("work_area_top", work_area.y()); |
48 window_preferences->SetInteger("work_area_right", work_area.right()); | 67 window_preferences->SetInteger("work_area_right", work_area.right()); |
49 window_preferences->SetInteger("work_area_bottom", work_area.bottom()); | 68 window_preferences->SetInteger("work_area_bottom", work_area.bottom()); |
50 } | 69 } |
51 | 70 |
52 bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, | 71 bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, |
53 gfx::Rect* bounds) const { | 72 gfx::Rect* bounds) const { |
54 if (!g_browser_process->local_state()) | 73 PrefService* pref_service = GetPrefService(window_name); |
| 74 if (!pref_service) |
55 return false; | 75 return false; |
56 | 76 |
57 const DictionaryValue* dictionary = | 77 const DictionaryValue* dictionary = pref_service->GetDictionary( |
58 g_browser_process->local_state()->GetDictionary( | 78 WideToUTF8(window_name).c_str()); |
59 WideToUTF8(window_name).c_str()); | 79 |
60 int left, top, right, bottom; | 80 int left, top, right, bottom; |
61 if (!dictionary || !dictionary->GetInteger("left", &left) || | 81 if (!dictionary || !dictionary->GetInteger("left", &left) || |
62 !dictionary->GetInteger("top", &top) || | 82 !dictionary->GetInteger("top", &top) || |
63 !dictionary->GetInteger("right", &right) || | 83 !dictionary->GetInteger("right", &right) || |
64 !dictionary->GetInteger("bottom", &bottom)) | 84 !dictionary->GetInteger("bottom", &bottom)) |
65 return false; | 85 return false; |
66 | 86 |
67 bounds->SetRect(left, top, right - left, bottom - top); | 87 bounds->SetRect(left, top, right - left, bottom - top); |
68 return true; | 88 return true; |
69 } | 89 } |
70 | 90 |
71 bool ChromeViewsDelegate::GetSavedMaximizedState( | 91 bool ChromeViewsDelegate::GetSavedMaximizedState( |
72 const std::wstring& window_name, | 92 const std::wstring& window_name, |
73 bool* maximized) const { | 93 bool* maximized) const { |
74 if (!g_browser_process->local_state()) | 94 PrefService* pref_service = GetPrefService(window_name); |
| 95 if (!pref_service) |
75 return false; | 96 return false; |
76 | 97 |
77 const DictionaryValue* dictionary = | 98 const DictionaryValue* dictionary = pref_service->GetDictionary( |
78 g_browser_process->local_state()->GetDictionary( | 99 WideToUTF8(window_name).c_str()); |
79 WideToUTF8(window_name).c_str()); | 100 |
80 return dictionary && dictionary->GetBoolean("maximized", maximized) && | 101 return dictionary && dictionary->GetBoolean("maximized", maximized) && |
81 maximized; | 102 maximized; |
82 } | 103 } |
83 | 104 |
84 void ChromeViewsDelegate::NotifyAccessibilityEvent( | 105 void ChromeViewsDelegate::NotifyAccessibilityEvent( |
85 views::View* view, AccessibilityTypes::Event event_type) { | 106 views::View* view, AccessibilityTypes::Event event_type) { |
86 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( | 107 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( |
87 view, event_type); | 108 view, event_type); |
88 } | 109 } |
89 | 110 |
90 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
91 HICON ChromeViewsDelegate::GetDefaultWindowIcon() const { | 112 HICON ChromeViewsDelegate::GetDefaultWindowIcon() const { |
92 return GetAppIcon(); | 113 return GetAppIcon(); |
93 } | 114 } |
94 #endif | 115 #endif |
95 | 116 |
96 void ChromeViewsDelegate::AddRef() { | 117 void ChromeViewsDelegate::AddRef() { |
97 g_browser_process->AddRefModule(); | 118 g_browser_process->AddRefModule(); |
98 } | 119 } |
99 | 120 |
100 void ChromeViewsDelegate::ReleaseRef() { | 121 void ChromeViewsDelegate::ReleaseRef() { |
101 g_browser_process->ReleaseModule(); | 122 g_browser_process->ReleaseModule(); |
102 } | 123 } |
OLD | NEW |