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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 295083002: BrowserPluginGuest is no longer a WebContentsDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@make_context_menu_easier_to_refactor
Patch Set: Fixed content_browsertests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" 11 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
14 #include "content/browser/browser_thread_impl.h" 13 #include "content/browser/browser_thread_impl.h"
15 #include "content/browser/child_process_security_policy_impl.h" 14 #include "content/browser/child_process_security_policy_impl.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h" 15 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/browser/frame_host/render_widget_host_view_guest.h" 16 #include "content/browser/frame_host/render_widget_host_view_guest.h"
18 #include "content/browser/loader/resource_dispatcher_host_impl.h" 17 #include "content/browser/loader/resource_dispatcher_host_impl.h"
19 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
20 #include "content/browser/renderer_host/render_view_host_impl.h" 18 #include "content/browser/renderer_host/render_view_host_impl.h"
21 #include "content/browser/renderer_host/render_widget_host_impl.h" 19 #include "content/browser/renderer_host/render_widget_host_impl.h"
22 #include "content/browser/renderer_host/render_widget_host_view_base.h" 20 #include "content/browser/renderer_host/render_widget_host_view_base.h"
23 #include "content/browser/web_contents/web_contents_impl.h" 21 #include "content/browser/web_contents/web_contents_impl.h"
24 #include "content/browser/web_contents/web_contents_view_guest.h" 22 #include "content/browser/web_contents/web_contents_view_guest.h"
25 #include "content/common/browser_plugin/browser_plugin_constants.h"
26 #include "content/common/browser_plugin/browser_plugin_messages.h" 23 #include "content/common/browser_plugin/browser_plugin_messages.h"
27 #include "content/common/content_constants_internal.h" 24 #include "content/common/content_constants_internal.h"
28 #include "content/common/drag_messages.h" 25 #include "content/common/drag_messages.h"
29 #include "content/common/input_messages.h" 26 #include "content/common/input_messages.h"
30 #include "content/common/view_messages.h" 27 #include "content/common/view_messages.h"
31 #include "content/public/browser/browser_context.h" 28 #include "content/public/browser/browser_context.h"
32 #include "content/public/browser/browser_plugin_guest_manager.h" 29 #include "content/public/browser/browser_plugin_guest_manager.h"
33 #include "content/public/browser/content_browser_client.h" 30 #include "content/public/browser/content_browser_client.h"
34 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/render_widget_host_view.h" 31 #include "content/public/browser/render_widget_host_view.h"
36 #include "content/public/browser/user_metrics.h" 32 #include "content/public/browser/user_metrics.h"
37 #include "content/public/browser/web_contents_observer.h" 33 #include "content/public/browser/web_contents_observer.h"
38 #include "content/public/common/context_menu_params.h"
39 #include "content/public/common/drop_data.h" 34 #include "content/public/common/drop_data.h"
40 #include "content/public/common/media_stream_request.h"
41 #include "content/public/common/result_codes.h"
42 #include "content/public/common/url_constants.h"
43 #include "content/public/common/url_utils.h"
44 #include "net/url_request/url_request.h"
45 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 35 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
46 #include "ui/events/keycodes/keyboard_codes.h"
47 #include "webkit/common/resource_type.h"
48 36
49 #if defined(OS_MACOSX) 37 #if defined(OS_MACOSX)
50 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" 38 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h"
51 #endif 39 #endif
52 40
53 namespace content { 41 namespace content {
54 42
55 // static 43 // static
56 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; 44 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL;
57 45
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 auto_size_enabled_(false), 94 auto_size_enabled_(false),
107 copy_request_id_(0), 95 copy_request_id_(0),
108 has_render_view_(has_render_view), 96 has_render_view_(has_render_view),
109 last_seen_auto_size_enabled_(false), 97 last_seen_auto_size_enabled_(false),
110 is_in_destruction_(false), 98 is_in_destruction_(false),
111 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 99 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
112 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 100 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
113 last_can_compose_inline_(true), 101 last_can_compose_inline_(true),
114 weak_ptr_factory_(this) { 102 weak_ptr_factory_(this) {
115 DCHECK(web_contents); 103 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 } 104 }
130 105
131 void BrowserPluginGuest::WillDestroy(WebContents* web_contents) { 106 void BrowserPluginGuest::WillDestroy(WebContents* web_contents) {
132 DCHECK_EQ(web_contents, GetWebContents()); 107 DCHECK_EQ(web_contents, GetWebContents());
133 is_in_destruction_ = true; 108 is_in_destruction_ = true;
134 } 109 }
135 110
136 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 111 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
137 return weak_ptr_factory_.GetWeakPtr(); 112 return weak_ptr_factory_.GetWeakPtr();
138 } 113 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 gfx::Rect guest_rect(bounds); 336 gfx::Rect guest_rect(bounds);
362 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); 337 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin());
363 return guest_rect; 338 return guest_rect;
364 } 339 }
365 340
366 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { 341 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) {
367 embedder_visible_ = visible; 342 embedder_visible_ = visible;
368 UpdateVisibility(); 343 UpdateVisibility();
369 } 344 }
370 345
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) { 346 void BrowserPluginGuest::SetZoom(double zoom_factor) {
442 if (delegate_) 347 if (delegate_)
443 delegate_->SetZoom(zoom_factor); 348 delegate_->SetZoom(zoom_factor);
444 } 349 }
445 350
446 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { 351 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) {
447 SendMessageToEmbedder( 352 SendMessageToEmbedder(
448 new BrowserPluginMsg_SetMouseLock(instance_id(), allow)); 353 new BrowserPluginMsg_SetMouseLock(instance_id(), allow));
449 } 354 }
450 355
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 { 356 WebContentsImpl* BrowserPluginGuest::GetWebContents() const {
516 return static_cast<WebContentsImpl*>(web_contents()); 357 return static_cast<WebContentsImpl*>(web_contents());
517 } 358 }
518 359
519 gfx::Point BrowserPluginGuest::GetScreenCoordinates( 360 gfx::Point BrowserPluginGuest::GetScreenCoordinates(
520 const gfx::Point& relative_position) const { 361 const gfx::Point& relative_position) const {
521 gfx::Point screen_pos(relative_position); 362 gfx::Point screen_pos(relative_position);
522 screen_pos += guest_window_rect_.OffsetFromOrigin(); 363 screen_pos += guest_window_rect_.OffsetFromOrigin();
523 return screen_pos; 364 return screen_pos;
524 } 365 }
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 void BrowserPluginGuest::OnShowWidget(int route_id, 908 void BrowserPluginGuest::OnShowWidget(int route_id,
1068 const gfx::Rect& initial_pos) { 909 const gfx::Rect& initial_pos) {
1069 GetWebContents()->ShowCreatedWidget(route_id, initial_pos); 910 GetWebContents()->ShowCreatedWidget(route_id, initial_pos);
1070 } 911 }
1071 912
1072 void BrowserPluginGuest::OnTakeFocus(bool reverse) { 913 void BrowserPluginGuest::OnTakeFocus(bool reverse) {
1073 SendMessageToEmbedder( 914 SendMessageToEmbedder(
1074 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); 915 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse));
1075 } 916 }
1076 917
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( 918 void BrowserPluginGuest::OnUpdateRect(
1100 const ViewHostMsg_UpdateRect_Params& params) { 919 const ViewHostMsg_UpdateRect_Params& params) {
1101 BrowserPluginMsg_UpdateRect_Params relay_params; 920 BrowserPluginMsg_UpdateRect_Params relay_params;
1102 relay_params.view_size = params.view_size; 921 relay_params.view_size = params.view_size;
1103 relay_params.scale_factor = params.scale_factor; 922 relay_params.scale_factor = params.scale_factor;
1104 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( 923 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
1105 params.flags); 924 params.flags);
1106 925
1107 bool size_changed = last_seen_view_size_ != params.view_size; 926 bool size_changed = last_seen_view_size_ != params.view_size;
1108 gfx::Size old_size = last_seen_view_size_; 927 gfx::Size old_size = last_seen_view_size_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 void BrowserPluginGuest::OnImeCompositionRangeChanged( 959 void BrowserPluginGuest::OnImeCompositionRangeChanged(
1141 const gfx::Range& range, 960 const gfx::Range& range,
1142 const std::vector<gfx::Rect>& character_bounds) { 961 const std::vector<gfx::Rect>& character_bounds) {
1143 static_cast<RenderWidgetHostViewBase*>( 962 static_cast<RenderWidgetHostViewBase*>(
1144 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 963 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
1145 range, character_bounds); 964 range, character_bounds);
1146 } 965 }
1147 #endif 966 #endif
1148 967
1149 } // namespace content 968 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698