This source file includes following definitions.
- StartDownload
- NotifyCacheOnIO
- CollectSites
- ForEachFrameInternal
- ForEachPendingFrameInternal
- SendToAllFramesInternal
- RunRenderFrameDeleted
- Create
- CreateWithSessionStorage
- AddCreatedCallback
- RemoveCreatedCallback
- FromRenderViewHost
- FromRenderFrameHost
- owner_
- WebContentsDestroyed
- is_subframe_
- CreateWithOpener
- CreateGuest
- GetRenderManagerForTesting
- OnMessageReceived
- OnMessageReceived
- RunFileChooser
- GetController
- GetController
- GetBrowserContext
- GetURL
- GetVisibleURL
- GetLastCommittedURL
- GetDelegate
- SetDelegate
- GetRenderProcessHost
- GetMainFrame
- GetFocusedFrame
- ForEachFrame
- SendToAllFrames
- GetRenderViewHost
- GetEmbedderWebContents
- GetEmbeddedInstanceID
- GetRoutingID
- GetFullscreenWidgetRoutingID
- GetRenderWidgetHostView
- GetRenderWidgetHostViewPort
- GetFullscreenRenderWidgetHostView
- GetView
- CreateWebUI
- GetWebUI
- GetCommittedWebUI
- SetUserAgentOverride
- GetUserAgentOverride
- SetParentNativeViewAccessible
- GetTitle
- GetMaxPageID
- GetMaxPageIDForSiteInstance
- UpdateMaxPageID
- UpdateMaxPageIDForSiteInstance
- CopyMaxPageIDsFrom
- GetSiteInstance
- GetPendingSiteInstance
- IsLoading
- IsWaitingForResponse
- GetLoadState
- GetLoadStateHost
- GetUploadSize
- GetUploadPosition
- GetSitesInTab
- GetEncoding
- DisplayedInsecureContent
- IncrementCapturerCount
- DecrementCapturerCount
- GetCapturerCount
- IsCrashed
- SetIsCrashed
- GetCrashedStatus
- IsBeingDestroyed
- NotifyNavigationStateChanged
- GetLastActiveTime
- WasShown
- WasHidden
- NeedToFireBeforeUnload
- Stop
- Clone
- Observe
- GetWebContents
- Init
- OnWebContentsDestroyed
- AddDestructionObserver
- RemoveDestructionObserver
- AddObserver
- RemoveObserver
- Activate
- Deactivate
- LostCapture
- RenderWidgetDeleted
- PreHandleKeyboardEvent
- HandleKeyboardEvent
- HandleWheelEvent
- PreHandleGestureEvent
- HandleGestureEvent
- GetParentNativeViewAccessible
- HandleMouseDown
- HandleMouseUp
- HandlePointerActivate
- HandleGestureBegin
- HandleGestureEnd
- ToggleFullscreenMode
- IsFullscreenForCurrentTab
- RequestToLockMouse
- LostMouseLock
- CreateNewWindow
- CreateNewWidget
- CreateNewFullscreenWidget
- CreateNewWidget
- ShowCreatedWindow
- ShowCreatedWidget
- ShowCreatedFullscreenWidget
- ShowCreatedWidget
- GetCreatedWindow
- GetCreatedWidget
- RequestMediaAccessPermission
- GetSessionStorageNamespace
- GetFrameTree
- AccessibilityEventReceived
- OnShowValidationMessage
- OnHideValidationMessage
- OnMoveValidationMessage
- DidSendScreenRects
- UpdatePreferredSize
- ResizeDueToAutoResize
- OpenURL
- Send
- NavigateToPendingEntry
- RenderFrameForInterstitialPageCreated
- AttachInterstitialPage
- DetachInterstitialPage
- SetHistoryLengthAndPrune
- ReloadFocusedFrame
- Replace
- ReplaceMisspelling
- FocusThroughTabTraversal
- ShowingInterstitialPage
- GetInterstitialPage
- IsSavable
- OnSavePage
- SavePage
- SaveFrame
- GenerateMHTML
- IsActiveEntry
- GetContentsMimeType
- WillNotifyDisconnection
- SetOverrideEncoding
- ResetOverrideEncoding
- GetMutableRendererPrefs
- Close
- DragSourceEndedAt
- DidGetResourceResponseStart
- DidGetRedirectForResourceRequest
- SystemDragEnded
- UserGestureDone
- SetClosedByUserGesture
- GetClosedByUserGesture
- GetZoomLevel
- GetZoomPercent
- ViewSource
- ViewFrameSource
- GetMinimumZoomPercent
- GetMaximumZoomPercent
- GetPreferredSize
- GotResponseToLockMouseRequest
- HasOpener
- DidChooseColorInColorChooser
- DidEndColorChooser
- DownloadImage
- IsSubframe
- SetZoomLevel
- Find
- StopFinding
- FocusLocationBarByDefault
- SetFocusToLocationBar
- DidStartProvisionalLoad
- DidFailProvisionalLoadWithError
- DidFailLoadWithError
- NotifyChangedNavigationState
- AboutToNavigateRenderFrame
- DidStartNavigationToPendingEntry
- RequestOpenURL
- DidRedirectProvisionalLoad
- DidCommitProvisionalLoad
- DidNavigateMainFramePreCommit
- DidNavigateMainFramePostCommit
- DidNavigateAnyFramePostCommit
- SetMainFrameMimeType
- CanOverscrollContent
- OnDidLoadResourceFromMemoryCache
- OnDidDisplayInsecureContent
- OnDidRunInsecureContent
- OnDocumentLoadedInFrame
- OnDidFinishLoad
- OnGoToEntryAtOffset
- OnUpdateZoomLimits
- OnEnumerateDirectory
- OnRegisterProtocolHandler
- OnFindReply
- OnFindMatchRectsReply
- OnOpenDateTimeDialog
- OnJavaBridgeGetChannelHandle
- OnPepperPluginHung
- OnPluginCrashed
- OnDomOperationResponse
- OnAppCacheAccessed
- OnOpenColorChooser
- OnEndColorChooser
- OnSetSelectedColorInColorChooser
- OnWebUISend
- OnRequestPpapiBrokerPermission
- OnPpapiBrokerPermissionResult
- OnBrowserPluginMessage
- OnDidDownloadImage
- OnUpdateFaviconURL
- OnMediaPlayingNotification
- OnMediaPausedNotification
- OnFirstVisuallyNonEmptyPaint
- DidChangeVisibleSSLState
- NotifyBeforeFormRepostWarningShow
- ActivateAndShowRepostFormWarningDialog
- SetIsLoading
- UpdateMaxPageIDIfNecessary
- UpdateTitleForEntry
- NotifySwapped
- NotifyDisconnected
- NotifyNavigationEntryCommitted
- OnMessageReceived
- GetMainFrameLastCommittedURL
- RenderFrameCreated
- RenderFrameDeleted
- WorkerCrashed
- ShowContextMenu
- GetAsWebContents
- GetDelegateView
- GetRendererPrefs
- GetRootWindowResizerRect
- RemoveBrowserPluginEmbedder
- RenderViewCreated
- RenderViewReady
- RenderViewTerminated
- RenderViewDeleted
- UpdateState
- UpdateTitle
- UpdateEncoding
- UpdateTargetURL
- Close
- SwappedOut
- RequestMove
- DidStartLoading
- DidStopLoading
- DidCancelLoading
- DidChangeLoadProgress
- DidDisownOpener
- DidAccessInitialDocument
- DocumentAvailableInMainFrame
- DocumentOnLoadCompletedInMainFrame
- RouteCloseEvent
- RouteMessageEvent
- RunJavaScriptMessage
- RunBeforeUnloadConfirm
- AddMessageToConsole
- GetWebkitPrefs
- CreateSwappedOutRenderView
- OnUserGesture
- OnIgnoredUIEvent
- RendererUnresponsive
- RendererResponsive
- LoadStateChanged
- BeforeUnloadFiredFromRenderManager
- RenderProcessGoneFromRenderManager
- UpdateRenderViewSizeForRenderManager
- CancelModalDialogsForRenderManager
- NotifySwappedFromRenderManager
- CreateOpenerRenderViewsForRenderManager
- CreateOpenerRenderViews
- GetControllerForRenderManager
- CreateWebUIForRenderManager
- GetLastCommittedNavigationEntryForRenderManager
- CreateRenderViewForRenderManager
- GetJavaWebContents
- CreateRenderViewForInitialEmptyDocument
- OnDialogClosed
- SetEncoding
- CreateViewAndSetSizeForRVH
- IsHidden
- GetRenderManager
- GetRenderViewHostImpl
- GetBrowserPluginGuest
- SetBrowserPluginGuest
- GetBrowserPluginEmbedder
- GetBrowserPluginGuestManager
- ClearPowerSaveBlockers
- ClearAllPowerSaveBlockers
- GetSizeForNewRenderView
- OnFrameRemoved
- OnPreferredSizeChanged
#include "content/browser/web_contents/web_contents_impl.h"
#include <utility>
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/stats_counters.h"
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "content/browser/browser_plugin/browser_plugin_embedder.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/render_view_devtools_agent_host.h"
#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
#include "content/browser/dom_storage/session_storage_namespace_impl.h"
#include "content/browser/download/download_stats.h"
#include "content/browser/download/mhtml_generation_manager.h"
#include "content/browser/download/save_package.h"
#include "content/browser/frame_host/cross_process_frame_connector.h"
#include "content/browser/frame_host/interstitial_page_impl.h"
#include "content/browser/frame_host/navigation_entry_impl.h"
#include "content/browser/frame_host/navigator_impl.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
#include "content/browser/host_zoom_map_impl.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/message_port_message_filter.h"
#include "content/browser/message_port_service.h"
#include "content/browser/power_save_blocker_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/web_contents/web_contents_view_guest.h"
#include "content/browser/webui/generic_handler.h"
#include "content/browser/webui/web_ui_controller_factory_registry.h"
#include "content/browser/webui/web_ui_impl.h"
#include "content/common/browser_plugin/browser_plugin_constants.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/image_messages.h"
#include "content/common/input_messages.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_view_host_delegate_view.h"
#include "content/port/browser/render_widget_host_view_port.h"
#include "content/public/browser/ax_event_notification_details.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/color_chooser.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_url_parameters.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/load_from_memory_cache_details.h"
#include "content/public/browser/load_notification_details.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/resource_request_details.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/page_zoom.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
#include "net/http/http_cache.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "ui/base/layout.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/gl/gl_switches.h"
#include "webkit/common/webpreferences.h"
#if defined(OS_ANDROID)
#include "content/browser/android/date_time_chooser_android.h"
#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
#include "content/browser/web_contents/web_contents_android.h"
#include "content/common/java_bridge_messages.h"
#include "content/public/browser/android/content_view_core.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac/foundation_util.h"
#include "ui/gl/io_surface_support_mac.h"
#endif
namespace content {
namespace {
const char kDotGoogleDotCom[] = ".google.com";
#if defined(OS_ANDROID)
const char kWebContentsAndroidKey[] = "web_contents_android";
#endif
base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
static int StartDownload(content::RenderFrameHost* rfh,
const GURL& url,
bool is_favicon,
uint32_t max_bitmap_size) {
static int g_next_image_download_id = 0;
rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
++g_next_image_download_id,
url,
is_favicon,
max_bitmap_size));
return g_next_image_download_id;
}
void NotifyCacheOnIO(
scoped_refptr<net::URLRequestContextGetter> request_context,
const GURL& url,
const std::string& http_method) {
request_context->GetURLRequestContext()->http_transaction_factory()->
GetCache()->OnExternalCacheHit(url, http_method);
}
bool CollectSites(BrowserContext* context,
std::set<GURL>* sites,
FrameTreeNode* node) {
sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
return true;
}
bool ForEachFrameInternal(
const base::Callback<void(RenderFrameHost*)>& on_frame,
FrameTreeNode* node) {
on_frame.Run(node->current_frame_host());
return true;
}
bool ForEachPendingFrameInternal(
const base::Callback<void(RenderFrameHost*)>& on_frame,
FrameTreeNode* node) {
RenderFrameHost* pending_frame_host =
node->render_manager()->pending_frame_host();
if (pending_frame_host)
on_frame.Run(pending_frame_host);
return true;
}
void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
IPC::Message* message_copy = new IPC::Message(*message);
message_copy->set_routing_id(rfh->GetRoutingID());
rfh->Send(message_copy);
}
void RunRenderFrameDeleted(
ObserverList<WebContentsObserver>* observer_list,
RenderFrameHost* render_frame_host) {
FOR_EACH_OBSERVER(WebContentsObserver,
*observer_list,
RenderFrameDeleted(render_frame_host));
}
}
WebContents* WebContents::Create(const WebContents::CreateParams& params) {
return WebContentsImpl::CreateWithOpener(
params, static_cast<WebContentsImpl*>(params.opener));
}
WebContents* WebContents::CreateWithSessionStorage(
const WebContents::CreateParams& params,
const SessionStorageNamespaceMap& session_storage_namespace_map) {
WebContentsImpl* new_contents = new WebContentsImpl(
params.browser_context, NULL);
for (SessionStorageNamespaceMap::const_iterator it =
session_storage_namespace_map.begin();
it != session_storage_namespace_map.end();
++it) {
new_contents->GetController()
.SetSessionStorageNamespace(it->first, it->second.get());
}
new_contents->Init(params);
return new_contents;
}
void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
g_created_callbacks.Get().push_back(callback);
}
void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
if (g_created_callbacks.Get().at(i).Equals(callback)) {
g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
return;
}
}
}
WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
return rvh->GetDelegate()->GetAsWebContents();
}
WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
if (!rfh_impl)
return NULL;
return rfh_impl->delegate()->GetAsWebContents();
}
class WebContentsImpl::DestructionObserver : public WebContentsObserver {
public:
DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
: WebContentsObserver(watched_contents),
owner_(owner) {
}
virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
}
private:
WebContentsImpl* owner_;
DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
};
WebContentsImpl::WebContentsImpl(
BrowserContext* browser_context,
WebContentsImpl* opener)
: delegate_(NULL),
controller_(this, browser_context),
render_view_host_delegate_view_(NULL),
opener_(opener),
#if defined(OS_WIN)
accessible_parent_(NULL),
#endif
frame_tree_(new NavigatorImpl(&controller_, this),
this, this, this, this),
is_loading_(false),
crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
crashed_error_code_(0),
waiting_for_response_(false),
load_state_(net::LOAD_STATE_IDLE, base::string16()),
upload_size_(0),
upload_position_(0),
displayed_insecure_content_(false),
capturer_count_(0),
should_normally_be_visible_(true),
is_being_destroyed_(false),
notify_disconnection_(false),
dialog_manager_(NULL),
is_showing_before_unload_dialog_(false),
last_active_time_(base::TimeTicks::Now()),
closed_by_user_gesture_(false),
minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
temporary_zoom_settings_(false),
totalPinchGestureAmount_(0),
currentPinchZoomStepDelta_(0),
color_chooser_identifier_(0),
render_view_message_source_(NULL),
fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
is_subframe_(false) {
for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
g_created_callbacks.Get().at(i).Run(this);
frame_tree_.SetFrameRemoveListener(
base::Bind(&WebContentsImpl::OnFrameRemoved,
base::Unretained(this)));
}
WebContentsImpl::~WebContentsImpl() {
is_being_destroyed_ = true;
frame_tree_.ForEach(
base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
ClearAllPowerSaveBlockers();
for (std::set<RenderWidgetHostImpl*>::iterator iter =
created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
(*iter)->DetachDelegate();
}
created_widgets_.clear();
if (dialog_manager_)
dialog_manager_->WebContentsDestroyed(this);
if (color_chooser_)
color_chooser_->End();
NotifyDisconnected();
NotificationService::current()->Notify(
NOTIFICATION_WEB_CONTENTS_DESTROYED,
Source<WebContents>(this),
NotificationService::NoDetails());
base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
run_render_frame_deleted_callback));
RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
if (pending_rvh) {
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
RenderViewDeleted(pending_rvh));
}
ForEachFrame(run_render_frame_deleted_callback);
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
RenderViewDeleted(GetRenderManager()->current_host()));
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
WebContentsImplDestroyed());
SetDelegate(NULL);
STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
destruction_observers_.end());
}
WebContentsImpl* WebContentsImpl::CreateWithOpener(
const WebContents::CreateParams& params,
WebContentsImpl* opener) {
TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
WebContentsImpl* new_contents = new WebContentsImpl(
params.browser_context, opener);
new_contents->Init(params);
return new_contents;
}
BrowserPluginGuest* WebContentsImpl::CreateGuest(
BrowserContext* browser_context,
SiteInstance* site_instance,
int guest_instance_id,
scoped_ptr<base::DictionaryValue> extra_params) {
WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
BrowserPluginGuest::Create(
guest_instance_id, site_instance, new_contents, extra_params.Pass());
WebContents::CreateParams create_params(browser_context, site_instance);
new_contents->Init(create_params);
new_contents->is_subframe_ = true;
return new_contents->browser_plugin_guest_.get();
}
RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
return GetRenderManager();
}
bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
const IPC::Message& message) {
return OnMessageReceived(render_view_host, NULL, message);
}
bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
RenderFrameHost* render_frame_host,
const IPC::Message& message) {
DCHECK(render_view_host || render_frame_host);
if (GetWebUI() &&
static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
return true;
}
ObserverListBase<WebContentsObserver>::Iterator it(observers_);
WebContentsObserver* observer;
while ((observer = it.GetNext()) != NULL)
if (observer->OnMessageReceived(message))
return true;
if (render_frame_host) {
if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
render_frame_host->GetRenderViewHost(), message))
return true;
render_frame_message_source_ = render_frame_host;
} else {
if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
render_view_host, message))
return true;
render_view_message_source_ = render_view_host;
}
bool handled = true;
bool message_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
OnDomOperationResponse)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
OnDidLoadResourceFromMemoryCache)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
OnDidDisplayInsecureContent)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
OnDidRunInsecureContent)
IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
OnDocumentLoadedInFrame)
IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
OnRegisterProtocolHandler)
IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
OnSetSelectedColorInColorChooser)
IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
OnRequestPpapiBrokerPermission)
IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
OnBrowserPluginMessage(message))
IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
OnBrowserPluginMessage(message))
IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
#if defined(OS_ANDROID)
IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
OnFindMatchRectsReply)
IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
OnOpenDateTimeDialog)
IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
OnJavaBridgeGetChannelHandle)
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
OnMediaPlayingNotification)
IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
OnMediaPausedNotification)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
OnFirstVisuallyNonEmptyPaint)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
OnShowValidationMessage)
IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
OnHideValidationMessage)
IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
OnMoveValidationMessage)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
render_view_message_source_ = NULL;
render_frame_message_source_ = NULL;
if (!message_is_ok) {
RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
GetRenderProcessHost()->ReceivedBadMessage();
}
return handled;
}
void WebContentsImpl::RunFileChooser(
RenderViewHost* render_view_host,
const FileChooserParams& params) {
if (delegate_)
delegate_->RunFileChooser(this, params);
}
NavigationControllerImpl& WebContentsImpl::GetController() {
return controller_;
}
const NavigationControllerImpl& WebContentsImpl::GetController() const {
return controller_;
}
BrowserContext* WebContentsImpl::GetBrowserContext() const {
return controller_.GetBrowserContext();
}
const GURL& WebContentsImpl::GetURL() const {
NavigationEntry* entry = controller_.GetVisibleEntry();
return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
}
const GURL& WebContentsImpl::GetVisibleURL() const {
NavigationEntry* entry = controller_.GetVisibleEntry();
return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
}
const GURL& WebContentsImpl::GetLastCommittedURL() const {
NavigationEntry* entry = controller_.GetLastCommittedEntry();
return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
}
WebContentsDelegate* WebContentsImpl::GetDelegate() {
return delegate_;
}
void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
if (delegate == delegate_)
return;
if (delegate_)
delegate_->Detach(this);
delegate_ = delegate;
if (delegate_) {
delegate_->Attach(this);
if (view_)
view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
}
}
RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
RenderViewHostImpl* host = GetRenderManager()->current_host();
return host ? host->GetProcess() : NULL;
}
RenderFrameHost* WebContentsImpl::GetMainFrame() {
return frame_tree_.root()->current_frame_host();
}
RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
if (!frame_tree_.GetFocusedFrame())
return NULL;
return frame_tree_.GetFocusedFrame()->current_frame_host();
}
void WebContentsImpl::ForEachFrame(
const base::Callback<void(RenderFrameHost*)>& on_frame) {
frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
}
void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
delete message;
}
RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
return GetRenderManager()->current_host();
}
WebContents* WebContentsImpl::GetEmbedderWebContents() const {
BrowserPluginGuest* guest = GetBrowserPluginGuest();
if (guest)
return guest->embedder_web_contents();
return NULL;
}
int WebContentsImpl::GetEmbeddedInstanceID() const {
BrowserPluginGuest* guest = GetBrowserPluginGuest();
if (guest)
return guest->instance_id();
return 0;
}
int WebContentsImpl::GetRoutingID() const {
if (!GetRenderViewHost())
return MSG_ROUTING_NONE;
return GetRenderViewHost()->GetRoutingID();
}
int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
return fullscreen_widget_routing_id_;
}
RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
return GetRenderManager()->GetRenderWidgetHostView();
}
RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
BrowserPluginGuest* guest = GetBrowserPluginGuest();
if (guest && guest->embedder_web_contents()) {
return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
}
return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
}
RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
const {
RenderWidgetHost* const widget_host =
RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
GetFullscreenWidgetRoutingID());
return widget_host ? widget_host->GetView() : NULL;
}
WebContentsView* WebContentsImpl::GetView() const {
return view_.get();
}
WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
WebUIImpl* web_ui = new WebUIImpl(this);
WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
CreateWebUIControllerForURL(web_ui, url);
if (controller) {
web_ui->AddMessageHandler(new GenericHandler());
web_ui->SetController(controller);
return web_ui;
}
delete web_ui;
return NULL;
}
WebUI* WebContentsImpl::GetWebUI() const {
return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
: GetRenderManager()->pending_web_ui();
}
WebUI* WebContentsImpl::GetCommittedWebUI() const {
return GetRenderManager()->web_ui();
}
void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
if (GetUserAgentOverride() == override)
return;
renderer_preferences_.user_agent_override = override;
RenderViewHost* host = GetRenderViewHost();
if (host)
host->SyncRendererPrefs();
NavigationEntry* entry = controller_.GetVisibleEntry();
if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
controller_.ReloadIgnoringCache(true);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
UserAgentOverrideSet(override));
}
const std::string& WebContentsImpl::GetUserAgentOverride() const {
return renderer_preferences_.user_agent_override;
}
#if defined(OS_WIN)
void WebContentsImpl::SetParentNativeViewAccessible(
gfx::NativeViewAccessible accessible_parent) {
accessible_parent_ = accessible_parent;
if (GetRenderViewHost())
GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
}
#endif
const base::string16& WebContentsImpl::GetTitle() const {
NavigationEntry* entry = controller_.GetTransientEntry();
std::string accept_languages =
GetContentClient()->browser()->GetAcceptLangs(
GetBrowserContext());
if (entry) {
return entry->GetTitleForDisplay(accept_languages);
}
WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
if (our_web_ui) {
entry = controller_.GetVisibleEntry();
if (!(entry && entry->IsViewSourceMode())) {
const base::string16& title = our_web_ui->GetOverriddenTitle();
if (!title.empty())
return title;
}
}
entry = controller_.GetLastCommittedEntry();
if (controller_.IsInitialNavigation()) {
if (entry ||
(controller_.GetVisibleEntry() &&
!controller_.GetVisibleEntry()->GetTitle().empty())) {
entry = controller_.GetVisibleEntry();
}
}
if (entry) {
return entry->GetTitleForDisplay(accept_languages);
}
return page_title_when_no_navigation_entry_;
}
int32 WebContentsImpl::GetMaxPageID() {
return GetMaxPageIDForSiteInstance(GetSiteInstance());
}
int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
SiteInstance* site_instance) {
if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
max_page_ids_[site_instance->GetId()] = -1;
return max_page_ids_[site_instance->GetId()];
}
void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
}
void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
SiteInstance* site_instance, int32 page_id) {
if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
max_page_ids_[site_instance->GetId()] = page_id;
}
void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
max_page_ids_ = contents->max_page_ids_;
}
SiteInstance* WebContentsImpl::GetSiteInstance() const {
return GetRenderManager()->current_host()->GetSiteInstance();
}
SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
GetRenderManager()->pending_render_view_host() :
GetRenderManager()->current_host();
return dest_rvh->GetSiteInstance();
}
bool WebContentsImpl::IsLoading() const {
return is_loading_;
}
bool WebContentsImpl::IsWaitingForResponse() const {
return waiting_for_response_;
}
const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
return load_state_;
}
const base::string16& WebContentsImpl::GetLoadStateHost() const {
return load_state_host_;
}
uint64 WebContentsImpl::GetUploadSize() const {
return upload_size_;
}
uint64 WebContentsImpl::GetUploadPosition() const {
return upload_position_;
}
std::set<GURL> WebContentsImpl::GetSitesInTab() const {
std::set<GURL> sites;
frame_tree_.ForEach(base::Bind(&CollectSites,
base::Unretained(GetBrowserContext()),
base::Unretained(&sites)));
return sites;
}
const std::string& WebContentsImpl::GetEncoding() const {
return encoding_;
}
bool WebContentsImpl::DisplayedInsecureContent() const {
return displayed_insecure_content_;
}
void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
DCHECK(!is_being_destroyed_);
++capturer_count_;
DVLOG(1) << "There are now " << capturer_count_
<< " capturing(s) of WebContentsImpl@" << this;
if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
preferred_size_for_capture_ = capture_size;
OnPreferredSizeChanged(preferred_size_);
}
}
void WebContentsImpl::DecrementCapturerCount() {
--capturer_count_;
DVLOG(1) << "There are now " << capturer_count_
<< " capturing(s) of WebContentsImpl@" << this;
DCHECK_LE(0, capturer_count_);
if (is_being_destroyed_)
return;
if (capturer_count_ == 0) {
const gfx::Size old_size = preferred_size_for_capture_;
preferred_size_for_capture_ = gfx::Size();
OnPreferredSizeChanged(old_size);
}
if (IsHidden()) {
DVLOG(1) << "Executing delayed WasHidden().";
WasHidden();
}
}
int WebContentsImpl::GetCapturerCount() const {
return capturer_count_;
}
bool WebContentsImpl::IsCrashed() const {
return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
}
void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
int error_code) {
if (status == crashed_status_)
return;
crashed_status_ = status;
crashed_error_code_ = error_code;
NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
}
base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
return crashed_status_;
}
bool WebContentsImpl::IsBeingDestroyed() const {
return is_being_destroyed_;
}
void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
if (delegate_)
delegate_->NavigationStateChanged(this, changed_flags);
}
base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
return last_active_time_;
}
void WebContentsImpl::WasShown() {
controller_.SetActive(true);
RenderWidgetHostViewPort* rwhv =
RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
if (rwhv) {
rwhv->Show();
#if defined(OS_MACOSX)
rwhv->SetActive(true);
#endif
}
last_active_time_ = base::TimeTicks::Now();
RenderViewHostImpl* rvh =
static_cast<RenderViewHostImpl*>(GetRenderViewHost());
if (rvh) {
rvh->ResizeRectChanged(GetRootWindowResizerRect());
}
FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
should_normally_be_visible_ = true;
}
void WebContentsImpl::WasHidden() {
if (capturer_count_ == 0) {
RenderWidgetHostViewPort* rwhv =
RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
if (rwhv)
rwhv->Hide();
}
FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
should_normally_be_visible_ = false;
}
bool WebContentsImpl::NeedToFireBeforeUnload() {
return WillNotifyDisconnection() &&
!ShowingInterstitialPage() &&
!static_cast<RenderViewHostImpl*>(
GetRenderViewHost())->SuddenTerminationAllowed();
}
void WebContentsImpl::Stop() {
GetRenderManager()->Stop();
FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
}
WebContents* WebContentsImpl::Clone() {
CreateParams create_params(GetBrowserContext(), GetSiteInstance());
create_params.initial_size = view_->GetContainerSize();
WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
tc->GetController().CopyStateFrom(controller_);
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
DidCloneToNewWebContents(this, tc));
return tc;
}
void WebContentsImpl::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
switch (type) {
case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
i != pending_widget_views_.end(); ++i) {
if (host->GetView() == i->second) {
pending_widget_views_.erase(i);
break;
}
}
break;
}
default:
NOTREACHED();
}
}
WebContents* WebContentsImpl::GetWebContents() {
return this;
}
void WebContentsImpl::Init(const WebContents::CreateParams& params) {
should_normally_be_visible_ = !params.initially_hidden;
GetRenderManager()->Init(
params.browser_context, params.site_instance, params.routing_id,
params.main_frame_routing_id);
view_.reset(GetContentClient()->browser()->
OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
if (view_) {
CHECK(render_view_host_delegate_view_);
} else {
WebContentsViewDelegate* delegate =
GetContentClient()->browser()->GetWebContentsViewDelegate(this);
if (browser_plugin_guest_) {
scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
this, delegate, &render_view_host_delegate_view_));
WebContentsViewGuest* rv = new WebContentsViewGuest(
this, browser_plugin_guest_.get(), platform_view.Pass(),
render_view_host_delegate_view_);
render_view_host_delegate_view_ = rv;
view_.reset(rv);
} else {
view_.reset(CreateWebContentsView(
this, delegate, &render_view_host_delegate_view_));
}
CHECK(render_view_host_delegate_view_);
}
CHECK(view_.get());
gfx::Size initial_size = params.initial_size;
view_->CreateView(initial_size, params.context);
if (opener_)
AddDestructionObserver(opener_);
registrar_.Add(this,
NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
NotificationService::AllBrowserContextsAndSources());
#if defined(OS_ANDROID)
java_bridge_dispatcher_host_manager_.reset(
new JavaBridgeDispatcherHostManager(this));
date_time_chooser_.reset(new DateTimeChooserAndroid());
#endif
}
void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
RemoveDestructionObserver(web_contents);
if (web_contents == opener_) {
opener_ = NULL;
return;
}
for (PendingContents::iterator iter = pending_contents_.begin();
iter != pending_contents_.end();
++iter) {
if (iter->second != web_contents)
continue;
pending_contents_.erase(iter);
return;
}
NOTREACHED();
}
void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
if (!ContainsKey(destruction_observers_, web_contents)) {
destruction_observers_[web_contents] =
new DestructionObserver(this, web_contents);
}
}
void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
DestructionObservers::iterator iter =
destruction_observers_.find(web_contents);
if (iter != destruction_observers_.end()) {
delete destruction_observers_[web_contents];
destruction_observers_.erase(iter);
}
}
void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
observers_.AddObserver(observer);
}
void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
observers_.RemoveObserver(observer);
}
void WebContentsImpl::Activate() {
if (delegate_)
delegate_->ActivateContents(this);
}
void WebContentsImpl::Deactivate() {
if (delegate_)
delegate_->DeactivateContents(this);
}
void WebContentsImpl::LostCapture() {
if (delegate_)
delegate_->LostCapture();
}
void WebContentsImpl::RenderWidgetDeleted(
RenderWidgetHostImpl* render_widget_host) {
if (is_being_destroyed_) {
return;
}
std::set<RenderWidgetHostImpl*>::iterator iter =
created_widgets_.find(render_widget_host);
if (iter != created_widgets_.end())
created_widgets_.erase(iter);
if (render_widget_host &&
render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
if (delegate_ && delegate_->EmbedsFullscreenWidget())
delegate_->ToggleFullscreenModeForTab(this, false);
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
DidDestroyFullscreenWidget(
fullscreen_widget_routing_id_));
fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
}
}
bool WebContentsImpl::PreHandleKeyboardEvent(
const NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) {
return delegate_ &&
delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
}
void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
if (browser_plugin_embedder_ &&
browser_plugin_embedder_->HandleKeyboardEvent(event)) {
return;
}
if (delegate_)
delegate_->HandleKeyboardEvent(this, event);
}
bool WebContentsImpl::HandleWheelEvent(
const blink::WebMouseWheelEvent& event) {
#if !defined(OS_MACOSX)
if (delegate_ &&
event.wheelTicksY &&
(event.modifiers & blink::WebInputEvent::ControlKey)) {
delegate_->ContentsZoomChange(event.wheelTicksY > 0);
return true;
}
#endif
return false;
}
bool WebContentsImpl::PreHandleGestureEvent(
const blink::WebGestureEvent& event) {
return delegate_ && delegate_->PreHandleGestureEvent(this, event);
}
bool WebContentsImpl::HandleGestureEvent(
const blink::WebGestureEvent& event) {
if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
event.sourceDevice == blink::WebGestureEvent::Touchpad) {
const float kZoomStepValue = 0.6f;
float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
: -backStep;
float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
: backStep;
totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
if (totalPinchGestureAmount_ > zoomInThreshold) {
currentPinchZoomStepDelta_++;
delegate_->ContentsZoomChange(true);
} else if (totalPinchGestureAmount_ < zoomOutThreshold) {
currentPinchZoomStepDelta_--;
delegate_->ContentsZoomChange(false);
}
return true;
}
return false;
}
#if defined(OS_WIN)
gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
return accessible_parent_;
}
#endif
void WebContentsImpl::HandleMouseDown() {
if (delegate_)
delegate_->HandleMouseDown();
}
void WebContentsImpl::HandleMouseUp() {
if (delegate_)
delegate_->HandleMouseUp();
}
void WebContentsImpl::HandlePointerActivate() {
if (delegate_)
delegate_->HandlePointerActivate();
}
void WebContentsImpl::HandleGestureBegin() {
if (delegate_)
delegate_->HandleGestureBegin();
}
void WebContentsImpl::HandleGestureEnd() {
if (delegate_)
delegate_->HandleGestureEnd();
}
void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
if (widget_view)
RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
if (delegate_)
delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
}
bool WebContentsImpl::IsFullscreenForCurrentTab() const {
return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
}
void WebContentsImpl::RequestToLockMouse(bool user_gesture,
bool last_unlocked_by_target) {
if (delegate_) {
delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
} else {
GotResponseToLockMouseRequest(false);
}
}
void WebContentsImpl::LostMouseLock() {
if (delegate_)
delegate_->LostMouseLock();
}
void WebContentsImpl::CreateNewWindow(
int render_process_id,
int route_id,
int main_frame_route_id,
const ViewHostMsg_CreateWindow_Params& params,
SessionStorageNamespace* session_storage_namespace) {
bool is_guest = GetRenderProcessHost()->IsGuest();
DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
scoped_refptr<SiteInstance> site_instance =
params.opener_suppressed && !is_guest ?
SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
GetSiteInstance();
if (GetRenderProcessHost()->GetID() != render_process_id) {
base::ProcessHandle process_handle =
RenderProcessHost::FromID(render_process_id)->GetHandle();
if (process_handle != base::kNullProcessHandle) {
RecordAction(
base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
}
return;
}
const std::string& partition_id =
GetContentClient()->browser()->
GetStoragePartitionIdForSite(GetBrowserContext(),
site_instance->GetSiteURL());
StoragePartition* partition = BrowserContext::GetStoragePartition(
GetBrowserContext(), site_instance.get());
DOMStorageContextWrapper* dom_storage_context =
static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
SessionStorageNamespaceImpl* session_storage_namespace_impl =
static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
if (delegate_ &&
!delegate_->ShouldCreateWebContents(this,
route_id,
params.window_container_type,
params.frame_name,
params.target_url,
partition_id,
session_storage_namespace)) {
if (route_id != MSG_ROUTING_NONE &&
!RenderViewHost::FromID(render_process_id, route_id)) {
Send(new ViewMsg_Close(route_id));
}
GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
main_frame_route_id);
return;
}
WebContentsImpl* new_contents =
new WebContentsImpl(GetBrowserContext(),
params.opener_suppressed ? NULL : this);
new_contents->GetController().SetSessionStorageNamespace(
partition_id,
session_storage_namespace);
CreateParams create_params(GetBrowserContext(), site_instance.get());
create_params.routing_id = route_id;
create_params.main_frame_routing_id = main_frame_route_id;
if (!is_guest) {
create_params.context = view_->GetNativeView();
create_params.initial_size = view_->GetContainerSize();
} else {
int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
WebContentsImpl* new_contents_impl =
static_cast<WebContentsImpl*>(new_contents);
BrowserPluginGuest::CreateWithOpener(instance_id,
new_contents_impl->opener() != NULL,
new_contents_impl,
GetBrowserPluginGuest());
}
if (params.disposition == NEW_BACKGROUND_TAB)
create_params.initially_hidden = true;
new_contents->Init(create_params);
if (!params.opener_suppressed) {
if (!is_guest) {
WebContentsViewPort* new_view = new_contents->view_.get();
new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
}
DCHECK_NE(MSG_ROUTING_NONE, route_id);
pending_contents_[route_id] = new_contents;
AddDestructionObserver(new_contents);
}
if (delegate_) {
delegate_->WebContentsCreated(
this, params.opener_render_frame_id, params.frame_name,
params.target_url, new_contents);
}
if (params.opener_suppressed) {
bool was_blocked = false;
if (delegate_) {
gfx::Rect initial_pos;
delegate_->AddNewContents(
this, new_contents, params.disposition, initial_pos,
params.user_gesture, &was_blocked);
}
if (!was_blocked) {
OpenURLParams open_params(params.target_url,
Referrer(),
CURRENT_TAB,
PAGE_TRANSITION_LINK,
true );
open_params.user_gesture = params.user_gesture;
new_contents->OpenURL(open_params);
}
}
}
void WebContentsImpl::CreateNewWidget(int render_process_id,
int route_id,
blink::WebPopupType popup_type) {
CreateNewWidget(render_process_id, route_id, false, popup_type);
}
void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
int route_id) {
CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
}
void WebContentsImpl::CreateNewWidget(int render_process_id,
int route_id,
bool is_fullscreen,
blink::WebPopupType popup_type) {
RenderProcessHost* process = GetRenderProcessHost();
if (process->GetID() != render_process_id) {
base::ProcessHandle process_handle =
RenderProcessHost::FromID(render_process_id)->GetHandle();
if (process_handle != base::kNullProcessHandle) {
RecordAction(
base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
}
return;
}
RenderWidgetHostImpl* widget_host =
new RenderWidgetHostImpl(this, process, route_id, IsHidden());
created_widgets_.insert(widget_host);
RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
view_->CreateViewForPopupWidget(widget_host));
if (!widget_view)
return;
if (!is_fullscreen) {
widget_view->SetPopupType(popup_type);
}
pending_widget_views_[route_id] = widget_view;
#if defined(OS_MACOSX)
base::mac::NSObjectRetain(widget_view->GetNativeView());
#endif
}
void WebContentsImpl::ShowCreatedWindow(int route_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
WebContentsImpl* contents = GetCreatedWindow(route_id);
if (contents) {
WebContentsDelegate* delegate = GetDelegate();
if (delegate) {
delegate->AddNewContents(
this, contents, disposition, initial_pos, user_gesture, NULL);
}
}
}
void WebContentsImpl::ShowCreatedWidget(int route_id,
const gfx::Rect& initial_pos) {
ShowCreatedWidget(route_id, false, initial_pos);
}
void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
ShowCreatedWidget(route_id, true, gfx::Rect());
}
void WebContentsImpl::ShowCreatedWidget(int route_id,
bool is_fullscreen,
const gfx::Rect& initial_pos) {
RenderWidgetHostViewPort* widget_host_view =
RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
if (!widget_host_view)
return;
if (is_fullscreen) {
DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
fullscreen_widget_routing_id_ = route_id;
if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
delegate_->ToggleFullscreenModeForTab(this, true);
} else {
widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
}
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
DidShowFullscreenWidget(route_id));
if (!widget_host_view->HasFocus())
widget_host_view->Focus();
} else {
widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
}
RenderWidgetHostImpl* render_widget_host_impl =
RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
render_widget_host_impl->Init();
render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
#if defined(OS_MACOSX)
base::mac::NSObjectRelease(widget_host_view->GetNativeView());
#endif
}
WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
PendingContents::iterator iter = pending_contents_.find(route_id);
if (iter == pending_contents_.end()) {
return NULL;
}
WebContentsImpl* new_contents = iter->second;
pending_contents_.erase(route_id);
RemoveDestructionObserver(new_contents);
if (new_contents->GetRenderProcessHost()->IsGuest())
return new_contents;
if (!new_contents->GetRenderProcessHost()->HasConnection() ||
!new_contents->GetRenderViewHost()->GetView())
return NULL;
static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
return new_contents;
}
RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
if (iter == pending_widget_views_.end()) {
DCHECK(false);
return NULL;
}
RenderWidgetHostView* widget_host_view = iter->second;
pending_widget_views_.erase(route_id);
RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
if (!widget_host->GetProcess()->HasConnection()) {
return NULL;
}
return widget_host_view;
}
void WebContentsImpl::RequestMediaAccessPermission(
const MediaStreamRequest& request,
const MediaResponseCallback& callback) {
if (delegate_) {
delegate_->RequestMediaAccessPermission(this, request, callback);
} else {
callback.Run(MediaStreamDevices(),
MEDIA_DEVICE_INVALID_STATE,
scoped_ptr<MediaStreamUI>());
}
}
SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
SiteInstance* instance) {
return controller_.GetSessionStorageNamespace(instance);
}
FrameTree* WebContentsImpl::GetFrameTree() {
return &frame_tree_;
}
void WebContentsImpl::AccessibilityEventReceived(
const std::vector<AXEventNotificationDetails>& details) {
FOR_EACH_OBSERVER(
WebContentsObserver, observers_, AccessibilityEventReceived(details));
}
void WebContentsImpl::OnShowValidationMessage(
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) {
if (delegate_)
delegate_->ShowValidationMessage(
this, anchor_in_root_view, main_text, sub_text);
}
void WebContentsImpl::OnHideValidationMessage() {
if (delegate_)
delegate_->HideValidationMessage(this);
}
void WebContentsImpl::OnMoveValidationMessage(
const gfx::Rect& anchor_in_root_view) {
if (delegate_)
delegate_->MoveValidationMessage(this, anchor_in_root_view);
}
void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
if (browser_plugin_embedder_)
browser_plugin_embedder_->DidSendScreenRects();
}
void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
const gfx::Size old_size = GetPreferredSize();
preferred_size_ = pref_size;
OnPreferredSizeChanged(old_size);
}
void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
if (delegate_)
delegate_->ResizeDueToAutoResize(this, new_size);
}
WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
if (!delegate_)
return NULL;
WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
return new_contents;
}
bool WebContentsImpl::Send(IPC::Message* message) {
if (!GetRenderViewHost()) {
delete message;
return false;
}
return GetRenderViewHost()->Send(message);
}
bool WebContentsImpl::NavigateToPendingEntry(
NavigationController::ReloadType reload_type) {
FrameTreeNode* node = frame_tree_.root();
NavigationEntryImpl* pending_entry =
NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
pending_entry->frame_tree_node_id() != -1) {
node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
}
return node->navigator()->NavigateToPendingEntry(
node->current_frame_host(), reload_type);
}
void WebContentsImpl::RenderFrameForInterstitialPageCreated(
RenderFrameHost* render_frame_host) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
RenderFrameForInterstitialPageCreated(render_frame_host));
}
void WebContentsImpl::AttachInterstitialPage(
InterstitialPageImpl* interstitial_page) {
DCHECK(interstitial_page);
GetRenderManager()->set_interstitial_page(interstitial_page);
if (dialog_manager_)
dialog_manager_->CancelActiveAndPendingDialogs(this);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidAttachInterstitialPage());
}
void WebContentsImpl::DetachInterstitialPage() {
if (GetInterstitialPage())
GetRenderManager()->remove_interstitial_page();
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidDetachInterstitialPage());
}
void WebContentsImpl::SetHistoryLengthAndPrune(
const SiteInstance* site_instance,
int history_length,
int32 minimum_page_id) {
if (GetRenderManager()->pending_render_view_host()) {
NOTREACHED();
return;
}
RenderViewHostImpl* rvh = GetRenderViewHostImpl();
if (!rvh) {
NOTREACHED();
return;
}
if (site_instance && rvh->GetSiteInstance() != site_instance) {
NOTREACHED();
return;
}
Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
history_length,
minimum_page_id));
}
void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
RenderFrameHost* focused_frame = GetFocusedFrame();
if (!focused_frame)
return;
Send(new FrameMsg_Reload(focused_frame->GetRoutingID(), ignore_cache));
}
void WebContentsImpl::Replace(const base::string16& word) {
RenderFrameHost* focused_frame = GetFocusedFrame();
if (!focused_frame)
return;
Send(new InputMsg_Replace(focused_frame->GetRoutingID(), word));
}
void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
RenderFrameHost* focused_frame = GetFocusedFrame();
if (!focused_frame)
return;
Send(new InputMsg_ReplaceMisspelling(focused_frame->GetRoutingID(), word));
}
void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
if (ShowingInterstitialPage()) {
GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
return;
}
GetRenderViewHostImpl()->SetInitialFocus(reverse);
}
bool WebContentsImpl::ShowingInterstitialPage() const {
return GetRenderManager()->interstitial_page() != NULL;
}
InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
return GetRenderManager()->interstitial_page();
}
bool WebContentsImpl::IsSavable() {
return contents_mime_type_ == "text/html" ||
contents_mime_type_ == "text/xml" ||
contents_mime_type_ == "application/xhtml+xml" ||
contents_mime_type_ == "text/plain" ||
contents_mime_type_ == "text/css" ||
net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
}
void WebContentsImpl::OnSavePage() {
if (!IsSavable()) {
RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
SaveFrame(GetURL(), Referrer());
return;
}
Stop();
save_package_ = new SavePackage(this);
save_package_->GetSaveInfo();
}
bool WebContentsImpl::SavePage(const base::FilePath& main_file,
const base::FilePath& dir_path,
SavePageType save_type) {
Stop();
save_package_ = new SavePackage(this, save_type, main_file, dir_path);
return save_package_->Init(SavePackageDownloadCreatedCallback());
}
void WebContentsImpl::SaveFrame(const GURL& url,
const Referrer& referrer) {
if (!GetURL().is_valid())
return;
bool is_main_frame = (url == GetURL());
DownloadManager* dlm =
BrowserContext::GetDownloadManager(GetBrowserContext());
if (!dlm)
return;
int64 post_id = -1;
if (is_main_frame) {
const NavigationEntry* entry = controller_.GetLastCommittedEntry();
if (entry)
post_id = entry->GetPostID();
}
scoped_ptr<DownloadUrlParameters> params(
DownloadUrlParameters::FromWebContents(this, url));
params->set_referrer(referrer);
params->set_post_id(post_id);
params->set_prefer_cache(true);
if (post_id >= 0)
params->set_method("POST");
params->set_prompt(true);
dlm->DownloadUrl(params.Pass());
}
void WebContentsImpl::GenerateMHTML(
const base::FilePath& file,
const base::Callback<void(int64)>& callback) {
MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
}
bool WebContentsImpl::IsActiveEntry(int32 page_id) {
NavigationEntryImpl* visible_entry =
NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
return (visible_entry != NULL &&
visible_entry->site_instance() == GetSiteInstance() &&
visible_entry->GetPageID() == page_id);
}
const std::string& WebContentsImpl::GetContentsMimeType() const {
return contents_mime_type_;
}
bool WebContentsImpl::WillNotifyDisconnection() const {
return notify_disconnection_;
}
void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
SetEncoding(encoding);
Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
}
void WebContentsImpl::ResetOverrideEncoding() {
encoding_.clear();
Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
}
RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
return &renderer_preferences_;
}
void WebContentsImpl::Close() {
Close(GetRenderViewHost());
}
void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
int screen_x, int screen_y, blink::WebDragOperation operation) {
if (browser_plugin_embedder_.get())
browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
screen_x, screen_y, operation);
if (GetRenderViewHost())
GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
screen_x, screen_y, operation);
}
void WebContentsImpl::DidGetResourceResponseStart(
const ResourceRequestDetails& details) {
controller_.ssl_manager()->DidStartResourceResponse(details);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidGetResourceResponseStart(details));
NotificationService::current()->Notify(
NOTIFICATION_RESOURCE_RESPONSE_STARTED,
Source<WebContents>(this),
Details<const ResourceRequestDetails>(&details));
}
void WebContentsImpl::DidGetRedirectForResourceRequest(
RenderViewHost* render_view_host,
const ResourceRedirectDetails& details) {
controller_.ssl_manager()->DidReceiveResourceRedirect(details);
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
DidGetRedirectForResourceRequest(render_view_host, details));
NotificationService::current()->Notify(
NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
Source<WebContents>(this),
Details<const ResourceRedirectDetails>(&details));
}
void WebContentsImpl::SystemDragEnded() {
if (GetRenderViewHost())
GetRenderViewHostImpl()->DragSourceSystemDragEnded();
if (delegate_)
delegate_->DragEnded();
if (browser_plugin_embedder_.get())
browser_plugin_embedder_->SystemDragEnded();
}
void WebContentsImpl::UserGestureDone() {
OnUserGesture();
}
void WebContentsImpl::SetClosedByUserGesture(bool value) {
closed_by_user_gesture_ = value;
}
bool WebContentsImpl::GetClosedByUserGesture() const {
return closed_by_user_gesture_;
}
double WebContentsImpl::GetZoomLevel() const {
HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
HostZoomMap::GetForBrowserContext(GetBrowserContext()));
if (!zoom_map)
return 0;
double zoom_level;
if (temporary_zoom_settings_) {
zoom_level = zoom_map->GetTemporaryZoomLevel(
GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
} else {
GURL url;
NavigationEntry* entry = GetController().GetLastCommittedEntry();
url = entry ? entry->GetURL() : GURL::EmptyGURL();
zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
net::GetHostOrSpecFromURL(url));
}
return zoom_level;
}
int WebContentsImpl::GetZoomPercent(bool* enable_increment,
bool* enable_decrement) const {
*enable_decrement = *enable_increment = false;
int percent = static_cast<int>(
ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
*enable_decrement = percent > minimum_zoom_percent_;
*enable_increment = percent < maximum_zoom_percent_;
return percent;
}
void WebContentsImpl::ViewSource() {
if (!delegate_)
return;
NavigationEntry* entry = GetController().GetLastCommittedEntry();
if (!entry)
return;
delegate_->ViewSourceForTab(this, entry->GetURL());
}
void WebContentsImpl::ViewFrameSource(const GURL& url,
const PageState& page_state) {
if (!delegate_)
return;
delegate_->ViewSourceForFrame(this, url, page_state);
}
int WebContentsImpl::GetMinimumZoomPercent() const {
return minimum_zoom_percent_;
}
int WebContentsImpl::GetMaximumZoomPercent() const {
return maximum_zoom_percent_;
}
gfx::Size WebContentsImpl::GetPreferredSize() const {
return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
}
bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
return GetRenderViewHost() ?
GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
}
bool WebContentsImpl::HasOpener() const {
return opener_ != NULL;
}
void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
Send(new ViewMsg_DidChooseColorResponse(
GetRoutingID(), color_chooser_identifier_, color));
}
void WebContentsImpl::DidEndColorChooser() {
Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
color_chooser_identifier_));
color_chooser_.reset();
color_chooser_identifier_ = 0;
}
int WebContentsImpl::DownloadImage(const GURL& url,
bool is_favicon,
uint32_t max_bitmap_size,
const ImageDownloadCallback& callback) {
int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
image_download_map_[id] = callback;
return id;
}
bool WebContentsImpl::IsSubframe() const {
return is_subframe_;
}
void WebContentsImpl::SetZoomLevel(double level) {
Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
if (embedder)
embedder->SetZoomLevel(level);
}
void WebContentsImpl::Find(int request_id,
const base::string16& search_text,
const blink::WebFindOptions& options) {
Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
}
void WebContentsImpl::StopFinding(StopFindAction action) {
Send(new ViewMsg_StopFinding(GetRoutingID(), action));
}
bool WebContentsImpl::FocusLocationBarByDefault() {
NavigationEntry* entry = controller_.GetVisibleEntry();
if (entry && entry->GetURL() == GURL(kAboutBlankURL))
return true;
return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
}
void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
if (delegate_)
delegate_->SetFocusToLocationBar(select_all);
}
void WebContentsImpl::DidStartProvisionalLoad(
RenderFrameHostImpl* render_frame_host,
int parent_routing_id,
const GURL& validated_url,
bool is_error_page,
bool is_iframe_srcdoc) {
bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
if (is_main_frame)
DidChangeLoadProgress(0);
int render_frame_id = render_frame_host->GetRoutingID();
RenderViewHost* render_view_host = render_frame_host->render_view_host();
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidStartProvisionalLoadForFrame(
render_frame_id, parent_routing_id, is_main_frame,
validated_url, is_error_page, is_iframe_srcdoc,
render_view_host));
if (is_main_frame) {
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
ProvisionalChangeToMainFrameUrl(validated_url,
render_frame_host));
}
}
void WebContentsImpl::DidFailProvisionalLoadWithError(
RenderFrameHostImpl* render_frame_host,
const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
GURL validated_url(params.url);
int render_frame_id = render_frame_host->GetRoutingID();
bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
RenderViewHost* render_view_host = render_frame_host->render_view_host();
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
DidFailProvisionalLoad(render_frame_id,
params.frame_unique_name,
is_main_frame,
validated_url,
params.error_code,
params.error_description,
render_view_host));
}
void WebContentsImpl::DidFailLoadWithError(
RenderFrameHostImpl* render_frame_host,
const GURL& url,
int error_code,
const base::string16& error_description) {
int render_frame_id = render_frame_host->GetRoutingID();
bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
RenderViewHost* render_view_host = render_frame_host->render_view_host();
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidFailLoad(render_frame_id, url, is_main_frame, error_code,
error_description, render_view_host));
}
void WebContentsImpl::NotifyChangedNavigationState(
InvalidateTypes changed_flags) {
NotifyNavigationStateChanged(changed_flags);
}
void WebContentsImpl::AboutToNavigateRenderFrame(
RenderFrameHostImpl* render_frame_host) {
RenderViewHost* render_view_host = render_frame_host->render_view_host();
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
AboutToNavigateRenderView(render_view_host));
}
void WebContentsImpl::DidStartNavigationToPendingEntry(
RenderFrameHostImpl* render_frame_host,
const GURL& url,
NavigationController::ReloadType reload_type) {
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
DidStartNavigationToPendingEntry(url, reload_type));
}
void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
const OpenURLParams& params) {
int source_render_frame_id = render_frame_host->GetRoutingID();
WebContents* new_contents = OpenURL(params);
if (new_contents) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidOpenRequestedURL(new_contents,
params.url,
params.referrer,
params.disposition,
params.transition,
source_render_frame_id));
}
}
void WebContentsImpl::DidRedirectProvisionalLoad(
RenderFrameHostImpl* render_frame_host,
const GURL& validated_target_url) {
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
ProvisionalChangeToMainFrameUrl(validated_target_url,
render_frame_host));
}
void WebContentsImpl::DidCommitProvisionalLoad(
RenderFrameHostImpl* render_frame_host,
const base::string16& frame_unique_name,
bool is_main_frame,
const GURL& url,
PageTransition transition_type) {
int render_frame_id = render_frame_host->GetRoutingID();
RenderViewHost* render_view_host = render_frame_host->render_view_host();
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
DidCommitProvisionalLoadForFrame(render_frame_id,
frame_unique_name,
is_main_frame,
url,
transition_type,
render_view_host));
}
void WebContentsImpl::DidNavigateMainFramePreCommit(
const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
if (params.was_within_same_page) {
return;
}
if (IsFullscreenForCurrentTab())
GetRenderViewHost()->ExitFullscreen();
DCHECK(!IsFullscreenForCurrentTab());
}
void WebContentsImpl::DidNavigateMainFramePostCommit(
const LoadCommittedDetails& details,
const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
if (details.is_navigation_to_different_page()) {
UpdateTargetURL(details.entry->GetPageID(), GURL());
}
if (!details.is_in_page) {
displayed_insecure_content_ = false;
SSLManager::NotifySSLInternalStateChanged(
GetController().GetBrowserContext());
}
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidNavigateMainFrame(details, params));
if (delegate_) {
delegate_->DidNavigateMainFramePostCommit(this);
view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
}
}
void WebContentsImpl::DidNavigateAnyFramePostCommit(
RenderFrameHostImpl* render_frame_host,
const LoadCommittedDetails& details,
const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
if (dialog_manager_ && !details.is_in_page)
dialog_manager_->CancelActiveAndPendingDialogs(this);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidNavigateAnyFrame(details, params));
}
void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
contents_mime_type_ = mime_type;
}
bool WebContentsImpl::CanOverscrollContent() {
if (delegate_)
return delegate_->CanOverscrollContent();
return false;
}
void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
const GURL& url,
const std::string& security_info,
const std::string& http_method,
const std::string& mime_type,
ResourceType::Type resource_type) {
base::StatsCounter cache("WebKit.CacheHit");
cache.Increment();
int cert_id = 0;
net::CertStatus cert_status = 0;
int security_bits = -1;
int connection_status = 0;
SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
&security_bits, &connection_status,
&signed_certificate_timestamp_ids);
LoadFromMemoryCacheDetails details(
url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
mime_type, resource_type);
controller_.ssl_manager()->DidLoadFromMemoryCache(details);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidLoadResourceFromMemoryCache(details));
if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
scoped_refptr<net::URLRequestContextGetter> request_context(
resource_type == ResourceType::MEDIA ?
GetBrowserContext()->GetMediaRequestContextForRenderProcess(
GetRenderProcessHost()->GetID()) :
GetBrowserContext()->GetRequestContextForRenderProcess(
GetRenderProcessHost()->GetID()));
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
}
}
void WebContentsImpl::OnDidDisplayInsecureContent() {
RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
displayed_insecure_content_ = true;
SSLManager::NotifySSLInternalStateChanged(
GetController().GetBrowserContext());
}
void WebContentsImpl::OnDidRunInsecureContent(
const std::string& security_origin, const GURL& target_url) {
LOG(WARNING) << security_origin << " ran insecure content from "
<< target_url.possibly_invalid_spec();
RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
if (EndsWith(security_origin, kDotGoogleDotCom, false))
RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
controller_.ssl_manager()->DidRunInsecureContent(security_origin);
displayed_insecure_content_ = true;
SSLManager::NotifySSLInternalStateChanged(
GetController().GetBrowserContext());
}
void WebContentsImpl::OnDocumentLoadedInFrame() {
CHECK(render_frame_message_source_);
CHECK(!render_view_message_source_);
RenderFrameHostImpl* rfh =
static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
int render_frame_id = rfh->GetRoutingID();
RenderViewHost* render_view_host = rfh->render_view_host();
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
DocumentLoadedInFrame(render_frame_id, render_view_host));
}
void WebContentsImpl::OnDidFinishLoad(
const GURL& url) {
if (!render_frame_message_source_) {
RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
GetRenderProcessHost()->ReceivedBadMessage();
return;
}
GURL validated_url(url);
RenderProcessHost* render_process_host =
render_frame_message_source_->GetProcess();
render_process_host->FilterURL(false, &validated_url);
RenderFrameHostImpl* rfh =
static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
int render_frame_id = rfh->GetRoutingID();
RenderViewHost* render_view_host = rfh->render_view_host();
bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidFinishLoad(render_frame_id, validated_url,
is_main_frame, render_view_host));
}
void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
controller_.GoToOffset(offset);
}
void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
int maximum_percent,
bool remember) {
minimum_zoom_percent_ = minimum_percent;
maximum_zoom_percent_ = maximum_percent;
temporary_zoom_settings_ = !remember;
}
void WebContentsImpl::OnEnumerateDirectory(int request_id,
const base::FilePath& path) {
if (!delegate_)
return;
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
delegate_->EnumerateDirectory(this, request_id, path);
}
void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
const GURL& url,
const base::string16& title,
bool user_gesture) {
if (!delegate_)
return;
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
if (policy->IsPseudoScheme(protocol))
return;
delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
}
void WebContentsImpl::OnFindReply(int request_id,
int number_of_matches,
const gfx::Rect& selection_rect,
int active_match_ordinal,
bool final_update) {
if (delegate_) {
delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
active_match_ordinal, final_update);
}
}
#if defined(OS_ANDROID)
void WebContentsImpl::OnFindMatchRectsReply(
int version,
const std::vector<gfx::RectF>& rects,
const gfx::RectF& active_rect) {
if (delegate_)
delegate_->FindMatchRectsReply(this, version, rects, active_rect);
}
void WebContentsImpl::OnOpenDateTimeDialog(
const ViewHostMsg_DateTimeDialogValue_Params& value) {
date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
GetRenderViewHost(),
value.dialog_type,
value.dialog_value,
value.minimum,
value.maximum,
value.step,
value.suggestions);
}
void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
render_frame_message_source_, reply_msg);
}
#endif
void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
const base::FilePath& path,
bool is_hung) {
UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
PluginHungStatusChanged(plugin_child_id, path, is_hung));
}
void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
base::ProcessId plugin_pid) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
PluginCrashed(plugin_path, plugin_pid));
}
void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
int automation_id) {
DomOperationNotificationDetails details(json_string, automation_id);
NotificationService::current()->Notify(
NOTIFICATION_DOM_OPERATION_RESPONSE,
Source<WebContents>(this),
Details<DomOperationNotificationDetails>(&details));
}
void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
bool blocked_by_policy) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
AppCacheAccessed(manifest_url, blocked_by_policy));
}
void WebContentsImpl::OnOpenColorChooser(
int color_chooser_id,
SkColor color,
const std::vector<ColorSuggestion>& suggestions) {
ColorChooser* new_color_chooser =
delegate_->OpenColorChooser(this, color, suggestions);
if (!new_color_chooser)
return;
if (color_chooser_)
color_chooser_->End();
color_chooser_.reset(new_color_chooser);
color_chooser_identifier_ = color_chooser_id;
}
void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
if (color_chooser_ &&
color_chooser_id == color_chooser_identifier_)
color_chooser_->End();
}
void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
SkColor color) {
if (color_chooser_ &&
color_chooser_id == color_chooser_identifier_)
color_chooser_->SetSelectedColor(color);
}
void WebContentsImpl::OnWebUISend(const GURL& source_url,
const std::string& name,
const base::ListValue& args) {
if (delegate_)
delegate_->WebUISend(this, source_url, name, args);
}
void WebContentsImpl::OnRequestPpapiBrokerPermission(
int routing_id,
const GURL& url,
const base::FilePath& plugin_path) {
if (!delegate_) {
OnPpapiBrokerPermissionResult(routing_id, false);
return;
}
if (!delegate_->RequestPpapiBrokerPermission(
this, url, plugin_path,
base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
base::Unretained(this), routing_id))) {
NOTIMPLEMENTED();
OnPpapiBrokerPermissionResult(routing_id, false);
}
}
void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
bool result) {
Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
}
void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
CHECK(!browser_plugin_embedder_.get());
browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
browser_plugin_embedder_->OnMessageReceived(message);
}
void WebContentsImpl::OnDidDownloadImage(
int id,
int http_status_code,
const GURL& image_url,
const std::vector<SkBitmap>& bitmaps,
const std::vector<gfx::Size>& original_bitmap_sizes) {
if (bitmaps.size() != original_bitmap_sizes.size())
return;
ImageDownloadMap::iterator iter = image_download_map_.find(id);
if (iter == image_download_map_.end()) {
return;
}
if (!iter->second.is_null()) {
iter->second.Run(
id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
}
image_download_map_.erase(id);
}
void WebContentsImpl::OnUpdateFaviconURL(
int32 page_id,
const std::vector<FaviconURL>& candidates) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidUpdateFaviconURL(page_id, candidates));
}
void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
bool has_video,
bool has_audio) {
#if !defined(OS_CHROMEOS)
scoped_ptr<PowerSaveBlocker> blocker;
if (has_video) {
blocker = PowerSaveBlocker::Create(
PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
#if defined(OS_ANDROID)
static_cast<PowerSaveBlockerImpl*>(blocker.get())
->InitDisplaySleepBlocker(GetView()->GetNativeView());
#endif
} else if (has_audio) {
blocker = PowerSaveBlocker::Create(
PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
}
if (blocker) {
power_save_blockers_[render_view_message_source_][player_cookie] =
blocker.release();
}
#endif
}
void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
#if !defined(OS_CHROMEOS)
delete power_save_blockers_[render_view_message_source_][player_cookie];
power_save_blockers_[render_view_message_source_].erase(player_cookie);
#endif
}
void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidFirstVisuallyNonEmptyPaint(page_id));
}
void WebContentsImpl::DidChangeVisibleSSLState() {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidChangeVisibleSSLState());
}
void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
BeforeFormRepostWarningShow());
}
void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
Activate();
if (delegate_)
delegate_->ShowRepostFormWarningDialog(this);
}
void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
bool is_loading,
bool to_different_document,
LoadNotificationDetails* details) {
if (is_loading == is_loading_)
return;
if (!is_loading) {
load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
base::string16());
load_state_host_.clear();
upload_size_ = 0;
upload_position_ = 0;
}
GetRenderManager()->SetIsLoading(is_loading);
is_loading_ = is_loading;
waiting_for_response_ = is_loading;
if (delegate_)
delegate_->LoadingStateChanged(this, to_different_document);
NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
if (is_loading) {
TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
"URL", url);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidStartLoading(render_view_host));
} else {
TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
"URL", url);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidStopLoading(render_view_host));
}
int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
NotificationDetails det = NotificationService::NoDetails();
if (details)
det = Details<LoadNotificationDetails>(details);
NotificationService::current()->Notify(
type, Source<NavigationController>(&controller_), det);
}
void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
int max_restored_page_id = controller_.GetMaxRestoredPageID();
if (max_restored_page_id >
GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
max_restored_page_id);
}
bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
const base::string16& title) {
base::string16 final_title;
bool explicit_set;
if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
explicit_set = false;
} else {
base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
explicit_set = true;
}
if (entry) {
if (final_title == entry->GetTitle())
return false;
entry->SetTitle(final_title);
} else {
if (page_title_when_no_navigation_entry_ == final_title)
return false;
page_title_when_no_navigation_entry_ = final_title;
}
view_->SetPageTitle(final_title);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
TitleWasSet(entry, explicit_set));
std::pair<NavigationEntry*, bool> details =
std::make_pair(entry, explicit_set);
NotificationService::current()->Notify(
NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
Source<WebContents>(this),
Details<std::pair<NavigationEntry*, bool> >(&details));
return true;
}
void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
RenderViewHost* new_host) {
notify_disconnection_ = true;
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
RenderViewHostChanged(old_host, new_host));
std::pair<RenderViewHost*, RenderViewHost*> details =
std::make_pair(old_host, new_host);
NotificationService::current()->Notify(
NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
Source<WebContents>(this),
Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
RemoveBrowserPluginEmbedder();
}
void WebContentsImpl::NotifyDisconnected() {
if (!notify_disconnection_)
return;
notify_disconnection_ = false;
NotificationService::current()->Notify(
NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
Source<WebContents>(this),
NotificationService::NoDetails());
}
void WebContentsImpl::NotifyNavigationEntryCommitted(
const LoadCommittedDetails& load_details) {
FOR_EACH_OBSERVER(
WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
}
bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
const IPC::Message& message) {
return OnMessageReceived(NULL, render_frame_host, message);
}
const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
return GetLastCommittedURL();
}
void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
RenderFrameCreated(render_frame_host));
}
void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
RenderFrameDeleted(render_frame_host));
}
void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
if (delegate_)
delegate_->WorkerCrashed(this);
}
void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
const ContextMenuParams& params) {
if (delegate_ && delegate_->HandleContextMenu(params))
return;
render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
}
WebContents* WebContentsImpl::GetAsWebContents() {
return this;
}
RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
return render_view_host_delegate_view_;
}
RendererPreferences WebContentsImpl::GetRendererPrefs(
BrowserContext* browser_context) const {
return renderer_preferences_;
}
gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
if (delegate_)
return delegate_->GetRootWindowResizerRect();
return gfx::Rect();
}
void WebContentsImpl::RemoveBrowserPluginEmbedder() {
if (browser_plugin_embedder_)
browser_plugin_embedder_.reset();
}
void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
return;
if (delegate_)
view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
NotificationService::current()->Notify(
NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
Source<WebContents>(this),
Details<RenderViewHost>(render_view_host));
if (GetRenderManager()->pending_web_ui())
GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
NavigationEntry* entry = controller_.GetPendingEntry();
if (entry && entry->IsViewSourceMode()) {
render_view_host->Send(
new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
}
view_->RenderViewCreated(render_view_host);
FOR_EACH_OBSERVER(
WebContentsObserver, observers_, RenderViewCreated(render_view_host));
RenderFrameHost* main_frame = render_view_host->GetMainFrame();
FOR_EACH_OBSERVER(
WebContentsObserver, observers_, RenderFrameCreated(main_frame));
}
void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
if (rvh != GetRenderViewHost()) {
return;
}
notify_disconnection_ = true;
NotificationService::current()->Notify(
NOTIFICATION_WEB_CONTENTS_CONNECTED,
Source<WebContents>(this),
NotificationService::NoDetails());
bool was_crashed = IsCrashed();
SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
if (was_crashed && !FocusLocationBarByDefault() &&
(!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
view_->Focus();
}
FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
}
void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
base::TerminationStatus status,
int error_code) {
if (rvh != GetRenderViewHost()) {
return;
}
if (IsFullscreenForCurrentTab())
ToggleFullscreenMode(false);
if (dialog_manager_)
dialog_manager_->CancelActiveAndPendingDialogs(this);
ClearPowerSaveBlockers(rvh);
SetIsLoading(rvh, false, true, NULL);
NotifyDisconnected();
SetIsCrashed(status, error_code);
GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
FOR_EACH_OBSERVER(WebContentsObserver,
observers_,
RenderProcessGone(GetCrashedStatus()));
}
void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ClearPowerSaveBlockers(rvh);
GetRenderManager()->RenderViewDeleted(rvh);
FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
}
void WebContentsImpl::UpdateState(RenderViewHost* rvh,
int32 page_id,
const PageState& page_state) {
if (rvh != GetRenderViewHost() &&
!GetRenderManager()->IsRVHOnSwappedOutList(
static_cast<RenderViewHostImpl*>(rvh)))
return;
int entry_index = controller_.GetEntryIndexWithPageID(
rvh->GetSiteInstance(), page_id);
if (entry_index < 0)
return;
NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
if (page_state == entry->GetPageState())
return;
entry->SetPageState(page_state);
controller_.NotifyEntryChanged(entry, entry_index);
}
void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
int32 page_id,
const base::string16& title,
base::i18n::TextDirection title_direction) {
SetNotWaitingForResponse();
NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
rvh->GetSiteInstance(), page_id);
if (!entry && rvh != GetRenderViewHost())
return;
if (!UpdateTitleForEntry(entry, title))
return;
if (entry == controller_.GetEntryAtOffset(0))
NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
}
void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
const std::string& encoding) {
SetEncoding(encoding);
}
void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
if (delegate_)
delegate_->UpdateTargetURL(this, page_id, url);
}
void WebContentsImpl::Close(RenderViewHost* rvh) {
#if defined(OS_MACOSX)
if (view_->IsEventTracking()) {
view_->CloseTabAfterEventTracking();
return;
}
#endif
if (delegate_ && rvh == GetRenderViewHost())
delegate_->CloseContents(this);
}
void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
delegate_->SwappedOut(this);
}
void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
if (delegate_ && delegate_->IsPopupOrPanel(this))
delegate_->MoveContents(this, new_bounds);
}
void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
bool to_different_document) {
SetIsLoading(render_frame_host->GetRenderViewHost(), true,
to_different_document, NULL);
}
void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
scoped_ptr<LoadNotificationDetails> details;
NavigationEntry* entry = controller_.GetLastCommittedEntry();
Navigator* navigator = frame_tree_.root()->navigator();
if (entry) {
base::TimeDelta elapsed =
base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
details.reset(new LoadNotificationDetails(
entry->GetVirtualURL(),
entry->GetTransitionType(),
elapsed,
&controller_,
controller_.GetCurrentEntryIndex()));
}
SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
details.get());
}
void WebContentsImpl::DidCancelLoading() {
controller_.DiscardNonCommittedEntries();
NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
}
void WebContentsImpl::DidChangeLoadProgress(double progress) {
if (delegate_)
delegate_->LoadProgressChanged(this, progress);
}
void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
if (opener_) {
RemoveDestructionObserver(opener_);
opener_ = NULL;
}
GetRenderManager()->DidDisownOpener(rvh);
}
void WebContentsImpl::DidAccessInitialDocument() {
NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
}
void WebContentsImpl::DocumentAvailableInMainFrame(
RenderViewHost* render_view_host) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DocumentAvailableInMainFrame());
}
void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
RenderViewHost* render_view_host,
int32 page_id) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DocumentOnLoadCompletedInMainFrame(page_id));
NotificationService::current()->Notify(
NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
Source<WebContents>(this),
Details<int>(&page_id));
}
void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
GetRenderViewHost()->ClosePage();
}
void WebContentsImpl::RouteMessageEvent(
RenderViewHost* rvh,
const ViewMsg_PostMessage_Params& params) {
if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
!GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
return;
ViewMsg_PostMessage_Params new_params(params);
if (!params.message_port_ids.empty()) {
MessagePortMessageFilter* message_port_message_filter =
static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
->message_port_message_filter();
std::vector<int> new_routing_ids(params.message_port_ids.size());
for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
MessagePortService::GetInstance()->UpdateMessagePort(
params.message_port_ids[i],
message_port_message_filter,
new_routing_ids[i]);
}
new_params.new_routing_ids = new_routing_ids;
}
if (new_params.source_routing_id != MSG_ROUTING_NONE) {
WebContentsImpl* source_contents = NULL;
RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
rvh->GetProcess()->GetID(), params.source_routing_id);
if (source_rvh) {
source_contents = static_cast<WebContentsImpl*>(
source_rvh->GetDelegate()->GetAsWebContents());
}
if (source_contents) {
if (GetBrowserPluginGuest()) {
new_params.source_routing_id =
source_contents->CreateSwappedOutRenderView(GetSiteInstance());
} else {
new_params.source_routing_id =
source_contents->CreateOpenerRenderViews(GetSiteInstance());
}
} else {
new_params.source_routing_id = MSG_ROUTING_NONE;
}
}
Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
}
void WebContentsImpl::RunJavaScriptMessage(
RenderViewHost* rvh,
const base::string16& message,
const base::string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType javascript_message_type,
IPC::Message* reply_msg,
bool* did_suppress_message) {
bool suppress_this_message =
static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
ShowingInterstitialPage() ||
!delegate_ ||
delegate_->ShouldSuppressDialogs() ||
!delegate_->GetJavaScriptDialogManager();
if (!suppress_this_message) {
std::string accept_lang = GetContentClient()->browser()->
GetAcceptLangs(GetBrowserContext());
dialog_manager_ = delegate_->GetJavaScriptDialogManager();
dialog_manager_->RunJavaScriptDialog(
this,
frame_url.GetOrigin(),
accept_lang,
javascript_message_type,
message,
default_prompt,
base::Bind(&WebContentsImpl::OnDialogClosed,
base::Unretained(this),
rvh,
reply_msg),
&suppress_this_message);
}
*did_suppress_message = suppress_this_message;
if (suppress_this_message) {
OnDialogClosed(rvh, reply_msg, false, base::string16());
}
}
void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
const base::string16& message,
bool is_reload,
IPC::Message* reply_msg) {
RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
if (delegate_)
delegate_->WillRunBeforeUnloadConfirm();
bool suppress_this_message =
rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
!delegate_ ||
delegate_->ShouldSuppressDialogs() ||
!delegate_->GetJavaScriptDialogManager();
if (suppress_this_message) {
rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
return;
}
is_showing_before_unload_dialog_ = true;
dialog_manager_ = delegate_->GetJavaScriptDialogManager();
dialog_manager_->RunBeforeUnloadDialog(
this, message, is_reload,
base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
reply_msg));
}
bool WebContentsImpl::AddMessageToConsole(int32 level,
const base::string16& message,
int32 line_no,
const base::string16& source_id) {
if (!delegate_)
return false;
return delegate_->AddMessageToConsole(this, level, message, line_no,
source_id);
}
WebPreferences WebContentsImpl::GetWebkitPrefs() {
GURL url = controller_.GetActiveEntry()
? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
return GetRenderManager()->current_host()->GetWebkitPrefs(url);
}
int WebContentsImpl::CreateSwappedOutRenderView(
SiteInstance* instance) {
return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
true, true);
}
void WebContentsImpl::OnUserGesture() {
FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
if (rdh)
rdh->OnUserGesture(this);
}
void WebContentsImpl::OnIgnoredUIEvent() {
FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
}
void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
bool is_during_beforeunload,
bool is_during_unload) {
if (rvh != GetRenderViewHost())
return;
RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
if (DevToolsAgentHost::IsDebuggerAttached(this))
return;
if (is_during_beforeunload || is_during_unload) {
rvhi->set_sudden_termination_allowed(true);
if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
return;
bool close = true;
if (is_during_beforeunload) {
delegate_->BeforeUnloadFired(this, true, &close);
}
if (close)
Close(rvh);
return;
}
if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
return;
if (delegate_)
delegate_->RendererUnresponsive(this);
}
void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
if (delegate_)
delegate_->RendererResponsive(this);
}
void WebContentsImpl::LoadStateChanged(
const GURL& url,
const net::LoadStateWithParam& load_state,
uint64 upload_position,
uint64 upload_size) {
load_state_ = load_state;
upload_position_ = upload_position;
upload_size_ = upload_size;
load_state_host_ = net::IDNToUnicode(url.host(),
GetContentClient()->browser()->GetAcceptLangs(
GetBrowserContext()));
if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
SetNotWaitingForResponse();
if (IsLoading()) {
NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
}
}
void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
bool proceed, const base::TimeTicks& proceed_time,
bool* proceed_to_fire_unload) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
BeforeUnloadFired(proceed_time));
if (delegate_)
delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
}
void WebContentsImpl::RenderProcessGoneFromRenderManager(
RenderViewHost* render_view_host) {
DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
}
void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
gfx::Size size = GetSizeForNewRenderView();
if (!size.IsEmpty())
view_->SizeContents(size);
}
void WebContentsImpl::CancelModalDialogsForRenderManager() {
if (dialog_manager_)
dialog_manager_->CancelActiveAndPendingDialogs(this);
}
void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
RenderViewHost* new_host) {
NotifySwapped(old_host, new_host);
if (delegate_)
view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
view_->RenderViewSwappedIn(new_host);
}
int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
SiteInstance* instance) {
if (!opener_)
return MSG_ROUTING_NONE;
return opener_->CreateOpenerRenderViews(instance);
}
int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
int opener_route_id = MSG_ROUTING_NONE;
if (opener_)
opener_route_id = opener_->CreateOpenerRenderViews(instance);
if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
return GetRenderManager()->current_host()->GetRoutingID();
if (GetRenderManager()->pending_render_view_host() &&
GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
instance)
return GetRenderManager()->pending_render_view_host()->GetRoutingID();
RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
instance);
if (rvh)
return rvh->GetRoutingID();
return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
true, true);
}
NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
return GetController();
}
WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
return static_cast<WebUIImpl*>(CreateWebUI(url));
}
NavigationEntry*
WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
return controller_.GetLastCommittedEntry();
}
bool WebContentsImpl::CreateRenderViewForRenderManager(
RenderViewHost* render_view_host,
int opener_route_id,
CrossProcessFrameConnector* frame_connector) {
TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
RenderWidgetHostView* rwh_view;
if (frame_connector) {
RenderWidgetHostViewChildFrame* rwh_view_child =
new RenderWidgetHostViewChildFrame(render_view_host);
frame_connector->set_view(rwh_view_child);
rwh_view = rwh_view_child;
} else {
rwh_view = view_->CreateViewForWidget(render_view_host);
}
if (rwh_view)
rwh_view->SetSize(GetSizeForNewRenderView());
UpdateMaxPageIDIfNecessary(render_view_host);
int32 max_page_id =
GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
if (!static_cast<RenderViewHostImpl*>(
render_view_host)->CreateRenderView(base::string16(),
opener_route_id,
max_page_id)) {
return false;
}
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
if (rwh_view) {
if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
render_widget_host->WasResized();
}
#endif
return true;
}
#if defined(OS_ANDROID)
base::android::ScopedJavaLocalRef<jobject>
WebContentsImpl::GetJavaWebContents() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
WebContentsAndroid* web_contents_android =
static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
if (!web_contents_android) {
web_contents_android = new WebContentsAndroid(this);
SetUserData(kWebContentsAndroidKey, web_contents_android);
}
return web_contents_android->GetJavaObject();
}
bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
return CreateRenderViewForRenderManager(GetRenderViewHost(),
MSG_ROUTING_NONE,
NULL);
}
#endif
void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
IPC::Message* reply_msg,
bool success,
const base::string16& user_input) {
if (is_showing_before_unload_dialog_ && !success) {
DidStopLoading(rvh->GetMainFrame());
controller_.DiscardNonCommittedEntries();
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
BeforeUnloadDialogCancelled());
}
is_showing_before_unload_dialog_ = false;
static_cast<RenderViewHostImpl*>(
rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
}
void WebContentsImpl::SetEncoding(const std::string& encoding) {
encoding_ = GetContentClient()->browser()->
GetCanonicalEncodingNameByAliasName(encoding);
}
void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
if (rwh_view)
rwh_view->SetSize(GetView()->GetContainerSize());
}
bool WebContentsImpl::IsHidden() {
return capturer_count_ == 0 && !should_normally_be_visible_;
}
RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
return frame_tree_.root()->render_manager();
}
RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
}
BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
return browser_plugin_guest_.get();
}
void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
CHECK(!browser_plugin_guest_);
browser_plugin_guest_.reset(guest);
}
BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
return browser_plugin_embedder_.get();
}
BrowserPluginGuestManager*
WebContentsImpl::GetBrowserPluginGuestManager() const {
return static_cast<BrowserPluginGuestManager*>(
GetBrowserContext()->GetUserData(
browser_plugin::kBrowserPluginGuestManagerKeyName));
}
void WebContentsImpl::ClearPowerSaveBlockers(
RenderViewHost* render_view_host) {
STLDeleteValues(&power_save_blockers_[render_view_host]);
power_save_blockers_.erase(render_view_host);
}
void WebContentsImpl::ClearAllPowerSaveBlockers() {
for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
i != power_save_blockers_.end(); ++i)
STLDeleteValues(&power_save_blockers_[i->first]);
power_save_blockers_.clear();
}
gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
gfx::Size size;
if (delegate_)
size = delegate_->GetSizeForNewRenderView(this);
if (size.IsEmpty())
size = view_->GetContainerSize();
return size;
}
void WebContentsImpl::OnFrameRemoved(
RenderViewHostImpl* render_view_host,
int frame_routing_id) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
FrameDetached(render_view_host, frame_routing_id));
}
void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
if (!delegate_)
return;
const gfx::Size new_size = GetPreferredSize();
if (new_size != old_size)
delegate_->UpdatePreferredSize(this, new_size);
}
}