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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "chrome/browser/renderer_host/web_cache_manager.h" | 9 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_command_controller.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
11 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
14 #include "net/base/load_states.h" | 17 #include "net/base/load_states.h" |
15 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
17 | 20 |
18 using content::WebContents; | 21 using content::WebContents; |
19 | 22 |
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper); | 23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper); |
21 | 24 |
22 CoreTabHelper::CoreTabHelper(WebContents* web_contents) | 25 CoreTabHelper::CoreTabHelper(WebContents* web_contents) |
23 : content::WebContentsObserver(web_contents), | 26 : content::WebContentsObserver(web_contents), |
24 delegate_(NULL) { | 27 delegate_(NULL), |
| 28 content_restrictions_(0) { |
25 } | 29 } |
26 | 30 |
27 CoreTabHelper::~CoreTabHelper() { | 31 CoreTabHelper::~CoreTabHelper() { |
28 } | 32 } |
29 | 33 |
30 string16 CoreTabHelper::GetDefaultTitle() { | 34 string16 CoreTabHelper::GetDefaultTitle() { |
31 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); | 35 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
32 } | 36 } |
33 | 37 |
34 string16 CoreTabHelper::GetStatusText() const { | 38 string16 CoreTabHelper::GetStatusText() const { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 107 |
104 void CoreTabHelper::OnUnloadStarted() { | 108 void CoreTabHelper::OnUnloadStarted() { |
105 before_unload_end_time_ = base::TimeTicks::Now(); | 109 before_unload_end_time_ = base::TimeTicks::Now(); |
106 } | 110 } |
107 | 111 |
108 void CoreTabHelper::OnUnloadDetachedStarted() { | 112 void CoreTabHelper::OnUnloadDetachedStarted() { |
109 if (unload_detached_start_time_.is_null()) | 113 if (unload_detached_start_time_.is_null()) |
110 unload_detached_start_time_ = base::TimeTicks::Now(); | 114 unload_detached_start_time_ = base::TimeTicks::Now(); |
111 } | 115 } |
112 | 116 |
| 117 void CoreTabHelper::UpdateContentRestrictions(int content_restrictions) { |
| 118 content_restrictions_ = content_restrictions; |
| 119 #if !defined(OS_ANDROID) |
| 120 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 121 if (!browser) |
| 122 return; |
| 123 |
| 124 browser->command_controller()->ContentRestrictionsChanged(); |
| 125 #endif |
| 126 } |
| 127 |
113 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
114 // WebContentsObserver overrides | 129 // WebContentsObserver overrides |
115 | 130 |
| 131 void CoreTabHelper::DidStartLoading(content::RenderViewHost* render_view_host) { |
| 132 UpdateContentRestrictions(0); |
| 133 } |
| 134 |
116 void CoreTabHelper::WasShown() { | 135 void CoreTabHelper::WasShown() { |
117 WebCacheManager::GetInstance()->ObserveActivity( | 136 WebCacheManager::GetInstance()->ObserveActivity( |
118 web_contents()->GetRenderProcessHost()->GetID()); | 137 web_contents()->GetRenderProcessHost()->GetID()); |
119 } | 138 } |
120 | 139 |
121 void CoreTabHelper::WebContentsDestroyed(WebContents* web_contents) { | 140 void CoreTabHelper::WebContentsDestroyed(WebContents* web_contents) { |
122 // OnCloseStarted isn't called in unit tests. | 141 // OnCloseStarted isn't called in unit tests. |
123 if (!close_start_time_.is_null()) { | 142 if (!close_start_time_.is_null()) { |
124 bool fast_tab_close_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | 143 bool fast_tab_close_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
125 switches::kEnableFastUnload); | 144 switches::kEnableFastUnload); |
(...skipping 23 matching lines...) Expand all Loading... |
149 | 168 |
150 } | 169 } |
151 | 170 |
152 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { | 171 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { |
153 before_unload_end_time_ = proceed_time; | 172 before_unload_end_time_ = proceed_time; |
154 } | 173 } |
155 | 174 |
156 void CoreTabHelper::BeforeUnloadDialogCancelled() { | 175 void CoreTabHelper::BeforeUnloadDialogCancelled() { |
157 OnCloseCanceled(); | 176 OnCloseCanceled(); |
158 } | 177 } |
OLD | NEW |