Bug 1202895 - Fix shift-reload check for setting up service worker. r=bkelly

This commit is contained in:
Brendan Dahl 2015-09-16 15:28:45 -07:00
Родитель 28d24ea24f
Коммит 47647e9a4f
3 изменённых файлов: 21 добавлений и 17 удалений

Просмотреть файл

@ -10871,10 +10871,7 @@ nsDocShell::DoChannelLoad(nsIChannel* aChannel,
// If the user pressed shift-reload, then do not allow ServiceWorker
// interception to occur. See step 12.1 of the SW HandleFetch algorithm.
if (mLoadType == LOAD_RELOAD_BYPASS_CACHE ||
mLoadType == LOAD_RELOAD_BYPASS_PROXY ||
mLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
mLoadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) {
if (IsForceReloadType(mLoadType)) {
nsCOMPtr<nsIHttpChannelInternal> internal = do_QueryInterface(aChannel);
if (internal) {
internal->ForceNoIntercept();
@ -11163,11 +11160,7 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel, nsISupports* aOwner,
* for the page. Save the new cacheKey in Session History.
* see bug 90098
*/
if (aChannel &&
(aLoadType == LOAD_RELOAD_BYPASS_CACHE ||
aLoadType == LOAD_RELOAD_BYPASS_PROXY ||
aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
aLoadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT)) {
if (aChannel && IsForceReloadType(aLoadType)) {
NS_ASSERTION(!updateSHistory,
"We shouldn't be updating session history for forced"
" reloads!");

Просмотреть файл

@ -101,5 +101,17 @@ IsValidLoadType(uint32_t aLoadType)
return false;
}
static inline bool
IsForceReloadType(uint32_t aLoadType) {
switch (aLoadType) {
case LOAD_RELOAD_BYPASS_CACHE:
case LOAD_RELOAD_BYPASS_PROXY:
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
return true;
}
return false;
}
#endif // MOZILLA_INTERNAL_API
#endif

Просмотреть файл

@ -33,6 +33,7 @@
#include "mozilla/css/Loader.h"
#include "mozilla/css/ImageLoader.h"
#include "nsDocShell.h"
#include "nsDocShellLoadTypes.h"
#include "nsIDocShellTreeItem.h"
#include "nsCOMArray.h"
#include "nsQueryObject.h"
@ -4730,15 +4731,13 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
mTemplateContentsOwner->SetScriptGlobalObject(aScriptGlobalObject);
}
nsCOMPtr<nsIChannel> channel = GetChannel();
if (!mMaybeServiceWorkerControlled && channel) {
nsLoadFlags loadFlags = 0;
channel->GetLoadFlags(&loadFlags);
if (!mMaybeServiceWorkerControlled && mDocumentContainer && mScriptGlobalObject && GetChannel()) {
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
uint32_t loadType;
docShell->GetLoadType(&loadType);
// If we are shift-reloaded, don't associate with a ServiceWorker.
// TODO: This should check the nsDocShell definition of shift-reload instead
// of trying to infer it from LOAD_BYPASS_CACHE. The current code
// will probably cause problems once bug 1120715 lands.
if (loadFlags & nsIRequest::LOAD_BYPASS_CACHE) {
if (IsForceReloadType(loadType)) {
NS_WARNING("Page was shift reloaded, skipping ServiceWorker control");
return;
}