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/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_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
11 #include "chrome/browser/automation/automation_tab_helper.h" | 11 #include "chrome/browser/automation/automation_tab_helper.h" |
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
13 #include "chrome/browser/custom_handlers/protocol_handler.h" | 13 #include "chrome/browser/custom_handlers/protocol_handler.h" |
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
15 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h" | 15 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.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/favicon/favicon_tab_helper.h" | 18 #include "chrome/browser/favicon/favicon_tab_helper.h" |
19 #include "chrome/browser/file_select_helper.h" | 19 #include "chrome/browser/file_select_helper.h" |
20 #include "chrome/browser/google/google_util.h" | |
20 #include "chrome/browser/history/history_tab_helper.h" | 21 #include "chrome/browser/history/history_tab_helper.h" |
21 #include "chrome/browser/omnibox_search_hint.h" | 22 #include "chrome/browser/omnibox_search_hint.h" |
22 #include "chrome/browser/password_manager/password_manager.h" | 23 #include "chrome/browser/password_manager/password_manager.h" |
23 #include "chrome/browser/password_manager_delegate_impl.h" | 24 #include "chrome/browser/password_manager_delegate_impl.h" |
24 #include "chrome/browser/pdf_unsupported_feature.h" | 25 #include "chrome/browser/pdf_unsupported_feature.h" |
25 #include "chrome/browser/plugin_observer.h" | 26 #include "chrome/browser/plugin_observer.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/prerender/prerender_observer.h" | 28 #include "chrome/browser/prerender/prerender_observer.h" |
28 #include "chrome/browser/printing/print_preview_message_handler.h" | 29 #include "chrome/browser/printing/print_preview_message_handler.h" |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/renderer_preferences_util.h" | |
30 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 32 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
31 #include "chrome/browser/tab_contents/infobar_delegate.h" | 33 #include "chrome/browser/tab_contents/infobar_delegate.h" |
32 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 34 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
33 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" | 35 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
34 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 36 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
35 #include "chrome/browser/translate/translate_tab_helper.h" | 37 #include "chrome/browser/translate/translate_tab_helper.h" |
36 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 38 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
37 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 39 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
38 #include "chrome/browser/ui/download/download_tab_helper.h" | 40 #include "chrome/browser/ui/download/download_tab_helper.h" |
39 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 41 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
40 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 42 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
41 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 43 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
42 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
43 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/render_messages.h" | 46 #include "chrome/common/render_messages.h" |
47 #include "content/browser/renderer_host/render_view_host.h" | |
45 #include "content/browser/tab_contents/tab_contents.h" | 48 #include "content/browser/tab_contents/tab_contents.h" |
46 #include "content/common/notification_service.h" | 49 #include "content/common/notification_service.h" |
47 #include "content/common/view_messages.h" | 50 #include "content/common/view_messages.h" |
48 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
49 #include "grit/locale_settings.h" | 52 #include "grit/locale_settings.h" |
50 #include "grit/platform_locale_settings.h" | 53 #include "grit/platform_locale_settings.h" |
51 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
52 #include "webkit/glue/webpreferences.h" | 55 #include "webkit/glue/webpreferences.h" |
53 | 56 |
57 namespace { | |
58 | |
54 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > | 59 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > |
55 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); | 60 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); |
56 | 61 |
62 // The list of prefs we want to observe. | |
63 const char* kPrefsToObserve[] = { | |
64 prefs::kAlternateErrorPagesEnabled, | |
65 prefs::kDefaultCharset, | |
66 prefs::kDefaultZoomLevel, | |
67 prefs::kEnableReferrers | |
68 }; | |
Avi (use Gerrit)
2011/05/25 02:34:34
This is a significantly shorter list than the one
jam
2011/05/25 16:00:59
I don't know why the old code was watching a long
| |
69 | |
70 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); | |
71 | |
72 } | |
73 | |
57 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
58 // TabContentsWrapper, public: | 75 // TabContentsWrapper, public: |
59 | 76 |
60 TabContentsWrapper::TabContentsWrapper(TabContents* contents) | 77 TabContentsWrapper::TabContentsWrapper(TabContents* contents) |
61 : TabContentsObserver(contents), | 78 : TabContentsObserver(contents), |
62 delegate_(NULL), | 79 delegate_(NULL), |
63 infobars_enabled_(true), | 80 infobars_enabled_(true), |
64 tab_contents_(contents) { | 81 tab_contents_(contents) { |
65 DCHECK(contents); | 82 DCHECK(contents); |
66 DCHECK(!GetCurrentWrapperForContents(contents)); | 83 DCHECK(!GetCurrentWrapperForContents(contents)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 // Start the in-browser thumbnailing if the feature is enabled. | 117 // Start the in-browser thumbnailing if the feature is enabled. |
101 if (CommandLine::ForCurrentProcess()->HasSwitch( | 118 if (CommandLine::ForCurrentProcess()->HasSwitch( |
102 switches::kEnableInBrowserThumbnailing)) { | 119 switches::kEnableInBrowserThumbnailing)) { |
103 thumbnail_generation_observer_.reset(new ThumbnailGenerator); | 120 thumbnail_generation_observer_.reset(new ThumbnailGenerator); |
104 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get()); | 121 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get()); |
105 } | 122 } |
106 | 123 |
107 // Set-up the showing of the omnibox search infobar if applicable. | 124 // Set-up the showing of the omnibox search infobar if applicable. |
108 if (OmniboxSearchHint::IsEnabled(contents->profile())) | 125 if (OmniboxSearchHint::IsEnabled(contents->profile())) |
109 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); | 126 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); |
127 | |
128 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED, | |
129 NotificationService::AllSources()); | |
130 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED, | |
131 NotificationService::AllSources()); | |
132 #if defined(OS_LINUX) | |
133 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
134 NotificationService::AllSources()); | |
135 #endif | |
136 | |
137 // Register for notifications about all interested prefs change. | |
138 PrefService* prefs = profile()->GetPrefs(); | |
139 pref_change_registrar_.Init(prefs); | |
140 if (prefs) { | |
141 for (int i = 0; i < kPrefsToObserveLength; ++i) | |
142 pref_change_registrar_.Add(kPrefsToObserve[i], this); | |
143 } | |
144 | |
145 renderer_preferences_util::UpdateFromSystemSettings( | |
146 tab_contents()->GetMutableRendererPrefs(), profile()); | |
110 } | 147 } |
111 | 148 |
112 TabContentsWrapper::~TabContentsWrapper() { | 149 TabContentsWrapper::~TabContentsWrapper() { |
113 // Notify any lasting InfobarDelegates that have not yet been removed that | 150 // Notify any lasting InfobarDelegates that have not yet been removed that |
114 // whatever infobar they were handling in this TabContents has closed, | 151 // whatever infobar they were handling in this TabContents has closed, |
115 // because the TabContents is going away entirely. | 152 // because the TabContents is going away entirely. |
116 // This must happen after the TAB_CONTENTS_DESTROYED notification as the | 153 // This must happen after the TAB_CONTENTS_DESTROYED notification as the |
117 // notification may trigger infobars calls that access their delegate. (and | 154 // notification may trigger infobars calls that access their delegate. (and |
118 // some implementations of InfoBarDelegate do delete themselves on | 155 // some implementations of InfoBarDelegate do delete themselves on |
119 // InfoBarClosed()). | 156 // InfoBarClosed()). |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 TabContents* contents) { | 318 TabContents* contents) { |
282 TabContentsWrapper** wrapper = | 319 TabContentsWrapper** wrapper = |
283 property_accessor()->GetProperty(contents->property_bag()); | 320 property_accessor()->GetProperty(contents->property_bag()); |
284 | 321 |
285 return wrapper ? *wrapper : NULL; | 322 return wrapper ? *wrapper : NULL; |
286 } | 323 } |
287 | 324 |
288 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
289 // TabContentsWrapper implementation: | 326 // TabContentsWrapper implementation: |
290 | 327 |
328 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { | |
329 UpdateAlternateErrorPageURL(render_view_host); | |
330 } | |
331 | |
291 void TabContentsWrapper::RenderViewGone() { | 332 void TabContentsWrapper::RenderViewGone() { |
292 // Remove all infobars. | 333 // Remove all infobars. |
293 while (!infobar_delegates_.empty()) | 334 while (!infobar_delegates_.empty()) |
294 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); | 335 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); |
295 } | 336 } |
296 | 337 |
297 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { | 338 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { |
298 bool handled = true; | 339 bool handled = true; |
299 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) | 340 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) |
300 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) | 341 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) |
(...skipping 22 matching lines...) Expand all Loading... | |
323 // use iterators, as the RemoveInfoBar() call synchronously modifies our | 364 // use iterators, as the RemoveInfoBar() call synchronously modifies our |
324 // delegate list. | 365 // delegate list. |
325 for (size_t i = infobar_delegates_.size(); i > 0; --i) { | 366 for (size_t i = infobar_delegates_.size(); i > 0; --i) { |
326 InfoBarDelegate* delegate = infobar_delegates_[i - 1]; | 367 InfoBarDelegate* delegate = infobar_delegates_[i - 1]; |
327 if (delegate->ShouldExpire(committed_details)) | 368 if (delegate->ShouldExpire(committed_details)) |
328 RemoveInfoBar(delegate); | 369 RemoveInfoBar(delegate); |
329 } | 370 } |
330 | 371 |
331 break; | 372 break; |
332 } | 373 } |
374 case NotificationType::GOOGLE_URL_UPDATED: | |
375 UpdateAlternateErrorPageURL(render_view_host()); | |
376 break; | |
377 case NotificationType::USER_STYLE_SHEET_UPDATED: | |
378 UpdateWebPreferences(); | |
379 break; | |
380 #if defined(OS_LINUX) | |
381 case NotificationType::BROWSER_THEME_CHANGED: { | |
382 UpdateRendererPreferences(); | |
383 break; | |
384 } | |
385 #endif | |
386 case NotificationType::PREF_CHANGED: { | |
387 std::string* pref_name_in = Details<std::string>(details).ptr(); | |
388 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); | |
389 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { | |
390 UpdateAlternateErrorPageURL(render_view_host()); | |
391 } else if ((*pref_name_in == prefs::kDefaultCharset) || | |
392 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { | |
393 UpdateWebPreferences(); | |
394 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | |
395 Send(new ViewMsg_SetZoomLevel( | |
396 routing_id(), tab_contents()->GetZoomLevel())); | |
397 } else if (*pref_name_in == prefs::kEnableReferrers) { | |
398 UpdateRendererPreferences(); | |
399 } else { | |
400 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; | |
401 } | |
402 break; | |
403 } | |
333 default: | 404 default: |
334 NOTREACHED(); | 405 NOTREACHED(); |
335 } | 406 } |
336 } | 407 } |
337 | 408 |
338 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { | 409 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { |
339 if (!infobars_enabled_) { | 410 if (!infobars_enabled_) { |
340 delegate->InfoBarClosed(); | 411 delegate->InfoBarClosed(); |
341 return; | 412 return; |
342 } | 413 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { | 522 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { |
452 NotificationService::current()->Notify( | 523 NotificationService::current()->Notify( |
453 NotificationType::TAB_SNAPSHOT_TAKEN, | 524 NotificationType::TAB_SNAPSHOT_TAKEN, |
454 Source<TabContentsWrapper>(this), | 525 Source<TabContentsWrapper>(this), |
455 Details<const SkBitmap>(&bitmap)); | 526 Details<const SkBitmap>(&bitmap)); |
456 } | 527 } |
457 | 528 |
458 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { | 529 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { |
459 PDFHasUnsupportedFeature(this); | 530 PDFHasUnsupportedFeature(this); |
460 } | 531 } |
532 | |
533 GURL TabContentsWrapper::GetAlternateErrorPageURL() const { | |
534 GURL url; | |
535 // Disable alternate error pages when in OffTheRecord/Incognito mode. | |
Avi (use Gerrit)
2011/05/25 02:34:34
Ok to just say "incognito". References to OTR are
jam
2011/05/25 16:00:59
Done.
| |
536 if (profile()->IsOffTheRecord()) | |
537 return url; | |
538 | |
539 PrefService* prefs = profile()->GetPrefs(); | |
540 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { | |
541 url = google_util::AppendGoogleLocaleParam( | |
542 GURL(google_util::kLinkDoctorBaseURL)); | |
543 url = google_util::AppendGoogleTLDParam(url); | |
544 } | |
545 return url; | |
546 } | |
547 | |
548 void TabContentsWrapper::UpdateAlternateErrorPageURL(RenderViewHost* rvh) { | |
549 rvh->Send(new ViewMsg_SetAltErrorPageURL( | |
550 rvh->routing_id(), GetAlternateErrorPageURL())); | |
551 } | |
552 | |
553 void TabContentsWrapper::UpdateWebPreferences() { | |
554 RenderViewHostDelegate* rvhd = tab_contents(); | |
555 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); | |
556 } | |
557 | |
558 void TabContentsWrapper::UpdateRendererPreferences() { | |
559 renderer_preferences_util::UpdateFromSystemSettings( | |
560 tab_contents()->GetMutableRendererPrefs(), profile()); | |
561 render_view_host()->SyncRendererPrefs(); | |
562 } | |
OLD | NEW |