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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/browser_shutdown.h" | |
12 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/ui/views/accessibility_event_router_views.h" | 14 #include "chrome/browser/ui/views/accessibility_event_router_views.h" |
16 #include "chrome/browser/ui/views/event_utils.h" | 15 #include "chrome/browser/ui/views/event_utils.h" |
17 #include "chrome/browser/ui/window_sizer.h" | 16 #include "chrome/browser/ui/window_sizer.h" |
18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
19 #include "ui/base/clipboard/clipboard.h" | 18 #include "ui/base/clipboard/clipboard.h" |
20 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
21 #include "views/widget/native_widget.h" | 20 #include "views/widget/native_widget.h" |
22 #include "views/widget/widget.h" | 21 #include "views/widget/widget.h" |
23 | 22 |
24 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
25 #include "chrome/browser/app_icon_win.h" | 24 #include "chrome/browser/app_icon_win.h" |
26 #endif | 25 #endif |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 // If the given window has a profile associated with it, use that profile's | 29 // If the given window has a profile associated with it, use that profile's |
31 // preference service. Otherwise, store and retrieve the data from Local State. | 30 // preference service. Otherwise, store and retrieve the data from Local State. |
32 // This function may return NULL if the necessary pref service has not yet | 31 // This function may return NULL if the necessary pref service has not yet |
33 // been initialized. | 32 // been initialized. |
34 // TODO(mirandac): This function will also separate windows by profile in a | 33 // TODO(mirandac): This function will also separate windows by profile in a |
35 // multi-profile environment. | 34 // multi-profile environment. |
36 // TODO(sky): remove is_incognito. Used in tracking 91396. | 35 PrefService* GetPrefsForWindow(const views::Widget* window) { |
37 PrefService* GetPrefsForWindow(const views::Widget* window, | |
38 bool* is_incognito) { | |
39 Profile* profile = reinterpret_cast<Profile*>( | 36 Profile* profile = reinterpret_cast<Profile*>( |
40 window->GetNativeWindowProperty(Profile::kProfileKey)); | 37 window->GetNativeWindowProperty(Profile::kProfileKey)); |
41 *is_incognito = false; | |
42 if (!profile) { | 38 if (!profile) { |
43 // Use local state for windows that have no explicit profile. | 39 // Use local state for windows that have no explicit profile. |
44 return g_browser_process->local_state(); | 40 return g_browser_process->local_state(); |
45 } | 41 } |
46 *is_incognito = profile->IsOffTheRecord(); | |
47 return profile->GetPrefs(); | 42 return profile->GetPrefs(); |
48 } | 43 } |
49 | 44 |
50 } // namespace | 45 } // namespace |
51 | 46 |
52 // static | 47 // static |
53 views::View* ChromeViewsDelegate::default_parent_view = NULL; | 48 views::View* ChromeViewsDelegate::default_parent_view = NULL; |
54 | 49 |
55 /////////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////////// |
56 // ChromeViewsDelegate, views::ViewsDelegate implementation: | 51 // ChromeViewsDelegate, views::ViewsDelegate implementation: |
57 | 52 |
58 ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { | 53 ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { |
59 return g_browser_process->clipboard(); | 54 return g_browser_process->clipboard(); |
60 } | 55 } |
61 | 56 |
62 views::View* ChromeViewsDelegate::GetDefaultParentView() { | 57 views::View* ChromeViewsDelegate::GetDefaultParentView() { |
63 return default_parent_view; | 58 return default_parent_view; |
64 } | 59 } |
65 | 60 |
66 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, | 61 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, |
67 const std::wstring& window_name, | 62 const std::wstring& window_name, |
68 const gfx::Rect& bounds, | 63 const gfx::Rect& bounds, |
69 bool maximized) { | 64 bool maximized) { |
70 bool is_incognito = false; | 65 PrefService* prefs = GetPrefsForWindow(window); |
71 PrefService* prefs = GetPrefsForWindow(window, &is_incognito); | |
72 if (!prefs) | 66 if (!prefs) |
73 return; | 67 return; |
74 | 68 |
75 volatile browser_shutdown::ShutdownType shutdown_type = | 69 DCHECK(prefs->FindPreference(WideToUTF8(window_name).c_str())); |
76 browser_shutdown::GetShutdownType(); | |
77 CHECK(prefs->FindPreference(WideToUTF8(window_name).c_str())) << | |
78 is_incognito << " " << shutdown_type; | |
79 DictionaryPrefUpdate update(prefs, WideToUTF8(window_name).c_str()); | 70 DictionaryPrefUpdate update(prefs, WideToUTF8(window_name).c_str()); |
80 DictionaryValue* window_preferences = update.Get(); | 71 DictionaryValue* window_preferences = update.Get(); |
81 CHECK(window_preferences) << is_incognito << " " << shutdown_type; | |
82 window_preferences->SetInteger("left", bounds.x()); | 72 window_preferences->SetInteger("left", bounds.x()); |
83 window_preferences->SetInteger("top", bounds.y()); | 73 window_preferences->SetInteger("top", bounds.y()); |
84 window_preferences->SetInteger("right", bounds.right()); | 74 window_preferences->SetInteger("right", bounds.right()); |
85 window_preferences->SetInteger("bottom", bounds.bottom()); | 75 window_preferences->SetInteger("bottom", bounds.bottom()); |
86 window_preferences->SetBoolean("maximized", maximized); | 76 window_preferences->SetBoolean("maximized", maximized); |
87 | 77 |
88 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( | 78 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( |
89 WindowSizer::CreateDefaultMonitorInfoProvider()); | 79 WindowSizer::CreateDefaultMonitorInfoProvider()); |
90 gfx::Rect work_area( | 80 gfx::Rect work_area( |
91 monitor_info_provider->GetMonitorWorkAreaMatching(bounds)); | 81 monitor_info_provider->GetMonitorWorkAreaMatching(bounds)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 g_browser_process->AddRefModule(); | 146 g_browser_process->AddRefModule(); |
157 } | 147 } |
158 | 148 |
159 void ChromeViewsDelegate::ReleaseRef() { | 149 void ChromeViewsDelegate::ReleaseRef() { |
160 g_browser_process->ReleaseModule(); | 150 g_browser_process->ReleaseModule(); |
161 } | 151 } |
162 | 152 |
163 int ChromeViewsDelegate::GetDispositionForEvent(int event_flags) { | 153 int ChromeViewsDelegate::GetDispositionForEvent(int event_flags) { |
164 return event_utils::DispositionFromEventFlags(event_flags); | 154 return event_utils::DispositionFromEventFlags(event_flags); |
165 } | 155 } |
OLD | NEW |