OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> |
6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. |
7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> | 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> |
8 * Copyright (C) 2011 Google Inc. All rights reserved. | 8 * Copyright (C) 2011 Google Inc. All rights reserved. |
9 * | 9 * |
10 * Redistribution and use in source and binary forms, with or without | 10 * Redistribution and use in source and binary forms, with or without |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 } | 847 } |
848 #endif // ENABLE(WEB_ARCHIVE) | 848 #endif // ENABLE(WEB_ARCHIVE) |
849 | 849 |
850 HistoryItem* parentItem = history()->currentItem(); | 850 HistoryItem* parentItem = history()->currentItem(); |
851 // If we're moving in the back/forward list, we might want to replace the co
ntent | 851 // If we're moving in the back/forward list, we might want to replace the co
ntent |
852 // of this child frame with whatever was there at that point. | 852 // of this child frame with whatever was there at that point. |
853 if (parentItem && parentItem->children().size() && isBackForwardLoadType(loa
dType()) | 853 if (parentItem && parentItem->children().size() && isBackForwardLoadType(loa
dType()) |
854 && !m_frame->document()->loadEventFinished()) { | 854 && !m_frame->document()->loadEventFinished()) { |
855 HistoryItem* childItem = parentItem->childItemWithTarget(childFrame->tre
e()->uniqueName()); | 855 HistoryItem* childItem = parentItem->childItemWithTarget(childFrame->tre
e()->uniqueName()); |
856 if (childItem) { | 856 if (childItem) { |
857 childFrame->loader()->loadDifferentDocumentItem(childItem, loadType(
), MayAttemptCacheOnlyLoadForFormSubmissionItem); | 857 childFrame->loader()->loadDifferentDocumentItem(childItem, loadType(
)); |
858 return; | 858 return; |
859 } | 859 } |
860 } | 860 } |
861 | 861 |
862 childFrame->loader()->loadURL(url, referer, "_self", false, FrameLoadTypeRed
irectWithLockedBackForwardList, 0, 0); | 862 childFrame->loader()->loadURL(url, referer, "_self", false, FrameLoadTypeRed
irectWithLockedBackForwardList, 0, 0); |
863 } | 863 } |
864 | 864 |
865 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) | 865 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
866 void FrameLoader::loadArchive(PassRefPtr<Archive> archive) | 866 void FrameLoader::loadArchive(PassRefPtr<Archive> archive) |
867 { | 867 { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 void FrameLoader::reloadWithOverrideEncoding(const String& encoding) | 1456 void FrameLoader::reloadWithOverrideEncoding(const String& encoding) |
1457 { | 1457 { |
1458 if (!m_documentLoader) | 1458 if (!m_documentLoader) |
1459 return; | 1459 return; |
1460 | 1460 |
1461 ResourceRequest request = m_documentLoader->request(); | 1461 ResourceRequest request = m_documentLoader->request(); |
1462 KURL unreachableURL = m_documentLoader->unreachableURL(); | 1462 KURL unreachableURL = m_documentLoader->unreachableURL(); |
1463 if (!unreachableURL.isEmpty()) | 1463 if (!unreachableURL.isEmpty()) |
1464 request.setURL(unreachableURL); | 1464 request.setURL(unreachableURL); |
1465 | 1465 |
1466 // FIXME: If the resource is a result of form submission and is not cached,
the form will be silently resubmitted. | |
1467 // We should ask the user for confirmation in this case. | |
1468 request.setCachePolicy(ReturnCacheDataElseLoad); | 1466 request.setCachePolicy(ReturnCacheDataElseLoad); |
1469 | 1467 |
1470 RefPtr<DocumentLoader> loader = m_client->createDocumentLoader(request, defa
ultSubstituteDataForURL(request.url())); | 1468 RefPtr<DocumentLoader> loader = m_client->createDocumentLoader(request, defa
ultSubstituteDataForURL(request.url())); |
1471 setPolicyDocumentLoader(loader.get()); | 1469 setPolicyDocumentLoader(loader.get()); |
1472 | 1470 |
1473 loader->setOverrideEncoding(encoding); | 1471 loader->setOverrideEncoding(encoding); |
1474 | 1472 |
1475 loadWithDocumentLoader(loader.get(), FrameLoadTypeReload, 0); | 1473 loadWithDocumentLoader(loader.get(), FrameLoadTypeReload, 0); |
1476 } | 1474 } |
1477 | 1475 |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 m_client->detachedFromParent3(); | 2413 m_client->detachedFromParent3(); |
2416 } | 2414 } |
2417 | 2415 |
2418 void FrameLoader::addExtraFieldsToSubresourceRequest(ResourceRequest& request) | 2416 void FrameLoader::addExtraFieldsToSubresourceRequest(ResourceRequest& request) |
2419 { | 2417 { |
2420 addExtraFieldsToRequest(request, m_loadType, false); | 2418 addExtraFieldsToRequest(request, m_loadType, false); |
2421 } | 2419 } |
2422 | 2420 |
2423 void FrameLoader::addExtraFieldsToMainResourceRequest(ResourceRequest& request) | 2421 void FrameLoader::addExtraFieldsToMainResourceRequest(ResourceRequest& request) |
2424 { | 2422 { |
2425 // FIXME: Using m_loadType seems wrong for some callers. | |
2426 // If we are only preparing to load the main resource, that is previous load
's load type! | |
2427 addExtraFieldsToRequest(request, m_loadType, true); | 2423 addExtraFieldsToRequest(request, m_loadType, true); |
2428 } | 2424 } |
2429 | 2425 |
2430 void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, FrameLoadTyp
e loadType, bool mainResource) | 2426 void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, FrameLoadTyp
e loadType, bool mainResource) |
2431 { | 2427 { |
2432 // Don't set the cookie policy URL if it's already been set. | 2428 // Don't set the cookie policy URL if it's already been set. |
2433 // But make sure to set it on all requests regardless of protocol, as it has
significance beyond the cookie policy (<rdar://problem/6616664>). | 2429 // But make sure to set it on all requests, as it has significance beyond th
e cookie policy for all protocols (<rdar://problem/6616664>). |
2434 if (request.firstPartyForCookies().isEmpty()) { | 2430 if (request.firstPartyForCookies().isEmpty()) { |
2435 if (mainResource && isLoadingMainFrame()) | 2431 if (mainResource && isLoadingMainFrame()) |
2436 request.setFirstPartyForCookies(request.url()); | 2432 request.setFirstPartyForCookies(request.url()); |
2437 else if (Document* document = m_frame->document()) | 2433 else if (Document* document = m_frame->document()) |
2438 request.setFirstPartyForCookies(document->firstPartyForCookies()); | 2434 request.setFirstPartyForCookies(document->firstPartyForCookies()); |
2439 } | 2435 } |
2440 | 2436 |
2441 // The remaining modifications are only necessary for HTTP and HTTPS. | 2437 // The remaining modifications are only necessary for HTTP and HTTPS. |
2442 if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) | 2438 if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) |
2443 return; | 2439 return; |
2444 | 2440 |
2445 applyUserAgent(request); | 2441 applyUserAgent(request); |
2446 | 2442 |
| 2443 // If we inherit cache policy from a main resource, we use the DocumentLoade
r's |
| 2444 // original request cache policy for two reasons: |
| 2445 // 1. For POST requests, we mutate the cache policy for the main resource, |
| 2446 // but we do not want this to apply to subresources |
| 2447 // 2. Delegates that modify the cache policy using willSendRequest: should |
| 2448 // not affect any other resources. Such changes need to be done |
| 2449 // per request. |
2447 if (!mainResource) { | 2450 if (!mainResource) { |
2448 if (request.isConditional()) | 2451 if (request.isConditional()) |
2449 request.setCachePolicy(ReloadIgnoringCacheData); | 2452 request.setCachePolicy(ReloadIgnoringCacheData); |
2450 else if (documentLoader()->isLoadingInAPISense()) { | 2453 else if (documentLoader()->isLoadingInAPISense()) |
2451 // If we inherit cache policy from a main resource, we use the Docum
entLoader's | 2454 request.setCachePolicy(documentLoader()->originalRequest().cachePoli
cy()); |
2452 // original request cache policy for two reasons: | 2455 else |
2453 // 1. For POST requests, we mutate the cache policy for the main res
ource, | |
2454 // but we do not want this to apply to subresources | |
2455 // 2. Delegates that modify the cache policy using willSendRequest:
should | |
2456 // not affect any other resources. Such changes need to be done | |
2457 // per request. | |
2458 ResourceRequestCachePolicy mainDocumentOriginalCachePolicy = documen
tLoader()->originalRequest().cachePolicy(); | |
2459 // Back-forward navigations try to load main resource from cache onl
y to avoid re-submitting form data, and start over (with a warning dialog) if th
at fails. | |
2460 // This policy is set on initial request too, but should not be inhe
rited. | |
2461 ResourceRequestCachePolicy subresourceCachePolicy = (mainDocumentOri
ginalCachePolicy == ReturnCacheDataDontLoad) ? ReturnCacheDataElseLoad : mainDoc
umentOriginalCachePolicy; | |
2462 request.setCachePolicy(subresourceCachePolicy); | |
2463 } else | |
2464 request.setCachePolicy(UseProtocolCachePolicy); | 2456 request.setCachePolicy(UseProtocolCachePolicy); |
2465 | |
2466 // FIXME: Other FrameLoader functions have duplicated code for setting cache
policy of main request when reloading. | |
2467 // It seems better to manage it explicitly than to hide the logic inside add
ExtraFieldsToRequest(). | |
2468 } else if (loadType == FrameLoadTypeReload || loadType == FrameLoadTypeReloa
dFromOrigin || request.isConditional()) | 2457 } else if (loadType == FrameLoadTypeReload || loadType == FrameLoadTypeReloa
dFromOrigin || request.isConditional()) |
2469 request.setCachePolicy(ReloadIgnoringCacheData); | 2458 request.setCachePolicy(ReloadIgnoringCacheData); |
2470 | 2459 else if (isBackForwardLoadType(loadType) && m_stateMachine.committedFirstRea
lDocumentLoad()) |
| 2460 request.setCachePolicy(ReturnCacheDataElseLoad); |
| 2461 |
2471 if (request.cachePolicy() == ReloadIgnoringCacheData) { | 2462 if (request.cachePolicy() == ReloadIgnoringCacheData) { |
2472 if (loadType == FrameLoadTypeReload) | 2463 if (loadType == FrameLoadTypeReload) |
2473 request.setHTTPHeaderField("Cache-Control", "max-age=0"); | 2464 request.setHTTPHeaderField("Cache-Control", "max-age=0"); |
2474 else if (loadType == FrameLoadTypeReloadFromOrigin) { | 2465 else if (loadType == FrameLoadTypeReloadFromOrigin) { |
2475 request.setHTTPHeaderField("Cache-Control", "no-cache"); | 2466 request.setHTTPHeaderField("Cache-Control", "no-cache"); |
2476 request.setHTTPHeaderField("Pragma", "no-cache"); | 2467 request.setHTTPHeaderField("Pragma", "no-cache"); |
2477 } | 2468 } |
2478 } | 2469 } |
2479 | 2470 |
2480 if (mainResource) | 2471 if (mainResource) |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3044 // loadInSameDocument() actually changes the URL and notifies load delegates
of a "fake" load | 3035 // loadInSameDocument() actually changes the URL and notifies load delegates
of a "fake" load |
3045 loadInSameDocument(item->url(), item->stateObject(), false); | 3036 loadInSameDocument(item->url(), item->stateObject(), false); |
3046 | 3037 |
3047 // Restore user view state from the current history item here since we don't
do a normal load. | 3038 // Restore user view state from the current history item here since we don't
do a normal load. |
3048 history()->restoreScrollPositionAndViewState(); | 3039 history()->restoreScrollPositionAndViewState(); |
3049 } | 3040 } |
3050 | 3041 |
3051 // FIXME: This function should really be split into a couple pieces, some of | 3042 // FIXME: This function should really be split into a couple pieces, some of |
3052 // which should be methods of HistoryController and some of which should be | 3043 // which should be methods of HistoryController and some of which should be |
3053 // methods of FrameLoader. | 3044 // methods of FrameLoader. |
3054 void FrameLoader::loadDifferentDocumentItem(HistoryItem* item, FrameLoadType loa
dType, FormSubmissionCacheLoadPolicy cacheLoadPolicy) | 3045 void FrameLoader::loadDifferentDocumentItem(HistoryItem* item, FrameLoadType loa
dType) |
3055 { | 3046 { |
3056 // Remember this item so we can traverse any child items as child frames loa
d | 3047 // Remember this item so we can traverse any child items as child frames loa
d |
3057 history()->setProvisionalItem(item); | 3048 history()->setProvisionalItem(item); |
3058 | 3049 |
3059 if (CachedPage* cachedPage = pageCache()->get(item)) { | 3050 if (CachedPage* cachedPage = pageCache()->get(item)) { |
3060 loadWithDocumentLoader(cachedPage->documentLoader(), loadType, 0); | 3051 loadWithDocumentLoader(cachedPage->documentLoader(), loadType, 0); |
3061 return; | 3052 return; |
3062 } | 3053 } |
3063 | 3054 |
3064 KURL itemURL = item->url(); | 3055 KURL itemURL = item->url(); |
(...skipping 14 matching lines...) Expand all Loading... |
3079 formData->generateFiles(m_frame->document()); | 3070 formData->generateFiles(m_frame->document()); |
3080 | 3071 |
3081 request.setHTTPMethod("POST"); | 3072 request.setHTTPMethod("POST"); |
3082 request.setHTTPBody(formData); | 3073 request.setHTTPBody(formData); |
3083 request.setHTTPContentType(item->formContentType()); | 3074 request.setHTTPContentType(item->formContentType()); |
3084 RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString
(item->referrer()); | 3075 RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString
(item->referrer()); |
3085 addHTTPOriginIfNeeded(request, securityOrigin->toString()); | 3076 addHTTPOriginIfNeeded(request, securityOrigin->toString()); |
3086 | 3077 |
3087 // Make sure to add extra fields to the request after the Origin header
is added for the FormData case. | 3078 // Make sure to add extra fields to the request after the Origin header
is added for the FormData case. |
3088 // See https://bugs.webkit.org/show_bug.cgi?id=22194 for more discussion
. | 3079 // See https://bugs.webkit.org/show_bug.cgi?id=22194 for more discussion
. |
3089 addExtraFieldsToRequest(request, loadType, true); | 3080 addExtraFieldsToRequest(request, m_loadType, true); |
3090 | 3081 |
3091 // FIXME: Slight hack to test if the NSURL cache contains the page we're
going to. | 3082 // FIXME: Slight hack to test if the NSURL cache contains the page we're
going to. |
3092 // We want to know this before talking to the policy delegate, since it
affects whether | 3083 // We want to know this before talking to the policy delegate, since it
affects whether |
3093 // we show the DoYouReallyWantToRepost nag. | 3084 // we show the DoYouReallyWantToRepost nag. |
3094 // | 3085 // |
3095 // This trick has a small bug (3123893) where we might find a cache hit,
but then | 3086 // This trick has a small bug (3123893) where we might find a cache hit,
but then |
3096 // have the item vanish when we try to use it in the ensuing nav. This
should be | 3087 // have the item vanish when we try to use it in the ensuing nav. This
should be |
3097 // extremely rare, but in that case the user will get an error on the na
vigation. | 3088 // extremely rare, but in that case the user will get an error on the na
vigation. |
3098 | 3089 |
3099 if (cacheLoadPolicy == MayAttemptCacheOnlyLoadForFormSubmissionItem) { | 3090 if (ResourceHandle::willLoadFromCache(request, m_frame)) |
3100 request.setCachePolicy(ReturnCacheDataDontLoad); | |
3101 action = NavigationAction(request, loadType, false); | 3091 action = NavigationAction(request, loadType, false); |
3102 } else { | 3092 else { |
3103 request.setCachePolicy(ReturnCacheDataElseLoad); | 3093 request.setCachePolicy(ReloadIgnoringCacheData); |
3104 action = NavigationAction(request, NavigationTypeFormResubmitted); | 3094 action = NavigationAction(request, NavigationTypeFormResubmitted); |
3105 } | 3095 } |
3106 } else { | 3096 } else { |
3107 switch (loadType) { | 3097 switch (loadType) { |
3108 case FrameLoadTypeReload: | 3098 case FrameLoadTypeReload: |
3109 case FrameLoadTypeReloadFromOrigin: | 3099 case FrameLoadTypeReloadFromOrigin: |
3110 request.setCachePolicy(ReloadIgnoringCacheData); | 3100 request.setCachePolicy(ReloadIgnoringCacheData); |
3111 break; | 3101 break; |
3112 case FrameLoadTypeBack: | 3102 case FrameLoadTypeBack: |
3113 case FrameLoadTypeForward: | 3103 case FrameLoadTypeForward: |
3114 case FrameLoadTypeIndexedBackForward: | 3104 case FrameLoadTypeIndexedBackForward: |
3115 // If the first load within a frame is a navigation within a bac
k/forward list that was attached | 3105 // If the first load within a frame is a navigation within a bac
k/forward list that was attached |
3116 // without any of the items being loaded then we should use the
default caching policy (<rdar://problem/8131355>). | 3106 // without any of the items being loaded then we should use the
default caching policy (<rdar://problem/8131355>). |
3117 if (m_stateMachine.committedFirstRealDocumentLoad()) | 3107 if (m_stateMachine.committedFirstRealDocumentLoad() && !itemURL.
protocolIs("https")) |
3118 request.setCachePolicy(ReturnCacheDataElseLoad); | 3108 request.setCachePolicy(ReturnCacheDataElseLoad); |
3119 break; | 3109 break; |
3120 case FrameLoadTypeStandard: | 3110 case FrameLoadTypeStandard: |
3121 case FrameLoadTypeRedirectWithLockedBackForwardList: | 3111 case FrameLoadTypeRedirectWithLockedBackForwardList: |
3122 break; | 3112 break; |
3123 case FrameLoadTypeSame: | 3113 case FrameLoadTypeSame: |
3124 default: | 3114 default: |
3125 ASSERT_NOT_REACHED(); | 3115 ASSERT_NOT_REACHED(); |
3126 } | 3116 } |
3127 | 3117 |
3128 addExtraFieldsToRequest(request, loadType, true); | 3118 addExtraFieldsToRequest(request, m_loadType, true); |
3129 | 3119 |
3130 ResourceRequest requestForOriginalURL(request); | 3120 ResourceRequest requestForOriginalURL(request); |
3131 requestForOriginalURL.setURL(itemOriginalURL); | 3121 requestForOriginalURL.setURL(itemOriginalURL); |
3132 action = NavigationAction(requestForOriginalURL, loadType, false); | 3122 action = NavigationAction(requestForOriginalURL, loadType, false); |
3133 } | 3123 } |
3134 | 3124 |
3135 loadWithNavigationAction(request, action, false, loadType, 0); | 3125 loadWithNavigationAction(request, action, false, loadType, 0); |
3136 } | 3126 } |
3137 | 3127 |
3138 // Loads content into this frame, as specified by history item | 3128 // Loads content into this frame, as specified by history item |
3139 void FrameLoader::loadItem(HistoryItem* item, FrameLoadType loadType) | 3129 void FrameLoader::loadItem(HistoryItem* item, FrameLoadType loadType) |
3140 { | 3130 { |
3141 m_requestedHistoryItem = item; | 3131 m_requestedHistoryItem = item; |
3142 HistoryItem* currentItem = history()->currentItem(); | 3132 HistoryItem* currentItem = history()->currentItem(); |
3143 bool sameDocumentNavigation = currentItem && item->shouldDoSameDocumentNavig
ationTo(currentItem); | 3133 bool sameDocumentNavigation = currentItem && item->shouldDoSameDocumentNavig
ationTo(currentItem); |
3144 | 3134 |
3145 if (sameDocumentNavigation) | 3135 if (sameDocumentNavigation) |
3146 loadSameDocumentItem(item); | 3136 loadSameDocumentItem(item); |
3147 else | 3137 else |
3148 loadDifferentDocumentItem(item, loadType, MayAttemptCacheOnlyLoadForForm
SubmissionItem); | 3138 loadDifferentDocumentItem(item, loadType); |
3149 } | |
3150 | |
3151 void FrameLoader::retryAfterFailedCacheOnlyMainResourceLoad() | |
3152 { | |
3153 ASSERT(m_state == FrameStateProvisional); | |
3154 ASSERT(!m_loadingFromCachedPage); | |
3155 // We only use cache-only loads to avoid resubmitting forms. | |
3156 ASSERT(isBackForwardLoadType(m_loadType)); | |
3157 ASSERT(m_history.provisionalItem()->formData()); | |
3158 ASSERT(m_history.provisionalItem() == m_requestedHistoryItem.get()); | |
3159 | |
3160 FrameLoadType loadType = m_loadType; | |
3161 HistoryItem* item = m_history.provisionalItem(); | |
3162 | |
3163 stopAllLoaders(ShouldNotClearProvisionalItem); | |
3164 loadDifferentDocumentItem(item, loadType, MayNotAttemptCacheOnlyLoadForFormS
ubmissionItem); | |
3165 } | 3139 } |
3166 | 3140 |
3167 ResourceError FrameLoader::cancelledError(const ResourceRequest& request) const | 3141 ResourceError FrameLoader::cancelledError(const ResourceRequest& request) const |
3168 { | 3142 { |
3169 ResourceError error = m_client->cancelledError(request); | 3143 ResourceError error = m_client->cancelledError(request); |
3170 error.setIsCancellation(true); | 3144 error.setIsCancellation(true); |
3171 return error; | 3145 return error; |
3172 } | 3146 } |
3173 | 3147 |
3174 void FrameLoader::setTitle(const StringWithDirection& title) | 3148 void FrameLoader::setTitle(const StringWithDirection& title) |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 FloatRect newWindowRect = DOMWindow::adjustWindowRect(page, windowRect); | 3368 FloatRect newWindowRect = DOMWindow::adjustWindowRect(page, windowRect); |
3395 | 3369 |
3396 page->chrome()->setWindowRect(newWindowRect); | 3370 page->chrome()->setWindowRect(newWindowRect); |
3397 page->chrome()->show(); | 3371 page->chrome()->show(); |
3398 | 3372 |
3399 created = true; | 3373 created = true; |
3400 return frame; | 3374 return frame; |
3401 } | 3375 } |
3402 | 3376 |
3403 } // namespace WebCore | 3377 } // namespace WebCore |
OLD | NEW |