diff options
Diffstat (limited to 'chrome/browser/extensions')
15 files changed, 134 insertions, 13 deletions
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index e10c534..feb5753 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -13,10 +13,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/extensions/convert_user_script.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/profile.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/web_applications/web_app.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/extensions/extension_file_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index e941260..44318aa 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -13,13 +13,13 @@ #include "chrome/browser/browser_window.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/extensions/crx_installer.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_install_ui.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 24e90f3..2789569 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -8,6 +8,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/extensions/autoupdate_interceptor.h" #include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_tabs_module.h" @@ -22,7 +23,6 @@ #endif #include "chrome/common/chrome_paths.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/notification_service.h" #include "chrome/common/url_constants.h" #include "chrome/test/ui_test_utils.h" diff --git a/chrome/browser/extensions/extension_devtools_browsertests.cc b/chrome/browser/extensions/extension_devtools_browsertests.cc index 6422f5f..a8e28ab 100644 --- a/chrome/browser/extensions/extension_devtools_browsertests.cc +++ b/chrome/browser/extensions/extension_devtools_browsertests.cc @@ -9,6 +9,7 @@ #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/debugger/devtools_client_host.h" #include "chrome/browser/extensions/extension_devtools_browsertest.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extensions_service.h" @@ -18,7 +19,6 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/devtools_messages.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/notification_service.h" #include "chrome/common/url_constants.h" #include "chrome/test/ui_test_utils.h" diff --git a/chrome/browser/extensions/extension_error_reporter.cc b/chrome/browser/extensions/extension_error_reporter.cc new file mode 100644 index 0000000..92f854e --- /dev/null +++ b/chrome/browser/extensions/extension_error_reporter.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2006-2009 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/extensions/extension_error_reporter.h" + +#include "build/build_config.h" + +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/platform_util.h" + +// No AddRef required when using ExtensionErrorReporter with RunnableMethod. +// This is okay since the ExtensionErrorReporter is a singleton that lives until +// the end of the process. +template <> struct RunnableMethodTraits<ExtensionErrorReporter> { + void RetainCallee(ExtensionErrorReporter*) {} + void ReleaseCallee(ExtensionErrorReporter*) {} +}; + +ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL; + +// static +void ExtensionErrorReporter::Init(bool enable_noisy_errors) { + if (!instance_) { + instance_ = new ExtensionErrorReporter(enable_noisy_errors); + } +} + +// static +ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { + CHECK(instance_) << "Init() was never called"; + return instance_; +} + +ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) + : ui_loop_(MessageLoop::current()), + enable_noisy_errors_(enable_noisy_errors) { +} + +void ExtensionErrorReporter::ReportError(const std::string& message, + bool be_noisy) { + // NOTE: There won't be a ui_loop_ in the unit test environment. + if (ui_loop_ && MessageLoop::current() != ui_loop_) { + ui_loop_->PostTask(FROM_HERE, + NewRunnableMethod(this, &ExtensionErrorReporter::ReportError, message, + be_noisy)); + return; + } + + errors_.push_back(message); + + // TODO(aa): Print the error message out somewhere better. I think we are + // going to need some sort of 'extension inspector'. + LOG(ERROR) << "Extension error: " << message; + + if (enable_noisy_errors_ && be_noisy) { + platform_util::SimpleErrorBox(NULL, + UTF8ToUTF16("Extension error"), + UTF8ToUTF16(message)); + } +} + +const std::vector<std::string>* ExtensionErrorReporter::GetErrors() { + return &errors_; +} + +void ExtensionErrorReporter::ClearErrors() { + errors_.clear(); +} diff --git a/chrome/browser/extensions/extension_error_reporter.h b/chrome/browser/extensions/extension_error_reporter.h new file mode 100644 index 0000000..f4205e9 --- /dev/null +++ b/chrome/browser/extensions/extension_error_reporter.h @@ -0,0 +1,50 @@ +// Copyright (c) 2006-2009 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_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_ + +#include <string> +#include <vector> + +class MessageLoop; + +// Exposes an easy way for the various components of the extension system to +// report errors. This is a singleton that lives on the UI thread, with the +// exception of ReportError() which may be called from any thread. +// TODO(aa): Hook this up to about:extensions, when we have about:extensions. +// TODO(aa): Consider exposing directly, or via a helper, to the renderer +// process and plumbing the errors out to the browser. +// TODO(aa): Add ReportError(extension_id, message, be_noisy), so that we can +// report errors that are specific to a particular extension. +class ExtensionErrorReporter { + public: + // Initializes the error reporter. Must be called before any other methods + // and on the UI thread. + static void Init(bool enable_noisy_errors); + + // Get the singleton instance. + static ExtensionErrorReporter* GetInstance(); + + // Report an error. Errors always go to LOG(INFO). Optionally, they can also + // cause a noisy alert box. This method can be called from any thread. + void ReportError(const std::string& message, bool be_noisy); + + // Get the errors that have been reported so far. + const std::vector<std::string>* GetErrors(); + + // Clear the list of errors reported so far. + void ClearErrors(); + + private: + static ExtensionErrorReporter* instance_; + + explicit ExtensionErrorReporter(bool enable_noisy_errors); + + MessageLoop* ui_loop_; + std::vector<std::string> errors_; + bool enable_noisy_errors_; +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_ diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 1d7de596..67af709 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -12,7 +12,6 @@ #include "base/message_loop.h" #include "base/singleton.h" #include "base/string_util.h" -#include "chrome/common/platform_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_shutdown.h" @@ -26,6 +25,7 @@ #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/in_process_webkit/webkit_context.h" #include "chrome/browser/message_box_handler.h" +#include "chrome/browser/platform_util.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index 801dee0..fa43635 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -15,6 +15,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" +#include "chrome/browser/platform_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #if defined(TOOLKIT_VIEWS) // TODO(port) @@ -24,7 +25,6 @@ #endif #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" -#include "chrome/common/platform_util.h" #include "chrome/common/url_constants.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/extensions/extension_process_manager_unittest.cc b/chrome/browser/extensions/extension_process_manager_unittest.cc index ae9eefe..8ab9517 100644 --- a/chrome/browser/extensions/extension_process_manager_unittest.cc +++ b/chrome/browser/extensions/extension_process_manager_unittest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/renderer_host/site_instance.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" diff --git a/chrome/browser/extensions/extension_shelf_model_browsertest.cc b/chrome/browser/extensions/extension_shelf_model_browsertest.cc index 59cf318..abb2a93 100644 --- a/chrome/browser/extensions/extension_shelf_model_browsertest.cc +++ b/chrome/browser/extensions/extension_shelf_model_browsertest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_shelf_model.h" #include "chrome/browser/extensions/extensions_service.h" @@ -12,7 +13,6 @@ #include "chrome/browser/views/frame/browser_view.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/test/in_process_browser_test.h" namespace { diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc index 3d9ecea..505796e 100644 --- a/chrome/browser/extensions/extension_updater.cc +++ b/chrome/browser/extensions/extension_updater.cc @@ -19,13 +19,13 @@ #include "base/version.h" #include "chrome/app/chrome_version_info.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/utility_process_host.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/pref_names.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc index 9c54d7a..b783517 100644 --- a/chrome/browser/extensions/extension_updater_unittest.cc +++ b/chrome/browser/extensions/extension_updater_unittest.cc @@ -12,6 +12,7 @@ #include "base/thread.h" #include "base/version.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_updater.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/test_extension_prefs.h" @@ -19,7 +20,6 @@ #include "chrome/browser/pref_service.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/pref_names.h" #include "net/base/escape.h" #include "net/base/load_flags.h" diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 42c41ca..67218a5 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -22,6 +22,7 @@ #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extension_data_deleter.h" #include "chrome/browser/extensions/extension_dom_ui.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_history_api.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" @@ -35,7 +36,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/extensions/extension_file_util.h" #include "chrome/common/extensions/extension_l10n_util.h" #include "chrome/common/notification_service.h" diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 9d3e242..5ed80c9 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -20,6 +20,7 @@ #include "base/version.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_creator.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/external_extension_provider.h" #include "chrome/browser/extensions/external_pref_extension_provider.h" @@ -28,7 +29,6 @@ #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/json_value_serializer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index 9565d69..48cc7e1 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -16,6 +16,7 @@ #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_message_service.h" @@ -32,7 +33,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" -#include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/extensions/user_script.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/jstemplate_builder.h" |