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

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: Set the final URL 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. Empty string is
146 // returned once fetching failed or exceeded |kOnlineTermsTimeoutSec|.
147 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate {
148 public:
149 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback;
150
151 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback)
152 : fetch_callback_(callback) {
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");
battre 2013/04/22 08:13:20 Can you please add eula_fetcher_->SetLoadFlags(
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_->GetResponseCode() != 200 ||
173 !eula_fetcher_->GetResponseHeaders()->GetMimeType(&mime_type) ||
174 mime_type != "text/html" ||
175 !eula_fetcher_->GetResponseAsString(response_string)) {
176 response_string->clear();
177 }
178 }
179
180 private:
181 // Prevents allocation on the stack. ChromeOSOnlineTermsHandler should be
182 // created by 'operator new'. |this| takes care of destruction.
183 virtual ~ChromeOSOnlineTermsHandler() {}
184
185 // net::URLFetcherDelegate:
186 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
187 if (source != eula_fetcher_.get()) {
188 NOTREACHED() << "Callback from foreign URL fetcher";
189 return;
190 }
191 fetch_callback_.Run(this);
192 delete this;
193 }
194
195 void OnDownloadTimeout() {
196 eula_fetcher_.reset();
197 fetch_callback_.Run(this);
198 delete this;
199 }
200
201 // Timer that enforces a timeout on the attempt to download the
202 // ChromeOS Terms.
203 base::OneShotTimer<ChromeOSOnlineTermsHandler> download_timer_;
204
205 // |fetch_callback_| called when fetching succeeded or failed.
206 FetchCallback fetch_callback_;
207
208 // Helper to fetch online eula.
209 scoped_ptr<net::URLFetcher> eula_fetcher_;
210
211 DISALLOW_COPY_AND_ASSIGN(ChromeOSOnlineTermsHandler);
212 };
213
140 class ChromeOSTermsHandler 214 class ChromeOSTermsHandler
141 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { 215 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
142 public: 216 public:
143 static void Start(const std::string& path, 217 static void Start(const std::string& path,
144 const content::URLDataSource::GotDataCallback& callback) { 218 const content::URLDataSource::GotDataCallback& callback) {
145 scoped_refptr<ChromeOSTermsHandler> handler( 219 scoped_refptr<ChromeOSTermsHandler> handler(
146 new ChromeOSTermsHandler(path, callback)); 220 new ChromeOSTermsHandler(path, callback));
147 handler->StartOnUIThread(); 221 handler->StartOnUIThread();
148 } 222 }
149 223
150 private: 224 private:
151 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; 225 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>;
152 226
153 ChromeOSTermsHandler(const std::string& path, 227 ChromeOSTermsHandler(const std::string& path,
154 const content::URLDataSource::GotDataCallback& callback) 228 const content::URLDataSource::GotDataCallback& callback)
155 : path_(path), 229 : path_(path),
156 callback_(callback), 230 callback_(callback),
157 // Previously we were using "initial locale" http://crbug.com/145142 231 // Previously we were using "initial locale" http://crbug.com/145142
158 locale_(g_browser_process->GetApplicationLocale()) { 232 locale_(g_browser_process->GetApplicationLocale()) {
159 } 233 }
160 234
161 ~ChromeOSTermsHandler() {} 235 virtual ~ChromeOSTermsHandler() {}
162 236
163 void StartOnUIThread() { 237 void StartOnUIThread() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165 BrowserThread::PostTask( 239 if (path_ == chrome::kOemEulaURLPath) {
166 BrowserThread::FILE, FROM_HERE, 240 // Load local OEM EULA from the disk.
167 base::Bind(&ChromeOSTermsHandler::LoadFileOnFileThread, this)); 241 BrowserThread::PostTask(
242 BrowserThread::FILE, FROM_HERE,
243 base::Bind(&ChromeOSTermsHandler::LoadOemEulaFileOnFileThread, this));
244 } else {
245 // Try to load online version of ChromeOS terms first.
246 // ChromeOSOnlineTermsHandler object destroys itself.
247 new ChromeOSOnlineTermsHandler(
248 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this));
249 }
168 } 250 }
169 251
170 void LoadFileOnFileThread() { 252 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) {
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
254 loader->GetResponseResult(&contents_);
255 if (contents_.empty()) {
256 // Load local ChromeOS terms from the file.
257 BrowserThread::PostTask(
258 BrowserThread::FILE, FROM_HERE,
259 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this));
260 } else {
261 ResponseOnUIThread();
262 }
263 }
264
265 void LoadOemEulaFileOnFileThread() {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
172 if (path_ == chrome::kOemEulaURLPath) { 267 const chromeos::StartupCustomizationDocument* customization =
173 const chromeos::StartupCustomizationDocument* customization = 268 chromeos::StartupCustomizationDocument::GetInstance();
174 chromeos::StartupCustomizationDocument::GetInstance(); 269 if (customization->IsReady()) {
175 if (customization->IsReady()) { 270 base::FilePath oem_eula_file_path;
176 base::FilePath oem_eula_file_path; 271 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)),
177 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), 272 &oem_eula_file_path)) {
178 &oem_eula_file_path)) { 273 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(); 274 contents_.clear();
195 } 275 }
196 } 276 }
197 } 277 }
198 BrowserThread::PostTask( 278 BrowserThread::PostTask(
199 BrowserThread::UI, FROM_HERE, 279 BrowserThread::UI, FROM_HERE,
200 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); 280 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
201 } 281 }
202 282
283 void LoadEulaFileOnFileThread() {
284 std::string file_path =
285 base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str());
286 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) {
287 // No EULA for given language - try en-US as default.
288 file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US");
289 if (!file_util::ReadFileToString(base::FilePath(file_path),
290 &contents_)) {
291 // File with EULA not found, ResponseOnUIThread will load EULA from
292 // resources if contents_ is empty.
293 contents_.clear();
294 }
295 }
296 BrowserThread::PostTask(
297 BrowserThread::UI, FROM_HERE,
298 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
299 }
300
203 void ResponseOnUIThread() { 301 void ResponseOnUIThread() {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 // If we fail to load Chrome OS EULA from disk, load it from resources. 303 // If we fail to load Chrome OS EULA from disk, load it from resources.
206 // Do nothing if OEM EULA load failed. 304 // Do nothing if OEM EULA load failed.
207 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) 305 if (contents_.empty() && path_ != chrome::kOemEulaURLPath)
208 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); 306 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
209 callback_.Run(base::RefCountedString::TakeString(&contents_)); 307 callback_.Run(base::RefCountedString::TakeString(&contents_));
210 } 308 }
211 309
212 // Path in the URL. 310 // Path in the URL.
213 std::string path_; 311 const std::string path_;
214 312
215 // Callback to run with the response. 313 // Callback to run with the response.
216 content::URLDataSource::GotDataCallback callback_; 314 content::URLDataSource::GotDataCallback callback_;
217 315
218 // Locale of the EULA. 316 // Locale of the EULA.
219 std::string locale_; 317 const std::string locale_;
220 318
221 // EULA contents that was loaded from file. 319 // EULA contents that was loaded from file.
222 std::string contents_; 320 std::string contents_;
223 321
224 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); 322 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler);
225 }; 323 };
226 324
227 #endif 325 #endif
228 326
229 } // namespace 327 } // namespace
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 Profile* profile = Profile::FromWebUI(web_ui); 1165 Profile* profile = Profile::FromWebUI(web_ui);
1068 1166
1069 #if defined(ENABLE_THEMES) 1167 #if defined(ENABLE_THEMES)
1070 // Set up the chrome://theme/ source. 1168 // Set up the chrome://theme/ source.
1071 ThemeSource* theme = new ThemeSource(profile); 1169 ThemeSource* theme = new ThemeSource(profile);
1072 content::URLDataSource::Add(profile, theme); 1170 content::URLDataSource::Add(profile, theme);
1073 #endif 1171 #endif
1074 1172
1075 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); 1173 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile));
1076 } 1174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698