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

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 8586045: Add extension API to change window show state using chrome.windows.update(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cr feedback Created 9 years, 1 month 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) 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
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 EXTENSION_FUNCTION_ERROR(keys::kInvalidWindowTypeError);
474 } 474 }
475 } 475 }
476 } 476 }
477 477
478 // Unlike other window types, Panels do not take focus by default. 478 // Unlike other window types, Panels do not take focus by default.
479 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) 479 if (!saw_focus_key && window_type == Browser::TYPE_PANEL)
480 focused = false; 480 focused = false;
481 481
482 Browser* new_window; 482 Browser* new_window;
483 if (extension_id.empty()) { 483 if (extension_id.empty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 523 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
524 524
525 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, 525 Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
526 include_incognito(), &error_); 526 include_incognito(), &error_);
527 if (!browser || !browser->window()) { 527 if (!browser || !browser->window()) {
528 error_ = ExtensionErrorUtils::FormatErrorMessage( 528 error_ = ExtensionErrorUtils::FormatErrorMessage(
529 keys::kWindowNotFoundError, base::IntToString(window_id)); 529 keys::kWindowNotFoundError, base::IntToString(window_id));
530 return false; 530 return false;
531 } 531 }
532 532
533 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
534 std::string state_str;
535 if (update_props->HasKey(keys::kShowStateKey)) {
536 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
537 &state_str));
538 if (state_str == keys::kShowStateValueNormal)
539 show_state = ui::SHOW_STATE_NORMAL;
540 else if (state_str == keys::kShowStateValueMinimized)
541 show_state = ui::SHOW_STATE_MINIMIZED;
542 else if (state_str == keys::kShowStateValueMaximized)
543 show_state = ui::SHOW_STATE_MAXIMIZED;
544 else
545 EXTENSION_FUNCTION_ERROR(keys::kInvalidWindowStateError);
546 }
547
548 switch (show_state) {
549 case ui::SHOW_STATE_MINIMIZED:
550 browser->window()->Minimize();
551 break;
552 case ui::SHOW_STATE_MAXIMIZED:
553 browser->window()->Maximize();
554 break;
555 case ui::SHOW_STATE_NORMAL:
556 browser->window()->Restore();
557 break;
558 default:
559 break;
560 }
561
533 gfx::Rect bounds = browser->window()->GetRestoredBounds(); 562 gfx::Rect bounds = browser->window()->GetRestoredBounds();
534 bool set_bounds = false; 563 bool set_bounds = false;
564
535 // Any part of the bounds can optionally be set by the caller. 565 // Any part of the bounds can optionally be set by the caller.
536 int bounds_val; 566 int bounds_val;
537 if (update_props->HasKey(keys::kLeftKey)) { 567 if (update_props->HasKey(keys::kLeftKey)) {
538 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 568 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
539 keys::kLeftKey, 569 keys::kLeftKey,
540 &bounds_val)); 570 &bounds_val));
541 bounds.set_x(bounds_val); 571 bounds.set_x(bounds_val);
542 set_bounds = true; 572 set_bounds = true;
543 } 573 }
544 574
(...skipping 13 matching lines...) Expand all
558 set_bounds = true; 588 set_bounds = true;
559 } 589 }
560 590
561 if (update_props->HasKey(keys::kHeightKey)) { 591 if (update_props->HasKey(keys::kHeightKey)) {
562 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 592 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
563 keys::kHeightKey, 593 keys::kHeightKey,
564 &bounds_val)); 594 &bounds_val));
565 bounds.set_height(bounds_val); 595 bounds.set_height(bounds_val);
566 set_bounds = true; 596 set_bounds = true;
567 } 597 }
568 if (set_bounds) 598
569 browser->window()->SetBounds(bounds); 599 if (set_bounds) {
600 if (show_state == ui::SHOW_STATE_MINIMIZED ||
601 show_state == ui::SHOW_STATE_MAXIMIZED)
602 EXTENSION_FUNCTION_ERROR(keys::kInvalidWindowStateError);
603 else
604 browser->window()->SetBounds(bounds);
605 }
570 606
571 bool active_val = false; 607 bool active_val = false;
572 if (update_props->HasKey(keys::kFocusedKey)) { 608 if (update_props->HasKey(keys::kFocusedKey)) {
573 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 609 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
574 keys::kFocusedKey, &active_val)); 610 keys::kFocusedKey, &active_val));
575 if (active_val) 611 if (active_val) {
576 browser->window()->Activate(); 612 if (show_state == ui::SHOW_STATE_MINIMIZED)
577 else 613 EXTENSION_FUNCTION_ERROR(keys::kInvalidWindowStateError);
578 browser->window()->Deactivate(); 614 else
615 browser->window()->Activate();
616 } else {
617 if (show_state == ui::SHOW_STATE_MAXIMIZED)
618 EXTENSION_FUNCTION_ERROR(keys::kInvalidWindowStateError);
asargent_no_longer_on_chrome 2011/11/21 19:04:05 nit: EXTENSION_FUNCTION_ERROR sets bad_message_ =
619 else
620 browser->window()->Deactivate();
621 }
579 } 622 }
580 623
581 bool draw_attention = false; 624 bool draw_attention = false;
582 if (update_props->HasKey(keys::kDrawAttentionKey)) { 625 if (update_props->HasKey(keys::kDrawAttentionKey)) {
583 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 626 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
584 keys::kDrawAttentionKey, &draw_attention)); 627 keys::kDrawAttentionKey, &draw_attention));
585 if (draw_attention) 628 if (draw_attention)
586 browser->window()->FlashFrame(); 629 browser->window()->FlashFrame();
587 } 630 }
588 631
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 // called for every API call the extension made. 1610 // called for every API call the extension made.
1568 GotLanguage(language); 1611 GotLanguage(language);
1569 } 1612 }
1570 1613
1571 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1614 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1572 result_.reset(Value::CreateStringValue(language.c_str())); 1615 result_.reset(Value::CreateStringValue(language.c_str()));
1573 SendResponse(true); 1616 SendResponse(true);
1574 1617
1575 Release(); // Balanced in Run() 1618 Release(); // Balanced in Run()
1576 } 1619 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tabs_apitest.cc ('k') | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698