OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/render_view_host.h" | 5 #include "content/browser/renderer_host/render_view_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "content/browser/browser_context.h" | 19 #include "content/browser/browser_context.h" |
20 #include "content/browser/browser_message_filter.h" | 20 #include "content/browser/browser_message_filter.h" |
21 #include "content/browser/child_process_security_policy.h" | 21 #include "content/browser/child_process_security_policy.h" |
22 #include "content/browser/cross_site_request_manager.h" | 22 #include "content/browser/cross_site_request_manager.h" |
23 #include "content/browser/host_zoom_map.h" | 23 #include "content/browser/host_zoom_map.h" |
24 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 24 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
25 #include "content/browser/power_save_blocker.h" | 25 #include "content/browser/power_save_blocker.h" |
26 #include "content/browser/renderer_host/render_process_host.h" | 26 #include "content/browser/renderer_host/render_process_host_impl.h" |
27 #include "content/browser/renderer_host/render_view_host_delegate.h" | 27 #include "content/browser/renderer_host/render_view_host_delegate.h" |
28 #include "content/browser/renderer_host/render_view_host_observer.h" | 28 #include "content/browser/renderer_host/render_view_host_observer.h" |
29 #include "content/browser/renderer_host/render_widget_host.h" | 29 #include "content/browser/renderer_host/render_widget_host.h" |
30 #include "content/browser/renderer_host/render_widget_host_view.h" | 30 #include "content/browser/renderer_host/render_widget_host_view.h" |
31 #include "content/browser/site_instance.h" | 31 #include "content/browser/site_instance.h" |
32 #include "content/browser/user_metrics.h" | 32 #include "content/browser/user_metrics.h" |
33 #include "content/common/desktop_notification_messages.h" | 33 #include "content/common/desktop_notification_messages.h" |
34 #include "content/common/drag_messages.h" | 34 #include "content/common/drag_messages.h" |
35 #include "content/common/speech_input_messages.h" | 35 #include "content/common/speech_input_messages.h" |
36 #include "content/common/swapped_out_messages.h" | 36 #include "content/common/swapped_out_messages.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 | 82 |
83 } // namespace | 83 } // namespace |
84 | 84 |
85 /////////////////////////////////////////////////////////////////////////////// | 85 /////////////////////////////////////////////////////////////////////////////// |
86 // RenderViewHost, public: | 86 // RenderViewHost, public: |
87 | 87 |
88 // static | 88 // static |
89 RenderViewHost* RenderViewHost::FromID(int render_process_id, | 89 RenderViewHost* RenderViewHost::FromID(int render_process_id, |
90 int render_view_id) { | 90 int render_view_id) { |
91 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); | 91 content::RenderProcessHost* process = |
| 92 content::RenderProcessHost::FromID(render_process_id); |
92 if (!process) | 93 if (!process) |
93 return NULL; | 94 return NULL; |
94 RenderWidgetHost* widget = static_cast<RenderWidgetHost*>( | 95 RenderWidgetHost* widget = static_cast<RenderWidgetHost*>( |
95 process->GetListenerByID(render_view_id)); | 96 process->GetListenerByID(render_view_id)); |
96 if (!widget || !widget->IsRenderView()) | 97 if (!widget || !widget->IsRenderView()) |
97 return NULL; | 98 return NULL; |
98 return static_cast<RenderViewHost*>(widget); | 99 return static_cast<RenderViewHost*>(widget); |
99 } | 100 } |
100 | 101 |
101 RenderViewHost::RenderViewHost(SiteInstance* instance, | 102 RenderViewHost::RenderViewHost(SiteInstance* instance, |
(...skipping 13 matching lines...) Expand all Loading... |
115 is_waiting_for_beforeunload_ack_(false), | 116 is_waiting_for_beforeunload_ack_(false), |
116 is_waiting_for_unload_ack_(false), | 117 is_waiting_for_unload_ack_(false), |
117 unload_ack_is_for_cross_site_transition_(false), | 118 unload_ack_is_for_cross_site_transition_(false), |
118 are_javascript_messages_suppressed_(false), | 119 are_javascript_messages_suppressed_(false), |
119 sudden_termination_allowed_(false), | 120 sudden_termination_allowed_(false), |
120 session_storage_namespace_(session_storage), | 121 session_storage_namespace_(session_storage), |
121 save_accessibility_tree_for_testing_(false), | 122 save_accessibility_tree_for_testing_(false), |
122 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) { | 123 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) { |
123 if (!session_storage_namespace_) { | 124 if (!session_storage_namespace_) { |
124 session_storage_namespace_ = new SessionStorageNamespace( | 125 session_storage_namespace_ = new SessionStorageNamespace( |
125 process()->browser_context()->GetWebKitContext()); | 126 process()->GetBrowserContext()->GetWebKitContext()); |
126 } | 127 } |
127 | 128 |
128 DCHECK(instance_); | 129 DCHECK(instance_); |
129 CHECK(delegate_); // http://crbug.com/82827 | 130 CHECK(delegate_); // http://crbug.com/82827 |
130 | 131 |
131 process()->EnableSendQueue(); | 132 process()->EnableSendQueue(); |
132 | 133 |
133 content::GetContentClient()->browser()->RenderViewHostCreated(this); | 134 content::GetContentClient()->browser()->RenderViewHostCreated(this); |
134 | 135 |
135 content::NotificationService::current()->Notify( | 136 content::NotificationService::current()->Notify( |
(...skipping 10 matching lines...) Expand all Loading... |
146 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 147 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
147 content::Source<RenderViewHost>(this), | 148 content::Source<RenderViewHost>(this), |
148 content::NotificationService::NoDetails()); | 149 content::NotificationService::NoDetails()); |
149 | 150 |
150 ClearPowerSaveBlockers(); | 151 ClearPowerSaveBlockers(); |
151 | 152 |
152 delegate()->RenderViewDeleted(this); | 153 delegate()->RenderViewDeleted(this); |
153 | 154 |
154 // Be sure to clean up any leftover state from cross-site requests. | 155 // Be sure to clean up any leftover state from cross-site requests. |
155 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( | 156 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( |
156 process()->id(), routing_id(), false); | 157 process()->GetID(), routing_id(), false); |
157 } | 158 } |
158 | 159 |
159 bool RenderViewHost::CreateRenderView(const string16& frame_name) { | 160 bool RenderViewHost::CreateRenderView(const string16& frame_name) { |
160 DCHECK(!IsRenderViewLive()) << "Creating view twice"; | 161 DCHECK(!IsRenderViewLive()) << "Creating view twice"; |
161 | 162 |
162 // The process may (if we're sharing a process with another host that already | 163 // The process may (if we're sharing a process with another host that already |
163 // initialized it) or may not (we have our own process or the old process | 164 // initialized it) or may not (we have our own process or the old process |
164 // crashed) have been initialized. Calling Init multiple times will be | 165 // crashed) have been initialized. Calling Init multiple times will be |
165 // ignored, so this is safe. | 166 // ignored, so this is safe. |
166 if (!process()->Init(renderer_accessible())) | 167 if (!process()->Init(renderer_accessible())) |
167 return false; | 168 return false; |
168 DCHECK(process()->HasConnection()); | 169 DCHECK(process()->HasConnection()); |
169 DCHECK(process()->browser_context()); | 170 DCHECK(process()->GetBrowserContext()); |
170 | 171 |
171 renderer_initialized_ = true; | 172 renderer_initialized_ = true; |
172 | 173 |
173 process()->SetCompositingSurface(routing_id(), | 174 process()->SetCompositingSurface(routing_id(), |
174 GetCompositingSurface()); | 175 GetCompositingSurface()); |
175 | 176 |
176 ViewMsg_New_Params params; | 177 ViewMsg_New_Params params; |
177 params.parent_window = GetNativeViewId(); | 178 params.parent_window = GetNativeViewId(); |
178 params.renderer_preferences = | 179 params.renderer_preferences = |
179 delegate_->GetRendererPrefs(process()->browser_context()); | 180 delegate_->GetRendererPrefs(process()->GetBrowserContext()); |
180 params.web_preferences = delegate_->GetWebkitPrefs(); | 181 params.web_preferences = delegate_->GetWebkitPrefs(); |
181 params.view_id = routing_id(); | 182 params.view_id = routing_id(); |
182 params.session_storage_namespace_id = session_storage_namespace_->id(); | 183 params.session_storage_namespace_id = session_storage_namespace_->id(); |
183 params.frame_name = frame_name; | 184 params.frame_name = frame_name; |
184 Send(new ViewMsg_New(params)); | 185 Send(new ViewMsg_New(params)); |
185 | 186 |
186 // If it's enabled, tell the renderer to set up the Javascript bindings for | 187 // If it's enabled, tell the renderer to set up the Javascript bindings for |
187 // sending messages back to the browser. | 188 // sending messages back to the browser. |
188 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); | 189 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); |
189 // Let our delegate know that we created a RenderView. | 190 // Let our delegate know that we created a RenderView. |
190 delegate_->RenderViewCreated(this); | 191 delegate_->RenderViewCreated(this); |
191 | 192 |
192 FOR_EACH_OBSERVER( | 193 FOR_EACH_OBSERVER( |
193 RenderViewHostObserver, observers_, RenderViewHostInitialized()); | 194 RenderViewHostObserver, observers_, RenderViewHostInitialized()); |
194 | 195 |
195 return true; | 196 return true; |
196 } | 197 } |
197 | 198 |
198 bool RenderViewHost::IsRenderViewLive() const { | 199 bool RenderViewHost::IsRenderViewLive() const { |
199 return process()->HasConnection() && renderer_initialized_; | 200 return process()->HasConnection() && renderer_initialized_; |
200 } | 201 } |
201 | 202 |
202 void RenderViewHost::SyncRendererPrefs() { | 203 void RenderViewHost::SyncRendererPrefs() { |
203 Send(new ViewMsg_SetRendererPrefs(routing_id(), | 204 Send(new ViewMsg_SetRendererPrefs(routing_id(), |
204 delegate_->GetRendererPrefs( | 205 delegate_->GetRendererPrefs( |
205 process()->browser_context()))); | 206 process()->GetBrowserContext()))); |
206 } | 207 } |
207 | 208 |
208 void RenderViewHost::Navigate(const ViewMsg_Navigate_Params& params) { | 209 void RenderViewHost::Navigate(const ViewMsg_Navigate_Params& params) { |
209 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( | 210 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( |
210 process()->id(), params.url); | 211 process()->GetID(), params.url); |
211 | 212 |
212 ViewMsg_Navigate* nav_message = new ViewMsg_Navigate(routing_id(), params); | 213 ViewMsg_Navigate* nav_message = new ViewMsg_Navigate(routing_id(), params); |
213 | 214 |
214 // Only send the message if we aren't suspended at the start of a cross-site | 215 // Only send the message if we aren't suspended at the start of a cross-site |
215 // request. | 216 // request. |
216 if (navigations_suspended_) { | 217 if (navigations_suspended_) { |
217 // Shouldn't be possible to have a second navigation while suspended, since | 218 // Shouldn't be possible to have a second navigation while suspended, since |
218 // navigations will only be suspended during a cross-site request. If a | 219 // navigations will only be suspended during a cross-site request. If a |
219 // second navigation occurs, TabContents will cancel this pending RVH | 220 // second navigation occurs, TabContents will cancel this pending RVH |
220 // create a new pending RVH. | 221 // create a new pending RVH. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // to false in SetNavigationsSuspended if we swap back in. | 324 // to false in SetNavigationsSuspended if we swap back in. |
324 is_swapped_out_ = true; | 325 is_swapped_out_ = true; |
325 | 326 |
326 // This will be set back to false in OnSwapOutACK, just before we replace | 327 // This will be set back to false in OnSwapOutACK, just before we replace |
327 // this RVH with the pending RVH. | 328 // this RVH with the pending RVH. |
328 is_waiting_for_unload_ack_ = true; | 329 is_waiting_for_unload_ack_ = true; |
329 // Start the hang monitor in case the renderer hangs in the unload handler. | 330 // Start the hang monitor in case the renderer hangs in the unload handler. |
330 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); | 331 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); |
331 | 332 |
332 ViewMsg_SwapOut_Params params; | 333 ViewMsg_SwapOut_Params params; |
333 params.closing_process_id = process()->id(); | 334 params.closing_process_id = process()->GetID(); |
334 params.closing_route_id = routing_id(); | 335 params.closing_route_id = routing_id(); |
335 params.new_render_process_host_id = new_render_process_host_id; | 336 params.new_render_process_host_id = new_render_process_host_id; |
336 params.new_request_id = new_request_id; | 337 params.new_request_id = new_request_id; |
337 if (IsRenderViewLive()) { | 338 if (IsRenderViewLive()) { |
338 Send(new ViewMsg_SwapOut(routing_id(), params)); | 339 Send(new ViewMsg_SwapOut(routing_id(), params)); |
339 } else { | 340 } else { |
340 // This RenderViewHost doesn't have a live renderer, so just skip the unload | 341 // This RenderViewHost doesn't have a live renderer, so just skip the unload |
341 // event. We must notify the ResourceDispatcherHost on the IO thread, | 342 // event. We must notify the ResourceDispatcherHost on the IO thread, |
342 // which we will do through the RenderProcessHost's widget helper. | 343 // which we will do through the RenderProcessHost's widget helper. |
343 process()->CrossSiteSwapOutACK(params); | 344 process()->CrossSiteSwapOutACK(params); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 is_waiting_for_beforeunload_ack_ = false; | 386 is_waiting_for_beforeunload_ack_ = false; |
386 is_waiting_for_unload_ack_ = false; | 387 is_waiting_for_unload_ack_ = false; |
387 | 388 |
388 sudden_termination_allowed_ = true; | 389 sudden_termination_allowed_ = true; |
389 delegate_->Close(this); | 390 delegate_->Close(this); |
390 } | 391 } |
391 | 392 |
392 void RenderViewHost::SetHasPendingCrossSiteRequest(bool has_pending_request, | 393 void RenderViewHost::SetHasPendingCrossSiteRequest(bool has_pending_request, |
393 int request_id) { | 394 int request_id) { |
394 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( | 395 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( |
395 process()->id(), routing_id(), has_pending_request); | 396 process()->GetID(), routing_id(), has_pending_request); |
396 pending_request_id_ = request_id; | 397 pending_request_id_ = request_id; |
397 } | 398 } |
398 | 399 |
399 int RenderViewHost::GetPendingRequestId() { | 400 int RenderViewHost::GetPendingRequestId() { |
400 return pending_request_id_; | 401 return pending_request_id_; |
401 } | 402 } |
402 | 403 |
403 void RenderViewHost::DragTargetDragEnter( | 404 void RenderViewHost::DragTargetDragEnter( |
404 const WebDropData& drop_data, | 405 const WebDropData& drop_data, |
405 const gfx::Point& client_pt, | 406 const gfx::Point& client_pt, |
406 const gfx::Point& screen_pt, | 407 const gfx::Point& screen_pt, |
407 WebDragOperationsMask operations_allowed) { | 408 WebDragOperationsMask operations_allowed) { |
408 // Grant the renderer the ability to load the drop_data. | 409 // Grant the renderer the ability to load the drop_data. |
409 ChildProcessSecurityPolicy* policy = | 410 ChildProcessSecurityPolicy* policy = |
410 ChildProcessSecurityPolicy::GetInstance(); | 411 ChildProcessSecurityPolicy::GetInstance(); |
411 policy->GrantRequestURL(process()->id(), drop_data.url); | 412 policy->GrantRequestURL(process()->GetID(), drop_data.url); |
412 for (std::vector<string16>::const_iterator iter(drop_data.filenames.begin()); | 413 for (std::vector<string16>::const_iterator iter(drop_data.filenames.begin()); |
413 iter != drop_data.filenames.end(); ++iter) { | 414 iter != drop_data.filenames.end(); ++iter) { |
414 FilePath path = FilePath::FromWStringHack(UTF16ToWideHack(*iter)); | 415 FilePath path = FilePath::FromWStringHack(UTF16ToWideHack(*iter)); |
415 policy->GrantRequestURL(process()->id(), | 416 policy->GrantRequestURL(process()->GetID(), |
416 net::FilePathToFileURL(path)); | 417 net::FilePathToFileURL(path)); |
417 policy->GrantReadFile(process()->id(), path); | 418 policy->GrantReadFile(process()->GetID(), path); |
418 | 419 |
419 // Allow dragged directories to be enumerated by the child process. | 420 // Allow dragged directories to be enumerated by the child process. |
420 // Note that we can't tell a file from a directory at this point. | 421 // Note that we can't tell a file from a directory at this point. |
421 policy->GrantReadDirectory(process()->id(), path); | 422 policy->GrantReadDirectory(process()->GetID(), path); |
422 } | 423 } |
423 Send(new DragMsg_TargetDragEnter(routing_id(), drop_data, client_pt, | 424 Send(new DragMsg_TargetDragEnter(routing_id(), drop_data, client_pt, |
424 screen_pt, operations_allowed)); | 425 screen_pt, operations_allowed)); |
425 } | 426 } |
426 | 427 |
427 void RenderViewHost::DragTargetDragOver( | 428 void RenderViewHost::DragTargetDragOver( |
428 const gfx::Point& client_pt, const gfx::Point& screen_pt, | 429 const gfx::Point& client_pt, const gfx::Point& screen_pt, |
429 WebDragOperationsMask operations_allowed) { | 430 WebDragOperationsMask operations_allowed) { |
430 Send(new DragMsg_TargetDragOver(routing_id(), client_pt, screen_pt, | 431 Send(new DragMsg_TargetDragOver(routing_id(), client_pt, screen_pt, |
431 operations_allowed)); | 432 operations_allowed)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 &observer, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, | 515 &observer, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
515 content::Source<RenderViewHost>(this)); | 516 content::Source<RenderViewHost>(this)); |
516 MessageLoop* loop = MessageLoop::current(); | 517 MessageLoop* loop = MessageLoop::current(); |
517 loop->Run(); | 518 loop->Run(); |
518 return observer.value()->DeepCopy(); | 519 return observer.value()->DeepCopy(); |
519 } | 520 } |
520 | 521 |
521 void RenderViewHost::JavaScriptDialogClosed(IPC::Message* reply_msg, | 522 void RenderViewHost::JavaScriptDialogClosed(IPC::Message* reply_msg, |
522 bool success, | 523 bool success, |
523 const string16& user_input) { | 524 const string16& user_input) { |
524 process()->set_ignore_input_events(false); | 525 process()->SetIgnoreInputEvents(false); |
525 bool is_waiting = | 526 bool is_waiting = |
526 is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_; | 527 is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_; |
527 if (is_waiting) | 528 if (is_waiting) |
528 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); | 529 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); |
529 | 530 |
530 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, | 531 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, |
531 success, user_input); | 532 success, user_input); |
532 Send(reply_msg); | 533 Send(reply_msg); |
533 | 534 |
534 // If we are waiting for an unload or beforeunload ack and the user has | 535 // If we are waiting for an unload or beforeunload ack and the user has |
(...skipping 25 matching lines...) Expand all Loading... |
560 false, WebDragOperationNone)); | 561 false, WebDragOperationNone)); |
561 } | 562 } |
562 | 563 |
563 void RenderViewHost::DragSourceSystemDragEnded() { | 564 void RenderViewHost::DragSourceSystemDragEnded() { |
564 Send(new DragMsg_SourceSystemDragEnded(routing_id())); | 565 Send(new DragMsg_SourceSystemDragEnded(routing_id())); |
565 } | 566 } |
566 | 567 |
567 void RenderViewHost::AllowBindings(int bindings_flags) { | 568 void RenderViewHost::AllowBindings(int bindings_flags) { |
568 if (bindings_flags & content::BINDINGS_POLICY_WEB_UI) { | 569 if (bindings_flags & content::BINDINGS_POLICY_WEB_UI) { |
569 ChildProcessSecurityPolicy::GetInstance()->GrantWebUIBindings( | 570 ChildProcessSecurityPolicy::GetInstance()->GrantWebUIBindings( |
570 process()->id()); | 571 process()->GetID()); |
571 } | 572 } |
572 | 573 |
573 enabled_bindings_ |= bindings_flags; | 574 enabled_bindings_ |= bindings_flags; |
574 if (renderer_initialized_) | 575 if (renderer_initialized_) |
575 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); | 576 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); |
576 } | 577 } |
577 | 578 |
578 void RenderViewHost::SetWebUIProperty(const std::string& name, | 579 void RenderViewHost::SetWebUIProperty(const std::string& name, |
579 const std::string& value) { | 580 const std::string& value) { |
580 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI); | 581 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI); |
(...skipping 22 matching lines...) Expand all Loading... |
603 Send(new ViewMsg_SetInitialFocus(routing_id(), reverse)); | 604 Send(new ViewMsg_SetInitialFocus(routing_id(), reverse)); |
604 } | 605 } |
605 | 606 |
606 void RenderViewHost::FilesSelectedInChooser( | 607 void RenderViewHost::FilesSelectedInChooser( |
607 const std::vector<FilePath>& files, | 608 const std::vector<FilePath>& files, |
608 int permissions) { | 609 int permissions) { |
609 // Grant the security access requested to the given files. | 610 // Grant the security access requested to the given files. |
610 for (std::vector<FilePath>::const_iterator file = files.begin(); | 611 for (std::vector<FilePath>::const_iterator file = files.begin(); |
611 file != files.end(); ++file) { | 612 file != files.end(); ++file) { |
612 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 613 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
613 process()->id(), *file, permissions); | 614 process()->GetID(), *file, permissions); |
614 } | 615 } |
615 Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); | 616 Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); |
616 } | 617 } |
617 | 618 |
618 void RenderViewHost::DirectoryEnumerationFinished( | 619 void RenderViewHost::DirectoryEnumerationFinished( |
619 int request_id, | 620 int request_id, |
620 const std::vector<FilePath>& files) { | 621 const std::vector<FilePath>& files) { |
621 // Grant the security access requested to the given files. | 622 // Grant the security access requested to the given files. |
622 for (std::vector<FilePath>::const_iterator file = files.begin(); | 623 for (std::vector<FilePath>::const_iterator file = files.begin(); |
623 file != files.end(); ++file) { | 624 file != files.end(); ++file) { |
624 ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( | 625 ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( |
625 process()->id(), *file); | 626 process()->GetID(), *file); |
626 } | 627 } |
627 Send(new ViewMsg_EnumerateDirectoryResponse(routing_id(), | 628 Send(new ViewMsg_EnumerateDirectoryResponse(routing_id(), |
628 request_id, | 629 request_id, |
629 files)); | 630 files)); |
630 } | 631 } |
631 | 632 |
632 void RenderViewHost::LoadStateChanged(const GURL& url, | 633 void RenderViewHost::LoadStateChanged(const GURL& url, |
633 const net::LoadStateWithParam& load_state, | 634 const net::LoadStateWithParam& load_state, |
634 uint64 upload_position, | 635 uint64 upload_position, |
635 uint64 upload_size) { | 636 uint64 upload_size) { |
636 delegate_->LoadStateChanged(url, load_state, upload_position, upload_size); | 637 delegate_->LoadStateChanged(url, load_state, upload_position, upload_size); |
637 } | 638 } |
638 | 639 |
639 bool RenderViewHost::SuddenTerminationAllowed() const { | 640 bool RenderViewHost::SuddenTerminationAllowed() const { |
640 return sudden_termination_allowed_ || process()->sudden_termination_allowed(); | 641 return sudden_termination_allowed_ || process()->SuddenTerminationAllowed(); |
641 } | 642 } |
642 | 643 |
643 /////////////////////////////////////////////////////////////////////////////// | 644 /////////////////////////////////////////////////////////////////////////////// |
644 // RenderViewHost, IPC message handlers: | 645 // RenderViewHost, IPC message handlers: |
645 | 646 |
646 bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { | 647 bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { |
647 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this)) | 648 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this)) |
648 return true; | 649 return true; |
649 | 650 |
650 // Filter out most IPC messages if this renderer is swapped out. | 651 // Filter out most IPC messages if this renderer is swapped out. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 } | 877 } |
877 | 878 |
878 // If we're waiting for an unload ack from this renderer and we receive a | 879 // If we're waiting for an unload ack from this renderer and we receive a |
879 // Navigate message, then the renderer was navigating before it received the | 880 // Navigate message, then the renderer was navigating before it received the |
880 // unload request. It will either respond to the unload request soon or our | 881 // unload request. It will either respond to the unload request soon or our |
881 // timer will expire. Either way, we should ignore this message, because we | 882 // timer will expire. Either way, we should ignore this message, because we |
882 // have already committed to closing this renderer. | 883 // have already committed to closing this renderer. |
883 if (is_waiting_for_unload_ack_) | 884 if (is_waiting_for_unload_ack_) |
884 return; | 885 return; |
885 | 886 |
886 const int renderer_id = process()->id(); | 887 const int renderer_id = process()->GetID(); |
887 ChildProcessSecurityPolicy* policy = | 888 ChildProcessSecurityPolicy* policy = |
888 ChildProcessSecurityPolicy::GetInstance(); | 889 ChildProcessSecurityPolicy::GetInstance(); |
889 // Without this check, an evil renderer can trick the browser into creating | 890 // Without this check, an evil renderer can trick the browser into creating |
890 // a navigation entry for a banned URL. If the user clicks the back button | 891 // a navigation entry for a banned URL. If the user clicks the back button |
891 // followed by the forward button (or clicks reload, or round-trips through | 892 // followed by the forward button (or clicks reload, or round-trips through |
892 // session restore, etc), we'll think that the browser commanded the | 893 // session restore, etc), we'll think that the browser commanded the |
893 // renderer to load the URL and grant the renderer the privileges to request | 894 // renderer to load the URL and grant the renderer the privileges to request |
894 // the URL. To prevent this attack, we block the renderer from inserting | 895 // the URL. To prevent this attack, we block the renderer from inserting |
895 // banned URLs into the navigation controller in the first place. | 896 // banned URLs into the navigation controller in the first place. |
896 FilterURL(policy, renderer_id, &validated_params.url); | 897 FilterURL(policy, renderer_id, &validated_params.url); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 } | 979 } |
979 | 980 |
980 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { | 981 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { |
981 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); | 982 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); |
982 if (!view) | 983 if (!view) |
983 return; | 984 return; |
984 | 985 |
985 // Validate the URLs in |params|. If the renderer can't request the URLs | 986 // Validate the URLs in |params|. If the renderer can't request the URLs |
986 // directly, don't show them in the context menu. | 987 // directly, don't show them in the context menu. |
987 ContextMenuParams validated_params(params); | 988 ContextMenuParams validated_params(params); |
988 int renderer_id = process()->id(); | 989 int renderer_id = process()->GetID(); |
989 ChildProcessSecurityPolicy* policy = | 990 ChildProcessSecurityPolicy* policy = |
990 ChildProcessSecurityPolicy::GetInstance(); | 991 ChildProcessSecurityPolicy::GetInstance(); |
991 | 992 |
992 // We don't validate |unfiltered_link_url| so that this field can be used | 993 // We don't validate |unfiltered_link_url| so that this field can be used |
993 // when users want to copy the original link URL. | 994 // when users want to copy the original link URL. |
994 FilterURL(policy, renderer_id, &validated_params.link_url); | 995 FilterURL(policy, renderer_id, &validated_params.link_url); |
995 FilterURL(policy, renderer_id, &validated_params.src_url); | 996 FilterURL(policy, renderer_id, &validated_params.src_url); |
996 FilterURL(policy, renderer_id, &validated_params.page_url); | 997 FilterURL(policy, renderer_id, &validated_params.page_url); |
997 FilterURL(policy, renderer_id, &validated_params.frame_url); | 998 FilterURL(policy, renderer_id, &validated_params.frame_url); |
998 | 999 |
999 view->ShowContextMenu(validated_params); | 1000 view->ShowContextMenu(validated_params); |
1000 } | 1001 } |
1001 | 1002 |
1002 void RenderViewHost::OnMsgToggleFullscreen(bool enter_fullscreen) { | 1003 void RenderViewHost::OnMsgToggleFullscreen(bool enter_fullscreen) { |
1003 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1004 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1004 delegate_->ToggleFullscreenMode(enter_fullscreen); | 1005 delegate_->ToggleFullscreenMode(enter_fullscreen); |
1005 } | 1006 } |
1006 | 1007 |
1007 void RenderViewHost::OnMsgOpenURL(const GURL& url, | 1008 void RenderViewHost::OnMsgOpenURL(const GURL& url, |
1008 const GURL& referrer, | 1009 const GURL& referrer, |
1009 WindowOpenDisposition disposition, | 1010 WindowOpenDisposition disposition, |
1010 int64 source_frame_id) { | 1011 int64 source_frame_id) { |
1011 GURL validated_url(url); | 1012 GURL validated_url(url); |
1012 FilterURL(ChildProcessSecurityPolicy::GetInstance(), | 1013 FilterURL(ChildProcessSecurityPolicy::GetInstance(), |
1013 process()->id(), &validated_url); | 1014 process()->GetID(), &validated_url); |
1014 | 1015 |
1015 delegate_->RequestOpenURL( | 1016 delegate_->RequestOpenURL( |
1016 validated_url, referrer, disposition, source_frame_id); | 1017 validated_url, referrer, disposition, source_frame_id); |
1017 } | 1018 } |
1018 | 1019 |
1019 void RenderViewHost::OnMsgDidContentsPreferredSizeChange( | 1020 void RenderViewHost::OnMsgDidContentsPreferredSizeChange( |
1020 const gfx::Size& new_size) { | 1021 const gfx::Size& new_size) { |
1021 delegate_->UpdatePreferredSize(new_size); | 1022 delegate_->UpdatePreferredSize(new_size); |
1022 } | 1023 } |
1023 | 1024 |
(...skipping 27 matching lines...) Expand all Loading... |
1051 } | 1052 } |
1052 | 1053 |
1053 void RenderViewHost::OnMsgRunJavaScriptMessage( | 1054 void RenderViewHost::OnMsgRunJavaScriptMessage( |
1054 const string16& message, | 1055 const string16& message, |
1055 const string16& default_prompt, | 1056 const string16& default_prompt, |
1056 const GURL& frame_url, | 1057 const GURL& frame_url, |
1057 const int flags, | 1058 const int flags, |
1058 IPC::Message* reply_msg) { | 1059 IPC::Message* reply_msg) { |
1059 // While a JS message dialog is showing, tabs in the same process shouldn't | 1060 // While a JS message dialog is showing, tabs in the same process shouldn't |
1060 // process input events. | 1061 // process input events. |
1061 process()->set_ignore_input_events(true); | 1062 process()->SetIgnoreInputEvents(true); |
1062 StopHangMonitorTimeout(); | 1063 StopHangMonitorTimeout(); |
1063 delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url, | 1064 delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url, |
1064 flags, reply_msg, | 1065 flags, reply_msg, |
1065 &are_javascript_messages_suppressed_); | 1066 &are_javascript_messages_suppressed_); |
1066 } | 1067 } |
1067 | 1068 |
1068 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const GURL& frame_url, | 1069 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const GURL& frame_url, |
1069 const string16& message, | 1070 const string16& message, |
1070 IPC::Message* reply_msg) { | 1071 IPC::Message* reply_msg) { |
1071 // While a JS before unload dialog is showing, tabs in the same process | 1072 // While a JS before unload dialog is showing, tabs in the same process |
1072 // shouldn't process input events. | 1073 // shouldn't process input events. |
1073 process()->set_ignore_input_events(true); | 1074 process()->SetIgnoreInputEvents(true); |
1074 StopHangMonitorTimeout(); | 1075 StopHangMonitorTimeout(); |
1075 delegate_->RunBeforeUnloadConfirm(this, message, reply_msg); | 1076 delegate_->RunBeforeUnloadConfirm(this, message, reply_msg); |
1076 } | 1077 } |
1077 | 1078 |
1078 void RenderViewHost::OnMsgStartDragging( | 1079 void RenderViewHost::OnMsgStartDragging( |
1079 const WebDropData& drop_data, | 1080 const WebDropData& drop_data, |
1080 WebDragOperationsMask drag_operations_mask, | 1081 WebDragOperationsMask drag_operations_mask, |
1081 const SkBitmap& image, | 1082 const SkBitmap& image, |
1082 const gfx::Point& image_offset) { | 1083 const gfx::Point& image_offset) { |
1083 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); | 1084 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); |
1084 if (!view) | 1085 if (!view) |
1085 return; | 1086 return; |
1086 | 1087 |
1087 GURL drag_url = drop_data.url; | 1088 GURL drag_url = drop_data.url; |
1088 GURL html_base_url = drop_data.html_base_url; | 1089 GURL html_base_url = drop_data.html_base_url; |
1089 | 1090 |
1090 ChildProcessSecurityPolicy* policy = | 1091 ChildProcessSecurityPolicy* policy = |
1091 ChildProcessSecurityPolicy::GetInstance(); | 1092 ChildProcessSecurityPolicy::GetInstance(); |
1092 | 1093 |
1093 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar. | 1094 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar. |
1094 if (!drag_url.SchemeIs(chrome::kJavaScriptScheme)) | 1095 if (!drag_url.SchemeIs(chrome::kJavaScriptScheme)) |
1095 FilterURL(policy, process()->id(), &drag_url); | 1096 FilterURL(policy, process()->GetID(), &drag_url); |
1096 FilterURL(policy, process()->id(), &html_base_url); | 1097 FilterURL(policy, process()->GetID(), &html_base_url); |
1097 | 1098 |
1098 if (drag_url != drop_data.url || html_base_url != drop_data.html_base_url) { | 1099 if (drag_url != drop_data.url || html_base_url != drop_data.html_base_url) { |
1099 WebDropData drop_data_copy = drop_data; | 1100 WebDropData drop_data_copy = drop_data; |
1100 drop_data_copy.url = drag_url; | 1101 drop_data_copy.url = drag_url; |
1101 drop_data_copy.html_base_url = html_base_url; | 1102 drop_data_copy.html_base_url = html_base_url; |
1102 view->StartDragging(drop_data_copy, drag_operations_mask, image, | 1103 view->StartDragging(drop_data_copy, drag_operations_mask, image, |
1103 image_offset); | 1104 image_offset); |
1104 } else { | 1105 } else { |
1105 view->StartDragging(drop_data, drag_operations_mask, image, image_offset); | 1106 view->StartDragging(drop_data, drag_operations_mask, image, image_offset); |
1106 } | 1107 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 content::NotificationService::current()->Notify( | 1404 content::NotificationService::current()->Notify( |
1404 content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, | 1405 content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
1405 content::Source<RenderViewHost>(this), | 1406 content::Source<RenderViewHost>(this), |
1406 content::Details<std::pair<int, Value*> >(&details)); | 1407 content::Details<std::pair<int, Value*> >(&details)); |
1407 } | 1408 } |
1408 | 1409 |
1409 void RenderViewHost::OnDidZoomURL(double zoom_level, | 1410 void RenderViewHost::OnDidZoomURL(double zoom_level, |
1410 bool remember, | 1411 bool remember, |
1411 const GURL& url) { | 1412 const GURL& url) { |
1412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1413 HostZoomMap* host_zoom_map = process()->browser_context()->GetHostZoomMap(); | 1414 HostZoomMap* host_zoom_map = process()->GetBrowserContext()-> |
| 1415 GetHostZoomMap(); |
1414 if (remember) { | 1416 if (remember) { |
1415 host_zoom_map->SetZoomLevel(net::GetHostOrSpecFromURL(url), zoom_level); | 1417 host_zoom_map->SetZoomLevel(net::GetHostOrSpecFromURL(url), zoom_level); |
1416 // Notify renderers from this browser context. | 1418 // Notify renderers from this browser context. |
1417 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 1419 for (content::RenderProcessHost::iterator i( |
| 1420 content::RenderProcessHost::AllHostsIterator()); |
1418 !i.IsAtEnd(); i.Advance()) { | 1421 !i.IsAtEnd(); i.Advance()) { |
1419 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 1422 content::RenderProcessHost* render_process_host = i.GetCurrentValue(); |
1420 if (render_process_host->browser_context()->GetHostZoomMap()-> | 1423 if (render_process_host->GetBrowserContext()->GetHostZoomMap()-> |
1421 GetOriginal() == host_zoom_map) { | 1424 GetOriginal() == host_zoom_map) { |
1422 render_process_host->Send( | 1425 render_process_host->Send( |
1423 new ViewMsg_SetZoomLevelForCurrentURL(url, zoom_level)); | 1426 new ViewMsg_SetZoomLevelForCurrentURL(url, zoom_level)); |
1424 } | 1427 } |
1425 } | 1428 } |
1426 } else { | 1429 } else { |
1427 host_zoom_map->SetTemporaryZoomLevel( | 1430 host_zoom_map->SetTemporaryZoomLevel( |
1428 process()->id(), routing_id(), zoom_level); | 1431 process()->GetID(), routing_id(), zoom_level); |
1429 } | 1432 } |
1430 } | 1433 } |
1431 | 1434 |
1432 void RenderViewHost::OnMediaNotification(int64 player_cookie, | 1435 void RenderViewHost::OnMediaNotification(int64 player_cookie, |
1433 bool has_video, | 1436 bool has_video, |
1434 bool has_audio, | 1437 bool has_audio, |
1435 bool is_playing) { | 1438 bool is_playing) { |
1436 if (is_playing) { | 1439 if (is_playing) { |
1437 PowerSaveBlocker* blocker = NULL; | 1440 PowerSaveBlocker* blocker = NULL; |
1438 if (has_video) { | 1441 if (has_video) { |
1439 blocker = new PowerSaveBlocker( | 1442 blocker = new PowerSaveBlocker( |
1440 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep); | 1443 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep); |
1441 } else if (has_audio) { | 1444 } else if (has_audio) { |
1442 blocker = new PowerSaveBlocker( | 1445 blocker = new PowerSaveBlocker( |
1443 PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep); | 1446 PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep); |
1444 } | 1447 } |
1445 | 1448 |
1446 if (blocker) | 1449 if (blocker) |
1447 power_save_blockers_[player_cookie] = blocker; | 1450 power_save_blockers_[player_cookie] = blocker; |
1448 } else { | 1451 } else { |
1449 delete power_save_blockers_[player_cookie]; | 1452 delete power_save_blockers_[player_cookie]; |
1450 power_save_blockers_.erase(player_cookie); | 1453 power_save_blockers_.erase(player_cookie); |
1451 } | 1454 } |
1452 } | 1455 } |
1453 | 1456 |
1454 void RenderViewHost::OnRequestDesktopNotificationPermission( | 1457 void RenderViewHost::OnRequestDesktopNotificationPermission( |
1455 const GURL& source_origin, int callback_context) { | 1458 const GURL& source_origin, int callback_context) { |
1456 content::GetContentClient()->browser()->RequestDesktopNotificationPermission( | 1459 content::GetContentClient()->browser()->RequestDesktopNotificationPermission( |
1457 source_origin, callback_context, process()->id(), routing_id()); | 1460 source_origin, callback_context, process()->GetID(), routing_id()); |
1458 } | 1461 } |
1459 | 1462 |
1460 void RenderViewHost::OnShowDesktopNotification( | 1463 void RenderViewHost::OnShowDesktopNotification( |
1461 const content::ShowDesktopNotificationHostMsgParams& params) { | 1464 const content::ShowDesktopNotificationHostMsgParams& params) { |
1462 // Disallow HTML notifications from javascript: and file: schemes as this | 1465 // Disallow HTML notifications from javascript: and file: schemes as this |
1463 // allows unwanted cross-domain access. | 1466 // allows unwanted cross-domain access. |
1464 GURL url = params.contents_url; | 1467 GURL url = params.contents_url; |
1465 if (params.is_html && | 1468 if (params.is_html && |
1466 (url.SchemeIs(chrome::kJavaScriptScheme) || | 1469 (url.SchemeIs(chrome::kJavaScriptScheme) || |
1467 url.SchemeIs(chrome::kFileScheme))) { | 1470 url.SchemeIs(chrome::kFileScheme))) { |
1468 return; | 1471 return; |
1469 } | 1472 } |
1470 | 1473 |
1471 content::GetContentClient()->browser()->ShowDesktopNotification( | 1474 content::GetContentClient()->browser()->ShowDesktopNotification( |
1472 params, process()->id(), routing_id(), false); | 1475 params, process()->GetID(), routing_id(), false); |
1473 } | 1476 } |
1474 | 1477 |
1475 void RenderViewHost::OnCancelDesktopNotification(int notification_id) { | 1478 void RenderViewHost::OnCancelDesktopNotification(int notification_id) { |
1476 content::GetContentClient()->browser()->CancelDesktopNotification( | 1479 content::GetContentClient()->browser()->CancelDesktopNotification( |
1477 process()->id(), routing_id(), notification_id); | 1480 process()->GetID(), routing_id(), notification_id); |
1478 } | 1481 } |
1479 | 1482 |
1480 #if defined(OS_MACOSX) | 1483 #if defined(OS_MACOSX) |
1481 void RenderViewHost::OnMsgShowPopup( | 1484 void RenderViewHost::OnMsgShowPopup( |
1482 const ViewHostMsg_ShowPopup_Params& params) { | 1485 const ViewHostMsg_ShowPopup_Params& params) { |
1483 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); | 1486 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); |
1484 if (view) { | 1487 if (view) { |
1485 view->ShowPopupMenu(params.bounds, | 1488 view->ShowPopupMenu(params.bounds, |
1486 params.item_height, | 1489 params.item_height, |
1487 params.item_font_size, | 1490 params.item_font_size, |
(...skipping 11 matching lines...) Expand all Loading... |
1499 | 1502 |
1500 void RenderViewHost::OnWebUISend(const GURL& source_url, | 1503 void RenderViewHost::OnWebUISend(const GURL& source_url, |
1501 const std::string& name, | 1504 const std::string& name, |
1502 const base::ListValue& args) { | 1505 const base::ListValue& args) { |
1503 delegate_->WebUISend(this, source_url, name, args); | 1506 delegate_->WebUISend(this, source_url, name, args); |
1504 } | 1507 } |
1505 | 1508 |
1506 void RenderViewHost::ClearPowerSaveBlockers() { | 1509 void RenderViewHost::ClearPowerSaveBlockers() { |
1507 STLDeleteValues(&power_save_blockers_); | 1510 STLDeleteValues(&power_save_blockers_); |
1508 } | 1511 } |
OLD | NEW |