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/ui/tab_contents/core_tab_helper.h" | 5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/renderer_host/web_cache_manager.h" | 7 #include "chrome/browser/renderer_host/web_cache_manager.h" |
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
9 #include "content/browser/renderer_host/render_view_host.h" | 9 #include "content/browser/renderer_host/render_view_host.h" |
10 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/public/browser/render_process_host.h" |
| 11 #include "content/public/browser/web_contents.h" |
11 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 | 14 |
14 CoreTabHelper::CoreTabHelper(TabContentsWrapper* wrapper) | 15 using content::WebContents; |
15 : content::WebContentsObserver(wrapper->tab_contents()), | 16 |
16 delegate_(NULL), | 17 CoreTabHelper::CoreTabHelper(WebContents* web_contents) |
17 wrapper_(wrapper) { | 18 : content::WebContentsObserver(web_contents), |
| 19 delegate_(NULL) { |
18 } | 20 } |
19 | 21 |
20 CoreTabHelper::~CoreTabHelper() { | 22 CoreTabHelper::~CoreTabHelper() { |
21 } | 23 } |
22 | 24 |
23 string16 CoreTabHelper::GetDefaultTitle() { | 25 string16 CoreTabHelper::GetDefaultTitle() { |
24 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); | 26 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
25 } | 27 } |
26 | 28 |
27 string16 CoreTabHelper::GetStatusText() const { | 29 string16 CoreTabHelper::GetStatusText() const { |
28 if (!tab_contents()->IsLoading() || | 30 if (!web_contents()->IsLoading() || |
29 tab_contents()->GetLoadState().state == net::LOAD_STATE_IDLE) { | 31 web_contents()->GetLoadState().state == net::LOAD_STATE_IDLE) { |
30 return string16(); | 32 return string16(); |
31 } | 33 } |
32 | 34 |
33 switch (tab_contents()->GetLoadState().state) { | 35 switch (web_contents()->GetLoadState().state) { |
34 case net::LOAD_STATE_WAITING_FOR_DELEGATE: | 36 case net::LOAD_STATE_WAITING_FOR_DELEGATE: |
35 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE, | 37 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE, |
36 tab_contents()->GetLoadState().param); | 38 web_contents()->GetLoadState().param); |
37 case net::LOAD_STATE_WAITING_FOR_CACHE: | 39 case net::LOAD_STATE_WAITING_FOR_CACHE: |
38 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE); | 40 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE); |
39 case net::LOAD_STATE_WAITING_FOR_APPCACHE: | 41 case net::LOAD_STATE_WAITING_FOR_APPCACHE: |
40 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE); | 42 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE); |
41 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL: | 43 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL: |
42 return | 44 return |
43 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); | 45 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); |
44 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: | 46 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: |
45 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); | 47 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); |
46 case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT: | 48 case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT: |
47 return l10n_util::GetStringUTF16( | 49 return l10n_util::GetStringUTF16( |
48 IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT); | 50 IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT); |
49 case net::LOAD_STATE_RESOLVING_HOST: | 51 case net::LOAD_STATE_RESOLVING_HOST: |
50 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST); | 52 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST); |
51 case net::LOAD_STATE_CONNECTING: | 53 case net::LOAD_STATE_CONNECTING: |
52 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING); | 54 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING); |
53 case net::LOAD_STATE_SSL_HANDSHAKE: | 55 case net::LOAD_STATE_SSL_HANDSHAKE: |
54 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE); | 56 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE); |
55 case net::LOAD_STATE_SENDING_REQUEST: | 57 case net::LOAD_STATE_SENDING_REQUEST: |
56 if (tab_contents()->GetUploadSize()) { | 58 if (web_contents()->GetUploadSize()) { |
57 return l10n_util::GetStringFUTF16Int( | 59 return l10n_util::GetStringFUTF16Int( |
58 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS, | 60 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS, |
59 static_cast<int>((100 * tab_contents()->GetUploadPosition()) / | 61 static_cast<int>((100 * web_contents()->GetUploadPosition()) / |
60 tab_contents()->GetUploadSize())); | 62 web_contents()->GetUploadSize())); |
61 } else { | 63 } else { |
62 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST); | 64 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST); |
63 } | 65 } |
64 case net::LOAD_STATE_WAITING_FOR_RESPONSE: | 66 case net::LOAD_STATE_WAITING_FOR_RESPONSE: |
65 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, | 67 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, |
66 tab_contents()->GetLoadStateHost()); | 68 web_contents()->GetLoadStateHost()); |
67 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE | 69 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE |
68 case net::LOAD_STATE_IDLE: | 70 case net::LOAD_STATE_IDLE: |
69 case net::LOAD_STATE_READING_RESPONSE: | 71 case net::LOAD_STATE_READING_RESPONSE: |
70 break; | 72 break; |
71 } | 73 } |
72 | 74 |
73 return string16(); | 75 return string16(); |
74 } | 76 } |
75 | 77 |
76 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
77 // WebContentsObserver overrides | 79 // WebContentsObserver overrides |
78 | 80 |
79 void CoreTabHelper::DidBecomeSelected() { | 81 void CoreTabHelper::DidBecomeSelected() { |
80 WebCacheManager::GetInstance()->ObserveActivity( | 82 WebCacheManager::GetInstance()->ObserveActivity( |
81 tab_contents()->GetRenderProcessHost()->GetID()); | 83 web_contents()->GetRenderProcessHost()->GetID()); |
82 } | 84 } |
OLD | NEW |