OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3319 } | 3319 } |
3320 | 3320 |
3321 void Browser::RenderWidgetShowing() { | 3321 void Browser::RenderWidgetShowing() { |
3322 window_->DisableInactiveFrame(); | 3322 window_->DisableInactiveFrame(); |
3323 } | 3323 } |
3324 | 3324 |
3325 int Browser::GetExtraRenderViewHeight() const { | 3325 int Browser::GetExtraRenderViewHeight() const { |
3326 return window_->GetExtraRenderViewHeight(); | 3326 return window_->GetExtraRenderViewHeight(); |
3327 } | 3327 } |
3328 | 3328 |
| 3329 void Browser::OnStartDownload(DownloadItem* download, TabContents* tab) { |
| 3330 TabContentsWrapper* wrapper = |
| 3331 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| 3332 TabContentsWrapper* constrained = GetConstrainingContentsWrapper(wrapper); |
| 3333 if (constrained != wrapper) { |
| 3334 // Download in a constrained popup is shown in the tab that opened it. |
| 3335 TabContents* constrained_tab = constrained->tab_contents(); |
| 3336 constrained_tab->delegate()->OnStartDownload(download, constrained_tab); |
| 3337 return; |
| 3338 } |
| 3339 |
| 3340 if (!window()) |
| 3341 return; |
| 3342 |
| 3343 #if defined(OS_CHROMEOS) |
| 3344 // Don't show content browser for extension/theme downloads from gallery. |
| 3345 if (download->is_extension_install()) { |
| 3346 ExtensionService* service = profile_->GetExtensionService(); |
| 3347 if (service && service->IsDownloadFromGallery(download->GetURL(), |
| 3348 download->referrer_url())) { |
| 3349 return; |
| 3350 } |
| 3351 } |
| 3352 // Open the Active Downloads ui for chromeos. |
| 3353 ActiveDownloadsUI::OpenPopup(profile_); |
| 3354 #else |
| 3355 // GetDownloadShelf creates the download shelf if it was not yet created. |
| 3356 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); |
| 3357 |
| 3358 // Don't show the animation for "Save file" downloads. |
| 3359 if (download->total_bytes() <= 0) |
| 3360 return; |
| 3361 |
| 3362 // For non-theme extensions, we don't show the download animation. |
| 3363 if (download->is_extension_install() && |
| 3364 !ExtensionService::IsDownloadFromMiniGallery(download->GetURL())) |
| 3365 return; |
| 3366 |
| 3367 TabContents* current_tab = GetSelectedTabContents(); |
| 3368 // We make this check for the case of minimized windows, unit tests, etc. |
| 3369 if (platform_util::IsVisible(current_tab->GetNativeView()) && |
| 3370 ui::Animation::ShouldRenderRichAnimation()) { |
| 3371 DownloadStartedAnimation::Show(current_tab); |
| 3372 } |
| 3373 #endif |
| 3374 |
| 3375 // If the download occurs in a new tab, close it. |
| 3376 if (tab->controller().IsInitialNavigation() && tab_count() > 1) |
| 3377 CloseContents(tab); |
| 3378 } |
| 3379 |
3329 void Browser::ShowPageInfo(Profile* profile, | 3380 void Browser::ShowPageInfo(Profile* profile, |
3330 const GURL& url, | 3381 const GURL& url, |
3331 const NavigationEntry::SSLStatus& ssl, | 3382 const NavigationEntry::SSLStatus& ssl, |
3332 bool show_history) { | 3383 bool show_history) { |
3333 window()->ShowPageInfo(profile, url, ssl, show_history); | 3384 window()->ShowPageInfo(profile, url, ssl, show_history); |
3334 } | 3385 } |
3335 | 3386 |
3336 void Browser::ViewSourceForTab(TabContents* source, const GURL& page_url) { | 3387 void Browser::ViewSourceForTab(TabContents* source, const GURL& page_url) { |
3337 DCHECK(source); | 3388 DCHECK(source); |
3338 int index = tabstrip_model()->GetWrapperIndex(source); | 3389 int index = tabstrip_model()->GetWrapperIndex(source); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3480 | 3531 |
3481 /////////////////////////////////////////////////////////////////////////////// | 3532 /////////////////////////////////////////////////////////////////////////////// |
3482 // Browser, BookmarkTabHelperDelegate implementation: | 3533 // Browser, BookmarkTabHelperDelegate implementation: |
3483 | 3534 |
3484 void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { | 3535 void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { |
3485 if (source == GetSelectedTabContentsWrapper()) | 3536 if (source == GetSelectedTabContentsWrapper()) |
3486 window_->SetStarredState(starred); | 3537 window_->SetStarredState(starred); |
3487 } | 3538 } |
3488 | 3539 |
3489 /////////////////////////////////////////////////////////////////////////////// | 3540 /////////////////////////////////////////////////////////////////////////////// |
3490 // Browser, DownloadTabHelperDelegate implementation: | |
3491 | |
3492 bool Browser::CanDownload(int request_id) { | |
3493 return true; | |
3494 } | |
3495 | |
3496 void Browser::OnStartDownload(DownloadItem* download, TabContentsWrapper* tab) { | |
3497 if (!window()) | |
3498 return; | |
3499 | |
3500 #if defined(OS_CHROMEOS) | |
3501 // Don't show content browser for extension/theme downloads from gallery. | |
3502 if (download->is_extension_install()) { | |
3503 ExtensionService* service = profile_->GetExtensionService(); | |
3504 if (service && service->IsDownloadFromGallery(download->GetURL(), | |
3505 download->referrer_url())) { | |
3506 return; | |
3507 } | |
3508 } | |
3509 // Open the Active Downloads ui for chromeos. | |
3510 ActiveDownloadsUI::OpenPopup(profile_); | |
3511 #else | |
3512 // GetDownloadShelf creates the download shelf if it was not yet created. | |
3513 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); | |
3514 | |
3515 // Don't show the animation for "Save file" downloads. | |
3516 if (download->total_bytes() <= 0) | |
3517 return; | |
3518 | |
3519 // For non-theme extensions, we don't show the download animation. | |
3520 if (download->is_extension_install() && | |
3521 !ExtensionService::IsDownloadFromMiniGallery(download->GetURL())) | |
3522 return; | |
3523 | |
3524 TabContents* current_tab = GetSelectedTabContents(); | |
3525 // We make this check for the case of minimized windows, unit tests, etc. | |
3526 if (platform_util::IsVisible(current_tab->GetNativeView()) && | |
3527 ui::Animation::ShouldRenderRichAnimation()) { | |
3528 DownloadStartedAnimation::Show(current_tab); | |
3529 } | |
3530 #endif | |
3531 | |
3532 // If the download occurs in a new tab, close it. | |
3533 if (tab->tab_contents()->controller().IsInitialNavigation() && | |
3534 GetConstrainingContentsWrapper(tab) == tab && tab_count() > 1) { | |
3535 CloseContents(tab->tab_contents()); | |
3536 } | |
3537 } | |
3538 | |
3539 /////////////////////////////////////////////////////////////////////////////// | |
3540 // Browser, SelectFileDialog::Listener implementation: | 3541 // Browser, SelectFileDialog::Listener implementation: |
3541 | 3542 |
3542 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 3543 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
3543 profile_->set_last_selected_directory(path.DirName()); | 3544 profile_->set_last_selected_directory(path.DirName()); |
3544 GURL file_url = net::FilePathToFileURL(path); | 3545 GURL file_url = net::FilePathToFileURL(path); |
3545 if (!file_url.is_empty()) | 3546 if (!file_url.is_empty()) |
3546 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 3547 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
3547 } | 3548 } |
3548 | 3549 |
3549 /////////////////////////////////////////////////////////////////////////////// | 3550 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4499 } | 4500 } |
4500 | 4501 |
4501 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { | 4502 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { |
4502 // TabContents... | 4503 // TabContents... |
4503 tab->tab_contents()->set_delegate(delegate); | 4504 tab->tab_contents()->set_delegate(delegate); |
4504 tab->set_delegate(delegate); | 4505 tab->set_delegate(delegate); |
4505 | 4506 |
4506 // ...and all the helpers. | 4507 // ...and all the helpers. |
4507 tab->blocked_content_tab_helper()->set_delegate(delegate); | 4508 tab->blocked_content_tab_helper()->set_delegate(delegate); |
4508 tab->bookmark_tab_helper()->set_delegate(delegate); | 4509 tab->bookmark_tab_helper()->set_delegate(delegate); |
4509 tab->download_tab_helper()->set_delegate(delegate); | |
4510 tab->search_engine_tab_helper()->set_delegate(delegate); | 4510 tab->search_engine_tab_helper()->set_delegate(delegate); |
4511 } | 4511 } |
4512 | 4512 |
4513 void Browser::FindInPage(bool find_next, bool forward_direction) { | 4513 void Browser::FindInPage(bool find_next, bool forward_direction) { |
4514 ShowFindBar(); | 4514 ShowFindBar(); |
4515 if (find_next) { | 4515 if (find_next) { |
4516 string16 find_text; | 4516 string16 find_text; |
4517 #if defined(OS_MACOSX) | 4517 #if defined(OS_MACOSX) |
4518 // We always want to search for the contents of the find pasteboard on OS X. | 4518 // We always want to search for the contents of the find pasteboard on OS X. |
4519 find_text = GetFindPboardText(); | 4519 find_text = GetFindPboardText(); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4769 window_->BookmarkBarStateChanged(animate_type); | 4769 window_->BookmarkBarStateChanged(animate_type); |
4770 } | 4770 } |
4771 | 4771 |
4772 void Browser::ShowSyncSetup() { | 4772 void Browser::ShowSyncSetup() { |
4773 ProfileSyncService* service = profile()->GetProfileSyncService(); | 4773 ProfileSyncService* service = profile()->GetProfileSyncService(); |
4774 if (service->HasSyncSetupCompleted()) | 4774 if (service->HasSyncSetupCompleted()) |
4775 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4775 ShowOptionsTab(chrome::kSyncSetupSubPage); |
4776 else | 4776 else |
4777 profile()->GetProfileSyncService()->ShowLoginDialog(); | 4777 profile()->GetProfileSyncService()->ShowLoginDialog(); |
4778 } | 4778 } |
OLD | NEW |