The find bar should be owned and managed from the BrowserView, not the WebContentsVie...
[chromium-blink-merge.git] / chrome / browser / renderer_host / render_view_host.cc
blob723e91e947203beb35063d6d8d778dc8df0da9e7
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/renderer_host/render_view_host.h"
7 #include <string>
8 #include <vector>
10 #include "base/gfx/native_widget_types.h"
11 #include "base/string_util.h"
12 #include "base/waitable_event.h"
13 #include "chrome/app/result_codes.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/cross_site_request_manager.h"
16 #include "chrome/browser/debugger/debugger_wrapper.h"
17 #include "chrome/browser/profile.h"
18 #include "chrome/browser/metrics/user_metrics.h"
19 #include "chrome/browser/renderer_host/renderer_security_policy.h"
20 #include "chrome/browser/renderer_host/render_process_host.h"
21 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
22 #include "chrome/browser/renderer_host/render_widget_host.h"
23 #include "chrome/browser/renderer_host/render_widget_host_view.h"
24 #include "chrome/browser/tab_contents/navigation_entry.h"
25 #include "chrome/browser/tab_contents/site_instance.h"
26 #include "chrome/browser/tab_contents/web_contents.h"
27 #include "chrome/common/render_messages.h"
28 #include "chrome/common/resource_bundle.h"
29 #include "chrome/common/notification_service.h"
30 #include "chrome/common/notification_type.h"
31 #include "chrome/common/thumbnail_score.h"
32 #include "net/base/net_util.h"
33 #include "skia/include/SkBitmap.h"
34 #include "webkit/glue/autofill_form.h"
36 using base::TimeDelta;
38 namespace {
40 void FilterURL(RendererSecurityPolicy* policy, int renderer_id, GURL* url) {
41 if (!url->is_valid())
42 return; // We don't need to block invalid URLs.
44 if (url->SchemeIs("about")) {
45 // The renderer treats all URLs in the about: scheme as being about:blank.
46 // Canonicalize about: URLs to about:blank.
47 *url = GURL("about:blank");
50 if (!policy->CanRequestURL(renderer_id, *url)) {
51 // If this renderer is not permitted to request this URL, we invalidate the
52 // URL. This prevents us from storing the blocked URL and becoming confused
53 // later.
54 LOG(INFO) << "Blocked URL " << url->spec();
55 *url = GURL();
59 // Delay to wait on closing the tab for a beforeunload/unload handler to fire.
60 const int kUnloadTimeoutMS = 1000;
62 } // namespace
64 ///////////////////////////////////////////////////////////////////////////////
65 // RenderViewHost, public:
67 // static
68 RenderViewHost* RenderViewHost::FromID(int render_process_id,
69 int render_view_id) {
70 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
71 if (!process)
72 return NULL;
73 RenderWidgetHost* widget = static_cast<RenderWidgetHost*>(
74 process->GetListenerByID(render_view_id));
75 if (!widget || !widget->IsRenderView())
76 return NULL;
77 return static_cast<RenderViewHost*>(widget);
80 RenderViewHost::RenderViewHost(SiteInstance* instance,
81 RenderViewHostDelegate* delegate,
82 int routing_id,
83 base::WaitableEvent* modal_dialog_event)
84 : RenderWidgetHost(instance->GetProcess(), routing_id),
85 instance_(instance),
86 delegate_(delegate),
87 renderer_initialized_(false),
88 waiting_for_drag_context_response_(false),
89 debugger_attached_(false),
90 enable_dom_ui_bindings_(false),
91 pending_request_id_(0),
92 enable_external_host_bindings_(false),
93 modal_dialog_count_(0),
94 navigations_suspended_(false),
95 suspended_nav_message_(NULL),
96 run_modal_reply_msg_(NULL),
97 has_unload_listener_(false),
98 is_waiting_for_unload_ack_(false),
99 are_javascript_messages_suppressed_(false) {
100 DCHECK(instance_);
101 DCHECK(delegate_);
102 if (modal_dialog_event == NULL)
103 modal_dialog_event = new base::WaitableEvent(true, false);
105 modal_dialog_event_.reset(modal_dialog_event);
106 #ifdef CHROME_PERSONALIZATION
107 personalization_ = Personalization::CreateHostPersonalization(this);
108 #endif
111 RenderViewHost::~RenderViewHost() {
112 OnDebugDisconnect();
114 #ifdef CHROME_PERSONALIZATION
115 Personalization::CleanupHostPersonalization(personalization_);
116 personalization_ = NULL;
117 #endif
119 // Be sure to clean up any leftover state from cross-site requests.
120 Singleton<CrossSiteRequestManager>()->SetHasPendingCrossSiteRequest(
121 process()->host_id(), routing_id(), false);
123 NotificationService::current()->Notify(
124 NotificationType::RENDER_VIEW_HOST_DELETED,
125 Source<RenderViewHost>(this),
126 NotificationService::NoDetails());
129 bool RenderViewHost::CreateRenderView() {
130 DCHECK(!IsRenderViewLive()) << "Creating view twice";
132 // The process may (if we're sharing a process with another host that already
133 // initialized it) or may not (we have our own process or the old process
134 // crashed) have been initialized. Calling Init multiple times will be
135 // ignored, so this is safe.
136 if (!process()->Init())
137 return false;
138 DCHECK(process()->channel());
139 DCHECK(process()->profile());
141 renderer_initialized_ = true;
143 #if defined(OS_WIN)
144 HANDLE modal_dialog_event_handle;
145 HANDLE renderer_process_handle = process()->process().handle();
146 if (renderer_process_handle == NULL)
147 renderer_process_handle = GetCurrentProcess();
149 BOOL result = DuplicateHandle(GetCurrentProcess(),
150 modal_dialog_event_->handle(),
151 renderer_process_handle,
152 &modal_dialog_event_handle,
153 SYNCHRONIZE,
154 FALSE,
156 DCHECK(result) <<
157 "Couldn't duplicate the modal dialog handle for the renderer.";
158 #endif
160 DCHECK(view());
162 ModalDialogEvent modal_dialog_event;
163 #if defined(OS_WIN)
164 modal_dialog_event.event = modal_dialog_event_handle;
165 #endif
167 Send(new ViewMsg_New(gfx::IdFromNativeView(view()->GetPluginNativeView()),
168 modal_dialog_event,
169 delegate_->GetWebkitPrefs(),
170 routing_id()));
172 // Set the alternate error page, which is profile specific, in the renderer.
173 GURL url = delegate_->GetAlternateErrorPageURL();
174 SetAlternateErrorPageURL(url);
176 // If it's enabled, tell the renderer to set up the Javascript bindings for
177 // sending messages back to the browser.
178 Send(new ViewMsg_AllowBindings(
179 routing_id(), enable_dom_ui_bindings_, enable_external_host_bindings_));
181 // Let our delegate know that we created a RenderView.
182 delegate_->RendererCreated(this);
184 return true;
187 bool RenderViewHost::IsRenderViewLive() const {
188 return process()->channel() && renderer_initialized_;
191 void RenderViewHost::Init() {
192 RenderWidgetHost::Init();
193 renderer_initialized_ = true;
196 void RenderViewHost::NavigateToEntry(const NavigationEntry& entry,
197 bool is_reload) {
198 ViewMsg_Navigate_Params params;
199 MakeNavigateParams(entry, is_reload, &params);
201 RendererSecurityPolicy::GetInstance()->GrantRequestURL(
202 process()->host_id(), params.url);
204 DoNavigate(new ViewMsg_Navigate(routing_id(), params));
207 void RenderViewHost::NavigateToURL(const GURL& url) {
208 ViewMsg_Navigate_Params params;
209 params.page_id = -1;
210 params.url = url;
211 params.transition = PageTransition::LINK;
212 params.reload = false;
214 RendererSecurityPolicy::GetInstance()->GrantRequestURL(
215 process()->host_id(), params.url);
217 DoNavigate(new ViewMsg_Navigate(routing_id(), params));
220 void RenderViewHost::DoNavigate(ViewMsg_Navigate* nav_message) {
221 // Only send the message if we aren't suspended at the start of a cross-site
222 // request.
223 if (navigations_suspended_) {
224 // Shouldn't be possible to have a second navigation while suspended, since
225 // navigations will only be suspended during a cross-site request. If a
226 // second navigation occurs, WebContents will cancel this pending RVH
227 // create a new pending RVH.
228 DCHECK(!suspended_nav_message_.get());
229 suspended_nav_message_.reset(nav_message);
230 } else {
231 Send(nav_message);
235 void RenderViewHost::LoadAlternateHTMLString(const std::string& html_text,
236 bool new_navigation,
237 const GURL& display_url,
238 const std::string& security_info) {
239 Send(new ViewMsg_LoadAlternateHTMLText(routing_id(), html_text,
240 new_navigation, display_url,
241 security_info));
244 void RenderViewHost::SetNavigationsSuspended(bool suspend) {
245 // This should only be called to toggle the state.
246 DCHECK(navigations_suspended_ != suspend);
248 navigations_suspended_ = suspend;
249 if (!suspend && suspended_nav_message_.get()) {
250 // There's a navigation message waiting to be sent. Now that we're not
251 // suspended anymore, resume navigation by sending it.
252 Send(suspended_nav_message_.release());
256 void RenderViewHost::FirePageBeforeUnload() {
257 if (!IsRenderViewLive()) {
258 // This RenderViewHost doesn't have a live renderer, so just skip running
259 // the onbeforeunload handler.
260 OnMsgShouldCloseACK(true);
261 return;
264 // This may be called more than once (if the user clicks the tab close button
265 // several times, or if she clicks the tab close button then the browser close
266 // button), so this test makes sure we only send the message once.
267 if (!is_waiting_for_unload_ack_) {
268 // Start the hang monitor in case the renderer hangs in the beforeunload
269 // handler.
270 is_waiting_for_unload_ack_ = true;
271 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
272 Send(new ViewMsg_ShouldClose(routing_id()));
276 void RenderViewHost::FirePageUnload() {
277 ClosePage(site_instance()->process_host_id(),
278 routing_id());
281 // static
282 void RenderViewHost::ClosePageIgnoringUnloadEvents(int render_process_host_id,
283 int request_id) {
284 RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id,
285 request_id);
286 if (!rvh)
287 return;
289 rvh->StopHangMonitorTimeout();
290 rvh->is_waiting_for_unload_ack_ = false;
292 rvh->UnloadListenerHasFired();
293 rvh->delegate()->Close(rvh);
296 void RenderViewHost::ClosePage(int new_render_process_host_id,
297 int new_request_id) {
298 // Start the hang monitor in case the renderer hangs in the unload handler.
299 is_waiting_for_unload_ack_ = true;
300 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
302 if (IsRenderViewLive()) {
303 Send(new ViewMsg_ClosePage(routing_id(),
304 new_render_process_host_id,
305 new_request_id));
306 } else {
307 // This RenderViewHost doesn't have a live renderer, so just skip closing
308 // the page. We must notify the ResourceDispatcherHost on the IO thread,
309 // which we will do through the RenderProcessHost's widget helper.
310 process()->CrossSiteClosePageACK(new_render_process_host_id,
311 new_request_id);
315 void RenderViewHost::SetHasPendingCrossSiteRequest(bool has_pending_request,
316 int request_id) {
317 Singleton<CrossSiteRequestManager>()->SetHasPendingCrossSiteRequest(
318 process()->host_id(), routing_id(), has_pending_request);
319 pending_request_id_ = request_id;
322 int RenderViewHost::GetPendingRequestId() {
323 return pending_request_id_;
326 void RenderViewHost::OnCrossSiteResponse(int new_render_process_host_id,
327 int new_request_id) {
328 delegate_->OnCrossSiteResponse(new_render_process_host_id, new_request_id);
331 void RenderViewHost::Stop() {
332 Send(new ViewMsg_Stop(routing_id()));
335 bool RenderViewHost::PrintPages() {
336 return Send(new ViewMsg_PrintPages(routing_id()));
339 void RenderViewHost::StartFinding(int request_id,
340 const std::wstring& search_string,
341 bool forward,
342 bool match_case,
343 bool find_next) {
344 if (search_string.empty())
345 return;
347 FindInPageRequest request;
348 request.request_id = request_id;
349 request.search_string = search_string;
350 request.forward = forward;
351 request.match_case = match_case;
352 request.find_next = find_next;
353 Send(new ViewMsg_Find(routing_id(), request));
355 // This call is asynchronous and returns immediately.
356 // The result of the search is sent as a notification message by the renderer.
359 void RenderViewHost::StopFinding(bool clear_selection) {
360 Send(new ViewMsg_StopFinding(routing_id(), clear_selection));
363 void RenderViewHost::Zoom(PageZoom::Function function) {
364 Send(new ViewMsg_Zoom(routing_id(), function));
367 void RenderViewHost::SetPageEncoding(const std::wstring& encoding_name) {
368 Send(new ViewMsg_SetPageEncoding(routing_id(), encoding_name));
371 void RenderViewHost::SetAlternateErrorPageURL(const GURL& url) {
372 Send(new ViewMsg_SetAltErrorPageURL(routing_id(), url));
375 void RenderViewHost::FillForm(const FormData& form_data) {
376 Send(new ViewMsg_FormFill(routing_id(), form_data));
379 void RenderViewHost::FillPasswordForm(
380 const PasswordFormDomManager::FillData& form_data) {
381 Send(new ViewMsg_FillPasswordForm(routing_id(), form_data));
384 void RenderViewHost::DragTargetDragEnter(const WebDropData& drop_data,
385 const gfx::Point& client_pt, const gfx::Point& screen_pt) {
386 // Grant the renderer the ability to load the drop_data.
387 RendererSecurityPolicy* policy = RendererSecurityPolicy::GetInstance();
388 policy->GrantRequestURL(process()->host_id(), drop_data.url);
389 for (std::vector<std::wstring>::const_iterator
390 iter(drop_data.filenames.begin());
391 iter != drop_data.filenames.end(); ++iter) {
392 policy->GrantRequestURL(process()->host_id(),
393 net::FilePathToFileURL(*iter));
394 policy->GrantUploadFile(process()->host_id(), *iter);
396 Send(new ViewMsg_DragTargetDragEnter(routing_id(), drop_data, client_pt,
397 screen_pt));
400 void RenderViewHost::DragTargetDragOver(
401 const gfx::Point& client_pt, const gfx::Point& screen_pt) {
402 Send(new ViewMsg_DragTargetDragOver(routing_id(), client_pt, screen_pt));
405 void RenderViewHost::DragTargetDragLeave() {
406 Send(new ViewMsg_DragTargetDragLeave(routing_id()));
409 void RenderViewHost::DragTargetDrop(
410 const gfx::Point& client_pt, const gfx::Point& screen_pt) {
411 Send(new ViewMsg_DragTargetDrop(routing_id(), client_pt, screen_pt));
414 void RenderViewHost::ReservePageIDRange(int size) {
415 Send(new ViewMsg_ReservePageIDRange(routing_id(), size));
418 void RenderViewHost::ExecuteJavascriptInWebFrame(
419 const std::wstring& frame_xpath, const std::wstring& jscript) {
420 Send(new ViewMsg_ScriptEvalRequest(routing_id(), frame_xpath, jscript));
423 void RenderViewHost::AddMessageToConsole(
424 const std::wstring& frame_xpath, const std::wstring& msg,
425 ConsoleMessageLevel level) {
426 Send(new ViewMsg_AddMessageToConsole(routing_id(), frame_xpath, msg, level));
429 void RenderViewHost::DebugCommand(const std::wstring& cmd) {
430 Send(new ViewMsg_DebugCommand(routing_id(), cmd));
433 void RenderViewHost::DebugAttach() {
434 if (!debugger_attached_)
435 Send(new ViewMsg_DebugAttach(routing_id()));
438 void RenderViewHost::DebugDetach() {
439 if (debugger_attached_) {
440 Send(new ViewMsg_DebugDetach(routing_id()));
441 debugger_attached_ = false;
445 void RenderViewHost::DebugBreak(bool force) {
446 if (debugger_attached_)
447 Send(new ViewMsg_DebugBreak(routing_id(), force));
450 void RenderViewHost::Undo() {
451 Send(new ViewMsg_Undo(routing_id()));
454 void RenderViewHost::Redo() {
455 Send(new ViewMsg_Redo(routing_id()));
458 void RenderViewHost::Cut() {
459 Send(new ViewMsg_Cut(routing_id()));
462 void RenderViewHost::Copy() {
463 Send(new ViewMsg_Copy(routing_id()));
466 void RenderViewHost::Paste() {
467 Send(new ViewMsg_Paste(routing_id()));
470 void RenderViewHost::Replace(const std::wstring& text_to_replace) {
471 Send(new ViewMsg_Replace(routing_id(), text_to_replace));
474 void RenderViewHost::ToggleSpellCheck() {
475 Send(new ViewMsg_ToggleSpellCheck(routing_id()));
478 void RenderViewHost::AddToDictionary(const std::wstring& word) {
479 process()->AddWord(word);
482 void RenderViewHost::Delete() {
483 Send(new ViewMsg_Delete(routing_id()));
486 void RenderViewHost::SelectAll() {
487 Send(new ViewMsg_SelectAll(routing_id()));
490 int RenderViewHost::DownloadImage(const GURL& url, int image_size) {
491 if (!url.is_valid()) {
492 NOTREACHED();
493 return 0;
495 static int next_id = 1;
496 int id = next_id++;
497 Send(new ViewMsg_DownloadImage(routing_id(), id, url, image_size));
498 return id;
501 void RenderViewHost::GetApplicationInfo(int32 page_id) {
502 Send(new ViewMsg_GetApplicationInfo(routing_id(), page_id));
505 void RenderViewHost::CaptureThumbnail() {
506 Send(new ViewMsg_CaptureThumbnail(routing_id()));
509 void RenderViewHost::JavaScriptMessageBoxClosed(IPC::Message* reply_msg,
510 bool success,
511 const std::wstring& prompt) {
512 if (is_waiting_for_unload_ack_) {
513 if (are_javascript_messages_suppressed_) {
514 delegate_->RendererUnresponsive(this, is_waiting_for_unload_ack_);
515 return;
518 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
521 if (--modal_dialog_count_ == 0)
522 modal_dialog_event_->Reset();
523 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg,
524 success, prompt);
525 Send(reply_msg);
528 void RenderViewHost::ModalHTMLDialogClosed(IPC::Message* reply_msg,
529 const std::string& json_retval) {
530 if (is_waiting_for_unload_ack_)
531 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
533 if (--modal_dialog_count_ == 0)
534 modal_dialog_event_->Reset();
536 ViewHostMsg_ShowModalHTMLDialog::WriteReplyParams(reply_msg, json_retval);
537 Send(reply_msg);
540 void RenderViewHost::CopyImageAt(int x, int y) {
541 Send(new ViewMsg_CopyImageAt(routing_id(), x, y));
544 void RenderViewHost::InspectElementAt(int x, int y) {
545 RendererSecurityPolicy::GetInstance()->GrantInspectElement(
546 process()->host_id());
547 Send(new ViewMsg_InspectElement(routing_id(), x, y));
550 void RenderViewHost::ShowJavaScriptConsole() {
551 RendererSecurityPolicy::GetInstance()->GrantInspectElement(
552 process()->host_id());
554 Send(new ViewMsg_ShowJavaScriptConsole(routing_id()));
557 void RenderViewHost::DragSourceEndedAt(
558 int client_x, int client_y, int screen_x, int screen_y) {
559 Send(new ViewMsg_DragSourceEndedOrMoved(
560 routing_id(), client_x, client_y, screen_x, screen_y, true));
563 void RenderViewHost::DragSourceMovedTo(
564 int client_x, int client_y, int screen_x, int screen_y) {
565 Send(new ViewMsg_DragSourceEndedOrMoved(
566 routing_id(), client_x, client_y, screen_x, screen_y, false));
569 void RenderViewHost::DragSourceSystemDragEnded() {
570 Send(new ViewMsg_DragSourceSystemDragEnded(routing_id()));
573 void RenderViewHost::AllowDomAutomationBindings() {
574 // Expose the binding that allows the DOM to send messages here.
575 Send(new ViewMsg_AllowDomAutomationBindings(routing_id(), true));
578 void RenderViewHost::AllowDOMUIBindings() {
579 DCHECK(!renderer_initialized_);
580 enable_dom_ui_bindings_ = true;
581 RendererSecurityPolicy::GetInstance()->GrantDOMUIBindings(
582 process()->host_id());
585 void RenderViewHost::AllowExternalHostBindings() {
586 enable_external_host_bindings_ = true;
589 void RenderViewHost::SetDOMUIProperty(const std::string& name,
590 const std::string& value) {
591 DCHECK(enable_dom_ui_bindings_);
592 Send(new ViewMsg_SetDOMUIProperty(routing_id(), name, value));
595 // static
596 void RenderViewHost::MakeNavigateParams(const NavigationEntry& entry,
597 bool reload,
598 ViewMsg_Navigate_Params* params) {
599 params->page_id = entry.page_id();
600 params->url = entry.url();
601 params->referrer = entry.referrer();
602 params->transition = entry.transition_type();
603 params->state = entry.content_state();
604 params->reload = reload;
607 bool RenderViewHost::CanBlur() const {
608 return delegate_->CanBlur();
611 void RenderViewHost::SetInitialFocus(bool reverse) {
612 Send(new ViewMsg_SetInitialFocus(routing_id(), reverse));
615 void RenderViewHost::UpdateWebPreferences(const WebPreferences& prefs) {
616 Send(new ViewMsg_UpdateWebPreferences(routing_id(), prefs));
619 void RenderViewHost::InstallMissingPlugin() {
620 Send(new ViewMsg_InstallMissingPlugin(routing_id()));
623 void RenderViewHost::FileSelected(const std::wstring& path) {
624 RendererSecurityPolicy::GetInstance()->GrantUploadFile(process()->host_id(),
625 path);
626 std::vector<std::wstring> files;
627 files.push_back(path);
628 Send(new ViewMsg_RunFileChooserResponse(routing_id(), files));
631 void RenderViewHost::MultiFilesSelected(
632 const std::vector<std::wstring>& files) {
633 for (std::vector<std::wstring>::const_iterator file = files.begin();
634 file != files.end(); ++file) {
635 RendererSecurityPolicy::GetInstance()->GrantUploadFile(
636 process()->host_id(), *file);
638 Send(new ViewMsg_RunFileChooserResponse(routing_id(), files));
641 void RenderViewHost::LoadStateChanged(const GURL& url,
642 net::LoadState load_state) {
643 delegate_->LoadStateChanged(url, load_state);
646 bool RenderViewHost::CanTerminate() const {
647 if (!delegate_->CanTerminate())
648 return false;
650 return has_unload_listener_;
653 ///////////////////////////////////////////////////////////////////////////////
654 // RenderViewHost, IPC message handlers:
656 void RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
657 if (msg.is_sync() && !msg.is_caller_pumping_messages()) {
658 NOTREACHED() << "Can't send sync messages to UI thread without pumping "
659 "messages in the renderer or else deadlocks can occur if the page"
660 "has windowed plugins! (message type " << msg.type() << ")";
661 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
662 reply->set_reply_error();
663 Send(reply);
664 return;
667 bool msg_is_ok = true;
668 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewHost, msg, msg_is_ok)
669 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindowWithRoute, OnMsgCreateWindow)
670 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidgetWithRoute, OnMsgCreateWidget)
671 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnMsgShowView)
672 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnMsgShowWidget)
673 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunModal, OnMsgRunModal)
674 IPC_MESSAGE_HANDLER(ViewHostMsg_RendererReady, OnMsgRendererReady)
675 IPC_MESSAGE_HANDLER(ViewHostMsg_RendererGone, OnMsgRendererGone)
676 IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_FrameNavigate, OnMsgNavigate(msg))
677 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState, OnMsgUpdateState)
678 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTitle, OnMsgUpdateTitle)
679 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateEncoding, OnMsgUpdateEncoding)
680 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL)
681 IPC_MESSAGE_HANDLER(ViewHostMsg_Thumbnail, OnMsgThumbnail)
682 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose)
683 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove)
684 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartLoading, OnMsgDidStartLoading)
685 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStopLoading, OnMsgDidStopLoading)
686 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
687 OnMsgDidLoadResourceFromMemoryCache)
688 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
689 OnMsgDidRedirectProvisionalLoad)
690 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
691 OnMsgDidStartProvisionalLoadForFrame)
692 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
693 OnMsgDidFailProvisionalLoadWithError)
694 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnMsgFindReply)
695 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFavIconURL, OnMsgUpdateFavIconURL)
696 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadImage, OnMsgDidDownloadImage)
697 IPC_MESSAGE_HANDLER(ViewHostMsg_ContextMenu, OnMsgContextMenu)
698 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL)
699 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse,
700 OnMsgDomOperationResponse)
701 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMUISend,
702 OnMsgDOMUISend)
703 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardMessageToExternalHost,
704 OnMsgForwardMessageToExternalHost)
705 #ifdef CHROME_PERSONALIZATION
706 IPC_MESSAGE_HANDLER(ViewHostMsg_PersonalizationEvent,
707 OnPersonalizationEvent)
708 #endif
709 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset,
710 OnMsgGoToEntryAtOffset)
711 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText)
712 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnMsgRunFileChooser)
713 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage,
714 OnMsgRunJavaScriptMessage)
715 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm,
716 OnMsgRunBeforeUnloadConfirm)
717 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ShowModalHTMLDialog,
718 OnMsgShowModalHTMLDialog)
719 IPC_MESSAGE_HANDLER(ViewHostMsg_PasswordFormsSeen, OnMsgPasswordFormsSeen)
720 IPC_MESSAGE_HANDLER(ViewHostMsg_AutofillFormSubmitted,
721 OnMsgAutofillFormSubmitted)
722 IPC_MESSAGE_HANDLER(ViewHostMsg_StartDragging, OnMsgStartDragging)
723 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateDragCursor, OnUpdateDragCursor)
724 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
725 IPC_MESSAGE_HANDLER(ViewHostMsg_PageHasOSDD, OnMsgPageHasOSDD)
726 IPC_MESSAGE_HANDLER(ViewHostMsg_InspectElement_Reply,
727 OnMsgInspectElementReply)
728 IPC_MESSAGE_FORWARD(ViewHostMsg_DidGetPrintedPagesCount,
729 delegate_,
730 RenderViewHostDelegate::DidGetPrintedPagesCount)
731 IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, DidPrintPage)
732 IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole)
733 IPC_MESSAGE_HANDLER(ViewHostMsg_DebuggerOutput, OnDebuggerOutput);
734 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDebugAttach, DidDebugAttach);
735 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction,
736 OnUserMetricsRecordAction)
737 IPC_MESSAGE_HANDLER(ViewHostMsg_MissingPluginStatus, OnMissingPluginStatus);
738 IPC_MESSAGE_FORWARD(ViewHostMsg_CrashedPlugin, delegate_,
739 RenderViewHostDelegate::OnCrashedPlugin);
740 IPC_MESSAGE_HANDLER(ViewHostMsg_SendCurrentPageAllSavableResourceLinks,
741 OnReceivedSavableResourceLinksForCurrentPage);
742 IPC_MESSAGE_HANDLER(ViewHostMsg_SendSerializedHtmlData,
743 OnReceivedSerializedHtmlData);
744 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
745 OnDidGetApplicationInfo);
746 IPC_MESSAGE_FORWARD(ViewHostMsg_JSOutOfMemory, delegate_,
747 RenderViewHostDelegate::OnJSOutOfMemory);
748 IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK);
749 IPC_MESSAGE_HANDLER(ViewHostMsg_UnloadListenerChanged,
750 OnUnloadListenerChanged);
751 IPC_MESSAGE_HANDLER(ViewHostMsg_QueryFormFieldAutofill,
752 OnQueryFormFieldAutofill)
753 // Have the super handle all other messages.
754 IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg))
755 IPC_END_MESSAGE_MAP_EX()
757 if (!msg_is_ok) {
758 // The message had a handler, but its de-serialization failed.
759 // Kill the renderer.
760 process()->ReceivedBadMessage(msg.type());
764 void RenderViewHost::Shutdown() {
765 // If we are being run modally (see RunModal), then we need to cleanup.
766 if (run_modal_reply_msg_) {
767 if (--modal_dialog_count_ == 0)
768 modal_dialog_event_->Reset();
769 Send(run_modal_reply_msg_);
770 run_modal_reply_msg_ = NULL;
772 RenderWidgetHost::Shutdown();
775 void RenderViewHost::OnMsgCreateWindow(int route_id,
776 ModalDialogEvent modal_dialog_event) {
777 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
778 base::WaitableEvent* waitable_event = new base::WaitableEvent(
779 #if defined(OS_WIN)
780 modal_dialog_event.event);
781 #else
782 true, false);
783 #endif
785 if (view)
786 view->CreateNewWindow(route_id, waitable_event);
789 void RenderViewHost::OnMsgCreateWidget(int route_id, bool activatable) {
790 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
791 if (view)
792 view->CreateNewWidget(route_id, activatable);
795 void RenderViewHost::OnMsgShowView(int route_id,
796 WindowOpenDisposition disposition,
797 const gfx::Rect& initial_pos,
798 bool user_gesture) {
799 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
800 if (view)
801 view->ShowCreatedWindow(route_id, disposition, initial_pos, user_gesture);
804 void RenderViewHost::OnMsgShowWidget(int route_id,
805 const gfx::Rect& initial_pos) {
806 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
807 if (view)
808 view->ShowCreatedWidget(route_id, initial_pos);
811 void RenderViewHost::OnMsgRunModal(IPC::Message* reply_msg) {
812 DCHECK(!run_modal_reply_msg_);
813 if (modal_dialog_count_++ == 0)
814 modal_dialog_event_->Reset();
815 run_modal_reply_msg_ = reply_msg;
817 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in
818 // an app-modal fashion.
821 void RenderViewHost::OnMsgRendererReady() {
822 WasResized();
823 delegate_->RendererReady(this);
826 void RenderViewHost::OnMsgRendererGone() {
827 // Our base class RenderWidgetHouse needs to reset some stuff.
828 RendererExited();
830 // Clearing this flag causes us to re-create the renderer when recovering
831 // from a crashed renderer.
832 renderer_initialized_ = false;
834 delegate_->RendererGone(this);
835 OnDebugDisconnect();
838 // Called when the renderer navigates. For every frame loaded, we'll get this
839 // notification containing parameters identifying the navigation.
841 // Subframes are identified by the page transition type. For subframes loaded
842 // as part of a wider page load, the page_id will be the same as for the top
843 // level frame. If the user explicitly requests a subframe navigation, we will
844 // get a new page_id because we need to create a new navigation entry for that
845 // action.
846 void RenderViewHost::OnMsgNavigate(const IPC::Message& msg) {
847 // Read the parameters out of the IPC message directly to avoid making another
848 // copy when we filter the URLs.
849 void* iter = NULL;
850 ViewHostMsg_FrameNavigate_Params validated_params;
851 if (!IPC::ParamTraits<ViewHostMsg_FrameNavigate_Params>::
852 Read(&msg, &iter, &validated_params))
853 return;
855 const int renderer_id = process()->host_id();
856 RendererSecurityPolicy* policy = RendererSecurityPolicy::GetInstance();
857 // Without this check, an evil renderer can trick the browser into creating
858 // a navigation entry for a banned URL. If the user clicks the back button
859 // followed by the forward button (or clicks reload, or round-trips through
860 // session restore, etc), we'll think that the browser commanded the
861 // renderer to load the URL and grant the renderer the privileges to request
862 // the URL. To prevent this attack, we block the renderer from inserting
863 // banned URLs into the navigation controller in the first place.
864 FilterURL(policy, renderer_id, &validated_params.url);
865 FilterURL(policy, renderer_id, &validated_params.referrer);
866 for (std::vector<GURL>::iterator it(validated_params.redirects.begin());
867 it != validated_params.redirects.end(); ++it) {
868 FilterURL(policy, renderer_id, &(*it));
870 FilterURL(policy, renderer_id, &validated_params.searchable_form_url);
871 FilterURL(policy, renderer_id, &validated_params.password_form.origin);
872 FilterURL(policy, renderer_id, &validated_params.password_form.action);
874 delegate_->DidNavigate(this, validated_params);
876 UpdateBackForwardListCount();
879 void RenderViewHost::OnMsgUpdateState(int32 page_id,
880 const std::string& state) {
881 delegate_->UpdateState(this, page_id, state);
884 void RenderViewHost::OnMsgUpdateTitle(int32 page_id,
885 const std::wstring& title) {
886 delegate_->UpdateTitle(this, page_id, title);
889 void RenderViewHost::OnMsgUpdateEncoding(const std::wstring& encoding_name) {
890 delegate_->UpdateEncoding(this, encoding_name);
893 void RenderViewHost::OnMsgUpdateTargetURL(int32 page_id,
894 const GURL& url) {
895 delegate_->UpdateTargetURL(page_id, url);
897 // Send a notification back to the renderer that we are ready to
898 // receive more target urls.
899 Send(new ViewMsg_UpdateTargetURL_ACK(routing_id()));
902 void RenderViewHost::OnMsgThumbnail(const GURL& url,
903 const ThumbnailScore& score,
904 const SkBitmap& bitmap) {
905 delegate_->UpdateThumbnail(url, bitmap, score);
908 void RenderViewHost::OnMsgClose() {
909 delegate_->Close(this);
912 void RenderViewHost::OnMsgRequestMove(const gfx::Rect& pos) {
913 delegate_->RequestMove(pos);
916 void RenderViewHost::OnMsgDidRedirectProvisionalLoad(int32 page_id,
917 const GURL& source_url,
918 const GURL& target_url) {
919 delegate_->DidRedirectProvisionalLoad(page_id, source_url, target_url);
922 void RenderViewHost::OnMsgDidStartLoading(int32 page_id) {
923 delegate_->DidStartLoading(this, page_id);
924 if (view())
925 view()->UpdateCursorIfOverSelf();
928 void RenderViewHost::OnMsgDidStopLoading(int32 page_id) {
929 delegate_->DidStopLoading(this, page_id);
930 if (view())
931 view()->UpdateCursorIfOverSelf();
934 void RenderViewHost::OnMsgDidLoadResourceFromMemoryCache(
935 const GURL& url,
936 const std::string& security_info) {
937 delegate_->DidLoadResourceFromMemoryCache(url, security_info);
940 void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(bool is_main_frame,
941 const GURL& url) {
942 GURL validated_url(url);
943 FilterURL(RendererSecurityPolicy::GetInstance(),
944 process()->host_id(), &validated_url);
946 delegate_->DidStartProvisionalLoadForFrame(this, is_main_frame,
947 validated_url);
950 void RenderViewHost::OnMsgDidFailProvisionalLoadWithError(
951 bool is_main_frame,
952 int error_code,
953 const GURL& url,
954 bool showing_repost_interstitial) {
955 GURL validated_url(url);
956 FilterURL(RendererSecurityPolicy::GetInstance(),
957 process()->host_id(), &validated_url);
959 delegate_->DidFailProvisionalLoadWithError(this, is_main_frame,
960 error_code, validated_url,
961 showing_repost_interstitial);
964 void RenderViewHost::OnMsgFindReply(int request_id,
965 int number_of_matches,
966 const gfx::Rect& selection_rect,
967 int active_match_ordinal,
968 bool final_update) {
969 delegate_->OnFindReply(request_id, number_of_matches, selection_rect,
970 active_match_ordinal, final_update);
972 // Send a notification to the renderer that we are ready to receive more
973 // results from the scoping effort of the Find operation. The FindInPage
974 // scoping is asynchronous and periodically sends results back up to the
975 // browser using IPC. In an effort to not spam the browser we have the
976 // browser send an ACK for each FindReply message and have the renderer
977 // queue up the latest status message while waiting for this ACK.
978 Send(new ViewMsg_FindReplyACK(routing_id()));
981 void RenderViewHost::OnMsgUpdateFavIconURL(int32 page_id,
982 const GURL& icon_url) {
983 delegate_->UpdateFavIconURL(this, page_id, icon_url);
986 void RenderViewHost::OnMsgDidDownloadImage(
987 int id,
988 const GURL& image_url,
989 bool errored,
990 const SkBitmap& image) {
991 delegate_->DidDownloadImage(this, id, image_url, errored, image);
994 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) {
995 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
996 if (!view)
997 return;
999 // Validate the URLs in |params|. If the renderer can't request the URLs
1000 // directly, don't show them in the context menu.
1001 ContextMenuParams validated_params(params);
1002 const int renderer_id = process()->host_id();
1003 RendererSecurityPolicy* policy = RendererSecurityPolicy::GetInstance();
1005 FilterURL(policy, renderer_id, &validated_params.link_url);
1006 FilterURL(policy, renderer_id, &validated_params.image_url);
1007 FilterURL(policy, renderer_id, &validated_params.page_url);
1008 FilterURL(policy, renderer_id, &validated_params.frame_url);
1010 view->ShowContextMenu(validated_params);
1013 void RenderViewHost::OnMsgOpenURL(const GURL& url,
1014 const GURL& referrer,
1015 WindowOpenDisposition disposition) {
1016 GURL validated_url(url);
1017 FilterURL(RendererSecurityPolicy::GetInstance(),
1018 process()->host_id(), &validated_url);
1020 delegate_->RequestOpenURL(validated_url, referrer, disposition);
1023 void RenderViewHost::OnMsgDomOperationResponse(
1024 const std::string& json_string, int automation_id) {
1025 delegate_->DomOperationResponse(json_string, automation_id);
1028 void RenderViewHost::OnMsgDOMUISend(
1029 const std::string& message, const std::string& content) {
1030 if (!RendererSecurityPolicy::GetInstance()->
1031 HasDOMUIBindings(process()->host_id())) {
1032 NOTREACHED() << "Blocked unauthorized use of DOMUIBindings.";
1033 return;
1035 delegate_->ProcessDOMUIMessage(message, content);
1038 void RenderViewHost::OnMsgForwardMessageToExternalHost(
1039 const std::string& receiver,
1040 const std::string& message) {
1041 delegate_->ProcessExternalHostMessage(receiver, message);
1044 #ifdef CHROME_PERSONALIZATION
1045 void RenderViewHost::OnPersonalizationEvent(const std::string& message,
1046 const std::string& content) {
1047 Personalization::HandlePersonalizationEvent(this, message, content);
1049 #endif
1051 void RenderViewHost::DisassociateFromPopupCount() {
1052 Send(new ViewMsg_DisassociateFromPopupCount(routing_id()));
1055 void RenderViewHost::PopupNotificationVisibilityChanged(bool visible) {
1056 Send(new ViewMsg_PopupNotificationVisiblityChanged(routing_id(), visible));
1059 void RenderViewHost::OnMsgGoToEntryAtOffset(int offset) {
1060 delegate_->GoToEntryAtOffset(offset);
1063 void RenderViewHost::OnMsgSetTooltipText(const std::wstring& tooltip_text) {
1064 if (view())
1065 view()->SetTooltipText(tooltip_text);
1068 void RenderViewHost::OnMsgRunFileChooser(bool multiple_files,
1069 const std::wstring& title,
1070 const std::wstring& default_file,
1071 const std::wstring& filter) {
1072 std::wstring real_filter = filter;
1073 std::replace(real_filter.begin(), real_filter.end(), '|', '\0');
1074 delegate_->RunFileChooser(multiple_files, title, default_file, real_filter);
1077 void RenderViewHost::OnMsgRunJavaScriptMessage(
1078 const std::wstring& message,
1079 const std::wstring& default_prompt,
1080 const int flags,
1081 IPC::Message* reply_msg) {
1082 StopHangMonitorTimeout();
1083 if (modal_dialog_count_++ == 0)
1084 modal_dialog_event_->Signal();
1085 delegate_->RunJavaScriptMessage(message, default_prompt, flags, reply_msg,
1086 &are_javascript_messages_suppressed_);
1089 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const std::wstring& message,
1090 IPC::Message* reply_msg) {
1091 StopHangMonitorTimeout();
1092 if (modal_dialog_count_++ == 0)
1093 modal_dialog_event_->Signal();
1094 delegate_->RunBeforeUnloadConfirm(message, reply_msg);
1097 void RenderViewHost::OnMsgShowModalHTMLDialog(
1098 const GURL& url, int width, int height, const std::string& json_arguments,
1099 IPC::Message* reply_msg) {
1100 StopHangMonitorTimeout();
1101 if (modal_dialog_count_++ == 0)
1102 modal_dialog_event_->Signal();
1103 delegate_->ShowModalHTMLDialog(url, width, height, json_arguments, reply_msg);
1106 void RenderViewHost::OnMsgPasswordFormsSeen(
1107 const std::vector<PasswordForm>& forms) {
1108 delegate_->PasswordFormsSeen(forms);
1111 void RenderViewHost::OnMsgAutofillFormSubmitted(
1112 const AutofillForm& form) {
1113 delegate_->AutofillFormSubmitted(form);
1116 void RenderViewHost::OnMsgStartDragging(
1117 const WebDropData& drop_data) {
1118 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1119 if (view)
1120 view->StartDragging(drop_data);
1123 void RenderViewHost::OnUpdateDragCursor(bool is_drop_target) {
1124 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1125 if (view)
1126 view->UpdateDragCursor(is_drop_target);
1129 void RenderViewHost::OnTakeFocus(bool reverse) {
1130 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1131 if (view)
1132 view->TakeFocus(reverse);
1135 void RenderViewHost::OnMsgPageHasOSDD(int32 page_id, const GURL& doc_url,
1136 bool autodetected) {
1137 delegate_->PageHasOSDD(this, page_id, doc_url, autodetected);
1140 void RenderViewHost::OnMsgInspectElementReply(int num_resources) {
1141 delegate_->InspectElementReply(num_resources);
1144 void RenderViewHost::DidPrintPage(
1145 const ViewHostMsg_DidPrintPage_Params& params) {
1146 delegate_->DidPrintPage(params);
1149 void RenderViewHost::OnAddMessageToConsole(const std::wstring& message,
1150 int32 line_no,
1151 const std::wstring& source_id) {
1152 std::wstring msg = StringPrintf(L"\"%ls,\" source: %ls (%d)", message.c_str(),
1153 source_id.c_str(), line_no);
1154 logging::LogMessage("CONSOLE", 0).stream() << msg;
1155 if (debugger_attached_)
1156 g_browser_process->debugger_wrapper()->DebugMessage(msg);
1159 void RenderViewHost::OnDebuggerOutput(const std::wstring& output) {
1160 if (debugger_attached_)
1161 g_browser_process->debugger_wrapper()->DebugMessage(output);
1164 void RenderViewHost::DidDebugAttach() {
1165 if (!debugger_attached_) {
1166 debugger_attached_ = true;
1167 g_browser_process->debugger_wrapper()->OnDebugAttach();
1171 void RenderViewHost::OnUserMetricsRecordAction(const std::wstring& action) {
1172 UserMetrics::RecordComputedAction(action.c_str(), process()->profile());
1175 void RenderViewHost::UnhandledInputEvent(const WebInputEvent& event) {
1176 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1177 if (view) {
1178 // TODO(brettw) why do we have to filter these types of events here. Can't
1179 // the renderer just send us the ones we care abount, or maybe the view
1180 // should be able to decide which ones it wants or not?
1181 if ((event.type == WebInputEvent::KEY_DOWN) ||
1182 (event.type == WebInputEvent::CHAR)) {
1183 view->HandleKeyboardEvent(
1184 static_cast<const WebKeyboardEvent&>(event));
1189 void RenderViewHost::OnEnterOrSpace() {
1190 delegate_->OnEnterOrSpace();
1193 void RenderViewHost::OnMissingPluginStatus(int status) {
1194 delegate_->OnMissingPluginStatus(status);
1197 void RenderViewHost::UpdateBackForwardListCount() {
1198 int back_list_count, forward_list_count;
1199 delegate_->GetHistoryListCount(&back_list_count, &forward_list_count);
1200 Send(new ViewMsg_UpdateBackForwardListCount(
1201 routing_id(), back_list_count, forward_list_count));
1204 void RenderViewHost::GetAllSavableResourceLinksForCurrentPage(
1205 const GURL& page_url) {
1206 Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id(),
1207 page_url));
1210 void RenderViewHost::OnReceivedSavableResourceLinksForCurrentPage(
1211 const std::vector<GURL>& resources_list,
1212 const std::vector<GURL>& referrers_list,
1213 const std::vector<GURL>& frames_list) {
1214 RenderViewHostDelegate::Save* save_delegate = delegate_->GetSaveDelegate();
1215 if (save_delegate) {
1216 save_delegate->OnReceivedSavableResourceLinksForCurrentPage(
1217 resources_list, referrers_list, frames_list);
1221 void RenderViewHost::OnDidGetApplicationInfo(
1222 int32 page_id,
1223 const webkit_glue::WebApplicationInfo& info) {
1224 delegate_->OnDidGetApplicationInfo(page_id, info);
1227 void RenderViewHost::GetSerializedHtmlDataForCurrentPageWithLocalLinks(
1228 const std::vector<GURL>& links,
1229 const std::vector<FilePath>& local_paths,
1230 const FilePath& local_directory_name) {
1231 Send(new ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks(
1232 routing_id(), links, local_paths, local_directory_name));
1235 void RenderViewHost::OnReceivedSerializedHtmlData(const GURL& frame_url,
1236 const std::string& data,
1237 int32 status) {
1238 RenderViewHostDelegate::Save* save_delegate = delegate_->GetSaveDelegate();
1239 if (save_delegate)
1240 save_delegate->OnReceivedSerializedHtmlData(frame_url, data, status);
1243 void RenderViewHost::OnMsgShouldCloseACK(bool proceed) {
1244 StopHangMonitorTimeout();
1245 DCHECK(is_waiting_for_unload_ack_);
1246 is_waiting_for_unload_ack_ = false;
1247 delegate_->ShouldClosePage(proceed);
1250 void RenderViewHost::OnUnloadListenerChanged(bool has_listener) {
1251 has_unload_listener_ = has_listener;
1254 void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name,
1255 const std::wstring& user_text,
1256 int64 node_id,
1257 int request_id) {
1258 delegate_->GetAutofillSuggestions(field_name, user_text, node_id, request_id);
1261 void RenderViewHost::AutofillSuggestionsReturned(
1262 const std::vector<std::wstring>& suggestions,
1263 int64 node_id, int request_id, int default_suggestion_index) {
1264 Send(new ViewMsg_AutofillSuggestions(routing_id(), node_id,
1265 request_id, suggestions, -1));
1266 // Default index -1 means no default suggestion.
1269 void RenderViewHost::NotifyRendererUnresponsive() {
1270 // If the debugger is attached, we're going to be unresponsive anytime it's
1271 // stopped at a breakpoint.
1272 if (!debugger_attached_) {
1273 delegate_->RendererUnresponsive(this, is_waiting_for_unload_ack_);
1277 void RenderViewHost::NotifyRendererResponsive() {
1278 delegate_->RendererResponsive(this);
1281 gfx::Rect RenderViewHost::GetRootWindowResizerRect() const {
1282 return delegate_->GetRootWindowResizerRect();
1285 void RenderViewHost::OnDebugDisconnect() {
1286 if (debugger_attached_) {
1287 debugger_attached_ = false;
1288 g_browser_process->debugger_wrapper()->OnDebugDisconnect();
1292 #ifdef CHROME_PERSONALIZATION
1293 void RenderViewHost::RaisePersonalizationEvent(std::string event_name,
1294 std::string event_arg) {
1295 Send(new ViewMsg_PersonalizationEvent(routing_id(), event_name, event_arg));
1297 #endif
1299 void RenderViewHost::ForwardMessageFromExternalHost(
1300 const std::string& target, const std::string& message) {
1301 Send(new ViewMsg_HandleMessageFromExternalHost(routing_id(), target,
1302 message));