| 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 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) | |
| 16 | |
| 17 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) | |
| 18 : content::WebContentsObserver(web_contents), | |
| 19 is_pinned_(false) {} | |
| 20 | |
| 21 MetroPinTabHelper::~MetroPinTabHelper() {} | |
| 22 | |
| 23 void MetroPinTabHelper::TogglePinnedToStartScreen() { | |
| 24 #if defined(OS_WIN) | |
| 25 HMODULE metro_module = base::win::GetMetroModule(); | |
| 26 if (metro_module) { | |
| 27 typedef void (*MetroTogglePinnedToStartScreen)(const string16&, | |
| 28 const string16&); | |
| 29 MetroTogglePinnedToStartScreen metro_toggle_pinned_to_start_screen = | |
| 30 reinterpret_cast<MetroTogglePinnedToStartScreen>( | |
| 31 ::GetProcAddress(metro_module, "MetroTogglePinnedToStartScreen")); | |
| 32 if (!metro_toggle_pinned_to_start_screen) { | |
| 33 NOTREACHED(); | |
| 34 return; | |
| 35 } | |
| 36 | |
| 37 GURL url = web_contents()->GetURL(); | |
| 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 } | |
| 50 | |
| 51 void MetroPinTabHelper::DidNavigateMainFrame( | |
| 52 const content::LoadCommittedDetails& /*details*/, | |
| 53 const content::FrameNavigateParams& /*params*/) { | |
| 54 UpdatePinnedStateForCurrentURL(); | |
| 55 } | |
| 56 | |
| 57 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { | |
| 58 #if defined(OS_WIN) | |
| 59 HMODULE metro_module = base::win::GetMetroModule(); | |
| 60 if (metro_module) { | |
| 61 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); | |
| 62 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen = | |
| 63 reinterpret_cast<MetroIsPinnedToStartScreen>( | |
| 64 ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen")); | |
| 65 if (!metro_is_pinned_to_start_screen) { | |
| 66 NOTREACHED(); | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 GURL url = web_contents()->GetURL(); | |
| 71 is_pinned_ = metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0; | |
| 72 VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec()) | |
| 73 << " result: " << is_pinned_; | |
| 74 } | |
| 75 #endif | |
| 76 } | |
| OLD | NEW |