Commit f4107ff9 authored by garykac@google.com's avatar garykac@google.com

Add basic debug log to host page.

BUG=none
TEST=manual
Review URL: http://codereview.chromium.org/7108007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88409 0039d316-1c4b-4281-b951-d872f2087c98
parent 342508e4
...@@ -9,10 +9,12 @@ found in the LICENSE file. ...@@ -9,10 +9,12 @@ found in the LICENSE file.
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="shortcut icon" href="chromoting128.png" /> <link rel="shortcut icon" href="chromoting128.png" />
<link rel="stylesheet" href="debug_log.css" />
<link rel="stylesheet" href="main.css" /> <link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="choice.css" /> <link rel="stylesheet" href="choice.css" />
<script src="remoting.js"></script> <script src="debug_log.js"></script>
<script src="oauth2.js"></script> <script src="oauth2.js"></script>
<script src="remoting.js"></script>
<title>Chromoting</title> <title>Chromoting</title>
</head> </head>
...@@ -47,6 +49,13 @@ found in the LICENSE file. ...@@ -47,6 +49,13 @@ found in the LICENSE file.
</form> </form>
</span> <!-- email-entry --> </span> <!-- email-entry -->
<span id="debug-enable">
<form>
<input id="debug-log-toggle" class="display-inline" type="button"
value="Debug Log" onclick="toggleDebugLog(); return false;"/>
</form>
</span> <!-- debug-enable -->
</div> <!-- auth-panel --> </div> <!-- auth-panel -->
<div id="main-panel" class="hidden"> <div id="main-panel" class="hidden">
...@@ -194,5 +203,7 @@ found in the LICENSE file. ...@@ -194,5 +203,7 @@ found in the LICENSE file.
<div id="plugin-wrapper"> <div id="plugin-wrapper">
</div> </div>
<div id="debug-log">
</div>
</body> </body>
</html> </html>
/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#debug-log {
background-color: white;
bottom: 0;
border-top: 1px solid black;
display: none;
height: 150px;
margin: 0;
opacity: 0.85;
overflow: auto;
padding: 0;
position: fixed;
width: 100%;
z-index: 100;
-webkit-user-select: text;
}
#debug-log > p {
font-family: monospace;
font-weight: bold;
font-size: small;
margin: 0.35em;
padding: 0;
}
#debug-log-toggle {
float: right;
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Maximum numer of lines to record in the debug log.
// Only the most recent <n> lines are displayed.
var MAX_DEBUG_LOG_SIZE = 1000;
function toggleDebugLog() {
debugLog = document.getElementById('debug-log');
toggleButton = document.getElementById('debug-log-toggle');
if (!debugLog.style.display || debugLog.style.display == 'none') {
debugLog.style.display = 'block';
toggleButton.value = 'Hide Debug Log';
} else {
debugLog.style.display = 'none';
toggleButton.value = 'Show Debug Log';
}
}
/**
* Add the given message to the debug log.
*
* @param {string} message The debug info to add to the log.
*/
function addToDebugLog(message) {
var debugLog = document.getElementById('debug-log');
// Remove lines from top if we've hit our max log size.
if (debugLog.childNodes.length == MAX_DEBUG_LOG_SIZE) {
debugLog.removeChild(debugLog.firstChild);
}
// Add the new <p> to the end of the debug log.
var p = document.createElement('p');
p.appendChild(document.createTextNode(message));
debugLog.appendChild(p);
// Scroll to bottom of div
debugLog.scrollTop = debugLog.scrollHeight;
}
...@@ -169,20 +169,25 @@ function setGlobalModePersistent(mode) { ...@@ -169,20 +169,25 @@ function setGlobalModePersistent(mode) {
function setHostMode(mode) { function setHostMode(mode) {
var section = document.getElementById('host-section'); var section = document.getElementById('host-section');
var modes = section.getElementsByClassName('mode'); var modes = section.getElementsByClassName('mode');
addToDebugLog('Host mode: ' + mode);
setMode_(mode, modes); setMode_(mode, modes);
} }
function setClientMode(mode) { function setClientMode(mode) {
var section = document.getElementById('client-section'); var section = document.getElementById('client-section');
var modes = section.getElementsByClassName('mode'); var modes = section.getElementsByClassName('mode');
addToDebugLog('Client mode: ' + mode);
setMode_(mode, modes); setMode_(mode, modes);
} }
function tryShare() { function tryShare() {
addToDebugLog("Attempting to share...");
if (remoting.oauth2.needsNewAccessToken()) { if (remoting.oauth2.needsNewAccessToken()) {
addToDebugLog("Refreshing token...");
remoting.oauth2.refreshAccessToken(function() { remoting.oauth2.refreshAccessToken(function() {
if (remoting.oauth2.needsNewAccessToken()) { if (remoting.oauth2.needsNewAccessToken()) {
// If we still need it, we're going to infinite loop. // If we still need it, we're going to infinite loop.
addToDebugLog("Unable to get access token");
throw "Unable to get access token"; throw "Unable to get access token";
} }
tryShare(); tryShare();
...@@ -217,16 +222,18 @@ function onStateChanged_() { ...@@ -217,16 +222,18 @@ function onStateChanged_() {
setHostMode('unshared'); setHostMode('unshared');
plugin.parentNode.removeChild(plugin); plugin.parentNode.removeChild(plugin);
} else { } else {
window.alert('Unknown state -> ' + state); addToDebugLog('Unknown state -> ' + state);
} }
} }
function cancelShare() { function cancelShare() {
addToDebugLog('Canceling share...');
var plugin = document.getElementById(remoting.HOST_PLUGIN_ID); var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
plugin.disconnect(); plugin.disconnect();
} }
function startSession_() { function startSession_() {
addToDebugLog('Starting session...');
remoting.username = remoting.getItem(remoting.XMPP_LOGIN_NAME); remoting.username = remoting.getItem(remoting.XMPP_LOGIN_NAME);
document.location = 'remoting_session.html'; document.location = 'remoting_session.html';
} }
...@@ -289,7 +296,7 @@ function tryConnect() { ...@@ -289,7 +296,7 @@ function tryConnect() {
remoting.oauth2.refreshAccessToken(function() { remoting.oauth2.refreshAccessToken(function() {
if (remoting.oauth2.needsNewAccessToken()) { if (remoting.oauth2.needsNewAccessToken()) {
// If we still need it, we're going to infinite loop. // If we still need it, we're going to infinite loop.
throw "Unable to get access token"; throw "Unable to get access token.";
} }
tryConnect(); tryConnect();
}); });
......
...@@ -12,25 +12,6 @@ body { ...@@ -12,25 +12,6 @@ body {
} }
/* Ids */ /* Ids */
#debug-log {
background-color: white;
bottom: 0;
border-top: 1px solid black;
display: none;
font-family: monospace;
font-weight: bold;
font-size: small;
height: 150px;
margin: 0;
opacity: 0.85;
overflow: auto;
padding: 0;
position: fixed;
width: 100%;
z-index: 100;
-webkit-user-select: text;
}
#plugin-scroll-panel { #plugin-scroll-panel {
overflow: auto; overflow: auto;
width: 100%; width: 100%;
......
...@@ -9,8 +9,10 @@ found in the LICENSE file. ...@@ -9,8 +9,10 @@ found in the LICENSE file.
<head> <head>
<title>Chromoting Session</title> <title>Chromoting Session</title>
<link rel="shortcut icon" href="chromoting128.png" /> <link rel="shortcut icon" href="chromoting128.png" />
<link rel="stylesheet" href="debug_log.css" />
<link rel="stylesheet" href="main.css" /> <link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="remoting_session.css" /> <link rel="stylesheet" href="remoting_session.css" />
<script src="debug_log.js"></script>
<script src="oauth2.js"></script> <script src="oauth2.js"></script>
<script src="remoting_session.js"></script> <script src="remoting_session.js"></script>
</head> </head>
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +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.
// Maximum numer of lines to record in the debug log.
// Only the most recent <n> lines are displayed.
var MAX_DEBUG_LOG_SIZE = 1000;
var remoting = chrome.extension.getBackgroundPage().remoting; var remoting = chrome.extension.getBackgroundPage().remoting;
// Chromoting session API version (for this javascript). // Chromoting session API version (for this javascript).
...@@ -170,19 +166,6 @@ function init_() { ...@@ -170,19 +166,6 @@ function init_() {
} }
function toggleDebugLog() {
debugLog = document.getElementById('debug-log');
toggleButton = document.getElementById('debug-log-toggle');
if (!debugLog.style.display || debugLog.style.display == 'none') {
debugLog.style.display = 'block';
toggleButton.value = 'Hide Debug Log';
} else {
debugLog.style.display = 'none';
toggleButton.value = 'Show Debug Log';
}
}
function toggleScaleToFit() { function toggleScaleToFit() {
remoting.scaleToFit = !remoting.scaleToFit; remoting.scaleToFit = !remoting.scaleToFit;
document.getElementById('scale-to-fit-toggle').value = document.getElementById('scale-to-fit-toggle').value =
...@@ -313,28 +296,6 @@ function debugInfoCallback(msg) { ...@@ -313,28 +296,6 @@ function debugInfoCallback(msg) {
addToDebugLog('plugin: ' + msg); addToDebugLog('plugin: ' + msg);
} }
/**
* Add the given message to the debug log.
*
* @param {string} message The debug info to add to the log.
*/
function addToDebugLog(message) {
var debugLog = document.getElementById('debug-log');
// Remove lines from top if we've hit our max log size.
if (debugLog.childNodes.length == MAX_DEBUG_LOG_SIZE) {
debugLog.removeChild(debugLog.firstChild);
}
// Add the new <p> to the end of the debug log.
var p = document.createElement('p');
p.appendChild(document.createTextNode(message));
debugLog.appendChild(p);
// Scroll to bottom of div
debugLog.scrollTop = debugLog.scrollHeight;
}
function updateStatusBarStats() { function updateStatusBarStats() {
if (remoting.plugin.status != remoting.plugin.STATUS_CONNECTED) if (remoting.plugin.status != remoting.plugin.STATUS_CONNECTED)
return; return;
......
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