OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/manifest/manifest_manager.h" | 5 #include "content/renderer/manifest/manifest_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" |
9 #include "content/common/manifest_manager_messages.h" | 9 #include "content/common/manifest_manager_messages.h" |
10 #include "content/public/renderer/document_state.h" | 10 #include "content/public/renderer/document_state.h" |
| 11 #include "content/public/renderer/manifest_parser.h" |
11 #include "content/public/renderer/navigation_state.h" | 12 #include "content/public/renderer/navigation_state.h" |
12 #include "content/public/renderer/render_frame.h" | 13 #include "content/public/renderer/render_frame.h" |
13 #include "content/renderer/fetchers/manifest_fetcher.h" | 14 #include "content/renderer/fetchers/manifest_fetcher.h" |
14 #include "content/renderer/manifest/manifest_parser.h" | |
15 #include "content/renderer/manifest/manifest_uma_util.h" | 15 #include "content/renderer/manifest/manifest_uma_util.h" |
16 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 16 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
18 #include "third_party/WebKit/public/web/WebDocument.h" | 18 #include "third_party/WebKit/public/web/WebDocument.h" |
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 ManifestManager::ManifestManager(RenderFrame* render_frame) | 23 ManifestManager::ManifestManager(RenderFrame* render_frame) |
24 : RenderFrameObserver(render_frame), | 24 : RenderFrameObserver(render_frame), |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 const blink::WebURLResponse& response, | 134 const blink::WebURLResponse& response, |
135 const std::string& data) { | 135 const std::string& data) { |
136 if (response.isNull() && data.empty()) { | 136 if (response.isNull() && data.empty()) { |
137 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON); | 137 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON); |
138 ResolveCallbacks(ResolveStateFailure); | 138 ResolveCallbacks(ResolveStateFailure); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 ManifestUmaUtil::FetchSucceeded(); | 142 ManifestUmaUtil::FetchSucceeded(); |
143 | 143 |
144 ManifestParser parser(data, response.url(), document_url); | 144 scoped_ptr<ManifestParser> parser = ManifestParser::Get(); |
145 parser.Parse(); | 145 parser->Parse(data, response.url(), document_url); |
146 | 146 |
147 fetcher_.reset(); | 147 fetcher_.reset(); |
148 | 148 |
149 for (const std::string& msg : parser.errors()) { | 149 for (const std::string& msg : parser->errors()) { |
150 blink::WebConsoleMessage message; | 150 blink::WebConsoleMessage message; |
151 message.level = blink::WebConsoleMessage::LevelError; | 151 message.level = blink::WebConsoleMessage::LevelError; |
152 message.text = blink::WebString::fromUTF8(msg); | 152 message.text = blink::WebString::fromUTF8(msg); |
153 render_frame()->GetWebFrame()->addMessageToConsole(message); | 153 render_frame()->GetWebFrame()->addMessageToConsole(message); |
154 } | 154 } |
155 | 155 |
156 // Having errors while parsing the manifest doesn't mean the manifest parsing | 156 // Having errors while parsing the manifest doesn't mean the manifest parsing |
157 // failed. Some properties might have been ignored but some others kept. | 157 // failed. Some properties might have been ignored but some others kept. |
158 if (parser.failed()) { | 158 if (parser->failed()) { |
159 ResolveCallbacks(ResolveStateFailure); | 159 ResolveCallbacks(ResolveStateFailure); |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 manifest_ = parser.manifest(); | 163 manifest_ = parser->manifest(); |
164 ResolveCallbacks(ResolveStateSuccess); | 164 ResolveCallbacks(ResolveStateSuccess); |
165 } | 165 } |
166 | 166 |
167 void ManifestManager::ResolveCallbacks(ResolveState state) { | 167 void ManifestManager::ResolveCallbacks(ResolveState state) { |
168 if (state == ResolveStateFailure) | 168 if (state == ResolveStateFailure) |
169 manifest_ = Manifest(); | 169 manifest_ = Manifest(); |
170 | 170 |
171 manifest_dirty_ = state != ResolveStateSuccess; | 171 manifest_dirty_ = state != ResolveStateSuccess; |
172 | 172 |
173 Manifest manifest = manifest_; | 173 Manifest manifest = manifest_; |
174 std::list<GetManifestCallback> callbacks = pending_callbacks_; | 174 std::list<GetManifestCallback> callbacks = pending_callbacks_; |
175 | 175 |
176 pending_callbacks_.clear(); | 176 pending_callbacks_.clear(); |
177 | 177 |
178 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); | 178 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); |
179 it != callbacks.end(); ++it) { | 179 it != callbacks.end(); ++it) { |
180 it->Run(manifest); | 180 it->Run(manifest); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 } // namespace content | 184 } // namespace content |
OLD | NEW |