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/sessions/session_service.h" | 5 #include "chrome/browser/sessions/session_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "content/public/browser/navigation_entry.h" | 38 #include "content/public/browser/navigation_entry.h" |
39 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
40 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/session_storage_namespace.h" | 41 #include "content/public/browser/session_storage_namespace.h" |
42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
43 | 43 |
44 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
45 #include "chrome/browser/app_controller_mac.h" | 45 #include "chrome/browser/app_controller_mac.h" |
46 #endif | 46 #endif |
47 | 47 |
| 48 #if defined(USE_ASH) |
| 49 #include "ash/wm/window_util.h" |
| 50 #endif |
| 51 |
48 using base::Time; | 52 using base::Time; |
49 using content::NavigationEntry; | 53 using content::NavigationEntry; |
50 using content::WebContents; | 54 using content::WebContents; |
51 | 55 |
52 // Identifier for commands written to file. | 56 // Identifier for commands written to file. |
53 static const SessionCommand::id_type kCommandSetTabWindow = 0; | 57 static const SessionCommand::id_type kCommandSetTabWindow = 0; |
54 // OBSOLETE Superseded by kCommandSetWindowBounds3. | 58 // OBSOLETE Superseded by kCommandSetWindowBounds3. |
55 // static const SessionCommand::id_type kCommandSetWindowBounds = 1; | 59 // static const SessionCommand::id_type kCommandSetWindowBounds = 1; |
56 static const SessionCommand::id_type kCommandSetTabIndexInWindow = 2; | 60 static const SessionCommand::id_type kCommandSetTabIndexInWindow = 2; |
57 // Original kCommandTabClosed/kCommandWindowClosed. See comment in | 61 // Original kCommandTabClosed/kCommandWindowClosed. See comment in |
(...skipping 12 matching lines...) Expand all Loading... |
70 kCommandTabNavigationPathPrunedFromFront = 11; | 74 kCommandTabNavigationPathPrunedFromFront = 11; |
71 static const SessionCommand::id_type kCommandSetPinnedState = 12; | 75 static const SessionCommand::id_type kCommandSetPinnedState = 12; |
72 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; | 76 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; |
73 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; | 77 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; |
74 static const SessionCommand::id_type kCommandSetWindowAppName = 15; | 78 static const SessionCommand::id_type kCommandSetWindowAppName = 15; |
75 static const SessionCommand::id_type kCommandTabClosed = 16; | 79 static const SessionCommand::id_type kCommandTabClosed = 16; |
76 static const SessionCommand::id_type kCommandWindowClosed = 17; | 80 static const SessionCommand::id_type kCommandWindowClosed = 17; |
77 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; | 81 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; |
78 static const SessionCommand::id_type kCommandSessionStorageAssociated = 19; | 82 static const SessionCommand::id_type kCommandSessionStorageAssociated = 19; |
79 static const SessionCommand::id_type kCommandSetActiveWindow = 20; | 83 static const SessionCommand::id_type kCommandSetActiveWindow = 20; |
| 84 static const SessionCommand::id_type kCommandSetWindowBounds4 = 21; |
80 | 85 |
81 // Every kWritesPerReset commands triggers recreating the file. | 86 // Every kWritesPerReset commands triggers recreating the file. |
82 static const int kWritesPerReset = 250; | 87 static const int kWritesPerReset = 250; |
83 | 88 |
84 namespace { | 89 namespace { |
85 | 90 |
86 // The callback from GetLastSession is internally routed to SessionService | 91 // The callback from GetLastSession is internally routed to SessionService |
87 // first and then the caller. This is done so that the SessionWindows can be | 92 // first and then the caller. This is done so that the SessionWindows can be |
88 // recreated from the SessionCommands and the SessionWindows passed to the | 93 // recreated from the SessionCommands and the SessionWindows passed to the |
89 // caller. The following class is used for this. | 94 // caller. The following class is used for this. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 128 |
124 struct WindowBoundsPayload3 { | 129 struct WindowBoundsPayload3 { |
125 SessionID::id_type window_id; | 130 SessionID::id_type window_id; |
126 int32 x; | 131 int32 x; |
127 int32 y; | 132 int32 y; |
128 int32 w; | 133 int32 w; |
129 int32 h; | 134 int32 h; |
130 int32 show_state; | 135 int32 show_state; |
131 }; | 136 }; |
132 | 137 |
| 138 struct WindowBoundsPayload4 { |
| 139 SessionID::id_type window_id; |
| 140 int32 x; |
| 141 int32 y; |
| 142 int32 w; |
| 143 int32 h; |
| 144 int32 show_state; |
| 145 bool user_has_changed_window_or_position; |
| 146 }; |
| 147 |
133 typedef SessionID::id_type ActiveWindowPayload; | 148 typedef SessionID::id_type ActiveWindowPayload; |
134 | 149 |
135 struct IDAndIndexPayload { | 150 struct IDAndIndexPayload { |
136 SessionID::id_type id; | 151 SessionID::id_type id; |
137 int32 index; | 152 int32 index; |
138 }; | 153 }; |
139 | 154 |
140 typedef IDAndIndexPayload TabIndexInWindowPayload; | 155 typedef IDAndIndexPayload TabIndexInWindowPayload; |
141 | 156 |
142 typedef IDAndIndexPayload TabNavigationPathPrunedFromBackPayload; | 157 typedef IDAndIndexPayload TabNavigationPathPrunedFromBackPayload; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 265 } |
251 | 266 |
252 void SessionService::SetTabWindow(const SessionID& window_id, | 267 void SessionService::SetTabWindow(const SessionID& window_id, |
253 const SessionID& tab_id) { | 268 const SessionID& tab_id) { |
254 if (!ShouldTrackChangesToWindow(window_id)) | 269 if (!ShouldTrackChangesToWindow(window_id)) |
255 return; | 270 return; |
256 | 271 |
257 ScheduleCommand(CreateSetTabWindowCommand(window_id, tab_id)); | 272 ScheduleCommand(CreateSetTabWindowCommand(window_id, tab_id)); |
258 } | 273 } |
259 | 274 |
260 void SessionService::SetWindowBounds(const SessionID& window_id, | 275 void SessionService::SetWindowBounds( |
261 const gfx::Rect& bounds, | 276 const SessionID& window_id, |
262 ui::WindowShowState show_state) { | 277 const gfx::Rect& bounds, |
| 278 ui::WindowShowState show_state, |
| 279 bool user_has_changed_window_or_position) { |
263 if (!ShouldTrackChangesToWindow(window_id)) | 280 if (!ShouldTrackChangesToWindow(window_id)) |
264 return; | 281 return; |
265 | 282 ScheduleCommand(CreateSetWindowBoundsCommand( |
266 ScheduleCommand(CreateSetWindowBoundsCommand(window_id, bounds, show_state)); | 283 window_id, |
| 284 bounds, |
| 285 show_state, |
| 286 user_has_changed_window_or_position)); |
267 } | 287 } |
268 | 288 |
269 void SessionService::SetTabIndexInWindow(const SessionID& window_id, | 289 void SessionService::SetTabIndexInWindow(const SessionID& window_id, |
270 const SessionID& tab_id, | 290 const SessionID& tab_id, |
271 int new_index) { | 291 int new_index) { |
272 if (!ShouldTrackChangesToWindow(window_id)) | 292 if (!ShouldTrackChangesToWindow(window_id)) |
273 return; | 293 return; |
274 | 294 |
275 ScheduleCommand(CreateSetTabIndexInWindowCommand(tab_id, new_index)); | 295 ScheduleCommand(CreateSetTabIndexInWindowCommand(tab_id, new_index)); |
276 } | 296 } |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 SessionID::id_type payload[] = { window_id.id(), tab_id.id() }; | 757 SessionID::id_type payload[] = { window_id.id(), tab_id.id() }; |
738 SessionCommand* command = | 758 SessionCommand* command = |
739 new SessionCommand(kCommandSetTabWindow, sizeof(payload)); | 759 new SessionCommand(kCommandSetTabWindow, sizeof(payload)); |
740 memcpy(command->contents(), payload, sizeof(payload)); | 760 memcpy(command->contents(), payload, sizeof(payload)); |
741 return command; | 761 return command; |
742 } | 762 } |
743 | 763 |
744 SessionCommand* SessionService::CreateSetWindowBoundsCommand( | 764 SessionCommand* SessionService::CreateSetWindowBoundsCommand( |
745 const SessionID& window_id, | 765 const SessionID& window_id, |
746 const gfx::Rect& bounds, | 766 const gfx::Rect& bounds, |
747 ui::WindowShowState show_state) { | 767 ui::WindowShowState show_state, |
748 WindowBoundsPayload3 payload = { 0 }; | 768 bool user_has_changed_window_or_position) { |
| 769 WindowBoundsPayload4 payload = { 0 }; |
749 payload.window_id = window_id.id(); | 770 payload.window_id = window_id.id(); |
750 payload.x = bounds.x(); | 771 payload.x = bounds.x(); |
751 payload.y = bounds.y(); | 772 payload.y = bounds.y(); |
752 payload.w = bounds.width(); | 773 payload.w = bounds.width(); |
753 payload.h = bounds.height(); | 774 payload.h = bounds.height(); |
754 payload.show_state = AdjustShowState(show_state); | 775 payload.show_state = AdjustShowState(show_state); |
755 SessionCommand* command = new SessionCommand(kCommandSetWindowBounds3, | 776 payload.user_has_changed_window_or_position = |
| 777 user_has_changed_window_or_position; |
| 778 SessionCommand* command = new SessionCommand(kCommandSetWindowBounds4, |
756 sizeof(payload)); | 779 sizeof(payload)); |
757 memcpy(command->contents(), &payload, sizeof(payload)); | 780 memcpy(command->contents(), &payload, sizeof(payload)); |
758 return command; | 781 return command; |
759 } | 782 } |
760 | 783 |
761 SessionCommand* SessionService::CreateSetTabIndexInWindowCommand( | 784 SessionCommand* SessionService::CreateSetTabIndexInWindowCommand( |
762 const SessionID& tab_id, | 785 const SessionID& tab_id, |
763 int new_index) { | 786 int new_index) { |
764 TabIndexInWindowPayload payload = { 0 }; | 787 TabIndexInWindowPayload payload = { 0 }; |
765 payload.id = tab_id.id(); | 788 payload.id = tab_id.id(); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 payload.show_state < ui::SHOW_STATE_END && | 1102 payload.show_state < ui::SHOW_STATE_END && |
1080 payload.show_state != ui::SHOW_STATE_INACTIVE) { | 1103 payload.show_state != ui::SHOW_STATE_INACTIVE) { |
1081 show_state = static_cast<ui::WindowShowState>(payload.show_state); | 1104 show_state = static_cast<ui::WindowShowState>(payload.show_state); |
1082 } else { | 1105 } else { |
1083 NOTREACHED(); | 1106 NOTREACHED(); |
1084 } | 1107 } |
1085 GetWindow(payload.window_id, windows)->show_state = show_state; | 1108 GetWindow(payload.window_id, windows)->show_state = show_state; |
1086 break; | 1109 break; |
1087 } | 1110 } |
1088 | 1111 |
| 1112 case kCommandSetWindowBounds4: { |
| 1113 WindowBoundsPayload4 payload; |
| 1114 if (!command->GetPayload(&payload, sizeof(payload))) { |
| 1115 VLOG(1) << "Failed reading command " << command->id(); |
| 1116 return true; |
| 1117 } |
| 1118 GetWindow(payload.window_id, windows)->bounds.SetRect(payload.x, |
| 1119 payload.y, |
| 1120 payload.w, |
| 1121 payload.h); |
| 1122 // SHOW_STATE_INACTIVE is not persisted. |
| 1123 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; |
| 1124 if (payload.show_state > ui::SHOW_STATE_DEFAULT && |
| 1125 payload.show_state < ui::SHOW_STATE_END && |
| 1126 payload.show_state != ui::SHOW_STATE_INACTIVE) { |
| 1127 show_state = static_cast<ui::WindowShowState>(payload.show_state); |
| 1128 } else { |
| 1129 NOTREACHED(); |
| 1130 } |
| 1131 GetWindow(payload.window_id, windows)->show_state = show_state; |
| 1132 GetWindow(payload.window_id, |
| 1133 windows)->user_has_changed_window_or_position = |
| 1134 payload.user_has_changed_window_or_position; |
| 1135 break; |
| 1136 } |
| 1137 |
1089 case kCommandSetTabIndexInWindow: { | 1138 case kCommandSetTabIndexInWindow: { |
1090 TabIndexInWindowPayload payload; | 1139 TabIndexInWindowPayload payload; |
1091 if (!command->GetPayload(&payload, sizeof(payload))) { | 1140 if (!command->GetPayload(&payload, sizeof(payload))) { |
1092 VLOG(1) << "Failed reading command " << command->id(); | 1141 VLOG(1) << "Failed reading command " << command->id(); |
1093 return true; | 1142 return true; |
1094 } | 1143 } |
1095 GetTab(payload.id, tabs)->tab_visual_index = payload.index; | 1144 GetTab(payload.id, tabs)->tab_visual_index = payload.index; |
1096 break; | 1145 break; |
1097 } | 1146 } |
1098 | 1147 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 std::set<SessionID::id_type>* windows_to_track) { | 1416 std::set<SessionID::id_type>* windows_to_track) { |
1368 DCHECK(browser && commands); | 1417 DCHECK(browser && commands); |
1369 DCHECK(browser->session_id().id()); | 1418 DCHECK(browser->session_id().id()); |
1370 | 1419 |
1371 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; | 1420 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; |
1372 if (browser->window()->IsMaximized()) | 1421 if (browser->window()->IsMaximized()) |
1373 show_state = ui::SHOW_STATE_MAXIMIZED; | 1422 show_state = ui::SHOW_STATE_MAXIMIZED; |
1374 else if (browser->window()->IsMinimized()) | 1423 else if (browser->window()->IsMinimized()) |
1375 show_state = ui::SHOW_STATE_MINIMIZED; | 1424 show_state = ui::SHOW_STATE_MINIMIZED; |
1376 | 1425 |
| 1426 bool user_has_changed_window_or_position = false; |
| 1427 #if defined(USE_ASH) |
| 1428 user_has_changed_window_or_position = |
| 1429 ash::wm::HasUserChangedWindowPositionOrSize( |
| 1430 browser->window()->GetNativeWindow()); |
| 1431 #endif |
1377 commands->push_back( | 1432 commands->push_back( |
1378 CreateSetWindowBoundsCommand(browser->session_id(), | 1433 CreateSetWindowBoundsCommand(browser->session_id(), |
1379 browser->window()->GetRestoredBounds(), | 1434 browser->window()->GetRestoredBounds(), |
1380 show_state)); | 1435 show_state, |
| 1436 user_has_changed_window_or_position)); |
1381 | 1437 |
1382 commands->push_back(CreateSetWindowTypeCommand( | 1438 commands->push_back(CreateSetWindowTypeCommand( |
1383 browser->session_id(), WindowTypeForBrowserType(browser->type()))); | 1439 browser->session_id(), WindowTypeForBrowserType(browser->type()))); |
1384 | 1440 |
1385 if (!browser->app_name().empty()) { | 1441 if (!browser->app_name().empty()) { |
1386 commands->push_back(CreateSetWindowAppNameCommand( | 1442 commands->push_back(CreateSetWindowAppNameCommand( |
1387 kCommandSetWindowAppName, | 1443 kCommandSetWindowAppName, |
1388 browser->session_id().id(), | 1444 browser->session_id().id(), |
1389 browser->app_name())); | 1445 browser->app_name())); |
1390 } | 1446 } |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 contents->GetController().GetDefaultSessionStorageNamespace(); | 1842 contents->GetController().GetDefaultSessionStorageNamespace(); |
1787 session_storage_namespace->SetShouldPersist(false); | 1843 session_storage_namespace->SetShouldPersist(false); |
1788 SessionTabHelper* session_tab_helper = | 1844 SessionTabHelper* session_tab_helper = |
1789 SessionTabHelper::FromWebContents(contents); | 1845 SessionTabHelper::FromWebContents(contents); |
1790 TabClosed(session_tab_helper->window_id(), | 1846 TabClosed(session_tab_helper->window_id(), |
1791 session_tab_helper->session_id(), | 1847 session_tab_helper->session_id(), |
1792 contents->GetClosedByUserGesture()); | 1848 contents->GetClosedByUserGesture()); |
1793 RecordSessionUpdateHistogramData(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1849 RecordSessionUpdateHistogramData(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
1794 &last_updated_tab_closed_time_); | 1850 &last_updated_tab_closed_time_); |
1795 } | 1851 } |
OLD | NEW |