blob: c316c7e384067dd0a866f1245adcc4cdf07e5129 [file] [log] [blame]
[email protected]5d98294912012-06-27 22:57:401// 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/browser_command_controller.h"
6
7#include "chrome/app/chrome_command_ids.h"
8#include "chrome/browser/browser_process.h"
9#include "chrome/browser/defaults.h"
10#include "chrome/browser/extensions/extension_service.h"
11#include "chrome/browser/prefs/incognito_mode_prefs.h"
12#include "chrome/browser/prefs/pref_service.h"
13#include "chrome/browser/printing/print_preview_tab_controller.h"
14#include "chrome/browser/profiles/profile.h"
15#include "chrome/browser/profiles/profile_manager.h"
16#include "chrome/browser/sessions/tab_restore_service.h"
17#include "chrome/browser/sessions/tab_restore_service_factory.h"
18#include "chrome/browser/sync/profile_sync_service.h"
19#include "chrome/browser/sync/profile_sync_service_factory.h"
20#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
21#include "chrome/browser/ui/browser.h"
22#include "chrome/browser/ui/browser_commands.h"
[email protected]52877dbc62012-06-29 22:22:0323#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]5d98294912012-06-27 22:57:4024#include "chrome/browser/ui/browser_window.h"
25#include "chrome/browser/ui/chrome_pages.h"
26#include "chrome/browser/ui/tab_contents/tab_contents.h"
27#include "chrome/browser/ui/tabs/tab_strip_model.h"
28#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
29#include "chrome/common/chrome_notification_types.h"
30#include "chrome/common/pref_names.h"
31#include "chrome/common/profiling.h"
32#include "content/public/browser/native_web_keyboard_event.h"
33#include "content/public/browser/navigation_controller.h"
34#include "content/public/browser/navigation_entry.h"
35#include "content/public/browser/notification_details.h"
36#include "content/public/browser/notification_source.h"
37#include "content/public/browser/web_contents.h"
38#include "content/public/common/content_restriction.h"
39#include "content/public/common/url_constants.h"
40#include "ui/base/keycodes/keyboard_codes.h"
41
42#if defined(OS_WIN)
43#include "base/win/metro.h"
44#endif
45
46using content::WebContents;
47using content::NavigationEntry;
48using content::NavigationController;
49using content::WebContents;
50
51namespace {
52
53// Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
54bool HasInternalURL(const NavigationEntry* entry) {
55 if (!entry)
56 return false;
57
58 // Check the |virtual_url()| first. This catches regular chrome:// URLs
59 // including URLs that were rewritten (such as chrome://bookmarks).
60 if (entry->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme))
61 return true;
62
63 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
64 // view-source: of a chrome:// URL.
65 if (entry->GetVirtualURL().SchemeIs(chrome::kViewSourceScheme))
66 return entry->GetURL().SchemeIs(chrome::kChromeUIScheme);
67
68 return false;
69}
70
71} // namespace
72
73namespace chrome {
74
75///////////////////////////////////////////////////////////////////////////////
76// BrowserCommandController, public:
77
78BrowserCommandController::BrowserCommandController(Browser* browser)
79 : browser_(browser),
80 ALLOW_THIS_IN_INITIALIZER_LIST(command_updater_(this)),
81 block_command_execution_(false),
82 last_blocked_command_id_(-1),
83 last_blocked_command_disposition_(CURRENT_TAB) {
84 browser_->tab_strip_model()->AddObserver(this);
85 PrefService* local_state = g_browser_process->local_state();
86 if (local_state) {
87 local_pref_registrar_.Init(local_state);
[email protected]5d98294912012-06-27 22:57:4088 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this);
89 local_pref_registrar_.Add(prefs::kInManagedMode, this);
90 }
91
92 profile_pref_registrar_.Init(profile()->GetPrefs());
93 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this);
94 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this);
95 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this);
96 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this);
[email protected]0045b0f42012-07-26 11:52:0897 profile_pref_registrar_.Add(prefs::kPrintingEnabled, this);
[email protected]5d98294912012-06-27 22:57:4098
99 InitCommandState();
100
101 TabRestoreService* tab_restore_service =
102 TabRestoreServiceFactory::GetForProfile(profile());
103 if (tab_restore_service) {
104 tab_restore_service->AddObserver(this);
105 TabRestoreServiceChanged(tab_restore_service);
106 }
107
108 ProfileSyncService* service =
109 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
110 if (service)
111 service->AddObserver(this);
112}
113
114BrowserCommandController::~BrowserCommandController() {
115 ProfileSyncService* service =
116 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
117 if (service)
118 service->RemoveObserver(this);
119
120 TabRestoreService* tab_restore_service =
121 TabRestoreServiceFactory::GetForProfile(profile());
122 if (tab_restore_service)
123 tab_restore_service->RemoveObserver(this);
124 profile_pref_registrar_.RemoveAll();
125 local_pref_registrar_.RemoveAll();
126 browser_->tab_strip_model()->RemoveObserver(this);
127}
128
129bool BrowserCommandController::IsReservedCommandOrKey(
130 int command_id,
131 const content::NativeWebKeyboardEvent& event) {
132 // In Apps mode, no keys are reserved.
133 if (browser_->is_app())
134 return false;
135
136#if defined(OS_CHROMEOS)
137 // Chrome OS's top row of keys produces F1-10. Make sure that web pages
138 // aren't able to block Chrome from performing the standard actions for F1-F4.
139 // We should not handle F5-10 here since they are processed by Ash. See also:
140 // crbug.com/127333#c8
141 ui::KeyboardCode key_code =
142 static_cast<ui::KeyboardCode>(event.windowsKeyCode);
143 if ((key_code == ui::VKEY_F1 ||
144 key_code == ui::VKEY_F2 ||
145 key_code == ui::VKEY_F3 ||
146 key_code == ui::VKEY_F4) &&
147 // Make sure it's a browser shortcut (i.e. not an Ash one like Alt+F4).
148 command_id != -1) {
149 return true;
150 }
151#endif
152
153 if (window()->IsFullscreen() && command_id == IDC_FULLSCREEN)
154 return true;
155 return command_id == IDC_CLOSE_TAB ||
156 command_id == IDC_CLOSE_WINDOW ||
157 command_id == IDC_NEW_INCOGNITO_WINDOW ||
158 command_id == IDC_NEW_TAB ||
159 command_id == IDC_NEW_WINDOW ||
160 command_id == IDC_RESTORE_TAB ||
161 command_id == IDC_SELECT_NEXT_TAB ||
162 command_id == IDC_SELECT_PREVIOUS_TAB ||
163 command_id == IDC_TABPOSE ||
164 command_id == IDC_EXIT ||
165 command_id == IDC_SEARCH;
166}
167
168void BrowserCommandController::SetBlockCommandExecution(bool block) {
169 block_command_execution_ = block;
170 if (block) {
171 last_blocked_command_id_ = -1;
172 last_blocked_command_disposition_ = CURRENT_TAB;
173 }
174}
175
176int BrowserCommandController::GetLastBlockedCommand(
177 WindowOpenDisposition* disposition) {
178 if (disposition)
179 *disposition = last_blocked_command_disposition_;
180 return last_blocked_command_id_;
181}
182
183void BrowserCommandController::TabStateChanged() {
184 UpdateCommandsForTabState();
185}
186
187void BrowserCommandController::ContentRestrictionsChanged() {
188 UpdateCommandsForContentRestrictionState();
189}
190
191void BrowserCommandController::FullscreenStateChanged() {
192 FullScreenMode fullscreen_mode = FULLSCREEN_DISABLED;
193 if (window()->IsFullscreen()) {
194#if defined(OS_WIN)
195 fullscreen_mode = window()->IsInMetroSnapMode() ? FULLSCREEN_METRO_SNAP :
196 FULLSCREEN_NORMAL;
197#else
198 fullscreen_mode = FULLSCREEN_NORMAL;
199#endif
200 }
201 UpdateCommandsForFullscreenMode(fullscreen_mode);
202}
203
204void BrowserCommandController::PrintingStateChanged() {
205 UpdatePrintingState();
206}
207
208void BrowserCommandController::LoadingStateChanged(bool is_loading,
209 bool force) {
210 UpdateReloadStopState(is_loading, force);
211}
212
213void BrowserCommandController::SendToMobileStateChanged(
214 bool send_to_mobile_available) {
215 command_updater_.UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE,
216 send_to_mobile_available);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220// BrowserCommandController,
221// CommandUpdater::CommandUpdaterDelegate implementation:
222
223void BrowserCommandController::ExecuteCommandWithDisposition(
224 int id, WindowOpenDisposition disposition) {
225 // No commands are enabled if there is not yet any selected tab.
226 // TODO(pkasting): It seems like we should not need this, because either
227 // most/all commands should not have been enabled yet anyway or the ones that
228 // are enabled should be global, or safe themselves against having no selected
229 // tab. However, Ben says he tried removing this before and got lots of
230 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
231 // window construction. This probably could use closer examination someday.
[email protected]52877dbc62012-06-29 22:22:03232 if (!chrome::GetActiveTabContents(browser_))
[email protected]5d98294912012-06-27 22:57:40233 return;
234
235 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
236 << id;
237
238 // If command execution is blocked then just record the command and return.
239 if (block_command_execution_) {
240 // We actually only allow no more than one blocked command, otherwise some
241 // commands maybe lost.
242 DCHECK_EQ(last_blocked_command_id_, -1);
243 last_blocked_command_id_ = id;
244 last_blocked_command_disposition_ = disposition;
245 return;
246 }
247
248 // The order of commands in this switch statement must match the function
249 // declaration order in browser.h!
250 switch (id) {
251 // Navigation commands
252 case IDC_BACK:
253 GoBack(browser_, disposition);
254 break;
255 case IDC_FORWARD:
256 GoForward(browser_, disposition);
257 break;
258 case IDC_RELOAD:
259 Reload(browser_, disposition);
260 break;
[email protected]58e29032012-08-06 20:19:57261 case IDC_RELOAD_CLEARING_CACHE:
262 ClearCache(browser_);
263 // FALL THROUGH
[email protected]5d98294912012-06-27 22:57:40264 case IDC_RELOAD_IGNORING_CACHE:
265 ReloadIgnoringCache(browser_, disposition);
266 break;
267 case IDC_HOME:
268 Home(browser_, disposition);
269 break;
270 case IDC_OPEN_CURRENT_URL:
271 OpenCurrentURL(browser_);
272 break;
273 case IDC_STOP:
274 Stop(browser_);
275 break;
276
277 // Window management commands
278 case IDC_NEW_WINDOW:
279 NewWindow(browser_);
280 break;
281 case IDC_NEW_INCOGNITO_WINDOW:
282 NewIncognitoWindow(browser_);
283 break;
284 case IDC_CLOSE_WINDOW:
[email protected]04b9e692012-08-24 14:49:09285 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40286 break;
287 case IDC_NEW_TAB:
288 NewTab(browser_);
289 break;
290 case IDC_CLOSE_TAB:
[email protected]04b9e692012-08-24 14:49:09291 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40292 break;
293 case IDC_SELECT_NEXT_TAB:
294 SelectNextTab(browser_);
295 break;
296 case IDC_SELECT_PREVIOUS_TAB:
297 SelectPreviousTab(browser_);
298 break;
299 case IDC_TABPOSE:
300 OpenTabpose(browser_);
301 break;
302 case IDC_MOVE_TAB_NEXT:
303 MoveTabNext(browser_);
304 break;
305 case IDC_MOVE_TAB_PREVIOUS:
306 MoveTabPrevious(browser_);
307 break;
308 case IDC_SELECT_TAB_0:
309 case IDC_SELECT_TAB_1:
310 case IDC_SELECT_TAB_2:
311 case IDC_SELECT_TAB_3:
312 case IDC_SELECT_TAB_4:
313 case IDC_SELECT_TAB_5:
314 case IDC_SELECT_TAB_6:
315 case IDC_SELECT_TAB_7:
316 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
317 break;
318 case IDC_SELECT_LAST_TAB:
319 SelectLastTab(browser_);
320 break;
321 case IDC_DUPLICATE_TAB:
322 DuplicateTab(browser_);
323 break;
324 case IDC_RESTORE_TAB:
325 RestoreTab(browser_);
326 break;
[email protected]5d98294912012-06-27 22:57:40327 case IDC_SHOW_AS_TAB:
328 ConvertPopupToTabbedBrowser(browser_);
329 break;
330 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28331 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40332 break;
333#if defined(OS_WIN)
334 case IDC_METRO_SNAP_ENABLE:
335 browser_->SetMetroSnapMode(true);
336 break;
337 case IDC_METRO_SNAP_DISABLE:
338 browser_->SetMetroSnapMode(false);
339 break;
340#endif
341#if defined(OS_MACOSX)
342 case IDC_PRESENTATION_MODE:
343 browser_->TogglePresentationMode();
344 break;
345#endif
346 case IDC_EXIT:
347 Exit();
348 break;
349
350 // Page-related commands
351 case IDC_SAVE_PAGE:
352 SavePage(browser_);
353 break;
354 case IDC_BOOKMARK_PAGE:
355 BookmarkCurrentPage(browser_);
356 break;
[email protected]e6ba5a12012-08-07 02:05:53357 case IDC_PIN_TO_START_SCREEN:
[email protected]ffe6de62012-07-19 00:02:35358 TogglePagePinnedToStartScreen(browser_);
[email protected]5d98294912012-06-27 22:57:40359 break;
360 case IDC_BOOKMARK_ALL_TABS:
361 BookmarkAllTabs(browser_);
362 break;
363 case IDC_VIEW_SOURCE:
364 ViewSelectedSource(browser_);
365 break;
366 case IDC_EMAIL_PAGE_LOCATION:
367 EmailPageLocation(browser_);
368 break;
369 case IDC_PRINT:
370 Print(browser_);
371 break;
372 case IDC_ADVANCED_PRINT:
373 AdvancedPrint(browser_);
374 break;
[email protected]d53e4032012-06-29 18:58:34375 case IDC_PRINT_TO_DESTINATION:
376 PrintToDestination(browser_);
377 break;
[email protected]5d98294912012-06-27 22:57:40378 case IDC_CHROME_TO_MOBILE_PAGE:
379 ShowChromeToMobileBubble(browser_);
380 break;
381 case IDC_ENCODING_AUTO_DETECT:
382 browser_->ToggleEncodingAutoDetect();
383 break;
384 case IDC_ENCODING_UTF8:
385 case IDC_ENCODING_UTF16LE:
386 case IDC_ENCODING_ISO88591:
387 case IDC_ENCODING_WINDOWS1252:
388 case IDC_ENCODING_GBK:
389 case IDC_ENCODING_GB18030:
390 case IDC_ENCODING_BIG5HKSCS:
391 case IDC_ENCODING_BIG5:
392 case IDC_ENCODING_KOREAN:
393 case IDC_ENCODING_SHIFTJIS:
394 case IDC_ENCODING_ISO2022JP:
395 case IDC_ENCODING_EUCJP:
396 case IDC_ENCODING_THAI:
397 case IDC_ENCODING_ISO885915:
398 case IDC_ENCODING_MACINTOSH:
399 case IDC_ENCODING_ISO88592:
400 case IDC_ENCODING_WINDOWS1250:
401 case IDC_ENCODING_ISO88595:
402 case IDC_ENCODING_WINDOWS1251:
403 case IDC_ENCODING_KOI8R:
404 case IDC_ENCODING_KOI8U:
405 case IDC_ENCODING_ISO88597:
406 case IDC_ENCODING_WINDOWS1253:
407 case IDC_ENCODING_ISO88594:
408 case IDC_ENCODING_ISO885913:
409 case IDC_ENCODING_WINDOWS1257:
410 case IDC_ENCODING_ISO88593:
411 case IDC_ENCODING_ISO885910:
412 case IDC_ENCODING_ISO885914:
413 case IDC_ENCODING_ISO885916:
414 case IDC_ENCODING_WINDOWS1254:
415 case IDC_ENCODING_ISO88596:
416 case IDC_ENCODING_WINDOWS1256:
417 case IDC_ENCODING_ISO88598:
418 case IDC_ENCODING_ISO88598I:
419 case IDC_ENCODING_WINDOWS1255:
420 case IDC_ENCODING_WINDOWS1258:
421 browser_->OverrideEncoding(id);
422 break;
423
424 // Clipboard commands
425 case IDC_CUT:
426 Cut(browser_);
427 break;
428 case IDC_COPY:
429 Copy(browser_);
430 break;
431 case IDC_PASTE:
432 Paste(browser_);
433 break;
434
435 // Find-in-page
436 case IDC_FIND:
437 Find(browser_);
438 break;
439 case IDC_FIND_NEXT:
440 FindNext(browser_);
441 break;
442 case IDC_FIND_PREVIOUS:
443 FindPrevious(browser_);
444 break;
445
446 // Zoom
447 case IDC_ZOOM_PLUS:
448 Zoom(browser_, content::PAGE_ZOOM_IN);
449 break;
450 case IDC_ZOOM_NORMAL:
451 Zoom(browser_, content::PAGE_ZOOM_RESET);
452 break;
453 case IDC_ZOOM_MINUS:
454 Zoom(browser_, content::PAGE_ZOOM_OUT);
455 break;
456
457 // Focus various bits of UI
458 case IDC_FOCUS_TOOLBAR:
459 FocusToolbar(browser_);
460 break;
461 case IDC_FOCUS_LOCATION:
462 FocusLocationBar(browser_);
463 break;
464 case IDC_FOCUS_SEARCH:
465 FocusSearch(browser_);
466 break;
467 case IDC_FOCUS_MENU_BAR:
468 FocusAppMenu(browser_);
469 break;
470 case IDC_FOCUS_BOOKMARKS:
471 FocusBookmarksToolbar(browser_);
472 break;
473 case IDC_FOCUS_NEXT_PANE:
474 FocusNextPane(browser_);
475 break;
476 case IDC_FOCUS_PREVIOUS_PANE:
477 FocusPreviousPane(browser_);
478 break;
479
480 // Show various bits of UI
481 case IDC_OPEN_FILE:
482 browser_->OpenFile();
483 break;
484 case IDC_CREATE_SHORTCUTS:
[email protected]619f86182012-07-03 21:30:18485 CreateApplicationShortcuts(browser_);
[email protected]5d98294912012-06-27 22:57:40486 break;
487 case IDC_DEV_TOOLS:
488 ToggleDevToolsWindow(browser_, DEVTOOLS_TOGGLE_ACTION_NONE);
489 break;
490 case IDC_DEV_TOOLS_CONSOLE:
491 ToggleDevToolsWindow(browser_, DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE);
492 break;
493 case IDC_DEV_TOOLS_INSPECT:
494 ToggleDevToolsWindow(browser_, DEVTOOLS_TOGGLE_ACTION_INSPECT);
495 break;
496 case IDC_TASK_MANAGER:
497 OpenTaskManager(browser_, false);
498 break;
499 case IDC_VIEW_BACKGROUND_PAGES:
500 OpenTaskManager(browser_, true);
501 break;
502 case IDC_FEEDBACK:
503 OpenFeedbackDialog(browser_);
504 break;
505
506 case IDC_SHOW_BOOKMARK_BAR:
507 ToggleBookmarkBar(browser_);
508 break;
509 case IDC_PROFILING_ENABLED:
510 Profiling::Toggle();
511 break;
512
513 case IDC_SHOW_BOOKMARK_MANAGER:
514 ShowBookmarkManager(browser_);
515 break;
516 case IDC_SHOW_APP_MENU:
517 ShowAppMenu(browser_);
518 break;
519 case IDC_SHOW_AVATAR_MENU:
520 ShowAvatarMenu(browser_);
521 break;
522 case IDC_SHOW_HISTORY:
523 ShowHistory(browser_);
524 break;
525 case IDC_SHOW_DOWNLOADS:
526 ShowDownloads(browser_);
527 break;
528 case IDC_MANAGE_EXTENSIONS:
529 ShowExtensions(browser_);
530 break;
531 case IDC_OPTIONS:
532 ShowSettings(browser_);
533 break;
534 case IDC_EDIT_SEARCH_ENGINES:
535 ShowSearchEngineSettings(browser_);
536 break;
537 case IDC_VIEW_PASSWORDS:
538 ShowPasswordManager(browser_);
539 break;
540 case IDC_CLEAR_BROWSING_DATA:
541 ShowClearBrowsingDataDialog(browser_);
542 break;
543 case IDC_IMPORT_SETTINGS:
544 ShowImportDialog(browser_);
545 break;
546 case IDC_ABOUT:
547 ShowAboutChrome(browser_);
548 break;
549 case IDC_UPGRADE_DIALOG:
550 OpenUpdateChromeDialog(browser_);
551 break;
552 case IDC_VIEW_INCOMPATIBILITIES:
553 ShowConflicts(browser_);
554 break;
555 case IDC_HELP_PAGE_VIA_KEYBOARD:
556 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
557 break;
558 case IDC_HELP_PAGE_VIA_MENU:
559 ShowHelp(browser_, HELP_SOURCE_MENU);
560 break;
561 case IDC_SHOW_SYNC_SETUP:
562 ShowSyncSetup(browser_, SyncPromoUI::SOURCE_MENU);
563 break;
564 case IDC_TOGGLE_SPEECH_INPUT:
565 ToggleSpeechInput(browser_);
566 break;
567
568 default:
569 LOG(WARNING) << "Received Unimplemented Command: " << id;
570 break;
571 }
572}
573
574////////////////////////////////////////////////////////////////////////////////
575// BrowserCommandController, content::NotificationObserver implementation:
576
577void BrowserCommandController::Observe(
578 int type,
579 const content::NotificationSource& source,
580 const content::NotificationDetails& details) {
581 switch (type) {
582 case NOTIFICATION_PREF_CHANGED: {
583 const std::string& pref_name =
584 *content::Details<std::string>(details).ptr();
585 if (pref_name == prefs::kPrintingEnabled) {
586 UpdatePrintingState();
587 } else if (pref_name == prefs::kIncognitoModeAvailability) {
588 UpdateCommandsForIncognitoAvailability();
589 } else if (pref_name == prefs::kDevToolsDisabled) {
590 UpdateCommandsForDevTools();
591 } else if (pref_name == prefs::kEditBookmarksEnabled) {
592 UpdateCommandsForBookmarkEditing();
593 } else if (pref_name == prefs::kShowBookmarkBar) {
594 UpdateCommandsForBookmarkBar();
595 } else if (pref_name == prefs::kAllowFileSelectionDialogs) {
596 UpdateSaveAsState();
597 UpdateOpenFileState();
598 } else if (pref_name == prefs::kInManagedMode) {
599 UpdateCommandsForMultipleProfiles();
600 } else {
601 NOTREACHED();
602 }
603 break;
604 }
605 case content::NOTIFICATION_INTERSTITIAL_ATTACHED:
606 UpdateCommandsForTabState();
607 break;
608
609 case content::NOTIFICATION_INTERSTITIAL_DETACHED:
610 UpdateCommandsForTabState();
611 break;
612
613 default:
614 NOTREACHED() << "Got a notification we didn't register for.";
615 }
616}
617
618////////////////////////////////////////////////////////////////////////////////
619// BrowserCommandController, TabStripModelObserver implementation:
620
621void BrowserCommandController::TabInsertedAt(TabContents* contents,
622 int index,
623 bool foreground) {
624 AddInterstitialObservers(contents);
625}
626
627void BrowserCommandController::TabDetachedAt(TabContents* contents, int index) {
628 RemoveInterstitialObservers(contents);
629}
630
631void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
632 TabContents* old_contents,
633 TabContents* new_contents,
634 int index) {
635 RemoveInterstitialObservers(old_contents);
636 AddInterstitialObservers(new_contents);
637}
638
639////////////////////////////////////////////////////////////////////////////////
640// BrowserCommandController, TabRestoreServiceObserver implementation:
641
642void BrowserCommandController::TabRestoreServiceChanged(
643 TabRestoreService* service) {
644 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB,
645 CanRestoreTab(browser_));
646}
647
648void BrowserCommandController::TabRestoreServiceDestroyed(
649 TabRestoreService* service) {
650 service->RemoveObserver(this);
651}
652
653////////////////////////////////////////////////////////////////////////////////
654// BrowserCommandController, ProfileSyncServiceObserver implementation:
655
656void BrowserCommandController::OnStateChanged() {
657 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
658 profile()));
659 // For unit tests, we don't have a window.
660 if (!window())
661 return;
662 const bool show_main_ui = IsShowingMainUI(window()->IsFullscreen());
663 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
664 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible());
665}
666
667////////////////////////////////////////////////////////////////////////////////
668// BrowserCommandController, private:
669
670bool BrowserCommandController::IsShowingMainUI(bool is_fullscreen) {
671#if !defined(OS_MACOSX)
672 return browser_->is_type_tabbed() && !is_fullscreen;
673#else
674 return browser_->is_type_tabbed();
675#endif
676}
677
678void BrowserCommandController::InitCommandState() {
679 // All browser commands whose state isn't set automagically some other way
680 // (like Back & Forward with initial page load) must have their state
681 // initialized here, otherwise they will be forever disabled.
682
683 // Navigation commands
684 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
685 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57686 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40687
688 // Window management commands
689 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
690 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
691 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
692 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
693 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false);
694 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
695 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
696
697 // Page-related commands
698 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
699 command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
700 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
701 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
702 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88591, true);
703 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true);
704 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true);
705 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true);
706 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS, true);
707 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true);
708 command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true);
709 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true);
710 command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true);
711 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true);
712 command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true);
713 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true);
714 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true);
715 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true);
716 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true);
717 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true);
718 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true);
719 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true);
720 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true);
721 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true);
722 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true);
723 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true);
724 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true);
725 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true);
726 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true);
727 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true);
728 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true);
729 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true);
730 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true);
731 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true);
732 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true);
733 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true);
734 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true);
735 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true);
736 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true);
737
738 // Zoom
739 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
740 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
741 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true);
742 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
743
744 // Show various bits of UI
745 UpdateOpenFileState();
746 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
747 UpdateCommandsForDevTools();
748 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
749 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true);
750 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
751 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
752 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
753 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, true);
754
755 command_updater_.UpdateCommandEnabled(
756 IDC_SHOW_SYNC_SETUP, profile()->GetOriginalProfile()->IsSyncAccessible());
757
758 // Initialize other commands based on the window type.
759 bool normal_window = browser_->is_type_tabbed();
760
761 // Navigation commands
762 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window);
763
764 // Window management commands
765 // TODO(rohitrao): Disable fullscreen on non-Lion?
766 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN,
767 !(browser_->is_type_panel() && browser_->is_app()));
768 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
769 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
770 normal_window);
771 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
772 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
773 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
774 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
775 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
776 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
777 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
778 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
779 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
780 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
781 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
782#if defined(OS_WIN)
783 const bool metro_mode = base::win::IsMetroProcess();
784 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode);
785 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode);
786#endif
787#if defined(OS_MACOSX)
788 command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window);
789 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE,
790 !(browser_->is_type_panel() && browser_->is_app()));
791#endif
792
[email protected]5d98294912012-06-27 22:57:40793 // Find-in-page
794 command_updater_.UpdateCommandEnabled(IDC_FIND, !browser_->is_devtools());
795 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT,
796 !browser_->is_devtools());
797 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS,
798 !browser_->is_devtools());
799
800 // Show various bits of UI
801 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
802
803 // The upgrade entry and the view incompatibility entry should always be
804 // enabled. Whether they are visible is a separate matter determined on menu
805 // show.
806 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
807 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
808
809 // View Background Pages entry is always enabled, but is hidden if there are
810 // no background pages.
811 command_updater_.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES, true);
812
813 // Toggle speech input
814 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true);
815
816 // Initialize other commands whose state changes based on fullscreen mode.
817 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED);
818
819 UpdateCommandsForContentRestrictionState();
820
821 UpdateCommandsForBookmarkEditing();
822
823 UpdateCommandsForIncognitoAvailability();
824}
825
826void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
827 IncognitoModePrefs::Availability incognito_availability =
828 IncognitoModePrefs::GetAvailability(profile()->GetPrefs());
829 command_updater_.UpdateCommandEnabled(
830 IDC_NEW_WINDOW,
831 incognito_availability != IncognitoModePrefs::FORCED);
832 command_updater_.UpdateCommandEnabled(
833 IDC_NEW_INCOGNITO_WINDOW,
834 incognito_availability != IncognitoModePrefs::DISABLED);
835
836 // Bookmark manager and settings page/subpages are forced to open in normal
837 // mode. For this reason we disable these commands when incognito is forced.
838 const bool command_enabled =
839 incognito_availability != IncognitoModePrefs::FORCED;
840 command_updater_.UpdateCommandEnabled(
841 IDC_SHOW_BOOKMARK_MANAGER,
842 browser_defaults::bookmarks_enabled && command_enabled);
843 ExtensionService* extension_service = profile()->GetExtensionService();
844 bool enable_extensions =
845 extension_service && extension_service->extensions_enabled();
846 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
847 enable_extensions && command_enabled);
848
849 const bool show_main_ui =
850 IsShowingMainUI(window() && window()->IsFullscreen());
851 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS,
852 show_main_ui && command_enabled);
853 command_updater_.UpdateCommandEnabled(IDC_OPTIONS,
854 show_main_ui && command_enabled);
855}
856
857void BrowserCommandController::UpdateCommandsForTabState() {
[email protected]52877dbc62012-06-29 22:22:03858 TabContents* current_tab_contents = chrome::GetActiveTabContents(browser_);
[email protected]5d98294912012-06-27 22:57:40859 if (!current_tab_contents) // May be NULL during tab restore.
860 return;
861 WebContents* current_web_contents = current_tab_contents->web_contents();
862
863 // Navigation commands
864 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
865 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
866 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
867 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE,
868 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:57869 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
870 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:40871
872 // Window management commands
873 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
874 !browser_->is_app() && CanDuplicateTab(browser_));
875
876 // Page-related commands
877 window()->SetStarredState(
878 current_tab_contents->bookmark_tab_helper()->is_starred());
[email protected]5423c372012-08-22 05:50:16879 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:40880 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
881 CanViewSource(browser_));
882 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
883 CanEmailPageLocation(browser_));
884 if (browser_->is_devtools())
885 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
886
887 // Changing the encoding is not possible on Chrome-internal webpages.
888 NavigationController& nc = current_web_contents->GetController();
889 bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) ||
890 current_web_contents->ShowingInterstitialPage();
891 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
892 !is_chrome_internal && current_web_contents->IsSavable());
893
894 // Show various bits of UI
895 // TODO(pinkerton): Disable app-mode in the model until we implement it
896 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
897#if !defined(OS_MACOSX)
898 command_updater_.UpdateCommandEnabled(
899 IDC_CREATE_SHORTCUTS,
900 CanCreateApplicationShortcuts(browser_));
901#endif
902
903 UpdateCommandsForContentRestrictionState();
904 UpdateCommandsForBookmarkEditing();
905}
906
907void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
908 int restrictions = GetContentRestrictions(browser_);
909
910 command_updater_.UpdateCommandEnabled(
911 IDC_COPY, !(restrictions & content::CONTENT_RESTRICTION_COPY));
912 command_updater_.UpdateCommandEnabled(
913 IDC_CUT, !(restrictions & content::CONTENT_RESTRICTION_CUT));
914 command_updater_.UpdateCommandEnabled(
915 IDC_PASTE, !(restrictions & content::CONTENT_RESTRICTION_PASTE));
916 UpdateSaveAsState();
917 UpdatePrintingState();
918}
919
920void BrowserCommandController::UpdateCommandsForDevTools() {
921 bool dev_tools_enabled =
922 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
923 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
924 dev_tools_enabled);
925 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
926 dev_tools_enabled);
927 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
928 dev_tools_enabled);
929}
930
931void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
932 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
933 CanBookmarkCurrentPage(browser_));
934 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
935 CanBookmarkAllTabs(browser_));
[email protected]e6ba5a12012-08-07 02:05:53936 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN,
[email protected]5d98294912012-06-27 22:57:40937 true);
938}
939
940void BrowserCommandController::UpdateCommandsForBookmarkBar() {
941 const bool show_main_ui =
942 IsShowingMainUI(window() && window()->IsFullscreen());
943 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR,
944 browser_defaults::bookmarks_enabled &&
945 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) &&
946 show_main_ui);
947}
948
949void BrowserCommandController::UpdateCommandsForFullscreenMode(
950 FullScreenMode fullscreen_mode) {
951 const bool show_main_ui =
952 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED);
953 bool main_not_fullscreen = show_main_ui &&
954 (fullscreen_mode == FULLSCREEN_DISABLED);
955
956 // Navigation commands
957 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
958
959 // Window management commands
960 command_updater_.UpdateCommandEnabled(
961 IDC_SHOW_AS_TAB,
962 !browser_->is_type_tabbed() && fullscreen_mode == FULLSCREEN_DISABLED);
963
964 // Focus various bits of UI
965 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
966 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
967 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
968 command_updater_.UpdateCommandEnabled(
969 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
970 command_updater_.UpdateCommandEnabled(
971 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
972 command_updater_.UpdateCommandEnabled(
973 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
974 command_updater_.UpdateCommandEnabled(
975 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
976
977 // Show various bits of UI
978 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
979 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
980 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
981 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible());
982
983 // Settings page/subpages are forced to open in normal mode. We disable these
984 // commands when incognito is forced.
985 const bool options_enabled = show_main_ui &&
986 IncognitoModePrefs::GetAvailability(
987 profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
988 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled);
989 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled);
990
991 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
992 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
993 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
994 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
995#if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
996 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
997#endif
998
999 // Disable explicit fullscreen toggling when in metro snap mode.
1000 command_updater_.UpdateCommandEnabled(
1001 IDC_FULLSCREEN,
1002 fullscreen_mode != FULLSCREEN_METRO_SNAP);
1003
1004 UpdateCommandsForBookmarkBar();
1005 UpdateCommandsForMultipleProfiles();
1006}
1007
1008void BrowserCommandController::UpdateCommandsForMultipleProfiles() {
1009 bool show_main_ui = IsShowingMainUI(window() && window()->IsFullscreen());
1010 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU,
1011 show_main_ui &&
1012 !profile()->IsOffTheRecord() &&
1013 ProfileManager::IsMultipleProfilesEnabled());
1014}
1015
1016void BrowserCommandController::UpdatePrintingState() {
[email protected]d53e4032012-06-29 18:58:341017 bool print_enabled = CanPrint(browser_);
1018 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
[email protected]5d98294912012-06-27 22:57:401019 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT,
1020 CanAdvancedPrint(browser_));
[email protected]d53e4032012-06-29 18:58:341021 command_updater_.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION,
1022 print_enabled);
1023#if defined(OS_WIN)
1024 HMODULE metro_module = base::win::GetMetroModule();
1025 if (metro_module != NULL) {
1026 typedef void (*MetroEnablePrinting)(BOOL);
1027 MetroEnablePrinting metro_enable_printing =
1028 reinterpret_cast<MetroEnablePrinting>(
1029 ::GetProcAddress(metro_module, "MetroEnablePrinting"));
1030 if (metro_enable_printing)
1031 metro_enable_printing(print_enabled);
1032 }
1033#endif
[email protected]5d98294912012-06-27 22:57:401034}
1035
1036void BrowserCommandController::UpdateSaveAsState() {
1037 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1038}
1039
1040void BrowserCommandController::UpdateOpenFileState() {
1041 bool enabled = true;
1042 PrefService* local_state = g_browser_process->local_state();
1043 if (local_state)
1044 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1045
1046 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
1047}
1048
1049void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1050 bool force) {
1051 window()->UpdateReloadStopState(is_loading, force);
1052 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1053}
1054
1055void BrowserCommandController::AddInterstitialObservers(TabContents* contents) {
1056 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
1057 content::Source<WebContents>(contents->web_contents()));
1058 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
1059 content::Source<WebContents>(contents->web_contents()));
1060}
1061
1062void BrowserCommandController::RemoveInterstitialObservers(
1063 TabContents* contents) {
1064 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
1065 content::Source<WebContents>(contents->web_contents()));
1066 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
1067 content::Source<WebContents>(contents->web_contents()));
1068}
1069
1070BrowserWindow* BrowserCommandController::window() {
1071 return browser_->window();
1072}
1073
1074Profile* BrowserCommandController::profile() {
1075 return browser_->profile();
1076}
1077
[email protected]5d98294912012-06-27 22:57:401078} // namespace chrome