OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 } | 174 } |
175 | 175 |
176 template <typename T> | 176 template <typename T> |
177 void AssignOptionalValue(const scoped_ptr<T>& source, | 177 void AssignOptionalValue(const scoped_ptr<T>& source, |
178 scoped_ptr<T>& destination) { | 178 scoped_ptr<T>& destination) { |
179 if (source.get()) { | 179 if (source.get()) { |
180 destination.reset(new T(*source.get())); | 180 destination.reset(new T(*source.get())); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 ui::WindowShowState ConvertToWindowShowState(windows::State state) { | |
185 switch (state) { | |
186 case windows::STATE_NORMAL: | |
187 return ui::SHOW_STATE_NORMAL; | |
188 case windows::STATE_MINIMIZED: | |
189 return ui::SHOW_STATE_MINIMIZED; | |
190 case windows::STATE_MAXIMIZED: | |
191 return ui::SHOW_STATE_MAXIMIZED; | |
192 case windows::STATE_FULLSCREEN: | |
193 return ui::SHOW_STATE_FULLSCREEN; | |
194 case windows::STATE_NONE: | |
195 return ui::SHOW_STATE_DEFAULT; | |
196 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.
| |
197 NOTREACHED(); | |
198 } | |
199 return ui::SHOW_STATE_DEFAULT; | |
200 } | |
201 | |
202 bool IsValidStateForWindowCreateFunction( | |
203 const windows::Create::Params::CreateData* create_data) { | |
204 if (!create_data) | |
205 return true; | |
206 | |
207 windows::State state = create_data->state; | |
208 if (create_data->focused) { | |
209 if (*create_data->focused) { | |
210 if (state == windows::STATE_MINIMIZED) { | |
211 return false; | |
212 } | |
213 } else { | |
214 if ((state == windows::STATE_MAXIMIZED || | |
215 state == windows::STATE_FULLSCREEN)) { | |
216 return false; | |
217 } | |
218 } | |
219 } | |
220 bool has_bound = create_data->left || create_data->top || | |
221 create_data->width || create_data->height; | |
222 if (has_bound && | |
223 (state == windows::STATE_MINIMIZED || state == windows::STATE_MAXIMIZED || | |
224 state == windows::STATE_FULLSCREEN)) { | |
225 return false; | |
226 } | |
227 bool is_panel = | |
228 create_data->type == windows::Create::Params::CreateData::TYPE_PANEL || | |
229 create_data->type == | |
230 windows::Create::Params::CreateData::TYPE_DETACHED_PANEL; | |
231 if (is_panel && | |
232 (state == windows::STATE_MINIMIZED || state == windows::STATE_MAXIMIZED || | |
233 state == windows::STATE_FULLSCREEN)) { | |
234 return false; | |
235 } | |
236 return true; | |
237 } | |
184 } // namespace | 238 } // namespace |
185 | 239 |
186 void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, | 240 void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, |
187 api::tabs::ZoomSettings* zoom_settings) { | 241 api::tabs::ZoomSettings* zoom_settings) { |
188 DCHECK(zoom_settings); | 242 DCHECK(zoom_settings); |
189 switch (zoom_mode) { | 243 switch (zoom_mode) { |
190 case ZoomController::ZOOM_MODE_DEFAULT: | 244 case ZoomController::ZOOM_MODE_DEFAULT: |
191 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; | 245 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; |
192 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN; | 246 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN; |
193 break; | 247 break; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 GetProfile(), | 451 GetProfile(), |
398 include_incognito(), | 452 include_incognito(), |
399 NULL, | 453 NULL, |
400 &source_tab_strip, | 454 &source_tab_strip, |
401 NULL, | 455 NULL, |
402 &tab_index, | 456 &tab_index, |
403 &error_)) | 457 &error_)) |
404 return false; | 458 return false; |
405 } | 459 } |
406 | 460 |
461 if (!IsValidStateForWindowCreateFunction(create_data)) { | |
462 error_ = keys::kInvalidWindowStateError; | |
463 return false; | |
464 } | |
465 | |
407 Profile* window_profile = GetProfile(); | 466 Profile* window_profile = GetProfile(); |
408 Browser::Type window_type = Browser::TYPE_TABBED; | 467 Browser::Type window_type = Browser::TYPE_TABBED; |
409 bool create_panel = false; | 468 bool create_panel = false; |
410 | 469 |
411 // panel_create_mode only applies if create_panel = true | 470 // panel_create_mode only applies if create_panel = true |
412 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; | 471 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; |
413 | 472 |
414 gfx::Rect window_bounds; | 473 gfx::Rect window_bounds; |
415 bool focused = true; | 474 bool focused = true; |
416 bool saw_focus_key = false; | 475 bool saw_focus_key = false; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 create_params.initial_bounds = window_bounds; | 611 create_params.initial_bounds = window_bounds; |
553 } else { | 612 } else { |
554 create_params = Browser::CreateParams::CreateForApp( | 613 create_params = Browser::CreateParams::CreateForApp( |
555 web_app::GenerateApplicationNameFromExtensionId(extension_id), | 614 web_app::GenerateApplicationNameFromExtensionId(extension_id), |
556 false /* trusted_source */, | 615 false /* trusted_source */, |
557 window_bounds, | 616 window_bounds, |
558 window_profile, | 617 window_profile, |
559 host_desktop_type); | 618 host_desktop_type); |
560 } | 619 } |
561 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; | 620 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; |
621 if (create_data && create_data->state) { | |
622 create_params.initial_show_state = | |
623 ConvertToWindowShowState(create_data->state); | |
624 } | |
562 create_params.host_desktop_type = chrome::GetActiveDesktop(); | 625 create_params.host_desktop_type = chrome::GetActiveDesktop(); |
563 | 626 |
564 Browser* new_window = new Browser(create_params); | 627 Browser* new_window = new Browser(create_params); |
565 | 628 |
566 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { | 629 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { |
567 WebContents* tab = chrome::AddSelectedTabWithURL( | 630 WebContents* tab = chrome::AddSelectedTabWithURL( |
568 new_window, *i, ui::PAGE_TRANSITION_LINK); | 631 new_window, *i, ui::PAGE_TRANSITION_LINK); |
569 if (create_panel) { | 632 if (create_panel) { |
570 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id); | 633 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id); |
571 } | 634 } |
(...skipping 16 matching lines...) Expand all Loading... | |
588 // tab when it is intended to create an empty popup. | 651 // tab when it is intended to create an empty popup. |
589 if (!contents && urls.empty() && window_type != Browser::TYPE_POPUP) { | 652 if (!contents && urls.empty() && window_type != Browser::TYPE_POPUP) { |
590 chrome::NewTab(new_window); | 653 chrome::NewTab(new_window); |
591 } | 654 } |
592 chrome::SelectNumberedTab(new_window, 0); | 655 chrome::SelectNumberedTab(new_window, 0); |
593 | 656 |
594 // Unlike other window types, Panels do not take focus by default. | 657 // Unlike other window types, Panels do not take focus by default. |
595 if (!saw_focus_key && create_panel) | 658 if (!saw_focus_key && create_panel) |
596 focused = false; | 659 focused = false; |
597 | 660 |
661 WindowController* controller = new_window->extension_window_controller(); | |
662 if (create_params.initial_show_state == ui::SHOW_STATE_FULLSCREEN) | |
663 controller->SetFullscreenMode(true, extension()->url()); | |
664 | |
665 if (create_params.initial_show_state == ui::SHOW_STATE_MINIMIZED) | |
666 focused = false; | |
667 | |
598 if (focused) | 668 if (focused) |
599 new_window->window()->Show(); | 669 new_window->window()->Show(); |
600 else | 670 else |
601 new_window->window()->ShowInactive(); | 671 new_window->window()->ShowInactive(); |
602 | 672 |
603 if (new_window->profile()->IsOffTheRecord() && | 673 if (new_window->profile()->IsOffTheRecord() && |
604 !GetProfile()->IsOffTheRecord() && !include_incognito()) { | 674 !GetProfile()->IsOffTheRecord() && !include_incognito()) { |
605 // Don't expose incognito windows if extension itself works in non-incognito | 675 // Don't expose incognito windows if extension itself works in non-incognito |
606 // profile and CanCrossIncognito isn't allowed. | 676 // profile and CanCrossIncognito isn't allowed. |
607 SetResult(base::Value::CreateNullValue()); | 677 SetResult(base::Value::CreateNullValue()); |
608 } else { | 678 } else { |
609 SetResult( | 679 SetResult(controller->CreateWindowValueWithTabs(extension())); |
610 new_window->extension_window_controller()->CreateWindowValueWithTabs( | |
611 extension())); | |
612 } | 680 } |
613 | 681 |
614 return true; | 682 return true; |
615 } | 683 } |
616 | 684 |
617 bool WindowsUpdateFunction::RunSync() { | 685 bool WindowsUpdateFunction::RunSync() { |
618 scoped_ptr<windows::Update::Params> params( | 686 scoped_ptr<windows::Update::Params> params( |
619 windows::Update::Params::Create(*args_)); | 687 windows::Update::Params::Create(*args_)); |
620 EXTENSION_FUNCTION_VALIDATE(params); | 688 EXTENSION_FUNCTION_VALIDATE(params); |
621 | 689 |
622 WindowController* controller; | 690 WindowController* controller; |
623 if (!windows_util::GetWindowFromWindowID(this, params->window_id, | 691 if (!windows_util::GetWindowFromWindowID(this, params->window_id, |
624 &controller)) | 692 &controller)) |
625 return false; | 693 return false; |
626 | 694 |
627 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. | 695 ui::WindowShowState show_state = |
628 switch (params->update_info.state) { | 696 ConvertToWindowShowState(params->update_info.state); |
629 case windows::Update::Params::UpdateInfo::STATE_NORMAL: | |
630 show_state = ui::SHOW_STATE_NORMAL; | |
631 break; | |
632 case windows::Update::Params::UpdateInfo::STATE_MINIMIZED: | |
633 show_state = ui::SHOW_STATE_MINIMIZED; | |
634 break; | |
635 case windows::Update::Params::UpdateInfo::STATE_MAXIMIZED: | |
636 show_state = ui::SHOW_STATE_MAXIMIZED; | |
637 break; | |
638 case windows::Update::Params::UpdateInfo::STATE_FULLSCREEN: | |
639 show_state = ui::SHOW_STATE_FULLSCREEN; | |
640 break; | |
641 case windows::Update::Params::UpdateInfo::STATE_NONE: | |
642 break; | |
643 default: | |
644 error_ = keys::kInvalidWindowStateError; | |
645 return false; | |
646 } | |
647 | 697 |
648 if (show_state != ui::SHOW_STATE_FULLSCREEN && | 698 if (show_state != ui::SHOW_STATE_FULLSCREEN && |
649 show_state != ui::SHOW_STATE_DEFAULT) | 699 show_state != ui::SHOW_STATE_DEFAULT) |
650 controller->SetFullscreenMode(false, extension()->url()); | 700 controller->SetFullscreenMode(false, extension()->url()); |
651 | 701 |
652 switch (show_state) { | 702 switch (show_state) { |
653 case ui::SHOW_STATE_MINIMIZED: | 703 case ui::SHOW_STATE_MINIMIZED: |
654 controller->window()->Minimize(); | 704 controller->window()->Minimize(); |
655 break; | 705 break; |
656 case ui::SHOW_STATE_MAXIMIZED: | 706 case ui::SHOW_STATE_MAXIMIZED: |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1953 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); | 2003 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); |
1954 api::tabs::ZoomSettings zoom_settings; | 2004 api::tabs::ZoomSettings zoom_settings; |
1955 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2005 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
1956 | 2006 |
1957 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2007 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
1958 SendResponse(true); | 2008 SendResponse(true); |
1959 return true; | 2009 return true; |
1960 } | 2010 } |
1961 | 2011 |
1962 } // namespace extensions | 2012 } // namespace extensions |
OLD | NEW |