Commit 6623b64b authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Add authentication status section to chrome:drive-internals

BUG=135328
TEST=auth status is shown in chrome:drive-internals properly

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148544 0039d316-1c4b-4281-b951-d872f2087c98
parent b61a1c1d
......@@ -3,9 +3,17 @@
<head>
<title>drive-internals</title>
<meta charset="utf-8">
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://drive-internals/drive_internals.js"></script>
</head>
<body>
To be implemented. crbug.com/135328
<h1>Drive Internals</h1>
<h2>Authentication Status</h2>
<table>
<tbody>
<tr><td>Has refresh token</td><td id='has-refresh-token'></td></tr>
<tr><td>Has access token</td><td id='has-access-token'></td></tr>
</tbody>
</table>
</body>
</html>
......@@ -2,4 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// To be implemented. crbug.com/135328
/**
* Updates the Authentication Status section.
* @param {Object} auth_status Dictionary containing auth status.
*/
function UpdateAuthStatus(auth_status) {
$('has-refresh-token').textContent = auth_status['has-refresh-token'];
$('has-access-token').textContent = auth_status['has-access-token'];
}
document.addEventListener('DOMContentLoaded', function() {
chrome.send('pageLoaded');
});
......@@ -4,16 +4,73 @@
#include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/gdata/gdata_auth_service.h"
#include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
namespace chromeos {
namespace {
// Class to handle messages from chrome://drive-internals.
class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
public:
DriveInternalsWebUIHandler()
: weak_ptr_factory_(this) {
}
virtual ~DriveInternalsWebUIHandler() {
}
private:
// WebUIMessageHandler override.
virtual void RegisterMessages() OVERRIDE {
web_ui()->RegisterMessageCallback(
"pageLoaded",
base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded,
weak_ptr_factory_.GetWeakPtr()));
}
// Called when the page is first loaded.
void OnPageLoaded(const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui());
gdata::GDataSystemService* system_service =
gdata::GDataSystemServiceFactory::GetForProfile(profile);
// |system_service| may be NULL in the guest/incognito mode.
if (!system_service)
return;
gdata::DocumentsServiceInterface* documents_service =
system_service->docs_service();
DCHECK(documents_service);
// Update the auth status section.
base::DictionaryValue auth_status;
auth_status.SetBoolean("has-refresh-token",
documents_service->HasRefreshToken());
auth_status.SetBoolean("has-access-token",
documents_service->HasAccessToken());
web_ui()->CallJavascriptFunction("UpdateAuthStatus", auth_status);
}
base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
};
} // namespace
DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
web_ui->AddMessageHandler(new DriveInternalsWebUIHandler());
ChromeWebUIDataSource* source =
new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
......
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