| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/extensions/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 if (!contents) { | 475 if (!contents) { |
| 476 error_ = ErrorUtils::FormatErrorMessage( | 476 error_ = ErrorUtils::FormatErrorMessage( |
| 477 keys::kTabNotFoundError, base::IntToString(tab_id)); | 477 keys::kTabNotFoundError, base::IntToString(tab_id)); |
| 478 return false; | 478 return false; |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 Profile* window_profile = profile(); | 483 Profile* window_profile = profile(); |
| 484 Browser::Type window_type = Browser::TYPE_TABBED; | 484 Browser::Type window_type = Browser::TYPE_TABBED; |
| 485 bool create_panel = false; |
| 485 | 486 |
| 486 // panel_create_mode only applies if window is TYPE_PANEL. | 487 // panel_create_mode only applies if create_panel = true |
| 487 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; | 488 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; |
| 488 | 489 |
| 489 gfx::Rect window_bounds; | 490 gfx::Rect window_bounds; |
| 490 bool focused = true; | 491 bool focused = true; |
| 491 bool saw_focus_key = false; | 492 bool saw_focus_key = false; |
| 492 std::string extension_id; | 493 std::string extension_id; |
| 493 | 494 |
| 494 // Decide whether we are opening a normal window or an incognito window. | 495 // Decide whether we are opening a normal window or an incognito window. |
| 495 bool is_error = true; | 496 bool is_error = true; |
| 496 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, | 497 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 514 window_type = Browser::TYPE_POPUP; | 515 window_type = Browser::TYPE_POPUP; |
| 515 extension_id = GetExtension()->id(); | 516 extension_id = GetExtension()->id(); |
| 516 } else if (type_str == keys::kWindowTypeValuePanel || | 517 } else if (type_str == keys::kWindowTypeValuePanel || |
| 517 type_str == keys::kWindowTypeValueDetachedPanel) { | 518 type_str == keys::kWindowTypeValueDetachedPanel) { |
| 518 extension_id = GetExtension()->id(); | 519 extension_id = GetExtension()->id(); |
| 519 bool use_panels = false; | 520 bool use_panels = false; |
| 520 #if !defined(OS_ANDROID) | 521 #if !defined(OS_ANDROID) |
| 521 use_panels = PanelManager::ShouldUsePanels(extension_id); | 522 use_panels = PanelManager::ShouldUsePanels(extension_id); |
| 522 #endif | 523 #endif |
| 523 if (use_panels) { | 524 if (use_panels) { |
| 524 window_type = Browser::TYPE_PANEL; | 525 create_panel = true; |
| 525 #if !defined(OS_CHROMEOS) | 526 #if !defined(OS_CHROMEOS) |
| 526 // Non-ChromeOS has both docked and detached panel types. | 527 // Non-ChromeOS has both docked and detached panel types. |
| 527 if (type_str == keys::kWindowTypeValueDetachedPanel) | 528 if (type_str == keys::kWindowTypeValueDetachedPanel) |
| 528 panel_create_mode = PanelManager::CREATE_AS_DETACHED; | 529 panel_create_mode = PanelManager::CREATE_AS_DETACHED; |
| 529 #endif | 530 #endif |
| 530 } else { | 531 } else { |
| 531 window_type = Browser::TYPE_POPUP; | 532 window_type = Browser::TYPE_POPUP; |
| 532 } | 533 } |
| 533 } else if (type_str != keys::kWindowTypeValueNormal) { | 534 } else if (type_str != keys::kWindowTypeValueNormal) { |
| 534 error_ = keys::kInvalidWindowTypeError; | 535 error_ = keys::kInvalidWindowTypeError; |
| 535 return false; | 536 return false; |
| 536 } | 537 } |
| 537 } | 538 } |
| 538 | 539 |
| 539 // Initialize default window bounds according to window type. | 540 // Initialize default window bounds according to window type. |
| 540 if (Browser::TYPE_TABBED == window_type || | 541 if (window_type == Browser::TYPE_TABBED || |
| 541 Browser::TYPE_POPUP == window_type || | 542 window_type == Browser::TYPE_POPUP || |
| 542 Browser::TYPE_PANEL == window_type) { | 543 create_panel) { |
| 543 // Try to position the new browser relative to its originating | 544 // Try to position the new browser relative to its originating |
| 544 // browser window. The call offsets the bounds by kWindowTilePixels | 545 // browser window. The call offsets the bounds by kWindowTilePixels |
| 545 // (defined in WindowSizer to be 10). | 546 // (defined in WindowSizer to be 10). |
| 546 // | 547 // |
| 547 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here. | 548 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here. |
| 548 // GetBrowserWindowBounds will default to saved "default" values for | 549 // GetBrowserWindowBounds will default to saved "default" values for |
| 549 // the app. | 550 // the app. |
| 550 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; | 551 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; |
| 551 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(), | 552 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(), |
| 552 gfx::Rect(), | 553 gfx::Rect(), |
| 553 GetCurrentBrowser(), | 554 GetCurrentBrowser(), |
| 554 &window_bounds, | 555 &window_bounds, |
| 555 &show_state); | 556 &show_state); |
| 556 } | 557 } |
| 557 | 558 |
| 558 if (Browser::TYPE_PANEL == window_type && | 559 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) { |
| 559 PanelManager::CREATE_AS_DETACHED == panel_create_mode) { | |
| 560 window_bounds.set_origin( | 560 window_bounds.set_origin( |
| 561 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin()); | 561 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin()); |
| 562 } | 562 } |
| 563 | 563 |
| 564 // Any part of the bounds can optionally be set by the caller. | 564 // Any part of the bounds can optionally be set by the caller. |
| 565 int bounds_val = -1; | 565 int bounds_val = -1; |
| 566 if (args->HasKey(keys::kLeftKey)) { | 566 if (args->HasKey(keys::kLeftKey)) { |
| 567 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, | 567 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, |
| 568 &bounds_val)); | 568 &bounds_val)); |
| 569 window_bounds.set_x(bounds_val); | 569 window_bounds.set_x(bounds_val); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 587 window_bounds.set_height(bounds_val); | 587 window_bounds.set_height(bounds_val); |
| 588 } | 588 } |
| 589 | 589 |
| 590 if (args->HasKey(keys::kFocusedKey)) { | 590 if (args->HasKey(keys::kFocusedKey)) { |
| 591 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, | 591 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, |
| 592 &focused)); | 592 &focused)); |
| 593 saw_focus_key = true; | 593 saw_focus_key = true; |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 | 596 |
| 597 if (window_type == Browser::TYPE_PANEL) { | 597 if (create_panel) { |
| 598 if (urls.empty()) | 598 if (urls.empty()) |
| 599 urls.push_back(GURL(chrome::kChromeUINewTabURL)); | 599 urls.push_back(GURL(chrome::kChromeUINewTabURL)); |
| 600 | 600 |
| 601 #if defined(OS_CHROMEOS) | 601 #if defined(OS_CHROMEOS) |
| 602 if (PanelManager::ShouldUsePanels(extension_id)) { | 602 if (PanelManager::ShouldUsePanels(extension_id)) { |
| 603 ShellWindow::CreateParams create_params; | 603 ShellWindow::CreateParams create_params; |
| 604 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL; | 604 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL; |
| 605 create_params.bounds = window_bounds; | 605 create_params.bounds = window_bounds; |
| 606 create_params.minimum_size = window_bounds.size(); | 606 create_params.minimum_size = window_bounds.size(); |
| 607 create_params.maximum_size = window_bounds.size(); | 607 create_params.maximum_size = window_bounds.size(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 632 | 632 |
| 633 SetResult( | 633 SetResult( |
| 634 panel->extension_window_controller()->CreateWindowValueWithTabs( | 634 panel->extension_window_controller()->CreateWindowValueWithTabs( |
| 635 GetExtension())); | 635 GetExtension())); |
| 636 return true; | 636 return true; |
| 637 #endif | 637 #endif |
| 638 } | 638 } |
| 639 | 639 |
| 640 // Create a new BrowserWindow. | 640 // Create a new BrowserWindow. |
| 641 chrome::HostDesktopType host_desktop_type = chrome::GetActiveDesktop(); | 641 chrome::HostDesktopType host_desktop_type = chrome::GetActiveDesktop(); |
| 642 if (create_panel) |
| 643 window_type = Browser::TYPE_POPUP; |
| 642 Browser::CreateParams create_params(window_type, window_profile, | 644 Browser::CreateParams create_params(window_type, window_profile, |
| 643 host_desktop_type); | 645 host_desktop_type); |
| 644 if (extension_id.empty()) { | 646 if (extension_id.empty()) { |
| 645 create_params.initial_bounds = window_bounds; | 647 create_params.initial_bounds = window_bounds; |
| 646 } else { | 648 } else { |
| 647 create_params = Browser::CreateParams::CreateForApp( | 649 create_params = Browser::CreateParams::CreateForApp( |
| 648 window_type, | 650 window_type, |
| 649 web_app::GenerateApplicationNameFromExtensionId(extension_id), | 651 web_app::GenerateApplicationNameFromExtensionId(extension_id), |
| 650 window_bounds, | 652 window_bounds, |
| 651 window_profile, | 653 window_profile, |
| 652 host_desktop_type); | 654 host_desktop_type); |
| 653 } | 655 } |
| 654 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; | 656 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; |
| 655 create_params.host_desktop_type = chrome::GetActiveDesktop(); | 657 create_params.host_desktop_type = chrome::GetActiveDesktop(); |
| 656 | 658 |
| 657 Browser* new_window = CreateBrowserWindow(create_params, window_profile, | 659 Browser* new_window = CreateBrowserWindow(create_params, window_profile, |
| 658 extension_id); | 660 extension_id); |
| 659 | 661 |
| 660 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { | 662 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { |
| 661 WebContents* tab = chrome::AddSelectedTabWithURL( | 663 WebContents* tab = chrome::AddSelectedTabWithURL( |
| 662 new_window, *i, content::PAGE_TRANSITION_LINK); | 664 new_window, *i, content::PAGE_TRANSITION_LINK); |
| 663 if (window_type == Browser::TYPE_PANEL) { | 665 if (create_panel) { |
| 664 extensions::TabHelper::FromWebContents(tab)-> | 666 extensions::TabHelper::FromWebContents(tab)-> |
| 665 SetExtensionAppIconById(extension_id); | 667 SetExtensionAppIconById(extension_id); |
| 666 } | 668 } |
| 667 } | 669 } |
| 668 if (contents) { | 670 if (contents) { |
| 669 TabStripModel* target_tab_strip = new_window->tab_strip_model(); | 671 TabStripModel* target_tab_strip = new_window->tab_strip_model(); |
| 670 target_tab_strip->InsertWebContentsAt(urls.size(), contents, | 672 target_tab_strip->InsertWebContentsAt(urls.size(), contents, |
| 671 TabStripModel::ADD_NONE); | 673 TabStripModel::ADD_NONE); |
| 672 } else if (urls.empty()) { | 674 } else if (urls.empty()) { |
| 673 chrome::NewTab(new_window); | 675 chrome::NewTab(new_window); |
| 674 } | 676 } |
| 675 chrome::SelectNumberedTab(new_window, 0); | 677 chrome::SelectNumberedTab(new_window, 0); |
| 676 | 678 |
| 677 // Unlike other window types, Panels do not take focus by default. | 679 // Unlike other window types, Panels do not take focus by default. |
| 678 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) | 680 if (!saw_focus_key && create_panel) |
| 679 focused = false; | 681 focused = false; |
| 680 | 682 |
| 681 if (focused) | 683 if (focused) |
| 682 new_window->window()->Show(); | 684 new_window->window()->Show(); |
| 683 else | 685 else |
| 684 new_window->window()->ShowInactive(); | 686 new_window->window()->ShowInactive(); |
| 685 | 687 |
| 686 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { | 688 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { |
| 687 // Don't expose incognito windows if the extension isn't allowed. | 689 // Don't expose incognito windows if the extension isn't allowed. |
| 688 SetResult(Value::CreateNullValue()); | 690 SetResult(Value::CreateNullValue()); |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 extension->id(), | 2166 extension->id(), |
| 2165 script_type, | 2167 script_type, |
| 2166 code_string, | 2168 code_string, |
| 2167 frame_scope, | 2169 frame_scope, |
| 2168 run_at, | 2170 run_at, |
| 2169 ScriptExecutor::ISOLATED_WORLD, | 2171 ScriptExecutor::ISOLATED_WORLD, |
| 2170 false /* is_web_view */, | 2172 false /* is_web_view */, |
| 2171 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); | 2173 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); |
| 2172 return true; | 2174 return true; |
| 2173 } | 2175 } |
| OLD | NEW |