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

Side by Side Diff: extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc

Issue 2923053002: Move MainWorldScriptContext accessor/method from WebFrame to WebLocalFrame. (Closed)
Patch Set: . Created 3 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 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/mime_handler_view/mime_handler_view_con tainer.h" 5 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_con tainer.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 if (!guest_proxy_frame) 233 if (!guest_proxy_frame)
234 return; 234 return;
235 235
236 v8::Context::Scope context_scope( 236 v8::Context::Scope context_scope(
237 render_frame()->GetWebFrame()->MainWorldScriptContext()); 237 render_frame()->GetWebFrame()->MainWorldScriptContext());
238 238
239 // TODO(lazyboy,nasko): The WebLocalFrame branch is not used when running 239 // TODO(lazyboy,nasko): The WebLocalFrame branch is not used when running
240 // on top of out-of-process iframes. Remove it once the code is converted. 240 // on top of out-of-process iframes. Remove it once the code is converted.
241 v8::Local<v8::Object> guest_proxy_window; 241 v8::Local<v8::Object> guest_proxy_window;
242 if (guest_proxy_frame->IsWebLocalFrame()) { 242 if (guest_proxy_frame->IsWebLocalFrame()) {
243 guest_proxy_window = guest_proxy_frame->MainWorldScriptContext()->Global(); 243 guest_proxy_window = guest_proxy_frame->ToWebLocalFrame()
244 ->MainWorldScriptContext()
245 ->Global();
244 } else { 246 } else {
245 guest_proxy_window = guest_proxy_frame->ToWebRemoteFrame()->GlobalProxy(); 247 guest_proxy_window = guest_proxy_frame->ToWebRemoteFrame()->GlobalProxy();
dcheng 2017/06/06 19:57:17 Since it would be used here (and a couple other pl
246 } 248 }
247 gin::Dictionary window_object(isolate, guest_proxy_window); 249 gin::Dictionary window_object(isolate, guest_proxy_window);
248 v8::Local<v8::Function> post_message; 250 v8::Local<v8::Function> post_message;
249 if (!window_object.Get(std::string(kPostMessageName), &post_message)) 251 if (!window_object.Get(std::string(kPostMessageName), &post_message))
250 return; 252 return;
251 253
252 v8::Local<v8::Value> args[] = { 254 v8::Local<v8::Value> args[] = {
253 message, 255 message,
254 // Post the message to any domain inside the browser plugin. The embedder 256 // Post the message to any domain inside the browser plugin. The embedder
255 // should already know what is embedded. 257 // should already know what is embedded.
256 gin::StringToV8(isolate, "*")}; 258 gin::StringToV8(isolate, "*")};
257 render_frame()->GetWebFrame()->CallFunctionEvenIfScriptDisabled( 259 render_frame()->GetWebFrame()->CallFunctionEvenIfScriptDisabled(
258 post_message.As<v8::Function>(), guest_proxy_window, arraysize(args), 260 post_message.As<v8::Function>(), guest_proxy_window, arraysize(args),
259 args); 261 args);
260 } 262 }
261 263
262 void MimeHandlerViewContainer::PostMessageFromValue( 264 void MimeHandlerViewContainer::PostMessageFromValue(
263 const base::Value& message) { 265 const base::Value& message) {
264 blink::WebFrame* frame = render_frame()->GetWebFrame(); 266 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
265 if (!frame) 267 if (!frame)
266 return; 268 return;
267 269
268 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 270 v8::Isolate* isolate = v8::Isolate::GetCurrent();
269 v8::HandleScope handle_scope(isolate); 271 v8::HandleScope handle_scope(isolate);
270 v8::Context::Scope context_scope(frame->MainWorldScriptContext()); 272 v8::Context::Scope context_scope(frame->MainWorldScriptContext());
271 std::unique_ptr<content::V8ValueConverter> converter( 273 std::unique_ptr<content::V8ValueConverter> converter(
272 content::V8ValueConverter::create()); 274 content::V8ValueConverter::create());
273 PostMessage(isolate, 275 PostMessage(isolate,
274 converter->ToV8Value(&message, frame->MainWorldScriptContext())); 276 converter->ToV8Value(&message, frame->MainWorldScriptContext()));
(...skipping 20 matching lines...) Expand all
295 void MimeHandlerViewContainer::OnMimeHandlerViewGuestOnLoadCompleted( 297 void MimeHandlerViewContainer::OnMimeHandlerViewGuestOnLoadCompleted(
296 int /* unused */) { 298 int /* unused */) {
297 if (!render_frame()) 299 if (!render_frame())
298 return; 300 return;
299 301
300 guest_loaded_ = true; 302 guest_loaded_ = true;
301 if (pending_messages_.empty()) 303 if (pending_messages_.empty())
302 return; 304 return;
303 305
304 // Now that the guest has loaded, flush any unsent messages. 306 // Now that the guest has loaded, flush any unsent messages.
305 blink::WebFrame* frame = render_frame()->GetWebFrame(); 307 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
306 if (!frame) 308 if (!frame)
307 return; 309 return;
308 310
309 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 311 v8::Isolate* isolate = v8::Isolate::GetCurrent();
310 v8::HandleScope handle_scope(isolate); 312 v8::HandleScope handle_scope(isolate);
311 v8::Context::Scope context_scope(frame->MainWorldScriptContext()); 313 v8::Context::Scope context_scope(frame->MainWorldScriptContext());
312 for (const auto& pending_message : pending_messages_) 314 for (const auto& pending_message : pending_messages_)
313 PostMessage(isolate, v8::Local<v8::Value>::New(isolate, pending_message)); 315 PostMessage(isolate, v8::Local<v8::Value>::New(isolate, pending_message));
314 316
315 pending_messages_.clear(); 317 pending_messages_.clear();
(...skipping 11 matching lines...) Expand all
327 if (!render_frame()) 329 if (!render_frame())
328 return; 330 return;
329 331
330 render_frame()->Send( 332 render_frame()->Send(
331 new ExtensionsGuestViewHostMsg_CreateMimeHandlerViewGuest( 333 new ExtensionsGuestViewHostMsg_CreateMimeHandlerViewGuest(
332 render_frame()->GetRoutingID(), view_id_, element_instance_id(), 334 render_frame()->GetRoutingID(), view_id_, element_instance_id(),
333 element_size_)); 335 element_size_));
334 } 336 }
335 337
336 } // namespace extensions 338 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698