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

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

Issue 1932623003: DevTools: Introduce Page.getManifest remote debugging protocol method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: browser test updated Created 4 years, 7 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
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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 Send(new ManifestManagerHostMsg_HasManifestResponse( 53 Send(new ManifestManagerHostMsg_HasManifestResponse(
54 routing_id(), request_id, has_manifest)); 54 routing_id(), request_id, has_manifest));
55 } 55 }
56 56
57 void ManifestManager::OnRequestManifest(int request_id) { 57 void ManifestManager::OnRequestManifest(int request_id) {
58 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete, 58 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete,
59 base::Unretained(this), request_id)); 59 base::Unretained(this), request_id));
60 } 60 }
61 61
62 void ManifestManager::OnRequestManifestComplete( 62 void ManifestManager::OnRequestManifestComplete(
63 int request_id, const Manifest& manifest) { 63 int request_id, const Manifest& manifest,
64 const ManifestDebugInfo&) {
64 // When sent via IPC, the Manifest must follow certain security rules. 65 // When sent via IPC, the Manifest must follow certain security rules.
65 Manifest ipc_manifest = manifest; 66 Manifest ipc_manifest = manifest;
66 ipc_manifest.name = base::NullableString16( 67 ipc_manifest.name = base::NullableString16(
67 ipc_manifest.name.string().substr(0, Manifest::kMaxIPCStringLength), 68 ipc_manifest.name.string().substr(0, Manifest::kMaxIPCStringLength),
68 ipc_manifest.name.is_null()); 69 ipc_manifest.name.is_null());
69 ipc_manifest.short_name = base::NullableString16( 70 ipc_manifest.short_name = base::NullableString16(
70 ipc_manifest.short_name.string().substr(0, 71 ipc_manifest.short_name.string().substr(0,
71 Manifest::kMaxIPCStringLength), 72 Manifest::kMaxIPCStringLength),
72 ipc_manifest.short_name.is_null()); 73 ipc_manifest.short_name.is_null());
73 for (auto& icon : ipc_manifest.icons) { 74 for (auto& icon : ipc_manifest.icons) {
(...skipping 11 matching lines...) Expand all
85 0, Manifest::kMaxIPCStringLength), 86 0, Manifest::kMaxIPCStringLength),
86 related_application.id.is_null()); 87 related_application.id.is_null());
87 } 88 }
88 89
89 Send(new ManifestManagerHostMsg_RequestManifestResponse( 90 Send(new ManifestManagerHostMsg_RequestManifestResponse(
90 routing_id(), request_id, ipc_manifest)); 91 routing_id(), request_id, ipc_manifest));
91 } 92 }
92 93
93 void ManifestManager::GetManifest(const GetManifestCallback& callback) { 94 void ManifestManager::GetManifest(const GetManifestCallback& callback) {
94 if (!may_have_manifest_) { 95 if (!may_have_manifest_) {
95 callback.Run(Manifest()); 96 callback.Run(Manifest(), ManifestDebugInfo());
96 return; 97 return;
97 } 98 }
98 99
99 if (!manifest_dirty_) { 100 if (!manifest_dirty_) {
100 callback.Run(manifest_); 101 callback.Run(manifest_, manifest_debug_info_);
101 return; 102 return;
102 } 103 }
103 104
104 pending_callbacks_.push_back(callback); 105 pending_callbacks_.push_back(callback);
105 106
106 // Just wait for the running call to be done if there are other callbacks. 107 // Just wait for the running call to be done if there are other callbacks.
107 if (pending_callbacks_.size() > 1) 108 if (pending_callbacks_.size() > 1)
108 return; 109 return;
109 110
110 FetchManifest(); 111 FetchManifest();
(...skipping 25 matching lines...) Expand all
136 137
137 fetcher_.reset(new ManifestFetcher(url)); 138 fetcher_.reset(new ManifestFetcher(url));
138 fetcher_->Start( 139 fetcher_->Start(
139 render_frame()->GetWebFrame(), 140 render_frame()->GetWebFrame(),
140 render_frame()->GetWebFrame()->document().manifestUseCredentials(), 141 render_frame()->GetWebFrame()->document().manifestUseCredentials(),
141 base::Bind(&ManifestManager::OnManifestFetchComplete, 142 base::Bind(&ManifestManager::OnManifestFetchComplete,
142 base::Unretained(this), 143 base::Unretained(this),
143 render_frame()->GetWebFrame()->document().url())); 144 render_frame()->GetWebFrame()->document().url()));
144 } 145 }
145 146
147 static const std::string& GetMessagePrefix() {
148 CR_DEFINE_STATIC_LOCAL(std::string, message_prefix, ("Manifest: "));
149 return message_prefix;
150 }
151
146 void ManifestManager::OnManifestFetchComplete( 152 void ManifestManager::OnManifestFetchComplete(
147 const GURL& document_url, 153 const GURL& document_url,
148 const blink::WebURLResponse& response, 154 const blink::WebURLResponse& response,
149 const std::string& data) { 155 const std::string& data) {
150 if (response.isNull() && data.empty()) { 156 if (response.isNull() && data.empty()) {
151 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON); 157 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON);
152 ResolveCallbacks(ResolveStateFailure); 158 ResolveCallbacks(ResolveStateFailure);
153 return; 159 return;
154 } 160 }
155 161
156 ManifestUmaUtil::FetchSucceeded(); 162 ManifestUmaUtil::FetchSucceeded();
157
158 ManifestParser parser(data, response.url(), document_url); 163 ManifestParser parser(data, response.url(), document_url);
159 parser.Parse(); 164 parser.Parse();
160 165
161 fetcher_.reset(); 166 fetcher_.reset();
167 manifest_debug_info_.raw_data = data;
168 parser.TakeErrors(&manifest_debug_info_.errors);
162 169
163 for (const std::unique_ptr<ManifestParser::ErrorInfo>& error_info : 170 for (const auto& error : manifest_debug_info_.errors) {
164 parser.errors()) {
165 blink::WebConsoleMessage message; 171 blink::WebConsoleMessage message;
166 message.level = blink::WebConsoleMessage::LevelError; 172 message.level = error.critical ? blink::WebConsoleMessage::LevelError :
167 message.text = blink::WebString::fromUTF8(error_info->error_msg); 173 blink::WebConsoleMessage::LevelWarning;
174 message.text =
175 blink::WebString::fromUTF8(GetMessagePrefix() + error.message);
168 message.url = 176 message.url =
169 render_frame()->GetWebFrame()->document().manifestURL().string(); 177 render_frame()->GetWebFrame()->document().manifestURL().string();
170 message.lineNumber = error_info->error_line; 178 message.lineNumber = error.line;
171 message.columnNumber = error_info->error_column; 179 message.columnNumber = error.column;
172 render_frame()->GetWebFrame()->addMessageToConsole(message); 180 render_frame()->GetWebFrame()->addMessageToConsole(message);
173 } 181 }
174 182
175 // Having errors while parsing the manifest doesn't mean the manifest parsing 183 // Having errors while parsing the manifest doesn't mean the manifest parsing
176 // failed. Some properties might have been ignored but some others kept. 184 // failed. Some properties might have been ignored but some others kept.
177 if (parser.failed()) { 185 if (parser.failed()) {
178 ResolveCallbacks(ResolveStateFailure); 186 ResolveCallbacks(ResolveStateFailure);
179 return; 187 return;
180 } 188 }
181 189
182 manifest_ = parser.manifest(); 190 manifest_ = parser.manifest();
183 ResolveCallbacks(ResolveStateSuccess); 191 ResolveCallbacks(ResolveStateSuccess);
184 } 192 }
185 193
186 void ManifestManager::ResolveCallbacks(ResolveState state) { 194 void ManifestManager::ResolveCallbacks(ResolveState state) {
187 if (state == ResolveStateFailure) 195 if (state == ResolveStateFailure)
188 manifest_ = Manifest(); 196 manifest_ = Manifest();
189 197
190 manifest_dirty_ = state != ResolveStateSuccess; 198 manifest_dirty_ = state != ResolveStateSuccess;
191 199
192 Manifest manifest = manifest_; 200 std::list<GetManifestCallback> callbacks;
193 std::list<GetManifestCallback> callbacks = pending_callbacks_; 201 callbacks.swap(pending_callbacks_);
194
195 pending_callbacks_.clear();
196 202
197 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); 203 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin();
198 it != callbacks.end(); ++it) { 204 it != callbacks.end(); ++it) {
199 it->Run(manifest); 205 it->Run(manifest_, manifest_debug_info_);
200 } 206 }
201 } 207 }
202 208
203 } // namespace content 209 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_manager.h ('k') | content/renderer/manifest/manifest_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698