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