| 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/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model.h" | 15 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
| 17 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_tab_helper.h" | 19 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sessions/tab_restore_service.h" | 21 #include "chrome/browser/sessions/tab_restore_service.h" |
| 22 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 22 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
| 23 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" | 23 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 27 #include "content/browser/renderer_host/render_process_host.h" | 28 #include "content/browser/renderer_host/render_process_host.h" |
| 28 #include "content/browser/tab_contents/navigation_controller.h" | 29 #include "content/browser/tab_contents/navigation_controller.h" |
| 29 #include "content/browser/tab_contents/tab_contents.h" | 30 #include "content/browser/tab_contents/tab_contents.h" |
| 30 #include "content/browser/tab_contents/tab_contents_delegate.h" | 31 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 31 #include "content/browser/tab_contents/tab_contents_view.h" | 32 #include "content/browser/tab_contents/tab_contents_view.h" |
| 32 #include "content/browser/user_metrics.h" | 33 #include "content/browser/user_metrics.h" |
| 33 #include "content/common/notification_service.h" | 34 #include "content/common/notification_service.h" |
| 34 | 35 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 62 TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile) | 63 TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile) |
| 63 : delegate_(delegate), | 64 : delegate_(delegate), |
| 64 profile_(profile), | 65 profile_(profile), |
| 65 closing_all_(false), | 66 closing_all_(false), |
| 66 order_controller_(NULL) { | 67 order_controller_(NULL) { |
| 67 DCHECK(delegate_); | 68 DCHECK(delegate_); |
| 68 registrar_.Add(this, | 69 registrar_.Add(this, |
| 69 NotificationType::TAB_CONTENTS_DESTROYED, | 70 NotificationType::TAB_CONTENTS_DESTROYED, |
| 70 NotificationService::AllSources()); | 71 NotificationService::AllSources()); |
| 71 registrar_.Add(this, | 72 registrar_.Add(this, |
| 72 NotificationType::EXTENSION_UNLOADED, | 73 chrome::EXTENSION_UNLOADED, |
| 73 Source<Profile>(profile_)); | 74 Source<Profile>(profile_)); |
| 74 order_controller_ = new TabStripModelOrderController(this); | 75 order_controller_ = new TabStripModelOrderController(this); |
| 75 } | 76 } |
| 76 | 77 |
| 77 TabStripModel::~TabStripModel() { | 78 TabStripModel::~TabStripModel() { |
| 78 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 79 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
| 79 TabStripModelDeleted()); | 80 TabStripModelDeleted()); |
| 80 STLDeleteContainerPointers(contents_data_.begin(), contents_data_.end()); | 81 STLDeleteContainerPointers(contents_data_.begin(), contents_data_.end()); |
| 81 delete order_controller_; | 82 delete order_controller_; |
| 82 } | 83 } |
| (...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 // here so we don't crash later. | 998 // here so we don't crash later. |
| 998 int index = GetWrapperIndex(Source<TabContents>(source).ptr()); | 999 int index = GetWrapperIndex(Source<TabContents>(source).ptr()); |
| 999 if (index != TabStripModel::kNoTab) { | 1000 if (index != TabStripModel::kNoTab) { |
| 1000 // Note that we only detach the contents here, not close it - it's | 1001 // Note that we only detach the contents here, not close it - it's |
| 1001 // already been closed. We just want to undo our bookkeeping. | 1002 // already been closed. We just want to undo our bookkeeping. |
| 1002 DetachTabContentsAt(index); | 1003 DetachTabContentsAt(index); |
| 1003 } | 1004 } |
| 1004 break; | 1005 break; |
| 1005 } | 1006 } |
| 1006 | 1007 |
| 1007 case NotificationType::EXTENSION_UNLOADED: { | 1008 case chrome::EXTENSION_UNLOADED: { |
| 1008 const Extension* extension = | 1009 const Extension* extension = |
| 1009 Details<UnloadedExtensionInfo>(details)->extension; | 1010 Details<UnloadedExtensionInfo>(details)->extension; |
| 1010 // Iterate backwards as we may remove items while iterating. | 1011 // Iterate backwards as we may remove items while iterating. |
| 1011 for (int i = count() - 1; i >= 0; i--) { | 1012 for (int i = count() - 1; i >= 0; i--) { |
| 1012 TabContentsWrapper* contents = GetTabContentsAt(i); | 1013 TabContentsWrapper* contents = GetTabContentsAt(i); |
| 1013 if (contents->extension_tab_helper()->extension_app() == extension) { | 1014 if (contents->extension_tab_helper()->extension_app() == extension) { |
| 1014 // The extension an app tab was created from has been nuked. Delete | 1015 // The extension an app tab was created from has been nuked. Delete |
| 1015 // the TabContents. Deleting a TabContents results in a notification | 1016 // the TabContents. Deleting a TabContents results in a notification |
| 1016 // of type TAB_CONTENTS_DESTROYED; we do the necessary cleanup in | 1017 // of type TAB_CONTENTS_DESTROYED; we do the necessary cleanup in |
| 1017 // handling that notification. | 1018 // handling that notification. |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1318 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1318 const NavigationController* tab) { | 1319 const NavigationController* tab) { |
| 1319 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1320 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1320 i != contents_data_.end(); ++i) { | 1321 i != contents_data_.end(); ++i) { |
| 1321 if ((*i)->group == tab) | 1322 if ((*i)->group == tab) |
| 1322 (*i)->group = NULL; | 1323 (*i)->group = NULL; |
| 1323 if ((*i)->opener == tab) | 1324 if ((*i)->opener == tab) |
| 1324 (*i)->opener = NULL; | 1325 (*i)->opener = NULL; |
| 1325 } | 1326 } |
| 1326 } | 1327 } |
| OLD | NEW |