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.
<message name="IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON" desc="Accept button text below EULA terms of service">
Accept and continue
</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">
System security setting
</message>
......
......@@ -810,6 +810,23 @@ html[dir=rtl] .step-extra-controls {
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 {
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 id="eulas" class="eula-columns one-column">
<div id="cros-eula">
<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 id="oem-eula">
<iframe id="oem-eula-frame" class="eula-frame"></iframe>
......
......@@ -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.
* @type {string}
......@@ -78,6 +91,8 @@ cr.define('oobe', function() {
var acceptButton = this.ownerDocument.createElement('button');
acceptButton.id = 'accept-button';
acceptButton.disabled = true;
acceptButton.classList.add('preserve-disabled-state');
acceptButton.textContent = loadTimeData.getString('acceptAgreement');
acceptButton.addEventListener('click', function(e) {
$('eula').classList.add('loading'); // Mark EULA screen busy.
......
......@@ -55,6 +55,9 @@
#include "grit/locale_settings.h"
#include "net/base/escape.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/resource/resource_bundle.h"
#include "ui/webui/jstemplate_builder.h"
......@@ -96,6 +99,8 @@ const char kMemoryJsPath[] = "memory.js";
const char kMemoryCssPath[] = "about_memory.css";
const char kStatsJsPath[] = "stats.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
// redirects you to the final page. This avoids the problem where typing
......@@ -137,6 +142,75 @@ class AboutMemoryHandler : public MemoryDetails {
};
#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
: public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
public:
......@@ -158,18 +232,38 @@ class ChromeOSTermsHandler
locale_(g_browser_process->GetApplicationLocale()) {
}
~ChromeOSTermsHandler() {}
virtual ~ChromeOSTermsHandler() {}
void StartOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (path_ == chrome::kOemEulaURLPath) {
// Load local OEM EULA from the disk.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&ChromeOSTermsHandler::LoadFileOnFileThread, this));
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 OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
loader->GetResponseResult(&contents_);
if (contents_.empty()) {
// Load local ChromeOS terms from the file.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this));
} else {
ResponseOnUIThread();
}
}
void LoadFileOnFileThread() {
void LoadOemEulaFileOnFileThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
if (path_ == chrome::kOemEulaURLPath) {
const chromeos::StartupCustomizationDocument* customization =
chromeos::StartupCustomizationDocument::GetInstance();
if (customization->IsReady()) {
......@@ -181,7 +275,12 @@ class ChromeOSTermsHandler
}
}
}
} else {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
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_)) {
......@@ -194,7 +293,6 @@ class ChromeOSTermsHandler
contents_.clear();
}
}
}
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this));
......@@ -210,13 +308,13 @@ class ChromeOSTermsHandler
}
// Path in the URL.
std::string path_;
const std::string path_;
// Callback to run with the response.
content::URLDataSource::GotDataCallback callback_;
// Locale of the EULA.
std::string locale_;
const std::string locale_;
// EULA contents that was loaded from file.
std::string contents_;
......
......@@ -59,6 +59,7 @@ void EulaScreenHandler::DeclareLocalizedValues(
builder->Add("eulaTpmDescPowerwash", IDS_EULA_TPM_KEY_DESCRIPTION_POWERWASH);
builder->Add("eulaTpmBusy", IDS_EULA_TPM_BUSY);
builder->Add("eulaSystemInstallationSettingsOkButton", IDS_OK);
builder->Add("termsOfServiceLoading", IDS_TERMS_OF_SERVICE_SCREEN_LOADING);
#if defined(ENABLE_RLZ)
builder->AddF("eulaRlzDesc",
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