Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 18808004: Refactoring: Extract DocumentInit for capture Document construction parameter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed webkit_unit_tests build failure. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentInit.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return; 361 return;
362 if (document->childNeedsStyleRecalc()) 362 if (document->childNeedsStyleRecalc())
363 return; 363 return;
364 if (document->focusedNode()->renderer() && document->focusedNode()->rend erer()->needsLayout()) 364 if (document->focusedNode()->renderer() && document->focusedNode()->rend erer()->needsLayout())
365 return; 365 return;
366 if (!document->focusedNode()->isFocusable()) 366 if (!document->focusedNode()->isFocusable())
367 document->setFocusedElement(0); 367 document->setFocusedElement(0);
368 } 368 }
369 }; 369 };
370 370
371 Document::Document(Frame* frame, const KURL& url, DocumentClassFlags documentCla sses) 371 Document::Document(const DocumentInit& initializer, DocumentClassFlags documentC lasses)
372 : ContainerNode(0, CreateDocument) 372 : ContainerNode(0, CreateDocument)
373 , TreeScope(this) 373 , TreeScope(this)
374 , m_styleResolverThrowawayTimer(this, &Document::styleResolverThrowawayTimer Fired) 374 , m_styleResolverThrowawayTimer(this, &Document::styleResolverThrowawayTimer Fired)
375 , m_lastStyleResolverAccessTime(0) 375 , m_lastStyleResolverAccessTime(0)
376 , m_didCalculateStyleResolver(false) 376 , m_didCalculateStyleResolver(false)
377 , m_ignorePendingStylesheets(false) 377 , m_ignorePendingStylesheets(false)
378 , m_needsNotifyRemoveAllPendingStylesheet(false) 378 , m_needsNotifyRemoveAllPendingStylesheet(false)
379 , m_hasNodesWithPlaceholderStyle(false) 379 , m_hasNodesWithPlaceholderStyle(false)
380 , m_pendingSheetLayout(NoLayoutWithPendingSheets) 380 , m_pendingSheetLayout(NoLayoutWithPendingSheets)
381 , m_frame(frame) 381 , m_frame(initializer.frame())
382 , m_domWindow(0) 382 , m_domWindow(0)
383 , m_import(initializer.import())
383 , m_activeParserCount(0) 384 , m_activeParserCount(0)
384 , m_contextFeatures(ContextFeatures::defaultSwitch()) 385 , m_contextFeatures(ContextFeatures::defaultSwitch())
385 , m_wellFormed(false) 386 , m_wellFormed(false)
386 , m_printing(false) 387 , m_printing(false)
387 , m_paginatedForScreen(false) 388 , m_paginatedForScreen(false)
388 , m_ignoreAutofocus(false) 389 , m_ignoreAutofocus(false)
389 , m_compatibilityMode(NoQuirksMode) 390 , m_compatibilityMode(NoQuirksMode)
390 , m_compatibilityModeLocked(false) 391 , m_compatibilityModeLocked(false)
391 , m_didPostCheckFocusedNodeTask(false) 392 , m_didPostCheckFocusedNodeTask(false)
392 , m_domTreeVersion(++s_globalTreeVersion) 393 , m_domTreeVersion(++s_globalTreeVersion)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 , m_referrerPolicy(ReferrerPolicyDefault) 436 , m_referrerPolicy(ReferrerPolicyDefault)
436 , m_directionSetOnDocumentElement(false) 437 , m_directionSetOnDocumentElement(false)
437 , m_writingModeSetOnDocumentElement(false) 438 , m_writingModeSetOnDocumentElement(false)
438 , m_writeRecursionIsTooDeep(false) 439 , m_writeRecursionIsTooDeep(false)
439 , m_writeRecursionDepth(0) 440 , m_writeRecursionDepth(0)
440 , m_wheelEventHandlerCount(0) 441 , m_wheelEventHandlerCount(0)
441 , m_lastHandledUserGestureTimestamp(0) 442 , m_lastHandledUserGestureTimestamp(0)
442 , m_prerenderer(Prerenderer::create(this)) 443 , m_prerenderer(Prerenderer::create(this))
443 , m_textAutosizer(TextAutosizer::create(this)) 444 , m_textAutosizer(TextAutosizer::create(this))
444 , m_pendingTasksTimer(this, &Document::pendingTasksTimerFired) 445 , m_pendingTasksTimer(this, &Document::pendingTasksTimerFired)
445 , m_import(0)
446 , m_scheduledTasksAreSuspended(false) 446 , m_scheduledTasksAreSuspended(false)
447 , m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFi red) 447 , m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFi red)
448 #ifndef NDEBUG 448 #ifndef NDEBUG
449 , m_didDispatchViewportPropertiesChanged(false) 449 , m_didDispatchViewportPropertiesChanged(false)
450 #endif 450 #endif
451 , m_timeline(DocumentTimeline::create(this)) 451 , m_timeline(DocumentTimeline::create(this))
452 , m_templateDocumentHost(0) 452 , m_templateDocumentHost(0)
453 , m_fontloader(0) 453 , m_fontloader(0)
454 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired) 454 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired)
455 { 455 {
456 ScriptWrappable::init(this); 456 ScriptWrappable::init(this);
457 457
458 if (m_frame) { 458 if (m_frame) {
459 provideContextFeaturesToDocumentFrom(this, m_frame->page()); 459 provideContextFeaturesToDocumentFrom(this, m_frame->page());
460 460
461 m_cachedResourceLoader = m_frame->loader()->activeDocumentLoader()->cach edResourceLoader(); 461 m_cachedResourceLoader = m_frame->loader()->activeDocumentLoader()->cach edResourceLoader();
462 } 462 }
463 463
464 if (!m_cachedResourceLoader) 464 if (!m_cachedResourceLoader)
465 m_cachedResourceLoader = CachedResourceLoader::create(0); 465 m_cachedResourceLoader = CachedResourceLoader::create(0);
466 m_cachedResourceLoader->setDocument(this); 466 m_cachedResourceLoader->setDocument(this);
467 467
468 // We depend on the url getting immediately set in subframes, but we 468 // We depend on the url getting immediately set in subframes, but we
469 // also depend on the url NOT getting immediately set in opened windows. 469 // also depend on the url NOT getting immediately set in opened windows.
470 // See fast/dom/early-frame-url.html 470 // See fast/dom/early-frame-url.html
471 // and fast/dom/location-new-window-no-crash.html, respectively. 471 // and fast/dom/location-new-window-no-crash.html, respectively.
472 // FIXME: Can/should we unify this behavior? 472 // FIXME: Can/should we unify this behavior?
473 if ((m_frame && m_frame->ownerElement()) || !url.isEmpty()) 473 if (initializer.shouldSetURL())
474 setURL(url); 474 setURL(initializer.url());
475 475
476 initSecurityContext(); 476 initSecurityContext(initializer);
477 initDNSPrefetch(); 477 initDNSPrefetch();
478 478
479 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++) 479 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++)
480 m_nodeListCounts[i] = 0; 480 m_nodeListCounts[i] = 0;
481 481
482 InspectorCounters::incrementCounter(InspectorCounters::DocumentCounter); 482 InspectorCounters::incrementCounter(InspectorCounters::DocumentCounter);
483 483
484 bool shouldProcessCustomElements = 484 bool shouldProcessCustomElements =
485 (isHTMLDocument() || isXHTMLDocument()) 485 (isHTMLDocument() || isXHTMLDocument())
486 && RuntimeEnabledFeatures::customDOMElementsEnabled(); 486 && RuntimeEnabledFeatures::customDOMElementsEnabled();
(...skipping 3691 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 return false; 4178 return false;
4179 if (child->isSrcdocDocument()) 4179 if (child->isSrcdocDocument())
4180 return true; 4180 return true;
4181 if (parent->securityOrigin()->canAccess(child->securityOrigin())) 4181 if (parent->securityOrigin()->canAccess(child->securityOrigin()))
4182 return true; 4182 return true;
4183 return parent->securityOrigin()->canRequest(child->url()); 4183 return parent->securityOrigin()->canRequest(child->url());
4184 } 4184 }
4185 4185
4186 void Document::initSecurityContext() 4186 void Document::initSecurityContext()
4187 { 4187 {
4188 initSecurityContext(DocumentInit(m_url, m_frame, m_import));
4189 }
4190
4191 void Document::initSecurityContext(const DocumentInit& initializer)
4192 {
4188 if (haveInitializedSecurityOrigin()) { 4193 if (haveInitializedSecurityOrigin()) {
4189 ASSERT(securityOrigin()); 4194 ASSERT(securityOrigin());
4190 return; 4195 return;
4191 } 4196 }
4192 4197
4193 if (!m_frame) { 4198 if (!initializer.frame()) {
4194 // No source for a security context. 4199 // No source for a security context.
4195 // This can occur via document.implementation.createDocument(). 4200 // This can occur via document.implementation.createDocument().
4196 m_cookieURL = KURL(ParsedURLString, emptyString()); 4201 m_cookieURL = KURL(ParsedURLString, emptyString());
4197 setSecurityOrigin(SecurityOrigin::createUnique()); 4202 setSecurityOrigin(SecurityOrigin::createUnique());
4198 setContentSecurityPolicy(ContentSecurityPolicy::create(this)); 4203 setContentSecurityPolicy(ContentSecurityPolicy::create(this));
4199 return; 4204 return;
4200 } 4205 }
4201 4206
4202 // In the common case, create the security context from the currently 4207 // In the common case, create the security context from the currently
4203 // loading URL with a fresh content security policy. 4208 // loading URL with a fresh content security policy.
4204 m_cookieURL = m_url; 4209 m_cookieURL = m_url;
4205 enforceSandboxFlags(m_frame->loader()->effectiveSandboxFlags()); 4210 enforceSandboxFlags(initializer.sandboxFlags());
4206 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url)); 4211 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url));
4207 setContentSecurityPolicy(ContentSecurityPolicy::create(this)); 4212 setContentSecurityPolicy(ContentSecurityPolicy::create(this));
4208 4213
4209 if (Settings* settings = this->settings()) { 4214 if (Settings* settings = initializer.settings()) {
4210 if (!settings->webSecurityEnabled()) { 4215 if (!settings->webSecurityEnabled()) {
4211 // Web security is turned off. We should let this document access ev ery other document. This is used primary by testing 4216 // Web security is turned off. We should let this document access ev ery other document. This is used primary by testing
4212 // harnesses for web sites. 4217 // harnesses for web sites.
4213 securityOrigin()->grantUniversalAccess(); 4218 securityOrigin()->grantUniversalAccess();
4214 } else if (securityOrigin()->isLocal()) { 4219 } else if (securityOrigin()->isLocal()) {
4215 if (settings->allowUniversalAccessFromFileURLs()) { 4220 if (settings->allowUniversalAccessFromFileURLs()) {
4216 // Some clients want local URLs to have universal access, but th at setting is dangerous for other clients. 4221 // Some clients want local URLs to have universal access, but th at setting is dangerous for other clients.
4217 securityOrigin()->grantUniversalAccess(); 4222 securityOrigin()->grantUniversalAccess();
4218 } else if (!settings->allowFileAccessFromFileURLs()) { 4223 } else if (!settings->allowFileAccessFromFileURLs()) {
4219 // Some clients want local URLs to have even tighter restriction s by default, and not be able to access other local files. 4224 // Some clients want local URLs to have even tighter restriction s by default, and not be able to access other local files.
4220 // FIXME 81578: The naming of this is confusing. Files with rest ricted access to other local files 4225 // FIXME 81578: The naming of this is confusing. Files with rest ricted access to other local files
4221 // still can have other privileges that can be remembered, there by not making them unique origins. 4226 // still can have other privileges that can be remembered, there by not making them unique origins.
4222 securityOrigin()->enforceFilePathSeparation(); 4227 securityOrigin()->enforceFilePathSeparation();
4223 } 4228 }
4224 } 4229 }
4225 } 4230 }
4226 4231
4227 Document* parentDocument = ownerElement() ? ownerElement()->document() : 0; 4232 Document* parentDocument = ownerElement() ? ownerElement()->document() : 0;
4228 if (parentDocument && m_frame->loader()->shouldTreatURLAsSrcdocDocument(url( ))) { 4233 if (parentDocument && initializer.shouldTreatURLAsSrcdocDocument()) {
4229 m_isSrcdocDocument = true; 4234 m_isSrcdocDocument = true;
4230 setBaseURLOverride(parentDocument->baseURL()); 4235 setBaseURLOverride(parentDocument->baseURL());
4231 } 4236 }
4232 4237
4233 // FIXME: What happens if we inherit the security origin? This check may nee d to be later. 4238 // FIXME: What happens if we inherit the security origin? This check may nee d to be later.
4234 // <iframe seamless src="about:blank"> likely won't work as-is. 4239 // <iframe seamless src="about:blank"> likely won't work as-is.
4235 m_mayDisplaySeamlesslyWithParent = isEligibleForSeamless(parentDocument, thi s); 4240 m_mayDisplaySeamlesslyWithParent = isEligibleForSeamless(parentDocument, thi s);
4236 4241
4237 if (!shouldInheritSecurityOriginFromOwner(m_url)) 4242 if (!shouldInheritSecurityOriginFromOwner(m_url))
4238 return; 4243 return;
4239 4244
4240 // If we do not obtain a meaningful origin from the URL, then we try to 4245 // If we do not obtain a meaningful origin from the URL, then we try to
4241 // find one via the frame hierarchy. 4246 // find one via the frame hierarchy.
4242 4247
4243 Frame* ownerFrame = m_frame->tree()->parent(); 4248 Frame* ownerFrame = initializer.ownerFrame();
4244 if (!ownerFrame)
4245 ownerFrame = m_frame->loader()->opener();
4246
4247 if (!ownerFrame) { 4249 if (!ownerFrame) {
4248 didFailToInitializeSecurityOrigin(); 4250 didFailToInitializeSecurityOrigin();
4249 return; 4251 return;
4250 } 4252 }
4251 4253
4252 if (isSandboxed(SandboxOrigin)) { 4254 if (isSandboxed(SandboxOrigin)) {
4253 // If we're supposed to inherit our security origin from our owner, 4255 // If we're supposed to inherit our security origin from our owner,
4254 // but we're also sandboxed, the only thing we inherit is the ability 4256 // but we're also sandboxed, the only thing we inherit is the ability
4255 // to load local resources. This lets about:blank iframes in file:// 4257 // to load local resources. This lets about:blank iframes in file://
4256 // URL documents load images and other resources from the file system. 4258 // URL documents load images and other resources from the file system.
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
5110 result.iterator->value = Locale::create(localeKey); 5112 result.iterator->value = Locale::create(localeKey);
5111 return *(result.iterator->value); 5113 return *(result.iterator->value);
5112 } 5114 }
5113 5115
5114 Document* Document::ensureTemplateDocument() 5116 Document* Document::ensureTemplateDocument()
5115 { 5117 {
5116 if (const Document* document = templateDocument()) 5118 if (const Document* document = templateDocument())
5117 return const_cast<Document*>(document); 5119 return const_cast<Document*>(document);
5118 5120
5119 if (isHTMLDocument()) 5121 if (isHTMLDocument())
5120 m_templateDocument = HTMLDocument::create(0, blankURL()); 5122 m_templateDocument = HTMLDocument::create(DocumentInit(blankURL()));
5121 else 5123 else
5122 m_templateDocument = Document::create(0, blankURL()); 5124 m_templateDocument = Document::create(DocumentInit(blankURL()));
5123 5125
5124 m_templateDocument->setTemplateDocumentHost(this); // balanced in dtor. 5126 m_templateDocument->setTemplateDocumentHost(this); // balanced in dtor.
5125 5127
5126 return m_templateDocument.get(); 5128 return m_templateDocument.get();
5127 } 5129 }
5128 5130
5129 PassRefPtr<FontLoader> Document::fontloader() 5131 PassRefPtr<FontLoader> Document::fontloader()
5130 { 5132 {
5131 if (!m_fontloader) 5133 if (!m_fontloader)
5132 m_fontloader = FontLoader::create(this); 5134 m_fontloader = FontLoader::create(this);
(...skipping 26 matching lines...) Expand all
5159 { 5161 {
5160 return DocumentLifecycleNotifier::create(this); 5162 return DocumentLifecycleNotifier::create(this);
5161 } 5163 }
5162 5164
5163 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5165 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5164 { 5166 {
5165 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5167 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5166 } 5168 }
5167 5169
5168 } // namespace WebCore 5170 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentInit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698