Chromium Code Reviews| 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/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 const GURL& document_url, | 148 const GURL& document_url, |
| 148 const blink::WebURLResponse& response, | 149 const blink::WebURLResponse& response, |
| 149 const std::string& data) { | 150 const std::string& data) { |
| 150 if (response.isNull() && data.empty()) { | 151 if (response.isNull() && data.empty()) { |
| 151 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON); | 152 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_UNSPECIFIED_REASON); |
| 152 ResolveCallbacks(ResolveStateFailure); | 153 ResolveCallbacks(ResolveStateFailure); |
| 153 return; | 154 return; |
| 154 } | 155 } |
| 155 | 156 |
| 156 ManifestUmaUtil::FetchSucceeded(); | 157 ManifestUmaUtil::FetchSucceeded(); |
| 157 | |
| 158 ManifestParser parser(data, response.url(), document_url); | 158 ManifestParser parser(data, response.url(), document_url); |
| 159 parser.Parse(); | 159 parser.Parse(); |
| 160 | 160 |
| 161 fetcher_.reset(); | 161 fetcher_.reset(); |
| 162 manifest_debug_info_.raw_data = data; | |
| 163 parser.TakeErrors(&manifest_debug_info_.errors); | |
| 162 | 164 |
| 163 for (const std::unique_ptr<ManifestParser::ErrorInfo>& error_info : | 165 for (const auto& error : manifest_debug_info_.errors) { |
| 164 parser.errors()) { | |
| 165 blink::WebConsoleMessage message; | 166 blink::WebConsoleMessage message; |
| 166 message.level = blink::WebConsoleMessage::LevelError; | 167 message.level = blink::WebConsoleMessage::LevelError; |
| 167 message.text = blink::WebString::fromUTF8(error_info->error_msg); | 168 message.text = blink::WebString::fromUTF8(error.message); |
| 168 message.url = | 169 message.url = |
| 169 render_frame()->GetWebFrame()->document().manifestURL().string(); | 170 render_frame()->GetWebFrame()->document().manifestURL().string(); |
| 170 message.lineNumber = error_info->error_line; | 171 message.lineNumber = error.line; |
| 171 message.columnNumber = error_info->error_column; | 172 message.columnNumber = error.column; |
| 172 render_frame()->GetWebFrame()->addMessageToConsole(message); | 173 render_frame()->GetWebFrame()->addMessageToConsole(message); |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Having errors while parsing the manifest doesn't mean the manifest parsing | 176 // Having errors while parsing the manifest doesn't mean the manifest parsing |
| 176 // failed. Some properties might have been ignored but some others kept. | 177 // failed. Some properties might have been ignored but some others kept. |
| 177 if (parser.failed()) { | 178 if (parser.failed()) { |
| 178 ResolveCallbacks(ResolveStateFailure); | 179 ResolveCallbacks(ResolveStateFailure); |
| 179 return; | 180 return; |
| 180 } | 181 } |
| 181 | 182 |
| 182 manifest_ = parser.manifest(); | 183 manifest_ = parser.manifest(); |
| 183 ResolveCallbacks(ResolveStateSuccess); | 184 ResolveCallbacks(ResolveStateSuccess); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void ManifestManager::ResolveCallbacks(ResolveState state) { | 187 void ManifestManager::ResolveCallbacks(ResolveState state) { |
| 187 if (state == ResolveStateFailure) | 188 if (state == ResolveStateFailure) |
| 188 manifest_ = Manifest(); | 189 manifest_ = Manifest(); |
| 189 | 190 |
| 190 manifest_dirty_ = state != ResolveStateSuccess; | 191 manifest_dirty_ = state != ResolveStateSuccess; |
| 191 | 192 |
| 192 Manifest manifest = manifest_; | 193 std::list<GetManifestCallback> callbacks; |
|
dgozman
2016/04/29 02:28:26
Maybe |manifest_| could change during callback, an
pfeldman
2016/04/29 02:36:18
Originally, I did not see how it was possible, but
| |
| 193 std::list<GetManifestCallback> callbacks = pending_callbacks_; | 194 callbacks.swap(pending_callbacks_); |
| 194 | |
| 195 pending_callbacks_.clear(); | |
| 196 | 195 |
| 197 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); | 196 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); |
| 198 it != callbacks.end(); ++it) { | 197 it != callbacks.end(); ++it) { |
| 199 it->Run(manifest); | 198 it->Run(manifest_, manifest_debug_info_); |
| 200 } | 199 } |
| 201 } | 200 } |
| 202 | 201 |
| 203 } // namespace content | 202 } // namespace content |
| OLD | NEW |