diff options
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_dom_ui.cc | 44 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_dom_ui.h | 4 |
2 files changed, 46 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc index 926b5d7..424dd80e 100644 --- a/chrome/browser/extensions/extension_dom_ui.cc +++ b/chrome/browser/extensions/extension_dom_ui.cc @@ -4,9 +4,13 @@ #include "chrome/browser/extensions/extension_dom_ui.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "net/base/file_stream.h" #include "base/string_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/extensions/extension_bookmark_manager_api.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/pref_service.h" @@ -15,16 +19,35 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/extensions/extension.h" #include "chrome/common/url_constants.h" namespace { const wchar_t kExtensionURLOverrides[] = L"extensions.chrome_url_overrides"; + +// Returns a piece of memory with the contents of the file |path|. +RefCountedMemory* ReadFileData(const FilePath& path) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); + + if (path.empty()) + return NULL; + + RefCountedBytes* result = new RefCountedBytes; + std::string content; + if (!file_util::ReadFileToString(path, &content)) + return NULL; + + result->data.resize(content.size()); + std::copy(content.begin(), content.end(), + result->data.begin()); + + return result; } +} // namespace + ExtensionDOMUI::ExtensionDOMUI(TabContents* tab_contents) : DOMUI(tab_contents) { - // TODO(aa): It would be cool to show the extension's icon in here. - hide_favicon_ = true; should_hide_url_ = true; bindings_ = BindingsPolicy::EXTENSION; @@ -290,3 +313,20 @@ void ExtensionDOMUI::UnregisterChromeURLOverrides( } } } + +// static +RefCountedMemory* ExtensionDOMUI::GetFaviconResourceBytes(Profile* profile, + GURL page_url) { + // Even when the extensions service is enabled by default, it's still + // disabled in incognito mode. + ExtensionsService* service = profile->GetExtensionsService(); + if (!service) + return NULL; + + Extension* extension = service->GetExtensionByURL(page_url); + if (!extension) + return NULL; + + return ReadFileData( + extension->GetIconPath(Extension::EXTENSION_ICON_BITTY).GetFilePath()); +} diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h index 42724575..fd98355 100644 --- a/chrome/browser/extensions/extension_dom_ui.h +++ b/chrome/browser/extensions/extension_dom_ui.h @@ -16,6 +16,7 @@ class ListValue; class PrefService; +class Profile; class RefCountedMemory; class RenderViewHost; class TabContents; @@ -74,6 +75,9 @@ class ExtensionDOMUI // Called from BrowserPrefs static void RegisterUserPrefs(PrefService* prefs); + static RefCountedMemory* GetFaviconResourceBytes(Profile* profile, + GURL page_url); + private: // Unregister the specified override, and if it's the currently active one, // ensure that something takes its place. |