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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/metro_pin_tab_helper.h" 5 #include "chrome/browser/ui/metro_pin_tab_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/favicon/favicon_tab_helper.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
9 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/image/image.h"
10 14
11 #if defined(OS_WIN) 15 #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
12 #include "base/win/metro.h" 16 #include "base/win/metro.h"
13 #endif 17 #endif
14 18
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper)
16 20
17 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) 21 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents)
18 : content::WebContentsObserver(web_contents), 22 : content::WebContentsObserver(web_contents),
19 is_pinned_(false) {} 23 is_pinned_(false) {}
20 24
21 MetroPinTabHelper::~MetroPinTabHelper() {} 25 MetroPinTabHelper::~MetroPinTabHelper() {}
22 26
23 void MetroPinTabHelper::TogglePinnedToStartScreen() { 27 void MetroPinTabHelper::TogglePinnedToStartScreen() {
24 #if defined(OS_WIN) 28 UpdatePinnedStateForCurrentURL();
25 HMODULE metro_module = base::win::GetMetroModule(); 29 bool was_pinned = is_pinned_;
26 if (metro_module) { 30
27 typedef void (*MetroTogglePinnedToStartScreen)(const string16&, 31 // TODO(benwells): This will update the state incorrectly if the user
28 const string16&); 32 // cancels. To fix this some sort of callback needs to be introduced as
29 MetroTogglePinnedToStartScreen metro_toggle_pinned_to_start_screen = 33 // the pinning happens on another thread.
30 reinterpret_cast<MetroTogglePinnedToStartScreen>( 34 is_pinned_ = !is_pinned_;
31 ::GetProcAddress(metro_module, "MetroTogglePinnedToStartScreen")); 35
32 if (!metro_toggle_pinned_to_start_screen) { 36 if (was_pinned) {
33 NOTREACHED(); 37 UnPinPageFromStartScreen();
38 return;
39 }
40
41 // TODO(benwells): Handle downloading a larger favicon if there is one.
42 GURL url = web_contents()->GetURL();
43 string16 url_str = UTF8ToUTF16(url.spec());
44 string16 title = web_contents()->GetTitle();
45 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
46 DCHECK(tab_contents);
47 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents(
48 tab_contents->web_contents());
49 // TODO(benwells): Handle the case where there is a favicon for the site but
50 // it isn't downloaded yet.
51 if (favicon_tab_helper->FaviconIsValid()) {
52 gfx::Image favicon = favicon_tab_helper->GetFavicon();
53 if (!favicon.IsEmpty()) {
54 const SkBitmap* favicon_skia = favicon.ToSkBitmap();
55 PinPageToStartScreen(title, url_str, favicon_skia);
34 return; 56 return;
35 } 57 }
58 }
36 59
37 GURL url = web_contents()->GetURL(); 60 PinPageToStartScreen(title, url_str, NULL);
38 string16 title = web_contents()->GetTitle();
39 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title
40 << " and url " << UTF8ToUTF16(url.spec());
41 metro_toggle_pinned_to_start_screen(title, UTF8ToUTF16(url.spec()));
42 // TODO(benwells): This will update the state incorrectly if the user
43 // cancels. To fix this some sort of callback needs to be introduced as
44 // the pinning happens on another thread.
45 is_pinned_ = !is_pinned_;
46 return;
47 }
48 #endif
49 } 61 }
50 62
51 void MetroPinTabHelper::DidNavigateMainFrame( 63 void MetroPinTabHelper::DidNavigateMainFrame(
52 const content::LoadCommittedDetails& /*details*/, 64 const content::LoadCommittedDetails& /*details*/,
53 const content::FrameNavigateParams& /*params*/) { 65 const content::FrameNavigateParams& /*params*/) {
54 UpdatePinnedStateForCurrentURL(); 66 UpdatePinnedStateForCurrentURL();
55 } 67 }
56 68
57 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { 69 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() {
58 #if defined(OS_WIN) 70 #if defined(OS_WIN)
59 HMODULE metro_module = base::win::GetMetroModule(); 71 HMODULE metro_module = base::win::GetMetroModule();
60 if (metro_module) { 72 if (metro_module) {
61 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); 73 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&);
62 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen = 74 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen =
63 reinterpret_cast<MetroIsPinnedToStartScreen>( 75 reinterpret_cast<MetroIsPinnedToStartScreen>(
64 ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen")); 76 ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen"));
65 if (!metro_is_pinned_to_start_screen) { 77 if (!metro_is_pinned_to_start_screen) {
66 NOTREACHED(); 78 NOTREACHED();
67 return; 79 return;
68 } 80 }
69 81
70 GURL url = web_contents()->GetURL(); 82 GURL url = web_contents()->GetURL();
71 is_pinned_ = metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0; 83 is_pinned_ = metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0;
72 VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec()) 84 VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec())
73 << " result: " << is_pinned_; 85 << " result: " << is_pinned_;
74 } 86 }
75 #endif 87 #endif
76 } 88 }
89
90 void MetroPinTabHelper::PinPageToStartScreen(
91 const string16& title,
92 const string16& url,
93 const SkBitmap* bitmap) {
94 #if defined(OS_WIN)
95 HMODULE metro_module = base::win::GetMetroModule();
96 if (metro_module) {
97 typedef void (*MetroPinToStartScreen)(const string16&,
98 const string16&, const SkBitmap*);
99 MetroPinToStartScreen metro_pin_to_start_screen =
100 reinterpret_cast<MetroPinToStartScreen>(
101 ::GetProcAddress(metro_module, "MetroPinToStartScreen"));
102 if (!metro_pin_to_start_screen) {
103 NOTREACHED();
104 return;
105 }
106
107 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title
108 << " and url: " << url;
109 metro_pin_to_start_screen(title, url, bitmap);
110 }
111 #endif
112 }
113
114 void MetroPinTabHelper::UnPinPageFromStartScreen() {
115 #if defined(OS_WIN)
116 HMODULE metro_module = base::win::GetMetroModule();
117 if (metro_module) {
118 typedef void (*MetroUnPinFromStartScreen)(const string16&);
119 MetroUnPinFromStartScreen metro_un_pin_from_start_screen =
120 reinterpret_cast<MetroUnPinFromStartScreen>(
121 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen"));
122 if (!metro_un_pin_from_start_screen) {
123 NOTREACHED();
124 return;
125 }
126
127 GURL url = web_contents()->GetURL();
128 VLOG(1) << __FUNCTION__ << " calling unpin with url: "
129 << UTF8ToUTF16(url.spec());
130 metro_un_pin_from_start_screen(UTF8ToUTF16(url.spec()));
131 }
132 #endif
133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698