Commit 7ef3bb62 authored by alp@webkit.org's avatar alp@webkit.org

2007-11-22 Alp Toker <alp@atoker.com>

        Reviewed by Mark Rowe.

        Implement and document several WebKitFrame functions, some of which
        are necessary to support DRT.

        Correct NULL handling and improve run-time checks.

        * Api/webkitgtkframe.cpp:
        * Api/webkitgtkframe.h:
        * Api/webkitgtkprivate.cpp:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27991 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent cc8e1369
/*
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -33,9 +34,16 @@
#include "FrameLoader.h"
#include "FrameLoaderClientGtk.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "HTMLFrameOwnerElement.h"
#include "kjs_binding.h"
#include "kjs_proxy.h"
#include "kjs_window.h"
#include <JavaScriptCore/APICast.h>
using namespace WebKit;
using namespace WebCore;
extern "C" {
......@@ -199,4 +207,126 @@ gchar* webkit_frame_get_location(WebKitFrame* frame)
return frameData->location;
}
/**
* webkit_frame_get_parent:
* @frame: a #WebKitFrame
*
* Returns the @frame's parent frame, or %NULL if it has none.
*
* Return value: the parent #WebKitFrame or %NULL in case there is none
*/
WebKitFrame* webkit_frame_get_parent(WebKitFrame* frame)
{
g_return_val_if_fail(WEBKIT_IS_FRAME(frame), NULL);
Frame* coreFrame = core(frame);
g_return_val_if_fail(coreFrame, NULL);
return kit(coreFrame->tree()->parent());
}
/**
* webkit_frame_load_request:
* @frame: a #WebKitFrame
* @request: a #WebKitNetworkRequest
*
* Connects to a given URL by initiating an asynchronous client request.
*
* Creates a provisional data source that will transition to a committed data
* source once any data has been received. Use webkit_frame_stop_loading() to
* stop the load. This function is typically invoked on the main frame.
*/
void webkit_frame_load_request(WebKitFrame* frame, WebKitNetworkRequest* request)
{
g_return_if_fail(WEBKIT_IS_FRAME(frame));
g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request));
Frame* coreFrame = core(frame);
g_return_if_fail(coreFrame);
// TODO: Use the ResourceRequest carried by WebKitNetworkRequest when it gets implemented.
DeprecatedString string = DeprecatedString::fromUtf8(webkit_network_request_get_url(request));
coreFrame->loader()->load(ResourceRequest(KURL(string)));
}
/**
* webkit_frame_stop_loading:
* @frame: a #WebKitFrame
*
* Stops any pending loads on @frame's data source, and those of its children.
*/
void webkit_frame_stop_loading(WebKitFrame* frame)
{
g_return_if_fail(WEBKIT_IS_FRAME(frame));
Frame* coreFrame = core(frame);
g_return_if_fail(coreFrame);
coreFrame->loader()->stopAllLoaders();
}
/**
* webkit_frame_reload:
* @frame: a #WebKitFrame
*
* Reloads the initial request.
*/
void webkit_frame_reload(WebKitFrame* frame)
{
g_return_if_fail(WEBKIT_IS_FRAME(frame));
Frame* coreFrame = core(frame);
g_return_if_fail(coreFrame);
coreFrame->loader()->reload();
}
/**
* webkit_frame_find_frame:
* @frame: a #WebKitFrame
* @name: the name of the frame to be found
*
* For pre-defined names, returns @frame if @name is "_self" or "_current",
* returns @frame's parent frame if @name is "_parent", and returns the main
* frame if @name is "_top". Also returns @frame if it is the main frame and
* @name is either "_parent" or "_top". For other names, this function returns
* the first frame that matches @name. This function searches @frame and its
* descendents first, then @frame's parent and its children moving up the
* hierarchy until a match is found. If no match is found in @frame's
* hierarchy, this function will search for a matching frame in other main
* frame hierarchies. Returns %NULL if no match is found.
*
* Return value: the found #WebKitFrame or %NULL in case none is found
*/
WebKitFrame* webkit_frame_find_frame(WebKitFrame* frame, const gchar* name)
{
g_return_val_if_fail(WEBKIT_IS_FRAME(frame), NULL);
g_return_val_if_fail(name, NULL);
Frame* coreFrame = core(frame);
g_return_val_if_fail(coreFrame, NULL);
String nameString = String::fromUTF8(name);
return kit(coreFrame->tree()->find(AtomicString(nameString)));
}
/**
* webkit_frame_get_global_context:
* @frame: a #WebKitFrame
*
* Gets the global JavaScript execution context. Use this function to bridge
* between the WebKit and JavaScriptCore APIs.
*
* Return value: the global JavaScript context
*/
JSGlobalContextRef webkit_frame_get_global_context(WebKitFrame* frame)
{
g_return_val_if_fail(WEBKIT_IS_FRAME(frame), NULL);
Frame* coreFrame = core(frame);
g_return_val_if_fail(coreFrame, NULL);
return toGlobalRef(coreFrame->scriptProxy()->interpreter()->globalExec());
}
}
/*
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -34,6 +35,10 @@
#include "webkitgtkdefines.h"
typedef struct OpaqueJSContext* JSGlobalContextRef;
typedef const struct OpaqueJSContext* JSContextRef;
typedef struct OpaqueJSValue* JSObjectRef;
G_BEGIN_DECLS
#define WEBKIT_TYPE_FRAME (webkit_frame_get_type())
......@@ -99,6 +104,24 @@ webkit_frame_get_rectangle (WebKitFrame* frame);
WEBKIT_API WebKitPage*
webkit_frame_get_page (WebKitFrame* frame);
WEBKIT_API WebKitFrame*
webkit_frame_get_parent (WebKitFrame* frame);
WEBKIT_API void
webkit_frame_load_request (WebKitFrame* frame, WebKitNetworkRequest* request);
WEBKIT_API void
webkit_frame_stop_loading (WebKitFrame* frame);
WEBKIT_API void
webkit_frame_reload (WebKitFrame* frame);
WEBKIT_API WebKitFrame*
webkit_frame_find_frame (WebKitFrame* frame, const gchar* name);
WEBKIT_API JSGlobalContextRef
webkit_frame_get_global_context (WebKitFrame* frame);
G_END_DECLS
#endif
......@@ -60,25 +60,39 @@ WebKitPage* getPageFromFrame(WebKitFrame* frame)
WebCore::Frame* core(WebKitFrame* frame)
{
if (!frame)
return 0;
WebKitFramePrivate* frame_data = WEBKIT_FRAME_GET_PRIVATE(frame);
return frame_data->frame;
return frame_data ? frame_data->frame : 0;
}
WebKitFrame* kit(WebCore::Frame* coreFrame)
{
if (!coreFrame)
return 0;
ASSERT(coreFrame->loader());
WebKit::FrameLoaderClient* client = static_cast<WebKit::FrameLoaderClient*>(coreFrame->loader()->client());
return client->webFrame();
return client ? client->webFrame() : 0;
}
WebCore::Page* core(WebKitPage* page)
{
if (!page)
return 0;
WebKitPagePrivate* page_data = WEBKIT_PAGE_GET_PRIVATE(page);
return page_data->page;
return page_data ? page_data->page : 0;
}
WebKitPage* kit(WebCore::Page* page)
{
if (!page)
return 0;
ASSERT(page->chrome());
WebKit::ChromeClient* client = static_cast<WebKit::ChromeClient*>(page->chrome()->client());
return client->webPage();
return client ? client->webPage() : 0;
}
}
2007-11-22 Alp Toker <alp@atoker.com>
Reviewed by Mark Rowe.
Implement and document several WebKitFrame functions, some of which
are necessary to support DRT.
Correct NULL handling and improve run-time checks.
* Api/webkitgtkframe.cpp:
* Api/webkitgtkframe.h:
* Api/webkitgtkprivate.cpp:
2007-11-22 Alp Toker <alp@atoker.com>
Whitespace fixes only.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment