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

Side by Side Diff: extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc

Issue 2695633008: Re-check existence of GuestViewContainer before requesting attach. (Closed)
Patch Set: Add checks for RenderFrame in AttachIFrameGuest. Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h" 5 #include "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // Add flag to |params| to indicate that the element size is specified in 159 // Add flag to |params| to indicate that the element size is specified in
160 // logical units. 160 // logical units.
161 params->SetBoolean(guest_view::kElementSizeIsLogical, true); 161 params->SetBoolean(guest_view::kElementSizeIsLogical, true);
162 162
163 std::unique_ptr<guest_view::GuestViewRequest> request( 163 std::unique_ptr<guest_view::GuestViewRequest> request(
164 new guest_view::GuestViewAttachRequest( 164 new guest_view::GuestViewAttachRequest(
165 guest_view_container, guest_instance_id, std::move(params), 165 guest_view_container, guest_instance_id, std::move(params),
166 args.Length() == 4 ? args[3].As<v8::Function>() 166 args.Length() == 4 ? args[3].As<v8::Function>()
167 : v8::Local<v8::Function>(), 167 : v8::Local<v8::Function>(),
168 args.GetIsolate())); 168 args.GetIsolate()));
169
170 // We should be careful that some malicious JS in the GuestView's embedder
171 // hasn't destroyed |guest_view_container| during the enumeration of the
172 // properties of the guest's object during extraction of |params| above
173 // (see https://crbug.com/683523).
174 // TODO(wjmaclean): Evaluate if it's possible for malicious JS to *change*
175 // the |guest_view_container| ... we guard against that below, but a simple
176 // null check might suffice.
177 // TODO(wjmaclean): Evaluate if it's worth removing the early-out above
178 // and just do it here.
179 if (guest_view_container !=
180 guest_view::GuestViewContainer::FromID(element_instance_id)) {
lfg 2017/02/16 20:00:58 GuestViewContainer already has a weak ptr factory,
wjmaclean 2017/02/16 21:26:16 Done.
181 return;
182 }
169 guest_view_container->IssueRequest(std::move(request)); 183 guest_view_container->IssueRequest(std::move(request));
170 184
171 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); 185 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
172 } 186 }
173 187
174 void GuestViewInternalCustomBindings::DetachGuest( 188 void GuestViewInternalCustomBindings::DetachGuest(
175 const v8::FunctionCallbackInfo<v8::Value>& args) { 189 const v8::FunctionCallbackInfo<v8::Value>& args) {
176 // Allow for an optional callback parameter. 190 // Allow for an optional callback parameter.
177 CHECK(args.Length() >= 1 && args.Length() <= 2); 191 CHECK(args.Length() >= 1 && args.Length() <= 2);
178 // Element Instance ID. 192 // Element Instance ID.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 converter->FromV8Value(args[2], context()->v8_context())); 242 converter->FromV8Value(args[2], context()->v8_context()));
229 params = base::DictionaryValue::From(std::move(params_as_value)); 243 params = base::DictionaryValue::From(std::move(params_as_value));
230 CHECK(params); 244 CHECK(params);
231 } 245 }
232 246
233 // Add flag to |params| to indicate that the element size is specified in 247 // Add flag to |params| to indicate that the element size is specified in
234 // logical units. 248 // logical units.
235 params->SetBoolean(guest_view::kElementSizeIsLogical, true); 249 params->SetBoolean(guest_view::kElementSizeIsLogical, true);
236 250
237 content::RenderFrame* render_frame = GetRenderFrame(args[3]); 251 content::RenderFrame* render_frame = GetRenderFrame(args[3]);
252 // It's possible that code executed during the |params| enumeration above
lfg 2017/02/16 20:00:58 Can we use the same approach as above: Get the Ren
wjmaclean 2017/02/16 21:26:16 How about if we grab the parent_frame WebLocalFram
lfg 2017/02/16 22:09:14 I think this is fine, the WebFrame may be closed w
253 // could delete the guest view's RenderFrame, so we shouldn't blindly assume
254 // it still exists.
255 if (!render_frame)
256 return;
257
238 blink::WebLocalFrame* frame = render_frame->GetWebFrame(); 258 blink::WebLocalFrame* frame = render_frame->GetWebFrame();
239 259
240 // Parent must exist. 260 // Parent must exist.
261 // TODO(wjmaclean): Reviewers ... can you confirm that as long as the
262 // GuestView object's RenderFrame exists, that it will have a local parent?
lfg 2017/02/16 20:00:57 The frame comes from getIframeContentWindow in jav
wjmaclean 2017/02/16 21:26:16 Acknowledged.
241 blink::WebFrame* parent_frame = frame->parent(); 263 blink::WebFrame* parent_frame = frame->parent();
242 DCHECK(parent_frame); 264 DCHECK(parent_frame);
243 DCHECK(parent_frame->isWebLocalFrame()); 265 DCHECK(parent_frame->isWebLocalFrame());
244 266
245 content::RenderFrame* embedder_parent_frame = 267 content::RenderFrame* embedder_parent_frame =
246 content::RenderFrame::FromWebFrame(parent_frame); 268 content::RenderFrame::FromWebFrame(parent_frame);
247 269
248 // Create a GuestViewContainer if it does not exist. 270 // Create a GuestViewContainer if it does not exist.
249 // An element instance ID uniquely identifies an IframeGuestViewContainer 271 // An element instance ID uniquely identifies an IframeGuestViewContainer
250 // within a RenderView. 272 // within a RenderView.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // EnterFullscreen() and do it directly rather than having a generic "run with 453 // EnterFullscreen() and do it directly rather than having a generic "run with
432 // user gesture" function. 454 // user gesture" function.
433 blink::WebScopedUserGesture user_gesture(context()->web_frame()); 455 blink::WebScopedUserGesture user_gesture(context()->web_frame());
434 CHECK_EQ(args.Length(), 1); 456 CHECK_EQ(args.Length(), 1);
435 CHECK(args[0]->IsFunction()); 457 CHECK(args[0]->IsFunction());
436 context()->SafeCallFunction( 458 context()->SafeCallFunction(
437 v8::Local<v8::Function>::Cast(args[0]), 0, nullptr); 459 v8::Local<v8::Function>::Cast(args[0]), 0, nullptr);
438 } 460 }
439 461
440 } // namespace extensions 462 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698