Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 // defined(OS_WIN) | 10 #endif // defined(OS_WIN) |
| (...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1327 // If |mode| is |SEARCH_SUGGESTIONS| and bookmark bar is still showing | 1327 // If |mode| is |SEARCH_SUGGESTIONS| and bookmark bar is still showing |
| 1328 // attached, the previous mode is definitely NTP; it won't be |DEFAULT| | 1328 // attached, the previous mode is definitely NTP; it won't be |DEFAULT| |
| 1329 // because ModeChanged() would have handled that transition by hiding the | 1329 // because ModeChanged() would have handled that transition by hiding the |
| 1330 // bookmark bar. | 1330 // bookmark bar. |
| 1331 if (mode.is_search_suggestions() && | 1331 if (mode.is_search_suggestions() && |
| 1332 bookmark_bar_state_ == BookmarkBar::SHOW) { | 1332 bookmark_bar_state_ == BookmarkBar::SHOW) { |
| 1333 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INSTANT_PREVIEW_STATE); | 1333 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INSTANT_PREVIEW_STATE); |
| 1334 } | 1334 } |
| 1335 } | 1335 } |
| 1336 | 1336 |
| 1337 void Browser::ShowDownload(content::DownloadItem* download) { | |
|
benjhayden
2012/12/20 21:09:14
Can this method be moved out to the Observer? It l
asanka
2012/12/20 22:41:19
The Browser class:
- Handles closing the tab that
| |
| 1338 scoped_ptr<DownloadItemModel> download_model(new DownloadItemModel(download)); | |
| 1339 if (!window()) | |
| 1340 return; | |
| 1341 | |
| 1342 // If the download occurs in a new tab, and it's not a save page | |
| 1343 // download (started before initial navigation completed) close it. | |
| 1344 WebContents* source = download->GetWebContents(); | |
| 1345 if (source && source->GetController().IsInitialNavigation() && | |
| 1346 tab_count() > 1 && !download->IsSavePackageDownload()) { | |
| 1347 CloseContents(source); | |
| 1348 } | |
| 1349 | |
| 1350 // Some (app downloads) are not supposed to appear on the shelf. | |
| 1351 if (!download_model->ShouldShowInShelf()) | |
| 1352 return; | |
| 1353 | |
| 1354 // GetDownloadShelf creates the download shelf if it was not yet created. | |
| 1355 DownloadShelf* shelf = window()->GetDownloadShelf(); | |
| 1356 shelf->AddDownload(download_model.release()); | |
| 1357 // Don't show the animation for "Save file" downloads. | |
| 1358 // For non-theme extensions, we don't show the download animation. | |
| 1359 // Show animation in same window as the download shelf. Download shelf | |
| 1360 // may not be in the same window that initiated the download. | |
| 1361 // Don't show the animation if the selected tab is not visible (i.e. the | |
| 1362 // window is minimized, we're in a unit test, etc.). | |
| 1363 WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser()); | |
| 1364 if ((download->GetTotalBytes() > 0) && | |
| 1365 !download_crx_util::IsExtensionDownload(*download) && | |
| 1366 platform_util::IsVisible(shelf_tab->GetNativeView()) && | |
| 1367 ui::Animation::ShouldRenderRichAnimation()) { | |
| 1368 DownloadStartedAnimation::Show(shelf_tab); | |
| 1369 } | |
| 1370 } | |
| 1371 | |
| 1337 /////////////////////////////////////////////////////////////////////////////// | 1372 /////////////////////////////////////////////////////////////////////////////// |
| 1338 // Browser, content::WebContentsDelegate implementation: | 1373 // Browser, content::WebContentsDelegate implementation: |
| 1339 | 1374 |
| 1340 WebContents* Browser::OpenURLFromTab(WebContents* source, | 1375 WebContents* Browser::OpenURLFromTab(WebContents* source, |
| 1341 const OpenURLParams& params) { | 1376 const OpenURLParams& params) { |
| 1342 chrome::NavigateParams nav_params(this, params.url, params.transition); | 1377 chrome::NavigateParams nav_params(this, params.url, params.transition); |
| 1343 nav_params.source_contents = source; | 1378 nav_params.source_contents = source; |
| 1344 nav_params.referrer = params.referrer; | 1379 nav_params.referrer = params.referrer; |
| 1345 nav_params.extra_headers = params.extra_headers; | 1380 nav_params.extra_headers = params.extra_headers; |
| 1346 nav_params.disposition = params.disposition; | 1381 nav_params.disposition = params.disposition; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1488 } | 1523 } |
| 1489 | 1524 |
| 1490 void Browser::RenderWidgetShowing() { | 1525 void Browser::RenderWidgetShowing() { |
| 1491 window_->DisableInactiveFrame(); | 1526 window_->DisableInactiveFrame(); |
| 1492 } | 1527 } |
| 1493 | 1528 |
| 1494 int Browser::GetExtraRenderViewHeight() const { | 1529 int Browser::GetExtraRenderViewHeight() const { |
| 1495 return window_->GetExtraRenderViewHeight(); | 1530 return window_->GetExtraRenderViewHeight(); |
| 1496 } | 1531 } |
| 1497 | 1532 |
| 1498 void Browser::OnStartDownload(WebContents* source, | |
| 1499 content::DownloadItem* download) { | |
| 1500 scoped_ptr<DownloadItemModel> download_model(new DownloadItemModel(download)); | |
| 1501 if (!download_model->ShouldShowInShelf()) | |
| 1502 return; | |
| 1503 | |
| 1504 WebContents* constrained = GetConstrainingWebContents(source); | |
| 1505 if (constrained != source) { | |
| 1506 // Download in a constrained popup is shown in the tab that opened it. | |
| 1507 constrained->GetDelegate()->OnStartDownload(constrained, download); | |
| 1508 return; | |
| 1509 } | |
| 1510 | |
| 1511 if (!window()) | |
| 1512 return; | |
| 1513 | |
| 1514 // GetDownloadShelf creates the download shelf if it was not yet created. | |
| 1515 DownloadShelf* shelf = window()->GetDownloadShelf(); | |
| 1516 shelf->AddDownload(download_model.release()); | |
| 1517 // Don't show the animation for "Save file" downloads. | |
| 1518 // For non-theme extensions, we don't show the download animation. | |
| 1519 // Show animation in same window as the download shelf. Download shelf | |
| 1520 // may not be in the same window that initiated the download. | |
| 1521 // Don't show the animation if the selected tab is not visible (i.e. the | |
| 1522 // window is minimized, we're in a unit test, etc.). | |
| 1523 WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser()); | |
| 1524 if ((download->GetTotalBytes() > 0) && | |
| 1525 !download_crx_util::IsExtensionDownload(*download) && | |
| 1526 platform_util::IsVisible(shelf_tab->GetNativeView()) && | |
| 1527 ui::Animation::ShouldRenderRichAnimation()) { | |
| 1528 DownloadStartedAnimation::Show(shelf_tab); | |
| 1529 } | |
| 1530 | |
| 1531 // If the download occurs in a new tab, and it's not a save page | |
| 1532 // download (started before initial navigation completed) close it. | |
| 1533 if (source->GetController().IsInitialNavigation() && tab_count() > 1 && | |
| 1534 !download->IsSavePackageDownload()) | |
| 1535 CloseContents(source); | |
| 1536 } | |
| 1537 | |
| 1538 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { | 1533 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
| 1539 DCHECK(source); | 1534 DCHECK(source); |
| 1540 chrome::ViewSource(this, source); | 1535 chrome::ViewSource(this, source); |
| 1541 } | 1536 } |
| 1542 | 1537 |
| 1543 void Browser::ViewSourceForFrame(WebContents* source, | 1538 void Browser::ViewSourceForFrame(WebContents* source, |
| 1544 const GURL& frame_url, | 1539 const GURL& frame_url, |
| 1545 const std::string& frame_content_state) { | 1540 const std::string& frame_content_state) { |
| 1546 DCHECK(source); | 1541 DCHECK(source); |
| 1547 chrome::ViewSource(this, source, frame_url, frame_content_state); | 1542 chrome::ViewSource(this, source, frame_url, frame_content_state); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2441 if (contents && !allow_js_access) { | 2436 if (contents && !allow_js_access) { |
| 2442 contents->web_contents()->GetController().LoadURL( | 2437 contents->web_contents()->GetController().LoadURL( |
| 2443 target_url, | 2438 target_url, |
| 2444 content::Referrer(), | 2439 content::Referrer(), |
| 2445 content::PAGE_TRANSITION_LINK, | 2440 content::PAGE_TRANSITION_LINK, |
| 2446 std::string()); // No extra headers. | 2441 std::string()); // No extra headers. |
| 2447 } | 2442 } |
| 2448 | 2443 |
| 2449 return contents != NULL; | 2444 return contents != NULL; |
| 2450 } | 2445 } |
| OLD | NEW |