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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_error_handler.cc

Issue 23624002: Add UI for RuntimeErrors in the ErrorConsole (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_merge
Patch Set: Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/extensions/extension_error_handler.h" 5 #include "chrome/browser/ui/webui/extensions/extension_error_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_system.h" 15 #include "chrome/browser/extensions/extension_system.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
20 #include "content/public/browser/web_ui_data_source.h" 20 #include "content/public/browser/web_ui_data_source.h"
21 #include "extensions/browser/extension_error.h" 21 #include "extensions/browser/extension_error.h"
22 #include "extensions/browser/manifest_highlighter.h" 22 #include "extensions/browser/file_highlighter.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 namespace { 28 namespace {
29 29
30 // Keys for objects passed to and from extension error UI. 30 // Keys for objects passed to and from extension error UI.
31 const char kFileTypeKey[] = "fileType"; 31 const char kFileTypeKey[] = "fileType";
32 const char kManifestFileType[] = "manifest"; 32 const char kManifestFileType[] = "manifest";
33 const char kPathSuffixKey[] = "pathSuffix"; 33 const char kPathSuffixKey[] = "pathSuffix";
34 const char kSourceFileType[] = "source";
34 const char kTitleKey[] = "title"; 35 const char kTitleKey[] = "title";
35 36
36 const char kBeforeHighlightKey[] = "beforeHighlight";
37 const char kHighlightKey[] = "highlight";
38 const char kAfterHighlightKey[] = "afterHighlight";
39
40 // Populate a DictionaryValue with the highlighted portions for the callback to
41 // ExtensionErrorOverlay, given the components.
42 void HighlightDictionary(base::DictionaryValue* dict,
43 const ManifestHighlighter& highlighter) {
44 std::string before_feature = highlighter.GetBeforeFeature();
45 if (!before_feature.empty())
46 dict->SetString(kBeforeHighlightKey, base::UTF8ToUTF16(before_feature));
47
48 std::string feature = highlighter.GetFeature();
49 if (!feature.empty())
50 dict->SetString(kHighlightKey, base::UTF8ToUTF16(feature));
51
52 std::string after_feature = highlighter.GetAfterFeature();
53 if (!after_feature.empty())
54 dict->SetString(kAfterHighlightKey, base::UTF8ToUTF16(after_feature));
55 }
56
57 } // namespace 37 } // namespace
58 38
59 ExtensionErrorHandler::ExtensionErrorHandler(Profile* profile) 39 ExtensionErrorHandler::ExtensionErrorHandler(Profile* profile)
60 : profile_(profile) { 40 : profile_(profile) {
61 } 41 }
62 42
63 ExtensionErrorHandler::~ExtensionErrorHandler() { 43 ExtensionErrorHandler::~ExtensionErrorHandler() {
64 } 44 }
65 45
66 void ExtensionErrorHandler::GetLocalizedValues( 46 void ExtensionErrorHandler::GetLocalizedValues(
67 content::WebUIDataSource* source) { 47 content::WebUIDataSource* source) {
68 source->AddString( 48 source->AddString(
69 "extensionErrorsManifestErrors", 49 "extensionErrorsManifestErrors",
70 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_MANIFEST_ERRORS)); 50 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_MANIFEST_ERRORS));
71 source->AddString( 51 source->AddString(
52 "extensionErrorsRuntimeErrors",
53 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_RUNTIME_ERRORS));
54 source->AddString(
72 "extensionErrorsShowMore", 55 "extensionErrorsShowMore",
73 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_MORE)); 56 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_MORE));
74 source->AddString( 57 source->AddString(
75 "extensionErrorsShowFewer", 58 "extensionErrorsShowFewer",
76 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_FEWER)); 59 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERRORS_SHOW_FEWER));
77 source->AddString( 60 source->AddString(
78 "extensionErrorViewSource", 61 "extensionErrorViewSource",
79 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_VIEW_SOURCE)); 62 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_VIEW_SOURCE));
63 source->AddString(
64 "extensionErrorContext",
65 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT));
66 source->AddString(
67 "extensionErrorStackTrace",
68 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_STACK_TRACE));
69 source->AddString(
70 "extensionErrorAnonymousFunction",
71 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_ANONYMOUS_FUNCTION));
80 } 72 }
81 73
82 void ExtensionErrorHandler::RegisterMessages() { 74 void ExtensionErrorHandler::RegisterMessages() {
83 web_ui()->RegisterMessageCallback( 75 web_ui()->RegisterMessageCallback(
84 "extensionErrorRequestFileSource", 76 "extensionErrorRequestFileSource",
85 base::Bind(&ExtensionErrorHandler::HandleRequestFileSource, 77 base::Bind(&ExtensionErrorHandler::HandleRequestFileSource,
86 base::Unretained(this))); 78 base::Unretained(this)));
87 } 79 }
88 80
89 void ExtensionErrorHandler::HandleRequestFileSource( 81 void ExtensionErrorHandler::HandleRequestFileSource(
90 const base::ListValue* args) { 82 const base::ListValue* args) {
91 // There should only be one argument, a dictionary. Use this instead of a list 83 // There should only be one argument, a dictionary. Use this instead of a list
92 // because it's more descriptive, harder to accidentally break with minor 84 // because it's more descriptive, harder to accidentally break with minor
93 // modifications, and supports optional arguments more easily. 85 // modifications, and supports optional arguments more easily.
94 CHECK_EQ(1u, args->GetSize()); 86 DCHECK_EQ(1u, args->GetSize());
not at google - send to devlin 2013/09/05 00:37:16 what was wrong with the CHECK
Devlin 2013/09/05 17:53:55 I thought a DCHECK would be more consistent, since
not at google - send to devlin 2013/09/06 17:05:19 We will pick it up in canary channel if there's a
Devlin 2013/09/06 18:18:02 CHECK it is.
95 87
96 const base::DictionaryValue* dict = NULL; 88 const base::DictionaryValue* dict = NULL;
97 89
98 // Four required arguments: extension_id, path_suffix, error_message, and 90 // Four required arguments: extension_id, path_suffix, error_message, and
99 // file_type. 91 // file_type.
100 std::string extension_id; 92 std::string extension_id;
101 base::FilePath::StringType path_suffix; 93 base::FilePath::StringType path_suffix;
102 base::string16 error_message; 94 base::string16 error_message;
103 std::string file_type; 95 std::string file_type;
104 96
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 std::string specific; 131 std::string specific;
140 dict->GetString(ManifestError::kManifestSpecificKey, &specific); 132 dict->GetString(ManifestError::kManifestSpecificKey, &specific);
141 133
142 contents = new std::string; // Owned by GetManifestFileCallback( ) 134 contents = new std::string; // Owned by GetManifestFileCallback( )
143 closure = base::Bind(&ExtensionErrorHandler::GetManifestFileCallback, 135 closure = base::Bind(&ExtensionErrorHandler::GetManifestFileCallback,
144 base::Unretained(this), 136 base::Unretained(this),
145 base::Owned(results.release()), 137 base::Owned(results.release()),
146 manifest_key, 138 manifest_key,
147 specific, 139 specific,
148 base::Owned(contents)); 140 base::Owned(contents));
141 } else if (file_type == kSourceFileType) {
142 int line_number = 1;
143 dict->GetInteger(RuntimeError::kLineNumberKey, &line_number);
144
145 contents = new std::string; // Owned by GetSourceFileCallback()
146 closure = base::Bind(&ExtensionErrorHandler::GetSourceFileCallback,
147 base::Unretained(this),
148 base::Owned(results.release()),
149 line_number,
150 base::Owned(contents));
149 } else { 151 } else {
150 // currently, only manifest file types supported.
151 NOTREACHED(); 152 NOTREACHED();
152 return; 153 return;
153 } 154 }
154 155
155 content::BrowserThread::PostBlockingPoolTaskAndReply( 156 content::BrowserThread::PostBlockingPoolTaskAndReply(
156 FROM_HERE, 157 FROM_HERE,
157 base::Bind(base::IgnoreResult(&base::ReadFileToString), 158 base::Bind(base::IgnoreResult(&base::ReadFileToString),
158 path, 159 path,
159 contents), 160 contents),
160 closure); 161 closure);
161 } 162 }
162 163
163 void ExtensionErrorHandler::GetManifestFileCallback( 164 void ExtensionErrorHandler::GetManifestFileCallback(
164 base::DictionaryValue* results, 165 base::DictionaryValue* results,
165 const std::string& key, 166 const std::string& key,
166 const std::string& specific, 167 const std::string& specific,
167 std::string* contents) { 168 std::string* contents) {
168 ManifestHighlighter highlighter(*contents, key, specific); 169 ManifestHighlighter highlighter(*contents, key, specific);
169 HighlightDictionary(results, highlighter); 170 highlighter.HighlightDictionary(results);
170 web_ui()->CallJavascriptFunction( 171 web_ui()->CallJavascriptFunction(
171 "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results); 172 "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results);
172 } 173 }
174
175 void ExtensionErrorHandler::GetSourceFileCallback(
176 base::DictionaryValue* results,
177 int line_number,
178 std::string* contents) {
179 SourceHighlighter highlighter(*contents, line_number);
180 highlighter.HighlightDictionary(results);
181 web_ui()->CallJavascriptFunction(
182 "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results);
183 }
173 184
174 } // namespace extensions 185 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698