Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_loader_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 web_ui()->RegisterMessageCallback( | 94 web_ui()->RegisterMessageCallback( |
| 95 "extensionLoaderIgnoreFailure", | 95 "extensionLoaderIgnoreFailure", |
| 96 base::Bind(&ExtensionLoaderHandler::HandleIgnoreFailure, | 96 base::Bind(&ExtensionLoaderHandler::HandleIgnoreFailure, |
| 97 weak_ptr_factory_.GetWeakPtr())); | 97 weak_ptr_factory_.GetWeakPtr())); |
| 98 web_ui()->RegisterMessageCallback( | 98 web_ui()->RegisterMessageCallback( |
| 99 "extensionLoaderDisplayFailures", | 99 "extensionLoaderDisplayFailures", |
| 100 base::Bind(&ExtensionLoaderHandler::HandleDisplayFailures, | 100 base::Bind(&ExtensionLoaderHandler::HandleDisplayFailures, |
| 101 weak_ptr_factory_.GetWeakPtr())); | 101 weak_ptr_factory_.GetWeakPtr())); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | |
| 105 void ExtensionLoaderHandler::GetManifestError( | |
| 106 const std::string& error, | |
| 107 const base::FilePath& extension_path, | |
| 108 const GetManifestErrorCallback& callback) { | |
| 109 size_t line = 0u; | |
|
Devlin
2017/03/22 19:03:32
Note: copy-paste.
lazyboy
2017/03/22 21:38:46
Acknowledged.
| |
| 110 size_t column = 0u; | |
| 111 std::string regex = base::StringPrintf("%s Line: (\\d+), column: (\\d+), .*", | |
| 112 manifest_errors::kManifestParseError); | |
| 113 // If this was a JSON parse error, we can highlight the exact line with the | |
| 114 // error. Otherwise, we should still display the manifest (for consistency, | |
| 115 // reference, and so that if we ever make this really fancy and add an editor, | |
| 116 // it's ready). | |
| 117 // | |
| 118 // This regex call can fail, but if it does, we just don't highlight anything. | |
| 119 re2::RE2::FullMatch(error, regex, &line, &column); | |
| 120 | |
| 121 // This will read the manifest and call AddFailure with the read manifest | |
| 122 // contents. | |
| 123 base::PostTaskWithTraitsAndReplyWithResult( | |
| 124 FROM_HERE, | |
| 125 base::TaskTraits().MayBlock().WithPriority( | |
| 126 base::TaskPriority::USER_BLOCKING), | |
| 127 base::Bind(&ReadFileToString, extension_path.Append(kManifestFilename)), | |
| 128 base::Bind(callback, extension_path, error, line)); | |
| 129 } | |
| 130 | |
| 104 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { | 131 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { |
| 105 DCHECK(args->empty()); | 132 DCHECK(args->empty()); |
| 106 const base::FilePath file_path = failed_paths_.back(); | 133 const base::FilePath file_path = failed_paths_.back(); |
| 107 failed_paths_.pop_back(); | 134 failed_paths_.pop_back(); |
| 108 LoadUnpackedExtension(file_path); | 135 LoadUnpackedExtension(file_path); |
| 109 } | 136 } |
| 110 | 137 |
| 111 void ExtensionLoaderHandler::HandleIgnoreFailure(const base::ListValue* args) { | 138 void ExtensionLoaderHandler::HandleIgnoreFailure(const base::ListValue* args) { |
| 112 DCHECK(args->empty()); | 139 DCHECK(args->empty()); |
| 113 failed_paths_.pop_back(); | 140 failed_paths_.pop_back(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 137 } | 164 } |
| 138 | 165 |
| 139 void ExtensionLoaderHandler::OnLoadFailure( | 166 void ExtensionLoaderHandler::OnLoadFailure( |
| 140 content::BrowserContext* browser_context, | 167 content::BrowserContext* browser_context, |
| 141 const base::FilePath& file_path, | 168 const base::FilePath& file_path, |
| 142 const std::string& error) { | 169 const std::string& error) { |
| 143 // Only show errors from our browser context. | 170 // Only show errors from our browser context. |
| 144 if (web_ui()->GetWebContents()->GetBrowserContext() != browser_context) | 171 if (web_ui()->GetWebContents()->GetBrowserContext() != browser_context) |
| 145 return; | 172 return; |
| 146 | 173 |
| 147 size_t line = 0u; | 174 GetManifestError(error, file_path, |
| 148 size_t column = 0u; | 175 base::Bind(&ExtensionLoaderHandler::AddFailure, |
| 149 std::string regex = | 176 weak_ptr_factory_.GetWeakPtr())); |
| 150 base::StringPrintf("%s Line: (\\d+), column: (\\d+), .*", | |
| 151 manifest_errors::kManifestParseError); | |
| 152 // If this was a JSON parse error, we can highlight the exact line with the | |
| 153 // error. Otherwise, we should still display the manifest (for consistency, | |
| 154 // reference, and so that if we ever make this really fancy and add an editor, | |
| 155 // it's ready). | |
| 156 // | |
| 157 // This regex call can fail, but if it does, we just don't highlight anything. | |
| 158 re2::RE2::FullMatch(error, regex, &line, &column); | |
| 159 | |
| 160 // This will read the manifest and call AddFailure with the read manifest | |
| 161 // contents. | |
| 162 base::PostTaskWithTraitsAndReplyWithResult( | |
| 163 FROM_HERE, | |
| 164 base::TaskTraits().MayBlock().WithPriority( | |
| 165 base::TaskPriority::USER_BLOCKING), | |
| 166 base::Bind(&ReadFileToString, file_path.Append(kManifestFilename)), | |
| 167 base::Bind(&ExtensionLoaderHandler::AddFailure, | |
| 168 weak_ptr_factory_.GetWeakPtr(), file_path, error, line)); | |
| 169 } | 177 } |
| 170 | 178 |
| 171 void ExtensionLoaderHandler::DidStartNavigation( | 179 void ExtensionLoaderHandler::DidStartNavigation( |
| 172 content::NavigationHandle* navigation_handle) { | 180 content::NavigationHandle* navigation_handle) { |
| 173 if (!navigation_handle->IsInMainFrame()) | 181 if (!navigation_handle->IsInMainFrame()) |
| 174 return; | 182 return; |
| 175 | 183 |
| 176 // In the event of a page reload, we ensure that the frontend is not notified | 184 // In the event of a page reload, we ensure that the frontend is not notified |
| 177 // until the UI finishes loading, so we set |ui_ready_| to false. This is | 185 // until the UI finishes loading, so we set |ui_ready_| to false. This is |
| 178 // balanced in HandleDisplayFailures, which is called when the frontend is | 186 // balanced in HandleDisplayFailures, which is called when the frontend is |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 207 NotifyFrontendOfFailure(); | 215 NotifyFrontendOfFailure(); |
| 208 } | 216 } |
| 209 | 217 |
| 210 void ExtensionLoaderHandler::NotifyFrontendOfFailure() { | 218 void ExtensionLoaderHandler::NotifyFrontendOfFailure() { |
| 211 web_ui()->CallJavascriptFunctionUnsafe( | 219 web_ui()->CallJavascriptFunctionUnsafe( |
| 212 "extensions.ExtensionLoader.notifyLoadFailed", failures_); | 220 "extensions.ExtensionLoader.notifyLoadFailed", failures_); |
| 213 failures_.Clear(); | 221 failures_.Clear(); |
| 214 } | 222 } |
| 215 | 223 |
| 216 } // namespace extensions | 224 } // namespace extensions |
| OLD | NEW |