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