#include "ios/web/webui/url_data_source_ios_impl.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_util.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
#include "ios/web/public/webui/url_data_source_ios.h"
#include "ios/web/webui/url_data_manager_ios_backend.h"
namespace web {
URLDataSourceIOSImpl::URLDataSourceIOSImpl(std::string_view source_name,
URLDataSourceIOS* source)
: source_name_(source_name), backend_(nullptr), source_(source) {}
URLDataSourceIOSImpl::~URLDataSourceIOSImpl() {}
void URLDataSourceIOSImpl::SendResponse(
int request_id,
scoped_refptr<base::RefCountedMemory> bytes) {
if (URLDataManagerIOS::IsScheduledForDeletion(this)) {
return;
}
web::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&URLDataSourceIOSImpl::SendResponseOnIOThread,
this, request_id, std::move(bytes)));
}
void URLDataSourceIOSImpl::SendResponseOnIOThread(
int request_id,
scoped_refptr<base::RefCountedMemory> bytes) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
if (backend_) {
backend_->DataAvailable(request_id, bytes.get());
}
}
const ui::TemplateReplacements* URLDataSourceIOSImpl::GetReplacements() const {
return nullptr;
}
bool URLDataSourceIOSImpl::ShouldReplaceI18nInJS() const {
return false;
}
}