Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/render_view_host.cc

Issue 16554: WaitableEvent (Closed)
Patch Set: Addresssing darin's comments (round 2) Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/render_view_host.h ('k') | chrome/browser/render_view_host_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/render_view_host.h" 5 #include "chrome/browser/render_view_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/waitable_event.h"
11 #include "chrome/app/result_codes.h" 12 #include "chrome/app/result_codes.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/cross_site_request_manager.h" 14 #include "chrome/browser/cross_site_request_manager.h"
14 #include "chrome/browser/navigation_entry.h" 15 #include "chrome/browser/navigation_entry.h"
15 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
16 #include "chrome/browser/render_process_host.h" 17 #include "chrome/browser/render_process_host.h"
17 #include "chrome/browser/render_widget_host.h" 18 #include "chrome/browser/render_widget_host.h"
18 #include "chrome/browser/render_widget_host_view.h" 19 #include "chrome/browser/render_widget_host_view.h"
19 #include "chrome/browser/render_view_host_delegate.h" 20 #include "chrome/browser/render_view_host_delegate.h"
20 #include "chrome/browser/renderer_security_policy.h" 21 #include "chrome/browser/renderer_security_policy.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 RenderWidgetHost* widget = static_cast<RenderWidgetHost*>( 68 RenderWidgetHost* widget = static_cast<RenderWidgetHost*>(
68 process->GetListenerByID(render_view_id)); 69 process->GetListenerByID(render_view_id));
69 if (!widget || !widget->IsRenderView()) 70 if (!widget || !widget->IsRenderView())
70 return NULL; 71 return NULL;
71 return static_cast<RenderViewHost*>(widget); 72 return static_cast<RenderViewHost*>(widget);
72 } 73 }
73 74
74 RenderViewHost::RenderViewHost(SiteInstance* instance, 75 RenderViewHost::RenderViewHost(SiteInstance* instance,
75 RenderViewHostDelegate* delegate, 76 RenderViewHostDelegate* delegate,
76 int routing_id, 77 int routing_id,
77 HANDLE modal_dialog_event) 78 base::WaitableEvent* modal_dialog_event)
78 : RenderWidgetHost(instance->GetProcess(), routing_id), 79 : RenderWidgetHost(instance->GetProcess(), routing_id),
79 instance_(instance), 80 instance_(instance),
80 enable_dom_ui_bindings_(false), 81 enable_dom_ui_bindings_(false),
81 enable_external_host_bindings_(false), 82 enable_external_host_bindings_(false),
82 delegate_(delegate), 83 delegate_(delegate),
83 renderer_initialized_(false), 84 renderer_initialized_(false),
84 waiting_for_drag_context_response_(false), 85 waiting_for_drag_context_response_(false),
85 debugger_attached_(false), 86 debugger_attached_(false),
86 modal_dialog_count_(0), 87 modal_dialog_count_(0),
87 navigations_suspended_(false), 88 navigations_suspended_(false),
88 suspended_nav_message_(NULL), 89 suspended_nav_message_(NULL),
89 run_modal_reply_msg_(NULL), 90 run_modal_reply_msg_(NULL),
90 has_unload_listener_(false), 91 has_unload_listener_(false),
91 is_waiting_for_unload_ack_(false), 92 is_waiting_for_unload_ack_(false),
92 are_javascript_messages_suppressed_(false) { 93 are_javascript_messages_suppressed_(false) {
93 DCHECK(instance_); 94 DCHECK(instance_);
94 DCHECK(delegate_); 95 DCHECK(delegate_);
95 if (modal_dialog_event == NULL) 96 if (modal_dialog_event == NULL)
96 modal_dialog_event = CreateEvent(NULL, TRUE, FALSE, NULL); 97 modal_dialog_event = new base::WaitableEvent(true, false);
97 98
98 modal_dialog_event_.Set(modal_dialog_event); 99 modal_dialog_event_.reset(modal_dialog_event);
99 #ifdef CHROME_PERSONALIZATION 100 #ifdef CHROME_PERSONALIZATION
100 personalization_ = Personalization::CreateHostPersonalization(this); 101 personalization_ = Personalization::CreateHostPersonalization(this);
101 #endif 102 #endif
102 } 103 }
103 104
104 RenderViewHost::~RenderViewHost() { 105 RenderViewHost::~RenderViewHost() {
105 OnDebugDisconnect(); 106 OnDebugDisconnect();
106 107
107 #ifdef CHROME_PERSONALIZATION 108 #ifdef CHROME_PERSONALIZATION
108 Personalization::CleanupHostPersonalization(personalization_); 109 Personalization::CleanupHostPersonalization(personalization_);
(...skipping 18 matching lines...) Expand all
127 DCHECK(process_->profile()); 128 DCHECK(process_->profile());
128 129
129 renderer_initialized_ = true; 130 renderer_initialized_ = true;
130 131
131 HANDLE modal_dialog_event; 132 HANDLE modal_dialog_event;
132 HANDLE renderer_process_handle = process()->process().handle(); 133 HANDLE renderer_process_handle = process()->process().handle();
133 if (renderer_process_handle == NULL) 134 if (renderer_process_handle == NULL)
134 renderer_process_handle = GetCurrentProcess(); 135 renderer_process_handle = GetCurrentProcess();
135 136
136 BOOL result = DuplicateHandle(GetCurrentProcess(), 137 BOOL result = DuplicateHandle(GetCurrentProcess(),
137 modal_dialog_event_.Get(), 138 modal_dialog_event_->handle(),
138 renderer_process_handle, 139 renderer_process_handle,
139 &modal_dialog_event, 140 &modal_dialog_event,
140 SYNCHRONIZE, 141 SYNCHRONIZE,
141 FALSE, 142 FALSE,
142 0); 143 0);
143 DCHECK(result) << "Couldn't duplicate the modal dialog handle for the renderer ."; 144 DCHECK(result) << "Couldn't duplicate the modal dialog handle for the renderer .";
144 145
145 DCHECK(view_); 146 DCHECK(view_);
146 Send(new ViewMsg_New(view_->GetPluginHWND(), 147 Send(new ViewMsg_New(view_->GetPluginHWND(),
147 modal_dialog_event, 148 modal_dialog_event,
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 if (is_waiting_for_unload_ack_) { 492 if (is_waiting_for_unload_ack_) {
492 if (are_javascript_messages_suppressed_) { 493 if (are_javascript_messages_suppressed_) {
493 delegate_->RendererUnresponsive(this, is_waiting_for_unload_ack_); 494 delegate_->RendererUnresponsive(this, is_waiting_for_unload_ack_);
494 return; 495 return;
495 } 496 }
496 497
497 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 498 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
498 } 499 }
499 500
500 if (--modal_dialog_count_ == 0) 501 if (--modal_dialog_count_ == 0)
501 ResetEvent(modal_dialog_event_.Get()); 502 modal_dialog_event_->Reset();
502 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, success, prompt) ; 503 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, success, prompt) ;
503 Send(reply_msg); 504 Send(reply_msg);
504 } 505 }
505 506
506 void RenderViewHost::ModalHTMLDialogClosed(IPC::Message* reply_msg, 507 void RenderViewHost::ModalHTMLDialogClosed(IPC::Message* reply_msg,
507 const std::string& json_retval) { 508 const std::string& json_retval) {
508 if (is_waiting_for_unload_ack_) 509 if (is_waiting_for_unload_ack_)
509 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 510 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
510 511
511 if (--modal_dialog_count_ == 0) 512 if (--modal_dialog_count_ == 0)
512 ResetEvent(modal_dialog_event_.Get()); 513 modal_dialog_event_->Reset();
513 514
514 ViewHostMsg_ShowModalHTMLDialog::WriteReplyParams(reply_msg, json_retval); 515 ViewHostMsg_ShowModalHTMLDialog::WriteReplyParams(reply_msg, json_retval);
515 Send(reply_msg); 516 Send(reply_msg);
516 } 517 }
517 518
518 void RenderViewHost::CopyImageAt(int x, int y) { 519 void RenderViewHost::CopyImageAt(int x, int y) {
519 Send(new ViewMsg_CopyImageAt(routing_id_, x, y)); 520 Send(new ViewMsg_CopyImageAt(routing_id_, x, y));
520 } 521 }
521 522
522 void RenderViewHost::InspectElementAt(int x, int y) { 523 void RenderViewHost::InspectElementAt(int x, int y) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // The message had a handler, but its de-serialization failed. 736 // The message had a handler, but its de-serialization failed.
736 // Kill the renderer. 737 // Kill the renderer.
737 process()->ReceivedBadMessage(msg.type()); 738 process()->ReceivedBadMessage(msg.type());
738 } 739 }
739 } 740 }
740 741
741 void RenderViewHost::Shutdown() { 742 void RenderViewHost::Shutdown() {
742 // If we are being run modally (see RunModal), then we need to cleanup. 743 // If we are being run modally (see RunModal), then we need to cleanup.
743 if (run_modal_reply_msg_) { 744 if (run_modal_reply_msg_) {
744 if (--modal_dialog_count_ == 0) 745 if (--modal_dialog_count_ == 0)
745 ResetEvent(modal_dialog_event_.Get()); 746 modal_dialog_event_->Reset();
746 Send(run_modal_reply_msg_); 747 Send(run_modal_reply_msg_);
747 run_modal_reply_msg_ = NULL; 748 run_modal_reply_msg_ = NULL;
748 } 749 }
749 RenderWidgetHost::Shutdown(); 750 RenderWidgetHost::Shutdown();
750 } 751 }
751 752
752 void RenderViewHost::OnMsgCreateWindow(int route_id, 753 void RenderViewHost::OnMsgCreateWindow(int route_id,
753 HANDLE modal_dialog_event) { 754 HANDLE modal_dialog_event) {
754 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 755 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
755 if (view) 756 if (view)
756 view->CreateNewWindow(route_id, modal_dialog_event); 757 view->CreateNewWindow(route_id,
758 new base::WaitableEvent(modal_dialog_event));
757 } 759 }
758 760
759 void RenderViewHost::OnMsgCreateWidget(int route_id, bool activatable) { 761 void RenderViewHost::OnMsgCreateWidget(int route_id, bool activatable) {
760 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 762 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
761 if (view) 763 if (view)
762 view->CreateNewWidget(route_id, activatable); 764 view->CreateNewWidget(route_id, activatable);
763 } 765 }
764 766
765 void RenderViewHost::OnMsgShowView(int route_id, 767 void RenderViewHost::OnMsgShowView(int route_id,
766 WindowOpenDisposition disposition, 768 WindowOpenDisposition disposition,
767 const gfx::Rect& initial_pos, 769 const gfx::Rect& initial_pos,
768 bool user_gesture) { 770 bool user_gesture) {
769 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 771 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
770 if (view) 772 if (view)
771 view->ShowCreatedWindow(route_id, disposition, initial_pos, user_gesture); 773 view->ShowCreatedWindow(route_id, disposition, initial_pos, user_gesture);
772 } 774 }
773 775
774 void RenderViewHost::OnMsgShowWidget(int route_id, 776 void RenderViewHost::OnMsgShowWidget(int route_id,
775 const gfx::Rect& initial_pos) { 777 const gfx::Rect& initial_pos) {
776 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 778 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
777 if (view) 779 if (view)
778 view->ShowCreatedWidget(route_id, initial_pos); 780 view->ShowCreatedWidget(route_id, initial_pos);
779 } 781 }
780 782
781 void RenderViewHost::OnMsgRunModal(IPC::Message* reply_msg) { 783 void RenderViewHost::OnMsgRunModal(IPC::Message* reply_msg) {
782 DCHECK(!run_modal_reply_msg_); 784 DCHECK(!run_modal_reply_msg_);
783 if (modal_dialog_count_++ == 0) 785 if (modal_dialog_count_++ == 0)
784 SetEvent(modal_dialog_event_.Get()); 786 modal_dialog_event_->Reset();
785 run_modal_reply_msg_ = reply_msg; 787 run_modal_reply_msg_ = reply_msg;
786 788
787 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in 789 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in
788 // an app-modal fashion. 790 // an app-modal fashion.
789 } 791 }
790 792
791 void RenderViewHost::OnMsgRendererReady() { 793 void RenderViewHost::OnMsgRendererReady() {
792 WasResized(); 794 WasResized();
793 delegate_->RendererReady(this); 795 delegate_->RendererReady(this);
794 } 796 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 delegate_->RunFileChooser(multiple_files, title, default_file, real_filter); 1080 delegate_->RunFileChooser(multiple_files, title, default_file, real_filter);
1079 } 1081 }
1080 1082
1081 void RenderViewHost::OnMsgRunJavaScriptMessage( 1083 void RenderViewHost::OnMsgRunJavaScriptMessage(
1082 const std::wstring& message, 1084 const std::wstring& message,
1083 const std::wstring& default_prompt, 1085 const std::wstring& default_prompt,
1084 const int flags, 1086 const int flags,
1085 IPC::Message* reply_msg) { 1087 IPC::Message* reply_msg) {
1086 StopHangMonitorTimeout(); 1088 StopHangMonitorTimeout();
1087 if (modal_dialog_count_++ == 0) 1089 if (modal_dialog_count_++ == 0)
1088 SetEvent(modal_dialog_event_.Get()); 1090 modal_dialog_event_->Signal();
1089 bool did_suppress_message = false; 1091 bool did_suppress_message = false;
1090 delegate_->RunJavaScriptMessage(message, default_prompt, flags, reply_msg, 1092 delegate_->RunJavaScriptMessage(message, default_prompt, flags, reply_msg,
1091 &are_javascript_messages_suppressed_); 1093 &are_javascript_messages_suppressed_);
1092 } 1094 }
1093 1095
1094 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const std::wstring& message, 1096 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const std::wstring& message,
1095 IPC::Message* reply_msg) { 1097 IPC::Message* reply_msg) {
1096 StopHangMonitorTimeout(); 1098 StopHangMonitorTimeout();
1097 if (modal_dialog_count_++ == 0) 1099 if (modal_dialog_count_++ == 0)
1098 SetEvent(modal_dialog_event_.Get()); 1100 modal_dialog_event_->Signal();
1099 delegate_->RunBeforeUnloadConfirm(message, reply_msg); 1101 delegate_->RunBeforeUnloadConfirm(message, reply_msg);
1100 } 1102 }
1101 1103
1102 void RenderViewHost::OnMsgShowModalHTMLDialog( 1104 void RenderViewHost::OnMsgShowModalHTMLDialog(
1103 const GURL& url, int width, int height, const std::string& json_arguments, 1105 const GURL& url, int width, int height, const std::string& json_arguments,
1104 IPC::Message* reply_msg) { 1106 IPC::Message* reply_msg) {
1105 StopHangMonitorTimeout(); 1107 StopHangMonitorTimeout();
1106 if (modal_dialog_count_++ == 0) 1108 if (modal_dialog_count_++ == 0)
1107 SetEvent(modal_dialog_event_.Get()); 1109 modal_dialog_event_->Signal();
1108 delegate_->ShowModalHTMLDialog(url, width, height, json_arguments, reply_msg); 1110 delegate_->ShowModalHTMLDialog(url, width, height, json_arguments, reply_msg);
1109 } 1111 }
1110 1112
1111 void RenderViewHost::OnMsgPasswordFormsSeen( 1113 void RenderViewHost::OnMsgPasswordFormsSeen(
1112 const std::vector<PasswordForm>& forms) { 1114 const std::vector<PasswordForm>& forms) {
1113 delegate_->PasswordFormsSeen(forms); 1115 delegate_->PasswordFormsSeen(forms);
1114 } 1116 }
1115 1117
1116 void RenderViewHost::OnMsgAutofillFormSubmitted( 1118 void RenderViewHost::OnMsgAutofillFormSubmitted(
1117 const AutofillForm& form) { 1119 const AutofillForm& form) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 Send(new ViewMsg_PersonalizationEvent(routing_id_, 1302 Send(new ViewMsg_PersonalizationEvent(routing_id_,
1301 event_name, 1303 event_name,
1302 event_arg)); 1304 event_arg));
1303 } 1305 }
1304 #endif 1306 #endif
1305 1307
1306 void RenderViewHost::ForwardMessageFromExternalHost( 1308 void RenderViewHost::ForwardMessageFromExternalHost(
1307 const std::string& target, const std::string& message) { 1309 const std::string& target, const std::string& message) {
1308 Send(new ViewMsg_HandleMessageFromExternalHost(routing_id_, target, message)); 1310 Send(new ViewMsg_HandleMessageFromExternalHost(routing_id_, target, message));
1309 } 1311 }
OLDNEW
« no previous file with comments | « chrome/browser/render_view_host.h ('k') | chrome/browser/render_view_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698