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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_tabs_module.cc
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index f493f1b2c7f221d160f2f0164c7485666b2ebe87..e7196678298480b8221642d9eff1aa9a2e948273 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -530,52 +530,81 @@ bool UpdateWindowFunction::RunImpl() {
return false;
}
- gfx::Rect bounds = browser->window()->GetRestoredBounds();
- bool set_bounds = false;
- // Any part of the bounds can optionally be set by the caller.
- int bounds_val;
- if (update_props->HasKey(keys::kLeftKey)) {
- EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
- keys::kLeftKey,
- &bounds_val));
- bounds.set_x(bounds_val);
- set_bounds = true;
- }
-
- if (update_props->HasKey(keys::kTopKey)) {
- EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
- keys::kTopKey,
- &bounds_val));
- bounds.set_y(bounds_val);
- set_bounds = true;
- }
-
- if (update_props->HasKey(keys::kWidthKey)) {
- EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
- keys::kWidthKey,
- &bounds_val));
- bounds.set_width(bounds_val);
- set_bounds = true;
- }
-
- if (update_props->HasKey(keys::kHeightKey)) {
- EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
- keys::kHeightKey,
- &bounds_val));
- bounds.set_height(bounds_val);
- set_bounds = true;
- }
- if (set_bounds)
- browser->window()->SetBounds(bounds);
+ ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
+ std::string state_str;
+ if (update_props->HasKey(keys::kShowStateKey)) {
+ EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
+ &state_str));
+ if (state_str == keys::kShowStateValueNormal)
+ show_state = ui::SHOW_STATE_NORMAL;
+ else if (state_str == keys::kShowStateValueMinimized)
+ show_state = ui::SHOW_STATE_MINIMIZED;
+ else if (state_str == keys::kShowStateValueMaximized)
+ show_state = ui::SHOW_STATE_MAXIMIZED;
+ else
+ 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.
+ }
+
+ // 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.
+ if (show_state == ui::SHOW_STATE_MINIMIZED) {
+ browser->window()->Minimize();
+ } else if (show_state == ui::SHOW_STATE_MAXIMIZED) {
+ browser->window()->Maximize();
+ } else {
+ if (show_state == ui::SHOW_STATE_NORMAL)
+ browser->window()->Restore();
+
+ gfx::Rect bounds = browser->window()->GetRestoredBounds();
+ bool set_bounds = false;
+
+ // Any part of the bounds can optionally be set by the caller.
+ int bounds_val;
+ if (update_props->HasKey(keys::kLeftKey)) {
+ EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
+ keys::kLeftKey,
+ &bounds_val));
+ bounds.set_x(bounds_val);
+ set_bounds = true;
+ }
+
+ if (update_props->HasKey(keys::kTopKey)) {
+ EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
+ keys::kTopKey,
+ &bounds_val));
+ bounds.set_y(bounds_val);
+ set_bounds = true;
+ }
+
+ if (update_props->HasKey(keys::kWidthKey)) {
+ EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
+ keys::kWidthKey,
+ &bounds_val));
+ bounds.set_width(bounds_val);
+ set_bounds = true;
+ }
+
+ if (update_props->HasKey(keys::kHeightKey)) {
+ EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
+ keys::kHeightKey,
+ &bounds_val));
+ bounds.set_height(bounds_val);
+ set_bounds = true;
+ }
+ if (set_bounds)
+ browser->window()->SetBounds(bounds);
+ }
bool active_val = false;
if (update_props->HasKey(keys::kFocusedKey)) {
EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
keys::kFocusedKey, &active_val));
- if (active_val)
- browser->window()->Activate();
- else
- browser->window()->Deactivate();
+ if (active_val) {
+ if (show_state != ui::SHOW_STATE_MINIMIZED)
+ browser->window()->Activate();
+ } else {
+ if (show_state != ui::SHOW_STATE_MAXIMIZED)
+ browser->window()->Deactivate();
+ }
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.
}
bool draw_attention = false;

Powered by Google App Engine
This is Rietveld 408576698