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

Side by Side Diff: content/renderer/manifest/manifest_manager.cc

Issue 748373003: Report errors when parsing Manifest and expose them in developer console. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 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 // 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/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
11 #include "content/renderer/fetchers/manifest_fetcher.h" 11 #include "content/renderer/fetchers/manifest_fetcher.h"
12 #include "content/renderer/manifest/manifest_parser.h" 12 #include "content/renderer/manifest/manifest_parser.h"
13 #include "content/renderer/manifest/manifest_uma_util.h" 13 #include "content/renderer/manifest/manifest_uma_util.h"
14 #include "third_party/WebKit/public/platform/WebURLResponse.h" 14 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
15 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 ManifestManager::ManifestManager(RenderFrame* render_frame) 21 ManifestManager::ManifestManager(RenderFrame* render_frame)
21 : RenderFrameObserver(render_frame), 22 : RenderFrameObserver(render_frame),
22 may_have_manifest_(false), 23 may_have_manifest_(false),
23 manifest_dirty_(true) { 24 manifest_dirty_(true) {
24 } 25 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void ManifestManager::FetchManifest() { 104 void ManifestManager::FetchManifest() {
104 GURL url(render_frame()->GetWebFrame()->document().manifestURL()); 105 GURL url(render_frame()->GetWebFrame()->document().manifestURL());
105 106
106 if (url.is_empty()) { 107 if (url.is_empty()) {
107 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_EMPTY_URL); 108 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_EMPTY_URL);
108 ResolveCallbacks(ResolveStateFailure); 109 ResolveCallbacks(ResolveStateFailure);
109 return; 110 return;
110 } 111 }
111 112
112 fetcher_.reset(new ManifestFetcher(url)); 113 fetcher_.reset(new ManifestFetcher(url));
113
114 // TODO(mlamouri,kenneth): this is not yet taking into account manifest-src
115 // CSP rule, see http://crbug.com/409996.
116 fetcher_->Start(render_frame()->GetWebFrame(), 114 fetcher_->Start(render_frame()->GetWebFrame(),
117 base::Bind(&ManifestManager::OnManifestFetchComplete, 115 base::Bind(&ManifestManager::OnManifestFetchComplete,
118 base::Unretained(this), 116 base::Unretained(this),
119 render_frame()->GetWebFrame()->document().url())); 117 render_frame()->GetWebFrame()->document().url()));
120 } 118 }
121 119
122 void ManifestManager::OnManifestFetchComplete( 120 void ManifestManager::OnManifestFetchComplete(
123 const GURL& document_url, 121 const GURL& document_url,
124 const blink::WebURLResponse& response, 122 const blink::WebURLResponse& response,
125 const std::string& data) { 123 const std::string& data) {
126 if (response.isNull() && data.empty()) { 124 if (response.isNull() && data.empty()) {
127 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON); 125 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON);
128 ResolveCallbacks(ResolveStateFailure); 126 ResolveCallbacks(ResolveStateFailure);
129 return; 127 return;
130 } 128 }
131 129
132 ManifestUmaUtil::FetchSucceeded(); 130 ManifestUmaUtil::FetchSucceeded();
133 manifest_ = ManifestParser::Parse(data, response.url(), document_url); 131
132 ManifestParser parser(data, response.url(), document_url);
133 parser.Parse();
134 134
135 fetcher_.reset(); 135 fetcher_.reset();
136
137 for (const std::string& msg : parser.errors()) {
138 blink::WebConsoleMessage message;
139 message.level = blink::WebConsoleMessage::LevelError;
140 message.text = blink::WebString::fromUTF8(msg);
141 render_frame()->GetWebFrame()->addMessageToConsole(message);
142 }
143
144 // Having errors while parsing the manifest doesn't mean the manifest parsing
145 // failed. Some properties might have been ignored but some others kept.
146 if (parser.failed()) {
147 ResolveCallbacks(ResolveStateFailure);
148 return;
149 }
150
151 manifest_ = parser.manifest();
136 ResolveCallbacks(ResolveStateSuccess); 152 ResolveCallbacks(ResolveStateSuccess);
137 } 153 }
138 154
139 void ManifestManager::ResolveCallbacks(ResolveState state) { 155 void ManifestManager::ResolveCallbacks(ResolveState state) {
140 if (state == ResolveStateFailure) 156 if (state == ResolveStateFailure)
141 manifest_ = Manifest(); 157 manifest_ = Manifest();
142 158
143 manifest_dirty_ = state != ResolveStateSuccess; 159 manifest_dirty_ = state != ResolveStateSuccess;
144 160
145 Manifest manifest = manifest_; 161 Manifest manifest = manifest_;
146 std::list<GetManifestCallback> callbacks = pending_callbacks_; 162 std::list<GetManifestCallback> callbacks = pending_callbacks_;
147 163
148 pending_callbacks_.clear(); 164 pending_callbacks_.clear();
149 165
150 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); 166 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin();
151 it != callbacks.end(); ++it) { 167 it != callbacks.end(); ++it) {
152 it->Run(manifest); 168 it->Run(manifest);
153 } 169 }
154 } 170 }
155 171
156 } // namespace content 172 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/manifest/manifest_browsertest.cc ('k') | content/renderer/manifest/manifest_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698