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