OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 auto_size_enabled_(false), | 106 auto_size_enabled_(false), |
107 copy_request_id_(0), | 107 copy_request_id_(0), |
108 has_render_view_(has_render_view), | 108 has_render_view_(has_render_view), |
109 last_seen_auto_size_enabled_(false), | 109 last_seen_auto_size_enabled_(false), |
110 is_in_destruction_(false), | 110 is_in_destruction_(false), |
111 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 111 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
112 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 112 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
113 last_can_compose_inline_(true), | 113 last_can_compose_inline_(true), |
114 weak_ptr_factory_(this) { | 114 weak_ptr_factory_(this) { |
115 DCHECK(web_contents); | 115 DCHECK(web_contents); |
116 web_contents->SetDelegate(this); | |
117 } | |
118 | |
119 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, | |
120 int32 level, | |
121 const base::string16& message, | |
122 int32 line_no, | |
123 const base::string16& source_id) { | |
124 if (!delegate_) | |
125 return false; | |
126 | |
127 delegate_->AddMessageToConsole(level, message, line_no, source_id); | |
128 return true; | |
129 } | 116 } |
130 | 117 |
131 void BrowserPluginGuest::WillDestroy(WebContents* web_contents) { | 118 void BrowserPluginGuest::WillDestroy(WebContents* web_contents) { |
132 DCHECK_EQ(web_contents, GetWebContents()); | 119 DCHECK_EQ(web_contents, GetWebContents()); |
133 is_in_destruction_ = true; | 120 is_in_destruction_ = true; |
134 } | 121 } |
135 | 122 |
136 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { | 123 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
137 return weak_ptr_factory_.GetWeakPtr(); | 124 return weak_ptr_factory_.GetWeakPtr(); |
138 } | 125 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 gfx::Rect guest_rect(bounds); | 348 gfx::Rect guest_rect(bounds); |
362 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); | 349 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); |
363 return guest_rect; | 350 return guest_rect; |
364 } | 351 } |
365 | 352 |
366 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { | 353 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
367 embedder_visible_ = visible; | 354 embedder_visible_ = visible; |
368 UpdateVisibility(); | 355 UpdateVisibility(); |
369 } | 356 } |
370 | 357 |
371 void BrowserPluginGuest::AddNewContents(WebContents* source, | |
372 WebContents* new_contents, | |
373 WindowOpenDisposition disposition, | |
374 const gfx::Rect& initial_pos, | |
375 bool user_gesture, | |
376 bool* was_blocked) { | |
377 if (!delegate_) | |
378 return; | |
379 | |
380 delegate_->AddNewContents(source, new_contents, disposition, | |
381 initial_pos, user_gesture, was_blocked); | |
382 } | |
383 | |
384 void BrowserPluginGuest::CanDownload( | |
385 RenderViewHost* render_view_host, | |
386 const GURL& url, | |
387 const std::string& request_method, | |
388 const base::Callback<void(bool)>& callback) { | |
389 if (!delegate_ || !url.is_valid()) { | |
390 callback.Run(false); | |
391 return; | |
392 } | |
393 | |
394 delegate_->CanDownload(request_method, url, callback); | |
395 } | |
396 | |
397 void BrowserPluginGuest::LoadProgressChanged(WebContents* contents, | |
398 double progress) { | |
399 if (delegate_) | |
400 delegate_->LoadProgressed(progress); | |
401 } | |
402 | |
403 void BrowserPluginGuest::CloseContents(WebContents* source) { | |
404 if (!delegate_) | |
405 return; | |
406 | |
407 delegate_->Close(); | |
408 } | |
409 | |
410 JavaScriptDialogManager* BrowserPluginGuest::GetJavaScriptDialogManager() { | |
411 if (!delegate_) | |
412 return NULL; | |
413 return delegate_->GetJavaScriptDialogManager(); | |
414 } | |
415 | |
416 ColorChooser* BrowserPluginGuest::OpenColorChooser( | |
417 WebContents* web_contents, | |
418 SkColor color, | |
419 const std::vector<ColorSuggestion>& suggestions) { | |
420 if (!delegate_) | |
421 return NULL; | |
422 return delegate_->OpenColorChooser(web_contents, color, suggestions); | |
423 } | |
424 | |
425 bool BrowserPluginGuest::HandleContextMenu(const ContextMenuParams& params) { | |
426 if (!delegate_) | |
427 return false; | |
428 | |
429 return delegate_->HandleContextMenu(params); | |
430 } | |
431 | |
432 void BrowserPluginGuest::HandleKeyboardEvent( | |
433 WebContents* source, | |
434 const NativeWebKeyboardEvent& event) { | |
435 if (!delegate_) | |
436 return; | |
437 | |
438 delegate_->HandleKeyboardEvent(event); | |
439 } | |
440 | |
441 void BrowserPluginGuest::SetZoom(double zoom_factor) { | 358 void BrowserPluginGuest::SetZoom(double zoom_factor) { |
442 if (delegate_) | 359 if (delegate_) |
443 delegate_->SetZoom(zoom_factor); | 360 delegate_->SetZoom(zoom_factor); |
444 } | 361 } |
445 | 362 |
446 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { | 363 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { |
447 SendMessageToEmbedder( | 364 SendMessageToEmbedder( |
448 new BrowserPluginMsg_SetMouseLock(instance_id(), allow)); | 365 new BrowserPluginMsg_SetMouseLock(instance_id(), allow)); |
449 } | 366 } |
450 | 367 |
451 void BrowserPluginGuest::FindReply(WebContents* contents, | |
452 int request_id, | |
453 int number_of_matches, | |
454 const gfx::Rect& selection_rect, | |
455 int active_match_ordinal, | |
456 bool final_update) { | |
457 if (!delegate_) | |
458 return; | |
459 | |
460 // |selection_rect| is updated to incorporate embedder coordinates. | |
461 delegate_->FindReply(request_id, number_of_matches, | |
462 ToGuestRect(selection_rect), | |
463 active_match_ordinal, final_update); | |
464 } | |
465 | |
466 WebContents* BrowserPluginGuest::OpenURLFromTab(WebContents* source, | |
467 const OpenURLParams& params) { | |
468 if (!delegate_) | |
469 return NULL; | |
470 return delegate_->OpenURLFromTab(source, params); | |
471 } | |
472 | |
473 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | |
474 int opener_render_frame_id, | |
475 const base::string16& frame_name, | |
476 const GURL& target_url, | |
477 WebContents* new_contents) { | |
478 if (!delegate_) | |
479 return; | |
480 | |
481 delegate_->WebContentsCreated(source_contents, | |
482 opener_render_frame_id, | |
483 frame_name, | |
484 target_url, | |
485 new_contents); | |
486 } | |
487 | |
488 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { | |
489 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Hung")); | |
490 if (!delegate_) | |
491 return; | |
492 delegate_->RendererUnresponsive(); | |
493 } | |
494 | |
495 void BrowserPluginGuest::RendererResponsive(WebContents* source) { | |
496 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Responsive")); | |
497 if (!delegate_) | |
498 return; | |
499 delegate_->RendererResponsive(); | |
500 } | |
501 | |
502 void BrowserPluginGuest::RunFileChooser(WebContents* web_contents, | |
503 const FileChooserParams& params) { | |
504 if (!delegate_) | |
505 return; | |
506 delegate_->RunFileChooser(web_contents, params); | |
507 } | |
508 | |
509 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { | |
510 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will | |
511 // manage the focus ourselves. | |
512 return false; | |
513 } | |
514 | |
515 WebContentsImpl* BrowserPluginGuest::GetWebContents() const { | 368 WebContentsImpl* BrowserPluginGuest::GetWebContents() const { |
516 return static_cast<WebContentsImpl*>(web_contents()); | 369 return static_cast<WebContentsImpl*>(web_contents()); |
517 } | 370 } |
518 | 371 |
519 gfx::Point BrowserPluginGuest::GetScreenCoordinates( | 372 gfx::Point BrowserPluginGuest::GetScreenCoordinates( |
520 const gfx::Point& relative_position) const { | 373 const gfx::Point& relative_position) const { |
521 gfx::Point screen_pos(relative_position); | 374 gfx::Point screen_pos(relative_position); |
522 screen_pos += guest_window_rect_.OffsetFromOrigin(); | 375 screen_pos += guest_window_rect_.OffsetFromOrigin(); |
523 return screen_pos; | 376 return screen_pos; |
524 } | 377 } |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 void BrowserPluginGuest::OnShowWidget(int route_id, | 920 void BrowserPluginGuest::OnShowWidget(int route_id, |
1068 const gfx::Rect& initial_pos) { | 921 const gfx::Rect& initial_pos) { |
1069 GetWebContents()->ShowCreatedWidget(route_id, initial_pos); | 922 GetWebContents()->ShowCreatedWidget(route_id, initial_pos); |
1070 } | 923 } |
1071 | 924 |
1072 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 925 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
1073 SendMessageToEmbedder( | 926 SendMessageToEmbedder( |
1074 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | 927 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); |
1075 } | 928 } |
1076 | 929 |
1077 void BrowserPluginGuest::RequestMediaAccessPermission( | |
1078 WebContents* web_contents, | |
1079 const MediaStreamRequest& request, | |
1080 const MediaResponseCallback& callback) { | |
1081 if (!delegate_) { | |
1082 callback.Run(MediaStreamDevices(), | |
1083 MEDIA_DEVICE_INVALID_STATE, | |
1084 scoped_ptr<MediaStreamUI>()); | |
1085 return; | |
1086 } | |
1087 | |
1088 delegate_->RequestMediaAccessPermission(request, callback); | |
1089 } | |
1090 | |
1091 bool BrowserPluginGuest::PreHandleGestureEvent( | |
1092 WebContents* source, const blink::WebGestureEvent& event) { | |
1093 if (!delegate_) | |
1094 return false; | |
1095 | |
1096 return delegate_->PreHandleGestureEvent(source, event); | |
1097 } | |
1098 | |
1099 void BrowserPluginGuest::OnUpdateRect( | 930 void BrowserPluginGuest::OnUpdateRect( |
1100 const ViewHostMsg_UpdateRect_Params& params) { | 931 const ViewHostMsg_UpdateRect_Params& params) { |
1101 BrowserPluginMsg_UpdateRect_Params relay_params; | 932 BrowserPluginMsg_UpdateRect_Params relay_params; |
1102 relay_params.view_size = params.view_size; | 933 relay_params.view_size = params.view_size; |
1103 relay_params.scale_factor = params.scale_factor; | 934 relay_params.scale_factor = params.scale_factor; |
1104 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 935 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
1105 params.flags); | 936 params.flags); |
1106 | 937 |
1107 bool size_changed = last_seen_view_size_ != params.view_size; | 938 bool size_changed = last_seen_view_size_ != params.view_size; |
1108 gfx::Size old_size = last_seen_view_size_; | 939 gfx::Size old_size = last_seen_view_size_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 971 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
1141 const gfx::Range& range, | 972 const gfx::Range& range, |
1142 const std::vector<gfx::Rect>& character_bounds) { | 973 const std::vector<gfx::Rect>& character_bounds) { |
1143 static_cast<RenderWidgetHostViewBase*>( | 974 static_cast<RenderWidgetHostViewBase*>( |
1144 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 975 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
1145 range, character_bounds); | 976 range, character_bounds); |
1146 } | 977 } |
1147 #endif | 978 #endif |
1148 | 979 |
1149 } // namespace content | 980 } // namespace content |
OLD | NEW |