blob: c76041379ae64633607c2e6835b9134f8d39dd72 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]b9535422012-02-09 01:47:5917#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4619#include "content/browser/download/download_stats.h"
[email protected]a53209b2012-01-20 16:48:1620#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3221#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5422#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0523#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0024#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0125#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0426#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3027#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5028#include "content/browser/renderer_host/render_view_host.h"
[email protected]686493142011-07-15 21:47:2229#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5030#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3331#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1332#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2333#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4434#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]105bb0f2011-05-24 17:12:1435#include "content/browser/tab_contents/title_updated_details.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5840#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1141#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4442#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4443#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1744#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4645#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1546#include "content/public/browser/javascript_dialogs.h"
[email protected]5b96836f2011-12-22 07:39:0047#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3849#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4250#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2551#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1052#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5053#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2154#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1856#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5457#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1659#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2960#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5461#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3462#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3763#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3864#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2465#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3166#include "webkit/glue/webpreferences.h"
67
68#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1269#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3170#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0071
[email protected]420ae012009-04-24 05:16:3272// Cross-Site Navigations
73//
74// If a TabContents is told to navigate to a different web site (as determined
75// by SiteInstance), it will replace its current RenderViewHost with a new
76// RenderViewHost dedicated to the new SiteInstance. This works as follows:
77//
78// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4679// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3280// - The pending RVH is "suspended," so that no navigation messages are sent to
81// its renderer until the onbeforeunload JavaScript handler has a chance to
82// run in the current RVH.
83// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
84// that it has a pending cross-site request. ResourceDispatcherHost will
85// check for this when the response arrives.
86// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4687// cancel all the pending logic. Otherwise we allow the pending RVH to send
88// the navigation request to its renderer.
89// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
90// main resource load on the pending RVH. It checks CrossSiteRequestManager
91// to see that it is a cross-site request, and installs a
92// CrossSiteResourceHandler.
93// - When RDH receives a response, the BufferedResourceHandler determines
94// whether it is a download. If so, it sends a message to the new renderer
95// causing it to cancel the request, and the download proceeds. For now, the
96// pending RVH remains until the next DidNavigate event for this TabContents.
97// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3298// - After RDH receives a response and determines that it is safe and not a
99// download, it pauses the response to first run the old page's onunload
100// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15101// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32102// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15103// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32104// the ResourceDispatcherHost, who unpauses the response. Data is then sent
105// to the pending RVH.
106// - The pending renderer sends a FrameNavigate message that invokes the
107// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46108// pending RVH.
[email protected]992db4c2011-05-12 15:37:15109// - The previous renderer is kept swapped out in RenderViewHostManager in case
110// the user goes back. The process only stays live if another tab is using
111// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32112
[email protected]0e12d7d2011-12-01 16:21:44113using content::DevToolsAgentHost;
114using content::DevToolsAgentHostRegistry;
115using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17116using content::DownloadItem;
117using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20118using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56119using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13120using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:50121using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23122using content::NavigationEntry;
123using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20124using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57125using content::RenderViewHostDelegate;
[email protected]5626b0892012-02-20 14:46:58126using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04127using content::RenderWidgetHostViewPort;
[email protected]adbfb8df2012-02-24 01:19:43128using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33129using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17130using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38131using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09132using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25133using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56134using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22135using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50136using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44137
[email protected]420ae012009-04-24 05:16:32138namespace {
139
140// Amount of time we wait between when a key event is received and the renderer
141// is queried for its state and pushed to the NavigationEntry.
142const int kQueryStateDelay = 5000;
143
[email protected]6ebdc9b2010-09-27 16:55:57144const int kSyncWaitDelay = 40;
145
[email protected]ca406032011-07-19 21:53:05146static const char kDotGoogleDotCom[] = ".google.com";
147
[email protected]420ae012009-04-24 05:16:32148#if defined(OS_WIN)
149
150BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
151 // Note: erase is required to properly paint some widgets borders. This can
152 // be seen with textfields.
153 InvalidateRect(hwnd, NULL, TRUE);
154 return TRUE;
155}
156#endif
157
[email protected]2c5569662011-03-22 20:45:02158ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23159 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50160 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16161 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47162 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02163 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47164 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02165 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47166 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16167 break; // Fall through to rest of function.
168 }
[email protected]5e369672009-11-03 23:48:30169
[email protected]59246c572012-02-10 13:32:13170 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
171 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23172 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13173 browser_context->DidLastSessionExitCleanly()) {
174 if (entry.GetHasPostData())
175 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02176 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13177 }
[email protected]5e369672009-11-03 23:48:30178
[email protected]2c5569662011-03-22 20:45:02179 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30180}
181
[email protected]10f417c52011-12-28 21:04:23182void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47183 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42184 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50185 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16186 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51187 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54188 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55189 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
190 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51191 params->url = entry.GetURL();
192 params->referrer = entry.GetReferrer();
193 params->transition = entry.GetTransitionType();
194 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00195 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55196 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34197 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47198 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48199 params->transferred_request_child_id =
200 entry.transferred_global_request_id().child_id;
201 params->transferred_request_request_id =
202 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47203
204 if (delegate)
205 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34206}
207
[email protected]420ae012009-04-24 05:16:32208} // namespace
209
[email protected]a81343d232011-12-27 07:39:20210namespace content {
211
212WebContents* WebContents::Create(
213 BrowserContext* browser_context,
214 SiteInstance* site_instance,
215 int routing_id,
216 const WebContents* base_tab_contents,
217 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43218 return new TabContents(
219 browser_context,
220 site_instance,
221 routing_id,
222 static_cast<const TabContents*>(base_tab_contents),
223 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20224}
225}
[email protected]f4f50ef2011-01-21 19:01:19226
227// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32228
[email protected]3d7474ff2011-07-27 17:47:37229TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32230 SiteInstance* site_instance,
231 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07232 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43233 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42234 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07235 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37236 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13237 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10238 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22239 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34240 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23241 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
242 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34243 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21244 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56245 upload_size_(0),
246 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47247 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57248 capturing_contents_(false),
249 is_being_destroyed_(false),
250 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55251 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57252#if defined(OS_WIN)
253 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
254#endif
[email protected]7ab1e7d62009-10-14 23:32:01255 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56256 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38257 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25258 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01259 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25260 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01261 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00262 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43263 content_restrictions_(0),
264 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37265 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32266
[email protected]34ac70502009-09-25 17:07:23267 // We have the initial size of the view be based on the size of the passed in
268 // tab contents (normally a tab from the same window).
269 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21270 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00271
272#if defined(ENABLE_JAVA_BRIDGE)
273 java_bridge_dispatcher_host_manager_.reset(
274 new JavaBridgeDispatcherHostManager(this));
275#endif
[email protected]332af7732009-03-11 13:21:35276}
initial.commit09911bf2008-07-26 23:55:29277
278TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32279 is_being_destroyed_ = true;
280
[email protected]3ab9cb82011-06-03 18:02:07281 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55282 if (dialog_creator_)
283 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07284
[email protected]420ae012009-04-24 05:16:32285 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32286
[email protected]420ae012009-04-24 05:16:32287 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07288 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09289 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
290 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07291 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32292
293 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07294#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32295 // If we still have a window handle, destroy it. GetNativeView can return
296 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42297 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52298 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44299 if (host && host->view())
[email protected]c30585c2012-02-16 15:02:04300 RenderWidgetHostViewPort::FromRWHV(host->view())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42301 }
[email protected]420ae012009-04-24 05:16:32302#endif
[email protected]7ab1e7d62009-10-14 23:32:01303
304 // OnCloseStarted isn't called in unit tests.
305 if (!tab_close_start_time_.is_null()) {
306 UMA_HISTOGRAM_TIMES("Tab.Close",
307 base::TimeTicks::Now() - tab_close_start_time_);
308 }
[email protected]b5a1d11c2011-02-17 03:09:42309
[email protected]d8c660432011-12-22 20:51:25310 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08311
[email protected]6934a702011-12-20 00:04:51312 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42313}
314
[email protected]64d69de42012-02-06 00:19:54315WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
316 const GURL& url) {
317 WebPreferences prefs;
318
319 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
320
321 prefs.developer_extras_enabled = true;
322 prefs.javascript_enabled =
323 !command_line.HasSwitch(switches::kDisableJavaScript);
324 prefs.web_security_enabled =
325 !command_line.HasSwitch(switches::kDisableWebSecurity);
326 prefs.plugins_enabled =
327 !command_line.HasSwitch(switches::kDisablePlugins);
328 prefs.java_enabled =
329 !command_line.HasSwitch(switches::kDisableJava);
330
331 prefs.uses_page_cache =
332 command_line.HasSwitch(switches::kEnableFastback);
333 prefs.remote_fonts_enabled =
334 !command_line.HasSwitch(switches::kDisableRemoteFonts);
335 prefs.xss_auditor_enabled =
336 !command_line.HasSwitch(switches::kDisableXSSAuditor);
337 prefs.application_cache_enabled =
338 !command_line.HasSwitch(switches::kDisableApplicationCache);
339
340 prefs.local_storage_enabled =
341 !command_line.HasSwitch(switches::kDisableLocalStorage);
342 prefs.databases_enabled =
343 !command_line.HasSwitch(switches::kDisableDatabases);
344 prefs.webaudio_enabled =
345 !command_line.HasSwitch(switches::kDisableWebAudio);
346
347 prefs.experimental_webgl_enabled =
348 GpuProcessHost::gpu_enabled() &&
349 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
350 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
351
352 prefs.gl_multisampling_enabled =
353 !command_line.HasSwitch(switches::kDisableGLMultisampling);
354 prefs.privileged_webgl_extensions_enabled =
355 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
356 prefs.site_specific_quirks_enabled =
357 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
358 prefs.allow_file_access_from_file_urls =
359 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
360 prefs.show_composited_layer_borders =
361 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
362 prefs.show_composited_layer_tree =
363 command_line.HasSwitch(switches::kShowCompositedLayerTree);
364 prefs.show_fps_counter =
365 command_line.HasSwitch(switches::kShowFPSCounter);
366 prefs.accelerated_compositing_enabled =
367 GpuProcessHost::gpu_enabled() &&
368 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
369 prefs.threaded_compositing_enabled =
370 command_line.HasSwitch(switches::kEnableThreadedCompositing);
371 prefs.force_compositing_mode =
372 command_line.HasSwitch(switches::kForceCompositingMode);
373 prefs.fixed_position_compositing_enabled =
374 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
375 prefs.accelerated_2d_canvas_enabled =
376 GpuProcessHost::gpu_enabled() &&
377 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58378 prefs.deferred_2d_canvas_enabled =
379 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36380 prefs.threaded_animation_enabled =
381 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54382 prefs.accelerated_painting_enabled =
383 GpuProcessHost::gpu_enabled() &&
384 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
385 prefs.accelerated_filters_enabled =
386 GpuProcessHost::gpu_enabled() &&
387 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
388 prefs.accelerated_layers_enabled =
389 prefs.accelerated_animation_enabled =
390 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
391 prefs.composite_to_texture_enabled =
392 command_line.HasSwitch(switches::kEnableCompositeToTexture);
393 prefs.accelerated_plugins_enabled =
394 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
395 prefs.accelerated_video_enabled =
396 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
397 prefs.partial_swap_enabled =
398 command_line.HasSwitch(switches::kEnablePartialSwap);
399 prefs.interactive_form_validation_enabled =
400 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
401 prefs.fullscreen_enabled =
402 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16403 prefs.css_regions_enabled =
404 command_line.HasSwitch(switches::kEnableCssRegions);
405
[email protected]64d69de42012-02-06 00:19:54406
407#if defined(OS_MACOSX)
408 bool default_enable_scroll_animator = true;
409#else
410 // On CrOS, the launcher always passes in the --enable flag.
411 bool default_enable_scroll_animator = false;
412#endif
413 prefs.enable_scroll_animator = default_enable_scroll_animator;
414 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
415 prefs.enable_scroll_animator = true;
416 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
417 prefs.enable_scroll_animator = false;
418
419 prefs.visual_word_movement_enabled =
420 command_line.HasSwitch(switches::kEnableVisualWordMovement);
421 prefs.per_tile_painting_enabled =
422 command_line.HasSwitch(switches::kEnablePerTilePainting);
423
424 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32425 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54426 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11427 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
428 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54429 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11430 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54431 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11432 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54433 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11434 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54435 prefs.gl_multisampling_enabled = false;
436
437 // Accelerated video and animation are slower than regular when using a
438 // software 3d rasterizer.
[email protected]79078df2012-02-16 01:22:32439 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54440 prefs.accelerated_video_enabled = false;
441 prefs.accelerated_animation_enabled = false;
442 }
443 }
444
[email protected]b9535422012-02-09 01:47:59445 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]64d69de42012-02-06 00:19:54446 rvh->process()->GetID())) {
447 prefs.loads_images_automatically = true;
448 prefs.javascript_enabled = true;
449 }
450
451 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
452
453 // Force accelerated compositing and 2d canvas off for chrome:, about: and
454 // chrome-devtools: pages (unless it's specifically allowed).
455 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54456 url.SchemeIs(chrome::kChromeUIScheme) ||
457 (url.SchemeIs(chrome::kAboutScheme) &&
458 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25459 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54460 prefs.accelerated_compositing_enabled = false;
461 prefs.accelerated_2d_canvas_enabled = false;
462 }
463
[email protected]43d9d782012-03-01 15:40:09464 int default_device_scale_factor;
465 base::StringToInt(command_line.GetSwitchValueASCII(
466 switches::kDefaultDeviceScaleFactor),
467 &default_device_scale_factor);
468
469 prefs.default_device_scale_factor = default_device_scale_factor;
470
[email protected]64d69de42012-02-06 00:19:54471 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
472
473 return prefs;
474}
475
[email protected]d202a7c2012-01-04 07:53:47476NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20477 return controller_;
478}
479
[email protected]765187182012-01-11 23:59:28480RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
481 return &render_manager_;
482}
483
[email protected]724159a2010-12-30 01:11:18484bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56485 if (GetWebUI() &&
486 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17487 return true;
[email protected]d2353452012-01-19 19:53:56488 }
[email protected]f82d57b52011-04-27 19:13:17489
[email protected]d8c660432011-12-22 20:51:25490 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
491 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10492 while ((observer = it.GetNext()) != NULL)
493 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53494 return true;
[email protected]403415a2011-01-10 18:57:53495
[email protected]724159a2010-12-30 01:11:18496 bool handled = true;
497 bool message_is_ok = true;
498 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58499 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
500 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24501 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
502 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18503 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
504 OnDidStartProvisionalLoadForFrame)
505 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
506 OnDidRedirectProvisionalLoad)
507 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
508 OnDidFailProvisionalLoadWithError)
509 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
510 OnDidLoadResourceFromMemoryCache)
511 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
512 OnDidDisplayInsecureContent)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
514 OnDidRunInsecureContent)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
516 OnDocumentLoadedInFrame)
517 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17518 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
519 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25520 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26521 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59522 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21523 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20524 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
525 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
526 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16527 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45528 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10529 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18530 IPC_MESSAGE_UNHANDLED(handled = false)
531 IPC_END_MESSAGE_MAP_EX()
532
533 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38534 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18535 GetRenderProcessHost()->ReceivedBadMessage();
536 }
537
538 return handled;
539}
540
[email protected]6c2e472f2011-08-24 23:26:18541void TabContents::RunFileChooser(
542 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23543 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51544 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18545}
546
[email protected]c5eed492012-01-04 17:07:50547NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56548 return controller_;
549}
550
[email protected]c5eed492012-01-04 17:07:50551const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56552 return controller_;
553}
554
[email protected]627e0512011-12-21 22:55:30555content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55556 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30557}
558
[email protected]f5fa20e2011-12-21 22:35:56559void TabContents::SetViewType(content::ViewType type) {
560 view_type_ = type;
561}
562
[email protected]ea049a02011-12-25 21:37:09563content::ViewType TabContents::GetViewType() const {
564 return view_type_;
565}
566
[email protected]be1f56ab2011-12-22 06:55:31567const GURL& TabContents::GetURL() const {
568 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23569 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51570 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31571}
572
573
574const base::PropertyBag* TabContents::GetPropertyBag() const {
575 return &property_bag_;
576}
577
578base::PropertyBag* TabContents::GetPropertyBag() {
579 return &property_bag_;
580}
581
582content::WebContentsDelegate* TabContents::GetDelegate() {
583 return delegate_;
584}
585
586void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
587 // TODO(cbentzel): remove this debugging code?
588 if (delegate == delegate_)
589 return;
590 if (delegate_)
591 delegate_->Detach(this);
592 delegate_ = delegate;
593 if (delegate_)
594 delegate_->Attach(this);
595}
596
[email protected]f3b1a082011-11-18 00:34:30597content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03598 if (render_manager_.current_host())
599 return render_manager_.current_host()->process();
600 else
601 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16602}
603
[email protected]be1f56ab2011-12-22 06:55:31604RenderViewHost* TabContents::GetRenderViewHost() const {
605 return render_manager_.current_host();
606}
607
608RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
609 return render_manager_.GetRenderWidgetHostView();
610}
611
[email protected]8643e6d2012-01-18 20:26:10612content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31613 return view_.get();
614}
615
[email protected]01ec4ec2012-01-18 04:13:47616content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50617 WebUIControllerFactory* factory =
618 content::GetContentClient()->browser()->GetWebUIControllerFactory();
619 if (!factory)
620 return NULL;
[email protected]d2353452012-01-19 19:53:56621 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22622 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50623 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22624 if (controller) {
625 web_ui->SetController(controller);
626 return web_ui;
627 }
628
629 delete web_ui;
630 return NULL;
631}
632
[email protected]01ec4ec2012-01-18 04:13:47633content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31634 return render_manager_.web_ui() ? render_manager_.web_ui()
635 : render_manager_.pending_web_ui();
636}
637
[email protected]01ec4ec2012-01-18 04:13:47638content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31639 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34640}
641
[email protected]96d185d2009-04-24 03:28:54642const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55643 // Transient entries take precedence. They are used for interstitial pages
644 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23645 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08646 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20647 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30648 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23649 if (entry) {
[email protected]b5cca982011-05-26 04:42:08650 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23651 }
[email protected]7ade2732011-02-10 00:13:58652 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
653 render_manager_.pending_web_ui() : render_manager_.web_ui();
654 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54655 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55656 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54657 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35658 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22659 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54660 if (!title.empty())
661 return title;
662 }
663 }
664
665 // We use the title for the last committed entry rather than a pending
666 // navigation entry. For example, when the user types in a URL, we want to
667 // keep the old page's title until the new load has committed and we get a new
668 // title.
[email protected]96d185d2009-04-24 03:28:54669 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23670 if (entry) {
[email protected]b5cca982011-05-26 04:42:08671 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23672 }
[email protected]987fc3a2011-05-26 14:18:09673
674 // |page_title_when_no_navigation_entry_| is finally used
675 // if no title cannot be retrieved.
676 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54677}
678
[email protected]d5f942ba2008-09-26 19:30:34679int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46680 return GetMaxPageIDForSiteInstance(GetSiteInstance());
681}
682
683int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33684 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
685 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46686
[email protected]b6583592012-01-25 19:52:33687 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34688}
689
690void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46691 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
692}
693
[email protected]b6583592012-01-25 19:52:33694void TabContents::UpdateMaxPageIDForSiteInstance(
695 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46696 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33697 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34698}
699
[email protected]91854cd2012-01-10 19:43:57700void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
701 max_page_ids_ = tab_contents->max_page_ids_;
702}
703
[email protected]96d185d2009-04-24 03:28:54704SiteInstance* TabContents::GetSiteInstance() const {
705 return render_manager_.current_host()->site_instance();
706}
707
[email protected]77362eb2011-08-01 17:18:38708SiteInstance* TabContents::GetPendingSiteInstance() const {
709 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
710 render_manager_.pending_render_view_host() :
711 render_manager_.current_host();
712 return dest_rvh->site_instance();
713}
714
[email protected]be1f56ab2011-12-22 06:55:31715bool TabContents::IsLoading() const {
716 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49717}
718
[email protected]be1f56ab2011-12-22 06:55:31719bool TabContents::IsWaitingForResponse() const {
720 return waiting_for_response_;
721}
722
723const net::LoadStateWithParam& TabContents::GetLoadState() const {
724 return load_state_;
725}
726
727const string16& TabContents::GetLoadStateHost() const {
728 return load_state_host_;
729}
730
731uint64 TabContents::GetUploadSize() const {
732 return upload_size_;
733}
734
735uint64 TabContents::GetUploadPosition() const {
736 return upload_position_;
737}
738
739const std::string& TabContents::GetEncoding() const {
740 return encoding_;
741}
742
743bool TabContents::DisplayedInsecureContent() const {
744 return displayed_insecure_content_;
745}
746
747void TabContents::SetCapturingContents(bool cap) {
748 capturing_contents_ = cap;
749}
750
751bool TabContents::IsCrashed() const {
752 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
753 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
754 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49755}
756
[email protected]443b80e2010-12-14 00:42:23757void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
758 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34759 return;
760
[email protected]443b80e2010-12-14 00:42:23761 crashed_status_ = status;
762 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46763 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34764}
765
[email protected]be1f56ab2011-12-22 06:55:31766base::TerminationStatus TabContents::GetCrashedStatus() const {
767 return crashed_status_;
768}
769
770bool TabContents::IsBeingDestroyed() const {
771 return is_being_destroyed_;
772}
773
[email protected]d5f942ba2008-09-26 19:30:34774void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
775 if (delegate_)
776 delegate_->NavigationStateChanged(this, changed_flags);
777}
778
[email protected]96d185d2009-04-24 03:28:54779void TabContents::DidBecomeSelected() {
780 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04781 RenderWidgetHostViewPort* rwhv =
782 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16783 if (rwhv) {
784 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43785#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16786 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43787#endif
788 }
[email protected]96d185d2009-04-24 03:28:54789
[email protected]5ac20162010-11-24 23:33:11790 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38791
[email protected]d8c660432011-12-22 20:51:25792 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59793
794 // The resize rect might have changed while this was inactive -- send the new
795 // one to make sure it's up to date.
796 RenderViewHost* rvh = GetRenderViewHost();
797 if (rvh) {
798 rvh->ResizeRectChanged(GetRootWindowResizerRect());
799 }
[email protected]96d185d2009-04-24 03:28:54800}
801
[email protected]be1f56ab2011-12-22 06:55:31802
803base::TimeTicks TabContents::GetLastSelectedTime() const {
804 return last_selected_time_;
805}
806
[email protected]96d185d2009-04-24 03:28:54807void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31808 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52809 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
810 // open a tab in then background, then closes the tab before selecting it.
811 // This is because closing the tab calls TabContents::Destroy(), which
812 // removes the |GetRenderViewHost()|; then when we actually destroy the
813 // window, OnWindowPosChanged() notices and calls HideContents() (which
814 // calls us).
[email protected]c30585c2012-02-16 15:02:04815 RenderWidgetHostViewPort* rwhv =
816 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16817 if (rwhv)
818 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54819 }
820
[email protected]ad50def52011-10-19 23:17:07821 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09822 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
823 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07824 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54825}
826
[email protected]be1f56ab2011-12-22 06:55:31827void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04828 RenderWidgetHostViewPort* rwhv =
829 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31830 if (rwhv)
831 rwhv->DidBecomeSelected();
832}
833
834void TabContents::HideContents() {
835 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
836 // our superclass HideContents(), because some callers want to be very picky
837 // about the order in which these get called. In addition to making the code
838 // here practically impossible to understand, this also means we end up
839 // calling TabContents::WasHidden() twice if callers call both versions of
840 // HideContents() on a TabContents.
841 WasHidden();
842}
843
844bool TabContents::NeedToFireBeforeUnload() {
845 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27846 return WillNotifyDisconnection() &&
847 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31848 !GetRenderViewHost()->SuddenTerminationAllowed();
849}
850
[email protected]0bfbf882011-12-22 18:19:27851void TabContents::Stop() {
852 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25853 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27854}
855
[email protected]d9083482012-01-06 00:38:46856WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27857 // We create a new SiteInstance so that the new tab won't share processes
858 // with the old one. This can be changed in the future if we need it to share
859 // processes for some reason.
860 TabContents* tc = new TabContents(
861 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33862 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27863 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20864 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27865 return tc;
866}
867
[email protected]2a6bc3e2011-12-28 23:51:33868void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27869 WindowOpenDisposition disposition,
870 const gfx::Rect& initial_pos,
871 bool user_gesture) {
872 if (!delegate_)
873 return;
874
875 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
876 user_gesture);
877}
878
879gfx::NativeView TabContents::GetContentNativeView() const {
880 return view_->GetContentNativeView();
881}
882
883gfx::NativeView TabContents::GetNativeView() const {
884 return view_->GetNativeView();
885}
886
887void TabContents::GetContainerBounds(gfx::Rect* out) const {
888 view_->GetContainerBounds(out);
889}
890
891void TabContents::Focus() {
892 view_->Focus();
893}
894
[email protected]d8c660432011-12-22 20:51:25895void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31896 observers_.AddObserver(observer);
897}
898
[email protected]d8c660432011-12-22 20:51:25899void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31900 observers_.RemoveObserver(observer);
901}
902
[email protected]d5f942ba2008-09-26 19:30:34903void TabContents::Activate() {
904 if (delegate_)
905 delegate_->ActivateContents(this);
906}
907
[email protected]ea42e7782010-08-23 23:58:12908void TabContents::Deactivate() {
909 if (delegate_)
910 delegate_->DeactivateContents(this);
911}
912
[email protected]63954792011-07-11 04:17:48913void TabContents::LostCapture() {
914 if (delegate_)
915 delegate_->LostCapture();
916}
917
918bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
919 bool* is_keyboard_shortcut) {
920 return delegate_ &&
921 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
922}
923
924void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
925 if (delegate_)
926 delegate_->HandleKeyboardEvent(event);
927}
928
[email protected]32ded2212011-11-10 18:51:43929void TabContents::HandleMouseDown() {
930 if (delegate_)
931 delegate_->HandleMouseDown();
932}
933
[email protected]63954792011-07-11 04:17:48934void TabContents::HandleMouseUp() {
935 if (delegate_)
936 delegate_->HandleMouseUp();
937}
938
939void TabContents::HandleMouseActivate() {
940 if (delegate_)
941 delegate_->HandleMouseActivate();
942}
943
[email protected]8a5e0ca2011-08-25 06:30:47944void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
945 if (delegate_)
946 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
947}
948
[email protected]5d5f7af2011-10-01 01:38:12949bool TabContents::IsFullscreenForCurrentTab() const {
950 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
951}
952
[email protected]e9621112011-10-17 05:38:37953void TabContents::RequestToLockMouse() {
954 if (delegate_) {
955 delegate_->RequestToLockMouse(this);
956 } else {
957 GotResponseToLockMouseRequest(false);
958 }
959}
960
961void TabContents::LostMouseLock() {
962 if (delegate_)
963 delegate_->LostMouseLock();
964}
965
[email protected]0548c5352011-09-07 00:33:33966void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23967 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33968 if (delegate_)
969 delegate_->UpdatePreferredSize(this, pref_size);
970}
971
[email protected]32ded2212011-11-10 18:51:43972void TabContents::WebUISend(RenderViewHost* render_view_host,
973 const GURL& source_url,
974 const std::string& name,
975 const base::ListValue& args) {
976 if (delegate_)
977 delegate_->WebUISend(this, source_url, name, args);
978}
979
[email protected]e5d549d2011-12-28 01:29:20980WebContents* TabContents::OpenURL(const OpenURLParams& params) {
981 if (!delegate_)
982 return NULL;
[email protected]00c37fc2011-08-02 00:22:50983
[email protected]e5d549d2011-12-28 01:29:20984 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
985 // Notify observers.
986 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
987 DidOpenURL(params.url, params.referrer,
988 params.disposition, params.transition));
989 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34990}
991
[email protected]1ccb3568d2010-02-19 10:51:16992bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50993 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25994 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23995 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25996 reload_type);
[email protected]876bc832010-09-07 16:29:54997}
[email protected]96d185d2009-04-24 03:28:54998
[email protected]876bc832010-09-07 16:29:54999bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231000 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501001 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401002 // The renderer will reject IPC messages with URLs longer than
1003 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511004 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401005 return false;
1006
[email protected]dd11de52011-11-03 22:54:271007 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:401008 if (!dest_render_view_host)
1009 return false; // Unable to create the desired render view host.
1010
[email protected]80a8fad2011-01-29 04:02:381011 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071012 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581013 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501014 WebUIControllerFactory* factory =
1015 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1016 bool is_allowed_in_web_ui_renderer =
1017 factory &&
1018 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431019#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511020 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431021#endif
[email protected]e091df82011-10-11 18:13:211022 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551023 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581024
[email protected]96d185d2009-04-24 03:28:541025 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441026 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521027 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441028 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511029 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541030
1031 // Used for page load time metrics.
1032 current_load_start_ = base::TimeTicks::Now();
1033
1034 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341035 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271036 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471037 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341038 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541039
[email protected]36fc0392011-12-25 03:59:511040 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541041 // HACK!! This code suppresses javascript: URLs from being added to
1042 // session history, which is what we want to do for javascript: URLs that
1043 // do not generate content. What we really need is a message from the
1044 // renderer telling us that a new page was not created. The same message
1045 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511046 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541047 return false;
1048 }
1049
[email protected]3c9e1872010-11-18 16:17:491050 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251051 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041052 observers_,
[email protected]36fc0392011-12-25 03:59:511053 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541054
[email protected]09b29342011-06-24 19:18:481055 if (delegate_)
1056 delegate_->DidNavigateToPendingEntry(this);
1057
[email protected]d5f942ba2008-09-26 19:30:341058 return true;
1059}
1060
[email protected]b6583592012-01-25 19:52:331061void TabContents::SetHistoryLengthAndPrune(
1062 const SiteInstance* site_instance,
1063 int history_length,
1064 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411065 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1066 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191067 if (render_manager_.pending_render_view_host()) {
1068 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141069 return;
[email protected]9e1ad4b2011-08-14 16:49:191070 }
[email protected]151a63d2011-12-20 22:32:521071 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191072 if (!rvh) {
1073 NOTREACHED();
1074 return;
1075 }
1076 if (site_instance && rvh->site_instance() != site_instance) {
1077 NOTREACHED();
1078 return;
1079 }
1080 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1081 history_length,
1082 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141083}
1084
[email protected]90daadb42009-06-08 21:27:281085void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271086 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541087 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1088 return;
1089 }
[email protected]151a63d2011-12-20 22:32:521090 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541091}
1092
[email protected]0bfbf882011-12-22 18:19:271093bool TabContents::ShowingInterstitialPage() const {
1094 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541095}
1096
[email protected]0bfbf882011-12-22 18:19:271097InterstitialPage* TabContents::GetInterstitialPage() const {
1098 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221099}
1100
[email protected]a53209b2012-01-20 16:48:161101bool TabContents::IsSavable() {
1102 // WebKit creates Document object when MIME type is application/xhtml+xml,
1103 // so we also support this MIME type.
1104 return contents_mime_type_ == "text/html" ||
1105 contents_mime_type_ == "text/xml" ||
1106 contents_mime_type_ == "application/xhtml+xml" ||
1107 contents_mime_type_ == "text/plain" ||
1108 contents_mime_type_ == "text/css" ||
1109 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1110}
1111
[email protected]c7dd2f62011-07-18 15:57:591112void TabContents::OnSavePage() {
1113 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161114 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481115 download_stats::RecordDownloadSource(
1116 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261117 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141118 return;
[email protected]c7dd2f62011-07-18 15:57:591119 }
1120
1121 Stop();
1122
1123 // Create the save package and possibly prompt the user for the name to save
1124 // the page as. The user prompt is an asynchronous operation that runs on
1125 // another thread.
1126 save_package_ = new SavePackage(this);
1127 save_package_->GetSaveInfo();
1128}
1129
1130// Used in automated testing to bypass prompting the user for file names.
1131// Instead, the names and paths are hard coded rather than running them through
1132// file name sanitation and extension / mime checking.
1133bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161134 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591135 // Stop the page from navigating.
1136 Stop();
1137
1138 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1139 return save_package_->Init();
1140}
1141
[email protected]420ae012009-04-24 05:16:321142bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231143 NavigationEntryImpl* active_entry =
1144 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321145 return (active_entry != NULL &&
1146 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511147 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321148}
1149
[email protected]0bfbf882011-12-22 18:19:271150const std::string& TabContents::GetContentsMimeType() const {
1151 return contents_mime_type_;
1152}
1153
1154bool TabContents::WillNotifyDisconnection() const {
1155 return notify_disconnection_;
1156}
1157
[email protected]b2fe07d12010-02-09 14:38:081158void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311159 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521160 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1161 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161162}
1163
[email protected]b2fe07d12010-02-09 14:38:081164void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311165 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521166 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1167 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161168}
1169
[email protected]0bfbf882011-12-22 18:19:271170content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1171 return &renderer_preferences_;
1172}
1173
1174void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1175 new_tab_start_time_ = time;
1176}
1177
1178base::TimeTicks TabContents::GetNewTabStartTime() const {
1179 return new_tab_start_time_;
1180}
1181
[email protected]7ab1e7d62009-10-14 23:32:011182void TabContents::OnCloseStarted() {
1183 if (tab_close_start_time_.is_null())
1184 tab_close_start_time_ = base::TimeTicks::Now();
1185}
1186
[email protected]46624bf2010-06-09 16:04:191187bool TabContents::ShouldAcceptDragAndDrop() const {
1188#if defined(OS_CHROMEOS)
1189 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1190 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511191 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201192 return false;
1193 return true;
[email protected]46624bf2010-06-09 16:04:191194#else
1195 return true;
1196#endif
1197}
1198
[email protected]7813bd72011-02-05 02:19:341199void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521200 if (GetRenderViewHost())
1201 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511202 if (delegate_)
1203 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341204}
1205
[email protected]0bfbf882011-12-22 18:19:271206void TabContents::SetClosedByUserGesture(bool value) {
1207 closed_by_user_gesture_ = value;
1208}
1209
1210bool TabContents::GetClosedByUserGesture() const {
1211 return closed_by_user_gesture_;
1212}
1213
[email protected]d0b8d092010-10-25 04:05:171214double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051215 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561216 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251217 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171218 return 0;
[email protected]b75b8292010-10-01 07:28:251219
1220 double zoom_level;
1221 if (temporary_zoom_settings_) {
1222 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521223 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251224 } else {
[email protected]2ae88d12011-10-14 09:11:191225 GURL url;
[email protected]10f417c52011-12-28 21:04:231226 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191227 // Since zoom map is updated using rewritten URL, use rewritten URL
1228 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511229 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191230 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251231 }
[email protected]d0b8d092010-10-25 04:05:171232 return zoom_level;
1233}
[email protected]b75b8292010-10-01 07:28:251234
[email protected]d0b8d092010-10-25 04:05:171235int TabContents::GetZoomPercent(bool* enable_increment,
1236 bool* enable_decrement) {
1237 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011238 // Calculate the zoom percent from the factor. Round up to the nearest whole
1239 // number.
[email protected]b75b8292010-10-01 07:28:251240 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011241 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251242 *enable_decrement = percent > minimum_zoom_percent_;
1243 *enable_increment = percent < maximum_zoom_percent_;
1244 return percent;
1245}
1246
[email protected]3c733bde2010-12-21 19:56:311247void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501248 if (!delegate_)
1249 return;
1250
[email protected]10f417c52011-12-28 21:04:231251 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501252 if (!active_entry)
1253 return;
1254
[email protected]36fc0392011-12-25 03:59:511255 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121256}
1257
[email protected]932b7a12011-03-09 12:50:271258void TabContents::ViewFrameSource(const GURL& url,
1259 const std::string& content_state) {
1260 if (!delegate_)
1261 return;
1262
1263 delegate_->ViewSourceForFrame(this, url, content_state);
1264}
1265
[email protected]0bfbf882011-12-22 18:19:271266int TabContents::GetMinimumZoomPercent() const {
1267 return minimum_zoom_percent_;
1268}
1269
1270int TabContents::GetMaximumZoomPercent() const {
1271 return maximum_zoom_percent_;
1272}
1273
[email protected]bcd2815602012-01-14 18:17:231274gfx::Size TabContents::GetPreferredSize() const {
1275 return preferred_size_;
1276}
1277
[email protected]0bfbf882011-12-22 18:19:271278int TabContents::GetContentRestrictions() const {
1279 return content_restrictions_;
1280}
1281
1282WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501283 WebUIControllerFactory* factory =
1284 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1285 if (!factory)
1286 return WebUI::kNoWebUI;
1287 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271288}
1289
[email protected]01ec4ec2012-01-18 04:13:471290content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271291 // When there is a pending navigation entry, we want to use the pending WebUI
1292 // that goes along with it to control the basic flags. For example, we want to
1293 // show the pending URL in the URL bar, so we want the display_url flag to
1294 // be from the pending entry.
1295 //
1296 // The confusion comes because there are multiple possibilities for the
1297 // initial load in a tab as a side effect of the way the RenderViewHostManager
1298 // works.
1299 //
1300 // - For the very first tab the load looks "normal". The new tab Web UI is
1301 // the pending one, and we want it to apply here.
1302 //
1303 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1304 // get switched to the one previously associated with the new tab pages.
1305 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1306 // have a committed Web UI in this case.
1307 //
1308 // This condition handles all of these cases:
1309 //
1310 // - First load in first tab: no committed nav entry + pending nav entry +
1311 // pending dom ui:
1312 // -> Use pending Web UI if any.
1313 //
1314 // - First load in second tab: no committed nav entry + pending nav entry +
1315 // no pending Web UI:
1316 // -> Use the committed Web UI if any.
1317 //
1318 // - Second navigation in any tab: committed nav entry + pending nav entry:
1319 // -> Use pending Web UI if any.
1320 //
1321 // - Normal state with no load: committed nav entry + no pending nav entry:
1322 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251323 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271324 (controller_.GetLastCommittedEntry() ||
1325 render_manager_.pending_web_ui()))
1326 return render_manager_.pending_web_ui();
1327 return render_manager_.web_ui();
1328}
1329
1330bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1331 return GetRenderViewHost() ?
1332 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1333}
1334
1335bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471336 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271337 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221338 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231339 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511340 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271341 return true;
1342 return false;
1343}
1344
1345void TabContents::SetFocusToLocationBar(bool select_all) {
1346 if (delegate_)
1347 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211348}
1349
[email protected]8b5af492011-11-28 21:50:581350void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301351 const string16& type,
1352 const string16& href,
1353 const string16& title,
1354 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511355 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301356 this, action, type, href, title, disposition);
1357}
1358
[email protected]678105012011-12-09 04:01:211359void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301360 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001361 WebIntentsDispatcherImpl* intents_dispatcher =
1362 new WebIntentsDispatcherImpl(this, intent, intent_id);
1363 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301364}
1365
[email protected]724159a2010-12-30 01:11:181366void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1367 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591368 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181369 const GURL& url) {
1370 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1371 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591372 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301373 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181374
[email protected]8093a542011-05-13 07:29:321375 RenderViewHost* rvh =
1376 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521377 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101378 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251379 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101380 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321381 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101382
[email protected]724159a2010-12-30 01:11:181383 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591384 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251385 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591386 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181387 }
1388}
1389
1390void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591391 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181392 const GURL& source_url,
1393 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491394 // TODO(creis): Remove this method and have the pre-rendering code listen to
1395 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1396 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231397 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181398 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251399 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181400 else
1401 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511402 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181403 return;
[email protected]e7d50892011-01-19 21:47:381404
[email protected]4850a7f2011-03-08 23:36:591405 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251406 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261407 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591408 opener_url));
[email protected]724159a2010-12-30 01:11:181409}
1410
1411void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581412 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1413 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1414 << ", error_code: " << params.error_code
1415 << ", error_description: " << params.error_description
1416 << ", is_main_frame: " << params.is_main_frame
1417 << ", showing_repost_interstitial: " <<
1418 params.showing_repost_interstitial
1419 << ", frame_id: " << params.frame_id;
1420 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591421 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301422 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181423
[email protected]d7b175e2011-10-11 15:31:581424 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181425 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1426 // This means that the interstitial won't be torn down properly, which is
1427 // bad. But if we have an interstitial, go back to another tab type, and
1428 // then load the same interstitial again, we could end up getting the first
1429 // interstitial's "failed" message (as a result of the cancel) when we're on
1430 // the second one.
1431 //
1432 // We can't tell this apart, so we think we're tearing down the current page
1433 // which will cause a crash later one. There is also some code in
1434 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1435 // out because of this problem.
1436 //
1437 // http://code.google.com/p/chromium/issues/detail?id=2855
1438 // Because this will not tear down the interstitial properly, if "back" is
1439 // back to another tab type, the interstitial will still be somewhat alive
1440 // in the previous tab type. If you navigate somewhere that activates the
1441 // tab with the interstitial again, you'll see a flash before the new load
1442 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271443 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181444 LOG(WARNING) << "Discarding message during interstitial.";
1445 return;
1446 }
1447
[email protected]02102f82011-06-13 20:37:021448 // Discard our pending entry if the load canceled (e.g. if we decided to
1449 // download the file instead of load it). We do not verify that the URL
1450 // being canceled matches the pending entry's URL because they will not
1451 // match if a redirect occurred (in which case we do not want to leave a
1452 // stale redirect URL showing). This means that we also cancel the pending
1453 // entry if the user started a new navigation. As a result, the navigation
1454 // controller may not remember that a load is in progress, but the
1455 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251456 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161457 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181458
[email protected]151a63d2011-12-20 22:32:521459 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181460 }
1461
1462 // Send out a notification that we failed a provisional load with an error.
1463 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581464 params.is_main_frame,
1465 controller_.IsURLInPageNavigation(validated_url),
1466 validated_url,
1467 std::string(),
1468 false,
1469 params.frame_id);
1470 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181471
[email protected]ad50def52011-10-19 23:17:071472 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271473 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501474 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531475 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101476
[email protected]d8c660432011-12-22 20:51:251477 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581478 observers_,
1479 DidFailProvisionalLoad(params.frame_id,
1480 params.is_main_frame,
1481 validated_url,
1482 params.error_code,
1483 params.error_description));
[email protected]724159a2010-12-30 01:11:181484}
1485
1486void TabContents::OnDidLoadResourceFromMemoryCache(
1487 const GURL& url,
[email protected]70435962011-08-02 20:13:281488 const std::string& security_info,
1489 const std::string& http_method,
1490 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191491 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181492 cache.Increment();
1493
1494 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081495 int cert_id = 0;
1496 net::CertStatus cert_status = 0;
1497 int security_bits = -1;
1498 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511499 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1500 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301501 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161502 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181503
[email protected]ad50def52011-10-19 23:17:071504 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271505 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501506 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531507 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181508}
1509
1510void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381511 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181512 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201513 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181514}
1515
1516void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021517 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231518 LOG(INFO) << security_origin << " ran insecure content from "
1519 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381520 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051521 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381522 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051523 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1524 }
[email protected]330614de2012-02-13 17:07:181525 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411526 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201527 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181528}
1529
1530void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1531 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251532 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101533 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181534}
1535
[email protected]1a55c5be2011-11-29 11:36:311536void TabContents::OnDidFinishLoad(
1537 int64 frame_id,
1538 const GURL& validated_url,
1539 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251540 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311541 DidFinishLoad(frame_id, validated_url, is_main_frame));
1542}
1543
1544void TabContents::OnDidFailLoadWithError(int64 frame_id,
1545 const GURL& validated_url,
1546 bool is_main_frame,
1547 int error_code,
1548 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251549 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311550 DidFailLoad(frame_id, validated_url, is_main_frame,
1551 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181552}
1553
[email protected]c8f73ab2011-01-22 00:05:171554void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271555 content_restrictions_ = restrictions;
1556 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171557}
1558
[email protected]216813952011-05-19 22:21:261559void TabContents::OnGoToEntryAtOffset(int offset) {
1560 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231561 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251562 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261563 if (!entry)
1564 return;
1565 // Note that we don't call NavigationController::GotToOffset() as we don't
1566 // want to create a pending navigation entry (it might end up lingering
1567 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251568 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581569 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511570 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581571 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471572 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571573
1574 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1575 // it in now that we know. This allows us to find the entry when it commits.
1576 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231577 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331578 entry->set_site_instance(
1579 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571580 }
[email protected]216813952011-05-19 22:21:261581 }
1582}
1583
1584void TabContents::OnUpdateZoomLimits(int minimum_percent,
1585 int maximum_percent,
1586 bool remember) {
1587 minimum_zoom_percent_ = minimum_percent;
1588 maximum_zoom_percent_ = maximum_percent;
1589 temporary_zoom_settings_ = !remember;
1590}
1591
[email protected]0bfbf882011-12-22 18:19:271592void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481593 download_stats::RecordDownloadSource(
1594 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261595 // Check if the URL to save matches the URL of the main frame. Since this
1596 // message originates from Pepper plugins, it may not be the case if the
1597 // plugin is an embedded element.
1598 GURL main_frame_url = GetURL();
1599 if (!main_frame_url.is_valid())
1600 return;
1601 bool is_main_frame = (url == main_frame_url);
1602 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271603}
1604
[email protected]3a29a6e2011-08-24 18:26:211605void TabContents::OnEnumerateDirectory(int request_id,
1606 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591607 ChildProcessSecurityPolicyImpl* policy =
1608 ChildProcessSecurityPolicyImpl::GetInstance();
1609 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1610 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211611}
1612
[email protected]7d189022011-08-25 22:54:201613void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511614 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201615}
1616
1617void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1618 const GURL& url,
1619 const string16& title) {
[email protected]b9535422012-02-09 01:47:591620 ChildProcessSecurityPolicyImpl* policy =
1621 ChildProcessSecurityPolicyImpl::GetInstance();
1622 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1623 return;
[email protected]6934a702011-12-20 00:04:511624 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201625}
1626
[email protected]b888919c2011-09-02 00:32:161627void TabContents::OnFindReply(int request_id,
1628 int number_of_matches,
1629 const gfx::Rect& selection_rect,
1630 int active_match_ordinal,
1631 bool final_update) {
[email protected]6934a702011-12-20 00:04:511632 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1633 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001634 // Send a notification to the renderer that we are ready to receive more
1635 // results from the scoping effort of the Find operation. The FindInPage
1636 // scoping is asynchronous and periodically sends results back up to the
1637 // browser using IPC. In an effort to not spam the browser we have the
1638 // browser send an ACK for each FindReply message and have the renderer
1639 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521640 GetRenderViewHost()->Send(
1641 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161642}
1643
[email protected]d952a052011-09-06 18:42:451644void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511645 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451646}
1647
[email protected]7fc4bbb2011-09-08 21:23:101648void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1649 bool blocked_by_policy) {
1650 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251651 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101652 AppCacheAccessed(manifest_url, blocked_by_policy));
1653}
1654
[email protected]96d185d2009-04-24 03:28:541655// Notifies the RenderWidgetHost instance about the fact that the page is
1656// loading, or done loading and calls the base implementation.
1657void TabContents::SetIsLoading(bool is_loading,
1658 LoadNotificationDetails* details) {
1659 if (is_loading == is_loading_)
1660 return;
1661
1662 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211663 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541664 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561665 upload_size_ = 0;
1666 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541667 }
1668
1669 render_manager_.SetIsLoading(is_loading);
1670
1671 is_loading_ = is_loading;
1672 waiting_for_response_ = is_loading;
1673
[email protected]6ebdc9b2010-09-27 16:55:571674 if (delegate_)
1675 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461676 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541677
[email protected]432115822011-07-10 15:52:271678 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1679 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071680 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541681 if (details)
[email protected]6c2381d2011-10-19 02:52:531682 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071683 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501684 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541685 det);
1686}
1687
[email protected]420ae012009-04-24 05:16:321688void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131689 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321690 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561691 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381692 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441693 // that opened the window, as long as both renderers have the same
1694 // privileges.
[email protected]1fd1a502011-03-30 16:55:561695 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561696 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581697 // web_ui might be NULL if the URL refers to a non-existent extension.
1698 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401699 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521700 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441701 }
1702 }
[email protected]1fd1a502011-03-30 16:55:561703 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441704 }
1705
[email protected]4e697b042011-07-08 06:44:561706 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321707 // Clear the status bubble. This is a workaround for a bug where WebKit
1708 // doesn't let us know that the cursor left an element during a
1709 // transition (this is also why the mouse cursor remains as a hand after
1710 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1711 // clear the bubble when a user navigates to a named anchor in the same
1712 // page.
[email protected]36fc0392011-12-25 03:59:511713 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321714 }
1715
[email protected]a6e82fc2010-02-24 22:28:141716 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471717 // Once the main frame is navigated, we're no longer considered to have
1718 // displayed insecure content.
1719 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171720 }
[email protected]ce5c4502009-05-06 16:46:111721
[email protected]3c9e1872010-11-18 16:17:491722 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041724 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321725}
1726
1727void TabContents::DidNavigateAnyFramePostCommit(
1728 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131729 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321730 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061731 // If we navigate off the page, reset JavaScript state. This does nothing
1732 // to prevent a malicious script from spamming messages, since the script
1733 // could just reload the page to stop blocking.
1734 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551735 dialog_creator_->ResetJavaScriptState(this);
1736 dialog_creator_ = NULL;
1737 }
[email protected]420ae012009-04-24 05:16:321738
[email protected]3c9e1872010-11-18 16:17:491739 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251740 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041741 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321742}
1743
[email protected]74ce1ad2011-12-16 21:51:461744void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1745 // If we are creating a RVH for a restored controller, then we need to make
1746 // sure the RenderView starts with a next_page_id_ larger than the number
1747 // of restored entries. This must be called before the RenderView starts
1748 // navigating (to avoid a race between the browser updating max_page_id and
1749 // the renderer updating next_page_id_). Because of this, we only call this
1750 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561751 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461752 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1753 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321754}
1755
[email protected]10f417c52011-12-28 21:04:231756bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571757 const string16& title) {
[email protected]420ae012009-04-24 05:16:321758 // For file URLs without a title, use the pathname instead. In the case of a
1759 // synthesized title, we don't want the update to count toward the "one set
1760 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511761 string16 final_title;
[email protected]420ae012009-04-24 05:16:321762 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511763 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1764 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321765 explicit_set = false; // Don't count synthetic titles toward the set limit.
1766 } else {
[email protected]acafd272011-07-26 17:35:571767 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321768 explicit_set = true;
1769 }
1770
[email protected]987fc3a2011-05-26 14:18:091771 // If a page is created via window.open and never navigated,
1772 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551773 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091774 if (entry) {
[email protected]36fc0392011-12-25 03:59:511775 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091776 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321777
[email protected]36fc0392011-12-25 03:59:511778 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091779 } else {
1780 if (page_title_when_no_navigation_entry_ == final_title)
1781 return false; // Nothing changed, don't bother.
1782
1783 page_title_when_no_navigation_entry_ = final_title;
1784 }
[email protected]420ae012009-04-24 05:16:321785
[email protected]420ae012009-04-24 05:16:321786 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231787 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321788
[email protected]105bb0f2011-05-24 17:12:141789 TitleUpdatedDetails details(entry, explicit_set);
1790
[email protected]ad50def52011-10-19 23:17:071791 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441792 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1793 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531794 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041795
[email protected]420ae012009-04-24 05:16:321796 return true;
1797}
1798
1799void TabContents::NotifySwapped() {
1800 // After sending out a swap notification, we need to send a disconnect
1801 // notification so that clients that pick up a pointer to |this| can NULL the
1802 // pointer. See Bug 1230284.
1803 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071804 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201805 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1806 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071807 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321808}
1809
1810void TabContents::NotifyConnected() {
1811 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071812 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121813 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1814 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071815 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321816}
1817
1818void TabContents::NotifyDisconnected() {
1819 if (!notify_disconnection_)
1820 return;
1821
1822 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071823 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321824 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1825 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071826 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321827}
1828
[email protected]8d3347f2009-07-09 22:00:211829RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321830 return view_.get();
1831}
1832
[email protected]8d3347f2009-07-09 22:00:211833RenderViewHostDelegate::RendererManagement*
1834TabContents::GetRendererManagementDelegate() {
1835 return &render_manager_;
1836}
1837
[email protected]daf82f82011-10-31 22:35:311838content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371839 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461840 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511841}
1842
[email protected]768c5472011-12-26 19:06:171843WebContents* TabContents::GetAsWebContents() {
1844 return this;
1845}
1846
[email protected]da4dfc42011-10-12 15:53:561847content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431848 return view_type_;
[email protected]7b291f92009-08-14 05:43:531849}
1850
[email protected]b7a756d42012-01-23 18:08:171851gfx::Rect TabContents::GetRootWindowResizerRect() const {
1852 if (delegate_)
1853 return delegate_->GetRootWindowResizerRect();
1854 return gfx::Rect();
1855}
1856
[email protected]420ae012009-04-24 05:16:321857void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071858 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271859 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321860 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531861 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231862 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321863 if (!entry)
1864 return;
1865
1866 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351867 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561868 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581869 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321870
1871 if (entry->IsViewSourceMode()) {
1872 // Put the renderer in view source mode.
1873 render_view_host->Send(
1874 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1875 }
[email protected]0666aef2009-05-13 19:48:081876
[email protected]d487beefe2011-12-21 05:41:211877 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261878
1879 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251880 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321881}
1882
1883void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521884 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321885 // Don't notify the world, since this came from a renderer in the
1886 // background.
1887 return;
1888 }
1889
1890 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311891 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231892 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301893
1894 // Restore the focus to the tab (otherwise the focus will be on the top
1895 // window).
[email protected]484ae5912010-09-29 19:16:141896 if (was_crashed && !FocusLocationBarByDefault() &&
1897 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301898 Focus();
[email protected]484ae5912010-09-29 19:16:141899 }
[email protected]32ded2212011-11-10 18:51:431900
[email protected]d8c660432011-12-22 20:51:251901 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321902}
1903
[email protected]443b80e2010-12-14 00:42:231904void TabContents::RenderViewGone(RenderViewHost* rvh,
1905 base::TerminationStatus status,
1906 int error_code) {
[email protected]151a63d2011-12-20 22:32:521907 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321908 // The pending page's RenderViewHost is gone.
1909 return;
1910 }
1911
1912 SetIsLoading(false, NULL);
1913 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231914 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311915 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321916
[email protected]d8c660432011-12-22 20:51:251917 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271918 observers_,
[email protected]be1f56ab2011-12-22 06:55:311919 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321920}
1921
[email protected]2e4633c2009-07-09 16:58:061922void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481923 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251924 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061925}
1926
[email protected]420ae012009-04-24 05:16:321927void TabContents::DidNavigate(RenderViewHost* rvh,
1928 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581929 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321930 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371931
[email protected]434f69f2012-02-06 21:56:521932 // Update the site of the SiteInstance if it doesn't have one yet, unless
1933 // this is for about:blank. In that case, the SiteInstance can still be
1934 // considered unused until a navigation to a real page.
1935 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1936 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331937 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521938 }
[email protected]420ae012009-04-24 05:16:321939
1940 // Need to update MIME type here because it's referred to in
1941 // UpdateNavigationCommands() called by RendererDidNavigate() to
1942 // determine whether or not to enable the encoding menu.
1943 // It's updated only for the main frame. For a subframe,
1944 // RenderView::UpdateURL does not set params.contents_mime_type.
1945 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1946 // TODO(jungshik): Add a test for the encoding menu to avoid
1947 // regressing it again.
[email protected]2905f742011-10-13 03:51:581948 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321949 contents_mime_type_ = params.contents_mime_type;
1950
[email protected]8286f51a2011-05-31 17:39:131951 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001952 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391953
[email protected]a9c0bfe2010-09-17 08:35:221954 // Send notification about committed provisional loads. This notification is
1955 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1956 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081957 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071958 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1959 // that is not recorded in the navigation history. For the purpose of
1960 // tracking navigation events, we treat this event as a sub frame navigation
1961 // event.
1962 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581963 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221964 // Whether or not a page transition was triggered by going backward or
1965 // forward in the history is only stored in the navigation controller's
1966 // entry list.
1967 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511968 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581969 content::PAGE_TRANSITION_FORWARD_BACK)) {
1970 transition_type = content::PageTransitionFromInt(
1971 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221972 }
[email protected]0d60f0192011-04-14 12:40:101973 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251974 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101975 DidCommitProvisionalLoadForFrame(params.frame_id,
1976 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221977 }
1978
[email protected]76543b92009-08-31 17:27:451979 if (!did_navigate)
1980 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321981
1982 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1983 // for the appropriate notification (best) or you can add it to
1984 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1985 // necessary, please).
1986
1987 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001988 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321989 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511990 if (delegate_)
1991 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001992 }
[email protected]420ae012009-04-24 05:16:321993 DidNavigateAnyFramePostCommit(rvh, details, params);
1994}
1995
1996void TabContents::UpdateState(RenderViewHost* rvh,
1997 int32 page_id,
1998 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151999 // Ensure that this state update comes from either the active RVH or one of
2000 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522001 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322002
2003 // We must be prepared to handle state updates for any page, these occur
2004 // when the user is scrolling and entering form data, as well as when we're
2005 // leaving a page, in which case our state may have already been moved to
2006 // the next page. The navigation controller will look up the appropriate
2007 // NavigationEntry and update it when it is notified via the delegate.
2008
2009 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:152010 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:322011 if (entry_index < 0)
2012 return;
[email protected]10f417c52011-12-28 21:04:232013 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322014
[email protected]36fc0392011-12-25 03:59:512015 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322016 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512017 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322018 controller_.NotifyEntryChanged(entry, entry_index);
2019}
2020
2021void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572022 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462023 const string16& title,
2024 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322025 // If we have a title, that's a pretty good indication that we've started
2026 // getting useful data.
2027 SetNotWaitingForResponse();
2028
[email protected]73eb2602012-02-09 19:50:552029 // Try to find the navigation entry, which might not be the current one.
2030 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232031 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2032 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092033
[email protected]73eb2602012-02-09 19:50:552034 // We can handle title updates when we don't have an entry in
2035 // UpdateTitleForEntry, but only if the update is from the current RVH.
2036 if (!entry && rvh != GetRenderViewHost())
2037 return;
2038
[email protected]a49e10b2011-08-01 23:57:462039 // TODO(evan): make use of title_direction.
2040 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092041 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322042 return;
2043
2044 // Broadcast notifications when the UI should be updated.
2045 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462046 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322047}
2048
[email protected]420ae012009-04-24 05:16:322049void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402050 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312051 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322052}
2053
2054void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512055 if (delegate_)
2056 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322057}
2058
[email protected]420ae012009-04-24 05:16:322059void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292060 // The UI may be in an event-tracking loop, such as between the
2061 // mouse-down and mouse-up in text selection or a button click.
2062 // Defer the close until after tracking is complete, so that we
2063 // don't free objects out from under the UI.
2064 // TODO(shess): This could probably be integrated with the
2065 // IsDoingDrag() test below. Punting for now because I need more
2066 // research to understand how this impacts platforms other than Mac.
2067 // TODO(shess): This could get more fine-grained. For instance,
2068 // closing a tab in another window while selecting text in the
2069 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212070 if (GetView()->IsEventTracking()) {
2071 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292072 return;
2073 }
2074
[email protected]24a4d1062009-07-10 23:10:422075 // If we close the tab while we're in the middle of a drag, we'll crash.
2076 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212077 if (GetView()->IsDoingDrag()) {
2078 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422079 return;
2080 }
2081
[email protected]420ae012009-04-24 05:16:322082 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522083 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512084 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322085}
2086
[email protected]cd9ed79d2011-11-15 19:22:572087void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522088 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512089 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572090}
2091
[email protected]420ae012009-04-24 05:16:322092void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512093 if (delegate_ && delegate_->IsPopupOrPanel(this))
2094 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322095}
2096
[email protected]7ab1e7d62009-10-14 23:32:012097void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322098 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492099
[email protected]6934a702011-12-20 00:04:512100 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212101 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512102 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002103 }
[email protected]3c9e1872010-11-18 16:17:492104
2105 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252106 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322107}
2108
[email protected]7ab1e7d62009-10-14 23:32:012109void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322110 scoped_ptr<LoadNotificationDetails> details;
2111
[email protected]10f417c52011-12-28 21:04:232112 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322113 // An entry may not exist for a stop when loading an initial blank page or
2114 // if an iframe injected by script into a blank page finishes loading.
2115 if (entry) {
[email protected]420ae012009-04-24 05:16:322116 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2117
2118 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512119 entry->GetVirtualURL(),
2120 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322121 elapsed,
2122 &controller_,
2123 controller_.GetCurrentEntryIndex()));
2124 }
2125
[email protected]420ae012009-04-24 05:16:322126 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492127
2128 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252129 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322130}
2131
[email protected]c95fa8b2011-04-28 20:26:162132void TabContents::DidCancelLoading() {
2133 controller_.DiscardNonCommittedEntries();
2134
2135 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462136 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162137}
2138
[email protected]1a3c3cb2010-12-16 21:03:402139void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512140 if (delegate_)
2141 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402142}
2143
[email protected]952a68e2011-11-17 00:36:102144void TabContents::DocumentAvailableInMainFrame(
2145 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252146 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102147 DocumentAvailableInMainFrame());
2148}
2149
[email protected]25497492010-09-11 15:15:082150void TabContents::DocumentOnLoadCompletedInMainFrame(
2151 RenderViewHost* render_view_host,
2152 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072153 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272154 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322155 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532156 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082157}
2158
[email protected]ae5184d62011-10-06 19:25:582159void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152160 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582161 WindowOpenDisposition disposition,
2162 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482163 // Delegate to RequestTransferURL because this is just the generic
2164 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582165 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482166 GlobalRequestID());
2167}
2168
2169void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582170 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482171 WindowOpenDisposition disposition,
2172 int64 source_frame_id,
2173 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202174 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582175 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582176 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352177 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322178 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2179 // generated suggestions).
2180 //
[email protected]e0112912011-02-02 22:54:352181 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162182 // want web sites to see a referrer of "chrome://blah" (and some
2183 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322184 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432185 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222186 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482187 false /* is_renderer_initiated */);
2188 params.transferred_global_request_id = old_request_id;
2189 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222190 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322191 } else {
[email protected]6bf6a6b52012-02-03 15:41:432192 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482193 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2194 params.transferred_global_request_id = old_request_id;
2195 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582196 }
2197 if (new_contents) {
2198 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252199 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582200 DidOpenRequestedURL(new_contents,
2201 url,
2202 referrer,
2203 disposition,
2204 transition_type,
2205 source_frame_id));
[email protected]420ae012009-04-24 05:16:322206 }
2207}
2208
[email protected]420ae012009-04-24 05:16:322209void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342210 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412211 const string16& message,
2212 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322213 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472214 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322215 IPC::Message* reply_msg,
2216 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072217 // Suppress JavaScript dialogs when requested. Also suppress messages when
2218 // showing an interstitial as it's shown over the previous page and we don't
2219 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502220 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152221 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272222 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072223 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522224 delegate_->ShouldSuppressDialogs() ||
2225 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322226
2227 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432228 std::string accept_lang = content::GetContentClient()->browser()->
2229 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552230 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522231 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432232 this,
2233 frame_url.GetOrigin(),
2234 accept_lang,
2235 javascript_message_type,
2236 message,
[email protected]51da7e32012-01-30 19:24:522237 default_prompt,
2238 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432239 reply_msg),
[email protected]51da7e32012-01-30 19:24:522240 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322241 }
[email protected]3ab9cb82011-06-03 18:02:072242
2243 if (suppress_this_message) {
2244 // If we are suppressing messages, just reply as if the user immediately
2245 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342246 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072247 }
2248
2249 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322250}
2251
[email protected]fedec012012-01-28 03:09:342252void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412253 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322254 bool is_reload,
[email protected]420ae012009-04-24 05:16:322255 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512256 if (delegate_)
2257 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072258
2259 bool suppress_this_message =
2260 rvh->is_swapped_out() ||
2261 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522262 delegate_->ShouldSuppressDialogs() ||
2263 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152264 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342265 // The reply must be sent to the RVH that sent the request.
2266 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502267 return;
2268 }
[email protected]3ab9cb82011-06-03 18:02:072269
[email protected]7ab1e7d62009-10-14 23:32:012270 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552271 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522272 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322273 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522274 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2275 reply_msg));
[email protected]420ae012009-04-24 05:16:322276}
2277
[email protected]420ae012009-04-24 05:16:322278WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542279 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322280}
2281
[email protected]7d472472011-01-22 01:30:252282void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272283 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252284 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222285
[email protected]99907362012-01-11 05:41:402286 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172287 if (rdh) // NULL in unittests.
2288 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252289}
2290
[email protected]fa1cf0b82010-01-15 21:49:442291void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442292 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252293 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442294}
2295
[email protected]420ae012009-04-24 05:16:322296void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2297 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152298 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522299 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152300 return;
2301
[email protected]e5fc1632011-08-08 07:51:532302 // Ignore renderer unresponsive event if debugger is attached to the tab
2303 // since the event may be a result of the renderer sitting on a breakpoint.
2304 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442305 DevToolsAgentHost* agent =
2306 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2307 if (agent &&
2308 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532309 return;
2310
[email protected]420ae012009-04-24 05:16:322311 if (is_during_unload) {
2312 // Hang occurred while firing the beforeunload/unload handler.
2313 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112314 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322315
2316 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2317 return;
2318
2319 // If the tab hangs in the beforeunload/unload handler there's really
2320 // nothing we can do to recover. Pretend the unload listeners have
2321 // all fired and close the tab. If the hang is in the beforeunload handler
2322 // then the user will not have the option of cancelling the close.
2323 Close(rvh);
2324 return;
2325 }
2326
[email protected]151a63d2011-12-20 22:32:522327 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472328 return;
2329
[email protected]6934a702011-12-20 00:04:512330 if (delegate_)
2331 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322332}
2333
2334void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512335 if (delegate_)
2336 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322337}
2338
2339void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212340 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562341 uint64 upload_position,
2342 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322343 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562344 upload_position_ = upload_position;
2345 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502346 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202347 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302348 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212349 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322350 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462351 if (IsLoading()) {
2352 NotifyNavigationStateChanged(
2353 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2354 }
[email protected]420ae012009-04-24 05:16:322355}
2356
[email protected]7d472472011-01-22 01:30:252357void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512358 if (delegate_)
2359 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252360}
2361
[email protected]420ae012009-04-24 05:16:322362void TabContents::BeforeUnloadFiredFromRenderManager(
2363 bool proceed,
2364 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512365 if (delegate_)
2366 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322367}
2368
[email protected]3a3d47472010-07-15 21:03:542369void TabContents::DidStartLoadingFromRenderManager(
2370 RenderViewHost* render_view_host) {
2371 DidStartLoading();
2372}
2373
2374void TabContents::RenderViewGoneFromRenderManager(
2375 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232376 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2377 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542378}
2379
[email protected]420ae012009-04-24 05:16:322380void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102381 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262382 gfx::Size size = view_->GetContainerSize();
2383 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2384 // here during container initialization and normal window size will be set
2385 // later. In case of tab duplication this resizing to 0x0 prevents setting
2386 // normal size later so just ignore it.
2387 if (!size.IsEmpty())
2388 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322389}
2390
[email protected]3a3d47472010-07-15 21:03:542391void TabContents::NotifySwappedFromRenderManager() {
2392 NotifySwapped();
2393}
2394
[email protected]d202a7c2012-01-04 07:53:472395NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202396 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542397}
2398
[email protected]d2353452012-01-19 19:53:562399WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2400 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322401}
2402
[email protected]10f417c52011-12-28 21:04:232403NavigationEntry*
2404 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322405 return controller_.GetLastCommittedEntry();
2406}
2407
2408bool TabContents::CreateRenderViewForRenderManager(
2409 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442410 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322411 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522412
[email protected]420ae012009-04-24 05:16:322413 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442414 if (rwh_view)
2415 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322416
[email protected]74ce1ad2011-12-16 21:51:462417 // Make sure we use the correct starting page_id in the new RenderView.
2418 UpdateMaxPageIDIfNecessary(render_view_host);
2419 int32 max_page_id =
2420 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2421
2422 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522423 return false;
2424
[email protected]e60c0232011-11-11 19:56:352425#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502426 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2427 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442428 if (rwh_view) {
2429 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2430 render_widget_host->WasResized();
2431 }
[email protected]f8233cc2011-05-31 20:24:502432#endif
2433
[email protected]420ae012009-04-24 05:16:322434 return true;
2435}
2436
[email protected]fedec012012-01-28 03:09:342437void TabContents::OnDialogClosed(RenderViewHost* rvh,
2438 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072439 bool success,
2440 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542441 if (is_showing_before_unload_dialog_ && !success) {
2442 // If a beforeunload dialog is canceled, we need to stop the throbber from
2443 // spinning, since we forced it to start spinning in Navigate.
2444 DidStopLoading();
2445
2446 tab_close_start_time_ = base::TimeTicks();
2447 }
2448 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342449 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542450}
2451
[email protected]be1f56ab2011-12-22 06:55:312452void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122453 encoding_ = content::GetContentClient()->browser()->
2454 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102455}
[email protected]f45d2a72010-03-08 23:28:352456
[email protected]e30d68d2012-02-09 00:06:262457void TabContents::SaveURL(const GURL& url,
2458 const GURL& referrer,
2459 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142460 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2461 if (!dlm)
2462 return;
2463 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262464 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142465 const NavigationEntry* entry = controller_.GetActiveEntry();
2466 if (entry)
2467 post_id = entry->GetPostID();
2468 }
2469 DownloadSaveInfo save_info;
2470 save_info.prompt_for_save_location = true;
2471 dlm->DownloadUrl(url,
2472 referrer,
2473 "",
2474 true, // prefer_cache
2475 post_id,
2476 save_info,
2477 this);
2478}
2479
[email protected]33f74972010-12-08 16:40:362480void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212481 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442482 // Can be NULL during tests.
2483 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212484 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362485}