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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLLinkElement.cpp

Issue 2553803003: Refactor HTMLLinkElement
Patch Set: a Created 4 years 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
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 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) 7 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com)
8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "public/platform/WebIconSizesParser.h" 43 #include "public/platform/WebIconSizesParser.h"
44 #include "public/platform/WebSize.h" 44 #include "public/platform/WebSize.h"
45 45
46 namespace blink { 46 namespace blink {
47 47
48 using namespace HTMLNames; 48 using namespace HTMLNames;
49 49
50 inline HTMLLinkElement::HTMLLinkElement(Document& document, 50 inline HTMLLinkElement::HTMLLinkElement(Document& document,
51 bool createdByParser) 51 bool createdByParser)
52 : HTMLElement(linkTag, document), 52 : HTMLElement(linkTag, document),
53 m_linkLoader(LinkLoader::create(this)),
54 m_sizes(DOMTokenList::create(this)), 53 m_sizes(DOMTokenList::create(this)),
55 m_relList(this, RelList::create(this)), 54 m_relList(this, RelList::create(this)),
56 m_createdByParser(createdByParser) {} 55 m_createdByParser(createdByParser) {}
57 56
58 HTMLLinkElement* HTMLLinkElement::create(Document& document, 57 HTMLLinkElement* HTMLLinkElement::create(Document& document,
59 bool createdByParser) { 58 bool createdByParser) {
60 return new HTMLLinkElement(document, createdByParser); 59 return new HTMLLinkElement(document, createdByParser);
61 } 60 }
62 61
63 HTMLLinkElement::~HTMLLinkElement() {} 62 HTMLLinkElement::~HTMLLinkElement() {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 102 }
104 103
105 HTMLElement::parseAttribute(name, oldValue, value); 104 HTMLElement::parseAttribute(name, oldValue, value);
106 } 105 }
107 } 106 }
108 107
109 bool HTMLLinkElement::shouldLoadLink() { 108 bool HTMLLinkElement::shouldLoadLink() {
110 return isInDocumentTree() || (isConnected() && m_relAttribute.isStyleSheet()); 109 return isInDocumentTree() || (isConnected() && m_relAttribute.isStyleSheet());
111 } 110 }
112 111
112 FetchRequest HTMLLinkElement::createFetchRequest() const {
113 AtomicString charset = getAttribute(charsetAttr);
114 if (charset.isEmpty() && document().frame())
115 charset = document().characterSet();
116
117 FetchRequest request(ResourceRequest(document().completeURL(
118 getNonEmptyURLAttribute(hrefAttr))),
119 localName(), charset);
120 request.setContentSecurityPolicyNonce(fastGetAttribute(HTMLNames::nonceAttr));
121 return request;
122 }
123
113 bool HTMLLinkElement::loadLink(const String& type, 124 bool HTMLLinkElement::loadLink(const String& type,
114 const String& as, 125 const String& as,
115 const String& media, 126 const String& media,
116 ReferrerPolicy referrerPolicy, 127 ReferrerPolicy referrerPolicy,
117 const KURL& url) { 128 const KURL& url) {
129 if (!m_linkLoader)
130 m_linkLoader = LinkLoader::create(this);
131
118 return m_linkLoader->loadLink( 132 return m_linkLoader->loadLink(
119 m_relAttribute, 133 m_relAttribute,
120 crossOriginAttributeValue(fastGetAttribute(HTMLNames::crossoriginAttr)), 134 crossOriginAttributeValue(fastGetAttribute(HTMLNames::crossoriginAttr)),
121 type, as, media, referrerPolicy, url, document(), 135 type, as, media, referrerPolicy, url, document(),
122 NetworkHintsInterfaceImpl()); 136 NetworkHintsInterfaceImpl());
123 } 137 }
124 138
125 LinkResource* HTMLLinkElement::linkResourceToProcess() { 139 LinkResource* HTMLLinkElement::linkResourceToProcess() {
126 if (!shouldLoadLink()) { 140 if (!shouldLoadLink()) {
127 DCHECK(!linkStyle() || !linkStyle()->hasSheet()); 141 DCHECK(!linkStyle() || !linkStyle()->hasSheet());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 217 }
204 218
205 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) { 219 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) {
206 // Store the result of isConnected() here before Node::removedFrom(..) clears 220 // Store the result of isConnected() here before Node::removedFrom(..) clears
207 // the flags. 221 // the flags.
208 bool wasConnected = isConnected(); 222 bool wasConnected = isConnected();
209 HTMLElement::removedFrom(insertionPoint); 223 HTMLElement::removedFrom(insertionPoint);
210 if (!insertionPoint->isConnected()) 224 if (!insertionPoint->isConnected())
211 return; 225 return;
212 226
213 m_linkLoader->released(); 227 if (m_linkLoader)
228 m_linkLoader->released();
214 229
215 if (!wasConnected) { 230 if (!wasConnected) {
216 DCHECK(!linkStyle() || !linkStyle()->hasSheet()); 231 DCHECK(!linkStyle() || !linkStyle()->hasSheet());
217 return; 232 return;
218 } 233 }
219 document().styleEngine().removeStyleSheetCandidateNode(*this); 234 document().styleEngine().removeStyleSheetCandidateNode(*this);
220 235
221 StyleSheet* removedSheet = sheet(); 236 StyleSheet* removedSheet = sheet();
222 237
223 if (m_link) 238 if (m_link)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 LinkLoaderClient::trace(visitor); 375 LinkLoaderClient::trace(visitor);
361 DOMTokenListObserver::trace(visitor); 376 DOMTokenListObserver::trace(visitor);
362 } 377 }
363 378
364 DEFINE_TRACE_WRAPPERS(HTMLLinkElement) { 379 DEFINE_TRACE_WRAPPERS(HTMLLinkElement) {
365 visitor->traceWrappers(m_relList); 380 visitor->traceWrappers(m_relList);
366 HTMLElement::traceWrappers(visitor); 381 HTMLElement::traceWrappers(visitor);
367 } 382 }
368 383
369 } // namespace blink 384 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLLinkElement.h ('k') | third_party/WebKit/Source/core/html/LinkResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698