[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 5 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 3952656 | 2011-02-05 03:41:51 | [diff] [blame] | 6 | |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 7 | #include <utility> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 8 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 10 | #include "base/metrics/histogram.h" |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 11 | #include "base/metrics/stats_counters.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 43d9d78 | 2012-03-01 15:40:09 | [diff] [blame] | 13 | #include "base/string_number_conversions.h" |
[email protected] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 15 | #include "base/time.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 16 | #include "base/utf_string_conversions.h" |
[email protected] | 8dd709fb | 2012-04-06 00:49:06 | [diff] [blame] | 17 | #include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 18 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 19 | #include "content/browser/debugger/devtools_manager_impl.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 20 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 21 | #include "content/browser/download/download_stats.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 22 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 23 | #include "content/browser/download/save_package.h" |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 24 | #include "content/browser/gpu/gpu_data_manager_impl.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 25 | #include "content/browser/gpu/gpu_process_host.h" |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 26 | #include "content/browser/host_zoom_map_impl.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 27 | #include "content/browser/intents/web_intents_dispatcher_impl.h" |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 28 | #include "content/browser/load_from_memory_cache_details.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 29 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 30 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 31 | #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 32 | #include "content/browser/site_instance_impl.h" |
[email protected] | f9e4dae | 2012-04-10 21:26:37 | [diff] [blame] | 33 | #include "content/browser/web_contents/interstitial_page_impl.h" |
| 34 | #include "content/browser/web_contents/navigation_entry_impl.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 35 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 36 | #include "content/common/intents_messages.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 37 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 38 | #include "content/common/view_messages.h" |
[email protected] | 5626b089 | 2012-02-20 14:46:58 | [diff] [blame] | 39 | #include "content/port/browser/render_widget_host_view_port.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 40 | #include "content/public/browser/browser_context.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 41 | #include "content/public/browser/color_chooser.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 42 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 43 | #include "content/public/browser/devtools_agent_host_registry.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 44 | #include "content/public/browser/download_manager.h" |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 45 | #include "content/public/browser/download_url_parameters.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 46 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 32f497b | 2012-01-30 20:33:15 | [diff] [blame] | 47 | #include "content/public/browser/javascript_dialogs.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 48 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 49 | #include "content/public/browser/navigation_details.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 50 | #include "content/public/browser/notification_service.h" |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 51 | #include "content/public/browser/resource_request_details.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 52 | #include "content/public/browser/user_metrics.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 53 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 54 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 55 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 56 | #include "content/public/browser/web_ui_controller_factory.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 57 | #include "content/public/common/bindings_policy.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 58 | #include "content/public/common/content_constants.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 59 | #include "content/public/common/content_restriction.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 60 | #include "content/public/common/content_switches.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 61 | #include "content/public/common/url_constants.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 62 | #include "net/base/mime_util.h" |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 63 | #include "net/base/net_util.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 64 | #include "net/base/network_change_notifier.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 65 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 66 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 67 | #include "ui/base/ui_base_switches.h" |
| 68 | #include "ui/gfx/monitor.h" |
| 69 | #include "ui/gfx/screen.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 70 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 71 | #include "webkit/glue/webpreferences.h" |
| 72 | |
[email protected] | 68b5225 | 2012-04-04 19:26:13 | [diff] [blame] | 73 | #if defined(USE_AURA) |
[email protected] | 6eddfd44 | 2012-04-11 16:18:35 | [diff] [blame] | 74 | #include "content/browser/web_contents/web_contents_view_aura.h" |
[email protected] | 68b5225 | 2012-04-04 19:26:13 | [diff] [blame] | 75 | #elif defined(OS_WIN) |
[email protected] | 6eddfd44 | 2012-04-11 16:18:35 | [diff] [blame] | 76 | #include "content/browser/web_contents/web_contents_view_win.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 77 | #elif defined(TOOLKIT_GTK) |
[email protected] | 6eddfd44 | 2012-04-11 16:18:35 | [diff] [blame] | 78 | #include "content/browser/web_contents/web_contents_view_gtk.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 79 | #elif defined(OS_MACOSX) |
[email protected] | 0c4e92e6 | 2012-04-11 15:19:00 | [diff] [blame] | 80 | #include "content/browser/web_contents/web_contents_view_mac.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 81 | #include "ui/surface/io_surface_support_mac.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 82 | #elif defined(OS_ANDROID) |
[email protected] | 0c4e92e6 | 2012-04-11 15:19:00 | [diff] [blame] | 83 | #include "content/browser/web_contents/web_contents_view_android.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 84 | #endif |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 85 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 86 | // Cross-Site Navigations |
| 87 | // |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 88 | // If a WebContentsImpl is told to navigate to a different web site (as |
| 89 | // determined by SiteInstance), it will replace its current RenderViewHost with |
| 90 | // a new RenderViewHost dedicated to the new SiteInstance. This works as |
| 91 | // follows: |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 92 | // |
| 93 | // - Navigate determines whether the destination is cross-site, and if so, |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 94 | // it creates a pending_render_view_host_. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 95 | // - The pending RVH is "suspended," so that no navigation messages are sent to |
| 96 | // its renderer until the onbeforeunload JavaScript handler has a chance to |
| 97 | // run in the current RVH. |
| 98 | // - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton) |
| 99 | // that it has a pending cross-site request. ResourceDispatcherHost will |
| 100 | // check for this when the response arrives. |
| 101 | // - The current RVH runs its onbeforeunload handler. If it returns false, we |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 102 | // cancel all the pending logic. Otherwise we allow the pending RVH to send |
| 103 | // the navigation request to its renderer. |
| 104 | // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the |
| 105 | // main resource load on the pending RVH. It checks CrossSiteRequestManager |
| 106 | // to see that it is a cross-site request, and installs a |
| 107 | // CrossSiteResourceHandler. |
| 108 | // - When RDH receives a response, the BufferedResourceHandler determines |
| 109 | // whether it is a download. If so, it sends a message to the new renderer |
| 110 | // causing it to cancel the request, and the download proceeds. For now, the |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 111 | // pending RVH remains until the next DidNavigate event for this |
| 112 | // WebContentsImpl. This isn't ideal, but it doesn't affect any functionality. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 113 | // - After RDH receives a response and determines that it is safe and not a |
| 114 | // download, it pauses the response to first run the old page's onunload |
| 115 | // handler. It does this by asynchronously calling the OnCrossSiteResponse |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 116 | // method of WebContentsImpl on the UI thread, which sends a SwapOut message |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 117 | // to the current RVH. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 118 | // - Once the onunload handler is finished, a SwapOut_ACK message is sent to |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 119 | // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 120 | // to the pending RVH. |
| 121 | // - The pending renderer sends a FrameNavigate message that invokes the |
| 122 | // DidNavigate method. This replaces the current RVH with the |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 123 | // pending RVH. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 124 | // - The previous renderer is kept swapped out in RenderViewHostManager in case |
| 125 | // the user goes back. The process only stays live if another tab is using |
| 126 | // it, but if so, the existing frame relationships will be maintained. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 127 | |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 128 | using content::DevToolsAgentHost; |
| 129 | using content::DevToolsAgentHostRegistry; |
| 130 | using content::DevToolsManagerImpl; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 131 | using content::DownloadItem; |
| 132 | using content::DownloadManager; |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 133 | using content::DownloadUrlParameters; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 134 | using content::GlobalRequestID; |
[email protected] | 5fe3713a | 2012-02-22 08:31:56 | [diff] [blame] | 135 | using content::HostZoomMap; |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 136 | using content::InterstitialPage; |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 137 | using content::LoadNotificationDetails; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 138 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 139 | using content::NavigationEntry; |
| 140 | using content::NavigationEntryImpl; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 141 | using content::OpenURLParams; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 142 | using content::RenderViewHost; |
[email protected] | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 143 | using content::RenderViewHostDelegate; |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 144 | using content::RenderViewHostImpl; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 145 | using content::RenderWidgetHost; |
[email protected] | 5626b089 | 2012-02-20 14:46:58 | [diff] [blame] | 146 | using content::RenderWidgetHostView; |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 147 | using content::RenderWidgetHostViewPort; |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 148 | using content::ResourceDispatcherHostImpl; |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 149 | using content::SSLStatus; |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 150 | using content::SessionStorageNamespace; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 151 | using content::SiteInstance; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 152 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 153 | using content::WebContents; |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 154 | using content::WebContentsObserver; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 155 | using content::WebUI; |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 156 | using content::WebUIController; |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 157 | using content::WebUIControllerFactory; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 158 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 159 | namespace { |
| 160 | |
| 161 | // Amount of time we wait between when a key event is received and the renderer |
| 162 | // is queried for its state and pushed to the NavigationEntry. |
| 163 | const int kQueryStateDelay = 5000; |
| 164 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 165 | const int kSyncWaitDelay = 40; |
| 166 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 167 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 168 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 169 | #if defined(OS_WIN) |
| 170 | |
| 171 | BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { |
| 172 | // Note: erase is required to properly paint some widgets borders. This can |
| 173 | // be seen with textfields. |
| 174 | InvalidateRect(hwnd, NULL, TRUE); |
| 175 | return TRUE; |
| 176 | } |
| 177 | #endif |
| 178 | |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 179 | ViewMsg_Navigate_Type::Value GetNavigationType( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 180 | content::BrowserContext* browser_context, const NavigationEntryImpl& entry, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 181 | NavigationController::ReloadType reload_type) { |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 182 | switch (reload_type) { |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 183 | case NavigationControllerImpl::RELOAD: |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 184 | return ViewMsg_Navigate_Type::RELOAD; |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 185 | case NavigationControllerImpl::RELOAD_IGNORING_CACHE: |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 186 | return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 187 | case NavigationControllerImpl::NO_RELOAD: |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 188 | break; // Fall through to rest of function. |
| 189 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 190 | |
[email protected] | 59246c57 | 2012-02-10 13:32:13 | [diff] [blame] | 191 | // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates |
| 192 | // between |RESTORE_WITH_POST| and |RESTORE|. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 193 | if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION && |
[email protected] | 59246c57 | 2012-02-10 13:32:13 | [diff] [blame] | 194 | browser_context->DidLastSessionExitCleanly()) { |
| 195 | if (entry.GetHasPostData()) |
| 196 | return ViewMsg_Navigate_Type::RESTORE_WITH_POST; |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 197 | return ViewMsg_Navigate_Type::RESTORE; |
[email protected] | 59246c57 | 2012-02-10 13:32:13 | [diff] [blame] | 198 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 199 | |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 200 | return ViewMsg_Navigate_Type::NORMAL; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 201 | } |
| 202 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 203 | void MakeNavigateParams(const NavigationEntryImpl& entry, |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 204 | const NavigationControllerImpl& controller, |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 205 | content::WebContentsDelegate* delegate, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 206 | NavigationController::ReloadType reload_type, |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 207 | ViewMsg_Navigate_Params* params) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 208 | params->page_id = entry.GetPageID(); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 209 | params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 210 | params->current_history_list_offset = controller.GetLastCommittedEntryIndex(); |
| 211 | params->current_history_list_length = controller.GetEntryCount(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 212 | params->url = entry.GetURL(); |
| 213 | params->referrer = entry.GetReferrer(); |
| 214 | params->transition = entry.GetTransitionType(); |
| 215 | params->state = entry.GetContentState(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 216 | params->navigation_type = |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 217 | GetNavigationType(controller.GetBrowserContext(), entry, reload_type); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 218 | params->request_time = base::Time::Now(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 219 | params->extra_headers = entry.extra_headers(); |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 220 | params->transferred_request_child_id = |
| 221 | entry.transferred_global_request_id().child_id; |
| 222 | params->transferred_request_request_id = |
| 223 | entry.transferred_global_request_id().request_id; |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 224 | // Avoid downloading when in view-source mode. |
| 225 | params->allow_download = !entry.IsViewSourceMode(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 226 | |
| 227 | if (delegate) |
| 228 | delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 229 | } |
| 230 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 231 | } // namespace |
| 232 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 233 | namespace content { |
| 234 | |
| 235 | WebContents* WebContents::Create( |
| 236 | BrowserContext* browser_context, |
| 237 | SiteInstance* site_instance, |
| 238 | int routing_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 239 | const WebContents* base_web_contents, |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 240 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 241 | return new WebContentsImpl( |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 242 | browser_context, |
| 243 | site_instance, |
| 244 | routing_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 245 | static_cast<const WebContentsImpl*>(base_web_contents), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 246 | NULL, |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 247 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace)); |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 248 | } |
| 249 | } |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 250 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 251 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 252 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 253 | WebContentsImpl::WebContentsImpl( |
| 254 | content::BrowserContext* browser_context, |
| 255 | SiteInstance* site_instance, |
| 256 | int routing_id, |
| 257 | const WebContentsImpl* base_web_contents, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 258 | WebContentsImpl* opener, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 259 | SessionStorageNamespaceImpl* session_storage_namespace) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 260 | : delegate_(NULL), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 261 | ALLOW_THIS_IN_INITIALIZER_LIST(controller_( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 262 | this, browser_context, session_storage_namespace)), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 263 | opener_(opener), |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 264 | ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 265 | is_loading_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 266 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 267 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 268 | waiting_for_response_(false), |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 269 | load_state_(net::LOAD_STATE_IDLE, string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 270 | upload_size_(0), |
| 271 | upload_position_(0), |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 272 | displayed_insecure_content_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 273 | capturing_contents_(false), |
| 274 | is_being_destroyed_(false), |
| 275 | notify_disconnection_(false), |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 276 | dialog_creator_(NULL), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 277 | #if defined(OS_WIN) |
| 278 | message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 279 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 280 | is_showing_before_unload_dialog_(false), |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 281 | opener_web_ui_type_(WebUI::kNoWebUI), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 282 | closed_by_user_gesture_(false), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 283 | minimum_zoom_percent_( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 284 | static_cast<int>(content::kMinimumZoomFactor * 100)), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 285 | maximum_zoom_percent_( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 286 | static_cast<int>(content::kMaximumZoomFactor * 100)), |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 287 | temporary_zoom_settings_(false), |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 288 | content_restrictions_(0), |
[email protected] | e018d3b | 2012-04-17 13:24:15 | [diff] [blame] | 289 | view_type_(content::VIEW_TYPE_WEB_CONTENTS), |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 290 | color_chooser_(NULL) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 291 | render_manager_.Init(browser_context, site_instance, routing_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 292 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 293 | view_.reset(content::GetContentClient()->browser()-> |
| 294 | OverrideCreateWebContentsView(this)); |
| 295 | if (!view_.get()) { |
| 296 | content::WebContentsViewDelegate* delegate = |
| 297 | content::GetContentClient()->browser()->GetWebContentsViewDelegate( |
| 298 | this); |
[email protected] | 68b5225 | 2012-04-04 19:26:13 | [diff] [blame] | 299 | #if defined(USE_AURA) |
[email protected] | 6eddfd44 | 2012-04-11 16:18:35 | [diff] [blame] | 300 | view_.reset(new WebContentsViewAura(this, delegate)); |
[email protected] | 68b5225 | 2012-04-04 19:26:13 | [diff] [blame] | 301 | #elif defined(OS_WIN) |
[email protected] | 6eddfd44 | 2012-04-11 16:18:35 | [diff] [blame] | 302 | view_.reset(new WebContentsViewWin(this, delegate)); |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 303 | #elif defined(TOOLKIT_GTK) |
[email protected] | 6eddfd44 | 2012-04-11 16:18:35 | [diff] [blame] | 304 | view_.reset(new content::WebContentsViewGtk(this, delegate)); |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 305 | #elif defined(OS_MACOSX) |
| 306 | view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate)); |
| 307 | #elif defined(OS_ANDROID) |
| 308 | view_.reset(new WebContentsViewAndroid(this)); |
| 309 | #endif |
[email protected] | dbd407f | 2012-03-14 21:30:37 | [diff] [blame] | 310 | (void)delegate; |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 311 | } |
| 312 | CHECK(view_.get()); |
| 313 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 314 | // We have the initial size of the view be based on the size of the view of |
| 315 | // the passed in WebContents. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 316 | view_->CreateView(base_web_contents ? |
| 317 | base_web_contents->GetView()->GetContainerSize() : gfx::Size()); |
[email protected] | 483623eb | 2011-10-25 09:30:00 | [diff] [blame] | 318 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 319 | // Listen for whether our opener gets destroyed. |
| 320 | if (opener_) { |
| 321 | registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 322 | content::Source<WebContents>(opener_)); |
| 323 | } |
| 324 | |
[email protected] | 483623eb | 2011-10-25 09:30:00 | [diff] [blame] | 325 | #if defined(ENABLE_JAVA_BRIDGE) |
| 326 | java_bridge_dispatcher_host_manager_.reset( |
| 327 | new JavaBridgeDispatcherHostManager(this)); |
| 328 | #endif |
[email protected] | 8dd709fb | 2012-04-06 00:49:06 | [diff] [blame] | 329 | |
| 330 | browser_plugin_web_contents_observer_.reset( |
| 331 | new content::BrowserPluginWebContentsObserver(this)); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 332 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 333 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 334 | WebContentsImpl::~WebContentsImpl() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 335 | is_being_destroyed_ = true; |
| 336 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 337 | // Clear out any JavaScript state. |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 338 | if (dialog_creator_) |
| 339 | dialog_creator_->ResetJavaScriptState(this); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 340 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 341 | if (color_chooser_) |
| 342 | color_chooser_->End(); |
| 343 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 344 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 345 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 346 | // Notify any observer that have a reference on this WebContents. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 347 | content::NotificationService::current()->Notify( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 348 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 349 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 350 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 351 | |
| 352 | // TODO(brettw) this should be moved to the view. |
[email protected] | 010882f | 2011-11-14 22:32:07 | [diff] [blame] | 353 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 354 | // If we still have a window handle, destroy it. GetNativeView can return |
| 355 | // NULL if this contents was part of a window that closed. |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 356 | if (GetNativeView()) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 357 | RenderViewHost* host = GetRenderViewHost(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 358 | if (host && host->GetView()) |
| 359 | RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy(); |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 360 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 361 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 362 | |
| 363 | // OnCloseStarted isn't called in unit tests. |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 364 | if (!close_start_time_.is_null()) { |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 365 | UMA_HISTOGRAM_TIMES("Tab.Close", |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 366 | base::TimeTicks::Now() - close_start_time_); |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 367 | } |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 368 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 369 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 370 | observers_, |
| 371 | WebContentsImplDestroyed()); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 372 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 373 | SetDelegate(NULL); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 376 | WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, |
| 377 | const GURL& url) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 378 | WebPreferences prefs; |
| 379 | |
| 380 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 381 | |
| 382 | prefs.developer_extras_enabled = true; |
| 383 | prefs.javascript_enabled = |
| 384 | !command_line.HasSwitch(switches::kDisableJavaScript); |
| 385 | prefs.web_security_enabled = |
| 386 | !command_line.HasSwitch(switches::kDisableWebSecurity); |
| 387 | prefs.plugins_enabled = |
| 388 | !command_line.HasSwitch(switches::kDisablePlugins); |
| 389 | prefs.java_enabled = |
| 390 | !command_line.HasSwitch(switches::kDisableJava); |
| 391 | |
| 392 | prefs.uses_page_cache = |
| 393 | command_line.HasSwitch(switches::kEnableFastback); |
| 394 | prefs.remote_fonts_enabled = |
| 395 | !command_line.HasSwitch(switches::kDisableRemoteFonts); |
| 396 | prefs.xss_auditor_enabled = |
| 397 | !command_line.HasSwitch(switches::kDisableXSSAuditor); |
| 398 | prefs.application_cache_enabled = |
| 399 | !command_line.HasSwitch(switches::kDisableApplicationCache); |
| 400 | |
| 401 | prefs.local_storage_enabled = |
| 402 | !command_line.HasSwitch(switches::kDisableLocalStorage); |
| 403 | prefs.databases_enabled = |
| 404 | !command_line.HasSwitch(switches::kDisableDatabases); |
| 405 | prefs.webaudio_enabled = |
| 406 | !command_line.HasSwitch(switches::kDisableWebAudio); |
| 407 | |
| 408 | prefs.experimental_webgl_enabled = |
| 409 | GpuProcessHost::gpu_enabled() && |
| 410 | !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 411 | !command_line.HasSwitch(switches::kDisableExperimentalWebGL); |
| 412 | |
| 413 | prefs.gl_multisampling_enabled = |
| 414 | !command_line.HasSwitch(switches::kDisableGLMultisampling); |
| 415 | prefs.privileged_webgl_extensions_enabled = |
| 416 | command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions); |
| 417 | prefs.site_specific_quirks_enabled = |
| 418 | !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks); |
| 419 | prefs.allow_file_access_from_file_urls = |
| 420 | command_line.HasSwitch(switches::kAllowFileAccessFromFiles); |
| 421 | prefs.show_composited_layer_borders = |
| 422 | command_line.HasSwitch(switches::kShowCompositedLayerBorders); |
| 423 | prefs.show_composited_layer_tree = |
| 424 | command_line.HasSwitch(switches::kShowCompositedLayerTree); |
| 425 | prefs.show_fps_counter = |
| 426 | command_line.HasSwitch(switches::kShowFPSCounter); |
| 427 | prefs.accelerated_compositing_enabled = |
| 428 | GpuProcessHost::gpu_enabled() && |
| 429 | !command_line.HasSwitch(switches::kDisableAcceleratedCompositing); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 430 | prefs.force_compositing_mode = |
| 431 | command_line.HasSwitch(switches::kForceCompositingMode); |
| 432 | prefs.fixed_position_compositing_enabled = |
| 433 | command_line.HasSwitch(switches::kEnableCompositingForFixedPosition); |
| 434 | prefs.accelerated_2d_canvas_enabled = |
| 435 | GpuProcessHost::gpu_enabled() && |
| 436 | !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas); |
[email protected] | e1f6bdd | 2012-02-07 21:52:58 | [diff] [blame] | 437 | prefs.deferred_2d_canvas_enabled = |
| 438 | command_line.HasSwitch(switches::kEnableDeferred2dCanvas); |
[email protected] | eb4c140 | 2012-02-25 00:46:36 | [diff] [blame] | 439 | prefs.threaded_animation_enabled = |
[email protected] | 7d2e053 | 2012-03-23 22:03:31 | [diff] [blame] | 440 | !command_line.HasSwitch(switches::kDisableThreadedAnimation); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 441 | prefs.accelerated_painting_enabled = |
| 442 | GpuProcessHost::gpu_enabled() && |
| 443 | command_line.HasSwitch(switches::kEnableAcceleratedPainting); |
| 444 | prefs.accelerated_filters_enabled = |
| 445 | GpuProcessHost::gpu_enabled() && |
| 446 | command_line.HasSwitch(switches::kEnableAcceleratedFilters); |
| 447 | prefs.accelerated_layers_enabled = |
| 448 | prefs.accelerated_animation_enabled = |
| 449 | !command_line.HasSwitch(switches::kDisableAcceleratedLayers); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 450 | prefs.accelerated_plugins_enabled = |
| 451 | !command_line.HasSwitch(switches::kDisableAcceleratedPlugins); |
| 452 | prefs.accelerated_video_enabled = |
| 453 | !command_line.HasSwitch(switches::kDisableAcceleratedVideo); |
| 454 | prefs.partial_swap_enabled = |
| 455 | command_line.HasSwitch(switches::kEnablePartialSwap); |
| 456 | prefs.interactive_form_validation_enabled = |
| 457 | !command_line.HasSwitch(switches::kDisableInteractiveFormValidation); |
| 458 | prefs.fullscreen_enabled = |
| 459 | !command_line.HasSwitch(switches::kDisableFullScreen); |
[email protected] | 37ac2a8 | 2012-03-01 05:30:16 | [diff] [blame] | 460 | prefs.css_regions_enabled = |
| 461 | command_line.HasSwitch(switches::kEnableCssRegions); |
[email protected] | bc19958 | 2012-03-29 09:02:29 | [diff] [blame] | 462 | prefs.css_shaders_enabled = |
| 463 | command_line.HasSwitch(switches::kEnableCssShaders); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 464 | |
| 465 | #if defined(OS_MACOSX) |
| 466 | bool default_enable_scroll_animator = true; |
| 467 | #else |
| 468 | // On CrOS, the launcher always passes in the --enable flag. |
| 469 | bool default_enable_scroll_animator = false; |
| 470 | #endif |
| 471 | prefs.enable_scroll_animator = default_enable_scroll_animator; |
| 472 | if (command_line.HasSwitch(switches::kEnableSmoothScrolling)) |
| 473 | prefs.enable_scroll_animator = true; |
| 474 | if (command_line.HasSwitch(switches::kDisableSmoothScrolling)) |
| 475 | prefs.enable_scroll_animator = false; |
| 476 | |
| 477 | prefs.visual_word_movement_enabled = |
| 478 | command_line.HasSwitch(switches::kEnableVisualWordMovement); |
| 479 | prefs.per_tile_painting_enabled = |
| 480 | command_line.HasSwitch(switches::kEnablePerTilePainting); |
| 481 | |
| 482 | { // Certain GPU features might have been blacklisted. |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 483 | GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 484 | DCHECK(gpu_data_manager); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 485 | uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType(); |
| 486 | if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 487 | prefs.accelerated_compositing_enabled = false; |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 488 | if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 489 | prefs.experimental_webgl_enabled = false; |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 490 | if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 491 | prefs.accelerated_2d_canvas_enabled = false; |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 492 | if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 493 | prefs.gl_multisampling_enabled = false; |
| 494 | |
| 495 | // Accelerated video and animation are slower than regular when using a |
[email protected] | 2ffd73d | 2012-03-02 17:33:45 | [diff] [blame] | 496 | // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile. |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 497 | if (gpu_data_manager->ShouldUseSoftwareRendering()) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 498 | prefs.accelerated_video_enabled = false; |
| 499 | prefs.accelerated_animation_enabled = false; |
[email protected] | 2ffd73d | 2012-03-02 17:33:45 | [diff] [blame] | 500 | prefs.accelerated_layers_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 504 | if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 505 | rvh->GetProcess()->GetID())) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 506 | prefs.loads_images_automatically = true; |
| 507 | prefs.javascript_enabled = true; |
| 508 | } |
| 509 | |
| 510 | prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); |
| 511 | |
| 512 | // Force accelerated compositing and 2d canvas off for chrome:, about: and |
| 513 | // chrome-devtools: pages (unless it's specifically allowed). |
| 514 | if ((url.SchemeIs(chrome::kChromeDevToolsScheme) || |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 515 | url.SchemeIs(chrome::kChromeUIScheme) || |
| 516 | (url.SchemeIs(chrome::kAboutScheme) && |
| 517 | url.spec() != chrome::kAboutBlankURL)) && |
[email protected] | b049fbd4 | 2012-02-08 02:03:25 | [diff] [blame] | 518 | !command_line.HasSwitch(switches::kAllowWebUICompositing)) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 519 | prefs.accelerated_compositing_enabled = false; |
| 520 | prefs.accelerated_2d_canvas_enabled = false; |
| 521 | } |
[email protected] | 8b3b3615 | 2012-05-01 04:55:07 | [diff] [blame] | 522 | #if defined(OS_MACOSX) |
| 523 | // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl. |
| 524 | // crbug.com/125690. |
[email protected] | 82c9a8e | 2012-05-02 01:07:23 | [diff] [blame] | 525 | prefs.default_device_scale_factor = |
| 526 | gfx::Monitor::GetDefaultDeviceScaleFactor(); |
[email protected] | 8b3b3615 | 2012-05-01 04:55:07 | [diff] [blame] | 527 | #else |
| 528 | if (rvh->GetView()) { |
| 529 | gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow( |
| 530 | rvh->GetView()->GetNativeView()); |
| 531 | prefs.default_device_scale_factor = |
| 532 | static_cast<int>(monitor.device_scale_factor()); |
| 533 | } else { |
[email protected] | 82c9a8e | 2012-05-02 01:07:23 | [diff] [blame] | 534 | prefs.default_device_scale_factor = |
| 535 | gfx::Monitor::GetDefaultDeviceScaleFactor();; |
[email protected] | 8b3b3615 | 2012-05-01 04:55:07 | [diff] [blame] | 536 | } |
| 537 | #endif |
[email protected] | 43d9d78 | 2012-03-01 15:40:09 | [diff] [blame] | 538 | |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 539 | content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 540 | |
| 541 | return prefs; |
| 542 | } |
| 543 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 544 | NavigationControllerImpl& WebContentsImpl::GetControllerImpl() { |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 545 | return controller_; |
| 546 | } |
| 547 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 548 | RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 549 | return &render_manager_; |
| 550 | } |
| 551 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 552 | bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 553 | if (GetWebUI() && |
| 554 | static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 555 | return true; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 556 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 557 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 558 | ObserverListBase<WebContentsObserver>::Iterator it(observers_); |
| 559 | WebContentsObserver* observer; |
[email protected] | 0f180ee | 2011-01-21 18:23:10 | [diff] [blame] | 560 | while ((observer = it.GetNext()) != NULL) |
| 561 | if (observer->OnMessageReceived(message)) |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 562 | return true; |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 563 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 564 | bool handled = true; |
| 565 | bool message_is_ok = true; |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 566 | IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok) |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 567 | IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService, |
| 568 | OnRegisterIntentService) |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 569 | IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch, |
| 570 | OnWebIntentDispatch) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 571 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache, |
| 572 | OnDidLoadResourceFromMemoryCache) |
| 573 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent, |
| 574 | OnDidDisplayInsecureContent) |
| 575 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent, |
| 576 | OnDidRunInsecureContent) |
| 577 | IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame, |
| 578 | OnDocumentLoadedInFrame) |
| 579 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad) |
[email protected] | 9bf6ee9f | 2012-04-11 11:07:26 | [diff] [blame] | 580 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError, |
| 581 | OnDidFailLoadWithError) |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 582 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions, |
| 583 | OnUpdateContentRestrictions) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 584 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 585 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 586 | IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 587 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 588 | IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) |
| 589 | IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, |
| 590 | OnRegisterProtocolHandler) |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 591 | IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 592 | IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 593 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 594 | IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 595 | IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
| 596 | IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
| 597 | OnSetSelectedColorInColorChooser) |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 598 | IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 599 | IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 600 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 601 | IPC_END_MESSAGE_MAP_EX() |
| 602 | |
| 603 | if (!message_is_ok) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 604 | content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 605 | GetRenderProcessHost()->ReceivedBadMessage(); |
| 606 | } |
| 607 | |
| 608 | return handled; |
| 609 | } |
| 610 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 611 | void WebContentsImpl::RunFileChooser( |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 612 | RenderViewHost* render_view_host, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 613 | const content::FileChooserParams& params) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 614 | delegate_->RunFileChooser(this, params); |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 615 | } |
| 616 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 617 | NavigationController& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 618 | return controller_; |
| 619 | } |
| 620 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 621 | const NavigationController& WebContentsImpl::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 622 | return controller_; |
| 623 | } |
| 624 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 625 | content::BrowserContext* WebContentsImpl::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 626 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 629 | void WebContentsImpl::SetViewType(content::ViewType type) { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 630 | view_type_ = type; |
| 631 | } |
| 632 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 633 | content::ViewType WebContentsImpl::GetViewType() const { |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 634 | return view_type_; |
| 635 | } |
| 636 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 637 | const GURL& WebContentsImpl::GetURL() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 638 | // We may not have a navigation entry yet |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 639 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 640 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 644 | const base::PropertyBag* WebContentsImpl::GetPropertyBag() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 645 | return &property_bag_; |
| 646 | } |
| 647 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 648 | base::PropertyBag* WebContentsImpl::GetPropertyBag() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 649 | return &property_bag_; |
| 650 | } |
| 651 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 652 | content::WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 653 | return delegate_; |
| 654 | } |
| 655 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 656 | void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 657 | // TODO(cbentzel): remove this debugging code? |
| 658 | if (delegate == delegate_) |
| 659 | return; |
| 660 | if (delegate_) |
| 661 | delegate_->Detach(this); |
| 662 | delegate_ = delegate; |
| 663 | if (delegate_) |
| 664 | delegate_->Attach(this); |
| 665 | } |
| 666 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 667 | content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 668 | RenderViewHostImpl* host = render_manager_.current_host(); |
| 669 | return host ? host->GetProcess() : NULL; |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 670 | } |
| 671 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 672 | RenderViewHost* WebContentsImpl::GetRenderViewHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 673 | return render_manager_.current_host(); |
| 674 | } |
| 675 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 676 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 677 | return render_manager_.GetRenderWidgetHostView(); |
| 678 | } |
| 679 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 680 | content::WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 681 | return view_.get(); |
| 682 | } |
| 683 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 684 | content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 685 | WebUIControllerFactory* factory = |
| 686 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 687 | if (!factory) |
| 688 | return NULL; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 689 | WebUIImpl* web_ui = new WebUIImpl(this); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 690 | WebUIController* controller = |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 691 | factory->CreateWebUIControllerForURL(web_ui, url); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 692 | if (controller) { |
| 693 | web_ui->SetController(controller); |
| 694 | return web_ui; |
| 695 | } |
| 696 | |
| 697 | delete web_ui; |
| 698 | return NULL; |
| 699 | } |
| 700 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 701 | content::WebUI* WebContentsImpl::GetWebUI() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 702 | return render_manager_.web_ui() ? render_manager_.web_ui() |
| 703 | : render_manager_.pending_web_ui(); |
| 704 | } |
| 705 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 706 | content::WebUI* WebContentsImpl::GetCommittedWebUI() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 707 | return render_manager_.web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 708 | } |
| 709 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 710 | const string16& WebContentsImpl::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 711 | // Transient entries take precedence. They are used for interstitial pages |
| 712 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 713 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 714 | std::string accept_languages = |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 715 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 716 | GetBrowserContext()); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 717 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 718 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 719 | } |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 720 | WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
| 721 | render_manager_.pending_web_ui() : render_manager_.web_ui(); |
| 722 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 723 | // Don't override the title in view source mode. |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 724 | entry = controller_.GetActiveEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 725 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 726 | // Give the Web UI the chance to override our title. |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 727 | const string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 728 | if (!title.empty()) |
| 729 | return title; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | // We use the title for the last committed entry rather than a pending |
| 734 | // navigation entry. For example, when the user types in a URL, we want to |
| 735 | // keep the old page's title until the new load has committed and we get a new |
| 736 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 737 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 738 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 739 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 740 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 741 | |
| 742 | // |page_title_when_no_navigation_entry_| is finally used |
| 743 | // if no title cannot be retrieved. |
| 744 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 747 | int32 WebContentsImpl::GetMaxPageID() { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 748 | return GetMaxPageIDForSiteInstance(GetSiteInstance()); |
| 749 | } |
| 750 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 751 | int32 WebContentsImpl::GetMaxPageIDForSiteInstance( |
| 752 | SiteInstance* site_instance) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 753 | if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) |
| 754 | max_page_ids_[site_instance->GetId()] = -1; |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 755 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 756 | return max_page_ids_[site_instance->GetId()]; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 757 | } |
| 758 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 759 | void WebContentsImpl::UpdateMaxPageID(int32 page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 760 | UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id); |
| 761 | } |
| 762 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 763 | void WebContentsImpl::UpdateMaxPageIDForSiteInstance( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 764 | SiteInstance* site_instance, int32 page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 765 | if (GetMaxPageIDForSiteInstance(site_instance) < page_id) |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 766 | max_page_ids_[site_instance->GetId()] = page_id; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 767 | } |
| 768 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 769 | void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) { |
| 770 | max_page_ids_ = web_contents->max_page_ids_; |
[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 771 | } |
| 772 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 773 | SiteInstance* WebContentsImpl::GetSiteInstance() const { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 774 | return render_manager_.current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 775 | } |
| 776 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 777 | SiteInstance* WebContentsImpl::GetPendingSiteInstance() const { |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 778 | RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ? |
| 779 | render_manager_.pending_render_view_host() : |
| 780 | render_manager_.current_host(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 781 | return dest_rvh->GetSiteInstance(); |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 782 | } |
| 783 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 784 | bool WebContentsImpl::IsLoading() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 785 | return is_loading_; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 786 | } |
| 787 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 788 | bool WebContentsImpl::IsWaitingForResponse() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 789 | return waiting_for_response_; |
| 790 | } |
| 791 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 792 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 793 | return load_state_; |
| 794 | } |
| 795 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 796 | const string16& WebContentsImpl::GetLoadStateHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 797 | return load_state_host_; |
| 798 | } |
| 799 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 800 | uint64 WebContentsImpl::GetUploadSize() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 801 | return upload_size_; |
| 802 | } |
| 803 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 804 | uint64 WebContentsImpl::GetUploadPosition() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 805 | return upload_position_; |
| 806 | } |
| 807 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 808 | const std::string& WebContentsImpl::GetEncoding() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 809 | return encoding_; |
| 810 | } |
| 811 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 812 | bool WebContentsImpl::DisplayedInsecureContent() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 813 | return displayed_insecure_content_; |
| 814 | } |
| 815 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 816 | void WebContentsImpl::SetCapturingContents(bool cap) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 817 | capturing_contents_ = cap; |
| 818 | } |
| 819 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 820 | bool WebContentsImpl::IsCrashed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 821 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 822 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
| 823 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 826 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 827 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 828 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 829 | return; |
| 830 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 831 | crashed_status_ = status; |
| 832 | crashed_error_code_ = error_code; |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 833 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 834 | } |
| 835 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 836 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 837 | return crashed_status_; |
| 838 | } |
| 839 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 840 | bool WebContentsImpl::IsBeingDestroyed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 841 | return is_being_destroyed_; |
| 842 | } |
| 843 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 844 | void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 845 | if (delegate_) |
| 846 | delegate_->NavigationStateChanged(this, changed_flags); |
| 847 | } |
| 848 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 849 | void WebContentsImpl::DidBecomeSelected() { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 850 | controller_.SetActive(true); |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 851 | RenderWidgetHostViewPort* rwhv = |
| 852 | RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 853 | if (rwhv) { |
| 854 | rwhv->DidBecomeSelected(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 855 | #if defined(OS_MACOSX) |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 856 | rwhv->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 857 | #endif |
| 858 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 859 | |
[email protected] | 5ac2016 | 2010-11-24 23:33:11 | [diff] [blame] | 860 | last_selected_time_ = base::TimeTicks::Now(); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 861 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 862 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected()); |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 863 | |
| 864 | // The resize rect might have changed while this was inactive -- send the new |
| 865 | // one to make sure it's up to date. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 866 | RenderViewHostImpl* rvh = |
| 867 | static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 868 | if (rvh) { |
| 869 | rvh->ResizeRectChanged(GetRootWindowResizerRect()); |
| 870 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 871 | } |
| 872 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 873 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 874 | base::TimeTicks WebContentsImpl::GetLastSelectedTime() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 875 | return last_selected_time_; |
| 876 | } |
| 877 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 878 | void WebContentsImpl::WasHidden() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 879 | if (!capturing_contents_) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 880 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
| 881 | // open a tab in then background, then closes the tab before selecting it. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 882 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 883 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 884 | // window, OnWindowPosChanged() notices and calls HideContents() (which |
| 885 | // calls us). |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 886 | RenderWidgetHostViewPort* rwhv = |
| 887 | RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 888 | if (rwhv) |
| 889 | rwhv->WasHidden(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 890 | } |
| 891 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 892 | content::NotificationService::current()->Notify( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 893 | content::NOTIFICATION_WEB_CONTENTS_HIDDEN, |
| 894 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 895 | content::NotificationService::NoDetails()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 896 | } |
| 897 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 898 | void WebContentsImpl::ShowContents() { |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 899 | RenderWidgetHostViewPort* rwhv = |
| 900 | RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 901 | if (rwhv) |
| 902 | rwhv->DidBecomeSelected(); |
| 903 | } |
| 904 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 905 | void WebContentsImpl::HideContents() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 906 | // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
| 907 | // our superclass HideContents(), because some callers want to be very picky |
| 908 | // about the order in which these get called. In addition to making the code |
| 909 | // here practically impossible to understand, this also means we end up |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 910 | // calling WebContentsImpl::WasHidden() twice if callers call both versions of |
| 911 | // HideContents() on a WebContentsImpl. |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 912 | WasHidden(); |
| 913 | } |
| 914 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 915 | bool WebContentsImpl::NeedToFireBeforeUnload() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 916 | // TODO(creis): Should we fire even for interstitial pages? |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 917 | return WillNotifyDisconnection() && |
| 918 | !ShowingInterstitialPage() && |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 919 | !static_cast<RenderViewHostImpl*>( |
| 920 | GetRenderViewHost())->SuddenTerminationAllowed(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 921 | } |
| 922 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 923 | void WebContentsImpl::Stop() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 924 | render_manager_.Stop(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 925 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 926 | } |
| 927 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 928 | WebContents* WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 929 | // We use our current SiteInstance since the cloned entry will use it anyway. |
| 930 | // We pass |this| for the |base_web_contents| to size the view correctly, and |
| 931 | // our own opener so that the cloned page can access it if it was before. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 932 | WebContentsImpl* tc = new WebContentsImpl( |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 933 | GetBrowserContext(), GetSiteInstance(), |
| 934 | MSG_ROUTING_NONE, this, opener_, NULL); |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 935 | tc->GetControllerImpl().CopyStateFrom(controller_); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 936 | return tc; |
| 937 | } |
| 938 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 939 | void WebContentsImpl::AddNewContents(WebContents* new_contents, |
| 940 | WindowOpenDisposition disposition, |
| 941 | const gfx::Rect& initial_pos, |
| 942 | bool user_gesture) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 943 | if (!delegate_) |
| 944 | return; |
| 945 | |
| 946 | delegate_->AddNewContents(this, new_contents, disposition, initial_pos, |
| 947 | user_gesture); |
| 948 | } |
| 949 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 950 | gfx::NativeView WebContentsImpl::GetContentNativeView() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 951 | return view_->GetContentNativeView(); |
| 952 | } |
| 953 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 954 | gfx::NativeView WebContentsImpl::GetNativeView() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 955 | return view_->GetNativeView(); |
| 956 | } |
| 957 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 958 | void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 959 | view_->GetContainerBounds(out); |
| 960 | } |
| 961 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 962 | void WebContentsImpl::Focus() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 963 | view_->Focus(); |
| 964 | } |
| 965 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 966 | void WebContentsImpl::Observe(int type, |
| 967 | const content::NotificationSource& source, |
| 968 | const content::NotificationDetails& details) { |
| 969 | switch (type) { |
| 970 | case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: |
| 971 | OnWebContentsDestroyed( |
| 972 | content::Source<content::WebContents>(source).ptr()); |
| 973 | break; |
| 974 | default: |
| 975 | NOTREACHED(); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) { |
| 980 | // Clear the opener if it has been closed. |
| 981 | if (web_contents == opener_) { |
| 982 | registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 983 | content::Source<WebContents>(opener_)); |
| 984 | opener_ = NULL; |
| 985 | } |
| 986 | } |
| 987 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 988 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 989 | observers_.AddObserver(observer); |
| 990 | } |
| 991 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 992 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 993 | observers_.RemoveObserver(observer); |
| 994 | } |
| 995 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 996 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 997 | if (delegate_) |
| 998 | delegate_->ActivateContents(this); |
| 999 | } |
| 1000 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1001 | void WebContentsImpl::Deactivate() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1002 | if (delegate_) |
| 1003 | delegate_->DeactivateContents(this); |
| 1004 | } |
| 1005 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1006 | void WebContentsImpl::LostCapture() { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1007 | if (delegate_) |
| 1008 | delegate_->LostCapture(); |
| 1009 | } |
| 1010 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1011 | bool WebContentsImpl::PreHandleKeyboardEvent( |
| 1012 | const NativeWebKeyboardEvent& event, |
| 1013 | bool* is_keyboard_shortcut) { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1014 | return delegate_ && |
| 1015 | delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 1016 | } |
| 1017 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1018 | void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1019 | if (delegate_) |
| 1020 | delegate_->HandleKeyboardEvent(event); |
| 1021 | } |
| 1022 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1023 | void WebContentsImpl::HandleMouseDown() { |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 1024 | if (delegate_) |
| 1025 | delegate_->HandleMouseDown(); |
| 1026 | } |
| 1027 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1028 | void WebContentsImpl::HandleMouseUp() { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1029 | if (delegate_) |
| 1030 | delegate_->HandleMouseUp(); |
| 1031 | } |
| 1032 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1033 | void WebContentsImpl::HandleMouseActivate() { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1034 | if (delegate_) |
| 1035 | delegate_->HandleMouseActivate(); |
| 1036 | } |
| 1037 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1038 | void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) { |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1039 | if (delegate_) |
| 1040 | delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen); |
| 1041 | } |
| 1042 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1043 | bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 1044 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1045 | } |
| 1046 | |
[email protected] | 42252e0 | 2012-04-26 16:29:39 | [diff] [blame] | 1047 | void WebContentsImpl::RequestToLockMouse(bool user_gesture) { |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1048 | if (delegate_) { |
[email protected] | 42252e0 | 2012-04-26 16:29:39 | [diff] [blame] | 1049 | delegate_->RequestToLockMouse(this, user_gesture); |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1050 | } else { |
| 1051 | GotResponseToLockMouseRequest(false); |
| 1052 | } |
| 1053 | } |
| 1054 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1055 | void WebContentsImpl::LostMouseLock() { |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1056 | if (delegate_) |
| 1057 | delegate_->LostMouseLock(); |
| 1058 | } |
| 1059 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1060 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 1061 | preferred_size_ = pref_size; |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 1062 | if (delegate_) |
| 1063 | delegate_->UpdatePreferredSize(this, pref_size); |
| 1064 | } |
| 1065 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1066 | void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1067 | if (delegate_) |
| 1068 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 1069 | } |
| 1070 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1071 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1072 | if (!delegate_) |
| 1073 | return NULL; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1074 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1075 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
| 1076 | // Notify observers. |
| 1077 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1078 | DidOpenURL(params.url, params.referrer, |
| 1079 | params.disposition, params.transition)); |
| 1080 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1081 | } |
| 1082 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1083 | bool WebContentsImpl::NavigateToPendingEntry( |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1084 | NavigationController::ReloadType reload_type) { |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1085 | return NavigateToEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1086 | *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()), |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1087 | reload_type); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 1088 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1089 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1090 | bool WebContentsImpl::NavigateToEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1091 | const NavigationEntryImpl& entry, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1092 | NavigationController::ReloadType reload_type) { |
[email protected] | 19e8114 | 2011-10-03 16:19:40 | [diff] [blame] | 1093 | // The renderer will reject IPC messages with URLs longer than |
| 1094 | // this limit, so don't attempt to navigate with a longer URL. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1095 | if (entry.GetURL().spec().size() > content::kMaxURLChars) |
[email protected] | 19e8114 | 2011-10-03 16:19:40 | [diff] [blame] | 1096 | return false; |
| 1097 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1098 | RenderViewHostImpl* dest_render_view_host = |
| 1099 | static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry)); |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1100 | if (!dest_render_view_host) |
| 1101 | return false; // Unable to create the desired render view host. |
| 1102 | |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1103 | // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
[email protected] | 05fdd49 | 2010-11-15 17:52:07 | [diff] [blame] | 1104 | // Double check that here. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1105 | int enabled_bindings = dest_render_view_host->GetEnabledBindings(); |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 1106 | WebUIControllerFactory* factory = |
| 1107 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 1108 | bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI(); |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 1109 | bool is_allowed_in_web_ui_renderer = |
| 1110 | factory && |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 1111 | factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(), |
| 1112 | data_urls_allowed); |
[email protected] | 1684454a | 2012-03-24 04:12:23 | [diff] [blame] | 1113 | if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) && |
| 1114 | !is_allowed_in_web_ui_renderer) { |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 1115 | // Log the URL to help us diagnose any future failures of this CHECK. |
[email protected] | 1684454a | 2012-03-24 04:12:23 | [diff] [blame] | 1116 | content::GetContentClient()->SetActiveURL(entry.GetURL()); |
| 1117 | CHECK(0); |
| 1118 | } |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 1119 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1120 | // Tell DevTools agent that it is attached prior to the navigation. |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 1121 | DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1122 | GetRenderViewHost(), |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 1123 | dest_render_view_host, |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1124 | entry.GetURL()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1125 | |
| 1126 | // Used for page load time metrics. |
| 1127 | current_load_start_ = base::TimeTicks::Now(); |
| 1128 | |
| 1129 | // Navigate in the desired RenderViewHost. |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 1130 | ViewMsg_Navigate_Params navigate_params; |
[email protected] | dd11de5 | 2011-11-03 22:54:27 | [diff] [blame] | 1131 | MakeNavigateParams(entry, controller_, delegate_, reload_type, |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1132 | &navigate_params); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 1133 | dest_render_view_host->Navigate(navigate_params); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1134 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1135 | if (entry.GetPageID() == -1) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1136 | // HACK!! This code suppresses javascript: URLs from being added to |
| 1137 | // session history, which is what we want to do for javascript: URLs that |
| 1138 | // do not generate content. What we really need is a message from the |
| 1139 | // renderer telling us that a new page was not created. The same message |
| 1140 | // could be used for mailto: URLs and the like. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1141 | if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme)) |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1142 | return false; |
| 1143 | } |
| 1144 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1145 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1146 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1147 | observers_, |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1148 | NavigateToPendingEntry(entry.GetURL(), reload_type)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1149 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1150 | if (delegate_) |
| 1151 | delegate_->DidNavigateToPendingEntry(this); |
| 1152 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1153 | return true; |
| 1154 | } |
| 1155 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1156 | void WebContentsImpl::SetHistoryLengthAndPrune( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1157 | const SiteInstance* site_instance, |
| 1158 | int history_length, |
| 1159 | int32 minimum_page_id) { |
[email protected] | 5229253b | 2011-08-16 14:36:41 | [diff] [blame] | 1160 | // SetHistoryLengthAndPrune doesn't work when there are pending cross-site |
| 1161 | // navigations. Callers should ensure that this is the case. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1162 | if (render_manager_.pending_render_view_host()) { |
| 1163 | NOTREACHED(); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 1164 | return; |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1165 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1166 | RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1167 | if (!rvh) { |
| 1168 | NOTREACHED(); |
| 1169 | return; |
| 1170 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1171 | if (site_instance && rvh->GetSiteInstance() != site_instance) { |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1172 | NOTREACHED(); |
| 1173 | return; |
| 1174 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1175 | rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(), |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1176 | history_length, |
| 1177 | minimum_page_id)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 1178 | } |
| 1179 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1180 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1181 | if (ShowingInterstitialPage()) { |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 1182 | render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); |
| 1183 | return; |
| 1184 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1185 | GetRenderViewHostImpl()->SetInitialFocus(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1186 | } |
| 1187 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1188 | bool WebContentsImpl::ShowingInterstitialPage() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1189 | return render_manager_.interstitial_page() != NULL; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1192 | InterstitialPage* WebContentsImpl::GetInterstitialPage() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1193 | return render_manager_.interstitial_page(); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1194 | } |
| 1195 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1196 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 1197 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 1198 | // so we also support this MIME type. |
| 1199 | return contents_mime_type_ == "text/html" || |
| 1200 | contents_mime_type_ == "text/xml" || |
| 1201 | contents_mime_type_ == "application/xhtml+xml" || |
| 1202 | contents_mime_type_ == "text/plain" || |
| 1203 | contents_mime_type_ == "text/css" || |
| 1204 | net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str()); |
| 1205 | } |
| 1206 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1207 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1208 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 1209 | if (!IsSavable()) { |
[email protected] | 731809e | 2012-02-15 21:56:48 | [diff] [blame] | 1210 | download_stats::RecordDownloadSource( |
| 1211 | download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML); |
[email protected] | e30d68d | 2012-02-09 00:06:26 | [diff] [blame] | 1212 | SaveURL(GetURL(), GURL(), true); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 1213 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | Stop(); |
| 1217 | |
| 1218 | // Create the save package and possibly prompt the user for the name to save |
| 1219 | // the page as. The user prompt is an asynchronous operation that runs on |
| 1220 | // another thread. |
| 1221 | save_package_ = new SavePackage(this); |
| 1222 | save_package_->GetSaveInfo(); |
| 1223 | } |
| 1224 | |
| 1225 | // Used in automated testing to bypass prompting the user for file names. |
| 1226 | // Instead, the names and paths are hard coded rather than running them through |
| 1227 | // file name sanitation and extension / mime checking. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1228 | bool WebContentsImpl::SavePage(const FilePath& main_file, |
| 1229 | const FilePath& dir_path, |
| 1230 | content::SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1231 | // Stop the page from navigating. |
| 1232 | Stop(); |
| 1233 | |
| 1234 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 6474b11 | 2012-05-04 19:35:27 | [diff] [blame] | 1235 | return save_package_->Init(content::SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1236 | } |
| 1237 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1238 | void WebContentsImpl::GenerateMHTML( |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 1239 | const FilePath& file, |
| 1240 | const base::Callback<void(const FilePath&, int64)>& callback) { |
| 1241 | MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback); |
| 1242 | } |
| 1243 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1244 | bool WebContentsImpl::IsActiveEntry(int32 page_id) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1245 | NavigationEntryImpl* active_entry = |
| 1246 | NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1247 | return (active_entry != NULL && |
| 1248 | active_entry->site_instance() == GetSiteInstance() && |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1249 | active_entry->GetPageID() == page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1250 | } |
| 1251 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1252 | const std::string& WebContentsImpl::GetContentsMimeType() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1253 | return contents_mime_type_; |
| 1254 | } |
| 1255 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1256 | bool WebContentsImpl::WillNotifyDisconnection() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1257 | return notify_disconnection_; |
| 1258 | } |
| 1259 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1260 | void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1261 | SetEncoding(encoding); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1262 | GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding( |
| 1263 | GetRenderViewHost()->GetRoutingID(), encoding)); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1264 | } |
| 1265 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1266 | void WebContentsImpl::ResetOverrideEncoding() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1267 | encoding_.clear(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1268 | GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault( |
| 1269 | GetRenderViewHost()->GetRoutingID())); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1270 | } |
| 1271 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1272 | content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1273 | return &renderer_preferences_; |
| 1274 | } |
| 1275 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1276 | void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1277 | new_tab_start_time_ = time; |
| 1278 | } |
| 1279 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1280 | base::TimeTicks WebContentsImpl::GetNewTabStartTime() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1281 | return new_tab_start_time_; |
| 1282 | } |
| 1283 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1284 | void WebContentsImpl::OnCloseStarted() { |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 1285 | if (close_start_time_.is_null()) |
| 1286 | close_start_time_ = base::TimeTicks::Now(); |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1287 | } |
| 1288 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1289 | bool WebContentsImpl::ShouldAcceptDragAndDrop() const { |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1290 | #if defined(OS_CHROMEOS) |
| 1291 | // ChromeOS panels (pop-ups) do not take drag-n-drop. |
| 1292 | // See http://crosbug.com/2413 |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1293 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
[email protected] | b83af49 | 2010-10-09 03:21:20 | [diff] [blame] | 1294 | return false; |
| 1295 | return true; |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1296 | #else |
| 1297 | return true; |
| 1298 | #endif |
| 1299 | } |
| 1300 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1301 | void WebContentsImpl::SystemDragEnded() { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1302 | if (GetRenderViewHost()) |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1303 | GetRenderViewHostImpl()->DragSourceSystemDragEnded(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1304 | if (delegate_) |
| 1305 | delegate_->DragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 1306 | } |
| 1307 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1308 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1309 | closed_by_user_gesture_ = value; |
| 1310 | } |
| 1311 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1312 | bool WebContentsImpl::GetClosedByUserGesture() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1313 | return closed_by_user_gesture_; |
| 1314 | } |
| 1315 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1316 | double WebContentsImpl::GetZoomLevel() const { |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 1317 | HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( |
[email protected] | 5fe3713a | 2012-02-22 08:31:56 | [diff] [blame] | 1318 | HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1319 | if (!zoom_map) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1320 | return 0; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1321 | |
| 1322 | double zoom_level; |
| 1323 | if (temporary_zoom_settings_) { |
| 1324 | zoom_level = zoom_map->GetTemporaryZoomLevel( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1325 | GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1326 | } else { |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1327 | GURL url; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1328 | NavigationEntry* active_entry = GetController().GetActiveEntry(); |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1329 | // Since zoom map is updated using rewritten URL, use rewritten URL |
| 1330 | // to get the zoom level. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1331 | url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1332 | zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1333 | } |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1334 | return zoom_level; |
| 1335 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1336 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1337 | int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
| 1338 | bool* enable_decrement) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1339 | *enable_decrement = *enable_increment = false; |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1340 | // Calculate the zoom percent from the factor. Round up to the nearest whole |
| 1341 | // number. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1342 | int percent = static_cast<int>( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1343 | WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1344 | *enable_decrement = percent > minimum_zoom_percent_; |
| 1345 | *enable_increment = percent < maximum_zoom_percent_; |
| 1346 | return percent; |
| 1347 | } |
| 1348 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1349 | void WebContentsImpl::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1350 | if (!delegate_) |
| 1351 | return; |
| 1352 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1353 | NavigationEntry* active_entry = GetController().GetActiveEntry(); |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1354 | if (!active_entry) |
| 1355 | return; |
| 1356 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1357 | delegate_->ViewSourceForTab(this, active_entry->GetURL()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1358 | } |
| 1359 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1360 | void WebContentsImpl::ViewFrameSource(const GURL& url, |
| 1361 | const std::string& content_state) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1362 | if (!delegate_) |
| 1363 | return; |
| 1364 | |
| 1365 | delegate_->ViewSourceForFrame(this, url, content_state); |
| 1366 | } |
| 1367 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1368 | int WebContentsImpl::GetMinimumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1369 | return minimum_zoom_percent_; |
| 1370 | } |
| 1371 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1372 | int WebContentsImpl::GetMaximumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1373 | return maximum_zoom_percent_; |
| 1374 | } |
| 1375 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1376 | gfx::Size WebContentsImpl::GetPreferredSize() const { |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 1377 | return preferred_size_; |
| 1378 | } |
| 1379 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1380 | int WebContentsImpl::GetContentRestrictions() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1381 | return content_restrictions_; |
| 1382 | } |
| 1383 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1384 | WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 1385 | WebUIControllerFactory* factory = |
| 1386 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 1387 | if (!factory) |
| 1388 | return WebUI::kNoWebUI; |
| 1389 | return factory->GetWebUIType(GetBrowserContext(), GetURL()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1390 | } |
| 1391 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1392 | content::WebUI* WebContentsImpl::GetWebUIForCurrentState() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1393 | // When there is a pending navigation entry, we want to use the pending WebUI |
| 1394 | // that goes along with it to control the basic flags. For example, we want to |
| 1395 | // show the pending URL in the URL bar, so we want the display_url flag to |
| 1396 | // be from the pending entry. |
| 1397 | // |
| 1398 | // The confusion comes because there are multiple possibilities for the |
| 1399 | // initial load in a tab as a side effect of the way the RenderViewHostManager |
| 1400 | // works. |
| 1401 | // |
| 1402 | // - For the very first tab the load looks "normal". The new tab Web UI is |
| 1403 | // the pending one, and we want it to apply here. |
| 1404 | // |
| 1405 | // - For subsequent new tabs, they'll get a new SiteInstance which will then |
| 1406 | // get switched to the one previously associated with the new tab pages. |
| 1407 | // This switching will cause the manager to commit the RVH/WebUI. So we'll |
| 1408 | // have a committed Web UI in this case. |
| 1409 | // |
| 1410 | // This condition handles all of these cases: |
| 1411 | // |
| 1412 | // - First load in first tab: no committed nav entry + pending nav entry + |
| 1413 | // pending dom ui: |
| 1414 | // -> Use pending Web UI if any. |
| 1415 | // |
| 1416 | // - First load in second tab: no committed nav entry + pending nav entry + |
| 1417 | // no pending Web UI: |
| 1418 | // -> Use the committed Web UI if any. |
| 1419 | // |
| 1420 | // - Second navigation in any tab: committed nav entry + pending nav entry: |
| 1421 | // -> Use pending Web UI if any. |
| 1422 | // |
| 1423 | // - Normal state with no load: committed nav entry + no pending nav entry: |
| 1424 | // -> Use committed Web UI. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1425 | if (controller_.GetPendingEntry() && |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1426 | (controller_.GetLastCommittedEntry() || |
| 1427 | render_manager_.pending_web_ui())) |
| 1428 | return render_manager_.pending_web_ui(); |
| 1429 | return render_manager_.web_ui(); |
| 1430 | } |
| 1431 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1432 | bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1433 | return GetRenderViewHost() ? |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1434 | GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1435 | } |
| 1436 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1437 | bool WebContentsImpl::HasOpener() const { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1438 | return opener_ != NULL; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 1439 | } |
| 1440 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1441 | void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1442 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1443 | GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse( |
| 1444 | GetRenderViewHost()->GetRoutingID(), color_chooser_id, color)); |
| 1445 | } |
| 1446 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1447 | void WebContentsImpl::DidEndColorChooser(int color_chooser_id) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1448 | GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser( |
| 1449 | GetRenderViewHost()->GetRoutingID(), color_chooser_id)); |
| 1450 | if (delegate_) |
| 1451 | delegate_->DidEndColorChooser(); |
| 1452 | color_chooser_ = NULL; |
| 1453 | } |
| 1454 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1455 | bool WebContentsImpl::FocusLocationBarByDefault() { |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 1456 | content::WebUI* web_ui = GetWebUIForCurrentState(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1457 | if (web_ui) |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1458 | return web_ui->ShouldFocusLocationBarByDefault(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1459 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 1460 | return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL)); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1463 | void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1464 | if (delegate_) |
| 1465 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 1466 | } |
| 1467 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1468 | void WebContentsImpl::OnRegisterIntentService(const string16& action, |
| 1469 | const string16& type, |
| 1470 | const string16& href, |
| 1471 | const string16& title, |
| 1472 | const string16& disposition) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1473 | delegate_->RegisterIntentHandler( |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1474 | this, action, type, href, title, disposition); |
| 1475 | } |
| 1476 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1477 | void WebContentsImpl::OnWebIntentDispatch( |
| 1478 | const webkit_glue::WebIntentData& intent, |
| 1479 | int intent_id) { |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1480 | WebIntentsDispatcherImpl* intents_dispatcher = |
| 1481 | new WebIntentsDispatcherImpl(this, intent, intent_id); |
| 1482 | delegate_->WebIntentDispatch(this, intents_dispatcher); |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1483 | } |
| 1484 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1485 | void WebContentsImpl::DidStartProvisionalLoadForFrame( |
| 1486 | content::RenderViewHost* render_view_host, |
| 1487 | int64 frame_id, |
| 1488 | bool is_main_frame, |
| 1489 | const GURL& opener_url, |
| 1490 | const GURL& url) { |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 1491 | bool is_error_page = (url.spec() == content::kUnreachableWebDataURL); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1492 | GURL validated_url(url); |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1493 | GURL validated_opener_url(opener_url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1494 | RenderViewHostImpl* render_view_host_impl = |
| 1495 | static_cast<RenderViewHostImpl*>(render_view_host); |
| 1496 | content::RenderProcessHost* render_process_host = |
| 1497 | render_view_host->GetProcess(); |
| 1498 | render_view_host_impl->FilterURL( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1499 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1500 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1501 | false, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1502 | &validated_url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1503 | render_view_host_impl->FilterURL( |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1504 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1505 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1506 | true, |
| 1507 | &validated_opener_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1508 | |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1509 | // Notify observers about the start of the provisional load. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1510 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1511 | DidStartProvisionalLoadForFrame(frame_id, is_main_frame, |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1512 | validated_url, is_error_page, render_view_host)); |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1513 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1514 | if (is_main_frame) { |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 1515 | // Notify observers about the provisional change in the main frame URL. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1516 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1517 | ProvisionalChangeToMainFrameUrl(validated_url, |
| 1518 | validated_opener_url)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1522 | void WebContentsImpl::DidRedirectProvisionalLoad( |
| 1523 | content::RenderViewHost* render_view_host, |
| 1524 | int32 page_id, |
| 1525 | const GURL& opener_url, |
| 1526 | const GURL& source_url, |
| 1527 | const GURL& target_url) { |
[email protected] | 18ba2b1 | 2011-04-06 16:35:49 | [diff] [blame] | 1528 | // TODO(creis): Remove this method and have the pre-rendering code listen to |
| 1529 | // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification |
| 1530 | // instead. See http://crbug.com/78512. |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1531 | GURL validated_source_url(source_url); |
| 1532 | GURL validated_target_url(target_url); |
| 1533 | GURL validated_opener_url(opener_url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1534 | RenderViewHostImpl* render_view_host_impl = |
| 1535 | static_cast<RenderViewHostImpl*>(render_view_host); |
| 1536 | content::RenderProcessHost* render_process_host = |
| 1537 | render_view_host->GetProcess(); |
| 1538 | render_view_host_impl->FilterURL( |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1539 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1540 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1541 | false, |
| 1542 | &validated_source_url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1543 | render_view_host_impl->FilterURL( |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1544 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1545 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1546 | false, |
| 1547 | &validated_target_url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1548 | render_view_host_impl->FilterURL( |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1549 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1550 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1551 | true, |
| 1552 | &validated_opener_url); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1553 | NavigationEntry* entry; |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1554 | if (page_id == -1) { |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1555 | entry = controller_.GetPendingEntry(); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1556 | } else { |
| 1557 | entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(), |
| 1558 | page_id); |
| 1559 | } |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1560 | if (!entry || entry->GetURL() != validated_source_url) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1561 | return; |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 1562 | |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 1563 | // Notify observers about the provisional change in the main frame URL. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1564 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1565 | ProvisionalChangeToMainFrameUrl(validated_target_url, |
| 1566 | validated_opener_url)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1567 | } |
| 1568 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1569 | void WebContentsImpl::DidFailProvisionalLoadWithError( |
| 1570 | content::RenderViewHost* render_view_host, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1571 | const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) { |
| 1572 | VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() |
| 1573 | << ", error_code: " << params.error_code |
| 1574 | << ", error_description: " << params.error_description |
| 1575 | << ", is_main_frame: " << params.is_main_frame |
| 1576 | << ", showing_repost_interstitial: " << |
| 1577 | params.showing_repost_interstitial |
| 1578 | << ", frame_id: " << params.frame_id; |
| 1579 | GURL validated_url(params.url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1580 | RenderViewHostImpl* render_view_host_impl = |
| 1581 | static_cast<RenderViewHostImpl*>(render_view_host); |
| 1582 | content::RenderProcessHost* render_process_host = |
| 1583 | render_view_host->GetProcess(); |
| 1584 | render_view_host_impl->FilterURL( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1585 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1586 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1587 | false, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1588 | &validated_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1589 | |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1590 | if (net::ERR_ABORTED == params.error_code) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1591 | // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. |
| 1592 | // This means that the interstitial won't be torn down properly, which is |
| 1593 | // bad. But if we have an interstitial, go back to another tab type, and |
| 1594 | // then load the same interstitial again, we could end up getting the first |
| 1595 | // interstitial's "failed" message (as a result of the cancel) when we're on |
| 1596 | // the second one. |
| 1597 | // |
| 1598 | // We can't tell this apart, so we think we're tearing down the current page |
| 1599 | // which will cause a crash later one. There is also some code in |
| 1600 | // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented |
| 1601 | // out because of this problem. |
| 1602 | // |
| 1603 | // http://code.google.com/p/chromium/issues/detail?id=2855 |
| 1604 | // Because this will not tear down the interstitial properly, if "back" is |
| 1605 | // back to another tab type, the interstitial will still be somewhat alive |
| 1606 | // in the previous tab type. If you navigate somewhere that activates the |
| 1607 | // tab with the interstitial again, you'll see a flash before the new load |
| 1608 | // commits of the interstitial page. |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1609 | if (ShowingInterstitialPage()) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1610 | LOG(WARNING) << "Discarding message during interstitial."; |
| 1611 | return; |
| 1612 | } |
| 1613 | |
[email protected] | 02102f8 | 2011-06-13 20:37:02 | [diff] [blame] | 1614 | // Discard our pending entry if the load canceled (e.g. if we decided to |
| 1615 | // download the file instead of load it). We do not verify that the URL |
| 1616 | // being canceled matches the pending entry's URL because they will not |
| 1617 | // match if a redirect occurred (in which case we do not want to leave a |
| 1618 | // stale redirect URL showing). This means that we also cancel the pending |
| 1619 | // entry if the user started a new navigation. As a result, the navigation |
| 1620 | // controller may not remember that a load is in progress, but the |
| 1621 | // navigation will still commit even if there is no pending entry. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1622 | if (controller_.GetPendingEntry()) |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 1623 | DidCancelLoading(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1624 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame^] | 1625 | render_manager_.RendererAbortedProvisionalLoad(render_view_host); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1626 | } |
| 1627 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1628 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1629 | observers_, |
| 1630 | DidFailProvisionalLoad(params.frame_id, |
| 1631 | params.is_main_frame, |
| 1632 | validated_url, |
| 1633 | params.error_code, |
| 1634 | params.error_description)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1635 | } |
| 1636 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1637 | void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1638 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 1639 | const std::string& security_info, |
| 1640 | const std::string& http_method, |
| 1641 | ResourceType::Type resource_type) { |
[email protected] | 2862086 | 2011-03-22 23:07:19 | [diff] [blame] | 1642 | base::StatsCounter cache("WebKit.CacheHit"); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1643 | cache.Increment(); |
| 1644 | |
| 1645 | // Send out a notification that we loaded a resource from our memory cache. |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 1646 | int cert_id = 0; |
| 1647 | net::CertStatus cert_status = 0; |
| 1648 | int security_bits = -1; |
| 1649 | int connection_status = 0; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 1650 | content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status, |
| 1651 | &security_bits, &connection_status); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1652 | LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(), |
[email protected] | 7a8c55e | 2011-02-15 08:21:16 | [diff] [blame] | 1653 | cert_id, cert_status); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1654 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1655 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1656 | content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1657 | content::Source<NavigationController>(&controller_), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1658 | content::Details<LoadFromMemoryCacheDetails>(&details)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1659 | } |
| 1660 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1661 | void WebContentsImpl::OnDidDisplayInsecureContent() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1662 | content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1663 | displayed_insecure_content_ = true; |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 1664 | SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1665 | } |
| 1666 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1667 | void WebContentsImpl::OnDidRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 1668 | const std::string& security_origin, const GURL& target_url) { |
[email protected] | 9941cf5 | 2011-02-08 16:17:23 | [diff] [blame] | 1669 | LOG(INFO) << security_origin << " ran insecure content from " |
| 1670 | << target_url.possibly_invalid_spec(); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1671 | content::RecordAction(UserMetricsAction("SSL.RanInsecureContent")); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 1672 | if (EndsWith(security_origin, kDotGoogleDotCom, false)) |
| 1673 | content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle")); |
[email protected] | 330614de | 2012-02-13 17:07:18 | [diff] [blame] | 1674 | controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
[email protected] | f2b58c4d | 2011-06-01 23:29:41 | [diff] [blame] | 1675 | displayed_insecure_content_ = true; |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 1676 | SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1677 | } |
| 1678 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1679 | void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1680 | controller_.DocumentLoadedInFrame(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1681 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1682 | DocumentLoadedInFrame(frame_id)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1683 | } |
| 1684 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1685 | void WebContentsImpl::OnDidFinishLoad( |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1686 | int64 frame_id, |
| 1687 | const GURL& validated_url, |
| 1688 | bool is_main_frame) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1689 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1690 | DidFinishLoad(frame_id, validated_url, is_main_frame)); |
| 1691 | } |
| 1692 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1693 | void WebContentsImpl::OnDidFailLoadWithError( |
| 1694 | int64 frame_id, |
| 1695 | const GURL& validated_url, |
| 1696 | bool is_main_frame, |
| 1697 | int error_code, |
| 1698 | const string16& error_description) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1699 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1700 | DidFailLoad(frame_id, validated_url, is_main_frame, |
| 1701 | error_code, error_description)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1702 | } |
| 1703 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1704 | void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1705 | content_restrictions_ = restrictions; |
| 1706 | delegate_->ContentRestrictionsChanged(this); |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 1707 | } |
| 1708 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1709 | void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1710 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1711 | NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1712 | controller_.GetEntryAtOffset(offset)); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1713 | if (!entry) |
| 1714 | return; |
| 1715 | // Note that we don't call NavigationController::GotToOffset() as we don't |
| 1716 | // want to create a pending navigation entry (it might end up lingering |
| 1717 | // http://crbug.com/51680). |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1718 | entry->SetTransitionType( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1719 | content::PageTransitionFromInt( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1720 | entry->GetTransitionType() | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1721 | content::PAGE_TRANSITION_FORWARD_BACK)); |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1722 | NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD); |
[email protected] | a13cc36 | 2011-07-28 21:29:57 | [diff] [blame] | 1723 | |
| 1724 | // If the entry is being restored and doesn't have a SiteInstance yet, fill |
| 1725 | // it in now that we know. This allows us to find the entry when it commits. |
| 1726 | if (!entry->site_instance() && |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1727 | entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1728 | entry->set_site_instance( |
| 1729 | static_cast<SiteInstanceImpl*>(GetPendingSiteInstance())); |
[email protected] | a13cc36 | 2011-07-28 21:29:57 | [diff] [blame] | 1730 | } |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1734 | void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
| 1735 | int maximum_percent, |
| 1736 | bool remember) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1737 | minimum_zoom_percent_ = minimum_percent; |
| 1738 | maximum_zoom_percent_ = maximum_percent; |
| 1739 | temporary_zoom_settings_ = !remember; |
| 1740 | } |
| 1741 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1742 | void WebContentsImpl::OnSaveURL(const GURL& url) { |
[email protected] | 731809e | 2012-02-15 21:56:48 | [diff] [blame] | 1743 | download_stats::RecordDownloadSource( |
| 1744 | download_stats::INITIATED_BY_PEPPER_SAVE); |
[email protected] | e30d68d | 2012-02-09 00:06:26 | [diff] [blame] | 1745 | // Check if the URL to save matches the URL of the main frame. Since this |
| 1746 | // message originates from Pepper plugins, it may not be the case if the |
| 1747 | // plugin is an embedded element. |
| 1748 | GURL main_frame_url = GetURL(); |
| 1749 | if (!main_frame_url.is_valid()) |
| 1750 | return; |
| 1751 | bool is_main_frame = (url == main_frame_url); |
| 1752 | SaveURL(url, main_frame_url, is_main_frame); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1753 | } |
| 1754 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1755 | void WebContentsImpl::OnEnumerateDirectory(int request_id, |
| 1756 | const FilePath& path) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 1757 | ChildProcessSecurityPolicyImpl* policy = |
| 1758 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 1759 | if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path)) |
| 1760 | delegate_->EnumerateDirectory(this, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1761 | } |
| 1762 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1763 | void WebContentsImpl::OnJSOutOfMemory() { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1764 | delegate_->JSOutOfMemory(this); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1765 | } |
| 1766 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1767 | void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol, |
| 1768 | const GURL& url, |
| 1769 | const string16& title) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 1770 | ChildProcessSecurityPolicyImpl* policy = |
| 1771 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 1772 | if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol)) |
| 1773 | return; |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1774 | delegate_->RegisterProtocolHandler(this, protocol, url, title); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1775 | } |
| 1776 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1777 | void WebContentsImpl::OnFindReply(int request_id, |
| 1778 | int number_of_matches, |
| 1779 | const gfx::Rect& selection_rect, |
| 1780 | int active_match_ordinal, |
| 1781 | bool final_update) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1782 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 1783 | active_match_ordinal, final_update); |
[email protected] | 4e6239c | 2011-09-23 00:11:00 | [diff] [blame] | 1784 | // Send a notification to the renderer that we are ready to receive more |
| 1785 | // results from the scoping effort of the Find operation. The FindInPage |
| 1786 | // scoping is asynchronous and periodically sends results back up to the |
| 1787 | // browser using IPC. In an effort to not spam the browser we have the |
| 1788 | // browser send an ACK for each FindReply message and have the renderer |
| 1789 | // queue up the latest status message while waiting for this ACK. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1790 | GetRenderViewHostImpl()->Send( |
| 1791 | new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID())); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 1792 | } |
| 1793 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1794 | void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) { |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 1795 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1796 | PluginCrashed(plugin_path)); |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 1797 | } |
| 1798 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1799 | void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, |
| 1800 | bool blocked_by_policy) { |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 1801 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1802 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 1803 | AppCacheAccessed(manifest_url, blocked_by_policy)); |
| 1804 | } |
| 1805 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1806 | void WebContentsImpl::OnOpenColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1807 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1808 | color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color); |
| 1809 | } |
| 1810 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1811 | void WebContentsImpl::OnEndColorChooser(int color_chooser_id) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1812 | if (color_chooser_ && |
| 1813 | color_chooser_id == color_chooser_->identifier()) |
| 1814 | color_chooser_->End(); |
| 1815 | } |
| 1816 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1817 | void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1818 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1819 | if (color_chooser_ && |
| 1820 | color_chooser_id == color_chooser_->identifier()) |
| 1821 | color_chooser_->SetSelectedColor(color); |
| 1822 | } |
| 1823 | |
[email protected] | 9f2a9d7 | 2012-04-16 16:02:22 | [diff] [blame] | 1824 | void WebContentsImpl::OnPepperPluginHung(int plugin_child_id, |
| 1825 | const FilePath& path, |
| 1826 | bool is_hung) { |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 1827 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1828 | PluginHungStatusChanged(plugin_child_id, path, is_hung)); |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 1829 | } |
| 1830 | |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 1831 | // This exists for render views that don't have a WebUI, but do have WebUI |
| 1832 | // bindings enabled. |
| 1833 | void WebContentsImpl::OnWebUISend(const GURL& source_url, |
| 1834 | const std::string& name, |
| 1835 | const base::ListValue& args) { |
| 1836 | if (delegate_) |
| 1837 | delegate_->WebUISend(this, source_url, name, args); |
| 1838 | } |
| 1839 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1840 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 1841 | // loading, or done loading and calls the base implementation. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1842 | void WebContentsImpl::SetIsLoading(bool is_loading, |
| 1843 | LoadNotificationDetails* details) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1844 | if (is_loading == is_loading_) |
| 1845 | return; |
| 1846 | |
| 1847 | if (!is_loading) { |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 1848 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1849 | load_state_host_.clear(); |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 1850 | upload_size_ = 0; |
| 1851 | upload_position_ = 0; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | render_manager_.SetIsLoading(is_loading); |
| 1855 | |
| 1856 | is_loading_ = is_loading; |
| 1857 | waiting_for_response_ = is_loading; |
| 1858 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1859 | if (delegate_) |
| 1860 | delegate_->LoadingStateChanged(this); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1861 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1862 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1863 | int type = is_loading ? content::NOTIFICATION_LOAD_START : |
| 1864 | content::NOTIFICATION_LOAD_STOP; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1865 | content::NotificationDetails det = content::NotificationService::NoDetails(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1866 | if (details) |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1867 | det = content::Details<LoadNotificationDetails>(details); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1868 | content::NotificationService::current()->Notify(type, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1869 | content::Source<NavigationController>(&controller_), |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1870 | det); |
| 1871 | } |
| 1872 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1873 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 1874 | const content::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1875 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1876 | if (opener_web_ui_type_ != WebUI::kNoWebUI) { |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1877 | // If this is a window.open navigation, use the same WebUI as the renderer |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1878 | // that opened the window, as long as both renderers have the same |
| 1879 | // privileges. |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1880 | if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 1881 | WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL())); |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1882 | // web_ui might be NULL if the URL refers to a non-existent extension. |
| 1883 | if (web_ui) { |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 1884 | render_manager_.SetWebUIPostCommit(web_ui); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1885 | web_ui->RenderViewCreated(GetRenderViewHost()); |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1886 | } |
| 1887 | } |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1888 | opener_web_ui_type_ = WebUI::kNoWebUI; |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1889 | } |
| 1890 | |
[email protected] | 4e697b04 | 2011-07-08 06:44:56 | [diff] [blame] | 1891 | if (details.is_navigation_to_different_page()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1892 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1893 | // doesn't let us know that the cursor left an element during a |
| 1894 | // transition (this is also why the mouse cursor remains as a hand after |
| 1895 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1896 | // clear the bubble when a user navigates to a named anchor in the same |
| 1897 | // page. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1898 | UpdateTargetURL(details.entry->GetPageID(), GURL()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1899 | } |
| 1900 | |
[email protected] | a6e82fc | 2010-02-24 22:28:14 | [diff] [blame] | 1901 | if (!details.is_in_page) { |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 1902 | // Once the main frame is navigated, we're no longer considered to have |
| 1903 | // displayed insecure content. |
| 1904 | displayed_insecure_content_ = false; |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 1905 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1906 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1907 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1908 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 1909 | DidNavigateMainFrame(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1912 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1913 | RenderViewHost* render_view_host, |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 1914 | const content::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1915 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | e550f5e | 2012-01-11 07:22:06 | [diff] [blame] | 1916 | // If we navigate off the page, reset JavaScript state. This does nothing |
| 1917 | // to prevent a malicious script from spamming messages, since the script |
| 1918 | // could just reload the page to stop blocking. |
| 1919 | if (dialog_creator_ && !details.is_in_page) { |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 1920 | dialog_creator_->ResetJavaScriptState(this); |
| 1921 | dialog_creator_ = NULL; |
| 1922 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1923 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1924 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1925 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 1926 | DidNavigateAnyFrame(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1927 | } |
| 1928 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1929 | void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1930 | // If we are creating a RVH for a restored controller, then we need to make |
| 1931 | // sure the RenderView starts with a next_page_id_ larger than the number |
| 1932 | // of restored entries. This must be called before the RenderView starts |
| 1933 | // navigating (to avoid a race between the browser updating max_page_id and |
| 1934 | // the renderer updating next_page_id_). Because of this, we only call this |
| 1935 | // from CreateRenderView and allow that to notify the RenderView for us. |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 1936 | int max_restored_page_id = controller_.GetMaxRestoredPageID(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1937 | if (max_restored_page_id > |
| 1938 | GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) |
| 1939 | UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), |
| 1940 | max_restored_page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1941 | } |
| 1942 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1943 | bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry, |
| 1944 | const string16& title) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1945 | // For file URLs without a title, use the pathname instead. In the case of a |
| 1946 | // synthesized title, we don't want the update to count toward the "one set |
| 1947 | // per page of the title to history." |
[email protected] | 6b2f7a8 | 2011-04-25 19:30:51 | [diff] [blame] | 1948 | string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1949 | bool explicit_set; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1950 | if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { |
| 1951 | final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1952 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 1953 | } else { |
[email protected] | acafd27 | 2011-07-26 17:35:57 | [diff] [blame] | 1954 | TrimWhitespace(title, TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1955 | explicit_set = true; |
| 1956 | } |
| 1957 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1958 | // If a page is created via window.open and never navigated, |
| 1959 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 1960 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1961 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1962 | if (final_title == entry->GetTitle()) |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1963 | return false; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1964 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1965 | entry->SetTitle(final_title); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1966 | } else { |
| 1967 | if (page_title_when_no_navigation_entry_ == final_title) |
| 1968 | return false; // Nothing changed, don't bother. |
| 1969 | |
| 1970 | page_title_when_no_navigation_entry_ = final_title; |
| 1971 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1972 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1973 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 1974 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1975 | |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 1976 | std::pair<content::NavigationEntry*, bool> details = |
| 1977 | std::make_pair(entry, explicit_set); |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 1978 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1979 | content::NotificationService::current()->Notify( |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 1980 | content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 1981 | content::Source<WebContents>(this), |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 1982 | content::Details<std::pair<content::NavigationEntry*, bool> >(&details)); |
[email protected] | cbc0e1b | 2010-04-12 18:33:04 | [diff] [blame] | 1983 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1984 | return true; |
| 1985 | } |
| 1986 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1987 | void WebContentsImpl::NotifySwapped() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1988 | // After sending out a swap notification, we need to send a disconnect |
| 1989 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 1990 | // pointer. See Bug 1230284. |
| 1991 | notify_disconnection_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1992 | content::NotificationService::current()->Notify( |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1993 | content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 1994 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1995 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1996 | } |
| 1997 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1998 | void WebContentsImpl::NotifyConnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1999 | notify_disconnection_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2000 | content::NotificationService::current()->Notify( |
[email protected] | ef9572e | 2012-01-04 22:14:12 | [diff] [blame] | 2001 | content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 2002 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2003 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2004 | } |
| 2005 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2006 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2007 | if (!notify_disconnection_) |
| 2008 | return; |
| 2009 | |
| 2010 | notify_disconnection_ = false; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2011 | content::NotificationService::current()->Notify( |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2012 | content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 2013 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2014 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2015 | } |
| 2016 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2017 | RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2018 | return view_.get(); |
| 2019 | } |
| 2020 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2021 | RenderViewHostDelegate::RendererManagement* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2022 | WebContentsImpl::GetRendererManagementDelegate() { |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2023 | return &render_manager_; |
| 2024 | } |
| 2025 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2026 | content::RendererPreferences WebContentsImpl::GetRendererPrefs( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2027 | content::BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 2028 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 2029 | } |
| 2030 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2031 | WebContents* WebContentsImpl::GetAsWebContents() { |
[email protected] | 768c547 | 2011-12-26 19:06:17 | [diff] [blame] | 2032 | return this; |
| 2033 | } |
| 2034 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2035 | content::ViewType WebContentsImpl::GetRenderViewType() const { |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 2036 | return view_type_; |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 2037 | } |
| 2038 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2039 | gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 2040 | if (delegate_) |
| 2041 | return delegate_->GetRootWindowResizerRect(); |
| 2042 | return gfx::Rect(); |
| 2043 | } |
| 2044 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2045 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2046 | // Don't send notifications if we are just creating a swapped-out RVH for |
| 2047 | // the opener chain. These won't be used for view-source or WebUI, so it's |
| 2048 | // ok to return early. |
| 2049 | if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
| 2050 | return; |
| 2051 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2052 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2053 | content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2054 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2055 | content::Details<RenderViewHost>(render_view_host)); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2056 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2057 | if (!entry) |
| 2058 | return; |
| 2059 | |
| 2060 | // When we're creating views, we're still doing initial setup, so we always |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2061 | // use the pending Web UI rather than any possibly existing committed one. |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 2062 | if (render_manager_.pending_web_ui()) |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 2063 | render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2064 | |
| 2065 | if (entry->IsViewSourceMode()) { |
| 2066 | // Put the renderer in view source mode. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2067 | static_cast<RenderViewHostImpl*>(render_view_host)->Send( |
| 2068 | new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2069 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 2070 | |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2071 | GetView()->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 2072 | |
| 2073 | FOR_EACH_OBSERVER( |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2074 | WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2075 | } |
| 2076 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2077 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2078 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2079 | // Don't notify the world, since this came from a renderer in the |
| 2080 | // background. |
| 2081 | return; |
| 2082 | } |
| 2083 | |
| 2084 | NotifyConnected(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2085 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2086 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2087 | |
| 2088 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 2089 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 2090 | if (was_crashed && !FocusLocationBarByDefault() && |
| 2091 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2092 | Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 2093 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 2094 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2095 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2096 | } |
| 2097 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2098 | void WebContentsImpl::RenderViewGone(RenderViewHost* rvh, |
| 2099 | base::TerminationStatus status, |
| 2100 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2101 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2102 | // The pending page's RenderViewHost is gone. |
| 2103 | return; |
| 2104 | } |
| 2105 | |
| 2106 | SetIsLoading(false, NULL); |
| 2107 | NotifyDisconnected(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2108 | SetIsCrashed(status, error_code); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2109 | GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2110 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2111 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 2112 | observers_, |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2113 | RenderViewGone(GetCrashedStatus())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2114 | } |
| 2115 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2116 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
[email protected] | fb7b79f7 | 2009-11-06 18:00:48 | [diff] [blame] | 2117 | render_manager_.RenderViewDeleted(rvh); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2118 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2119 | } |
| 2120 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2121 | void WebContentsImpl::DidNavigate( |
| 2122 | RenderViewHost* rvh, |
| 2123 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2124 | if (content::PageTransitionIsMainFrame(params.transition)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2125 | render_manager_.DidNavigateMainFrame(rvh); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2126 | |
[email protected] | 434f69f | 2012-02-06 21:56:52 | [diff] [blame] | 2127 | // Update the site of the SiteInstance if it doesn't have one yet, unless |
| 2128 | // this is for about:blank. In that case, the SiteInstance can still be |
| 2129 | // considered unused until a navigation to a real page. |
| 2130 | if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() && |
| 2131 | params.url != GURL(chrome::kAboutBlankURL)) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 2132 | static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url); |
[email protected] | 434f69f | 2012-02-06 21:56:52 | [diff] [blame] | 2133 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2134 | |
| 2135 | // Need to update MIME type here because it's referred to in |
| 2136 | // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 2137 | // determine whether or not to enable the encoding menu. |
| 2138 | // It's updated only for the main frame. For a subframe, |
| 2139 | // RenderView::UpdateURL does not set params.contents_mime_type. |
| 2140 | // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 2141 | // TODO(jungshik): Add a test for the encoding menu to avoid |
| 2142 | // regressing it again. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2143 | if (content::PageTransitionIsMainFrame(params.transition)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2144 | contents_mime_type_ = params.contents_mime_type; |
| 2145 | |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 2146 | content::LoadCommittedDetails details; |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2147 | bool did_navigate = controller_.RendererDidNavigate(params, &details); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2148 | |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2149 | // Send notification about committed provisional loads. This notification is |
| 2150 | // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
| 2151 | // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 2152 | if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) { |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2153 | // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
| 2154 | // that is not recorded in the navigation history. For the purpose of |
| 2155 | // tracking navigation events, we treat this event as a sub frame navigation |
| 2156 | // event. |
| 2157 | bool is_main_frame = did_navigate ? details.is_main_frame : false; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2158 | content::PageTransition transition_type = params.transition; |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2159 | // Whether or not a page transition was triggered by going backward or |
| 2160 | // forward in the history is only stored in the navigation controller's |
| 2161 | // entry list. |
| 2162 | if (did_navigate && |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2163 | (controller_.GetActiveEntry()->GetTransitionType() & |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2164 | content::PAGE_TRANSITION_FORWARD_BACK)) { |
| 2165 | transition_type = content::PageTransitionFromInt( |
| 2166 | params.transition | content::PAGE_TRANSITION_FORWARD_BACK); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2167 | } |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 2168 | // Notify observers about the commit of the provisional load. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2169 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 2170 | DidCommitProvisionalLoadForFrame(params.frame_id, |
| 2171 | is_main_frame, params.url, transition_type)); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2172 | } |
| 2173 | |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 2174 | if (!did_navigate) |
| 2175 | return; // No navigation happened. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2176 | |
| 2177 | // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 2178 | // for the appropriate notification (best) or you can add it to |
| 2179 | // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 2180 | // necessary, please). |
| 2181 | |
| 2182 | // Run post-commit tasks. |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2183 | if (details.is_main_frame) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2184 | DidNavigateMainFramePostCommit(details, params); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2185 | if (delegate_) |
| 2186 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2187 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2188 | DidNavigateAnyFramePostCommit(rvh, details, params); |
| 2189 | } |
| 2190 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2191 | void WebContentsImpl::UpdateState(RenderViewHost* rvh, |
| 2192 | int32 page_id, |
| 2193 | const std::string& state) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2194 | // Ensure that this state update comes from either the active RVH or one of |
| 2195 | // the swapped out RVHs. We don't expect to hear from any other RVHs. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2196 | DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2197 | |
| 2198 | // We must be prepared to handle state updates for any page, these occur |
| 2199 | // when the user is scrolling and entering form data, as well as when we're |
| 2200 | // leaving a page, in which case our state may have already been moved to |
| 2201 | // the next page. The navigation controller will look up the appropriate |
| 2202 | // NavigationEntry and update it when it is notified via the delegate. |
| 2203 | |
| 2204 | int entry_index = controller_.GetEntryIndexWithPageID( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2205 | rvh->GetSiteInstance(), page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2206 | if (entry_index < 0) |
| 2207 | return; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2208 | NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2209 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2210 | if (state == entry->GetContentState()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2211 | return; // Nothing to update. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2212 | entry->SetContentState(state); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2213 | controller_.NotifyEntryChanged(entry, entry_index); |
| 2214 | } |
| 2215 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2216 | void WebContentsImpl::UpdateTitle(RenderViewHost* rvh, |
| 2217 | int32 page_id, |
| 2218 | const string16& title, |
| 2219 | base::i18n::TextDirection title_direction) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2220 | // If we have a title, that's a pretty good indication that we've started |
| 2221 | // getting useful data. |
| 2222 | SetNotWaitingForResponse(); |
| 2223 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2224 | // Try to find the navigation entry, which might not be the current one. |
| 2225 | // For example, it might be from a pending RVH for the pending entry. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2226 | NavigationEntryImpl* entry = controller_.GetEntryWithPageID( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2227 | rvh->GetSiteInstance(), page_id); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2228 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2229 | // We can handle title updates when we don't have an entry in |
| 2230 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 2231 | if (!entry && rvh != GetRenderViewHost()) |
| 2232 | return; |
| 2233 | |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2234 | // TODO(evan): make use of title_direction. |
| 2235 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2236 | if (!UpdateTitleForEntry(entry, title)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2237 | return; |
| 2238 | |
| 2239 | // Broadcast notifications when the UI should be updated. |
| 2240 | if (entry == controller_.GetEntryAtOffset(0)) |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2241 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2242 | } |
| 2243 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2244 | void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host, |
| 2245 | const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2246 | SetEncoding(encoding); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2247 | } |
| 2248 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2249 | void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2250 | if (delegate_) |
| 2251 | delegate_->UpdateTargetURL(this, page_id, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2252 | } |
| 2253 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2254 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 2255 | // The UI may be in an event-tracking loop, such as between the |
| 2256 | // mouse-down and mouse-up in text selection or a button click. |
| 2257 | // Defer the close until after tracking is complete, so that we |
| 2258 | // don't free objects out from under the UI. |
| 2259 | // TODO(shess): This could probably be integrated with the |
| 2260 | // IsDoingDrag() test below. Punting for now because I need more |
| 2261 | // research to understand how this impacts platforms other than Mac. |
| 2262 | // TODO(shess): This could get more fine-grained. For instance, |
| 2263 | // closing a tab in another window while selecting text in the |
| 2264 | // current window's Omnibox should be just fine. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2265 | if (GetView()->IsEventTracking()) { |
| 2266 | GetView()->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 2267 | return; |
| 2268 | } |
| 2269 | |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 2270 | // If we close the tab while we're in the middle of a drag, we'll crash. |
| 2271 | // Instead, cancel the drag and close it as soon as the drag ends. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2272 | if (GetView()->IsDoingDrag()) { |
| 2273 | GetView()->CancelDragAndCloseTab(); |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 2274 | return; |
| 2275 | } |
| 2276 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2277 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2278 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2279 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2280 | } |
| 2281 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2282 | void WebContentsImpl::SwappedOut(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2283 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2284 | delegate_->SwappedOut(this); |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 2285 | } |
| 2286 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2287 | void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2288 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
| 2289 | delegate_->MoveContents(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2290 | } |
| 2291 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2292 | void WebContentsImpl::DidStartLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2293 | SetIsLoading(true, NULL); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2294 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2295 | if (delegate_ && content_restrictions_) |
| 2296 | OnUpdateContentRestrictions(0); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2297 | |
| 2298 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2299 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2300 | } |
| 2301 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2302 | void WebContentsImpl::DidStopLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2303 | scoped_ptr<LoadNotificationDetails> details; |
| 2304 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2305 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2306 | // An entry may not exist for a stop when loading an initial blank page or |
| 2307 | // if an iframe injected by script into a blank page finishes loading. |
| 2308 | if (entry) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2309 | base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_; |
| 2310 | |
| 2311 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2312 | entry->GetVirtualURL(), |
| 2313 | entry->GetTransitionType(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2314 | elapsed, |
| 2315 | &controller_, |
| 2316 | controller_.GetCurrentEntryIndex())); |
| 2317 | } |
| 2318 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2319 | SetIsLoading(false, details.get()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2320 | |
| 2321 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2322 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2323 | } |
| 2324 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2325 | void WebContentsImpl::DidCancelLoading() { |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 2326 | controller_.DiscardNonCommittedEntries(); |
| 2327 | |
| 2328 | // Update the URL display. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2329 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 2330 | } |
| 2331 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2332 | void WebContentsImpl::DidChangeLoadProgress(double progress) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2333 | if (delegate_) |
| 2334 | delegate_->LoadProgressChanged(progress); |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 2335 | } |
| 2336 | |
[email protected] | 87717d0e | 2012-04-26 02:58:43 | [diff] [blame] | 2337 | void WebContentsImpl::DocumentAvailableInMainFrame( |
| 2338 | RenderViewHost* render_view_host) { |
| 2339 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2340 | DocumentAvailableInMainFrame()); |
[email protected] | 952a68e | 2011-11-17 00:36:10 | [diff] [blame] | 2341 | } |
| 2342 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2343 | void WebContentsImpl::DocumentOnLoadCompletedInMainFrame( |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2344 | RenderViewHost* render_view_host, |
| 2345 | int32 page_id) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2346 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2347 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2348 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2349 | content::Details<int>(&page_id)); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2350 | } |
| 2351 | |
[email protected] | 196159d | 2012-05-04 17:26:54 | [diff] [blame] | 2352 | void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh, |
| 2353 | const GURL& url, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2354 | const content::Referrer& referrer, |
| 2355 | WindowOpenDisposition disposition, |
| 2356 | int64 source_frame_id) { |
[email protected] | 196159d | 2012-05-04 17:26:54 | [diff] [blame] | 2357 | // If this came from a swapped out RenderViewHost, we only allow the request |
| 2358 | // if we are still in the same BrowsingInstance. |
| 2359 | if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() && |
| 2360 | !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) { |
| 2361 | return; |
| 2362 | } |
| 2363 | |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2364 | // Delegate to RequestTransferURL because this is just the generic |
| 2365 | // case where |old_request_id| is empty. |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 2366 | RequestTransferURL(url, referrer, disposition, source_frame_id, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2367 | GlobalRequestID()); |
| 2368 | } |
| 2369 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2370 | void WebContentsImpl::RequestTransferURL( |
| 2371 | const GURL& url, |
| 2372 | const content::Referrer& referrer, |
| 2373 | WindowOpenDisposition disposition, |
| 2374 | int64 source_frame_id, |
| 2375 | const GlobalRequestID& old_request_id) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2376 | WebContents* new_contents = NULL; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2377 | content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 2378 | if (render_manager_.web_ui()) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2379 | // When we're a Web UI, it will provide a page transition type for us (this |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2380 | // is so the new tab page can specify AUTO_BOOKMARK for automatically |
| 2381 | // generated suggestions). |
| 2382 | // |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2383 | // Note also that we hide the referrer for Web UI pages. We don't really |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 2384 | // want web sites to see a referrer of "chrome://blah" (and some |
| 2385 | // 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] | 2386 | // send to the site), so we send no referrer. |
[email protected] | 6bf6a6b5 | 2012-02-03 15:41:43 | [diff] [blame] | 2387 | OpenURLParams params(url, content::Referrer(), source_frame_id, disposition, |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 2388 | render_manager_.web_ui()->GetLinkTransitionType(), |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2389 | false /* is_renderer_initiated */); |
| 2390 | params.transferred_global_request_id = old_request_id; |
| 2391 | new_contents = OpenURL(params); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 2392 | transition_type = render_manager_.web_ui()->GetLinkTransitionType(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2393 | } else { |
[email protected] | 6bf6a6b5 | 2012-02-03 15:41:43 | [diff] [blame] | 2394 | OpenURLParams params(url, referrer, source_frame_id, disposition, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2395 | content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */); |
| 2396 | params.transferred_global_request_id = old_request_id; |
| 2397 | new_contents = OpenURL(params); |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2398 | } |
| 2399 | if (new_contents) { |
| 2400 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2401 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2402 | DidOpenRequestedURL(new_contents, |
| 2403 | url, |
| 2404 | referrer, |
| 2405 | disposition, |
| 2406 | transition_type, |
| 2407 | source_frame_id)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 2411 | void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 2412 | // Tell the active RenderViewHost to run unload handlers and close, as long |
| 2413 | // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 2414 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 2415 | // It is possible to receive it from one that has just been swapped in, |
| 2416 | // in which case we might as well deliver the message anyway. |
| 2417 | if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
| 2418 | GetRenderViewHost()->ClosePage(); |
| 2419 | } |
| 2420 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2421 | void WebContentsImpl::RunJavaScriptMessage( |
[email protected] | fedec01 | 2012-01-28 03:09:34 | [diff] [blame] | 2422 | RenderViewHost* rvh, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2423 | const string16& message, |
| 2424 | const string16& default_prompt, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2425 | const GURL& frame_url, |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2426 | ui::JavascriptMessageType javascript_message_type, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2427 | IPC::Message* reply_msg, |
| 2428 | bool* did_suppress_message) { |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2429 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 2430 | // showing an interstitial as it's shown over the previous page and we don't |
| 2431 | // want the hidden page's dialogs to interfere with the interstitial. |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2432 | bool suppress_this_message = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2433 | static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() || |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2434 | ShowingInterstitialPage() || |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2435 | !delegate_ || |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2436 | delegate_->ShouldSuppressDialogs() || |
| 2437 | !delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2438 | |
| 2439 | if (!suppress_this_message) { |
[email protected] | 55df909 | 2012-02-29 22:56:43 | [diff] [blame] | 2440 | std::string accept_lang = content::GetContentClient()->browser()-> |
| 2441 | GetAcceptLangs(GetBrowserContext()); |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2442 | dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2443 | dialog_creator_->RunJavaScriptDialog( |
[email protected] | 55df909 | 2012-02-29 22:56:43 | [diff] [blame] | 2444 | this, |
| 2445 | frame_url.GetOrigin(), |
| 2446 | accept_lang, |
| 2447 | javascript_message_type, |
| 2448 | message, |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2449 | default_prompt, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2450 | base::Bind(&WebContentsImpl::OnDialogClosed, |
| 2451 | base::Unretained(this), |
| 2452 | rvh, |
| 2453 | reply_msg), |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2454 | &suppress_this_message); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2455 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2456 | |
| 2457 | if (suppress_this_message) { |
| 2458 | // If we are suppressing messages, just reply as if the user immediately |
| 2459 | // pressed "Cancel". |
[email protected] | fedec01 | 2012-01-28 03:09:34 | [diff] [blame] | 2460 | OnDialogClosed(rvh, reply_msg, false, string16()); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | *did_suppress_message = suppress_this_message; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2464 | } |
| 2465 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2466 | void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh, |
| 2467 | const string16& message, |
| 2468 | bool is_reload, |
| 2469 | IPC::Message* reply_msg) { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2470 | RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2471 | if (delegate_) |
| 2472 | delegate_->WillRunBeforeUnloadConfirm(); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2473 | |
| 2474 | bool suppress_this_message = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2475 | rvhi->is_swapped_out() || |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2476 | !delegate_ || |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2477 | delegate_->ShouldSuppressDialogs() || |
| 2478 | !delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2479 | if (suppress_this_message) { |
[email protected] | fedec01 | 2012-01-28 03:09:34 | [diff] [blame] | 2480 | // The reply must be sent to the RVH that sent the request. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2481 | rvhi->JavaScriptDialogClosed(reply_msg, true, string16()); |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2482 | return; |
| 2483 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2484 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2485 | is_showing_before_unload_dialog_ = true; |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2486 | dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2487 | dialog_creator_->RunBeforeUnloadDialog( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2488 | this, message, is_reload, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2489 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh, |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2490 | reply_msg)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2491 | } |
| 2492 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2493 | WebPreferences WebContentsImpl::GetWebkitPrefs() { |
[email protected] | f913393 | 2012-03-16 16:37:33 | [diff] [blame] | 2494 | // We want to base the page config off of the real URL, rather than the |
| 2495 | // display URL. |
| 2496 | GURL url = controller_.GetActiveEntry() |
| 2497 | ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); |
| 2498 | return GetWebkitPrefs(GetRenderViewHost(), url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2499 | } |
| 2500 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2501 | void WebContentsImpl::OnUserGesture() { |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 2502 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2503 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 2504 | |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 2505 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
[email protected] | b39e7a88b | 2012-01-10 21:43:17 | [diff] [blame] | 2506 | if (rdh) // NULL in unittests. |
| 2507 | rdh->OnUserGesture(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2508 | } |
| 2509 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2510 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 2511 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2512 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 2513 | } |
| 2514 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2515 | void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh, |
| 2516 | bool is_during_unload) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2517 | // Don't show hung renderer dialog for a swapped out RVH. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2518 | if (rvh != GetRenderViewHost()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2519 | return; |
| 2520 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2521 | RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
| 2522 | |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 2523 | // Ignore renderer unresponsive event if debugger is attached to the tab |
| 2524 | // since the event may be a result of the renderer sitting on a breakpoint. |
| 2525 | // See http://crbug.com/65458 |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 2526 | DevToolsAgentHost* agent = |
| 2527 | content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh); |
| 2528 | if (agent && |
| 2529 | DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent)) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 2530 | return; |
| 2531 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2532 | if (is_during_unload) { |
| 2533 | // Hang occurred while firing the beforeunload/unload handler. |
| 2534 | // Pretend the handler fired so tab closing continues as if it had. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2535 | rvhi->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2536 | |
| 2537 | if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 2538 | return; |
| 2539 | |
| 2540 | // If the tab hangs in the beforeunload/unload handler there's really |
| 2541 | // nothing we can do to recover. Pretend the unload listeners have |
| 2542 | // all fired and close the tab. If the hang is in the beforeunload handler |
| 2543 | // then the user will not have the option of cancelling the close. |
| 2544 | Close(rvh); |
| 2545 | return; |
| 2546 | } |
| 2547 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2548 | if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 2549 | return; |
| 2550 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2551 | if (delegate_) |
| 2552 | delegate_->RendererUnresponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2553 | } |
| 2554 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2555 | void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2556 | if (delegate_) |
| 2557 | delegate_->RendererResponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2558 | } |
| 2559 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2560 | void WebContentsImpl::LoadStateChanged( |
| 2561 | const GURL& url, |
| 2562 | const net::LoadStateWithParam& load_state, |
| 2563 | uint64 upload_position, |
| 2564 | uint64 upload_size) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2565 | load_state_ = load_state; |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2566 | upload_position_ = upload_position; |
| 2567 | upload_size_ = upload_size; |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 2568 | load_state_host_ = net::IDNToUnicode(url.host(), |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2569 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 2570 | GetBrowserContext())); |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 2571 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2572 | SetNotWaitingForResponse(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2573 | if (IsLoading()) { |
| 2574 | NotifyNavigationStateChanged( |
| 2575 | content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB); |
| 2576 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2577 | } |
| 2578 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2579 | void WebContentsImpl::WorkerCrashed() { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2580 | if (delegate_) |
| 2581 | delegate_->WorkerCrashed(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2582 | } |
| 2583 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2584 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2585 | bool proceed, |
| 2586 | bool* proceed_to_fire_unload) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2587 | if (delegate_) |
| 2588 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2589 | } |
| 2590 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2591 | void WebContentsImpl::DidStartLoadingFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2592 | RenderViewHost* render_view_host) { |
| 2593 | DidStartLoading(); |
| 2594 | } |
| 2595 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2596 | void WebContentsImpl::RenderViewGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2597 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2598 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
| 2599 | RenderViewGone(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2600 | } |
| 2601 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2602 | void WebContentsImpl::UpdateRenderViewSizeForRenderManager() { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 2603 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 2604 | gfx::Size size = view_->GetContainerSize(); |
| 2605 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 2606 | // here during container initialization and normal window size will be set |
| 2607 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 2608 | // normal size later so just ignore it. |
| 2609 | if (!size.IsEmpty()) |
| 2610 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2611 | } |
| 2612 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2613 | void WebContentsImpl::NotifySwappedFromRenderManager() { |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2614 | NotifySwapped(); |
| 2615 | } |
| 2616 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2617 | int WebContentsImpl::CreateOpenerRenderViewsForRenderManager( |
| 2618 | SiteInstance* instance) { |
| 2619 | if (!opener_) |
| 2620 | return MSG_ROUTING_NONE; |
| 2621 | |
| 2622 | // Recursively create RenderViews for anything else in the opener chain. |
| 2623 | return opener_->CreateOpenerRenderViews(instance); |
| 2624 | } |
| 2625 | |
| 2626 | int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) { |
| 2627 | int opener_route_id = MSG_ROUTING_NONE; |
| 2628 | |
| 2629 | // If this tab has an opener, ensure it has a RenderView in the given |
| 2630 | // SiteInstance as well. |
| 2631 | if (opener_) |
| 2632 | opener_route_id = opener_->CreateOpenerRenderViews(instance); |
| 2633 | |
| 2634 | // Create a swapped out RenderView in the given SiteInstance if none exists, |
| 2635 | // setting its opener to the given route_id. Return the new view's route_id. |
| 2636 | return render_manager_.CreateRenderView(instance, opener_route_id, true); |
| 2637 | } |
| 2638 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2639 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 2640 | return GetControllerImpl(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2641 | } |
| 2642 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2643 | WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 2644 | return static_cast<WebUIImpl*>(CreateWebUI(url)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2645 | } |
| 2646 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2647 | NavigationEntry* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2648 | WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2649 | return controller_.GetLastCommittedEntry(); |
| 2650 | } |
| 2651 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2652 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2653 | RenderViewHost* render_view_host, int opener_route_id) { |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2654 | // Can be NULL during tests. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2655 | RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 2656 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2657 | // Now that the RenderView has been created, we need to tell it its size. |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2658 | if (rwh_view) |
| 2659 | rwh_view->SetSize(view_->GetContainerSize()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2660 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 2661 | // Make sure we use the correct starting page_id in the new RenderView. |
| 2662 | UpdateMaxPageIDIfNecessary(render_view_host); |
| 2663 | int32 max_page_id = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2664 | GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance()); |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 2665 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2666 | if (!static_cast<RenderViewHostImpl*>( |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2667 | render_view_host)->CreateRenderView(string16(), opener_route_id, |
| 2668 | max_page_id)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 2669 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2670 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 2671 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2672 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 2673 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 2674 | // linux. See crbug.com/83941. |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2675 | if (rwh_view) { |
| 2676 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
| 2677 | render_widget_host->WasResized(); |
| 2678 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 2679 | #endif |
| 2680 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2681 | return true; |
| 2682 | } |
| 2683 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2684 | void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh, |
| 2685 | IPC::Message* reply_msg, |
| 2686 | bool success, |
| 2687 | const string16& user_input) { |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2688 | if (is_showing_before_unload_dialog_ && !success) { |
| 2689 | // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 2690 | // spinning, since we forced it to start spinning in Navigate. |
| 2691 | DidStopLoading(); |
| 2692 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 2693 | close_start_time_ = base::TimeTicks(); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2694 | } |
| 2695 | is_showing_before_unload_dialog_ = false; |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2696 | static_cast<RenderViewHostImpl*>( |
| 2697 | rvh)->JavaScriptDialogClosed(reply_msg, success, user_input); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2698 | } |
| 2699 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2700 | void WebContentsImpl::SetEncoding(const std::string& encoding) { |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 2701 | encoding_ = content::GetContentClient()->browser()-> |
| 2702 | GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 2703 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 2704 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2705 | void WebContentsImpl::SaveURL(const GURL& url, |
| 2706 | const GURL& referrer, |
| 2707 | bool is_main_frame) { |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2708 | DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); |
| 2709 | if (!dlm) |
| 2710 | return; |
| 2711 | int64 post_id = -1; |
[email protected] | e30d68d | 2012-02-09 00:06:26 | [diff] [blame] | 2712 | if (is_main_frame) { |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2713 | const NavigationEntry* entry = controller_.GetActiveEntry(); |
| 2714 | if (entry) |
| 2715 | post_id = entry->GetPostID(); |
| 2716 | } |
[email protected] | 29a5ffc8 | 2012-03-13 19:35:58 | [diff] [blame] | 2717 | content::DownloadSaveInfo save_info; |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2718 | save_info.prompt_for_save_location = true; |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 2719 | scoped_ptr<DownloadUrlParameters> params( |
| 2720 | DownloadUrlParameters::FromWebContents(this, url, save_info)); |
| 2721 | params->set_referrer(referrer); |
| 2722 | params->set_post_id(post_id); |
| 2723 | params->set_prefer_cache(true); |
| 2724 | if (post_id >= 0) |
| 2725 | params->set_method("POST"); |
| 2726 | dlm->DownloadUrl(params.Pass()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2727 | } |
| 2728 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2729 | void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2730 | RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2731 | // Can be NULL during tests. |
| 2732 | if (rwh_view) |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2733 | rwh_view->SetSize(GetView()->GetContainerSize()); |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 2734 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2735 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2736 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2737 | return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
| 2738 | } |