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

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

Issue 258373002: Towards moving guest management to chrome: Introduce GuestViewManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT 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_embedder.h" 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "content/browser/browser_plugin/browser_plugin_guest.h" 8 #include "content/browser/browser_plugin/browser_plugin_guest.h"
9 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" 9 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
25 #include "net/base/escape.h" 25 #include "net/base/escape.h"
26 #include "ui/events/keycodes/keyboard_codes.h" 26 #include "ui/events/keycodes/keyboard_codes.h"
27 27
28 namespace content { 28 namespace content {
29 29
30 // static 30 // static
31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; 31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL;
32 32
33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) 33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents)
34 : WebContentsObserver(web_contents) { 34 : WebContentsObserver(web_contents),
35 weak_ptr_factory_(this) {
35 } 36 }
36 37
37 BrowserPluginEmbedder::~BrowserPluginEmbedder() { 38 BrowserPluginEmbedder::~BrowserPluginEmbedder() {
38 } 39 }
39 40
40 // static 41 // static
41 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( 42 BrowserPluginEmbedder* BrowserPluginEmbedder::Create(
42 WebContentsImpl* web_contents) { 43 WebContentsImpl* web_contents) {
43 if (factory_) 44 if (factory_)
44 return factory_->CreateBrowserPluginEmbedder(web_contents); 45 return factory_->CreateBrowserPluginEmbedder(web_contents);
(...skipping 13 matching lines...) Expand all
58 } 59 }
59 60
60 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { 61 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) {
61 guest_started_drag_ = guest->AsWeakPtr(); 62 guest_started_drag_ = guest->AsWeakPtr();
62 } 63 }
63 64
64 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() { 65 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() {
65 return static_cast<WebContentsImpl*>(web_contents()); 66 return static_cast<WebContentsImpl*>(web_contents());
66 } 67 }
67 68
69 void BrowserPluginEmbedder::AllocateInstanceIDResponse(int request_id,
lazyboy 2014/05/01 20:06:59 SendAllocateInstanceIDResponse
Fady Samuel 2014/05/01 21:05:28 I removed this entirely.
70 int instance_id) {
71 Send(new BrowserPluginMsg_AllocateInstanceID_ACK(
72 routing_id(), request_id, instance_id));
73 }
74
68 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( 75 bool BrowserPluginEmbedder::DidSendScreenRectsCallback(
69 BrowserPluginGuest* guest) { 76 BrowserPluginGuest* guest) {
70 static_cast<RenderViewHostImpl*>( 77 static_cast<RenderViewHostImpl*>(
71 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); 78 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects();
72 // Not handled => Iterate over all guests. 79 // Not handled => Iterate over all guests.
73 return false; 80 return false;
74 } 81 }
75 82
76 void BrowserPluginEmbedder::DidSendScreenRects() { 83 void BrowserPluginEmbedder::DidSendScreenRects() {
77 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( 84 BrowserPluginGuestManager::FromBrowserContext(
lazyboy 2014/05/01 20:06:59 Can we keep GetBrowserPluginGuestManager() functio
Fady Samuel 2014/05/01 21:05:28 Done.
78 &BrowserPluginEmbedder::DidSendScreenRectsCallback, 85 GetWebContents()->GetBrowserContext())->ForEachGuest(
79 base::Unretained(this))); 86 GetWebContents(), base::Bind(
87 &BrowserPluginEmbedder::DidSendScreenRectsCallback,
88 base::Unretained(this)));
80 } 89 }
81 90
82 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( 91 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback(
83 const NativeWebKeyboardEvent& event, 92 const NativeWebKeyboardEvent& event,
84 BrowserPluginGuest* guest) { 93 BrowserPluginGuest* guest) {
85 return guest->UnlockMouseIfNecessary(event); 94 return guest->UnlockMouseIfNecessary(event);
86 } 95 }
87 96
88 bool BrowserPluginEmbedder::HandleKeyboardEvent( 97 bool BrowserPluginEmbedder::HandleKeyboardEvent(
89 const NativeWebKeyboardEvent& event) { 98 const NativeWebKeyboardEvent& event) {
90 if ((event.type != blink::WebInputEvent::RawKeyDown) || 99 if ((event.type != blink::WebInputEvent::RawKeyDown) ||
91 (event.windowsKeyCode != ui::VKEY_ESCAPE) || 100 (event.windowsKeyCode != ui::VKEY_ESCAPE) ||
92 (event.modifiers & blink::WebInputEvent::InputModifiers)) { 101 (event.modifiers & blink::WebInputEvent::InputModifiers)) {
93 return false; 102 return false;
94 } 103 }
95 104
96 return GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), 105 return BrowserPluginGuestManager::FromBrowserContext(
97 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, 106 GetWebContents()->GetBrowserContext())->ForEachGuest(
98 base::Unretained(this), 107 GetWebContents(),
99 event)); 108 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback,
109 base::Unretained(this),
110 event));
100 } 111 }
101 112
102 bool BrowserPluginEmbedder::SetZoomLevelCallback( 113 bool BrowserPluginEmbedder::SetZoomLevelCallback(
103 double level, BrowserPluginGuest* guest) { 114 double level, BrowserPluginGuest* guest) {
104 double zoom_factor = content::ZoomLevelToZoomFactor(level); 115 double zoom_factor = content::ZoomLevelToZoomFactor(level);
105 guest->SetZoom(zoom_factor); 116 guest->SetZoom(zoom_factor);
106 // Not handled => Iterate over all guests. 117 // Not handled => Iterate over all guests.
107 return false; 118 return false;
108 } 119 }
109 120
110 void BrowserPluginEmbedder::SetZoomLevel(double level) { 121 void BrowserPluginEmbedder::SetZoomLevel(double level) {
111 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( 122 BrowserPluginGuestManager::FromBrowserContext(
112 &BrowserPluginEmbedder::SetZoomLevelCallback, 123 GetWebContents()->GetBrowserContext())->ForEachGuest(
113 base::Unretained(this), 124 GetWebContents(), base::Bind(
114 level)); 125 &BrowserPluginEmbedder::SetZoomLevelCallback,
126 base::Unretained(this),
127 level));
115 } 128 }
116 129
117 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { 130 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) {
118 bool handled = true; 131 bool handled = true;
119 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) 132 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message)
120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, 133 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID,
121 OnAllocateInstanceID) 134 OnAllocateInstanceID)
122 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) 135 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach)
123 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, 136 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor,
124 OnUpdateDragCursor(&handled)); 137 OnUpdateDragCursor(&handled));
(...skipping 19 matching lines...) Expand all
144 if (guest_started_drag_.get()) 157 if (guest_started_drag_.get())
145 guest_started_drag_->EndSystemDrag(); 158 guest_started_drag_->EndSystemDrag();
146 guest_started_drag_.reset(); 159 guest_started_drag_.reset();
147 guest_dragging_over_.reset(); 160 guest_dragging_over_.reset();
148 } 161 }
149 162
150 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { 163 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) {
151 *handled = (guest_dragging_over_.get() != NULL); 164 *handled = (guest_dragging_over_.get() != NULL);
152 } 165 }
153 166
154 BrowserPluginGuestManager* 167 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id,
155 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { 168 const std::string& src) {
156 BrowserPluginGuestManager* guest_manager = 169 BrowserPluginGuestManager::FromBrowserContext(
157 GetWebContents()->GetBrowserPluginGuestManager(); 170 GetWebContents()->GetBrowserContext())->RequestInstanceID(
158 if (!guest_manager) { 171 src, base::Bind(&BrowserPluginEmbedder::AllocateInstanceIDResponse,
159 guest_manager = BrowserPluginGuestManager::Create(); 172 weak_ptr_factory_.GetWeakPtr(),
lazyboy 2014/05/01 20:06:59 indentation is off
Fady Samuel 2014/05/01 21:05:28 Done.
160 GetWebContents()->GetBrowserContext()->SetUserData( 173 request_id));
161 browser_plugin::kBrowserPluginGuestManagerKeyName, guest_manager);
162 }
163 return guest_manager;
164 }
165
166 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) {
167 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
168 Send(new BrowserPluginMsg_AllocateInstanceID_ACK(
169 routing_id(), request_id, instance_id));
170 } 174 }
171 175
172 void BrowserPluginEmbedder::OnAttach( 176 void BrowserPluginEmbedder::OnAttach(
173 int instance_id, 177 int instance_id,
174 const BrowserPluginHostMsg_Attach_Params& params, 178 const BrowserPluginHostMsg_Attach_Params& params,
175 const base::DictionaryValue& extra_params) { 179 const base::DictionaryValue& extra_params) {
176 if (!GetBrowserPluginGuestManager()->CanEmbedderAccessInstanceIDMaybeKill( 180 BrowserPluginGuestManager* guest_manager =
181 BrowserPluginGuestManager::FromBrowserContext(
182 GetWebContents()->GetBrowserContext());
183 if (!guest_manager->CanEmbedderAccessInstanceIDMaybeKill(
177 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id)) 184 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id))
178 return; 185 return;
179 186
180 BrowserPluginGuest* guest = 187 BrowserPluginGuest* guest =
181 GetBrowserPluginGuestManager()->GetGuestByInstanceID( 188 guest_manager->GetGuestByInstanceID(
182 instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); 189 instance_id, GetWebContents()->GetRenderProcessHost()->GetID());
183 190
184 if (guest) { 191 if (guest) {
185 // There is an implicit order expectation here: 192 // There is an implicit order expectation here:
186 // 1. The content embedder is made aware of the attachment. 193 // 1. The content embedder is made aware of the attachment.
187 // 2. BrowserPluginGuest::Attach is called. 194 // 2. BrowserPluginGuest::Attach is called.
188 // 3. The content embedder issues queued events if any that happened 195 // 3. The content embedder issues queued events if any that happened
189 // prior to attachment. 196 // prior to attachment.
190 GetContentClient()->browser()->GuestWebContentsAttached( 197 GetContentClient()->browser()->GuestWebContentsAttached(
191 guest->GetWebContents(), 198 guest->GetWebContents(),
192 GetWebContents(), 199 GetWebContents(),
193 extra_params); 200 extra_params);
194 guest->Attach(GetWebContents(), params, extra_params); 201 guest->Attach(GetWebContents(), params, extra_params);
195 return; 202 return;
196 } 203 }
197 204
198 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); 205 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy());
199 guest = GetBrowserPluginGuestManager()->CreateGuest( 206 guest = guest_manager->CreateGuest(
200 GetWebContents()->GetSiteInstance(), 207 GetWebContents()->GetSiteInstance(),
201 instance_id, params, 208 instance_id, params,
202 copy_extra_params.Pass()); 209 copy_extra_params.Pass());
203 if (guest) { 210 if (guest) {
204 GetContentClient()->browser()->GuestWebContentsAttached( 211 GetContentClient()->browser()->GuestWebContentsAttached(
205 guest->GetWebContents(), 212 guest->GetWebContents(),
206 GetWebContents(), 213 GetWebContents(),
207 extra_params); 214 extra_params);
208 guest->Initialize(params, GetWebContents()); 215 guest->Initialize(params, GetWebContents());
209 } 216 }
210 } 217 }
211 218
212 } // namespace content 219 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698