Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: chrome/browser/ui/webui/about_ui.cc

Issue 13820014: Show online policy on CrOS EULA page (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add localization and "Loading" string Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "content/public/common/content_client.h" 48 #include "content/public/common/content_client.h"
49 #include "content/public/common/process_type.h" 49 #include "content/public/common/process_type.h"
50 #include "google_apis/gaia/google_service_auth_error.h" 50 #include "google_apis/gaia/google_service_auth_error.h"
51 #include "googleurl/src/gurl.h" 51 #include "googleurl/src/gurl.h"
52 #include "grit/browser_resources.h" 52 #include "grit/browser_resources.h"
53 #include "grit/chromium_strings.h" 53 #include "grit/chromium_strings.h"
54 #include "grit/generated_resources.h" 54 #include "grit/generated_resources.h"
55 #include "grit/locale_settings.h" 55 #include "grit/locale_settings.h"
56 #include "net/base/escape.h" 56 #include "net/base/escape.h"
57 #include "net/base/net_util.h" 57 #include "net/base/net_util.h"
58 #include "net/http/http_response_headers.h"
59 #include "net/url_request/url_fetcher.h"
60 #include "net/url_request/url_request_status.h"
58 #include "ui/base/l10n/l10n_util.h" 61 #include "ui/base/l10n/l10n_util.h"
59 #include "ui/base/resource/resource_bundle.h" 62 #include "ui/base/resource/resource_bundle.h"
60 #include "ui/webui/jstemplate_builder.h" 63 #include "ui/webui/jstemplate_builder.h"
61 #include "ui/webui/web_ui_util.h" 64 #include "ui/webui/web_ui_util.h"
62 65
63 #if defined(ENABLE_THEMES) 66 #if defined(ENABLE_THEMES)
64 #include "chrome/browser/ui/webui/theme_source.h" 67 #include "chrome/browser/ui/webui/theme_source.h"
65 #endif 68 #endif
66 69
67 #if defined(OS_LINUX) || defined(OS_OPENBSD) 70 #if defined(OS_LINUX) || defined(OS_OPENBSD)
(...skipping 21 matching lines...) Expand all
89 using content::BrowserThread; 92 using content::BrowserThread;
90 using content::WebContents; 93 using content::WebContents;
91 94
92 namespace { 95 namespace {
93 96
94 const char kCreditsJsPath[] = "credits.js"; 97 const char kCreditsJsPath[] = "credits.js";
95 const char kMemoryJsPath[] = "memory.js"; 98 const char kMemoryJsPath[] = "memory.js";
96 const char kMemoryCssPath[] = "about_memory.css"; 99 const char kMemoryCssPath[] = "about_memory.css";
97 const char kStatsJsPath[] = "stats.js"; 100 const char kStatsJsPath[] = "stats.js";
98 const char kStringsJsPath[] = "strings.js"; 101 const char kStringsJsPath[] = "strings.js";
102 // chrome://terms falls back to offline page after kOnlineTermsTimeoutSec.
103 const int kOnlineTermsTimeoutSec = 10;
99 104
100 // When you type about:memory, it actually loads this intermediate URL that 105 // When you type about:memory, it actually loads this intermediate URL that
101 // redirects you to the final page. This avoids the problem where typing 106 // redirects you to the final page. This avoids the problem where typing
102 // "about:memory" on the new tab page or any other page where a process 107 // "about:memory" on the new tab page or any other page where a process
103 // transition would occur to the about URL will cause some confusion. 108 // transition would occur to the about URL will cause some confusion.
104 // 109 //
105 // The problem is that during the processing of the memory page, there are two 110 // The problem is that during the processing of the memory page, there are two
106 // processes active, the original and the destination one. This can create the 111 // processes active, the original and the destination one. This can create the
107 // impression that we're using more resources than we actually are. This 112 // impression that we're using more resources than we actually are. This
108 // redirect solves the problem by eliminating the process transition during the 113 // redirect solves the problem by eliminating the process transition during the
(...skipping 21 matching lines...) Expand all
130 void BindProcessMetrics(DictionaryValue* data, 135 void BindProcessMetrics(DictionaryValue* data,
131 ProcessMemoryInformation* info); 136 ProcessMemoryInformation* info);
132 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); 137 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
133 138
134 content::URLDataSource::GotDataCallback callback_; 139 content::URLDataSource::GotDataCallback callback_;
135 140
136 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); 141 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler);
137 }; 142 };
138 143
139 #if defined(OS_CHROMEOS) 144 #if defined(OS_CHROMEOS)
145 // Helper class that fetches the online Chrome OS terms.
battre 2013/04/17 10:41:19 Add comment that it returns an empty string in cas
vasilii 2013/04/17 16:58:56 Done.
146 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate {
147 public:
148 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback;
149
150 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback)
151 : fetch_callback_(callback) {
152 // TODO(vasilii): request a real EULA specific to locale.
153 eula_fetcher_.reset(net::URLFetcher::Create(
154 GURL(l10n_util::GetStringUTF16(IDS_EULA_POLICY_URL)),
155 net::URLFetcher::GET,
156 this));
157 eula_fetcher_->SetRequestContext(
158 g_browser_process->system_request_context());
159 eula_fetcher_->AddExtraRequestHeader("Accept: text/html");
160 eula_fetcher_->Start();
161 // Abort the download attempt if it takes longer than one minute.
162 download_timer_.Start(FROM_HERE,
163 base::TimeDelta::FromSeconds(kOnlineTermsTimeoutSec),
164 this,
165 &ChromeOSOnlineTermsHandler::OnDownloadTimeout);
166 }
167
168 void GetResponseResult(std::string* response_string) {
169 std::string mime_type;
170 if (!eula_fetcher_ ||
171 !eula_fetcher_->GetStatus().is_success() ||
172 !eula_fetcher_->GetResponseHeaders()->GetMimeType(&mime_type) ||
173 mime_type != "text/html" ||
174 !eula_fetcher_->GetResponseAsString(response_string)) {
175 response_string->clear();
176 }
177 }
178
179 private:
180 // Prevents allocation on the stack. ChromeOSOnlineTermsHandler should be
181 // created by 'operator new'. |this| takes care of destruction.
182 virtual ~ChromeOSOnlineTermsHandler() {}
183
184 // net::URLFetcherDelegate:
185 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
186 if (source != eula_fetcher_.get()) {
187 NOTREACHED() << "Callback from foreign URL fetcher";
188 return;
189 }
190 fetch_callback_.Run(this);
191 delete this;
192 }
193
194 void OnDownloadTimeout() {
195 eula_fetcher_.reset();
196 fetch_callback_.Run(this);
197 delete this;
198 }
199
200 // Timer that enforces a timeout on the attempt to download the
201 // ChromeOS Terms.
202 base::OneShotTimer<ChromeOSOnlineTermsHandler> download_timer_;
203
204 // |fetch_callback_| called when fetching succeeded or failed.
205 FetchCallback fetch_callback_;
206
207 // Helper to fetch online eula.
208 scoped_ptr<net::URLFetcher> eula_fetcher_;
209
210 DISALLOW_COPY_AND_ASSIGN(ChromeOSOnlineTermsHandler);
211 };
212
140 class ChromeOSTermsHandler 213 class ChromeOSTermsHandler
141 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { 214 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
142 public: 215 public:
143 static void Start(const std::string& path, 216 static void Start(const std::string& path,
144 const content::URLDataSource::GotDataCallback& callback) { 217 const content::URLDataSource::GotDataCallback& callback) {
145 scoped_refptr<ChromeOSTermsHandler> handler( 218 scoped_refptr<ChromeOSTermsHandler> handler(
146 new ChromeOSTermsHandler(path, callback)); 219 new ChromeOSTermsHandler(path, callback));
147 handler->StartOnUIThread(); 220 handler->StartOnUIThread();
148 } 221 }
149 222
150 private: 223 private:
151 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; 224 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>;
152 225
153 ChromeOSTermsHandler(const std::string& path, 226 ChromeOSTermsHandler(const std::string& path,
154 const content::URLDataSource::GotDataCallback& callback) 227 const content::URLDataSource::GotDataCallback& callback)
155 : path_(path), 228 : path_(path),
156 callback_(callback), 229 callback_(callback),
157 // Previously we were using "initial locale" http://crbug.com/145142 230 // Previously we were using "initial locale" http://crbug.com/145142
158 locale_(g_browser_process->GetApplicationLocale()) { 231 locale_(g_browser_process->GetApplicationLocale()) {
159 } 232 }
160 233
161 ~ChromeOSTermsHandler() {} 234 virtual ~ChromeOSTermsHandler() {}
162 235
163 void StartOnUIThread() { 236 void StartOnUIThread() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165 BrowserThread::PostTask( 238 if (path_ == chrome::kOemEulaURLPath) {
166 BrowserThread::FILE, FROM_HERE, 239 // Load local OEM EULA from the disk.
167 base::Bind(&ChromeOSTermsHandler::LoadFileOnFileThread, this)); 240 BrowserThread::PostTask(
241 BrowserThread::FILE, FROM_HERE,
242 base::Bind(&ChromeOSTermsHandler::LoadOemEulaFileOnFileThread, this));
243 } else {
244 // Try to load online version of ChromeOS terms first.
245 // ChromeOSOnlineTermsHandler object destroys itself.
246 new ChromeOSOnlineTermsHandler(
247 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this));
248 }
168 } 249 }
169 250
170 void LoadFileOnFileThread() { 251 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) {
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
253 loader->GetResponseResult(&contents_);
254 if (contents_.empty()) {
255 // Load local ChromeOS terms from the file.
256 BrowserThread::PostTask(
257 BrowserThread::FILE, FROM_HERE,
258 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this));
259 } else {
260 ResponseOnUIThread();
261 }
262 }
263
264 void LoadOemEulaFileOnFileThread() {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
172 if (path_ == chrome::kOemEulaURLPath) { 266 const chromeos::StartupCustomizationDocument* customization =
173 const chromeos::StartupCustomizationDocument* customization = 267 chromeos::StartupCustomizationDocument::GetInstance();
174 chromeos::StartupCustomizationDocument::GetInstance(); 268 if (customization->IsReady()) {
175 if (customization->IsReady()) { 269 base::FilePath oem_eula_file_path;
176 base::FilePath oem_eula_file_path; 270 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)),
177 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), 271 &oem_eula_file_path)) {
178 &oem_eula_file_path)) { 272 if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) {
179 if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) {
180 contents_.clear();
181 }
182 }
183 }
184 } else {
185 std::string file_path =
186 base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str());
187 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) {
188 // No EULA for given language - try en-US as default.
189 file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US");
190 if (!file_util::ReadFileToString(base::FilePath(file_path),
191 &contents_)) {
192 // File with EULA not found, ResponseOnUIThread will load EULA from
193 // resources if contents_ is empty.
194 contents_.clear(); 273 contents_.clear();
195 } 274 }
196 } 275 }
197 } 276 }
198 BrowserThread::PostTask( 277 BrowserThread::PostTask(
199 BrowserThread::UI, FROM_HERE, 278 BrowserThread::UI, FROM_HERE,
200 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); 279 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
201 } 280 }
202 281
282 void LoadEulaFileOnFileThread() {
283 std::string file_path =
284 base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str());
285 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) {
286 // No EULA for given language - try en-US as default.
287 file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US");
288 if (!file_util::ReadFileToString(base::FilePath(file_path),
289 &contents_)) {
290 // File with EULA not found, ResponseOnUIThread will load EULA from
291 // resources if contents_ is empty.
292 contents_.clear();
293 }
294 }
295 BrowserThread::PostTask(
296 BrowserThread::UI, FROM_HERE,
297 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
298 }
299
203 void ResponseOnUIThread() { 300 void ResponseOnUIThread() {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 // If we fail to load Chrome OS EULA from disk, load it from resources. 302 // If we fail to load Chrome OS EULA from disk, load it from resources.
206 // Do nothing if OEM EULA load failed. 303 // Do nothing if OEM EULA load failed.
207 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) 304 if (contents_.empty() && path_ != chrome::kOemEulaURLPath)
208 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); 305 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
209 callback_.Run(base::RefCountedString::TakeString(&contents_)); 306 callback_.Run(base::RefCountedString::TakeString(&contents_));
210 } 307 }
211 308
212 // Path in the URL. 309 // Path in the URL.
213 std::string path_; 310 const std::string path_;
214 311
215 // Callback to run with the response. 312 // Callback to run with the response.
216 content::URLDataSource::GotDataCallback callback_; 313 content::URLDataSource::GotDataCallback callback_;
217 314
218 // Locale of the EULA. 315 // Locale of the EULA.
219 std::string locale_; 316 const std::string locale_;
220 317
221 // EULA contents that was loaded from file. 318 // EULA contents that was loaded from file.
222 std::string contents_; 319 std::string contents_;
223 320
224 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); 321 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler);
225 }; 322 };
226 323
227 #endif 324 #endif
228 325
229 } // namespace 326 } // namespace
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 Profile* profile = Profile::FromWebUI(web_ui); 1164 Profile* profile = Profile::FromWebUI(web_ui);
1068 1165
1069 #if defined(ENABLE_THEMES) 1166 #if defined(ENABLE_THEMES)
1070 // Set up the chrome://theme/ source. 1167 // Set up the chrome://theme/ source.
1071 ThemeSource* theme = new ThemeSource(profile); 1168 ThemeSource* theme = new ThemeSource(profile);
1072 content::URLDataSource::Add(profile, theme); 1169 content::URLDataSource::Add(profile, theme);
1073 #endif 1170 #endif
1074 1171
1075 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); 1172 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile));
1076 } 1173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698