Commit 01f3c26a authored by John Lee's avatar John Lee Committed by Commit Bot

WebUI: Remove usage of CallJavaScriptFunctionUnsafe from chrome://nacl

Bug: None
Change-Id: I86da18034e0664780e24559868357c0d0df0ef4c
Reviewed-on: https://chromium-review.googlesource.com/c/1423698Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: John Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625833}
parent 584fa82c
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
</span> </span>
</div> </div>
</div> </div>
<script src="chrome://resources/js/promise_resolver.js"></script>
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/js/load_time_data.js"></script> <script src="chrome://resources/js/load_time_data.js"></script>
<script src="chrome://nacl/about_nacl.js"></script> <script src="chrome://nacl/about_nacl.js"></script>
<script src="chrome://nacl/strings.js"></script> <script src="chrome://nacl/strings.js"></script>
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
const nacl = {};
(function() { (function() {
/** /**
* Takes the |moduleListData| input argument which represents data about * Takes the |moduleListData| input argument which represents data about
...@@ -19,24 +17,18 @@ function renderTemplate(moduleListData) { ...@@ -19,24 +17,18 @@ function renderTemplate(moduleListData) {
} }
/** /**
* Asks the C++ NaClUIDOMHandler to get details about the NaCl and return * Asks the C++ NaClUIDOMHandler to get details about the NaCl and
* the data in returnNaClInfo() (below). * re-populates the page with the data.
*/ */
function requestNaClInfo() { function requestNaClInfo() {
chrome.send('requestNaClInfo'); cr.sendWithPromise('requestNaClInfo').then((moduleListData) => {
$('loading-message').hidden = 'hidden';
$('body-container').hidden = '';
renderTemplate(moduleListData);
});
} }
/**
* Called by the WebUI to re-populate the page with data representing the
* current state of NaCl.
* @param {Object} moduleListData Information about available modules
*/
nacl.returnNaClInfo = function(moduleListData) {
$('loading-message').hidden = 'hidden';
$('body-container').hidden = '';
renderTemplate(moduleListData);
};
// Get data and have it displayed upon loading. // Get data and have it displayed upon loading.
document.addEventListener('DOMContentLoaded', requestNaClInfo); document.addEventListener('DOMContentLoaded', requestNaClInfo);
})(); })();
...@@ -120,8 +120,8 @@ class NaClDomHandler : public WebUIMessageHandler { ...@@ -120,8 +120,8 @@ class NaClDomHandler : public WebUIMessageHandler {
// Adds the information relevant to NaCl to list. // Adds the information relevant to NaCl to list.
void AddNaClInfo(base::ListValue* list); void AddNaClInfo(base::ListValue* list);
// Whether the page has requested data. // The callback ID for requested data.
bool page_has_requested_data_; std::string callback_id_;
// Whether the plugin information is ready. // Whether the plugin information is ready.
bool has_plugin_info_; bool has_plugin_info_;
...@@ -139,8 +139,7 @@ class NaClDomHandler : public WebUIMessageHandler { ...@@ -139,8 +139,7 @@ class NaClDomHandler : public WebUIMessageHandler {
}; };
NaClDomHandler::NaClDomHandler() NaClDomHandler::NaClDomHandler()
: page_has_requested_data_(false), : has_plugin_info_(false),
has_plugin_info_(false),
pnacl_path_validated_(false), pnacl_path_validated_(false),
pnacl_path_exists_(false), pnacl_path_exists_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
...@@ -282,11 +281,15 @@ void NaClDomHandler::AddNaClInfo(base::ListValue* list) { ...@@ -282,11 +281,15 @@ void NaClDomHandler::AddNaClInfo(base::ListValue* list) {
} }
void NaClDomHandler::HandleRequestNaClInfo(const base::ListValue* args) { void NaClDomHandler::HandleRequestNaClInfo(const base::ListValue* args) {
page_has_requested_data_ = true; CHECK(callback_id_.empty());
CHECK_EQ(1U, args->GetSize());
callback_id_ = args->GetList()[0].GetString();
// Force re-validation of PNaCl's path in the next call to // Force re-validation of PNaCl's path in the next call to
// MaybeRespondToPage(), in case PNaCl went from not-installed // MaybeRespondToPage(), in case PNaCl went from not-installed
// to installed since the request. // to installed since the request.
pnacl_path_validated_ = false; pnacl_path_validated_ = false;
AllowJavascript();
MaybeRespondToPage(); MaybeRespondToPage();
} }
...@@ -349,7 +352,7 @@ bool CheckPathAndVersion(std::string* version) { ...@@ -349,7 +352,7 @@ bool CheckPathAndVersion(std::string* version) {
void NaClDomHandler::MaybeRespondToPage() { void NaClDomHandler::MaybeRespondToPage() {
// Don't reply until everything is ready. The page will show a 'loading' // Don't reply until everything is ready. The page will show a 'loading'
// message until then. // message until then.
if (!page_has_requested_data_ || !has_plugin_info_) if (callback_id_.empty() || !has_plugin_info_)
return; return;
if (!pnacl_path_validated_) { if (!pnacl_path_validated_) {
...@@ -365,7 +368,8 @@ void NaClDomHandler::MaybeRespondToPage() { ...@@ -365,7 +368,8 @@ void NaClDomHandler::MaybeRespondToPage() {
base::DictionaryValue naclInfo; base::DictionaryValue naclInfo;
PopulatePageInformation(&naclInfo); PopulatePageInformation(&naclInfo);
web_ui()->CallJavascriptFunctionUnsafe("nacl.returnNaClInfo", naclInfo); ResolveJavascriptCallback(base::Value(callback_id_), naclInfo);
callback_id_.clear();
} }
} // namespace } // namespace
......
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