Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1398)

Unified Diff: chrome/browser/ui/webui/extensions/extension_error_ui_util.cc

Issue 150663013: Integrate ErrorConsole with Apps Dev Tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/extensions/extension_error_ui_util.cc
diff --git a/chrome/browser/ui/webui/extensions/extension_error_handler.cc b/chrome/browser/ui/webui/extensions/extension_error_ui_util.cc
similarity index 55%
copy from chrome/browser/ui/webui/extensions/extension_error_handler.cc
copy to chrome/browser/ui/webui/extensions/extension_error_ui_util.cc
index b4f09680fdde745444095a4df7af4c10d370ee46..eac636f2f618f94751c4addad58f4fd62c1488d7 100644
--- a/chrome/browser/ui/webui/extensions/extension_error_handler.cc
+++ b/chrome/browser/ui/webui/extensions/extension_error_ui_util.cc
@@ -1,14 +1,13 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 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/extensions/extension_error_handler.h"
+#include "chrome/browser/ui/webui/extensions/extension_error_ui_util.h"
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/location.h"
-#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/values.h"
@@ -21,8 +20,6 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.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 "extensions/browser/extension_error.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/file_highlighter.h"
@@ -32,6 +29,7 @@
#include "ui/base/l10n/l10n_util.h"
namespace extensions {
+namespace error_ui_util {
namespace {
@@ -45,86 +43,72 @@ std::string ReadFileToString(const base::FilePath& path) {
return data;
}
-} // namespace
-
-ExtensionErrorHandler::ExtensionErrorHandler(Profile* profile)
- : profile_(profile) {
+void GetManifestFileCallback(base::DictionaryValue* results,
+ const std::string& key,
+ const std::string& specific,
+ const JavascriptResponseCallback& response,
+ const std::string& contents) {
+ ManifestHighlighter highlighter(contents, key, specific);
+ highlighter.SetHighlightedRegions(results);
+ response.Run(*results);
}
-ExtensionErrorHandler::~ExtensionErrorHandler() {
+void GetSourceFileCallback(base::DictionaryValue* results,
+ int line_number,
+ const JavascriptResponseCallback& response,
+ const std::string& contents) {
+ SourceHighlighter highlighter(contents, line_number);
+ highlighter.SetHighlightedRegions(results);
+ response.Run(*results);
}
-void ExtensionErrorHandler::GetLocalizedValues(
- content::WebUIDataSource* source) {
- source->AddString(
- "extensionErrorsShowMore",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_MORE));
- source->AddString(
- "extensionErrorsShowFewer",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_FEWER));
- source->AddString(
- "extensionErrorViewDetails",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_VIEW_DETAILS));
- source->AddString(
- "extensionErrorViewManifest",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_VIEW_MANIFEST));
- source->AddString(
- "extensionErrorOverlayContextUrl",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT));
- source->AddString(
- "extensionErrorOverlayStackTrace",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_STACK_TRACE));
- source->AddString(
+} // namespace
+
+void GetLocalizedValues(const AddLocalizedStringCallback& add_string) {
+ add_string.Run("extensionErrorsShowMore",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_MORE));
+ add_string.Run("extensionErrorsShowFewer",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_FEWER));
+ add_string.Run("extensionErrorViewDetails",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_VIEW_DETAILS));
+ add_string.Run("extensionErrorViewManifest",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_VIEW_MANIFEST));
+ add_string.Run("extensionErrorOverlayContextUrl",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT));
+ add_string.Run("extensionErrorOverlayStackTrace",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_STACK_TRACE));
+ add_string.Run(
"extensionErrorOverlayAnonymousFunction",
- l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_ANONYMOUS_FUNCTION));
- source->AddString(
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_ANONYMOUS_FUNCTION));
+ add_string.Run(
"extensionErrorOverlayLaunchDevtools",
l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_LAUNCH_DEVTOOLS));
- source->AddString(
+ add_string.Run(
"extensionErrorOverlayContextUnknown",
l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT_UNKNOWN));
- source->AddString(
+ add_string.Run(
"extensionErrorOverlayNoCodeToDisplay",
l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY));
}
-void ExtensionErrorHandler::RegisterMessages() {
- web_ui()->RegisterMessageCallback(
- "extensionErrorRequestFileSource",
- base::Bind(&ExtensionErrorHandler::HandleRequestFileSource,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- "extensionErrorOpenDevTools",
- base::Bind(&ExtensionErrorHandler::HandleOpenDevTools,
- base::Unretained(this)));
-}
-
-void ExtensionErrorHandler::HandleRequestFileSource(
- const base::ListValue* args) {
- // There should only be one argument, a dictionary. Use this instead of a list
- // because it's more descriptive, harder to accidentally break with minor
- // modifications, and supports optional arguments more easily.
- CHECK_EQ(1u, args->GetSize());
-
- const base::DictionaryValue* dict = NULL;
-
+void HandleRequestFileSource(const base::DictionaryValue* args,
+ Profile* profile,
+ const JavascriptResponseCallback& response) {
// Three required arguments: extension_id, path_suffix, and error_message.
std::string extension_id;
base::FilePath::StringType path_suffix_string;
base::string16 error_message;
- if (!args->GetDictionary(0, &dict) ||
- !dict->GetString(kPathSuffixKey, &path_suffix_string) ||
- !dict->GetString(ExtensionError::kExtensionIdKey, &extension_id) ||
- !dict->GetString(ExtensionError::kMessageKey, &error_message)) {
+ if (!args->GetString(kPathSuffixKey, &path_suffix_string) ||
+ !args->GetString(ExtensionError::kExtensionIdKey, &extension_id) ||
+ !args->GetString(ExtensionError::kMessageKey, &error_message)) {
NOTREACHED();
return;
}
const Extension* extension =
- ExtensionSystem::Get(Profile::FromWebUI(web_ui()))->
- extension_service()->GetExtensionById(extension_id,
- true /* include disabled */ );
+ ExtensionSystem::Get(profile)->extension_service()->
+ GetExtensionById(extension_id, true /* include disabled */ );
// Under no circumstances should we ever need to reference a file outside of
// the extension's directory. If it tries to, abort.
@@ -145,28 +129,28 @@ void ExtensionErrorHandler::HandleRequestFileSource(
base::Callback<void(const std::string&)> reply;
if (path_suffix_string == kManifestFilename) {
std::string manifest_key;
- if (!dict->GetString(ManifestError::kManifestKeyKey, &manifest_key)) {
+ if (!args->GetString(ManifestError::kManifestKeyKey, &manifest_key)) {
NOTREACHED();
return;
}
// A "specific" location is optional.
std::string specific;
- dict->GetString(ManifestError::kManifestSpecificKey, &specific);
+ args->GetString(ManifestError::kManifestSpecificKey, &specific);
- reply = base::Bind(&ExtensionErrorHandler::GetManifestFileCallback,
- base::Unretained(this),
+ reply = base::Bind(&GetManifestFileCallback,
base::Owned(results.release()),
manifest_key,
- specific);
+ specific,
+ response);
} else {
int line_number = 0;
- dict->GetInteger(RuntimeError::kLineNumberKey, &line_number);
+ args->GetInteger(RuntimeError::kLineNumberKey, &line_number);
- reply = base::Bind(&ExtensionErrorHandler::GetSourceFileCallback,
- base::Unretained(this),
+ reply = base::Bind(&GetSourceFileCallback,
base::Owned(results.release()),
- line_number);
+ line_number,
+ response);
}
base::PostTaskAndReplyWithResult(
@@ -176,18 +160,14 @@ void ExtensionErrorHandler::HandleRequestFileSource(
reply);
}
-void ExtensionErrorHandler::HandleOpenDevTools(const base::ListValue* args) {
- CHECK_EQ(1U, args->GetSize());
-
- const base::DictionaryValue* dict = NULL;
+void HandleOpenDevTools(const base::DictionaryValue* args) {
int render_process_id = 0;
int render_view_id = 0;
// The render view and render process ids are required.
- if (!args->GetDictionary(0, &dict) ||
- !dict->GetInteger(RuntimeError::kRenderProcessIdKey,
+ if (!args->GetInteger(RuntimeError::kRenderProcessIdKey,
&render_process_id) ||
- !dict->GetInteger(RuntimeError::kRenderViewIdKey, &render_view_id)) {
+ !args->GetInteger(RuntimeError::kRenderViewIdKey, &render_view_id)) {
NOTREACHED();
return;
}
@@ -203,17 +183,18 @@ void ExtensionErrorHandler::HandleOpenDevTools(const base::ListValue* args) {
// If we include a url, we should inspect it specifically (and not just the
// render view).
base::string16 url;
- if (dict->GetString(RuntimeError::kUrlKey, &url)) {
+ if (args->GetString(RuntimeError::kUrlKey, &url)) {
// Line and column numbers are optional; default to the first line.
int line_number = 1;
int column_number = 1;
- dict->GetInteger(RuntimeError::kLineNumberKey, &line_number);
- dict->GetInteger(RuntimeError::kColumnNumberKey, &column_number);
+ args->GetInteger(RuntimeError::kLineNumberKey, &line_number);
+ args->GetInteger(RuntimeError::kColumnNumberKey, &column_number);
// Line/column numbers are reported in display-friendly 1-based numbers,
// but are inspected in zero-based numbers.
- DevToolsWindow::OpenDevToolsWindow(rvh,
- DevToolsToggleAction::Reveal(url, line_number - 1, column_number - 1));
+ DevToolsWindow::OpenDevToolsWindow(
+ rvh,
+ DevToolsToggleAction::Reveal(url, line_number - 1, column_number -1));
} else {
DevToolsWindow::OpenDevToolsWindow(rvh);
}
@@ -232,25 +213,5 @@ void ExtensionErrorHandler::HandleOpenDevTools(const base::ListValue* args) {
false); // Not through direct user gesture.
}
-void ExtensionErrorHandler::GetManifestFileCallback(
- base::DictionaryValue* results,
- const std::string& key,
- const std::string& specific,
- const std::string& contents) {
- ManifestHighlighter highlighter(contents, key, specific);
- highlighter.SetHighlightedRegions(results);
- web_ui()->CallJavascriptFunction(
- "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results);
-}
-
-void ExtensionErrorHandler::GetSourceFileCallback(
- base::DictionaryValue* results,
- int line_number,
- const std::string& contents) {
- SourceHighlighter highlighter(contents, line_number);
- highlighter.SetHighlightedRegions(results);
- web_ui()->CallJavascriptFunction(
- "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results);
-}
-
+} // namespace error_ui_util
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698