OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "chrome/browser/download/download_manager.h" | 44 #include "chrome/browser/download/download_manager.h" |
45 #include "chrome/browser/download/download_shelf.h" | 45 #include "chrome/browser/download/download_shelf.h" |
46 #include "chrome/browser/download/download_started_animation.h" | 46 #include "chrome/browser/download/download_started_animation.h" |
47 #include "chrome/browser/extensions/crashed_extension_infobar.h" | 47 #include "chrome/browser/extensions/crashed_extension_infobar.h" |
48 #include "chrome/browser/extensions/crx_installer.h" | 48 #include "chrome/browser/extensions/crx_installer.h" |
49 #include "chrome/browser/extensions/extension_browser_event_router.h" | 49 #include "chrome/browser/extensions/extension_browser_event_router.h" |
50 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 50 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
51 #include "chrome/browser/extensions/extension_host.h" | 51 #include "chrome/browser/extensions/extension_host.h" |
52 #include "chrome/browser/extensions/extension_prefs.h" | 52 #include "chrome/browser/extensions/extension_prefs.h" |
53 #include "chrome/browser/extensions/extension_tabs_module.h" | 53 #include "chrome/browser/extensions/extension_tabs_module.h" |
54 #include "chrome/browser/extensions/extensions_service.h" | 54 #include "chrome/browser/extensions/extension_service.h" |
55 #include "chrome/browser/first_run/first_run.h" | 55 #include "chrome/browser/first_run/first_run.h" |
56 #include "chrome/browser/google/google_url_tracker.h" | 56 #include "chrome/browser/google/google_url_tracker.h" |
57 #include "chrome/browser/google/google_util.h" | 57 #include "chrome/browser/google/google_util.h" |
58 #include "chrome/browser/host_zoom_map.h" | 58 #include "chrome/browser/host_zoom_map.h" |
59 #include "chrome/browser/instant/instant_controller.h" | 59 #include "chrome/browser/instant/instant_controller.h" |
60 #include "chrome/browser/instant/instant_unload_handler.h" | 60 #include "chrome/browser/instant/instant_unload_handler.h" |
61 #include "chrome/browser/metrics/user_metrics.h" | 61 #include "chrome/browser/metrics/user_metrics.h" |
62 #include "chrome/browser/net/browser_url_util.h" | 62 #include "chrome/browser/net/browser_url_util.h" |
63 #include "chrome/browser/net/url_fixer_upper.h" | 63 #include "chrome/browser/net/url_fixer_upper.h" |
64 #include "chrome/browser/platform_util.h" | 64 #include "chrome/browser/platform_util.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 browser->window()->Show(); | 487 browser->window()->Show(); |
488 } | 488 } |
489 | 489 |
490 // static | 490 // static |
491 // TODO(erikkay): There are multiple reasons why this could fail. Should | 491 // TODO(erikkay): There are multiple reasons why this could fail. Should |
492 // this function return an error reason as well so that callers can show | 492 // this function return an error reason as well so that callers can show |
493 // reasonable errors? | 493 // reasonable errors? |
494 TabContents* Browser::OpenApplication(Profile* profile, | 494 TabContents* Browser::OpenApplication(Profile* profile, |
495 const std::string& app_id, | 495 const std::string& app_id, |
496 TabContents* existing_tab) { | 496 TabContents* existing_tab) { |
497 ExtensionsService* extensions_service = profile->GetExtensionsService(); | 497 ExtensionService* extensions_service = profile->GetExtensionService(); |
498 | 498 |
499 // If the extension with |app_id| could't be found, most likely because it | 499 // If the extension with |app_id| could't be found, most likely because it |
500 // was uninstalled. | 500 // was uninstalled. |
501 const Extension* extension = | 501 const Extension* extension = |
502 extensions_service->GetExtensionById(app_id, false); | 502 extensions_service->GetExtensionById(app_id, false); |
503 if (!extension) | 503 if (!extension) |
504 return NULL; | 504 return NULL; |
505 | 505 |
506 return OpenApplication(profile, extension, extension->launch_container(), | 506 return OpenApplication(profile, extension, extension->launch_container(), |
507 existing_tab); | 507 existing_tab); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 // static | 612 // static |
613 TabContents* Browser::OpenApplicationTab(Profile* profile, | 613 TabContents* Browser::OpenApplicationTab(Profile* profile, |
614 const Extension* extension, | 614 const Extension* extension, |
615 TabContents* existing_tab) { | 615 TabContents* existing_tab) { |
616 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 616 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
617 TabContents* contents = NULL; | 617 TabContents* contents = NULL; |
618 if (!browser || browser->type() != Browser::TYPE_NORMAL) | 618 if (!browser || browser->type() != Browser::TYPE_NORMAL) |
619 return contents; | 619 return contents; |
620 | 620 |
621 // Check the prefs for overridden mode. | 621 // Check the prefs for overridden mode. |
622 ExtensionsService* extensions_service = profile->GetExtensionsService(); | 622 ExtensionService* extensions_service = profile->GetExtensionService(); |
623 DCHECK(extensions_service); | 623 DCHECK(extensions_service); |
624 | 624 |
625 ExtensionPrefs::LaunchType launch_type = | 625 ExtensionPrefs::LaunchType launch_type = |
626 extensions_service->extension_prefs()->GetLaunchType( | 626 extensions_service->extension_prefs()->GetLaunchType( |
627 extension->id(), ExtensionPrefs::LAUNCH_REGULAR); | 627 extension->id(), ExtensionPrefs::LAUNCH_REGULAR); |
628 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); | 628 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
629 int add_type = TabStripModel::ADD_SELECTED; | 629 int add_type = TabStripModel::ADD_SELECTED; |
630 if (launch_type == ExtensionPrefs::LAUNCH_PINNED) | 630 if (launch_type == ExtensionPrefs::LAUNCH_PINNED) |
631 add_type |= TabStripModel::ADD_PINNED; | 631 add_type |= TabStripModel::ADD_PINNED; |
632 | 632 |
(...skipping 2400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3033 return window_->GetExtraRenderViewHeight(); | 3033 return window_->GetExtraRenderViewHeight(); |
3034 } | 3034 } |
3035 | 3035 |
3036 void Browser::OnStartDownload(DownloadItem* download, TabContents* tab) { | 3036 void Browser::OnStartDownload(DownloadItem* download, TabContents* tab) { |
3037 if (!window()) | 3037 if (!window()) |
3038 return; | 3038 return; |
3039 | 3039 |
3040 #if defined(OS_CHROMEOS) | 3040 #if defined(OS_CHROMEOS) |
3041 // Don't show content browser for extension/theme downloads from gallery. | 3041 // Don't show content browser for extension/theme downloads from gallery. |
3042 if (download->is_extension_install()) { | 3042 if (download->is_extension_install()) { |
3043 ExtensionsService* service = profile_->GetExtensionsService(); | 3043 ExtensionService* service = profile_->GetExtensionService(); |
3044 if (service && service->IsDownloadFromGallery(download->url(), | 3044 if (service && service->IsDownloadFromGallery(download->url(), |
3045 download->referrer_url())) { | 3045 download->referrer_url())) { |
3046 return; | 3046 return; |
3047 } | 3047 } |
3048 } | 3048 } |
3049 | 3049 |
3050 // skip the download shelf and just open the file browser in chromeos | 3050 // skip the download shelf and just open the file browser in chromeos |
3051 std::string arg = download->full_path().DirName().value(); | 3051 std::string arg = download->full_path().DirName().value(); |
3052 FileBrowseUI::OpenPopup(profile_, | 3052 FileBrowseUI::OpenPopup(profile_, |
3053 arg, | 3053 arg, |
3054 FileBrowseUI::kPopupWidth, | 3054 FileBrowseUI::kPopupWidth, |
3055 FileBrowseUI::kPopupHeight); | 3055 FileBrowseUI::kPopupHeight); |
3056 | 3056 |
3057 #else | 3057 #else |
3058 // GetDownloadShelf creates the download shelf if it was not yet created. | 3058 // GetDownloadShelf creates the download shelf if it was not yet created. |
3059 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); | 3059 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); |
3060 | 3060 |
3061 // Don't show the animation for "Save file" downloads. | 3061 // Don't show the animation for "Save file" downloads. |
3062 if (download->total_bytes() <= 0) | 3062 if (download->total_bytes() <= 0) |
3063 return; | 3063 return; |
3064 | 3064 |
3065 // For non-theme extensions, we don't show the download animation. | 3065 // For non-theme extensions, we don't show the download animation. |
3066 if (download->is_extension_install() && | 3066 if (download->is_extension_install() && |
3067 !ExtensionsService::IsDownloadFromMiniGallery(download->url())) | 3067 !ExtensionService::IsDownloadFromMiniGallery(download->url())) |
3068 return; | 3068 return; |
3069 | 3069 |
3070 TabContents* current_tab = GetSelectedTabContents(); | 3070 TabContents* current_tab = GetSelectedTabContents(); |
3071 // We make this check for the case of minimized windows, unit tests, etc. | 3071 // We make this check for the case of minimized windows, unit tests, etc. |
3072 if (platform_util::IsVisible(current_tab->GetNativeView()) && | 3072 if (platform_util::IsVisible(current_tab->GetNativeView()) && |
3073 Animation::ShouldRenderRichAnimation()) { | 3073 Animation::ShouldRenderRichAnimation()) { |
3074 DownloadStartedAnimation::Show(current_tab); | 3074 DownloadStartedAnimation::Show(current_tab); |
3075 } | 3075 } |
3076 #endif | 3076 #endif |
3077 | 3077 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3159 default: | 3159 default: |
3160 NOTREACHED(); | 3160 NOTREACHED(); |
3161 break; | 3161 break; |
3162 } | 3162 } |
3163 | 3163 |
3164 pending_web_app_action_ = NONE; | 3164 pending_web_app_action_ = NONE; |
3165 } | 3165 } |
3166 | 3166 |
3167 void Browser::OnInstallApplication(TabContents* source, | 3167 void Browser::OnInstallApplication(TabContents* source, |
3168 const WebApplicationInfo& web_app) { | 3168 const WebApplicationInfo& web_app) { |
3169 ExtensionsService* extensions_service = profile()->GetExtensionsService(); | 3169 ExtensionService* extensions_service = profile()->GetExtensionService(); |
3170 if (!extensions_service) | 3170 if (!extensions_service) |
3171 return; | 3171 return; |
3172 | 3172 |
3173 scoped_refptr<CrxInstaller> installer( | 3173 scoped_refptr<CrxInstaller> installer( |
3174 new CrxInstaller(extensions_service, | 3174 new CrxInstaller(extensions_service, |
3175 extensions_service->show_extensions_prompts() ? | 3175 extensions_service->show_extensions_prompts() ? |
3176 new ExtensionInstallUI(profile()) : NULL)); | 3176 new ExtensionInstallUI(profile()) : NULL)); |
3177 installer->InstallWebApp(web_app); | 3177 installer->InstallWebApp(web_app); |
3178 } | 3178 } |
3179 | 3179 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3219 if (GetSelectedTabContents() && | 3219 if (GetSelectedTabContents() && |
3220 &GetSelectedTabContents()->controller() == | 3220 &GetSelectedTabContents()->controller() == |
3221 Source<NavigationController>(source).ptr()) | 3221 Source<NavigationController>(source).ptr()) |
3222 UpdateToolbar(false); | 3222 UpdateToolbar(false); |
3223 break; | 3223 break; |
3224 | 3224 |
3225 case NotificationType::EXTENSION_UPDATE_DISABLED: { | 3225 case NotificationType::EXTENSION_UPDATE_DISABLED: { |
3226 // Show the UI if the extension was disabled for escalated permissions. | 3226 // Show the UI if the extension was disabled for escalated permissions. |
3227 Profile* profile = Source<Profile>(source).ptr(); | 3227 Profile* profile = Source<Profile>(source).ptr(); |
3228 if (profile_->IsSameProfile(profile)) { | 3228 if (profile_->IsSameProfile(profile)) { |
3229 ExtensionsService* service = profile->GetExtensionsService(); | 3229 ExtensionService* service = profile->GetExtensionService(); |
3230 DCHECK(service); | 3230 DCHECK(service); |
3231 const Extension* extension = Details<const Extension>(details).ptr(); | 3231 const Extension* extension = Details<const Extension>(details).ptr(); |
3232 if (service->extension_prefs()->DidExtensionEscalatePermissions( | 3232 if (service->extension_prefs()->DidExtensionEscalatePermissions( |
3233 extension->id())) | 3233 extension->id())) |
3234 ShowExtensionDisabledUI(service, profile_, extension); | 3234 ShowExtensionDisabledUI(service, profile_, extension); |
3235 } | 3235 } |
3236 break; | 3236 break; |
3237 } | 3237 } |
3238 | 3238 |
3239 case NotificationType::EXTENSION_UNLOADED: | 3239 case NotificationType::EXTENSION_UNLOADED: |
(...skipping 13 matching lines...) Expand all Loading... |
3253 | 3253 |
3254 break; | 3254 break; |
3255 } | 3255 } |
3256 | 3256 |
3257 case NotificationType::EXTENSION_PROCESS_TERMINATED: { | 3257 case NotificationType::EXTENSION_PROCESS_TERMINATED: { |
3258 window()->GetLocationBar()->InvalidatePageActions(); | 3258 window()->GetLocationBar()->InvalidatePageActions(); |
3259 | 3259 |
3260 TabContents* tab_contents = GetSelectedTabContents(); | 3260 TabContents* tab_contents = GetSelectedTabContents(); |
3261 if (!tab_contents) | 3261 if (!tab_contents) |
3262 break; | 3262 break; |
3263 ExtensionsService* extensions_service = | 3263 ExtensionService* extensions_service = |
3264 Source<Profile>(source).ptr()->GetExtensionsService(); | 3264 Source<Profile>(source).ptr()->GetExtensionService(); |
3265 ExtensionHost* extension_host = Details<ExtensionHost>(details).ptr(); | 3265 ExtensionHost* extension_host = Details<ExtensionHost>(details).ptr(); |
3266 tab_contents->AddInfoBar(new CrashedExtensionInfoBarDelegate( | 3266 tab_contents->AddInfoBar(new CrashedExtensionInfoBarDelegate( |
3267 tab_contents, extensions_service, extension_host->extension())); | 3267 tab_contents, extensions_service, extension_host->extension())); |
3268 break; | 3268 break; |
3269 } | 3269 } |
3270 | 3270 |
3271 case NotificationType::EXTENSION_LOADED: { | 3271 case NotificationType::EXTENSION_LOADED: { |
3272 window()->GetLocationBar()->UpdatePageActions(); | 3272 window()->GetLocationBar()->UpdatePageActions(); |
3273 | 3273 |
3274 // If any "This extension has crashed" InfoBarDelegates are around for | 3274 // If any "This extension has crashed" InfoBarDelegates are around for |
(...skipping 26 matching lines...) Expand all Loading... |
3301 if (BrowserList::FindBrowserWithType(profile(), | 3301 if (BrowserList::FindBrowserWithType(profile(), |
3302 Browser::TYPE_NORMAL, | 3302 Browser::TYPE_NORMAL, |
3303 true) != this) | 3303 true) != this) |
3304 break; | 3304 break; |
3305 | 3305 |
3306 // We only want to show the loading dialog for themes, but we don't want | 3306 // We only want to show the loading dialog for themes, but we don't want |
3307 // to wait until unpack to find out an extension is a theme, so we test | 3307 // to wait until unpack to find out an extension is a theme, so we test |
3308 // the download_url GURL instead. This means that themes in the extensions | 3308 // the download_url GURL instead. This means that themes in the extensions |
3309 // gallery won't get the loading dialog. | 3309 // gallery won't get the loading dialog. |
3310 GURL download_url = *(Details<GURL>(details).ptr()); | 3310 GURL download_url = *(Details<GURL>(details).ptr()); |
3311 if (ExtensionsService::IsDownloadFromMiniGallery(download_url)) | 3311 if (ExtensionService::IsDownloadFromMiniGallery(download_url)) |
3312 window()->ShowThemeInstallBubble(); | 3312 window()->ShowThemeInstallBubble(); |
3313 break; | 3313 break; |
3314 } | 3314 } |
3315 | 3315 |
3316 case NotificationType::PROFILE_ERROR: { | 3316 case NotificationType::PROFILE_ERROR: { |
3317 if (BrowserList::GetLastActive() != this) | 3317 if (BrowserList::GetLastActive() != this) |
3318 break; | 3318 break; |
3319 int* message_id = Details<int>(details).ptr(); | 3319 int* message_id = Details<int>(details).ptr(); |
3320 window()->ShowProfileErrorDialog(*message_id); | 3320 window()->ShowProfileErrorDialog(*message_id); |
3321 break; | 3321 break; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3489 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); | 3489 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); |
3490 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); | 3490 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); |
3491 | 3491 |
3492 #if defined(OS_CHROMEOS) | 3492 #if defined(OS_CHROMEOS) |
3493 command_updater_.UpdateCommandEnabled(IDC_SEARCH, true); | 3493 command_updater_.UpdateCommandEnabled(IDC_SEARCH, true); |
3494 command_updater_.UpdateCommandEnabled(IDC_SHOW_KEYBOARD_OVERLAY, true); | 3494 command_updater_.UpdateCommandEnabled(IDC_SHOW_KEYBOARD_OVERLAY, true); |
3495 command_updater_.UpdateCommandEnabled(IDC_SYSTEM_OPTIONS, true); | 3495 command_updater_.UpdateCommandEnabled(IDC_SYSTEM_OPTIONS, true); |
3496 command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true); | 3496 command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true); |
3497 #endif | 3497 #endif |
3498 | 3498 |
3499 ExtensionsService* extensions_service = profile()->GetExtensionsService(); | 3499 ExtensionService* extensions_service = profile()->GetExtensionService(); |
3500 bool enable_extensions = | 3500 bool enable_extensions = |
3501 extensions_service && extensions_service->extensions_enabled(); | 3501 extensions_service && extensions_service->extensions_enabled(); |
3502 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, | 3502 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
3503 enable_extensions); | 3503 enable_extensions); |
3504 | 3504 |
3505 // Initialize other commands based on the window type. | 3505 // Initialize other commands based on the window type. |
3506 bool normal_window = type() == TYPE_NORMAL; | 3506 bool normal_window = type() == TYPE_NORMAL; |
3507 bool non_devtools_window = type() != TYPE_DEVTOOLS; | 3507 bool non_devtools_window = type() != TYPE_DEVTOOLS; |
3508 | 3508 |
3509 // Navigation commands | 3509 // Navigation commands |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4160 return false; | 4160 return false; |
4161 } | 4161 } |
4162 | 4162 |
4163 void Browser::CreateInstantIfNecessary() { | 4163 void Browser::CreateInstantIfNecessary() { |
4164 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && | 4164 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && |
4165 !profile()->IsOffTheRecord()) { | 4165 !profile()->IsOffTheRecord()) { |
4166 instant_.reset(new InstantController(profile_, this)); | 4166 instant_.reset(new InstantController(profile_, this)); |
4167 instant_unload_handler_.reset(new InstantUnloadHandler(this)); | 4167 instant_unload_handler_.reset(new InstantUnloadHandler(this)); |
4168 } | 4168 } |
4169 } | 4169 } |
OLD | NEW |