| 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 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 WebContents* web_contents = tab_strip_model_->GetActiveWebContents(); | 578 WebContents* web_contents = tab_strip_model_->GetActiveWebContents(); |
| 579 // |web_contents| can be NULL since GetCurrentPageIcon() is called by the | 579 // |web_contents| can be NULL since GetCurrentPageIcon() is called by the |
| 580 // window during the window's creation (before tabs have been added). | 580 // window during the window's creation (before tabs have been added). |
| 581 favicon::FaviconDriver* favicon_driver = | 581 favicon::FaviconDriver* favicon_driver = |
| 582 web_contents | 582 web_contents |
| 583 ? favicon::ContentFaviconDriver::FromWebContents(web_contents) | 583 ? favicon::ContentFaviconDriver::FromWebContents(web_contents) |
| 584 : nullptr; | 584 : nullptr; |
| 585 return favicon_driver ? favicon_driver->GetFavicon() : gfx::Image(); | 585 return favicon_driver ? favicon_driver->GetFavicon() : gfx::Image(); |
| 586 } | 586 } |
| 587 | 587 |
| 588 base::string16 Browser::GetWindowTitleForCurrentTab() const { | 588 base::string16 Browser::GetWindowTitleForCurrentTab( |
| 589 bool include_app_name) const { |
| 589 WebContents* contents = tab_strip_model_->GetActiveWebContents(); | 590 WebContents* contents = tab_strip_model_->GetActiveWebContents(); |
| 590 base::string16 title; | 591 base::string16 title; |
| 591 | 592 |
| 592 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the | 593 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 593 // window during the window's creation (before tabs have been added). | 594 // window during the window's creation (before tabs have been added). |
| 594 if (contents) { | 595 if (contents) { |
| 595 // The web app frame uses the host instead of the title. | 596 // The web app frame uses the host instead of the title. |
| 596 if (ShouldUseWebAppFrame()) | 597 if (ShouldUseWebAppFrame()) |
| 597 return base::UTF8ToUTF16(contents->GetURL().host()); | 598 return base::UTF8ToUTF16(contents->GetURL().host()); |
| 598 | 599 |
| 599 title = contents->GetTitle(); | 600 title = contents->GetTitle(); |
| 600 FormatTitleForDisplay(&title); | 601 FormatTitleForDisplay(&title); |
| 601 } | 602 } |
| 602 if (title.empty()) | 603 if (title.empty()) |
| 603 title = CoreTabHelper::GetDefaultTitle(); | 604 title = CoreTabHelper::GetDefaultTitle(); |
| 604 | 605 |
| 605 #if defined(OS_MACOSX) || defined(USE_ASH) | 606 #if defined(OS_MACOSX) |
| 606 // On Mac and Ash, we don't want to suffix the page title with the application | 607 // On Mac, we don't want to suffix the page title with the application name. |
| 607 // name. | |
| 608 return title; | 608 return title; |
| 609 #endif | 609 #endif |
| 610 // Don't append the app name to window titles on app frames and app popups | 610 // Include the app name in window titles for tabbed browser windows when |
| 611 return is_app() ? | 611 // requested with |include_app_name|. |
| 612 title : | 612 return (!is_app() && include_app_name) ? |
| 613 l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, title); | 613 l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, title): |
| 614 title; |
| 614 } | 615 } |
| 615 | 616 |
| 616 // static | 617 // static |
| 617 void Browser::FormatTitleForDisplay(base::string16* title) { | 618 void Browser::FormatTitleForDisplay(base::string16* title) { |
| 618 size_t current_index = 0; | 619 size_t current_index = 0; |
| 619 size_t match_index; | 620 size_t match_index; |
| 620 while ((match_index = title->find(L'\n', current_index)) != | 621 while ((match_index = title->find(L'\n', current_index)) != |
| 621 base::string16::npos) { | 622 base::string16::npos) { |
| 622 title->replace(match_index, 1, base::string16()); | 623 title->replace(match_index, 1, base::string16()); |
| 623 current_index = match_index; | 624 current_index = match_index; |
| (...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 if (contents && !allow_js_access) { | 2599 if (contents && !allow_js_access) { |
| 2599 contents->web_contents()->GetController().LoadURL( | 2600 contents->web_contents()->GetController().LoadURL( |
| 2600 target_url, | 2601 target_url, |
| 2601 content::Referrer(), | 2602 content::Referrer(), |
| 2602 ui::PAGE_TRANSITION_LINK, | 2603 ui::PAGE_TRANSITION_LINK, |
| 2603 std::string()); // No extra headers. | 2604 std::string()); // No extra headers. |
| 2604 } | 2605 } |
| 2605 | 2606 |
| 2606 return contents != NULL; | 2607 return contents != NULL; |
| 2607 } | 2608 } |
| OLD | NEW |