2
* Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14
* its contributors may be used to endorse or promote products derived
15
* from this software without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
#import "WebFrameInternal.h"
31
#import "DOMCSSStyleDeclarationInternal.h"
32
#import "DOMDocumentFragmentInternal.h"
33
#import "DOMDocumentInternal.h"
34
#import "DOMElementInternal.h"
35
#import "DOMHTMLElementInternal.h"
36
#import "DOMNodeInternal.h"
37
#import "DOMRangeInternal.h"
38
#import "WebArchiveInternal.h"
39
#import "WebChromeClient.h"
40
#import "WebDataSourceInternal.h"
41
#import "WebDocumentLoaderMac.h"
42
#import "WebDynamicScrollBarsView.h"
43
#import "WebFrameLoaderClient.h"
44
#import "WebFrameViewInternal.h"
45
#import "WebHTMLView.h"
46
#import "WebHTMLViewInternal.h"
47
#import "WebKitStatisticsPrivate.h"
48
#import "WebKitVersionChecks.h"
49
#import "WebNSObjectExtras.h"
50
#import "WebNSURLExtras.h"
51
#import "WebScriptDebugger.h"
52
#import "WebScriptWorldInternal.h"
53
#import "WebViewInternal.h"
54
#import <JavaScriptCore/APICast.h>
55
#import <WebCore/AXObjectCache.h>
56
#import <WebCore/AccessibilityObject.h>
57
#import <WebCore/AnimationController.h>
58
#import <WebCore/CSSStyleDeclaration.h>
59
#import <WebCore/CachedResourceLoader.h>
60
#import <WebCore/Chrome.h>
61
#import <WebCore/ColorMac.h>
62
#import <WebCore/DOMImplementation.h>
63
#import <WebCore/DatabaseContext.h>
64
#import <WebCore/DocumentFragment.h>
65
#import <WebCore/DocumentLoader.h>
66
#import <WebCore/DocumentMarkerController.h>
67
#import <WebCore/EventHandler.h>
68
#import <WebCore/EventNames.h>
69
#import <WebCore/Frame.h>
70
#import <WebCore/FrameLoadRequest.h>
71
#import <WebCore/FrameLoader.h>
72
#import <WebCore/FrameLoaderStateMachine.h>
73
#import <WebCore/FrameTree.h>
74
#import <WebCore/GraphicsContext.h>
75
#import <WebCore/HTMLFrameOwnerElement.h>
76
#import <WebCore/HTMLNames.h>
77
#import <WebCore/HistoryItem.h>
78
#import <WebCore/HitTestResult.h>
79
#import <WebCore/LegacyWebArchive.h>
80
#import <WebCore/Page.h>
81
#import <WebCore/PlatformEventFactoryMac.h>
82
#import <WebCore/PluginData.h>
83
#import <WebCore/PrintContext.h>
84
#import <WebCore/RenderPart.h>
85
#import <WebCore/RenderView.h>
86
#import <WebCore/RuntimeApplicationChecks.h>
87
#import <WebCore/ScriptValue.h>
88
#import <WebCore/SecurityOrigin.h>
89
#import <WebCore/SmartReplace.h>
90
#import <WebCore/TextIterator.h>
91
#import <WebCore/ThreadCheck.h>
92
#import <WebCore/htmlediting.h>
93
#import <WebCore/markup.h>
94
#import <WebCore/visible_units.h>
95
#import <WebKitSystemInterface.h>
96
#import <runtime/JSLock.h>
97
#import <runtime/JSObject.h>
98
#import <runtime/JSValue.h>
99
#import <wtf/CurrentTime.h>
102
using namespace WebCore;
103
using namespace HTMLNames;
105
using JSC::JSGlobalObject;
110
Here is the current behavior matrix for four types of navigations:
114
Restore form state: YES
115
Restore scroll and focus state: YES
116
Cache policy: NSURLRequestUseProtocolCachePolicy
117
Add to back/forward list: YES
121
Restore form state: YES
122
Restore scroll and focus state: YES
123
Cache policy: NSURLRequestReturnCacheDataElseLoad
124
Add to back/forward list: NO
126
Reload (meaning only the reload button):
128
Restore form state: NO
129
Restore scroll and focus state: YES
130
Cache policy: NSURLRequestReloadIgnoringCacheData
131
Add to back/forward list: NO
133
Repeat load of the same URL (by any other means of navigation other than the reload button, including hitting return in the location field):
135
Restore form state: NO
136
Restore scroll and focus state: NO, reset to initial conditions
137
Cache policy: NSURLRequestReloadIgnoringCacheData
138
Add to back/forward list: NO
141
NSString *WebPageCacheEntryDateKey = @"WebPageCacheEntryDateKey";
142
NSString *WebPageCacheDataSourceKey = @"WebPageCacheDataSourceKey";
143
NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
145
NSString *WebFrameMainDocumentError = @"WebFrameMainDocumentErrorKey";
146
NSString *WebFrameHasPlugins = @"WebFrameHasPluginsKey";
147
NSString *WebFrameHasUnloadListener = @"WebFrameHasUnloadListenerKey";
148
NSString *WebFrameUsesDatabases = @"WebFrameUsesDatabasesKey";
149
NSString *WebFrameUsesGeolocation = @"WebFrameUsesGeolocationKey";
150
NSString *WebFrameUsesApplicationCache = @"WebFrameUsesApplicationCacheKey";
151
NSString *WebFrameCanSuspendActiveDOMObjects = @"WebFrameCanSuspendActiveDOMObjectsKey";
153
// FIXME: Remove when this key becomes publicly defined
154
NSString *NSAccessibilityEnhancedUserInterfaceAttribute = @"AXEnhancedUserInterface";
156
@implementation WebFramePrivate
160
[webFrameView release];
162
delete scriptDebugger;
169
delete scriptDebugger;
174
- (void)setWebFrameView:(WebFrameView *)v
177
[webFrameView release];
183
EditableLinkBehavior core(WebKitEditableLinkBehavior editableLinkBehavior)
185
switch (editableLinkBehavior) {
186
case WebKitEditableLinkDefaultBehavior:
187
return EditableLinkDefaultBehavior;
188
case WebKitEditableLinkAlwaysLive:
189
return EditableLinkAlwaysLive;
190
case WebKitEditableLinkOnlyLiveWithShiftKey:
191
return EditableLinkOnlyLiveWithShiftKey;
192
case WebKitEditableLinkLiveWhenNotFocused:
193
return EditableLinkLiveWhenNotFocused;
194
case WebKitEditableLinkNeverLive:
195
return EditableLinkNeverLive;
197
ASSERT_NOT_REACHED();
198
return EditableLinkDefaultBehavior;
201
TextDirectionSubmenuInclusionBehavior core(WebTextDirectionSubmenuInclusionBehavior behavior)
204
case WebTextDirectionSubmenuNeverIncluded:
205
return TextDirectionSubmenuNeverIncluded;
206
case WebTextDirectionSubmenuAutomaticallyIncluded:
207
return TextDirectionSubmenuAutomaticallyIncluded;
208
case WebTextDirectionSubmenuAlwaysIncluded:
209
return TextDirectionSubmenuAlwaysIncluded;
211
ASSERT_NOT_REACHED();
212
return TextDirectionSubmenuNeverIncluded;
215
@implementation WebFrame (WebInternal)
217
Frame* core(WebFrame *frame)
219
return frame ? frame->_private->coreFrame : 0;
222
WebFrame *kit(Frame* frame)
224
return frame ? static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame() : nil;
227
Page* core(WebView *webView)
229
return [webView page];
232
WebView *kit(Page* page)
234
return page ? static_cast<WebView*>(page->chrome()->client()->webView()) : nil;
237
WebView *getWebView(WebFrame *webFrame)
239
Frame* coreFrame = core(webFrame);
242
return kit(coreFrame->page());
245
+ (PassRefPtr<Frame>)_createFrameWithPage:(Page*)page frameName:(const String&)name frameView:(WebFrameView *)frameView ownerElement:(HTMLFrameOwnerElement*)ownerElement
247
WebView *webView = kit(page);
249
WebFrame *frame = [[self alloc] _initWithWebFrameView:frameView webView:webView];
250
RefPtr<Frame> coreFrame = Frame::create(page, ownerElement, new WebFrameLoaderClient(frame));
252
frame->_private->coreFrame = coreFrame.get();
254
coreFrame->tree()->setName(name);
256
ASSERT(ownerElement->document()->frame());
257
ownerElement->document()->frame()->tree()->appendChild(coreFrame.get());
262
[webView _setZoomMultiplier:[webView _realZoomMultiplier] isTextOnly:[webView _realZoomMultiplierIsTextOnly]];
264
return coreFrame.release();
267
+ (void)_createMainFrameWithPage:(Page*)page frameName:(const String&)name frameView:(WebFrameView *)frameView
269
[self _createFrameWithPage:page frameName:name frameView:frameView ownerElement:0];
272
+ (PassRefPtr<WebCore::Frame>)_createSubframeWithOwnerElement:(HTMLFrameOwnerElement*)ownerElement frameName:(const String&)name frameView:(WebFrameView *)frameView
274
return [self _createFrameWithPage:ownerElement->document()->frame()->page() frameName:name frameView:frameView ownerElement:ownerElement];
277
- (BOOL)_isIncludedInWebKitStatistics
279
return _private && _private->includedInWebKitStatistics;
282
- (void)_attachScriptDebugger
284
ScriptController* scriptController = _private->coreFrame->script();
286
// Calling ScriptController::globalObject() would create a window shell, and dispatch corresponding callbacks, which may be premature
287
// if the script debugger is attached before a document is created. These calls use the debuggerWorld(), we will need to pass a world
288
// to be able to debug isolated worlds.
289
if (!scriptController->existingWindowShell(debuggerWorld()))
292
JSGlobalObject* globalObject = scriptController->globalObject(debuggerWorld());
296
if (_private->scriptDebugger) {
297
ASSERT(_private->scriptDebugger == globalObject->debugger());
301
_private->scriptDebugger = new WebScriptDebugger(globalObject);
304
- (void)_detachScriptDebugger
306
if (!_private->scriptDebugger)
309
delete _private->scriptDebugger;
310
_private->scriptDebugger = 0;
313
- (id)_initWithWebFrameView:(WebFrameView *)fv webView:(WebView *)v
319
_private = [[WebFramePrivate alloc] init];
321
// Set includedInWebKitStatistics before calling WebFrameView _setWebFrame, since
322
// it calls WebFrame _isIncludedInWebKitStatistics.
323
if ((_private->includedInWebKitStatistics = [[v class] shouldIncludeInWebKitStatistics]))
327
[_private setWebFrameView:fv];
328
[fv _setWebFrame:self];
331
_private->shouldCreateRenderers = YES;
336
- (void)_clearCoreFrame
338
_private->coreFrame = 0;
341
- (void)_updateBackgroundAndUpdatesWhileOffscreen
343
WebView *webView = getWebView(self);
344
BOOL drawsBackground = [webView drawsBackground];
345
NSColor *backgroundColor = [webView backgroundColor];
347
Frame* coreFrame = _private->coreFrame;
348
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
349
// Don't call setDrawsBackground:YES here because it may be NO because of a load
350
// in progress; WebFrameLoaderClient keeps it set to NO during the load process.
351
WebFrame *webFrame = kit(frame);
352
if (!drawsBackground)
353
[[[webFrame frameView] _scrollView] setDrawsBackground:NO];
354
[[[webFrame frameView] _scrollView] setBackgroundColor:backgroundColor];
355
id documentView = [[webFrame frameView] documentView];
356
if ([documentView respondsToSelector:@selector(setDrawsBackground:)])
357
[documentView setDrawsBackground:drawsBackground];
358
if ([documentView respondsToSelector:@selector(setBackgroundColor:)])
359
[documentView setBackgroundColor:backgroundColor];
361
if (FrameView* view = frame->view()) {
362
view->setTransparent(!drawsBackground);
363
view->setBaseBackgroundColor(colorFromNSColor([backgroundColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]));
364
view->setShouldUpdateWhileOffscreen([webView shouldUpdateWhileOffscreen]);
369
- (void)_setInternalLoadDelegate:(id)internalLoadDelegate
371
_private->internalLoadDelegate = internalLoadDelegate;
374
- (id)_internalLoadDelegate
376
return _private->internalLoadDelegate;
379
- (void)_unmarkAllBadGrammar
381
Frame* coreFrame = _private->coreFrame;
382
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
383
if (Document* document = frame->document())
384
document->markers()->removeMarkers(DocumentMarker::Grammar);
388
- (void)_unmarkAllMisspellings
390
Frame* coreFrame = _private->coreFrame;
391
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
392
if (Document* document = frame->document())
393
document->markers()->removeMarkers(DocumentMarker::Spelling);
397
- (BOOL)_hasSelection
399
id documentView = [_private->webFrameView documentView];
401
// optimization for common case to avoid creating potentially large selection string
402
if ([documentView isKindOfClass:[WebHTMLView class]])
403
if (Frame* coreFrame = _private->coreFrame)
404
return coreFrame->selection()->isRange();
406
if ([documentView conformsToProtocol:@protocol(WebDocumentText)])
407
return [[documentView selectedString] length] > 0;
412
- (void)_clearSelection
414
id documentView = [_private->webFrameView documentView];
415
if ([documentView conformsToProtocol:@protocol(WebDocumentText)])
416
[documentView deselectAll];
420
- (BOOL)_atMostOneFrameHasSelection
422
// FIXME: 4186050 is one known case that makes this debug check fail.
424
Frame* coreFrame = _private->coreFrame;
425
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame))
426
if ([kit(frame) _hasSelection]) {
435
- (WebFrame *)_findFrameWithSelection
437
Frame* coreFrame = _private->coreFrame;
438
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
439
WebFrame *webFrame = kit(frame);
440
if ([webFrame _hasSelection])
446
- (void)_clearSelectionInOtherFrames
448
// We rely on WebDocumentSelection protocol implementors to call this method when they become first
449
// responder. It would be nicer to just notice first responder changes here instead, but there's no
450
// notification sent when the first responder changes in general (Radar 2573089).
451
WebFrame *frameWithSelection = [[getWebView(self) mainFrame] _findFrameWithSelection];
452
if (frameWithSelection != self)
453
[frameWithSelection _clearSelection];
455
// While we're in the general area of selection and frames, check that there is only one now.
456
ASSERT([[getWebView(self) mainFrame] _atMostOneFrameHasSelection]);
459
static inline WebDataSource *dataSource(DocumentLoader* loader)
461
return loader ? static_cast<WebDocumentLoaderMac*>(loader)->dataSource() : nil;
464
- (WebDataSource *)_dataSource
466
return dataSource(_private->coreFrame->loader()->documentLoader());
469
- (NSString *)_stringWithDocumentTypeStringAndMarkupString:(NSString *)markupString
471
return String(_private->coreFrame->documentTypeString() + String(markupString));
474
- (NSArray *)_nodesFromList:(Vector<Node*> *)nodesVector
476
size_t size = nodesVector->size();
477
NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:size];
478
for (size_t i = 0; i < size; ++i)
479
[nodes addObject:kit((*nodesVector)[i])];
483
- (NSString *)_markupStringFromRange:(DOMRange *)range nodes:(NSArray **)nodes
485
// FIXME: This is always "for interchange". Is that right? See the previous method.
486
Vector<Node*> nodeList;
487
NSString *markupString = createMarkup(core(range), nodes ? &nodeList : 0, AnnotateForInterchange);
489
*nodes = [self _nodesFromList:&nodeList];
491
return [self _stringWithDocumentTypeStringAndMarkupString:markupString];
494
- (NSString *)_selectedString
496
return _private->coreFrame->displayStringModifiedByEncoding(_private->coreFrame->editor()->selectedText());
499
- (NSString *)_stringForRange:(DOMRange *)range
501
return plainText(core(range), TextIteratorDefaultBehavior, true);
504
- (BOOL)_shouldFlattenCompositingLayers:(CGContextRef)context
506
// -currentContextDrawingToScreen returns YES for bitmap contexts.
507
BOOL isPrinting = ![NSGraphicsContext currentContextDrawingToScreen];
511
if (!WKCGContextIsBitmapContext(context))
514
// If we're drawing into a bitmap, we might be snapshotting, or drawing into a layer-backed view.
515
id documentView = [_private->webFrameView documentView];
516
if ([documentView isKindOfClass:[WebHTMLView class]] && [(WebHTMLView *)documentView _web_isDrawingIntoLayer])
519
return [getWebView(self) _includesFlattenedCompositingLayersWhenDrawingToBitmap];
522
- (void)_drawRect:(NSRect)rect contentsOnly:(BOOL)contentsOnly
524
ASSERT([[NSGraphicsContext currentContext] isFlipped]);
526
CGContextRef ctx = static_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
527
GraphicsContext context(ctx);
529
FrameView* view = _private->coreFrame->view();
531
bool shouldFlatten = false;
532
if (Frame* parentFrame = _private->coreFrame->tree()->parent()) {
533
// For subframes, we need to inherit the paint behavior from our parent
534
FrameView* parentView = parentFrame ? parentFrame->view() : 0;
536
shouldFlatten = parentView->paintBehavior() & PaintBehaviorFlattenCompositingLayers;
538
shouldFlatten = [self _shouldFlattenCompositingLayers:ctx];
540
PaintBehavior oldBehavior = PaintBehaviorNormal;
542
oldBehavior = view->paintBehavior();
543
view->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
547
view->paintContents(&context, enclosingIntRect(rect));
549
view->paint(&context, enclosingIntRect(rect));
552
view->setPaintBehavior(oldBehavior);
555
- (BOOL)_getVisibleRect:(NSRect*)rect
557
ASSERT_ARG(rect, rect);
558
if (RenderPart* ownerRenderer = _private->coreFrame->ownerRenderer()) {
559
if (ownerRenderer->needsLayout())
561
*rect = ownerRenderer->pixelSnappedAbsoluteClippedOverflowRect();
568
- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string
570
return [self _stringByEvaluatingJavaScriptFromString:string forceUserGesture:true];
573
- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string forceUserGesture:(BOOL)forceUserGesture
578
ASSERT(_private->coreFrame->document());
579
RetainPtr<WebFrame> protect(self); // Executing arbitrary JavaScript can destroy the frame.
581
JSValue result = _private->coreFrame->script()->executeScript(string, forceUserGesture).jsValue();
583
if (!_private->coreFrame) // In case the script removed our frame from the page.
586
// This bizarre set of rules matches behavior from WebKit for Safari 2.0.
587
// If you don't like it, use -[WebScriptObject evaluateWebScript:] or
588
// JSEvaluateScript instead, since they have less surprising semantics.
589
if (!result || (!result.isBoolean() && !result.isString() && !result.isNumber()))
592
JSC::ExecState* exec = _private->coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec();
593
JSC::JSLockHolder lock(exec);
594
return result.toWTFString(exec);
597
- (NSRect)_caretRectAtPosition:(const Position&)pos affinity:(NSSelectionAffinity)affinity
599
VisiblePosition visiblePosition(pos, static_cast<EAffinity>(affinity));
600
return visiblePosition.absoluteCaretBounds();
603
- (NSRect)_firstRectForDOMRange:(DOMRange *)range
605
return _private->coreFrame->editor()->firstRectForRange(core(range));
608
- (void)_scrollDOMRangeToVisible:(DOMRange *)range
610
NSRect rangeRect = [self _firstRectForDOMRange:range];
611
Node *startNode = core([range startContainer]);
613
if (startNode && startNode->renderer())
614
startNode->renderer()->scrollRectToVisible(enclosingIntRect(rangeRect), ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
619
return _private->coreFrame->view() ? _private->coreFrame->view()->needsLayout() : false;
622
- (DOMRange *)_rangeByAlteringCurrentSelection:(FrameSelection::EAlteration)alteration direction:(SelectionDirection)direction granularity:(TextGranularity)granularity
624
if (_private->coreFrame->selection()->isNone())
627
FrameSelection selection;
628
selection.setSelection(_private->coreFrame->selection()->selection());
629
selection.modify(alteration, direction, granularity);
630
return kit(selection.toNormalizedRange().get());
633
- (TextGranularity)_selectionGranularity
635
return _private->coreFrame->selection()->granularity();
638
- (NSRange)_convertToNSRange:(Range *)range
641
return NSMakeRange(NSNotFound, 0);
645
if (!TextIterator::getLocationAndLengthFromRange(_private->coreFrame->selection()->rootEditableElementOrDocumentElement(), range, location, length))
646
return NSMakeRange(NSNotFound, 0);
648
return NSMakeRange(location, length);
651
- (PassRefPtr<Range>)_convertToDOMRange:(NSRange)nsrange
653
if (nsrange.location > INT_MAX)
655
if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
656
nsrange.length = INT_MAX - nsrange.location;
658
// our critical assumption is that we are only called by input methods that
659
// concentrate on a given area containing the selection
660
// We have to do this because of text fields and textareas. The DOM for those is not
661
// directly in the document DOM, so serialization is problematic. Our solution is
662
// to use the root editable element of the selection start as the positional base.
663
// That fits with AppKit's idea of an input context.
664
return TextIterator::rangeFromLocationAndLength(_private->coreFrame->selection()->rootEditableElementOrDocumentElement(), nsrange.location, nsrange.length);
667
- (DOMRange *)_convertNSRangeToDOMRange:(NSRange)nsrange
669
return kit([self _convertToDOMRange:nsrange].get());
672
- (NSRange)_convertDOMRangeToNSRange:(DOMRange *)range
674
return [self _convertToNSRange:core(range)];
677
- (DOMRange *)_markDOMRange
679
return kit(_private->coreFrame->editor()->mark().toNormalizedRange().get());
682
// Given proposedRange, returns an extended range that includes adjacent whitespace that should
683
// be deleted along with the proposed range in order to preserve proper spacing and punctuation of
684
// the text surrounding the deletion.
685
- (DOMRange *)_smartDeleteRangeForProposedRange:(DOMRange *)proposedRange
687
Node* startContainer = core([proposedRange startContainer]);
688
Node* endContainer = core([proposedRange endContainer]);
689
if (startContainer == nil || endContainer == nil)
692
ASSERT(startContainer->document() == endContainer->document());
694
_private->coreFrame->document()->updateLayoutIgnorePendingStylesheets();
696
Position start = Position(startContainer, [proposedRange startOffset], Position::PositionIsOffsetInAnchor);
697
Position end = Position(endContainer, [proposedRange endOffset], Position::PositionIsOffsetInAnchor);
698
Position newStart = start.upstream().leadingWhitespacePosition(DOWNSTREAM, true);
699
if (newStart.isNull())
701
Position newEnd = end.downstream().trailingWhitespacePosition(DOWNSTREAM, true);
705
newStart = newStart.parentAnchoredEquivalent();
706
newEnd = newEnd.parentAnchoredEquivalent();
708
RefPtr<Range> range = _private->coreFrame->document()->createRange();
710
range->setStart(newStart.containerNode(), newStart.offsetInContainerNode(), exception);
711
range->setEnd(newStart.containerNode(), newStart.offsetInContainerNode(), exception);
712
return kit(range.get());
715
- (DOMDocumentFragment *)_documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString
717
if (!_private->coreFrame || !_private->coreFrame->document())
720
return kit(createFragmentFromMarkup(_private->coreFrame->document(), markupString, baseURLString, DisallowScriptingContent).get());
723
- (DOMDocumentFragment *)_documentFragmentWithNodesAsParagraphs:(NSArray *)nodes
725
if (!_private->coreFrame || !_private->coreFrame->document())
728
NSEnumerator *nodeEnum = [nodes objectEnumerator];
729
Vector<Node*> nodesVector;
731
while ((node = [nodeEnum nextObject]))
732
nodesVector.append(core(node));
734
return kit(createFragmentFromNodes(_private->coreFrame->document(), nodesVector).get());
737
- (void)_replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
739
DOMDocumentFragment *fragment = kit(_private->coreFrame->document()->createDocumentFragment().get());
740
[fragment appendChild:node];
741
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:matchStyle];
744
- (void)_insertParagraphSeparatorInQuotedContent
746
if (_private->coreFrame->selection()->isNone())
749
_private->coreFrame->editor()->insertParagraphSeparatorInQuotedContent();
752
- (VisiblePosition)_visiblePositionForPoint:(NSPoint)point
754
// FIXME: Someone with access to Apple's sources could remove this needless wrapper call.
755
return _private->coreFrame->visiblePositionForPoint(IntPoint(point));
758
- (DOMRange *)_characterRangeAtPoint:(NSPoint)point
760
return kit(_private->coreFrame->rangeForPoint(IntPoint(point)).get());
763
- (DOMCSSStyleDeclaration *)_typingStyle
765
if (!_private->coreFrame)
767
RefPtr<StylePropertySet> typingStyle = _private->coreFrame->selection()->copyTypingStyle();
770
return kit(typingStyle->ensureCSSStyleDeclaration());
773
- (void)_setTypingStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
775
if (!_private->coreFrame || !style)
777
// FIXME: We shouldn't have to create a copy here.
778
_private->coreFrame->editor()->computeAndSetTypingStyle(core(style)->copy().get(), undoAction);
781
#if ENABLE(DRAG_SUPPORT)
782
- (void)_dragSourceEndedAt:(NSPoint)windowLoc operation:(NSDragOperation)operation
784
if (!_private->coreFrame)
786
FrameView* view = _private->coreFrame->view();
789
// FIXME: These are fake modifier keys here, but they should be real ones instead.
790
PlatformMouseEvent event(IntPoint(windowLoc), globalPoint(windowLoc, [view->platformWidget() window]),
791
LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, currentTime());
792
_private->coreFrame->eventHandler()->dragSourceEndedAt(event, (DragOperation)operation);
796
- (BOOL)_canProvideDocumentSource
798
Frame* frame = _private->coreFrame;
799
String mimeType = frame->document()->loader()->writer()->mimeType();
800
PluginData* pluginData = frame->page() ? frame->page()->pluginData() : 0;
802
if (WebCore::DOMImplementation::isTextMIMEType(mimeType) ||
803
Image::supportsType(mimeType) ||
804
(pluginData && pluginData->supportsMimeType(mimeType)))
810
- (BOOL)_canSaveAsWebArchive
812
// Currently, all documents that we can view source for
813
// (HTML and XML documents) can also be saved as web archives
814
return [self _canProvideDocumentSource];
817
- (void)_commitData:(NSData *)data
819
// FIXME: This really should be a setting.
820
Document* document = _private->coreFrame->document();
821
document->setShouldCreateRenderers(_private->shouldCreateRenderers);
823
_private->coreFrame->loader()->documentLoader()->commitData((const char *)[data bytes], [data length]);
828
@implementation WebFrame (WebPrivate)
830
// FIXME: This exists only as a convenience for Safari, consider moving there.
831
- (BOOL)_isDescendantOfFrame:(WebFrame *)ancestor
833
Frame* coreFrame = _private->coreFrame;
834
return coreFrame && coreFrame->tree()->isDescendantOf(core(ancestor));
837
- (void)_setShouldCreateRenderers:(BOOL)shouldCreateRenderers
839
_private->shouldCreateRenderers = shouldCreateRenderers;
842
- (NSColor *)_bodyBackgroundColor
844
Document* document = _private->coreFrame->document();
847
HTMLElement* body = document->body();
850
RenderObject* bodyRenderer = body->renderer();
853
Color color = bodyRenderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
854
if (!color.isValid())
856
return nsColor(color);
861
Document* document = _private->coreFrame->document();
862
return document && document->isFrameSet();
865
- (BOOL)_firstLayoutDone
867
return _private->coreFrame->loader()->stateMachine()->firstLayoutDone();
870
- (BOOL)_isVisuallyNonEmpty
872
if (FrameView* view = _private->coreFrame->view())
873
return view->isVisuallyNonEmpty();
877
- (WebFrameLoadType)_loadType
879
return (WebFrameLoadType)_private->coreFrame->loader()->loadType();
882
- (NSRange)_selectedNSRange
884
return [self _convertToNSRange:_private->coreFrame->selection()->toNormalizedRange().get()];
887
- (void)_selectNSRange:(NSRange)range
889
RefPtr<Range> domRange = [self _convertToDOMRange:range];
891
_private->coreFrame->selection()->setSelection(VisibleSelection(domRange.get(), SEL_DEFAULT_AFFINITY));
894
- (BOOL)_isDisplayingStandaloneImage
896
Document* document = _private->coreFrame->document();
897
return document && document->isImageDocument();
900
- (unsigned)_pendingFrameUnloadEventCount
902
return _private->coreFrame->document()->domWindow()->pendingUnloadEventListeners();
905
#if ENABLE(NETSCAPE_PLUGIN_API)
906
- (void)_recursive_resumeNullEventsForAllNetscapePlugins
908
Frame* coreFrame = core(self);
909
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
910
NSView <WebDocumentView> *documentView = [[kit(frame) frameView] documentView];
911
if ([documentView isKindOfClass:[WebHTMLView class]])
912
[(WebHTMLView *)documentView _resumeNullEventsForAllNetscapePlugins];
916
- (void)_recursive_pauseNullEventsForAllNetscapePlugins
918
Frame* coreFrame = core(self);
919
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
920
NSView <WebDocumentView> *documentView = [[kit(frame) frameView] documentView];
921
if ([documentView isKindOfClass:[WebHTMLView class]])
922
[(WebHTMLView *)documentView _pauseNullEventsForAllNetscapePlugins];
927
- (BOOL)_pauseAnimation:(NSString*)name onNode:(DOMNode *)node atTime:(NSTimeInterval)time
929
Frame* frame = core(self);
933
AnimationController* controller = frame->animation();
937
Node* coreNode = core(node);
938
if (!coreNode || !coreNode->renderer())
941
return controller->pauseAnimationAtTime(coreNode->renderer(), name, time);
944
- (BOOL)_pauseTransitionOfProperty:(NSString*)name onNode:(DOMNode*)node atTime:(NSTimeInterval)time
946
Frame* frame = core(self);
950
AnimationController* controller = frame->animation();
954
Node* coreNode = core(node);
955
if (!coreNode || !coreNode->renderer())
958
return controller->pauseTransitionAtTime(coreNode->renderer(), name, time);
961
- (unsigned) _numberOfActiveAnimations
963
Frame* frame = core(self);
967
AnimationController* controller = frame->animation();
971
return controller->numberOfActiveAnimations(frame->document());
974
- (void)_replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
976
if (_private->coreFrame->selection()->isNone() || !fragment)
978
_private->coreFrame->editor()->replaceSelectionWithFragment(core(fragment), selectReplacement, smartReplace, matchStyle);
981
- (void)_replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
983
DOMDocumentFragment* fragment = kit(createFragmentFromText(_private->coreFrame->selection()->toNormalizedRange().get(), text).get());
984
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES];
987
- (void)_replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
989
DOMDocumentFragment *fragment = [self _documentFragmentWithMarkupString:markupString baseURLString:baseURLString];
990
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:NO];
993
// Determines whether whitespace needs to be added around aString to preserve proper spacing and
994
// punctuation when it's inserted into the receiver's text over charRange. Returns by reference
995
// in beforeString and afterString any whitespace that should be added, unless either or both are
996
// nil. Both are returned as nil if aString is nil or if smart insertion and deletion are disabled.
997
- (void)_smartInsertForString:(NSString *)pasteString replacingRange:(DOMRange *)rangeToReplace beforeString:(NSString **)beforeString afterString:(NSString **)afterString
999
// give back nil pointers in case of early returns
1001
*beforeString = nil;
1005
// inspect destination
1006
Node *startContainer = core([rangeToReplace startContainer]);
1007
Node *endContainer = core([rangeToReplace endContainer]);
1009
Position startPos(startContainer, [rangeToReplace startOffset], Position::PositionIsOffsetInAnchor);
1010
Position endPos(endContainer, [rangeToReplace endOffset], Position::PositionIsOffsetInAnchor);
1012
VisiblePosition startVisiblePos = VisiblePosition(startPos, VP_DEFAULT_AFFINITY);
1013
VisiblePosition endVisiblePos = VisiblePosition(endPos, VP_DEFAULT_AFFINITY);
1015
// this check also ensures startContainer, startPos, endContainer, and endPos are non-null
1016
if (startVisiblePos.isNull() || endVisiblePos.isNull())
1019
bool addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfParagraph(startVisiblePos);
1020
if (addLeadingSpace)
1021
if (UChar previousChar = startVisiblePos.previous().characterAfter())
1022
addLeadingSpace = !isCharacterSmartReplaceExempt(previousChar, true);
1024
bool addTrailingSpace = endPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfParagraph(endVisiblePos);
1025
if (addTrailingSpace)
1026
if (UChar thisChar = endVisiblePos.characterAfter())
1027
addTrailingSpace = !isCharacterSmartReplaceExempt(thisChar, false);
1030
bool hasWhitespaceAtStart = false;
1031
bool hasWhitespaceAtEnd = false;
1032
unsigned pasteLength = [pasteString length];
1033
if (pasteLength > 0) {
1034
NSCharacterSet *whiteSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
1036
if ([whiteSet characterIsMember:[pasteString characterAtIndex:0]]) {
1037
hasWhitespaceAtStart = YES;
1039
if ([whiteSet characterIsMember:[pasteString characterAtIndex:(pasteLength - 1)]]) {
1040
hasWhitespaceAtEnd = YES;
1044
// issue the verdict
1045
if (beforeString && addLeadingSpace && !hasWhitespaceAtStart)
1046
*beforeString = @" ";
1047
if (afterString && addTrailingSpace && !hasWhitespaceAtEnd)
1048
*afterString = @" ";
1051
- (NSMutableDictionary *)_cacheabilityDictionary
1053
NSMutableDictionary *result = [NSMutableDictionary dictionary];
1055
FrameLoader* frameLoader = _private->coreFrame->loader();
1056
DocumentLoader* documentLoader = frameLoader->documentLoader();
1057
if (documentLoader && !documentLoader->mainDocumentError().isNull())
1058
[result setObject:(NSError *)documentLoader->mainDocumentError() forKey:WebFrameMainDocumentError];
1060
if (frameLoader->subframeLoader()->containsPlugins())
1061
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameHasPlugins];
1063
if (DOMWindow* domWindow = _private->coreFrame->document()->domWindow()) {
1064
if (domWindow->hasEventListeners(eventNames().unloadEvent))
1065
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameHasUnloadListener];
1066
if (domWindow->optionalApplicationCache())
1067
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameUsesApplicationCache];
1070
if (Document* document = _private->coreFrame->document()) {
1071
#if ENABLE(SQL_DATABASE)
1072
if (DatabaseContext::hasOpenDatabases(document))
1073
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameUsesDatabases];
1075
if (!document->canSuspendActiveDOMObjects())
1076
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameCanSuspendActiveDOMObjects];
1082
- (BOOL)_allowsFollowingLink:(NSURL *)URL
1084
if (!_private->coreFrame)
1086
return _private->coreFrame->document()->securityOrigin()->canDisplay(URL);
1089
- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string withGlobalObject:(JSObjectRef)globalObjectRef inScriptWorld:(WebScriptWorld *)world
1094
// Start off with some guess at a frame and a global object, we'll try to do better...!
1095
JSDOMWindow* anyWorldGlobalObject = _private->coreFrame->script()->globalObject(mainThreadNormalWorld());
1097
// The global object is probably a shell object? - if so, we know how to use this!
1098
JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
1099
if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
1100
anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
1102
// Get the frame frome the global object we've settled on.
1103
Frame* frame = anyWorldGlobalObject->impl()->frame();
1104
ASSERT(frame->document());
1105
RetainPtr<WebFrame> webFrame(kit(frame)); // Running arbitrary JavaScript can destroy the frame.
1107
JSValue result = frame->script()->executeScriptInWorld(core(world), string, true).jsValue();
1109
if (!webFrame->_private->coreFrame) // In case the script removed our frame from the page.
1112
// This bizarre set of rules matches behavior from WebKit for Safari 2.0.
1113
// If you don't like it, use -[WebScriptObject evaluateWebScript:] or
1114
// JSEvaluateScript instead, since they have less surprising semantics.
1115
if (!result || (!result.isBoolean() && !result.isString() && !result.isNumber()))
1118
JSC::ExecState* exec = anyWorldGlobalObject->globalExec();
1119
JSC::JSLockHolder lock(exec);
1120
return result.toWTFString(exec);
1123
- (JSGlobalContextRef)_globalContextForScriptWorld:(WebScriptWorld *)world
1125
Frame* coreFrame = _private->coreFrame;
1128
DOMWrapperWorld* coreWorld = core(world);
1131
return toGlobalRef(coreFrame->script()->globalObject(coreWorld)->globalExec());
1134
- (void)setAllowsScrollersToOverlapContent:(BOOL)flag
1136
ASSERT([[[self frameView] _scrollView] isKindOfClass:[WebDynamicScrollBarsView class]]);
1137
[(WebDynamicScrollBarsView *)[[self frameView] _scrollView] setAllowsScrollersToOverlapContent:flag];
1140
- (void)setAlwaysHideHorizontalScroller:(BOOL)flag
1142
ASSERT([[[self frameView] _scrollView] isKindOfClass:[WebDynamicScrollBarsView class]]);
1143
[(WebDynamicScrollBarsView *)[[self frameView] _scrollView] setAlwaysHideHorizontalScroller:flag];
1145
- (void)setAlwaysHideVerticalScroller:(BOOL)flag
1147
ASSERT([[[self frameView] _scrollView] isKindOfClass:[WebDynamicScrollBarsView class]]);
1148
[(WebDynamicScrollBarsView *)[[self frameView] _scrollView] setAlwaysHideVerticalScroller:flag];
1151
- (void)setAccessibleName:(NSString *)name
1153
#if HAVE(ACCESSIBILITY)
1154
if (!AXObjectCache::accessibilityEnabled())
1157
if (!_private->coreFrame || !_private->coreFrame->document())
1160
AccessibilityObject* rootObject = _private->coreFrame->document()->axObjectCache()->rootObject();
1162
String strName(name);
1163
rootObject->setAccessibleName(strName);
1168
- (NSString*)_layerTreeAsText
1170
Frame* coreFrame = _private->coreFrame;
1174
return coreFrame->layerTreeAsText();
1177
- (id)accessibilityRoot
1179
#if HAVE(ACCESSIBILITY)
1180
if (!AXObjectCache::accessibilityEnabled()) {
1181
AXObjectCache::enableAccessibility();
1182
AXObjectCache::setEnhancedUserInterfaceAccessibility([[NSApp accessibilityAttributeValue:NSAccessibilityEnhancedUserInterfaceAttribute] boolValue]);
1185
if (!_private->coreFrame || !_private->coreFrame->document())
1188
AccessibilityObject* rootObject = _private->coreFrame->document()->axObjectCache()->rootObjectForFrame(_private->coreFrame);
1192
// The root object will be a WebCore scroll view object. In WK1, scroll views are handled
1193
// by the system and the root object should be the web area (instead of the scroll view).
1194
if (rootObject->isAttachment() && rootObject->firstChild())
1195
return rootObject->firstChild()->wrapper();
1197
return rootObject->wrapper();
1203
- (void)_clearOpener
1205
Frame* coreFrame = _private->coreFrame;
1207
coreFrame->loader()->setOpener(0);
1210
// Used by pagination code called from AppKit when a standalone web page is printed.
1211
- (NSArray *)_computePageRectsWithPrintScaleFactor:(float)printScaleFactor pageSize:(NSSize)pageSize
1213
if (printScaleFactor <= 0) {
1214
LOG_ERROR("printScaleFactor has bad value %.2f", printScaleFactor);
1215
return [NSArray array];
1218
if (!_private->coreFrame)
1219
return [NSArray array];
1220
if (!_private->coreFrame->document())
1221
return [NSArray array];
1222
if (!_private->coreFrame->view())
1223
return [NSArray array];
1224
if (!_private->coreFrame->view()->documentView())
1225
return [NSArray array];
1227
RenderView* root = toRenderView(_private->coreFrame->document()->renderer());
1229
return [NSArray array];
1231
const LayoutRect& documentRect = root->documentRect();
1232
float printWidth = root->style()->isHorizontalWritingMode() ? static_cast<float>(documentRect.width()) / printScaleFactor : pageSize.width;
1233
float printHeight = root->style()->isHorizontalWritingMode() ? pageSize.height : static_cast<float>(documentRect.height()) / printScaleFactor;
1235
PrintContext printContext(_private->coreFrame);
1236
printContext.computePageRectsWithPageSize(FloatSize(printWidth, printHeight), true);
1237
const Vector<IntRect>& pageRects = printContext.pageRects();
1239
size_t size = pageRects.size();
1240
NSMutableArray *pages = [NSMutableArray arrayWithCapacity:size];
1241
for (size_t i = 0; i < size; ++i)
1242
[pages addObject:[NSValue valueWithRect:NSRect(pageRects[i])]];
1248
@implementation WebFrame
1255
// Should be deprecated.
1256
- (id)initWithName:(NSString *)name webFrameView:(WebFrameView *)view webView:(WebView *)webView
1263
if (_private && _private->includedInWebKitStatistics)
1273
if (_private && _private->includedInWebKitStatistics)
1281
Frame* coreFrame = _private->coreFrame;
1284
return coreFrame->tree()->uniqueName();
1287
- (WebFrameView *)frameView
1289
return _private->webFrameView;
1292
- (WebView *)webView
1294
return getWebView(self);
1297
static bool needsMicrosoftMessengerDOMDocumentWorkaround()
1299
static bool needsWorkaround = applicationIsMicrosoftMessenger() && [[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey] compare:@"7.1" options:NSNumericSearch] == NSOrderedAscending;
1300
return needsWorkaround;
1303
- (DOMDocument *)DOMDocument
1305
if (needsMicrosoftMessengerDOMDocumentWorkaround() && !pthread_main_np())
1308
Frame* coreFrame = _private->coreFrame;
1312
// FIXME: <rdar://problem/5145841> When loading a custom view/representation
1313
// into a web frame, the old document can still be around. This makes sure that
1314
// we'll return nil in those cases.
1315
if (![[self _dataSource] _isDocumentHTML])
1318
Document* document = coreFrame->document();
1320
// According to the documentation, we should return nil if the frame doesn't have a document.
1321
// While full-frame images and plugins do have an underlying HTML document, we return nil here to be
1322
// backwards compatible.
1323
if (document && (document->isPluginDocument() || document->isImageDocument()))
1326
return kit(coreFrame->document());
1329
- (DOMHTMLElement *)frameElement
1331
Frame* coreFrame = _private->coreFrame;
1334
return kit(coreFrame->ownerElement());
1337
- (WebDataSource *)provisionalDataSource
1339
Frame* coreFrame = _private->coreFrame;
1340
return coreFrame ? dataSource(coreFrame->loader()->provisionalDocumentLoader()) : nil;
1343
- (WebDataSource *)dataSource
1345
Frame* coreFrame = _private->coreFrame;
1346
return coreFrame && coreFrame->loader()->frameHasLoaded() ? [self _dataSource] : nil;
1349
- (void)loadRequest:(NSURLRequest *)request
1351
Frame* coreFrame = _private->coreFrame;
1355
ResourceRequest resourceRequest(request);
1357
// Some users of WebKit API incorrectly use "file path as URL" style requests which are invalid.
1358
// By re-writing those URLs here we technically break the -[WebDataSource initialRequest] API
1359
// but that is necessary to implement this quirk only at the API boundary.
1360
// Note that other users of WebKit API use nil requests or requests with nil URLs or empty URLs, so we
1361
// only implement this workaround when the request had a non-nil or non-empty URL.
1362
if (!resourceRequest.url().isValid() && !resourceRequest.url().isEmpty())
1363
resourceRequest.setURL([NSURL URLWithString:[@"file:" stringByAppendingString:[[request URL] absoluteString]]]);
1365
coreFrame->loader()->load(FrameLoadRequest(coreFrame, resourceRequest));
1368
static NSURL *createUniqueWebDataURL()
1370
CFUUIDRef UUIDRef = CFUUIDCreate(kCFAllocatorDefault);
1371
NSString *UUIDString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, UUIDRef);
1373
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"applewebdata://%@", UUIDString]];
1374
CFRelease(UUIDString);
1378
- (void)_loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL unreachableURL:(NSURL *)unreachableURL
1380
if (!pthread_main_np())
1381
return [[self _webkit_invokeOnMainThread] _loadData:data MIMEType:MIMEType textEncodingName:encodingName baseURL:baseURL unreachableURL:unreachableURL];
1385
baseURL = blankURL();
1386
responseURL = createUniqueWebDataURL();
1389
ResourceRequest request([baseURL absoluteURL]);
1391
// hack because Mail checks for this property to detect data / archive loads
1392
[NSURLProtocol setProperty:@"" forKey:@"WebDataRequest" inRequest:(NSMutableURLRequest *)request.nsURLRequest()];
1394
SubstituteData substituteData(WebCore::SharedBuffer::wrapNSData(data), MIMEType, encodingName, [unreachableURL absoluteURL], responseURL);
1396
_private->coreFrame->loader()->load(FrameLoadRequest(_private->coreFrame, request, substituteData));
1400
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
1402
WebCoreThreadViolationCheckRoundTwo();
1405
MIMEType = @"text/html";
1406
[self _loadData:data MIMEType:MIMEType textEncodingName:encodingName baseURL:[baseURL _webkit_URLFromURLOrSchemelessFileURL] unreachableURL:nil];
1409
- (void)_loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL unreachableURL:(NSURL *)unreachableURL
1411
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
1412
[self _loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL unreachableURL:unreachableURL];
1415
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
1417
WebCoreThreadViolationCheckRoundTwo();
1419
[self _loadHTMLString:string baseURL:[baseURL _webkit_URLFromURLOrSchemelessFileURL] unreachableURL:nil];
1422
- (void)loadAlternateHTMLString:(NSString *)string baseURL:(NSURL *)baseURL forUnreachableURL:(NSURL *)unreachableURL
1424
WebCoreThreadViolationCheckRoundTwo();
1426
[self _loadHTMLString:string baseURL:[baseURL _webkit_URLFromURLOrSchemelessFileURL] unreachableURL:[unreachableURL _webkit_URLFromURLOrSchemelessFileURL]];
1429
- (void)loadArchive:(WebArchive *)archive
1431
if (LegacyWebArchive* coreArchive = [archive _coreLegacyWebArchive])
1432
_private->coreFrame->loader()->loadArchive(coreArchive);
1437
if (!_private->coreFrame)
1439
_private->coreFrame->loader()->stopForUserCancel();
1444
if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_RELOAD_FROM_ORIGIN) && applicationIsSafari())
1445
_private->coreFrame->loader()->reload(GetCurrentKeyModifiers() & shiftKey);
1447
_private->coreFrame->loader()->reload(false);
1450
- (void)reloadFromOrigin
1452
_private->coreFrame->loader()->reload(true);
1455
- (WebFrame *)findFrameNamed:(NSString *)name
1457
Frame* coreFrame = _private->coreFrame;
1460
return kit(coreFrame->tree()->find(name));
1463
- (WebFrame *)parentFrame
1465
Frame* coreFrame = _private->coreFrame;
1468
return [[kit(coreFrame->tree()->parent()) retain] autorelease];
1471
- (NSArray *)childFrames
1473
Frame* coreFrame = _private->coreFrame;
1475
return [NSArray array];
1476
NSMutableArray *children = [NSMutableArray arrayWithCapacity:coreFrame->tree()->childCount()];
1477
for (Frame* child = coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling())
1478
[children addObject:kit(child)];
1482
- (WebScriptObject *)windowObject
1484
Frame* coreFrame = _private->coreFrame;
1487
return coreFrame->script()->windowScriptObject();
1490
- (JSGlobalContextRef)globalContext
1492
Frame* coreFrame = _private->coreFrame;
1495
return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());