| 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/mojo_context_state.h" | 5 #include "content/renderer/mojo_context_state.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 DCHECK(url.is_valid() && !url.is_empty()); | 163 DCHECK(url.is_valid() && !url.is_empty()); |
| 164 DCHECK(fetched_modules_.find(id) == fetched_modules_.end()); | 164 DCHECK(fetched_modules_.find(id) == fetched_modules_.end()); |
| 165 fetched_modules_.insert(id); | 165 fetched_modules_.insert(id); |
| 166 ResourceFetcher* fetcher = ResourceFetcher::Create(url); | 166 ResourceFetcher* fetcher = ResourceFetcher::Create(url); |
| 167 module_fetchers_.push_back(fetcher); | 167 module_fetchers_.push_back(fetcher); |
| 168 fetcher->Start(frame_, | 168 fetcher->Start(frame_, |
| 169 blink::WebURLRequest::RequestContextScript, | 169 blink::WebURLRequest::RequestContextScript, |
| 170 blink::WebURLRequest::FrameTypeNone, | 170 blink::WebURLRequest::FrameTypeNone, |
| 171 ResourceFetcher::PLATFORM_LOADER, | 171 ResourceFetcher::PLATFORM_LOADER, |
| 172 base::Bind(&MojoContextState::OnFetchModuleComplete, | 172 base::Bind(&MojoContextState::OnFetchModuleComplete, |
| 173 base::Unretained(this), fetcher)); | 173 base::Unretained(this), fetcher, id)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void MojoContextState::OnFetchModuleComplete( | 176 void MojoContextState::OnFetchModuleComplete( |
| 177 ResourceFetcher* fetcher, | 177 ResourceFetcher* fetcher, |
| 178 const std::string& id, |
| 178 const blink::WebURLResponse& response, | 179 const blink::WebURLResponse& response, |
| 179 const std::string& data) { | 180 const std::string& data) { |
| 180 DCHECK_EQ(module_prefix_, | 181 if (response.isNull()) { |
| 181 response.url().string().utf8().substr(0, module_prefix_.size())); | 182 LOG(ERROR) << "Failed to fetch source for module \"" << id << "\""; |
| 182 const std::string module = | 183 return; |
| 183 response.url().string().utf8().substr(module_prefix_.size()); | 184 } |
| 185 DCHECK_EQ(module_prefix_ + id, response.url().string().utf8()); |
| 184 // We can't delete fetch right now as the arguments to this function come from | 186 // We can't delete fetch right now as the arguments to this function come from |
| 185 // it and are used below. Instead use a scope_ptr to cleanup. | 187 // it and are used below. Instead use a scope_ptr to cleanup. |
| 186 scoped_ptr<ResourceFetcher> deleter(fetcher); | 188 scoped_ptr<ResourceFetcher> deleter(fetcher); |
| 187 module_fetchers_.weak_erase( | 189 module_fetchers_.weak_erase( |
| 188 std::find(module_fetchers_.begin(), module_fetchers_.end(), fetcher)); | 190 std::find(module_fetchers_.begin(), module_fetchers_.end(), fetcher)); |
| 189 if (data.empty()) { | 191 if (data.empty()) { |
| 190 NOTREACHED(); | 192 LOG(ERROR) << "Fetched empty source for module \"" << id << "\""; |
| 191 return; // TODO(sky): log something? | 193 return; |
| 192 } | 194 } |
| 193 | 195 |
| 194 runner_->Run(data, module); | 196 runner_->Run(data, id); |
| 195 } | 197 } |
| 196 | 198 |
| 197 void MojoContextState::OnDidAddPendingModule( | 199 void MojoContextState::OnDidAddPendingModule( |
| 198 const std::string& id, | 200 const std::string& id, |
| 199 const std::vector<std::string>& dependencies) { | 201 const std::vector<std::string>& dependencies) { |
| 200 FetchModules(dependencies); | 202 FetchModules(dependencies); |
| 201 | 203 |
| 202 gin::ContextHolder* context_holder = runner_->GetContextHolder(); | 204 gin::ContextHolder* context_holder = runner_->GetContextHolder(); |
| 203 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( | 205 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( |
| 204 context_holder->context()); | 206 context_holder->context()); |
| 205 registry->AttemptToLoadMoreModules(context_holder->isolate()); | 207 registry->AttemptToLoadMoreModules(context_holder->isolate()); |
| 206 } | 208 } |
| 207 | 209 |
| 208 } // namespace content | 210 } // namespace content |
| OLD | NEW |