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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 1015123003: Extension window.create API accepts state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch default Created 5 years, 9 months 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
OLDNEW
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
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 }
197 NOTREACHED();
198 return ui::SHOW_STATE_DEFAULT;
199 }
200
184 } // namespace 201 } // namespace
185 202
186 void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, 203 void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode,
187 api::tabs::ZoomSettings* zoom_settings) { 204 api::tabs::ZoomSettings* zoom_settings) {
188 DCHECK(zoom_settings); 205 DCHECK(zoom_settings);
189 switch (zoom_mode) { 206 switch (zoom_mode) {
190 case ZoomController::ZOOM_MODE_DEFAULT: 207 case ZoomController::ZOOM_MODE_DEFAULT:
191 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; 208 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC;
192 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN; 209 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN;
193 break; 210 break;
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 create_params.initial_bounds = window_bounds; 569 create_params.initial_bounds = window_bounds;
553 } else { 570 } else {
554 create_params = Browser::CreateParams::CreateForApp( 571 create_params = Browser::CreateParams::CreateForApp(
555 web_app::GenerateApplicationNameFromExtensionId(extension_id), 572 web_app::GenerateApplicationNameFromExtensionId(extension_id),
556 false /* trusted_source */, 573 false /* trusted_source */,
557 window_bounds, 574 window_bounds,
558 window_profile, 575 window_profile,
559 host_desktop_type); 576 host_desktop_type);
560 } 577 }
561 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; 578 create_params.initial_show_state = ui::SHOW_STATE_NORMAL;
579 if (create_data && create_data->state) {
580 create_params.initial_show_state =
581 ConvertToWindowShowState(create_data->state);
582 }
562 create_params.host_desktop_type = chrome::GetActiveDesktop(); 583 create_params.host_desktop_type = chrome::GetActiveDesktop();
563 584
564 Browser* new_window = new Browser(create_params); 585 Browser* new_window = new Browser(create_params);
565 586
566 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { 587 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) {
567 WebContents* tab = chrome::AddSelectedTabWithURL( 588 WebContents* tab = chrome::AddSelectedTabWithURL(
568 new_window, *i, ui::PAGE_TRANSITION_LINK); 589 new_window, *i, ui::PAGE_TRANSITION_LINK);
569 if (create_panel) { 590 if (create_panel) {
570 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id); 591 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id);
571 } 592 }
(...skipping 16 matching lines...) Expand all
588 // tab when it is intended to create an empty popup. 609 // tab when it is intended to create an empty popup.
589 if (!contents && urls.empty() && window_type != Browser::TYPE_POPUP) { 610 if (!contents && urls.empty() && window_type != Browser::TYPE_POPUP) {
590 chrome::NewTab(new_window); 611 chrome::NewTab(new_window);
591 } 612 }
592 chrome::SelectNumberedTab(new_window, 0); 613 chrome::SelectNumberedTab(new_window, 0);
593 614
594 // Unlike other window types, Panels do not take focus by default. 615 // Unlike other window types, Panels do not take focus by default.
595 if (!saw_focus_key && create_panel) 616 if (!saw_focus_key && create_panel)
596 focused = false; 617 focused = false;
597 618
619 WindowController* controller = new_window->extension_window_controller();
620 if (create_params.initial_show_state == ui::SHOW_STATE_FULLSCREEN)
621 controller->SetFullscreenMode(true, extension()->url());
not at google - send to devlin 2015/03/19 17:56:31 Can you double-check this works? I'm just wonderin
limasdf 2015/03/20 17:03:46 It works well. and even more natural. If I move th
622
623 if (create_params.initial_show_state == ui::SHOW_STATE_MINIMIZED)
not at google - send to devlin 2015/03/19 17:56:31 Also, also double checking: do you need to manuall
limasdf 2015/03/20 17:03:46 => do you need to manually Minimize()/Maximize() t
limasdf 2015/03/21 09:31:34 The initial show state doesn't automatically Minim
624 focused = false;
625
598 if (focused) 626 if (focused)
599 new_window->window()->Show(); 627 new_window->window()->Show();
600 else 628 else
601 new_window->window()->ShowInactive(); 629 new_window->window()->ShowInactive();
602 630
603 if (new_window->profile()->IsOffTheRecord() && 631 if (new_window->profile()->IsOffTheRecord() &&
604 !GetProfile()->IsOffTheRecord() && !include_incognito()) { 632 !GetProfile()->IsOffTheRecord() && !include_incognito()) {
605 // Don't expose incognito windows if extension itself works in non-incognito 633 // Don't expose incognito windows if extension itself works in non-incognito
606 // profile and CanCrossIncognito isn't allowed. 634 // profile and CanCrossIncognito isn't allowed.
607 SetResult(base::Value::CreateNullValue()); 635 SetResult(base::Value::CreateNullValue());
608 } else { 636 } else {
609 SetResult( 637 SetResult(controller->CreateWindowValueWithTabs(extension()));
610 new_window->extension_window_controller()->CreateWindowValueWithTabs(
611 extension()));
612 } 638 }
613 639
614 return true; 640 return true;
615 } 641 }
616 642
617 bool WindowsUpdateFunction::RunSync() { 643 bool WindowsUpdateFunction::RunSync() {
618 scoped_ptr<windows::Update::Params> params( 644 scoped_ptr<windows::Update::Params> params(
619 windows::Update::Params::Create(*args_)); 645 windows::Update::Params::Create(*args_));
620 EXTENSION_FUNCTION_VALIDATE(params); 646 EXTENSION_FUNCTION_VALIDATE(params);
621 647
622 WindowController* controller; 648 WindowController* controller;
623 if (!windows_util::GetWindowFromWindowID(this, params->window_id, 649 if (!windows_util::GetWindowFromWindowID(this, params->window_id,
624 &controller)) 650 &controller))
625 return false; 651 return false;
626 652
627 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 653 ui::WindowShowState show_state =
628 switch (params->update_info.state) { 654 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 655
648 if (show_state != ui::SHOW_STATE_FULLSCREEN && 656 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
649 show_state != ui::SHOW_STATE_DEFAULT) 657 show_state != ui::SHOW_STATE_DEFAULT)
650 controller->SetFullscreenMode(false, extension()->url()); 658 controller->SetFullscreenMode(false, extension()->url());
651 659
652 switch (show_state) { 660 switch (show_state) {
653 case ui::SHOW_STATE_MINIMIZED: 661 case ui::SHOW_STATE_MINIMIZED:
654 controller->window()->Minimize(); 662 controller->window()->Minimize();
655 break; 663 break;
656 case ui::SHOW_STATE_MAXIMIZED: 664 case ui::SHOW_STATE_MAXIMIZED:
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); 1961 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode();
1954 api::tabs::ZoomSettings zoom_settings; 1962 api::tabs::ZoomSettings zoom_settings;
1955 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 1963 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
1956 1964
1957 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 1965 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
1958 SendResponse(true); 1966 SendResponse(true);
1959 return true; 1967 return true;
1960 } 1968 }
1961 1969
1962 } // namespace extensions 1970 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698