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

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

Issue 306003002: Move guest lifetime management to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 25 matching lines...) Expand all
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
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;
109 } 101 }
110 102
111 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 103 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
112 return weak_ptr_factory_.GetWeakPtr(); 104 return weak_ptr_factory_.GetWeakPtr();
113 } 105 }
114 106
115 bool BrowserPluginGuest::LockMouse(bool allowed) { 107 bool BrowserPluginGuest::LockMouse(bool allowed) {
116 if (!attached() || (mouse_locked_ == allowed)) 108 if (!attached() || (mouse_locked_ == allowed))
117 return false; 109 return false;
118 110
119 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); 111 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed);
120 } 112 }
121 113
122 void BrowserPluginGuest::EmbedderDestroyed() {
123 embedder_web_contents_ = NULL;
124 if (delegate_)
125 delegate_->EmbedderDestroyed();
126 Destroy();
127 }
128
129 void BrowserPluginGuest::Destroy() { 114 void BrowserPluginGuest::Destroy() {
130 if (!delegate_) 115 if (!delegate_)
131 return; 116 return;
132 delegate_->Destroy(); 117 delegate_->Destroy();
133 } 118 }
134 119
135 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( 120 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
136 const IPC::Message& message) { 121 const IPC::Message& message) {
137 bool handled = true; 122 bool handled = true;
138 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 123 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 instance_id, 279 instance_id,
295 guest_site_instance, 280 guest_site_instance,
296 web_contents, 281 web_contents,
297 opener_web_contents, 282 opener_web_contents,
298 &delegate, 283 &delegate,
299 extra_params.Pass()); 284 extra_params.Pass());
300 if (delegate) { 285 if (delegate) {
301 delegate->RegisterDestructionCallback( 286 delegate->RegisterDestructionCallback(
302 base::Bind(&BrowserPluginGuest::WillDestroy, 287 base::Bind(&BrowserPluginGuest::WillDestroy,
303 base::Unretained(guest))); 288 base::Unretained(guest)));
304 guest->SetDelegate(delegate); 289 guest->set_delegate(delegate);
305 } 290 }
306 return guest; 291 return guest;
307 } 292 }
308 293
309 // static 294 // static
310 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { 295 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) {
311 return web_contents && web_contents->GetBrowserPluginGuest(); 296 return web_contents && web_contents->GetBrowserPluginGuest();
312 } 297 }
313 298
314 // static 299 // static
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 385 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
401 screen_x, screen_y, operation); 386 screen_x, screen_y, operation);
402 } 387 }
403 388
404 void BrowserPluginGuest::EndSystemDrag() { 389 void BrowserPluginGuest::EndSystemDrag() {
405 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 390 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
406 GetWebContents()->GetRenderViewHost()); 391 GetWebContents()->GetRenderViewHost());
407 guest_rvh->DragSourceSystemDragEnded(); 392 guest_rvh->DragSourceSystemDragEnded();
408 } 393 }
409 394
410 void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) {
411 DCHECK(!delegate_);
412 delegate_.reset(delegate);
413 }
414
415 void BrowserPluginGuest::SendQueuedMessages() { 395 void BrowserPluginGuest::SendQueuedMessages() {
416 if (!attached()) 396 if (!attached())
417 return; 397 return;
418 398
419 while (!pending_messages_.empty()) { 399 while (!pending_messages_.empty()) {
420 IPC::Message* message = pending_messages_.front(); 400 IPC::Message* message = pending_messages_.front();
421 pending_messages_.pop(); 401 pending_messages_.pop();
422 SendMessageToEmbedder(message); 402 SendMessageToEmbedder(message);
423 } 403 }
424 } 404 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 void BrowserPluginGuest::OnImeCompositionRangeChanged( 949 void BrowserPluginGuest::OnImeCompositionRangeChanged(
970 const gfx::Range& range, 950 const gfx::Range& range,
971 const std::vector<gfx::Rect>& character_bounds) { 951 const std::vector<gfx::Rect>& character_bounds) {
972 static_cast<RenderWidgetHostViewBase*>( 952 static_cast<RenderWidgetHostViewBase*>(
973 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 953 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
974 range, character_bounds); 954 range, character_bounds);
975 } 955 }
976 #endif 956 #endif
977 957
978 } // namespace content 958 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698