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/tab_contents/core_tab_helper.h" | 5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/renderer_host/web_cache_manager.h" | 8 #include "chrome/browser/renderer_host/web_cache_manager.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "net/base/load_states.h" | 12 #include "net/base/load_states.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 using content::WebContents; | 16 using content::WebContents; |
17 | 17 |
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper); | 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper); |
19 | 19 |
20 CoreTabHelper::CoreTabHelper(WebContents* web_contents) | 20 CoreTabHelper::CoreTabHelper(WebContents* web_contents) |
21 : content::WebContentsObserver(web_contents), | 21 : content::WebContentsObserver(web_contents), |
22 delegate_(NULL) { | 22 delegate_(NULL), |
| 23 detached_as_part_of_unload_(false) { |
23 } | 24 } |
24 | 25 |
25 CoreTabHelper::~CoreTabHelper() { | 26 CoreTabHelper::~CoreTabHelper() { |
26 } | 27 } |
27 | 28 |
28 string16 CoreTabHelper::GetDefaultTitle() { | 29 string16 CoreTabHelper::GetDefaultTitle() { |
29 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); | 30 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
30 } | 31 } |
31 | 32 |
32 string16 CoreTabHelper::GetStatusText() const { | 33 string16 CoreTabHelper::GetStatusText() const { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 web_contents()->GetLoadStateHost()); | 79 web_contents()->GetLoadStateHost()); |
79 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE | 80 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE |
80 case net::LOAD_STATE_IDLE: | 81 case net::LOAD_STATE_IDLE: |
81 case net::LOAD_STATE_READING_RESPONSE: | 82 case net::LOAD_STATE_READING_RESPONSE: |
82 break; | 83 break; |
83 } | 84 } |
84 | 85 |
85 return string16(); | 86 return string16(); |
86 } | 87 } |
87 | 88 |
| 89 bool CoreTabHelper::GetWebContentsDetachedToClose() const { |
| 90 return detached_as_part_of_unload_; |
| 91 } |
| 92 |
88 void CoreTabHelper::OnCloseStarted() { | 93 void CoreTabHelper::OnCloseStarted() { |
89 if (close_start_time_.is_null()) | 94 if (close_start_time_.is_null()) |
90 close_start_time_ = base::TimeTicks::Now(); | 95 close_start_time_ = base::TimeTicks::Now(); |
91 } | 96 } |
92 | 97 |
93 void CoreTabHelper::OnCloseCanceled() { | 98 void CoreTabHelper::OnCloseCanceled() { |
94 close_start_time_ = base::TimeTicks(); | 99 close_start_time_ = base::TimeTicks(); |
95 before_unload_end_time_ = base::TimeTicks(); | 100 before_unload_end_time_ = base::TimeTicks(); |
96 unload_detached_start_time_ = base::TimeTicks(); | 101 unload_detached_start_time_ = base::TimeTicks(); |
97 } | 102 } |
98 | 103 |
99 void CoreTabHelper::OnUnloadStarted() { | 104 void CoreTabHelper::OnUnloadStarted() { |
100 before_unload_end_time_ = base::TimeTicks::Now(); | 105 before_unload_end_time_ = base::TimeTicks::Now(); |
101 } | 106 } |
102 | 107 |
| 108 void CoreTabHelper::OnUnloadAboutToDetach() { |
| 109 detached_as_part_of_unload_ = true; |
| 110 } |
| 111 |
103 void CoreTabHelper::OnUnloadDetachedStarted() { | 112 void CoreTabHelper::OnUnloadDetachedStarted() { |
104 if (unload_detached_start_time_.is_null()) | 113 if (unload_detached_start_time_.is_null()) |
105 unload_detached_start_time_ = base::TimeTicks::Now(); | 114 unload_detached_start_time_ = base::TimeTicks::Now(); |
106 } | 115 } |
107 | 116 |
108 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
109 // WebContentsObserver overrides | 118 // WebContentsObserver overrides |
110 | 119 |
111 void CoreTabHelper::WasShown() { | 120 void CoreTabHelper::WasShown() { |
112 WebCacheManager::GetInstance()->ObserveActivity( | 121 WebCacheManager::GetInstance()->ObserveActivity( |
(...skipping 19 matching lines...) Expand all Loading... |
132 } | 141 } |
133 } | 142 } |
134 | 143 |
135 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { | 144 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { |
136 before_unload_end_time_ = proceed_time; | 145 before_unload_end_time_ = proceed_time; |
137 } | 146 } |
138 | 147 |
139 void CoreTabHelper::BeforeUnloadDialogCancelled() { | 148 void CoreTabHelper::BeforeUnloadDialogCancelled() { |
140 OnCloseCanceled(); | 149 OnCloseCanceled(); |
141 } | 150 } |
OLD | NEW |