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

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

Issue 910073003: <webview>: Make contentWindow available prior to attachment (on display:none). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use constants Created 5 years, 9 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/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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "content/public/child/v8_value_converter.h" 10 #include "content/public/child/v8_value_converter.h"
11 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_messages.h" 13 #include "extensions/common/extension_messages.h"
14 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" 14 #include "extensions/renderer/guest_view/extensions_guest_view_container.h"
15 #include "extensions/renderer/script_context.h" 15 #include "extensions/renderer/script_context.h"
16 #include "third_party/WebKit/public/web/WebFrame.h"
17 #include "third_party/WebKit/public/web/WebView.h"
16 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
17 19
18 using content::V8ValueConverter; 20 using content::V8ValueConverter;
19 21
20 namespace extensions { 22 namespace extensions {
21 23
22 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( 24 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings(
23 ScriptContext* context) 25 ScriptContext* context)
24 : ObjectBackedNativeHandler(context) { 26 : ObjectBackedNativeHandler(context) {
25 RouteFunction("AttachGuest", 27 RouteFunction("AttachGuest",
26 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, 28 base::Bind(&GuestViewInternalCustomBindings::AttachGuest,
27 base::Unretained(this))); 29 base::Unretained(this)));
28 RouteFunction("DetachGuest", 30 RouteFunction("DetachGuest",
29 base::Bind(&GuestViewInternalCustomBindings::DetachGuest, 31 base::Bind(&GuestViewInternalCustomBindings::DetachGuest,
30 base::Unretained(this))); 32 base::Unretained(this)));
33 RouteFunction("GetContentWindow",
34 base::Bind(&GuestViewInternalCustomBindings::GetContentWindow,
35 base::Unretained(this)));
31 RouteFunction( 36 RouteFunction(
32 "RegisterDestructionCallback", 37 "RegisterDestructionCallback",
33 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback, 38 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback,
34 base::Unretained(this))); 39 base::Unretained(this)));
35 RouteFunction( 40 RouteFunction(
36 "RegisterElementResizeCallback", 41 "RegisterElementResizeCallback",
37 base::Bind( 42 base::Bind(
38 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, 43 &GuestViewInternalCustomBindings::RegisterElementResizeCallback,
39 base::Unretained(this))); 44 base::Unretained(this)));
40 } 45 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 new ExtensionsGuestViewContainer::DetachRequest( 115 new ExtensionsGuestViewContainer::DetachRequest(
111 guest_view_container, 116 guest_view_container,
112 args.Length() == 2 ? args[1].As<v8::Function>() : 117 args.Length() == 2 ? args[1].As<v8::Function>() :
113 v8::Handle<v8::Function>(), 118 v8::Handle<v8::Function>(),
114 args.GetIsolate())); 119 args.GetIsolate()));
115 guest_view_container->IssueRequest(request); 120 guest_view_container->IssueRequest(request);
116 121
117 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); 122 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
118 } 123 }
119 124
125 void GuestViewInternalCustomBindings::GetContentWindow(
126 const v8::FunctionCallbackInfo<v8::Value>& args) {
127 // Default to returning null.
128 args.GetReturnValue().SetNull();
129
130 if (args.Length() != 1)
131 return;
132
133 // The routing ID for the RenderView.
134 if (!args[0]->IsInt32())
135 return;
136
137 int view_id = args[0]->Int32Value();
138 if (view_id == MSG_ROUTING_NONE)
139 return;
140
141 content::RenderView* view = content::RenderView::FromRoutingID(view_id);
142 if (!view)
143 return;
144
145 blink::WebFrame* frame = view->GetWebView()->mainFrame();
146 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global();
147 args.GetReturnValue().Set(window);
148 }
149
120 void GuestViewInternalCustomBindings::RegisterDestructionCallback( 150 void GuestViewInternalCustomBindings::RegisterDestructionCallback(
121 const v8::FunctionCallbackInfo<v8::Value>& args) { 151 const v8::FunctionCallbackInfo<v8::Value>& args) {
122 // There are two parameters. 152 // There are two parameters.
123 CHECK(args.Length() == 2); 153 CHECK(args.Length() == 2);
124 // Element Instance ID. 154 // Element Instance ID.
125 CHECK(args[0]->IsInt32()); 155 CHECK(args[0]->IsInt32());
126 // Callback function. 156 // Callback function.
127 CHECK(args[1]->IsFunction()); 157 CHECK(args[1]->IsFunction());
128 158
129 int element_instance_id = args[0]->Int32Value(); 159 int element_instance_id = args[0]->Int32Value();
(...skipping 27 matching lines...) Expand all
157 if (!guest_view_container) 187 if (!guest_view_container)
158 return; 188 return;
159 189
160 guest_view_container->RegisterElementResizeCallback( 190 guest_view_container->RegisterElementResizeCallback(
161 args[1].As<v8::Function>(), args.GetIsolate()); 191 args[1].As<v8::Function>(), args.GetIsolate());
162 192
163 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); 193 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
164 } 194 }
165 195
166 } // namespace extensions 196 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698