@@ -172,9 +172,63 @@ void Dispatcher::documentCallback(const char* ev, WebKit::WebFrame* frame) {
172172 frame->mainWorldScriptContext ()->GetIsolate ());
173173 }
174174 args->Set (0 , element);
175- v8::Handle<v8::Value> argv[] = {val, v8::String::New (ev), args };
175+ v8::Handle<v8::Value> argv[] = {val, v8_str (ev), args };
176176
177177 node::MakeCallback (objects_registry, " handleEvent" , 3 , argv);
178178}
179179
180+ void Dispatcher::willHandleNavigationPolicy (
181+ content::RenderView* rv,
182+ WebKit::WebFrame* frame,
183+ const WebKit::WebURLRequest& request,
184+ WebKit::WebNavigationPolicy* policy) {
185+
186+ WebKit::WebView* web_view = rv->GetWebView ();
187+
188+ if (!web_view)
189+ return ;
190+
191+ v8::Context::Scope cscope (web_view->mainFrame ()->mainWorldScriptContext ());
192+
193+ v8::Handle<v8::Value> id_val = nwapi::Dispatcher::GetWindowId (web_view->mainFrame ());
194+ if (id_val->IsNull () || id_val->IsUndefined ())
195+ return ;
196+
197+ v8::Handle<v8::Object> objects_registry = nwapi::Dispatcher::GetObjectRegistry ();
198+ if (objects_registry->IsUndefined ())
199+ return ;
200+
201+ v8::Local<v8::Array> args = v8::Array::New ();
202+ v8::Handle<v8::Value> element = v8::Null ();
203+ v8::Handle<v8::Object> policy_obj = v8::Object::New ();
204+
205+ WebCore::Frame* core_frame = WebKit::toWebFrameImpl (frame)->frame ();
206+ if (core_frame->ownerElement ()) {
207+ element = WebCore::toV8 ((WebCore::HTMLElement*)core_frame->ownerElement (),
208+ frame->mainWorldScriptContext ()->Global (),
209+ frame->mainWorldScriptContext ()->GetIsolate ());
210+ }
211+ args->Set (0 , element);
212+ args->Set (1 , v8_str (request.url ().string ().utf8 ().c_str ()));
213+ args->Set (2 , policy_obj);
214+
215+ v8::Handle<v8::Value> argv[] = {id_val, v8_str (" new-win-policy" ), args };
216+
217+ node::MakeCallback (objects_registry, " handleEvent" , 3 , argv);
218+ v8::Local<v8::Value> val = policy_obj->Get (v8_str (" val" ));
219+ if (!val->IsString ())
220+ return ;
221+ v8::String::Utf8Value policy_str (val);
222+ if (!strcmp (*policy_str, " ignore" ))
223+ *policy = WebKit::WebNavigationPolicyIgnore;
224+ else if (!strcmp (*policy_str, " download" ))
225+ *policy = WebKit::WebNavigationPolicyDownload;
226+ else if (!strcmp (*policy_str, " current" ))
227+ *policy = WebKit::WebNavigationPolicyCurrentTab;
228+ else if (!strcmp (*policy_str, " new-window" ))
229+ *policy = WebKit::WebNavigationPolicyNewWindow;
230+ else if (!strcmp (*policy_str, " new-popup" ))
231+ *policy = WebKit::WebNavigationPolicyNewPopup;
232+ }
233+
180234} // namespace nwapi
0 commit comments