diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-24 04:25:00 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-24 04:25:00 +0000 |
commit | daed9531b8d4343077cc7dede18a20245e42f45b (patch) | |
tree | 30b1d7dc7e3771563d195263a69a7ba9570235d3 /chrome | |
parent | a1c2b8da95ec035e25bc7130b55a21bae328e4a5 (diff) | |
download | chromium_src-daed9531b8d4343077cc7dede18a20245e42f45b.zip chromium_src-daed9531b8d4343077cc7dede18a20245e42f45b.tar.gz chromium_src-daed9531b8d4343077cc7dede18a20245e42f45b.tar.bz2 |
Do some header file cleanup of RenderWidgetHost. I moved everything to be
private except the few functions that actually are overridden by
RenderViewHost.
Review URL: http://codereview.chromium.org/18739
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 190 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 30 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host.cc | 535 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host.h | 197 | ||||
-rw-r--r-- | chrome/browser/renderer_host/test_render_view_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/test_render_view_host.h | 3 |
7 files changed, 476 insertions, 483 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index dfe2c1f..7e3d771 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -787,7 +787,7 @@ NewTabUIContents::NewTabUIContents(Profile* profile, NewTabHTMLSource::set_first_view(false); } - render_view_host()->SetPaintObserver(new PaintTimer); + render_view_host()->set_paint_observer(new PaintTimer); } void NewTabUIContents::AttachMessageHandlers() { diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index dca1a1d..adfebaa 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -112,7 +112,7 @@ RenderViewHost::~RenderViewHost() { // Be sure to clean up any leftover state from cross-site requests. Singleton<CrossSiteRequestManager>()->SetHasPendingCrossSiteRequest( - process()->host_id(), routing_id_, false); + process()->host_id(), routing_id(), false); } bool RenderViewHost::CreateRenderView() { @@ -122,10 +122,10 @@ bool RenderViewHost::CreateRenderView() { // initialized it) or may not (we have our own process or the old process // crashed) have been initialized. Calling Init multiple times will be // ignored, so this is safe. - if (!process_->Init()) + if (!process()->Init()) return false; - DCHECK(process_->channel()); - DCHECK(process_->profile()); + DCHECK(process()->channel()); + DCHECK(process()->profile()); renderer_initialized_ = true; @@ -143,11 +143,11 @@ bool RenderViewHost::CreateRenderView() { 0); DCHECK(result) << "Couldn't duplicate the modal dialog handle for the renderer."; - DCHECK(view_); - Send(new ViewMsg_New(view_->GetPluginHWND(), + DCHECK(view()); + Send(new ViewMsg_New(view()->GetPluginHWND(), modal_dialog_event, delegate_->GetWebkitPrefs(), - routing_id_)); + routing_id())); // Set the alternate error page, which is profile specific, in the renderer. GURL url = delegate_->GetAlternateErrorPageURL(); @@ -156,7 +156,7 @@ bool RenderViewHost::CreateRenderView() { // If it's enabled, tell the renderer to set up the Javascript bindings for // sending messages back to the browser. Send(new ViewMsg_AllowBindings( - routing_id_, enable_dom_ui_bindings_, enable_external_host_bindings_)); + routing_id(), enable_dom_ui_bindings_, enable_external_host_bindings_)); // Let our delegate know that we created a RenderView. delegate_->RendererCreated(this); @@ -165,7 +165,7 @@ bool RenderViewHost::CreateRenderView() { } bool RenderViewHost::IsRenderViewLive() const { - return process_->channel() && renderer_initialized_; + return process()->channel() && renderer_initialized_; } void RenderViewHost::Init() { @@ -181,7 +181,7 @@ void RenderViewHost::NavigateToEntry(const NavigationEntry& entry, RendererSecurityPolicy::GetInstance()->GrantRequestURL( process()->host_id(), params.url); - DoNavigate(new ViewMsg_Navigate(routing_id_, params)); + DoNavigate(new ViewMsg_Navigate(routing_id(), params)); } void RenderViewHost::NavigateToURL(const GURL& url) { @@ -194,7 +194,7 @@ void RenderViewHost::NavigateToURL(const GURL& url) { RendererSecurityPolicy::GetInstance()->GrantRequestURL( process()->host_id(), params.url); - DoNavigate(new ViewMsg_Navigate(routing_id_, params)); + DoNavigate(new ViewMsg_Navigate(routing_id(), params)); } void RenderViewHost::DoNavigate(ViewMsg_Navigate* nav_message) { @@ -216,7 +216,7 @@ void RenderViewHost::LoadAlternateHTMLString(const std::string& html_text, bool new_navigation, const GURL& display_url, const std::string& security_info) { - Send(new ViewMsg_LoadAlternateHTMLText(routing_id_, html_text, + Send(new ViewMsg_LoadAlternateHTMLText(routing_id(), html_text, new_navigation, display_url, security_info)); } @@ -246,7 +246,7 @@ void RenderViewHost::FirePageBeforeUnload() { // handler. is_waiting_for_unload_ack_ = true; StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); - Send(new ViewMsg_ShouldClose(routing_id_)); + Send(new ViewMsg_ShouldClose(routing_id())); } } @@ -277,7 +277,7 @@ void RenderViewHost::ClosePage(int new_render_process_host_id, StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); if (IsRenderViewLive()) { - Send(new ViewMsg_ClosePage(routing_id_, + Send(new ViewMsg_ClosePage(routing_id(), new_render_process_host_id, new_request_id)); } else { @@ -292,7 +292,7 @@ void RenderViewHost::ClosePage(int new_render_process_host_id, void RenderViewHost::SetHasPendingCrossSiteRequest(bool has_pending_request, int request_id) { Singleton<CrossSiteRequestManager>()->SetHasPendingCrossSiteRequest( - process()->host_id(), routing_id_, has_pending_request); + process()->host_id(), routing_id(), has_pending_request); pending_request_id_ = request_id; } @@ -306,15 +306,15 @@ void RenderViewHost::OnCrossSiteResponse(int new_render_process_host_id, } void RenderViewHost::Stop() { - Send(new ViewMsg_Stop(routing_id_)); + Send(new ViewMsg_Stop(routing_id())); } bool RenderViewHost::GetPrintedPagesCount(const ViewMsg_Print_Params& params) { - return Send(new ViewMsg_GetPrintedPagesCount(routing_id_, params)); + return Send(new ViewMsg_GetPrintedPagesCount(routing_id(), params)); } bool RenderViewHost::PrintPages(const ViewMsg_PrintPages_Params& params) { - return Send(new ViewMsg_PrintPages(routing_id_, params)); + return Send(new ViewMsg_PrintPages(routing_id(), params)); } void RenderViewHost::StartFinding(int request_id, @@ -331,35 +331,35 @@ void RenderViewHost::StartFinding(int request_id, request.forward = forward; request.match_case = match_case; request.find_next = find_next; - Send(new ViewMsg_Find(routing_id_, request)); + Send(new ViewMsg_Find(routing_id(), request)); // This call is asynchronous and returns immediately. // The result of the search is sent as a notification message by the renderer. } void RenderViewHost::StopFinding(bool clear_selection) { - Send(new ViewMsg_StopFinding(routing_id_, clear_selection)); + Send(new ViewMsg_StopFinding(routing_id(), clear_selection)); } void RenderViewHost::Zoom(PageZoom::Function function) { - Send(new ViewMsg_Zoom(routing_id_, function)); + Send(new ViewMsg_Zoom(routing_id(), function)); } void RenderViewHost::SetPageEncoding(const std::wstring& encoding_name) { - Send(new ViewMsg_SetPageEncoding(routing_id_, encoding_name)); + Send(new ViewMsg_SetPageEncoding(routing_id(), encoding_name)); } void RenderViewHost::SetAlternateErrorPageURL(const GURL& url) { - Send(new ViewMsg_SetAltErrorPageURL(routing_id_, url)); + Send(new ViewMsg_SetAltErrorPageURL(routing_id(), url)); } void RenderViewHost::FillForm(const FormData& form_data) { - Send(new ViewMsg_FormFill(routing_id_, form_data)); + Send(new ViewMsg_FormFill(routing_id(), form_data)); } void RenderViewHost::FillPasswordForm( const PasswordFormDomManager::FillData& form_data) { - Send(new ViewMsg_FillPasswordForm(routing_id_, form_data)); + Send(new ViewMsg_FillPasswordForm(routing_id(), form_data)); } void RenderViewHost::DragTargetDragEnter(const WebDropData& drop_data, @@ -373,98 +373,98 @@ void RenderViewHost::DragTargetDragEnter(const WebDropData& drop_data, net::FilePathToFileURL(*iter)); policy->GrantUploadFile(process()->host_id(), *iter); } - Send(new ViewMsg_DragTargetDragEnter(routing_id_, drop_data, client_pt, + Send(new ViewMsg_DragTargetDragEnter(routing_id(), drop_data, client_pt, screen_pt)); } void RenderViewHost::DragTargetDragOver( const gfx::Point& client_pt, const gfx::Point& screen_pt) { - Send(new ViewMsg_DragTargetDragOver(routing_id_, client_pt, screen_pt)); + Send(new ViewMsg_DragTargetDragOver(routing_id(), client_pt, screen_pt)); } void RenderViewHost::DragTargetDragLeave() { - Send(new ViewMsg_DragTargetDragLeave(routing_id_)); + Send(new ViewMsg_DragTargetDragLeave(routing_id())); } void RenderViewHost::DragTargetDrop( const gfx::Point& client_pt, const gfx::Point& screen_pt) { - Send(new ViewMsg_DragTargetDrop(routing_id_, client_pt, screen_pt)); + Send(new ViewMsg_DragTargetDrop(routing_id(), client_pt, screen_pt)); } void RenderViewHost::ReservePageIDRange(int size) { - Send(new ViewMsg_ReservePageIDRange(routing_id_, size)); + Send(new ViewMsg_ReservePageIDRange(routing_id(), size)); } void RenderViewHost::ExecuteJavascriptInWebFrame( const std::wstring& frame_xpath, const std::wstring& jscript) { - Send(new ViewMsg_ScriptEvalRequest(routing_id_, frame_xpath, jscript)); + Send(new ViewMsg_ScriptEvalRequest(routing_id(), frame_xpath, jscript)); } void RenderViewHost::AddMessageToConsole( const std::wstring& frame_xpath, const std::wstring& msg, ConsoleMessageLevel level) { - Send(new ViewMsg_AddMessageToConsole(routing_id_, frame_xpath, msg, level)); + Send(new ViewMsg_AddMessageToConsole(routing_id(), frame_xpath, msg, level)); } void RenderViewHost::DebugCommand(const std::wstring& cmd) { - Send(new ViewMsg_DebugCommand(routing_id_, cmd)); + Send(new ViewMsg_DebugCommand(routing_id(), cmd)); } void RenderViewHost::DebugAttach() { if (!debugger_attached_) - Send(new ViewMsg_DebugAttach(routing_id_)); + Send(new ViewMsg_DebugAttach(routing_id())); } void RenderViewHost::DebugDetach() { if (debugger_attached_) { - Send(new ViewMsg_DebugDetach(routing_id_)); + Send(new ViewMsg_DebugDetach(routing_id())); debugger_attached_ = false; } } void RenderViewHost::DebugBreak(bool force) { if (debugger_attached_) - Send(new ViewMsg_DebugBreak(routing_id_, force)); + Send(new ViewMsg_DebugBreak(routing_id(), force)); } void RenderViewHost::Undo() { - Send(new ViewMsg_Undo(routing_id_)); + Send(new ViewMsg_Undo(routing_id())); } void RenderViewHost::Redo() { - Send(new ViewMsg_Redo(routing_id_)); + Send(new ViewMsg_Redo(routing_id())); } void RenderViewHost::Cut() { - Send(new ViewMsg_Cut(routing_id_)); + Send(new ViewMsg_Cut(routing_id())); } void RenderViewHost::Copy() { - Send(new ViewMsg_Copy(routing_id_)); + Send(new ViewMsg_Copy(routing_id())); } void RenderViewHost::Paste() { - Send(new ViewMsg_Paste(routing_id_)); + Send(new ViewMsg_Paste(routing_id())); } void RenderViewHost::Replace(const std::wstring& text_to_replace) { - Send(new ViewMsg_Replace(routing_id_, text_to_replace)); + Send(new ViewMsg_Replace(routing_id(), text_to_replace)); } void RenderViewHost::ToggleSpellCheck() { - Send(new ViewMsg_ToggleSpellCheck(routing_id_)); + Send(new ViewMsg_ToggleSpellCheck(routing_id())); } void RenderViewHost::AddToDictionary(const std::wstring& word) { - process_->AddWord(word); + process()->AddWord(word); } void RenderViewHost::Delete() { - Send(new ViewMsg_Delete(routing_id_)); + Send(new ViewMsg_Delete(routing_id())); } void RenderViewHost::SelectAll() { - Send(new ViewMsg_SelectAll(routing_id_)); + Send(new ViewMsg_SelectAll(routing_id())); } int RenderViewHost::DownloadImage(const GURL& url, int image_size) { @@ -474,16 +474,16 @@ int RenderViewHost::DownloadImage(const GURL& url, int image_size) { } static int next_id = 1; int id = next_id++; - Send(new ViewMsg_DownloadImage(routing_id_, id, url, image_size)); + Send(new ViewMsg_DownloadImage(routing_id(), id, url, image_size)); return id; } void RenderViewHost::GetApplicationInfo(int32 page_id) { - Send(new ViewMsg_GetApplicationInfo(routing_id_, page_id)); + Send(new ViewMsg_GetApplicationInfo(routing_id(), page_id)); } void RenderViewHost::CaptureThumbnail() { - Send(new ViewMsg_CaptureThumbnail(routing_id_)); + Send(new ViewMsg_CaptureThumbnail(routing_id())); } void RenderViewHost::JavaScriptMessageBoxClosed(IPC::Message* reply_msg, @@ -517,41 +517,41 @@ void RenderViewHost::ModalHTMLDialogClosed(IPC::Message* reply_msg, } void RenderViewHost::CopyImageAt(int x, int y) { - Send(new ViewMsg_CopyImageAt(routing_id_, x, y)); + Send(new ViewMsg_CopyImageAt(routing_id(), x, y)); } void RenderViewHost::InspectElementAt(int x, int y) { RendererSecurityPolicy::GetInstance()->GrantInspectElement( process()->host_id()); - Send(new ViewMsg_InspectElement(routing_id_, x, y)); + Send(new ViewMsg_InspectElement(routing_id(), x, y)); } void RenderViewHost::ShowJavaScriptConsole() { RendererSecurityPolicy::GetInstance()->GrantInspectElement( process()->host_id()); - Send(new ViewMsg_ShowJavaScriptConsole(routing_id_)); + Send(new ViewMsg_ShowJavaScriptConsole(routing_id())); } void RenderViewHost::DragSourceEndedAt( int client_x, int client_y, int screen_x, int screen_y) { Send(new ViewMsg_DragSourceEndedOrMoved( - routing_id_, client_x, client_y, screen_x, screen_y, true)); + routing_id(), client_x, client_y, screen_x, screen_y, true)); } void RenderViewHost::DragSourceMovedTo( int client_x, int client_y, int screen_x, int screen_y) { Send(new ViewMsg_DragSourceEndedOrMoved( - routing_id_, client_x, client_y, screen_x, screen_y, false)); + routing_id(), client_x, client_y, screen_x, screen_y, false)); } void RenderViewHost::DragSourceSystemDragEnded() { - Send(new ViewMsg_DragSourceSystemDragEnded(routing_id_)); + Send(new ViewMsg_DragSourceSystemDragEnded(routing_id())); } void RenderViewHost::AllowDomAutomationBindings() { // Expose the binding that allows the DOM to send messages here. - Send(new ViewMsg_AllowDomAutomationBindings(routing_id_, true)); + Send(new ViewMsg_AllowDomAutomationBindings(routing_id(), true)); } void RenderViewHost::AllowDOMUIBindings() { @@ -567,7 +567,7 @@ void RenderViewHost::AllowExternalHostBindings() { void RenderViewHost::SetDOMUIProperty(const std::string& name, const std::string& value) { DCHECK(enable_dom_ui_bindings_); - Send(new ViewMsg_SetDOMUIProperty(routing_id_, name, value)); + Send(new ViewMsg_SetDOMUIProperty(routing_id(), name, value)); } // static @@ -587,15 +587,15 @@ bool RenderViewHost::CanBlur() const { } void RenderViewHost::SetInitialFocus(bool reverse) { - Send(new ViewMsg_SetInitialFocus(routing_id_, reverse)); + Send(new ViewMsg_SetInitialFocus(routing_id(), reverse)); } void RenderViewHost::UpdateWebPreferences(const WebPreferences& prefs) { - Send(new ViewMsg_UpdateWebPreferences(routing_id_, prefs)); + Send(new ViewMsg_UpdateWebPreferences(routing_id(), prefs)); } void RenderViewHost::InstallMissingPlugin() { - Send(new ViewMsg_InstallMissingPlugin(routing_id_)); + Send(new ViewMsg_InstallMissingPlugin(routing_id())); } void RenderViewHost::FileSelected(const std::wstring& path) { @@ -603,7 +603,7 @@ void RenderViewHost::FileSelected(const std::wstring& path) { path); std::vector<std::wstring> files; files.push_back(path); - Send(new ViewMsg_RunFileChooserResponse(routing_id_, files)); + Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); } void RenderViewHost::MultiFilesSelected( @@ -613,7 +613,7 @@ void RenderViewHost::MultiFilesSelected( RendererSecurityPolicy::GetInstance()->GrantUploadFile( process()->host_id(), *file); } - Send(new ViewMsg_RunFileChooserResponse(routing_id_, files)); + Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); } void RenderViewHost::LoadStateChanged(const GURL& url, @@ -796,25 +796,13 @@ void RenderViewHost::OnMsgRendererReady() { } void RenderViewHost::OnMsgRendererGone() { - // Must reset these to ensure that mouse move events work with a new renderer. - mouse_move_pending_ = false; - next_mouse_move_.reset(); + // Our base class RenderWidgetHouse needs to reset some stuff. + RendererExited(); // Clearing this flag causes us to re-create the renderer when recovering // from a crashed renderer. renderer_initialized_ = false; - // Reset some fields in preparation for recovering from a crash. - resize_ack_pending_ = false; - current_size_ = gfx::Size(); - is_hidden_ = false; - - RendererExited(); - - if (view_) { - view_->RendererGone(); - view_ = NULL; // The View should be deleted by RendererGone. - } delegate_->RendererGone(this); OnDebugDisconnect(); } @@ -880,7 +868,7 @@ void RenderViewHost::OnMsgUpdateTargetURL(int32 page_id, // Send a notification back to the renderer that we are ready to // receive more target urls. - Send(new ViewMsg_UpdateTargetURL_ACK(routing_id_)); + Send(new ViewMsg_UpdateTargetURL_ACK(routing_id())); } void RenderViewHost::OnMsgThumbnail(const IPC::Message& msg) { @@ -918,18 +906,14 @@ void RenderViewHost::OnMsgDidRedirectProvisionalLoad(int32 page_id, void RenderViewHost::OnMsgDidStartLoading(int32 page_id) { delegate_->DidStartLoading(this, page_id); - - if (view_) { - view_->UpdateCursorIfOverSelf(); - } + if (view()) + view()->UpdateCursorIfOverSelf(); } void RenderViewHost::OnMsgDidStopLoading(int32 page_id) { delegate_->DidStopLoading(this, page_id); - - if (view_) { - view_->UpdateCursorIfOverSelf(); - } + if (view()) + view()->UpdateCursorIfOverSelf(); } void RenderViewHost::OnMsgDidLoadResourceFromMemoryCache( @@ -978,7 +962,7 @@ void RenderViewHost::OnMsgFindReply(int request_id, // browser using IPC. In an effort to not spam the browser we have the // browser send an ACK for each FindReply message and have the renderer // queue up the latest status message while waiting for this ACK. - Send(new ViewMsg_FindReplyACK(routing_id_)); + Send(new ViewMsg_FindReplyACK(routing_id())); } void RenderViewHost::OnMsgUpdateFavIconURL(int32 page_id, @@ -1053,11 +1037,11 @@ void RenderViewHost::OnPersonalizationEvent(const std::string& message, #endif void RenderViewHost::DisassociateFromPopupCount() { - Send(new ViewMsg_DisassociateFromPopupCount(routing_id_)); + Send(new ViewMsg_DisassociateFromPopupCount(routing_id())); } void RenderViewHost::PopupNotificationVisibilityChanged(bool visible) { - Send(new ViewMsg_PopupNotificationVisiblityChanged(routing_id_, visible)); + Send(new ViewMsg_PopupNotificationVisiblityChanged(routing_id(), visible)); } void RenderViewHost::OnMsgGoToEntryAtOffset(int offset) { @@ -1065,9 +1049,8 @@ void RenderViewHost::OnMsgGoToEntryAtOffset(int offset) { } void RenderViewHost::OnMsgSetTooltipText(const std::wstring& tooltip_text) { - if (view_) { - view_->SetTooltipText(tooltip_text); - } + if (view()) + view()->SetTooltipText(tooltip_text); } void RenderViewHost::OnMsgRunFileChooser(bool multiple_files, @@ -1175,7 +1158,7 @@ void RenderViewHost::DidDebugAttach() { } void RenderViewHost::OnUserMetricsRecordAction(const std::wstring& action) { - UserMetrics::RecordComputedAction(action.c_str(), process_->profile()); + UserMetrics::RecordComputedAction(action.c_str(), process()->profile()); } void RenderViewHost::UnhandledInputEvent(const WebInputEvent& event) { @@ -1192,12 +1175,8 @@ void RenderViewHost::UnhandledInputEvent(const WebInputEvent& event) { } } -void RenderViewHost::ForwardKeyboardEvent(const WebKeyboardEvent& key_event) { - if (key_event.type == WebKeyboardEvent::CHAR && - (key_event.key_code == VK_RETURN || key_event.key_code == VK_SPACE)) { - delegate_->OnEnterOrSpace(); - } - RenderWidgetHost::ForwardKeyboardEvent(key_event); +void RenderViewHost::OnEnterOrSpace() { + delegate_->OnEnterOrSpace(); } void RenderViewHost::OnMissingPluginStatus(int status) { @@ -1208,12 +1187,12 @@ void RenderViewHost::UpdateBackForwardListCount() { int back_list_count, forward_list_count; delegate_->GetHistoryListCount(&back_list_count, &forward_list_count); Send(new ViewMsg_UpdateBackForwardListCount( - routing_id_, back_list_count, forward_list_count)); + routing_id(), back_list_count, forward_list_count)); } void RenderViewHost::GetAllSavableResourceLinksForCurrentPage( const GURL& page_url) { - Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id_, + Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id(), page_url)); } @@ -1239,7 +1218,7 @@ void RenderViewHost::GetSerializedHtmlDataForCurrentPageWithLocalLinks( const std::vector<std::wstring>& local_paths, const std::wstring& local_directory_name) { Send(new ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks( - routing_id_, links, local_paths, local_directory_name)); + routing_id(), links, local_paths, local_directory_name)); } void RenderViewHost::OnReceivedSerializedHtmlData(const GURL& frame_url, @@ -1271,7 +1250,7 @@ void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name, void RenderViewHost::AutofillSuggestionsReturned( const std::vector<std::wstring>& suggestions, int64 node_id, int request_id, int default_suggestion_index) { - Send(new ViewMsg_AutofillSuggestions(routing_id_, node_id, + Send(new ViewMsg_AutofillSuggestions(routing_id(), node_id, request_id, suggestions, -1)); // Default index -1 means no default suggestion. } @@ -1298,13 +1277,12 @@ void RenderViewHost::OnDebugDisconnect() { #ifdef CHROME_PERSONALIZATION void RenderViewHost::RaisePersonalizationEvent(std::string event_name, std::string event_arg) { - Send(new ViewMsg_PersonalizationEvent(routing_id_, - event_name, - event_arg)); + Send(new ViewMsg_PersonalizationEvent(routing_id(), event_name, event_arg)); } #endif void RenderViewHost::ForwardMessageFromExternalHost( const std::string& target, const std::string& message) { - Send(new ViewMsg_HandleMessageFromExternalHost(routing_id_, target, message)); + Send(new ViewMsg_HandleMessageFromExternalHost(routing_id(), target, + message)); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 4ae497f..f4c40ed 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -100,9 +100,6 @@ class RenderViewHost : public RenderWidgetHost { virtual bool CreateRenderView(); // Returns true if the RenderView is active and has not crashed. virtual bool IsRenderViewLive() const; - // Create a new RenderViewHost but recycle an existing RenderView child - // process. - virtual void Init(); // Load the specified entry, optionally reloading. virtual void NavigateToEntry(const NavigationEntry& entry, bool is_reload); @@ -329,16 +326,6 @@ class RenderViewHost : public RenderWidgetHost { bool reload, ViewMsg_Navigate_Params* params); - // Overridden from RenderWidgetHost: We are hosting a web page. - virtual bool IsRenderView() { return true; } - virtual bool CanBlur() const; - - // IPC::Channel::Listener - virtual void OnMessageReceived(const IPC::Message& msg); - - // Override the RenderWidgetHost's Shutdown method. - virtual void Shutdown(); - // Tells the renderer view to focus the first (last if reverse is true) node. void SetInitialFocus(bool reverse); @@ -414,12 +401,21 @@ class RenderViewHost : public RenderWidgetHost { int request_id, int default_suggestion_index); + // RenderWidgetHost public overrides. + virtual void Init(); + virtual void Shutdown(); + virtual bool IsRenderView() { return true; } + virtual void OnMessageReceived(const IPC::Message& msg); + virtual bool CanBlur() const; + protected: - // Overridden from RenderWidgetHost: + // RenderWidgetHost protected overrides. virtual void UnhandledInputEvent(const WebInputEvent& event); - virtual void ForwardKeyboardEvent(const WebKeyboardEvent& key_event); + virtual void OnEnterOrSpace(); + virtual void NotifyRendererUnresponsive(); + virtual void NotifyRendererResponsive(); - // IPC message handlers: + // IPC message handlers. void OnMsgCreateWindow(int route_id, HANDLE modal_dialog_event); void OnMsgCreateWidget(int route_id, bool activatable); void OnMsgShowView(int route_id, @@ -525,8 +521,6 @@ class RenderViewHost : public RenderWidgetHost { const std::wstring& user_text, int64 node_id, int request_id); - virtual void NotifyRendererUnresponsive(); - virtual void NotifyRendererResponsive(); // Helper function to send a navigation message. If a cross-site request is // in progress, we may be suspended while waiting for the onbeforeunload diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index 63dd0f3..865abbb 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -73,8 +73,16 @@ void RenderWidgetHost::Init() { WasResized(); } -/////////////////////////////////////////////////////////////////////////////// -// RenderWidgetHost, protected: +void RenderWidgetHost::Shutdown() { + if (process_->channel()) { + // Tell the renderer object to close. + process_->ReportExpectingClose(routing_id_); + bool rv = Send(new ViewMsg_Close(routing_id_)); + DCHECK(rv); + } + + Destroy(); +} IPC_DEFINE_MESSAGE_MAP(RenderWidgetHost) IPC_MESSAGE_HANDLER(ViewHostMsg_RendererReady, OnMsgRendererReady) @@ -91,6 +99,269 @@ IPC_DEFINE_MESSAGE_MAP(RenderWidgetHost) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() +bool RenderWidgetHost::Send(IPC::Message* msg) { + return process_->Send(msg); +} + +void RenderWidgetHost::WasHidden() { + is_hidden_ = true; + + // Don't bother reporting hung state when we aren't the active tab. + StopHangMonitorTimeout(); + + // If we have a renderer, then inform it that we are being hidden so it can + // reduce its resource utilization. + Send(new ViewMsg_WasHidden(routing_id_)); + + // TODO(darin): what about constrained windows? it doesn't look like they + // see a message when their parent is hidden. maybe there is something more + // generic we can do at the TabContents API level instead of relying on + // Windows messages. + + // Tell the RenderProcessHost we were hidden. + process_->WidgetHidden(); +} + +void RenderWidgetHost::WasRestored() { + // When we create the widget, it is created as *not* hidden. + if (!is_hidden_) + return; + is_hidden_ = false; + + BackingStore* backing_store = BackingStoreManager::Lookup(this); + // If we already have a backing store for this widget, then we don't need to + // repaint on restore _unless_ we know that our backing store is invalid. + bool needs_repainting; + if (needs_repainting_on_restore_ || !backing_store) { + needs_repainting = true; + needs_repainting_on_restore_ = false; + } else { + needs_repainting = false; + } + Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); + + process_->WidgetRestored(); +} + +void RenderWidgetHost::WasResized() { + if (resize_ack_pending_ || !process_->channel() || !view_) + return; + + gfx::Rect view_bounds = view_->GetViewBounds(); + gfx::Size new_size(view_bounds.width(), view_bounds.height()); + + // Avoid asking the RenderWidget to resize to its current size, since it + // won't send us a PaintRect message in that case. + if (new_size == current_size_) + return; + + // We don't expect to receive an ACK when the requested size is empty. + if (!new_size.IsEmpty()) + resize_ack_pending_ = true; + + if (!Send(new ViewMsg_Resize(routing_id_, new_size))) + resize_ack_pending_ = false; +} + +void RenderWidgetHost::Focus() { + Send(new ViewMsg_SetFocus(routing_id_, true)); +} + +void RenderWidgetHost::Blur() { + Send(new ViewMsg_SetFocus(routing_id_, false)); +} + +void RenderWidgetHost::LostCapture() { + Send(new ViewMsg_MouseCaptureLost(routing_id_)); +} + +void RenderWidgetHost::ViewDestroyed() { + // TODO(evanm): tracking this may no longer be necessary; + // eliminate this function if so. + view_ = NULL; +} + +void RenderWidgetHost::SetIsLoading(bool is_loading) { + is_loading_ = is_loading; + if (!view_) + return; + view_->SetIsLoading(is_loading); +} + +BackingStore* RenderWidgetHost::GetBackingStore() { + // We should not be asked to paint while we are hidden. If we are hidden, + // then it means that our consumer failed to call WasRestored. + DCHECK(!is_hidden_) << "GetBackingStore called while hidden!"; + + // We might have a cached backing store that we can reuse! + BackingStore* backing_store = + BackingStoreManager::GetBackingStore(this, current_size_); + // If we fail to find a backing store in the cache, send out a request + // to the renderer to paint the view if required. + if (!backing_store && !repaint_ack_pending_ && !resize_ack_pending_ && + !view_being_painted_) { + repaint_start_time_ = TimeTicks::Now(); + repaint_ack_pending_ = true; + Send(new ViewMsg_Repaint(routing_id_, current_size_)); + } + + // When we have asked the RenderWidget to resize, and we are still waiting on + // a response, block for a little while to see if we can't get a response + // before returning the old (incorrectly sized) backing store. + if (resize_ack_pending_ || !backing_store) { + IPC::Message msg; + TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); + if (process_->WaitForPaintMsg(routing_id_, max_delay, &msg)) { + suppress_view_updating_ = true; + ViewHostMsg_PaintRect::Dispatch( + &msg, this, &RenderWidgetHost::OnMsgPaintRect); + suppress_view_updating_ = false; + backing_store = BackingStoreManager::GetBackingStore(this, current_size_); + } + } + + return backing_store; +} + +void RenderWidgetHost::StartHangMonitorTimeout(TimeDelta delay) { + time_when_considered_hung_ = Time::Now() + delay; + + // If we already have a timer that will expire at or before the given delay, + // then we have nothing more to do now. + if (hung_renderer_timer_.IsRunning() && + hung_renderer_timer_.GetCurrentDelay() <= delay) + return; + + // Either the timer is not yet running, or we need to adjust the timer to + // fire sooner. + hung_renderer_timer_.Stop(); + hung_renderer_timer_.Start(delay, this, + &RenderWidgetHost::CheckRendererIsUnresponsive); +} + +void RenderWidgetHost::RestartHangMonitorTimeout() { + StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); +} + +void RenderWidgetHost::StopHangMonitorTimeout() { + time_when_considered_hung_ = Time(); + RendererIsResponsive(); + + // We do not bother to stop the hung_renderer_timer_ here in case it will be + // started again shortly, which happens to be the common use case. +} + +void RenderWidgetHost::SystemThemeChanged() { + Send(new ViewMsg_ThemeChanged(routing_id_)); +} + +void RenderWidgetHost::ForwardMouseEvent(const WebMouseEvent& mouse_event) { + // Avoid spamming the renderer with mouse move events. It is important + // to note that WM_MOUSEMOVE events are anyways synthetic, but since our + // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way + // more WM_MOUSEMOVE events than we wish to send to the renderer. + if (mouse_event.type == WebInputEvent::MOUSE_MOVE) { + if (mouse_move_pending_) { + next_mouse_move_.reset(new WebMouseEvent(mouse_event)); + return; + } + mouse_move_pending_ = true; + } + + ForwardInputEvent(mouse_event, sizeof(WebMouseEvent)); +} + +void RenderWidgetHost::ForwardWheelEvent( + const WebMouseWheelEvent& wheel_event) { + ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent)); +} + +void RenderWidgetHost::ForwardKeyboardEvent(const WebKeyboardEvent& key_event) { + if (key_event.type == WebKeyboardEvent::CHAR && + (key_event.key_code == VK_RETURN || key_event.key_code == VK_SPACE)) + OnEnterOrSpace(); + + ForwardInputEvent(key_event, sizeof(WebKeyboardEvent)); +} + +void RenderWidgetHost::ForwardInputEvent(const WebInputEvent& input_event, + int event_size) { + if (!process_->channel()) + return; + + IPC::Message* message = new ViewMsg_HandleInputEvent(routing_id_); + message->WriteData( + reinterpret_cast<const char*>(&input_event), event_size); + input_event_start_time_ = TimeTicks::Now(); + Send(message); + + // Any input event cancels a pending mouse move event. + next_mouse_move_.reset(); + + StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); +} + +void RenderWidgetHost::RendererExited() { + // Must reset these to ensure that mouse move events work with a new renderer. + mouse_move_pending_ = false; + next_mouse_move_.reset(); + + // Reset some fields in preparation for recovering from a crash. + resize_ack_pending_ = false; + current_size_ = gfx::Size(); + is_hidden_ = false; + + if (view_) { + view_->RendererGone(); + view_ = NULL; // The View should be deleted by RendererGone. + } + + BackingStoreManager::RemoveBackingStore(this); +} + +void RenderWidgetHost::Destroy() { + NotificationService::current()->Notify( + NOTIFY_RENDER_WIDGET_HOST_DESTROYED, + Source<RenderWidgetHost>(this), + NotificationService::NoDetails()); + + // Tell the view to die. + // Note that in the process of the view shutting down, it can call a ton + // of other messages on us. So if you do any other deinitialization here, + // do it after this call to view_->Destroy(). + if (view_) + view_->Destroy(); + + delete this; +} + +void RenderWidgetHost::CheckRendererIsUnresponsive() { + // If we received a call to StopHangMonitorTimeout. + if (time_when_considered_hung_.is_null()) + return; + + // If we have not waited long enough, then wait some more. + Time now = Time::Now(); + if (now < time_when_considered_hung_) { + StartHangMonitorTimeout(time_when_considered_hung_ - now); + return; + } + + // OK, looks like we have a hung renderer! + NotificationService::current()->Notify(NOTIFY_RENDERER_PROCESS_HANG, + Source<RenderWidgetHost>(this), + NotificationService::NoDetails()); + is_unresponsive_ = true; + NotifyRendererUnresponsive(); +} + +void RenderWidgetHost::RendererIsResponsive() { + if (is_unresponsive_) { + is_unresponsive_ = false; + NotifyRendererResponsive(); + } +} + void RenderWidgetHost::OnMsgRendererReady() { WasResized(); } @@ -275,229 +546,6 @@ void RenderWidgetHost::OnMsgImeUpdateStatus(ViewHostMsg_ImeControl control, } } -/////////////////////////////////////////////////////////////////////////////// - -void RenderWidgetHost::WasHidden() { - is_hidden_ = true; - - // Don't bother reporting hung state when we aren't the active tab. - StopHangMonitorTimeout(); - - // If we have a renderer, then inform it that we are being hidden so it can - // reduce its resource utilization. - Send(new ViewMsg_WasHidden(routing_id_)); - - // TODO(darin): what about constrained windows? it doesn't look like they - // see a message when their parent is hidden. maybe there is something more - // generic we can do at the TabContents API level instead of relying on - // Windows messages. - - // Tell the RenderProcessHost we were hidden. - process_->WidgetHidden(); -} - -void RenderWidgetHost::WasRestored() { - // When we create the widget, it is created as *not* hidden. - if (!is_hidden_) - return; - is_hidden_ = false; - - BackingStore* backing_store = BackingStoreManager::Lookup(this); - // If we already have a backing store for this widget, then we don't need to - // repaint on restore _unless_ we know that our backing store is invalid. - bool needs_repainting; - if (needs_repainting_on_restore_ || !backing_store) { - needs_repainting = true; - needs_repainting_on_restore_ = false; - } else { - needs_repainting = false; - } - Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); - - process_->WidgetRestored(); -} - -void RenderWidgetHost::WasResized() { - if (resize_ack_pending_ || !process_->channel() || !view_) - return; - - gfx::Rect view_bounds = view_->GetViewBounds(); - gfx::Size new_size(view_bounds.width(), view_bounds.height()); - - // Avoid asking the RenderWidget to resize to its current size, since it - // won't send us a PaintRect message in that case. - if (new_size == current_size_) - return; - - // We don't expect to receive an ACK when the requested size is empty. - if (!new_size.IsEmpty()) - resize_ack_pending_ = true; - - if (!Send(new ViewMsg_Resize(routing_id_, new_size))) - resize_ack_pending_ = false; -} - -void RenderWidgetHost::ForwardMouseEvent(const WebMouseEvent& mouse_event) { - // Avoid spamming the renderer with mouse move events. It is important - // to note that WM_MOUSEMOVE events are anyways synthetic, but since our - // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way - // more WM_MOUSEMOVE events than we wish to send to the renderer. - if (mouse_event.type == WebInputEvent::MOUSE_MOVE) { - if (mouse_move_pending_) { - next_mouse_move_.reset(new WebMouseEvent(mouse_event)); - return; - } - mouse_move_pending_ = true; - } - - ForwardInputEvent(mouse_event, sizeof(WebMouseEvent)); -} - -void RenderWidgetHost::ForwardKeyboardEvent( - const WebKeyboardEvent& key_event) { - ForwardInputEvent(key_event, sizeof(WebKeyboardEvent)); -} - -void RenderWidgetHost::ForwardWheelEvent( - const WebMouseWheelEvent& wheel_event) { - ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent)); -} - -void RenderWidgetHost::ForwardInputEvent(const WebInputEvent& input_event, - int event_size) { - if (!process_->channel()) - return; - - IPC::Message* message = new ViewMsg_HandleInputEvent(routing_id_); - message->WriteData( - reinterpret_cast<const char*>(&input_event), event_size); - input_event_start_time_ = TimeTicks::Now(); - Send(message); - - // any input event cancels a pending mouse move event - next_mouse_move_.reset(); - - StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); -} - -void RenderWidgetHost::Shutdown() { - if (process_->channel()) { - // Tell the renderer object to close. - process_->ReportExpectingClose(routing_id_); - bool rv = Send(new ViewMsg_Close(routing_id_)); - DCHECK(rv); - } - - Destroy(); -} - -void RenderWidgetHost::Focus() { - Send(new ViewMsg_SetFocus(routing_id_, true)); -} - -void RenderWidgetHost::Blur() { - Send(new ViewMsg_SetFocus(routing_id_, false)); -} - -void RenderWidgetHost::LostCapture() { - Send(new ViewMsg_MouseCaptureLost(routing_id_)); -} - -void RenderWidgetHost::ViewDestroyed() { - // TODO(evanm): tracking this may no longer be necessary; - // eliminate this function if so. - view_ = NULL; -} - -void RenderWidgetHost::Destroy() { - NotificationService::current()->Notify( - NOTIFY_RENDER_WIDGET_HOST_DESTROYED, - Source<RenderWidgetHost>(this), - NotificationService::NoDetails()); - - // Tell the view to die. - // Note that in the process of the view shutting down, it can call a ton - // of other messages on us. So if you do any other deinitialization here, - // do it after this call to view_->Destroy(). - if (view_) - view_->Destroy(); - - delete this; -} - -void RenderWidgetHost::CheckRendererIsUnresponsive() { - // If we received a call to StopHangMonitorTimeout. - if (time_when_considered_hung_.is_null()) - return; - - // If we have not waited long enough, then wait some more. - Time now = Time::Now(); - if (now < time_when_considered_hung_) { - StartHangMonitorTimeout(time_when_considered_hung_ - now); - return; - } - - // OK, looks like we have a hung renderer! - NotificationService::current()->Notify(NOTIFY_RENDERER_PROCESS_HANG, - Source<RenderWidgetHost>(this), - NotificationService::NoDetails()); - is_unresponsive_ = true; - NotifyRendererUnresponsive(); -} - -void RenderWidgetHost::RendererIsResponsive() { - if (is_unresponsive_) { - is_unresponsive_ = false; - NotifyRendererResponsive(); - } -} - -bool RenderWidgetHost::Send(IPC::Message* msg) { - return process_->Send(msg); -} - -void RenderWidgetHost::SetIsLoading(bool is_loading) { - is_loading_ = is_loading; - if (!view_) - return; - view_->SetIsLoading(is_loading); -} - -BackingStore* RenderWidgetHost::GetBackingStore() { - // We should not be asked to paint while we are hidden. If we are hidden, - // then it means that our consumer failed to call WasRestored. - DCHECK(!is_hidden_) << "GetBackingStore called while hidden!"; - - // We might have a cached backing store that we can reuse! - BackingStore* backing_store = - BackingStoreManager::GetBackingStore(this, current_size_); - // If we fail to find a backing store in the cache, send out a request - // to the renderer to paint the view if required. - if (!backing_store && !repaint_ack_pending_ && !resize_ack_pending_ && - !view_being_painted_) { - repaint_start_time_ = TimeTicks::Now(); - repaint_ack_pending_ = true; - Send(new ViewMsg_Repaint(routing_id_, current_size_)); - } - - // When we have asked the RenderWidget to resize, and we are still waiting on - // a response, block for a little while to see if we can't get a response - // before returning the old (incorrectly sized) backing store. - if (resize_ack_pending_ || !backing_store) { - IPC::Message msg; - TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); - if (process_->WaitForPaintMsg(routing_id_, max_delay, &msg)) { - suppress_view_updating_ = true; - ViewHostMsg_PaintRect::Dispatch( - &msg, this, &RenderWidgetHost::OnMsgPaintRect); - suppress_view_updating_ = false; - backing_store = BackingStoreManager::GetBackingStore(this, current_size_); - } - } - - return backing_store; -} - void RenderWidgetHost::PaintBackingStoreRect(HANDLE bitmap, const gfx::Rect& bitmap_rect, const gfx::Size& view_size) { @@ -549,40 +597,3 @@ void RenderWidgetHost::ScrollBackingStoreRect(HANDLE bitmap, backing_store->ScrollRect(process_->process().handle(), bitmap, bitmap_rect, dx, dy, clip_rect, view_size); } - - -void RenderWidgetHost::RestartHangMonitorTimeout() { - StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); -} - -void RenderWidgetHost::StopHangMonitorTimeout() { - time_when_considered_hung_ = Time(); - RendererIsResponsive(); - - // We do not bother to stop the hung_renderer_timer_ here in case it will be - // started again shortly, which happens to be the common use case. -} - -void RenderWidgetHost::StartHangMonitorTimeout(TimeDelta delay) { - time_when_considered_hung_ = Time::Now() + delay; - - // If we already have a timer that will expire at or before the given delay, - // then we have nothing more to do now. - if (hung_renderer_timer_.IsRunning() && - hung_renderer_timer_.GetCurrentDelay() <= delay) - return; - - // Either the timer is not yet running, or we need to adjust the timer to - // fire sooner. - hung_renderer_timer_.Stop(); - hung_renderer_timer_.Start(delay, this, - &RenderWidgetHost::CheckRendererIsUnresponsive); -} - -void RenderWidgetHost::RendererExited() { - BackingStoreManager::RemoveBackingStore(this); -} - -void RenderWidgetHost::SystemThemeChanged() { - Send(new ViewMsg_ThemeChanged(routing_id_)); -} diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h index 5992b69..70d6cf5 100644 --- a/chrome/browser/renderer_host/render_widget_host.h +++ b/chrome/browser/renderer_host/render_widget_host.h @@ -107,6 +107,14 @@ struct WebPluginGeometry; // class RenderWidgetHost : public IPC::Channel::Listener { public: + // An interface that gets called whenever a paint occurs. + // Used in performance tests. + class PaintObserver { + public: + virtual ~PaintObserver() {} + virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh) = 0; + }; + // routing_id can be MSG_ROUTING_NONE, in which case the next available // routing id is taken from the RenderProcessHost. RenderWidgetHost(RenderProcessHost* process, int routing_id); @@ -122,14 +130,22 @@ class RenderWidgetHost : public IPC::Channel::Listener { RenderProcessHost* process() const { return process_; } int routing_id() const { return routing_id_; } - // Manual RTTI FTW. We are not hosting a web page. - virtual bool IsRenderView() { return false; } + // Set the PaintObserver on this object. Takes ownership. + void set_paint_observer(PaintObserver* paint_observer) { + paint_observer_.reset(paint_observer); + } // Called when a renderer object already been created for this host, and we // just need to be attached to it. Used for window.open, <select> dropdown // menus, and other times when the renderer initiates creating an object. virtual void Init(); + // Tells the renderer to die and then calls Destroy(). + virtual void Shutdown(); + + // Manual RTTI FTW. We are not hosting a web page. + virtual bool IsRenderView() { return false; } + // IPC::Channel::Listener virtual void OnMessageReceived(const IPC::Message& msg); @@ -144,9 +160,6 @@ class RenderWidgetHost : public IPC::Channel::Listener { // Called to notify the RenderWidget that it has been resized. void WasResized(); - // Tells the renderer to die and then calls Destroy(). - virtual void Shutdown(); - void Focus(); void Blur(); void LostCapture(); @@ -155,7 +168,7 @@ class RenderWidgetHost : public IPC::Channel::Listener { void ViewDestroyed(); // Indicates if the page has finished loading. - virtual void SetIsLoading(bool is_loading); + void SetIsLoading(bool is_loading); // Get access to the widget's backing store. If a resize is in progress, // then the current size of the backing store may be less than the size of @@ -163,53 +176,76 @@ class RenderWidgetHost : public IPC::Channel::Listener { // not be created. BackingStore* GetBackingStore(); - // An interface that gets called when paints happen. - // Used in performance tests. - class PaintObserver; - // Set the PaintObserver on this object. Takes ownership. - void SetPaintObserver(PaintObserver* paint_observer) { - paint_observer_.reset(paint_observer); - } - - // Checks to see if we can give up focus to this widget through a - // javascript call. + // Checks to see if we can give up focus to this widget through a JS call. virtual bool CanBlur() const { return true; } + // Starts a hang monitor timeout. If there's already a hang monitor timeout + // the new one will only fire if it has a shorter delay than the time + // left on the existing timeouts. + void StartHangMonitorTimeout(base::TimeDelta delay); + // Restart the active hang monitor timeout. Clears all existing timeouts and // starts with a new one. This can be because the renderer has become // active, the tab is being hidden, or the user has chosen to wait some more // to give the tab a chance to become active and we don't want to display a // warning too soon. void RestartHangMonitorTimeout(); - + // Stops all existing hang monitor timeouts and assumes the renderer is // responsive. void StopHangMonitorTimeout(); - // Starts a hang monitor timeout. If there's already a hang monitor timeout - // the new one will only fire if it has a shorter delay than the time - // left on the existing timeouts. - void StartHangMonitorTimeout(base::TimeDelta delay); - - // Called when we receive a notification indicating that the renderer - // process has gone. - void RendererExited(); - // Called when the system theme changes. At this time all existing native // theme handles are invalid and the renderer must obtain new ones and // repaint. void SystemThemeChanged(); + // Forwards the given message to the renderer. These are called by the view + // when it has received a message. + void ForwardMouseEvent(const WebMouseEvent& mouse_event); + void ForwardWheelEvent(const WebMouseWheelEvent& wheel_event); + void ForwardKeyboardEvent(const WebKeyboardEvent& key_event); + void ForwardInputEvent(const WebInputEvent& input_event, int event_size); + protected: - // Called when we an InputEvent was not processed by the renderer. - virtual void UnhandledInputEvent(const WebInputEvent& event) { } + // Called when we receive a notification indicating that the renderer + // process has gone. This will reset our state so that our state will be + // consistent if a new renderer is created. + void RendererExited(); + + // Called when we an InputEvent was not processed by the renderer. This is + // overridden by RenderView to send upwards to its delegate. + virtual void UnhandledInputEvent(const WebInputEvent& event) {} + + // Notification that the user pressed the enter key or the spacebar. The + // render view host overrides this to forward the information to its delegate + // (see corresponding function in RenderViewHostDelegate). + virtual void OnEnterOrSpace() {} + + // Callbacks for notification when the renderer becomes unresponsive to user + // input events, and subsequently responsive again. RenderViewHost overrides + // these to tell its delegate to show the user a warning. + virtual void NotifyRendererUnresponsive() {} + virtual void NotifyRendererResponsive() {} + + private: + // Tell this object to destroy itself. + void Destroy(); + + // Checks whether the renderer is hung and calls NotifyRendererUnresponsive + // if it is. + void CheckRendererIsUnresponsive(); + + // Called if we know the renderer is responsive. When we currently thing the + // renderer is unresponsive, this will clear that state and call + // NotifyRendererResponsive. + void RendererIsResponsive(); // IPC message handlers void OnMsgRendererReady(); void OnMsgRendererGone(); void OnMsgClose(); void OnMsgRequestMove(const gfx::Rect& pos); - void OnMsgResizeAck(); void OnMsgPaintRect(const ViewHostMsg_PaintRect_Params& params); void OnMsgScrollRect(const ViewHostMsg_ScrollRect_Params& params); void OnMsgInputEventAck(const IPC::Message& message); @@ -219,26 +255,26 @@ class RenderWidgetHost : public IPC::Channel::Listener { void OnMsgImeUpdateStatus(ViewHostMsg_ImeControl control, const gfx::Rect& caret_rect); - // TODO(beng): (Cleanup) remove this friendship once we expose a clean API to - // RenderWidgetHost Views. This exists only to give RenderWidgetHostView - // access to Forward*Event. - friend class RenderWidgetHostViewWin; - - void ForwardMouseEvent(const WebMouseEvent& mouse_event); - virtual void ForwardKeyboardEvent(const WebKeyboardEvent& key_event); - void ForwardWheelEvent(const WebMouseWheelEvent& wheel_event); - void ForwardInputEvent(const WebInputEvent& input_event, int event_size); + // Paints the given bitmap to the current backing store at the given location. + void PaintBackingStoreRect(HANDLE bitmap, + const gfx::Rect& bitmap_rect, + const gfx::Size& view_size); - // Tell this object to destroy itself. - void Destroy(); + // Scrolls the given |clip_rect| in the backing by the given dx/dy amount. The + // |bitmap| and its corresponding location |bitmap_rect| in the backing store + // is the newly painted pixels by the renderer. + void ScrollBackingStoreRect(HANDLE bitmap, + const gfx::Rect& bitmap_rect, + int dx, int dy, + const gfx::Rect& clip_rect, + const gfx::Size& view_size); - // Callbacks for notification when the renderer becomes unresponsive to user - // input events, and subsequently responsive again. The delegate can use - // these notifications to show a warning. - void CheckRendererIsUnresponsive(); - virtual void NotifyRendererUnresponsive() {} - void RendererIsResponsive(); - virtual void NotifyRendererResponsive() {} + // The View associated with the RenderViewHost. The lifetime of this object + // is associated with the lifetime of the Render process. If the Renderer + // crashes, its View is destroyed and this pointer becomes NULL, even though + // render_view_host_ lives on to load another URL (creating a new View while + // doing so). + RenderWidgetHostView* view_; // Created during construction but initialized during Init*(). Therefore, it // is guaranteed never to be NULL, but its channel may be NULL if the @@ -248,8 +284,24 @@ class RenderWidgetHost : public IPC::Channel::Listener { // The ID of the corresponding object in the Renderer Instance. int routing_id_; - bool resize_ack_pending_; // True when waiting for RESIZE_ACK. - gfx::Size current_size_; // The current size of the RenderWidget. + // Indicates whether a page is loading or not. + bool is_loading_; + + // Indicates whether a page is hidden or not. + bool is_hidden_; + + // Set if we are waiting for a repaint ack for the view. + bool repaint_ack_pending_; + + // True when waiting for RESIZE_ACK. + bool resize_ack_pending_; + + // The current size of the RenderWidget. + gfx::Size current_size_; + + // If true, then we should not ask our view to repaint when our backingstore + // is updated. + bool suppress_view_updating_; // True if a mouse move event was sent to the render view and we are waiting // for a corresponding ViewHostMsg_HandleInputEvent_ACK message. @@ -259,30 +311,18 @@ class RenderWidgetHost : public IPC::Channel::Listener { // is true). scoped_ptr<WebMouseEvent> next_mouse_move_; - // The View associated with the RenderViewHost. The lifetime of this object - // is associated with the lifetime of the Render process. If the Renderer - // crashes, its View is destroyed and this pointer becomes NULL, even though - // render_view_host_ lives on to load another URL (creating a new View while - // doing so). - RenderWidgetHostView* view_; - // The time when an input event was sent to the RenderWidget. base::TimeTicks input_event_start_time_; - // Indicates whether a page is loading or not. - bool is_loading_; - // Indicates whether a page is hidden or not. - bool is_hidden_; - // If true, then we should not ask our view to repaint when our backingstore - // is updated. - bool suppress_view_updating_; - // If true, then we should repaint when restoring even if we have a // backingstore. This flag is set to true if we receive a paint message // while is_hidden_ to true. Even though we tell the render widget to hide // itself, a paint message could already be in flight at that point. bool needs_repainting_on_restore_; + // This is true if the renderer is currently unresponsive. + bool is_unresponsive_; + // The following value indicates a time in the future when we would consider // the renderer hung if it does not generate an appropriate response message. base::Time time_when_considered_hung_; @@ -290,46 +330,17 @@ class RenderWidgetHost : public IPC::Channel::Listener { // This timer runs to check if time_when_considered_hung_ has past. base::OneShotTimer<RenderWidgetHost> hung_renderer_timer_; - // This is true if the renderer is currently unresponsive. - bool is_unresponsive_; - // Optional observer that listens for notifications of painting. scoped_ptr<PaintObserver> paint_observer_; // Set when we call DidPaintRect/DidScrollRect on the view. bool view_being_painted_; - // Set if we are waiting for a repaint ack for the view. - bool repaint_ack_pending_; - // Used for UMA histogram logging to measure the time for a repaint view // operation to finish. base::TimeTicks repaint_start_time_; - private: - // Paints the given bitmap to the current backing store at the given location. - void PaintBackingStoreRect(HANDLE bitmap, - const gfx::Rect& bitmap_rect, - const gfx::Size& view_size); - - // Scrolls the given |clip_rect| in the backing by the given dx/dy amount. The - // |bitmap| and its corresponding location |bitmap_rect| in the backing store - // is the newly painted pixels by the renderer. - void ScrollBackingStoreRect(HANDLE bitmap, - const gfx::Rect& bitmap_rect, - int dx, int dy, - const gfx::Rect& clip_rect, - const gfx::Size& view_size); - DISALLOW_COPY_AND_ASSIGN(RenderWidgetHost); }; -class RenderWidgetHost::PaintObserver { - public: - virtual ~PaintObserver() {} - - // Called each time the RenderWidgetHost paints. - virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh) = 0; -}; - #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ diff --git a/chrome/browser/renderer_host/test_render_view_host.cc b/chrome/browser/renderer_host/test_render_view_host.cc index 1c77bb8..4442138 100644 --- a/chrome/browser/renderer_host/test_render_view_host.cc +++ b/chrome/browser/renderer_host/test_render_view_host.cc @@ -20,7 +20,7 @@ TestRenderViewHost::~TestRenderViewHost() { ++*delete_counter_; // Since this isn't a traditional view, we have to delete it. - delete view_; + delete view(); } bool TestRenderViewHost::CreateRenderView() { diff --git a/chrome/browser/renderer_host/test_render_view_host.h b/chrome/browser/renderer_host/test_render_view_host.h index 6741067..f7d8bfa 100644 --- a/chrome/browser/renderer_host/test_render_view_host.h +++ b/chrome/browser/renderer_host/test_render_view_host.h @@ -51,10 +51,9 @@ class TestRenderWidgetHostView : public RenderWidgetHostView { virtual void Show() { is_showing_ = true; } virtual void Hide() { is_showing_ = false; } virtual gfx::Rect GetViewBounds() const { return gfx::Rect(); } + virtual void SetIsLoading(bool is_loading) {} virtual void UpdateCursor(const WebCursor& cursor) {} virtual void UpdateCursorIfOverSelf() {} - // Indicates if the page has finished loading. - virtual void SetIsLoading(bool is_loading) {} virtual void IMEUpdateStatus(ViewHostMsg_ImeControl control, const gfx::Rect& caret_rect) {} virtual void DidPaintRect(const gfx::Rect& rect) {} |