diff options
-rw-r--r-- | chrome/browser/extensions/extension.cc | 32 | ||||
-rw-r--r-- | chrome/browser/extensions/extension.h | 16 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 31 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 7 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 22 |
6 files changed, 60 insertions, 52 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index de90637..a11afb0 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -16,23 +16,23 @@ const wchar_t* Extension::kNameKey = L"name"; const wchar_t* Extension::kDescriptionKey = L"description"; const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; -const wchar_t* Extension::kInvalidManifestError = - L"Manifest is missing or invalid."; -const wchar_t* Extension::kInvalidFormatVersionError = - L"Required key 'format_version' is missing or invalid"; -const wchar_t* Extension::kInvalidIdError = - L"Required key 'id' is missing or invalid."; -const wchar_t* Extension::kInvalidNameError = - L"Required key 'name' is missing or has invalid type."; -const wchar_t* Extension::kInvalidDescriptionError = - L"Invalid type for 'description' key."; -const wchar_t* Extension::kInvalidContentScriptsListError = - L"Invalid type for 'content_scripts' key."; -const wchar_t* Extension::kInvalidContentScriptError = - L"Invalid type for content_scripts at index "; +const char* Extension::kInvalidManifestError = + "Manifest is missing or invalid."; +const char* Extension::kInvalidFormatVersionError = + "Required key 'format_version' is missing or invalid"; +const char* Extension::kInvalidIdError = + "Required key 'id' is missing or invalid."; +const char* Extension::kInvalidNameError = + "Required key 'name' is missing or has invalid type."; +const char* Extension::kInvalidDescriptionError = + "Invalid type for 'description' key."; +const char* Extension::kInvalidContentScriptsListError = + "Invalid type for 'content_scripts' key."; +const char* Extension::kInvalidContentScriptError = + "Invalid type for content_scripts at index "; bool Extension::InitFromValue(const DictionaryValue& source, - std::wstring* error) { + std::string* error) { // Check format version. int format_version = 0; if (!source.GetInteger(kFormatVersionKey, &format_version) || @@ -76,7 +76,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, std::wstring content_script; if (!list_value->Get(i, &value) || !value->GetAsString(&content_script)) { *error = kInvalidContentScriptError; - *error += IntToWString(i); + *error += IntToString(i); return false; } diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h index 94127ac..6b9ba52 100644 --- a/chrome/browser/extensions/extension.h +++ b/chrome/browser/extensions/extension.h @@ -31,13 +31,13 @@ class Extension { static const wchar_t* kContentScriptsKey; // Error messages returned from InitFromValue(). - static const wchar_t* kInvalidFormatVersionError; - static const wchar_t* kInvalidManifestError; - static const wchar_t* kInvalidIdError; - static const wchar_t* kInvalidNameError; - static const wchar_t* kInvalidDescriptionError; - static const wchar_t* kInvalidContentScriptsListError; - static const wchar_t* kInvalidContentScriptError; + static const char* kInvalidFormatVersionError; + static const char* kInvalidManifestError; + static const char* kInvalidIdError; + static const char* kInvalidNameError; + static const char* kInvalidDescriptionError; + static const char* kInvalidContentScriptsListError; + static const char* kInvalidContentScriptError; // A human-readable ID for the extension. The convention is to use something // like 'com.example.myextension', but this is not currently enforced. An @@ -59,7 +59,7 @@ class Extension { } // Initialize the extension from a parsed manifest. - bool InitFromValue(const DictionaryValue& value, std::wstring* error); + bool InitFromValue(const DictionaryValue& value, std::string* error); // Serialize the extension to a DictionaryValue. void CopyToValue(DictionaryValue* value); diff --git a/chrome/browser/extensions/extension_unittest.cc b/chrome/browser/extensions/extension_unittest.cc index 2377dae..7aa51a0 100644 --- a/chrome/browser/extensions/extension_unittest.cc +++ b/chrome/browser/extensions/extension_unittest.cc @@ -11,7 +11,7 @@ class ExtensionTest : public testing::Test { TEST(ExtensionTest, InitFromValueInvalid) { Extension extension; - std::wstring error; + std::string error; // Test invalid format version DictionaryValue input_value; @@ -57,7 +57,7 @@ TEST(ExtensionTest, InitFromValueInvalid) { TEST(ExtensionTest, InitFromValueValid) { Extension extension; - std::wstring error; + std::string error; DictionaryValue input_value; DictionaryValue output_value; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 32cc861..a9810c0 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -55,11 +55,10 @@ void ExtensionsService::OnExtensionsLoadedFromDirectory( // TODO(aa): Notify extensions are loaded. } -void ExtensionsService::OnExtensionLoadError(const std::wstring& error) { - // TODO(aa): Print the error message out somewhere better. Ideally we would - // use the JavaScript console I think, but that is complicated since these - // errors are not related to any particular page. - LOG(WARNING) << "Error loading extension: " << error; +void ExtensionsService::OnExtensionLoadError(const std::string& error) { + // TODO(aa): Print the error message out somewhere better. I think we are + // going to need some sort of 'extension inspector'. + LOG(WARNING) << error; } @@ -79,35 +78,34 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory( FilePath manifest_path = FilePath::FromWStringHack(child_path).Append( Extension::kManifestFilename); if (!file_util::PathExists(manifest_path)) { - ReportExtensionLoadError(frontend.get(), + ReportExtensionLoadError(frontend.get(), child_path, Extension::kInvalidManifestError); continue; } JSONFileValueSerializer serializer(manifest_path.ToWStringHack()); Value* root = NULL; - if (!serializer.Deserialize(&root, NULL)) { - ReportExtensionLoadError(frontend.get(), - Extension::kInvalidManifestError); + std::string error; + if (!serializer.Deserialize(&root, &error)) { + ReportExtensionLoadError(frontend.get(), child_path, error); continue; } if (!root->IsType(Value::TYPE_DICTIONARY)) { - ReportExtensionLoadError(frontend.get(), + ReportExtensionLoadError(frontend.get(), child_path, Extension::kInvalidManifestError); continue; } scoped_ptr<Extension> extension(new Extension()); - std::wstring error; if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root), &error)) { - ReportExtensionLoadError(frontend.get(), - Extension::kInvalidManifestError); + ReportExtensionLoadError(frontend.get(), child_path, error); continue; } extensions->push_back(extension.release()); + delete root; } ReportExtensionsLoaded(frontend.get(), extensions.release()); @@ -115,10 +113,13 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory( } void ExtensionsServiceBackend::ReportExtensionLoadError( - ExtensionsServiceFrontendInterface *frontend, const std::wstring &error) { + ExtensionsServiceFrontendInterface *frontend, const std::wstring& path, + const std::string &error) { + std::string message = StringPrintf("Could not load extension from '%s'. %s", + WideToASCII(path).c_str(), error.c_str()); frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod( frontend, &ExtensionsServiceFrontendInterface::OnExtensionLoadError, - error)); + message)); } void ExtensionsServiceBackend::ReportExtensionsLoaded( diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 17f25b7..ed5a81c 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -27,7 +27,7 @@ class ExtensionsServiceFrontendInterface virtual MessageLoop* GetMessageLoop() = 0; // Called when loading an extension fails. - virtual void OnExtensionLoadError(const std::wstring& message) = 0; + virtual void OnExtensionLoadError(const std::string& message) = 0; // Called with results from LoadExtensionsFromDirectory(). The frontend // takes ownership of the list. @@ -51,7 +51,7 @@ class ExtensionsService : public ExtensionsServiceFrontendInterface { // ExtensionsServiceFrontendInterface virtual MessageLoop* GetMessageLoop(); - virtual void OnExtensionLoadError(const std::wstring& message); + virtual void OnExtensionLoadError(const std::string& message); virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions); private: @@ -94,7 +94,8 @@ class ExtensionsServiceBackend private: // Notify a frontend that there was an error loading an extension. void ReportExtensionLoadError(ExtensionsServiceFrontendInterface* frontend, - const std::wstring& error); + const std::wstring& path, + const std::string& error); // Notify a frontend that extensions were loaded. void ReportExtensionsLoaded(ExtensionsServiceFrontendInterface* frontend, diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index da86f27..b3e4880 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -21,12 +21,19 @@ class ExtensionsServiceTestFrontend : public ExtensionsServiceFrontendInterface { public: - std::vector<std::wstring>* errors() { + ~ExtensionsServiceTestFrontend() { + for (ExtensionList::iterator iter = extensions_.begin(); + iter != extensions_.end(); ++iter) { + delete *iter; + } + } + + std::vector<std::string>* errors() { return &errors_; } ExtensionList* extensions() { - return extensions_.get(); + return &extensions_; } // ExtensionsServiceFrontendInterface @@ -34,18 +41,19 @@ class ExtensionsServiceTestFrontend return &message_loop_; } - virtual void OnExtensionLoadError(const std::wstring& message) { + virtual void OnExtensionLoadError(const std::string& message) { errors_.push_back(message); } virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions) { - extensions_.reset(extensions); + extensions_.assign(extensions->begin(), extensions->end()); + delete extensions; } private: MessageLoop message_loop_; - scoped_ptr<ExtensionList> extensions_; - std::vector<std::wstring> errors_; + ExtensionList extensions_; + std::vector<std::string> errors_; }; // make the test a PlatformTest to setup autorelease pools properly on mac @@ -70,8 +78,6 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { // Note: There can be more errors if there are extra directories, like .svn // directories. EXPECT_TRUE(frontend->errors()->size() >= 2u); - EXPECT_EQ(Extension::kInvalidManifestError, frontend->errors()->at(0)); - EXPECT_EQ(Extension::kInvalidManifestError, frontend->errors()->at(1)); EXPECT_EQ(2u, frontend->extensions()->size()); EXPECT_EQ(std::wstring(L"com.google.myextension1"), |