Skip to content

Commit

Permalink
Added chrome://translate-internals. For now, this shows only the pref…
Browse files Browse the repository at this point in the history
…erences concerned with the translation.

BUG=175967

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195745 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hajimehoshi@chromium.org committed Apr 23, 2013
1 parent 78a158b commit 147408a
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 2 deletions.
1 change: 1 addition & 0 deletions chrome/browser/browser_about_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const char* const kPaths[] = {
chrome::kChromeUIStatsHost,
chrome::kChromeUISyncInternalsHost,
chrome::kChromeUITermsHost,
chrome::kChromeUITranslateInternalsHost,
chrome::kChromeUIUserActionsHost,
chrome::kChromeUIVersionHost,
#if defined(OS_ANDROID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Copyright 2013 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. */

#tabpanel-prefs p {
font-family: monospace;
text-wrap: unrestricted;
white-space: pre-wrap;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html i18n-values="dir:textdirection">
<!--
Copyright 2013 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.
-->
<head>
<meta charset="utf-8">
<title>Translate Internals</title>
<link rel="stylesheet" href="chrome://resources/css/tabs.css">
<link rel="stylesheet" href="./translate_internals.css">
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/js/i18n_template.js"></script>
<script src="chrome://resources/js/cr/event_target.js"></script>
<script src="chrome://resources/js/cr/ui.js"></script>
<script src="chrome://resources/js/cr/ui/tabs.js"></script>
<script src="chrome://resources/js/cr/ui/focus_outline_manager.js"></script>
<script src="./translate_internals.js"></script>
</head>

<body>

<tabbox>
<tabs>
<tab>Prefs</tab>
</tabs>
<tabpanels>

<tabpanel id="tabpanel-prefs">
<h2>Prefs</h2>
<p></p>
</tabpanel>

</tabpanels>
</tabbox>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2013 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.

(function() {
'use strict';

cr.define('cr.translateInternals', function() {

/**
* Initializes UI and sends a message to the browser for
* initialization.
*/
function initialize() {
cr.ui.decorate('tabbox', cr.ui.TabBox);
chrome.send('requestInfo');
}

/**
* Handles the message of 'prefsUpdated' from the browser.
* @param {Object} detail The object which represents pref values.
*/
function onPrefsUpdated(detail) {
var p = $('tabpanel-prefs').querySelector('p');
var content = JSON.stringify(detail, null, 2);
p.textContent = content;
}

/**
* The callback entry point from the browser. This function will be
* called by the browser.
* @param {string} message The name of the sent message
* @param {Object} detail The argument of the sent message
*/
function messageHandler(message, detail) {
switch (message) {
case 'prefsUpdated':
cr.translateInternals.onPrefsUpdated(detail);
break;
default:
console.error('Unknown message:', message);
break;
}
}

return {
initialize: initialize,
messageHandler: messageHandler,
onPrefsUpdated: onPrefsUpdated
};
});

/**
* The entry point of the UI.
*/
function main() {
cr.doc.addEventListener('DOMContentLoaded',
cr.translateInternals.initialize);
}

main();
})();
17 changes: 17 additions & 0 deletions chrome/browser/resources/translate_internals_resources.grd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/translate_internals_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/translate_internals_resources_map.cc" type="resource_file_map_source" />
<output filename="grit/translate_internals_resources_map.h" type="resource_map_header" />
<output filename="translate_internals_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<include name="IDR_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_HTML" file="translate_internals/translate_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_JS" file="translate_internals/translate_internals.js" type="BINDATA" />
</includes>
</release>
</grit>
2 changes: 1 addition & 1 deletion chrome/browser/translate/translate_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void TranslatePrefs::ClearBlacklistedLanguages() {
prefs_->ClearPref(kPrefTranslateLanguageBlacklist);
}

bool TranslatePrefs::HasBlacklistedSites() {
bool TranslatePrefs::HasBlacklistedSites() const {
return !IsListEmpty(kPrefTranslateSiteBlacklist);
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/translate/translate_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TranslatePrefs {
void ClearBlacklistedLanguages();

// Will return true if at least one site has been blacklisted.
bool HasBlacklistedSites();
bool HasBlacklistedSites() const;
void ClearBlacklistedSites();

// These methods are used to track how many times the user has denied the
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "chrome/browser/ui/webui/signin/profile_signin_confirmation_ui.h"
#include "chrome/browser/ui/webui/signin_internals_ui.h"
#include "chrome/browser/ui/webui/sync_internals_ui.h"
#include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"
#include "chrome/browser/ui/webui/user_actions/user_actions_ui.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/common/chrome_switches.h"
Expand Down Expand Up @@ -241,6 +242,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<SyncInternalsUI>;
if (url.host() == chrome::kChromeUISyncResourcesHost)
return &NewWebUI<WebDialogUI>;
if (url.host() == chrome::kChromeUITranslateInternalsHost)
return &NewWebUI<TranslateInternalsUI>;
if (url.host() == chrome::kChromeUIUserActionsHost)
return &NewWebUI<UserActionsUI>;
if (url.host() == chrome::kChromeUIVersionHost)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2013 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.

#include "chrome/browser/ui/webui/translate_internals/translate_internals_handler.h"

#include <map>
#include <string>
#include <vector>

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/prefs/pref_service.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/translate/translate_prefs.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"

void TranslateInternalsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("requestInfo", base::Bind(
&TranslateInternalsHandler::OnRequestInfo, base::Unretained(this)));
}

void TranslateInternalsHandler::OnRequestInfo(const base::ListValue* /*args*/) {
content::WebContents* web_contents = web_ui()->GetWebContents();
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
PrefService* prefs = profile->GetOriginalProfile()->GetPrefs();

base::DictionaryValue dict;

static const char* keys[] = {
prefs::kEnableTranslate,
TranslatePrefs::kPrefTranslateLanguageBlacklist,
TranslatePrefs::kPrefTranslateSiteBlacklist,
TranslatePrefs::kPrefTranslateWhitelists,
TranslatePrefs::kPrefTranslateDeniedCount,
TranslatePrefs::kPrefTranslateAcceptedCount,
};

for (size_t i = 0; i < arraysize(keys); ++i) {
const char* key = keys[i];
const PrefService::Preference* pref = prefs->FindPreference(key);
if (pref)
dict.Set(key, pref->GetValue()->DeepCopy());
}

SendMessageToJs("prefsUpdated", dict);
}

void TranslateInternalsHandler::SendMessageToJs(const std::string& message,
const base::Value& value) {
const char func[] = "cr.translateInternals.messageHandler";
base::StringValue message_data(message);
web_ui()->CallJavascriptFunction(func, message_data, value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2013 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.

#ifndef CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_HANDLER_H_

#include <string>

#include "content/public/browser/web_ui_message_handler.h"
#include "webkit/plugins/webplugininfo.h"

namespace base {
class ListValue;
class Value;
}

// The handler class for TranslateInternals page operations.
class TranslateInternalsHandler : public content::WebUIMessageHandler {
public:
TranslateInternalsHandler() {}
virtual ~TranslateInternalsHandler() {}

// content::WebUIMessageHandler methods:
virtual void RegisterMessages() OVERRIDE;

private:
// Handles the Javascript message 'requestInfo'. This message is sent
// when UI needs to show information concerned with the translation.
// For now, this returns only prefs to Javascript.
void OnRequestInfo(const base::ListValue* args);

// Sends a messsage to Javascript.
void SendMessageToJs(const std::string& message, const base::Value& value);

DISALLOW_COPY_AND_ASSIGN(TranslateInternalsHandler);
};

#endif // CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_HANDLER_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2013 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.

#include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"

#include <string>

#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/translate_internals/translate_internals_handler.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "grit/browser_resources.h"
#include "grit/translate_internals_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"

using content::WebContents;

namespace {

content::WebUIDataSource* CreateTranslateInternalsHTMLSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUITranslateInternalsHost);
source->SetDefaultResource(IDR_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_HTML);
source->AddResourcePath("translate_internals.js",
IDR_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_JS);
return source;
}

} // namespace

TranslateInternalsUI::TranslateInternalsUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
web_ui->AddMessageHandler(new TranslateInternalsHandler);

Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, CreateTranslateInternalsHTMLSource());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2013 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.

#ifndef CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_UI_H_
#define CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_UI_H_
#include "content/public/browser/web_ui_controller.h"

// The implementation for the chrome://translate-internals page.
class TranslateInternalsUI : public content::WebUIController {
public:
explicit TranslateInternalsUI(content::WebUI* web_ui);
virtual ~TranslateInternalsUI() {}

private:
DISALLOW_COPY_AND_ASSIGN(TranslateInternalsUI);
};

#endif // CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_UI_H_
4 changes: 4 additions & 0 deletions chrome/chrome_browser_ui.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,10 @@
'browser/ui/webui/theme_handler.h',
'browser/ui/webui/theme_source.cc',
'browser/ui/webui/theme_source.h',
'browser/ui/webui/translate_internals/translate_internals_handler.cc',
'browser/ui/webui/translate_internals/translate_internals_handler.h',
'browser/ui/webui/translate_internals/translate_internals_ui.cc',
'browser/ui/webui/translate_internals/translate_internals_ui.h',
'browser/ui/webui/uber/uber_ui.cc',
'browser/ui/webui/uber/uber_ui.h',
'browser/ui/webui/user_actions/user_actions_ui.cc',
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_repack_resources.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'<(grit_out_dir)/net_internals_resources.pak',
'<(grit_out_dir)/signin_internals_resources.pak',
'<(grit_out_dir)/sync_internals_resources.pak',
'<(grit_out_dir)/translate_internals_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/webui_resources.pak',
],
'conditions': [
Expand Down
7 changes: 7 additions & 0 deletions chrome/chrome_resources.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
},
'includes': [ '../build/grit_action.gypi' ],
},
{
'action_name': 'translate_internals_resources',
'variables': {
'grit_grd_file': 'browser/resources/translate_internals_resources.grd',
},
'includes': [ '../build/grit_action.gypi' ],
},
],
'includes': [ '../build/grit_target.gypi' ],
'conditions': [
Expand Down
1 change: 1 addition & 0 deletions chrome/common/url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const char kChromeUITermsHost[] = "terms";
const char kChromeUIThemeHost[] = "theme";
const char kChromeUIThumbnailHost[] = "thumb";
const char kChromeUITouchIconHost[] = "touch-icon";
const char kChromeUITranslateInternalsHost[] = "translate-internals";
const char kChromeUIUberFrameHost[] = "uber-frame";
const char kChromeUIUberHost[] = "chrome";
const char kChromeUIUserActionsHost[] = "user-actions";
Expand Down
1 change: 1 addition & 0 deletions chrome/common/url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ extern const char kChromeUITermsHost[];
extern const char kChromeUIThemeHost[];
extern const char kChromeUIThumbnailHost[];
extern const char kChromeUITouchIconHost[];
extern const char kChromeUITranslateInternalsHost[];
extern const char kChromeUIUberFrameHost[];
extern const char kChromeUIUberHost[];
extern const char kChromeUIUserActionsHost[];
Expand Down
4 changes: 4 additions & 0 deletions tools/gritsettings/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,9 @@
"ui/keyboard/keyboard_resources.grd": {
"includes": [28050],
},
"chrome/browser/resources/translate_internals_resources.grd": {
"includes": [28500],
},

# Resource ids starting at 31000 are reserved for projects built on Chromium.
}

0 comments on commit 147408a

Please sign in to comment.