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