| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "apps/shell/renderer/shell_custom_bindings.h" | |
| 6 | |
| 7 #include "content/public/renderer/render_thread.h" | |
| 8 #include "content/public/renderer/render_view.h" | |
| 9 #include "content/public/renderer/v8_value_converter.h" | |
| 10 #include "extensions/common/extension_messages.h" | |
| 11 #include "extensions/renderer/script_context.h" | |
| 12 #include "extensions/renderer/script_context_set.h" | |
| 13 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 14 #include "third_party/WebKit/public/web/WebView.h" | |
| 15 #include "v8/include/v8.h" | |
| 16 | |
| 17 namespace apps { | |
| 18 | |
| 19 ShellCustomBindings::ShellCustomBindings(extensions::ScriptContext* context) | |
| 20 : extensions::ObjectBackedNativeHandler(context) { | |
| 21 RouteFunction( | |
| 22 "GetView", | |
| 23 base::Bind(&ShellCustomBindings::GetView, base::Unretained(this))); | |
| 24 } | |
| 25 | |
| 26 void ShellCustomBindings::GetView( | |
| 27 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 28 if (args.Length() != 1 || !args[0]->IsInt32()) | |
| 29 return; | |
| 30 | |
| 31 int view_id = args[0]->Int32Value(); | |
| 32 if (view_id == MSG_ROUTING_NONE) | |
| 33 return; | |
| 34 | |
| 35 content::RenderView* view = content::RenderView::FromRoutingID(view_id); | |
| 36 if (!view) | |
| 37 return; | |
| 38 | |
| 39 // Set the opener so we have a security origin set up before returning the DOM | |
| 40 // reference. | |
| 41 content::RenderView* render_view = context()->GetRenderView(); | |
| 42 if (!render_view) | |
| 43 return; | |
| 44 blink::WebFrame* opener = render_view->GetWebView()->mainFrame(); | |
| 45 blink::WebFrame* frame = view->GetWebView()->mainFrame(); | |
| 46 frame->setOpener(opener); | |
| 47 | |
| 48 // Resume resource requests. | |
| 49 content::RenderThread::Get()->Send( | |
| 50 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); | |
| 51 | |
| 52 // Return the script context. | |
| 53 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); | |
| 54 args.GetReturnValue().Set(window); | |
| 55 } | |
| 56 | |
| 57 } // namespace apps | |
| OLD | NEW |