Skip to content
Permalink
Browse files
[GLib] WebKitNavigationAction should tell whether it is a redirect
https://bugs.webkit.org/show_bug.cgi?id=178178

Source/WebKit:

There is no good way to know whether a given navigation action has been caused
by a redirect through the glib API. This is necessary to implement some app mode
heuristics for Epiphany.

Reviewed by Carlos Garcia Campos.

* UIProcess/API/glib/WebKitNavigationAction.cpp:
(webkit_navigation_action_is_redirect): returns whether the navigation action is a redirect.
* UIProcess/API/glib/WebKitNavigationActionPrivate.h: add isRedirect to the wrapper object.
(_WebKitNavigationAction::_WebKitNavigationAction):
* UIProcess/API/gtk/WebKitNavigationAction.h: add the new API.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: ditto.
* UIProcess/API/wpe/WebKitNavigationAction.h: ditto.

Tools:

Test that WebKitNavigationAction properly reports being a redirect.

Reviewed by Carlos Garcia Campos.

* TestWebKitAPI/Tests/WebKitGLib/TestWebKitPolicyClient.cpp:
(testNavigationPolicy): test that loading /redirect leads to a redirect WebKitNavigationAction.
(serverCallback): add a /redirect path to the server, which causes a redirect.

Canonical link: https://commits.webkit.org/194496@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223282 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
kov committed Oct 13, 2017
1 parent cba2be9 commit 0aee2470c3a76b243577bcaded6eaf76b5420658
Showing 8 changed files with 74 additions and 0 deletions.
@@ -1,3 +1,22 @@
2017-10-11 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>

[GLib] WebKitNavigationAction should tell whether it is a redirect
https://bugs.webkit.org/show_bug.cgi?id=178178

There is no good way to know whether a given navigation action has been caused
by a redirect through the glib API. This is necessary to implement some app mode
heuristics for Epiphany.

Reviewed by Carlos Garcia Campos.

* UIProcess/API/glib/WebKitNavigationAction.cpp:
(webkit_navigation_action_is_redirect): returns whether the navigation action is a redirect.
* UIProcess/API/glib/WebKitNavigationActionPrivate.h: add isRedirect to the wrapper object.
(_WebKitNavigationAction::_WebKitNavigationAction):
* UIProcess/API/gtk/WebKitNavigationAction.h: add the new API.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: ditto.
* UIProcess/API/wpe/WebKitNavigationAction.h: ditto.

2017-10-12 Brady Eidson <beidson@apple.com>

SW "Hello world".
@@ -150,3 +150,19 @@ gboolean webkit_navigation_action_is_user_gesture(WebKitNavigationAction* naviga
g_return_val_if_fail(navigation, FALSE);
return navigation->isUserGesture;
}

/**
* webkit_navigation_action_is_redirect:
* @navigation: a #WebKitNavigationAction
*
* Returns whether the @navigation was redirected.
*
* Returns: %TRUE if the original navigation was redirected, %FALSE otherwise.
*
* Since: 2.20
*/
gboolean webkit_navigation_action_is_redirect(WebKitNavigationAction* navigation)
{
g_return_val_if_fail(navigation, FALSE);
return navigation->isRedirect;
}
@@ -30,6 +30,7 @@ struct _WebKitNavigationAction {
, mouseButton(toWebKitMouseButton(navigationActionData.mouseButton))
, modifiers(toPlatformModifiers(navigationActionData.modifiers))
, isUserGesture(navigationActionData.userGestureTokenIdentifier)
, isRedirect(navigationActionData.isRedirect)
, request(uriRequest)
{
}
@@ -47,6 +48,7 @@ struct _WebKitNavigationAction {
unsigned mouseButton;
unsigned modifiers;
bool isUserGesture : 1;
bool isRedirect : 1;
GRefPtr<WebKitURIRequest> request;
};

@@ -79,6 +79,9 @@ webkit_navigation_action_get_request (WebKitNavigationAction *navigation
WEBKIT_API gboolean
webkit_navigation_action_is_user_gesture (WebKitNavigationAction *navigation);

WEBKIT_API gboolean
webkit_navigation_action_is_redirect (WebKitNavigationAction *navigation);

G_END_DECLS

#endif
@@ -649,6 +649,7 @@ webkit_navigation_action_get_mouse_button
webkit_navigation_action_get_modifiers
webkit_navigation_action_get_request
webkit_navigation_action_is_user_gesture
webkit_navigation_action_is_redirect

<SUBSECTION Standard>
WEBKIT_TYPE_NAVIGATION_ACTION
@@ -79,6 +79,9 @@ webkit_navigation_action_get_request (WebKitNavigationAction *navigation
WEBKIT_API gboolean
webkit_navigation_action_is_user_gesture (WebKitNavigationAction *navigation);

WEBKIT_API gboolean
webkit_navigation_action_is_redirect (WebKitNavigationAction *navigation);

G_END_DECLS

#endif
@@ -1,3 +1,16 @@
2017-10-11 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>

[GLib] WebKitNavigationAction should tell whether it is a redirect
https://bugs.webkit.org/show_bug.cgi?id=178178

Test that WebKitNavigationAction properly reports being a redirect.

Reviewed by Carlos Garcia Campos.

* TestWebKitAPI/Tests/WebKitGLib/TestWebKitPolicyClient.cpp:
(testNavigationPolicy): test that loading /redirect leads to a redirect WebKitNavigationAction.
(serverCallback): add a /redirect path to the server, which causes a redirect.

2017-10-13 Chris Dumez <cdumez@apple.com>

Unreviewed, fix webkitpy failure after r223273
@@ -121,6 +121,7 @@ static void testNavigationPolicy(PolicyClientTest* test, gconstpointer)
g_assert_cmpint(webkit_navigation_action_get_navigation_type(navigationAction), ==, WEBKIT_NAVIGATION_TYPE_OTHER);
g_assert_cmpint(webkit_navigation_action_get_mouse_button(navigationAction), ==, 0);
g_assert_cmpint(webkit_navigation_action_get_modifiers(navigationAction), ==, 0);
g_assert_false(webkit_navigation_action_is_redirect(navigationAction));
g_assert(!webkit_navigation_policy_decision_get_frame_name(decision));
WebKitURIRequest* request = webkit_navigation_action_get_request(navigationAction);
g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, "http://webkitgtk.org/");
@@ -131,6 +132,19 @@ static void testNavigationPolicy(PolicyClientTest* test, gconstpointer)
test->waitUntilLoadFinished();
g_assert_cmpint(test->m_loadEvents.size(), ==, 3);

test->m_policyDecisionResponse = PolicyClientTest::Use;
test->m_respondToPolicyDecisionAsynchronously = false;
test->loadURI(kServer->getURIForPath("/redirect").data());
test->waitUntilLoadFinished();
g_assert_cmpint(test->m_loadEvents.size(), ==, 4);

decision = WEBKIT_NAVIGATION_POLICY_DECISION(test->m_previousPolicyDecision.get());
navigationAction = webkit_navigation_policy_decision_get_navigation_action(decision);
g_assert_true(webkit_navigation_action_is_redirect(navigationAction));
g_assert(!webkit_navigation_policy_decision_get_frame_name(decision));
request = webkit_navigation_action_get_request(navigationAction);
g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/").data());

// If we are waiting until load completion, it will never complete if we ignore the
// navigation. So we tell the main loop to quit sometime later.
test->m_policyDecisionResponse = PolicyClientTest::Ignore;
@@ -248,6 +262,9 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
soup_message_set_status(message, SOUP_STATUS_OK);
soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
soup_message_body_complete(message->response_body);
} else if (g_str_equal(path, "/redirect")) {
soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
soup_message_headers_append(message->response_headers, "Location", "/");
} else
soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}

0 comments on commit 0aee247

Please sign in to comment.