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

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: make test non-linux, generated crx docs 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 512 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 gfx::Rect bounds = browser->window()->GetRestoredBounds(); 533 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
534 bool set_bounds = false; 534 std::string state_str;
535 // Any part of the bounds can optionally be set by the caller. 535 if (update_props->HasKey(keys::kShowStateKey)) {
536 int bounds_val; 536 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
537 if (update_props->HasKey(keys::kLeftKey)) { 537 &state_str));
538 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 538 if (state_str == keys::kShowStateValueNormal)
539 keys::kLeftKey, 539 show_state = ui::SHOW_STATE_NORMAL;
540 &bounds_val)); 540 else if (state_str == keys::kShowStateValueMinimized)
541 bounds.set_x(bounds_val); 541 show_state = ui::SHOW_STATE_MINIMIZED;
542 set_bounds = true; 542 else if (state_str == keys::kShowStateValueMaximized)
543 show_state = ui::SHOW_STATE_MAXIMIZED;
544 else
545 EXTENSION_FUNCTION_VALIDATE(false);
asargent_no_longer_on_chrome 2011/11/18 18:52:24 nit: instead of EXTENSION_FUNCTION_VALIDATE(false
jennb 2011/11/19 01:44:33 Done.
543 } 546 }
544 547
545 if (update_props->HasKey(keys::kTopKey)) { 548 // Bounds information is ignored if minimized or maximized state is requested.
asargent_no_longer_on_chrome 2011/11/18 18:52:24 Instead of ignoring, I wonder if it would make sen
jennb 2011/11/19 01:44:33 Done.
546 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 549 if (show_state == ui::SHOW_STATE_MINIMIZED) {
547 keys::kTopKey, 550 browser->window()->Minimize();
548 &bounds_val)); 551 } else if (show_state == ui::SHOW_STATE_MAXIMIZED) {
549 bounds.set_y(bounds_val); 552 browser->window()->Maximize();
550 set_bounds = true; 553 } else {
554 if (show_state == ui::SHOW_STATE_NORMAL)
555 browser->window()->Restore();
556
557 gfx::Rect bounds = browser->window()->GetRestoredBounds();
558 bool set_bounds = false;
559
560 // Any part of the bounds can optionally be set by the caller.
561 int bounds_val;
562 if (update_props->HasKey(keys::kLeftKey)) {
563 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
564 keys::kLeftKey,
565 &bounds_val));
566 bounds.set_x(bounds_val);
567 set_bounds = true;
568 }
569
570 if (update_props->HasKey(keys::kTopKey)) {
571 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
572 keys::kTopKey,
573 &bounds_val));
574 bounds.set_y(bounds_val);
575 set_bounds = true;
576 }
577
578 if (update_props->HasKey(keys::kWidthKey)) {
579 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
580 keys::kWidthKey,
581 &bounds_val));
582 bounds.set_width(bounds_val);
583 set_bounds = true;
584 }
585
586 if (update_props->HasKey(keys::kHeightKey)) {
587 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
588 keys::kHeightKey,
589 &bounds_val));
590 bounds.set_height(bounds_val);
591 set_bounds = true;
592 }
593 if (set_bounds)
594 browser->window()->SetBounds(bounds);
551 } 595 }
552 596
553 if (update_props->HasKey(keys::kWidthKey)) {
554 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
555 keys::kWidthKey,
556 &bounds_val));
557 bounds.set_width(bounds_val);
558 set_bounds = true;
559 }
560
561 if (update_props->HasKey(keys::kHeightKey)) {
562 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
563 keys::kHeightKey,
564 &bounds_val));
565 bounds.set_height(bounds_val);
566 set_bounds = true;
567 }
568 if (set_bounds)
569 browser->window()->SetBounds(bounds);
570
571 bool active_val = false; 597 bool active_val = false;
572 if (update_props->HasKey(keys::kFocusedKey)) { 598 if (update_props->HasKey(keys::kFocusedKey)) {
573 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 599 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
574 keys::kFocusedKey, &active_val)); 600 keys::kFocusedKey, &active_val));
575 if (active_val) 601 if (active_val) {
576 browser->window()->Activate(); 602 if (show_state != ui::SHOW_STATE_MINIMIZED)
577 else 603 browser->window()->Activate();
578 browser->window()->Deactivate(); 604 } else {
605 if (show_state != ui::SHOW_STATE_MAXIMIZED)
606 browser->window()->Deactivate();
607 }
asargent_no_longer_on_chrome 2011/11/18 18:52:24 Same question here: would it be better to return a
jennb 2011/11/19 01:44:33 Done.
579 } 608 }
580 609
581 bool draw_attention = false; 610 bool draw_attention = false;
582 if (update_props->HasKey(keys::kDrawAttentionKey)) { 611 if (update_props->HasKey(keys::kDrawAttentionKey)) {
583 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 612 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
584 keys::kDrawAttentionKey, &draw_attention)); 613 keys::kDrawAttentionKey, &draw_attention));
585 if (draw_attention) 614 if (draw_attention)
586 browser->window()->FlashFrame(); 615 browser->window()->FlashFrame();
587 } 616 }
588 617
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 // called for every API call the extension made. 1596 // called for every API call the extension made.
1568 GotLanguage(language); 1597 GotLanguage(language);
1569 } 1598 }
1570 1599
1571 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1600 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1572 result_.reset(Value::CreateStringValue(language.c_str())); 1601 result_.reset(Value::CreateStringValue(language.c_str()));
1573 SendResponse(true); 1602 SendResponse(true);
1574 1603
1575 Release(); // Balanced in Run() 1604 Release(); // Balanced in Run()
1576 } 1605 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698