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