| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/keyboard_codes.h" | 10 #include "base/keyboard_codes.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 is_attempting_to_close_browser_(false), | 130 is_attempting_to_close_browser_(false), |
| 131 cancel_download_confirmation_state_(NOT_PROMPTED), | 131 cancel_download_confirmation_state_(NOT_PROMPTED), |
| 132 maximized_state_(MAXIMIZED_STATE_DEFAULT), | 132 maximized_state_(MAXIMIZED_STATE_DEFAULT), |
| 133 method_factory_(this) { | 133 method_factory_(this) { |
| 134 tabstrip_model_.AddObserver(this); | 134 tabstrip_model_.AddObserver(this); |
| 135 | 135 |
| 136 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, | 136 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, |
| 137 NotificationService::AllSources()); | 137 NotificationService::AllSources()); |
| 138 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 138 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
| 139 NotificationService::AllSources()); | 139 NotificationService::AllSources()); |
| 140 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | |
| 141 NotificationService::AllSources()); | |
| 142 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 140 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 143 NotificationService::AllSources()); | 141 NotificationService::AllSources()); |
| 144 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CRASHED, | 142 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CRASHED, |
| 145 NotificationService::AllSources()); | 143 NotificationService::AllSources()); |
| 146 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 144 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 147 NotificationService::AllSources()); | 145 NotificationService::AllSources()); |
| 148 registrar_.Add(this, NotificationType::HISTORY_TOO_NEW, | 146 registrar_.Add(this, NotificationType::HISTORY_TOO_NEW, |
| 149 NotificationService::AllSources()); | 147 NotificationService::AllSources()); |
| 150 | 148 |
| 151 // Need to know when to alert the user of theme install delay. | 149 // Need to know when to alert the user of theme install delay. |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 default: | 1460 default: |
| 1463 LOG(WARNING) << "Received Unimplemented Command: " << id; | 1461 LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 1464 break; | 1462 break; |
| 1465 } | 1463 } |
| 1466 } | 1464 } |
| 1467 | 1465 |
| 1468 /////////////////////////////////////////////////////////////////////////////// | 1466 /////////////////////////////////////////////////////////////////////////////// |
| 1469 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: | 1467 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
| 1470 | 1468 |
| 1471 void Browser::ExecuteCommand(int id) { | 1469 void Browser::ExecuteCommand(int id) { |
| 1472 if (id >= IDC_BROWSER_ACTION_FIRST && id <= IDC_BROWSER_ACTION_LAST) { | |
| 1473 ExtensionsService* service = profile_->GetExtensionsService(); | |
| 1474 DCHECK(service); // No browser action command should have been created | |
| 1475 // in this window. | |
| 1476 | |
| 1477 // Go find the browser action in question. | |
| 1478 std::vector<ExtensionAction*> browser_actions = | |
| 1479 service->GetBrowserActions(false); // false means no popup actions. | |
| 1480 for (size_t i = 0; i < browser_actions.size(); ++i) { | |
| 1481 if (browser_actions[i]->command_id() == id) { | |
| 1482 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( | |
| 1483 profile_, browser_actions[i]->extension_id(), this); | |
| 1484 return; | |
| 1485 } | |
| 1486 } | |
| 1487 | |
| 1488 // Could not find the command in question. Perhaps it went away while the | |
| 1489 // menu was open? More likely, it is a bug. | |
| 1490 LOG(WARNING) << "Unknown browser action executed: " << id; | |
| 1491 } | |
| 1492 | |
| 1493 ExecuteCommandWithDisposition(id, CURRENT_TAB); | 1470 ExecuteCommandWithDisposition(id, CURRENT_TAB); |
| 1494 } | 1471 } |
| 1495 | 1472 |
| 1496 /////////////////////////////////////////////////////////////////////////////// | 1473 /////////////////////////////////////////////////////////////////////////////// |
| 1497 // Browser, TabStripModelDelegate implementation: | 1474 // Browser, TabStripModelDelegate implementation: |
| 1498 | 1475 |
| 1499 TabContents* Browser::AddBlankTab(bool foreground) { | 1476 TabContents* Browser::AddBlankTab(bool foreground) { |
| 1500 return AddBlankTabAt(-1, foreground); | 1477 return AddBlankTabAt(-1, foreground); |
| 1501 } | 1478 } |
| 1502 | 1479 |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 break; | 2160 break; |
| 2184 | 2161 |
| 2185 case NotificationType::EXTENSION_UPDATE_DISABLED: { | 2162 case NotificationType::EXTENSION_UPDATE_DISABLED: { |
| 2186 // Show the UI. | 2163 // Show the UI. |
| 2187 ExtensionsService* service = Source<ExtensionsService>(source).ptr(); | 2164 ExtensionsService* service = Source<ExtensionsService>(source).ptr(); |
| 2188 Extension* extension = Details<Extension>(details).ptr(); | 2165 Extension* extension = Details<Extension>(details).ptr(); |
| 2189 ShowExtensionDisabledUI(service, profile_, extension); | 2166 ShowExtensionDisabledUI(service, profile_, extension); |
| 2190 break; | 2167 break; |
| 2191 } | 2168 } |
| 2192 | 2169 |
| 2193 case NotificationType::EXTENSION_LOADED: { | |
| 2194 // Enable the browser action for the extension, if it has one. | |
| 2195 Extension* extension = Details<Extension>(details).ptr(); | |
| 2196 if (extension->browser_action()) { | |
| 2197 command_updater_.UpdateCommandEnabled( | |
| 2198 extension->browser_action()->command_id(), true); | |
| 2199 } | |
| 2200 break; | |
| 2201 } | |
| 2202 | |
| 2203 case NotificationType::EXTENSION_UNLOADED: { | 2170 case NotificationType::EXTENSION_UNLOADED: { |
| 2204 window()->GetLocationBar()->InvalidatePageActions(); | 2171 window()->GetLocationBar()->InvalidatePageActions(); |
| 2205 | 2172 |
| 2206 // Close any tabs from the unloaded extension. | 2173 // Close any tabs from the unloaded extension. |
| 2207 Extension* extension = Details<Extension>(details).ptr(); | 2174 Extension* extension = Details<Extension>(details).ptr(); |
| 2208 for (int i = 0; i < tabstrip_model_.count(); i++) { | 2175 for (int i = 0; i < tabstrip_model_.count(); i++) { |
| 2209 TabContents* tc = tabstrip_model_.GetTabContentsAt(i); | 2176 TabContents* tc = tabstrip_model_.GetTabContentsAt(i); |
| 2210 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && | 2177 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 2211 tc->GetURL().host() == extension->id()) { | 2178 tc->GetURL().host() == extension->id()) { |
| 2212 CloseTabContents(tc); | 2179 CloseTabContents(tc); |
| 2213 return; | 2180 return; |
| 2214 } | 2181 } |
| 2215 } | 2182 } |
| 2216 | 2183 |
| 2217 // Disable the browser action for the extension, if it has one. | |
| 2218 if (extension->browser_action()) { | |
| 2219 command_updater_.UpdateCommandEnabled( | |
| 2220 extension->browser_action()->command_id(), false); | |
| 2221 } | |
| 2222 | |
| 2223 break; | 2184 break; |
| 2224 } | 2185 } |
| 2225 | 2186 |
| 2226 case NotificationType::EXTENSION_PROCESS_CRASHED: { | 2187 case NotificationType::EXTENSION_PROCESS_CRASHED: { |
| 2227 window()->GetLocationBar()->InvalidatePageActions(); | 2188 window()->GetLocationBar()->InvalidatePageActions(); |
| 2228 | 2189 |
| 2229 TabContents* tab_contents = GetSelectedTabContents(); | 2190 TabContents* tab_contents = GetSelectedTabContents(); |
| 2230 if (!tab_contents) | 2191 if (!tab_contents) |
| 2231 break; | 2192 break; |
| 2232 ExtensionsService* extensions_service = | 2193 ExtensionsService* extensions_service = |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2370 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); | 2331 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
| 2371 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); | 2332 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); |
| 2372 command_updater_.UpdateCommandEnabled(IDC_SHOW_EXTENSION_SHELF, true); | 2333 command_updater_.UpdateCommandEnabled(IDC_SHOW_EXTENSION_SHELF, true); |
| 2373 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 2334 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 2374 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); | 2335 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); |
| 2375 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); | 2336 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); |
| 2376 #if defined(OS_CHROMEOS) | 2337 #if defined(OS_CHROMEOS) |
| 2377 command_updater_.UpdateCommandEnabled(IDC_CONTROL_PANEL, true); | 2338 command_updater_.UpdateCommandEnabled(IDC_CONTROL_PANEL, true); |
| 2378 #endif | 2339 #endif |
| 2379 | 2340 |
| 2380 // Set up any browser action commands that are installed. | |
| 2381 ExtensionsService* service = profile()->GetExtensionsService(); | |
| 2382 if (service) { | |
| 2383 std::vector<ExtensionAction*> browser_actions = | |
| 2384 service->GetBrowserActions(false); // false means no popup actions. | |
| 2385 for (size_t i = 0; i < browser_actions.size(); ++i) { | |
| 2386 command_updater_.UpdateCommandEnabled(browser_actions[i]->command_id(), | |
| 2387 true); | |
| 2388 } | |
| 2389 } | |
| 2390 | |
| 2391 // Initialize other commands based on the window type. | 2341 // Initialize other commands based on the window type. |
| 2392 { | 2342 { |
| 2393 bool normal_window = type() == TYPE_NORMAL; | 2343 bool normal_window = type() == TYPE_NORMAL; |
| 2394 | 2344 |
| 2395 // Navigation commands | 2345 // Navigation commands |
| 2396 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 2346 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
| 2397 | 2347 |
| 2398 // Window management commands | 2348 // Window management commands |
| 2399 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 2349 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 2400 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 2350 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2974 /////////////////////////////////////////////////////////////////////////////// | 2924 /////////////////////////////////////////////////////////////////////////////// |
| 2975 // BrowserToolbarModel (private): | 2925 // BrowserToolbarModel (private): |
| 2976 | 2926 |
| 2977 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2927 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
| 2978 // This |current_tab| can be NULL during the initialization of the | 2928 // This |current_tab| can be NULL during the initialization of the |
| 2979 // toolbar during window creation (i.e. before any tabs have been added | 2929 // toolbar during window creation (i.e. before any tabs have been added |
| 2980 // to the window). | 2930 // to the window). |
| 2981 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2931 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 2982 return current_tab ? ¤t_tab->controller() : NULL; | 2932 return current_tab ? ¤t_tab->controller() : NULL; |
| 2983 } | 2933 } |
| OLD | NEW |