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 <shellapi.h> | 8 #include <shellapi.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 3283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3294 } | 3294 } |
3295 | 3295 |
3296 void Browser::RenderWidgetShowing() { | 3296 void Browser::RenderWidgetShowing() { |
3297 window_->DisableInactiveFrame(); | 3297 window_->DisableInactiveFrame(); |
3298 } | 3298 } |
3299 | 3299 |
3300 int Browser::GetExtraRenderViewHeight() const { | 3300 int Browser::GetExtraRenderViewHeight() const { |
3301 return window_->GetExtraRenderViewHeight(); | 3301 return window_->GetExtraRenderViewHeight(); |
3302 } | 3302 } |
3303 | 3303 |
3304 void Browser::OnStartDownload(DownloadItem* download, TabContents* tab) { | |
3305 if (!window()) | |
3306 return; | |
3307 | |
3308 #if defined(OS_CHROMEOS) | |
3309 // Don't show content browser for extension/theme downloads from gallery. | |
3310 if (download->is_extension_install()) { | |
3311 ExtensionService* service = profile_->GetExtensionService(); | |
3312 if (service && service->IsDownloadFromGallery(download->url(), | |
3313 download->referrer_url())) { | |
3314 return; | |
3315 } | |
3316 } | |
3317 // Open the Active Downloads ui for chromeos. | |
3318 ActiveDownloadsUI::OpenPopup(profile_); | |
3319 #else | |
3320 // GetDownloadShelf creates the download shelf if it was not yet created. | |
3321 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); | |
3322 | |
3323 // Don't show the animation for "Save file" downloads. | |
3324 if (download->total_bytes() <= 0) | |
3325 return; | |
3326 | |
3327 // For non-theme extensions, we don't show the download animation. | |
3328 if (download->is_extension_install() && | |
3329 !ExtensionService::IsDownloadFromMiniGallery(download->url())) | |
3330 return; | |
3331 | |
3332 TabContents* current_tab = GetSelectedTabContents(); | |
3333 // We make this check for the case of minimized windows, unit tests, etc. | |
3334 if (platform_util::IsVisible(current_tab->GetNativeView()) && | |
3335 ui::Animation::ShouldRenderRichAnimation()) { | |
3336 DownloadStartedAnimation::Show(current_tab); | |
3337 } | |
3338 #endif | |
3339 | |
3340 // If the download occurs in a new tab, close it. | |
3341 TabContentsWrapper* wrapper = | |
3342 TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
3343 if (tab->controller().IsInitialNavigation() && | |
3344 GetConstrainingContentsWrapper(wrapper) == wrapper && tab_count() > 1) { | |
3345 CloseContents(tab); | |
3346 } | |
3347 } | |
3348 | |
3349 void Browser::ShowPageInfo(Profile* profile, | 3304 void Browser::ShowPageInfo(Profile* profile, |
3350 const GURL& url, | 3305 const GURL& url, |
3351 const NavigationEntry::SSLStatus& ssl, | 3306 const NavigationEntry::SSLStatus& ssl, |
3352 bool show_history) { | 3307 bool show_history) { |
3353 window()->ShowPageInfo(profile, url, ssl, show_history); | 3308 window()->ShowPageInfo(profile, url, ssl, show_history); |
3354 } | 3309 } |
3355 | 3310 |
3356 void Browser::ViewSourceForTab(TabContents* source, const GURL& page_url) { | 3311 void Browser::ViewSourceForTab(TabContents* source, const GURL& page_url) { |
3357 DCHECK(source); | 3312 DCHECK(source); |
3358 int index = tabstrip_model()->GetWrapperIndex(source); | 3313 int index = tabstrip_model()->GetWrapperIndex(source); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3478 | 3433 |
3479 /////////////////////////////////////////////////////////////////////////////// | 3434 /////////////////////////////////////////////////////////////////////////////// |
3480 // Browser, BookmarkTabHelperDelegate implementation: | 3435 // Browser, BookmarkTabHelperDelegate implementation: |
3481 | 3436 |
3482 void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { | 3437 void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { |
3483 if (source == GetSelectedTabContentsWrapper()) | 3438 if (source == GetSelectedTabContentsWrapper()) |
3484 window_->SetStarredState(starred); | 3439 window_->SetStarredState(starred); |
3485 } | 3440 } |
3486 | 3441 |
3487 /////////////////////////////////////////////////////////////////////////////// | 3442 /////////////////////////////////////////////////////////////////////////////// |
| 3443 // Browser, DownloadTabHelperDelegate implementation: |
| 3444 |
| 3445 bool Browser::CanDownload(int request_id) { |
| 3446 return true; |
| 3447 } |
| 3448 |
| 3449 void Browser::OnStartDownload(DownloadItem* download, TabContentsWrapper* tab) { |
| 3450 if (!window()) |
| 3451 return; |
| 3452 |
| 3453 #if defined(OS_CHROMEOS) |
| 3454 // Don't show content browser for extension/theme downloads from gallery. |
| 3455 if (download->is_extension_install()) { |
| 3456 ExtensionService* service = profile_->GetExtensionService(); |
| 3457 if (service && service->IsDownloadFromGallery(download->url(), |
| 3458 download->referrer_url())) { |
| 3459 return; |
| 3460 } |
| 3461 } |
| 3462 // Open the Active Downloads ui for chromeos. |
| 3463 ActiveDownloadsUI::OpenPopup(profile_); |
| 3464 #else |
| 3465 // GetDownloadShelf creates the download shelf if it was not yet created. |
| 3466 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); |
| 3467 |
| 3468 // Don't show the animation for "Save file" downloads. |
| 3469 if (download->total_bytes() <= 0) |
| 3470 return; |
| 3471 |
| 3472 // For non-theme extensions, we don't show the download animation. |
| 3473 if (download->is_extension_install() && |
| 3474 !ExtensionService::IsDownloadFromMiniGallery(download->url())) |
| 3475 return; |
| 3476 |
| 3477 TabContents* current_tab = GetSelectedTabContents(); |
| 3478 // We make this check for the case of minimized windows, unit tests, etc. |
| 3479 if (platform_util::IsVisible(current_tab->GetNativeView()) && |
| 3480 ui::Animation::ShouldRenderRichAnimation()) { |
| 3481 DownloadStartedAnimation::Show(current_tab); |
| 3482 } |
| 3483 #endif |
| 3484 |
| 3485 // If the download occurs in a new tab, close it. |
| 3486 if (tab->tab_contents()->controller().IsInitialNavigation() && |
| 3487 GetConstrainingContentsWrapper(tab) == tab && tab_count() > 1) { |
| 3488 CloseContents(tab->tab_contents()); |
| 3489 } |
| 3490 } |
| 3491 |
| 3492 /////////////////////////////////////////////////////////////////////////////// |
3488 // Browser, SelectFileDialog::Listener implementation: | 3493 // Browser, SelectFileDialog::Listener implementation: |
3489 | 3494 |
3490 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 3495 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
3491 profile_->set_last_selected_directory(path.DirName()); | 3496 profile_->set_last_selected_directory(path.DirName()); |
3492 GURL file_url = net::FilePathToFileURL(path); | 3497 GURL file_url = net::FilePathToFileURL(path); |
3493 if (!file_url.is_empty()) | 3498 if (!file_url.is_empty()) |
3494 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 3499 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
3495 } | 3500 } |
3496 | 3501 |
3497 /////////////////////////////////////////////////////////////////////////////// | 3502 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4377 } | 4382 } |
4378 | 4383 |
4379 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { | 4384 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { |
4380 // TabContents... | 4385 // TabContents... |
4381 tab->tab_contents()->set_delegate(delegate); | 4386 tab->tab_contents()->set_delegate(delegate); |
4382 tab->set_delegate(delegate); | 4387 tab->set_delegate(delegate); |
4383 | 4388 |
4384 // ...and all the helpers. | 4389 // ...and all the helpers. |
4385 tab->blocked_content_tab_helper()->set_delegate(delegate); | 4390 tab->blocked_content_tab_helper()->set_delegate(delegate); |
4386 tab->bookmark_tab_helper()->set_delegate(delegate); | 4391 tab->bookmark_tab_helper()->set_delegate(delegate); |
| 4392 tab->download_tab_helper()->set_delegate(delegate); |
4387 tab->search_engine_tab_helper()->set_delegate(delegate); | 4393 tab->search_engine_tab_helper()->set_delegate(delegate); |
4388 } | 4394 } |
4389 | 4395 |
4390 void Browser::FindInPage(bool find_next, bool forward_direction) { | 4396 void Browser::FindInPage(bool find_next, bool forward_direction) { |
4391 ShowFindBar(); | 4397 ShowFindBar(); |
4392 if (find_next) { | 4398 if (find_next) { |
4393 string16 find_text; | 4399 string16 find_text; |
4394 #if defined(OS_MACOSX) | 4400 #if defined(OS_MACOSX) |
4395 // We always want to search for the contents of the find pasteboard on OS X. | 4401 // We always want to search for the contents of the find pasteboard on OS X. |
4396 find_text = GetFindPboardText(); | 4402 find_text = GetFindPboardText(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4600 TabContents* current_tab = GetSelectedTabContents(); | 4606 TabContents* current_tab = GetSelectedTabContents(); |
4601 if (current_tab) { | 4607 if (current_tab) { |
4602 content_restrictions = current_tab->content_restrictions(); | 4608 content_restrictions = current_tab->content_restrictions(); |
4603 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); | 4609 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
4604 // See comment in UpdateCommandsForTabState about why we call url(). | 4610 // See comment in UpdateCommandsForTabState about why we call url(). |
4605 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) | 4611 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
4606 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 4612 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
4607 } | 4613 } |
4608 return content_restrictions; | 4614 return content_restrictions; |
4609 } | 4615 } |
OLD | NEW |