summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.cc15
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.h4
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.h18
3 files changed, 34 insertions, 3 deletions
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc
index 4eb7b9f..1102b87 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc
@@ -52,6 +52,10 @@ class URLRequestChromeJob : public URLRequestJob {
// for us.
void DataAvailable(RefCountedBytes* bytes);
+ void SetMimeType(const std::string& mime_type) {
+ mime_type_ = mime_type;
+ }
+
private:
// Helper for Start(), to let us start asynchronously.
// (This pattern is shared by most URLRequestJob implementations.)
@@ -71,6 +75,7 @@ class URLRequestChromeJob : public URLRequestJob {
// we're reading into.
char* pending_buf_;
int pending_buf_size_;
+ std::string mime_type_;
DISALLOW_EVIL_CONSTRUCTORS(URLRequestChromeJob);
};
@@ -187,6 +192,11 @@ bool ChromeURLDataManager::StartRequest(const GURL& url,
RequestID request_id = next_request_id_++;
pending_requests_.insert(std::make_pair(request_id, job));
+ // TODO(eroman): would be nicer if the mimetype were set at the same time
+ // as the data blob. For now do it here, since NotifyHeadersComplete() is
+ // going to get called once we return.
+ job->SetMimeType(source->GetMimeType(path));
+
// Forward along the request to the data source.
source->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(source, &DataSource::StartDataRequest,
@@ -258,9 +268,8 @@ void URLRequestChromeJob::Kill() {
}
bool URLRequestChromeJob::GetMimeType(std::string* mime_type) {
- // Rely on MIME sniffing to simplify the logic here.
- *mime_type = "text/html";
- return true;
+ *mime_type = mime_type_;
+ return !mime_type_.empty();
}
void URLRequestChromeJob::DataAvailable(RefCountedBytes* bytes) {
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.h b/chrome/browser/dom_ui/chrome_url_data_manager.h
index a7f07f2..895ff46 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.h
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.h
@@ -48,6 +48,10 @@ class ChromeURLDataManager {
// not be satisfied.
virtual void StartDataRequest(const std::string& path, int request_id) = 0;
+ // Return the mimetype that should be sent with this response, or empty
+ // string to specify no mime type.
+ virtual std::string GetMimeType(const std::string& path) const = 0;
+
// Report that a request has resulted in the data |bytes|.
// If the request can't be satisfied, pass NULL for |bytes| to indicate
// the request is over.
diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h
index aab91f2..ed31cde 100644
--- a/chrome/browser/dom_ui/new_tab_ui.h
+++ b/chrome/browser/dom_ui/new_tab_ui.h
@@ -36,6 +36,10 @@ class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
// the path we registered.
virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
// Setters and getters for first_view.
static void set_first_view(bool first_view) { first_view_ = first_view; }
static bool first_view() { return first_view_; }
@@ -57,6 +61,10 @@ class IncognitoTabHTMLSource : public ChromeURLDataManager::DataSource {
// the path we registered.
virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
private:
DISALLOW_EVIL_CONSTRUCTORS(IncognitoTabHTMLSource);
};
@@ -71,6 +79,11 @@ class ThumbnailSource : public ChromeURLDataManager::DataSource {
// the path we registered.
virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ // Rely on image decoder inferring the correct type.
+ return std::string();
+ }
+
// Called when thumbnail data is available from the history backend.
void OnThumbnailDataAvailable(
HistoryService::Handle request_handle,
@@ -97,6 +110,11 @@ class FavIconSource : public ChromeURLDataManager::DataSource {
// the path we registered.
virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ // Rely on image decoder inferring the correct type.
+ return std::string();
+ }
+
// Called when favicon data is available from the history backend.
void OnFavIconDataAvailable(
HistoryService::Handle request_handle,