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

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

Issue 10919046: Allow panels to be created as detached panels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: avoid panel_create_mode being unused_var in Ash Created 8 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "chrome/browser/extensions/api/tabs/tabs.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return false; 452 return false;
453 contents = source_tab_strip->DetachTabContentsAt(tab_index); 453 contents = source_tab_strip->DetachTabContentsAt(tab_index);
454 if (!contents) { 454 if (!contents) {
455 error_ = ExtensionErrorUtils::FormatErrorMessage( 455 error_ = ExtensionErrorUtils::FormatErrorMessage(
456 keys::kTabNotFoundError, base::IntToString(tab_id)); 456 keys::kTabNotFoundError, base::IntToString(tab_id));
457 return false; 457 return false;
458 } 458 }
459 } 459 }
460 } 460 }
461 461
462 // Try to position the new browser relative its originating browser window.
463 gfx::Rect window_bounds;
464 // The call offsets the bounds by kWindowTilePixels (defined in WindowSizer to
465 // be 10)
466 //
467 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here.
468 // GetBrowserWindowBounds will default to saved "default" values for the app.
469 WindowSizer::GetBrowserWindowBounds(std::string(), gfx::Rect(),
470 GetCurrentBrowser(), &window_bounds);
471
472 // Calculate popup and panels bounds separately.
473 gfx::Rect popup_bounds;
474 gfx::Rect panel_bounds; // Use 0x0 for panels. Panel manager sizes them.
475
476 // In ChromiumOS the default popup bounds is 0x0 which indicates default
477 // window sizes in PanelBrowserView. In other OSs use the same default
478 // bounds as windows.
479 #if defined(OS_CHROMEOS)
480 popup_bounds = panel_bounds;
481 #else
482 popup_bounds = window_bounds; // Use window size as default for popups
483 #endif
484
485 Profile* window_profile = profile(); 462 Profile* window_profile = profile();
486 Browser::Type window_type = Browser::TYPE_TABBED; 463 Browser::Type window_type = Browser::TYPE_TABBED;
464
465 // panel_create_mode only applies if window is TYPE_PANEL.
466 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED;
467
468 gfx::Rect window_bounds;
487 bool focused = true; 469 bool focused = true;
488 bool saw_focus_key = false; 470 bool saw_focus_key = false;
489 std::string extension_id; 471 std::string extension_id;
490 472
491 // Decide whether we are opening a normal window or an incognito window. 473 // Decide whether we are opening a normal window or an incognito window.
492 bool is_error = true; 474 bool is_error = true;
493 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, 475 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls,
494 &is_error); 476 &is_error);
495 if (is_error) { 477 if (is_error) {
496 // error_ member variable is set inside of ShouldOpenIncognitoWindow. 478 // error_ member variable is set inside of ShouldOpenIncognitoWindow.
497 return false; 479 return false;
498 } 480 }
499 if (open_incognito_window) { 481 if (open_incognito_window) {
500 window_profile = window_profile->GetOffTheRecordProfile(); 482 window_profile = window_profile->GetOffTheRecordProfile();
501 } 483 }
502 484
503 if (args) { 485 if (args) {
486 // Figure out window type before figuring out bounds so that default
487 // bounds can be set according to the window type.
488 std::string type_str;
489 if (args->HasKey(keys::kWindowTypeKey)) {
490 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey,
491 &type_str));
492 if (type_str == keys::kWindowTypeValuePopup) {
493 window_type = Browser::TYPE_POPUP;
494 extension_id = GetExtension()->id();
495 } else if (type_str == keys::kWindowTypeValuePanel ||
496 type_str == keys::kWindowTypeValueDetachedPanel) {
497 extension_id = GetExtension()->id();
498 bool use_panels = false;
499 #if !defined(OS_ANDROID)
500 use_panels = PanelManager::ShouldUsePanels(extension_id);
501 #endif
502 if (use_panels) {
503 window_type = Browser::TYPE_PANEL;
504 #if !defined(US_ASH)
505 // Non-Ash has both docked and detached panel types.
506 if (type_str == keys::kWindowTypeValueDetachedPanel)
507 panel_create_mode = PanelManager::CREATE_AS_DETACHED;
508 #endif
509 } else {
510 window_type = Browser::TYPE_POPUP;
511 }
512 } else if (type_str != keys::kWindowTypeValueNormal) {
513 error_ = keys::kInvalidWindowTypeError;
514 return false;
515 }
516 }
517
518 // Initialize default window bounds according to window type.
519 // In ChromiumOS the default popup bounds is 0x0 which indicates default
520 // window sizes in PanelBrowserView. In other OSs use the same default
521 // bounds as windows.
522 #if !defined(OS_CHROMEOS)
523 if (Browser::TYPE_TABBED == window_type ||
524 Browser::TYPE_POPUP == window_type) {
525 #else
526 if (Browser::TYPE_TABBED == window_type) {
527 #endif
528 // Try to position the new browser relative to its originating
529 // browser window. The call offsets the bounds by kWindowTilePixels
530 // (defined in WindowSizer to be 10).
531 //
532 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here.
533 // GetBrowserWindowBounds will default to saved "default" values for
534 // the app.
535 WindowSizer::GetBrowserWindowBounds(std::string(), gfx::Rect(),
536 GetCurrentBrowser(),
537 &window_bounds);
538 }
539
540 if (Browser::TYPE_PANEL == window_type &&
541 PanelManager::CREATE_AS_DETACHED == panel_create_mode) {
542 window_bounds.set_origin(
543 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin());
544 }
545
504 // Any part of the bounds can optionally be set by the caller. 546 // Any part of the bounds can optionally be set by the caller.
505 int bounds_val = -1; 547 int bounds_val = -1;
506 if (args->HasKey(keys::kLeftKey)) { 548 if (args->HasKey(keys::kLeftKey)) {
507 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, 549 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey,
508 &bounds_val)); 550 &bounds_val));
509 window_bounds.set_x(bounds_val); 551 window_bounds.set_x(bounds_val);
510 popup_bounds.set_x(bounds_val);
511 panel_bounds.set_x(bounds_val);
512 } 552 }
513 553
514 if (args->HasKey(keys::kTopKey)) { 554 if (args->HasKey(keys::kTopKey)) {
515 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, 555 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey,
516 &bounds_val)); 556 &bounds_val));
517 window_bounds.set_y(bounds_val); 557 window_bounds.set_y(bounds_val);
518 popup_bounds.set_y(bounds_val);
519 panel_bounds.set_y(bounds_val);
520 } 558 }
521 559
522 if (args->HasKey(keys::kWidthKey)) { 560 if (args->HasKey(keys::kWidthKey)) {
523 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kWidthKey, 561 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kWidthKey,
524 &bounds_val)); 562 &bounds_val));
525 window_bounds.set_width(bounds_val); 563 window_bounds.set_width(bounds_val);
526 popup_bounds.set_width(bounds_val);
527 panel_bounds.set_width(bounds_val);
528 } 564 }
529 565
530 if (args->HasKey(keys::kHeightKey)) { 566 if (args->HasKey(keys::kHeightKey)) {
531 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 567 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey,
532 &bounds_val)); 568 &bounds_val));
533 window_bounds.set_height(bounds_val); 569 window_bounds.set_height(bounds_val);
534 popup_bounds.set_height(bounds_val);
535 panel_bounds.set_height(bounds_val);
536 } 570 }
537 571
538 if (args->HasKey(keys::kFocusedKey)) { 572 if (args->HasKey(keys::kFocusedKey)) {
539 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 573 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey,
540 &focused)); 574 &focused));
541 saw_focus_key = true; 575 saw_focus_key = true;
542 } 576 }
543
544 std::string type_str;
545 if (args->HasKey(keys::kWindowTypeKey)) {
546 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey,
547 &type_str));
548 if (type_str == keys::kWindowTypeValuePopup) {
549 window_type = Browser::TYPE_POPUP;
550 extension_id = GetExtension()->id();
551 } else if (type_str == keys::kWindowTypeValuePanel) {
552 extension_id = GetExtension()->id();
553 bool use_panels = false;
554 #if !defined(OS_ANDROID)
555 use_panels = PanelManager::ShouldUsePanels(extension_id);
556 #endif
557 if (use_panels)
558 window_type = Browser::TYPE_PANEL;
559 else
560 window_type = Browser::TYPE_POPUP;
561 } else if (type_str != keys::kWindowTypeValueNormal) {
562 error_ = keys::kInvalidWindowTypeError;
563 return false;
564 }
565 }
566 } 577 }
567 578
568 if (window_type == Browser::TYPE_PANEL) { 579 #if !defined(USE_ASH)
580 if (window_type == Browser::TYPE_PANEL &&
581 PanelManager::UseBrowserlessPanels()) {
569 std::string title = 582 std::string title =
570 web_app::GenerateApplicationNameFromExtensionId(extension_id); 583 web_app::GenerateApplicationNameFromExtensionId(extension_id);
571 #if !defined(USE_ASH) 584 // Note: Panels ignore all but the first url provided.
572 if (PanelManager::UseBrowserlessPanels()) { 585 Panel* panel = PanelManager::GetInstance()->CreatePanel(
573 // Note: Panels ignore all but the first url provided. 586 title, window_profile, urls[0], window_bounds, panel_create_mode);
574 Panel* panel = PanelManager::GetInstance()->CreatePanel(
575 title, window_profile, urls[0], panel_bounds.size());
576 587
577 // Unlike other window types, Panels do not take focus by default. 588 // Unlike other window types, Panels do not take focus by default.
578 if (!saw_focus_key || !focused) 589 if (!saw_focus_key || !focused)
579 panel->ShowInactive(); 590 panel->ShowInactive();
580 else 591 else
581 panel->Show(); 592 panel->Show();
582 593
583 SetResult( 594 SetResult(
584 panel->extension_window_controller()->CreateWindowValueWithTabs( 595 panel->extension_window_controller()->CreateWindowValueWithTabs(
585 GetExtension())); 596 GetExtension()));
586 return true; 597 return true;
587 } 598 }
599 // else fall through to create BrowserWindow
588 #endif 600 #endif
589 // else fall through to create BrowserWindow
590 }
591 601
592 // Create a new BrowserWindow. 602 // Create a new BrowserWindow.
593 Browser::CreateParams create_params(window_type, window_profile); 603 Browser::CreateParams create_params(window_type, window_profile);
594 if (extension_id.empty()) { 604 if (extension_id.empty()) {
595 create_params.initial_bounds = window_bounds; 605 create_params.initial_bounds = window_bounds;
596 } else { 606 } else {
597 create_params = Browser::CreateParams::CreateForApp( 607 create_params = Browser::CreateParams::CreateForApp(
598 window_type, 608 window_type,
599 web_app::GenerateApplicationNameFromExtensionId(extension_id), 609 web_app::GenerateApplicationNameFromExtensionId(extension_id),
600 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), 610 window_bounds,
601 window_profile); 611 window_profile);
602 } 612 }
603 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; 613 create_params.initial_show_state = ui::SHOW_STATE_NORMAL;
604 614
605 Browser* new_window = CreateBrowserWindow(create_params, window_profile, 615 Browser* new_window = CreateBrowserWindow(create_params, window_profile,
606 extension_id); 616 extension_id);
607 617
608 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { 618 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) {
609 TabContents* tab = chrome::AddSelectedTabWithURL( 619 TabContents* tab = chrome::AddSelectedTabWithURL(
610 new_window, *i, content::PAGE_TRANSITION_LINK); 620 new_window, *i, content::PAGE_TRANSITION_LINK);
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 // called for every API call the extension made. 1833 // called for every API call the extension made.
1824 GotLanguage(language); 1834 GotLanguage(language);
1825 } 1835 }
1826 1836
1827 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1837 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1828 SetResult(Value::CreateStringValue(language.c_str())); 1838 SetResult(Value::CreateStringValue(language.c_str()));
1829 SendResponse(true); 1839 SendResponse(true);
1830 1840
1831 Release(); // Balanced in Run() 1841 Release(); // Balanced in Run()
1832 } 1842 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698