1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "base/command_line.h"
10 #include "base/lazy_instance.h"
11 #include "base/logging.h"
12 #include "base/metrics/histogram.h"
13 #include "base/process/process.h"
14 #include "base/profiler/scoped_tracker.h"
15 #include "base/strings/string16.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h"
20 #include "base/trace_event/trace_event.h"
21 #include "content/browser/accessibility/accessibility_mode_helper.h"
22 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
23 #include "content/browser/bad_message.h"
24 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
25 #include "content/browser/browser_plugin/browser_plugin_guest.h"
26 #include "content/browser/child_process_security_policy_impl.h"
27 #include "content/browser/devtools/devtools_manager.h"
28 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
29 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
30 #include "content/browser/download/download_stats.h"
31 #include "content/browser/download/mhtml_generation_manager.h"
32 #include "content/browser/download/save_package.h"
33 #include "content/browser/frame_host/cross_process_frame_connector.h"
34 #include "content/browser/frame_host/interstitial_page_impl.h"
35 #include "content/browser/frame_host/navigation_entry_impl.h"
36 #include "content/browser/frame_host/navigator_impl.h"
37 #include "content/browser/frame_host/render_frame_host_impl.h"
38 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
39 #include "content/browser/geolocation/geolocation_service_context.h"
40 #include "content/browser/host_zoom_map_impl.h"
41 #include "content/browser/loader/resource_dispatcher_host_impl.h"
42 #include "content/browser/manifest/manifest_manager_host.h"
43 #include "content/browser/media/audio_stream_monitor.h"
44 #include "content/browser/media/capture/web_contents_audio_muter.h"
45 #include "content/browser/message_port_message_filter.h"
46 #include "content/browser/plugin_content_origin_whitelist.h"
47 #include "content/browser/power_save_blocker_impl.h"
48 #include "content/browser/renderer_host/render_process_host_impl.h"
49 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
50 #include "content/browser/renderer_host/render_view_host_impl.h"
51 #include "content/browser/renderer_host/render_widget_host_impl.h"
52 #include "content/browser/renderer_host/render_widget_host_view_base.h"
53 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
54 #include "content/browser/site_instance_impl.h"
55 #include "content/browser/web_contents/web_contents_view_guest.h"
56 #include "content/browser/webui/generic_handler.h"
57 #include "content/browser/webui/web_ui_controller_factory_registry.h"
58 #include "content/browser/webui/web_ui_impl.h"
59 #include "content/common/browser_plugin/browser_plugin_constants.h"
60 #include "content/common/browser_plugin/browser_plugin_messages.h"
61 #include "content/common/frame_messages.h"
62 #include "content/common/image_messages.h"
63 #include "content/common/input_messages.h"
64 #include "content/common/ssl_status_serialization.h"
65 #include "content/common/view_messages.h"
66 #include "content/public/browser/ax_event_notification_details.h"
67 #include "content/public/browser/browser_context.h"
68 #include "content/public/browser/browser_plugin_guest_manager.h"
69 #include "content/public/browser/content_browser_client.h"
70 #include "content/public/browser/devtools_agent_host.h"
71 #include "content/public/browser/download_manager.h"
72 #include "content/public/browser/download_url_parameters.h"
73 #include "content/public/browser/invalidate_type.h"
74 #include "content/public/browser/javascript_dialog_manager.h"
75 #include "content/public/browser/load_from_memory_cache_details.h"
76 #include "content/public/browser/load_notification_details.h"
77 #include "content/public/browser/navigation_details.h"
78 #include "content/public/browser/notification_details.h"
79 #include "content/public/browser/notification_service.h"
80 #include "content/public/browser/render_widget_host_iterator.h"
81 #include "content/public/browser/resource_request_details.h"
82 #include "content/public/browser/screen_orientation_dispatcher_host.h"
83 #include "content/public/browser/storage_partition.h"
84 #include "content/public/browser/user_metrics.h"
85 #include "content/public/browser/web_contents_delegate.h"
86 #include "content/public/browser/web_contents_observer.h"
87 #include "content/public/common/bindings_policy.h"
88 #include "content/public/common/content_constants.h"
89 #include "content/public/common/content_switches.h"
90 #include "content/public/common/page_zoom.h"
91 #include "content/public/common/result_codes.h"
92 #include "content/public/common/url_constants.h"
93 #include "content/public/common/url_utils.h"
94 #include "content/public/common/web_preferences.h"
95 #include "net/base/mime_util.h"
96 #include "net/base/net_util.h"
97 #include "net/http/http_cache.h"
98 #include "net/http/http_transaction_factory.h"
99 #include "net/url_request/url_request_context.h"
100 #include "net/url_request/url_request_context_getter.h"
101 #include "ui/base/layout.h"
102 #include "ui/gfx/display.h"
103 #include "ui/gfx/screen.h"
104 #include "ui/gl/gl_switches.h"
106 #if defined(ENABLE_BROWSER_CDMS)
107 #include "content/browser/media/media_web_contents_observer.h"
110 #if defined(OS_ANDROID)
111 #include "content/browser/android/content_video_view.h"
112 #include "content/browser/android/date_time_chooser_android.h"
113 #include "content/browser/android/media_players_observer.h"
114 #include "content/browser/media/android/browser_media_player_manager.h"
115 #include "content/browser/web_contents/web_contents_android.h"
118 #if defined(OS_MACOSX)
119 #include "base/mac/foundation_util.h"
125 const int kMinimumDelayBetweenLoadingUpdatesMS
= 100;
126 const char kDotGoogleDotCom
[] = ".google.com";
128 #if defined(OS_ANDROID)
129 const char kWebContentsAndroidKey
[] = "web_contents_android";
132 base::LazyInstance
<std::vector
<WebContentsImpl::CreatedCallback
> >
133 g_created_callbacks
= LAZY_INSTANCE_INITIALIZER
;
135 static int StartDownload(RenderFrameHost
* rfh
,
138 uint32_t max_bitmap_size
,
140 static int g_next_image_download_id
= 0;
141 rfh
->Send(new ImageMsg_DownloadImage(rfh
->GetRoutingID(),
142 ++g_next_image_download_id
,
147 return g_next_image_download_id
;
150 void NotifyCacheOnIO(
151 scoped_refptr
<net::URLRequestContextGetter
> request_context
,
153 const std::string
& http_method
) {
154 net::HttpCache
* cache
= request_context
->GetURLRequestContext()->
155 http_transaction_factory()->GetCache();
157 cache
->OnExternalCacheHit(url
, http_method
);
160 // Helper function for retrieving all the sites in a frame tree.
161 bool CollectSites(BrowserContext
* context
,
162 std::set
<GURL
>* sites
,
163 FrameTreeNode
* node
) {
164 sites
->insert(SiteInstance::GetSiteForURL(context
, node
->current_url()));
168 bool ForEachFrameInternal(
169 const base::Callback
<void(RenderFrameHost
*)>& on_frame
,
170 FrameTreeNode
* node
) {
171 on_frame
.Run(node
->current_frame_host());
175 bool ForEachPendingFrameInternal(
176 const base::Callback
<void(RenderFrameHost
*)>& on_frame
,
177 FrameTreeNode
* node
) {
178 RenderFrameHost
* pending_frame_host
=
179 node
->render_manager()->pending_frame_host();
180 if (pending_frame_host
)
181 on_frame
.Run(pending_frame_host
);
185 void SendToAllFramesInternal(IPC::Message
* message
, RenderFrameHost
* rfh
) {
186 IPC::Message
* message_copy
= new IPC::Message(*message
);
187 message_copy
->set_routing_id(rfh
->GetRoutingID());
188 rfh
->Send(message_copy
);
191 void AddRenderWidgetHostViewToSet(std::set
<RenderWidgetHostView
*>* set
,
192 RenderFrameHost
* rfh
) {
193 RenderWidgetHostView
* rwhv
= static_cast<RenderFrameHostImpl
*>(rfh
)
196 ->GetRenderWidgetHostView();
200 void SetAccessibilityModeOnFrame(AccessibilityMode mode
,
201 RenderFrameHost
* frame_host
) {
202 static_cast<RenderFrameHostImpl
*>(frame_host
)->SetAccessibilityMode(mode
);
208 WebContents
* WebContents::Create(const WebContents::CreateParams
& params
) {
209 return WebContentsImpl::CreateWithOpener(
210 params
, static_cast<WebContentsImpl
*>(params
.opener
));
213 WebContents
* WebContents::CreateWithSessionStorage(
214 const WebContents::CreateParams
& params
,
215 const SessionStorageNamespaceMap
& session_storage_namespace_map
) {
216 WebContentsImpl
* new_contents
= new WebContentsImpl(
217 params
.browser_context
, NULL
);
219 for (SessionStorageNamespaceMap::const_iterator it
=
220 session_storage_namespace_map
.begin();
221 it
!= session_storage_namespace_map
.end();
223 new_contents
->GetController()
224 .SetSessionStorageNamespace(it
->first
, it
->second
.get());
227 new_contents
->Init(params
);
231 void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
232 const CreatedCallback
& callback
) {
233 g_created_callbacks
.Get().push_back(callback
);
236 void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
237 const CreatedCallback
& callback
) {
238 for (size_t i
= 0; i
< g_created_callbacks
.Get().size(); ++i
) {
239 if (g_created_callbacks
.Get().at(i
).Equals(callback
)) {
240 g_created_callbacks
.Get().erase(g_created_callbacks
.Get().begin() + i
);
246 WebContents
* WebContents::FromRenderViewHost(const RenderViewHost
* rvh
) {
247 return rvh
->GetDelegate()->GetAsWebContents();
250 WebContents
* WebContents::FromRenderFrameHost(RenderFrameHost
* rfh
) {
251 RenderFrameHostImpl
* rfh_impl
= static_cast<RenderFrameHostImpl
*>(rfh
);
254 return rfh_impl
->delegate()->GetAsWebContents();
257 // WebContentsImpl::DestructionObserver ----------------------------------------
259 class WebContentsImpl::DestructionObserver
: public WebContentsObserver
{
261 DestructionObserver(WebContentsImpl
* owner
, WebContents
* watched_contents
)
262 : WebContentsObserver(watched_contents
),
266 // WebContentsObserver:
267 void WebContentsDestroyed() override
{
268 owner_
->OnWebContentsDestroyed(
269 static_cast<WebContentsImpl
*>(web_contents()));
273 WebContentsImpl
* owner_
;
275 DISALLOW_COPY_AND_ASSIGN(DestructionObserver
);
278 WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id
,
280 ColorChooser
* chooser
,
282 : render_process_id(render_process_id
),
283 render_frame_id(render_frame_id
),
285 identifier(identifier
) {
288 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
291 // WebContentsImpl -------------------------------------------------------------
293 WebContentsImpl::WebContentsImpl(BrowserContext
* browser_context
,
294 WebContentsImpl
* opener
)
296 controller_(this, browser_context
),
297 render_view_host_delegate_view_(NULL
),
299 created_with_opener_(!!opener
),
301 accessible_parent_(NULL
),
303 frame_tree_(new NavigatorImpl(&controller_
, this),
309 is_load_to_different_document_(false),
310 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING
),
311 crashed_error_code_(0),
312 waiting_for_response_(false),
313 load_state_(net::LOAD_STATE_IDLE
, base::string16()),
314 loading_total_progress_(0.0),
317 displayed_insecure_content_(false),
318 has_accessed_initial_document_(false),
319 theme_color_(SK_ColorTRANSPARENT
),
320 last_sent_theme_color_(SK_ColorTRANSPARENT
),
322 should_normally_be_visible_(true),
323 is_being_destroyed_(false),
324 notify_disconnection_(false),
325 dialog_manager_(NULL
),
326 is_showing_before_unload_dialog_(false),
327 last_active_time_(base::TimeTicks::Now()),
328 closed_by_user_gesture_(false),
329 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor
* 100)),
330 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor
* 100)),
331 render_view_message_source_(NULL
),
332 render_frame_message_source_(NULL
),
333 fullscreen_widget_routing_id_(MSG_ROUTING_NONE
),
334 fullscreen_widget_had_focus_at_shutdown_(false),
336 force_disable_overscroll_content_(false),
337 last_dialog_suppressed_(false),
338 geolocation_service_context_(new GeolocationServiceContext()),
340 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
341 virtual_keyboard_requested_(false),
342 loading_weak_factory_(this) {
343 frame_tree_
.SetFrameRemoveListener(
344 base::Bind(&WebContentsImpl::OnFrameRemoved
,
345 base::Unretained(this)));
346 #if defined(ENABLE_BROWSER_CDMS)
347 media_web_contents_observer_
.reset(new MediaWebContentsObserver(this));
350 #if defined(OS_ANDROID)
351 audio_state_provider_
.reset(new MediaPlayersObserver(this));
353 audio_state_provider_
.reset(new AudioStreamMonitor(this));
357 WebContentsImpl::~WebContentsImpl() {
358 is_being_destroyed_
= true;
360 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
361 // shutdown and be deleted as well.
363 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown
));
365 ClearAllPowerSaveBlockers();
367 for (std::set
<RenderWidgetHostImpl
*>::iterator iter
=
368 created_widgets_
.begin(); iter
!= created_widgets_
.end(); ++iter
) {
369 (*iter
)->DetachDelegate();
371 created_widgets_
.clear();
373 // Clear out any JavaScript state.
375 dialog_manager_
->WebContentsDestroyed(this);
377 if (color_chooser_info_
.get())
378 color_chooser_info_
->chooser
->End();
380 NotifyDisconnected();
382 // Notify any observer that have a reference on this WebContents.
383 NotificationService::current()->Notify(
384 NOTIFICATION_WEB_CONTENTS_DESTROYED
,
385 Source
<WebContents
>(this),
386 NotificationService::NoDetails());
388 // Destroy all frame tree nodes except for the root; this notifies observers.
389 frame_tree_
.ResetForMainFrameSwap();
390 GetRenderManager()->ResetProxyHosts();
392 // Manually call the observer methods for the root frame tree node.
393 RenderFrameHostManager
* root
= GetRenderManager();
395 if (root
->pending_frame_host())
396 root
->pending_frame_host()->SetRenderFrameCreated(false);
397 root
->current_frame_host()->SetRenderFrameCreated(false);
399 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
400 FrameDeleted(root
->current_frame_host()));
402 if (root
->pending_render_view_host()) {
403 FOR_EACH_OBSERVER(WebContentsObserver
,
405 RenderViewDeleted(root
->pending_render_view_host()));
408 FOR_EACH_OBSERVER(WebContentsObserver
,
410 RenderViewDeleted(root
->current_host()));
412 FOR_EACH_OBSERVER(WebContentsObserver
,
414 WebContentsDestroyed());
416 FOR_EACH_OBSERVER(WebContentsObserver
,
422 STLDeleteContainerPairSecondPointers(destruction_observers_
.begin(),
423 destruction_observers_
.end());
426 WebContentsImpl
* WebContentsImpl::CreateWithOpener(
427 const WebContents::CreateParams
& params
,
428 WebContentsImpl
* opener
) {
429 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
430 WebContentsImpl
* new_contents
= new WebContentsImpl(
431 params
.browser_context
, params
.opener_suppressed
? NULL
: opener
);
433 if (params
.guest_delegate
) {
434 // This makes |new_contents| act as a guest.
435 // For more info, see comment above class BrowserPluginGuest.
436 BrowserPluginGuest::Create(new_contents
, params
.guest_delegate
);
437 // We are instantiating a WebContents for browser plugin. Set its subframe
439 new_contents
->is_subframe_
= true;
441 new_contents
->Init(params
);
446 std::vector
<WebContentsImpl
*> WebContentsImpl::GetAllWebContents() {
447 std::vector
<WebContentsImpl
*> result
;
448 scoped_ptr
<RenderWidgetHostIterator
> widgets(
449 RenderWidgetHostImpl::GetRenderWidgetHosts());
450 std::set
<WebContentsImpl
*> web_contents_set
;
451 while (RenderWidgetHost
* rwh
= widgets
->GetNextHost()) {
452 if (!rwh
->IsRenderView())
454 RenderViewHost
* rvh
= RenderViewHost::From(rwh
);
457 WebContents
* web_contents
= WebContents::FromRenderViewHost(rvh
);
460 WebContentsImpl
* wci
= static_cast<WebContentsImpl
*>(web_contents
);
461 if (web_contents_set
.find(wci
) == web_contents_set
.end()) {
462 web_contents_set
.insert(wci
);
463 result
.push_back(wci
);
469 RenderFrameHostManager
* WebContentsImpl::GetRenderManagerForTesting() {
470 return GetRenderManager();
473 bool WebContentsImpl::OnMessageReceived(RenderViewHost
* render_view_host
,
474 const IPC::Message
& message
) {
475 return OnMessageReceived(render_view_host
, NULL
, message
);
478 bool WebContentsImpl::OnMessageReceived(RenderViewHost
* render_view_host
,
479 RenderFrameHost
* render_frame_host
,
480 const IPC::Message
& message
) {
481 DCHECK(render_view_host
|| render_frame_host
);
483 static_cast<WebUIImpl
*>(GetWebUI())->OnMessageReceived(message
)) {
487 ObserverListBase
<WebContentsObserver
>::Iterator
it(&observers_
);
488 WebContentsObserver
* observer
;
489 if (render_frame_host
) {
490 while ((observer
= it
.GetNext()) != NULL
)
491 if (observer
->OnMessageReceived(message
, render_frame_host
))
494 while ((observer
= it
.GetNext()) != NULL
)
495 if (observer
->OnMessageReceived(message
))
499 // Message handlers should be aware of which
500 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
501 // stored in render_(view|frame)_message_source_.
502 if (render_frame_host
)
503 render_frame_message_source_
= render_frame_host
;
505 render_view_message_source_
= render_view_host
;
508 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl
, message
)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse
,
510 OnDomOperationResponse
)
511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor
,
513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad
,
514 OnDocumentLoadedInFrame
)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad
, OnDidFinishLoad
)
516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading
, OnDidStartLoading
)
517 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading
, OnDidStopLoading
)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress
,
519 OnDidChangeLoadProgress
)
520 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser
, OnOpenColorChooser
)
521 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser
, OnEndColorChooser
)
522 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser
,
523 OnSetSelectedColorInColorChooser
)
524 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification
,
525 OnMediaPlayingNotification
)
526 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification
,
527 OnMediaPausedNotification
)
528 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint
,
529 OnFirstVisuallyNonEmptyPaint
)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache
,
531 OnDidLoadResourceFromMemoryCache
)
532 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent
,
533 OnDidDisplayInsecureContent
)
534 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent
,
535 OnDidRunInsecureContent
)
536 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset
, OnGoToEntryAtOffset
)
537 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits
, OnUpdateZoomLimits
)
538 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory
, OnEnumerateDirectory
)
539 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler
,
540 OnRegisterProtocolHandler
)
541 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler
,
542 OnUnregisterProtocolHandler
)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply
, OnFindReply
)
544 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed
, OnAppCacheAccessed
)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend
, OnWebUISend
)
546 #if defined(ENABLE_PLUGINS)
547 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung
, OnPepperPluginHung
)
548 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed
, OnPluginCrashed
)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission
,
550 OnRequestPpapiBrokerPermission
)
551 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach
,
552 OnBrowserPluginMessage(render_frame_host
,
555 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage
, OnDidDownloadImage
)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL
, OnUpdateFaviconURL
)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage
,
558 OnShowValidationMessage
)
559 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage
,
560 OnHideValidationMessage
)
561 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage
,
562 OnMoveValidationMessage
)
563 #if defined(OS_ANDROID)
564 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply
,
565 OnFindMatchRectsReply
)
566 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog
,
567 OnOpenDateTimeDialog
)
569 IPC_MESSAGE_UNHANDLED(handled
= false)
570 IPC_END_MESSAGE_MAP()
571 render_view_message_source_
= NULL
;
572 render_frame_message_source_
= NULL
;
577 bool WebContentsImpl::HasValidFrameSource() {
578 if (!render_frame_message_source_
) {
579 DCHECK(render_view_message_source_
);
580 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
581 bad_message::WC_INVALID_FRAME_SOURCE
);
588 void WebContentsImpl::RunFileChooser(
589 RenderViewHost
* render_view_host
,
590 const FileChooserParams
& params
) {
592 delegate_
->RunFileChooser(this, params
);
595 NavigationControllerImpl
& WebContentsImpl::GetController() {
599 const NavigationControllerImpl
& WebContentsImpl::GetController() const {
603 BrowserContext
* WebContentsImpl::GetBrowserContext() const {
604 return controller_
.GetBrowserContext();
607 const GURL
& WebContentsImpl::GetURL() const {
608 // We may not have a navigation entry yet.
609 NavigationEntry
* entry
= controller_
.GetVisibleEntry();
610 return entry
? entry
->GetVirtualURL() : GURL::EmptyGURL();
613 const GURL
& WebContentsImpl::GetVisibleURL() const {
614 // We may not have a navigation entry yet.
615 NavigationEntry
* entry
= controller_
.GetVisibleEntry();
616 return entry
? entry
->GetVirtualURL() : GURL::EmptyGURL();
619 const GURL
& WebContentsImpl::GetLastCommittedURL() const {
620 // We may not have a navigation entry yet.
621 NavigationEntry
* entry
= controller_
.GetLastCommittedEntry();
622 return entry
? entry
->GetVirtualURL() : GURL::EmptyGURL();
625 WebContentsDelegate
* WebContentsImpl::GetDelegate() {
629 void WebContentsImpl::SetDelegate(WebContentsDelegate
* delegate
) {
630 // TODO(cbentzel): remove this debugging code?
631 if (delegate
== delegate_
)
634 delegate_
->Detach(this);
635 delegate_
= delegate
;
637 delegate_
->Attach(this);
638 // Ensure the visible RVH reflects the new delegate's preferences.
640 view_
->SetOverscrollControllerEnabled(CanOverscrollContent());
644 RenderProcessHost
* WebContentsImpl::GetRenderProcessHost() const {
645 RenderViewHostImpl
* host
= GetRenderManager()->current_host();
646 return host
? host
->GetProcess() : NULL
;
649 RenderFrameHostImpl
* WebContentsImpl::GetMainFrame() {
650 return frame_tree_
.root()->current_frame_host();
653 RenderFrameHost
* WebContentsImpl::GetFocusedFrame() {
654 if (!frame_tree_
.GetFocusedFrame())
656 return frame_tree_
.GetFocusedFrame()->current_frame_host();
659 void WebContentsImpl::ForEachFrame(
660 const base::Callback
<void(RenderFrameHost
*)>& on_frame
) {
661 frame_tree_
.ForEach(base::Bind(&ForEachFrameInternal
, on_frame
));
664 void WebContentsImpl::SendToAllFrames(IPC::Message
* message
) {
665 ForEachFrame(base::Bind(&SendToAllFramesInternal
, message
));
669 RenderViewHost
* WebContentsImpl::GetRenderViewHost() const {
670 return GetRenderManager()->current_host();
673 int WebContentsImpl::GetRoutingID() const {
674 if (!GetRenderViewHost())
675 return MSG_ROUTING_NONE
;
677 return GetRenderViewHost()->GetRoutingID();
680 int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
681 return fullscreen_widget_routing_id_
;
684 RenderWidgetHostView
* WebContentsImpl::GetRenderWidgetHostView() const {
685 return GetRenderManager()->GetRenderWidgetHostView();
688 RenderWidgetHostView
* WebContentsImpl::GetFullscreenRenderWidgetHostView()
690 RenderWidgetHost
* const widget_host
=
691 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
692 GetFullscreenWidgetRoutingID());
693 return widget_host
? widget_host
->GetView() : NULL
;
696 WebContentsView
* WebContentsImpl::GetView() const {
700 SkColor
WebContentsImpl::GetThemeColor() const {
704 void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode
) {
705 if (mode
== accessibility_mode_
)
708 accessibility_mode_
= mode
;
710 base::Bind(&ForEachFrameInternal
,
711 base::Bind(&SetAccessibilityModeOnFrame
, mode
)));
713 base::Bind(&ForEachPendingFrameInternal
,
714 base::Bind(&SetAccessibilityModeOnFrame
, mode
)));
717 void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode
) {
718 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_
, mode
));
721 void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode
) {
722 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_
, mode
));
725 void WebContentsImpl::ClearNavigationTransitionData() {
726 FrameTreeNode
* node
= frame_tree_
.root();
727 node
->render_manager()->ClearNavigationTransitionData();
730 WebUI
* WebContentsImpl::CreateWebUI(const GURL
& url
) {
731 WebUIImpl
* web_ui
= new WebUIImpl(this);
732 WebUIController
* controller
= WebUIControllerFactoryRegistry::GetInstance()->
733 CreateWebUIControllerForURL(web_ui
, url
);
735 web_ui
->AddMessageHandler(new GenericHandler());
736 web_ui
->SetController(controller
);
744 WebUI
* WebContentsImpl::GetWebUI() const {
745 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
746 : GetRenderManager()->pending_web_ui();
749 WebUI
* WebContentsImpl::GetCommittedWebUI() const {
750 return GetRenderManager()->web_ui();
753 void WebContentsImpl::SetUserAgentOverride(const std::string
& override
) {
754 if (GetUserAgentOverride() == override
)
757 renderer_preferences_
.user_agent_override
= override
;
759 // Send the new override string to the renderer.
760 RenderViewHost
* host
= GetRenderViewHost();
762 host
->SyncRendererPrefs();
764 // Reload the page if a load is currently in progress to avoid having
765 // different parts of the page loaded using different user agents.
766 NavigationEntry
* entry
= controller_
.GetVisibleEntry();
767 if (is_loading_
&& entry
!= NULL
&& entry
->GetIsOverridingUserAgent())
768 controller_
.ReloadIgnoringCache(true);
770 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
771 UserAgentOverrideSet(override
));
774 const std::string
& WebContentsImpl::GetUserAgentOverride() const {
775 return renderer_preferences_
.user_agent_override
;
778 void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
779 AddAccessibilityMode(AccessibilityModeTreeOnly
);
782 bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
783 return accessibility_mode_
== AccessibilityModeTreeOnly
;
786 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
787 return accessibility_mode_
== AccessibilityModeComplete
;
791 void WebContentsImpl::SetParentNativeViewAccessible(
792 gfx::NativeViewAccessible accessible_parent
) {
793 accessible_parent_
= accessible_parent
;
794 RenderFrameHostImpl
* rfh
= static_cast<RenderFrameHostImpl
*>(GetMainFrame());
796 rfh
->SetParentNativeViewAccessible(accessible_parent
);
800 const base::string16
& WebContentsImpl::GetTitle() const {
801 // Transient entries take precedence. They are used for interstitial pages
802 // that are shown on top of existing pages.
803 NavigationEntry
* entry
= controller_
.GetTransientEntry();
804 std::string accept_languages
=
805 GetContentClient()->browser()->GetAcceptLangs(
806 GetBrowserContext());
808 return entry
->GetTitleForDisplay(accept_languages
);
810 WebUI
* our_web_ui
= GetRenderManager()->pending_web_ui() ?
811 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
813 // Don't override the title in view source mode.
814 entry
= controller_
.GetVisibleEntry();
815 if (!(entry
&& entry
->IsViewSourceMode())) {
816 // Give the Web UI the chance to override our title.
817 const base::string16
& title
= our_web_ui
->GetOverriddenTitle();
823 // We use the title for the last committed entry rather than a pending
824 // navigation entry. For example, when the user types in a URL, we want to
825 // keep the old page's title until the new load has committed and we get a new
827 entry
= controller_
.GetLastCommittedEntry();
829 // We make an exception for initial navigations.
830 if (controller_
.IsInitialNavigation()) {
831 // We only want to use the title from the visible entry in one of two cases:
832 // 1. There's already a committed entry for an initial navigation, in which
833 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
834 // 2. The pending entry has been explicitly assigned a title to display.
836 // If there's no last committed entry and no assigned title, we should fall
837 // back to |page_title_when_no_navigation_entry_| rather than showing the
840 (controller_
.GetVisibleEntry() &&
841 !controller_
.GetVisibleEntry()->GetTitle().empty())) {
842 entry
= controller_
.GetVisibleEntry();
847 return entry
->GetTitleForDisplay(accept_languages
);
850 // |page_title_when_no_navigation_entry_| is finally used
851 // if no title cannot be retrieved.
852 return page_title_when_no_navigation_entry_
;
855 int32
WebContentsImpl::GetMaxPageID() {
856 return GetMaxPageIDForSiteInstance(GetSiteInstance());
859 int32
WebContentsImpl::GetMaxPageIDForSiteInstance(
860 SiteInstance
* site_instance
) {
861 if (max_page_ids_
.find(site_instance
->GetId()) == max_page_ids_
.end())
862 max_page_ids_
[site_instance
->GetId()] = -1;
864 return max_page_ids_
[site_instance
->GetId()];
867 void WebContentsImpl::UpdateMaxPageID(int32 page_id
) {
868 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id
);
871 void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
872 SiteInstance
* site_instance
, int32 page_id
) {
873 if (GetMaxPageIDForSiteInstance(site_instance
) < page_id
)
874 max_page_ids_
[site_instance
->GetId()] = page_id
;
877 void WebContentsImpl::CopyMaxPageIDsFrom(WebContents
* web_contents
) {
878 WebContentsImpl
* contents
= static_cast<WebContentsImpl
*>(web_contents
);
879 max_page_ids_
= contents
->max_page_ids_
;
882 SiteInstanceImpl
* WebContentsImpl::GetSiteInstance() const {
883 return GetRenderManager()->current_host()->GetSiteInstance();
886 SiteInstanceImpl
* WebContentsImpl::GetPendingSiteInstance() const {
887 RenderViewHostImpl
* dest_rvh
=
888 GetRenderManager()->pending_render_view_host() ?
889 GetRenderManager()->pending_render_view_host() :
890 GetRenderManager()->current_host();
891 return dest_rvh
->GetSiteInstance();
894 bool WebContentsImpl::IsLoading() const {
898 bool WebContentsImpl::IsLoadingToDifferentDocument() const {
899 return is_loading_
&& is_load_to_different_document_
;
902 bool WebContentsImpl::IsWaitingForResponse() const {
903 return waiting_for_response_
&& is_load_to_different_document_
;
906 const net::LoadStateWithParam
& WebContentsImpl::GetLoadState() const {
910 const base::string16
& WebContentsImpl::GetLoadStateHost() const {
911 return load_state_host_
;
914 uint64
WebContentsImpl::GetUploadSize() const {
918 uint64
WebContentsImpl::GetUploadPosition() const {
919 return upload_position_
;
922 std::set
<GURL
> WebContentsImpl::GetSitesInTab() const {
923 std::set
<GURL
> sites
;
924 frame_tree_
.ForEach(base::Bind(&CollectSites
,
925 base::Unretained(GetBrowserContext()),
926 base::Unretained(&sites
)));
930 const std::string
& WebContentsImpl::GetEncoding() const {
931 return canonical_encoding_
;
934 bool WebContentsImpl::DisplayedInsecureContent() const {
935 return displayed_insecure_content_
;
938 void WebContentsImpl::IncrementCapturerCount(const gfx::Size
& capture_size
) {
939 DCHECK(!is_being_destroyed_
);
941 DVLOG(1) << "There are now " << capturer_count_
942 << " capturing(s) of WebContentsImpl@" << this;
944 // Note: This provides a hint to upstream code to size the views optimally
945 // for quality (e.g., to avoid scaling).
946 if (!capture_size
.IsEmpty() && preferred_size_for_capture_
.IsEmpty()) {
947 preferred_size_for_capture_
= capture_size
;
948 OnPreferredSizeChanged(preferred_size_
);
951 // Ensure that all views are un-occluded before capture begins.
955 void WebContentsImpl::DecrementCapturerCount() {
957 DVLOG(1) << "There are now " << capturer_count_
958 << " capturing(s) of WebContentsImpl@" << this;
959 DCHECK_LE(0, capturer_count_
);
961 if (is_being_destroyed_
)
964 if (capturer_count_
== 0) {
965 const gfx::Size old_size
= preferred_size_for_capture_
;
966 preferred_size_for_capture_
= gfx::Size();
967 OnPreferredSizeChanged(old_size
);
971 DVLOG(1) << "Executing delayed WasHidden().";
976 int WebContentsImpl::GetCapturerCount() const {
977 return capturer_count_
;
980 bool WebContentsImpl::IsAudioMuted() const {
981 return audio_muter_
.get() && audio_muter_
->is_muting();
984 void WebContentsImpl::SetAudioMuted(bool mute
) {
985 DVLOG(1) << "SetAudioMuted(mute=" << mute
<< "), was " << IsAudioMuted()
986 << " for WebContentsImpl@" << this;
988 if (mute
== IsAudioMuted())
993 audio_muter_
.reset(new WebContentsAudioMuter(this));
994 audio_muter_
->StartMuting();
996 DCHECK(audio_muter_
);
997 audio_muter_
->StopMuting();
1000 // Notification for UI updates in response to the changed muting state.
1001 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB
);
1004 bool WebContentsImpl::IsCrashed() const {
1005 return (crashed_status_
== base::TERMINATION_STATUS_PROCESS_CRASHED
||
1006 crashed_status_
== base::TERMINATION_STATUS_ABNORMAL_TERMINATION
||
1007 crashed_status_
== base::TERMINATION_STATUS_PROCESS_WAS_KILLED
);
1010 void WebContentsImpl::SetIsCrashed(base::TerminationStatus status
,
1012 if (status
== crashed_status_
)
1015 crashed_status_
= status
;
1016 crashed_error_code_
= error_code
;
1017 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB
);
1020 base::TerminationStatus
WebContentsImpl::GetCrashedStatus() const {
1021 return crashed_status_
;
1024 bool WebContentsImpl::IsBeingDestroyed() const {
1025 return is_being_destroyed_
;
1028 void WebContentsImpl::NotifyNavigationStateChanged(
1029 InvalidateTypes changed_flags
) {
1030 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1032 tracked_objects::ScopedTracker
tracking_profile(
1033 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1034 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
1035 // Create and release the audio power save blocker depending on whether the
1036 // tab is actively producing audio or not.
1037 if ((changed_flags
& INVALIDATE_TYPE_TAB
) &&
1038 audio_state_provider_
->IsAudioStateAvailable()) {
1039 if (WasRecentlyAudible()) {
1040 if (!audio_power_save_blocker_
)
1041 CreateAudioPowerSaveBlocker();
1043 audio_power_save_blocker_
.reset();
1048 delegate_
->NavigationStateChanged(this, changed_flags
);
1051 base::TimeTicks
WebContentsImpl::GetLastActiveTime() const {
1052 return last_active_time_
;
1055 void WebContentsImpl::WasShown() {
1056 controller_
.SetActive(true);
1058 for (RenderWidgetHostView
* view
: GetRenderWidgetHostViewsInTree()) {
1061 #if defined(OS_MACOSX)
1062 view
->SetActive(true);
1067 last_active_time_
= base::TimeTicks::Now();
1069 // The resize rect might have changed while this was inactive -- send the new
1070 // one to make sure it's up to date.
1071 RenderViewHostImpl
* rvh
=
1072 static_cast<RenderViewHostImpl
*>(GetRenderViewHost());
1074 rvh
->ResizeRectChanged(GetRootWindowResizerRect());
1077 // Restore power save blocker if there are active video players running.
1078 if (!active_video_players_
.empty() && !video_power_save_blocker_
)
1079 CreateVideoPowerSaveBlocker();
1081 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, WasShown());
1083 should_normally_be_visible_
= true;
1086 void WebContentsImpl::WasHidden() {
1087 // If there are entities capturing screenshots or video (e.g., mirroring),
1088 // don't activate the "disable rendering" optimization.
1089 if (capturer_count_
== 0) {
1090 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1091 // open a tab in the background, then closes the tab before selecting it.
1092 // This is because closing the tab calls WebContentsImpl::Destroy(), which
1093 // removes the |GetRenderViewHost()|; then when we actually destroy the
1094 // window, OnWindowPosChanged() notices and calls WasHidden() (which
1096 for (RenderWidgetHostView
* view
: GetRenderWidgetHostViewsInTree()) {
1101 // Release any video power save blockers held as video is not visible.
1102 video_power_save_blocker_
.reset();
1105 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, WasHidden());
1107 should_normally_be_visible_
= false;
1110 void WebContentsImpl::WasOccluded() {
1111 if (capturer_count_
> 0)
1114 for (RenderWidgetHostView
* view
: GetRenderWidgetHostViewsInTree()) {
1116 view
->WasOccluded();
1120 void WebContentsImpl::WasUnOccluded() {
1121 for (RenderWidgetHostView
* view
: GetRenderWidgetHostViewsInTree()) {
1123 view
->WasUnOccluded();
1127 bool WebContentsImpl::NeedToFireBeforeUnload() {
1128 // TODO(creis): Should we fire even for interstitial pages?
1129 return WillNotifyDisconnection() &&
1130 !ShowingInterstitialPage() &&
1131 !static_cast<RenderViewHostImpl
*>(
1132 GetRenderViewHost())->SuddenTerminationAllowed();
1135 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition
) {
1136 static_cast<RenderFrameHostImpl
*>(GetMainFrame())->DispatchBeforeUnload(
1137 for_cross_site_transition
);
1140 void WebContentsImpl::Stop() {
1141 GetRenderManager()->Stop();
1142 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, NavigationStopped());
1145 WebContents
* WebContentsImpl::Clone() {
1146 // We use our current SiteInstance since the cloned entry will use it anyway.
1147 // We pass our own opener so that the cloned page can access it if it was
1149 CreateParams
create_params(GetBrowserContext(), GetSiteInstance());
1150 create_params
.initial_size
= GetContainerBounds().size();
1151 WebContentsImpl
* tc
= CreateWithOpener(create_params
, opener_
);
1152 tc
->GetController().CopyStateFrom(controller_
);
1153 FOR_EACH_OBSERVER(WebContentsObserver
,
1155 DidCloneToNewWebContents(this, tc
));
1159 void WebContentsImpl::Observe(int type
,
1160 const NotificationSource
& source
,
1161 const NotificationDetails
& details
) {
1163 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
: {
1164 RenderWidgetHost
* host
= Source
<RenderWidgetHost
>(source
).ptr();
1165 RenderWidgetHostView
* view
= host
->GetView();
1166 if (view
== GetFullscreenRenderWidgetHostView()) {
1167 // We cannot just call view_->RestoreFocus() here. On some platforms,
1168 // attempting to focus the currently-invisible WebContentsView will be
1169 // flat-out ignored. Therefore, this boolean is used to track whether
1170 // we will request focus after the fullscreen widget has been
1172 fullscreen_widget_had_focus_at_shutdown_
= (view
&& view
->HasFocus());
1174 for (PendingWidgetViews::iterator i
= pending_widget_views_
.begin();
1175 i
!= pending_widget_views_
.end(); ++i
) {
1176 if (host
->GetView() == i
->second
) {
1177 pending_widget_views_
.erase(i
);
1189 WebContents
* WebContentsImpl::GetWebContents() {
1193 void WebContentsImpl::Init(const WebContents::CreateParams
& params
) {
1194 // This is set before initializing the render manager since
1195 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
1196 // it should be hidden.
1197 should_normally_be_visible_
= !params
.initially_hidden
;
1199 // Either both routing ids can be given, or neither can be.
1200 DCHECK((params
.routing_id
== MSG_ROUTING_NONE
&&
1201 params
.main_frame_routing_id
== MSG_ROUTING_NONE
) ||
1202 (params
.routing_id
!= MSG_ROUTING_NONE
&&
1203 params
.main_frame_routing_id
!= MSG_ROUTING_NONE
));
1204 GetRenderManager()->Init(
1205 params
.browser_context
, params
.site_instance
, params
.routing_id
,
1206 params
.main_frame_routing_id
);
1208 WebContentsViewDelegate
* delegate
=
1209 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1211 if (browser_plugin_guest_
) {
1212 scoped_ptr
<WebContentsView
> platform_view(CreateWebContentsView(
1213 this, delegate
, &render_view_host_delegate_view_
));
1215 WebContentsViewGuest
* rv
= new WebContentsViewGuest(
1216 this, browser_plugin_guest_
.get(), platform_view
.Pass(),
1217 render_view_host_delegate_view_
);
1218 render_view_host_delegate_view_
= rv
;
1221 // Regular WebContentsView.
1222 view_
.reset(CreateWebContentsView(
1223 this, delegate
, &render_view_host_delegate_view_
));
1225 CHECK(render_view_host_delegate_view_
);
1228 gfx::Size initial_size
= params
.initial_size
;
1229 view_
->CreateView(initial_size
, params
.context
);
1231 // Listen for whether our opener gets destroyed.
1233 AddDestructionObserver(opener_
);
1235 #if defined(ENABLE_PLUGINS)
1236 plugin_content_origin_whitelist_
.reset(
1237 new PluginContentOriginWhitelist(this));
1240 registrar_
.Add(this,
1241 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
,
1242 NotificationService::AllBrowserContextsAndSources());
1244 screen_orientation_dispatcher_host_
.reset(
1245 new ScreenOrientationDispatcherHostImpl(this));
1247 manifest_manager_host_
.reset(new ManifestManagerHost(this));
1249 #if defined(OS_ANDROID)
1250 date_time_chooser_
.reset(new DateTimeChooserAndroid());
1253 // BrowserPluginGuest::Init needs to be called after this WebContents has
1254 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1255 if (browser_plugin_guest_
)
1256 browser_plugin_guest_
->Init();
1258 for (size_t i
= 0; i
< g_created_callbacks
.Get().size(); i
++)
1259 g_created_callbacks
.Get().at(i
).Run(this);
1261 // If the WebContents creation was renderer-initiated, it means that the
1262 // corresponding RenderView and main RenderFrame have already been created.
1263 // Ensure observers are notified about this.
1264 if (params
.renderer_initiated_creation
) {
1265 RenderViewCreated(GetRenderViewHost());
1266 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1269 // Ensure that observers are notified of the creation of this WebContents's
1270 // main RenderFrameHost. It must be done here for main frames, since the
1271 // NotifySwappedFromRenderManager expects view_ to already be created and that
1272 // happens after RenderFrameHostManager::Init.
1273 NotifySwappedFromRenderManager(
1274 nullptr, GetRenderManager()->current_frame_host(), true);
1277 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl
* web_contents
) {
1278 RemoveDestructionObserver(web_contents
);
1280 // Clear the opener if it has been closed.
1281 if (web_contents
== opener_
) {
1285 // Clear a pending contents that has been closed before being shown.
1286 for (PendingContents::iterator iter
= pending_contents_
.begin();
1287 iter
!= pending_contents_
.end();
1289 if (iter
->second
!= web_contents
)
1291 pending_contents_
.erase(iter
);
1297 void WebContentsImpl::AddDestructionObserver(WebContentsImpl
* web_contents
) {
1298 if (!ContainsKey(destruction_observers_
, web_contents
)) {
1299 destruction_observers_
[web_contents
] =
1300 new DestructionObserver(this, web_contents
);
1304 void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl
* web_contents
) {
1305 DestructionObservers::iterator iter
=
1306 destruction_observers_
.find(web_contents
);
1307 if (iter
!= destruction_observers_
.end()) {
1308 delete destruction_observers_
[web_contents
];
1309 destruction_observers_
.erase(iter
);
1313 void WebContentsImpl::AddObserver(WebContentsObserver
* observer
) {
1314 observers_
.AddObserver(observer
);
1317 void WebContentsImpl::RemoveObserver(WebContentsObserver
* observer
) {
1318 observers_
.RemoveObserver(observer
);
1321 std::set
<RenderWidgetHostView
*>
1322 WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1323 std::set
<RenderWidgetHostView
*> set
;
1324 if (ShowingInterstitialPage()) {
1325 set
.insert(GetRenderWidgetHostView());
1328 base::Bind(&AddRenderWidgetHostViewToSet
, base::Unretained(&set
)));
1333 void WebContentsImpl::Activate() {
1335 delegate_
->ActivateContents(this);
1338 void WebContentsImpl::Deactivate() {
1340 delegate_
->DeactivateContents(this);
1343 void WebContentsImpl::LostCapture() {
1345 delegate_
->LostCapture();
1348 void WebContentsImpl::RenderWidgetDeleted(
1349 RenderWidgetHostImpl
* render_widget_host
) {
1350 if (is_being_destroyed_
) {
1351 // |created_widgets_| might have been destroyed.
1355 std::set
<RenderWidgetHostImpl
*>::iterator iter
=
1356 created_widgets_
.find(render_widget_host
);
1357 if (iter
!= created_widgets_
.end())
1358 created_widgets_
.erase(iter
);
1360 if (render_widget_host
&&
1361 render_widget_host
->GetRoutingID() == fullscreen_widget_routing_id_
) {
1362 if (delegate_
&& delegate_
->EmbedsFullscreenWidget())
1363 delegate_
->ExitFullscreenModeForTab(this);
1364 FOR_EACH_OBSERVER(WebContentsObserver
,
1366 DidDestroyFullscreenWidget(
1367 fullscreen_widget_routing_id_
));
1368 fullscreen_widget_routing_id_
= MSG_ROUTING_NONE
;
1369 if (fullscreen_widget_had_focus_at_shutdown_
)
1370 view_
->RestoreFocus();
1374 void WebContentsImpl::RenderWidgetGotFocus(
1375 RenderWidgetHostImpl
* render_widget_host
) {
1376 // Notify the delegate if an embedded fullscreen widget was focused.
1377 if (delegate_
&& render_widget_host
&&
1378 delegate_
->EmbedsFullscreenWidget() &&
1379 render_widget_host
->GetView() == GetFullscreenRenderWidgetHostView())
1380 delegate_
->WebContentsFocused(this);
1383 void WebContentsImpl::RenderWidgetWasResized(
1384 RenderWidgetHostImpl
* render_widget_host
,
1385 bool width_changed
) {
1386 RenderFrameHostImpl
* rfh
= static_cast<RenderFrameHostImpl
*>(GetMainFrame());
1387 if (!rfh
|| render_widget_host
!= rfh
->GetRenderWidgetHost())
1390 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
1391 MainFrameWasResized(width_changed
));
1394 void WebContentsImpl::ScreenInfoChanged() {
1395 if (browser_plugin_embedder_
)
1396 browser_plugin_embedder_
->ScreenInfoChanged();
1399 bool WebContentsImpl::PreHandleKeyboardEvent(
1400 const NativeWebKeyboardEvent
& event
,
1401 bool* is_keyboard_shortcut
) {
1403 delegate_
->PreHandleKeyboardEvent(this, event
, is_keyboard_shortcut
);
1406 void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent
& event
) {
1407 if (browser_plugin_embedder_
&&
1408 browser_plugin_embedder_
->HandleKeyboardEvent(event
)) {
1412 delegate_
->HandleKeyboardEvent(this, event
);
1415 bool WebContentsImpl::HandleWheelEvent(
1416 const blink::WebMouseWheelEvent
& event
) {
1417 #if !defined(OS_MACOSX)
1418 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1419 // this isn't done for two reasons:
1420 // -the OS already has a gesture to do this through pinch-zoom
1421 // -if a user starts an inertial scroll, let's go, and presses control
1422 // (i.e. control+tab) then the OS's buffered scroll events will come in
1423 // with control key set which isn't what the user wants
1424 if (delegate_
&& event
.wheelTicksY
&&
1425 (event
.modifiers
& blink::WebInputEvent::ControlKey
) &&
1427 delegate_
->ContentsZoomChange(event
.wheelTicksY
> 0);
1434 bool WebContentsImpl::PreHandleGestureEvent(
1435 const blink::WebGestureEvent
& event
) {
1436 return delegate_
&& delegate_
->PreHandleGestureEvent(this, event
);
1439 void WebContentsImpl::EnterFullscreenMode(const GURL
& origin
) {
1440 // This method is being called to enter renderer-initiated fullscreen mode.
1441 // Make sure any existing fullscreen widget is shut down first.
1442 RenderWidgetHostView
* const widget_view
= GetFullscreenRenderWidgetHostView();
1444 RenderWidgetHostImpl::From(widget_view
->GetRenderWidgetHost())->Shutdown();
1447 delegate_
->EnterFullscreenModeForTab(this, origin
);
1449 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
1450 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1453 void WebContentsImpl::ExitFullscreenMode() {
1454 // This method is being called to leave renderer-initiated fullscreen mode.
1455 // Make sure any existing fullscreen widget is shut down first.
1456 RenderWidgetHostView
* const widget_view
= GetFullscreenRenderWidgetHostView();
1458 RenderWidgetHostImpl::From(widget_view
->GetRenderWidgetHost())->Shutdown();
1460 #if defined(OS_ANDROID)
1461 ContentVideoView
* video_view
= ContentVideoView::GetInstance();
1462 if (video_view
!= NULL
)
1463 video_view
->OnExitFullscreen();
1467 delegate_
->ExitFullscreenModeForTab(this);
1469 // Ensure web contents exit fullscreen state by sending a resize message,
1470 // which includes the fullscreen state. This is required for the situation
1471 // of the browser moving the view into a fullscreen state "browser fullscreen"
1472 // and then the contents entering "tab fullscreen". Exiting the contents
1473 // "tab fullscreen" then won't have the side effect of the view resizing,
1474 // hence the explicit call here is required.
1475 if (RenderWidgetHostView
* rwh_view
= GetRenderWidgetHostView()) {
1476 if (RenderWidgetHost
* render_widget_host
= rwh_view
->GetRenderWidgetHost())
1477 render_widget_host
->WasResized();
1480 FOR_EACH_OBSERVER(WebContentsObserver
,
1482 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1485 bool WebContentsImpl::IsFullscreenForCurrentTab() const {
1486 return delegate_
? delegate_
->IsFullscreenForTabOrPending(this) : false;
1489 void WebContentsImpl::RequestToLockMouse(bool user_gesture
,
1490 bool last_unlocked_by_target
) {
1492 delegate_
->RequestToLockMouse(this, user_gesture
, last_unlocked_by_target
);
1494 GotResponseToLockMouseRequest(false);
1498 void WebContentsImpl::LostMouseLock() {
1500 delegate_
->LostMouseLock();
1503 void WebContentsImpl::CreateNewWindow(
1504 int render_process_id
,
1506 int main_frame_route_id
,
1507 const ViewHostMsg_CreateWindow_Params
& params
,
1508 SessionStorageNamespace
* session_storage_namespace
) {
1509 // We usually create the new window in the same BrowsingInstance (group of
1510 // script-related windows), by passing in the current SiteInstance. However,
1511 // if the opener is being suppressed (in a non-guest), we create a new
1512 // SiteInstance in its own BrowsingInstance.
1513 bool is_guest
= BrowserPluginGuest::IsGuest(this);
1515 // If the opener is to be suppressed, the new window can be in any process.
1516 // Since routing ids are process specific, we must not have one passed in
1517 // as argument here.
1518 DCHECK(!params
.opener_suppressed
|| route_id
== MSG_ROUTING_NONE
);
1520 scoped_refptr
<SiteInstance
> site_instance
=
1521 params
.opener_suppressed
&& !is_guest
?
1522 SiteInstance::CreateForURL(GetBrowserContext(), params
.target_url
) :
1525 // A message to create a new window can only come from the active process for
1526 // this WebContentsImpl instance. If any other process sends the request,
1527 // it is invalid and the process must be terminated.
1528 if (GetRenderProcessHost()->GetID() != render_process_id
) {
1529 RenderProcessHost
* rph
= RenderProcessHost::FromID(render_process_id
);
1530 base::ProcessHandle process_handle
= rph
->GetHandle();
1531 if (process_handle
!= base::kNullProcessHandle
) {
1533 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1534 rph
->Shutdown(RESULT_CODE_KILLED
, false);
1539 // We must assign the SessionStorageNamespace before calling Init().
1541 // http://crbug.com/142685
1542 const std::string
& partition_id
=
1543 GetContentClient()->browser()->
1544 GetStoragePartitionIdForSite(GetBrowserContext(),
1545 site_instance
->GetSiteURL());
1546 StoragePartition
* partition
= BrowserContext::GetStoragePartition(
1547 GetBrowserContext(), site_instance
.get());
1548 DOMStorageContextWrapper
* dom_storage_context
=
1549 static_cast<DOMStorageContextWrapper
*>(partition
->GetDOMStorageContext());
1550 SessionStorageNamespaceImpl
* session_storage_namespace_impl
=
1551 static_cast<SessionStorageNamespaceImpl
*>(session_storage_namespace
);
1552 CHECK(session_storage_namespace_impl
->IsFromContext(dom_storage_context
));
1555 !delegate_
->ShouldCreateWebContents(this,
1557 main_frame_route_id
,
1558 params
.window_container_type
,
1562 session_storage_namespace
)) {
1563 if (route_id
!= MSG_ROUTING_NONE
&&
1564 !RenderViewHost::FromID(render_process_id
, route_id
)) {
1565 // If the embedder didn't create a WebContents for this route, we need to
1566 // delete the RenderView that had already been created.
1567 Send(new ViewMsg_Close(route_id
));
1569 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id
);
1570 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1571 main_frame_route_id
);
1575 // Create the new web contents. This will automatically create the new
1576 // WebContentsView. In the future, we may want to create the view separately.
1577 CreateParams
create_params(GetBrowserContext(), site_instance
.get());
1578 create_params
.routing_id
= route_id
;
1579 create_params
.main_frame_routing_id
= main_frame_route_id
;
1580 create_params
.opener
= this;
1581 create_params
.opener_suppressed
= params
.opener_suppressed
;
1582 if (params
.disposition
== NEW_BACKGROUND_TAB
)
1583 create_params
.initially_hidden
= true;
1584 create_params
.renderer_initiated_creation
= true;
1586 WebContentsImpl
* new_contents
= NULL
;
1588 create_params
.context
= view_
->GetNativeView();
1589 create_params
.initial_size
= GetContainerBounds().size();
1590 new_contents
= static_cast<WebContentsImpl
*>(
1591 WebContents::Create(create_params
));
1593 new_contents
= GetBrowserPluginGuest()->CreateNewGuestWindow(create_params
);
1595 new_contents
->GetController().SetSessionStorageNamespace(
1597 session_storage_namespace
);
1599 // Save the window for later if we're not suppressing the opener (since it
1600 // will be shown immediately).
1601 if (!params
.opener_suppressed
) {
1603 WebContentsView
* new_view
= new_contents
->view_
.get();
1605 // TODO(brettw): It seems bogus that we have to call this function on the
1606 // newly created object and give it one of its own member variables.
1607 new_view
->CreateViewForWidget(new_contents
->GetRenderViewHost(), false);
1609 // Save the created window associated with the route so we can show it
1611 DCHECK_NE(MSG_ROUTING_NONE
, route_id
);
1612 pending_contents_
[route_id
] = new_contents
;
1613 AddDestructionObserver(new_contents
);
1617 delegate_
->WebContentsCreated(
1618 this, params
.opener_render_frame_id
, params
.frame_name
,
1619 params
.target_url
, new_contents
);
1622 if (params
.opener_suppressed
) {
1623 // When the opener is suppressed, the original renderer cannot access the
1624 // new window. As a result, we need to show and navigate the window here.
1625 bool was_blocked
= false;
1627 gfx::Rect initial_rect
;
1628 delegate_
->AddNewContents(
1629 this, new_contents
, params
.disposition
, initial_rect
,
1630 params
.user_gesture
, &was_blocked
);
1633 OpenURLParams
open_params(params
.target_url
,
1636 ui::PAGE_TRANSITION_LINK
,
1637 true /* is_renderer_initiated */);
1638 open_params
.user_gesture
= params
.user_gesture
;
1639 new_contents
->OpenURL(open_params
);
1644 void WebContentsImpl::CreateNewWidget(int render_process_id
,
1646 blink::WebPopupType popup_type
) {
1647 CreateNewWidget(render_process_id
, route_id
, false, popup_type
);
1650 void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id
,
1652 CreateNewWidget(render_process_id
, route_id
, true, blink::WebPopupTypeNone
);
1655 void WebContentsImpl::CreateNewWidget(int render_process_id
,
1658 blink::WebPopupType popup_type
) {
1659 RenderProcessHost
* process
= GetRenderProcessHost();
1660 // A message to create a new widget can only come from the active process for
1661 // this WebContentsImpl instance. If any other process sends the request,
1662 // it is invalid and the process must be terminated.
1663 if (process
->GetID() != render_process_id
) {
1664 RenderProcessHost
* rph
= RenderProcessHost::FromID(render_process_id
);
1665 base::ProcessHandle process_handle
= rph
->GetHandle();
1666 if (process_handle
!= base::kNullProcessHandle
) {
1668 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1669 rph
->Shutdown(RESULT_CODE_KILLED
, false);
1674 RenderWidgetHostImpl
* widget_host
=
1675 new RenderWidgetHostImpl(this, process
, route_id
, IsHidden());
1676 created_widgets_
.insert(widget_host
);
1678 RenderWidgetHostViewBase
* widget_view
=
1679 static_cast<RenderWidgetHostViewBase
*>(
1680 view_
->CreateViewForPopupWidget(widget_host
));
1683 if (!is_fullscreen
) {
1684 // Popups should not get activated.
1685 widget_view
->SetPopupType(popup_type
);
1687 // Save the created widget associated with the route so we can show it later.
1688 pending_widget_views_
[route_id
] = widget_view
;
1690 #if defined(OS_MACOSX)
1691 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1692 // to allow it to survive the trip without being hosted.
1693 base::mac::NSObjectRetain(widget_view
->GetNativeView());
1697 void WebContentsImpl::ShowCreatedWindow(int route_id
,
1698 WindowOpenDisposition disposition
,
1699 const gfx::Rect
& initial_rect
,
1700 bool user_gesture
) {
1701 WebContentsImpl
* contents
= GetCreatedWindow(route_id
);
1703 WebContentsDelegate
* delegate
= GetDelegate();
1705 delegate
->AddNewContents(
1706 this, contents
, disposition
, initial_rect
, user_gesture
, NULL
);
1711 void WebContentsImpl::ShowCreatedWidget(int route_id
,
1712 const gfx::Rect
& initial_rect
) {
1713 ShowCreatedWidget(route_id
, false, initial_rect
);
1716 void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id
) {
1717 ShowCreatedWidget(route_id
, true, gfx::Rect());
1720 void WebContentsImpl::ShowCreatedWidget(int route_id
,
1722 const gfx::Rect
& initial_rect
) {
1723 RenderWidgetHostViewBase
* widget_host_view
=
1724 static_cast<RenderWidgetHostViewBase
*>(GetCreatedWidget(route_id
));
1725 if (!widget_host_view
)
1728 RenderWidgetHostView
* view
= NULL
;
1729 BrowserPluginGuest
* guest
= GetBrowserPluginGuest();
1730 if (guest
&& guest
->embedder_web_contents()) {
1731 view
= guest
->embedder_web_contents()->GetRenderWidgetHostView();
1733 view
= GetRenderWidgetHostView();
1736 if (is_fullscreen
) {
1737 DCHECK_EQ(MSG_ROUTING_NONE
, fullscreen_widget_routing_id_
);
1738 view_
->StoreFocus();
1739 fullscreen_widget_routing_id_
= route_id
;
1740 if (delegate_
&& delegate_
->EmbedsFullscreenWidget()) {
1741 widget_host_view
->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1742 delegate_
->EnterFullscreenModeForTab(this, GURL());
1744 widget_host_view
->InitAsFullscreen(view
);
1746 FOR_EACH_OBSERVER(WebContentsObserver
,
1748 DidShowFullscreenWidget(route_id
));
1749 if (!widget_host_view
->HasFocus())
1750 widget_host_view
->Focus();
1752 widget_host_view
->InitAsPopup(view
, initial_rect
);
1755 RenderWidgetHostImpl
* render_widget_host_impl
=
1756 RenderWidgetHostImpl::From(widget_host_view
->GetRenderWidgetHost());
1757 render_widget_host_impl
->Init();
1758 // Only allow privileged mouse lock for fullscreen render widget, which is
1759 // used to implement Pepper Flash fullscreen.
1760 render_widget_host_impl
->set_allow_privileged_mouse_lock(is_fullscreen
);
1762 #if defined(OS_MACOSX)
1763 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1764 // properly embedded (or purposefully ignored) we can release the retain we
1765 // took in CreateNewWidget().
1766 base::mac::NSObjectRelease(widget_host_view
->GetNativeView());
1770 WebContentsImpl
* WebContentsImpl::GetCreatedWindow(int route_id
) {
1771 PendingContents::iterator iter
= pending_contents_
.find(route_id
);
1773 // Certain systems can block the creation of new windows. If we didn't succeed
1774 // in creating one, just return NULL.
1775 if (iter
== pending_contents_
.end()) {
1779 WebContentsImpl
* new_contents
= iter
->second
;
1780 pending_contents_
.erase(route_id
);
1781 RemoveDestructionObserver(new_contents
);
1783 // Don't initialize the guest WebContents immediately.
1784 if (BrowserPluginGuest::IsGuest(new_contents
))
1785 return new_contents
;
1787 if (!new_contents
->GetRenderProcessHost()->HasConnection() ||
1788 !new_contents
->GetRenderViewHost()->GetView())
1791 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
1792 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1793 static_cast<RenderViewHostImpl
*>(new_contents
->GetRenderViewHost())->Init();
1794 static_cast<RenderFrameHostImpl
*>(new_contents
->GetMainFrame())->Init();
1796 return new_contents
;
1799 RenderWidgetHostView
* WebContentsImpl::GetCreatedWidget(int route_id
) {
1800 PendingWidgetViews::iterator iter
= pending_widget_views_
.find(route_id
);
1801 if (iter
== pending_widget_views_
.end()) {
1806 RenderWidgetHostView
* widget_host_view
= iter
->second
;
1807 pending_widget_views_
.erase(route_id
);
1809 RenderWidgetHost
* widget_host
= widget_host_view
->GetRenderWidgetHost();
1810 if (!widget_host
->GetProcess()->HasConnection()) {
1811 // The view has gone away or the renderer crashed. Nothing to do.
1815 return widget_host_view
;
1818 void WebContentsImpl::RequestMediaAccessPermission(
1819 const MediaStreamRequest
& request
,
1820 const MediaResponseCallback
& callback
) {
1822 delegate_
->RequestMediaAccessPermission(this, request
, callback
);
1824 callback
.Run(MediaStreamDevices(),
1825 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN
,
1826 scoped_ptr
<MediaStreamUI
>());
1830 bool WebContentsImpl::CheckMediaAccessPermission(const GURL
& security_origin
,
1831 MediaStreamType type
) {
1832 DCHECK(type
== MEDIA_DEVICE_AUDIO_CAPTURE
||
1833 type
== MEDIA_DEVICE_VIDEO_CAPTURE
);
1835 delegate_
->CheckMediaAccessPermission(this, security_origin
, type
);
1838 SessionStorageNamespace
* WebContentsImpl::GetSessionStorageNamespace(
1839 SiteInstance
* instance
) {
1840 return controller_
.GetSessionStorageNamespace(instance
);
1843 SessionStorageNamespaceMap
WebContentsImpl::GetSessionStorageNamespaceMap() {
1844 return controller_
.GetSessionStorageNamespaceMap();
1847 FrameTree
* WebContentsImpl::GetFrameTree() {
1848 return &frame_tree_
;
1851 void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested
) {
1852 virtual_keyboard_requested_
= requested
;
1855 bool WebContentsImpl::IsVirtualKeyboardRequested() {
1856 return virtual_keyboard_requested_
;
1859 AccessibilityMode
WebContentsImpl::GetAccessibilityMode() const {
1860 return accessibility_mode_
;
1863 void WebContentsImpl::AccessibilityEventReceived(
1864 const std::vector
<AXEventNotificationDetails
>& details
) {
1866 WebContentsObserver
, observers_
, AccessibilityEventReceived(details
));
1869 RenderFrameHost
* WebContentsImpl::GetGuestByInstanceID(
1870 RenderFrameHost
* render_frame_host
,
1871 int browser_plugin_instance_id
) {
1872 BrowserPluginGuestManager
* guest_manager
=
1873 GetBrowserContext()->GetGuestManager();
1874 WebContents
* guest
= guest_manager
->GetGuestByInstanceID(
1875 render_frame_host
->GetProcess()->GetID(), browser_plugin_instance_id
);
1878 return guest
->GetMainFrame();
1881 GeolocationServiceContext
* WebContentsImpl::GetGeolocationServiceContext() {
1882 return geolocation_service_context_
.get();
1885 void WebContentsImpl::OnShowValidationMessage(
1886 const gfx::Rect
& anchor_in_root_view
,
1887 const base::string16
& main_text
,
1888 const base::string16
& sub_text
) {
1890 delegate_
->ShowValidationMessage(
1891 this, anchor_in_root_view
, main_text
, sub_text
);
1894 void WebContentsImpl::OnHideValidationMessage() {
1896 delegate_
->HideValidationMessage(this);
1899 void WebContentsImpl::OnMoveValidationMessage(
1900 const gfx::Rect
& anchor_in_root_view
) {
1902 delegate_
->MoveValidationMessage(this, anchor_in_root_view
);
1905 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl
* rwh
) {
1906 if (browser_plugin_embedder_
)
1907 browser_plugin_embedder_
->DidSendScreenRects();
1910 BrowserAccessibilityManager
*
1911 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1912 RenderFrameHostImpl
* rfh
= static_cast<RenderFrameHostImpl
*>(GetMainFrame());
1913 return rfh
? rfh
->browser_accessibility_manager() : NULL
;
1916 BrowserAccessibilityManager
*
1917 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1918 RenderFrameHostImpl
* rfh
= static_cast<RenderFrameHostImpl
*>(GetMainFrame());
1919 return rfh
? rfh
->GetOrCreateBrowserAccessibilityManager() : NULL
;
1922 void WebContentsImpl::UpdatePreferredSize(const gfx::Size
& pref_size
) {
1923 const gfx::Size old_size
= GetPreferredSize();
1924 preferred_size_
= pref_size
;
1925 OnPreferredSizeChanged(old_size
);
1928 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size
& new_size
) {
1930 delegate_
->ResizeDueToAutoResize(this, new_size
);
1933 WebContents
* WebContentsImpl::OpenURL(const OpenURLParams
& params
) {
1937 WebContents
* new_contents
= delegate_
->OpenURLFromTab(this, params
);
1938 return new_contents
;
1941 bool WebContentsImpl::Send(IPC::Message
* message
) {
1942 if (!GetRenderViewHost()) {
1947 return GetRenderViewHost()->Send(message
);
1950 bool WebContentsImpl::NavigateToPendingEntry(
1951 NavigationController::ReloadType reload_type
) {
1952 FrameTreeNode
* node
= frame_tree_
.root();
1954 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1955 // is currently only used in --site-per-process and tests.
1956 // TODO(creis): Remove this method and NavigationEntryImpl::frame_tree_node_id
1957 // by using FrameNavigationEntries instead. See https://crbug.com/236848.
1958 NavigationEntryImpl
* pending_entry
= controller_
.GetPendingEntry();
1959 if (pending_entry
->frame_tree_node_id() != -1) {
1960 FrameTreeNode
* subframe
=
1961 frame_tree_
.FindByID(pending_entry
->frame_tree_node_id());
1967 return node
->navigator()->NavigateToPendingEntry(node
, reload_type
);
1970 void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1971 RenderFrameHost
* render_frame_host
) {
1972 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
1973 RenderFrameForInterstitialPageCreated(render_frame_host
));
1976 void WebContentsImpl::AttachInterstitialPage(
1977 InterstitialPageImpl
* interstitial_page
) {
1978 DCHECK(interstitial_page
);
1979 GetRenderManager()->set_interstitial_page(interstitial_page
);
1981 // Cancel any visible dialogs so that they don't interfere with the
1983 if (dialog_manager_
)
1984 dialog_manager_
->CancelActiveAndPendingDialogs(this);
1986 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
1987 DidAttachInterstitialPage());
1990 void WebContentsImpl::DetachInterstitialPage() {
1991 if (ShowingInterstitialPage())
1992 GetRenderManager()->remove_interstitial_page();
1993 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
1994 DidDetachInterstitialPage());
1997 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset
,
1998 int history_length
) {
1999 SetHistoryOffsetAndLengthForView(
2000 GetRenderViewHost(), history_offset
, history_length
);
2003 void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2004 RenderViewHost
* render_view_host
,
2006 int history_length
) {
2007 render_view_host
->Send(new ViewMsg_SetHistoryOffsetAndLength(
2008 render_view_host
->GetRoutingID(), history_offset
, history_length
));
2011 void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache
) {
2012 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2016 focused_frame
->Send(new FrameMsg_Reload(
2017 focused_frame
->GetRoutingID(), ignore_cache
));
2020 void WebContentsImpl::Undo() {
2021 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2025 focused_frame
->Send(new InputMsg_Undo(focused_frame
->GetRoutingID()));
2026 RecordAction(base::UserMetricsAction("Undo"));
2029 void WebContentsImpl::Redo() {
2030 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2033 focused_frame
->Send(new InputMsg_Redo(focused_frame
->GetRoutingID()));
2034 RecordAction(base::UserMetricsAction("Redo"));
2037 void WebContentsImpl::Cut() {
2038 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2042 focused_frame
->Send(new InputMsg_Cut(focused_frame
->GetRoutingID()));
2043 RecordAction(base::UserMetricsAction("Cut"));
2046 void WebContentsImpl::Copy() {
2047 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2051 focused_frame
->Send(new InputMsg_Copy(focused_frame
->GetRoutingID()));
2052 RecordAction(base::UserMetricsAction("Copy"));
2055 void WebContentsImpl::CopyToFindPboard() {
2056 #if defined(OS_MACOSX)
2057 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2061 // Windows/Linux don't have the concept of a find pasteboard.
2062 focused_frame
->Send(
2063 new InputMsg_CopyToFindPboard(focused_frame
->GetRoutingID()));
2064 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2068 void WebContentsImpl::Paste() {
2069 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2073 focused_frame
->Send(new InputMsg_Paste(focused_frame
->GetRoutingID()));
2074 RecordAction(base::UserMetricsAction("Paste"));
2077 void WebContentsImpl::PasteAndMatchStyle() {
2078 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2082 focused_frame
->Send(new InputMsg_PasteAndMatchStyle(
2083 focused_frame
->GetRoutingID()));
2084 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2087 void WebContentsImpl::Delete() {
2088 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2092 focused_frame
->Send(new InputMsg_Delete(focused_frame
->GetRoutingID()));
2093 RecordAction(base::UserMetricsAction("DeleteSelection"));
2096 void WebContentsImpl::SelectAll() {
2097 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2101 focused_frame
->Send(new InputMsg_SelectAll(focused_frame
->GetRoutingID()));
2102 RecordAction(base::UserMetricsAction("SelectAll"));
2105 void WebContentsImpl::Unselect() {
2106 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2110 focused_frame
->Send(new InputMsg_Unselect(focused_frame
->GetRoutingID()));
2111 RecordAction(base::UserMetricsAction("Unselect"));
2114 void WebContentsImpl::Replace(const base::string16
& word
) {
2115 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2119 focused_frame
->Send(new InputMsg_Replace(
2120 focused_frame
->GetRoutingID(), word
));
2123 void WebContentsImpl::ReplaceMisspelling(const base::string16
& word
) {
2124 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2128 focused_frame
->Send(new InputMsg_ReplaceMisspelling(
2129 focused_frame
->GetRoutingID(), word
));
2132 void WebContentsImpl::NotifyContextMenuClosed(
2133 const CustomContextMenuContext
& context
) {
2134 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2138 focused_frame
->Send(new FrameMsg_ContextMenuClosed(
2139 focused_frame
->GetRoutingID(), context
));
2142 void WebContentsImpl::ExecuteCustomContextMenuCommand(
2143 int action
, const CustomContextMenuContext
& context
) {
2144 RenderFrameHost
* focused_frame
= GetFocusedFrame();
2148 focused_frame
->Send(new FrameMsg_CustomContextMenuAction(
2149 focused_frame
->GetRoutingID(), context
, action
));
2152 gfx::NativeView
WebContentsImpl::GetNativeView() {
2153 return view_
->GetNativeView();
2156 gfx::NativeView
WebContentsImpl::GetContentNativeView() {
2157 return view_
->GetContentNativeView();
2160 gfx::NativeWindow
WebContentsImpl::GetTopLevelNativeWindow() {
2161 return view_
->GetTopLevelNativeWindow();
2164 gfx::Rect
WebContentsImpl::GetViewBounds() {
2165 return view_
->GetViewBounds();
2168 gfx::Rect
WebContentsImpl::GetContainerBounds() {
2170 view_
->GetContainerBounds(&rv
);
2174 DropData
* WebContentsImpl::GetDropData() {
2175 return view_
->GetDropData();
2178 void WebContentsImpl::Focus() {
2182 void WebContentsImpl::SetInitialFocus() {
2183 view_
->SetInitialFocus();
2186 void WebContentsImpl::StoreFocus() {
2187 view_
->StoreFocus();
2190 void WebContentsImpl::RestoreFocus() {
2191 view_
->RestoreFocus();
2194 void WebContentsImpl::FocusThroughTabTraversal(bool reverse
) {
2195 if (ShowingInterstitialPage()) {
2196 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse
);
2199 RenderWidgetHostView
* const fullscreen_view
=
2200 GetFullscreenRenderWidgetHostView();
2201 if (fullscreen_view
) {
2202 fullscreen_view
->Focus();
2205 GetRenderViewHostImpl()->SetInitialFocus(reverse
);
2208 bool WebContentsImpl::ShowingInterstitialPage() const {
2209 return GetRenderManager()->interstitial_page() != NULL
;
2212 InterstitialPage
* WebContentsImpl::GetInterstitialPage() const {
2213 return GetRenderManager()->interstitial_page();
2216 bool WebContentsImpl::IsSavable() {
2217 // WebKit creates Document object when MIME type is application/xhtml+xml,
2218 // so we also support this MIME type.
2219 return contents_mime_type_
== "text/html" ||
2220 contents_mime_type_
== "text/xml" ||
2221 contents_mime_type_
== "application/xhtml+xml" ||
2222 contents_mime_type_
== "text/plain" ||
2223 contents_mime_type_
== "text/css" ||
2224 net::IsSupportedJavascriptMimeType(contents_mime_type_
.c_str());
2227 void WebContentsImpl::OnSavePage() {
2228 // If we can not save the page, try to download it.
2230 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML
);
2231 SaveFrame(GetLastCommittedURL(), Referrer());
2237 // Create the save package and possibly prompt the user for the name to save
2238 // the page as. The user prompt is an asynchronous operation that runs on
2240 save_package_
= new SavePackage(this);
2241 save_package_
->GetSaveInfo();
2244 // Used in automated testing to bypass prompting the user for file names.
2245 // Instead, the names and paths are hard coded rather than running them through
2246 // file name sanitation and extension / mime checking.
2247 bool WebContentsImpl::SavePage(const base::FilePath
& main_file
,
2248 const base::FilePath
& dir_path
,
2249 SavePageType save_type
) {
2250 // Stop the page from navigating.
2253 save_package_
= new SavePackage(this, save_type
, main_file
, dir_path
);
2254 return save_package_
->Init(SavePackageDownloadCreatedCallback());
2257 void WebContentsImpl::SaveFrame(const GURL
& url
,
2258 const Referrer
& referrer
) {
2259 SaveFrameWithHeaders(url
, referrer
, std::string());
2262 void WebContentsImpl::SaveFrameWithHeaders(const GURL
& url
,
2263 const Referrer
& referrer
,
2264 const std::string
& headers
) {
2265 if (!GetLastCommittedURL().is_valid())
2267 if (delegate_
&& delegate_
->SaveFrame(url
, referrer
))
2270 // TODO(nasko): This check for main frame is incorrect and should be fixed
2271 // by explicitly passing in which frame this method should target.
2272 bool is_main_frame
= (url
== GetLastCommittedURL());
2274 DownloadManager
* dlm
=
2275 BrowserContext::GetDownloadManager(GetBrowserContext());
2279 if (is_main_frame
) {
2280 const NavigationEntry
* entry
= controller_
.GetLastCommittedEntry();
2282 post_id
= entry
->GetPostID();
2284 scoped_ptr
<DownloadUrlParameters
> params(
2285 DownloadUrlParameters::FromWebContents(this, url
));
2286 params
->set_referrer(referrer
);
2287 params
->set_post_id(post_id
);
2289 params
->set_method("POST");
2290 params
->set_prompt(true);
2292 if (headers
.empty()) {
2293 params
->set_prefer_cache(true);
2295 std::vector
<std::string
> key_value_list
;
2296 base::SplitString(headers
, '\n', &key_value_list
);
2297 for (const auto& key_value
: key_value_list
) {
2298 std::vector
<std::string
> pair
;
2299 base::SplitString(key_value
, ':', &pair
);
2300 DCHECK_EQ(2ul, pair
.size());
2301 params
->add_request_header(pair
[0], pair
[1]);
2304 dlm
->DownloadUrl(params
.Pass());
2307 void WebContentsImpl::GenerateMHTML(
2308 const base::FilePath
& file
,
2309 const base::Callback
<void(int64
)>& callback
) {
2310 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file
, callback
);
2313 const std::string
& WebContentsImpl::GetContentsMimeType() const {
2314 return contents_mime_type_
;
2317 bool WebContentsImpl::WillNotifyDisconnection() const {
2318 return notify_disconnection_
;
2321 void WebContentsImpl::SetOverrideEncoding(const std::string
& encoding
) {
2322 SetEncoding(encoding
);
2323 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding
));
2326 void WebContentsImpl::ResetOverrideEncoding() {
2327 canonical_encoding_
.clear();
2328 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
2331 RendererPreferences
* WebContentsImpl::GetMutableRendererPrefs() {
2332 return &renderer_preferences_
;
2335 void WebContentsImpl::Close() {
2336 Close(GetRenderViewHost());
2339 void WebContentsImpl::DragSourceEndedAt(int client_x
, int client_y
,
2340 int screen_x
, int screen_y
, blink::WebDragOperation operation
) {
2341 if (browser_plugin_embedder_
.get())
2342 browser_plugin_embedder_
->DragSourceEndedAt(client_x
, client_y
,
2343 screen_x
, screen_y
, operation
);
2344 if (GetRenderViewHost())
2345 GetRenderViewHostImpl()->DragSourceEndedAt(client_x
, client_y
,
2346 screen_x
, screen_y
, operation
);
2349 void WebContentsImpl::DidGetResourceResponseStart(
2350 const ResourceRequestDetails
& details
) {
2351 controller_
.ssl_manager()->DidStartResourceResponse(details
);
2353 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
2354 DidGetResourceResponseStart(details
));
2356 // TODO(avi): Remove. http://crbug.com/170921
2357 NotificationService::current()->Notify(
2358 NOTIFICATION_RESOURCE_RESPONSE_STARTED
,
2359 Source
<WebContents
>(this),
2360 Details
<const ResourceRequestDetails
>(&details
));
2363 void WebContentsImpl::DidGetRedirectForResourceRequest(
2364 RenderFrameHost
* render_frame_host
,
2365 const ResourceRedirectDetails
& details
) {
2366 controller_
.ssl_manager()->DidReceiveResourceRedirect(details
);
2369 WebContentsObserver
,
2371 DidGetRedirectForResourceRequest(render_frame_host
, details
));
2373 // TODO(avi): Remove. http://crbug.com/170921
2374 NotificationService::current()->Notify(
2375 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT
,
2376 Source
<WebContents
>(this),
2377 Details
<const ResourceRedirectDetails
>(&details
));
2380 void WebContentsImpl::SystemDragEnded() {
2381 if (GetRenderViewHost())
2382 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
2383 if (browser_plugin_embedder_
.get())
2384 browser_plugin_embedder_
->SystemDragEnded();
2387 void WebContentsImpl::UserGestureDone() {
2391 void WebContentsImpl::SetClosedByUserGesture(bool value
) {
2392 closed_by_user_gesture_
= value
;
2395 bool WebContentsImpl::GetClosedByUserGesture() const {
2396 return closed_by_user_gesture_
;
2399 void WebContentsImpl::ViewSource() {
2403 NavigationEntry
* entry
= GetController().GetLastCommittedEntry();
2407 delegate_
->ViewSourceForTab(this, entry
->GetURL());
2410 void WebContentsImpl::ViewFrameSource(const GURL
& url
,
2411 const PageState
& page_state
) {
2415 delegate_
->ViewSourceForFrame(this, url
, page_state
);
2418 int WebContentsImpl::GetMinimumZoomPercent() const {
2419 return minimum_zoom_percent_
;
2422 int WebContentsImpl::GetMaximumZoomPercent() const {
2423 return maximum_zoom_percent_
;
2426 void WebContentsImpl::ResetPageScale() {
2427 Send(new ViewMsg_ResetPageScale(GetRoutingID()));
2430 gfx::Size
WebContentsImpl::GetPreferredSize() const {
2431 return capturer_count_
== 0 ? preferred_size_
: preferred_size_for_capture_
;
2434 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed
) {
2435 if (GetBrowserPluginGuest())
2436 return GetBrowserPluginGuest()->LockMouse(allowed
);
2438 return GetRenderViewHost() ?
2439 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed
) : false;
2442 bool WebContentsImpl::HasOpener() const {
2443 return opener_
!= NULL
;
2446 WebContents
* WebContentsImpl::GetOpener() const {
2447 return static_cast<WebContents
*>(opener_
);
2450 void WebContentsImpl::DidChooseColorInColorChooser(SkColor color
) {
2451 if (!color_chooser_info_
.get())
2453 RenderFrameHost
* rfh
= RenderFrameHost::FromID(
2454 color_chooser_info_
->render_process_id
,
2455 color_chooser_info_
->render_frame_id
);
2459 rfh
->Send(new FrameMsg_DidChooseColorResponse(
2460 rfh
->GetRoutingID(), color_chooser_info_
->identifier
, color
));
2463 void WebContentsImpl::DidEndColorChooser() {
2464 if (!color_chooser_info_
.get())
2466 RenderFrameHost
* rfh
= RenderFrameHost::FromID(
2467 color_chooser_info_
->render_process_id
,
2468 color_chooser_info_
->render_frame_id
);
2472 rfh
->Send(new FrameMsg_DidEndColorChooser(
2473 rfh
->GetRoutingID(), color_chooser_info_
->identifier
));
2474 color_chooser_info_
.reset();
2477 int WebContentsImpl::DownloadImage(const GURL
& url
,
2479 uint32_t max_bitmap_size
,
2481 const ImageDownloadCallback
& callback
) {
2482 int id
= StartDownload(GetMainFrame(), url
, is_favicon
, max_bitmap_size
,
2484 image_download_map_
[id
] = callback
;
2488 bool WebContentsImpl::IsSubframe() const {
2489 return is_subframe_
;
2492 void WebContentsImpl::Find(int request_id
,
2493 const base::string16
& search_text
,
2494 const blink::WebFindOptions
& options
) {
2495 // See if a top level browser plugin handles the find request first.
2496 if (browser_plugin_embedder_
&&
2497 browser_plugin_embedder_
->Find(request_id
, search_text
, options
)) {
2500 Send(new ViewMsg_Find(GetRoutingID(), request_id
, search_text
, options
));
2503 void WebContentsImpl::StopFinding(StopFindAction action
) {
2504 // See if a top level browser plugin handles the stop finding request first.
2505 if (browser_plugin_embedder_
&&
2506 browser_plugin_embedder_
->StopFinding(action
)) {
2509 Send(new ViewMsg_StopFinding(GetRoutingID(), action
));
2512 void WebContentsImpl::InsertCSS(const std::string
& css
) {
2513 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2514 GetMainFrame()->GetRoutingID(), css
));
2517 bool WebContentsImpl::WasRecentlyAudible() {
2518 return audio_state_provider_
->WasRecentlyAudible();
2521 void WebContentsImpl::GetManifest(const GetManifestCallback
& callback
) {
2522 manifest_manager_host_
->GetManifest(GetMainFrame(), callback
);
2525 void WebContentsImpl::ExitFullscreen() {
2526 // Clean up related state and initiate the fullscreen exit.
2527 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2528 ExitFullscreenMode();
2531 bool WebContentsImpl::FocusLocationBarByDefault() {
2532 NavigationEntry
* entry
= controller_
.GetVisibleEntry();
2533 if (entry
&& entry
->GetURL() == GURL(url::kAboutBlankURL
))
2535 return delegate_
&& delegate_
->ShouldFocusLocationBarByDefault(this);
2538 void WebContentsImpl::SetFocusToLocationBar(bool select_all
) {
2540 delegate_
->SetFocusToLocationBar(select_all
);
2543 void WebContentsImpl::DidStartProvisionalLoad(
2544 RenderFrameHostImpl
* render_frame_host
,
2545 const GURL
& validated_url
,
2547 bool is_iframe_srcdoc
) {
2548 // Notify observers about the start of the provisional load.
2550 WebContentsObserver
,
2552 DidStartProvisionalLoadForFrame(
2553 render_frame_host
, validated_url
, is_error_page
, is_iframe_srcdoc
));
2555 // Notify accessibility if this is a reload.
2556 NavigationEntry
* entry
= controller_
.GetVisibleEntry();
2557 if (entry
&& ui::PageTransitionCoreTypeIs(
2558 entry
->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD
)) {
2559 FrameTreeNode
* ftn
= render_frame_host
->frame_tree_node();
2560 BrowserAccessibilityManager
* manager
=
2561 ftn
->current_frame_host()->browser_accessibility_manager();
2563 manager
->UserIsReloading();
2567 void WebContentsImpl::DidStartNavigationTransition(
2568 RenderFrameHostImpl
* render_frame_host
) {
2569 #if defined(OS_ANDROID)
2570 int render_frame_id
= render_frame_host
->GetRoutingID();
2571 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
2576 void WebContentsImpl::DidFailProvisionalLoadWithError(
2577 RenderFrameHostImpl
* render_frame_host
,
2578 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
) {
2579 GURL
validated_url(params
.url
);
2580 FOR_EACH_OBSERVER(WebContentsObserver
,
2582 DidFailProvisionalLoad(render_frame_host
,
2585 params
.error_description
));
2587 FrameTreeNode
* ftn
= render_frame_host
->frame_tree_node();
2588 BrowserAccessibilityManager
* manager
=
2589 ftn
->current_frame_host()->browser_accessibility_manager();
2591 manager
->NavigationFailed();
2594 void WebContentsImpl::DidFailLoadWithError(
2595 RenderFrameHostImpl
* render_frame_host
,
2598 const base::string16
& error_description
) {
2600 WebContentsObserver
,
2602 DidFailLoad(render_frame_host
, url
, error_code
, error_description
));
2605 void WebContentsImpl::NotifyChangedNavigationState(
2606 InvalidateTypes changed_flags
) {
2607 NotifyNavigationStateChanged(changed_flags
);
2610 void WebContentsImpl::AboutToNavigateRenderFrame(
2611 RenderFrameHostImpl
* old_host
,
2612 RenderFrameHostImpl
* new_host
) {
2613 // Notify observers that we will navigate in this RenderFrame.
2615 WebContentsObserver
,
2617 AboutToNavigateRenderFrame(old_host
, new_host
));
2620 void WebContentsImpl::DidStartNavigationToPendingEntry(
2622 NavigationController::ReloadType reload_type
) {
2623 // Notify observers about navigation.
2625 WebContentsObserver
,
2627 DidStartNavigationToPendingEntry(url
, reload_type
));
2630 void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl
* render_frame_host
,
2631 const OpenURLParams
& params
) {
2632 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2633 // weak pointer of sorts.
2634 const int32_t process_id
= render_frame_host
->GetProcess()->GetID();
2635 const int32_t frame_id
= render_frame_host
->GetRoutingID();
2637 WebContents
* new_contents
= OpenURL(params
);
2639 if (new_contents
&& RenderFrameHost::FromID(process_id
, frame_id
)) {
2640 // Notify observers.
2641 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
2642 DidOpenRequestedURL(new_contents
,
2647 params
.transition
));
2651 bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2654 return delegate_
->ShouldPreserveAbortedURLs(this);
2657 void WebContentsImpl::DidCommitProvisionalLoad(
2658 RenderFrameHostImpl
* render_frame_host
,
2660 ui::PageTransition transition_type
) {
2661 // Notify observers about the commit of the provisional load.
2662 FOR_EACH_OBSERVER(WebContentsObserver
,
2664 DidCommitProvisionalLoadForFrame(
2665 render_frame_host
, url
, transition_type
));
2667 BrowserAccessibilityManager
* manager
=
2668 render_frame_host
->browser_accessibility_manager();
2670 manager
->NavigationSucceeded();
2673 void WebContentsImpl::DidNavigateMainFramePreCommit(
2674 bool navigation_is_within_page
) {
2675 // Ensure fullscreen mode is exited before committing the navigation to a
2676 // different page. The next page will not start out assuming it is in
2678 if (navigation_is_within_page
) {
2679 // No page change? Then, the renderer and browser can remain in fullscreen.
2682 if (IsFullscreenForCurrentTab())
2684 DCHECK(!IsFullscreenForCurrentTab());
2687 void WebContentsImpl::DidNavigateMainFramePostCommit(
2688 RenderFrameHostImpl
* render_frame_host
,
2689 const LoadCommittedDetails
& details
,
2690 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) {
2691 if (details
.is_navigation_to_different_page()) {
2692 // Clear the status bubble. This is a workaround for a bug where WebKit
2693 // doesn't let us know that the cursor left an element during a
2694 // transition (this is also why the mouse cursor remains as a hand after
2695 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2696 // clear the bubble when a user navigates to a named anchor in the same
2698 UpdateTargetURL(render_frame_host
->GetRenderViewHost(), GURL());
2700 RenderWidgetHostViewBase
* rwhvb
=
2701 static_cast<RenderWidgetHostViewBase
*>(GetRenderWidgetHostView());
2703 rwhvb
->OnDidNavigateMainFrameToNewPage();
2705 // Reset theme color on navigation to new page.
2706 theme_color_
= SK_ColorTRANSPARENT
;
2709 if (!details
.is_in_page
) {
2710 // Once the main frame is navigated, we're no longer considered to have
2711 // displayed insecure content.
2712 displayed_insecure_content_
= false;
2713 SSLManager::NotifySSLInternalStateChanged(
2714 GetController().GetBrowserContext());
2717 // Notify observers about navigation.
2718 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
2719 DidNavigateMainFrame(details
, params
));
2722 delegate_
->DidNavigateMainFramePostCommit(this);
2723 view_
->SetOverscrollControllerEnabled(CanOverscrollContent());
2726 void WebContentsImpl::DidNavigateAnyFramePostCommit(
2727 RenderFrameHostImpl
* render_frame_host
,
2728 const LoadCommittedDetails
& details
,
2729 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) {
2730 // Now that something has committed, we don't need to track whether the
2731 // initial page has been accessed.
2732 has_accessed_initial_document_
= false;
2734 // If we navigate off the page, close all JavaScript dialogs.
2735 if (dialog_manager_
&& !details
.is_in_page
)
2736 dialog_manager_
->CancelActiveAndPendingDialogs(this);
2738 // Notify observers about navigation.
2739 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
2740 DidNavigateAnyFrame(render_frame_host
, details
, params
));
2743 void WebContentsImpl::SetMainFrameMimeType(const std::string
& mime_type
) {
2744 contents_mime_type_
= mime_type
;
2747 bool WebContentsImpl::CanOverscrollContent() const {
2748 // Disable overscroll when touch emulation is on. See crbug.com/369938.
2749 if (force_disable_overscroll_content_
)
2753 return delegate_
->CanOverscrollContent();
2758 void WebContentsImpl::OnThemeColorChanged(SkColor theme_color
) {
2759 // Update the theme color. This is to be published to observers on visually
2761 theme_color_
= theme_color
;
2764 void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
2766 const std::string
& security_info
,
2767 const std::string
& http_method
,
2768 const std::string
& mime_type
,
2769 ResourceType resource_type
) {
2771 // Send out a notification that we loaded a resource from our memory cache.
2773 net::CertStatus cert_status
= 0;
2774 int security_bits
= -1;
2775 int connection_status
= 0;
2776 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids
;
2777 DeserializeSecurityInfo(security_info
, &cert_id
, &cert_status
,
2778 &security_bits
, &connection_status
,
2779 &signed_certificate_timestamp_ids
);
2780 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
2781 LoadFromMemoryCacheDetails
details(
2782 url
, GetRenderProcessHost()->GetID(), cert_id
, cert_status
, http_method
,
2783 mime_type
, resource_type
);
2785 controller_
.ssl_manager()->DidLoadFromMemoryCache(details
);
2787 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
2788 DidLoadResourceFromMemoryCache(details
));
2790 if (url
.is_valid() && url
.SchemeIsHTTPOrHTTPS()) {
2791 scoped_refptr
<net::URLRequestContextGetter
> request_context(
2792 resource_type
== RESOURCE_TYPE_MEDIA
?
2793 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2794 GetRenderProcessHost()->GetID()) :
2795 GetBrowserContext()->GetRequestContextForRenderProcess(
2796 GetRenderProcessHost()->GetID()));
2797 BrowserThread::PostTask(
2800 base::Bind(&NotifyCacheOnIO
, request_context
, url
, http_method
));
2804 void WebContentsImpl::OnDidDisplayInsecureContent() {
2805 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
2806 displayed_insecure_content_
= true;
2807 SSLManager::NotifySSLInternalStateChanged(
2808 GetController().GetBrowserContext());
2811 void WebContentsImpl::OnDidRunInsecureContent(
2812 const std::string
& security_origin
, const GURL
& target_url
) {
2813 LOG(WARNING
) << security_origin
<< " ran insecure content from "
2814 << target_url
.possibly_invalid_spec();
2815 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
2816 if (EndsWith(security_origin
, kDotGoogleDotCom
, false))
2817 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
2818 controller_
.ssl_manager()->DidRunInsecureContent(security_origin
);
2819 displayed_insecure_content_
= true;
2820 SSLManager::NotifySSLInternalStateChanged(
2821 GetController().GetBrowserContext());
2824 void WebContentsImpl::OnDocumentLoadedInFrame() {
2825 if (!HasValidFrameSource())
2828 RenderFrameHostImpl
* rfh
=
2829 static_cast<RenderFrameHostImpl
*>(render_frame_message_source_
);
2831 WebContentsObserver
, observers_
, DocumentLoadedInFrame(rfh
));
2834 void WebContentsImpl::OnDidFinishLoad(const GURL
& url
) {
2835 if (!HasValidFrameSource())
2838 GURL
validated_url(url
);
2839 RenderProcessHost
* render_process_host
=
2840 render_frame_message_source_
->GetProcess();
2841 render_process_host
->FilterURL(false, &validated_url
);
2843 RenderFrameHostImpl
* rfh
=
2844 static_cast<RenderFrameHostImpl
*>(render_frame_message_source_
);
2846 WebContentsObserver
, observers_
, DidFinishLoad(rfh
, validated_url
));
2849 void WebContentsImpl::OnDidStartLoading(bool to_different_document
) {
2850 if (!HasValidFrameSource())
2853 RenderFrameHostImpl
* rfh
=
2854 static_cast<RenderFrameHostImpl
*>(render_frame_message_source_
);
2856 // Any main frame load to a new document should reset the load progress, since
2857 // it will replace the current page and any frames.
2858 if (to_different_document
&& !rfh
->GetParent()) {
2859 ResetLoadProgressState();
2860 rfh
->set_is_loading(false);
2863 // This method should never be called when the frame is loading.
2864 // Unfortunately, it can happen if a history navigation happens during a
2865 // BeforeUnload or Unload event.
2866 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
2867 // refactored in Blink. See crbug.com/466089
2868 if (rfh
->is_loading()) {
2869 LOG(WARNING
) << "OnDidStartLoading was called twice.";
2873 if (!frame_tree_
.IsLoading())
2874 DidStartLoading(rfh
, to_different_document
);
2876 rfh
->set_is_loading(true);
2878 FrameTreeNode
* ftn
= rfh
->frame_tree_node();
2879 ftn
->set_loading_progress(FrameTreeNode::kLoadingProgressMinimum
);
2881 // Notify the RenderFrameHostManager of the event.
2882 ftn
->render_manager()->OnDidStartLoading();
2884 SendLoadProgressChanged();
2887 void WebContentsImpl::OnDidStopLoading() {
2888 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2890 tracked_objects::ScopedTracker
tracking_profile1(
2891 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2892 "465796 WebContentsImpl::OnDidStopLoading::Start"));
2894 if (!HasValidFrameSource())
2897 RenderFrameHostImpl
* rfh
=
2898 static_cast<RenderFrameHostImpl
*>(render_frame_message_source_
);
2900 // This method should never be called when the frame is not loading.
2901 // Unfortunately, it can happen if a history navigation happens during a
2902 // BeforeUnload or Unload event.
2903 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
2904 // refactored in Blink. See crbug.com/466089
2905 if (!rfh
->is_loading()) {
2906 LOG(WARNING
) << "OnDidStopLoading was called twice.";
2910 rfh
->set_is_loading(false);
2912 FrameTreeNode
* ftn
= rfh
->frame_tree_node();
2913 ftn
->set_loading_progress(FrameTreeNode::kLoadingProgressDone
);
2915 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2917 tracked_objects::ScopedTracker
tracking_profile2(
2918 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2920 "WebContentsImpl::OnDidStopLoading::SendLoadProgressChanged"));
2922 // Update progress based on this frame's completion.
2923 SendLoadProgressChanged();
2925 // Then clean-up the states.
2926 if (loading_total_progress_
== 1.0)
2927 ResetLoadProgressState();
2929 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2931 tracked_objects::ScopedTracker
tracking_profile3(
2932 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2933 "465796 WebContentsImpl::OnDidStopLoading::NotifyRenderManager"));
2934 // Notify the RenderFrameHostManager of the event.
2935 ftn
->render_manager()->OnDidStopLoading();
2937 if (!frame_tree_
.IsLoading()) {
2938 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2940 tracked_objects::ScopedTracker
tracking_profile4(
2941 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2942 "465796 WebContentsImpl::OnDidStopLoading::WCIDidStopLoading"));
2946 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2948 tracked_objects::ScopedTracker
tracking_profile4(
2949 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2950 "465796 WebContentsImpl::OnDidStopLoading::End"));
2953 void WebContentsImpl::OnDidChangeLoadProgress(double load_progress
) {
2954 if (!HasValidFrameSource())
2957 RenderFrameHostImpl
* rfh
=
2958 static_cast<RenderFrameHostImpl
*>(render_frame_message_source_
);
2959 FrameTreeNode
* ftn
= rfh
->frame_tree_node();
2961 ftn
->set_loading_progress(load_progress
);
2963 // We notify progress change immediately for the first and last updates.
2964 // Also, since the message loop may be pretty busy when a page is loaded, it
2965 // might not execute a posted task in a timely manner so we make sure to
2966 // immediately send progress report if enough time has passed.
2967 base::TimeDelta min_delay
=
2968 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS
);
2969 if (load_progress
== 1.0 || loading_last_progress_update_
.is_null() ||
2970 base::TimeTicks::Now() - loading_last_progress_update_
> min_delay
) {
2971 // If there is a pending task to send progress, it is now obsolete.
2972 loading_weak_factory_
.InvalidateWeakPtrs();
2973 SendLoadProgressChanged();
2974 if (loading_total_progress_
== 1.0)
2975 ResetLoadProgressState();
2979 if (loading_weak_factory_
.HasWeakPtrs())
2982 base::MessageLoop::current()->PostDelayedTask(
2984 base::Bind(&WebContentsImpl::SendLoadProgressChanged
,
2985 loading_weak_factory_
.GetWeakPtr()),
2989 void WebContentsImpl::OnGoToEntryAtOffset(int offset
) {
2990 if (!delegate_
|| delegate_
->OnGoToEntryOffset(offset
))
2991 controller_
.GoToOffset(offset
);
2994 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent
,
2995 int maximum_percent
) {
2996 minimum_zoom_percent_
= minimum_percent
;
2997 maximum_zoom_percent_
= maximum_percent
;
3000 void WebContentsImpl::OnEnumerateDirectory(int request_id
,
3001 const base::FilePath
& path
) {
3005 ChildProcessSecurityPolicyImpl
* policy
=
3006 ChildProcessSecurityPolicyImpl::GetInstance();
3007 if (policy
->CanReadFile(GetRenderProcessHost()->GetID(), path
))
3008 delegate_
->EnumerateDirectory(this, request_id
, path
);
3011 void WebContentsImpl::OnRegisterProtocolHandler(const std::string
& protocol
,
3013 const base::string16
& title
,
3014 bool user_gesture
) {
3018 ChildProcessSecurityPolicyImpl
* policy
=
3019 ChildProcessSecurityPolicyImpl::GetInstance();
3020 if (policy
->IsPseudoScheme(protocol
))
3023 delegate_
->RegisterProtocolHandler(this, protocol
, url
, user_gesture
);
3026 void WebContentsImpl::OnUnregisterProtocolHandler(const std::string
& protocol
,
3028 bool user_gesture
) {
3032 ChildProcessSecurityPolicyImpl
* policy
=
3033 ChildProcessSecurityPolicyImpl::GetInstance();
3034 if (policy
->IsPseudoScheme(protocol
))
3037 delegate_
->UnregisterProtocolHandler(this, protocol
, url
, user_gesture
);
3040 void WebContentsImpl::OnFindReply(int request_id
,
3041 int number_of_matches
,
3042 const gfx::Rect
& selection_rect
,
3043 int active_match_ordinal
,
3044 bool final_update
) {
3046 delegate_
->FindReply(this, request_id
, number_of_matches
, selection_rect
,
3047 active_match_ordinal
, final_update
);
3051 #if defined(OS_ANDROID)
3052 void WebContentsImpl::OnFindMatchRectsReply(
3054 const std::vector
<gfx::RectF
>& rects
,
3055 const gfx::RectF
& active_rect
) {
3057 delegate_
->FindMatchRectsReply(this, version
, rects
, active_rect
);
3060 void WebContentsImpl::OnOpenDateTimeDialog(
3061 const ViewHostMsg_DateTimeDialogValue_Params
& value
) {
3062 date_time_chooser_
->ShowDialog(GetTopLevelNativeWindow(),
3063 GetRenderViewHost(),
3073 void WebContentsImpl::OnDomOperationResponse(const std::string
& json_string
,
3074 int automation_id
) {
3075 DomOperationNotificationDetails
details(json_string
, automation_id
);
3076 NotificationService::current()->Notify(
3077 NOTIFICATION_DOM_OPERATION_RESPONSE
,
3078 Source
<WebContents
>(this),
3079 Details
<DomOperationNotificationDetails
>(&details
));
3082 void WebContentsImpl::OnAppCacheAccessed(const GURL
& manifest_url
,
3083 bool blocked_by_policy
) {
3084 // Notify observers about navigation.
3085 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3086 AppCacheAccessed(manifest_url
, blocked_by_policy
));
3089 void WebContentsImpl::OnOpenColorChooser(
3090 int color_chooser_id
,
3092 const std::vector
<ColorSuggestion
>& suggestions
) {
3093 if (!HasValidFrameSource())
3096 ColorChooser
* new_color_chooser
= delegate_
?
3097 delegate_
->OpenColorChooser(this, color
, suggestions
) :
3099 if (!new_color_chooser
)
3101 if (color_chooser_info_
.get())
3102 color_chooser_info_
->chooser
->End();
3104 color_chooser_info_
.reset(new ColorChooserInfo(
3105 render_frame_message_source_
->GetProcess()->GetID(),
3106 render_frame_message_source_
->GetRoutingID(),
3111 void WebContentsImpl::OnEndColorChooser(int color_chooser_id
) {
3112 if (color_chooser_info_
&&
3113 color_chooser_id
== color_chooser_info_
->identifier
)
3114 color_chooser_info_
->chooser
->End();
3117 void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id
,
3119 if (color_chooser_info_
&&
3120 color_chooser_id
== color_chooser_info_
->identifier
)
3121 color_chooser_info_
->chooser
->SetSelectedColor(color
);
3124 // This exists for render views that don't have a WebUI, but do have WebUI
3125 // bindings enabled.
3126 void WebContentsImpl::OnWebUISend(const GURL
& source_url
,
3127 const std::string
& name
,
3128 const base::ListValue
& args
) {
3130 delegate_
->WebUISend(this, source_url
, name
, args
);
3133 #if defined(ENABLE_PLUGINS)
3134 void WebContentsImpl::OnPepperPluginHung(int plugin_child_id
,
3135 const base::FilePath
& path
,
3137 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3139 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3140 PluginHungStatusChanged(plugin_child_id
, path
, is_hung
));
3143 void WebContentsImpl::OnPluginCrashed(const base::FilePath
& plugin_path
,
3144 base::ProcessId plugin_pid
) {
3145 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3146 PluginCrashed(plugin_path
, plugin_pid
));
3149 void WebContentsImpl::OnRequestPpapiBrokerPermission(
3152 const base::FilePath
& plugin_path
) {
3154 OnPpapiBrokerPermissionResult(routing_id
, false);
3158 if (!delegate_
->RequestPpapiBrokerPermission(
3159 this, url
, plugin_path
,
3160 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult
,
3161 base::Unretained(this), routing_id
))) {
3163 OnPpapiBrokerPermissionResult(routing_id
, false);
3167 void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id
,
3169 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id
, result
));
3172 void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost
* render_frame_host
,
3173 const IPC::Message
& message
) {
3174 CHECK(!browser_plugin_embedder_
.get());
3175 CreateBrowserPluginEmbedderIfNecessary();
3176 browser_plugin_embedder_
->OnMessageReceived(message
, render_frame_host
);
3178 #endif // defined(ENABLE_PLUGINS)
3180 void WebContentsImpl::OnDidDownloadImage(
3182 int http_status_code
,
3183 const GURL
& image_url
,
3184 const std::vector
<SkBitmap
>& bitmaps
,
3185 const std::vector
<gfx::Size
>& original_bitmap_sizes
) {
3186 if (bitmaps
.size() != original_bitmap_sizes
.size())
3189 ImageDownloadMap::iterator iter
= image_download_map_
.find(id
);
3190 if (iter
== image_download_map_
.end()) {
3191 // Currently WebContents notifies us of ANY downloads so that it is
3192 // possible to get here.
3195 if (!iter
->second
.is_null()) {
3197 id
, http_status_code
, image_url
, bitmaps
, original_bitmap_sizes
);
3199 image_download_map_
.erase(id
);
3202 void WebContentsImpl::OnUpdateFaviconURL(
3203 const std::vector
<FaviconURL
>& candidates
) {
3204 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3205 DidUpdateFaviconURL(candidates
));
3208 void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3209 DCHECK(!audio_power_save_blocker_
);
3210 audio_power_save_blocker_
= PowerSaveBlocker::Create(
3211 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension
,
3212 PowerSaveBlocker::kReasonAudioPlayback
, "Playing audio");
3215 void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3216 DCHECK(!video_power_save_blocker_
);
3217 DCHECK(!active_video_players_
.empty());
3218 video_power_save_blocker_
= PowerSaveBlocker::Create(
3219 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep
,
3220 PowerSaveBlocker::kReasonVideoPlayback
, "Playing video");
3221 #if defined(OS_ANDROID)
3222 static_cast<PowerSaveBlockerImpl
*>(video_power_save_blocker_
.get())
3223 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3227 void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3228 // If there are no more audio players and we don't have audio stream
3229 // monitoring, release the audio power save blocker here instead of during
3230 // NotifyNavigationStateChanged().
3231 if (active_audio_players_
.empty() &&
3232 !audio_state_provider_
->IsAudioStateAvailable()) {
3233 audio_power_save_blocker_
.reset();
3236 // If there are no more video players, clear the video power save blocker.
3237 if (active_video_players_
.empty())
3238 video_power_save_blocker_
.reset();
3241 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie
,
3245 // Ignore the videos playing remotely and don't hold the wake lock for the
3247 if (is_remote
) return;
3250 AddMediaPlayerEntry(player_cookie
, &active_audio_players_
);
3252 // If we don't have audio stream monitoring, allocate the audio power save
3253 // blocker here instead of during NotifyNavigationStateChanged().
3254 if (!audio_power_save_blocker_
&&
3255 !audio_state_provider_
->IsAudioStateAvailable()) {
3256 CreateAudioPowerSaveBlocker();
3261 AddMediaPlayerEntry(player_cookie
, &active_video_players_
);
3263 // If we're not hidden and have just created a player, create a blocker.
3264 if (!video_power_save_blocker_
&& !IsHidden())
3265 CreateVideoPowerSaveBlocker();
3268 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, MediaStartedPlaying());
3271 void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie
) {
3272 RemoveMediaPlayerEntry(player_cookie
, &active_audio_players_
);
3273 RemoveMediaPlayerEntry(player_cookie
, &active_video_players_
);
3274 MaybeReleasePowerSaveBlockers();
3276 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, MediaPaused());
3279 void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
3280 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3281 DidFirstVisuallyNonEmptyPaint());
3283 if (theme_color_
!= last_sent_theme_color_
) {
3284 // Theme color should have updated by now if there was one.
3285 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3286 DidChangeThemeColor(theme_color_
));
3287 last_sent_theme_color_
= theme_color_
;
3291 void WebContentsImpl::DidChangeVisibleSSLState() {
3293 delegate_
->VisibleSSLStateChanged(this);
3296 void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3297 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3298 BeforeFormRepostWarningShow());
3301 void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3304 delegate_
->ShowRepostFormWarningDialog(this);
3307 bool WebContentsImpl::HasAccessedInitialDocument() {
3308 return has_accessed_initial_document_
;
3311 // Notifies the RenderWidgetHost instance about the fact that the page is
3312 // loading, or done loading.
3313 void WebContentsImpl::SetIsLoading(bool is_loading
,
3314 bool to_different_document
,
3315 LoadNotificationDetails
* details
) {
3316 if (is_loading
== is_loading_
)
3320 load_state_
= net::LoadStateWithParam(net::LOAD_STATE_IDLE
,
3322 load_state_host_
.clear();
3324 upload_position_
= 0;
3327 GetRenderManager()->SetIsLoading(is_loading
);
3329 is_loading_
= is_loading
;
3330 waiting_for_response_
= is_loading
;
3331 is_load_to_different_document_
= to_different_document
;
3334 delegate_
->LoadingStateChanged(this, to_different_document
);
3335 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD
);
3337 std::string url
= (details
? details
->url
.possibly_invalid_spec() : "NULL");
3339 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3341 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, DidStartLoading());
3343 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3345 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, DidStopLoading());
3348 // TODO(avi): Remove. http://crbug.com/170921
3349 int type
= is_loading
? NOTIFICATION_LOAD_START
: NOTIFICATION_LOAD_STOP
;
3350 NotificationDetails det
= NotificationService::NoDetails();
3352 det
= Details
<LoadNotificationDetails
>(details
);
3353 NotificationService::current()->Notify(
3354 type
, Source
<NavigationController
>(&controller_
), det
);
3357 void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point
& extent
) {
3358 RenderFrameHost
* focused_frame
= GetFocusedFrame();
3362 focused_frame
->Send(new InputMsg_MoveRangeSelectionExtent(
3363 focused_frame
->GetRoutingID(), extent
));
3366 void WebContentsImpl::SelectRange(const gfx::Point
& base
,
3367 const gfx::Point
& extent
) {
3368 RenderFrameHost
* focused_frame
= GetFocusedFrame();
3372 focused_frame
->Send(
3373 new InputMsg_SelectRange(focused_frame
->GetRoutingID(), base
, extent
));
3376 void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost
* rvh
) {
3377 // If we are creating a RVH for a restored controller, then we need to make
3378 // sure the RenderView starts with a next_page_id_ larger than the number
3379 // of restored entries. This must be called before the RenderView starts
3380 // navigating (to avoid a race between the browser updating max_page_id and
3381 // the renderer updating next_page_id_). Because of this, we only call this
3382 // from CreateRenderView and allow that to notify the RenderView for us.
3383 int max_restored_page_id
= controller_
.GetMaxRestoredPageID();
3384 if (max_restored_page_id
>
3385 GetMaxPageIDForSiteInstance(rvh
->GetSiteInstance()))
3386 UpdateMaxPageIDForSiteInstance(rvh
->GetSiteInstance(),
3387 max_restored_page_id
);
3390 bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl
* entry
,
3391 const base::string16
& title
) {
3392 // For file URLs without a title, use the pathname instead. In the case of a
3393 // synthesized title, we don't want the update to count toward the "one set
3394 // per page of the title to history."
3395 base::string16 final_title
;
3397 if (entry
&& entry
->GetURL().SchemeIsFile() && title
.empty()) {
3398 final_title
= base::UTF8ToUTF16(entry
->GetURL().ExtractFileName());
3399 explicit_set
= false; // Don't count synthetic titles toward the set limit.
3401 base::TrimWhitespace(title
, base::TRIM_ALL
, &final_title
);
3402 explicit_set
= true;
3405 // If a page is created via window.open and never navigated,
3406 // there will be no navigation entry. In this situation,
3407 // |page_title_when_no_navigation_entry_| will be used for page title.
3409 if (final_title
== entry
->GetTitle())
3410 return false; // Nothing changed, don't bother.
3412 entry
->SetTitle(final_title
);
3414 if (page_title_when_no_navigation_entry_
== final_title
)
3415 return false; // Nothing changed, don't bother.
3417 page_title_when_no_navigation_entry_
= final_title
;
3420 // Lastly, set the title for the view.
3421 view_
->SetPageTitle(final_title
);
3423 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3424 TitleWasSet(entry
, explicit_set
));
3426 // TODO(avi): Remove. http://crbug.com/170921
3427 std::pair
<NavigationEntry
*, bool> details
=
3428 std::make_pair(entry
, explicit_set
);
3429 NotificationService::current()->Notify(
3430 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED
,
3431 Source
<WebContents
>(this),
3432 Details
<std::pair
<NavigationEntry
*, bool> >(&details
));
3437 void WebContentsImpl::SendLoadProgressChanged() {
3438 loading_last_progress_update_
= base::TimeTicks::Now();
3439 double progress
= frame_tree_
.GetLoadProgress();
3441 DCHECK_LE(progress
, 1.0);
3443 if (progress
<= loading_total_progress_
)
3445 loading_total_progress_
= progress
;
3448 delegate_
->LoadProgressChanged(this, progress
);
3451 void WebContentsImpl::ResetLoadProgressState() {
3452 frame_tree_
.ResetLoadProgress();
3453 loading_total_progress_
= 0.0;
3454 loading_weak_factory_
.InvalidateWeakPtrs();
3455 loading_last_progress_update_
= base::TimeTicks();
3458 void WebContentsImpl::NotifyViewSwapped(RenderViewHost
* old_host
,
3459 RenderViewHost
* new_host
) {
3460 // After sending out a swap notification, we need to send a disconnect
3461 // notification so that clients that pick up a pointer to |this| can NULL the
3462 // pointer. See Bug 1230284.
3463 notify_disconnection_
= true;
3464 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3465 RenderViewHostChanged(old_host
, new_host
));
3467 // TODO(avi): Remove. http://crbug.com/170921
3468 std::pair
<RenderViewHost
*, RenderViewHost
*> details
=
3469 std::make_pair(old_host
, new_host
);
3470 NotificationService::current()->Notify(
3471 NOTIFICATION_RENDER_VIEW_HOST_CHANGED
,
3472 Source
<WebContents
>(this),
3473 Details
<std::pair
<RenderViewHost
*, RenderViewHost
*> >(&details
));
3475 // Ensure that the associated embedder gets cleared after a RenderViewHost
3476 // gets swapped, so we don't reuse the same embedder next time a
3477 // RenderViewHost is attached to this WebContents.
3478 RemoveBrowserPluginEmbedder();
3481 void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost
* old_host
,
3482 RenderFrameHost
* new_host
) {
3483 FOR_EACH_OBSERVER(WebContentsObserver
,
3485 RenderFrameHostChanged(old_host
, new_host
));
3488 // TODO(avi): Remove this entire function because this notification is already
3489 // covered by two observer functions. http://crbug.com/170921
3490 void WebContentsImpl::NotifyDisconnected() {
3491 if (!notify_disconnection_
)
3494 notify_disconnection_
= false;
3495 NotificationService::current()->Notify(
3496 NOTIFICATION_WEB_CONTENTS_DISCONNECTED
,
3497 Source
<WebContents
>(this),
3498 NotificationService::NoDetails());
3501 void WebContentsImpl::NotifyNavigationEntryCommitted(
3502 const LoadCommittedDetails
& load_details
) {
3504 WebContentsObserver
, observers_
, NavigationEntryCommitted(load_details
));
3507 bool WebContentsImpl::OnMessageReceived(RenderFrameHost
* render_frame_host
,
3508 const IPC::Message
& message
) {
3509 return OnMessageReceived(NULL
, render_frame_host
, message
);
3512 const GURL
& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3513 return GetLastCommittedURL();
3516 void WebContentsImpl::RenderFrameCreated(RenderFrameHost
* render_frame_host
) {
3517 // Note this is only for subframes, the notification for the main frame
3518 // happens in RenderViewCreated.
3519 FOR_EACH_OBSERVER(WebContentsObserver
,
3521 RenderFrameCreated(render_frame_host
));
3522 SetAccessibilityModeOnFrame(accessibility_mode_
, render_frame_host
);
3525 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost
* render_frame_host
) {
3526 ClearPowerSaveBlockers(render_frame_host
);
3527 FOR_EACH_OBSERVER(WebContentsObserver
,
3529 RenderFrameDeleted(render_frame_host
));
3532 void WebContentsImpl::WorkerCrashed(RenderFrameHost
* render_frame_host
) {
3534 delegate_
->WorkerCrashed(this);
3537 void WebContentsImpl::ShowContextMenu(RenderFrameHost
* render_frame_host
,
3538 const ContextMenuParams
& params
) {
3539 ContextMenuParams
context_menu_params(params
);
3540 // Allow WebContentsDelegates to handle the context menu operation first.
3541 if (GetBrowserPluginGuest()) {
3542 WebContentsViewGuest
* view_guest
=
3543 static_cast<WebContentsViewGuest
*>(GetView());
3544 context_menu_params
= view_guest
->ConvertContextMenuParams(params
);
3546 if (delegate_
&& delegate_
->HandleContextMenu(context_menu_params
))
3549 render_view_host_delegate_view_
->ShowContextMenu(render_frame_host
,
3550 context_menu_params
);
3553 void WebContentsImpl::RunJavaScriptMessage(
3554 RenderFrameHost
* render_frame_host
,
3555 const base::string16
& message
,
3556 const base::string16
& default_prompt
,
3557 const GURL
& frame_url
,
3558 JavaScriptMessageType javascript_message_type
,
3559 IPC::Message
* reply_msg
) {
3560 // Suppress JavaScript dialogs when requested. Also suppress messages when
3561 // showing an interstitial as it's shown over the previous page and we don't
3562 // want the hidden page's dialogs to interfere with the interstitial.
3563 bool suppress_this_message
=
3564 static_cast<RenderFrameHostImpl
*>(render_frame_host
)->is_swapped_out() ||
3565 ShowingInterstitialPage() || !delegate_
||
3566 delegate_
->ShouldSuppressDialogs(this) ||
3567 !delegate_
->GetJavaScriptDialogManager(this);
3569 if (!suppress_this_message
) {
3570 std::string accept_lang
= GetContentClient()->browser()->
3571 GetAcceptLangs(GetBrowserContext());
3572 dialog_manager_
= delegate_
->GetJavaScriptDialogManager(this);
3573 dialog_manager_
->RunJavaScriptDialog(
3575 frame_url
.GetOrigin(),
3577 javascript_message_type
,
3580 base::Bind(&WebContentsImpl::OnDialogClosed
,
3581 base::Unretained(this),
3582 render_frame_host
->GetProcess()->GetID(),
3583 render_frame_host
->GetRoutingID(),
3586 &suppress_this_message
);
3589 if (suppress_this_message
) {
3590 // If we are suppressing messages, just reply as if the user immediately
3591 // pressed "Cancel", passing true to |dialog_was_suppressed|.
3592 OnDialogClosed(render_frame_host
->GetProcess()->GetID(),
3593 render_frame_host
->GetRoutingID(), reply_msg
,
3594 true, false, base::string16());
3597 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3598 // http://crbug.com/288961 ). The only safe thing to do here is return.
3601 void WebContentsImpl::RunBeforeUnloadConfirm(
3602 RenderFrameHost
* render_frame_host
,
3603 const base::string16
& message
,
3605 IPC::Message
* reply_msg
) {
3606 RenderFrameHostImpl
* rfhi
=
3607 static_cast<RenderFrameHostImpl
*>(render_frame_host
);
3609 delegate_
->WillRunBeforeUnloadConfirm();
3611 bool suppress_this_message
=
3612 rfhi
->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT
|| !delegate_
||
3613 delegate_
->ShouldSuppressDialogs(this) ||
3614 !delegate_
->GetJavaScriptDialogManager(this);
3615 if (suppress_this_message
) {
3616 rfhi
->JavaScriptDialogClosed(reply_msg
, true, base::string16(), true);
3620 is_showing_before_unload_dialog_
= true;
3621 dialog_manager_
= delegate_
->GetJavaScriptDialogManager(this);
3622 dialog_manager_
->RunBeforeUnloadDialog(
3623 this, message
, is_reload
,
3624 base::Bind(&WebContentsImpl::OnDialogClosed
, base::Unretained(this),
3625 render_frame_host
->GetProcess()->GetID(),
3626 render_frame_host
->GetRoutingID(), reply_msg
,
3630 WebContents
* WebContentsImpl::GetAsWebContents() {
3634 bool WebContentsImpl::IsNeverVisible() {
3637 return delegate_
->IsNeverVisible(this);
3641 gfx::NativeViewAccessible
WebContentsImpl::GetParentNativeViewAccessible() {
3642 return accessible_parent_
;
3646 RenderViewHostDelegateView
* WebContentsImpl::GetDelegateView() {
3647 return render_view_host_delegate_view_
;
3650 RendererPreferences
WebContentsImpl::GetRendererPrefs(
3651 BrowserContext
* browser_context
) const {
3652 return renderer_preferences_
;
3655 gfx::Rect
WebContentsImpl::GetRootWindowResizerRect() const {
3657 return delegate_
->GetRootWindowResizerRect();
3661 void WebContentsImpl::RemoveBrowserPluginEmbedder() {
3662 if (browser_plugin_embedder_
)
3663 browser_plugin_embedder_
.reset();
3666 void WebContentsImpl::RenderViewCreated(RenderViewHost
* render_view_host
) {
3667 // Don't send notifications if we are just creating a swapped-out RVH for
3668 // the opener chain. These won't be used for view-source or WebUI, so it's
3669 // ok to return early.
3670 if (!static_cast<RenderViewHostImpl
*>(render_view_host
)->is_active())
3674 view_
->SetOverscrollControllerEnabled(CanOverscrollContent());
3676 NotificationService::current()->Notify(
3677 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED
,
3678 Source
<WebContents
>(this),
3679 Details
<RenderViewHost
>(render_view_host
));
3681 // When we're creating views, we're still doing initial setup, so we always
3682 // use the pending Web UI rather than any possibly existing committed one.
3683 if (GetRenderManager()->pending_web_ui())
3684 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host
);
3686 NavigationEntry
* entry
= controller_
.GetPendingEntry();
3687 if (entry
&& entry
->IsViewSourceMode()) {
3688 // Put the renderer in view source mode.
3689 render_view_host
->Send(
3690 new ViewMsg_EnableViewSourceMode(render_view_host
->GetRoutingID()));
3693 view_
->RenderViewCreated(render_view_host
);
3696 WebContentsObserver
, observers_
, RenderViewCreated(render_view_host
));
3698 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host
);
3701 void WebContentsImpl::RenderViewReady(RenderViewHost
* rvh
) {
3702 if (rvh
!= GetRenderViewHost()) {
3703 // Don't notify the world, since this came from a renderer in the
3708 notify_disconnection_
= true;
3709 // TODO(avi): Remove. http://crbug.com/170921
3710 NotificationService::current()->Notify(
3711 NOTIFICATION_WEB_CONTENTS_CONNECTED
,
3712 Source
<WebContents
>(this),
3713 NotificationService::NoDetails());
3715 bool was_crashed
= IsCrashed();
3716 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING
, 0);
3718 // Restore the focus to the tab (otherwise the focus will be on the top
3720 if (was_crashed
&& !FocusLocationBarByDefault() &&
3721 (!delegate_
|| delegate_
->ShouldFocusPageAfterCrash())) {
3725 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, RenderViewReady());
3728 void WebContentsImpl::RenderViewTerminated(RenderViewHost
* rvh
,
3729 base::TerminationStatus status
,
3731 if (rvh
!= GetRenderViewHost()) {
3732 // The pending page's RenderViewHost is gone.
3736 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3737 // renderer may not have made a clean exit.
3738 if (IsFullscreenForCurrentTab())
3739 ExitFullscreenMode();
3741 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3742 if (dialog_manager_
)
3743 dialog_manager_
->CancelActiveAndPendingDialogs(this);
3746 delegate_
->HideValidationMessage(this);
3748 SetIsLoading(false, true, nullptr);
3749 NotifyDisconnected();
3750 SetIsCrashed(status
, error_code
);
3752 // Reset the loading progress. TODO(avi): What does it mean to have a
3753 // "renderer crash" when there is more than one renderer process serving a
3754 // webpage? Once this function is called at a more granular frame level, we
3755 // probably will need to more granularly reset the state here.
3756 ResetLoadProgressState();
3758 FOR_EACH_OBSERVER(WebContentsObserver
,
3760 RenderProcessGone(GetCrashedStatus()));
3763 void WebContentsImpl::RenderViewDeleted(RenderViewHost
* rvh
) {
3764 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, RenderViewDeleted(rvh
));
3767 void WebContentsImpl::UpdateState(RenderViewHost
* rvh
,
3769 const PageState
& page_state
) {
3770 // Ensure that this state update comes from a RenderViewHost that belongs to
3771 // this WebContents.
3772 // TODO(nasko): This should go through RenderFrameHost.
3773 // TODO(creis): We can't update state for cross-process subframes until we
3774 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3775 if (rvh
->GetDelegate()->GetAsWebContents() != this)
3778 // We must be prepared to handle state updates for any page, these occur
3779 // when the user is scrolling and entering form data, as well as when we're
3780 // leaving a page, in which case our state may have already been moved to
3781 // the next page. The navigation controller will look up the appropriate
3782 // NavigationEntry and update it when it is notified via the delegate.
3784 int entry_index
= controller_
.GetEntryIndexWithPageID(
3785 rvh
->GetSiteInstance(), page_id
);
3786 if (entry_index
< 0)
3788 NavigationEntry
* entry
= controller_
.GetEntryAtIndex(entry_index
);
3790 if (page_state
== entry
->GetPageState())
3791 return; // Nothing to update.
3792 entry
->SetPageState(page_state
);
3793 controller_
.NotifyEntryChanged(entry
, entry_index
);
3796 void WebContentsImpl::UpdateTargetURL(RenderViewHost
* render_view_host
,
3798 if (fullscreen_widget_routing_id_
!= MSG_ROUTING_NONE
) {
3799 // If we're fullscreen only update the url if it's from the fullscreen
3801 RenderWidgetHostView
* fs
= GetFullscreenRenderWidgetHostView();
3802 if (fs
&& fs
->GetRenderWidgetHost() != render_view_host
)
3806 delegate_
->UpdateTargetURL(this, url
);
3809 void WebContentsImpl::Close(RenderViewHost
* rvh
) {
3810 #if defined(OS_MACOSX)
3811 // The UI may be in an event-tracking loop, such as between the
3812 // mouse-down and mouse-up in text selection or a button click.
3813 // Defer the close until after tracking is complete, so that we
3814 // don't free objects out from under the UI.
3815 // TODO(shess): This could get more fine-grained. For instance,
3816 // closing a tab in another window while selecting text in the
3817 // current window's Omnibox should be just fine.
3818 if (view_
->IsEventTracking()) {
3819 view_
->CloseTabAfterEventTracking();
3824 // Ignore this if it comes from a RenderViewHost that we aren't showing.
3825 if (delegate_
&& rvh
== GetRenderViewHost())
3826 delegate_
->CloseContents(this);
3829 void WebContentsImpl::SwappedOut(RenderFrameHost
* rfh
) {
3830 if (delegate_
&& rfh
->GetRenderViewHost() == GetRenderViewHost())
3831 delegate_
->SwappedOut(this);
3834 void WebContentsImpl::DidDeferAfterResponseStarted(
3835 const TransitionLayerData
& transition_data
) {
3836 #if defined(OS_ANDROID)
3837 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data
);
3841 bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3842 #if defined(OS_ANDROID)
3843 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
3849 void WebContentsImpl::RequestMove(const gfx::Rect
& new_bounds
) {
3850 if (delegate_
&& delegate_
->IsPopupOrPanel(this))
3851 delegate_
->MoveContents(this, new_bounds
);
3854 void WebContentsImpl::DidStartLoading(RenderFrameHost
* render_frame_host
,
3855 bool to_different_document
) {
3856 SetIsLoading(true, to_different_document
, nullptr);
3858 // Notify accessibility that the user is navigating away from the
3859 // current document.
3861 // TODO(dmazzoni): do this using a WebContentsObserver.
3862 FrameTreeNode
* ftn
= static_cast<RenderFrameHostImpl
*>(render_frame_host
)->
3864 BrowserAccessibilityManager
* manager
=
3865 ftn
->current_frame_host()->browser_accessibility_manager();
3867 manager
->UserIsNavigatingAway();
3870 void WebContentsImpl::DidStopLoading() {
3871 scoped_ptr
<LoadNotificationDetails
> details
;
3873 // Use the last committed entry rather than the active one, in case a
3874 // pending entry has been created.
3875 NavigationEntry
* entry
= controller_
.GetLastCommittedEntry();
3876 Navigator
* navigator
= frame_tree_
.root()->navigator();
3878 // An entry may not exist for a stop when loading an initial blank page or
3879 // if an iframe injected by script into a blank page finishes loading.
3881 base::TimeDelta elapsed
=
3882 base::TimeTicks::Now() - navigator
->GetCurrentLoadStart();
3884 details
.reset(new LoadNotificationDetails(
3885 entry
->GetVirtualURL(),
3886 entry
->GetTransitionType(),
3889 controller_
.GetCurrentEntryIndex()));
3892 SetIsLoading(false, true, details
.get());
3895 void WebContentsImpl::DidCancelLoading() {
3896 controller_
.DiscardNonCommittedEntries();
3898 // Update the URL display.
3899 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL
);
3902 void WebContentsImpl::DidAccessInitialDocument() {
3903 has_accessed_initial_document_
= true;
3905 // We may have left a failed browser-initiated navigation in the address bar
3906 // to let the user edit it and try again. Clear it now that content might
3907 // show up underneath it.
3908 if (!IsLoading() && controller_
.GetPendingEntry())
3909 controller_
.DiscardPendingEntry(false);
3911 // Update the URL display.
3912 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL
);
3915 void WebContentsImpl::DidChangeName(RenderFrameHost
* render_frame_host
,
3916 const std::string
& name
) {
3917 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3918 FrameNameChanged(render_frame_host
, name
));
3921 void WebContentsImpl::DidDisownOpener(RenderFrameHost
* render_frame_host
) {
3922 // No action is necessary if the opener has already been cleared.
3926 // Clear our opener so that future cross-process navigations don't have an
3928 RemoveDestructionObserver(opener_
);
3931 // Notify all swapped out RenderViewHosts for this tab. This is important
3932 // in case we go back to them, or if another window in those processes tries
3933 // to access window.opener.
3934 GetRenderManager()->DidDisownOpener(render_frame_host
);
3937 void WebContentsImpl::DocumentOnLoadCompleted(
3938 RenderFrameHost
* render_frame_host
) {
3939 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3940 DocumentOnLoadCompletedInMainFrame());
3942 // TODO(avi): Remove. http://crbug.com/170921
3943 NotificationService::current()->Notify(
3944 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
,
3945 Source
<WebContents
>(this),
3946 NotificationService::NoDetails());
3949 void WebContentsImpl::UpdateTitle(RenderFrameHost
* render_frame_host
,
3951 const base::string16
& title
,
3952 base::i18n::TextDirection title_direction
) {
3953 RenderViewHost
* rvh
= render_frame_host
->GetRenderViewHost();
3955 // If we have a title, that's a pretty good indication that we've started
3956 // getting useful data.
3957 SetNotWaitingForResponse();
3959 // Try to find the navigation entry, which might not be the current one.
3960 // For example, it might be from a pending RVH for the pending entry.
3961 NavigationEntryImpl
* entry
= controller_
.GetEntryWithPageID(
3962 rvh
->GetSiteInstance(), page_id
);
3964 // We can handle title updates when we don't have an entry in
3965 // UpdateTitleForEntry, but only if the update is from the current RVH.
3966 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3967 if (!entry
&& rvh
!= GetRenderViewHost())
3970 // TODO(evan): make use of title_direction.
3971 // http://code.google.com/p/chromium/issues/detail?id=27094
3972 if (!UpdateTitleForEntry(entry
, title
))
3975 // Broadcast notifications when the UI should be updated.
3976 if (entry
== controller_
.GetEntryAtOffset(0))
3977 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE
);
3980 void WebContentsImpl::UpdateEncoding(RenderFrameHost
* render_frame_host
,
3981 const std::string
& encoding
) {
3982 SetEncoding(encoding
);
3985 void WebContentsImpl::DocumentAvailableInMainFrame(
3986 RenderViewHost
* render_view_host
) {
3987 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
3988 DocumentAvailableInMainFrame());
3990 void WebContentsImpl::RouteCloseEvent(RenderViewHost
* rvh
) {
3991 // Tell the active RenderViewHost to run unload handlers and close, as long
3992 // as the request came from a RenderViewHost in the same BrowsingInstance.
3993 // In most cases, we receive this from a swapped out RenderViewHost.
3994 // It is possible to receive it from one that has just been swapped in,
3995 // in which case we might as well deliver the message anyway.
3996 if (rvh
->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3997 GetRenderViewHost()->ClosePage();
4000 void WebContentsImpl::RouteMessageEvent(
4001 RenderViewHost
* rvh
,
4002 const ViewMsg_PostMessage_Params
& params
) {
4003 // Only deliver the message to the active RenderViewHost if the request
4004 // came from a RenderViewHost in the same BrowsingInstance or if this
4005 // WebContents is dedicated to a browser plugin guest.
4006 // Note: This check means that an embedder could theoretically receive a
4007 // postMessage from anyone (not just its own guests). However, this is
4008 // probably not a risk for apps since other pages won't have references
4010 if (!rvh
->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
4011 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
4014 ViewMsg_PostMessage_Params
new_params(params
);
4016 // If there is a source_routing_id, translate it to the routing ID for
4017 // the equivalent swapped out RVH in the target process. If we need
4018 // to create a swapped out RVH for the source tab, we create its opener
4019 // chain as well, since those will also be accessible to the target page.
4020 if (new_params
.source_routing_id
!= MSG_ROUTING_NONE
) {
4021 // Try to look up the WebContents for the source page.
4022 WebContentsImpl
* source_contents
= NULL
;
4023 RenderViewHostImpl
* source_rvh
= RenderViewHostImpl::FromID(
4024 rvh
->GetProcess()->GetID(), params
.source_routing_id
);
4026 source_contents
= static_cast<WebContentsImpl
*>(
4027 source_rvh
->GetDelegate()->GetAsWebContents());
4030 if (source_contents
) {
4031 if (GetBrowserPluginGuest()) {
4032 // We create a swapped out RenderView for the embedder in the guest's
4033 // render process but we intentionally do not expose the embedder's
4034 // opener chain to it.
4035 new_params
.source_routing_id
=
4036 source_contents
->CreateSwappedOutRenderView(GetSiteInstance());
4038 new_params
.source_routing_id
=
4039 source_contents
->CreateOpenerRenderViews(GetSiteInstance());
4042 // We couldn't find it, so don't pass a source frame.
4043 new_params
.source_routing_id
= MSG_ROUTING_NONE
;
4047 // In most cases, we receive this from a swapped out RenderViewHost.
4048 // It is possible to receive it from one that has just been swapped in,
4049 // in which case we might as well deliver the message anyway.
4050 if (!params
.message_ports
.empty()) {
4051 // Updating the message port information has to be done in the IO thread;
4052 // MessagePortMessageFilter::RouteMessageEventWithMessagePorts will send
4053 // ViewMsg_PostMessageEvent after it's done. Note that a trivial solution
4054 // would've been to post a task on the IO thread to do the IO-thread-bound
4055 // work, and make that post a task back to WebContentsImpl in the UI
4056 // thread. But we cannot do that, since there's nothing to guarantee that
4057 // WebContentsImpl stays alive during the round trip.
4058 scoped_refptr
<MessagePortMessageFilter
> message_port_message_filter(
4059 static_cast<RenderProcessHostImpl
*>(GetRenderProcessHost())
4060 ->message_port_message_filter());
4061 BrowserThread::PostTask(
4062 BrowserThread::IO
, FROM_HERE
,
4063 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts
,
4064 message_port_message_filter
, GetRoutingID(), new_params
));
4066 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params
));
4070 bool WebContentsImpl::AddMessageToConsole(int32 level
,
4071 const base::string16
& message
,
4073 const base::string16
& source_id
) {
4076 return delegate_
->AddMessageToConsole(this, level
, message
, line_no
,
4080 int WebContentsImpl::CreateSwappedOutRenderView(
4081 SiteInstance
* instance
) {
4082 int render_view_routing_id
= MSG_ROUTING_NONE
;
4083 GetRenderManager()->CreateRenderFrame(
4084 instance
, nullptr, MSG_ROUTING_NONE
,
4085 CREATE_RF_SWAPPED_OUT
| CREATE_RF_FOR_MAIN_FRAME_NAVIGATION
|
4087 &render_view_routing_id
);
4088 return render_view_routing_id
;
4091 void WebContentsImpl::OnUserGesture() {
4092 // Notify observers.
4093 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, DidGetUserGesture());
4095 ResourceDispatcherHostImpl
* rdh
= ResourceDispatcherHostImpl::Get();
4096 if (rdh
) // NULL in unittests.
4097 rdh
->OnUserGesture(this);
4100 void WebContentsImpl::OnIgnoredUIEvent() {
4101 // Notify observers.
4102 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
, DidGetIgnoredUIEvent());
4105 void WebContentsImpl::RendererUnresponsive(RenderViewHost
* render_view_host
) {
4106 // Don't show hung renderer dialog for a swapped out RVH.
4107 if (render_view_host
!= GetRenderViewHost())
4110 RenderViewHostImpl
* rvhi
= static_cast<RenderViewHostImpl
*>(render_view_host
);
4111 RenderFrameHostImpl
* rfhi
=
4112 static_cast<RenderFrameHostImpl
*>(rvhi
->GetMainFrame());
4114 // Ignore renderer unresponsive event if debugger is attached to the tab
4115 // since the event may be a result of the renderer sitting on a breakpoint.
4116 // See http://crbug.com/65458
4117 if (DevToolsAgentHost::IsDebuggerAttached(this))
4120 if (rfhi
->IsWaitingForBeforeUnloadACK() ||
4121 rfhi
->IsWaitingForUnloadACK()) {
4122 // Hang occurred while firing the beforeunload/unload handler.
4123 // Pretend the handler fired so tab closing continues as if it had.
4124 rvhi
->set_sudden_termination_allowed(true);
4126 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
4129 // If the tab hangs in the beforeunload/unload handler there's really
4130 // nothing we can do to recover. If the hang is in the beforeunload handler,
4131 // pretend the beforeunload listeners have all fired and allow the delegate
4132 // to continue closing; the user will not have the option of cancelling the
4133 // close. Otherwise, pretend the unload listeners have all fired and close
4136 if (rfhi
->IsWaitingForBeforeUnloadACK() && delegate_
) {
4137 delegate_
->BeforeUnloadFired(this, true, &close
);
4144 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
4148 delegate_
->RendererUnresponsive(this);
4151 void WebContentsImpl::RendererResponsive(RenderViewHost
* render_view_host
) {
4153 delegate_
->RendererResponsive(this);
4156 void WebContentsImpl::LoadStateChanged(
4158 const net::LoadStateWithParam
& load_state
,
4159 uint64 upload_position
,
4160 uint64 upload_size
) {
4161 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4163 tracked_objects::ScopedTracker
tracking_profile1(
4164 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4165 "466285 WebContentsImpl::LoadStateChanged::Start"));
4166 load_state_
= load_state
;
4167 upload_position_
= upload_position
;
4168 upload_size_
= upload_size
;
4169 load_state_host_
= net::IDNToUnicode(url
.host(),
4170 GetContentClient()->browser()->GetAcceptLangs(
4171 GetBrowserContext()));
4172 if (load_state_
.state
== net::LOAD_STATE_READING_RESPONSE
)
4173 SetNotWaitingForResponse();
4175 NotifyNavigationStateChanged(static_cast<InvalidateTypes
>(
4176 INVALIDATE_TYPE_LOAD
| INVALIDATE_TYPE_TAB
));
4180 void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
4181 bool proceed
, const base::TimeTicks
& proceed_time
,
4182 bool* proceed_to_fire_unload
) {
4183 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
4184 BeforeUnloadFired(proceed_time
));
4186 delegate_
->BeforeUnloadFired(this, proceed
, proceed_to_fire_unload
);
4187 // Note: |this| might be deleted at this point.
4190 void WebContentsImpl::RenderProcessGoneFromRenderManager(
4191 RenderViewHost
* render_view_host
) {
4192 DCHECK(crashed_status_
!= base::TERMINATION_STATUS_STILL_RUNNING
);
4193 RenderViewTerminated(render_view_host
, crashed_status_
, crashed_error_code_
);
4196 void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
4197 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
4198 gfx::Size size
= GetSizeForNewRenderView();
4199 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4200 // here during container initialization and normal window size will be set
4201 // later. In case of tab duplication this resizing to 0x0 prevents setting
4202 // normal size later so just ignore it.
4203 if (!size
.IsEmpty())
4204 view_
->SizeContents(size
);
4207 void WebContentsImpl::CancelModalDialogsForRenderManager() {
4208 // We need to cancel modal dialogs when doing a process swap, since the load
4209 // deferrer would prevent us from swapping out.
4210 if (dialog_manager_
)
4211 dialog_manager_
->CancelActiveAndPendingDialogs(this);
4214 void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost
* old_host
,
4215 RenderFrameHost
* new_host
,
4216 bool is_main_frame
) {
4217 if (is_main_frame
) {
4218 NotifyViewSwapped(old_host
? old_host
->GetRenderViewHost() : nullptr,
4219 new_host
->GetRenderViewHost());
4221 // Make sure the visible RVH reflects the new delegate's preferences.
4223 view_
->SetOverscrollControllerEnabled(CanOverscrollContent());
4225 view_
->RenderViewSwappedIn(new_host
->GetRenderViewHost());
4228 NotifyFrameSwapped(old_host
, new_host
);
4231 void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4232 RenderViewHost
* old_host
,
4233 RenderViewHost
* new_host
) {
4234 NotifyViewSwapped(old_host
, new_host
);
4237 int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4238 SiteInstance
* instance
) {
4240 return MSG_ROUTING_NONE
;
4242 // Recursively create RenderViews for anything else in the opener chain.
4243 return opener_
->CreateOpenerRenderViews(instance
);
4246 int WebContentsImpl::CreateOpenerRenderViews(SiteInstance
* instance
) {
4247 int opener_route_id
= MSG_ROUTING_NONE
;
4249 // If this tab has an opener, ensure it has a RenderView in the given
4250 // SiteInstance as well.
4252 opener_route_id
= opener_
->CreateOpenerRenderViews(instance
);
4254 // If any of the renderers (current, pending, or swapped out) for this
4255 // WebContents has the same SiteInstance, use it.
4256 if (GetRenderManager()->current_host()->GetSiteInstance() == instance
)
4257 return GetRenderManager()->current_host()->GetRoutingID();
4259 if (GetRenderManager()->pending_render_view_host() &&
4260 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4262 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
4264 RenderViewHostImpl
* rvh
= GetRenderManager()->GetSwappedOutRenderViewHost(
4267 return rvh
->GetRoutingID();
4269 // Create a swapped out RenderView in the given SiteInstance if none exists,
4270 // setting its opener to the given route_id. Return the new view's route_id.
4271 int render_view_routing_id
= MSG_ROUTING_NONE
;
4272 GetRenderManager()->CreateRenderFrame(instance
, nullptr, opener_route_id
,
4273 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION
|
4274 CREATE_RF_SWAPPED_OUT
|
4276 &render_view_routing_id
);
4277 return render_view_routing_id
;
4280 NavigationControllerImpl
& WebContentsImpl::GetControllerForRenderManager() {
4281 return GetController();
4284 scoped_ptr
<WebUIImpl
> WebContentsImpl::CreateWebUIForRenderManager(
4286 return scoped_ptr
<WebUIImpl
>(static_cast<WebUIImpl
*>(CreateWebUI(url
)));
4290 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
4291 return controller_
.GetLastCommittedEntry();
4294 bool WebContentsImpl::CreateRenderViewForRenderManager(
4295 RenderViewHost
* render_view_host
,
4296 int opener_route_id
,
4297 int proxy_routing_id
,
4298 bool for_main_frame_navigation
) {
4299 TRACE_EVENT0("browser,navigation",
4300 "WebContentsImpl::CreateRenderViewForRenderManager");
4301 // Can be NULL during tests.
4302 RenderWidgetHostViewBase
* rwh_view
;
4303 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4304 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4305 // case this because RWH is still a base class of RenderViewHost, and child
4306 // frame RWHVs are unique in that they do not have their own WebContents.
4307 if (!for_main_frame_navigation
) {
4308 RenderWidgetHostViewChildFrame
* rwh_view_child
=
4309 new RenderWidgetHostViewChildFrame(render_view_host
);
4310 rwh_view
= rwh_view_child
;
4312 rwh_view
= view_
->CreateViewForWidget(render_view_host
, false);
4315 // Now that the RenderView has been created, we need to tell it its size.
4317 rwh_view
->SetSize(GetSizeForNewRenderView());
4319 // Make sure we use the correct starting page_id in the new RenderView.
4320 UpdateMaxPageIDIfNecessary(render_view_host
);
4322 GetMaxPageIDForSiteInstance(render_view_host
->GetSiteInstance());
4324 if (!static_cast<RenderViewHostImpl
*>(
4325 render_view_host
)->CreateRenderView(base::string16(),
4329 created_with_opener_
)) {
4333 SetHistoryOffsetAndLengthForView(render_view_host
,
4334 controller_
.GetLastCommittedEntryIndex(),
4335 controller_
.GetEntryCount());
4337 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
4338 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4339 // linux. See crbug.com/83941.
4341 if (RenderWidgetHost
* render_widget_host
= rwh_view
->GetRenderWidgetHost())
4342 render_widget_host
->WasResized();
4349 bool WebContentsImpl::CreateRenderFrameForRenderManager(
4350 RenderFrameHost
* render_frame_host
,
4351 int parent_routing_id
,
4352 int proxy_routing_id
) {
4353 TRACE_EVENT0("browser,navigation",
4354 "WebContentsImpl::CreateRenderFrameForRenderManager");
4356 RenderFrameHostImpl
* rfh
=
4357 static_cast<RenderFrameHostImpl
*>(render_frame_host
);
4358 if (!rfh
->CreateRenderFrame(parent_routing_id
, proxy_routing_id
))
4361 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4362 // RenderFrameHost will have to be associated with the appropriate
4363 // RenderWidgetHostView or a new one should be created here.
4368 #if defined(OS_ANDROID)
4370 base::android::ScopedJavaLocalRef
<jobject
>
4371 WebContentsImpl::GetJavaWebContents() {
4372 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
4373 return GetWebContentsAndroid()->GetJavaObject();
4376 WebContentsAndroid
* WebContentsImpl::GetWebContentsAndroid() {
4377 WebContentsAndroid
* web_contents_android
=
4378 static_cast<WebContentsAndroid
*>(GetUserData(kWebContentsAndroidKey
));
4379 if (!web_contents_android
) {
4380 web_contents_android
= new WebContentsAndroid(this);
4381 SetUserData(kWebContentsAndroidKey
, web_contents_android
);
4383 return web_contents_android
;
4386 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4387 return CreateRenderViewForRenderManager(GetRenderViewHost(),
4393 #elif defined(OS_MACOSX)
4395 void WebContentsImpl::SetAllowOtherViews(bool allow
) {
4396 view_
->SetAllowOtherViews(allow
);
4399 bool WebContentsImpl::GetAllowOtherViews() {
4400 return view_
->GetAllowOtherViews();
4405 void WebContentsImpl::OnDialogClosed(int render_process_id
,
4406 int render_frame_id
,
4407 IPC::Message
* reply_msg
,
4408 bool dialog_was_suppressed
,
4410 const base::string16
& user_input
) {
4411 RenderFrameHostImpl
* rfh
= RenderFrameHostImpl::FromID(render_process_id
,
4413 last_dialog_suppressed_
= dialog_was_suppressed
;
4415 if (is_showing_before_unload_dialog_
&& !success
) {
4416 // If a beforeunload dialog is canceled, we need to stop the throbber from
4417 // spinning, since we forced it to start spinning in Navigate.
4420 controller_
.DiscardNonCommittedEntries();
4422 FOR_EACH_OBSERVER(WebContentsObserver
, observers_
,
4423 BeforeUnloadDialogCancelled());
4426 is_showing_before_unload_dialog_
= false;
4428 rfh
->JavaScriptDialogClosed(reply_msg
, success
, user_input
,
4429 dialog_was_suppressed
);
4431 // Don't leak the sync IPC reply if the RFH or process is gone.
4436 void WebContentsImpl::SetEncoding(const std::string
& encoding
) {
4437 if (encoding
== last_reported_encoding_
)
4439 last_reported_encoding_
= encoding
;
4441 canonical_encoding_
= GetContentClient()->browser()->
4442 GetCanonicalEncodingNameByAliasName(encoding
);
4445 bool WebContentsImpl::IsHidden() {
4446 return capturer_count_
== 0 && !should_normally_be_visible_
;
4449 RenderFrameHostManager
* WebContentsImpl::GetRenderManager() const {
4450 return frame_tree_
.root()->render_manager();
4453 RenderViewHostImpl
* WebContentsImpl::GetRenderViewHostImpl() {
4454 return static_cast<RenderViewHostImpl
*>(GetRenderViewHost());
4457 BrowserPluginGuest
* WebContentsImpl::GetBrowserPluginGuest() const {
4458 return browser_plugin_guest_
.get();
4461 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest
* guest
) {
4462 CHECK(!browser_plugin_guest_
);
4463 browser_plugin_guest_
.reset(guest
);
4466 BrowserPluginEmbedder
* WebContentsImpl::GetBrowserPluginEmbedder() const {
4467 return browser_plugin_embedder_
.get();
4470 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4471 if (browser_plugin_embedder_
)
4473 browser_plugin_embedder_
.reset(BrowserPluginEmbedder::Create(this));
4476 void WebContentsImpl::ClearPowerSaveBlockers(
4477 RenderFrameHost
* render_frame_host
) {
4478 RemoveAllMediaPlayerEntries(render_frame_host
, &active_audio_players_
);
4479 RemoveAllMediaPlayerEntries(render_frame_host
, &active_video_players_
);
4480 MaybeReleasePowerSaveBlockers();
4483 void WebContentsImpl::ClearAllPowerSaveBlockers() {
4484 active_audio_players_
.clear();
4485 active_video_players_
.clear();
4486 audio_power_save_blocker_
.reset();
4487 video_power_save_blocker_
.reset();
4490 gfx::Size
WebContentsImpl::GetSizeForNewRenderView() {
4493 size
= delegate_
->GetSizeForNewRenderView(this);
4495 size
= GetContainerBounds().size();
4499 void WebContentsImpl::OnFrameRemoved(RenderFrameHost
* render_frame_host
) {
4501 WebContentsObserver
, observers_
, FrameDeleted(render_frame_host
));
4504 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size
& old_size
) {
4507 const gfx::Size new_size
= GetPreferredSize();
4508 if (new_size
!= old_size
)
4509 delegate_
->UpdatePreferredSize(this, new_size
);
4512 void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie
,
4513 ActiveMediaPlayerMap
* player_map
) {
4514 if (!HasValidFrameSource())
4517 const uintptr_t key
=
4518 reinterpret_cast<uintptr_t>(render_frame_message_source_
);
4519 DCHECK(std::find((*player_map
)[key
].begin(),
4520 (*player_map
)[key
].end(),
4521 player_cookie
) == (*player_map
)[key
].end());
4522 (*player_map
)[key
].push_back(player_cookie
);
4525 void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie
,
4526 ActiveMediaPlayerMap
* player_map
) {
4527 if (!HasValidFrameSource())
4530 const uintptr_t key
=
4531 reinterpret_cast<uintptr_t>(render_frame_message_source_
);
4532 ActiveMediaPlayerMap::iterator it
= player_map
->find(key
);
4533 if (it
== player_map
->end())
4536 // Remove the player.
4537 PlayerList::iterator player_it
=
4538 std::find(it
->second
.begin(), it
->second
.end(), player_cookie
);
4539 if (player_it
!= it
->second
.end())
4540 it
->second
.erase(player_it
);
4542 // If there are no players left, remove the map entry.
4543 if (it
->second
.empty())
4544 player_map
->erase(it
);
4547 void WebContentsImpl::RemoveAllMediaPlayerEntries(
4548 RenderFrameHost
* render_frame_host
,
4549 ActiveMediaPlayerMap
* player_map
) {
4550 ActiveMediaPlayerMap::iterator it
=
4551 player_map
->find(reinterpret_cast<uintptr_t>(render_frame_host
));
4552 if (it
== player_map
->end())
4554 player_map
->erase(it
);
4557 void WebContentsImpl::ResumeResponseDeferredAtStart() {
4558 FrameTreeNode
* node
= frame_tree_
.root();
4559 node
->render_manager()->ResumeResponseDeferredAtStart();
4562 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable
) {
4563 force_disable_overscroll_content_
= force_disable
;
4565 view_
->SetOverscrollControllerEnabled(CanOverscrollContent());
4568 } // namespace content