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/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #if defined(OS_MACOSX) | 37 #if defined(OS_MACOSX) |
38 #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" |
39 #endif | 39 #endif |
40 | 40 |
41 namespace content { | 41 namespace content { |
42 | 42 |
43 // static | 43 // static |
44 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 44 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
45 | 45 |
46 namespace { | |
47 | |
48 } // namespace | |
49 | |
50 class BrowserPluginGuest::EmbedderWebContentsObserver | 46 class BrowserPluginGuest::EmbedderWebContentsObserver |
51 : public WebContentsObserver { | 47 : public WebContentsObserver { |
52 public: | 48 public: |
53 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) | 49 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) |
54 : WebContentsObserver(guest->embedder_web_contents()), | 50 : WebContentsObserver(guest->embedder_web_contents()), |
55 browser_plugin_guest_(guest) { | 51 browser_plugin_guest_(guest) { |
56 } | 52 } |
57 | 53 |
58 virtual ~EmbedderWebContentsObserver() { | 54 virtual ~EmbedderWebContentsObserver() { |
59 } | 55 } |
60 | 56 |
61 // WebContentsObserver: | 57 // WebContentsObserver implementation. |
62 virtual void WebContentsDestroyed() OVERRIDE { | |
63 browser_plugin_guest_->EmbedderDestroyed(); | |
64 } | |
65 | |
66 virtual void WasShown() OVERRIDE { | 58 virtual void WasShown() OVERRIDE { |
67 browser_plugin_guest_->EmbedderVisibilityChanged(true); | 59 browser_plugin_guest_->EmbedderVisibilityChanged(true); |
68 } | 60 } |
69 | 61 |
70 virtual void WasHidden() OVERRIDE { | 62 virtual void WasHidden() OVERRIDE { |
71 browser_plugin_guest_->EmbedderVisibilityChanged(false); | 63 browser_plugin_guest_->EmbedderVisibilityChanged(false); |
72 } | 64 } |
73 | 65 |
74 private: | 66 private: |
75 BrowserPluginGuest* browser_plugin_guest_; | 67 BrowserPluginGuest* browser_plugin_guest_; |
(...skipping 16 matching lines...) Expand all Loading... |
92 guest_opaque_(true), | 84 guest_opaque_(true), |
93 embedder_visible_(true), | 85 embedder_visible_(true), |
94 auto_size_enabled_(false), | 86 auto_size_enabled_(false), |
95 copy_request_id_(0), | 87 copy_request_id_(0), |
96 has_render_view_(has_render_view), | 88 has_render_view_(has_render_view), |
97 last_seen_auto_size_enabled_(false), | 89 last_seen_auto_size_enabled_(false), |
98 is_in_destruction_(false), | 90 is_in_destruction_(false), |
99 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 91 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
100 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 92 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
101 last_can_compose_inline_(true), | 93 last_can_compose_inline_(true), |
| 94 delegate_(NULL), |
102 weak_ptr_factory_(this) { | 95 weak_ptr_factory_(this) { |
103 DCHECK(web_contents); | 96 DCHECK(web_contents); |
104 } | 97 } |
105 | 98 |
106 void BrowserPluginGuest::WillDestroy(WebContents* web_contents) { | 99 void BrowserPluginGuest::WillDestroy() { |
107 DCHECK_EQ(web_contents, GetWebContents()); | |
108 is_in_destruction_ = true; | 100 is_in_destruction_ = true; |
| 101 embedder_web_contents_ = NULL; |
| 102 delegate_ = NULL; |
109 } | 103 } |
110 | 104 |
111 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { | 105 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
112 return weak_ptr_factory_.GetWeakPtr(); | 106 return weak_ptr_factory_.GetWeakPtr(); |
113 } | 107 } |
114 | 108 |
115 bool BrowserPluginGuest::LockMouse(bool allowed) { | 109 bool BrowserPluginGuest::LockMouse(bool allowed) { |
116 if (!attached() || (mouse_locked_ == allowed)) | 110 if (!attached() || (mouse_locked_ == allowed)) |
117 return false; | 111 return false; |
118 | 112 |
119 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); | 113 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); |
120 } | 114 } |
121 | 115 |
122 void BrowserPluginGuest::EmbedderDestroyed() { | |
123 embedder_web_contents_ = NULL; | |
124 if (delegate_) | |
125 delegate_->EmbedderDestroyed(); | |
126 Destroy(); | |
127 } | |
128 | |
129 void BrowserPluginGuest::Destroy() { | 116 void BrowserPluginGuest::Destroy() { |
130 if (!delegate_) | 117 if (!delegate_) |
131 return; | 118 return; |
132 delegate_->Destroy(); | 119 delegate_->Destroy(); |
133 } | 120 } |
134 | 121 |
135 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 122 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
136 const IPC::Message& message) { | 123 const IPC::Message& message) { |
137 bool handled = true; | 124 bool handled = true; |
138 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 125 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 instance_id, | 281 instance_id, |
295 guest_site_instance, | 282 guest_site_instance, |
296 web_contents, | 283 web_contents, |
297 opener_web_contents, | 284 opener_web_contents, |
298 &delegate, | 285 &delegate, |
299 extra_params.Pass()); | 286 extra_params.Pass()); |
300 if (delegate) { | 287 if (delegate) { |
301 delegate->RegisterDestructionCallback( | 288 delegate->RegisterDestructionCallback( |
302 base::Bind(&BrowserPluginGuest::WillDestroy, | 289 base::Bind(&BrowserPluginGuest::WillDestroy, |
303 base::Unretained(guest))); | 290 base::Unretained(guest))); |
304 guest->SetDelegate(delegate); | 291 guest->set_delegate(delegate); |
305 } | 292 } |
306 return guest; | 293 return guest; |
307 } | 294 } |
308 | 295 |
309 // static | 296 // static |
310 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { | 297 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { |
311 return web_contents && web_contents->GetBrowserPluginGuest(); | 298 return web_contents && web_contents->GetBrowserPluginGuest(); |
312 } | 299 } |
313 | 300 |
314 // static | 301 // static |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, | 387 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
401 screen_x, screen_y, operation); | 388 screen_x, screen_y, operation); |
402 } | 389 } |
403 | 390 |
404 void BrowserPluginGuest::EndSystemDrag() { | 391 void BrowserPluginGuest::EndSystemDrag() { |
405 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 392 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
406 GetWebContents()->GetRenderViewHost()); | 393 GetWebContents()->GetRenderViewHost()); |
407 guest_rvh->DragSourceSystemDragEnded(); | 394 guest_rvh->DragSourceSystemDragEnded(); |
408 } | 395 } |
409 | 396 |
410 void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) { | |
411 DCHECK(!delegate_); | |
412 delegate_.reset(delegate); | |
413 } | |
414 | |
415 void BrowserPluginGuest::SendQueuedMessages() { | 397 void BrowserPluginGuest::SendQueuedMessages() { |
416 if (!attached()) | 398 if (!attached()) |
417 return; | 399 return; |
418 | 400 |
419 while (!pending_messages_.empty()) { | 401 while (!pending_messages_.empty()) { |
420 IPC::Message* message = pending_messages_.front(); | 402 IPC::Message* message = pending_messages_.front(); |
421 pending_messages_.pop(); | 403 pending_messages_.pop(); |
422 SendMessageToEmbedder(message); | 404 SendMessageToEmbedder(message); |
423 } | 405 } |
424 } | 406 } |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 951 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
970 const gfx::Range& range, | 952 const gfx::Range& range, |
971 const std::vector<gfx::Rect>& character_bounds) { | 953 const std::vector<gfx::Rect>& character_bounds) { |
972 static_cast<RenderWidgetHostViewBase*>( | 954 static_cast<RenderWidgetHostViewBase*>( |
973 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 955 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
974 range, character_bounds); | 956 range, character_bounds); |
975 } | 957 } |
976 #endif | 958 #endif |
977 | 959 |
978 } // namespace content | 960 } // namespace content |
OLD | NEW |