Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Unified Diff: chrome/browser/ui/metro_pin_tab_helper.cc

Issue 11198025: Site specific secondary tiles for Windows 8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/metro_pin_tab_helper.cc
diff --git a/chrome/browser/ui/metro_pin_tab_helper.cc b/chrome/browser/ui/metro_pin_tab_helper.cc
index 7644355c6a5b8506d5e333410e3cdf638f928b9b..8c877c3880c2668325b95e7ba9ca013a61954e21 100644
--- a/chrome/browser/ui/metro_pin_tab_helper.cc
+++ b/chrome/browser/ui/metro_pin_tab_helper.cc
@@ -6,7 +6,11 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "content/public/browser/web_contents.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/image/image.h"
#if defined(OS_WIN)
sky 2012/10/19 16:09:56 Isn't this whole file windows specific?
benwells 2012/10/22 06:20:47 It's only used on windows, yes. I've only put the
sky 2012/10/22 15:51:21 Yes please. Additionally move this out of TabConte
#include "base/win/metro.h"
@@ -21,31 +25,39 @@ MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents)
MetroPinTabHelper::~MetroPinTabHelper() {}
void MetroPinTabHelper::TogglePinnedToStartScreen() {
-#if defined(OS_WIN)
- HMODULE metro_module = base::win::GetMetroModule();
- if (metro_module) {
- typedef void (*MetroTogglePinnedToStartScreen)(const string16&,
- const string16&);
- MetroTogglePinnedToStartScreen metro_toggle_pinned_to_start_screen =
- reinterpret_cast<MetroTogglePinnedToStartScreen>(
- ::GetProcAddress(metro_module, "MetroTogglePinnedToStartScreen"));
- if (!metro_toggle_pinned_to_start_screen) {
- NOTREACHED();
- return;
- }
+ UpdatePinnedStateForCurrentURL();
+ bool was_pinned = is_pinned_;
- GURL url = web_contents()->GetURL();
- string16 title = web_contents()->GetTitle();
- VLOG(1) << __FUNCTION__ << " calling pin with title: " << title
- << " and url " << UTF8ToUTF16(url.spec());
- metro_toggle_pinned_to_start_screen(title, UTF8ToUTF16(url.spec()));
- // TODO(benwells): This will update the state incorrectly if the user
- // cancels. To fix this some sort of callback needs to be introduced as
- // the pinning happens on another thread.
- is_pinned_ = !is_pinned_;
+ // TODO(benwells): This will update the state incorrectly if the user
+ // cancels. To fix this some sort of callback needs to be introduced as
+ // the pinning happens on another thread.
+ is_pinned_ = !is_pinned_;
+
+ if (was_pinned) {
+ UnPinPageFromStartScreen();
return;
}
-#endif
+
+ // TODO(benwells): Handle downloading a larger favicon if there is one.
+ GURL url = web_contents()->GetURL();
+ string16 url_str = UTF8ToUTF16(url.spec());
+ string16 title = web_contents()->GetTitle();
+ TabContents* tab_contents = TabContents::FromWebContents(web_contents());
+ DCHECK(tab_contents);
+ FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents(
+ tab_contents->web_contents());
+ // TODO(benwells): Handle the case where there is a favicon for the site but
+ // it isn't downloaded yet.
+ if (favicon_tab_helper->FaviconIsValid()) {
+ gfx::Image favicon = favicon_tab_helper->GetFavicon();
+ if (!favicon.IsEmpty()) {
+ const SkBitmap* favicon_skia = favicon.ToSkBitmap();
+ PinPageToStartScreen(title, url_str, favicon_skia);
+ return;
+ }
+ }
+
+ PinPageToStartScreen(title, url_str, NULL);
}
void MetroPinTabHelper::DidNavigateMainFrame(
@@ -74,3 +86,48 @@ void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() {
}
#endif
}
+
+void MetroPinTabHelper::PinPageToStartScreen(
+ const string16& title,
+ const string16& url,
+ const SkBitmap* bitmap) {
+#if defined(OS_WIN)
+ HMODULE metro_module = base::win::GetMetroModule();
+ if (metro_module) {
+ typedef void (*MetroPinToStartScreen)(const string16&,
+ const string16&, const SkBitmap*);
+ MetroPinToStartScreen metro_pin_to_start_screen =
+ reinterpret_cast<MetroPinToStartScreen>(
+ ::GetProcAddress(metro_module, "MetroPinToStartScreen"));
+ if (!metro_pin_to_start_screen) {
+ NOTREACHED();
+ return;
+ }
+
+ VLOG(1) << __FUNCTION__ << " calling pin with title: " << title
+ << " and url: " << url;
+ metro_pin_to_start_screen(title, url, bitmap);
+ }
+#endif
+}
+
+void MetroPinTabHelper::UnPinPageFromStartScreen() {
+#if defined(OS_WIN)
+ HMODULE metro_module = base::win::GetMetroModule();
+ if (metro_module) {
+ typedef void (*MetroUnPinFromStartScreen)(const string16&);
+ MetroUnPinFromStartScreen metro_un_pin_from_start_screen =
+ reinterpret_cast<MetroUnPinFromStartScreen>(
+ ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen"));
+ if (!metro_un_pin_from_start_screen) {
+ NOTREACHED();
+ return;
+ }
+
+ GURL url = web_contents()->GetURL();
+ VLOG(1) << __FUNCTION__ << " calling unpin with url: "
+ << UTF8ToUTF16(url.spec());
+ metro_un_pin_from_start_screen(UTF8ToUTF16(url.spec()));
+ }
+#endif
+}

Powered by Google App Engine
This is Rietveld 408576698