| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 Browser* browser, | 222 Browser* browser, |
| 223 bool is_new_menu, | 223 bool is_new_menu, |
| 224 bool supports_new_separators) | 224 bool supports_new_separators) |
| 225 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 225 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| 226 provider_(provider), | 226 provider_(provider), |
| 227 browser_(browser), | 227 browser_(browser), |
| 228 tab_strip_model_(browser_->tab_strip_model()) { | 228 tab_strip_model_(browser_->tab_strip_model()) { |
| 229 Build(is_new_menu, supports_new_separators); | 229 Build(is_new_menu, supports_new_separators); |
| 230 UpdateZoomControls(); | 230 UpdateZoomControls(); |
| 231 | 231 |
| 232 HostZoomMap::GetForBrowserContext( |
| 233 browser->profile())->AddZoomLevelChangedCallback( |
| 234 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| 235 base::Unretained(this))); |
| 236 |
| 232 tab_strip_model_->AddObserver(this); | 237 tab_strip_model_->AddObserver(this); |
| 233 | 238 |
| 234 registrar_.Add( | |
| 235 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
| 236 content::Source<HostZoomMap>( | |
| 237 HostZoomMap::GetForBrowserContext(browser_->profile()))); | |
| 238 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 239 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 239 content::NotificationService::AllSources()); | 240 content::NotificationService::AllSources()); |
| 240 } | 241 } |
| 241 | 242 |
| 242 WrenchMenuModel::~WrenchMenuModel() { | 243 WrenchMenuModel::~WrenchMenuModel() { |
| 243 if (tab_strip_model_) | 244 if (tab_strip_model_) |
| 244 tab_strip_model_->RemoveObserver(this); | 245 tab_strip_model_->RemoveObserver(this); |
| 246 |
| 247 HostZoomMap::GetForBrowserContext( |
| 248 browser()->profile())->RemoveZoomLevelChangedCallback( |
| 249 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| 250 base::Unretained(this))); |
| 245 } | 251 } |
| 246 | 252 |
| 247 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { | 253 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { |
| 248 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; | 254 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; |
| 249 } | 255 } |
| 250 | 256 |
| 251 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { | 257 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
| 252 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 258 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
| 253 #if defined(OS_MACOSX) | 259 #if defined(OS_MACOSX) |
| 254 command_id == IDC_FULLSCREEN || | 260 command_id == IDC_FULLSCREEN || |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 UpdateZoomControls(); | 451 UpdateZoomControls(); |
| 446 } | 452 } |
| 447 | 453 |
| 448 void WrenchMenuModel::TabStripModelDeleted() { | 454 void WrenchMenuModel::TabStripModelDeleted() { |
| 449 // During views shutdown, the tabstrip model/browser is deleted first, while | 455 // During views shutdown, the tabstrip model/browser is deleted first, while |
| 450 // it is the opposite in gtk land. | 456 // it is the opposite in gtk land. |
| 451 tab_strip_model_->RemoveObserver(this); | 457 tab_strip_model_->RemoveObserver(this); |
| 452 tab_strip_model_ = NULL; | 458 tab_strip_model_ = NULL; |
| 453 } | 459 } |
| 454 | 460 |
| 461 void WrenchMenuModel::OnZoomLevelChanged(const std::string& host) { |
| 462 UpdateZoomControls(); |
| 463 } |
| 464 |
| 455 void WrenchMenuModel::Observe(int type, | 465 void WrenchMenuModel::Observe(int type, |
| 456 const content::NotificationSource& source, | 466 const content::NotificationSource& source, |
| 457 const content::NotificationDetails& details) { | 467 const content::NotificationDetails& details) { |
| 458 switch (type) { | 468 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
| 459 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: | 469 UpdateZoomControls(); |
| 460 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
| 461 UpdateZoomControls(); | |
| 462 break; | |
| 463 default: | |
| 464 NOTREACHED(); | |
| 465 } | |
| 466 } | 470 } |
| 467 | 471 |
| 468 // For testing. | 472 // For testing. |
| 469 WrenchMenuModel::WrenchMenuModel() | 473 WrenchMenuModel::WrenchMenuModel() |
| 470 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 474 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| 471 provider_(NULL), | 475 provider_(NULL), |
| 472 browser_(NULL), | 476 browser_(NULL), |
| 473 tab_strip_model_(NULL) { | 477 tab_strip_model_(NULL) { |
| 474 } | 478 } |
| 475 | 479 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // registration framework. | 751 // registration framework. |
| 748 if (profile->IsSyncAccessible()) { | 752 if (profile->IsSyncAccessible()) { |
| 749 ProfileSyncService* service = | 753 ProfileSyncService* service = |
| 750 ProfileSyncServiceFactory::GetForProfile(profile); | 754 ProfileSyncServiceFactory::GetForProfile(profile); |
| 751 SyncGlobalError* error = service->sync_global_error(); | 755 SyncGlobalError* error = service->sync_global_error(); |
| 752 if (error && error->HasBadge()) | 756 if (error && error->HasBadge()) |
| 753 return error; | 757 return error; |
| 754 } | 758 } |
| 755 return NULL; | 759 return NULL; |
| 756 } | 760 } |
| OLD | NEW |