WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp

22 * Copyright (C) 2007 Alp Toker <[email protected]>
33 * Copyright (C) 2007 Holger Hans Peter Freyther
44 * Copyright (C) 2007 Christian Dywan <[email protected]>
 5 * Copyright (C) 2007 Collabora Ltd. All rights reserved.
56 *
67 * This library is free software; you can redistribute it and/or
78 * modify it under the terms of the GNU Lesser General Public

217218 m_response = response;
218219}
219220
220 void FrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction policyFunction, const String&, const ResourceRequest&)
 221void FrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction policyFunction, const String& mime, const ResourceRequest& resourceRequest)
221222{
222  // FIXME: we need to call directly here (comment copied from Qt version)
223223 ASSERT(policyFunction);
224224 if (!policyFunction)
225225 return;
226  (core(m_frame)->loader()->*policyFunction)(PolicyUse);
 226
 227 WebKitWebView* page = getViewFromFrame(m_frame);
 228 WebKitNetworkRequest* request = webkit_network_request_new(resourceRequest.url().string().utf8().data());
 229 WebKitPolicyResponse response;
 230 g_print("++ Signal for %s :", resourceRequest.url().string().utf8().data());
 231
 232 g_signal_emit_by_name(page, "mime-type-policy-decision-requested", m_frame, request, mime.utf8().data(), &response);
 233
 234 g_object_unref(request);
 235
 236 if (response == WEBKIT_POLICY_RESPONSE_ERROR)
 237 {
 238 // response will be set ERROR if the signal hasn't been handled
 239 // Apply default behavior
 240 if(canShowMIMEType(mime))
 241 response = WEBKIT_POLICY_RESPONSE_ACCEPT;
 242 else
 243 response = WEBKIT_POLICY_RESPONSE_IGNORE;
 244 }
 245
 246
 247 g_print(" %d \n", response);
 248 if (response == WEBKIT_POLICY_RESPONSE_ACCEPT) {
 249 (core(m_frame)->loader()->*policyFunction)(PolicyUse);
 250 return;
 251 } else if (response == WEBKIT_POLICY_RESPONSE_DOWNLOAD) {
 252 (core(m_frame)->loader()->*policyFunction)(PolicyDownload);
 253 return;
 254 }
 255 (core(m_frame)->loader()->*policyFunction)(PolicyIgnore);
 256
227257}
228258
229 void FrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction policyFunction, const NavigationAction&, const ResourceRequest&, const String&)
 259void FrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction policyFunction, const NavigationAction&, const ResourceRequest& resourceRequest, const String&)
230260{
231261 ASSERT(policyFunction);
232262 if (!policyFunction)
233263 return;
234  // FIXME: I think Qt version marshals this to another thread so when we
235  // have multi-threaded download, we might need to do the same
 264
 265 WebKitWebView* page = getViewFromFrame(m_frame);
 266 WebKitNetworkRequest* request = webkit_network_request_new(resourceRequest.url().string().utf8().data());
 267 WebKitPolicyResponse response;
 268
 269 g_signal_emit_by_name(page, "new-window-requested", m_frame, request, &response);
 270
 271 g_object_unref(request);
 272
 273 if (response == WEBKIT_POLICY_RESPONSE_ACCEPT) {
 274 (core(m_frame)->loader()->*policyFunction)(PolicyUse);
 275 return;
 276 }
236277 (core(m_frame)->loader()->*policyFunction)(PolicyIgnore);
237278}
238279

244285
245286 WebKitWebView* webView = getViewFromFrame(m_frame);
246287 WebKitNetworkRequest* request = webkit_network_request_new(resourceRequest.url().string().utf8().data());
247  WebKitNavigationResponse response;
 288 WebKitPolicyResponse response;
248289
249290 g_signal_emit_by_name(webView, "navigation-requested", m_frame, request, &response);
250291
251292 g_object_unref(request);
252293
253  if (response == WEBKIT_NAVIGATION_RESPONSE_IGNORE) {
 294 if (response == WEBKIT_POLICY_RESPONSE_IGNORE) {
254295 (core(m_frame)->loader()->*policyFunction)(PolicyIgnore);
255296 return;
256297 }

603644 return true;
604645}
605646
606 bool FrameLoaderClient::canShowMIMEType(const String&) const
607 {
608  notImplemented();
609  return true;
 647bool FrameLoaderClient::canShowMIMEType(const String& type) const
 648{
 649 // FIXME: add supported mimestypes of plugins
 650 return MIMETypeRegistry::isSupportedImageMIMEType(type) || MIMETypeRegistry::isSupportedNonImageMIMEType(type);
610651}
611652
612653bool FrameLoaderClient::representationExistsForURLScheme(const String&) const

685726
686727void FrameLoaderClient::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
687728{
 729 g_print("DEBUG");
688730 notImplemented();
689731}
690732
révision 29341

WebKit/gtk/ChangeLog

 12008-01-09 Pierre-Luc Beaudoin <[email protected]>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 This implements the delegates methods of WebPolicyDelegate.
 6 Since Gtk+/C doesn't have delegate methods, I replaced them with signals.
 7 Also, since WebPolicyDelegate only has 3 delegate, I added them to WebView
 8 instead of creating new GObject with only 3 signals.
 9
 10 I tried to copy the behavior described in http://developer.apple.com/documentation/Cocoa/Reference/WebKit/Protocols/WebPolicyDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/instm/NSObject/webView:decidePolicyForNavigationAction:request:frame:decisionListener:
 11
 12 * WebCoreSupport/FrameLoaderClientGtk.cpp:
 13 (WebKit::FrameLoaderClient::dispatchDecidePolicyForMIMEType):
 14 (WebKit::FrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
 15 (WebKit::FrameLoaderClient::dispatchDecidePolicyForNavigationAction):
 16 (WebKit::FrameLoaderClient::canShowMIMEType):
 17 (WebKit::FrameLoaderClient::download):
 18 * WebView/webkit-marshal.list:
 19 * WebView/webkitwebview.cpp:
 20 * WebView/webkitwebview.h:
 21
1222008-01-09 Luca Bruno <[email protected]>
223
324 Reviewed by Alp Toker.
révision 29342

WebKit/gtk/WebView/webkitwebview.cpp

33 * Copyright (C) 2007 Christian Dywan <[email protected]>
44 * Copyright (C) 2007 Xan Lopez <[email protected]>
55 * Copyright (C) 2007 Alp Toker <[email protected]>
 6 * Copyright (C) 2007 Collabora Ltd. All rights reserved.
67 *
78 * This library is free software; you can redistribute it and/or
89 * modify it under the terms of the GNU Lesser General Public

5960enum {
6061 /* normal signals */
6162 NAVIGATION_REQUESTED,
 63 MIME_TYPE_POLICY_DECISION_REQUESTED,
 64 NEW_WINDOW_REQUESTED,
6265 WINDOW_OBJECT_CLEARED,
6366 LOAD_STARTED,
6467 LOAD_COMMITTED,

412415 return 0;
413416}
414417
415 static WebKitNavigationResponse webkit_web_view_real_navigation_requested(WebKitWebView*, WebKitWebFrame* frame, WebKitNetworkRequest*)
 418static WebKitPolicyResponse webkit_web_view_real_navigation_requested(WebKitWebView*, WebKitWebFrame* frame, WebKitNetworkRequest*)
416419{
417420 notImplemented();
418  return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
 421 return WEBKIT_POLICY_RESPONSE_ACCEPT;
419422}
420423
 424static WebKitPolicyResponse webkit_web_view_real_new_window_requested(WebKitWebView*, WebKitWebFrame* frame, WebKitNetworkRequest*)
 425{
 426 notImplemented();
 427 // FIXME: Change this to accept once it is implemented
 428 return WEBKIT_POLICY_RESPONSE_IGNORE;
 429}
 430
421431static void webkit_web_view_real_window_object_cleared(WebKitWebView*, WebKitWebFrame*, JSGlobalContextRef context, JSObjectRef window_object)
422432{
423433 notImplemented();

575585 int signalHandled = g_value_get_int(handlerReturn);
576586 g_value_set_int(returnAccu, signalHandled);
577587
578  if (signalHandled != WEBKIT_NAVIGATION_RESPONSE_ACCEPT)
 588 if (signalHandled != WEBKIT_POLICY_RESPONSE_ACCEPT)
579589 continueEmission = FALSE;
580590
581591 return continueEmission;

593603 * Signals
594604 */
595605
 606 /**
 607 * WebKitWebView::navigation-requested:
 608 * @web_view: the object on which the signal is emitted
 609 * @web_frame: the frame on which the action
 610 * @return: WEBKIT_POLICY_RESPONSE_ACCEPT to allow WebKit to display this location,
 611 WEBKIT_POLICY_RESPONSE_IGNORE not to display this location
 612 *
 613 * Routes a navigation action internally or to an external viewer.
 614 */
596615 webkit_web_view_signals[NAVIGATION_REQUESTED] = g_signal_new("navigation-requested",
597616 G_TYPE_FROM_CLASS(webViewClass),
598617 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),

605624 G_TYPE_OBJECT);
606625
607626 /**
 627 * WebKitWebView::mime-type-policy-decision-requested:
 628 * @web_view: the object on which the signal is emitted
 629 * @web_frame: the frame on which the action
 630 * @mimetype: the MIME type attempted to load
 631 * @return: WEBKIT_POLICY_RESPONSE_ACCEPT to allow WebKit to display this MIME type,
 632 WEBKIT_POLICY_RESPONSE_IGNORE to make WebKit ignore this resource,
 633 WEBKIT_POLICY_RESPONSE_DOWNLOAD to make WebKit download this resource.
 634 *
 635 * Decide wether to display of not the given MIME type.
 636 * If this signal is not handled, the default behavior is as follows. If WebKit can
 637 * show this MIME type, the WEBKIT_POLICY_RESPONSE_ACCEPT will be used, else
 638 * WEBKIT_POLICY_RESPONSE_IGNORE will be used.
 639 */
 640 webkit_web_view_signals[MIME_TYPE_POLICY_DECISION_REQUESTED] = g_signal_new("mime-type-policy-decision-requested",
 641 G_TYPE_FROM_CLASS(webViewClass),
 642 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
 643 0,
 644 NULL,
 645 NULL,
 646 webkit_marshal_INT__OBJECT_OBJECT_STRING,
 647 G_TYPE_INT, 3,
 648 G_TYPE_OBJECT,
 649 G_TYPE_OBJECT,
 650 G_TYPE_STRING);
 651
 652 /**
 653 * WebKitWebView::new-window-requested:
 654 * @web_view: the object on which the signal is emitted
 655 * @web_frame: the frame on which the action
 656 * @return: WEBKIT_POLICY_RESPONSE_ACCEPT to allow WebKit to display a new window,
 657 WEBKIT_POLICY_RESPONSE_IGNORE not to display a new window
 658 *
 659 * Decides whether to allow a targeted navigation event, such as opening a link in a new window.
 660 * The default behavior is to accept.
 661 */
 662 webkit_web_view_signals[NEW_WINDOW_REQUESTED] = g_signal_new("new-window-requested",
 663 G_TYPE_FROM_CLASS(webViewClass),
 664 (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
 665 G_STRUCT_OFFSET(WebKitWebViewClass, new_window_requested),
 666 NULL,
 667 NULL,
 668 webkit_marshal_INT__OBJECT_OBJECT,
 669 G_TYPE_INT, 2,
 670 G_TYPE_OBJECT,
 671 G_TYPE_OBJECT);
 672
 673 /**
608674 * WebKitWebView::window-object-cleared:
609675 * @web_view: the object on which the signal is emitted
610676 * @frame: the #WebKitWebFrame to which @window_object belongs

902968 */
903969 webViewClass->create_web_view = webkit_web_view_real_create_web_view;
904970 webViewClass->navigation_requested = webkit_web_view_real_navigation_requested;
 971 webViewClass->new_window_requested = webkit_web_view_real_new_window_requested;
905972 webViewClass->window_object_cleared = webkit_web_view_real_window_object_cleared;
906973 webViewClass->choose_file = webkit_web_view_real_choose_file;
907974 webViewClass->script_alert = webkit_web_view_real_script_alert;

14941561 return webViewData->paste_target_list;
14951562}
14961563
 1564gboolean webkit_web_view_can_show_mime_type (WebKitWebView* web_view, const gchar* mime_type)
 1565{
 1566 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(web_view), FALSE);
 1567
 1568 Frame* frame = core(webkit_web_view_get_main_frame(web_view));
 1569 if (FrameLoader* loader = frame->loader())
 1570 return loader->canShowMIMEType(mime_type);
 1571 else
 1572 return FALSE;
14971573}
 1574
 1575}
 1576
révision 29341

WebKit/gtk/WebView/webkit-marshal.list

1010BOOLEAN:OBJECT,STRING,BOOLEAN
1111BOOLEAN:OBJECT,STRING,STRING,STRING
1212INT:OBJECT,OBJECT
 13INT:OBJECT,OBJECT,STRING
révision 29341

WebKit/gtk/WebView/webkitwebview.h

11/*
22 * Copyright (C) 2007 Holger Hans Peter Freyther
 3 * Copyright (C) 2007 Collabora Ltd. All rights reserved.
34 *
45 * This library is free software; you can redistribute it and/or
56 * modify it under the terms of the GNU Library General Public

3637
3738
3839typedef enum {
39  WEBKIT_NAVIGATION_RESPONSE_ACCEPT,
40  WEBKIT_NAVIGATION_RESPONSE_IGNORE,
41  WEBKIT_NAVIGATION_RESPONSE_DOWNLOAD
42 } WebKitNavigationResponse;
 40 WEBKIT_POLICY_RESPONSE_ERROR = 0,
 41 WEBKIT_POLICY_RESPONSE_ACCEPT,
 42 WEBKIT_POLICY_RESPONSE_IGNORE,
 43 WEBKIT_POLICY_RESPONSE_DOWNLOAD
 44} WebKitPolicyResponse;
4345
4446typedef enum
4547{

6365 WebKitWebView* (*create_web_view) (WebKitWebView* web_view);
6466
6567 /*
66  * TODO: FIXME: Create something like WebPolicyDecisionListener_Protocol instead
 68 * Policy handlers
6769 */
68  WebKitNavigationResponse (*navigation_requested) (WebKitWebView* web_view, WebKitWebFrame* frame, WebKitNetworkRequest* request);
 70 WebKitPolicyResponse (*navigation_requested) (WebKitWebView* web_view, WebKitWebFrame* frame, WebKitNetworkRequest* request);
 71 WebKitPolicyResponse (*new_window_requested) (WebKitWebView* web_view, WebKitWebFrame* frame, WebKitNetworkRequest* request);
6972
7073 void (*window_object_cleared) (WebKitWebView* web_view, WebKitWebFrame* frame, JSGlobalContextRef context, JSObjectRef window_object);
7174 gchar* (*choose_file) (WebKitWebView* web_view, WebKitWebFrame* frame, const gchar* old_file);

174177WEBKIT_API GtkTargetList*
175178webkit_web_view_get_paste_target_list (WebKitWebView* webView);
176179
 180WEBKIT_API gboolean
 181webkit_web_view_can_show_mime_type (WebKitWebView* web_view, const gchar* mime_type);
 182
177183G_END_DECLS
178184
179185#endif
révision 29341

WebCore/platform/network/curl/ResourceHandleManager.cpp

9393 // of html page even if it is a redirect that was handled internally
9494 // can be observed e.g. on gmail.com
9595 CURL* h = d->m_handle;
 96 ASSERT(h);
9697 long httpCode = 0;
9798 CURLcode err = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &httpCode);
9899 if (CURLE_OK == err && httpCode >= 300 && httpCode < 400)

515516 if (removeScheduledJob(job))
516517 return;
517518
518  if (m_downloadTimer.isActive()) {
519  ResourceHandleInternal* d = job->getInternal();
520  d->m_cancelled = true;
521  } else
522  removeFromCurl(job);
 519 ResourceHandleInternal* d = job->getInternal();
 520 d->m_cancelled = true;
523521}
524522
525523} // namespace WebCore
révision 29341

WebCore/ChangeLog

 12008-01-09 Pierre-Luc Beaudoin <[email protected]>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Using PolicyIgnore will cause curl to crash because the easy handle
 6 is cleaned up before the end for the downloadTimerCallback(). Using
 7 delayed cancel for all jobs solves the problem.
 8
 9 * platform/network/curl/ResourceHandleManager.cpp:
 10 (WebCore::writeCallback): the handle should always be valid at that point
 11 (WebCore::ResourceHandleManager::cancel): force delayed cancel for all jobs
 12
 13
1142008-01-09 John Sullivan <[email protected]>
215
316 Reviewed by Adam Roben and Anders Carlsson
révision 29342