| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 extension_id = GetExtension()->id(); | 463 extension_id = GetExtension()->id(); |
| 464 } else if (type_str == keys::kWindowTypeValuePanel) { | 464 } else if (type_str == keys::kWindowTypeValuePanel) { |
| 465 if (CommandLine::ForCurrentProcess()->HasSwitch( | 465 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 466 switches::kDisablePanels)) { | 466 switches::kDisablePanels)) { |
| 467 window_type = Browser::TYPE_POPUP; | 467 window_type = Browser::TYPE_POPUP; |
| 468 } else { | 468 } else { |
| 469 window_type = Browser::TYPE_PANEL; | 469 window_type = Browser::TYPE_PANEL; |
| 470 } | 470 } |
| 471 extension_id = GetExtension()->id(); | 471 extension_id = GetExtension()->id(); |
| 472 } else if (type_str != keys::kWindowTypeValueNormal) { | 472 } else if (type_str != keys::kWindowTypeValueNormal) { |
| 473 EXTENSION_FUNCTION_VALIDATE(false); | 473 error_ = keys::kInvalidWindowTypeError; |
| 474 return false; |
| 474 } | 475 } |
| 475 } | 476 } |
| 476 } | 477 } |
| 477 | 478 |
| 478 // Unlike other window types, Panels do not take focus by default. | 479 // Unlike other window types, Panels do not take focus by default. |
| 479 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) | 480 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) |
| 480 focused = false; | 481 focused = false; |
| 481 | 482 |
| 482 Browser* new_window; | 483 Browser* new_window; |
| 483 if (extension_id.empty()) { | 484 if (extension_id.empty()) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 524 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 524 | 525 |
| 525 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, | 526 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, |
| 526 include_incognito(), &error_); | 527 include_incognito(), &error_); |
| 527 if (!browser || !browser->window()) { | 528 if (!browser || !browser->window()) { |
| 528 error_ = ExtensionErrorUtils::FormatErrorMessage( | 529 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 529 keys::kWindowNotFoundError, base::IntToString(window_id)); | 530 keys::kWindowNotFoundError, base::IntToString(window_id)); |
| 530 return false; | 531 return false; |
| 531 } | 532 } |
| 532 | 533 |
| 534 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. |
| 535 std::string state_str; |
| 536 if (update_props->HasKey(keys::kShowStateKey)) { |
| 537 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey, |
| 538 &state_str)); |
| 539 if (state_str == keys::kShowStateValueNormal) { |
| 540 show_state = ui::SHOW_STATE_NORMAL; |
| 541 } else if (state_str == keys::kShowStateValueMinimized) { |
| 542 show_state = ui::SHOW_STATE_MINIMIZED; |
| 543 } else if (state_str == keys::kShowStateValueMaximized) { |
| 544 show_state = ui::SHOW_STATE_MAXIMIZED; |
| 545 } else { |
| 546 error_ = keys::kInvalidWindowStateError; |
| 547 return false; |
| 548 } |
| 549 } |
| 550 |
| 551 switch (show_state) { |
| 552 case ui::SHOW_STATE_MINIMIZED: |
| 553 browser->window()->Minimize(); |
| 554 break; |
| 555 case ui::SHOW_STATE_MAXIMIZED: |
| 556 browser->window()->Maximize(); |
| 557 break; |
| 558 case ui::SHOW_STATE_NORMAL: |
| 559 browser->window()->Restore(); |
| 560 break; |
| 561 default: |
| 562 break; |
| 563 } |
| 564 |
| 533 gfx::Rect bounds = browser->window()->GetRestoredBounds(); | 565 gfx::Rect bounds = browser->window()->GetRestoredBounds(); |
| 534 bool set_bounds = false; | 566 bool set_bounds = false; |
| 567 |
| 535 // Any part of the bounds can optionally be set by the caller. | 568 // Any part of the bounds can optionally be set by the caller. |
| 536 int bounds_val; | 569 int bounds_val; |
| 537 if (update_props->HasKey(keys::kLeftKey)) { | 570 if (update_props->HasKey(keys::kLeftKey)) { |
| 538 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 571 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 539 keys::kLeftKey, | 572 keys::kLeftKey, |
| 540 &bounds_val)); | 573 &bounds_val)); |
| 541 bounds.set_x(bounds_val); | 574 bounds.set_x(bounds_val); |
| 542 set_bounds = true; | 575 set_bounds = true; |
| 543 } | 576 } |
| 544 | 577 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 558 set_bounds = true; | 591 set_bounds = true; |
| 559 } | 592 } |
| 560 | 593 |
| 561 if (update_props->HasKey(keys::kHeightKey)) { | 594 if (update_props->HasKey(keys::kHeightKey)) { |
| 562 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 595 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 563 keys::kHeightKey, | 596 keys::kHeightKey, |
| 564 &bounds_val)); | 597 &bounds_val)); |
| 565 bounds.set_height(bounds_val); | 598 bounds.set_height(bounds_val); |
| 566 set_bounds = true; | 599 set_bounds = true; |
| 567 } | 600 } |
| 568 if (set_bounds) | 601 |
| 602 if (set_bounds) { |
| 603 if (show_state == ui::SHOW_STATE_MINIMIZED || |
| 604 show_state == ui::SHOW_STATE_MAXIMIZED) { |
| 605 error_ = keys::kInvalidWindowStateError; |
| 606 return false; |
| 607 } |
| 569 browser->window()->SetBounds(bounds); | 608 browser->window()->SetBounds(bounds); |
| 609 } |
| 570 | 610 |
| 571 bool active_val = false; | 611 bool active_val = false; |
| 572 if (update_props->HasKey(keys::kFocusedKey)) { | 612 if (update_props->HasKey(keys::kFocusedKey)) { |
| 573 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 613 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 574 keys::kFocusedKey, &active_val)); | 614 keys::kFocusedKey, &active_val)); |
| 575 if (active_val) | 615 if (active_val) { |
| 616 if (show_state == ui::SHOW_STATE_MINIMIZED) { |
| 617 error_ = keys::kInvalidWindowStateError; |
| 618 return false; |
| 619 } |
| 576 browser->window()->Activate(); | 620 browser->window()->Activate(); |
| 577 else | 621 } else { |
| 622 if (show_state == ui::SHOW_STATE_MAXIMIZED) { |
| 623 error_ = keys::kInvalidWindowStateError; |
| 624 return false; |
| 625 } |
| 578 browser->window()->Deactivate(); | 626 browser->window()->Deactivate(); |
| 627 } |
| 579 } | 628 } |
| 580 | 629 |
| 581 bool draw_attention = false; | 630 bool draw_attention = false; |
| 582 if (update_props->HasKey(keys::kDrawAttentionKey)) { | 631 if (update_props->HasKey(keys::kDrawAttentionKey)) { |
| 583 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 632 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 584 keys::kDrawAttentionKey, &draw_attention)); | 633 keys::kDrawAttentionKey, &draw_attention)); |
| 585 if (draw_attention) | 634 if (draw_attention) |
| 586 browser->window()->FlashFrame(); | 635 browser->window()->FlashFrame(); |
| 587 } | 636 } |
| 588 | 637 |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 // called for every API call the extension made. | 1616 // called for every API call the extension made. |
| 1568 GotLanguage(language); | 1617 GotLanguage(language); |
| 1569 } | 1618 } |
| 1570 | 1619 |
| 1571 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1620 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1572 result_.reset(Value::CreateStringValue(language.c_str())); | 1621 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1573 SendResponse(true); | 1622 SendResponse(true); |
| 1574 | 1623 |
| 1575 Release(); // Balanced in Run() | 1624 Release(); // Balanced in Run() |
| 1576 } | 1625 } |
| OLD | NEW |