| 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 20 matching lines...) Expand all Loading... |
| 31 // Consumers in the browser process will not receive this message but they | 31 // Consumers in the browser process will not receive this message but they |
| 32 // will be aware of the RenderFrame dying and should act on that. Consumers | 32 // will be aware of the RenderFrame dying and should act on that. Consumers |
| 33 // in the renderer process should be correctly notified. | 33 // in the renderer process should be correctly notified. |
| 34 ResolveCallbacks(ResolveStateFailure); | 34 ResolveCallbacks(ResolveStateFailure); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool ManifestManager::OnMessageReceived(const IPC::Message& message) { | 37 bool ManifestManager::OnMessageReceived(const IPC::Message& message) { |
| 38 bool handled = true; | 38 bool handled = true; |
| 39 | 39 |
| 40 IPC_BEGIN_MESSAGE_MAP(ManifestManager, message) | 40 IPC_BEGIN_MESSAGE_MAP(ManifestManager, message) |
| 41 IPC_MESSAGE_HANDLER(ManifestManagerMsg_HasManifest, OnHasManifest) | |
| 42 IPC_MESSAGE_HANDLER(ManifestManagerMsg_RequestManifest, OnRequestManifest) | 41 IPC_MESSAGE_HANDLER(ManifestManagerMsg_RequestManifest, OnRequestManifest) |
| 43 IPC_MESSAGE_UNHANDLED(handled = false) | 42 IPC_MESSAGE_UNHANDLED(handled = false) |
| 44 IPC_END_MESSAGE_MAP() | 43 IPC_END_MESSAGE_MAP() |
| 45 | 44 |
| 46 return handled; | 45 return handled; |
| 47 } | 46 } |
| 48 | 47 |
| 49 void ManifestManager::OnHasManifest(int request_id) { | |
| 50 GURL url(render_frame()->GetWebFrame()->document().manifestURL()); | |
| 51 | |
| 52 bool has_manifest = may_have_manifest_ && !url.is_empty(); | |
| 53 Send(new ManifestManagerHostMsg_HasManifestResponse( | |
| 54 routing_id(), request_id, has_manifest)); | |
| 55 } | |
| 56 | |
| 57 void ManifestManager::OnRequestManifest(int request_id) { | 48 void ManifestManager::OnRequestManifest(int request_id) { |
| 58 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete, | 49 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete, |
| 59 base::Unretained(this), request_id)); | 50 base::Unretained(this), request_id)); |
| 60 } | 51 } |
| 61 | 52 |
| 62 void ManifestManager::OnRequestManifestComplete(int request_id, | 53 void ManifestManager::OnRequestManifestComplete(int request_id, |
| 63 const GURL& manifest_url, | 54 const GURL& manifest_url, |
| 64 const Manifest& manifest, | 55 const Manifest& manifest, |
| 65 const ManifestDebugInfo&) { | 56 const ManifestDebugInfo&) { |
| 66 // When sent via IPC, the Manifest must follow certain security rules. | 57 // When sent via IPC, the Manifest must follow certain security rules. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Just wait for the running call to be done if there are other callbacks. | 99 // Just wait for the running call to be done if there are other callbacks. |
| 109 if (pending_callbacks_.size() > 1) | 100 if (pending_callbacks_.size() > 1) |
| 110 return; | 101 return; |
| 111 | 102 |
| 112 FetchManifest(); | 103 FetchManifest(); |
| 113 } | 104 } |
| 114 | 105 |
| 115 void ManifestManager::DidChangeManifest() { | 106 void ManifestManager::DidChangeManifest() { |
| 116 may_have_manifest_ = true; | 107 may_have_manifest_ = true; |
| 117 manifest_dirty_ = true; | 108 manifest_dirty_ = true; |
| 109 manifest_url_ = GURL(); |
| 118 } | 110 } |
| 119 | 111 |
| 120 void ManifestManager::DidCommitProvisionalLoad( | 112 void ManifestManager::DidCommitProvisionalLoad( |
| 121 bool is_new_navigation, | 113 bool is_new_navigation, |
| 122 bool is_same_page_navigation) { | 114 bool is_same_page_navigation) { |
| 123 if (is_same_page_navigation) | 115 if (is_same_page_navigation) |
| 124 return; | 116 return; |
| 125 | 117 |
| 126 may_have_manifest_ = false; | 118 may_have_manifest_ = false; |
| 127 manifest_dirty_ = true; | 119 manifest_dirty_ = true; |
| 120 manifest_url_ = GURL(); |
| 128 } | 121 } |
| 129 | 122 |
| 130 void ManifestManager::FetchManifest() { | 123 void ManifestManager::FetchManifest() { |
| 131 GURL url(render_frame()->GetWebFrame()->document().manifestURL()); | 124 manifest_url_ = render_frame()->GetWebFrame()->document().manifestURL(); |
| 132 | 125 |
| 133 if (url.is_empty()) { | 126 if (manifest_url_.is_empty()) { |
| 134 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_EMPTY_URL); | 127 ManifestUmaUtil::FetchFailed(ManifestUmaUtil::FETCH_EMPTY_URL); |
| 135 ResolveCallbacks(ResolveStateFailure); | 128 ResolveCallbacks(ResolveStateFailure); |
| 136 return; | 129 return; |
| 137 } | 130 } |
| 138 | 131 |
| 139 fetcher_.reset(new ManifestFetcher(url)); | 132 fetcher_.reset(new ManifestFetcher(manifest_url_)); |
| 140 fetcher_->Start( | 133 fetcher_->Start( |
| 141 render_frame()->GetWebFrame(), | 134 render_frame()->GetWebFrame(), |
| 142 render_frame()->GetWebFrame()->document().manifestUseCredentials(), | 135 render_frame()->GetWebFrame()->document().manifestUseCredentials(), |
| 143 base::Bind(&ManifestManager::OnManifestFetchComplete, | 136 base::Bind(&ManifestManager::OnManifestFetchComplete, |
| 144 base::Unretained(this), | 137 base::Unretained(this), |
| 145 render_frame()->GetWebFrame()->document().url())); | 138 render_frame()->GetWebFrame()->document().url())); |
| 146 } | 139 } |
| 147 | 140 |
| 148 static const std::string& GetMessagePrefix() { | 141 static const std::string& GetMessagePrefix() { |
| 149 CR_DEFINE_STATIC_LOCAL(std::string, message_prefix, ("Manifest: ")); | 142 CR_DEFINE_STATIC_LOCAL(std::string, message_prefix, ("Manifest: ")); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ResolveCallbacks(ResolveStateFailure); | 180 ResolveCallbacks(ResolveStateFailure); |
| 188 return; | 181 return; |
| 189 } | 182 } |
| 190 | 183 |
| 191 manifest_url_ = response.url(); | 184 manifest_url_ = response.url(); |
| 192 manifest_ = parser.manifest(); | 185 manifest_ = parser.manifest(); |
| 193 ResolveCallbacks(ResolveStateSuccess); | 186 ResolveCallbacks(ResolveStateSuccess); |
| 194 } | 187 } |
| 195 | 188 |
| 196 void ManifestManager::ResolveCallbacks(ResolveState state) { | 189 void ManifestManager::ResolveCallbacks(ResolveState state) { |
| 197 if (state == ResolveStateFailure) { | 190 // Do not reset |manifest_url_| on failure here. If manifest_url_ is |
| 198 manifest_url_ = GURL(); | 191 // non-empty, that means the link 404s, we failed to fetch it, or it was |
| 192 // unparseable. However, the site still tried to specify a manifest, so |
| 193 // preserve that information in the URL for the callbacks. |
| 194 // |manifest_url| will be reset on navigation or if we receive a didchange |
| 195 // event. |
| 196 if (state == ResolveStateFailure) |
| 199 manifest_ = Manifest(); | 197 manifest_ = Manifest(); |
| 200 } | |
| 201 | 198 |
| 202 manifest_dirty_ = state != ResolveStateSuccess; | 199 manifest_dirty_ = state != ResolveStateSuccess; |
| 203 | 200 |
| 204 std::list<GetManifestCallback> callbacks; | 201 std::list<GetManifestCallback> callbacks; |
| 205 callbacks.swap(pending_callbacks_); | 202 callbacks.swap(pending_callbacks_); |
| 206 | 203 |
| 207 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); | 204 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); |
| 208 it != callbacks.end(); ++it) { | 205 it != callbacks.end(); ++it) { |
| 209 it->Run(manifest_url_, manifest_, manifest_debug_info_); | 206 it->Run(manifest_url_, manifest_, manifest_debug_info_); |
| 210 } | 207 } |
| 211 } | 208 } |
| 212 | 209 |
| 213 void ManifestManager::OnDestruct() { | 210 void ManifestManager::OnDestruct() { |
| 214 delete this; | 211 delete this; |
| 215 } | 212 } |
| 216 | 213 |
| 217 } // namespace content | 214 } // namespace content |
| OLD | NEW |