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

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: Rebasing... 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (!guest_proxy_render_view) 229 if (!guest_proxy_render_view)
230 return; 230 return;
231 blink::WebFrame* guest_proxy_frame = 231 blink::WebFrame* guest_proxy_frame =
232 guest_proxy_render_view->GetWebView()->MainFrame(); 232 guest_proxy_render_view->GetWebView()->MainFrame();
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 v8::Local<v8::Object> guest_proxy_window = guest_proxy_frame->GlobalProxy();
240 // on top of out-of-process iframes. Remove it once the code is converted.
241 v8::Local<v8::Object> guest_proxy_window;
242 if (guest_proxy_frame->IsWebLocalFrame()) {
243 guest_proxy_window = guest_proxy_frame->MainWorldScriptContext()->Global();
244 } else {
245 guest_proxy_window = guest_proxy_frame->ToWebRemoteFrame()->GlobalProxy();
246 }
247 gin::Dictionary window_object(isolate, guest_proxy_window); 240 gin::Dictionary window_object(isolate, guest_proxy_window);
248 v8::Local<v8::Function> post_message; 241 v8::Local<v8::Function> post_message;
249 if (!window_object.Get(std::string(kPostMessageName), &post_message)) 242 if (!window_object.Get(std::string(kPostMessageName), &post_message))
250 return; 243 return;
251 244
252 v8::Local<v8::Value> args[] = { 245 v8::Local<v8::Value> args[] = {
253 message, 246 message,
254 // Post the message to any domain inside the browser plugin. The embedder 247 // Post the message to any domain inside the browser plugin. The embedder
255 // should already know what is embedded. 248 // should already know what is embedded.
256 gin::StringToV8(isolate, "*")}; 249 gin::StringToV8(isolate, "*")};
257 render_frame()->GetWebFrame()->CallFunctionEvenIfScriptDisabled( 250 render_frame()->GetWebFrame()->CallFunctionEvenIfScriptDisabled(
258 post_message.As<v8::Function>(), guest_proxy_window, arraysize(args), 251 post_message.As<v8::Function>(), guest_proxy_window, arraysize(args),
259 args); 252 args);
260 } 253 }
261 254
262 void MimeHandlerViewContainer::PostMessageFromValue( 255 void MimeHandlerViewContainer::PostMessageFromValue(
263 const base::Value& message) { 256 const base::Value& message) {
264 blink::WebFrame* frame = render_frame()->GetWebFrame(); 257 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
265 if (!frame) 258 if (!frame)
266 return; 259 return;
267 260
268 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 261 v8::Isolate* isolate = v8::Isolate::GetCurrent();
269 v8::HandleScope handle_scope(isolate); 262 v8::HandleScope handle_scope(isolate);
270 v8::Context::Scope context_scope(frame->MainWorldScriptContext()); 263 v8::Context::Scope context_scope(frame->MainWorldScriptContext());
271 std::unique_ptr<content::V8ValueConverter> converter( 264 std::unique_ptr<content::V8ValueConverter> converter(
272 content::V8ValueConverter::create()); 265 content::V8ValueConverter::create());
273 PostMessage(isolate, 266 PostMessage(isolate,
274 converter->ToV8Value(&message, frame->MainWorldScriptContext())); 267 converter->ToV8Value(&message, frame->MainWorldScriptContext()));
(...skipping 20 matching lines...) Expand all
295 void MimeHandlerViewContainer::OnMimeHandlerViewGuestOnLoadCompleted( 288 void MimeHandlerViewContainer::OnMimeHandlerViewGuestOnLoadCompleted(
296 int /* unused */) { 289 int /* unused */) {
297 if (!render_frame()) 290 if (!render_frame())
298 return; 291 return;
299 292
300 guest_loaded_ = true; 293 guest_loaded_ = true;
301 if (pending_messages_.empty()) 294 if (pending_messages_.empty())
302 return; 295 return;
303 296
304 // Now that the guest has loaded, flush any unsent messages. 297 // Now that the guest has loaded, flush any unsent messages.
305 blink::WebFrame* frame = render_frame()->GetWebFrame(); 298 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
306 if (!frame) 299 if (!frame)
307 return; 300 return;
308 301
309 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 302 v8::Isolate* isolate = v8::Isolate::GetCurrent();
310 v8::HandleScope handle_scope(isolate); 303 v8::HandleScope handle_scope(isolate);
311 v8::Context::Scope context_scope(frame->MainWorldScriptContext()); 304 v8::Context::Scope context_scope(frame->MainWorldScriptContext());
312 for (const auto& pending_message : pending_messages_) 305 for (const auto& pending_message : pending_messages_)
313 PostMessage(isolate, v8::Local<v8::Value>::New(isolate, pending_message)); 306 PostMessage(isolate, v8::Local<v8::Value>::New(isolate, pending_message));
314 307
315 pending_messages_.clear(); 308 pending_messages_.clear();
(...skipping 11 matching lines...) Expand all
327 if (!render_frame()) 320 if (!render_frame())
328 return; 321 return;
329 322
330 render_frame()->Send( 323 render_frame()->Send(
331 new ExtensionsGuestViewHostMsg_CreateMimeHandlerViewGuest( 324 new ExtensionsGuestViewHostMsg_CreateMimeHandlerViewGuest(
332 render_frame()->GetRoutingID(), view_id_, element_instance_id(), 325 render_frame()->GetRoutingID(), view_id_, element_instance_id(),
333 element_size_)); 326 element_size_));
334 } 327 }
335 328
336 } // namespace extensions 329 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc ('k') | extensions/renderer/runtime_custom_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698