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

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

Issue 10801006: Allow secondary tiles to be unpinned. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove NULL check 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/metro_pin_tab_helper.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..0a16543cdfdffc42f1b389fe0db7a5a0e9988daf
--- /dev/null
+++ b/chrome/browser/ui/metro_pin_tab_helper.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/metro_pin_tab_helper.h"
+
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "content/public/browser/web_contents.h"
+
+#if defined(OS_WIN)
+#include "base/win/metro.h"
+#endif
+
+MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents),
+ is_pinned_(false) {}
+
+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;
+ }
+
+ 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_;
+ return;
+ }
+#endif
+}
+
+void MetroPinTabHelper::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& /*details*/,
+ const content::FrameNavigateParams& /*params*/) {
+ UpdatePinnedStateForCurrentURL();
+}
+
+void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() {
+#if defined(OS_WIN)
+ HMODULE metro_module = base::win::GetMetroModule();
+ if (metro_module) {
+ typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&);
+ MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen =
+ reinterpret_cast<MetroIsPinnedToStartScreen>(
+ ::GetProcAddress(metro_module, "MetroIsPinnedToStartScreen"));
+ if (!metro_is_pinned_to_start_screen) {
+ NOTREACHED();
+ return;
+ }
+
+ GURL url = web_contents()->GetURL();
+ is_pinned_ = metro_is_pinned_to_start_screen(UTF8ToUTF16(url.spec())) != 0;
+ VLOG(1) << __FUNCTION__ << " with url " << UTF8ToUTF16(url.spec())
+ << " result: " << is_pinned_;
+ }
+#endif
+}
« no previous file with comments | « chrome/browser/ui/metro_pin_tab_helper.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698