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

Side by Side Diff: chrome/browser/ui/metro_pin_tab_helper.cc

Issue 10800054: Add pin icon to the omnibar in windows 8 metro mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 10
11 #if defined(OS_WIN) 11 #if defined(OS_WIN)
12 #include "base/win/metro.h" 12 #include "base/win/metro.h"
13 #endif 13 #endif
14 14
15 MetroPinTabHelper::Delegate::~Delegate() {}
16
15 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) 17 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents)
16 : content::WebContentsObserver(web_contents), 18 : content::WebContentsObserver(web_contents),
17 is_pinned_(false) {} 19 is_pinned_(false),
20 delegate_(NULL) {}
18 21
19 MetroPinTabHelper::~MetroPinTabHelper() {} 22 MetroPinTabHelper::~MetroPinTabHelper() {}
20 23
21 void MetroPinTabHelper::TogglePinnedToStartScreen() { 24 void MetroPinTabHelper::TogglePinnedToStartScreen() {
22 #if defined(OS_WIN) 25 #if defined(OS_WIN)
23 HMODULE metro_module = base::win::GetMetroModule(); 26 HMODULE metro_module = base::win::GetMetroModule();
24 if (metro_module) { 27 if (metro_module) {
25 typedef void (*MetroTogglePinnedToStartScreen)(const string16&, 28 typedef void (*MetroTogglePinnedToStartScreen)(const string16&,
26 const string16&); 29 const string16&);
27 MetroTogglePinnedToStartScreen metro_toggle_pinned_to_start_screen = 30 MetroTogglePinnedToStartScreen metro_toggle_pinned_to_start_screen =
28 reinterpret_cast<MetroTogglePinnedToStartScreen>( 31 reinterpret_cast<MetroTogglePinnedToStartScreen>(
29 ::GetProcAddress(metro_module, "MetroTogglePinnedToStartScreen")); 32 ::GetProcAddress(metro_module, "MetroTogglePinnedToStartScreen"));
30 if (!metro_toggle_pinned_to_start_screen) { 33 if (!metro_toggle_pinned_to_start_screen) {
31 NOTREACHED(); 34 NOTREACHED();
32 return; 35 return;
33 } 36 }
34 37
35 GURL url = web_contents()->GetURL(); 38 GURL url = web_contents()->GetURL();
36 string16 title = web_contents()->GetTitle(); 39 string16 title = web_contents()->GetTitle();
37 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title 40 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title
38 << " and url " << UTF8ToUTF16(url.spec()); 41 << " and url " << UTF8ToUTF16(url.spec());
39 metro_toggle_pinned_to_start_screen(title, UTF8ToUTF16(url.spec())); 42 metro_toggle_pinned_to_start_screen(title, UTF8ToUTF16(url.spec()));
40 // TODO(benwells): This will update the state incorrectly if the user 43 // TODO(benwells): This will update the state incorrectly if the user
41 // cancels. To fix this some sort of callback needs to be introduced as 44 // cancels. To fix this some sort of callback needs to be introduced as
42 // the pinning happens on another thread. 45 // the pinning happens on another thread.
43 is_pinned_ = !is_pinned_; 46 SetIsPinned(!is_pinned_);
44 return;
45 } 47 }
46 #endif 48 #endif
47 } 49 }
48 50
49 void MetroPinTabHelper::DidNavigateMainFrame( 51 void MetroPinTabHelper::DidNavigateMainFrame(
50 const content::LoadCommittedDetails& /*details*/, 52 const content::LoadCommittedDetails& /*details*/,
51 const content::FrameNavigateParams& /*params*/) { 53 const content::FrameNavigateParams& /*params*/) {
52 UpdatePinnedStateForCurrentURL(); 54 UpdatePinnedStateForCurrentURL();
53 } 55 }
54 56
55 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { 57 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() {
56 #if defined(OS_WIN) 58 #if defined(OS_WIN)
57 HMODULE metro_module = base::win::GetMetroModule(); 59 HMODULE metro_module = base::win::GetMetroModule();
58 if (metro_module) { 60 if (metro_module) {
59 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); 61 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&);
60 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen = 62 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen =
61 reinterpret_cast<MetroIsPinnedToStartScreen>( 63 reinterpret_cast<MetroIsPinnedToStartScreen>(
62 ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen")); 64 ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen"));
63 if (!metro_is_pinned_to_start_screen) { 65 if (!metro_is_pinned_to_start_screen) {
64 NOTREACHED(); 66 NOTREACHED();
65 return; 67 return;
66 } 68 }
67 69
68 GURL url = web_contents()->GetURL(); 70 GURL url = web_contents()->GetURL();
69 is_pinned_ = metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0; 71 SetIsPinned(metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0);
70 VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec()) 72 VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec())
71 << " result: " << is_pinned_; 73 << " result: " << is_pinned_;
72 } 74 }
73 #endif 75 #endif
74 } 76 }
77
78 void MetroPinTabHelper::SetIsPinned(bool is_pinned) {
79 bool was_pinned = is_pinned_;
80 is_pinned_ = is_pinned;
81 if (delegate_ && is_pinned_ != was_pinned)
82 delegate_->IsPinnedChanged(web_contents(), is_pinned_);
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698