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/idle_timer.h" | 10 #include "base/idle_timer.h" |
11 #include "base/keyboard_codes.h" | 11 #include "base/keyboard_codes.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/thread.h" | 14 #include "base/thread.h" |
15 #include "chrome/app/chrome_dll_resource.h" | 15 #include "chrome/app/chrome_dll_resource.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/browser_list.h" | 17 #include "chrome/browser/browser_list.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/browser_shutdown.h" | 19 #include "chrome/browser/browser_shutdown.h" |
20 #include "chrome/browser/browser_window.h" | 20 #include "chrome/browser/browser_window.h" |
21 #include "chrome/browser/character_encoding.h" | 21 #include "chrome/browser/character_encoding.h" |
22 #include "chrome/browser/debugger/devtools_manager.h" | 22 #include "chrome/browser/debugger/devtools_manager.h" |
23 #include "chrome/browser/download/download_item_model.h" | 23 #include "chrome/browser/download/download_item_model.h" |
24 #include "chrome/browser/download/download_manager.h" | 24 #include "chrome/browser/download/download_manager.h" |
25 #include "chrome/browser/download/download_shelf.h" | 25 #include "chrome/browser/download/download_shelf.h" |
26 #include "chrome/browser/download/download_started_animation.h" | 26 #include "chrome/browser/download/download_started_animation.h" |
27 #include "chrome/browser/extensions/crashed_extension_infobar.h" | 27 #include "chrome/browser/extensions/crashed_extension_infobar.h" |
| 28 #include "chrome/browser/extensions/extension_browser_event_router.h" |
28 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 29 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| 30 #include "chrome/browser/extensions/extension_tabs_module.h" |
29 #include "chrome/browser/find_bar.h" | 31 #include "chrome/browser/find_bar.h" |
30 #include "chrome/browser/find_bar_controller.h" | 32 #include "chrome/browser/find_bar_controller.h" |
31 #include "chrome/browser/google_url_tracker.h" | 33 #include "chrome/browser/google_url_tracker.h" |
32 #include "chrome/browser/location_bar.h" | 34 #include "chrome/browser/location_bar.h" |
33 #include "chrome/browser/metrics/user_metrics.h" | 35 #include "chrome/browser/metrics/user_metrics.h" |
34 #include "chrome/browser/net/url_fixer_upper.h" | 36 #include "chrome/browser/net/url_fixer_upper.h" |
35 #include "chrome/browser/options_window.h" | 37 #include "chrome/browser/options_window.h" |
36 #include "chrome/browser/profile.h" | 38 #include "chrome/browser/profile.h" |
37 #include "chrome/browser/renderer_host/site_instance.h" | 39 #include "chrome/browser/renderer_host/site_instance.h" |
38 #include "chrome/browser/sessions/session_service.h" | 40 #include "chrome/browser/sessions/session_service.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 cancel_download_confirmation_state_(NOT_PROMPTED), | 182 cancel_download_confirmation_state_(NOT_PROMPTED), |
181 maximized_state_(MAXIMIZED_STATE_DEFAULT), | 183 maximized_state_(MAXIMIZED_STATE_DEFAULT), |
182 method_factory_(this), | 184 method_factory_(this), |
183 idle_task_(new BrowserIdleTimer) { | 185 idle_task_(new BrowserIdleTimer) { |
184 tabstrip_model_.AddObserver(this); | 186 tabstrip_model_.AddObserver(this); |
185 | 187 |
186 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, | 188 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, |
187 NotificationService::AllSources()); | 189 NotificationService::AllSources()); |
188 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 190 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
189 NotificationService::AllSources()); | 191 NotificationService::AllSources()); |
| 192 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 193 NotificationService::AllSources()); |
190 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 194 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
191 NotificationService::AllSources()); | 195 NotificationService::AllSources()); |
192 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CRASHED, | 196 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CRASHED, |
193 NotificationService::AllSources()); | 197 NotificationService::AllSources()); |
194 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 198 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
195 NotificationService::AllSources()); | 199 NotificationService::AllSources()); |
196 registrar_.Add(this, NotificationType::HISTORY_TOO_NEW, | 200 registrar_.Add(this, NotificationType::HISTORY_TOO_NEW, |
197 NotificationService::AllSources()); | 201 NotificationService::AllSources()); |
198 | 202 |
199 // Need to know when to alert the user of theme install delay. | 203 // Need to know when to alert the user of theme install delay. |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 UserMetrics::RecordAction(L"AboutChrome", profile_); | 1258 UserMetrics::RecordAction(L"AboutChrome", profile_); |
1255 window_->ShowAboutChromeDialog(); | 1259 window_->ShowAboutChromeDialog(); |
1256 } | 1260 } |
1257 | 1261 |
1258 void Browser::OpenHelpTab() { | 1262 void Browser::OpenHelpTab() { |
1259 GURL help_url(WideToASCII(l10n_util::GetString(IDS_HELP_CONTENT_URL))); | 1263 GURL help_url(WideToASCII(l10n_util::GetString(IDS_HELP_CONTENT_URL))); |
1260 AddTabWithURL(help_url, GURL(), PageTransition::AUTO_BOOKMARK, true, -1, | 1264 AddTabWithURL(help_url, GURL(), PageTransition::AUTO_BOOKMARK, true, -1, |
1261 false, NULL); | 1265 false, NULL); |
1262 } | 1266 } |
1263 | 1267 |
| 1268 void Browser::OpenExtensionsTab() { |
| 1269 AddTabWithURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), |
| 1270 PageTransition::AUTO_BOOKMARK, true, -1, false, NULL); |
| 1271 } |
| 1272 |
1264 #if defined(OS_CHROMEOS) | 1273 #if defined(OS_CHROMEOS) |
1265 void Browser::ShowControlPanel() { | 1274 void Browser::ShowControlPanel() { |
1266 GURL url("http://localhost:8080"); | 1275 GURL url("http://localhost:8080"); |
1267 AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, true, -1, | 1276 AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, true, -1, |
1268 false, NULL); | 1277 false, NULL); |
1269 } | 1278 } |
1270 #endif | 1279 #endif |
1271 | 1280 |
1272 /////////////////////////////////////////////////////////////////////////////// | 1281 /////////////////////////////////////////////////////////////////////////////// |
1273 | 1282 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 #ifdef CHROME_PERSONALIZATION | 1494 #ifdef CHROME_PERSONALIZATION |
1486 case IDC_SYNC_BOOKMARKS: OpenSyncMyBookmarksDialog(); break; | 1495 case IDC_SYNC_BOOKMARKS: OpenSyncMyBookmarksDialog(); break; |
1487 #endif | 1496 #endif |
1488 case IDC_OPTIONS: OpenOptionsDialog(); break; | 1497 case IDC_OPTIONS: OpenOptionsDialog(); break; |
1489 case IDC_EDIT_SEARCH_ENGINES: OpenKeywordEditor(); break; | 1498 case IDC_EDIT_SEARCH_ENGINES: OpenKeywordEditor(); break; |
1490 case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; | 1499 case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; |
1491 case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; | 1500 case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; |
1492 case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; | 1501 case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; |
1493 case IDC_ABOUT: OpenAboutChromeDialog(); break; | 1502 case IDC_ABOUT: OpenAboutChromeDialog(); break; |
1494 case IDC_HELP_PAGE: OpenHelpTab(); break; | 1503 case IDC_HELP_PAGE: OpenHelpTab(); break; |
| 1504 case IDC_MANAGE_EXTENSIONS: OpenExtensionsTab(); break; |
1495 #if defined(OS_CHROMEOS) | 1505 #if defined(OS_CHROMEOS) |
1496 case IDC_CONTROL_PANEL: ShowControlPanel(); break; | 1506 case IDC_CONTROL_PANEL: ShowControlPanel(); break; |
1497 #endif | 1507 #endif |
1498 | 1508 |
1499 default: | 1509 default: |
1500 LOG(WARNING) << "Received Unimplemented Command: " << id; | 1510 LOG(WARNING) << "Received Unimplemented Command: " << id; |
1501 break; | 1511 break; |
1502 } | 1512 } |
1503 } | 1513 } |
1504 | 1514 |
1505 /////////////////////////////////////////////////////////////////////////////// | 1515 /////////////////////////////////////////////////////////////////////////////// |
1506 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: | 1516 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
1507 | 1517 |
1508 void Browser::ExecuteCommand(int id) { | 1518 void Browser::ExecuteCommand(int id) { |
| 1519 if (id >= IDC_BROWSER_ACTION_FIRST && id <= IDC_BROWSER_ACTION_LAST) { |
| 1520 ExtensionsService* service = profile_->GetExtensionsService(); |
| 1521 DCHECK(service); // No browser action command should have been created |
| 1522 // in this window. |
| 1523 |
| 1524 // Go find the browser action in question. |
| 1525 std::vector<ContextualAction*> browser_actions = |
| 1526 service->GetBrowserActions(); |
| 1527 for (size_t i = 0; i < browser_actions.size(); ++i) { |
| 1528 if (browser_actions[i]->command_id() == id) { |
| 1529 int window_id = ExtensionTabUtil::GetWindowId(this); |
| 1530 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
| 1531 profile_, browser_actions[i]->extension_id(), window_id); |
| 1532 return; |
| 1533 } |
| 1534 } |
| 1535 |
| 1536 // Could not find the command in question. Perhaps it went away while the |
| 1537 // menu was open? More likely, it is a bug. |
| 1538 LOG(WARNING) << "Unknown browser action executed: " << id; |
| 1539 } |
| 1540 |
1509 ExecuteCommandWithDisposition(id, CURRENT_TAB); | 1541 ExecuteCommandWithDisposition(id, CURRENT_TAB); |
1510 } | 1542 } |
1511 | 1543 |
1512 /////////////////////////////////////////////////////////////////////////////// | 1544 /////////////////////////////////////////////////////////////////////////////// |
1513 // Browser, TabStripModelDelegate implementation: | 1545 // Browser, TabStripModelDelegate implementation: |
1514 | 1546 |
1515 TabContents* Browser::AddBlankTab(bool foreground) { | 1547 TabContents* Browser::AddBlankTab(bool foreground) { |
1516 return AddBlankTabAt(-1, foreground); | 1548 return AddBlankTabAt(-1, foreground); |
1517 } | 1549 } |
1518 | 1550 |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 break; | 2189 break; |
2158 | 2190 |
2159 case NotificationType::EXTENSION_UPDATE_DISABLED: { | 2191 case NotificationType::EXTENSION_UPDATE_DISABLED: { |
2160 // Show the UI. | 2192 // Show the UI. |
2161 ExtensionsService* service = Source<ExtensionsService>(source).ptr(); | 2193 ExtensionsService* service = Source<ExtensionsService>(source).ptr(); |
2162 Extension* extension = Details<Extension>(details).ptr(); | 2194 Extension* extension = Details<Extension>(details).ptr(); |
2163 ShowExtensionDisabledUI(service, profile_, extension); | 2195 ShowExtensionDisabledUI(service, profile_, extension); |
2164 break; | 2196 break; |
2165 } | 2197 } |
2166 | 2198 |
| 2199 case NotificationType::EXTENSION_LOADED: { |
| 2200 // Enable the browser action for the extension, if it has one. |
| 2201 Extension* extension = Details<Extension>(details).ptr(); |
| 2202 if (extension->browser_action()) { |
| 2203 command_updater_.UpdateCommandEnabled( |
| 2204 extension->browser_action()->command_id(), true); |
| 2205 } |
| 2206 break; |
| 2207 } |
| 2208 |
2167 case NotificationType::EXTENSION_UNLOADED: { | 2209 case NotificationType::EXTENSION_UNLOADED: { |
2168 window()->GetLocationBar()->InvalidatePageActions(); | 2210 window()->GetLocationBar()->InvalidatePageActions(); |
2169 | 2211 |
2170 // Close any tabs from the unloaded extension. | 2212 // Close any tabs from the unloaded extension. |
2171 Extension* extension = Details<Extension>(details).ptr(); | 2213 Extension* extension = Details<Extension>(details).ptr(); |
2172 for (int i = 0; i < tabstrip_model_.count(); i++) { | 2214 for (int i = 0; i < tabstrip_model_.count(); i++) { |
2173 TabContents* tc = tabstrip_model_.GetTabContentsAt(i); | 2215 TabContents* tc = tabstrip_model_.GetTabContentsAt(i); |
2174 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && | 2216 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
2175 tc->GetURL().host() == extension->id()) { | 2217 tc->GetURL().host() == extension->id()) { |
2176 CloseTabContents(tc); | 2218 CloseTabContents(tc); |
2177 return; | 2219 return; |
2178 } | 2220 } |
2179 } | 2221 } |
| 2222 |
| 2223 // Disable the browser action for the extension, if it has one. |
| 2224 if (extension->browser_action()) { |
| 2225 command_updater_.UpdateCommandEnabled( |
| 2226 extension->browser_action()->command_id(), false); |
| 2227 } |
| 2228 |
2180 break; | 2229 break; |
2181 } | 2230 } |
2182 | 2231 |
2183 case NotificationType::EXTENSION_PROCESS_CRASHED: { | 2232 case NotificationType::EXTENSION_PROCESS_CRASHED: { |
2184 window()->GetLocationBar()->InvalidatePageActions(); | 2233 window()->GetLocationBar()->InvalidatePageActions(); |
2185 | 2234 |
2186 TabContents* tab_contents = GetSelectedTabContents(); | 2235 TabContents* tab_contents = GetSelectedTabContents(); |
2187 if (!tab_contents) | 2236 if (!tab_contents) |
2188 break; | 2237 break; |
2189 ExtensionsService* extensions_service = | 2238 ExtensionsService* extensions_service = |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, true); | 2370 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, true); |
2322 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); | 2371 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
2323 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, true); | 2372 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, true); |
2324 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); | 2373 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
2325 command_updater_.UpdateCommandEnabled(IDC_SELECT_PROFILE, true); | 2374 command_updater_.UpdateCommandEnabled(IDC_SELECT_PROFILE, true); |
2326 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); | 2375 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
2327 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); | 2376 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); |
2328 command_updater_.UpdateCommandEnabled(IDC_SHOW_EXTENSION_SHELF, true); | 2377 command_updater_.UpdateCommandEnabled(IDC_SHOW_EXTENSION_SHELF, true); |
2329 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 2378 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
2330 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); | 2379 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); |
| 2380 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); |
2331 #if defined(OS_CHROMEOS) | 2381 #if defined(OS_CHROMEOS) |
2332 command_updater_.UpdateCommandEnabled(IDC_CONTROL_PANEL, true); | 2382 command_updater_.UpdateCommandEnabled(IDC_CONTROL_PANEL, true); |
2333 #endif | 2383 #endif |
2334 | 2384 |
2335 // Initialize other commands based on the window type. | 2385 // Initialize other commands based on the window type. |
2336 { | 2386 { |
2337 bool normal_window = type() == TYPE_NORMAL; | 2387 bool normal_window = type() == TYPE_NORMAL; |
2338 | 2388 |
2339 // Navigation commands | 2389 // Navigation commands |
2340 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 2390 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2919 /////////////////////////////////////////////////////////////////////////////// | 2969 /////////////////////////////////////////////////////////////////////////////// |
2920 // BrowserToolbarModel (private): | 2970 // BrowserToolbarModel (private): |
2921 | 2971 |
2922 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2972 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
2923 // This |current_tab| can be NULL during the initialization of the | 2973 // This |current_tab| can be NULL during the initialization of the |
2924 // toolbar during window creation (i.e. before any tabs have been added | 2974 // toolbar during window creation (i.e. before any tabs have been added |
2925 // to the window). | 2975 // to the window). |
2926 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2976 TabContents* current_tab = browser_->GetSelectedTabContents(); |
2927 return current_tab ? ¤t_tab->controller() : NULL; | 2977 return current_tab ? ¤t_tab->controller() : NULL; |
2928 } | 2978 } |
OLD | NEW |