OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/about_ui.h" | 5 #include "chrome/browser/ui/webui/about_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/about_flags.h" | 30 #include "chrome/browser/about_flags.h" |
31 #include "chrome/browser/browser_about_handler.h" | 31 #include "chrome/browser/browser_about_handler.h" |
32 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
33 #include "chrome/browser/defaults.h" | 33 #include "chrome/browser/defaults.h" |
34 #include "chrome/browser/memory_details.h" | 34 #include "chrome/browser/memory_details.h" |
35 #include "chrome/browser/net/predictor.h" | 35 #include "chrome/browser/net/predictor.h" |
36 #include "chrome/browser/net/url_fixer_upper.h" | 36 #include "chrome/browser/net/url_fixer_upper.h" |
37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
38 #include "chrome/browser/profiles/profile_manager.h" | 38 #include "chrome/browser/profiles/profile_manager.h" |
39 #include "chrome/browser/ui/browser_dialogs.h" | 39 #include "chrome/browser/ui/browser_dialogs.h" |
40 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 40 #include "chrome/browser/ui/webui/web_ui_util.h" |
41 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
42 #include "chrome/common/jstemplate_builder.h" | 42 #include "chrome/common/jstemplate_builder.h" |
43 #include "chrome/common/render_messages.h" | 43 #include "chrome/common/render_messages.h" |
44 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
45 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
46 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_host.h" |
47 #include "content/public/browser/render_view_host.h" | 47 #include "content/public/browser/render_view_host.h" |
48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
49 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
50 #include "content/public/common/process_type.h" | 50 #include "content/public/common/process_type.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 std::string GetAboutMemoryRedirectResponse(Profile* profile) { | 108 std::string GetAboutMemoryRedirectResponse(Profile* profile) { |
109 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", | 109 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", |
110 chrome::kChromeUIMemoryRedirectURL); | 110 chrome::kChromeUIMemoryRedirectURL); |
111 } | 111 } |
112 | 112 |
113 // Handling about:memory is complicated enough to encapsulate its related | 113 // Handling about:memory is complicated enough to encapsulate its related |
114 // methods into a single class. The user should create it (on the heap) and call | 114 // methods into a single class. The user should create it (on the heap) and call |
115 // its |StartFetch()| method. | 115 // its |StartFetch()| method. |
116 class AboutMemoryHandler : public MemoryDetails { | 116 class AboutMemoryHandler : public MemoryDetails { |
117 public: | 117 public: |
118 AboutMemoryHandler(const base::WeakPtr<AboutUIHTMLSource>& source, | 118 explicit AboutMemoryHandler( |
119 int request_id) | 119 const content::URLDataSource::GotDataCallback& callback) |
120 : source_(source), | 120 : callback_(callback) { |
121 request_id_(request_id) { | |
122 } | 121 } |
123 | 122 |
124 virtual void OnDetailsAvailable() OVERRIDE; | 123 virtual void OnDetailsAvailable() OVERRIDE; |
125 | 124 |
126 private: | 125 private: |
127 ~AboutMemoryHandler() {} | 126 ~AboutMemoryHandler() {} |
128 | 127 |
129 void BindProcessMetrics(DictionaryValue* data, | 128 void BindProcessMetrics(DictionaryValue* data, |
130 ProcessMemoryInformation* info); | 129 ProcessMemoryInformation* info); |
131 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); | 130 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); |
132 | 131 |
133 base::WeakPtr<AboutUIHTMLSource> source_; | 132 content::URLDataSource::GotDataCallback callback_; |
134 int request_id_; | |
135 | 133 |
136 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); | 134 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); |
137 }; | 135 }; |
138 | 136 |
139 #if defined(OS_CHROMEOS) | 137 #if defined(OS_CHROMEOS) |
140 class ChromeOSTermsHandler | 138 class ChromeOSTermsHandler |
141 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { | 139 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { |
142 public: | 140 public: |
143 static void Start(const base::WeakPtr<AboutUIHTMLSource>& source, | 141 static void Start(const std::string& path, |
144 const std::string& path, | 142 const content::URLDataSource::GotDataCallback& callback) { |
145 int request_id) { | |
146 scoped_refptr<ChromeOSTermsHandler> handler( | 143 scoped_refptr<ChromeOSTermsHandler> handler( |
147 new ChromeOSTermsHandler(source, path, request_id)); | 144 new ChromeOSTermsHandler(path, callback)); |
148 handler->StartOnUIThread(); | 145 handler->StartOnUIThread(); |
149 } | 146 } |
150 | 147 |
151 private: | 148 private: |
152 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; | 149 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; |
153 | 150 |
154 ChromeOSTermsHandler(const base::WeakPtr<AboutUIHTMLSource>& source, | 151 ChromeOSTermsHandler(const std::string& path, |
155 const std::string& path, | 152 const content::URLDataSource::GotDataCallback& callback) |
156 int request_id) | 153 : path_(path), |
157 : source_(source), | 154 callback_(callback), |
158 path_(path), | |
159 request_id_(request_id), | |
160 // Previously we were using "initial locale" http://crbug.com/145142 | 155 // Previously we were using "initial locale" http://crbug.com/145142 |
161 locale_(g_browser_process->GetApplicationLocale()) { | 156 locale_(g_browser_process->GetApplicationLocale()) { |
162 } | 157 } |
163 | 158 |
164 ~ChromeOSTermsHandler() {} | 159 ~ChromeOSTermsHandler() {} |
165 | 160 |
166 void StartOnUIThread() { | 161 void StartOnUIThread() { |
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
168 BrowserThread::PostTask( | 163 BrowserThread::PostTask( |
169 BrowserThread::FILE, FROM_HERE, | 164 BrowserThread::FILE, FROM_HERE, |
(...skipping 27 matching lines...) Expand all Loading... |
197 } | 192 } |
198 } | 193 } |
199 } | 194 } |
200 BrowserThread::PostTask( | 195 BrowserThread::PostTask( |
201 BrowserThread::UI, FROM_HERE, | 196 BrowserThread::UI, FROM_HERE, |
202 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); | 197 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); |
203 } | 198 } |
204 | 199 |
205 void ResponseOnUIThread() { | 200 void ResponseOnUIThread() { |
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
207 if (!source_) | |
208 return; | |
209 | |
210 // If we fail to load Chrome OS EULA from disk, load it from resources. | 202 // If we fail to load Chrome OS EULA from disk, load it from resources. |
211 // Do nothing if OEM EULA load failed. | 203 // Do nothing if OEM EULA load failed. |
212 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) | 204 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) |
213 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); | 205 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); |
214 source_->FinishDataRequest(contents_, request_id_); | 206 callback_.Run(base::RefCountedString::TakeString(&contents_)); |
215 } | 207 } |
216 | 208 |
217 // Where the results are fed to. | |
218 base::WeakPtr<AboutUIHTMLSource> source_; | |
219 | |
220 // Path in the URL. | 209 // Path in the URL. |
221 std::string path_; | 210 std::string path_; |
222 | 211 |
223 // ID identifying the request. | 212 // Callback to run with the response. |
224 int request_id_; | 213 content::URLDataSource::GotDataCallback callback_; |
225 | 214 |
226 // Locale of the EULA. | 215 // Locale of the EULA. |
227 std::string locale_; | 216 std::string locale_; |
228 | 217 |
229 // EULA contents that was loaded from file. | 218 // EULA contents that was loaded from file. |
230 std::string contents_; | 219 std::string contents_; |
231 | 220 |
232 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); | 221 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); |
233 }; | 222 }; |
234 | 223 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 AppendFooter(&output); | 485 AppendFooter(&output); |
497 return output; | 486 return output; |
498 } | 487 } |
499 | 488 |
500 #endif // USE_ASH | 489 #endif // USE_ASH |
501 | 490 |
502 // AboutDnsHandler bounces the request back to the IO thread to collect | 491 // AboutDnsHandler bounces the request back to the IO thread to collect |
503 // the DNS information. | 492 // the DNS information. |
504 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { | 493 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { |
505 public: | 494 public: |
506 static void Start(const base::WeakPtr<AboutUIHTMLSource>& source, | 495 static void Start(Profile* profile, |
507 int request_id) { | 496 const content::URLDataSource::GotDataCallback& callback) { |
508 scoped_refptr<AboutDnsHandler> handler( | 497 scoped_refptr<AboutDnsHandler> handler( |
509 new AboutDnsHandler(source, request_id)); | 498 new AboutDnsHandler(profile, callback)); |
510 handler->StartOnUIThread(); | 499 handler->StartOnUIThread(); |
511 } | 500 } |
512 | 501 |
513 private: | 502 private: |
514 friend class base::RefCountedThreadSafe<AboutDnsHandler>; | 503 friend class base::RefCountedThreadSafe<AboutDnsHandler>; |
515 | 504 |
516 AboutDnsHandler(const base::WeakPtr<AboutUIHTMLSource>& source, | 505 AboutDnsHandler(Profile* profile, |
517 int request_id) | 506 const content::URLDataSource::GotDataCallback& callback) |
518 : source_(source), | 507 : profile_(profile), |
519 request_id_(request_id) { | 508 callback_(callback) { |
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
521 } | 510 } |
522 | 511 |
523 virtual ~AboutDnsHandler() {} | 512 virtual ~AboutDnsHandler() {} |
524 | 513 |
525 // Calls FinishOnUIThread() on completion. | 514 // Calls FinishOnUIThread() on completion. |
526 void StartOnUIThread() { | 515 void StartOnUIThread() { |
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
528 chrome_browser_net::Predictor* predictor = | 517 chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor(); |
529 source_->profile()->GetNetworkPredictor(); | |
530 BrowserThread::PostTask( | 518 BrowserThread::PostTask( |
531 BrowserThread::IO, FROM_HERE, | 519 BrowserThread::IO, FROM_HERE, |
532 base::Bind(&AboutDnsHandler::StartOnIOThread, this, predictor)); | 520 base::Bind(&AboutDnsHandler::StartOnIOThread, this, predictor)); |
533 } | 521 } |
534 | 522 |
535 void StartOnIOThread(chrome_browser_net::Predictor* predictor) { | 523 void StartOnIOThread(chrome_browser_net::Predictor* predictor) { |
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
537 | 525 |
538 std::string data; | 526 std::string data; |
539 AppendHeader(&data, 0, "About DNS"); | 527 AppendHeader(&data, 0, "About DNS"); |
540 AppendBody(&data); | 528 AppendBody(&data); |
541 chrome_browser_net::Predictor::PredictorGetHtmlInfo(predictor, &data); | 529 chrome_browser_net::Predictor::PredictorGetHtmlInfo(predictor, &data); |
542 AppendFooter(&data); | 530 AppendFooter(&data); |
543 | 531 |
544 BrowserThread::PostTask( | 532 BrowserThread::PostTask( |
545 BrowserThread::UI, FROM_HERE, | 533 BrowserThread::UI, FROM_HERE, |
546 base::Bind(&AboutDnsHandler::FinishOnUIThread, this, data)); | 534 base::Bind(&AboutDnsHandler::FinishOnUIThread, this, data)); |
547 } | 535 } |
548 | 536 |
549 void FinishOnUIThread(const std::string& data) { | 537 void FinishOnUIThread(const std::string& data) { |
550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
551 if (source_) | 539 std::string data_copy(data); |
552 source_->FinishDataRequest(data, request_id_); | 540 callback_.Run(base::RefCountedString::TakeString(&data_copy)); |
553 } | 541 } |
554 | 542 |
555 // Where the results are fed to. | 543 Profile* profile_; |
556 base::WeakPtr<AboutUIHTMLSource> source_; | |
557 | 544 |
558 // ID identifying the request. | 545 // Callback to run with the response. |
559 int request_id_; | 546 content::URLDataSource::GotDataCallback callback_; |
560 | 547 |
561 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); | 548 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); |
562 }; | 549 }; |
563 | 550 |
564 void FinishMemoryDataRequest(const std::string& path, | 551 void FinishMemoryDataRequest( |
565 AboutUIHTMLSource* source, | 552 const std::string& path, |
566 int request_id) { | 553 AboutUIHTMLSource* source, |
| 554 const content::URLDataSource::GotDataCallback& callback) { |
567 if (path == kStringsJsPath) { | 555 if (path == kStringsJsPath) { |
568 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want | 556 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want |
569 // the refcount to be greater than 0. | 557 // the refcount to be greater than 0. |
570 scoped_refptr<AboutMemoryHandler> | 558 scoped_refptr<AboutMemoryHandler> handler(new AboutMemoryHandler(callback)); |
571 handler(new AboutMemoryHandler(source->AsWeakPtr(), request_id)); | |
572 // TODO(jamescook): Maybe this shouldn't update UMA? | 559 // TODO(jamescook): Maybe this shouldn't update UMA? |
573 handler->StartFetch(MemoryDetails::UPDATE_USER_METRICS); | 560 handler->StartFetch(MemoryDetails::UPDATE_USER_METRICS); |
574 } else { | 561 } else { |
575 source->FinishDataRequest( | 562 source->FinishDataRequest( |
576 ResourceBundle::GetSharedInstance().GetRawDataResource( | 563 ResourceBundle::GetSharedInstance().GetRawDataResource( |
577 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS : | 564 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS : |
578 IDR_ABOUT_MEMORY_HTML).as_string(), request_id); | 565 IDR_ABOUT_MEMORY_HTML).as_string(), callback); |
579 } | 566 } |
580 } | 567 } |
581 | 568 |
582 // Handler for filling in the "about:stats" page, as called by the browser's | 569 // Handler for filling in the "about:stats" page, as called by the browser's |
583 // About handler processing. | 570 // About handler processing. |
584 // |query| is roughly the query string of the about:stats URL. | 571 // |query| is roughly the query string of the about:stats URL. |
585 // Returns a string containing the HTML to render for the about:stats page. | 572 // Returns a string containing the HTML to render for the about:stats page. |
586 // Conditional Output: | 573 // Conditional Output: |
587 // if |query| is "json", returns a JSON format of all counters. | 574 // if |query| is "json", returns a JSON format of all counters. |
588 // if |query| is "raw", returns plain text of counter deltas. | 575 // if |query| is "raw", returns plain text of counter deltas. |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 if (info->is_diagnostics) | 850 if (info->is_diagnostics) |
864 child_label.append(" (diagnostics)"); | 851 child_label.append(" (diagnostics)"); |
865 child->SetString("child_name", child_label); | 852 child->SetString("child_name", child_label); |
866 ListValue* titles = new ListValue(); | 853 ListValue* titles = new ListValue(); |
867 child->Set("titles", titles); | 854 child->Set("titles", titles); |
868 for (size_t i = 0; i < info->titles.size(); ++i) | 855 for (size_t i = 0; i < info->titles.size(); ++i) |
869 titles->Append(new StringValue(info->titles[i])); | 856 titles->Append(new StringValue(info->titles[i])); |
870 } | 857 } |
871 | 858 |
872 void AboutMemoryHandler::OnDetailsAvailable() { | 859 void AboutMemoryHandler::OnDetailsAvailable() { |
873 if (!source_) | |
874 return; | |
875 | |
876 // the root of the JSON hierarchy for about:memory jstemplate | 860 // the root of the JSON hierarchy for about:memory jstemplate |
877 scoped_ptr<DictionaryValue> root(new DictionaryValue); | 861 scoped_ptr<DictionaryValue> root(new DictionaryValue); |
878 ListValue* browsers = new ListValue(); | 862 ListValue* browsers = new ListValue(); |
879 root->Set("browsers", browsers); | 863 root->Set("browsers", browsers); |
880 | 864 |
881 const std::vector<ProcessData>& browser_processes = processes(); | 865 const std::vector<ProcessData>& browser_processes = processes(); |
882 | 866 |
883 // Aggregate per-process data into browser summary data. | 867 // Aggregate per-process data into browser summary data. |
884 string16 log_string; | 868 string16 log_string; |
885 for (size_t index = 0; index < browser_processes.size(); index++) { | 869 for (size_t index = 0; index < browser_processes.size(); index++) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 AppendProcess(child_data, &process.processes[index]); | 924 AppendProcess(child_data, &process.processes[index]); |
941 } | 925 } |
942 | 926 |
943 root->SetBoolean("show_other_browsers", | 927 root->SetBoolean("show_other_browsers", |
944 browser_defaults::kShowOtherBrowsersInAboutMemory); | 928 browser_defaults::kShowOtherBrowsersInAboutMemory); |
945 | 929 |
946 DictionaryValue load_time_data; | 930 DictionaryValue load_time_data; |
947 load_time_data.SetString( | 931 load_time_data.SetString( |
948 "summary_desc", | 932 "summary_desc", |
949 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC)); | 933 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC)); |
950 URLDataSource::SetFontAndTextDirection(&load_time_data); | 934 web_ui_util::SetFontAndTextDirection(&load_time_data); |
951 load_time_data.Set("jstemplateData", root.release()); | 935 load_time_data.Set("jstemplateData", root.release()); |
952 | 936 |
953 jstemplate_builder::UseVersion2 version2; | 937 jstemplate_builder::UseVersion2 version2; |
954 std::string data; | 938 std::string data; |
955 jstemplate_builder::AppendJsonJS(&load_time_data, &data); | 939 jstemplate_builder::AppendJsonJS(&load_time_data, &data); |
956 source_->FinishDataRequest(data, request_id_); | 940 callback_.Run(base::RefCountedString::TakeString(&data)); |
957 } | 941 } |
958 | 942 |
959 } // namespace | 943 } // namespace |
960 | 944 |
961 // AboutUIHTMLSource ---------------------------------------------------------- | 945 // AboutUIHTMLSource ---------------------------------------------------------- |
962 | 946 |
963 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, | 947 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, |
964 Profile* profile) | 948 Profile* profile) |
965 : source_name_(source_name), | 949 : source_name_(source_name), |
966 profile_(profile) {} | 950 profile_(profile) {} |
967 | 951 |
968 AboutUIHTMLSource::~AboutUIHTMLSource() {} | 952 AboutUIHTMLSource::~AboutUIHTMLSource() {} |
969 | 953 |
970 std::string AboutUIHTMLSource::GetSource() { | 954 std::string AboutUIHTMLSource::GetSource() { |
971 return source_name_; | 955 return source_name_; |
972 } | 956 } |
973 | 957 |
974 void AboutUIHTMLSource::StartDataRequest(const std::string& path, | 958 void AboutUIHTMLSource::StartDataRequest( |
975 bool is_incognito, | 959 const std::string& path, |
976 int request_id) { | 960 bool is_incognito, |
| 961 const content::URLDataSource::GotDataCallback& callback) { |
977 std::string response; | 962 std::string response; |
978 // Add your data source here, in alphabetical order. | 963 // Add your data source here, in alphabetical order. |
979 if (source_name_ == chrome::kChromeUIChromeURLsHost) { | 964 if (source_name_ == chrome::kChromeUIChromeURLsHost) { |
980 response = ChromeURLs(); | 965 response = ChromeURLs(); |
981 } else if (source_name_ == chrome::kChromeUICreditsHost) { | 966 } else if (source_name_ == chrome::kChromeUICreditsHost) { |
982 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; | 967 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; |
983 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 968 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
984 idr).as_string(); | 969 idr).as_string(); |
985 #if defined(OS_CHROMEOS) | 970 #if defined(OS_CHROMEOS) |
986 } else if (source_name_ == chrome::kChromeUIDiscardsHost) { | 971 } else if (source_name_ == chrome::kChromeUIDiscardsHost) { |
987 response = AboutDiscards(path); | 972 response = AboutDiscards(path); |
988 #endif | 973 #endif |
989 #if defined(USE_ASH) | 974 #if defined(USE_ASH) |
990 } else if (source_name_ == chrome::kChromeUITransparencyHost) { | 975 } else if (source_name_ == chrome::kChromeUITransparencyHost) { |
991 response = AboutTransparency(path); | 976 response = AboutTransparency(path); |
992 #endif | 977 #endif |
993 } else if (source_name_ == chrome::kChromeUIDNSHost) { | 978 } else if (source_name_ == chrome::kChromeUIDNSHost) { |
994 AboutDnsHandler::Start(AsWeakPtr(), request_id); | 979 AboutDnsHandler::Start(profile(), callback); |
995 return; | 980 return; |
996 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 981 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
997 } else if (source_name_ == chrome::kChromeUILinuxProxyConfigHost) { | 982 } else if (source_name_ == chrome::kChromeUILinuxProxyConfigHost) { |
998 response = AboutLinuxProxyConfig(); | 983 response = AboutLinuxProxyConfig(); |
999 #endif | 984 #endif |
1000 } else if (source_name_ == chrome::kChromeUIMemoryHost) { | 985 } else if (source_name_ == chrome::kChromeUIMemoryHost) { |
1001 response = GetAboutMemoryRedirectResponse(profile()); | 986 response = GetAboutMemoryRedirectResponse(profile()); |
1002 } else if (source_name_ == chrome::kChromeUIMemoryRedirectHost) { | 987 } else if (source_name_ == chrome::kChromeUIMemoryRedirectHost) { |
1003 FinishMemoryDataRequest(path, this, request_id); | 988 FinishMemoryDataRequest(path, this, callback); |
1004 return; | 989 return; |
1005 #if defined(OS_CHROMEOS) | 990 #if defined(OS_CHROMEOS) |
1006 } else if (source_name_ == chrome::kChromeUINetworkHost) { | 991 } else if (source_name_ == chrome::kChromeUINetworkHost) { |
1007 response = chromeos::about_ui::AboutNetwork(path); | 992 response = chromeos::about_ui::AboutNetwork(path); |
1008 } else if (source_name_ == chrome::kChromeUIOSCreditsHost) { | 993 } else if (source_name_ == chrome::kChromeUIOSCreditsHost) { |
1009 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 994 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
1010 IDR_OS_CREDITS_HTML).as_string(); | 995 IDR_OS_CREDITS_HTML).as_string(); |
1011 #endif | 996 #endif |
1012 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 997 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
1013 } else if (source_name_ == chrome::kChromeUISandboxHost) { | 998 } else if (source_name_ == chrome::kChromeUISandboxHost) { |
1014 response = AboutSandbox(); | 999 response = AboutSandbox(); |
1015 #endif | 1000 #endif |
1016 } else if (source_name_ == chrome::kChromeUIStatsHost) { | 1001 } else if (source_name_ == chrome::kChromeUIStatsHost) { |
1017 response = AboutStats(path); | 1002 response = AboutStats(path); |
1018 } else if (source_name_ == chrome::kChromeUITermsHost) { | 1003 } else if (source_name_ == chrome::kChromeUITermsHost) { |
1019 #if defined(OS_CHROMEOS) | 1004 #if defined(OS_CHROMEOS) |
1020 ChromeOSTermsHandler::Start(AsWeakPtr(), path, request_id); | 1005 ChromeOSTermsHandler::Start(path, callback); |
1021 return; | 1006 return; |
1022 #else | 1007 #else |
1023 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); | 1008 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); |
1024 #endif | 1009 #endif |
1025 } | 1010 } |
1026 | 1011 |
1027 FinishDataRequest(response, request_id); | 1012 FinishDataRequest(response, callback); |
1028 } | 1013 } |
1029 | 1014 |
1030 void AboutUIHTMLSource::FinishDataRequest(const std::string& html, | 1015 void AboutUIHTMLSource::FinishDataRequest( |
1031 int request_id) { | 1016 const std::string& html, |
| 1017 const content::URLDataSource::GotDataCallback& callback) { |
1032 std::string html_copy(html); | 1018 std::string html_copy(html); |
1033 url_data_source()->SendResponse( | 1019 callback.Run(base::RefCountedString::TakeString(&html_copy)); |
1034 request_id, base::RefCountedString::TakeString(&html_copy)); | |
1035 } | 1020 } |
1036 | 1021 |
1037 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { | 1022 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { |
1038 if (path == kCreditsJsPath || | 1023 if (path == kCreditsJsPath || |
1039 path == kStatsJsPath || | 1024 path == kStatsJsPath || |
1040 path == kStringsJsPath || | 1025 path == kStringsJsPath || |
1041 path == kMemoryJsPath) { | 1026 path == kMemoryJsPath) { |
1042 return "application/javascript"; | 1027 return "application/javascript"; |
1043 } | 1028 } |
1044 return "text/html"; | 1029 return "text/html"; |
1045 } | 1030 } |
1046 | 1031 |
1047 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) | 1032 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) |
1048 : WebUIController(web_ui) { | 1033 : WebUIController(web_ui) { |
1049 Profile* profile = Profile::FromWebUI(web_ui); | 1034 Profile* profile = Profile::FromWebUI(web_ui); |
1050 | 1035 |
1051 #if defined(ENABLE_THEMES) | 1036 #if defined(ENABLE_THEMES) |
1052 // Set up the chrome://theme/ source. | 1037 // Set up the chrome://theme/ source. |
1053 ThemeSource* theme = new ThemeSource(profile); | 1038 ThemeSource* theme = new ThemeSource(profile); |
1054 ChromeURLDataManager::AddDataSource(profile, theme); | 1039 ChromeURLDataManager::AddDataSource(profile, theme); |
1055 #endif | 1040 #endif |
1056 | 1041 |
1057 content::URLDataSourceDelegate* source = new AboutUIHTMLSource(name, profile); | 1042 ChromeURLDataManager::AddDataSource( |
1058 ChromeURLDataManager::AddDataSource(profile, source); | 1043 profile, new AboutUIHTMLSource(name, profile)); |
1059 } | 1044 } |
OLD | NEW |