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

Side by Side Diff: Source/core/html/LinkImport.cpp

Issue 22573005: [HTML Imports] Implement "load" and "error" events. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: For landing Created 7 years, 4 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/html/LinkImport.h ('k') | Source/core/html/LinkResource.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/html/LinkImport.h" 32 #include "core/html/LinkImport.h"
33 33
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/html/HTMLImportLoader.h" 35 #include "core/html/HTMLImportLoader.h"
36 #include "core/html/HTMLImportsController.h" 36 #include "core/html/HTMLImportsController.h"
37 #include "core/html/HTMLLinkElement.h" 37 #include "core/html/HTMLLinkElement.h"
38 #include "core/loader/CrossOriginAccessControl.h" 38 #include "core/loader/CrossOriginAccessControl.h"
39 #include "core/loader/cache/ResourceFetcher.h"
40 39
41 namespace WebCore { 40 namespace WebCore {
42 41
43 PassRefPtr<LinkImport> LinkImport::create(HTMLLinkElement* owner) 42 PassRefPtr<LinkImport> LinkImport::create(HTMLLinkElement* owner)
44 { 43 {
45 return adoptRef(new LinkImport(owner)); 44 return adoptRef(new LinkImport(owner));
46 } 45 }
47 46
48 LinkImport::LinkImport(HTMLLinkElement* owner) 47 LinkImport::LinkImport(HTMLLinkElement* owner)
49 : LinkResource(owner) 48 : LinkResource(owner)
50 { 49 {
51 } 50 }
52 51
53 LinkImport::~LinkImport() 52 LinkImport::~LinkImport()
54 { 53 {
54 clear();
55 } 55 }
56 56
57 Document* LinkImport::importedDocument() const 57 Document* LinkImport::importedDocument() const
58 { 58 {
59 if (!m_loader) 59 if (!m_loader)
60 return 0; 60 return 0;
61 return m_loader->importedDocument(); 61 return m_loader->importedDocument();
62 } 62 }
63 63
64 void LinkImport::process() 64 void LinkImport::process()
65 { 65 {
66 if (m_loader) 66 if (m_loader)
67 return; 67 return;
68 if (!m_owner) 68 if (!m_owner)
69 return; 69 return;
70
71 if (!m_owner->document()->frame() && !m_owner->document()->import()) 70 if (!m_owner->document()->frame() && !m_owner->document()->import())
72 return; 71 return;
73 72
74 LinkRequestBuilder builder(m_owner);
75 if (!builder.isValid())
76 return;
77
78 if (!m_owner->document()->import()) { 73 if (!m_owner->document()->import()) {
79 ASSERT(m_owner->document()->frame()); // The document should be the mast er. 74 ASSERT(m_owner->document()->frame()); // The document should be the mast er.
80 HTMLImportsController::provideTo(m_owner->document()); 75 HTMLImportsController::provideTo(m_owner->document());
81 } 76 }
82 77
83 HTMLImport* parent = m_owner->document()->import(); 78 LinkRequestBuilder builder(m_owner);
84 HTMLImportsController* controller = parent->controller(); 79 if (!builder.isValid()) {
85 if (RefPtr<HTMLImportLoader> found = controller->findLinkFor(builder.url())) { 80 didFinish();
86 m_loader = found;
87 return; 81 return;
88 } 82 }
89 83
90 FetchRequest request = builder.build(true); 84 HTMLImport* parent = m_owner->document()->import();
91 request.setPotentiallyCrossOriginEnabled(controller->securityOrigin(), DoNot AllowStoredCredentials); 85 HTMLImportsController* controller = parent->controller();
92 ResourcePtr<CachedRawResource> resource = m_owner->document()->fetcher()->re questImport(request); 86 m_loader = controller->createLoader(parent, builder.build(true));
93 if (!resource) 87 if (!m_loader) {
88 didFinish();
94 return; 89 return;
90 }
95 91
96 m_loader = controller->createLoader(parent, builder.url(), resource); 92 m_loader->addClient(this);
93 }
94
95 void LinkImport::clear()
96 {
97 m_owner = 0;
98
99 if (m_loader) {
100 m_loader->removeClient(this);
101 m_loader.clear();
102 }
97 } 103 }
98 104
99 void LinkImport::ownerRemoved() 105 void LinkImport::ownerRemoved()
100 { 106 {
101 m_owner = 0; 107 clear();
102 m_loader.clear(); 108 }
109
110 void LinkImport::didFinish()
111 {
112 if (!m_owner)
113 return;
114 m_owner->scheduleEvent();
115 }
116
117 bool LinkImport::hasLoaded() const
118 {
119 return m_loader && m_loader->isLoaded();
103 } 120 }
104 121
105 } // namespace WebCore 122 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/LinkImport.h ('k') | Source/core/html/LinkResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698