[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 5 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 3952656 | 2011-02-05 03:41:51 | [diff] [blame] | 6 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 7 | #include <cmath> |
| 8 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 9 | #include "base/auto_reset.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 10 | #include "base/metrics/histogram.h" |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 11 | #include "base/metrics/stats_counters.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 13 | #include "base/string_util.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 14 | #include "base/time.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 15 | #include "base/utf_string_conversions.h" |
[email protected] | 6db0def9 | 2010-03-02 19:55:45 | [diff] [blame] | 16 | #include "chrome/browser/autocomplete_history_manager.h" |
[email protected] | 21674df | 2009-10-28 19:51:21 | [diff] [blame] | 17 | #include "chrome/browser/autofill/autofill_manager.h" |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 18 | #include "chrome/browser/blocked_content_container.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 19 | #include "chrome/browser/browser_process.h" |
[email protected] | cf68b09 | 2010-01-15 20:05:55 | [diff] [blame] | 20 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 21 | #include "chrome/browser/character_encoding.h" |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 22 | #include "chrome/browser/child_process_security_policy.h" |
[email protected] | 5f24f21 | 2010-12-02 14:47:45 | [diff] [blame] | 23 | #include "chrome/browser/content_settings/content_settings_details.h" |
[email protected] | 9d01a6a | 2010-11-30 12:03:33 | [diff] [blame] | 24 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 25 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | c8f7494 | 2010-09-03 10:04:14 | [diff] [blame] | 26 | #include "chrome/browser/defaults.h" |
[email protected] | 74da5bd | 2011-01-27 22:03:27 | [diff] [blame] | 27 | #include "chrome/browser/desktop_notification_handler.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 28 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 29 | #include "chrome/browser/dom_ui/dom_ui.h" |
[email protected] | bcef0dc0 | 2009-02-28 00:35:02 | [diff] [blame] | 30 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 31 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 4129132 | 2010-07-15 17:09:01 | [diff] [blame] | 32 | #include "chrome/browser/download/download_request_limiter.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 33 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 34 | #include "chrome/browser/external_protocol_handler.h" |
| 35 | #include "chrome/browser/favicon_service.h" |
| 36 | #include "chrome/browser/file_select_helper.h" |
| 37 | #include "chrome/browser/google/google_util.h" |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 38 | #include "chrome/browser/history/history.h" |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 39 | #include "chrome/browser/history/history_types.h" |
[email protected] | 523623c | 2010-05-19 16:03:42 | [diff] [blame] | 40 | #include "chrome/browser/history/top_sites.h" |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 41 | #include "chrome/browser/host_zoom_map.h" |
[email protected] | 8897c38 | 2009-05-06 17:53:26 | [diff] [blame] | 42 | #include "chrome/browser/hung_renderer_dialog.h" |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 43 | #include "chrome/browser/in_process_webkit/session_storage_namespace.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 44 | #include "chrome/browser/load_from_memory_cache_details.h" |
| 45 | #include "chrome/browser/load_notification_details.h" |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 46 | #include "chrome/browser/metrics/metric_event_duration_details.h" |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 47 | #include "chrome/browser/metrics/user_metrics.h" |
[email protected] | ea0e8089 | 2009-08-22 00:36:05 | [diff] [blame] | 48 | #include "chrome/browser/modal_html_dialog_delegate.h" |
[email protected] | c886548 | 2009-07-23 20:40:10 | [diff] [blame] | 49 | #include "chrome/browser/omnibox_search_hint.h" |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 50 | #include "chrome/browser/pdf_unsupported_feature.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 51 | #include "chrome/browser/platform_util.h" |
[email protected] | 67c052e | 2011-01-31 16:33:58 | [diff] [blame] | 52 | #include "chrome/browser/plugin_observer.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 53 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 54 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 973407b | 2011-01-26 23:18:23 | [diff] [blame] | 55 | #include "chrome/browser/prerender/prerender_plt_recorder.h" |
[email protected] | eb15e24e | 2011-02-03 22:34:34 | [diff] [blame] | 56 | #include "chrome/browser/printing/print_preview_message_handler.h" |
[email protected] | dbeebd5 | 2010-11-16 20:34:16 | [diff] [blame] | 57 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 58 | #include "chrome/browser/printing/print_view_manager.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 59 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 60 | #include "chrome/browser/renderer_host/render_process_host.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 61 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 62 | #include "chrome/browser/renderer_host/render_widget_host_view.h" |
[email protected] | fd69498 | 2009-07-03 17:32:37 | [diff] [blame] | 63 | #include "chrome/browser/renderer_host/resource_request_details.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 64 | #include "chrome/browser/renderer_host/site_instance.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 65 | #include "chrome/browser/renderer_host/web_cache_manager.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 66 | #include "chrome/browser/renderer_preferences_util.h" |
[email protected] | 8b62334b | 2010-08-31 22:37:11 | [diff] [blame] | 67 | #include "chrome/browser/search_engines/template_url.h" |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 68 | #include "chrome/browser/search_engines/template_url_fetcher.h" |
[email protected] | 0b5b85c | 2010-10-11 23:00:12 | [diff] [blame] | 69 | #include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h" |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 70 | #include "chrome/browser/search_engines/template_url_model.h" |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 71 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | bd1ad68 | 2009-05-15 22:19:17 | [diff] [blame] | 72 | #include "chrome/browser/tab_contents/infobar_delegate.h" |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 73 | #include "chrome/browser/tab_contents/interstitial_page.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 74 | #include "chrome/browser/tab_contents/navigation_entry.h" |
[email protected] | de34a96 | 2009-06-26 23:22:43 | [diff] [blame] | 75 | #include "chrome/browser/tab_contents/provisional_load_details.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 76 | #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 77 | #include "chrome/browser/tab_contents/tab_contents_observer.h" |
[email protected] | 1f18184a | 2010-07-21 19:34:49 | [diff] [blame] | 78 | #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 79 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 80 | #include "chrome/browser/tab_contents/thumbnail_generator.h" |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 81 | #include "chrome/browser/translate/page_translated_details.h" |
[email protected] | 1caa152 | 2010-12-01 20:23:35 | [diff] [blame] | 82 | #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 83 | #include "chrome/common/bindings_policy.h" |
[email protected] | 35f7d21 | 2009-04-29 21:19:27 | [diff] [blame] | 84 | #include "chrome/common/chrome_switches.h" |
[email protected] | de4761b | 2010-12-07 21:05:21 | [diff] [blame] | 85 | #include "chrome/common/content_restriction.h" |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 86 | #include "chrome/common/extensions/extension.h" |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 87 | #include "chrome/common/extensions/extension_action.h" |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 88 | #include "chrome/common/extensions/extension_icon_set.h" |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 89 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 90 | #include "chrome/common/extensions/url_pattern.h" |
| 91 | #include "chrome/common/navigation_types.h" |
| 92 | #include "chrome/common/net/url_request_context_getter.h" |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 93 | #include "chrome/common/notification_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 94 | #include "chrome/common/pref_names.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 95 | #include "chrome/common/render_messages.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 96 | #include "chrome/common/render_messages_params.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 97 | #include "chrome/common/url_constants.h" |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 98 | #include "grit/chromium_strings.h" |
[email protected] | 8897c38 | 2009-05-06 17:53:26 | [diff] [blame] | 99 | #include "grit/generated_resources.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 100 | #include "grit/locale_settings.h" |
[email protected] | fd62678 | 2010-01-22 05:26:06 | [diff] [blame] | 101 | #include "grit/platform_locale_settings.h" |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 102 | #include "grit/theme_resources.h" |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 103 | #include "net/base/net_util.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 104 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 105 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 106 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 42ce29d | 2011-01-20 23:19:46 | [diff] [blame] | 107 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 108 | #include "ui/gfx/codec/png_codec.h" |
[email protected] | d5e311b | 2010-07-20 17:15:03 | [diff] [blame] | 109 | #include "webkit/glue/password_form.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 110 | #include "webkit/glue/webpreferences.h" |
| 111 | |
| 112 | #if defined(OS_MACOSX) |
| 113 | #include "app/surface/io_surface_support_mac.h" |
| 114 | #endif // defined(OS_MACOSX) |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 115 | |
[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 116 | #if defined(OS_CHROMEOS) |
| 117 | #include "chrome/browser/chromeos/locale_change_guard.h" |
| 118 | #endif // defined(OS_CHROMEOS) |
| 119 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 120 | // Cross-Site Navigations |
| 121 | // |
| 122 | // If a TabContents is told to navigate to a different web site (as determined |
| 123 | // by SiteInstance), it will replace its current RenderViewHost with a new |
| 124 | // RenderViewHost dedicated to the new SiteInstance. This works as follows: |
| 125 | // |
| 126 | // - Navigate determines whether the destination is cross-site, and if so, |
| 127 | // it creates a pending_render_view_host_ and moves into the PENDING |
| 128 | // RendererState. |
| 129 | // - The pending RVH is "suspended," so that no navigation messages are sent to |
| 130 | // its renderer until the onbeforeunload JavaScript handler has a chance to |
| 131 | // run in the current RVH. |
| 132 | // - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton) |
| 133 | // that it has a pending cross-site request. ResourceDispatcherHost will |
| 134 | // check for this when the response arrives. |
| 135 | // - The current RVH runs its onbeforeunload handler. If it returns false, we |
| 136 | // cancel all the pending logic and go back to NORMAL. Otherwise we allow |
| 137 | // the pending RVH to send the navigation request to its renderer. |
| 138 | // - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It |
| 139 | // checks CrossSiteRequestManager to see that the RVH responsible has a |
| 140 | // pending cross-site request, and then installs a CrossSiteEventHandler. |
| 141 | // - When RDH receives a response, the BufferedEventHandler determines whether |
| 142 | // it is a download. If so, it sends a message to the new renderer causing |
| 143 | // it to cancel the request, and the download proceeds in the download |
| 144 | // thread. For now, we stay in a PENDING state (with a pending RVH) until |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 145 | // the next DidNavigate event for this TabContents. This isn't ideal, but it |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 146 | // doesn't affect any functionality. |
| 147 | // - After RDH receives a response and determines that it is safe and not a |
| 148 | // download, it pauses the response to first run the old page's onunload |
| 149 | // handler. It does this by asynchronously calling the OnCrossSiteResponse |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 150 | // method of TabContents on the UI thread, which sends a ClosePage message |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 151 | // to the current RVH. |
| 152 | // - Once the onunload handler is finished, a ClosePage_ACK message is sent to |
| 153 | // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 154 | // to the pending RVH. |
| 155 | // - The pending renderer sends a FrameNavigate message that invokes the |
| 156 | // DidNavigate method. This replaces the current RVH with the |
| 157 | // pending RVH and goes back to the NORMAL RendererState. |
| 158 | |
| 159 | namespace { |
| 160 | |
| 161 | // Amount of time we wait between when a key event is received and the renderer |
| 162 | // is queried for its state and pushed to the NavigationEntry. |
| 163 | const int kQueryStateDelay = 5000; |
| 164 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 165 | const int kSyncWaitDelay = 40; |
| 166 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 167 | // If another javascript message box is displayed within |
| 168 | // kJavascriptMessageExpectedDelay of a previous javascript message box being |
| 169 | // dismissed, display an option to suppress future message boxes from this |
| 170 | // contents. |
| 171 | const int kJavascriptMessageExpectedDelay = 1000; |
| 172 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 173 | // The list of prefs we want to observe. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 174 | const char* kPrefsToObserve[] = { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 175 | prefs::kAlternateErrorPagesEnabled, |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 176 | prefs::kDefaultZoomLevel, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 177 | prefs::kWebKitJavaEnabled, |
| 178 | prefs::kWebKitJavascriptEnabled, |
| 179 | prefs::kWebKitLoadsImagesAutomatically, |
| 180 | prefs::kWebKitPluginsEnabled, |
| 181 | prefs::kWebKitUsesUniversalDetector, |
| 182 | prefs::kWebKitSerifFontFamily, |
| 183 | prefs::kWebKitSansSerifFontFamily, |
| 184 | prefs::kWebKitFixedFontFamily, |
| 185 | prefs::kWebKitDefaultFontSize, |
| 186 | prefs::kWebKitDefaultFixedFontSize, |
[email protected] | 6bdf05b | 2010-10-13 20:34:13 | [diff] [blame] | 187 | prefs::kWebKitMinimumFontSize, |
| 188 | prefs::kWebKitMinimumLogicalFontSize, |
[email protected] | 1661a3c0 | 2010-05-20 16:32:36 | [diff] [blame] | 189 | prefs::kWebkitTabsToLinks, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 190 | prefs::kDefaultCharset |
| 191 | // kWebKitStandardFontIsSerif needs to be added |
| 192 | // if we let users pick which font to use, serif or sans-serif when |
| 193 | // no font is specified or a CSS generic family (serif or sans-serif) |
| 194 | // is not specified. |
| 195 | }; |
| 196 | |
| 197 | const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 198 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 199 | // Returns true if the entry's transition type is FORM_SUBMIT. |
| 200 | bool IsFormSubmit(const NavigationEntry* entry) { |
| 201 | return (PageTransition::StripQualifier(entry->transition_type()) == |
| 202 | PageTransition::FORM_SUBMIT); |
| 203 | } |
| 204 | |
| 205 | #if defined(OS_WIN) |
| 206 | |
| 207 | BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { |
| 208 | // Note: erase is required to properly paint some widgets borders. This can |
| 209 | // be seen with textfields. |
| 210 | InvalidateRect(hwnd, NULL, TRUE); |
| 211 | return TRUE; |
| 212 | } |
| 213 | #endif |
| 214 | |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 215 | ViewMsg_Navigate_Params::NavigationType GetNavigationType( |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 216 | Profile* profile, const NavigationEntry& entry, |
| 217 | NavigationController::ReloadType reload_type) { |
| 218 | switch (reload_type) { |
| 219 | case NavigationController::RELOAD: |
| 220 | return ViewMsg_Navigate_Params::RELOAD; |
| 221 | case NavigationController::RELOAD_IGNORING_CACHE: |
| 222 | return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
| 223 | case NavigationController::NO_RELOAD: |
| 224 | break; // Fall through to rest of function. |
| 225 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 226 | |
| 227 | if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION && |
| 228 | profile->DidLastSessionExitCleanly()) |
| 229 | return ViewMsg_Navigate_Params::RESTORE; |
| 230 | |
| 231 | return ViewMsg_Navigate_Params::NORMAL; |
| 232 | } |
| 233 | |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 234 | void MakeNavigateParams(const NavigationEntry& entry, |
| 235 | const NavigationController& controller, |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 236 | NavigationController::ReloadType reload_type, |
| 237 | ViewMsg_Navigate_Params* params) { |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 238 | params->page_id = entry.page_id(); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 239 | params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 240 | params->current_history_list_offset = controller.last_committed_entry_index(); |
| 241 | params->current_history_list_length = controller.entry_count(); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 242 | params->url = entry.url(); |
| 243 | params->referrer = entry.referrer(); |
| 244 | params->transition = entry.transition_type(); |
| 245 | params->state = entry.content_state(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 246 | params->navigation_type = |
| 247 | GetNavigationType(controller.profile(), entry, reload_type); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 248 | params->request_time = base::Time::Now(); |
| 249 | } |
| 250 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 251 | } // namespace |
| 252 | |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 253 | |
| 254 | // TabContents ---------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 255 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 256 | TabContents::TabContents(Profile* profile, |
| 257 | SiteInstance* site_instance, |
| 258 | int routing_id, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 259 | const TabContents* base_tab_contents, |
| 260 | SessionStorageNamespace* session_storage_namespace) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 261 | : delegate_(NULL), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 262 | ALLOW_THIS_IN_INITIALIZER_LIST(controller_( |
| 263 | this, profile, session_storage_namespace)), |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 264 | ALLOW_THIS_IN_INITIALIZER_LIST(view_( |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 265 | TabContentsView::Create(this))), |
| 266 | ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 267 | property_bag_(), |
| 268 | registrar_(), |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 269 | ALLOW_THIS_IN_INITIALIZER_LIST(printing_( |
| 270 | new printing::PrintViewManager(*this))), |
[email protected] | eb15e24e | 2011-02-03 22:34:34 | [diff] [blame] | 271 | ALLOW_THIS_IN_INITIALIZER_LIST(print_preview_( |
| 272 | new printing::PrintPreviewMessageHandler(this))), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 273 | save_package_(), |
[email protected] | 6db0def9 | 2010-03-02 19:55:45 | [diff] [blame] | 274 | autocomplete_history_manager_(), |
[email protected] | 21674df | 2009-10-28 19:51:21 | [diff] [blame] | 275 | autofill_manager_(), |
[email protected] | 973407b | 2011-01-26 23:18:23 | [diff] [blame] | 276 | prerender_plt_recorder_(), |
[email protected] | 6f821dd | 2010-02-23 00:54:06 | [diff] [blame] | 277 | bookmark_drag_(NULL), |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 278 | ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 279 | is_loading_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 280 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 281 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 282 | waiting_for_response_(false), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 283 | max_page_id_(-1), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 284 | current_load_start_(), |
| 285 | load_state_(net::LOAD_STATE_IDLE), |
| 286 | load_state_host_(), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 287 | upload_size_(0), |
| 288 | upload_position_(0), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 289 | received_page_title_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 290 | contents_mime_type_(), |
| 291 | encoding_(), |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 292 | blocked_contents_(NULL), |
| 293 | all_contents_blocked_(false), |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 294 | dont_notify_render_view_(false), |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 295 | displayed_insecure_content_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 296 | infobar_delegates_(), |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 297 | extension_app_(NULL), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 298 | capturing_contents_(false), |
| 299 | is_being_destroyed_(false), |
| 300 | notify_disconnection_(false), |
| 301 | history_requests_(), |
| 302 | #if defined(OS_WIN) |
| 303 | message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 304 | #endif |
| 305 | last_javascript_message_dismissal_(), |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 306 | suppress_javascript_messages_(false), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 307 | is_showing_before_unload_dialog_(false), |
[email protected] | 7ff431e | 2010-01-07 18:18:54 | [diff] [blame] | 308 | renderer_preferences_(), |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 309 | opener_web_ui_type_(WebUIFactory::kNoWebUI), |
[email protected] | 777a7b6 | 2010-05-11 13:28:16 | [diff] [blame] | 310 | language_state_(&controller_), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 311 | closed_by_user_gesture_(false), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 312 | minimum_zoom_percent_( |
| 313 | static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
| 314 | maximum_zoom_percent_( |
| 315 | static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 316 | temporary_zoom_settings_(false), |
| 317 | content_restrictions_(0) { |
[email protected] | 7ff431e | 2010-01-07 18:18:54 | [diff] [blame] | 318 | renderer_preferences_util::UpdateFromSystemSettings( |
| 319 | &renderer_preferences_, profile); |
| 320 | |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 321 | content_settings_delegate_.reset( |
| 322 | new TabSpecificContentSettings(this, profile)); |
| 323 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 324 | render_manager_.Init(profile, site_instance, routing_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 325 | |
[email protected] | 34ac7050 | 2009-09-25 17:07:23 | [diff] [blame] | 326 | // We have the initial size of the view be based on the size of the passed in |
| 327 | // tab contents (normally a tab from the same window). |
| 328 | view_->CreateView(base_tab_contents ? |
| 329 | base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 330 | |
| 331 | // Register for notifications about all interested prefs change. |
| 332 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 333 | pref_change_registrar_.Init(prefs); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 334 | if (prefs) { |
| 335 | for (int i = 0; i < kPrefsToObserveLength; ++i) |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 336 | pref_change_registrar_.Add(kPrefsToObserve[i], this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 339 | registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
| 340 | NotificationService::AllSources()); |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 341 | #if defined(OS_LINUX) |
| 342 | registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 343 | NotificationService::AllSources()); |
| 344 | #endif |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 345 | |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 346 | registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED, |
| 347 | NotificationService::AllSources()); |
| 348 | |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 349 | // Register for notifications about content setting changes. |
| 350 | registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, |
| 351 | NotificationService::AllSources()); |
| 352 | |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 353 | // Listen for extension changes so we can update extension_for_current_page_. |
| 354 | registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 355 | NotificationService::AllSources()); |
| 356 | registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 357 | NotificationService::AllSources()); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 358 | |
[email protected] | 8815205 | 2010-10-01 04:05:18 | [diff] [blame] | 359 | // Listen for Google URL changes |
| 360 | registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED, |
| 361 | NotificationService::AllSources()); |
| 362 | |
[email protected] | c886548 | 2009-07-23 20:40:10 | [diff] [blame] | 363 | // Set-up the showing of the omnibox search infobar if applicable. |
| 364 | if (OmniboxSearchHint::IsEnabled(profile)) |
| 365 | omnibox_search_hint_.reset(new OmniboxSearchHint(this)); |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 366 | |
| 367 | autofill_manager_.reset(new AutoFillManager(this)); |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 368 | AddObserver(autofill_manager_.get()); |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 369 | autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this)); |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 370 | AddObserver(autocomplete_history_manager_.get()); |
[email protected] | 973407b | 2011-01-26 23:18:23 | [diff] [blame] | 371 | prerender_plt_recorder_.reset(new PrerenderPLTRecorder(this)); |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 372 | AddObserver(prerender_plt_recorder_.get()); |
| 373 | AddObserver(&fav_icon_helper_); |
| 374 | AddObserver(printing_.get()); |
[email protected] | 74da5bd | 2011-01-27 22:03:27 | [diff] [blame] | 375 | desktop_notification_handler_.reset( |
| 376 | new DesktopNotificationHandler(this, GetRenderProcessHost())); |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 377 | AddObserver(desktop_notification_handler_.get()); |
[email protected] | 67c052e | 2011-01-31 16:33:58 | [diff] [blame] | 378 | plugin_observer_.reset(new PluginObserver(this)); |
| 379 | AddObserver(plugin_observer_.get()); |
[email protected] | eb15e24e | 2011-02-03 22:34:34 | [diff] [blame] | 380 | AddObserver(print_preview_.get()); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 381 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 382 | |
| 383 | TabContents::~TabContents() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 384 | is_being_destroyed_ = true; |
| 385 | |
[email protected] | bfe4c158 | 2009-10-02 18:11:09 | [diff] [blame] | 386 | // We don't want any notifications while we're running our destructor. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 387 | registrar_.RemoveAll(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 388 | pref_change_registrar_.RemoveAll(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 389 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 390 | NotifyDisconnected(); |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 391 | hung_renderer_dialog::HideForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 392 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 393 | // First cleanly close all child windows. |
| 394 | // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
| 395 | // some of these to close. CloseWindows is async, so it might get called |
| 396 | // twice before it runs. |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 397 | CloseConstrainedWindows(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 398 | |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 399 | // Close all blocked contents. |
| 400 | if (blocked_contents_) |
| 401 | blocked_contents_->Destroy(); |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 402 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 403 | // Notify any observer that have a reference on this tab contents. |
| 404 | NotificationService::current()->Notify( |
| 405 | NotificationType::TAB_CONTENTS_DESTROYED, |
| 406 | Source<TabContents>(this), |
| 407 | NotificationService::NoDetails()); |
| 408 | |
[email protected] | 1e5e74f | 2009-05-27 20:55:12 | [diff] [blame] | 409 | // Notify any lasting InfobarDelegates that have not yet been removed that |
| 410 | // whatever infobar they were handling in this TabContents has closed, |
| 411 | // because the TabContents is going away entirely. |
| 412 | // This must happen after the TAB_CONTENTS_DESTROYED notification as the |
| 413 | // notification may trigger infobars calls that access their delegate. (and |
| 414 | // some implementations of InfoBarDelegate do delete themselves on |
| 415 | // InfoBarClosed()). |
| 416 | for (int i = 0; i < infobar_delegate_count(); ++i) { |
| 417 | InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); |
| 418 | delegate->InfoBarClosed(); |
| 419 | } |
| 420 | infobar_delegates_.clear(); |
| 421 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 422 | // TODO(brettw) this should be moved to the view. |
| 423 | #if defined(OS_WIN) |
| 424 | // If we still have a window handle, destroy it. GetNativeView can return |
| 425 | // NULL if this contents was part of a window that closed. |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 426 | if (GetNativeView()) { |
| 427 | RenderViewHost* host = render_view_host(); |
| 428 | if (host && host->view()) { |
| 429 | host->view()->WillWmDestroy(); |
| 430 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 431 | ::DestroyWindow(GetNativeView()); |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 432 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 433 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 434 | |
| 435 | // OnCloseStarted isn't called in unit tests. |
| 436 | if (!tab_close_start_time_.is_null()) { |
| 437 | UMA_HISTOGRAM_TIMES("Tab.Close", |
| 438 | base::TimeTicks::Now() - tab_close_start_time_); |
| 439 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 442 | // static |
| 443 | void TabContents::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 444 | prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); |
| 445 | |
| 446 | WebPreferences pref_defaults; |
| 447 | prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, |
| 448 | pref_defaults.javascript_enabled); |
| 449 | prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, |
| 450 | pref_defaults.web_security_enabled); |
| 451 | prefs->RegisterBooleanPref( |
| 452 | prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true); |
| 453 | prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically, |
| 454 | pref_defaults.loads_images_automatically); |
| 455 | prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled, |
| 456 | pref_defaults.plugins_enabled); |
| 457 | prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled, |
| 458 | pref_defaults.dom_paste_enabled); |
| 459 | prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit, |
| 460 | pref_defaults.shrinks_standalone_images_to_fit); |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 461 | prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 462 | prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable, |
| 463 | pref_defaults.text_areas_are_resizable); |
| 464 | prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled, |
| 465 | pref_defaults.java_enabled); |
[email protected] | 1661a3c0 | 2010-05-20 16:32:36 | [diff] [blame] | 466 | prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks, |
| 467 | pref_defaults.tabs_to_links); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 468 | |
| 469 | prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages, |
| 470 | IDS_ACCEPT_LANGUAGES); |
| 471 | prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset, |
| 472 | IDS_DEFAULT_ENCODING); |
| 473 | prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif, |
| 474 | IDS_STANDARD_FONT_IS_SERIF); |
| 475 | prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily, |
| 476 | IDS_FIXED_FONT_FAMILY); |
| 477 | prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily, |
| 478 | IDS_SERIF_FONT_FAMILY); |
| 479 | prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily, |
| 480 | IDS_SANS_SERIF_FONT_FAMILY); |
| 481 | prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily, |
| 482 | IDS_CURSIVE_FONT_FAMILY); |
| 483 | prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily, |
| 484 | IDS_FANTASY_FONT_FAMILY); |
| 485 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, |
| 486 | IDS_DEFAULT_FONT_SIZE); |
| 487 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, |
| 488 | IDS_DEFAULT_FIXED_FONT_SIZE); |
| 489 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, |
| 490 | IDS_MINIMUM_FONT_SIZE); |
| 491 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize, |
| 492 | IDS_MINIMUM_LOGICAL_FONT_SIZE); |
| 493 | prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector, |
| 494 | IDS_USES_UNIVERSAL_DETECTOR); |
| 495 | prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings, |
| 496 | IDS_STATIC_ENCODING_LIST); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 497 | } |
| 498 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 499 | bool TabContents::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 500 | ObserverListBase<TabContentsObserver>::Iterator it(observers_); |
| 501 | TabContentsObserver* observer; |
[email protected] | 0f180ee | 2011-01-21 18:23:10 | [diff] [blame] | 502 | while ((observer = it.GetNext()) != NULL) |
| 503 | if (observer->OnMessageReceived(message)) |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 504 | return true; |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 505 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 506 | bool handled = true; |
| 507 | bool message_is_ok = true; |
| 508 | IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok) |
| 509 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
| 510 | OnDidStartProvisionalLoadForFrame) |
| 511 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad, |
| 512 | OnDidRedirectProvisionalLoad) |
| 513 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError, |
| 514 | OnDidFailProvisionalLoadWithError) |
| 515 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache, |
| 516 | OnDidLoadResourceFromMemoryCache) |
| 517 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent, |
| 518 | OnDidDisplayInsecureContent) |
| 519 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent, |
| 520 | OnDidRunInsecureContent) |
| 521 | IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame, |
| 522 | OnDocumentLoadedInFrame) |
| 523 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad) |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 524 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions, |
| 525 | OnUpdateContentRestrictions) |
| 526 | IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature, |
| 527 | OnPDFHasUnsupportedFeature) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 528 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 529 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo, |
| 530 | OnDidGetApplicationInfo) |
| 531 | IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication, |
| 532 | OnInstallApplication) |
| 533 | IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) |
| 534 | IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated) |
| 535 | IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) |
| 536 | IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, |
| 537 | OnInstantSupportDetermined) |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 538 | IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 539 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 540 | IPC_END_MESSAGE_MAP_EX() |
| 541 | |
| 542 | if (!message_is_ok) { |
| 543 | UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
| 544 | GetRenderProcessHost()->ReceivedBadMessage(); |
| 545 | } |
| 546 | |
| 547 | return handled; |
| 548 | } |
| 549 | |
[email protected] | 13367f7 | 2009-07-08 16:39:02 | [diff] [blame] | 550 | // Returns true if contains content rendered by an extension. |
| 551 | bool TabContents::HostsExtension() const { |
| 552 | return GetURL().SchemeIs(chrome::kExtensionScheme); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 553 | } |
| 554 | |
[email protected] | 1f18184a | 2010-07-21 19:34:49 | [diff] [blame] | 555 | TabContentsSSLHelper* TabContents::GetSSLHelper() { |
| 556 | if (ssl_helper_.get() == NULL) |
| 557 | ssl_helper_.reset(new TabContentsSSLHelper(this)); |
| 558 | return ssl_helper_.get(); |
| 559 | } |
| 560 | |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 561 | RenderProcessHost* TabContents::GetRenderProcessHost() const { |
| 562 | return render_manager_.current_host()->process(); |
| 563 | } |
| 564 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 565 | void TabContents::SetExtensionApp(const Extension* extension) { |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 566 | DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 567 | extension_app_ = extension; |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 568 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 569 | UpdateExtensionAppIcon(extension_app_); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 570 | |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 571 | NotificationService::current()->Notify( |
| 572 | NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 573 | Source<TabContents>(this), |
| 574 | NotificationService::NoDetails()); |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 575 | } |
| 576 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 577 | void TabContents::SetExtensionAppById(const std::string& extension_app_id) { |
| 578 | if (extension_app_id.empty()) |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 579 | return; |
| 580 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 581 | ExtensionService* extension_service = profile()->GetExtensionService(); |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 582 | if (!extension_service || !extension_service->is_ready()) |
| 583 | return; |
| 584 | |
| 585 | const Extension* extension = |
| 586 | extension_service->GetExtensionById(extension_app_id, false); |
| 587 | if (extension) |
| 588 | SetExtensionApp(extension); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 589 | } |
| 590 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 591 | SkBitmap* TabContents::GetExtensionAppIcon() { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 592 | if (extension_app_icon_.empty()) |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 593 | return NULL; |
| 594 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 595 | return &extension_app_icon_; |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 596 | } |
| 597 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 598 | const GURL& TabContents::GetURL() const { |
| 599 | // We may not have a navigation entry yet |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 600 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 601 | return entry ? entry->virtual_url() : GURL::EmptyGURL(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 602 | } |
| 603 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 604 | const string16& TabContents::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 605 | // Transient entries take precedence. They are used for interstitial pages |
| 606 | // that are shown on top of existing pages. |
| 607 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 608 | if (entry) { |
| 609 | return entry->GetTitleForDisplay(profile()->GetPrefs()-> |
| 610 | GetString(prefs::kAcceptLanguages)); |
| 611 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 612 | DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ? |
| 613 | render_manager_.pending_dom_ui() : render_manager_.dom_ui(); |
| 614 | if (our_dom_ui) { |
| 615 | // Don't override the title in view source mode. |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 616 | entry = controller_.GetActiveEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 617 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 618 | // Give the Web UI the chance to override our title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 619 | const string16& title = our_dom_ui->overridden_title(); |
| 620 | if (!title.empty()) |
| 621 | return title; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | // We use the title for the last committed entry rather than a pending |
| 626 | // navigation entry. For example, when the user types in a URL, we want to |
| 627 | // keep the old page's title until the new load has committed and we get a new |
| 628 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 629 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 630 | if (entry) { |
| 631 | return entry->GetTitleForDisplay(profile()->GetPrefs()-> |
| 632 | GetString(prefs::kAcceptLanguages)); |
| 633 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 634 | return EmptyString16(); |
| 635 | } |
| 636 | |
[email protected] | bbbc1ef | 2010-02-12 18:03:41 | [diff] [blame] | 637 | // static |
| 638 | string16 TabContents::GetDefaultTitle() { |
| 639 | return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
| 640 | } |
| 641 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 642 | int32 TabContents::GetMaxPageID() { |
| 643 | if (GetSiteInstance()) |
| 644 | return GetSiteInstance()->max_page_id(); |
| 645 | else |
| 646 | return max_page_id_; |
| 647 | } |
| 648 | |
| 649 | void TabContents::UpdateMaxPageID(int32 page_id) { |
| 650 | // Ensure both the SiteInstance and RenderProcessHost update their max page |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 651 | // IDs in sync. Only TabContents will also have site instances, except during |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 652 | // testing. |
| 653 | if (GetSiteInstance()) |
| 654 | GetSiteInstance()->UpdateMaxPageID(page_id); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 655 | GetRenderProcessHost()->UpdateMaxPageID(page_id); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 656 | } |
| 657 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 658 | SiteInstance* TabContents::GetSiteInstance() const { |
| 659 | return render_manager_.current_host()->site_instance(); |
| 660 | } |
| 661 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 662 | bool TabContents::ShouldDisplayURL() { |
[email protected] | 8ab24cc | 2009-11-13 20:56:15 | [diff] [blame] | 663 | // Don't hide the url in view source mode and with interstitials. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 664 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 8ab24cc | 2009-11-13 20:56:15 | [diff] [blame] | 665 | if (entry && (entry->IsViewSourceMode() || |
[email protected] | cccd376 | 2010-11-12 18:40:01 | [diff] [blame] | 666 | entry->page_type() == INTERSTITIAL_PAGE)) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 667 | return true; |
[email protected] | 8ab24cc | 2009-11-13 20:56:15 | [diff] [blame] | 668 | } |
[email protected] | 83e3895b | 2009-06-11 00:07:16 | [diff] [blame] | 669 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 670 | DOMUI* dom_ui = GetDOMUIForCurrentState(); |
| 671 | if (dom_ui) |
| 672 | return !dom_ui->should_hide_url(); |
| 673 | return true; |
| 674 | } |
| 675 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 676 | SkBitmap TabContents::GetFavIcon() const { |
| 677 | // Like GetTitle(), we also want to use the favicon for the last committed |
| 678 | // entry rather than a pending navigation entry. |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 679 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 680 | if (entry) |
| 681 | return entry->favicon().bitmap(); |
| 682 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 683 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 684 | if (entry) |
| 685 | return entry->favicon().bitmap(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 686 | return SkBitmap(); |
| 687 | } |
| 688 | |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 689 | bool TabContents::FavIconIsValid() const { |
| 690 | NavigationEntry* entry = controller_.GetTransientEntry(); |
| 691 | if (entry) |
| 692 | return entry->favicon().is_valid(); |
| 693 | |
| 694 | entry = controller_.GetLastCommittedEntry(); |
| 695 | if (entry) |
| 696 | return entry->favicon().is_valid(); |
| 697 | |
| 698 | return false; |
| 699 | } |
| 700 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 701 | bool TabContents::ShouldDisplayFavIcon() { |
| 702 | // Always display a throbber during pending loads. |
| 703 | if (controller_.GetLastCommittedEntry() && controller_.pending_entry()) |
| 704 | return true; |
| 705 | |
| 706 | DOMUI* dom_ui = GetDOMUIForCurrentState(); |
| 707 | if (dom_ui) |
| 708 | return !dom_ui->hide_favicon(); |
| 709 | return true; |
| 710 | } |
| 711 | |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 712 | string16 TabContents::GetStatusText() const { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 713 | if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 714 | return string16(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 715 | |
| 716 | switch (load_state_) { |
| 717 | case net::LOAD_STATE_WAITING_FOR_CACHE: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 718 | return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE); |
[email protected] | 8a1f331 | 2010-05-25 19:25:04 | [diff] [blame] | 719 | case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 720 | return |
| 721 | l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 722 | case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 723 | return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 724 | case net::LOAD_STATE_RESOLVING_HOST: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 725 | return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 726 | case net::LOAD_STATE_CONNECTING: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 727 | return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING); |
[email protected] | 375e311 | 2010-05-27 20:32:06 | [diff] [blame] | 728 | case net::LOAD_STATE_SSL_HANDSHAKE: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 729 | return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 730 | case net::LOAD_STATE_SENDING_REQUEST: |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 731 | if (upload_size_) |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 732 | return l10n_util::GetStringFUTF16Int( |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 733 | IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS, |
| 734 | static_cast<int>((100 * upload_position_) / upload_size_)); |
| 735 | else |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 736 | return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 737 | case net::LOAD_STATE_WAITING_FOR_RESPONSE: |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 738 | return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, |
| 739 | load_state_host_); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 740 | // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE |
| 741 | case net::LOAD_STATE_IDLE: |
| 742 | case net::LOAD_STATE_READING_RESPONSE: |
| 743 | break; |
| 744 | } |
| 745 | |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 746 | return string16(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 747 | } |
| 748 | |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 749 | void TabContents::AddObserver(TabContentsObserver* observer) { |
| 750 | observers_.AddObserver(observer); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 751 | } |
| 752 | |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 753 | void TabContents::RemoveObserver(TabContentsObserver* observer) { |
| 754 | observers_.RemoveObserver(observer); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 755 | } |
| 756 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 757 | void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) { |
| 758 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 759 | return; |
| 760 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 761 | crashed_status_ = status; |
| 762 | crashed_error_code_ = error_code; |
[email protected] | c9cd222 | 2009-05-06 05:16:50 | [diff] [blame] | 763 | NotifyNavigationStateChanged(INVALIDATE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 764 | } |
| 765 | |
[email protected] | 744ef17 | 2009-10-16 21:53:46 | [diff] [blame] | 766 | void TabContents::PageActionStateChanged() { |
| 767 | NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 768 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 769 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 770 | void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { |
| 771 | if (delegate_) |
| 772 | delegate_->NavigationStateChanged(this, changed_flags); |
| 773 | } |
| 774 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 775 | void TabContents::DidBecomeSelected() { |
| 776 | controller_.SetActive(true); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 777 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 778 | if (rwhv) { |
| 779 | rwhv->DidBecomeSelected(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 780 | #if defined(OS_MACOSX) |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 781 | rwhv->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 782 | #endif |
| 783 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 784 | |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 785 | WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id()); |
[email protected] | 5ac2016 | 2010-11-24 23:33:11 | [diff] [blame] | 786 | last_selected_time_ = base::TimeTicks::Now(); |
[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 787 | #if defined(OS_CHROMEOS) |
| 788 | chromeos::LocaleChangeGuard::Check(this); |
| 789 | #endif |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | a94454b | 2010-12-16 04:16:03 | [diff] [blame] | 792 | void TabContents::FadeForInstant(bool animate) { |
[email protected] | 1b07256 | 2010-12-13 19:37:45 | [diff] [blame] | 793 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 794 | SkColor whitish = SkColorSetARGB(192, 255, 255, 255); |
| 795 | if (rwhv) |
[email protected] | a94454b | 2010-12-16 04:16:03 | [diff] [blame] | 796 | rwhv->SetVisuallyDeemphasized(&whitish, animate); |
[email protected] | 1b07256 | 2010-12-13 19:37:45 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | void TabContents::CancelInstantFade() { |
| 800 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 801 | if (rwhv) |
| 802 | rwhv->SetVisuallyDeemphasized(NULL, false); |
| 803 | } |
| 804 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 805 | void TabContents::WasHidden() { |
| 806 | if (!capturing_contents()) { |
| 807 | // |render_view_host()| can be NULL if the user middle clicks a link to open |
| 808 | // a tab in then background, then closes the tab before selecting it. This |
| 809 | // is because closing the tab calls TabContents::Destroy(), which removes |
| 810 | // the |render_view_host()|; then when we actually destroy the window, |
| 811 | // OnWindowPosChanged() notices and calls HideContents() (which calls us). |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 812 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 813 | if (rwhv) |
| 814 | rwhv->WasHidden(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | NotificationService::current()->Notify( |
| 818 | NotificationType::TAB_CONTENTS_HIDDEN, |
| 819 | Source<TabContents>(this), |
| 820 | NotificationService::NoDetails()); |
| 821 | } |
| 822 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 823 | void TabContents::Activate() { |
| 824 | if (delegate_) |
| 825 | delegate_->ActivateContents(this); |
| 826 | } |
| 827 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 828 | void TabContents::Deactivate() { |
| 829 | if (delegate_) |
| 830 | delegate_->DeactivateContents(this); |
| 831 | } |
| 832 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 833 | void TabContents::ShowContents() { |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 834 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 835 | if (rwhv) |
| 836 | rwhv->DidBecomeSelected(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | void TabContents::HideContents() { |
| 840 | // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
| 841 | // our superclass HideContents(), because some callers want to be very picky |
| 842 | // about the order in which these get called. In addition to making the code |
| 843 | // here practically impossible to understand, this also means we end up |
| 844 | // calling TabContents::WasHidden() twice if callers call both versions of |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 845 | // HideContents() on a TabContents. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 846 | WasHidden(); |
| 847 | } |
| 848 | |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 849 | bool TabContents::NeedToFireBeforeUnload() { |
| 850 | // TODO(creis): Should we fire even for interstitial pages? |
| 851 | return notify_disconnection() && |
| 852 | !showing_interstitial_page() && |
| 853 | !render_view_host()->SuddenTerminationAllowed(); |
| 854 | } |
| 855 | |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 856 | void TabContents::OpenURL(const GURL& url, const GURL& referrer, |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 857 | WindowOpenDisposition disposition, |
| 858 | PageTransition::Type transition) { |
| 859 | if (delegate_) |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 860 | delegate_->OpenURLFromTab(this, url, referrer, disposition, transition); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 861 | } |
| 862 | |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 863 | bool TabContents::NavigateToPendingEntry( |
| 864 | NavigationController::ReloadType reload_type) { |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 865 | return NavigateToEntry(*controller_.pending_entry(), reload_type); |
| 866 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 867 | |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 868 | bool TabContents::NavigateToEntry( |
| 869 | const NavigationEntry& entry, |
| 870 | NavigationController::ReloadType reload_type) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 871 | RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); |
| 872 | if (!dest_render_view_host) |
| 873 | return false; // Unable to create the desired render view host. |
| 874 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 875 | if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { |
| 876 | dest_render_view_host->EnablePreferredSizeChangedMode( |
| 877 | kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
| 878 | } |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 879 | |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 880 | // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
[email protected] | 05fdd49 | 2010-11-15 17:52:07 | [diff] [blame] | 881 | // Double check that here. |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 882 | int enabled_bindings = dest_render_view_host->enabled_bindings(); |
[email protected] | 0352e547 | 2010-04-29 00:11:40 | [diff] [blame] | 883 | bool is_allowed_in_dom_ui_renderer = |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 884 | WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url()); |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 885 | CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) || |
[email protected] | 0352e547 | 2010-04-29 00:11:40 | [diff] [blame] | 886 | is_allowed_in_dom_ui_renderer); |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 887 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 888 | // Tell DevTools agent that it is attached prior to the navigation. |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 889 | DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
[email protected] | 7e8e6b6 | 2009-05-08 11:28:32 | [diff] [blame] | 890 | if (devtools_manager) { // NULL in unit tests. |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 891 | devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
| 892 | dest_render_view_host, |
| 893 | entry.url()); |
[email protected] | 7e8e6b6 | 2009-05-08 11:28:32 | [diff] [blame] | 894 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 895 | |
| 896 | // Used for page load time metrics. |
| 897 | current_load_start_ = base::TimeTicks::Now(); |
| 898 | |
| 899 | // Navigate in the desired RenderViewHost. |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 900 | ViewMsg_Navigate_Params navigate_params; |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 901 | MakeNavigateParams(entry, controller_, reload_type, &navigate_params); |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 902 | if (delegate_) { |
| 903 | navigate_params.extra_headers = |
| 904 | delegate_->GetNavigationHeaders(navigate_params.url); |
| 905 | } |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 906 | dest_render_view_host->Navigate(navigate_params); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 907 | |
| 908 | if (entry.page_id() == -1) { |
| 909 | // HACK!! This code suppresses javascript: URLs from being added to |
| 910 | // session history, which is what we want to do for javascript: URLs that |
| 911 | // do not generate content. What we really need is a message from the |
| 912 | // renderer telling us that a new page was not created. The same message |
| 913 | // could be used for mailto: URLs and the like. |
| 914 | if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) |
| 915 | return false; |
| 916 | } |
| 917 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 918 | // Notify observers about navigation. |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 919 | FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 920 | |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 921 | if (reload_type != NavigationController::NO_RELOAD && |
| 922 | !profile()->IsOffTheRecord()) { |
[email protected] | 0189bc72 | 2009-08-28 21:56:48 | [diff] [blame] | 923 | FaviconService* favicon_service = |
| 924 | profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); |
| 925 | if (favicon_service) |
| 926 | favicon_service->SetFaviconOutOfDateForPage(entry.url()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 929 | return true; |
| 930 | } |
| 931 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 932 | void TabContents::Stop() { |
| 933 | render_manager_.Stop(); |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 934 | printing_->Stop(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 935 | } |
| 936 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 937 | void TabContents::DisassociateFromPopupCount() { |
| 938 | render_view_host()->DisassociateFromPopupCount(); |
| 939 | } |
| 940 | |
| 941 | TabContents* TabContents::Clone() { |
| 942 | // We create a new SiteInstance so that the new tab won't share processes |
| 943 | // with the old one. This can be changed in the future if we need it to share |
| 944 | // processes for some reason. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 945 | TabContents* tc = new TabContents(profile(), |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 946 | SiteInstance::CreateSiteInstance(profile()), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 947 | MSG_ROUTING_NONE, this, NULL); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 948 | tc->controller().CopyStateFrom(controller_); |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 949 | tc->extension_app_ = extension_app_; |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 950 | tc->extension_app_icon_ = extension_app_icon_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 951 | return tc; |
| 952 | } |
| 953 | |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 954 | void TabContents::ShowPageInfo(const GURL& url, |
| 955 | const NavigationEntry::SSLStatus& ssl, |
| 956 | bool show_history) { |
| 957 | if (!delegate_) |
| 958 | return; |
| 959 | |
[email protected] | bb67833 | 2009-07-21 00:15:50 | [diff] [blame] | 960 | delegate_->ShowPageInfo(profile(), url, ssl, show_history); |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 961 | } |
| 962 | |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 963 | void TabContents::SaveFavicon() { |
| 964 | NavigationEntry* entry = controller_.GetActiveEntry(); |
| 965 | if (!entry || entry->url().is_empty()) |
| 966 | return; |
| 967 | |
| 968 | // Make sure the page is in history, otherwise adding the favicon does |
| 969 | // nothing. |
| 970 | HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService( |
| 971 | Profile::IMPLICIT_ACCESS); |
| 972 | if (!history) |
| 973 | return; |
| 974 | history->AddPageNoVisitForBookmark(entry->url()); |
| 975 | |
| 976 | FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService( |
| 977 | Profile::IMPLICIT_ACCESS); |
| 978 | if (!service) |
| 979 | return; |
| 980 | const NavigationEntry::FaviconStatus& favicon(entry->favicon()); |
| 981 | if (!favicon.is_valid() || favicon.url().is_empty() || |
| 982 | favicon.bitmap().empty()) { |
| 983 | return; |
| 984 | } |
| 985 | std::vector<unsigned char> image_data; |
| 986 | gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); |
| 987 | service->SetFavicon(entry->url(), favicon.url(), image_data); |
| 988 | } |
| 989 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 990 | ConstrainedWindow* TabContents::CreateConstrainedDialog( |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 991 | ConstrainedWindowDelegate* delegate) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 992 | ConstrainedWindow* window = |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 993 | ConstrainedWindow::CreateConstrainedDialog(this, delegate); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 994 | child_windows_.push_back(window); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 995 | |
| 996 | if (child_windows_.size() == 1) { |
| 997 | window->ShowConstrainedWindow(); |
| 998 | BlockTabContent(true); |
| 999 | } |
| 1000 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1001 | return window; |
| 1002 | } |
| 1003 | |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1004 | void TabContents::BlockTabContent(bool blocked) { |
[email protected] | 8dccd7cb | 2010-02-25 05:19:55 | [diff] [blame] | 1005 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
[email protected] | 1b07256 | 2010-12-13 19:37:45 | [diff] [blame] | 1006 | // 70% opaque grey. |
| 1007 | SkColor greyish = SkColorSetARGB(178, 0, 0, 0); |
[email protected] | 8dccd7cb | 2010-02-25 05:19:55 | [diff] [blame] | 1008 | if (rwhv) |
[email protected] | 1b07256 | 2010-12-13 19:37:45 | [diff] [blame] | 1009 | rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1010 | render_view_host()->set_ignore_input_events(blocked); |
| 1011 | if (delegate_) |
| 1012 | delegate_->SetTabContentBlocked(this, blocked); |
| 1013 | } |
| 1014 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1015 | void TabContents::AddNewContents(TabContents* new_contents, |
| 1016 | WindowOpenDisposition disposition, |
| 1017 | const gfx::Rect& initial_pos, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1018 | bool user_gesture) { |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1019 | if (all_contents_blocked_) { |
| 1020 | if (!blocked_contents_) |
| 1021 | blocked_contents_ = new BlockedContentContainer(this); |
| 1022 | blocked_contents_->AddTabContents( |
| 1023 | new_contents, disposition, initial_pos, user_gesture); |
| 1024 | return; |
| 1025 | } |
| 1026 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1027 | if (!delegate_) |
| 1028 | return; |
| 1029 | |
[email protected] | 35f7d21 | 2009-04-29 21:19:27 | [diff] [blame] | 1030 | if ((disposition == NEW_POPUP) && !user_gesture && |
| 1031 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1032 | switches::kDisablePopupBlocking)) { |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 1033 | // Unrequested popups from normal pages are constrained unless they're in |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 1034 | // the whitelist. The popup owner will handle checking this. |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1035 | delegate_->GetConstrainingContents(this)->AddPopup( |
| 1036 | new_contents, initial_pos); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 1037 | } else { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1038 | new_contents->DisassociateFromPopupCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1039 | delegate_->AddNewContents(this, new_contents, disposition, initial_pos, |
| 1040 | user_gesture); |
[email protected] | 7f37dd9 | 2009-09-15 16:35:49 | [diff] [blame] | 1041 | NotificationService::current()->Notify( |
| 1042 | NotificationType::TAB_ADDED, |
| 1043 | Source<TabContentsDelegate>(delegate_), |
| 1044 | Details<TabContents>(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1045 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1046 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1047 | // TODO(pkasting): Why is this necessary? |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1048 | PopupNotificationVisibilityChanged(blocked_contents_ != NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1049 | } |
| 1050 | |
[email protected] | bcd9dc4 | 2010-01-23 16:38:18 | [diff] [blame] | 1051 | bool TabContents::ExecuteCode(int request_id, const std::string& extension_id, |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 1052 | bool is_js_code, const std::string& code_string, |
| 1053 | bool all_frames) { |
[email protected] | ebd0eae7 | 2010-02-16 23:50:51 | [diff] [blame] | 1054 | RenderViewHost* host = render_view_host(); |
| 1055 | if (!host) |
| 1056 | return false; |
| 1057 | |
| 1058 | return host->Send(new ViewMsg_ExecuteCode(host->routing_id(), |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 1059 | ViewMsg_ExecuteCode_Params(request_id, extension_id, |
[email protected] | ebd0eae7 | 2010-02-16 23:50:51 | [diff] [blame] | 1060 | is_js_code, code_string, all_frames))); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 1061 | } |
| 1062 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1063 | void TabContents::PopupNotificationVisibilityChanged(bool visible) { |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1064 | if (is_being_destroyed_) |
| 1065 | return; |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 1066 | content_settings_delegate_->SetPopupsBlocked(visible); |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1067 | if (!dont_notify_render_view_) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1068 | render_view_host()->AllowScriptToClose(!visible); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1069 | } |
| 1070 | |
[email protected] | 5c9e97a | 2009-09-09 23:48:30 | [diff] [blame] | 1071 | gfx::NativeView TabContents::GetContentNativeView() const { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1072 | return view_->GetContentNativeView(); |
| 1073 | } |
| 1074 | |
| 1075 | gfx::NativeView TabContents::GetNativeView() const { |
| 1076 | return view_->GetNativeView(); |
| 1077 | } |
| 1078 | |
| 1079 | void TabContents::GetContainerBounds(gfx::Rect *out) const { |
| 1080 | view_->GetContainerBounds(out); |
| 1081 | } |
| 1082 | |
| 1083 | void TabContents::Focus() { |
| 1084 | view_->Focus(); |
| 1085 | } |
| 1086 | |
[email protected] | 90daadb4 | 2009-06-08 21:27:28 | [diff] [blame] | 1087 | void TabContents::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 1088 | if (showing_interstitial_page()) { |
| 1089 | render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); |
| 1090 | return; |
| 1091 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1092 | render_view_host()->SetInitialFocus(reverse); |
| 1093 | } |
| 1094 | |
| 1095 | bool TabContents::FocusLocationBarByDefault() { |
| 1096 | DOMUI* dom_ui = GetDOMUIForCurrentState(); |
| 1097 | if (dom_ui) |
| 1098 | return dom_ui->focus_location_bar_by_default(); |
[email protected] | 3e3f0eb | 2009-06-22 18:33:43 | [diff] [blame] | 1099 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 1100 | if (entry && entry->url() == GURL(chrome::kAboutBlankURL)) |
[email protected] | 3e3f0eb | 2009-06-22 18:33:43 | [diff] [blame] | 1101 | return true; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1102 | return false; |
| 1103 | } |
| 1104 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1105 | void TabContents::SetFocusToLocationBar(bool select_all) { |
[email protected] | a11aaf2 | 2010-03-30 00:03:38 | [diff] [blame] | 1106 | if (delegate()) |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1107 | delegate()->SetFocusToLocationBar(select_all); |
[email protected] | a11aaf2 | 2010-03-30 00:03:38 | [diff] [blame] | 1108 | } |
| 1109 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1110 | void TabContents::AddInfoBar(InfoBarDelegate* delegate) { |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 1111 | if (delegate_ && !delegate_->infobars_enabled()) { |
| 1112 | delegate->InfoBarClosed(); |
| 1113 | return; |
| 1114 | } |
| 1115 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1116 | // Look through the existing InfoBarDelegates we have for a match. If we've |
| 1117 | // already got one that matches, then we don't add the new one. |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 1118 | for (int i = 0; i < infobar_delegate_count(); ++i) { |
[email protected] | 6d27a7b | 2009-12-18 23:25:45 | [diff] [blame] | 1119 | if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { |
| 1120 | // Tell the new infobar to close so that it can clean itself up. |
| 1121 | delegate->InfoBarClosed(); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1122 | return; |
[email protected] | 6d27a7b | 2009-12-18 23:25:45 | [diff] [blame] | 1123 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | infobar_delegates_.push_back(delegate); |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1127 | NotificationService::current()->Notify( |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 1128 | NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this), |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1129 | Details<InfoBarDelegate>(delegate)); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1130 | |
| 1131 | // Add ourselves as an observer for navigations the first time a delegate is |
| 1132 | // added. We use this notification to expire InfoBars that need to expire on |
| 1133 | // page transitions. |
| 1134 | if (infobar_delegates_.size() == 1) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1135 | registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1136 | Source<NavigationController>(&controller_)); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) { |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 1141 | if (delegate_ && !delegate_->infobars_enabled()) { |
| 1142 | return; |
| 1143 | } |
| 1144 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1145 | std::vector<InfoBarDelegate*>::iterator it = |
| 1146 | find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); |
| 1147 | if (it != infobar_delegates_.end()) { |
| 1148 | InfoBarDelegate* delegate = *it; |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1149 | NotificationService::current()->Notify( |
| 1150 | NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
| 1151 | Source<TabContents>(this), |
| 1152 | Details<InfoBarDelegate>(delegate)); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1153 | |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 1154 | infobar_delegates_.erase(it); |
| 1155 | // Remove ourselves as an observer if we are tracking no more InfoBars. |
| 1156 | if (infobar_delegates_.empty()) { |
| 1157 | registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 1158 | Source<NavigationController>(&controller_)); |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 1159 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1160 | } |
| 1161 | } |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1162 | |
[email protected] | f81821c | 2009-08-07 01:29:47 | [diff] [blame] | 1163 | void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, |
| 1164 | InfoBarDelegate* new_delegate) { |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 1165 | if (delegate_ && !delegate_->infobars_enabled()) { |
| 1166 | new_delegate->InfoBarClosed(); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
[email protected] | f81821c | 2009-08-07 01:29:47 | [diff] [blame] | 1170 | std::vector<InfoBarDelegate*>::iterator it = |
| 1171 | find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); |
| 1172 | DCHECK(it != infobar_delegates_.end()); |
| 1173 | |
| 1174 | // Notify the container about the change of plans. |
| 1175 | scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( |
| 1176 | new std::pair<InfoBarDelegate*, InfoBarDelegate*>( |
| 1177 | old_delegate, new_delegate)); |
| 1178 | NotificationService::current()->Notify( |
| 1179 | NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, |
| 1180 | Source<TabContents>(this), |
| 1181 | Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); |
| 1182 | |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 1183 | // Remove the old one. |
| 1184 | infobar_delegates_.erase(it); |
[email protected] | f81821c | 2009-08-07 01:29:47 | [diff] [blame] | 1185 | |
| 1186 | // Add the new one. |
[email protected] | cdadf6f | 2010-08-20 16:36:08 | [diff] [blame] | 1187 | DCHECK(find(infobar_delegates_.begin(), |
| 1188 | infobar_delegates_.end(), new_delegate) == |
| 1189 | infobar_delegates_.end()); |
[email protected] | f81821c | 2009-08-07 01:29:47 | [diff] [blame] | 1190 | infobar_delegates_.push_back(new_delegate); |
| 1191 | } |
| 1192 | |
[email protected] | 20ede07 | 2009-10-06 00:28:35 | [diff] [blame] | 1193 | bool TabContents::ShouldShowBookmarkBar() { |
[email protected] | aa9196f | 2009-10-22 16:20:27 | [diff] [blame] | 1194 | if (showing_interstitial_page()) |
| 1195 | return false; |
| 1196 | |
[email protected] | c8f7494 | 2010-09-03 10:04:14 | [diff] [blame] | 1197 | // Do not show bookmarks bar if bookmarks aren't enabled. |
| 1198 | if (!browser_defaults::bookmarks_enabled) |
| 1199 | return false; |
| 1200 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1201 | // See GetDOMUIForCurrentState() comment for more info. This case is very |
| 1202 | // similar, but for non-first loads, we want to use the committed entry. This |
| 1203 | // is so the bookmarks bar disappears at the same time the page does. |
| 1204 | if (controller_.GetLastCommittedEntry()) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1205 | // Not the first load, always use the committed Web UI. |
[email protected] | d621991 | 2010-11-17 19:47:37 | [diff] [blame] | 1206 | return (render_manager_.dom_ui() == NULL) ? |
| 1207 | false : render_manager_.dom_ui()->force_bookmark_bar_visible(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | // When it's the first load, we know either the pending one or the committed |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1211 | // one will have the Web UI in it (see GetDOMUIForCurrentState), and only one |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1212 | // of them will be valid, so we can just check both. |
| 1213 | if (render_manager_.pending_dom_ui()) |
| 1214 | return render_manager_.pending_dom_ui()->force_bookmark_bar_visible(); |
[email protected] | d621991 | 2010-11-17 19:47:37 | [diff] [blame] | 1215 | return (render_manager_.dom_ui() == NULL) ? |
| 1216 | false : render_manager_.dom_ui()->force_bookmark_bar_visible(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1217 | } |
| 1218 | |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1219 | void TabContents::ToolbarSizeChanged(bool is_animating) { |
| 1220 | TabContentsDelegate* d = delegate(); |
| 1221 | if (d) |
| 1222 | d->ToolbarSizeChanged(this, is_animating); |
| 1223 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1224 | |
[email protected] | fc6fb7fb | 2009-11-07 02:35:04 | [diff] [blame] | 1225 | bool TabContents::CanDownload(int request_id) { |
| 1226 | TabContentsDelegate* d = delegate(); |
| 1227 | if (d) |
| 1228 | return d->CanDownload(request_id); |
| 1229 | return true; |
| 1230 | } |
| 1231 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1232 | void TabContents::OnStartDownload(DownloadItem* download) { |
| 1233 | DCHECK(download); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1234 | |
| 1235 | // Download in a constrained popup is shown in the tab that opened it. |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 1236 | TabContents* tab_contents = delegate()->GetConstrainingContents(this); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1237 | |
[email protected] | 5b928b6 | 2010-08-03 11:46:51 | [diff] [blame] | 1238 | if (tab_contents && tab_contents->delegate()) |
| 1239 | tab_contents->delegate()->OnStartDownload(download, this); |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1240 | } |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1241 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1242 | void TabContents::WillClose(ConstrainedWindow* window) { |
[email protected] | d621991 | 2010-11-17 19:47:37 | [diff] [blame] | 1243 | ConstrainedWindowList::iterator i( |
| 1244 | std::find(child_windows_.begin(), child_windows_.end(), window)); |
| 1245 | bool removed_topmost_window = i == child_windows_.begin(); |
| 1246 | if (i != child_windows_.end()) |
| 1247 | child_windows_.erase(i); |
| 1248 | if (child_windows_.empty()) { |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1249 | BlockTabContent(false); |
[email protected] | d621991 | 2010-11-17 19:47:37 | [diff] [blame] | 1250 | } else { |
| 1251 | if (removed_topmost_window) |
| 1252 | child_windows_[0]->ShowConstrainedWindow(); |
| 1253 | BlockTabContent(true); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1254 | } |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 1255 | } |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1256 | |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1257 | void TabContents::WillCloseBlockedContentContainer( |
| 1258 | BlockedContentContainer* container) { |
| 1259 | DCHECK(blocked_contents_ == container); |
| 1260 | blocked_contents_ = NULL; |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1261 | PopupNotificationVisibilityChanged(false); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1262 | } |
| 1263 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1264 | void TabContents::DidMoveOrResize(ConstrainedWindow* window) { |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 1265 | #if defined(OS_WIN) |
[email protected] | 92edc47 | 2009-02-10 20:32:06 | [diff] [blame] | 1266 | UpdateWindow(GetNativeView()); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 1267 | #endif |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1268 | } |
| 1269 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1270 | void TabContents::OnSavePage() { |
| 1271 | // If we can not save the page, try to download it. |
| 1272 | if (!SavePackage::IsSavableContents(contents_mime_type())) { |
| 1273 | DownloadManager* dlm = profile()->GetDownloadManager(); |
| 1274 | const GURL& current_page_url = GetURL(); |
| 1275 | if (dlm && current_page_url.is_valid()) |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1276 | dlm->DownloadUrl(current_page_url, GURL(), "", this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1277 | return; |
| 1278 | } |
| 1279 | |
| 1280 | Stop(); |
| 1281 | |
| 1282 | // Create the save package and possibly prompt the user for the name to save |
| 1283 | // the page as. The user prompt is an asynchronous operation that runs on |
| 1284 | // another thread. |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 1285 | SetSavePackage(new SavePackage(this)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1286 | save_package_->GetSaveInfo(); |
| 1287 | } |
| 1288 | |
| 1289 | // Used in automated testing to bypass prompting the user for file names. |
| 1290 | // Instead, the names and paths are hard coded rather than running them through |
| 1291 | // file name sanitation and extension / mime checking. |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 1292 | bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1293 | SavePackage::SavePackageType save_type) { |
| 1294 | // Stop the page from navigating. |
| 1295 | Stop(); |
| 1296 | |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 1297 | SetSavePackage(new SavePackage(this, save_type, main_file, dir_path)); |
[email protected] | cdf6cc8 | 2009-08-04 21:48:59 | [diff] [blame] | 1298 | return save_package_->Init(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1299 | } |
| 1300 | |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 1301 | void TabContents::SetSavePackage(SavePackage* save_package) { |
| 1302 | if (save_package_.get()) |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 1303 | RemoveObserver(save_package_.get()); |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 1304 | save_package_ = save_package; |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 1305 | AddObserver(save_package); |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 1306 | } |
| 1307 | |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1308 | void TabContents::EmailPageLocation() { |
| 1309 | std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false); |
| 1310 | std::string page_url = EscapeQueryParamValue(GetURL().spec(), false); |
| 1311 | std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
| 1312 | title + "&body=%0A%0A" + page_url; |
| 1313 | platform_util::OpenExternal(GURL(mailto)); |
| 1314 | } |
| 1315 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1316 | void TabContents::PrintPreview() { |
[email protected] | dbeebd5 | 2010-11-16 20:34:16 | [diff] [blame] | 1317 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1318 | switches::kEnablePrintPreview)) { |
| 1319 | if (showing_interstitial_page()) |
| 1320 | return; |
[email protected] | 83a58a2 | 2011-02-05 03:44:48 | [diff] [blame^] | 1321 | |
| 1322 | printing::PrintPreviewTabController* tab_controller = |
| 1323 | printing::PrintPreviewTabController::GetInstance(); |
| 1324 | if (!tab_controller) |
| 1325 | return; |
| 1326 | tab_controller->GetOrCreatePreviewTab(this, controller().window_id().id()); |
| 1327 | |
[email protected] | dbeebd5 | 2010-11-16 20:34:16 | [diff] [blame] | 1328 | render_view_host()->PrintPreview(); |
| 1329 | } else { |
| 1330 | PrintNow(); |
| 1331 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | bool TabContents::PrintNow() { |
| 1335 | // We can't print interstitial page for now. |
| 1336 | if (showing_interstitial_page()) |
| 1337 | return false; |
| 1338 | |
| 1339 | return render_view_host()->PrintPages(); |
| 1340 | } |
| 1341 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 1342 | void TabContents::PrintingDone(int document_cookie, bool success) { |
| 1343 | render_view_host()->PrintingDone(document_cookie, success); |
| 1344 | } |
| 1345 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1346 | bool TabContents::IsActiveEntry(int32 page_id) { |
| 1347 | NavigationEntry* active_entry = controller_.GetActiveEntry(); |
| 1348 | return (active_entry != NULL && |
| 1349 | active_entry->site_instance() == GetSiteInstance() && |
| 1350 | active_entry->page_id() == page_id); |
| 1351 | } |
| 1352 | |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1353 | void TabContents::SetOverrideEncoding(const std::string& encoding) { |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1354 | set_encoding(encoding); |
| 1355 | render_view_host()->SetPageEncoding(encoding); |
| 1356 | } |
| 1357 | |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1358 | void TabContents::ResetOverrideEncoding() { |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1359 | reset_encoding(); |
| 1360 | render_view_host()->ResetPageEncodingToDefault(); |
| 1361 | } |
| 1362 | |
| 1363 | void TabContents::WindowMoveOrResizeStarted() { |
| 1364 | render_view_host()->WindowMoveOrResizeStarted(); |
| 1365 | } |
| 1366 | |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1367 | void TabContents::SetAllContentsBlocked(bool value) { |
| 1368 | if (all_contents_blocked_ == value) |
| 1369 | return; |
| 1370 | |
| 1371 | all_contents_blocked_ = value; |
| 1372 | if (!all_contents_blocked_ && blocked_contents_) { |
| 1373 | std::vector<TabContents*> blocked; |
| 1374 | blocked_contents_->GetBlockedContents(&blocked); |
| 1375 | for (size_t i = 0; i < blocked.size(); ++i) |
| 1376 | blocked_contents_->LaunchForContents(blocked[i]); |
| 1377 | } |
| 1378 | } |
| 1379 | |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1380 | void TabContents::LogNewTabTime(const std::string& event_name) { |
| 1381 | // Not all new tab pages get timed. In those cases, we don't have a |
| 1382 | // new_tab_start_time_. |
| 1383 | if (new_tab_start_time_.is_null()) |
| 1384 | return; |
| 1385 | |
| 1386 | base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_; |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1387 | MetricEventDurationDetails details(event_name, |
| 1388 | static_cast<int>(duration.InMilliseconds())); |
| 1389 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1390 | if (event_name == "Tab.NewTabScriptStart") { |
| 1391 | UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); |
| 1392 | } else if (event_name == "Tab.NewTabDOMContentLoaded") { |
| 1393 | UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); |
| 1394 | } else if (event_name == "Tab.NewTabOnload") { |
| 1395 | UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1396 | // The new tab page has finished loading; reset it. |
| 1397 | new_tab_start_time_ = base::TimeTicks(); |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1398 | } else { |
| 1399 | NOTREACHED(); |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1400 | } |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1401 | NotificationService::current()->Notify( |
| 1402 | NotificationType::METRIC_EVENT_DURATION, |
| 1403 | Source<TabContents>(this), |
| 1404 | Details<MetricEventDurationDetails>(&details)); |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1405 | } |
| 1406 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1407 | void TabContents::OnCloseStarted() { |
| 1408 | if (tab_close_start_time_.is_null()) |
| 1409 | tab_close_start_time_ = base::TimeTicks::Now(); |
| 1410 | } |
| 1411 | |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1412 | bool TabContents::ShouldAcceptDragAndDrop() const { |
| 1413 | #if defined(OS_CHROMEOS) |
| 1414 | // ChromeOS panels (pop-ups) do not take drag-n-drop. |
| 1415 | // See http://crosbug.com/2413 |
[email protected] | b83af49 | 2010-10-09 03:21:20 | [diff] [blame] | 1416 | if (delegate() && delegate()->IsPopup(this)) |
| 1417 | return false; |
| 1418 | return true; |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1419 | #else |
| 1420 | return true; |
| 1421 | #endif |
| 1422 | } |
| 1423 | |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 1424 | void TabContents::SystemDragEnded() { |
| 1425 | if (render_view_host()) |
| 1426 | render_view_host()->DragSourceSystemDragEnded(); |
| 1427 | if (delegate()) |
| 1428 | delegate()->DragEnded(); |
| 1429 | } |
| 1430 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1431 | void TabContents::UpdateHistoryForNavigation( |
| 1432 | scoped_refptr<history::HistoryAddPageArgs> add_page_args) { |
| 1433 | if (profile()->IsOffTheRecord()) |
| 1434 | return; |
| 1435 | |
| 1436 | // Add to history service. |
| 1437 | HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1438 | if (hs) |
| 1439 | hs->AddPage(*add_page_args); |
| 1440 | } |
| 1441 | |
| 1442 | void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
| 1443 | if (profile()->IsOffTheRecord()) |
| 1444 | return; |
| 1445 | |
| 1446 | HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1447 | if (hs) |
| 1448 | hs->SetPageTitle(entry.virtual_url(), entry.title()); |
| 1449 | } |
| 1450 | |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1451 | double TabContents::GetZoomLevel() const { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1452 | HostZoomMap* zoom_map = profile()->GetHostZoomMap(); |
| 1453 | if (!zoom_map) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1454 | return 0; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1455 | |
| 1456 | double zoom_level; |
| 1457 | if (temporary_zoom_settings_) { |
| 1458 | zoom_level = zoom_map->GetTemporaryZoomLevel( |
| 1459 | GetRenderProcessHost()->id(), render_view_host()->routing_id()); |
| 1460 | } else { |
| 1461 | zoom_level = zoom_map->GetZoomLevel(GetURL()); |
| 1462 | } |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1463 | return zoom_level; |
| 1464 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1465 | |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1466 | int TabContents::GetZoomPercent(bool* enable_increment, |
| 1467 | bool* enable_decrement) { |
| 1468 | *enable_decrement = *enable_increment = false; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1469 | int percent = static_cast<int>( |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1470 | WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1471 | *enable_decrement = percent > minimum_zoom_percent_; |
| 1472 | *enable_increment = percent < maximum_zoom_percent_; |
| 1473 | return percent; |
| 1474 | } |
| 1475 | |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 1476 | void TabContents::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1477 | if (!delegate_) |
| 1478 | return; |
| 1479 | |
| 1480 | NavigationEntry* active_entry = controller().GetActiveEntry(); |
| 1481 | if (!active_entry) |
| 1482 | return; |
| 1483 | |
| 1484 | delegate_->ViewSourceForTab(this, active_entry->url()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1487 | void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, |
| 1488 | bool is_main_frame, |
| 1489 | const GURL& url) { |
| 1490 | bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL); |
| 1491 | GURL validated_url(url); |
| 1492 | render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(), |
| 1493 | GetRenderProcessHost()->id(), &validated_url); |
| 1494 | |
| 1495 | ProvisionalLoadDetails details( |
| 1496 | is_main_frame, |
| 1497 | controller_.IsURLInPageNavigation(validated_url), |
| 1498 | validated_url, std::string(), false, is_error_page, frame_id); |
| 1499 | NotificationService::current()->Notify( |
| 1500 | NotificationType::FRAME_PROVISIONAL_LOAD_START, |
| 1501 | Source<NavigationController>(&controller_), |
| 1502 | Details<ProvisionalLoadDetails>(&details)); |
| 1503 | if (is_main_frame) { |
| 1504 | // If we're displaying a network error page do not reset the content |
| 1505 | // settings delegate's cookies so the user has a chance to modify cookie |
| 1506 | // settings. |
| 1507 | if (!is_error_page) |
| 1508 | content_settings_delegate_->ClearCookieSpecificContentSettings(); |
| 1509 | content_settings_delegate_->ClearGeolocationContentSettings(); |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 1510 | |
| 1511 | // Check if the URL we are about to load has been prerendered by any chance, |
| 1512 | // and use it if possible. |
| 1513 | MaybeUsePreloadedPage(url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | void TabContents::OnDidRedirectProvisionalLoad(int32 page_id, |
| 1518 | const GURL& source_url, |
| 1519 | const GURL& target_url) { |
| 1520 | NavigationEntry* entry; |
| 1521 | if (page_id == -1) |
| 1522 | entry = controller_.pending_entry(); |
| 1523 | else |
| 1524 | entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id); |
| 1525 | if (!entry || entry->url() != source_url) |
| 1526 | return; |
| 1527 | entry->set_url(target_url); |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 1528 | |
| 1529 | // Check if the URL we are about to load has been prerendered by any chance, |
| 1530 | // and use it if possible. |
| 1531 | MaybeUsePreloadedPage(target_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | void TabContents::OnDidFailProvisionalLoadWithError( |
| 1535 | int64 frame_id, |
| 1536 | bool is_main_frame, |
| 1537 | int error_code, |
| 1538 | const GURL& url, |
| 1539 | bool showing_repost_interstitial) { |
| 1540 | VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec() |
| 1541 | << ", error_code: " << error_code |
| 1542 | << " is_main_frame: " << is_main_frame |
| 1543 | << " showing_repost_interstitial: " << showing_repost_interstitial |
| 1544 | << " frame_id: " << frame_id; |
| 1545 | GURL validated_url(url); |
| 1546 | render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(), |
| 1547 | GetRenderProcessHost()->id(), &validated_url); |
| 1548 | |
| 1549 | if (net::ERR_ABORTED == error_code) { |
| 1550 | // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. |
| 1551 | // This means that the interstitial won't be torn down properly, which is |
| 1552 | // bad. But if we have an interstitial, go back to another tab type, and |
| 1553 | // then load the same interstitial again, we could end up getting the first |
| 1554 | // interstitial's "failed" message (as a result of the cancel) when we're on |
| 1555 | // the second one. |
| 1556 | // |
| 1557 | // We can't tell this apart, so we think we're tearing down the current page |
| 1558 | // which will cause a crash later one. There is also some code in |
| 1559 | // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented |
| 1560 | // out because of this problem. |
| 1561 | // |
| 1562 | // http://code.google.com/p/chromium/issues/detail?id=2855 |
| 1563 | // Because this will not tear down the interstitial properly, if "back" is |
| 1564 | // back to another tab type, the interstitial will still be somewhat alive |
| 1565 | // in the previous tab type. If you navigate somewhere that activates the |
| 1566 | // tab with the interstitial again, you'll see a flash before the new load |
| 1567 | // commits of the interstitial page. |
| 1568 | if (showing_interstitial_page()) { |
| 1569 | LOG(WARNING) << "Discarding message during interstitial."; |
| 1570 | return; |
| 1571 | } |
| 1572 | |
| 1573 | // This will discard our pending entry if we cancelled the load (e.g., if we |
| 1574 | // decided to download the file instead of load it). Only discard the |
| 1575 | // pending entry if the URLs match, otherwise the user initiated a navigate |
| 1576 | // before the page loaded so that the discard would discard the wrong entry. |
| 1577 | NavigationEntry* pending_entry = controller_.pending_entry(); |
| 1578 | if (pending_entry && pending_entry->url() == validated_url) { |
| 1579 | controller_.DiscardNonCommittedEntries(); |
| 1580 | // Update the URL display. |
| 1581 | NotifyNavigationStateChanged(TabContents::INVALIDATE_URL); |
| 1582 | } |
| 1583 | |
| 1584 | render_manager_.RendererAbortedProvisionalLoad(render_view_host()); |
| 1585 | } |
| 1586 | |
| 1587 | // Send out a notification that we failed a provisional load with an error. |
| 1588 | ProvisionalLoadDetails details( |
| 1589 | is_main_frame, controller_.IsURLInPageNavigation(validated_url), |
| 1590 | validated_url, std::string(), false, false, frame_id); |
| 1591 | details.set_error_code(error_code); |
| 1592 | |
| 1593 | NotificationService::current()->Notify( |
| 1594 | NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 1595 | Source<NavigationController>(&controller_), |
| 1596 | Details<ProvisionalLoadDetails>(&details)); |
| 1597 | } |
| 1598 | |
| 1599 | void TabContents::OnDidLoadResourceFromMemoryCache( |
| 1600 | const GURL& url, |
| 1601 | const std::string& frame_origin, |
| 1602 | const std::string& main_frame_origin, |
| 1603 | const std::string& security_info) { |
| 1604 | static base::StatsCounter cache("WebKit.CacheHit"); |
| 1605 | cache.Increment(); |
| 1606 | |
| 1607 | // Send out a notification that we loaded a resource from our memory cache. |
| 1608 | int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0; |
| 1609 | SSLManager::DeserializeSecurityInfo(security_info, |
| 1610 | &cert_id, &cert_status, |
| 1611 | &security_bits, |
| 1612 | &connection_status); |
| 1613 | LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin, |
| 1614 | GetRenderProcessHost()->id(), cert_id, |
| 1615 | cert_status); |
| 1616 | |
| 1617 | NotificationService::current()->Notify( |
| 1618 | NotificationType::LOAD_FROM_MEMORY_CACHE, |
| 1619 | Source<NavigationController>(&controller_), |
| 1620 | Details<LoadFromMemoryCacheDetails>(&details)); |
| 1621 | } |
| 1622 | |
| 1623 | void TabContents::OnDidDisplayInsecureContent() { |
| 1624 | displayed_insecure_content_ = true; |
| 1625 | SSLManager::NotifySSLInternalStateChanged(); |
| 1626 | } |
| 1627 | |
| 1628 | void TabContents::OnDidRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 1629 | const std::string& security_origin, const GURL& target_url) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1630 | controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
| 1631 | } |
| 1632 | |
| 1633 | void TabContents::OnDocumentLoadedInFrame(int64 frame_id) { |
| 1634 | controller_.DocumentLoadedInFrame(); |
| 1635 | NotificationService::current()->Notify( |
| 1636 | NotificationType::FRAME_DOM_CONTENT_LOADED, |
| 1637 | Source<NavigationController>(&controller_), |
| 1638 | Details<int64>(&frame_id)); |
| 1639 | } |
| 1640 | |
| 1641 | void TabContents::OnDidFinishLoad(int64 frame_id) { |
| 1642 | NotificationService::current()->Notify( |
| 1643 | NotificationType::FRAME_DID_FINISH_LOAD, |
| 1644 | Source<NavigationController>(&controller_), |
| 1645 | Details<int64>(&frame_id)); |
| 1646 | } |
| 1647 | |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 1648 | void TabContents::OnUpdateContentRestrictions(int restrictions) { |
| 1649 | content_restrictions_ = restrictions; |
| 1650 | delegate()->ContentRestrictionsChanged(this); |
| 1651 | } |
| 1652 | |
| 1653 | void TabContents::OnPDFHasUnsupportedFeature() { |
| 1654 | PDFHasUnsupportedFeature(this); |
| 1655 | } |
| 1656 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1657 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 1658 | // loading, or done loading and calls the base implementation. |
| 1659 | void TabContents::SetIsLoading(bool is_loading, |
| 1660 | LoadNotificationDetails* details) { |
| 1661 | if (is_loading == is_loading_) |
| 1662 | return; |
| 1663 | |
| 1664 | if (!is_loading) { |
| 1665 | load_state_ = net::LOAD_STATE_IDLE; |
| 1666 | load_state_host_.clear(); |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 1667 | upload_size_ = 0; |
| 1668 | upload_position_ = 0; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | render_manager_.SetIsLoading(is_loading); |
| 1672 | |
| 1673 | is_loading_ = is_loading; |
| 1674 | waiting_for_response_ = is_loading; |
| 1675 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1676 | if (delegate_) |
| 1677 | delegate_->LoadingStateChanged(this); |
[email protected] | 329581b | 2009-04-28 06:52:35 | [diff] [blame] | 1678 | NotifyNavigationStateChanged(INVALIDATE_LOAD); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1679 | |
| 1680 | NotificationType type = is_loading ? NotificationType::LOAD_START : |
| 1681 | NotificationType::LOAD_STOP; |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1682 | NotificationDetails det = NotificationService::NoDetails(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1683 | if (details) |
| 1684 | det = Details<LoadNotificationDetails>(details); |
| 1685 | NotificationService::current()->Notify(type, |
| 1686 | Source<NavigationController>(&controller_), |
| 1687 | det); |
| 1688 | } |
| 1689 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 1690 | void TabContents::AddPopup(TabContents* new_contents, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1691 | const gfx::Rect& initial_pos) { |
[email protected] | 57eda82a | 2010-05-05 21:28:06 | [diff] [blame] | 1692 | // A page can't spawn popups (or do anything else, either) until its load |
| 1693 | // commits, so when we reach here, the popup was spawned by the |
| 1694 | // NavigationController's last committed entry, not the active entry. For |
| 1695 | // example, if a page opens a popup in an onunload() handler, then the active |
| 1696 | // entry is the page to be loaded as we navigate away from the unloading |
| 1697 | // page. For this reason, we can't use GetURL() to get the opener URL, |
| 1698 | // because it returns the active entry. |
| 1699 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 1700 | GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL(); |
| 1701 | |
| 1702 | if (creator.is_valid() && |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1703 | profile()->GetHostContentSettingsMap()->GetContentSetting( |
[email protected] | ca35245 | 2010-08-06 11:14:09 | [diff] [blame] | 1704 | creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) { |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1705 | AddNewContents(new_contents, NEW_POPUP, initial_pos, true); |
| 1706 | } else { |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1707 | if (!blocked_contents_) |
| 1708 | blocked_contents_ = new BlockedContentContainer(this); |
| 1709 | blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos, |
| 1710 | true); |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 1711 | content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS, |
| 1712 | std::string()); |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1713 | } |
[email protected] | b968131 | 2008-11-07 00:08:26 | [diff] [blame] | 1714 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1715 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1716 | void TabContents::ExpireInfoBars( |
| 1717 | const NavigationController::LoadCommittedDetails& details) { |
| 1718 | // Only hide InfoBars when the user has done something that makes the main |
| 1719 | // frame load. We don't want various automatic or subframe navigations making |
| 1720 | // it disappear. |
| 1721 | if (!details.is_user_initiated_main_frame_load()) |
| 1722 | return; |
| 1723 | |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 1724 | for (int i = infobar_delegate_count() - 1; i >= 0; --i) { |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1725 | InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 1726 | if (delegate->ShouldExpire(details)) |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1727 | RemoveInfoBar(delegate); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1728 | } |
| 1729 | } |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 1730 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1731 | DOMUI* TabContents::GetDOMUIForCurrentState() { |
| 1732 | // When there is a pending navigation entry, we want to use the pending DOMUI |
| 1733 | // that goes along with it to control the basic flags. For example, we want to |
| 1734 | // show the pending URL in the URL bar, so we want the display_url flag to |
| 1735 | // be from the pending entry. |
| 1736 | // |
| 1737 | // The confusion comes because there are multiple possibilities for the |
| 1738 | // initial load in a tab as a side effect of the way the RenderViewHostManager |
| 1739 | // works. |
| 1740 | // |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1741 | // - For the very first tab the load looks "normal". The new tab Web UI is |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1742 | // the pending one, and we want it to apply here. |
| 1743 | // |
| 1744 | // - For subsequent new tabs, they'll get a new SiteInstance which will then |
| 1745 | // get switched to the one previously associated with the new tab pages. |
| 1746 | // This switching will cause the manager to commit the RVH/DOMUI. So we'll |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1747 | // have a committed Web UI in this case. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1748 | // |
| 1749 | // This condition handles all of these cases: |
| 1750 | // |
| 1751 | // - First load in first tab: no committed nav entry + pending nav entry + |
| 1752 | // pending dom ui: |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1753 | // -> Use pending Web UI if any. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1754 | // |
| 1755 | // - First load in second tab: no committed nav entry + pending nav entry + |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1756 | // no pending Web UI: |
| 1757 | // -> Use the committed Web UI if any. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1758 | // |
| 1759 | // - Second navigation in any tab: committed nav entry + pending nav entry: |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1760 | // -> Use pending Web UI if any. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1761 | // |
| 1762 | // - Normal state with no load: committed nav entry + no pending nav entry: |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1763 | // -> Use committed Web UI. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1764 | if (controller_.pending_entry() && |
| 1765 | (controller_.GetLastCommittedEntry() || |
| 1766 | render_manager_.pending_dom_ui())) |
| 1767 | return render_manager_.pending_dom_ui(); |
| 1768 | return render_manager_.dom_ui(); |
| 1769 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1770 | |
| 1771 | void TabContents::DidNavigateMainFramePostCommit( |
| 1772 | const NavigationController::LoadCommittedDetails& details, |
| 1773 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1774 | if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) { |
| 1775 | // If this is a window.open navigation, use the same WebUI as the renderer |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1776 | // that opened the window, as long as both renderers have the same |
| 1777 | // privileges. |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1778 | if (opener_web_ui_type_ == |
| 1779 | WebUIFactory::GetWebUIType(profile(), GetURL())) { |
| 1780 | DOMUI* dom_ui = WebUIFactory::CreateWebUIForURL(this, GetURL()); |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1781 | // dom_ui might be NULL if the URL refers to a non-existent extension. |
| 1782 | if (dom_ui) { |
| 1783 | render_manager_.SetDOMUIPostCommit(dom_ui); |
| 1784 | dom_ui->RenderViewCreated(render_view_host()); |
| 1785 | } |
| 1786 | } |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1787 | opener_web_ui_type_ = WebUIFactory::kNoWebUI; |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1788 | } |
| 1789 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1790 | if (details.is_user_initiated_main_frame_load()) { |
| 1791 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1792 | // doesn't let us know that the cursor left an element during a |
| 1793 | // transition (this is also why the mouse cursor remains as a hand after |
| 1794 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1795 | // clear the bubble when a user navigates to a named anchor in the same |
| 1796 | // page. |
| 1797 | UpdateTargetURL(details.entry->page_id(), GURL()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | // The keyword generator uses the navigation entries, so must be called after |
| 1801 | // the commit. |
| 1802 | GenerateKeywordIfNecessary(params); |
| 1803 | |
| 1804 | // Allow the new page to set the title again. |
| 1805 | received_page_title_ = false; |
| 1806 | |
| 1807 | // Get the favicon, either from history or request it from the net. |
| 1808 | fav_icon_helper_.FetchFavIcon(details.entry->url()); |
| 1809 | |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1810 | // Clear all page actions, blocked content notifications and browser actions |
| 1811 | // for this tab, unless this is an in-page navigation. |
[email protected] | a6e82fc | 2010-02-24 22:28:14 | [diff] [blame] | 1812 | if (!details.is_in_page) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1813 | ExtensionService* service = profile()->GetExtensionService(); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1814 | if (service) { |
| 1815 | for (size_t i = 0; i < service->extensions()->size(); ++i) { |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 1816 | ExtensionAction* browser_action = |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1817 | service->extensions()->at(i)->browser_action(); |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 1818 | if (browser_action) { |
| 1819 | browser_action->ClearAllValuesForTab(controller().session_id().id()); |
| 1820 | NotificationService::current()->Notify( |
| 1821 | NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 1822 | Source<ExtensionAction>(browser_action), |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 1823 | NotificationService::NoDetails()); |
| 1824 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1825 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 1826 | ExtensionAction* page_action = |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 1827 | service->extensions()->at(i)->page_action(); |
| 1828 | if (page_action) { |
| 1829 | page_action->ClearAllValuesForTab(controller().session_id().id()); |
| 1830 | PageActionStateChanged(); |
| 1831 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1832 | } |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 1833 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1834 | |
| 1835 | // Close blocked popups. |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1836 | if (blocked_contents_) { |
[email protected] | 0fbd7033 | 2010-06-01 19:28:34 | [diff] [blame] | 1837 | AutoReset<bool> auto_reset(&dont_notify_render_view_, true); |
[email protected] | c65e2f15 | 2010-10-14 15:30:40 | [diff] [blame] | 1838 | blocked_contents_->Destroy(); |
| 1839 | blocked_contents_ = NULL; |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | // Clear "blocked" flags. |
[email protected] | da4f8a1 | 2010-08-19 08:33:41 | [diff] [blame] | 1843 | content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies(); |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 1844 | content_settings_delegate_->GeolocationDidNavigate(details); |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 1845 | |
| 1846 | // Once the main frame is navigated, we're no longer considered to have |
| 1847 | // displayed insecure content. |
| 1848 | displayed_insecure_content_ = false; |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 1849 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1850 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1851 | // Close constrained windows if necessary. |
| 1852 | if (!net::RegistryControlledDomainService::SameDomainOrHost( |
| 1853 | details.previous_url, details.entry->url())) |
| 1854 | CloseConstrainedWindows(); |
| 1855 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1856 | // Notify observers about navigation. |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 1857 | FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1858 | DidNavigateMainFramePostCommit(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | void TabContents::DidNavigateAnyFramePostCommit( |
| 1862 | RenderViewHost* render_view_host, |
| 1863 | const NavigationController::LoadCommittedDetails& details, |
| 1864 | const ViewHostMsg_FrameNavigate_Params& params) { |
| 1865 | // If we navigate, start showing messages again. This does nothing to prevent |
| 1866 | // a malicious script from spamming messages, since the script could just |
| 1867 | // reload the page to stop blocking. |
| 1868 | suppress_javascript_messages_ = false; |
| 1869 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1870 | // Notify observers about navigation. |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 1871 | FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1872 | DidNavigateAnyFramePostCommit(details, params)); |
[email protected] | 3b1c181 | 2010-02-12 21:53:55 | [diff] [blame] | 1873 | |
| 1874 | // Let the LanguageState clear its state. |
[email protected] | 80fc611 | 2010-08-13 20:10:58 | [diff] [blame] | 1875 | language_state_.DidNavigate(details); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1876 | } |
| 1877 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1878 | void TabContents::CloseConstrainedWindows() { |
| 1879 | // Clear out any constrained windows since we are leaving this page entirely. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1880 | // We use indices instead of iterators in case CloseWindow does something |
| 1881 | // that may invalidate an iterator. |
[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 1882 | for (size_t i = 0; i < child_windows_.size(); ++i) { |
| 1883 | ConstrainedWindow* window = child_windows_[child_windows_.size() - 1 - i]; |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1884 | if (window) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1885 | window->CloseConstrainedWindow(); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1886 | BlockTabContent(false); |
| 1887 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1888 | } |
| 1889 | } |
| 1890 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1891 | void TabContents::UpdateAlternateErrorPageURL() { |
| 1892 | GURL url = GetAlternateErrorPageURL(); |
| 1893 | render_view_host()->SetAlternateErrorPageURL(url); |
| 1894 | } |
| 1895 | |
| 1896 | void TabContents::UpdateWebPreferences() { |
| 1897 | render_view_host()->UpdateWebPreferences(GetWebkitPrefs()); |
| 1898 | } |
| 1899 | |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1900 | void TabContents::UpdateZoomLevel() { |
| 1901 | render_view_host()->SetZoomLevel(GetZoomLevel()); |
| 1902 | } |
| 1903 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1904 | void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
| 1905 | RenderViewHost* rvh) { |
| 1906 | // If we are creating a RVH for a restored controller, then we might |
| 1907 | // have more page IDs than the SiteInstance's current max page ID. We must |
| 1908 | // make sure that the max page ID is larger than any restored page ID. |
| 1909 | // Note that it is ok for conflicting page IDs to exist in another tab |
| 1910 | // (i.e., NavigationController), but if any page ID is larger than the max, |
| 1911 | // the back/forward list will get confused. |
| 1912 | int max_restored_page_id = controller_.max_restored_page_id(); |
| 1913 | if (max_restored_page_id > 0) { |
| 1914 | int curr_max_page_id = site_instance->max_page_id(); |
| 1915 | if (max_restored_page_id > curr_max_page_id) { |
| 1916 | // Need to update the site instance immediately. |
| 1917 | site_instance->UpdateMaxPageID(max_restored_page_id); |
| 1918 | |
| 1919 | // Also tell the renderer to update its internal representation. We |
| 1920 | // need to reserve enough IDs to make all restored page IDs less than |
| 1921 | // the max. |
| 1922 | if (curr_max_page_id < 0) |
| 1923 | curr_max_page_id = 0; |
| 1924 | rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id); |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1929 | scoped_refptr<history::HistoryAddPageArgs> |
| 1930 | TabContents::CreateHistoryAddPageArgs( |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1931 | const GURL& virtual_url, |
[email protected] | befd8d82 | 2009-07-01 04:51:47 | [diff] [blame] | 1932 | const NavigationController::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1933 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1934 | scoped_refptr<history::HistoryAddPageArgs> add_page_args( |
| 1935 | new history::HistoryAddPageArgs( |
| 1936 | params.url, base::Time::Now(), this, params.page_id, params.referrer, |
| 1937 | params.redirects, params.transition, history::SOURCE_BROWSED, |
| 1938 | details.did_replace_entry)); |
| 1939 | if (PageTransition::IsMainFrame(params.transition) && |
| 1940 | virtual_url != params.url) { |
| 1941 | // Hack on the "virtual" URL so that it will appear in history. For some |
| 1942 | // types of URLs, we will display a magic URL that is different from where |
| 1943 | // the page is actually navigated. We want the user to see in history what |
| 1944 | // they saw in the URL bar, so we add the virtual URL as a redirect. This |
| 1945 | // only applies to the main frame, as the virtual URL doesn't apply to |
| 1946 | // sub-frames. |
| 1947 | add_page_args->url = virtual_url; |
| 1948 | if (!add_page_args->redirects.empty()) |
| 1949 | add_page_args->redirects.back() = virtual_url; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1950 | } |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1951 | return add_page_args; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | bool TabContents::UpdateTitleForEntry(NavigationEntry* entry, |
| 1955 | const std::wstring& title) { |
| 1956 | // For file URLs without a title, use the pathname instead. In the case of a |
| 1957 | // synthesized title, we don't want the update to count toward the "one set |
| 1958 | // per page of the title to history." |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1959 | string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1960 | bool explicit_set; |
| 1961 | if (entry->url().SchemeIsFile() && title.empty()) { |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1962 | final_title = UTF8ToUTF16(entry->url().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1963 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 1964 | } else { |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1965 | TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1966 | explicit_set = true; |
| 1967 | } |
| 1968 | |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1969 | if (final_title == entry->title()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1970 | return false; // Nothing changed, don't bother. |
| 1971 | |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1972 | entry->set_title(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1973 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1974 | if (!received_page_title_) { |
| 1975 | UpdateHistoryPageTitle(*entry); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1976 | received_page_title_ = explicit_set; |
| 1977 | } |
| 1978 | |
| 1979 | // Lastly, set the title for the view. |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1980 | view_->SetPageTitle(UTF16ToWideHack(final_title)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1981 | |
[email protected] | cbc0e1b | 2010-04-12 18:33:04 | [diff] [blame] | 1982 | NotificationService::current()->Notify( |
| 1983 | NotificationType::TAB_CONTENTS_TITLE_UPDATED, |
| 1984 | Source<TabContents>(this), |
| 1985 | NotificationService::NoDetails()); |
| 1986 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1987 | return true; |
| 1988 | } |
| 1989 | |
| 1990 | void TabContents::NotifySwapped() { |
| 1991 | // After sending out a swap notification, we need to send a disconnect |
| 1992 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 1993 | // pointer. See Bug 1230284. |
| 1994 | notify_disconnection_ = true; |
| 1995 | NotificationService::current()->Notify( |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1996 | NotificationType::TAB_CONTENTS_SWAPPED, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1997 | Source<TabContents>(this), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1998 | NotificationService::NoDetails()); |
| 1999 | } |
| 2000 | |
| 2001 | void TabContents::NotifyConnected() { |
| 2002 | notify_disconnection_ = true; |
| 2003 | NotificationService::current()->Notify( |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2004 | NotificationType::TAB_CONTENTS_CONNECTED, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2005 | Source<TabContents>(this), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2006 | NotificationService::NoDetails()); |
| 2007 | } |
| 2008 | |
| 2009 | void TabContents::NotifyDisconnected() { |
| 2010 | if (!notify_disconnection_) |
| 2011 | return; |
| 2012 | |
| 2013 | notify_disconnection_ = false; |
| 2014 | NotificationService::current()->Notify( |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2015 | NotificationType::TAB_CONTENTS_DISCONNECTED, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2016 | Source<TabContents>(this), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2017 | NotificationService::NoDetails()); |
| 2018 | } |
| 2019 | |
| 2020 | void TabContents::GenerateKeywordIfNecessary( |
| 2021 | const ViewHostMsg_FrameNavigate_Params& params) { |
| 2022 | if (!params.searchable_form_url.is_valid()) |
| 2023 | return; |
| 2024 | |
| 2025 | if (profile()->IsOffTheRecord()) |
| 2026 | return; |
| 2027 | |
| 2028 | int last_index = controller_.last_committed_entry_index(); |
| 2029 | // When there was no previous page, the last index will be 0. This is |
| 2030 | // normally due to a form submit that opened in a new tab. |
| 2031 | // TODO(brettw) bug 916126: we should support keywords when form submits |
| 2032 | // happen in new tabs. |
| 2033 | if (last_index <= 0) |
| 2034 | return; |
| 2035 | const NavigationEntry* previous_entry = |
| 2036 | controller_.GetEntryAtIndex(last_index - 1); |
| 2037 | if (IsFormSubmit(previous_entry)) { |
| 2038 | // Only generate a keyword if the previous page wasn't itself a form |
| 2039 | // submit. |
| 2040 | return; |
| 2041 | } |
| 2042 | |
| 2043 | GURL keyword_url = previous_entry->user_typed_url().is_valid() ? |
| 2044 | previous_entry->user_typed_url() : previous_entry->url(); |
[email protected] | 400b133f | 2011-01-19 18:32:30 | [diff] [blame] | 2045 | string16 keyword = |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2046 | TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected |
| 2047 | if (keyword.empty()) |
| 2048 | return; |
| 2049 | |
| 2050 | TemplateURLModel* url_model = profile()->GetTemplateURLModel(); |
| 2051 | if (!url_model) |
| 2052 | return; |
| 2053 | |
| 2054 | if (!url_model->loaded()) { |
| 2055 | url_model->Load(); |
| 2056 | return; |
| 2057 | } |
| 2058 | |
| 2059 | const TemplateURL* current_url; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2060 | GURL url = params.searchable_form_url; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2061 | if (!url_model->CanReplaceKeyword(keyword, url, ¤t_url)) |
| 2062 | return; |
| 2063 | |
| 2064 | if (current_url) { |
| 2065 | if (current_url->originating_url().is_valid()) { |
| 2066 | // The existing keyword was generated from an OpenSearch description |
| 2067 | // document, don't regenerate. |
| 2068 | return; |
| 2069 | } |
| 2070 | url_model->Remove(current_url); |
| 2071 | } |
| 2072 | TemplateURL* new_url = new TemplateURL(); |
| 2073 | new_url->set_keyword(keyword); |
| 2074 | new_url->set_short_name(keyword); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2075 | new_url->SetURL(url.spec(), 0, 0); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2076 | new_url->add_input_encoding(params.searchable_form_encoding); |
| 2077 | DCHECK(controller_.GetLastCommittedEntry()); |
| 2078 | const GURL& favicon_url = |
| 2079 | controller_.GetLastCommittedEntry()->favicon().url(); |
| 2080 | if (favicon_url.is_valid()) { |
| 2081 | new_url->SetFavIconURL(favicon_url); |
| 2082 | } else { |
| 2083 | // The favicon url isn't valid. This means there really isn't a favicon, |
| 2084 | // or the favicon url wasn't obtained before the load started. This assumes |
| 2085 | // the later. |
| 2086 | // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 2087 | // its url. |
| 2088 | new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
| 2089 | } |
| 2090 | new_url->set_safe_for_autoreplace(true); |
| 2091 | url_model->Add(new_url); |
| 2092 | } |
| 2093 | |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2094 | void TabContents::OnGoToEntryAtOffset(int offset) { |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 2095 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
| 2096 | NavigationEntry* entry = controller_.GetEntryAtOffset(offset); |
| 2097 | if (!entry) |
| 2098 | return; |
| 2099 | // Note that we don't call NavigationController::GotToOffset() as we don't |
| 2100 | // want to create a pending navigation entry (it might end up lingering |
| 2101 | // http://crbug.com/51680). |
[email protected] | 784688a6 | 2010-09-13 07:06:52 | [diff] [blame] | 2102 | entry->set_transition_type(entry->transition_type() | |
| 2103 | PageTransition::FORWARD_BACK); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 2104 | NavigateToEntry(*entry, NavigationController::NO_RELOAD); |
| 2105 | } |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2106 | } |
| 2107 | |
[email protected] | 38789d8 | 2010-11-17 06:03:44 | [diff] [blame] | 2108 | void TabContents::OnDidGetApplicationInfo(int32 page_id, |
| 2109 | const WebApplicationInfo& info) { |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 2110 | web_app_info_ = info; |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2111 | |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 2112 | if (delegate()) |
| 2113 | delegate()->OnDidGetApplicationInfo(this, page_id); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2114 | } |
| 2115 | |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 2116 | void TabContents::OnInstallApplication(const WebApplicationInfo& info) { |
| 2117 | if (delegate()) |
| 2118 | delegate()->OnInstallApplication(this, info); |
| 2119 | } |
| 2120 | |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2121 | void TabContents::OnPageContents(const GURL& url, |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2122 | int32 page_id, |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 2123 | const string16& contents, |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 2124 | const std::string& language, |
| 2125 | bool page_translatable) { |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2126 | // Don't index any https pages. People generally don't want their bank |
| 2127 | // accounts, etc. indexed on their computer, especially since some of these |
| 2128 | // things are not marked cachable. |
| 2129 | // TODO(brettw) we may want to consider more elaborate heuristics such as |
| 2130 | // the cachability of the page. We may also want to consider subframes (this |
| 2131 | // test will still index subframes if the subframe is SSL). |
[email protected] | ccd40a5 | 2010-05-11 16:15:27 | [diff] [blame] | 2132 | // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable |
| 2133 | // content indexing for chromeos in some future releases. |
| 2134 | #if !defined(OS_CHROMEOS) |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2135 | if (!url.SchemeIsSecure()) { |
| 2136 | Profile* p = profile(); |
| 2137 | if (p && !p->IsOffTheRecord()) { |
| 2138 | HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 2139 | if (hs) |
| 2140 | hs->SetPageContents(url, contents); |
| 2141 | } |
| 2142 | } |
[email protected] | ccd40a5 | 2010-05-11 16:15:27 | [diff] [blame] | 2143 | #endif |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 2144 | |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 2145 | language_state_.LanguageDetermined(language, page_translatable); |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 2146 | |
| 2147 | std::string lang = language; |
| 2148 | NotificationService::current()->Notify( |
| 2149 | NotificationType::TAB_LANGUAGE_DETERMINED, |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 2150 | Source<TabContents>(this), |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 2151 | Details<std::string>(&lang)); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 2152 | |
| 2153 | // Generate the thumbnail here if the in-browser thumbnailing is enabled. |
| 2154 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2155 | switches::kEnableInBrowserThumbnailing)) { |
| 2156 | ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url); |
| 2157 | } |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2158 | } |
| 2159 | |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 2160 | void TabContents::OnPageTranslated(int32 page_id, |
| 2161 | const std::string& original_lang, |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 2162 | const std::string& translated_lang, |
| 2163 | TranslateErrors::Type error_type) { |
[email protected] | 3b1c181 | 2010-02-12 21:53:55 | [diff] [blame] | 2164 | language_state_.set_current_language(translated_lang); |
| 2165 | language_state_.set_translation_pending(false); |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 2166 | PageTranslatedDetails details(original_lang, translated_lang, error_type); |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 2167 | NotificationService::current()->Notify( |
| 2168 | NotificationType::PAGE_TRANSLATED, |
| 2169 | Source<TabContents>(this), |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 2170 | Details<PageTranslatedDetails>(&details)); |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 2171 | } |
| 2172 | |
[email protected] | ce83328 | 2010-11-04 15:48:39 | [diff] [blame] | 2173 | void TabContents::OnSetSuggestions( |
| 2174 | int32 page_id, |
| 2175 | const std::vector<std::string>& suggestions) { |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 2176 | if (delegate()) |
[email protected] | ce83328 | 2010-11-04 15:48:39 | [diff] [blame] | 2177 | delegate()->OnSetSuggestions(page_id, suggestions); |
| 2178 | } |
| 2179 | |
| 2180 | void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) { |
| 2181 | if (delegate()) |
| 2182 | delegate()->OnInstantSupportDetermined(page_id, result); |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 2183 | } |
| 2184 | |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 2185 | void TabContents::OnRunFileChooser( |
| 2186 | const ViewHostMsg_RunFileChooser_Params& params) { |
| 2187 | if (file_select_helper_.get() == NULL) |
| 2188 | file_select_helper_.reset(new FileSelectHelper(profile())); |
| 2189 | file_select_helper_->RunFileChooser(render_view_host(), params); |
| 2190 | } |
| 2191 | |
| 2192 | |
[email protected] | dcd5b33 | 2010-08-11 08:55:18 | [diff] [blame] | 2193 | void TabContents::OnContentSettingsAccessed(bool content_was_blocked) { |
[email protected] | 614c0e1 | 2010-03-25 10:12:56 | [diff] [blame] | 2194 | if (delegate_) |
[email protected] | 20ad6a9 | 2010-04-21 14:07:24 | [diff] [blame] | 2195 | delegate_->OnContentSettingsChange(this); |
[email protected] | 614c0e1 | 2010-03-25 10:12:56 | [diff] [blame] | 2196 | } |
| 2197 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2198 | RenderViewHostDelegate::View* TabContents::GetViewDelegate() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2199 | return view_.get(); |
| 2200 | } |
| 2201 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2202 | RenderViewHostDelegate::RendererManagement* |
| 2203 | TabContents::GetRendererManagementDelegate() { |
| 2204 | return &render_manager_; |
| 2205 | } |
| 2206 | |
[email protected] | 46ba908 | 2010-06-22 10:00:58 | [diff] [blame] | 2207 | RenderViewHostDelegate::ContentSettings* |
| 2208 | TabContents::GetContentSettingsDelegate() { |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 2209 | return content_settings_delegate_.get(); |
[email protected] | 46ba908 | 2010-06-22 10:00:58 | [diff] [blame] | 2210 | } |
| 2211 | |
[email protected] | 1f18184a | 2010-07-21 19:34:49 | [diff] [blame] | 2212 | RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() { |
| 2213 | return GetSSLHelper(); |
| 2214 | } |
| 2215 | |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 2216 | AutomationResourceRoutingDelegate* |
| 2217 | TabContents::GetAutomationResourceRoutingDelegate() { |
| 2218 | return delegate(); |
| 2219 | } |
| 2220 | |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 2221 | RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() { |
| 2222 | return bookmark_drag_; |
| 2223 | } |
| 2224 | |
| 2225 | void TabContents::SetBookmarkDragDelegate( |
| 2226 | RenderViewHostDelegate::BookmarkDrag* bookmark_drag) { |
| 2227 | bookmark_drag_ = bookmark_drag; |
| 2228 | } |
| 2229 | |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 2230 | TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const { |
| 2231 | return content_settings_delegate_.get(); |
| 2232 | } |
| 2233 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 2234 | RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 2235 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 2236 | } |
| 2237 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2238 | TabContents* TabContents::GetAsTabContents() { |
| 2239 | return this; |
| 2240 | } |
| 2241 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 2242 | ViewType::Type TabContents::GetRenderViewType() const { |
| 2243 | return ViewType::TAB_CONTENTS; |
| 2244 | } |
| 2245 | |
| 2246 | int TabContents::GetBrowserWindowID() const { |
| 2247 | return controller().window_id().id(); |
| 2248 | } |
| 2249 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2250 | void TabContents::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2251 | NotificationService::current()->Notify( |
| 2252 | NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 2253 | Source<TabContents>(this), |
| 2254 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2255 | NavigationEntry* entry = controller_.GetActiveEntry(); |
| 2256 | if (!entry) |
| 2257 | return; |
| 2258 | |
| 2259 | // When we're creating views, we're still doing initial setup, so we always |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2260 | // use the pending Web UI rather than any possibly existing committed one. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2261 | if (render_manager_.pending_dom_ui()) { |
| 2262 | render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host); |
| 2263 | } |
| 2264 | |
| 2265 | if (entry->IsViewSourceMode()) { |
| 2266 | // Put the renderer in view source mode. |
| 2267 | render_view_host->Send( |
| 2268 | new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
| 2269 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 2270 | |
| 2271 | view()->RenderViewCreated(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | void TabContents::RenderViewReady(RenderViewHost* rvh) { |
| 2275 | if (rvh != render_view_host()) { |
| 2276 | // Don't notify the world, since this came from a renderer in the |
| 2277 | // background. |
| 2278 | return; |
| 2279 | } |
| 2280 | |
| 2281 | NotifyConnected(); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2282 | bool was_crashed = is_crashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2283 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2284 | |
| 2285 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 2286 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 2287 | if (was_crashed && !FocusLocationBarByDefault() && |
| 2288 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2289 | Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 2290 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2291 | } |
| 2292 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2293 | void TabContents::RenderViewGone(RenderViewHost* rvh, |
| 2294 | base::TerminationStatus status, |
| 2295 | int error_code) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2296 | // Ask the print preview if this renderer was valuable. |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 2297 | if (!printing_->OnRenderViewGone(rvh)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2298 | return; |
| 2299 | if (rvh != render_view_host()) { |
| 2300 | // The pending page's RenderViewHost is gone. |
| 2301 | return; |
| 2302 | } |
| 2303 | |
| 2304 | SetIsLoading(false, NULL); |
| 2305 | NotifyDisconnected(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2306 | SetIsCrashed(status, error_code); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2307 | |
[email protected] | ff9efc6 | 2010-02-18 22:10:54 | [diff] [blame] | 2308 | // Remove all infobars. |
[email protected] | e5430c9 | 2010-02-18 22:39:21 | [diff] [blame] | 2309 | for (int i = infobar_delegate_count() - 1; i >=0 ; --i) |
[email protected] | ff9efc6 | 2010-02-18 22:10:54 | [diff] [blame] | 2310 | RemoveInfoBar(GetInfoBarDelegateAt(i)); |
| 2311 | |
[email protected] | 8e53730 | 2009-06-10 21:19:58 | [diff] [blame] | 2312 | // Tell the view that we've crashed so it can prepare the sad tab page. |
[email protected] | cf68b09 | 2010-01-15 20:05:55 | [diff] [blame] | 2313 | // Only do this if we're not in browser shutdown, so that TabContents |
| 2314 | // objects that are not in a browser (e.g., HTML dialogs) and thus are |
| 2315 | // visible do not flash a sad tab page. |
| 2316 | if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 2317 | view_->OnTabCrashed(status, error_code); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2318 | |
| 2319 | // Hide any visible hung renderer warning for this web contents' process. |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 2320 | hung_renderer_dialog::HideForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2321 | } |
| 2322 | |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2323 | void TabContents::RenderViewDeleted(RenderViewHost* rvh) { |
| 2324 | NotificationService::current()->Notify( |
| 2325 | NotificationType::RENDER_VIEW_HOST_DELETED, |
| 2326 | Source<TabContents>(this), |
| 2327 | Details<RenderViewHost>(rvh)); |
[email protected] | fb7b79f7 | 2009-11-06 18:00:48 | [diff] [blame] | 2328 | render_manager_.RenderViewDeleted(rvh); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2329 | } |
| 2330 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2331 | void TabContents::DidNavigate(RenderViewHost* rvh, |
| 2332 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2333 | int extra_invalidate_flags = 0; |
| 2334 | |
| 2335 | if (PageTransition::IsMainFrame(params.transition)) { |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 2336 | if (MaybeUsePreloadedPage(params.url)) { |
| 2337 | return; |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 2338 | } |
| 2339 | |
[email protected] | 20ede07 | 2009-10-06 00:28:35 | [diff] [blame] | 2340 | bool was_bookmark_bar_visible = ShouldShowBookmarkBar(); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2341 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2342 | render_manager_.DidNavigateMainFrame(rvh); |
| 2343 | |
[email protected] | 20ede07 | 2009-10-06 00:28:35 | [diff] [blame] | 2344 | if (was_bookmark_bar_visible != ShouldShowBookmarkBar()) |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2345 | extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR; |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2346 | } |
| 2347 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2348 | // Update the site of the SiteInstance if it doesn't have one yet. |
| 2349 | if (!GetSiteInstance()->has_site()) |
| 2350 | GetSiteInstance()->SetSite(params.url); |
| 2351 | |
| 2352 | // Need to update MIME type here because it's referred to in |
| 2353 | // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 2354 | // determine whether or not to enable the encoding menu. |
| 2355 | // It's updated only for the main frame. For a subframe, |
| 2356 | // RenderView::UpdateURL does not set params.contents_mime_type. |
| 2357 | // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 2358 | // TODO(jungshik): Add a test for the encoding menu to avoid |
| 2359 | // regressing it again. |
| 2360 | if (PageTransition::IsMainFrame(params.transition)) |
| 2361 | contents_mime_type_ = params.contents_mime_type; |
| 2362 | |
| 2363 | NavigationController::LoadCommittedDetails details; |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2364 | bool did_navigate = controller_.RendererDidNavigate( |
| 2365 | params, extra_invalidate_flags, &details); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2366 | |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2367 | // Send notification about committed provisional loads. This notification is |
| 2368 | // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
| 2369 | // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. |
| 2370 | if (details.type != NavigationType::NAV_IGNORE) { |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2371 | // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
| 2372 | // that is not recorded in the navigation history. For the purpose of |
| 2373 | // tracking navigation events, we treat this event as a sub frame navigation |
| 2374 | // event. |
| 2375 | bool is_main_frame = did_navigate ? details.is_main_frame : false; |
| 2376 | ProvisionalLoadDetails load_details( |
| 2377 | is_main_frame, details.is_in_page, params.url, std::string(), false, |
[email protected] | dd0aafd | 2010-12-02 13:13:41 | [diff] [blame] | 2378 | false, params.frame_id); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2379 | load_details.set_transition_type(params.transition); |
| 2380 | // Whether or not a page transition was triggered by going backward or |
| 2381 | // forward in the history is only stored in the navigation controller's |
| 2382 | // entry list. |
| 2383 | if (did_navigate && |
| 2384 | (controller_.GetActiveEntry()->transition_type() & |
| 2385 | PageTransition::FORWARD_BACK)) { |
| 2386 | load_details.set_transition_type( |
| 2387 | params.transition | PageTransition::FORWARD_BACK); |
| 2388 | } |
| 2389 | NotificationService::current()->Notify( |
| 2390 | NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED, |
| 2391 | Source<NavigationController>(&controller_), |
| 2392 | Details<ProvisionalLoadDetails>(&load_details)); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2393 | } |
| 2394 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2395 | // Update history. Note that this needs to happen after the entry is complete, |
| 2396 | // which WillNavigate[Main,Sub]Frame will do before this function is called. |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 2397 | if (params.should_update_history) { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2398 | // Most of the time, the displayURL matches the loaded URL, but for about: |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 2399 | // URLs, we use a data: URL as the real value. We actually want to save the |
| 2400 | // about: URL to the history db and keep the data: URL hidden. This is what |
| 2401 | // the TabContents' URL getter does. |
| 2402 | scoped_refptr<history::HistoryAddPageArgs> add_page_args( |
| 2403 | CreateHistoryAddPageArgs(GetURL(), details, params)); |
| 2404 | if (!delegate() || |
| 2405 | delegate()->ShouldAddNavigationToHistory(*add_page_args, |
| 2406 | details.type)) { |
| 2407 | UpdateHistoryForNavigation(add_page_args); |
| 2408 | } |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2409 | } |
| 2410 | |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 2411 | if (!did_navigate) |
| 2412 | return; // No navigation happened. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2413 | |
| 2414 | // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 2415 | // for the appropriate notification (best) or you can add it to |
| 2416 | // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 2417 | // necessary, please). |
| 2418 | |
| 2419 | // Run post-commit tasks. |
| 2420 | if (details.is_main_frame) |
| 2421 | DidNavigateMainFramePostCommit(details, params); |
| 2422 | DidNavigateAnyFramePostCommit(rvh, details, params); |
| 2423 | } |
| 2424 | |
| 2425 | void TabContents::UpdateState(RenderViewHost* rvh, |
| 2426 | int32 page_id, |
| 2427 | const std::string& state) { |
| 2428 | DCHECK(rvh == render_view_host()); |
| 2429 | |
| 2430 | // We must be prepared to handle state updates for any page, these occur |
| 2431 | // when the user is scrolling and entering form data, as well as when we're |
| 2432 | // leaving a page, in which case our state may have already been moved to |
| 2433 | // the next page. The navigation controller will look up the appropriate |
| 2434 | // NavigationEntry and update it when it is notified via the delegate. |
| 2435 | |
| 2436 | int entry_index = controller_.GetEntryIndexWithPageID( |
| 2437 | GetSiteInstance(), page_id); |
| 2438 | if (entry_index < 0) |
| 2439 | return; |
| 2440 | NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
| 2441 | |
| 2442 | if (state == entry->content_state()) |
| 2443 | return; // Nothing to update. |
| 2444 | entry->set_content_state(state); |
| 2445 | controller_.NotifyEntryChanged(entry, entry_index); |
| 2446 | } |
| 2447 | |
| 2448 | void TabContents::UpdateTitle(RenderViewHost* rvh, |
| 2449 | int32 page_id, const std::wstring& title) { |
| 2450 | // If we have a title, that's a pretty good indication that we've started |
| 2451 | // getting useful data. |
| 2452 | SetNotWaitingForResponse(); |
| 2453 | |
| 2454 | DCHECK(rvh == render_view_host()); |
[email protected] | 371cc8b | 2010-09-01 16:03:48 | [diff] [blame] | 2455 | NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(), |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 2456 | page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2457 | if (!entry || !UpdateTitleForEntry(entry, title)) |
| 2458 | return; |
| 2459 | |
| 2460 | // Broadcast notifications when the UI should be updated. |
| 2461 | if (entry == controller_.GetEntryAtOffset(0)) |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2462 | NotifyNavigationStateChanged(INVALIDATE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2463 | } |
| 2464 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2465 | void TabContents::UpdateEncoding(RenderViewHost* render_view_host, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2466 | const std::string& encoding) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2467 | set_encoding(encoding); |
| 2468 | } |
| 2469 | |
| 2470 | void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { |
| 2471 | if (delegate()) |
| 2472 | delegate()->UpdateTargetURL(this, url); |
| 2473 | } |
| 2474 | |
| 2475 | void TabContents::UpdateThumbnail(const GURL& url, |
| 2476 | const SkBitmap& bitmap, |
| 2477 | const ThumbnailScore& score) { |
[email protected] | e6baed56 | 2010-11-02 22:33:44 | [diff] [blame] | 2478 | if (profile()->IsOffTheRecord()) |
| 2479 | return; |
| 2480 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2481 | // Tell History about this thumbnail |
[email protected] | 54097492f | 2011-01-18 08:32:07 | [diff] [blame] | 2482 | history::TopSites* ts = profile()->GetTopSites(); |
| 2483 | if (ts) |
| 2484 | ts->SetPageThumbnail(url, bitmap, score); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2485 | } |
| 2486 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2487 | void TabContents::UpdateInspectorSetting(const std::string& key, |
| 2488 | const std::string& value) { |
[email protected] | 24d27d7 | 2010-10-12 16:30:05 | [diff] [blame] | 2489 | RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value); |
[email protected] | 0df3012 | 2009-06-03 12:13:08 | [diff] [blame] | 2490 | } |
| 2491 | |
[email protected] | 45aafc9 | 2010-06-07 14:18:53 | [diff] [blame] | 2492 | void TabContents::ClearInspectorSettings() { |
[email protected] | 24d27d7 | 2010-10-12 16:30:05 | [diff] [blame] | 2493 | RenderViewHostDelegateHelper::ClearInspectorSettings(profile()); |
[email protected] | 45aafc9 | 2010-06-07 14:18:53 | [diff] [blame] | 2494 | } |
| 2495 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2496 | void TabContents::Close(RenderViewHost* rvh) { |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 2497 | // The UI may be in an event-tracking loop, such as between the |
| 2498 | // mouse-down and mouse-up in text selection or a button click. |
| 2499 | // Defer the close until after tracking is complete, so that we |
| 2500 | // don't free objects out from under the UI. |
| 2501 | // TODO(shess): This could probably be integrated with the |
| 2502 | // IsDoingDrag() test below. Punting for now because I need more |
| 2503 | // research to understand how this impacts platforms other than Mac. |
| 2504 | // TODO(shess): This could get more fine-grained. For instance, |
| 2505 | // closing a tab in another window while selecting text in the |
| 2506 | // current window's Omnibox should be just fine. |
| 2507 | if (view()->IsEventTracking()) { |
| 2508 | view()->CloseTabAfterEventTracking(); |
| 2509 | return; |
| 2510 | } |
| 2511 | |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 2512 | // If we close the tab while we're in the middle of a drag, we'll crash. |
| 2513 | // Instead, cancel the drag and close it as soon as the drag ends. |
| 2514 | if (view()->IsDoingDrag()) { |
| 2515 | view()->CancelDragAndCloseTab(); |
| 2516 | return; |
| 2517 | } |
| 2518 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2519 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
| 2520 | if (delegate() && rvh == render_view_host()) |
| 2521 | delegate()->CloseContents(this); |
| 2522 | } |
| 2523 | |
| 2524 | void TabContents::RequestMove(const gfx::Rect& new_bounds) { |
| 2525 | if (delegate() && delegate()->IsPopup(this)) |
| 2526 | delegate()->MoveContents(this, new_bounds); |
| 2527 | } |
| 2528 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2529 | void TabContents::DidStartLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2530 | SetIsLoading(true, NULL); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2531 | |
[email protected] | de4761b | 2010-12-07 21:05:21 | [diff] [blame] | 2532 | if (delegate()) { |
| 2533 | bool is_print_preview_tab = |
| 2534 | printing::PrintPreviewTabController::IsPrintPreviewTab(this); |
| 2535 | if (content_restrictions_ || is_print_preview_tab) { |
| 2536 | content_restrictions_= is_print_preview_tab ? |
| 2537 | CONTENT_RESTRICTION_PRINT : 0; |
| 2538 | delegate()->ContentRestrictionsChanged(this); |
| 2539 | } |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 2540 | } |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2541 | |
| 2542 | // Notify observers about navigation. |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 2543 | FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2544 | } |
| 2545 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2546 | void TabContents::DidStopLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2547 | scoped_ptr<LoadNotificationDetails> details; |
| 2548 | |
| 2549 | NavigationEntry* entry = controller_.GetActiveEntry(); |
| 2550 | // An entry may not exist for a stop when loading an initial blank page or |
| 2551 | // if an iframe injected by script into a blank page finishes loading. |
| 2552 | if (entry) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2553 | base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_; |
| 2554 | |
| 2555 | details.reset(new LoadNotificationDetails( |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 2556 | entry->virtual_url(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2557 | entry->transition_type(), |
| 2558 | elapsed, |
| 2559 | &controller_, |
| 2560 | controller_.GetCurrentEntryIndex())); |
| 2561 | } |
| 2562 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2563 | SetIsLoading(false, details.get()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2564 | |
| 2565 | // Notify observers about navigation. |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 2566 | FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2567 | } |
| 2568 | |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 2569 | void TabContents::DidChangeLoadProgress(double progress) { |
| 2570 | if (delegate()) |
| 2571 | delegate()->LoadProgressChanged(progress); |
| 2572 | } |
| 2573 | |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2574 | void TabContents::DocumentOnLoadCompletedInMainFrame( |
| 2575 | RenderViewHost* render_view_host, |
| 2576 | int32 page_id) { |
| 2577 | NotificationService::current()->Notify( |
| 2578 | NotificationType::LOAD_COMPLETED_MAIN_FRAME, |
| 2579 | Source<TabContents>(this), |
| 2580 | Details<int>(&page_id)); |
| 2581 | } |
| 2582 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2583 | void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer, |
| 2584 | WindowOpenDisposition disposition) { |
| 2585 | if (render_manager_.dom_ui()) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2586 | // When we're a Web UI, it will provide a page transition type for us (this |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2587 | // is so the new tab page can specify AUTO_BOOKMARK for automatically |
| 2588 | // generated suggestions). |
| 2589 | // |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2590 | // Note also that we hide the referrer for Web UI pages. We don't really |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 2591 | // want web sites to see a referrer of "chrome://blah" (and some |
| 2592 | // chrome: URLs might have search terms or other stuff we don't want to |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2593 | // send to the site), so we send no referrer. |
| 2594 | OpenURL(url, GURL(), disposition, |
| 2595 | render_manager_.dom_ui()->link_transition_type()); |
| 2596 | } else { |
| 2597 | OpenURL(url, referrer, disposition, PageTransition::LINK); |
| 2598 | } |
| 2599 | } |
| 2600 | |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 2601 | void TabContents::DomOperationResponse(const std::string& json_string, |
| 2602 | int automation_id) { |
| 2603 | } |
| 2604 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 2605 | void TabContents::ProcessDOMUIMessage( |
| 2606 | const ViewHostMsg_DomMessage_Params& params) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2607 | if (!render_manager_.dom_ui()) { |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 2608 | // This can happen if someone uses window.open() to open an extension URL |
| 2609 | // from a non-extension context. |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 2610 | render_view_host()->BlockExtensionRequest(params.request_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2611 | return; |
| 2612 | } |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 2613 | render_manager_.dom_ui()->ProcessDOMUIMessage(params); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | void TabContents::ProcessExternalHostMessage(const std::string& message, |
| 2617 | const std::string& origin, |
| 2618 | const std::string& target) { |
| 2619 | if (delegate()) |
| 2620 | delegate()->ForwardMessageToExternalHost(message, origin, target); |
| 2621 | } |
| 2622 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2623 | void TabContents::RunJavaScriptMessage( |
| 2624 | const std::wstring& message, |
| 2625 | const std::wstring& default_prompt, |
| 2626 | const GURL& frame_url, |
| 2627 | const int flags, |
| 2628 | IPC::Message* reply_msg, |
| 2629 | bool* did_suppress_message) { |
| 2630 | // Suppress javascript messages when requested and when inside a constrained |
| 2631 | // popup window (because that activates them and breaks them out of the |
| 2632 | // constrained window jail). |
[email protected] | 91ed49a | 2009-07-07 21:29:55 | [diff] [blame] | 2633 | // Also suppress messages when showing an interstitial. The interstitial is |
| 2634 | // shown over the previous page, we don't want the hidden page dialogs to |
| 2635 | // interfere with the interstitial. |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2636 | bool suppress_this_message = |
| 2637 | suppress_javascript_messages_ || |
| 2638 | showing_interstitial_page() || |
| 2639 | (delegate() && delegate()->ShouldSuppressDialogs()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2640 | if (delegate()) |
| 2641 | suppress_this_message |= |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 2642 | (delegate()->GetConstrainingContents(this) != this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2643 | |
| 2644 | *did_suppress_message = suppress_this_message; |
| 2645 | |
| 2646 | if (!suppress_this_message) { |
| 2647 | base::TimeDelta time_since_last_message( |
| 2648 | base::TimeTicks::Now() - last_javascript_message_dismissal_); |
| 2649 | bool show_suppress_checkbox = false; |
| 2650 | // Show a checkbox offering to suppress further messages if this message is |
| 2651 | // being displayed within kJavascriptMessageExpectedDelay of the last one. |
| 2652 | if (time_since_last_message < |
| 2653 | base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay)) |
| 2654 | show_suppress_checkbox = true; |
| 2655 | |
[email protected] | d6ad744 | 2010-09-05 19:06:52 | [diff] [blame] | 2656 | RunJavascriptMessageBox(profile(), this, frame_url, flags, message, |
| 2657 | default_prompt, show_suppress_checkbox, reply_msg); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2658 | } else { |
| 2659 | // If we are suppressing messages, just reply as is if the user immediately |
| 2660 | // pressed "Cancel". |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2661 | OnMessageBoxClosed(reply_msg, false, std::wstring()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, |
| 2666 | IPC::Message* reply_msg) { |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 2667 | if (delegate()) |
| 2668 | delegate()->WillRunBeforeUnloadConfirm(); |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2669 | if (delegate() && delegate()->ShouldSuppressDialogs()) { |
| 2670 | render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, |
| 2671 | std::wstring()); |
| 2672 | return; |
| 2673 | } |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2674 | is_showing_before_unload_dialog_ = true; |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2675 | RunBeforeUnloadDialog(this, message, reply_msg); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, |
| 2679 | const std::string& json_arguments, |
| 2680 | IPC::Message* reply_msg) { |
| 2681 | if (delegate()) { |
| 2682 | HtmlDialogUIDelegate* dialog_delegate = |
| 2683 | new ModalHtmlDialogDelegate(url, width, height, json_arguments, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2684 | reply_msg, this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2685 | delegate()->ShowHtmlDialog(dialog_delegate, NULL); |
| 2686 | } |
| 2687 | } |
| 2688 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2689 | // Checks to see if we should generate a keyword based on the OSDD, and if |
| 2690 | // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 2691 | void TabContents::PageHasOSDD( |
| 2692 | RenderViewHost* render_view_host, |
| 2693 | int32 page_id, |
| 2694 | const GURL& url, |
| 2695 | const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) { |
[email protected] | 0b5b85c | 2010-10-11 23:00:12 | [diff] [blame] | 2696 | // Make sure page_id is the current page and other basic checks. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2697 | DCHECK(url.is_valid()); |
| 2698 | if (!IsActiveEntry(page_id)) |
| 2699 | return; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2700 | if (!profile()->GetTemplateURLFetcher()) |
| 2701 | return; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2702 | if (profile()->IsOffTheRecord()) |
| 2703 | return; |
| 2704 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 2705 | TemplateURLFetcher::ProviderType provider_type; |
| 2706 | switch (msg_provider_type.type) { |
| 2707 | case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER: |
| 2708 | provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER; |
| 2709 | break; |
| 2710 | |
| 2711 | case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER: |
| 2712 | provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER; |
| 2713 | break; |
| 2714 | |
| 2715 | case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER: |
| 2716 | provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER; |
| 2717 | break; |
| 2718 | |
| 2719 | default: |
| 2720 | NOTREACHED(); |
| 2721 | return; |
| 2722 | } |
| 2723 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2724 | const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 2725 | DCHECK(entry); |
| 2726 | |
| 2727 | const NavigationEntry* base_entry = entry; |
| 2728 | if (IsFormSubmit(base_entry)) { |
| 2729 | // If the current page is a form submit, find the last page that was not |
| 2730 | // a form submit and use its url to generate the keyword from. |
| 2731 | int index = controller_.last_committed_entry_index() - 1; |
| 2732 | while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index))) |
| 2733 | index--; |
| 2734 | if (index >= 0) |
| 2735 | base_entry = controller_.GetEntryAtIndex(index); |
| 2736 | else |
| 2737 | base_entry = NULL; |
| 2738 | } |
| 2739 | |
| 2740 | // We want to use the user typed URL if available since that represents what |
| 2741 | // the user typed to get here, and fall back on the regular URL if not. |
| 2742 | if (!base_entry) |
| 2743 | return; |
| 2744 | GURL keyword_url = base_entry->user_typed_url().is_valid() ? |
| 2745 | base_entry->user_typed_url() : base_entry->url(); |
| 2746 | if (!keyword_url.is_valid()) |
| 2747 | return; |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 2748 | |
[email protected] | 400b133f | 2011-01-19 18:32:30 | [diff] [blame] | 2749 | string16 keyword = TemplateURLModel::GenerateKeyword( |
[email protected] | 0b5b85c | 2010-10-11 23:00:12 | [diff] [blame] | 2750 | keyword_url, |
| 2751 | provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER); |
[email protected] | a88dbdd5 | 2010-01-15 19:25:53 | [diff] [blame] | 2752 | |
[email protected] | 0b5b85c | 2010-10-11 23:00:12 | [diff] [blame] | 2753 | // Download the OpenSearch description document. If this is successful, a |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2754 | // new keyword will be created when done. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2755 | profile()->GetTemplateURLFetcher()->ScheduleDownload( |
| 2756 | keyword, |
| 2757 | url, |
| 2758 | base_entry->favicon().url(), |
[email protected] | 0b5b85c | 2010-10-11 23:00:12 | [diff] [blame] | 2759 | new TemplateURLFetcherUICallbacks(this), |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 2760 | provider_type); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2761 | } |
| 2762 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2763 | GURL TabContents::GetAlternateErrorPageURL() const { |
| 2764 | GURL url; |
| 2765 | // Disable alternate error pages when in OffTheRecord/Incognito mode. |
| 2766 | if (profile()->IsOffTheRecord()) |
| 2767 | return url; |
| 2768 | |
| 2769 | PrefService* prefs = profile()->GetPrefs(); |
| 2770 | DCHECK(prefs); |
| 2771 | if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
[email protected] | a33457b8 | 2009-09-21 23:07:15 | [diff] [blame] | 2772 | url = google_util::AppendGoogleLocaleParam( |
| 2773 | GURL(google_util::kLinkDoctorBaseURL)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2774 | url = google_util::AppendGoogleTLDParam(url); |
| 2775 | } |
| 2776 | return url; |
| 2777 | } |
| 2778 | |
| 2779 | WebPreferences TabContents::GetWebkitPrefs() { |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 2780 | Profile* profile = render_view_host()->process()->profile(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 2781 | bool is_dom_ui = false; |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2782 | WebPreferences web_prefs = |
| 2783 | RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui); |
| 2784 | |
[email protected] | 9beff75 | 2010-09-22 19:35:43 | [diff] [blame] | 2785 | // Force accelerated compositing and 2d canvas off for chrome: and |
| 2786 | // chrome-extension: pages. |
[email protected] | 27c790d4 | 2010-10-22 09:28:43 | [diff] [blame] | 2787 | if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || |
| 2788 | GetURL().SchemeIs(chrome::kChromeUIScheme)) { |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2789 | web_prefs.accelerated_compositing_enabled = false; |
[email protected] | 9beff75 | 2010-09-22 19:35:43 | [diff] [blame] | 2790 | web_prefs.accelerated_2d_canvas_enabled = false; |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2791 | } |
| 2792 | |
[email protected] | 3955344 | 2010-09-09 00:01:55 | [diff] [blame] | 2793 | #if defined(OS_MACOSX) |
| 2794 | // Disable accelerated compositing if IOSurface's are not supported, |
| 2795 | // as is the case in 10.5. |
| 2796 | if (!IOSurfaceSupport::Initialize()) |
| 2797 | web_prefs.accelerated_compositing_enabled = false; |
| 2798 | #endif |
| 2799 | |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2800 | return web_prefs; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2801 | } |
| 2802 | |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2803 | void TabContents::OnUserGesture() { |
| 2804 | // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. |
| 2805 | DownloadRequestLimiter* limiter = |
| 2806 | g_browser_process->download_request_limiter(); |
| 2807 | if (limiter) |
| 2808 | limiter->OnUserGesture(this); |
| 2809 | ExternalProtocolHandler::PermitLaunchUrl(); |
| 2810 | } |
| 2811 | |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 2812 | void TabContents::OnIgnoredUIEvent() { |
| 2813 | if (constrained_window_count()) { |
| 2814 | ConstrainedWindow* window = *constrained_window_begin(); |
| 2815 | window->FocusConstrainedWindow(); |
| 2816 | } |
| 2817 | } |
| 2818 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2819 | void TabContents::OnJSOutOfMemory() { |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 2820 | AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL, |
| 2821 | l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2822 | } |
| 2823 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2824 | void TabContents::OnCrossSiteResponse(int new_render_process_host_id, |
| 2825 | int new_request_id) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2826 | // Allows the TabContents to react when a cross-site response is ready to be |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2827 | // delivered to a pending RenderViewHost. We must first run the onunload |
| 2828 | // handler of the old RenderViewHost before we can allow it to proceed. |
| 2829 | render_manager_.OnCrossSiteResponse(new_render_process_host_id, |
| 2830 | new_request_id); |
| 2831 | } |
| 2832 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2833 | void TabContents::RendererUnresponsive(RenderViewHost* rvh, |
| 2834 | bool is_during_unload) { |
| 2835 | if (is_during_unload) { |
| 2836 | // Hang occurred while firing the beforeunload/unload handler. |
| 2837 | // Pretend the handler fired so tab closing continues as if it had. |
[email protected] | 829e761 | 2009-04-25 01:15:11 | [diff] [blame] | 2838 | rvh->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2839 | |
| 2840 | if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 2841 | return; |
| 2842 | |
| 2843 | // If the tab hangs in the beforeunload/unload handler there's really |
| 2844 | // nothing we can do to recover. Pretend the unload listeners have |
| 2845 | // all fired and close the tab. If the hang is in the beforeunload handler |
| 2846 | // then the user will not have the option of cancelling the close. |
| 2847 | Close(rvh); |
| 2848 | return; |
| 2849 | } |
| 2850 | |
[email protected] | 61b5009 | 2011-02-03 18:02:19 | [diff] [blame] | 2851 | if (render_view_host() && render_view_host()->IsRenderViewLive() && |
| 2852 | (!delegate() || delegate()->ShouldShowHungRendererDialog())) { |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 2853 | hung_renderer_dialog::ShowForTabContents(this); |
[email protected] | 61b5009 | 2011-02-03 18:02:19 | [diff] [blame] | 2854 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | void TabContents::RendererResponsive(RenderViewHost* render_view_host) { |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 2858 | hung_renderer_dialog::HideForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | void TabContents::LoadStateChanged(const GURL& url, |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2862 | net::LoadState load_state, |
| 2863 | uint64 upload_position, |
| 2864 | uint64 upload_size) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2865 | load_state_ = load_state; |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2866 | upload_position_ = upload_position; |
| 2867 | upload_size_ = upload_size; |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 2868 | std::wstring languages = |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2869 | UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 2870 | std::string host = url.host(); |
[email protected] | 42197a2 | 2010-12-28 23:29:42 | [diff] [blame] | 2871 | load_state_host_ = WideToUTF16Hack( |
| 2872 | net::IDNToUnicode(host.c_str(), host.size(), languages, NULL)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2873 | if (load_state_ == net::LOAD_STATE_READING_RESPONSE) |
| 2874 | SetNotWaitingForResponse(); |
| 2875 | if (is_loading()) |
[email protected] | c9cd222 | 2009-05-06 05:16:50 | [diff] [blame] | 2876 | NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2877 | } |
| 2878 | |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 2879 | bool TabContents::IsExternalTabContainer() const { |
| 2880 | if (!delegate()) |
| 2881 | return false; |
| 2882 | |
| 2883 | return delegate()->IsExternalTabContainer(); |
| 2884 | } |
| 2885 | |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 2886 | void TabContents::DidInsertCSS() { |
| 2887 | // This RVHDelegate function is used for extensions and not us. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2888 | } |
| 2889 | |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 2890 | void TabContents::FocusedNodeChanged(bool is_editable_node) { |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 2891 | NotificationService::current()->Notify( |
| 2892 | NotificationType::FOCUS_CHANGED_IN_PAGE, |
[email protected] | 4e85c11 | 2011-01-26 22:27:21 | [diff] [blame] | 2893 | Source<TabContents>(this), |
[email protected] | 546ae4e0 | 2010-12-08 14:57:19 | [diff] [blame] | 2894 | Details<const bool>(&is_editable_node)); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 2895 | } |
| 2896 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2897 | void TabContents::UpdateZoomLimits(int minimum_percent, |
| 2898 | int maximum_percent, |
| 2899 | bool remember) { |
| 2900 | minimum_zoom_percent_ = minimum_percent; |
| 2901 | maximum_zoom_percent_ = maximum_percent; |
| 2902 | temporary_zoom_settings_ = !remember; |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 2903 | } |
| 2904 | |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2905 | void TabContents::WorkerCrashed() { |
| 2906 | AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL, |
| 2907 | l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true)); |
| 2908 | } |
| 2909 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2910 | void TabContents::BeforeUnloadFiredFromRenderManager( |
| 2911 | bool proceed, |
| 2912 | bool* proceed_to_fire_unload) { |
| 2913 | if (delegate()) |
| 2914 | delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
| 2915 | } |
| 2916 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2917 | void TabContents::DidStartLoadingFromRenderManager( |
| 2918 | RenderViewHost* render_view_host) { |
| 2919 | DidStartLoading(); |
| 2920 | } |
| 2921 | |
| 2922 | void TabContents::RenderViewGoneFromRenderManager( |
| 2923 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2924 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
| 2925 | RenderViewGone(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2926 | } |
| 2927 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2928 | void TabContents::UpdateRenderViewSizeForRenderManager() { |
| 2929 | // TODO(brettw) this is a hack. See TabContentsView::SizeContents. |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 2930 | gfx::Size size = view_->GetContainerSize(); |
| 2931 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 2932 | // here during container initialization and normal window size will be set |
| 2933 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 2934 | // normal size later so just ignore it. |
| 2935 | if (!size.IsEmpty()) |
| 2936 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2937 | } |
| 2938 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2939 | void TabContents::NotifySwappedFromRenderManager() { |
| 2940 | NotifySwapped(); |
| 2941 | } |
| 2942 | |
| 2943 | NavigationController& TabContents::GetControllerForRenderManager() { |
| 2944 | return controller(); |
| 2945 | } |
| 2946 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2947 | DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) { |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 2948 | return WebUIFactory::CreateWebUIForURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | NavigationEntry* |
| 2952 | TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
| 2953 | return controller_.GetLastCommittedEntry(); |
| 2954 | } |
| 2955 | |
| 2956 | bool TabContents::CreateRenderViewForRenderManager( |
| 2957 | RenderViewHost* render_view_host) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2958 | RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 2959 | |
[email protected] | 674b382 | 2010-08-04 04:02:51 | [diff] [blame] | 2960 | if (!render_view_host->CreateRenderView(string16())) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2961 | return false; |
| 2962 | |
| 2963 | // Now that the RenderView has been created, we need to tell it its size. |
| 2964 | rwh_view->SetSize(view_->GetContainerSize()); |
| 2965 | |
| 2966 | UpdateMaxPageIDIfNecessary(render_view_host->site_instance(), |
| 2967 | render_view_host); |
| 2968 | return true; |
| 2969 | } |
| 2970 | |
| 2971 | void TabContents::Observe(NotificationType type, |
| 2972 | const NotificationSource& source, |
| 2973 | const NotificationDetails& details) { |
| 2974 | switch (type.value) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2975 | case NotificationType::PREF_CHANGED: { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 2976 | std::string* pref_name_in = Details<std::string>(details).ptr(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2977 | DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); |
| 2978 | if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { |
| 2979 | UpdateAlternateErrorPageURL(); |
[email protected] | 88e1438 | 2010-10-14 21:45:53 | [diff] [blame] | 2980 | } else if ((*pref_name_in == prefs::kDefaultCharset) || |
| 2981 | StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2982 | UpdateWebPreferences(); |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 2983 | } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
| 2984 | UpdateZoomLevel(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2985 | } else { |
| 2986 | NOTREACHED() << "unexpected pref change notification" << *pref_name_in; |
| 2987 | } |
| 2988 | break; |
| 2989 | } |
| 2990 | case NotificationType::RENDER_WIDGET_HOST_DESTROYED: |
| 2991 | view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); |
| 2992 | break; |
| 2993 | |
| 2994 | case NotificationType::NAV_ENTRY_COMMITTED: { |
| 2995 | DCHECK(&controller_ == Source<NavigationController>(source).ptr()); |
| 2996 | |
| 2997 | NavigationController::LoadCommittedDetails& committed_details = |
| 2998 | *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); |
| 2999 | ExpireInfoBars(committed_details); |
| 3000 | break; |
| 3001 | } |
| 3002 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 3003 | #if defined(OS_LINUX) |
| 3004 | case NotificationType::BROWSER_THEME_CHANGED: { |
[email protected] | 7ff431e | 2010-01-07 18:18:54 | [diff] [blame] | 3005 | renderer_preferences_util::UpdateFromSystemSettings( |
| 3006 | &renderer_preferences_, profile()); |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 3007 | render_view_host()->SyncRendererPrefs(); |
| 3008 | break; |
| 3009 | } |
| 3010 | #endif |
| 3011 | |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 3012 | case NotificationType::USER_STYLE_SHEET_UPDATED: |
| 3013 | UpdateWebPreferences(); |
| 3014 | break; |
| 3015 | |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3016 | case NotificationType::CONTENT_SETTINGS_CHANGED: { |
[email protected] | 5f24f21 | 2010-12-02 14:47:45 | [diff] [blame] | 3017 | Details<const ContentSettingsDetails> settings_details(details); |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3018 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | da0c8e9 | 2010-02-09 23:25:49 | [diff] [blame] | 3019 | GURL entry_url; |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3020 | if (entry) |
[email protected] | da0c8e9 | 2010-02-09 23:25:49 | [diff] [blame] | 3021 | entry_url = entry->url(); |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3022 | if (settings_details.ptr()->update_all() || |
| 3023 | settings_details.ptr()->pattern().Matches(entry_url)) { |
| 3024 | render_view_host()->SendContentSettings(entry_url, |
[email protected] | b9a4ea7f | 2010-06-25 07:11:23 | [diff] [blame] | 3025 | profile()->GetHostContentSettingsMap()-> |
| 3026 | GetContentSettings(entry_url)); |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3027 | } |
| 3028 | break; |
| 3029 | } |
| 3030 | |
[email protected] | e5adff7 | 2010-06-14 18:13:06 | [diff] [blame] | 3031 | case NotificationType::EXTENSION_LOADED: |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3032 | break; |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3033 | |
| 3034 | case NotificationType::EXTENSION_UNLOADED: |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3035 | break; |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3036 | |
[email protected] | 8815205 | 2010-10-01 04:05:18 | [diff] [blame] | 3037 | case NotificationType::GOOGLE_URL_UPDATED: |
| 3038 | UpdateAlternateErrorPageURL(); |
| 3039 | break; |
| 3040 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3041 | default: |
| 3042 | NOTREACHED(); |
| 3043 | } |
| 3044 | } |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 3045 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3046 | void TabContents::UpdateExtensionAppIcon(const Extension* extension) { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3047 | extension_app_icon_.reset(); |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 3048 | |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3049 | if (extension) { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3050 | extension_app_image_loader_.reset(new ImageLoadingTracker(this)); |
| 3051 | extension_app_image_loader_->LoadImage( |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3052 | extension, |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 3053 | extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH, |
| 3054 | ExtensionIconSet::MATCH_EXACTLY), |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3055 | gfx::Size(Extension::EXTENSION_ICON_SMALLISH, |
| 3056 | Extension::EXTENSION_ICON_SMALLISH), |
| 3057 | ImageLoadingTracker::CACHE); |
| 3058 | } else { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3059 | extension_app_image_loader_.reset(NULL); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3063 | const Extension* TabContents::GetExtensionContaining(const GURL& url) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3064 | ExtensionService* extensions_service = profile()->GetExtensionService(); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3065 | if (!extensions_service) |
| 3066 | return NULL; |
| 3067 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3068 | const Extension* extension = extensions_service->GetExtensionByURL(url); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3069 | return extension ? |
| 3070 | extension : extensions_service->GetExtensionByWebExtent(url); |
| 3071 | } |
| 3072 | |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3073 | void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource, |
| 3074 | int index) { |
| 3075 | if (image) { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3076 | extension_app_icon_ = *image; |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3077 | NotifyNavigationStateChanged(INVALIDATE_TAB); |
| 3078 | } |
| 3079 | } |
| 3080 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 3081 | gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { |
| 3082 | return view_->GetTopLevelNativeWindow(); |
| 3083 | } |
| 3084 | |
| 3085 | void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| 3086 | bool success, |
| 3087 | const std::wstring& prompt) { |
| 3088 | last_javascript_message_dismissal_ = base::TimeTicks::Now(); |
| 3089 | if (is_showing_before_unload_dialog_ && !success) { |
| 3090 | // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 3091 | // spinning, since we forced it to start spinning in Navigate. |
| 3092 | DidStopLoading(); |
| 3093 | |
| 3094 | tab_close_start_time_ = base::TimeTicks(); |
| 3095 | } |
| 3096 | is_showing_before_unload_dialog_ = false; |
| 3097 | render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 3098 | } |
| 3099 | |
| 3100 | void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { |
| 3101 | set_suppress_javascript_messages(suppress_message_boxes); |
| 3102 | } |
| 3103 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 3104 | TabContents* TabContents::AsTabContents() { |
| 3105 | return this; |
| 3106 | } |
| 3107 | |
| 3108 | ExtensionHost* TabContents::AsExtensionHost() { |
| 3109 | return NULL; |
| 3110 | } |
| 3111 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3112 | void TabContents::set_encoding(const std::string& encoding) { |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 3113 | encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 3114 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 3115 | |
| 3116 | void TabContents::SetAppIcon(const SkBitmap& app_icon) { |
| 3117 | app_icon_ = app_icon; |
| 3118 | NotifyNavigationStateChanged(INVALIDATE_TITLE); |
| 3119 | } |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 3120 | |
| 3121 | void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
| 3122 | render_manager_.SwapInRenderViewHost(rvh); |
| 3123 | } |
| 3124 | |
| 3125 | void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 3126 | RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 3127 | rwh_view->SetSize(view()->GetContainerSize()); |
| 3128 | } |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 3129 | |
| 3130 | bool TabContents::MaybeUsePreloadedPage(const GURL& url) { |
| 3131 | PrerenderManager* pm = profile()->GetPrerenderManager(); |
| 3132 | if (pm != NULL) { |
[email protected] | 973407b | 2011-01-26 23:18:23 | [diff] [blame] | 3133 | if (pm->MaybeUsePreloadedPage(this, url)) |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 3134 | return true; |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 3135 | } |
| 3136 | return false; |
| 3137 | } |