| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "app/animation.h" | 10 #include "app/animation.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // TODO(eroman): should we have referrer here? | 381 // TODO(eroman): should we have referrer here? |
| 382 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, -1, false, | 382 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, -1, false, |
| 383 NULL); | 383 NULL); |
| 384 browser->window()->Show(); | 384 browser->window()->Show(); |
| 385 } | 385 } |
| 386 | 386 |
| 387 // static | 387 // static |
| 388 // TODO(erikkay): There are multiple reasons why this could fail. Should | 388 // TODO(erikkay): There are multiple reasons why this could fail. Should |
| 389 // this function return an error reason as well so that callers can show | 389 // this function return an error reason as well so that callers can show |
| 390 // reasonable errors? | 390 // reasonable errors? |
| 391 bool Browser::OpenApplication(Profile* profile, const std::string& app_id) { | 391 TabContents* Browser::OpenApplication(Profile* profile, |
| 392 const std::string& app_id) { |
| 392 ExtensionsService* extensions_service = profile->GetExtensionsService(); | 393 ExtensionsService* extensions_service = profile->GetExtensionsService(); |
| 393 if (!extensions_service->is_ready()) | 394 if (!extensions_service->is_ready()) |
| 394 return false; | 395 return NULL; |
| 395 | 396 |
| 396 // If the extension with |app_id| could't be found, most likely because it | 397 // If the extension with |app_id| could't be found, most likely because it |
| 397 // was uninstalled. | 398 // was uninstalled. |
| 398 Extension* extension_app = | 399 Extension* extension = extensions_service->GetExtensionById(app_id, false); |
| 399 extensions_service->GetExtensionById(app_id, false); | 400 if (!extension) |
| 400 if (!extension_app) | 401 return NULL; |
| 401 return false; | |
| 402 | 402 |
| 403 // TODO(erikkay): Support refocus. | 403 return OpenApplication(profile, extension, extension->launch_container()); |
| 404 Extension::LaunchContainer launch_container = | 404 } |
| 405 extension_app->launch_container(); | 405 |
| 406 switch (launch_container) { | 406 TabContents* Browser::OpenApplication(Profile* profile, |
| 407 Extension* extension, |
| 408 Extension::LaunchContainer container) { |
| 409 TabContents* tab = NULL; |
| 410 switch (container) { |
| 407 case Extension::LAUNCH_WINDOW: | 411 case Extension::LAUNCH_WINDOW: |
| 408 case Extension::LAUNCH_PANEL: | 412 case Extension::LAUNCH_PANEL: |
| 409 Browser::OpenApplicationWindow(profile, extension_app); | 413 tab = Browser::OpenApplicationWindow(profile, extension, container, |
| 414 GURL()); |
| 410 break; | 415 break; |
| 411 case Extension::LAUNCH_TAB: { | 416 case Extension::LAUNCH_TAB: { |
| 412 return Browser::OpenApplicationTab(profile, extension_app); | 417 tab = Browser::OpenApplicationTab(profile, extension); |
| 413 break; | 418 break; |
| 414 } | 419 } |
| 415 default: | 420 default: |
| 416 NOTREACHED(); | 421 NOTREACHED(); |
| 417 return false; | 422 break; |
| 418 } | 423 } |
| 419 return true; | 424 if (tab) { |
| 425 Browser* browser = tab->delegate()->GetBrowser(); |
| 426 if (browser && extension && extension->launch_fullscreen()) |
| 427 browser->window()->SetFullscreen(true); |
| 428 } |
| 429 return tab; |
| 420 } | 430 } |
| 421 | 431 |
| 422 // static | 432 // static |
| 423 void Browser::OpenApplicationWindow(Profile* profile, Extension* extension, | 433 TabContents* Browser::OpenApplicationWindow( |
| 424 const GURL& url, bool as_panel) { | 434 Profile* profile, |
| 435 Extension* extension, |
| 436 Extension::LaunchContainer container, |
| 437 const GURL& url) { |
| 438 // TODO(erikkay) this can't be correct for extensions |
| 425 std::wstring app_name = web_app::GenerateApplicationNameFromURL(url); | 439 std::wstring app_name = web_app::GenerateApplicationNameFromURL(url); |
| 426 RegisterAppPrefs(app_name); | 440 RegisterAppPrefs(app_name); |
| 427 | 441 |
| 442 bool as_panel = extension && (container == Extension::LAUNCH_PANEL); |
| 428 Browser* browser = Browser::CreateForApp(app_name, extension, profile, | 443 Browser* browser = Browser::CreateForApp(app_name, extension, profile, |
| 429 as_panel); | 444 as_panel); |
| 430 browser->AddTabWithURL(extension ? extension->GetFullLaunchURL() : url, | 445 browser->AddTabWithURL(extension ? extension->GetFullLaunchURL() : url, |
| 431 GURL(), PageTransition::START_PAGE, true, -1, | 446 GURL(), PageTransition::START_PAGE, true, -1, |
| 432 false, NULL); | 447 false, NULL); |
| 433 | 448 |
| 434 TabContents* tab_contents = browser->GetSelectedTabContents(); | 449 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 435 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 450 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 436 tab_contents->render_view_host()->SyncRendererPrefs(); | 451 tab_contents->render_view_host()->SyncRendererPrefs(); |
| 437 browser->window()->Show(); | 452 browser->window()->Show(); |
| 453 |
| 438 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 454 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 439 // focus explicitly. | 455 // focus explicitly. |
| 440 tab_contents->view()->SetInitialFocus(); | 456 tab_contents->view()->SetInitialFocus(); |
| 441 | 457 |
| 442 if (!as_panel) { | 458 if (!as_panel) { |
| 443 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked | 459 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 444 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 460 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 445 // the web app info is available, TabContents notifies Browser via | 461 // the web app info is available, TabContents notifies Browser via |
| 446 // OnDidGetApplicationInfo, which calls | 462 // OnDidGetApplicationInfo, which calls |
| 447 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 463 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 448 // pending web app action. | 464 // pending web app action. |
| 449 browser->pending_web_app_action_ = UPDATE_SHORTCUT; | 465 browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
| 450 } | 466 } |
| 467 |
| 468 return tab_contents; |
| 451 } | 469 } |
| 452 | 470 |
| 453 // static | 471 // static |
| 454 void Browser::OpenApplicationWindow(Profile* profile, Extension* extension) { | 472 TabContents* Browser::OpenApplicationWindow(Profile* profile, |
| 455 OpenApplicationWindow(profile, extension, GURL(), | 473 GURL& url) { |
| 456 (extension->launch_container() == Extension::LAUNCH_PANEL)); | 474 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url); |
| 457 } | 475 } |
| 458 | 476 |
| 459 // static | 477 // static |
| 460 bool Browser::OpenApplicationTab(Profile* profile, Extension* extension) { | 478 TabContents* Browser::OpenApplicationTab(Profile* profile, |
| 479 Extension* extension) { |
| 461 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 480 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 462 if (!browser || browser->type() != Browser::TYPE_NORMAL) | 481 if (!browser || browser->type() != Browser::TYPE_NORMAL) |
| 463 return false; | 482 return NULL; |
| 464 | 483 |
| 465 // TODO(erikkay): This doesn't seem like the right transition in all cases. | 484 // TODO(erikkay): This doesn't seem like the right transition in all cases. |
| 466 PageTransition::Type transition = PageTransition::START_PAGE; | 485 PageTransition::Type transition = PageTransition::START_PAGE; |
| 467 GURL url = extension->GetFullLaunchURL(); | 486 GURL url = extension->GetFullLaunchURL(); |
| 468 TabContents* tab_contents = | 487 TabContents* tab_contents = |
| 469 browser->CreateTabContentsForURL(url, GURL(), profile, | 488 browser->CreateTabContentsForURL(url, GURL(), profile, |
| 470 transition, false, NULL); | 489 transition, false, NULL); |
| 471 tab_contents->SetAppExtension(extension); | 490 tab_contents->SetAppExtension(extension); |
| 472 browser->AddTab(tab_contents, transition); | 491 browser->AddTab(tab_contents, transition); |
| 473 return true; | 492 return tab_contents; |
| 474 } | 493 } |
| 475 | 494 |
| 476 // static | 495 // static |
| 477 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 496 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 478 Browser* browser = Browser::Create(profile); | 497 Browser* browser = Browser::Create(profile); |
| 479 browser->ShowBookmarkManagerTab(); | 498 browser->ShowBookmarkManagerTab(); |
| 480 browser->window()->Show(); | 499 browser->window()->Show(); |
| 481 } | 500 } |
| 482 | 501 |
| 483 #if defined(OS_MACOSX) | 502 #if defined(OS_MACOSX) |
| (...skipping 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3556 if (TabHasUnloadListener(contents)) { | 3575 if (TabHasUnloadListener(contents)) { |
| 3557 // If the page has unload listeners, then we tell the renderer to fire | 3576 // If the page has unload listeners, then we tell the renderer to fire |
| 3558 // them. Once they have fired, we'll get a message back saying whether | 3577 // them. Once they have fired, we'll get a message back saying whether |
| 3559 // to proceed closing the page or not, which sends us back to this method | 3578 // to proceed closing the page or not, which sends us back to this method |
| 3560 // with the HasUnloadListener bit cleared. | 3579 // with the HasUnloadListener bit cleared. |
| 3561 contents->render_view_host()->FirePageBeforeUnload(false); | 3580 contents->render_view_host()->FirePageBeforeUnload(false); |
| 3562 return true; | 3581 return true; |
| 3563 } | 3582 } |
| 3564 return false; | 3583 return false; |
| 3565 } | 3584 } |
| OLD | NEW |