forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added chrome://translate-internals. For now, this shows only the pref…
…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
Showing
18 changed files
with
310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
chrome/browser/resources/translate_internals/translate_internals.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
41 changes: 41 additions & 0 deletions
41
chrome/browser/resources/translate_internals/translate_internals.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
62 changes: 62 additions & 0 deletions
62
chrome/browser/resources/translate_internals/translate_internals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
chrome/browser/resources/translate_internals_resources.grd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
chrome/browser/ui/webui/translate_internals/translate_internals_handler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
39 changes: 39 additions & 0 deletions
39
chrome/browser/ui/webui/translate_internals/translate_internals_handler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
41 changes: 41 additions & 0 deletions
41
chrome/browser/ui/webui/translate_internals/translate_internals_ui.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
19 changes: 19 additions & 0 deletions
19
chrome/browser/ui/webui/translate_internals/translate_internals_ui.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters