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

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

Issue 8865004: Create CoreTabHelper, move remaining core TCW functionality into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "chrome/browser/autocomplete_history_manager.h" 9 #include "chrome/browser/autocomplete_history_manager.h"
10 #include "chrome/browser/autofill/autofill_external_delegate.h" 10 #include "chrome/browser/autofill/autofill_external_delegate.h"
11 #include "chrome/browser/autofill/autofill_manager.h" 11 #include "chrome/browser/autofill/autofill_manager.h"
12 #include "chrome/browser/automation/automation_tab_helper.h" 12 #include "chrome/browser/automation/automation_tab_helper.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
15 #include "chrome/browser/download/download_request_limiter_observer.h" 15 #include "chrome/browser/download/download_request_limiter_observer.h"
16 #include "chrome/browser/extensions/extension_tab_helper.h" 16 #include "chrome/browser/extensions/extension_tab_helper.h"
17 #include "chrome/browser/extensions/extension_webnavigation_api.h" 17 #include "chrome/browser/extensions/extension_webnavigation_api.h"
18 #include "chrome/browser/external_protocol/external_protocol_observer.h" 18 #include "chrome/browser/external_protocol/external_protocol_observer.h"
19 #include "chrome/browser/favicon/favicon_tab_helper.h" 19 #include "chrome/browser/favicon/favicon_tab_helper.h"
20 #include "chrome/browser/google/google_util.h"
21 #include "chrome/browser/history/history_tab_helper.h" 20 #include "chrome/browser/history/history_tab_helper.h"
22 #include "chrome/browser/infobars/infobar_tab_helper.h" 21 #include "chrome/browser/infobars/infobar_tab_helper.h"
23 #include "chrome/browser/omnibox_search_hint.h" 22 #include "chrome/browser/omnibox_search_hint.h"
24 #include "chrome/browser/password_manager/password_manager.h" 23 #include "chrome/browser/password_manager/password_manager.h"
25 #include "chrome/browser/password_manager_delegate_impl.h" 24 #include "chrome/browser/password_manager_delegate_impl.h"
26 #include "chrome/browser/pdf_unsupported_feature.h"
27 #include "chrome/browser/plugin_observer.h" 25 #include "chrome/browser/plugin_observer.h"
28 #include "chrome/browser/prefs/pref_service.h" 26 #include "chrome/browser/prefs/pref_service.h"
29 #include "chrome/browser/prerender/prerender_tab_helper.h" 27 #include "chrome/browser/prerender/prerender_tab_helper.h"
30 #include "chrome/browser/printing/print_preview_message_handler.h" 28 #include "chrome/browser/printing/print_preview_message_handler.h"
31 #include "chrome/browser/printing/print_view_manager.h" 29 #include "chrome/browser/printing/print_view_manager.h"
32 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/renderer_host/web_cache_manager.h"
34 #include "chrome/browser/sessions/restore_tab_helper.h" 30 #include "chrome/browser/sessions/restore_tab_helper.h"
35 #include "chrome/browser/safe_browsing/client_side_detection_host.h" 31 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
36 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" 32 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
37 #include "chrome/browser/tab_contents/thumbnail_generator.h" 33 #include "chrome/browser/tab_contents/thumbnail_generator.h"
38 #include "chrome/browser/translate/translate_tab_helper.h" 34 #include "chrome/browser/translate/translate_tab_helper.h"
39 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 35 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
40 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 36 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
41 #include "chrome/browser/ui/constrained_window_tab_helper.h" 37 #include "chrome/browser/ui/constrained_window_tab_helper.h"
42 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 38 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
43 #include "chrome/browser/ui/intents/web_intent_picker_factory_impl.h" 39 #include "chrome/browser/ui/intents/web_intent_picker_factory_impl.h"
44 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" 40 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
45 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 41 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
46 #include "chrome/browser/ui/sad_tab_observer.h" 42 #include "chrome/browser/ui/sad_tab_observer.h"
47 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 43 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
48 #include "chrome/browser/ui/sync/tab_contents_wrapper_synced_tab_delegate.h" 44 #include "chrome/browser/ui/sync/tab_contents_wrapper_synced_tab_delegate.h"
45 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
49 #include "chrome/common/chrome_notification_types.h" 46 #include "chrome/common/chrome_notification_types.h"
50 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
51 #include "chrome/common/pref_names.h" 48 #include "chrome/common/pref_names.h"
52 #include "chrome/common/render_messages.h" 49 #include "chrome/common/render_messages.h"
53 #include "content/browser/renderer_host/render_view_host.h" 50 #include "content/browser/renderer_host/render_view_host.h"
54 #include "content/public/browser/notification_details.h" 51 #include "content/public/browser/notification_details.h"
55 #include "content/public/browser/notification_service.h" 52 #include "content/public/browser/notification_source.h"
56 #include "grit/generated_resources.h"
57 #include "grit/locale_settings.h"
58 #include "grit/platform_locale_settings.h"
59 #include "ui/base/l10n/l10n_util.h"
60 53
61 namespace { 54 namespace {
62 55
63 static base::LazyInstance<base::PropertyAccessor<TabContentsWrapper*> > 56 static base::LazyInstance<base::PropertyAccessor<TabContentsWrapper*> >
64 g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER; 57 g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER;
65 58
66 // The list of prefs we want to observe.
67 const char* kPrefsToObserve[] = {
68 prefs::kAlternateErrorPagesEnabled,
69 prefs::kDefaultZoomLevel,
70 #if defined (ENABLE_SAFE_BROWSING)
71 prefs::kSafeBrowsingEnabled,
72 #endif
73 };
74
75 const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
76
77 } // namespace 59 } // namespace
78 60
79 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
80 // TabContentsWrapper, public: 62 // TabContentsWrapper, public:
81 63
82 TabContentsWrapper::TabContentsWrapper(TabContents* contents) 64 TabContentsWrapper::TabContentsWrapper(TabContents* contents)
83 : TabContentsObserver(contents), 65 : TabContentsObserver(contents),
84 delegate_(NULL),
85 in_destructor_(false), 66 in_destructor_(false),
86 tab_contents_(contents) { 67 tab_contents_(contents) {
87 DCHECK(contents); 68 DCHECK(contents);
88 DCHECK(!GetCurrentWrapperForContents(contents)); 69 DCHECK(!GetCurrentWrapperForContents(contents));
70
89 // Stash this in the property bag so it can be retrieved without having to 71 // Stash this in the property bag so it can be retrieved without having to
90 // go to a Browser. 72 // go to a Browser.
91 property_accessor()->SetProperty(contents->property_bag(), this); 73 property_accessor()->SetProperty(contents->property_bag(), this);
92 74
93 PrefService* prefs = profile()->GetPrefs();
94 pref_change_registrar_.Init(prefs);
95 if (prefs) {
96 for (int i = 0; i < kPrefsToObserveLength; ++i)
97 pref_change_registrar_.Add(kPrefsToObserve[i], this);
98 }
99
100 // Create the tab helpers. 75 // Create the tab helpers.
101 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); 76 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents));
102 autofill_manager_ = new AutofillManager(this); 77 autofill_manager_ = new AutofillManager(this);
103 if (CommandLine::ForCurrentProcess()->HasSwitch( 78 if (CommandLine::ForCurrentProcess()->HasSwitch(
104 switches::kExternalAutofillPopup)) { 79 switches::kExternalAutofillPopup)) {
105 autofill_external_delegate_.reset( 80 autofill_external_delegate_.reset(
106 AutofillExternalDelegate::Create(this, autofill_manager_.get())); 81 AutofillExternalDelegate::Create(this, autofill_manager_.get()));
107 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get()); 82 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get());
108 autocomplete_history_manager_->SetExternalDelegate( 83 autocomplete_history_manager_->SetExternalDelegate(
109 autofill_external_delegate_.get()); 84 autofill_external_delegate_.get());
110 } 85 }
111 automation_tab_helper_.reset(new AutomationTabHelper(contents)); 86 automation_tab_helper_.reset(new AutomationTabHelper(contents));
112 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); 87 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this));
113 bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); 88 bookmark_tab_helper_.reset(new BookmarkTabHelper(this));
114 constrained_window_tab_helper_.reset(new ConstrainedWindowTabHelper(this)); 89 constrained_window_tab_helper_.reset(new ConstrainedWindowTabHelper(this));
90 core_tab_helper_.reset(new CoreTabHelper(this));
115 extension_tab_helper_.reset(new ExtensionTabHelper(this)); 91 extension_tab_helper_.reset(new ExtensionTabHelper(this));
116 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); 92 favicon_tab_helper_.reset(new FaviconTabHelper(contents));
117 find_tab_helper_.reset(new FindTabHelper(contents)); 93 find_tab_helper_.reset(new FindTabHelper(contents));
118 history_tab_helper_.reset(new HistoryTabHelper(contents)); 94 history_tab_helper_.reset(new HistoryTabHelper(contents));
119 infobar_tab_helper_.reset(new InfoBarTabHelper(contents)); 95 infobar_tab_helper_.reset(new InfoBarTabHelper(contents));
120 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); 96 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this));
121 password_manager_.reset( 97 password_manager_.reset(
122 new PasswordManager(contents, password_manager_delegate_.get())); 98 new PasswordManager(contents, password_manager_delegate_.get()));
123 prefs_tab_helper_.reset(new PrefsTabHelper(this)); 99 prefs_tab_helper_.reset(new PrefsTabHelper(this));
124 prerender_tab_helper_.reset(new prerender::PrerenderTabHelper(this)); 100 prerender_tab_helper_.reset(new prerender::PrerenderTabHelper(this));
(...skipping 26 matching lines...) Expand all
151 // Start the in-browser thumbnailing if the feature is enabled. 127 // Start the in-browser thumbnailing if the feature is enabled.
152 if (switches::IsInBrowserThumbnailingEnabled()) { 128 if (switches::IsInBrowserThumbnailingEnabled()) {
153 thumbnail_generation_observer_.reset(new ThumbnailGenerator); 129 thumbnail_generation_observer_.reset(new ThumbnailGenerator);
154 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get()); 130 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get());
155 } 131 }
156 132
157 // Set-up the showing of the omnibox search infobar if applicable. 133 // Set-up the showing of the omnibox search infobar if applicable.
158 if (OmniboxSearchHint::IsEnabled(profile())) 134 if (OmniboxSearchHint::IsEnabled(profile()))
159 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); 135 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
160 136
161 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 137 #if defined(ENABLE_SAFE_BROWSING)
162 content::NotificationService::AllSources()); 138 PrefService* prefs = profile()->GetPrefs();
139 pref_change_registrar_.Init(prefs);
140 if (prefs) {
141 pref_change_registrar_.Add(prefs::kSafeBrowsingEnabled, this);
142 }
143 #endif // ENABLE_SAFE_BROWSING
163 } 144 }
164 145
165 TabContentsWrapper::~TabContentsWrapper() { 146 TabContentsWrapper::~TabContentsWrapper() {
166 in_destructor_ = true; 147 in_destructor_ = true;
167 148
168 // Need to tear down infobars before the TabContents goes away. 149 // Need to tear down infobars before the TabContents goes away.
150 // TODO(avi): Can we get this handled by the tab helper itself?
169 infobar_tab_helper_.reset(); 151 infobar_tab_helper_.reset();
170 } 152 }
171 153
172 base::PropertyAccessor<TabContentsWrapper*>* 154 base::PropertyAccessor<TabContentsWrapper*>*
173 TabContentsWrapper::property_accessor() { 155 TabContentsWrapper::property_accessor() {
174 return g_tab_contents_wrapper_property_accessor.Pointer(); 156 return g_tab_contents_wrapper_property_accessor.Pointer();
175 } 157 }
176 158
177 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) {
178 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled,
179 true,
180 PrefService::SYNCABLE_PREF);
181 }
182
183 string16 TabContentsWrapper::GetDefaultTitle() {
184 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
185 }
186
187 string16 TabContentsWrapper::GetStatusText() const {
188 if (!tab_contents()->IsLoading() ||
189 tab_contents()->load_state().state == net::LOAD_STATE_IDLE) {
190 return string16();
191 }
192
193 switch (tab_contents()->load_state().state) {
194 case net::LOAD_STATE_WAITING_FOR_DELEGATE:
195 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE,
196 tab_contents()->load_state().param);
197 case net::LOAD_STATE_WAITING_FOR_CACHE:
198 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
199 case net::LOAD_STATE_WAITING_FOR_APPCACHE:
200 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE);
201 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
202 return
203 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
204 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
205 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
206 case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT:
207 return l10n_util::GetStringUTF16(
208 IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
209 case net::LOAD_STATE_RESOLVING_HOST:
210 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
211 case net::LOAD_STATE_CONNECTING:
212 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
213 case net::LOAD_STATE_SSL_HANDSHAKE:
214 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
215 case net::LOAD_STATE_SENDING_REQUEST:
216 if (tab_contents()->upload_size())
217 return l10n_util::GetStringFUTF16Int(
218 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
219 static_cast<int>((100 * tab_contents()->upload_position()) /
220 tab_contents()->upload_size()));
221 else
222 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
223 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
224 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
225 tab_contents()->load_state_host());
226 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
227 case net::LOAD_STATE_IDLE:
228 case net::LOAD_STATE_READING_RESPONSE:
229 break;
230 }
231
232 return string16();
233 }
234
235 TabContentsWrapper* TabContentsWrapper::Clone() { 159 TabContentsWrapper* TabContentsWrapper::Clone() {
236 TabContents* new_contents = tab_contents()->Clone(); 160 TabContents* new_contents = tab_contents()->Clone();
237 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); 161 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents);
238 162
163 // TODO(avi): Can we generalize this so that knowledge of the functionings of
164 // the tab helpers isn't required here?
239 new_wrapper->extension_tab_helper()->CopyStateFrom( 165 new_wrapper->extension_tab_helper()->CopyStateFrom(
240 *extension_tab_helper_.get()); 166 *extension_tab_helper_.get());
241 return new_wrapper; 167 return new_wrapper;
242 } 168 }
243 169
244 void TabContentsWrapper::CaptureSnapshot() {
245 Send(new ChromeViewMsg_CaptureSnapshot(routing_id()));
246 }
247
248 // static 170 // static
249 TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents( 171 TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents(
250 TabContents* contents) { 172 TabContents* contents) {
251 TabContentsWrapper** wrapper = 173 TabContentsWrapper** wrapper =
252 property_accessor()->GetProperty(contents->property_bag()); 174 property_accessor()->GetProperty(contents->property_bag());
253 175
254 return wrapper ? *wrapper : NULL; 176 return wrapper ? *wrapper : NULL;
255 } 177 }
256 178
257 // static 179 // static
258 const TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents( 180 const TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents(
259 const TabContents* contents) { 181 const TabContents* contents) {
260 TabContentsWrapper* const* wrapper = 182 TabContentsWrapper* const* wrapper =
261 property_accessor()->GetProperty(contents->property_bag()); 183 property_accessor()->GetProperty(contents->property_bag());
262 184
263 return wrapper ? *wrapper : NULL; 185 return wrapper ? *wrapper : NULL;
264 } 186 }
265 187
266 Profile* TabContentsWrapper::profile() const { 188 Profile* TabContentsWrapper::profile() const {
267 return Profile::FromBrowserContext(tab_contents()->browser_context()); 189 return Profile::FromBrowserContext(tab_contents()->browser_context());
268 } 190 }
269 191
270 //////////////////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////////////////////
271 // TabContentsWrapper implementation: 193 // TabContentsObserver overrides
272
273 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) {
274 UpdateAlternateErrorPageURL(render_view_host);
275 }
276
277 void TabContentsWrapper::DidBecomeSelected() {
278 WebCacheManager::GetInstance()->ObserveActivity(
279 tab_contents()->GetRenderProcessHost()->GetID());
280 }
281
282 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) {
283 bool handled = true;
284 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message)
285 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot)
286 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
287 OnPDFHasUnsupportedFeature)
288 IPC_MESSAGE_UNHANDLED(handled = false)
289 IPC_END_MESSAGE_MAP()
290 return handled;
291 }
292 194
293 void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) { 195 void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) {
294 // Destruction of the TabContents should only be done by us from our 196 // Destruction of the TabContents should only be done by us from our
295 // destructor. Otherwise it's very likely we (or one of the helpers we own) 197 // destructor. Otherwise it's very likely we (or one of the helpers we own)
296 // will attempt to access the TabContents and we'll crash. 198 // will attempt to access the TabContents and we'll crash.
297 DCHECK(in_destructor_); 199 DCHECK(in_destructor_);
298 } 200 }
299 201
202 ////////////////////////////////////////////////////////////////////////////////
203 // content::NotificationObserver overrides
204
300 void TabContentsWrapper::Observe(int type, 205 void TabContentsWrapper::Observe(int type,
301 const content::NotificationSource& source, 206 const content::NotificationSource& source,
302 const content::NotificationDetails& details) { 207 const content::NotificationDetails& details) {
303 switch (type) { 208 switch (type) {
304 case chrome::NOTIFICATION_GOOGLE_URL_UPDATED:
305 UpdateAlternateErrorPageURL(render_view_host());
306 break;
307 case chrome::NOTIFICATION_PREF_CHANGED: { 209 case chrome::NOTIFICATION_PREF_CHANGED: {
308 std::string* pref_name_in = content::Details<std::string>(details).ptr(); 210 std::string* pref_name = content::Details<std::string>(details).ptr();
309 DCHECK(content::Source<PrefService>(source).ptr() == 211 DCHECK(content::Source<PrefService>(source).ptr() ==
310 profile()->GetPrefs()); 212 profile()->GetPrefs());
311 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { 213 if (*pref_name == prefs::kSafeBrowsingEnabled) {
312 UpdateAlternateErrorPageURL(render_view_host());
313 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
314 tab_contents()->render_view_host()->SetZoomLevel(
315 tab_contents()->GetZoomLevel());
316 } else if (*pref_name_in == prefs::kSafeBrowsingEnabled) {
317 UpdateSafebrowsingDetectionHost(); 214 UpdateSafebrowsingDetectionHost();
318 } else { 215 } else {
319 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; 216 NOTREACHED() << "unexpected pref change notification" << *pref_name;
320 } 217 }
321 break; 218 break;
322 } 219 }
323 default: 220 default:
324 NOTREACHED(); 221 NOTREACHED();
325 } 222 }
326 } 223 }
327 224
328 //////////////////////////////////////////////////////////////////////////////// 225 ////////////////////////////////////////////////////////////////////////////////
329 // Internal helpers 226 // Internal helpers
330 227
331 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) {
332 content::NotificationService::current()->Notify(
333 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
334 content::Source<TabContentsWrapper>(this),
335 content::Details<const SkBitmap>(&bitmap));
336 }
337
338 void TabContentsWrapper::OnPDFHasUnsupportedFeature() {
339 PDFHasUnsupportedFeature(this);
340 }
341
342 GURL TabContentsWrapper::GetAlternateErrorPageURL() const {
343 GURL url;
344 // Disable alternate error pages when in Incognito mode.
345 if (profile()->IsOffTheRecord())
346 return url;
347
348 PrefService* prefs = profile()->GetPrefs();
349 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
350 url = google_util::AppendGoogleLocaleParam(
351 GURL(google_util::kLinkDoctorBaseURL));
352 url = google_util::AppendGoogleTLDParam(url);
353 }
354 return url;
355 }
356
357 void TabContentsWrapper::UpdateAlternateErrorPageURL(RenderViewHost* rvh) {
358 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL());
359 }
360
361 void TabContentsWrapper::UpdateSafebrowsingDetectionHost() { 228 void TabContentsWrapper::UpdateSafebrowsingDetectionHost() {
362 #if defined(ENABLE_SAFE_BROWSING) 229 #if defined(ENABLE_SAFE_BROWSING)
363 PrefService* prefs = profile()->GetPrefs(); 230 PrefService* prefs = profile()->GetPrefs();
364 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); 231 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
365 if (safe_browsing && 232 if (safe_browsing &&
366 g_browser_process->safe_browsing_detection_service()) { 233 g_browser_process->safe_browsing_detection_service()) {
367 if (!safebrowsing_detection_host_.get()) { 234 if (!safebrowsing_detection_host_.get()) {
368 safebrowsing_detection_host_.reset( 235 safebrowsing_detection_host_.reset(
369 safe_browsing::ClientSideDetectionHost::Create(tab_contents())); 236 safe_browsing::ClientSideDetectionHost::Create(tab_contents()));
370 } 237 }
371 } else { 238 } else {
372 safebrowsing_detection_host_.reset(); 239 safebrowsing_detection_host_.reset();
373 } 240 }
374 render_view_host()->Send( 241 tab_contents()->render_view_host()->Send(
375 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(), 242 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(),
376 safe_browsing)); 243 safe_browsing));
377 #endif 244 #endif
378 } 245 }
379
380 void TabContentsWrapper::ExitFullscreenMode() {
381 if (tab_contents() && render_view_host())
382 tab_contents()->render_view_host()->ExitFullscreen();
383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698