OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser.h" | 5 #include "chrome/browser/browser.h" |
6 | 6 |
7 #include "app/animation.h" | 7 #include "app/animation.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 : type_(type), | 133 : type_(type), |
134 profile_(profile), | 134 profile_(profile), |
135 window_(NULL), | 135 window_(NULL), |
136 tabstrip_model_(this, profile), | 136 tabstrip_model_(this, profile), |
137 command_updater_(this), | 137 command_updater_(this), |
138 toolbar_model_(this), | 138 toolbar_model_(this), |
139 chrome_updater_factory_(this), | 139 chrome_updater_factory_(this), |
140 is_attempting_to_close_browser_(false), | 140 is_attempting_to_close_browser_(false), |
141 cancel_download_confirmation_state_(NOT_PROMPTED), | 141 cancel_download_confirmation_state_(NOT_PROMPTED), |
142 maximized_state_(MAXIMIZED_STATE_DEFAULT), | 142 maximized_state_(MAXIMIZED_STATE_DEFAULT), |
143 method_factory_(this) { | 143 method_factory_(this), |
| 144 block_command_execution_(false), |
| 145 last_blocked_command_id_(-1), |
| 146 last_blocked_command_disposition_(CURRENT_TAB) { |
144 tabstrip_model_.AddObserver(this); | 147 tabstrip_model_.AddObserver(this); |
145 | 148 |
146 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, | 149 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, |
147 NotificationService::AllSources()); | 150 NotificationService::AllSources()); |
148 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 151 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
149 NotificationService::AllSources()); | 152 NotificationService::AllSources()); |
150 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 153 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
151 NotificationService::AllSources()); | 154 NotificationService::AllSources()); |
152 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, | 155 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, |
153 NotificationService::AllSources()); | 156 NotificationService::AllSources()); |
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 // most/all commands should not have been enabled yet anyway or the ones that | 1398 // most/all commands should not have been enabled yet anyway or the ones that |
1396 // are enabled should be global, or safe themselves against having no selected | 1399 // are enabled should be global, or safe themselves against having no selected |
1397 // tab. However, Ben says he tried removing this before and got lots of | 1400 // tab. However, Ben says he tried removing this before and got lots of |
1398 // crashes, e.g. from Windows sending WM_COMMANDs at random times during | 1401 // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
1399 // window construction. This probably could use closer examination someday. | 1402 // window construction. This probably could use closer examination someday. |
1400 if (!GetSelectedTabContents()) | 1403 if (!GetSelectedTabContents()) |
1401 return; | 1404 return; |
1402 | 1405 |
1403 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command"; | 1406 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command"; |
1404 | 1407 |
| 1408 // If command execution is blocked then just record the command and return. |
| 1409 if (block_command_execution_) { |
| 1410 // We actually only allow no more than one blocked command, otherwise some |
| 1411 // commands maybe lost. |
| 1412 DCHECK(last_blocked_command_id_ == -1); |
| 1413 last_blocked_command_id_ = id; |
| 1414 last_blocked_command_disposition_ = disposition; |
| 1415 return; |
| 1416 } |
| 1417 |
1405 // The order of commands in this switch statement must match the function | 1418 // The order of commands in this switch statement must match the function |
1406 // declaration order in browser.h! | 1419 // declaration order in browser.h! |
1407 switch (id) { | 1420 switch (id) { |
1408 // Navigation commands | 1421 // Navigation commands |
1409 case IDC_BACK: GoBack(disposition); break; | 1422 case IDC_BACK: GoBack(disposition); break; |
1410 case IDC_FORWARD: GoForward(disposition); break; | 1423 case IDC_FORWARD: GoForward(disposition); break; |
1411 case IDC_RELOAD: Reload(); break; | 1424 case IDC_RELOAD: Reload(); break; |
1412 case IDC_HOME: Home(disposition); break; | 1425 case IDC_HOME: Home(disposition); break; |
1413 case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; | 1426 case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; |
1414 case IDC_GO: Go(disposition); break; | 1427 case IDC_GO: Go(disposition); break; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 #if defined(OS_CHROMEOS) | 1569 #if defined(OS_CHROMEOS) |
1557 case IDC_CONTROL_PANEL: ShowControlPanel(); break; | 1570 case IDC_CONTROL_PANEL: ShowControlPanel(); break; |
1558 #endif | 1571 #endif |
1559 | 1572 |
1560 default: | 1573 default: |
1561 LOG(WARNING) << "Received Unimplemented Command: " << id; | 1574 LOG(WARNING) << "Received Unimplemented Command: " << id; |
1562 break; | 1575 break; |
1563 } | 1576 } |
1564 } | 1577 } |
1565 | 1578 |
| 1579 bool Browser::IsReservedCommand(int command_id) { |
| 1580 return command_id == IDC_CLOSE_TAB || |
| 1581 command_id == IDC_CLOSE_POPUPS || |
| 1582 command_id == IDC_CLOSE_WINDOW || |
| 1583 command_id == IDC_NEW_INCOGNITO_WINDOW || |
| 1584 command_id == IDC_NEW_TAB || |
| 1585 command_id == IDC_NEW_WINDOW || |
| 1586 command_id == IDC_RESTORE_TAB || |
| 1587 command_id == IDC_SELECT_NEXT_TAB || |
| 1588 command_id == IDC_SELECT_PREVIOUS_TAB || |
| 1589 command_id == IDC_EXIT; |
| 1590 } |
| 1591 |
| 1592 void Browser::SetBlockCommandExecution(bool block) { |
| 1593 block_command_execution_ = block; |
| 1594 if (block) { |
| 1595 last_blocked_command_id_ = -1; |
| 1596 last_blocked_command_disposition_ = CURRENT_TAB; |
| 1597 } |
| 1598 } |
| 1599 |
| 1600 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { |
| 1601 if (disposition) |
| 1602 *disposition = last_blocked_command_disposition_; |
| 1603 return last_blocked_command_id_; |
| 1604 } |
| 1605 |
1566 /////////////////////////////////////////////////////////////////////////////// | 1606 /////////////////////////////////////////////////////////////////////////////// |
1567 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: | 1607 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
1568 | 1608 |
1569 void Browser::ExecuteCommand(int id) { | 1609 void Browser::ExecuteCommand(int id) { |
1570 ExecuteCommandWithDisposition(id, CURRENT_TAB); | 1610 ExecuteCommandWithDisposition(id, CURRENT_TAB); |
1571 } | 1611 } |
1572 | 1612 |
1573 /////////////////////////////////////////////////////////////////////////////// | 1613 /////////////////////////////////////////////////////////////////////////////// |
1574 // Browser, TabStripModelDelegate implementation: | 1614 // Browser, TabStripModelDelegate implementation: |
1575 | 1615 |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 window()->ConfirmAddSearchProvider(template_url, profile); | 2230 window()->ConfirmAddSearchProvider(template_url, profile); |
2191 } | 2231 } |
2192 | 2232 |
2193 void Browser::ShowPageInfo(Profile* profile, | 2233 void Browser::ShowPageInfo(Profile* profile, |
2194 const GURL& url, | 2234 const GURL& url, |
2195 const NavigationEntry::SSLStatus& ssl, | 2235 const NavigationEntry::SSLStatus& ssl, |
2196 bool show_history) { | 2236 bool show_history) { |
2197 window()->ShowPageInfo(profile, url, ssl, show_history); | 2237 window()->ShowPageInfo(profile, url, ssl, show_history); |
2198 } | 2238 } |
2199 | 2239 |
2200 bool Browser::IsReservedAccelerator(const NativeWebKeyboardEvent& event) { | 2240 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
2201 // Other platforms don't send close-app keyboard shortcuts to apps first. | 2241 bool* is_keyboard_shortcut) { |
2202 #if defined(OS_WIN) | 2242 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
2203 if ((event.modifiers & NativeWebKeyboardEvent::AltKey) && | 2243 } |
2204 event.windowsKeyCode == VK_F4) { | |
2205 return true; | |
2206 } | |
2207 #endif | |
2208 | 2244 |
2209 int command_id = window()->GetCommandId(event); | 2245 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
2210 return command_id == IDC_CLOSE_TAB || | 2246 window()->HandleKeyboardEvent(event); |
2211 command_id == IDC_CLOSE_POPUPS || | |
2212 command_id == IDC_CLOSE_WINDOW || | |
2213 command_id == IDC_NEW_INCOGNITO_WINDOW || | |
2214 command_id == IDC_NEW_TAB || | |
2215 command_id == IDC_NEW_WINDOW || | |
2216 command_id == IDC_RESTORE_TAB || | |
2217 command_id == IDC_SELECT_NEXT_TAB || | |
2218 command_id == IDC_SELECT_PREVIOUS_TAB; | |
2219 } | 2247 } |
2220 | 2248 |
2221 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { | 2249 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { |
2222 window()->ShowRepostFormWarningDialog(tab_contents); | 2250 window()->ShowRepostFormWarningDialog(tab_contents); |
2223 } | 2251 } |
2224 | 2252 |
2225 bool Browser::ShouldAddNavigationsToHistory() const { | 2253 bool Browser::ShouldAddNavigationsToHistory() const { |
2226 // Don't update history if running as app. | 2254 // Don't update history if running as app. |
2227 return !IsApplication(); | 2255 return !IsApplication(); |
2228 } | 2256 } |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3071 /////////////////////////////////////////////////////////////////////////////// | 3099 /////////////////////////////////////////////////////////////////////////////// |
3072 // BrowserToolbarModel (private): | 3100 // BrowserToolbarModel (private): |
3073 | 3101 |
3074 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 3102 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
3075 // This |current_tab| can be NULL during the initialization of the | 3103 // This |current_tab| can be NULL during the initialization of the |
3076 // toolbar during window creation (i.e. before any tabs have been added | 3104 // toolbar during window creation (i.e. before any tabs have been added |
3077 // to the window). | 3105 // to the window). |
3078 TabContents* current_tab = browser_->GetSelectedTabContents(); | 3106 TabContents* current_tab = browser_->GetSelectedTabContents(); |
3079 return current_tab ? ¤t_tab->controller() : NULL; | 3107 return current_tab ? ¤t_tab->controller() : NULL; |
3080 } | 3108 } |
OLD | NEW |