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