15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/web_contents_impl.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/debug/trace_event.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/lazy_instance.h"
12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/logging.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/metrics/histogram.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/metrics/stats_counters.h"
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/process/process.h"
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_number_conversions.h"
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h"
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
21116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/accessibility/accessibility_mode_helper.h"
22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/accessibility/browser_accessibility_state_impl.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/browser_plugin/browser_plugin_embedder.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/browser_plugin/browser_plugin_guest.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/child_process_security_policy_impl.h"
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/browser/devtools/render_view_devtools_agent_host.h"
27bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/dom_storage/session_storage_namespace_impl.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/download/download_stats.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/download/mhtml_generation_manager.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/download/save_package.h"
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/frame_host/cross_process_frame_connector.h"
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/interstitial_page_impl.h"
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/navigation_entry_impl.h"
35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/navigator_impl.h"
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/render_frame_host_impl.h"
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/browser/geolocation/geolocation_dispatcher_host.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/host_zoom_map_impl.h"
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/loader/resource_dispatcher_host_impl.h"
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/manifest/manifest_manager_host.h"
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/media/audio_stream_monitor.h"
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/media/capture/web_contents_audio_muter.h"
44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "content/browser/media/midi_dispatcher_host.h"
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/browser/message_port_message_filter.h"
468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/browser/message_port_service.h"
47ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "content/browser/power_save_blocker_impl.h"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_process_host_impl.h"
49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/browser/renderer_host/render_view_host_delegate_view.h"
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h"
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_impl.h"
52010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_view_base.h"
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/site_instance_impl.h"
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/web_contents/web_contents_view_guest.h"
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/webui/generic_handler.h"
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/webui/web_ui_controller_factory_registry.h"
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/webui/web_ui_impl.h"
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/common/browser_plugin/browser_plugin_constants.h"
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/common/browser_plugin/browser_plugin_messages.h"
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/common/frame_messages.h"
62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/common/image_messages.h"
63c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "content/common/input_messages.h"
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/ssl_status_serialization.h"
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/view_messages.h"
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/ax_event_notification_details.h"
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_context.h"
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/public/browser/browser_plugin_guest_manager.h"
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/content_browser_client.h"
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/devtools_agent_host.h"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/download_manager.h"
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/download_url_parameters.h"
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/invalidate_type.h"
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/javascript_dialog_manager.h"
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/load_from_memory_cache_details.h"
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/load_notification_details.h"
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_details.h"
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h"
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/browser/render_widget_host_iterator.h"
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/resource_request_details.h"
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/screen_orientation_dispatcher_host.h"
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/storage_partition.h"
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_delegate.h"
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_observer.h"
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/bindings_policy.h"
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_constants.h"
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_switches.h"
9058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch#include "content/public/common/page_zoom.h"
91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/public/common/result_codes.h"
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/url_constants.h"
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/url_utils.h"
94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/common/web_preferences.h"
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/mime_util.h"
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_util.h"
9758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "net/http/http_cache.h"
9858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "net/http/http_transaction_factory.h"
9958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "net/url_request/url_request_context.h"
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_context_getter.h"
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/layout.h"
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h"
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gl/gl_switches.h"
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_ANDROID)
107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/android/content_view_core_impl.h"
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/android/date_time_chooser_android.h"
109010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/browser/media/android/browser_media_player_manager.h"
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/web_contents/web_contents_android.h"
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/browser/android/content_view_core.h"
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_MACOSX)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/mac/foundation_util.h"
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Cross-Site Navigations
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If a WebContentsImpl is told to navigate to a different web site (as
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// determined by SiteInstance), it will replace its current RenderViewHost with
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// a new RenderViewHost dedicated to the new SiteInstance.  This works as
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// follows:
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// - RVHM::Navigate determines whether the destination is cross-site, and if so,
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   it creates a pending_render_view_host_.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// - The pending RVH is "suspended," so that no navigation messages are sent to
1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   its renderer until the beforeunload JavaScript handler has a chance to
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   run in the current RVH.
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   that it has a pending cross-site request.  We will check this on the IO
1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   thread when deciding how to handle the response.
1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// - The current RVH runs its beforeunload handler.  If it returns false, we
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   cancel all the pending logic.  Otherwise we allow the pending RVH to send
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   the navigation request to its renderer.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   main resource load on the pending RVH.  It creates a
1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   CrossSiteResourceHandler to check whether a process swap is needed when
1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   the request is ready to commit.
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// - When RDH receives a response, the BufferedResourceHandler determines
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   whether it is a download.  If so, it sends a message to the new renderer
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   causing it to cancel the request, and the download proceeds. For now, the
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   pending RVH remains until the next DidNavigate event for this
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// - After RDH receives a response and determines that it is safe and not a
1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   download, the CrossSiteResourceHandler checks whether a process swap is
1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   needed (either because CrossSiteRequestManager has state for it or because
1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   a transfer was needed for a redirect).
1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// - If so, CrossSiteResourceHandler pauses the response to first run the old
1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   page's unload handler.  It does this by asynchronously calling the
151f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//   OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
152f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//   which sends a SwapOut message to the current RVH.
1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
1544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   to a new process is needed, based on the stored pending_nav_params_.  (This
1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   is independent of whether we started out with a cross-process navigation.)
1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   - If not, it just tells the ResourceDispatcherHost to resume the response
1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//     to its current RenderViewHost.
1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//   - If so, it cancels the current pending RenderViewHost and sets up a new
1594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//     navigation using RequestTransferURL.  When the transferred request
1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//     arrives in the ResourceDispatcherHost, we transfer the response and
1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//     resume it.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// - The pending renderer sends a FrameNavigate message that invokes the
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   DidNavigate method.  This replaces the current RVH with the
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   pending RVH.
165f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// - The previous renderer is kept swapped out in RenderFrameHostManager in case
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   the user goes back.  The process only stays live if another tab is using
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   it, but if so, the existing frame relationships will be maintained.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
173cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
174cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// This matches what Blink's ProgressTracker has traditionally used for a
175cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// minimum progress value.
176cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)const double kMinimumLoadingProgress = 0.1;
177cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kDotGoogleDotCom[] = ".google.com";
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_ANDROID)
181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const char kWebContentsAndroidKey[] = "web_contents_android";
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // OS_ANDROID
183a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccistatic int StartDownload(RenderFrameHost* rfh,
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                         const GURL& url,
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                         bool is_favicon,
190d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                         uint32_t max_bitmap_size) {
191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static int g_next_image_download_id = 0;
192e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                       ++g_next_image_download_id,
194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                       url,
195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                       is_favicon,
196d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                       max_bitmap_size));
197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return g_next_image_download_id;
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
20058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void NotifyCacheOnIO(
20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    scoped_refptr<net::URLRequestContextGetter> request_context,
20258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const GURL& url,
20358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const std::string& http_method) {
20458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  request_context->GetURLRequestContext()->http_transaction_factory()->
20558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      GetCache()->OnExternalCacheHit(url, http_method);
20658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
20758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Helper function for retrieving all the sites in a frame tree.
2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool CollectSites(BrowserContext* context,
2104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                  std::set<GURL>* sites,
2114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                  FrameTreeNode* node) {
2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
2134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return true;
2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool ForEachFrameInternal(
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::Callback<void(RenderFrameHost*)>& on_frame,
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FrameTreeNode* node) {
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  on_frame.Run(node->current_frame_host());
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
223116680a4aac90f2aa7413d9095a592090648e557Ben Murdochbool ForEachPendingFrameInternal(
224116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const base::Callback<void(RenderFrameHost*)>& on_frame,
225116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    FrameTreeNode* node) {
226116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderFrameHost* pending_frame_host =
227116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      node->render_manager()->pending_frame_host();
228116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (pending_frame_host)
229116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    on_frame.Run(pending_frame_host);
230116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return true;
231116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
232116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  IPC::Message* message_copy = new IPC::Message(*message);
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  message_copy->set_routing_id(rfh->GetRoutingID());
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  rfh->Send(message_copy);
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
239f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
240f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                  RenderFrameHost* rfh) {
241f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
242f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   ->frame_tree_node()
243f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   ->render_manager()
244f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   ->GetRenderWidgetHostView();
245f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  set->insert(rwhv);
246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
248116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid SetAccessibilityModeOnFrame(AccessibilityMode mode,
249116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                 RenderFrameHost* frame_host) {
250116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
251116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
252116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebContents* WebContents::Create(const WebContents::CreateParams& params) {
256a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return WebContentsImpl::CreateWithOpener(
257a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      params, static_cast<WebContentsImpl*>(params.opener));
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContents* WebContents::CreateWithSessionStorage(
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WebContents::CreateParams& params,
262ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    const SessionStorageNamespaceMap& session_storage_namespace_map) {
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContentsImpl* new_contents = new WebContentsImpl(
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      params.browser_context, NULL);
265ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
266ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  for (SessionStorageNamespaceMap::const_iterator it =
267ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch           session_storage_namespace_map.begin();
268ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch       it != session_storage_namespace_map.end();
269ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch       ++it) {
270ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    new_contents->GetController()
271ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        .SetSessionStorageNamespace(it->first, it->second.get());
272ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
273ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  new_contents->Init(params);
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new_contents;
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
278f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
279868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  g_created_callbacks.Get().push_back(callback);
280868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
281868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
282f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if (g_created_callbacks.Get().at(i).Equals(callback)) {
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      return;
287868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    }
288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
289868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
290868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return rvh->GetDelegate()->GetAsWebContents();
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!rfh_impl)
2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return NULL;
2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return rfh_impl->delegate()->GetAsWebContents();
3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
30290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// WebContentsImpl::DestructionObserver ----------------------------------------
30390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
30490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class WebContentsImpl::DestructionObserver : public WebContentsObserver {
30590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public:
30690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
30790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      : WebContentsObserver(watched_contents),
30890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        owner_(owner) {
30990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
31090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
31190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // WebContentsObserver:
312010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void WebContentsDestroyed() OVERRIDE {
313010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    owner_->OnWebContentsDestroyed(
314010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        static_cast<WebContentsImpl*>(web_contents()));
31590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
31690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
31790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private:
31890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  WebContentsImpl* owner_;
31990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
32090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
32190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
32290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
323a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochWebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
324a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                                    int render_frame_id,
325a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                                    ColorChooser* chooser,
326a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                                    int identifier)
327a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    : render_process_id(render_process_id),
328a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      render_frame_id(render_frame_id),
329a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      chooser(chooser),
330a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      identifier(identifier) {
331a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
332a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
333a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochWebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
334a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
335a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsImpl -------------------------------------------------------------
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsImpl::WebContentsImpl(
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BrowserContext* browser_context,
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WebContentsImpl* opener)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : delegate_(NULL),
342c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller_(this, browser_context),
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      render_view_host_delegate_view_(NULL),
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      opener_(opener),
3450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      created_with_opener_(!!opener),
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_WIN)
347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      accessible_parent_(NULL),
348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      frame_tree_(new NavigatorImpl(&controller_, this),
350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                  this, this, this, this),
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_loading_(false),
352cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      is_load_to_different_document_(false),
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      crashed_error_code_(0),
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      waiting_for_response_(false),
356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      load_state_(net::LOAD_STATE_IDLE, base::string16()),
357cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      loading_total_progress_(0.0),
358cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      loading_frames_in_progress_(0),
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      upload_size_(0),
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      upload_position_(0),
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      displayed_insecure_content_(false),
3625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      has_accessed_initial_document_(false),
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      capturer_count_(0),
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      should_normally_be_visible_(true),
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_being_destroyed_(false),
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      notify_disconnection_(false),
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      dialog_manager_(NULL),
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_showing_before_unload_dialog_(false),
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      last_active_time_(base::TimeTicks::Now()),
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      closed_by_user_gesture_(false),
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
373effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      totalPinchGestureAmount_(0),
374effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      currentPinchZoomStepDelta_(0),
375a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      render_view_message_source_(NULL),
3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
377116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      fullscreen_widget_had_focus_at_shutdown_(false),
378c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      is_subframe_(false),
37903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      force_disable_overscroll_content_(false),
380116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      last_dialog_suppressed_(false),
381116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      accessibility_mode_(
3821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
3831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      audio_stream_monitor_(this),
3841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      loading_weak_factory_(this) {
385868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
386868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    g_created_callbacks.Get().at(i).Run(this);
3874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  frame_tree_.SetFrameRemoveListener(
3884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      base::Bind(&WebContentsImpl::OnFrameRemoved,
3894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                 base::Unretained(this)));
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsImpl::~WebContentsImpl() {
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  is_being_destroyed_ = true;
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Delete all RFH pending shutdown, which will lead the corresponding RVH to
396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // shutdown and be deleted as well.
397a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  frame_tree_.ForEach(
398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
400ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  ClearAllPowerSaveBlockers();
401ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (std::set<RenderWidgetHostImpl*>::iterator iter =
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    (*iter)->DetachDelegate();
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  created_widgets_.clear();
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Clear out any JavaScript state.
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dialog_manager_)
410a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    dialog_manager_->WebContentsDestroyed(this);
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
412a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (color_chooser_info_.get())
413a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    color_chooser_info_->chooser->End();
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifyDisconnected();
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notify any observer that have a reference on this WebContents.
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotificationService::current()->Notify(
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NOTIFICATION_WEB_CONTENTS_DESTROYED,
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Source<WebContents>(this),
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NotificationService::NoDetails());
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
423cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Destroy all frame tree nodes except for the root; this notifies observers.
424cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  frame_tree_.ResetForMainFrameSwap();
425cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  GetRenderManager()->ResetProxyHosts();
426a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
427cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Manually call the observer methods for the root frame tree node.
428cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  RenderFrameHostManager* root = GetRenderManager();
429cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (root->pending_frame_host()) {
4308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FOR_EACH_OBSERVER(WebContentsObserver,
4318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                      observers_,
432cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                      RenderFrameDeleted(root->pending_frame_host()));
4338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
434cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FOR_EACH_OBSERVER(WebContentsObserver,
435cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                    observers_,
436cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                    RenderFrameDeleted(root->current_frame_host()));
4378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
438cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (root->pending_render_view_host()) {
439cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    FOR_EACH_OBSERVER(WebContentsObserver,
440cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                      observers_,
441cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                      RenderViewDeleted(root->pending_render_view_host()));
442cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
443a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
4448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  FOR_EACH_OBSERVER(WebContentsObserver,
4458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    observers_,
446cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                    RenderViewDeleted(root->current_host()));
4478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(WebContentsObserver,
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    observers_,
450010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    WebContentsDestroyed());
451010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
452010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  FOR_EACH_OBSERVER(WebContentsObserver,
453010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    observers_,
454010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    ResetWebContents());
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetDelegate(NULL);
45790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
45890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
45990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                       destruction_observers_.end());
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsImpl* WebContentsImpl::CreateWithOpener(
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WebContents::CreateParams& params,
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WebContentsImpl* opener) {
4657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContentsImpl* new_contents = new WebContentsImpl(
467cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      params.browser_context, params.opener_suppressed ? NULL : opener);
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
469116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (params.guest_delegate) {
470cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // This makes |new_contents| act as a guest.
471cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // For more info, see comment above class BrowserPluginGuest.
47203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    BrowserPluginGuest::Create(new_contents, params.guest_delegate);
473cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // We are instantiating a WebContents for browser plugin. Set its subframe
474cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // bit to true.
475cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    new_contents->is_subframe_ = true;
476cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  new_contents->Init(params);
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new_contents;
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
481116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// static
482116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstd::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
483116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  std::vector<WebContentsImpl*> result;
484116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<RenderWidgetHostIterator> widgets(
485116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      RenderWidgetHostImpl::GetRenderWidgetHosts());
486116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  std::set<WebContentsImpl*> web_contents_set;
487116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
488116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (!rwh->IsRenderView())
489116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      continue;
490116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    RenderViewHost* rvh = RenderViewHost::From(rwh);
491116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (!rvh)
492116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      continue;
493116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
494116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (!web_contents)
495116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      continue;
496116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
497116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (web_contents_set.find(wci) == web_contents_set.end()) {
498116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      web_contents_set.insert(wci);
499116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      result.push_back(wci);
500116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    }
501116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
502116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return result;
503116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
504116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
505f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
506f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return GetRenderManager();
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        const IPC::Message& message) {
511a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return OnMessageReceived(render_view_host, NULL, message);
512a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
513a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
514a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
515a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                        RenderFrameHost* render_frame_host,
516a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                        const IPC::Message& message) {
517a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DCHECK(render_view_host || render_frame_host);
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetWebUI() &&
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ObserverListBase<WebContentsObserver>::Iterator it(observers_);
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsObserver* observer;
525cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (render_frame_host) {
526cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    while ((observer = it.GetNext()) != NULL)
527cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      if (observer->OnMessageReceived(message, render_frame_host))
528cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        return true;
529cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  } else {
530cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    while ((observer = it.GetNext()) != NULL)
531cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      if (observer->OnMessageReceived(message))
532cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        return true;
533cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Message handlers should be aware of which
5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // RenderViewHost/RenderFrameHost sent the message, which is temporarily
5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // stored in render_(view|frame)_message_source_.
5386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (render_frame_host)
5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    render_frame_message_source_ = render_frame_host;
5406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  else
5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    render_view_message_source_ = render_view_host;
5425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool handled = true;
544cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
545a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
547a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
548a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        OnDomOperationResponse)
549116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
550116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        OnThemeColorChanged)
551a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
552a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                        OnDocumentLoadedInFrame)
553a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
554cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
555cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
556cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
557cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                        OnDidChangeLoadProgress)
558a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
559a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
560a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
561a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                        OnSetSelectedColorInColorChooser)
562010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
563010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        OnMediaPlayingNotification)
564010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
565010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        OnMediaPausedNotification)
5665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
5675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                        OnFirstVisuallyNonEmptyPaint)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        OnDidLoadResourceFromMemoryCache)
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        OnDidDisplayInsecureContent)
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        OnDidRunInsecureContent)
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        OnRegisterProtocolHandler)
579116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
580116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        OnUnregisterProtocolHandler)
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
5841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(ENABLE_PLUGINS)
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        OnRequestPpapiBrokerPermission)
5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                OnBrowserPluginMessage(message))
5891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        OnShowValidationMessage)
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        OnHideValidationMessage)
5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        OnMoveValidationMessage)
598a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(OS_ANDROID)
599a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
600a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                        OnFindMatchRectsReply)
601a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
602a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                        OnOpenDateTimeDialog)
603a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#endif
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_UNHANDLED(handled = false)
605cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  IPC_END_MESSAGE_MAP()
606a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  render_view_message_source_ = NULL;
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  render_frame_message_source_ = NULL;
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return handled;
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsImpl::RunFileChooser(
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RenderViewHost* render_view_host,
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const FileChooserParams& params) {
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (delegate_)
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate_->RunFileChooser(this, params);
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NavigationControllerImpl& WebContentsImpl::GetController() {
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return controller_;
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const NavigationControllerImpl& WebContentsImpl::GetController() const {
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return controller_;
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BrowserContext* WebContentsImpl::GetBrowserContext() const {
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return controller_.GetBrowserContext();
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const GURL& WebContentsImpl::GetURL() const {
63290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // We may not have a navigation entry yet.
633868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  NavigationEntry* entry = controller_.GetVisibleEntry();
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
637ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochconst GURL& WebContentsImpl::GetVisibleURL() const {
63890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // We may not have a navigation entry yet.
639868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  NavigationEntry* entry = controller_.GetVisibleEntry();
64090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
64190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
64290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
64390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const GURL& WebContentsImpl::GetLastCommittedURL() const {
64490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // We may not have a navigation entry yet.
64590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NavigationEntry* entry = controller_.GetLastCommittedEntry();
64690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
64790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
64890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsDelegate* WebContentsImpl::GetDelegate() {
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return delegate_;
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(cbentzel): remove this debugging code?
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (delegate == delegate_)
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (delegate_)
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate_->Detach(this);
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  delegate_ = delegate;
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (delegate_) {
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate_->Attach(this);
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Ensure the visible RVH reflects the new delegate's preferences.
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (view_)
664f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      view_->SetOverscrollControllerEnabled(CanOverscrollContent());
6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
669f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RenderViewHostImpl* host = GetRenderManager()->current_host();
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return host ? host->GetProcess() : NULL;
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
673a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)RenderFrameHost* WebContentsImpl::GetMainFrame() {
6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return frame_tree_.root()->current_frame_host();
6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
677a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
678a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!frame_tree_.GetFocusedFrame())
679a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return NULL;
680a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return frame_tree_.GetFocusedFrame()->current_frame_host();
681a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
682a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WebContentsImpl::ForEachFrame(
6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::Callback<void(RenderFrameHost*)>& on_frame) {
6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  delete message;
691a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
692a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
694f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return GetRenderManager()->current_host();
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int WebContentsImpl::GetRoutingID() const {
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!GetRenderViewHost())
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return MSG_ROUTING_NONE;
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetRenderViewHost()->GetRoutingID();
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return fullscreen_widget_routing_id_;
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
709f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return GetRenderManager()->GetRenderWidgetHostView();
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
712d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
713d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const {
714d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  RenderWidgetHost* const widget_host =
715d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
716d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                   GetFullscreenWidgetRoutingID());
717d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return widget_host ? widget_host->GetView() : NULL;
718d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
719d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsView* WebContentsImpl::GetView() const {
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return view_.get();
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
724116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
725116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (mode == accessibility_mode_)
726116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return;
727116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
728116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  accessibility_mode_ = mode;
729116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  frame_tree_.ForEach(
730116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::Bind(&ForEachFrameInternal,
731116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                 base::Bind(&SetAccessibilityModeOnFrame, mode)));
732116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  frame_tree_.ForEach(
733116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::Bind(&ForEachPendingFrameInternal,
734116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                 base::Bind(&SetAccessibilityModeOnFrame, mode)));
735116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
736116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
737116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
7381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
739116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
740116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
741116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
7421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
743116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
744116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebUIImpl* web_ui = new WebUIImpl(this);
7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      CreateWebUIControllerForURL(web_ui, url);
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (controller) {
7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    web_ui->AddMessageHandler(new GenericHandler());
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    web_ui->SetController(controller);
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return web_ui;
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  delete web_ui;
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NULL;
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebUI* WebContentsImpl::GetWebUI() const {
760f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
761f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      : GetRenderManager()->pending_web_ui();
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebUI* WebContentsImpl::GetCommittedWebUI() const {
765f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return GetRenderManager()->web_ui();
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetUserAgentOverride() == override)
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  renderer_preferences_.user_agent_override = override;
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Send the new override string to the renderer.
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHost* host = GetRenderViewHost();
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (host)
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    host->SyncRendererPrefs();
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reload the page if a load is currently in progress to avoid having
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // different parts of the page loaded using different user agents.
7814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  NavigationEntry* entry = controller_.GetVisibleEntry();
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    controller_.ReloadIgnoringCache(true);
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(WebContentsObserver, observers_,
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    UserAgentOverrideSet(override));
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const std::string& WebContentsImpl::GetUserAgentOverride() const {
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return renderer_preferences_.user_agent_override;
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
793116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
794116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  AddAccessibilityMode(AccessibilityModeTreeOnly);
795116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
796116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
797116680a4aac90f2aa7413d9095a592090648e557Ben Murdochbool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
798116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return accessibility_mode_ == AccessibilityModeTreeOnly;
799116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
800116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
801116680a4aac90f2aa7413d9095a592090648e557Ben Murdochbool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
802116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return accessibility_mode_ == AccessibilityModeComplete;
803116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
804116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_WIN)
806c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void WebContentsImpl::SetParentNativeViewAccessible(
807c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)gfx::NativeViewAccessible accessible_parent) {
808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  accessible_parent_ = accessible_parent;
809116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
810116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (rfh)
811116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    rfh->SetParentNativeViewAccessible(accessible_parent);
812c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
813c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
814c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
815a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const base::string16& WebContentsImpl::GetTitle() const {
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Transient entries take precedence. They are used for interstitial pages
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that are shown on top of existing pages.
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationEntry* entry = controller_.GetTransientEntry();
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string accept_languages =
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetContentClient()->browser()->GetAcceptLangs(
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          GetBrowserContext());
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (entry) {
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return entry->GetTitleForDisplay(accept_languages);
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
825f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
826f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (our_web_ui) {
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Don't override the title in view source mode.
829868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    entry = controller_.GetVisibleEntry();
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!(entry && entry->IsViewSourceMode())) {
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Give the Web UI the chance to override our title.
832a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const base::string16& title = our_web_ui->GetOverriddenTitle();
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (!title.empty())
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return title;
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We use the title for the last committed entry rather than a pending
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // navigation entry. For example, when the user types in a URL, we want to
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // keep the old page's title until the new load has committed and we get a new
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // title.
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  entry = controller_.GetLastCommittedEntry();
843868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
844f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // We make an exception for initial navigations.
845f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (controller_.IsInitialNavigation()) {
846f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // We only want to use the title from the visible entry in one of two cases:
847f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // 1. There's already a committed entry for an initial navigation, in which
848f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    //    case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
849f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // 2. The pending entry has been explicitly assigned a title to display.
850f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    //
851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // If there's no last committed entry and no assigned title, we should fall
852f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // back to |page_title_when_no_navigation_entry_| rather than showing the
853f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // URL.
854f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (entry ||
855f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        (controller_.GetVisibleEntry() &&
856f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)         !controller_.GetVisibleEntry()->GetTitle().empty())) {
857f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      entry = controller_.GetVisibleEntry();
858f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
859f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
860868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (entry) {
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return entry->GetTitleForDisplay(accept_languages);
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |page_title_when_no_navigation_entry_| is finally used
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if no title cannot be retrieved.
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return page_title_when_no_navigation_entry_;
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32 WebContentsImpl::GetMaxPageID() {
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetMaxPageIDForSiteInstance(GetSiteInstance());
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SiteInstance* site_instance) {
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    max_page_ids_[site_instance->GetId()] = -1;
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return max_page_ids_[site_instance->GetId()];
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SiteInstance* site_instance, int32 page_id) {
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    max_page_ids_[site_instance->GetId()] = page_id;
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
8931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
8941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  max_page_ids_ = contents->max_page_ids_;
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SiteInstance* WebContentsImpl::GetSiteInstance() const {
898f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return GetRenderManager()->current_host()->GetSiteInstance();
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
902f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
903f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetRenderManager()->pending_render_view_host() :
904f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetRenderManager()->current_host();
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return dest_rvh->GetSiteInstance();
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsImpl::IsLoading() const {
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return is_loading_;
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
912cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool WebContentsImpl::IsLoadingToDifferentDocument() const {
913cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return is_loading_ && is_load_to_different_document_;
914cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
915cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsImpl::IsWaitingForResponse() const {
917cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return waiting_for_response_ && is_load_to_different_document_;
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return load_state_;
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
924a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const base::string16& WebContentsImpl::GetLoadStateHost() const {
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return load_state_host_;
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)uint64 WebContentsImpl::GetUploadSize() const {
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return upload_size_;
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)uint64 WebContentsImpl::GetUploadPosition() const {
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return upload_position_;
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)std::set<GURL> WebContentsImpl::GetSitesInTab() const {
9377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::set<GURL> sites;
9385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_.ForEach(base::Bind(&CollectSites,
9395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Unretained(GetBrowserContext()),
9405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Unretained(&sites)));
9417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return sites;
9427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
9437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const std::string& WebContentsImpl::GetEncoding() const {
945cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return canonical_encoding_;
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsImpl::DisplayedInsecureContent() const {
9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return displayed_insecure_content_;
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
9532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(!is_being_destroyed_);
9542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ++capturer_count_;
9552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DVLOG(1) << "There are now " << capturer_count_
9562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           << " capturing(s) of WebContentsImpl@" << this;
9575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note: This provides a hint to upstream code to size the views optimally
9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // for quality (e.g., to avoid scaling).
9605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    preferred_size_for_capture_ = capture_size;
9625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    OnPreferredSizeChanged(preferred_size_);
9635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7