diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/ui/browser_command_controller.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/browser_commands.cc | 7 | ||||
-rw-r--r-- | chrome/browser/ui/browser_commands.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/browser_win.cc | 24 | ||||
-rw-r--r-- | chrome/browser/ui/metro_pin_tab_helper.cc | 74 | ||||
-rw-r--r-- | chrome/browser/ui/metro_pin_tab_helper.h | 35 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/toolbar/wrench_menu_model.cc | 13 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
11 files changed, 143 insertions, 30 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index f3ac0d8..27cb7d4 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -948,6 +948,9 @@ Psst! Incognito mode <ph name="SHORTCUT_KEY">$1<ex>(Ctrl+Shift+N)</ex></ph> may <message name="IDS_PIN_TO_START_SCREEN" desc="The text label of the Pin to start screen menu item"> Pin to Start Screen </message> + <message name="IDS_UNPIN_FROM_START_SCREEN" desc="The text label of the unpin from start screen menu item"> + Unpin from Start Screen + </message> <message name="IDS_EDIT2" desc="The text label before the cut/copy/paste buttons in the merged menu"> Edit </message> @@ -1037,6 +1040,9 @@ Psst! Incognito mode <ph name="SHORTCUT_KEY">$1<ex>(Ctrl+Shift+N)</ex></ph> may <message name="IDS_PIN_TO_START_SCREEN" desc="In Title Case: The text label of the Pin to start screen menu item"> Pin to Start Screen </message> + <message name="IDS_UNPIN_FROM_START_SCREEN" desc="In Title Case: The text label of the Unpin from start screen menu item"> + Unpin from Start Screen + </message> <message name="IDS_UNDO" desc="In Title Case: The text label of the Undo menu item"> &Undo </message> diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index 29ab1f7..f2d7be6 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -352,7 +352,7 @@ void BrowserCommandController::ExecuteCommandWithDisposition( BookmarkCurrentPage(browser_); break; case IDC_PIN_TO_START_SCREEN: - PinCurrentPageToStartScreen(browser_); + TogglePagePinnedToStartScreen(browser_); break; case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(browser_); diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index 5ff86c5..5fdb3c1 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -41,6 +41,7 @@ #include "chrome/browser/ui/find_bar/find_bar_controller.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" +#include "chrome/browser/ui/metro_pin_tab_helper.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/search/search_model.h" @@ -599,10 +600,10 @@ bool CanBookmarkAllTabs(const Browser* browser) { return browser->tab_count() > 1 && CanBookmarkCurrentPage(browser); } -#if !defined(OS_WIN) -void PinCurrentPageToStartScreen(Browser* browser) { +void TogglePagePinnedToStartScreen(Browser* browser) { + GetActiveTabContents(browser)->metro_pin_tab_helper()-> + TogglePinnedToStartScreen(); } -#endif void SavePage(Browser* browser) { content::RecordAction(UserMetricsAction("SavePage")); diff --git a/chrome/browser/ui/browser_commands.h b/chrome/browser/ui/browser_commands.h index efe9490..477291c 100644 --- a/chrome/browser/ui/browser_commands.h +++ b/chrome/browser/ui/browser_commands.h @@ -90,7 +90,7 @@ void BookmarkCurrentPage(Browser* browser); bool CanBookmarkCurrentPage(const Browser* browser); void BookmarkAllTabs(Browser* browser); bool CanBookmarkAllTabs(const Browser* browser); -void PinCurrentPageToStartScreen(Browser* browser); +void TogglePagePinnedToStartScreen(Browser* browser); void SavePage(Browser* browser); bool CanSavePage(const Browser* browser); void ShowFindBar(Browser* browser); diff --git a/chrome/browser/ui/browser_win.cc b/chrome/browser/ui/browser_win.cc index 04e203f..b4498b0 100644 --- a/chrome/browser/ui/browser_win.cc +++ b/chrome/browser/ui/browser_win.cc @@ -58,30 +58,6 @@ void NewIncognitoWindow(Browser* browser) { NewEmptyWindow(browser->profile()->GetOffTheRecordProfile()); } -void PinCurrentPageToStartScreen(Browser* browser) { - HMODULE metro_module = base::win::GetMetroModule(); - if (metro_module) { - GURL url; - string16 title; - TabContents* tab = chrome::GetActiveTabContents(browser); - bookmark_utils::GetURLAndTitleToBookmark(tab->web_contents(), &url, &title); - - typedef BOOL (*MetroPinUrlToStartScreen)(const string16&, const string16&); - MetroPinUrlToStartScreen metro_pin_url_to_start_screen = - reinterpret_cast<MetroPinUrlToStartScreen>( - ::GetProcAddress(metro_module, "MetroPinUrlToStartScreen")); - if (!metro_pin_url_to_start_screen) { - NOTREACHED(); - return; - } - - VLOG(1) << __FUNCTION__ << " calling pin with title: " << title - << " and url " << UTF8ToUTF16(url.spec()); - metro_pin_url_to_start_screen(title, UTF8ToUTF16(url.spec())); - return; - } -} - } // namespace chrome void Browser::SetMetroSnapMode(bool enable) { 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 0000000..0a16543 --- /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 +} diff --git a/chrome/browser/ui/metro_pin_tab_helper.h b/chrome/browser/ui/metro_pin_tab_helper.h new file mode 100644 index 0000000..c72e503 --- /dev/null +++ b/chrome/browser/ui/metro_pin_tab_helper.h @@ -0,0 +1,35 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_H_ +#define CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_H_ + +#include "content/public/browser/web_contents_observer.h" + +// Per-tab class to help manage metro pinning. +class MetroPinTabHelper : public content::WebContentsObserver { + public: + explicit MetroPinTabHelper(content::WebContents* tab_contents); + virtual ~MetroPinTabHelper(); + + bool is_pinned() const { return is_pinned_; } + + void TogglePinnedToStartScreen(); + + // content::WebContentsObserver overrides: + virtual void DidNavigateMainFrame( + const content::LoadCommittedDetails& details, + const content::FrameNavigateParams& params) OVERRIDE; + + private: + // Queries the metro driver about the pinned state of the current URL. + void UpdatePinnedStateForCurrentURL(); + + // Whether the current URL is pinned to the metro start screen. + bool is_pinned_; + + DISALLOW_COPY_AND_ASSIGN(MetroPinTabHelper); +}; + +#endif // CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_H_ diff --git a/chrome/browser/ui/tab_contents/tab_contents.cc b/chrome/browser/ui/tab_contents/tab_contents.cc index cf93415..f8048b7 100644 --- a/chrome/browser/ui/tab_contents/tab_contents.cc +++ b/chrome/browser/ui/tab_contents/tab_contents.cc @@ -37,6 +37,7 @@ #include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/hung_plugin_tab_helper.h" #include "chrome/browser/ui/intents/web_intent_picker_controller.h" +#include "chrome/browser/ui/metro_pin_tab_helper.h" #include "chrome/browser/ui/pdf/pdf_tab_observer.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/sad_tab_helper.h" @@ -112,6 +113,7 @@ TabContents::TabContents(WebContents* contents) history_tab_helper_.reset(new HistoryTabHelper(contents)); hung_plugin_tab_helper_.reset(new HungPluginTabHelper(contents)); infobar_tab_helper_.reset(new InfoBarTabHelper(contents)); + metro_pin_tab_helper_.reset(new MetroPinTabHelper(contents)); password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); password_manager_.reset( new PasswordManager(contents, password_manager_delegate_.get())); diff --git a/chrome/browser/ui/tab_contents/tab_contents.h b/chrome/browser/ui/tab_contents/tab_contents.h index 0004fa0..70138d8 100644 --- a/chrome/browser/ui/tab_contents/tab_contents.h +++ b/chrome/browser/ui/tab_contents/tab_contents.h @@ -27,6 +27,7 @@ class FindTabHelper; class HistoryTabHelper; class HungPluginTabHelper; class InfoBarTabHelper; +class MetroPinTabHelper; class OmniboxSearchHint; class PasswordManager; class PasswordManagerDelegate; @@ -175,6 +176,10 @@ class TabContents : public content::WebContentsObserver { } InfoBarTabHelper* infobar_tab_helper() { return infobar_tab_helper_.get(); } + MetroPinTabHelper* metro_pin_tab_helper() { + return metro_pin_tab_helper_.get(); + } + #if defined(ENABLE_ONE_CLICK_SIGNIN) OneClickSigninHelper* one_click_signin_helper() { return one_click_signin_helper_.get(); @@ -272,6 +277,7 @@ class TabContents : public content::WebContentsObserver { scoped_ptr<HistoryTabHelper> history_tab_helper_; scoped_ptr<HungPluginTabHelper> hung_plugin_tab_helper_; scoped_ptr<InfoBarTabHelper> infobar_tab_helper_; + scoped_ptr<MetroPinTabHelper> metro_pin_tab_helper_; // PasswordManager and its delegate. The delegate must outlive the manager, // per documentation in password_manager.h. diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index 0f38dde..2605521 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -32,6 +32,8 @@ #include "chrome/browser/ui/global_error/global_error.h" #include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h" +#include "chrome/browser/ui/metro_pin_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" #include "chrome/browser/upgrade_detector.h" @@ -239,7 +241,8 @@ bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { #endif command_id == IDC_VIEW_BACKGROUND_PAGES || command_id == IDC_UPGRADE_DIALOG || - command_id == IDC_SHOW_SYNC_SETUP; + command_id == IDC_SHOW_SYNC_SETUP || + command_id == IDC_PIN_TO_START_SCREEN; } string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { @@ -281,6 +284,14 @@ string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_PRE_SYNCED_LABEL, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); } + case IDC_PIN_TO_START_SCREEN: { + int string_id = IDS_PIN_TO_START_SCREEN; + TabContents* tab_contents = chrome::GetActiveTabContents(browser_); + if (tab_contents && tab_contents->metro_pin_tab_helper()->is_pinned()) { + string_id = IDS_UNPIN_FROM_START_SCREEN; + } + return l10n_util::GetStringUTF16(string_id); + } default: NOTREACHED(); return string16(); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index fd169cd..3d6744e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3250,6 +3250,8 @@ 'browser/ui/login/login_prompt.h', 'browser/ui/media_stream_infobar_delegate.h', 'browser/ui/media_stream_infobar_delegate.cc', + 'browser/ui/metro_pin_tab_helper.cc', + 'browser/ui/metro_pin_tab_helper.h', 'browser/ui/network_profile_bubble.cc', 'browser/ui/network_profile_bubble.h', 'browser/ui/omnibox/location_bar.h', |