Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/idle_timer.h" | 6 #include "base/idle_timer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 off_the_record_profile, | 302 off_the_record_profile, |
| 303 TYPE_NORMAL); | 303 TYPE_NORMAL); |
| 304 if (!browser) | 304 if (!browser) |
| 305 browser = Browser::Create(off_the_record_profile); | 305 browser = Browser::Create(off_the_record_profile); |
| 306 // TODO(eroman): should we have referrer here? | 306 // TODO(eroman): should we have referrer here? |
| 307 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL); | 307 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL); |
| 308 browser->window()->Show(); | 308 browser->window()->Show(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // static | 311 // static |
| 312 void Browser::OpenWebApplication(Profile* profile, WebApp* app) { | 312 void Browser::OpenApplicationWindow(Profile* profile, const GURL& url) { |
| 313 #if defined(OS_WIN) | 313 const std::wstring& app_name = ComputeApplicationNameFromURL(url); |
|
brettw
2009/02/02 06:26:46
While not wrong, I think this is better as a std::
| |
| 314 const std::wstring& app_name = | |
| 315 app->name().empty() ? ComputeApplicationNameFromURL(app->url()) : | |
| 316 app->name(); | |
| 317 RegisterAppPrefs(app_name); | 314 RegisterAppPrefs(app_name); |
| 318 | 315 |
| 319 Browser* browser = Browser::CreateForApp(app_name, profile); | 316 Browser* browser = Browser::CreateForApp(app_name, profile); |
| 320 browser->AddWebApplicationTab(profile, app, false); | 317 browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, NULL); |
| 321 browser->window()->Show(); | 318 browser->window()->Show(); |
| 322 #endif | |
| 323 } | 319 } |
| 324 | 320 |
| 325 /////////////////////////////////////////////////////////////////////////////// | 321 /////////////////////////////////////////////////////////////////////////////// |
| 326 // Browser, State Storage and Retrieval for UI: | 322 // Browser, State Storage and Retrieval for UI: |
| 327 | 323 |
| 328 std::wstring Browser::GetWindowPlacementKey() const { | 324 std::wstring Browser::GetWindowPlacementKey() const { |
| 329 std::wstring name(prefs::kBrowserWindowPlacement); | 325 std::wstring name(prefs::kBrowserWindowPlacement); |
| 330 if (!app_name_.empty()) { | 326 if (!app_name_.empty()) { |
| 331 name.append(L"_"); | 327 name.append(L"_"); |
| 332 name.append(app_name_); | 328 name.append(app_name_); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 CreateTabContentsForURL(url_to_load, referrer, profile_, transition, | 478 CreateTabContentsForURL(url_to_load, referrer, profile_, transition, |
| 483 false, instance); | 479 false, instance); |
| 484 tabstrip_model_.AddTabContents(contents, -1, transition, foreground); | 480 tabstrip_model_.AddTabContents(contents, -1, transition, foreground); |
| 485 // By default, content believes it is not hidden. When adding contents | 481 // By default, content believes it is not hidden. When adding contents |
| 486 // in the background, tell it that it's hidden. | 482 // in the background, tell it that it's hidden. |
| 487 if (!foreground) | 483 if (!foreground) |
| 488 contents->WasHidden(); | 484 contents->WasHidden(); |
| 489 return contents; | 485 return contents; |
| 490 } | 486 } |
| 491 | 487 |
| 492 #if defined(OS_WIN) | |
| 493 | |
| 494 TabContents* Browser::AddWebApplicationTab(Profile* profile, | |
| 495 WebApp* web_app, | |
| 496 bool lazy) { | |
| 497 DCHECK(web_app); | |
| 498 | |
| 499 // TODO(acw): Do we need an "application launched" transition type? | |
| 500 // TODO(creis): Should we reuse the current instance (ie. process) here? | |
| 501 TabContents* contents = | |
| 502 CreateTabContentsForURL(web_app->url(), GURL(), profile, | |
| 503 PageTransition::LINK, lazy, NULL); | |
| 504 WebContents* web_contents = contents->AsWebContents(); | |
| 505 if (web_contents) | |
| 506 web_contents->SetWebApp(web_app); | |
| 507 | |
| 508 if (lazy) { | |
| 509 contents->controller()->LoadURLLazily( | |
| 510 web_app->url(), GURL(), PageTransition::LINK, web_app->name(), NULL); | |
| 511 } | |
| 512 tabstrip_model_.AddTabContents(contents, -1, PageTransition::LINK, !lazy); | |
| 513 return contents; | |
| 514 } | |
| 515 | |
| 516 #endif | |
| 517 | |
| 518 TabContents* Browser::AddTabWithNavigationController( | 488 TabContents* Browser::AddTabWithNavigationController( |
| 519 NavigationController* ctrl, PageTransition::Type type) { | 489 NavigationController* ctrl, PageTransition::Type type) { |
| 520 TabContents* tc = ctrl->active_contents(); | 490 TabContents* tc = ctrl->active_contents(); |
| 521 tabstrip_model_.AddTabContents(tc, -1, type, true); | 491 tabstrip_model_.AddTabContents(tc, -1, type, true); |
| 522 return tc; | 492 return tc; |
| 523 } | 493 } |
| 524 | 494 |
| 525 #if defined(OS_WIN) | 495 #if defined(OS_WIN) |
| 526 | 496 |
| 527 NavigationController* Browser::AddRestoredTab( | 497 NavigationController* Browser::AddRestoredTab( |
| (...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1825 | 1795 |
| 1826 void Browser::ContentsZoomChange(bool zoom_in) { | 1796 void Browser::ContentsZoomChange(bool zoom_in) { |
| 1827 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); | 1797 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
| 1828 } | 1798 } |
| 1829 | 1799 |
| 1830 bool Browser::IsApplication() const { | 1800 bool Browser::IsApplication() const { |
| 1831 return type_ == TYPE_APP; | 1801 return type_ == TYPE_APP; |
| 1832 } | 1802 } |
| 1833 | 1803 |
| 1834 void Browser::ConvertContentsToApplication(TabContents* contents) { | 1804 void Browser::ConvertContentsToApplication(TabContents* contents) { |
| 1835 WebContents* web_contents = contents->AsWebContents(); | |
| 1836 if (!web_contents || !web_contents->web_app()) { | |
| 1837 NOTREACHED(); | |
| 1838 return; | |
| 1839 } | |
| 1840 | |
| 1841 int index = tabstrip_model_.GetIndexOfTabContents(contents); | 1805 int index = tabstrip_model_.GetIndexOfTabContents(contents); |
| 1842 if (index < 0) | 1806 if (index < 0) |
| 1843 return; | 1807 return; |
| 1844 | 1808 |
| 1845 WebApp* app = web_contents->web_app(); | 1809 const GURL& url = contents->controller()->GetActiveEntry()->url(); |
| 1846 const std::wstring& app_name = app->name().empty() ? | 1810 const std::wstring& app_name = ComputeApplicationNameFromURL(url); |
|
brettw
2009/02/02 06:26:46
Same string comment.
| |
| 1847 ComputeApplicationNameFromURL(app->url()) : app->name(); | |
| 1848 RegisterAppPrefs(app_name); | 1811 RegisterAppPrefs(app_name); |
| 1849 | 1812 |
| 1850 tabstrip_model_.DetachTabContentsAt(index); | 1813 tabstrip_model_.DetachTabContentsAt(index); |
| 1851 Browser* browser = Browser::CreateForApp(app_name, profile_); | 1814 Browser* browser = Browser::CreateForApp(app_name, profile_); |
| 1852 browser->tabstrip_model()->AppendTabContents(contents, true); | 1815 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1853 browser->window()->Show(); | 1816 browser->window()->Show(); |
| 1854 } | 1817 } |
| 1855 | 1818 |
| 1856 void Browser::ContentsStateChanged(TabContents* source) { | 1819 void Browser::ContentsStateChanged(TabContents* source) { |
| 1857 int index = tabstrip_model_.GetIndexOfTabContents(source); | 1820 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2441 | 2404 |
| 2442 void Browser::AdvanceFindSelection(bool forward_direction) { | 2405 void Browser::AdvanceFindSelection(bool forward_direction) { |
| 2443 GetSelectedTabContents()->AsWebContents()->view()->FindInPage( | 2406 GetSelectedTabContents()->AsWebContents()->view()->FindInPage( |
| 2444 *this, true, forward_direction); | 2407 *this, true, forward_direction); |
| 2445 } | 2408 } |
| 2446 | 2409 |
| 2447 void Browser::CloseFrame() { | 2410 void Browser::CloseFrame() { |
| 2448 window_->Close(); | 2411 window_->Close(); |
| 2449 } | 2412 } |
| 2450 | 2413 |
| 2414 #endif // OS_WIN | |
| 2415 | |
| 2451 // static | 2416 // static |
| 2452 std::wstring Browser::ComputeApplicationNameFromURL(const GURL& url) { | 2417 std::wstring Browser::ComputeApplicationNameFromURL(const GURL& url) { |
| 2453 std::string t; | 2418 std::string t; |
| 2454 t.append(url.host()); | 2419 t.append(url.host()); |
| 2455 t.append("_"); | 2420 t.append("_"); |
| 2456 t.append(url.path()); | 2421 t.append(url.path()); |
| 2457 return UTF8ToWide(t); | 2422 return UTF8ToWide(t); |
| 2458 } | 2423 } |
| 2459 | 2424 |
| 2460 // static | 2425 // static |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2472 | 2437 |
| 2473 // We need to register the window position pref. | 2438 // We need to register the window position pref. |
| 2474 std::wstring window_pref(prefs::kBrowserWindowPlacement); | 2439 std::wstring window_pref(prefs::kBrowserWindowPlacement); |
| 2475 window_pref.append(L"_"); | 2440 window_pref.append(L"_"); |
| 2476 window_pref.append(app_name); | 2441 window_pref.append(app_name); |
| 2477 PrefService* prefs = g_browser_process->local_state(); | 2442 PrefService* prefs = g_browser_process->local_state(); |
| 2478 DCHECK(prefs); | 2443 DCHECK(prefs); |
| 2479 | 2444 |
| 2480 prefs->RegisterDictionaryPref(window_pref.c_str()); | 2445 prefs->RegisterDictionaryPref(window_pref.c_str()); |
| 2481 } | 2446 } |
| 2482 | |
| 2483 #endif // OS_WIN | |
| OLD | NEW |