Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 13139004: Deprecate Browser::TYPE_PANEL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 25 matching lines...) Expand all
633 633
634 SetResult( 634 SetResult(
635 panel->extension_window_controller()->CreateWindowValueWithTabs( 635 panel->extension_window_controller()->CreateWindowValueWithTabs(
636 GetExtension())); 636 GetExtension()));
637 return true; 637 return true;
638 #endif 638 #endif
639 } 639 }
640 640
641 // Create a new BrowserWindow. 641 // Create a new BrowserWindow.
642 chrome::HostDesktopType host_desktop_type = chrome::GetActiveDesktop(); 642 chrome::HostDesktopType host_desktop_type = chrome::GetActiveDesktop();
643 if (create_panel)
644 window_type = Browser::TYPE_POPUP;
643 Browser::CreateParams create_params(window_type, window_profile, 645 Browser::CreateParams create_params(window_type, window_profile,
644 host_desktop_type); 646 host_desktop_type);
645 if (extension_id.empty()) { 647 if (extension_id.empty()) {
646 create_params.initial_bounds = window_bounds; 648 create_params.initial_bounds = window_bounds;
647 } else { 649 } else {
648 create_params = Browser::CreateParams::CreateForApp( 650 create_params = Browser::CreateParams::CreateForApp(
649 window_type, 651 window_type,
650 web_app::GenerateApplicationNameFromExtensionId(extension_id), 652 web_app::GenerateApplicationNameFromExtensionId(extension_id),
651 window_bounds, 653 window_bounds,
652 window_profile, 654 window_profile,
653 host_desktop_type); 655 host_desktop_type);
654 } 656 }
655 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; 657 create_params.initial_show_state = ui::SHOW_STATE_NORMAL;
656 create_params.host_desktop_type = chrome::GetActiveDesktop(); 658 create_params.host_desktop_type = chrome::GetActiveDesktop();
657 659
658 Browser* new_window = CreateBrowserWindow(create_params, window_profile, 660 Browser* new_window = CreateBrowserWindow(create_params, window_profile,
659 extension_id); 661 extension_id);
660 662
661 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { 663 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) {
662 WebContents* tab = chrome::AddSelectedTabWithURL( 664 WebContents* tab = chrome::AddSelectedTabWithURL(
663 new_window, *i, content::PAGE_TRANSITION_LINK); 665 new_window, *i, content::PAGE_TRANSITION_LINK);
664 if (window_type == Browser::TYPE_PANEL) { 666 if (create_panel) {
665 extensions::TabHelper::FromWebContents(tab)-> 667 extensions::TabHelper::FromWebContents(tab)->
666 SetExtensionAppIconById(extension_id); 668 SetExtensionAppIconById(extension_id);
667 } 669 }
668 } 670 }
669 if (contents) { 671 if (contents) {
670 TabStripModel* target_tab_strip = new_window->tab_strip_model(); 672 TabStripModel* target_tab_strip = new_window->tab_strip_model();
671 target_tab_strip->InsertWebContentsAt(urls.size(), contents, 673 target_tab_strip->InsertWebContentsAt(urls.size(), contents,
672 TabStripModel::ADD_NONE); 674 TabStripModel::ADD_NONE);
673 } else if (urls.empty()) { 675 } else if (urls.empty()) {
674 chrome::NewTab(new_window); 676 chrome::NewTab(new_window);
675 } 677 }
676 chrome::SelectNumberedTab(new_window, 0); 678 chrome::SelectNumberedTab(new_window, 0);
677 679
678 // Unlike other window types, Panels do not take focus by default. 680 // Unlike other window types, Panels do not take focus by default.
679 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) 681 if (!saw_focus_key && create_panel)
680 focused = false; 682 focused = false;
681 683
682 if (focused) 684 if (focused)
683 new_window->window()->Show(); 685 new_window->window()->Show();
684 else 686 else
685 new_window->window()->ShowInactive(); 687 new_window->window()->ShowInactive();
686 688
687 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { 689 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) {
688 // Don't expose incognito windows if the extension isn't allowed. 690 // Don't expose incognito windows if the extension isn't allowed.
689 SetResult(Value::CreateNullValue()); 691 SetResult(Value::CreateNullValue());
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 extension->id(), 2167 extension->id(),
2166 script_type, 2168 script_type,
2167 code_string, 2169 code_string,
2168 frame_scope, 2170 frame_scope,
2169 run_at, 2171 run_at,
2170 ScriptExecutor::ISOLATED_WORLD, 2172 ScriptExecutor::ISOLATED_WORLD,
2171 false /* is_web_view */, 2173 false /* is_web_view */,
2172 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); 2174 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this));
2173 return true; 2175 return true;
2174 } 2176 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/ash_panel_contents.h ('k') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698