1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
|
/*
* Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "WebFrameInternal.h"
#import "DOMCSSStyleDeclarationInternal.h"
#import "DOMDocumentFragmentInternal.h"
#import "DOMDocumentInternal.h"
#import "DOMElementInternal.h"
#import "DOMHTMLElementInternal.h"
#import "DOMNodeInternal.h"
#import "DOMRangeInternal.h"
#import "WebArchiveInternal.h"
#import "WebChromeClient.h"
#import "WebDataSourceInternal.h"
#import "WebDocumentLoaderMac.h"
#import "WebDynamicScrollBarsView.h"
#import "WebElementDictionary.h"
#import "WebFrameLoaderClient.h"
#import "WebFrameViewInternal.h"
#import "WebHTMLView.h"
#import "WebHTMLViewInternal.h"
#import "WebKitStatisticsPrivate.h"
#import "WebKitVersionChecks.h"
#import "WebNSObjectExtras.h"
#import "WebNSURLExtras.h"
#import "WebScriptDebugger.h"
#import "WebScriptWorldInternal.h"
#import "WebViewInternal.h"
#import <JavaScriptCore/APICast.h>
#import <JavaScriptCore/JSContextInternal.h>
#import <WebCore/AXObjectCache.h>
#import <WebCore/AccessibilityObject.h>
#import <WebCore/AnimationController.h>
#import <WebCore/CSSStyleDeclaration.h>
#import <WebCore/CachedResourceLoader.h>
#import <WebCore/Chrome.h>
#import <WebCore/ColorMac.h>
#import <WebCore/DOMImplementation.h>
#import <WebCore/DatabaseManager.h>
#import <WebCore/DocumentFragment.h>
#import <WebCore/DocumentLoader.h>
#import <WebCore/DocumentMarkerController.h>
#import <WebCore/Editor.h>
#import <WebCore/EventHandler.h>
#import <WebCore/EventNames.h>
#import <WebCore/Frame.h>
#import <WebCore/FrameLoadRequest.h>
#import <WebCore/FrameLoader.h>
#import <WebCore/FrameLoaderStateMachine.h>
#import <WebCore/FrameTree.h>
#import <WebCore/GraphicsContext.h>
#import <WebCore/HTMLFrameOwnerElement.h>
#import <WebCore/HTMLNames.h>
#import <WebCore/HistoryItem.h>
#import <WebCore/HitTestResult.h>
#import <WebCore/JSNode.h>
#import <WebCore/LegacyWebArchive.h>
#import <WebCore/Page.h>
#import <WebCore/PlatformEventFactoryMac.h>
#import <WebCore/PluginData.h>
#import <WebCore/PrintContext.h>
#import <WebCore/RenderPart.h>
#import <WebCore/RenderView.h>
#import <WebCore/RuntimeApplicationChecks.h>
#import <WebCore/ScriptController.h>
#import <WebCore/ScriptValue.h>
#import <WebCore/SecurityOrigin.h>
#import <WebCore/SmartReplace.h>
#import <WebCore/StylePropertySet.h>
#import <WebCore/TextIterator.h>
#import <WebCore/ThreadCheck.h>
#import <WebCore/VisibleUnits.h>
#import <WebCore/htmlediting.h>
#import <WebCore/markup.h>
#import <WebKitSystemInterface.h>
#import <runtime/JSLock.h>
#import <runtime/JSObject.h>
#import <runtime/JSCJSValue.h>
#import <wtf/CurrentTime.h>
using namespace WebCore;
using namespace HTMLNames;
using JSC::JSGlobalObject;
using JSC::JSLock;
/*
Here is the current behavior matrix for four types of navigations:
Standard Nav:
Restore form state: YES
Restore scroll and focus state: YES
Cache policy: NSURLRequestUseProtocolCachePolicy
Add to back/forward list: YES
Back/Forward:
Restore form state: YES
Restore scroll and focus state: YES
Cache policy: NSURLRequestReturnCacheDataElseLoad
Add to back/forward list: NO
Reload (meaning only the reload button):
Restore form state: NO
Restore scroll and focus state: YES
Cache policy: NSURLRequestReloadIgnoringCacheData
Add to back/forward list: NO
Repeat load of the same URL (by any other means of navigation other than the reload button, including hitting return in the location field):
Restore form state: NO
Restore scroll and focus state: NO, reset to initial conditions
Cache policy: NSURLRequestReloadIgnoringCacheData
Add to back/forward list: NO
*/
NSString *WebPageCacheEntryDateKey = @"WebPageCacheEntryDateKey";
NSString *WebPageCacheDataSourceKey = @"WebPageCacheDataSourceKey";
NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
NSString *WebFrameMainDocumentError = @"WebFrameMainDocumentErrorKey";
NSString *WebFrameHasPlugins = @"WebFrameHasPluginsKey";
NSString *WebFrameHasUnloadListener = @"WebFrameHasUnloadListenerKey";
NSString *WebFrameUsesDatabases = @"WebFrameUsesDatabasesKey";
NSString *WebFrameUsesGeolocation = @"WebFrameUsesGeolocationKey";
NSString *WebFrameUsesApplicationCache = @"WebFrameUsesApplicationCacheKey";
NSString *WebFrameCanSuspendActiveDOMObjects = @"WebFrameCanSuspendActiveDOMObjectsKey";
// FIXME: Remove when this key becomes publicly defined
NSString *NSAccessibilityEnhancedUserInterfaceAttribute = @"AXEnhancedUserInterface";
@implementation WebFramePrivate
- (void)dealloc
{
[webFrameView release];
delete scriptDebugger;
[super dealloc];
}
- (void)finalize
{
delete scriptDebugger;
[super finalize];
}
- (void)setWebFrameView:(WebFrameView *)v
{
[v retain];
[webFrameView release];
webFrameView = v;
}
@end
EditableLinkBehavior core(WebKitEditableLinkBehavior editableLinkBehavior)
{
switch (editableLinkBehavior) {
case WebKitEditableLinkDefaultBehavior:
return EditableLinkDefaultBehavior;
case WebKitEditableLinkAlwaysLive:
return EditableLinkAlwaysLive;
case WebKitEditableLinkOnlyLiveWithShiftKey:
return EditableLinkOnlyLiveWithShiftKey;
case WebKitEditableLinkLiveWhenNotFocused:
return EditableLinkLiveWhenNotFocused;
case WebKitEditableLinkNeverLive:
return EditableLinkNeverLive;
}
ASSERT_NOT_REACHED();
return EditableLinkDefaultBehavior;
}
TextDirectionSubmenuInclusionBehavior core(WebTextDirectionSubmenuInclusionBehavior behavior)
{
switch (behavior) {
case WebTextDirectionSubmenuNeverIncluded:
return TextDirectionSubmenuNeverIncluded;
case WebTextDirectionSubmenuAutomaticallyIncluded:
return TextDirectionSubmenuAutomaticallyIncluded;
case WebTextDirectionSubmenuAlwaysIncluded:
return TextDirectionSubmenuAlwaysIncluded;
}
ASSERT_NOT_REACHED();
return TextDirectionSubmenuNeverIncluded;
}
@implementation WebFrame (WebInternal)
Frame* core(WebFrame *frame)
{
return frame ? frame->_private->coreFrame : 0;
}
WebFrame *kit(Frame* frame)
{
if (!frame)
return nil;
FrameLoaderClient* frameLoaderClient = frame->loader()->client();
if (frameLoaderClient->isEmptyFrameLoaderClient())
return nil;
return static_cast<WebFrameLoaderClient*>(frameLoaderClient)->webFrame();
}
Page* core(WebView *webView)
{
return [webView page];
}
WebView *kit(Page* page)
{
if (!page)
return nil;
ChromeClient* chromeClient = page->chrome().client();
if (chromeClient->isEmptyChromeClient())
return nil;
return static_cast<WebChromeClient*>(chromeClient)->webView();
}
WebView *getWebView(WebFrame *webFrame)
{
Frame* coreFrame = core(webFrame);
if (!coreFrame)
return nil;
return kit(coreFrame->page());
}
+ (PassRefPtr<Frame>)_createFrameWithPage:(Page*)page frameName:(const String&)name frameView:(WebFrameView *)frameView ownerElement:(HTMLFrameOwnerElement*)ownerElement
{
WebView *webView = kit(page);
WebFrame *frame = [[self alloc] _initWithWebFrameView:frameView webView:webView];
RefPtr<Frame> coreFrame = Frame::create(page, ownerElement, new WebFrameLoaderClient(frame));
[frame release];
frame->_private->coreFrame = coreFrame.get();
coreFrame->tree()->setName(name);
if (ownerElement) {
ASSERT(ownerElement->document()->frame());
ownerElement->document()->frame()->tree()->appendChild(coreFrame.get());
}
coreFrame->init();
[webView _setZoomMultiplier:[webView _realZoomMultiplier] isTextOnly:[webView _realZoomMultiplierIsTextOnly]];
return coreFrame.release();
}
+ (void)_createMainFrameWithPage:(Page*)page frameName:(const String&)name frameView:(WebFrameView *)frameView
{
[self _createFrameWithPage:page frameName:name frameView:frameView ownerElement:0];
}
+ (PassRefPtr<WebCore::Frame>)_createSubframeWithOwnerElement:(HTMLFrameOwnerElement*)ownerElement frameName:(const String&)name frameView:(WebFrameView *)frameView
{
return [self _createFrameWithPage:ownerElement->document()->frame()->page() frameName:name frameView:frameView ownerElement:ownerElement];
}
- (BOOL)_isIncludedInWebKitStatistics
{
return _private && _private->includedInWebKitStatistics;
}
- (void)_attachScriptDebugger
{
ScriptController* scriptController = _private->coreFrame->script();
// Calling ScriptController::globalObject() would create a window shell, and dispatch corresponding callbacks, which may be premature
// if the script debugger is attached before a document is created. These calls use the debuggerWorld(), we will need to pass a world
// to be able to debug isolated worlds.
if (!scriptController->existingWindowShell(debuggerWorld()))
return;
JSGlobalObject* globalObject = scriptController->globalObject(debuggerWorld());
if (!globalObject)
return;
if (_private->scriptDebugger) {
ASSERT(_private->scriptDebugger == globalObject->debugger());
return;
}
_private->scriptDebugger = new WebScriptDebugger(globalObject);
}
- (void)_detachScriptDebugger
{
if (!_private->scriptDebugger)
return;
delete _private->scriptDebugger;
_private->scriptDebugger = 0;
}
- (id)_initWithWebFrameView:(WebFrameView *)fv webView:(WebView *)v
{
self = [super init];
if (!self)
return nil;
_private = [[WebFramePrivate alloc] init];
// Set includedInWebKitStatistics before calling WebFrameView _setWebFrame, since
// it calls WebFrame _isIncludedInWebKitStatistics.
if ((_private->includedInWebKitStatistics = [[v class] shouldIncludeInWebKitStatistics]))
++WebFrameCount;
if (fv) {
[_private setWebFrameView:fv];
[fv _setWebFrame:self];
}
_private->shouldCreateRenderers = YES;
return self;
}
- (void)_clearCoreFrame
{
_private->coreFrame = 0;
}
- (void)_updateBackgroundAndUpdatesWhileOffscreen
{
WebView *webView = getWebView(self);
BOOL drawsBackground = [webView drawsBackground];
NSColor *backgroundColor = [webView backgroundColor];
Frame* coreFrame = _private->coreFrame;
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
// Don't call setDrawsBackground:YES here because it may be NO because of a load
// in progress; WebFrameLoaderClient keeps it set to NO during the load process.
WebFrame *webFrame = kit(frame);
if (!drawsBackground)
[[[webFrame frameView] _scrollView] setDrawsBackground:NO];
[[[webFrame frameView] _scrollView] setBackgroundColor:backgroundColor];
if (FrameView* view = frame->view()) {
view->setTransparent(!drawsBackground);
view->setBaseBackgroundColor(colorFromNSColor([backgroundColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]));
view->setShouldUpdateWhileOffscreen([webView shouldUpdateWhileOffscreen]);
}
}
}
- (void)_setInternalLoadDelegate:(id)internalLoadDelegate
{
_private->internalLoadDelegate = internalLoadDelegate;
}
- (id)_internalLoadDelegate
{
return _private->internalLoadDelegate;
}
- (void)_unmarkAllBadGrammar
{
Frame* coreFrame = _private->coreFrame;
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
if (Document* document = frame->document())
document->markers()->removeMarkers(DocumentMarker::Grammar);
}
}
- (void)_unmarkAllMisspellings
{
Frame* coreFrame = _private->coreFrame;
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
if (Document* document = frame->document())
document->markers()->removeMarkers(DocumentMarker::Spelling);
}
}
- (BOOL)_hasSelection
{
id documentView = [_private->webFrameView documentView];
// optimization for common case to avoid creating potentially large selection string
if ([documentView isKindOfClass:[WebHTMLView class]])
if (Frame* coreFrame = _private->coreFrame)
return coreFrame->selection()->isRange();
if ([documentView conformsToProtocol:@protocol(WebDocumentText)])
return [[documentView selectedString] length] > 0;
return NO;
}
- (void)_clearSelection
{
id documentView = [_private->webFrameView documentView];
if ([documentView conformsToProtocol:@protocol(WebDocumentText)])
[documentView deselectAll];
}
#if !ASSERT_DISABLED
- (BOOL)_atMostOneFrameHasSelection
{
// FIXME: 4186050 is one known case that makes this debug check fail.
BOOL found = NO;
Frame* coreFrame = _private->coreFrame;
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame))
if ([kit(frame) _hasSelection]) {
if (found)
return NO;
found = YES;
}
return YES;
}
#endif
- (WebFrame *)_findFrameWithSelection
{
Frame* coreFrame = _private->coreFrame;
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
WebFrame *webFrame = kit(frame);
if ([webFrame _hasSelection])
return webFrame;
}
return nil;
}
- (void)_clearSelectionInOtherFrames
{
// We rely on WebDocumentSelection protocol implementors to call this method when they become first
// responder. It would be nicer to just notice first responder changes here instead, but there's no
// notification sent when the first responder changes in general (Radar 2573089).
WebFrame *frameWithSelection = [[getWebView(self) mainFrame] _findFrameWithSelection];
if (frameWithSelection != self)
[frameWithSelection _clearSelection];
// While we're in the general area of selection and frames, check that there is only one now.
ASSERT([[getWebView(self) mainFrame] _atMostOneFrameHasSelection]);
}
static inline WebDataSource *dataSource(DocumentLoader* loader)
{
return loader ? static_cast<WebDocumentLoaderMac*>(loader)->dataSource() : nil;
}
- (WebDataSource *)_dataSource
{
return dataSource(_private->coreFrame->loader()->documentLoader());
}
- (NSString *)_stringWithDocumentTypeStringAndMarkupString:(NSString *)markupString
{
return String(_private->coreFrame->documentTypeString() + String(markupString));
}
- (NSArray *)_nodesFromList:(Vector<Node*> *)nodesVector
{
size_t size = nodesVector->size();
NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:size];
for (size_t i = 0; i < size; ++i)
[nodes addObject:kit((*nodesVector)[i])];
return nodes;
}
- (NSString *)_markupStringFromRange:(DOMRange *)range nodes:(NSArray **)nodes
{
// FIXME: This is always "for interchange". Is that right? See the previous method.
Vector<Node*> nodeList;
NSString *markupString = createMarkup(core(range), nodes ? &nodeList : 0, AnnotateForInterchange);
if (nodes)
*nodes = [self _nodesFromList:&nodeList];
return [self _stringWithDocumentTypeStringAndMarkupString:markupString];
}
- (NSString *)_selectedString
{
return _private->coreFrame->displayStringModifiedByEncoding(_private->coreFrame->editor().selectedText());
}
- (NSString *)_stringForRange:(DOMRange *)range
{
return plainText(core(range), TextIteratorDefaultBehavior, true);
}
- (BOOL)_shouldFlattenCompositingLayers:(CGContextRef)context
{
// -currentContextDrawingToScreen returns YES for bitmap contexts.
BOOL isPrinting = ![NSGraphicsContext currentContextDrawingToScreen];
if (isPrinting)
return YES;
if (!WKCGContextIsBitmapContext(context))
return NO;
// If we're drawing into a bitmap, we might be snapshotting, or drawing into a layer-backed view.
id documentView = [_private->webFrameView documentView];
if ([documentView isKindOfClass:[WebHTMLView class]] && [(WebHTMLView *)documentView _web_isDrawingIntoLayer])
return NO;
return [getWebView(self) _includesFlattenedCompositingLayersWhenDrawingToBitmap];
}
- (void)_drawRect:(NSRect)rect contentsOnly:(BOOL)contentsOnly
{
ASSERT([[NSGraphicsContext currentContext] isFlipped]);
CGContextRef ctx = static_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
GraphicsContext context(ctx);
FrameView* view = _private->coreFrame->view();
bool shouldFlatten = false;
if (Frame* parentFrame = _private->coreFrame->tree()->parent()) {
// For subframes, we need to inherit the paint behavior from our parent
FrameView* parentView = parentFrame ? parentFrame->view() : 0;
if (parentView)
shouldFlatten = parentView->paintBehavior() & PaintBehaviorFlattenCompositingLayers;
} else
shouldFlatten = [self _shouldFlattenCompositingLayers:ctx];
PaintBehavior oldBehavior = PaintBehaviorNormal;
if (shouldFlatten) {
oldBehavior = view->paintBehavior();
view->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
}
if (contentsOnly)
view->paintContents(&context, enclosingIntRect(rect));
else
view->paint(&context, enclosingIntRect(rect));
if (shouldFlatten)
view->setPaintBehavior(oldBehavior);
}
- (BOOL)_getVisibleRect:(NSRect*)rect
{
ASSERT_ARG(rect, rect);
if (RenderPart* ownerRenderer = _private->coreFrame->ownerRenderer()) {
if (ownerRenderer->needsLayout())
return NO;
*rect = ownerRenderer->pixelSnappedAbsoluteClippedOverflowRect();
return YES;
}
return NO;
}
- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string
{
return [self _stringByEvaluatingJavaScriptFromString:string forceUserGesture:true];
}
- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string forceUserGesture:(BOOL)forceUserGesture
{
if (!string)
return @"";
ASSERT(_private->coreFrame->document());
RetainPtr<WebFrame> protect(self); // Executing arbitrary JavaScript can destroy the frame.
JSC::JSValue result = _private->coreFrame->script()->executeScript(string, forceUserGesture).jsValue();
if (!_private->coreFrame) // In case the script removed our frame from the page.
return @"";
// This bizarre set of rules matches behavior from WebKit for Safari 2.0.
// If you don't like it, use -[WebScriptObject evaluateWebScript:] or
// JSEvaluateScript instead, since they have less surprising semantics.
if (!result || (!result.isBoolean() && !result.isString() && !result.isNumber()))
return @"";
JSC::ExecState* exec = _private->coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec();
JSC::JSLockHolder lock(exec);
return result.toWTFString(exec);
}
- (NSRect)_caretRectAtPosition:(const Position&)pos affinity:(NSSelectionAffinity)affinity
{
VisiblePosition visiblePosition(pos, static_cast<EAffinity>(affinity));
return visiblePosition.absoluteCaretBounds();
}
- (NSRect)_firstRectForDOMRange:(DOMRange *)range
{
return _private->coreFrame->editor().firstRectForRange(core(range));
}
- (void)_scrollDOMRangeToVisible:(DOMRange *)range
{
NSRect rangeRect = [self _firstRectForDOMRange:range];
Node *startNode = core([range startContainer]);
if (startNode && startNode->renderer())
startNode->renderer()->scrollRectToVisible(enclosingIntRect(rangeRect), ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
}
- (BOOL)_needsLayout
{
return _private->coreFrame->view() ? _private->coreFrame->view()->needsLayout() : false;
}
- (DOMRange *)_rangeByAlteringCurrentSelection:(FrameSelection::EAlteration)alteration direction:(SelectionDirection)direction granularity:(TextGranularity)granularity
{
if (_private->coreFrame->selection()->isNone())
return nil;
FrameSelection selection;
selection.setSelection(_private->coreFrame->selection()->selection());
selection.modify(alteration, direction, granularity);
return kit(selection.toNormalizedRange().get());
}
- (TextGranularity)_selectionGranularity
{
return _private->coreFrame->selection()->granularity();
}
- (NSRange)_convertToNSRange:(Range *)range
{
if (!range)
return NSMakeRange(NSNotFound, 0);
size_t location;
size_t length;
if (!TextIterator::getLocationAndLengthFromRange(_private->coreFrame->selection()->rootEditableElementOrDocumentElement(), range, location, length))
return NSMakeRange(NSNotFound, 0);
return NSMakeRange(location, length);
}
- (PassRefPtr<Range>)_convertToDOMRange:(NSRange)nsrange
{
if (nsrange.location > INT_MAX)
return 0;
if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
nsrange.length = INT_MAX - nsrange.location;
// our critical assumption is that we are only called by input methods that
// concentrate on a given area containing the selection
// We have to do this because of text fields and textareas. The DOM for those is not
// directly in the document DOM, so serialization is problematic. Our solution is
// to use the root editable element of the selection start as the positional base.
// That fits with AppKit's idea of an input context.
return TextIterator::rangeFromLocationAndLength(_private->coreFrame->selection()->rootEditableElementOrDocumentElement(), nsrange.location, nsrange.length);
}
- (DOMRange *)_convertNSRangeToDOMRange:(NSRange)nsrange
{
return kit([self _convertToDOMRange:nsrange].get());
}
- (NSRange)_convertDOMRangeToNSRange:(DOMRange *)range
{
return [self _convertToNSRange:core(range)];
}
- (DOMRange *)_markDOMRange
{
return kit(_private->coreFrame->editor().mark().toNormalizedRange().get());
}
// Given proposedRange, returns an extended range that includes adjacent whitespace that should
// be deleted along with the proposed range in order to preserve proper spacing and punctuation of
// the text surrounding the deletion.
- (DOMRange *)_smartDeleteRangeForProposedRange:(DOMRange *)proposedRange
{
Node* startContainer = core([proposedRange startContainer]);
Node* endContainer = core([proposedRange endContainer]);
if (startContainer == nil || endContainer == nil)
return nil;
ASSERT(startContainer->document() == endContainer->document());
_private->coreFrame->document()->updateLayoutIgnorePendingStylesheets();
Position start = Position(startContainer, [proposedRange startOffset], Position::PositionIsOffsetInAnchor);
Position end = Position(endContainer, [proposedRange endOffset], Position::PositionIsOffsetInAnchor);
Position newStart = start.upstream().leadingWhitespacePosition(DOWNSTREAM, true);
if (newStart.isNull())
newStart = start;
Position newEnd = end.downstream().trailingWhitespacePosition(DOWNSTREAM, true);
if (newEnd.isNull())
newEnd = end;
newStart = newStart.parentAnchoredEquivalent();
newEnd = newEnd.parentAnchoredEquivalent();
RefPtr<Range> range = _private->coreFrame->document()->createRange();
int exception = 0;
range->setStart(newStart.containerNode(), newStart.offsetInContainerNode(), exception);
range->setEnd(newStart.containerNode(), newStart.offsetInContainerNode(), exception);
return kit(range.get());
}
- (DOMDocumentFragment *)_documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString
{
if (!_private->coreFrame || !_private->coreFrame->document())
return nil;
return kit(createFragmentFromMarkup(_private->coreFrame->document(), markupString, baseURLString, DisallowScriptingContent).get());
}
- (DOMDocumentFragment *)_documentFragmentWithNodesAsParagraphs:(NSArray *)nodes
{
if (!_private->coreFrame || !_private->coreFrame->document())
return nil;
NSEnumerator *nodeEnum = [nodes objectEnumerator];
Vector<Node*> nodesVector;
DOMNode *node;
while ((node = [nodeEnum nextObject]))
nodesVector.append(core(node));
return kit(createFragmentFromNodes(_private->coreFrame->document(), nodesVector).get());
}
- (void)_replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
{
DOMDocumentFragment *fragment = kit(_private->coreFrame->document()->createDocumentFragment().get());
[fragment appendChild:node];
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:matchStyle];
}
- (void)_insertParagraphSeparatorInQuotedContent
{
if (_private->coreFrame->selection()->isNone())
return;
_private->coreFrame->editor().insertParagraphSeparatorInQuotedContent();
}
- (VisiblePosition)_visiblePositionForPoint:(NSPoint)point
{
// FIXME: Someone with access to Apple's sources could remove this needless wrapper call.
return _private->coreFrame->visiblePositionForPoint(IntPoint(point));
}
- (DOMRange *)_characterRangeAtPoint:(NSPoint)point
{
return kit(_private->coreFrame->rangeForPoint(IntPoint(point)).get());
}
- (DOMCSSStyleDeclaration *)_typingStyle
{
if (!_private->coreFrame)
return nil;
RefPtr<MutableStylePropertySet> typingStyle = _private->coreFrame->selection()->copyTypingStyle();
if (!typingStyle)
return nil;
return kit(typingStyle->ensureCSSStyleDeclaration());
}
- (void)_setTypingStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
{
if (!_private->coreFrame || !style)
return;
// FIXME: We shouldn't have to create a copy here.
_private->coreFrame->editor().computeAndSetTypingStyle(core(style)->copyProperties().get(), undoAction);
}
#if ENABLE(DRAG_SUPPORT)
- (void)_dragSourceEndedAt:(NSPoint)windowLoc operation:(NSDragOperation)operation
{
if (!_private->coreFrame)
return;
FrameView* view = _private->coreFrame->view();
if (!view)
return;
// FIXME: These are fake modifier keys here, but they should be real ones instead.
PlatformMouseEvent event(IntPoint(windowLoc), globalPoint(windowLoc, [view->platformWidget() window]),
LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, currentTime());
_private->coreFrame->eventHandler()->dragSourceEndedAt(event, (DragOperation)operation);
}
#endif
- (BOOL)_canProvideDocumentSource
{
Frame* frame = _private->coreFrame;
String mimeType = frame->document()->loader()->writer()->mimeType();
PluginData* pluginData = frame->page() ? frame->page()->pluginData() : 0;
if (WebCore::DOMImplementation::isTextMIMEType(mimeType)
|| Image::supportsType(mimeType)
|| (pluginData && pluginData->supportsMimeType(mimeType, PluginData::AllPlugins) && frame->loader()->subframeLoader()->allowPlugins(NotAboutToInstantiatePlugin))
|| (pluginData && pluginData->supportsMimeType(mimeType, PluginData::OnlyApplicationPlugins)))
return NO;
return YES;
}
- (BOOL)_canSaveAsWebArchive
{
// Currently, all documents that we can view source for
// (HTML and XML documents) can also be saved as web archives
return [self _canProvideDocumentSource];
}
- (void)_commitData:(NSData *)data
{
// FIXME: This really should be a setting.
Document* document = _private->coreFrame->document();
document->setShouldCreateRenderers(_private->shouldCreateRenderers);
_private->coreFrame->loader()->documentLoader()->commitData((const char *)[data bytes], [data length]);
}
@end
@implementation WebFrame (WebPrivate)
// FIXME: This exists only as a convenience for Safari, consider moving there.
- (BOOL)_isDescendantOfFrame:(WebFrame *)ancestor
{
Frame* coreFrame = _private->coreFrame;
return coreFrame && coreFrame->tree()->isDescendantOf(core(ancestor));
}
- (void)_setShouldCreateRenderers:(BOOL)shouldCreateRenderers
{
_private->shouldCreateRenderers = shouldCreateRenderers;
}
- (NSColor *)_bodyBackgroundColor
{
Document* document = _private->coreFrame->document();
if (!document)
return nil;
HTMLElement* body = document->body();
if (!body)
return nil;
RenderObject* bodyRenderer = body->renderer();
if (!bodyRenderer)
return nil;
Color color = bodyRenderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
if (!color.isValid())
return nil;
return nsColor(color);
}
- (BOOL)_isFrameSet
{
Document* document = _private->coreFrame->document();
return document && document->isFrameSet();
}
- (BOOL)_firstLayoutDone
{
return _private->coreFrame->loader()->stateMachine()->firstLayoutDone();
}
- (BOOL)_isVisuallyNonEmpty
{
if (FrameView* view = _private->coreFrame->view())
return view->isVisuallyNonEmpty();
return NO;
}
- (WebFrameLoadType)_loadType
{
return (WebFrameLoadType)_private->coreFrame->loader()->loadType();
}
- (NSRange)_selectedNSRange
{
return [self _convertToNSRange:_private->coreFrame->selection()->toNormalizedRange().get()];
}
- (void)_selectNSRange:(NSRange)range
{
RefPtr<Range> domRange = [self _convertToDOMRange:range];
if (domRange)
_private->coreFrame->selection()->setSelection(VisibleSelection(domRange.get(), SEL_DEFAULT_AFFINITY));
}
- (BOOL)_isDisplayingStandaloneImage
{
Document* document = _private->coreFrame->document();
return document && document->isImageDocument();
}
- (unsigned)_pendingFrameUnloadEventCount
{
return _private->coreFrame->document()->domWindow()->pendingUnloadEventListeners();
}
#if ENABLE(NETSCAPE_PLUGIN_API)
- (void)_recursive_resumeNullEventsForAllNetscapePlugins
{
Frame* coreFrame = core(self);
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
NSView <WebDocumentView> *documentView = [[kit(frame) frameView] documentView];
if ([documentView isKindOfClass:[WebHTMLView class]])
[(WebHTMLView *)documentView _resumeNullEventsForAllNetscapePlugins];
}
}
- (void)_recursive_pauseNullEventsForAllNetscapePlugins
{
Frame* coreFrame = core(self);
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
NSView <WebDocumentView> *documentView = [[kit(frame) frameView] documentView];
if ([documentView isKindOfClass:[WebHTMLView class]])
[(WebHTMLView *)documentView _pauseNullEventsForAllNetscapePlugins];
}
}
#endif
- (void)_replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
{
if (_private->coreFrame->selection()->isNone() || !fragment)
return;
_private->coreFrame->editor().replaceSelectionWithFragment(core(fragment), selectReplacement, smartReplace, matchStyle);
}
- (void)_replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
{
DOMDocumentFragment* fragment = kit(createFragmentFromText(_private->coreFrame->selection()->toNormalizedRange().get(), text).get());
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES];
}
- (void)_replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
{
DOMDocumentFragment *fragment = [self _documentFragmentWithMarkupString:markupString baseURLString:baseURLString];
[self _replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:NO];
}
// Determines whether whitespace needs to be added around aString to preserve proper spacing and
// punctuation when it's inserted into the receiver's text over charRange. Returns by reference
// in beforeString and afterString any whitespace that should be added, unless either or both are
// nil. Both are returned as nil if aString is nil or if smart insertion and deletion are disabled.
- (void)_smartInsertForString:(NSString *)pasteString replacingRange:(DOMRange *)rangeToReplace beforeString:(NSString **)beforeString afterString:(NSString **)afterString
{
// give back nil pointers in case of early returns
if (beforeString)
*beforeString = nil;
if (afterString)
*afterString = nil;
// inspect destination
Node *startContainer = core([rangeToReplace startContainer]);
Node *endContainer = core([rangeToReplace endContainer]);
Position startPos(startContainer, [rangeToReplace startOffset], Position::PositionIsOffsetInAnchor);
Position endPos(endContainer, [rangeToReplace endOffset], Position::PositionIsOffsetInAnchor);
VisiblePosition startVisiblePos = VisiblePosition(startPos, VP_DEFAULT_AFFINITY);
VisiblePosition endVisiblePos = VisiblePosition(endPos, VP_DEFAULT_AFFINITY);
// this check also ensures startContainer, startPos, endContainer, and endPos are non-null
if (startVisiblePos.isNull() || endVisiblePos.isNull())
return;
bool addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfParagraph(startVisiblePos);
if (addLeadingSpace)
if (UChar previousChar = startVisiblePos.previous().characterAfter())
addLeadingSpace = !isCharacterSmartReplaceExempt(previousChar, true);
bool addTrailingSpace = endPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfParagraph(endVisiblePos);
if (addTrailingSpace)
if (UChar thisChar = endVisiblePos.characterAfter())
addTrailingSpace = !isCharacterSmartReplaceExempt(thisChar, false);
// inspect source
bool hasWhitespaceAtStart = false;
bool hasWhitespaceAtEnd = false;
unsigned pasteLength = [pasteString length];
if (pasteLength > 0) {
NSCharacterSet *whiteSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
if ([whiteSet characterIsMember:[pasteString characterAtIndex:0]]) {
hasWhitespaceAtStart = YES;
}
if ([whiteSet characterIsMember:[pasteString characterAtIndex:(pasteLength - 1)]]) {
hasWhitespaceAtEnd = YES;
}
}
// issue the verdict
if (beforeString && addLeadingSpace && !hasWhitespaceAtStart)
*beforeString = @" ";
if (afterString && addTrailingSpace && !hasWhitespaceAtEnd)
*afterString = @" ";
}
- (NSMutableDictionary *)_cacheabilityDictionary
{
NSMutableDictionary *result = [NSMutableDictionary dictionary];
FrameLoader* frameLoader = _private->coreFrame->loader();
DocumentLoader* documentLoader = frameLoader->documentLoader();
if (documentLoader && !documentLoader->mainDocumentError().isNull())
[result setObject:(NSError *)documentLoader->mainDocumentError() forKey:WebFrameMainDocumentError];
if (frameLoader->subframeLoader()->containsPlugins())
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameHasPlugins];
if (DOMWindow* domWindow = _private->coreFrame->document()->domWindow()) {
if (domWindow->hasEventListeners(eventNames().unloadEvent))
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameHasUnloadListener];
if (domWindow->optionalApplicationCache())
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameUsesApplicationCache];
}
if (Document* document = _private->coreFrame->document()) {
#if ENABLE(SQL_DATABASE)
if (DatabaseManager::manager().hasOpenDatabases(document))
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameUsesDatabases];
#endif
if (!document->canSuspendActiveDOMObjects())
[result setObject:[NSNumber numberWithBool:YES] forKey:WebFrameCanSuspendActiveDOMObjects];
}
return result;
}
- (BOOL)_allowsFollowingLink:(NSURL *)URL
{
if (!_private->coreFrame)
return YES;
return _private->coreFrame->document()->securityOrigin()->canDisplay(URL);
}
- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string withGlobalObject:(JSObjectRef)globalObjectRef inScriptWorld:(WebScriptWorld *)world
{
if (!string)
return @"";
// Start off with some guess at a frame and a global object, we'll try to do better...!
JSDOMWindow* anyWorldGlobalObject = _private->coreFrame->script()->globalObject(mainThreadNormalWorld());
// The global object is probably a shell object? - if so, we know how to use this!
JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
// Get the frame frome the global object we've settled on.
Frame* frame = anyWorldGlobalObject->impl()->frame();
ASSERT(frame->document());
RetainPtr<WebFrame> webFrame(kit(frame)); // Running arbitrary JavaScript can destroy the frame.
JSC::JSValue result = frame->script()->executeScriptInWorld(core(world), string, true).jsValue();
if (!webFrame->_private->coreFrame) // In case the script removed our frame from the page.
return @"";
// This bizarre set of rules matches behavior from WebKit for Safari 2.0.
// If you don't like it, use -[WebScriptObject evaluateWebScript:] or
// JSEvaluateScript instead, since they have less surprising semantics.
if (!result || (!result.isBoolean() && !result.isString() && !result.isNumber()))
return @"";
JSC::ExecState* exec = anyWorldGlobalObject->globalExec();
JSC::JSLockHolder lock(exec);
return result.toWTFString(exec);
}
- (JSGlobalContextRef)_globalContextForScriptWorld:(WebScriptWorld *)world
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return 0;
DOMWrapperWorld* coreWorld = core(world);
if (!coreWorld)
return 0;
return toGlobalRef(coreFrame->script()->globalObject(coreWorld)->globalExec());
}
#if JSC_OBJC_API_ENABLED
- (JSContext *)_javaScriptContextForScriptWorld:(WebScriptWorld *)world
{
JSGlobalContextRef globalContextRef = [self _globalContextForScriptWorld:world];
if (!globalContextRef)
return 0;
return [JSContext contextWithJSGlobalContextRef:globalContextRef];
}
#endif
- (void)setAllowsScrollersToOverlapContent:(BOOL)flag
{
ASSERT([[[self frameView] _scrollView] isKindOfClass:[WebDynamicScrollBarsView class]]);
[(WebDynamicScrollBarsView *)[[self frameView] _scrollView] setAllowsScrollersToOverlapContent:flag];
}
- (void)setAlwaysHideHorizontalScroller:(BOOL)flag
{
ASSERT([[[self frameView] _scrollView] isKindOfClass:[WebDynamicScrollBarsView class]]);
[(WebDynamicScrollBarsView *)[[self frameView] _scrollView] setAlwaysHideHorizontalScroller:flag];
}
- (void)setAlwaysHideVerticalScroller:(BOOL)flag
{
ASSERT([[[self frameView] _scrollView] isKindOfClass:[WebDynamicScrollBarsView class]]);
[(WebDynamicScrollBarsView *)[[self frameView] _scrollView] setAlwaysHideVerticalScroller:flag];
}
- (void)setAccessibleName:(NSString *)name
{
#if HAVE(ACCESSIBILITY)
if (!AXObjectCache::accessibilityEnabled())
return;
if (!_private->coreFrame || !_private->coreFrame->document())
return;
AccessibilityObject* rootObject = _private->coreFrame->document()->axObjectCache()->rootObject();
if (rootObject) {
String strName(name);
rootObject->setAccessibleName(strName);
}
#endif
}
- (NSString*)_layerTreeAsText
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return @"";
return coreFrame->layerTreeAsText();
}
- (id)accessibilityRoot
{
#if HAVE(ACCESSIBILITY)
if (!AXObjectCache::accessibilityEnabled()) {
AXObjectCache::enableAccessibility();
AXObjectCache::setEnhancedUserInterfaceAccessibility([[NSApp accessibilityAttributeValue:NSAccessibilityEnhancedUserInterfaceAttribute] boolValue]);
}
if (!_private->coreFrame || !_private->coreFrame->document())
return nil;
AccessibilityObject* rootObject = _private->coreFrame->document()->axObjectCache()->rootObjectForFrame(_private->coreFrame);
if (!rootObject)
return nil;
// The root object will be a WebCore scroll view object. In WK1, scroll views are handled
// by the system and the root object should be the web area (instead of the scroll view).
if (rootObject->isAttachment() && rootObject->firstChild())
return rootObject->firstChild()->wrapper();
return rootObject->wrapper();
#else
return nil;
#endif
}
- (void)_clearOpener
{
Frame* coreFrame = _private->coreFrame;
if (coreFrame)
coreFrame->loader()->setOpener(0);
}
// Used by pagination code called from AppKit when a standalone web page is printed.
- (NSArray *)_computePageRectsWithPrintScaleFactor:(float)printScaleFactor pageSize:(NSSize)pageSize
{
if (printScaleFactor <= 0) {
LOG_ERROR("printScaleFactor has bad value %.2f", printScaleFactor);
return [NSArray array];
}
if (!_private->coreFrame)
return [NSArray array];
if (!_private->coreFrame->document())
return [NSArray array];
if (!_private->coreFrame->view())
return [NSArray array];
if (!_private->coreFrame->view()->documentView())
return [NSArray array];
RenderView* root = toRenderView(_private->coreFrame->document()->renderer());
if (!root)
return [NSArray array];
const LayoutRect& documentRect = root->documentRect();
float printWidth = root->style()->isHorizontalWritingMode() ? static_cast<float>(documentRect.width()) / printScaleFactor : pageSize.width;
float printHeight = root->style()->isHorizontalWritingMode() ? pageSize.height : static_cast<float>(documentRect.height()) / printScaleFactor;
PrintContext printContext(_private->coreFrame);
printContext.computePageRectsWithPageSize(FloatSize(printWidth, printHeight), true);
const Vector<IntRect>& pageRects = printContext.pageRects();
size_t size = pageRects.size();
NSMutableArray *pages = [NSMutableArray arrayWithCapacity:size];
for (size_t i = 0; i < size; ++i)
[pages addObject:[NSValue valueWithRect:NSRect(pageRects[i])]];
return pages;
}
- (JSValueRef)jsWrapperForNode:(DOMNode *)node inScriptWorld:(WebScriptWorld *)world
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return 0;
JSDOMWindow* globalObject = coreFrame->script()->globalObject(core(world));
JSC::ExecState* exec = globalObject->globalExec();
JSC::JSLockHolder lock(exec);
return toRef(exec, toJS(exec, globalObject, core(node)));
}
- (NSDictionary *)elementAtPoint:(NSPoint)point
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return nil;
return [[[WebElementDictionary alloc] initWithHitTestResult:coreFrame->eventHandler()->hitTestResultAtPoint(IntPoint(point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent)] autorelease];
}
- (NSURL *)_unreachableURL
{
return [[self _dataSource] unreachableURL];
}
@end
@implementation WebFrame
- (id)init
{
return nil;
}
// Should be deprecated.
- (id)initWithName:(NSString *)name webFrameView:(WebFrameView *)view webView:(WebView *)webView
{
return nil;
}
- (void)dealloc
{
if (_private && _private->includedInWebKitStatistics)
--WebFrameCount;
[_private release];
[super dealloc];
}
- (void)finalize
{
if (_private && _private->includedInWebKitStatistics)
--WebFrameCount;
[super finalize];
}
- (NSString *)name
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return nil;
return coreFrame->tree()->uniqueName();
}
- (WebFrameView *)frameView
{
return _private->webFrameView;
}
- (WebView *)webView
{
return getWebView(self);
}
static bool needsMicrosoftMessengerDOMDocumentWorkaround()
{
static bool needsWorkaround = applicationIsMicrosoftMessenger() && [[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey] compare:@"7.1" options:NSNumericSearch] == NSOrderedAscending;
return needsWorkaround;
}
- (DOMDocument *)DOMDocument
{
if (needsMicrosoftMessengerDOMDocumentWorkaround() && !pthread_main_np())
return nil;
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return nil;
// FIXME: <rdar://problem/5145841> When loading a custom view/representation
// into a web frame, the old document can still be around. This makes sure that
// we'll return nil in those cases.
if (![[self _dataSource] _isDocumentHTML])
return nil;
Document* document = coreFrame->document();
// According to the documentation, we should return nil if the frame doesn't have a document.
// While full-frame images and plugins do have an underlying HTML document, we return nil here to be
// backwards compatible.
if (document && (document->isPluginDocument() || document->isImageDocument()))
return nil;
return kit(coreFrame->document());
}
- (DOMHTMLElement *)frameElement
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return nil;
return kit(coreFrame->ownerElement());
}
- (WebDataSource *)provisionalDataSource
{
Frame* coreFrame = _private->coreFrame;
return coreFrame ? dataSource(coreFrame->loader()->provisionalDocumentLoader()) : nil;
}
- (WebDataSource *)dataSource
{
Frame* coreFrame = _private->coreFrame;
return coreFrame && coreFrame->loader()->frameHasLoaded() ? [self _dataSource] : nil;
}
- (void)loadRequest:(NSURLRequest *)request
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return;
ResourceRequest resourceRequest(request);
// Some users of WebKit API incorrectly use "file path as URL" style requests which are invalid.
// By re-writing those URLs here we technically break the -[WebDataSource initialRequest] API
// but that is necessary to implement this quirk only at the API boundary.
// Note that other users of WebKit API use nil requests or requests with nil URLs or empty URLs, so we
// only implement this workaround when the request had a non-nil or non-empty URL.
if (!resourceRequest.url().isValid() && !resourceRequest.url().isEmpty())
resourceRequest.setURL([NSURL URLWithString:[@"file:" stringByAppendingString:[[request URL] absoluteString]]]);
coreFrame->loader()->load(FrameLoadRequest(coreFrame, resourceRequest));
}
static NSURL *createUniqueWebDataURL()
{
CFUUIDRef UUIDRef = CFUUIDCreate(kCFAllocatorDefault);
NSString *UUIDString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, UUIDRef);
CFRelease(UUIDRef);
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"applewebdata://%@", UUIDString]];
CFRelease(UUIDString);
return URL;
}
- (void)_loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL unreachableURL:(NSURL *)unreachableURL
{
if (!pthread_main_np())
return [[self _webkit_invokeOnMainThread] _loadData:data MIMEType:MIMEType textEncodingName:encodingName baseURL:baseURL unreachableURL:unreachableURL];
KURL responseURL;
if (!baseURL) {
baseURL = blankURL();
responseURL = createUniqueWebDataURL();
}
ResourceRequest request([baseURL absoluteURL]);
// hack because Mail checks for this property to detect data / archive loads
[NSURLProtocol setProperty:@"" forKey:@"WebDataRequest" inRequest:(NSMutableURLRequest *)request.nsURLRequest(UpdateHTTPBody)];
SubstituteData substituteData(WebCore::SharedBuffer::wrapNSData(data), MIMEType, encodingName, [unreachableURL absoluteURL], responseURL);
_private->coreFrame->loader()->load(FrameLoadRequest(_private->coreFrame, request, substituteData));
}
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
{
WebCoreThreadViolationCheckRoundTwo();
if (!MIMEType)
MIMEType = @"text/html";
[self _loadData:data MIMEType:MIMEType textEncodingName:encodingName baseURL:[baseURL _webkit_URLFromURLOrSchemelessFileURL] unreachableURL:nil];
}
- (void)_loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL unreachableURL:(NSURL *)unreachableURL
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
[self _loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL unreachableURL:unreachableURL];
}
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
{
WebCoreThreadViolationCheckRoundTwo();
[self _loadHTMLString:string baseURL:[baseURL _webkit_URLFromURLOrSchemelessFileURL] unreachableURL:nil];
}
- (void)loadAlternateHTMLString:(NSString *)string baseURL:(NSURL *)baseURL forUnreachableURL:(NSURL *)unreachableURL
{
WebCoreThreadViolationCheckRoundTwo();
[self _loadHTMLString:string baseURL:[baseURL _webkit_URLFromURLOrSchemelessFileURL] unreachableURL:[unreachableURL _webkit_URLFromURLOrSchemelessFileURL]];
}
- (void)loadArchive:(WebArchive *)archive
{
if (LegacyWebArchive* coreArchive = [archive _coreLegacyWebArchive])
_private->coreFrame->loader()->loadArchive(coreArchive);
}
- (void)stopLoading
{
if (!_private->coreFrame)
return;
_private->coreFrame->loader()->stopForUserCancel();
}
- (void)reload
{
if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_RELOAD_FROM_ORIGIN) && applicationIsSafari())
_private->coreFrame->loader()->reload(GetCurrentKeyModifiers() & shiftKey);
else
_private->coreFrame->loader()->reload(false);
}
- (void)reloadFromOrigin
{
_private->coreFrame->loader()->reload(true);
}
- (WebFrame *)findFrameNamed:(NSString *)name
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return nil;
return kit(coreFrame->tree()->find(name));
}
- (WebFrame *)parentFrame
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return nil;
return [[kit(coreFrame->tree()->parent()) retain] autorelease];
}
- (NSArray *)childFrames
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return [NSArray array];
NSMutableArray *children = [NSMutableArray arrayWithCapacity:coreFrame->tree()->childCount()];
for (Frame* child = coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling())
[children addObject:kit(child)];
return children;
}
- (WebScriptObject *)windowObject
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return 0;
return coreFrame->script()->windowScriptObject();
}
- (JSGlobalContextRef)globalContext
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return 0;
return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
}
#if JSC_OBJC_API_ENABLED
- (JSContext *)javaScriptContext
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return 0;
return coreFrame->script()->javaScriptContext();
}
#endif
@end
|