📄 webkitwebframe.cpp
字号:
/* * Copyright (C) 2007, 2008 Holger Hans Peter Freyther * Copyright (C) 2007 Alp Toker <alp@atoker.com> * Copyright (C) 2007 Apple Inc. * Copyright (C) 2008 Christian Dywan <christian@imendio.com> * Copyright (C) 2008 Collabora Ltd. * Copyright (C) 2008 Nuanti Ltd. * Copyright (C) 2009 Jan Alonzo <jmalonzo@gmail.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "config.h"#include "webkitwebframe.h"#include "webkitwebview.h"#include "webkitmarshal.h"#include "webkitprivate.h"#include "AnimationController.h"#include "CString.h"#include "DocumentLoader.h"#include "FrameLoader.h"#include "FrameLoaderClientGtk.h"#include "FrameTree.h"#include "FrameView.h"#include "GraphicsContext.h"#include "HTMLFrameOwnerElement.h"#include "JSDOMWindow.h"#include "PrintContext.h"#include "RenderView.h"#include "RenderTreeAsText.h"#include "JSDOMBinding.h"#include "ScriptController.h"#include "SubstituteData.h"#include <JavaScriptCore/APICast.h>/** * SECTION:webkitwebframe * @short_description: The content of a #WebKitWebView * * A #WebKitWebView contains a main #WebKitWebFrame. A #WebKitWebFrame * contains the content of one URI. The URI and name of the frame can * be retrieved, the load status and progress can be observed using the * signals and can be controlled using the methods of the #WebKitWebFrame. * A #WebKitWebFrame can have any number of children and one child can * be found by using #webkit_web_frame_find_frame. * * <informalexample><programlisting> * /<!-- -->* Get the frame from the #WebKitWebView *<!-- -->/ * WebKitWebFrame *frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW(my_view)); * g_print("The URI of this frame is '%s'", webkit_web_frame_get_uri (frame)); * </programlisting></informalexample> */using namespace WebKit;using namespace WebCore;using namespace std;extern "C" {enum { CLEARED, LOAD_COMMITTED, LOAD_DONE, TITLE_CHANGED, HOVERING_OVER_LINK, LAST_SIGNAL};enum { PROP_0, PROP_NAME, PROP_TITLE, PROP_URI};static guint webkit_web_frame_signals[LAST_SIGNAL] = { 0, };G_DEFINE_TYPE(WebKitWebFrame, webkit_web_frame, G_TYPE_OBJECT)static void webkit_web_frame_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec){ WebKitWebFrame* frame = WEBKIT_WEB_FRAME(object); switch(prop_id) { case PROP_NAME: g_value_set_string(value, webkit_web_frame_get_name(frame)); break; case PROP_TITLE: g_value_set_string(value, webkit_web_frame_get_title(frame)); break; case PROP_URI: g_value_set_string(value, webkit_web_frame_get_uri(frame)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; }}// Called from the FrameLoaderClient when it is destroyed. Normally// the unref in the FrameLoaderClient is destroying this object as// well but due reference counting a user might have added a reference...void webkit_web_frame_core_frame_gone(WebKitWebFrame* frame){ ASSERT(WEBKIT_IS_WEB_FRAME(frame)); frame->priv->coreFrame = 0;}static void webkit_web_frame_finalize(GObject* object){ WebKitWebFrame* frame = WEBKIT_WEB_FRAME(object); WebKitWebFramePrivate* priv = frame->priv; if (priv->coreFrame) { priv->coreFrame->loader()->cancelAndClear(); priv->coreFrame = 0; } g_free(priv->name); g_free(priv->title); g_free(priv->uri); G_OBJECT_CLASS(webkit_web_frame_parent_class)->finalize(object);}static void webkit_web_frame_class_init(WebKitWebFrameClass* frameClass){ webkit_init(); /* * signals */ webkit_web_frame_signals[CLEARED] = g_signal_new("cleared", G_TYPE_FROM_CLASS(frameClass), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); webkit_web_frame_signals[LOAD_COMMITTED] = g_signal_new("load-committed", G_TYPE_FROM_CLASS(frameClass), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); webkit_web_frame_signals[LOAD_DONE] = g_signal_new("load-done", G_TYPE_FROM_CLASS(frameClass), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); webkit_web_frame_signals[TITLE_CHANGED] = g_signal_new("title-changed", G_TYPE_FROM_CLASS(frameClass), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, NULL, NULL, webkit_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); webkit_web_frame_signals[HOVERING_OVER_LINK] = g_signal_new("hovering-over-link", G_TYPE_FROM_CLASS(frameClass), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, NULL, NULL, webkit_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); /* * implementations of virtual methods */ GObjectClass* objectClass = G_OBJECT_CLASS(frameClass); objectClass->finalize = webkit_web_frame_finalize; objectClass->get_property = webkit_web_frame_get_property; /* * properties */ g_object_class_install_property(objectClass, PROP_NAME, g_param_spec_string("name", "Name", "The name of the frame", NULL, WEBKIT_PARAM_READABLE)); g_object_class_install_property(objectClass, PROP_TITLE, g_param_spec_string("title", "Title", "The document title of the frame", NULL, WEBKIT_PARAM_READABLE)); g_object_class_install_property(objectClass, PROP_URI, g_param_spec_string("uri", "URI", "The current URI of the contents displayed by the frame", NULL, WEBKIT_PARAM_READABLE)); g_type_class_add_private(frameClass, sizeof(WebKitWebFramePrivate));}static void webkit_web_frame_init(WebKitWebFrame* frame){ WebKitWebFramePrivate* priv = WEBKIT_WEB_FRAME_GET_PRIVATE(frame); // TODO: Move constructor code here. frame->priv = priv;}/** * webkit_web_frame_new: * @web_view: the controlling #WebKitWebView * * Creates a new #WebKitWebFrame initialized with a controlling #WebKitWebView. * * Returns: a new #WebKitWebFrame * * Deprecated: 1.0.2: #WebKitWebFrame can only be used to inspect existing * frames. **/WebKitWebFrame* webkit_web_frame_new(WebKitWebView* webView){ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); WebKitWebFrame* frame = WEBKIT_WEB_FRAME(g_object_new(WEBKIT_TYPE_WEB_FRAME, NULL)); WebKitWebFramePrivate* priv = frame->priv; WebKitWebViewPrivate* viewPriv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView); priv->webView = webView; WebKit::FrameLoaderClient* client = new WebKit::FrameLoaderClient(frame); priv->coreFrame = Frame::create(viewPriv->corePage, 0, client).get(); priv->coreFrame->init(); return frame;}PassRefPtr<Frame> webkit_web_frame_init_with_web_view(WebKitWebView* webView, HTMLFrameOwnerElement* element){ WebKitWebFrame* frame = WEBKIT_WEB_FRAME(g_object_new(WEBKIT_TYPE_WEB_FRAME, NULL)); WebKitWebFramePrivate* priv = frame->priv; WebKitWebViewPrivate* viewPriv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView); priv->webView = webView; WebKit::FrameLoaderClient* client = new WebKit::FrameLoaderClient(frame); RefPtr<Frame> coreFrame = Frame::create(viewPriv->corePage, element, client); priv->coreFrame = coreFrame.get(); return coreFrame.release();}/** * webkit_web_frame_get_title: * @frame: a #WebKitWebFrame * * Returns the @frame's document title * * Return value: the title of @frame */G_CONST_RETURN gchar* webkit_web_frame_get_title(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); WebKitWebFramePrivate* priv = frame->priv; return priv->title;}/** * webkit_web_frame_get_uri: * @frame: a #WebKitWebFrame * * Returns the current URI of the contents displayed by the @frame * * Return value: the URI of @frame */G_CONST_RETURN gchar* webkit_web_frame_get_uri(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); WebKitWebFramePrivate* priv = frame->priv; return priv->uri;}/** * webkit_web_frame_get_web_view: * @frame: a #WebKitWebFrame * * Returns the #WebKitWebView that manages this #WebKitWebFrame. * * The #WebKitWebView returned manages the entire hierarchy of #WebKitWebFrame * objects that contains @frame. * * Return value: the #WebKitWebView that manages @frame */WebKitWebView* webkit_web_frame_get_web_view(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); WebKitWebFramePrivate* priv = frame->priv; return priv->webView;}/** * webkit_web_frame_get_name: * @frame: a #WebKitWebFrame * * Returns the @frame's name * * Return value: the name of @frame */G_CONST_RETURN gchar* webkit_web_frame_get_name(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); WebKitWebFramePrivate* priv = frame->priv; if (priv->name) return priv->name; Frame* coreFrame = core(frame); if (!coreFrame) return ""; String string = coreFrame->tree()->name(); priv->name = g_strdup(string.utf8().data()); return priv->name;}/** * webkit_web_frame_get_parent: * @frame: a #WebKitWebFrame * * Returns the @frame's parent frame, or %NULL if it has none. * * Return value: the parent #WebKitWebFrame or %NULL in case there is none */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -