summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 19:37:52 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 19:37:52 +0000
commit591948964e3088901b3d66fee2837446700d9083 (patch)
tree062993137f4a82b2a544bc0a3d8666b8b0c0b1ff /chrome/browser
parentf34b7c5bab399a1cb348e29306b0961fb572f48e (diff)
downloadchromium_src-591948964e3088901b3d66fee2837446700d9083.zip
chromium_src-591948964e3088901b3d66fee2837446700d9083.tar.gz
chromium_src-591948964e3088901b3d66fee2837446700d9083.tar.bz2
Show favicons for extensions.
This uses the 16x16 icon as defined in the manifest for extension pages. BUG=36514 TEST=Open the new bookmark manager. It should now show its favicon. Review URL: http://codereview.chromium.org/650185 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41462 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.cc10
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.h4
-rw-r--r--chrome/browser/extensions/extension_dom_ui.cc44
-rw-r--r--chrome/browser/extensions/extension_dom_ui.h4
-rw-r--r--chrome/browser/favicon_service.cc63
-rw-r--r--chrome/browser/favicon_service.h5
6 files changed, 102 insertions, 28 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc
index 86f78c5..b6de466 100644
--- a/chrome/browser/dom_ui/dom_ui_factory.cc
+++ b/chrome/browser/dom_ui/dom_ui_factory.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/dom_ui/dom_ui_factory.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/bookmarks_ui.h"
#include "chrome/browser/dom_ui/downloads_ui.h"
#include "chrome/browser/dom_ui/devtools_ui.h"
@@ -136,7 +137,14 @@ DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents,
}
// static
-RefCountedMemory* DOMUIFactory::GetFaviconResourceBytes(const GURL& page_url) {
+RefCountedMemory* DOMUIFactory::GetFaviconResourceBytes(Profile* profile,
+ const GURL& page_url) {
+ // The extensions DOM UI might need to load the favicon file so we alwyas run
+ // this on the FILE thread.
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+ if (page_url.SchemeIs(chrome::kExtensionScheme))
+ return ExtensionDOMUI::GetFaviconResourceBytes(profile, page_url);
+
if (!HasDOMUIScheme(page_url))
return NULL;
diff --git a/chrome/browser/dom_ui/dom_ui_factory.h b/chrome/browser/dom_ui/dom_ui_factory.h
index 33c32cb..7b84867 100644
--- a/chrome/browser/dom_ui/dom_ui_factory.h
+++ b/chrome/browser/dom_ui/dom_ui_factory.h
@@ -9,6 +9,7 @@
class DOMUI;
class GURL;
+class Profile;
class RefCountedMemory;
class TabContents;
@@ -43,7 +44,8 @@ class DOMUIFactory {
// Gets the data for the favicon for a DOMUI page. Returns false if the DOMUI
// does not have a favicon.
- static RefCountedMemory* GetFaviconResourceBytes(const GURL& page_url);
+ static RefCountedMemory* GetFaviconResourceBytes(Profile* profile,
+ const GURL& page_url);
private:
// Class is for scoping only.
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.
diff --git a/chrome/browser/favicon_service.cc b/chrome/browser/favicon_service.cc
index 4acf7dc..621d93b 100644
--- a/chrome/browser/favicon_service.cc
+++ b/chrome/browser/favicon_service.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/favicon_service.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/dom_ui_factory.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_backend.h"
@@ -48,29 +49,12 @@ FaviconService::Handle FaviconService::GetFaviconForURL(
FaviconDataCallback* callback) {
GetFaviconRequest* request = new GetFaviconRequest(callback);
AddRequest(request, consumer);
- FaviconService::Handle handle = request->handle();
- if (page_url.SchemeIs(chrome::kChromeUIScheme)) {
- // TODO(erg): For now, we're cheating here. DOMUIFactory returns the new
- // RefCountedMemory superclass, but consumers of favicon information are
- // still all hardcoded to use RefCountedBytes. For now, just copy the
- // favicon data in this case because the returned RefCountedMemory class is
- // the statically allocated memory one; not the vector backed
- // RefCountedBytes.
- scoped_refptr<RefCountedBytes> icon_data = NULL;
- scoped_refptr<RefCountedMemory> static_memory(
- DOMUIFactory::GetFaviconResourceBytes(page_url));
- bool know_icon = static_memory.get() != NULL;
-
- if (know_icon) {
- std::vector<unsigned char> bytes;
- bytes.insert(bytes.begin(),
- static_memory->front(),
- static_memory->front() + static_memory->size());
- icon_data = RefCountedBytes::TakeVector(&bytes);
- }
-
- request->ForwardResultAsync(FaviconDataCallback::TupleType(handle,
- know_icon, icon_data, false, GURL()));
+
+ if (page_url.SchemeIs(chrome::kChromeUIScheme) ||
+ page_url.SchemeIs(chrome::kExtensionScheme)) {
+ ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
+ NewRunnableMethod(this, &FaviconService::GetFaviconForDOMUIOnFileThread,
+ request, page_url));
} else {
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
if (hs)
@@ -78,9 +62,40 @@ FaviconService::Handle FaviconService::GetFaviconForURL(
else
ForwardEmptyResultAsync(request);
}
- return handle;
+ return request->handle();
+}
+
+void FaviconService::GetFaviconForDOMUIOnFileThread(GetFaviconRequest* request,
+ const GURL& page_url) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+ DCHECK(page_url.SchemeIs(chrome::kChromeUIScheme) ||
+ page_url.SchemeIs(chrome::kExtensionScheme));
+
+ // TODO(erg): For now, we're cheating here. DOMUIFactory returns the new
+ // RefCountedMemory superclass, but consumers of favicon information are
+ // still all hardcoded to use RefCountedBytes. For now, just copy the
+ // favicon data in this case because the returned RefCountedMemory class is
+ // the statically allocated memory one; not the vector backed
+ // RefCountedBytes.
+
+ scoped_refptr<RefCountedBytes> icon_data = NULL;
+ scoped_refptr<RefCountedMemory> static_memory(
+ DOMUIFactory::GetFaviconResourceBytes(profile_, page_url));
+ bool know_icon = static_memory.get() != NULL;
+
+ if (know_icon) {
+ std::vector<unsigned char> bytes;
+ bytes.insert(bytes.begin(),
+ static_memory->front(),
+ static_memory->front() + static_memory->size());
+ icon_data = RefCountedBytes::TakeVector(&bytes);
+ }
+
+ request->ForwardResult(FaviconDataCallback::TupleType(request->handle(),
+ know_icon, icon_data, false, GURL()));
}
+
void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) {
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
if (hs)
diff --git a/chrome/browser/favicon_service.h b/chrome/browser/favicon_service.h
index 38c3303..3cc2880 100644
--- a/chrome/browser/favicon_service.h
+++ b/chrome/browser/favicon_service.h
@@ -91,6 +91,11 @@ class FaviconService : public CancelableRequestProvider,
~FaviconService() {}
+ // This is used to get the favicon for DOMUI on the file thread since these
+ // might be loaded from disk.
+ void GetFaviconForDOMUIOnFileThread(GetFaviconRequest* request,
+ const GURL& page_url);
+
Profile* profile_;
// Helper to forward an empty result if we cannot get the history service.