4 Copyright 2001, Apple, Inc. All rights reserved.
6 #import <Cocoa/Cocoa.h>
8 #import <WebKit/IFWebFrame.h>
9 #import <WebKit/IFWebFramePrivate.h>
10 #import <WebKit/IFWebViewPrivate.h>
11 #import <WebKit/IFWebDataSourcePrivate.h>
12 #import <WebKit/IFBaseWebControllerPrivate.h>
13 #import <WebKit/IFWebController.h>
14 #import <WebKit/IFLocationChangeHandler.h>
15 #import <WebKit/IFDownloadHandler.h>
16 #import <WebFoundation/WebFoundation.h>
18 #import <WebKit/WebKitDebug.h>
20 #import <khtml_part.h>
21 #import <rendering/render_frames.h>
23 @implementation IFWebFrame
27 return [self initWithName: nil view: nil provisionalDataSource: nil controller: nil];
30 - initWithName: (NSString *)n view: v provisionalDataSource: (IFWebDataSource *)d controller: (id<IFWebController>)c
34 _private = [[IFWebFramePrivate alloc] init];
36 [self _setState: IFWEBFRAMESTATE_UNINITIALIZED];
38 [self setController: c];
40 // Allow controller to override?
41 if (d && [self setProvisionalDataSource: d] == NO){
46 [_private setName: n];
62 return [_private name];
68 [_private setView: v];
69 [v _setController: [self controller]];
74 return [_private view];
77 - (id <IFWebController>)controller
79 return [_private controller];
83 - (void)setController: (id <IFWebController>)controller
85 [_private setController: controller];
89 - (IFWebDataSource *)provisionalDataSource
91 return [_private provisionalDataSource];
95 - (IFWebDataSource *)dataSource
97 return [_private dataSource];
101 // FIXME: The name of this method is a little misleading, perhaps
102 // we could call it prepareProvisionalDataSource?.
103 - (BOOL)setProvisionalDataSource: (IFWebDataSource *)newDataSource
105 IFWebDataSource *oldDataSource;
106 id <IFLocationChangeHandler>locationChangeHandler;
107 IFURLPolicy urlPolicy;
109 WEBKIT_ASSERT ([self controller] != nil);
111 // Unfortunately the view must be non-nil, this is ultimately due
112 // to KDE parser requiring a KHTMLView. Once we settle on a final
113 // KDE drop we should fix this dependency.
114 WEBKIT_ASSERT ([self view] != nil);
116 urlPolicy = [[self controller] URLPolicyForURL:[newDataSource inputURL]];
118 if(urlPolicy == IFURLPolicyUseContentPolicy){
120 if ([self _state] != IFWEBFRAMESTATE_COMPLETE){
124 locationChangeHandler = [[self controller] provideLocationChangeHandlerForFrame: self];
126 [newDataSource _setLocationChangeHandler: locationChangeHandler];
128 oldDataSource = [self dataSource];
130 // Is this the top frame? If so set the data source's parent to nil.
131 if (self == [[self controller] mainFrame])
132 [newDataSource _setParent: nil];
134 // Otherwise set the new data source's parent to the old data source's parent.
135 else if (oldDataSource && oldDataSource != newDataSource)
136 [newDataSource _setParent: [oldDataSource parent]];
138 [newDataSource _setController: [self controller]];
140 [_private setProvisionalDataSource: newDataSource];
142 [[self view] provisionalDataSourceChanged: newDataSource];
145 // This introduces a nasty dependency on the view.
146 khtml::RenderPart *renderPartFrame = [self _renderFramePart];
147 id view = [self view];
148 if (renderPartFrame && [view isKindOfClass: NSClassFromString(@"IFWebView")])
149 renderPartFrame->setWidget ([view _provisionalWidget]);
152 [self _setState: IFWEBFRAMESTATE_PROVISIONAL];
155 else if(urlPolicy == IFURLPolicyOpenExternally){
156 return [[NSWorkspace sharedWorkspace] openURL:[newDataSource inputURL]];
159 // Do nothing in the IFURLPolicyIgnore case.
167 if (self == [[self controller] mainFrame])
168 WEBKITDEBUGLEVEL (WEBKIT_LOG_DOCUMENTLOAD, "loading %s", [[[[self provisionalDataSource] inputURL] absoluteString] cString]);
170 // Force refresh is irrelevant, as this will always be the first load.
171 // The controller will transition the provisional data source to the
172 // committed data source.
173 [_private->provisionalDataSource startLoading: NO];
179 [_private->provisionalDataSource stopLoading];
180 [_private->dataSource stopLoading];
184 - (void)reload: (BOOL)forceRefresh
186 [_private->dataSource _clearErrors];
188 [_private->dataSource startLoading: forceRefresh];
194 [_private setDataSource: nil];
195 [[_private view] _resetWidget];
196 [_private setView: nil];
199 - (IFWebFrame *)frameNamed:(NSString *)name
201 if([name isEqualToString:@"_self"] || [name isEqualToString:@"_current"])
204 else if([name isEqualToString:@"_top"])
205 return [[self controller] mainFrame];
207 else if([name isEqualToString:@"_parent"]){
208 if([[self dataSource] parent]){
209 return [[[self dataSource] parent] webFrame];
214 return [[self controller] frameNamed:name];