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