OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_window_state.h" | 5 #include "chrome/browser/ui/browser_window_state.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/defaults.h" | 11 #include "chrome/browser/defaults.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sessions/session_service.h" | 13 #include "chrome/browser/sessions/session_service.h" |
13 #include "chrome/browser/sessions/session_service_factory.h" | 14 #include "chrome/browser/sessions/session_service_factory.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 16 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 | 19 |
(...skipping 14 matching lines...) Expand all Loading... | |
33 int num2 = 0; | 34 int num2 = 0; |
34 if (!base::StringToInt(str.substr(0, num1_size), &num1) || | 35 if (!base::StringToInt(str.substr(0, num1_size), &num1) || |
35 !base::StringToInt(str.substr(num2_pos, num2_size), &num2)) | 36 !base::StringToInt(str.substr(num2_pos, num2_size), &num2)) |
36 return false; | 37 return false; |
37 | 38 |
38 *ret_num1 = num1; | 39 *ret_num1 = num1; |
39 *ret_num2 = num2; | 40 *ret_num2 = num2; |
40 return true; | 41 return true; |
41 } | 42 } |
42 | 43 |
44 class WindowPlacementPrefUpdate : public DictionaryPrefUpdate { | |
45 public: | |
46 WindowPlacementPrefUpdate(PrefService* service, | |
47 const std::string& window_name) | |
48 : DictionaryPrefUpdate(service, prefs::kAppWindowPlacement), | |
49 window_name_(window_name) {} | |
50 | |
51 virtual ~WindowPlacementPrefUpdate() {} | |
52 | |
53 virtual base::DictionaryValue* Get() OVERRIDE { | |
54 base::DictionaryValue* all_apps_dict = DictionaryPrefUpdate::Get(); | |
55 base::DictionaryValue* this_app_dict = NULL; | |
56 if (!all_apps_dict->GetDictionary(window_name_, &this_app_dict)) { | |
57 this_app_dict = new base::DictionaryValue; | |
58 all_apps_dict->Set(window_name_, this_app_dict); | |
59 } | |
60 return this_app_dict; | |
61 } | |
62 | |
63 private: | |
64 const std::string window_name_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(WindowPlacementPrefUpdate); | |
67 }; | |
68 | |
43 } // namespace | 69 } // namespace |
44 | 70 |
45 std::string GetWindowPlacementKey(const Browser* browser) { | 71 std::string GetWindowName(const Browser* browser) { |
46 if (browser->app_name().empty()) { | 72 if (browser->app_name().empty()) { |
47 return browser->is_type_popup() ? | 73 return browser->is_type_popup() ? |
48 prefs::kBrowserWindowPlacementPopup : prefs::kBrowserWindowPlacement; | 74 prefs::kBrowserWindowPlacementPopup : prefs::kBrowserWindowPlacement; |
49 } | 75 } |
50 return std::string(prefs::kBrowserWindowPlacement) + "_" + | 76 return browser->app_name(); |
51 browser->app_name(); | 77 } |
78 | |
79 scoped_ptr<DictionaryPrefUpdate> GetWindowPlacementDictionaryReadWrite( | |
80 const std::string& window_name, | |
81 PrefService* prefs) { | |
82 DCHECK(!window_name.empty()); | |
83 if (prefs->FindPreference(window_name.c_str())) { | |
84 return make_scoped_ptr( | |
85 new DictionaryPrefUpdate(prefs, window_name.c_str())); | |
86 } | |
87 return make_scoped_ptr(new WindowPlacementPrefUpdate(prefs, window_name)) | |
gab
2014/09/05 00:53:10
Isn't the whole point of WindowPlacementPrefUpdate
dgrogan
2014/09/06 00:47:06
The check here is for kBrowserWindowPlacement and
| |
88 .PassAs<DictionaryPrefUpdate>(); | |
89 } | |
90 | |
91 const base::DictionaryValue* GetWindowPlacementDictionaryReadOnly( | |
92 const Browser* browser) { | |
93 if (browser->app_name().empty()) { | |
94 const char* entry = browser->is_type_popup() ? | |
95 prefs::kBrowserWindowPlacementPopup : prefs::kBrowserWindowPlacement; | |
96 return browser->profile()->GetPrefs()->GetDictionary(entry); | |
97 } | |
98 const base::DictionaryValue* app_windows = | |
99 browser->profile()->GetPrefs()->GetDictionary(prefs::kAppWindowPlacement); | |
100 if (!app_windows) | |
101 return NULL; | |
102 const base::DictionaryValue* to_return = NULL; | |
103 app_windows->GetDictionary(browser->app_name(), &to_return); | |
104 return to_return; | |
52 } | 105 } |
53 | 106 |
54 bool ShouldSaveWindowPlacement(const Browser* browser) { | 107 bool ShouldSaveWindowPlacement(const Browser* browser) { |
55 // Only save the window placement of popups if the window is from a trusted | 108 // Only save the window placement of popups if the window is from a trusted |
56 // source (v1 app, devtools, or system window). | 109 // source (v1 app, devtools, or system window). |
57 return (browser->type() == Browser::TYPE_TABBED) || | 110 return (browser->type() == Browser::TYPE_TABBED) || |
58 ((browser->type() == Browser::TYPE_POPUP) && browser->is_trusted_source()); | 111 ((browser->type() == Browser::TYPE_POPUP) && browser->is_trusted_source()); |
59 } | 112 } |
60 | 113 |
61 void SaveWindowPlacement(const Browser* browser, | 114 void SaveWindowPlacement(const Browser* browser, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 if (parsed_command_line.HasSwitch(switches::kWindowPosition)) { | 160 if (parsed_command_line.HasSwitch(switches::kWindowPosition)) { |
108 std::string str = | 161 std::string str = |
109 parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition); | 162 parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition); |
110 int x, y; | 163 int x, y; |
111 if (ParseCommaSeparatedIntegers(str, &x, &y)) | 164 if (ParseCommaSeparatedIntegers(str, &x, &y)) |
112 bounds->set_origin(gfx::Point(x, y)); | 165 bounds->set_origin(gfx::Point(x, y)); |
113 } | 166 } |
114 } | 167 } |
115 | 168 |
116 } // namespace chrome | 169 } // namespace chrome |
OLD | NEW |