| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/metro_pin_tab_helper.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 |
| 11 #if defined(OS_WIN) |
| 12 #include "base/win/metro.h" |
| 13 #endif |
| 14 |
| 15 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) |
| 16 : content::WebContentsObserver(web_contents), |
| 17 is_pinned_(false) {} |
| 18 |
| 19 MetroPinTabHelper::~MetroPinTabHelper() {} |
| 20 |
| 21 void MetroPinTabHelper::TogglePinnedToStartScreen() { |
| 22 #if defined(OS_WIN) |
| 23 HMODULE metro_module = base::win::GetMetroModule(); |
| 24 if (metro_module) { |
| 25 typedef void (*MetroTogglePinnedToStartScreen)(const string16&, |
| 26 const string16&); |
| 27 MetroTogglePinnedToStartScreen metro_toggle_pinned_to_start_screen = |
| 28 reinterpret_cast<MetroTogglePinnedToStartScreen>( |
| 29 ::GetProcAddress(metro_module, "MetroTogglePinnedToStartScreen")); |
| 30 if (!metro_toggle_pinned_to_start_screen) { |
| 31 NOTREACHED(); |
| 32 return; |
| 33 } |
| 34 |
| 35 GURL url = web_contents()->GetURL(); |
| 36 string16 title = web_contents()->GetTitle(); |
| 37 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title |
| 38 << " and url " << UTF8ToUTF16(url.spec()); |
| 39 metro_toggle_pinned_to_start_screen(title, UTF8ToUTF16(url.spec())); |
| 40 // 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 |
| 42 // the pinning happens on another thread. |
| 43 is_pinned_ = !is_pinned_; |
| 44 return; |
| 45 } |
| 46 #endif |
| 47 } |
| 48 |
| 49 void MetroPinTabHelper::DidNavigateMainFrame( |
| 50 const content::LoadCommittedDetails& /*details*/, |
| 51 const content::FrameNavigateParams& /*params*/) { |
| 52 UpdatePinnedStateForCurrentURL(); |
| 53 } |
| 54 |
| 55 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { |
| 56 #if defined(OS_WIN) |
| 57 HMODULE metro_module = base::win::GetMetroModule(); |
| 58 if (metro_module) { |
| 59 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); |
| 60 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen = |
| 61 reinterpret_cast<MetroIsPinnedToStartScreen>( |
| 62 ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen")); |
| 63 if (!metro_is_pinned_to_start_screen) { |
| 64 NOTREACHED(); |
| 65 return; |
| 66 } |
| 67 |
| 68 GURL url = web_contents()->GetURL(); |
| 69 is_pinned_ = metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0; |
| 70 VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec()) |
| 71 << " result: " << is_pinned_; |
| 72 } |
| 73 #endif |
| 74 } |
| OLD | NEW |