Commit ad4576ba authored by vasilii@chromium.org's avatar vasilii@chromium.org

CL modifies behavior of 'chrome://terms'.

It should show online policy on CrOS. In case of timeout (10 sec proposed by Nikita) the static version is shown. 
The real online resource isn't available at the moment.


BUG=174271
TBR=cpu@chromium.org

Review URL: https://chromiumcodereview.appspot.com/13820014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195152 0039d316-1c4b-4281-b951-d872f2087c98
parent 114d1b13
...@@ -1475,6 +1475,9 @@ Press any key to continue exploring. ...@@ -1475,6 +1475,9 @@ Press any key to continue exploring.
<message name="IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON" desc="Accept button text below EULA terms of service"> <message name="IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON" desc="Accept button text below EULA terms of service">
Accept and continue Accept and continue
</message> </message>
<message name="IDS_EULA_POLICY_URL" desc="Link to online ChromeOS Terms of Service">
https://www.google.com/intl/[GRITLANGCODE]/chromebook/tos_text.html
</message>
<message name="IDS_EULA_SYSTEM_SECURITY_SETTING" desc="Link from the EULA wizard screen and title of the TPM info dialog"> <message name="IDS_EULA_SYSTEM_SECURITY_SETTING" desc="Link from the EULA wizard screen and title of the TPM info dialog">
System security setting System security setting
</message> </message>
......
...@@ -810,6 +810,23 @@ html[dir=rtl] .step-extra-controls { ...@@ -810,6 +810,23 @@ html[dir=rtl] .step-extra-controls {
height: 222px; height: 222px;
} }
#cros-eula-loading {
-webkit-align-items: center;
-webkit-flex-direction: column;
-webkit-justify-content: center;
display: none;
height: 100%;
width: 100%;
}
.step.eula-loading #cros-eula-frame {
display: none;
}
.step.eula-loading #cros-eula-loading {
display: -webkit-flex;
}
#cros-eula { #cros-eula {
width: 314px; width: 314px;
} }
......
<div class="step right hidden animated" id="eula"> <div class="step right hidden animated eula-loading" id="eula">
<div class="step-contents"> <div class="step-contents">
<div id="eulas" class="eula-columns one-column"> <div id="eulas" class="eula-columns one-column">
<div id="cros-eula"> <div id="cros-eula">
<iframe id="cros-eula-frame" class="eula-frame" <iframe id="cros-eula-frame" class="eula-frame"
src="chrome://terms"></iframe> src="about:blank"></iframe>
<div id="cros-eula-loading">
<div>
<p i18n-content="termsOfServiceLoading"></p>
</div>
</div>
</div> </div>
<div id="oem-eula"> <div id="oem-eula">
<iframe id="oem-eula-frame" class="eula-frame"></iframe> <iframe id="oem-eula-frame" class="eula-frame"></iframe>
......
...@@ -52,6 +52,19 @@ cr.define('oobe', function() { ...@@ -52,6 +52,19 @@ cr.define('oobe', function() {
}); });
}, },
/**
* Event handler that is invoked just before the screen is shown.
* @param {object} data Screen init payload.
*/
onBeforeShow: function() {
$('eula').classList.add('eula-loading');
$('cros-eula-frame').onload = function() {
$('accept-button').disabled = false;
$('eula').classList.remove('eula-loading');
}
$('cros-eula-frame').src = 'chrome://terms';
},
/** /**
* Header text of the screen. * Header text of the screen.
* @type {string} * @type {string}
...@@ -78,6 +91,8 @@ cr.define('oobe', function() { ...@@ -78,6 +91,8 @@ cr.define('oobe', function() {
var acceptButton = this.ownerDocument.createElement('button'); var acceptButton = this.ownerDocument.createElement('button');
acceptButton.id = 'accept-button'; acceptButton.id = 'accept-button';
acceptButton.disabled = true;
acceptButton.classList.add('preserve-disabled-state');
acceptButton.textContent = loadTimeData.getString('acceptAgreement'); acceptButton.textContent = loadTimeData.getString('acceptAgreement');
acceptButton.addEventListener('click', function(e) { acceptButton.addEventListener('click', function(e) {
$('eula').classList.add('loading'); // Mark EULA screen busy. $('eula').classList.add('loading'); // Mark EULA screen busy.
......
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
#include "grit/locale_settings.h" #include "grit/locale_settings.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/webui/jstemplate_builder.h" #include "ui/webui/jstemplate_builder.h"
...@@ -96,6 +99,8 @@ const char kMemoryJsPath[] = "memory.js"; ...@@ -96,6 +99,8 @@ const char kMemoryJsPath[] = "memory.js";
const char kMemoryCssPath[] = "about_memory.css"; const char kMemoryCssPath[] = "about_memory.css";
const char kStatsJsPath[] = "stats.js"; const char kStatsJsPath[] = "stats.js";
const char kStringsJsPath[] = "strings.js"; const char kStringsJsPath[] = "strings.js";
// chrome://terms falls back to offline page after kOnlineTermsTimeoutSec.
const int kOnlineTermsTimeoutSec = 10;
// When you type about:memory, it actually loads this intermediate URL that // When you type about:memory, it actually loads this intermediate URL that
// redirects you to the final page. This avoids the problem where typing // redirects you to the final page. This avoids the problem where typing
...@@ -137,6 +142,75 @@ class AboutMemoryHandler : public MemoryDetails { ...@@ -137,6 +142,75 @@ class AboutMemoryHandler : public MemoryDetails {
}; };
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Helper class that fetches the online Chrome OS terms. Empty string is
// returned once fetching failed or exceeded |kOnlineTermsTimeoutSec|.
class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate {
public:
typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback;
explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback)
: fetch_callback_(callback) {
eula_fetcher_.reset(net::URLFetcher::Create(
GURL(l10n_util::GetStringUTF16(IDS_EULA_POLICY_URL)),
net::URLFetcher::GET,
this));
eula_fetcher_->SetRequestContext(
g_browser_process->system_request_context());
eula_fetcher_->AddExtraRequestHeader("Accept: text/html");
eula_fetcher_->Start();
// Abort the download attempt if it takes longer than one minute.
download_timer_.Start(FROM_HERE,
base::TimeDelta::FromSeconds(kOnlineTermsTimeoutSec),
this,
&ChromeOSOnlineTermsHandler::OnDownloadTimeout);
}
void GetResponseResult(std::string* response_string) {
std::string mime_type;
if (!eula_fetcher_ ||
!eula_fetcher_->GetStatus().is_success() ||
eula_fetcher_->GetResponseCode() != 200 ||
!eula_fetcher_->GetResponseHeaders()->GetMimeType(&mime_type) ||
mime_type != "text/html" ||
!eula_fetcher_->GetResponseAsString(response_string)) {
response_string->clear();
}
}
private:
// Prevents allocation on the stack. ChromeOSOnlineTermsHandler should be
// created by 'operator new'. |this| takes care of destruction.
virtual ~ChromeOSOnlineTermsHandler() {}
// net::URLFetcherDelegate:
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
if (source != eula_fetcher_.get()) {
NOTREACHED() << "Callback from foreign URL fetcher";
return;
}
fetch_callback_.Run(this);
delete this;
}
void OnDownloadTimeout() {
eula_fetcher_.reset();
fetch_callback_.Run(this);
delete this;
}
// Timer that enforces a timeout on the attempt to download the
// ChromeOS Terms.
base::OneShotTimer<ChromeOSOnlineTermsHandler> download_timer_;
// |fetch_callback_| called when fetching succeeded or failed.
FetchCallback fetch_callback_;
// Helper to fetch online eula.
scoped_ptr<net::URLFetcher> eula_fetcher_;
DISALLOW_COPY_AND_ASSIGN(ChromeOSOnlineTermsHandler);
};
class ChromeOSTermsHandler class ChromeOSTermsHandler
: public base::RefCountedThreadSafe<ChromeOSTermsHandler> { : public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
public: public:
...@@ -158,39 +232,45 @@ class ChromeOSTermsHandler ...@@ -158,39 +232,45 @@ class ChromeOSTermsHandler
locale_(g_browser_process->GetApplicationLocale()) { locale_(g_browser_process->GetApplicationLocale()) {
} }
~ChromeOSTermsHandler() {} virtual ~ChromeOSTermsHandler() {}
void StartOnUIThread() { void StartOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask( if (path_ == chrome::kOemEulaURLPath) {
BrowserThread::FILE, FROM_HERE, // Load local OEM EULA from the disk.
base::Bind(&ChromeOSTermsHandler::LoadFileOnFileThread, this)); BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&ChromeOSTermsHandler::LoadOemEulaFileOnFileThread, this));
} else {
// Try to load online version of ChromeOS terms first.
// ChromeOSOnlineTermsHandler object destroys itself.
new ChromeOSOnlineTermsHandler(
base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this));
}
} }
void LoadFileOnFileThread() { void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (path_ == chrome::kOemEulaURLPath) { loader->GetResponseResult(&contents_);
const chromeos::StartupCustomizationDocument* customization = if (contents_.empty()) {
chromeos::StartupCustomizationDocument::GetInstance(); // Load local ChromeOS terms from the file.
if (customization->IsReady()) { BrowserThread::PostTask(
base::FilePath oem_eula_file_path; BrowserThread::FILE, FROM_HERE,
if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this));
&oem_eula_file_path)) {
if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) {
contents_.clear();
}
}
}
} else { } else {
std::string file_path = ResponseOnUIThread();
base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str()); }
if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) { }
// No EULA for given language - try en-US as default.
file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US"); void LoadOemEulaFileOnFileThread() {
if (!file_util::ReadFileToString(base::FilePath(file_path), DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
&contents_)) { const chromeos::StartupCustomizationDocument* customization =
// File with EULA not found, ResponseOnUIThread will load EULA from chromeos::StartupCustomizationDocument::GetInstance();
// resources if contents_ is empty. if (customization->IsReady()) {
base::FilePath oem_eula_file_path;
if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)),
&oem_eula_file_path)) {
if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) {
contents_.clear(); contents_.clear();
} }
} }
...@@ -200,6 +280,24 @@ class ChromeOSTermsHandler ...@@ -200,6 +280,24 @@ class ChromeOSTermsHandler
base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
} }
void LoadEulaFileOnFileThread() {
std::string file_path =
base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str());
if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) {
// No EULA for given language - try en-US as default.
file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US");
if (!file_util::ReadFileToString(base::FilePath(file_path),
&contents_)) {
// File with EULA not found, ResponseOnUIThread will load EULA from
// resources if contents_ is empty.
contents_.clear();
}
}
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
}
void ResponseOnUIThread() { void ResponseOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// If we fail to load Chrome OS EULA from disk, load it from resources. // If we fail to load Chrome OS EULA from disk, load it from resources.
...@@ -210,13 +308,13 @@ class ChromeOSTermsHandler ...@@ -210,13 +308,13 @@ class ChromeOSTermsHandler
} }
// Path in the URL. // Path in the URL.
std::string path_; const std::string path_;
// Callback to run with the response. // Callback to run with the response.
content::URLDataSource::GotDataCallback callback_; content::URLDataSource::GotDataCallback callback_;
// Locale of the EULA. // Locale of the EULA.
std::string locale_; const std::string locale_;
// EULA contents that was loaded from file. // EULA contents that was loaded from file.
std::string contents_; std::string contents_;
......
...@@ -59,6 +59,7 @@ void EulaScreenHandler::DeclareLocalizedValues( ...@@ -59,6 +59,7 @@ void EulaScreenHandler::DeclareLocalizedValues(
builder->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH); builder->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH);
builder->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY); builder->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY);
builder->Add("eulaSystemInstallationSettingsOkButton", IDS_OK); builder->Add("eulaSystemInstallationSettingsOkButton", IDS_OK);
builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING);
#if defined(ENABLE_RLZ) #if defined(ENABLE_RLZ)
builder->AddF("eulaRlzDesc", builder->AddF("eulaRlzDesc",
IDS_EULA_RLZ_DESCRIPTION, IDS_EULA_RLZ_DESCRIPTION,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment