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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 AboutMemoryHandler(const base::WeakPtr<AboutUIHTMLSource>& source, |
119 int request_id) | 119 const content::URLDataSource::GotDataCallback& callback) |
120 : source_(source), | 120 : source_(source), |
121 request_id_(request_id) { | 121 callback_(callback) { |
122 } | 122 } |
123 | 123 |
124 virtual void OnDetailsAvailable() OVERRIDE; | 124 virtual void OnDetailsAvailable() OVERRIDE; |
125 | 125 |
126 private: | 126 private: |
127 ~AboutMemoryHandler() {} | 127 ~AboutMemoryHandler() {} |
128 | 128 |
129 void BindProcessMetrics(DictionaryValue* data, | 129 void BindProcessMetrics(DictionaryValue* data, |
130 ProcessMemoryInformation* info); | 130 ProcessMemoryInformation* info); |
131 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); | 131 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); |
132 | 132 |
133 base::WeakPtr<AboutUIHTMLSource> source_; | 133 base::WeakPtr<AboutUIHTMLSource> source_; |
134 int request_id_; | 134 const content::URLDataSource::GotDataCallback& callback_; |
135 | 135 |
136 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); | 136 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); |
137 }; | 137 }; |
138 | 138 |
139 #if defined(OS_CHROMEOS) | 139 #if defined(OS_CHROMEOS) |
140 class ChromeOSTermsHandler | 140 class ChromeOSTermsHandler |
141 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { | 141 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { |
142 public: | 142 public: |
143 static void Start(const base::WeakPtr<AboutUIHTMLSource>& source, | 143 static void Start(const base::WeakPtr<AboutUIHTMLSource>& source, |
144 const std::string& path, | 144 const std::string& path, |
145 int request_id) { | 145 const content::URLDataSource::GotDataCallback& callback) { |
146 scoped_refptr<ChromeOSTermsHandler> handler( | 146 scoped_refptr<ChromeOSTermsHandler> handler( |
147 new ChromeOSTermsHandler(source, path, request_id)); | 147 new ChromeOSTermsHandler(source, path, callback)); |
148 handler->StartOnUIThread(); | 148 handler->StartOnUIThread(); |
149 } | 149 } |
150 | 150 |
151 private: | 151 private: |
152 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; | 152 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; |
153 | 153 |
154 ChromeOSTermsHandler(const base::WeakPtr<AboutUIHTMLSource>& source, | 154 ChromeOSTermsHandler(const base::WeakPtr<AboutUIHTMLSource>& source, |
155 const std::string& path, | 155 const std::string& path, |
156 int request_id) | 156 const content::URLDataSource::GotDataCallback& callback) |
157 : source_(source), | 157 : source_(source), |
158 path_(path), | 158 path_(path), |
159 request_id_(request_id), | 159 callback_(callback), |
160 // Previously we were using "initial locale" http://crbug.com/145142 | 160 // Previously we were using "initial locale" http://crbug.com/145142 |
161 locale_(g_browser_process->GetApplicationLocale()) { | 161 locale_(g_browser_process->GetApplicationLocale()) { |
162 } | 162 } |
163 | 163 |
164 ~ChromeOSTermsHandler() {} | 164 ~ChromeOSTermsHandler() {} |
165 | 165 |
166 void StartOnUIThread() { | 166 void StartOnUIThread() { |
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
168 BrowserThread::PostTask( | 168 BrowserThread::PostTask( |
169 BrowserThread::FILE, FROM_HERE, | 169 BrowserThread::FILE, FROM_HERE, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 204 |
205 void ResponseOnUIThread() { | 205 void ResponseOnUIThread() { |
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
207 if (!source_) | 207 if (!source_) |
208 return; | 208 return; |
209 | 209 |
210 // If we fail to load Chrome OS EULA from disk, load it from resources. | 210 // If we fail to load Chrome OS EULA from disk, load it from resources. |
211 // Do nothing if OEM EULA load failed. | 211 // Do nothing if OEM EULA load failed. |
212 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) | 212 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) |
213 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); | 213 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); |
214 source_->FinishDataRequest(contents_, request_id_); | 214 source_->FinishDataRequest(contents_, callback_); |
215 } | 215 } |
216 | 216 |
217 // Where the results are fed to. | 217 // Where the results are fed to. |
218 base::WeakPtr<AboutUIHTMLSource> source_; | 218 base::WeakPtr<AboutUIHTMLSource> source_; |
219 | 219 |
220 // Path in the URL. | 220 // Path in the URL. |
221 std::string path_; | 221 std::string path_; |
222 | 222 |
223 // ID identifying the request. | 223 // Callback to run with the response. |
224 int request_id_; | 224 const content::URLDataSource::GotDataCallback& callback_; |
225 | 225 |
226 // Locale of the EULA. | 226 // Locale of the EULA. |
227 std::string locale_; | 227 std::string locale_; |
228 | 228 |
229 // EULA contents that was loaded from file. | 229 // EULA contents that was loaded from file. |
230 std::string contents_; | 230 std::string contents_; |
231 | 231 |
232 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); | 232 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); |
233 }; | 233 }; |
234 | 234 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 return output; | 497 return output; |
498 } | 498 } |
499 | 499 |
500 #endif // USE_ASH | 500 #endif // USE_ASH |
501 | 501 |
502 // AboutDnsHandler bounces the request back to the IO thread to collect | 502 // AboutDnsHandler bounces the request back to the IO thread to collect |
503 // the DNS information. | 503 // the DNS information. |
504 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { | 504 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { |
505 public: | 505 public: |
506 static void Start(const base::WeakPtr<AboutUIHTMLSource>& source, | 506 static void Start(const base::WeakPtr<AboutUIHTMLSource>& source, |
507 int request_id) { | 507 const content::URLDataSource::GotDataCallback& callback) { |
508 scoped_refptr<AboutDnsHandler> handler( | 508 scoped_refptr<AboutDnsHandler> handler( |
509 new AboutDnsHandler(source, request_id)); | 509 new AboutDnsHandler(source, callback)); |
510 handler->StartOnUIThread(); | 510 handler->StartOnUIThread(); |
511 } | 511 } |
512 | 512 |
513 private: | 513 private: |
514 friend class base::RefCountedThreadSafe<AboutDnsHandler>; | 514 friend class base::RefCountedThreadSafe<AboutDnsHandler>; |
515 | 515 |
516 AboutDnsHandler(const base::WeakPtr<AboutUIHTMLSource>& source, | 516 AboutDnsHandler(const base::WeakPtr<AboutUIHTMLSource>& source, |
517 int request_id) | 517 const content::URLDataSource::GotDataCallback& callback) |
518 : source_(source), | 518 : source_(source), |
519 request_id_(request_id) { | 519 callback_(callback) { |
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
521 } | 521 } |
522 | 522 |
523 virtual ~AboutDnsHandler() {} | 523 virtual ~AboutDnsHandler() {} |
524 | 524 |
525 // Calls FinishOnUIThread() on completion. | 525 // Calls FinishOnUIThread() on completion. |
526 void StartOnUIThread() { | 526 void StartOnUIThread() { |
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
528 chrome_browser_net::Predictor* predictor = | 528 chrome_browser_net::Predictor* predictor = |
529 source_->profile()->GetNetworkPredictor(); | 529 source_->profile()->GetNetworkPredictor(); |
(...skipping 12 matching lines...) Expand all Loading... | |
542 AppendFooter(&data); | 542 AppendFooter(&data); |
543 | 543 |
544 BrowserThread::PostTask( | 544 BrowserThread::PostTask( |
545 BrowserThread::UI, FROM_HERE, | 545 BrowserThread::UI, FROM_HERE, |
546 base::Bind(&AboutDnsHandler::FinishOnUIThread, this, data)); | 546 base::Bind(&AboutDnsHandler::FinishOnUIThread, this, data)); |
547 } | 547 } |
548 | 548 |
549 void FinishOnUIThread(const std::string& data) { | 549 void FinishOnUIThread(const std::string& data) { |
550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
551 if (source_) | 551 if (source_) |
552 source_->FinishDataRequest(data, request_id_); | 552 source_->FinishDataRequest(data, callback_); |
553 } | 553 } |
554 | 554 |
555 // Where the results are fed to. | 555 // Where the results are fed to. |
556 base::WeakPtr<AboutUIHTMLSource> source_; | 556 base::WeakPtr<AboutUIHTMLSource> source_; |
557 | 557 |
558 // ID identifying the request. | 558 // Callback to run with the response. |
559 int request_id_; | 559 const content::URLDataSource::GotDataCallback& callback_; |
560 | 560 |
561 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); | 561 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); |
562 }; | 562 }; |
563 | 563 |
564 void FinishMemoryDataRequest(const std::string& path, | 564 void FinishMemoryDataRequest( |
565 AboutUIHTMLSource* source, | 565 const std::string& path, |
566 int request_id) { | 566 AboutUIHTMLSource* source, |
567 const content::URLDataSource::GotDataCallback& callback) { | |
567 if (path == kStringsJsPath) { | 568 if (path == kStringsJsPath) { |
568 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want | 569 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want |
569 // the refcount to be greater than 0. | 570 // the refcount to be greater than 0. |
570 scoped_refptr<AboutMemoryHandler> | 571 scoped_refptr<AboutMemoryHandler> |
571 handler(new AboutMemoryHandler(source->AsWeakPtr(), request_id)); | 572 handler(new AboutMemoryHandler(source->AsWeakPtr(), callback)); |
572 // TODO(jamescook): Maybe this shouldn't update UMA? | 573 // TODO(jamescook): Maybe this shouldn't update UMA? |
573 handler->StartFetch(MemoryDetails::UPDATE_USER_METRICS); | 574 handler->StartFetch(MemoryDetails::UPDATE_USER_METRICS); |
574 } else { | 575 } else { |
575 source->FinishDataRequest( | 576 source->FinishDataRequest( |
576 ResourceBundle::GetSharedInstance().GetRawDataResource( | 577 ResourceBundle::GetSharedInstance().GetRawDataResource( |
577 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS : | 578 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS : |
578 IDR_ABOUT_MEMORY_HTML).as_string(), request_id); | 579 IDR_ABOUT_MEMORY_HTML).as_string(), callback); |
579 } | 580 } |
580 } | 581 } |
581 | 582 |
582 // Handler for filling in the "about:stats" page, as called by the browser's | 583 // Handler for filling in the "about:stats" page, as called by the browser's |
583 // About handler processing. | 584 // About handler processing. |
584 // |query| is roughly the query string of the about:stats URL. | 585 // |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. | 586 // Returns a string containing the HTML to render for the about:stats page. |
586 // Conditional Output: | 587 // Conditional Output: |
587 // if |query| is "json", returns a JSON format of all counters. | 588 // if |query| is "json", returns a JSON format of all counters. |
588 // if |query| is "raw", returns plain text of counter deltas. | 589 // if |query| is "raw", returns plain text of counter deltas. |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 AppendProcess(child_data, &process.processes[index]); | 941 AppendProcess(child_data, &process.processes[index]); |
941 } | 942 } |
942 | 943 |
943 root->SetBoolean("show_other_browsers", | 944 root->SetBoolean("show_other_browsers", |
944 browser_defaults::kShowOtherBrowsersInAboutMemory); | 945 browser_defaults::kShowOtherBrowsersInAboutMemory); |
945 | 946 |
946 DictionaryValue load_time_data; | 947 DictionaryValue load_time_data; |
947 load_time_data.SetString( | 948 load_time_data.SetString( |
948 "summary_desc", | 949 "summary_desc", |
949 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC)); | 950 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC)); |
950 URLDataSource::SetFontAndTextDirection(&load_time_data); | 951 web_ui_util::SetFontAndTextDirection(&load_time_data); |
951 load_time_data.Set("jstemplateData", root.release()); | 952 load_time_data.Set("jstemplateData", root.release()); |
952 | 953 |
953 jstemplate_builder::UseVersion2 version2; | 954 jstemplate_builder::UseVersion2 version2; |
954 std::string data; | 955 std::string data; |
955 jstemplate_builder::AppendJsonJS(&load_time_data, &data); | 956 jstemplate_builder::AppendJsonJS(&load_time_data, &data); |
956 source_->FinishDataRequest(data, request_id_); | 957 source_->FinishDataRequest(data, callback_); |
957 } | 958 } |
958 | 959 |
959 } // namespace | 960 } // namespace |
960 | 961 |
961 // AboutUIHTMLSource ---------------------------------------------------------- | 962 // AboutUIHTMLSource ---------------------------------------------------------- |
962 | 963 |
963 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, | 964 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, |
964 Profile* profile) | 965 Profile* profile) |
965 : source_name_(source_name), | 966 : source_name_(source_name), |
966 profile_(profile) {} | 967 profile_(profile) {} |
967 | 968 |
968 AboutUIHTMLSource::~AboutUIHTMLSource() {} | 969 AboutUIHTMLSource::~AboutUIHTMLSource() {} |
969 | 970 |
970 std::string AboutUIHTMLSource::GetSource() { | 971 std::string AboutUIHTMLSource::GetSource() { |
971 return source_name_; | 972 return source_name_; |
972 } | 973 } |
973 | 974 |
974 void AboutUIHTMLSource::StartDataRequest(const std::string& path, | 975 void AboutUIHTMLSource::StartDataRequest( |
975 bool is_incognito, | 976 const std::string& path, |
976 int request_id) { | 977 bool is_incognito, |
978 const content::URLDataSource::GotDataCallback& callback) { | |
977 std::string response; | 979 std::string response; |
978 // Add your data source here, in alphabetical order. | 980 // Add your data source here, in alphabetical order. |
979 if (source_name_ == chrome::kChromeUIChromeURLsHost) { | 981 if (source_name_ == chrome::kChromeUIChromeURLsHost) { |
980 response = ChromeURLs(); | 982 response = ChromeURLs(); |
981 } else if (source_name_ == chrome::kChromeUICreditsHost) { | 983 } else if (source_name_ == chrome::kChromeUICreditsHost) { |
982 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; | 984 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; |
983 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 985 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
984 idr).as_string(); | 986 idr).as_string(); |
985 #if defined(OS_CHROMEOS) | 987 #if defined(OS_CHROMEOS) |
986 } else if (source_name_ == chrome::kChromeUIDiscardsHost) { | 988 } else if (source_name_ == chrome::kChromeUIDiscardsHost) { |
987 response = AboutDiscards(path); | 989 response = AboutDiscards(path); |
988 #endif | 990 #endif |
989 #if defined(USE_ASH) | 991 #if defined(USE_ASH) |
990 } else if (source_name_ == chrome::kChromeUITransparencyHost) { | 992 } else if (source_name_ == chrome::kChromeUITransparencyHost) { |
991 response = AboutTransparency(path); | 993 response = AboutTransparency(path); |
992 #endif | 994 #endif |
993 } else if (source_name_ == chrome::kChromeUIDNSHost) { | 995 } else if (source_name_ == chrome::kChromeUIDNSHost) { |
994 AboutDnsHandler::Start(AsWeakPtr(), request_id); | 996 AboutDnsHandler::Start(AsWeakPtr(), callback); |
995 return; | 997 return; |
996 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 998 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
997 } else if (source_name_ == chrome::kChromeUILinuxProxyConfigHost) { | 999 } else if (source_name_ == chrome::kChromeUILinuxProxyConfigHost) { |
998 response = AboutLinuxProxyConfig(); | 1000 response = AboutLinuxProxyConfig(); |
999 #endif | 1001 #endif |
1000 } else if (source_name_ == chrome::kChromeUIMemoryHost) { | 1002 } else if (source_name_ == chrome::kChromeUIMemoryHost) { |
1001 response = GetAboutMemoryRedirectResponse(profile()); | 1003 response = GetAboutMemoryRedirectResponse(profile()); |
1002 } else if (source_name_ == chrome::kChromeUIMemoryRedirectHost) { | 1004 } else if (source_name_ == chrome::kChromeUIMemoryRedirectHost) { |
1003 FinishMemoryDataRequest(path, this, request_id); | 1005 FinishMemoryDataRequest(path, this, callback); |
1004 return; | 1006 return; |
1005 #if defined(OS_CHROMEOS) | 1007 #if defined(OS_CHROMEOS) |
1006 } else if (source_name_ == chrome::kChromeUINetworkHost) { | 1008 } else if (source_name_ == chrome::kChromeUINetworkHost) { |
1007 response = chromeos::about_ui::AboutNetwork(path); | 1009 response = chromeos::about_ui::AboutNetwork(path); |
1008 } else if (source_name_ == chrome::kChromeUIOSCreditsHost) { | 1010 } else if (source_name_ == chrome::kChromeUIOSCreditsHost) { |
1009 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 1011 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
1010 IDR_OS_CREDITS_HTML).as_string(); | 1012 IDR_OS_CREDITS_HTML).as_string(); |
1011 #endif | 1013 #endif |
1012 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 1014 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
1013 } else if (source_name_ == chrome::kChromeUISandboxHost) { | 1015 } else if (source_name_ == chrome::kChromeUISandboxHost) { |
1014 response = AboutSandbox(); | 1016 response = AboutSandbox(); |
1015 #endif | 1017 #endif |
1016 } else if (source_name_ == chrome::kChromeUIStatsHost) { | 1018 } else if (source_name_ == chrome::kChromeUIStatsHost) { |
1017 response = AboutStats(path); | 1019 response = AboutStats(path); |
1018 } else if (source_name_ == chrome::kChromeUITermsHost) { | 1020 } else if (source_name_ == chrome::kChromeUITermsHost) { |
1019 #if defined(OS_CHROMEOS) | 1021 #if defined(OS_CHROMEOS) |
1020 ChromeOSTermsHandler::Start(AsWeakPtr(), path, request_id); | 1022 ChromeOSTermsHandler::Start(AsWeakPtr(), path, callback); |
1021 return; | 1023 return; |
1022 #else | 1024 #else |
1023 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); | 1025 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); |
1024 #endif | 1026 #endif |
1025 } | 1027 } |
1026 | 1028 |
1027 FinishDataRequest(response, request_id); | 1029 FinishDataRequest(response, callback); |
1028 } | 1030 } |
1029 | 1031 |
1030 void AboutUIHTMLSource::FinishDataRequest(const std::string& html, | 1032 void AboutUIHTMLSource::FinishDataRequest( |
1031 int request_id) { | 1033 const std::string& html, |
1034 const content::URLDataSource::GotDataCallback& callback) { | |
1032 std::string html_copy(html); | 1035 std::string html_copy(html); |
1033 url_data_source()->SendResponse( | 1036 callback.Run(base::RefCountedString::TakeString(&html_copy)); |
1034 request_id, base::RefCountedString::TakeString(&html_copy)); | |
1035 } | 1037 } |
1036 | 1038 |
1037 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { | 1039 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { |
1038 if (path == kCreditsJsPath || | 1040 if (path == kCreditsJsPath || |
1039 path == kStatsJsPath || | 1041 path == kStatsJsPath || |
1040 path == kStringsJsPath || | 1042 path == kStringsJsPath || |
1041 path == kMemoryJsPath) { | 1043 path == kMemoryJsPath) { |
1042 return "application/javascript"; | 1044 return "application/javascript"; |
1043 } | 1045 } |
1044 return "text/html"; | 1046 return "text/html"; |
1045 } | 1047 } |
1046 | 1048 |
1047 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) | 1049 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) |
1048 : WebUIController(web_ui) { | 1050 : WebUIController(web_ui) { |
1049 Profile* profile = Profile::FromWebUI(web_ui); | 1051 Profile* profile = Profile::FromWebUI(web_ui); |
1050 | 1052 |
1051 #if defined(ENABLE_THEMES) | 1053 #if defined(ENABLE_THEMES) |
1052 // Set up the chrome://theme/ source. | 1054 // Set up the chrome://theme/ source. |
1053 ThemeSource* theme = new ThemeSource(profile); | 1055 ThemeSource* theme = new ThemeSource(profile); |
1054 ChromeURLDataManager::AddDataSource(profile, theme); | 1056 ChromeURLDataManager::AddDataSource(profile, theme); |
1055 #endif | 1057 #endif |
1056 | 1058 |
1057 content::URLDataSourceDelegate* source = new AboutUIHTMLSource(name, profile); | 1059 AboutUIHTMLSource* source = new AboutUIHTMLSource(name, profile); |
1058 ChromeURLDataManager::AddDataSource(profile, source); | 1060 ChromeURLDataManager::AddDataSource(profile, source); |
Evan Stade
2013/01/15 20:49:34
combine these lines?
jam
2013/01/15 21:09:08
(just tried it) that would take two lines
Evan Stade
2013/01/15 21:33:43
yea, but I still think it's better. For one thing,
jam
2013/01/15 21:39:47
Done. btw this is my style preference as well; but
| |
1059 } | 1061 } |
OLD | NEW |