diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-03 00:50:07 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-03 00:50:07 +0000 |
commit | 9714ed638fe3391a610e58ff3fe618561ce9432a (patch) | |
tree | 37df305160242a21e618b12d32d3ddb22bc20808 | |
parent | dd8c82308f2d551397dd928bead33e24d5179efb (diff) | |
download | chromium_src-9714ed638fe3391a610e58ff3fe618561ce9432a.zip chromium_src-9714ed638fe3391a610e58ff3fe618561ce9432a.tar.gz chromium_src-9714ed638fe3391a610e58ff3fe618561ce9432a.tar.bz2 |
[Win8] Fix pin / unpin status if the user cancels an action or pins / unpins from start screen.
Previously the state was cached whenever a navigation happened, or whenever the user started a pin / unpin action. As the state query does not happen on the metro thread (it happens on the UI thread and is synchronous) there is no need for the caching.
BUG=144332
Review URL: https://chromiumcodereview.appspot.com/11362050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165818 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/metro_pin_tab_helper_win.cc | 50 | ||||
-rw-r--r-- | chrome/browser/ui/metro_pin_tab_helper_win.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/toolbar/wrench_menu_model.cc | 2 |
3 files changed, 22 insertions, 38 deletions
diff --git a/chrome/browser/ui/metro_pin_tab_helper_win.cc b/chrome/browser/ui/metro_pin_tab_helper_win.cc index 37a6b01..0adc88f 100644 --- a/chrome/browser/ui/metro_pin_tab_helper_win.cc +++ b/chrome/browser/ui/metro_pin_tab_helper_win.cc @@ -363,21 +363,31 @@ void MetroPinTabHelper::FaviconDownloader::OnDidDownloadFavicon( } MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) - : content::WebContentsObserver(web_contents), - is_pinned_(false) {} + : content::WebContentsObserver(web_contents) {} MetroPinTabHelper::~MetroPinTabHelper() {} -void MetroPinTabHelper::TogglePinnedToStartScreen() { - UpdatePinnedStateForCurrentURL(); - bool was_pinned = is_pinned_; +bool MetroPinTabHelper::IsPinned() const { + HMODULE metro_module = base::win::GetMetroModule(); + if (!metro_module) + return false; - // 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_; + 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 false; + } + + GURL url = web_contents()->GetURL(); + string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); + return metro_is_pinned_to_start_screen(tile_id) != 0; +} - if (was_pinned) { +void MetroPinTabHelper::TogglePinnedToStartScreen() { + if (IsPinned()) { UnPinPageFromStartScreen(); return; } @@ -400,7 +410,6 @@ void MetroPinTabHelper::TogglePinnedToStartScreen() { void MetroPinTabHelper::DidNavigateMainFrame( const content::LoadCommittedDetails& /*details*/, const content::FrameNavigateParams& /*params*/) { - UpdatePinnedStateForCurrentURL(); // Cancel any outstanding pin operations once the user navigates away from // the page. if (favicon_downloader_.get()) @@ -436,25 +445,6 @@ void MetroPinTabHelper::OnDidDownloadFavicon( requested_size, bitmaps); } -void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { - HMODULE metro_module = base::win::GetMetroModule(); - if (!metro_module) - return; - - 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(); - string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); - is_pinned_ = metro_is_pinned_to_start_screen(tile_id) != 0; -} - void MetroPinTabHelper::UnPinPageFromStartScreen() { HMODULE metro_module = base::win::GetMetroModule(); if (!metro_module) diff --git a/chrome/browser/ui/metro_pin_tab_helper_win.h b/chrome/browser/ui/metro_pin_tab_helper_win.h index 77a81a7b..737832e 100644 --- a/chrome/browser/ui/metro_pin_tab_helper_win.h +++ b/chrome/browser/ui/metro_pin_tab_helper_win.h @@ -20,7 +20,7 @@ class MetroPinTabHelper public: virtual ~MetroPinTabHelper(); - bool is_pinned() const { return is_pinned_; } + bool IsPinned() const; void TogglePinnedToStartScreen(); @@ -49,17 +49,11 @@ class MetroPinTabHelper int requested_size, const std::vector<SkBitmap>& bitmaps); - // Queries the metro driver about the pinned state of the current URL. - void UpdatePinnedStateForCurrentURL(); - void UnPinPageFromStartScreen(); // Called by the |favicon_downloader_| when it has finished. void FaviconDownloaderFinished(); - // Whether the current URL is pinned to the metro start screen. - bool is_pinned_; - // Candidate Favicon URLs for the current page. std::vector<FaviconURL> favicon_url_candidates_; diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index e8ff92c..9163f8f 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -271,7 +271,7 @@ string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { MetroPinTabHelper* tab_helper = web_contents ? MetroPinTabHelper::FromWebContents(web_contents) : NULL; - if (tab_helper && tab_helper->is_pinned()) + if (tab_helper && tab_helper->IsPinned()) string_id = IDS_UNPIN_FROM_START_SCREEN; return l10n_util::GetStringUTF16(string_id); } |