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

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

Issue 6537015: Start moving core pieces of Chrome multi-process code to src\content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months 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
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/tab_contents_wrapper.h" 5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/password_manager/password_manager.h" 9 #include "chrome/browser/password_manager/password_manager.h"
10 #include "chrome/browser/password_manager_delegate_impl.h" 10 #include "chrome/browser/password_manager_delegate_impl.h"
11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/infobar_delegate.h"
13 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 14 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
14 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 15 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
16 #include "chrome/common/notification_service.h" 17 #include "chrome/common/notification_service.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/render_messages.h"
20 #include "content/browser/tab_contents/tab_contents.h"
21 #include "grit/locale_settings.h"
22 #include "grit/generated_resources.h"
23 #include "grit/platform_locale_settings.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "webkit/glue/webpreferences.h"
17 26
18 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > 27 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> >
19 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); 28 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED);
20 29
21 //////////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////////
22 // TabContentsWrapper, public: 31 // TabContentsWrapper, public:
23 32
24 TabContentsWrapper::TabContentsWrapper(TabContents* contents) 33 TabContentsWrapper::TabContentsWrapper(TabContents* contents)
25 : TabContentsObserver(contents), 34 : TabContentsObserver(contents),
26 delegate_(NULL), 35 delegate_(NULL),
(...skipping 20 matching lines...) Expand all
47 56
48 TabContentsWrapper::~TabContentsWrapper() { 57 TabContentsWrapper::~TabContentsWrapper() {
49 // We don't want any notifications while we're running our destructor. 58 // We don't want any notifications while we're running our destructor.
50 registrar_.RemoveAll(); 59 registrar_.RemoveAll();
51 } 60 }
52 61
53 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { 62 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() {
54 return g_tab_contents_wrapper_property_accessor.Pointer(); 63 return g_tab_contents_wrapper_property_accessor.Pointer();
55 } 64 }
56 65
66 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) {
67 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
68
69 WebPreferences pref_defaults;
70 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
71 pref_defaults.javascript_enabled);
72 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
73 pref_defaults.web_security_enabled);
74 prefs->RegisterBooleanPref(
75 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
76 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
77 pref_defaults.loads_images_automatically);
78 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
79 pref_defaults.plugins_enabled);
80 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
81 pref_defaults.dom_paste_enabled);
82 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
83 pref_defaults.shrinks_standalone_images_to_fit);
84 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
85 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
86 pref_defaults.text_areas_are_resizable);
87 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
88 pref_defaults.java_enabled);
89 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
90 pref_defaults.tabs_to_links);
91
92 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
93 IDS_ACCEPT_LANGUAGES);
94 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
95 IDS_DEFAULT_ENCODING);
96 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
97 IDS_STANDARD_FONT_IS_SERIF);
98 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
99 IDS_FIXED_FONT_FAMILY);
100 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
101 IDS_SERIF_FONT_FAMILY);
102 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
103 IDS_SANS_SERIF_FONT_FAMILY);
104 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
105 IDS_CURSIVE_FONT_FAMILY);
106 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
107 IDS_FANTASY_FONT_FAMILY);
108 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
109 IDS_DEFAULT_FONT_SIZE);
110 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
111 IDS_DEFAULT_FIXED_FONT_SIZE);
112 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
113 IDS_MINIMUM_FONT_SIZE);
114 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
115 IDS_MINIMUM_LOGICAL_FONT_SIZE);
116 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
117 IDS_USES_UNIVERSAL_DETECTOR);
118 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
119 IDS_STATIC_ENCODING_LIST);
120 }
121
122 string16 TabContentsWrapper::GetDefaultTitle() {
123 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
124 }
125
126 string16 TabContentsWrapper::GetStatusText() const {
127 if (!tab_contents()->is_loading() ||
128 tab_contents()->load_state() == net::LOAD_STATE_IDLE) {
129 return string16();
130 }
131
132 switch (tab_contents()->load_state()) {
133 case net::LOAD_STATE_WAITING_FOR_CACHE:
134 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
135 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
136 return
137 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
138 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
139 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
140 case net::LOAD_STATE_RESOLVING_HOST:
141 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
142 case net::LOAD_STATE_CONNECTING:
143 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
144 case net::LOAD_STATE_SSL_HANDSHAKE:
145 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
146 case net::LOAD_STATE_SENDING_REQUEST:
147 if (tab_contents()->upload_size())
148 return l10n_util::GetStringFUTF16Int(
149 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
150 static_cast<int>((100 * tab_contents()->upload_position()) /
151 tab_contents()->upload_size()));
152 else
153 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
154 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
155 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
156 tab_contents()->load_state_host());
157 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
158 case net::LOAD_STATE_IDLE:
159 case net::LOAD_STATE_READING_RESPONSE:
160 break;
161 }
162
163 return string16();
164 }
165
57 TabContentsWrapper* TabContentsWrapper::Clone() { 166 TabContentsWrapper* TabContentsWrapper::Clone() {
58 TabContents* new_contents = tab_contents()->Clone(); 167 TabContents* new_contents = tab_contents()->Clone();
59 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); 168 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents);
60 return new_wrapper; 169 return new_wrapper;
61 } 170 }
62 171
63 TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents( 172 TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents(
64 TabContents* contents) { 173 TabContents* contents) {
65 TabContentsWrapper** wrapper = 174 TabContentsWrapper** wrapper =
66 property_accessor()->GetProperty(contents->property_bag()); 175 property_accessor()->GetProperty(contents->property_bag());
67 176
68 return wrapper ? *wrapper : NULL; 177 return wrapper ? *wrapper : NULL;
69 } 178 }
70 179
71 //////////////////////////////////////////////////////////////////////////////// 180 ////////////////////////////////////////////////////////////////////////////////
72 // TabContentsWrapper, TabContentsObserver implementation: 181 // TabContentsWrapper, TabContentsObserver implementation:
73 182
74 void TabContentsWrapper::DidNavigateMainFramePostCommit( 183 void TabContentsWrapper::DidNavigateMainFramePostCommit(
75 const NavigationController::LoadCommittedDetails& /*details*/, 184 const NavigationController::LoadCommittedDetails& /*details*/,
76 const ViewHostMsg_FrameNavigate_Params& /*params*/) { 185 const ViewHostMsg_FrameNavigate_Params& /*params*/) {
77 UpdateStarredStateForCurrentURL(); 186 UpdateStarredStateForCurrentURL();
78 } 187 }
79 188
189 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) {
190 bool handled = true;
191 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message)
192 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
193 IPC_MESSAGE_UNHANDLED(handled = false)
194 IPC_END_MESSAGE_MAP()
195 return handled;
196 }
197
80 //////////////////////////////////////////////////////////////////////////////// 198 ////////////////////////////////////////////////////////////////////////////////
81 // TabContentsWrapper, NotificationObserver implementation: 199 // TabContentsWrapper, NotificationObserver implementation:
82 200
83 void TabContentsWrapper::Observe(NotificationType type, 201 void TabContentsWrapper::Observe(NotificationType type,
84 const NotificationSource& source, 202 const NotificationSource& source,
85 const NotificationDetails& details) { 203 const NotificationDetails& details) {
86 switch (type.value) { 204 switch (type.value) {
87 case NotificationType::BOOKMARK_MODEL_LOADED: 205 case NotificationType::BOOKMARK_MODEL_LOADED:
88 // BookmarkModel finished loading, fall through to update starred state. 206 // BookmarkModel finished loading, fall through to update starred state.
89 case NotificationType::URLS_STARRED: { 207 case NotificationType::URLS_STARRED: {
90 // Somewhere, a URL has been starred. 208 // Somewhere, a URL has been starred.
91 // Ignore notifications for profiles other than our current one. 209 // Ignore notifications for profiles other than our current one.
92 Profile* source_profile = Source<Profile>(source).ptr(); 210 Profile* source_profile = Source<Profile>(source).ptr();
93 if (!source_profile || !source_profile->IsSameProfile(profile())) 211 if (!source_profile || !source_profile->IsSameProfile(profile()))
94 return; 212 return;
95 213
96 UpdateStarredStateForCurrentURL(); 214 UpdateStarredStateForCurrentURL();
97 break; 215 break;
98 } 216 }
99 217
100 default: 218 default:
101 NOTREACHED(); 219 NOTREACHED();
102 } 220 }
103 } 221 }
104 222
105 //////////////////////////////////////////////////////////////////////////////// 223 ////////////////////////////////////////////////////////////////////////////////
106 // Internal helpers 224 // Internal helpers
107 225
226 void TabContentsWrapper::OnJSOutOfMemory() {
227 tab_contents()->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(),
228 NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true));
229 }
230
108 void TabContentsWrapper::UpdateStarredStateForCurrentURL() { 231 void TabContentsWrapper::UpdateStarredStateForCurrentURL() {
109 BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel(); 232 BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel();
110 const bool old_state = is_starred_; 233 const bool old_state = is_starred_;
111 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL())); 234 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL()));
112 235
113 if (is_starred_ != old_state && delegate()) 236 if (is_starred_ != old_state && delegate())
114 delegate()->URLStarredChanged(this, is_starred_); 237 delegate()->URLStarredChanged(this, is_starred_);
115 } 238 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tab_contents/tab_contents_wrapper.h ('k') | chrome/browser/ui/views/hung_renderer_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698