Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chrome/browser/ui/tab_contents/core_tab_helper.cc

Issue 8865004: Create CoreTabHelper, move remaining core TCW functionality into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lots of helpers now Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
6
7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/renderer_host/web_cache_manager.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/pref_names.h"
13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/public/browser/notification_service.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 CoreTabHelper::CoreTabHelper(TabContentsWrapper* wrapper)
19 : TabContentsObserver(wrapper->tab_contents()),
20 delegate_(NULL),
21 wrapper_(wrapper) {
22 PrefService* prefs = wrapper_->profile()->GetPrefs();
23 if (prefs) {
24 pref_change_registrar_.Init(prefs);
25 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this);
26 }
27 }
28
29 CoreTabHelper::~CoreTabHelper() {
30 }
31
32 string16 CoreTabHelper::GetDefaultTitle() {
33 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
34 }
35
36 string16 CoreTabHelper::GetStatusText() const {
37 if (!tab_contents()->IsLoading() ||
38 tab_contents()->load_state().state == net::LOAD_STATE_IDLE) {
39 return string16();
40 }
41
42 switch (tab_contents()->load_state().state) {
43 case net::LOAD_STATE_WAITING_FOR_DELEGATE:
44 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE,
45 tab_contents()->load_state().param);
46 case net::LOAD_STATE_WAITING_FOR_CACHE:
47 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
48 case net::LOAD_STATE_WAITING_FOR_APPCACHE:
49 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE);
50 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
51 return
52 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
53 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
54 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
55 case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT:
56 return l10n_util::GetStringUTF16(
57 IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
58 case net::LOAD_STATE_RESOLVING_HOST:
59 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
60 case net::LOAD_STATE_CONNECTING:
61 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
62 case net::LOAD_STATE_SSL_HANDSHAKE:
63 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
64 case net::LOAD_STATE_SENDING_REQUEST:
65 if (tab_contents()->upload_size())
66 return l10n_util::GetStringFUTF16Int(
67 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
68 static_cast<int>((100 * tab_contents()->upload_position()) /
69 tab_contents()->upload_size()));
70 else
71 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
72 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
73 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
74 tab_contents()->load_state_host());
75 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
76 case net::LOAD_STATE_IDLE:
77 case net::LOAD_STATE_READING_RESPONSE:
78 break;
79 }
80
81 return string16();
82 }
83
84 ////////////////////////////////////////////////////////////////////////////////
85 // TabContentsObserver overrides
86
87 void CoreTabHelper::DidBecomeSelected() {
88 WebCacheManager::GetInstance()->ObserveActivity(
89 tab_contents()->GetRenderProcessHost()->GetID());
90 }
91
92 ////////////////////////////////////////////////////////////////////////////////
93 // content::NotificationObserver overrides
94
95 void CoreTabHelper::Observe(int type,
96 const content::NotificationSource& source,
97 const content::NotificationDetails& details) {
98 switch (type) {
99 case chrome::NOTIFICATION_PREF_CHANGED: {
100 std::string* pref_name = content::Details<std::string>(details).ptr();
101 DCHECK(content::Source<PrefService>(source).ptr() ==
102 wrapper_->profile()->GetPrefs());
103 if (*pref_name == prefs::kDefaultZoomLevel) {
104 tab_contents()->render_view_host()->SetZoomLevel(
105 tab_contents()->GetZoomLevel());
106 } else {
107 NOTREACHED() << "unexpected pref change notification" << *pref_name;
108 }
109 break;
110 }
111 default:
112 NOTREACHED();
113 }
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698