Index: chrome/browser/extensions/api/tabs/tabs_api.cc |
diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc |
index 229d89aaed2445c1b428504800768e261b4dedac..554fce4d82c09348466dac525feaec419821ffda 100644 |
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc |
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc |
@@ -181,6 +181,60 @@ void AssignOptionalValue(const scoped_ptr<T>& source, |
} |
} |
+ui::WindowShowState ConvertToWindowShowState(windows::State state) { |
+ switch (state) { |
+ case windows::STATE_NORMAL: |
+ return ui::SHOW_STATE_NORMAL; |
+ case windows::STATE_MINIMIZED: |
+ return ui::SHOW_STATE_MINIMIZED; |
+ case windows::STATE_MAXIMIZED: |
+ return ui::SHOW_STATE_MAXIMIZED; |
+ case windows::STATE_FULLSCREEN: |
+ return ui::SHOW_STATE_FULLSCREEN; |
+ case windows::STATE_NONE: |
+ return ui::SHOW_STATE_DEFAULT; |
+ default: |
not at google - send to devlin
2015/03/19 15:43:45
No default case; have the NOTREACHED() outside the
limasdf
2015/03/19 17:40:13
Done.
|
+ NOTREACHED(); |
+ } |
+ return ui::SHOW_STATE_DEFAULT; |
+} |
+ |
+bool IsValidStateForWindowCreateFunction( |
+ const windows::Create::Params::CreateData* create_data) { |
+ if (!create_data) |
+ return true; |
+ |
+ windows::State state = create_data->state; |
+ if (create_data->focused) { |
+ if (*create_data->focused) { |
+ if (state == windows::STATE_MINIMIZED) { |
+ return false; |
+ } |
+ } else { |
+ if ((state == windows::STATE_MAXIMIZED || |
+ state == windows::STATE_FULLSCREEN)) { |
+ return false; |
+ } |
+ } |
+ } |
+ bool has_bound = create_data->left || create_data->top || |
+ create_data->width || create_data->height; |
+ if (has_bound && |
+ (state == windows::STATE_MINIMIZED || state == windows::STATE_MAXIMIZED || |
+ state == windows::STATE_FULLSCREEN)) { |
+ return false; |
+ } |
+ bool is_panel = |
+ create_data->type == windows::Create::Params::CreateData::TYPE_PANEL || |
+ create_data->type == |
+ windows::Create::Params::CreateData::TYPE_DETACHED_PANEL; |
+ if (is_panel && |
+ (state == windows::STATE_MINIMIZED || state == windows::STATE_MAXIMIZED || |
+ state == windows::STATE_FULLSCREEN)) { |
+ return false; |
+ } |
+ return true; |
+} |
} // namespace |
void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, |
@@ -404,6 +458,11 @@ bool WindowsCreateFunction::RunSync() { |
return false; |
} |
+ if (!IsValidStateForWindowCreateFunction(create_data)) { |
+ error_ = keys::kInvalidWindowStateError; |
+ return false; |
+ } |
+ |
Profile* window_profile = GetProfile(); |
Browser::Type window_type = Browser::TYPE_TABBED; |
bool create_panel = false; |
@@ -559,6 +618,10 @@ bool WindowsCreateFunction::RunSync() { |
host_desktop_type); |
} |
create_params.initial_show_state = ui::SHOW_STATE_NORMAL; |
+ if (create_data && create_data->state) { |
+ create_params.initial_show_state = |
+ ConvertToWindowShowState(create_data->state); |
+ } |
create_params.host_desktop_type = chrome::GetActiveDesktop(); |
Browser* new_window = new Browser(create_params); |
@@ -595,6 +658,13 @@ bool WindowsCreateFunction::RunSync() { |
if (!saw_focus_key && create_panel) |
focused = false; |
+ WindowController* controller = new_window->extension_window_controller(); |
+ if (create_params.initial_show_state == ui::SHOW_STATE_FULLSCREEN) |
+ controller->SetFullscreenMode(true, extension()->url()); |
+ |
+ if (create_params.initial_show_state == ui::SHOW_STATE_MINIMIZED) |
+ focused = false; |
+ |
if (focused) |
new_window->window()->Show(); |
else |
@@ -606,9 +676,7 @@ bool WindowsCreateFunction::RunSync() { |
// profile and CanCrossIncognito isn't allowed. |
SetResult(base::Value::CreateNullValue()); |
} else { |
- SetResult( |
- new_window->extension_window_controller()->CreateWindowValueWithTabs( |
- extension())); |
+ SetResult(controller->CreateWindowValueWithTabs(extension())); |
} |
return true; |
@@ -624,26 +692,8 @@ bool WindowsUpdateFunction::RunSync() { |
&controller)) |
return false; |
- ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. |
- switch (params->update_info.state) { |
- case windows::Update::Params::UpdateInfo::STATE_NORMAL: |
- show_state = ui::SHOW_STATE_NORMAL; |
- break; |
- case windows::Update::Params::UpdateInfo::STATE_MINIMIZED: |
- show_state = ui::SHOW_STATE_MINIMIZED; |
- break; |
- case windows::Update::Params::UpdateInfo::STATE_MAXIMIZED: |
- show_state = ui::SHOW_STATE_MAXIMIZED; |
- break; |
- case windows::Update::Params::UpdateInfo::STATE_FULLSCREEN: |
- show_state = ui::SHOW_STATE_FULLSCREEN; |
- break; |
- case windows::Update::Params::UpdateInfo::STATE_NONE: |
- break; |
- default: |
- error_ = keys::kInvalidWindowStateError; |
- return false; |
- } |
+ ui::WindowShowState show_state = |
+ ConvertToWindowShowState(params->update_info.state); |
if (show_state != ui::SHOW_STATE_FULLSCREEN && |
show_state != ui::SHOW_STATE_DEFAULT) |