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

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: rebase and review comment Created 5 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::WindowState state) {
185 switch (state) {
186 case windows::WINDOW_STATE_NORMAL:
187 return ui::SHOW_STATE_NORMAL;
188 case windows::WINDOW_STATE_MINIMIZED:
189 return ui::SHOW_STATE_MINIMIZED;
190 case windows::WINDOW_STATE_MAXIMIZED:
191 return ui::SHOW_STATE_MAXIMIZED;
192 case windows::WINDOW_STATE_FULLSCREEN:
193 return ui::SHOW_STATE_FULLSCREEN;
194 case windows::WINDOW_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::ZOOM_SETTINGS_MODE_AUTOMATIC; 208 zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC;
192 zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN; 209 zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN;
193 break; 210 break;
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 create_params.initial_bounds = window_bounds; 568 create_params.initial_bounds = window_bounds;
552 } else { 569 } else {
553 create_params = Browser::CreateParams::CreateForApp( 570 create_params = Browser::CreateParams::CreateForApp(
554 web_app::GenerateApplicationNameFromExtensionId(extension_id), 571 web_app::GenerateApplicationNameFromExtensionId(extension_id),
555 false /* trusted_source */, 572 false /* trusted_source */,
556 window_bounds, 573 window_bounds,
557 window_profile, 574 window_profile,
558 host_desktop_type); 575 host_desktop_type);
559 } 576 }
560 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; 577 create_params.initial_show_state = ui::SHOW_STATE_NORMAL;
578 if (create_data && create_data->state) {
579 create_params.initial_show_state =
580 ConvertToWindowShowState(create_data->state);
581 }
561 create_params.host_desktop_type = chrome::GetActiveDesktop(); 582 create_params.host_desktop_type = chrome::GetActiveDesktop();
562 583
563 Browser* new_window = new Browser(create_params); 584 Browser* new_window = new Browser(create_params);
564 585
565 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { 586 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) {
566 WebContents* tab = chrome::AddSelectedTabWithURL( 587 WebContents* tab = chrome::AddSelectedTabWithURL(
567 new_window, *i, ui::PAGE_TRANSITION_LINK); 588 new_window, *i, ui::PAGE_TRANSITION_LINK);
568 if (create_panel) { 589 if (create_panel) {
569 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id); 590 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id);
570 } 591 }
(...skipping 21 matching lines...) Expand all
592 613
593 // Unlike other window types, Panels do not take focus by default. 614 // Unlike other window types, Panels do not take focus by default.
594 if (!saw_focus_key && create_panel) 615 if (!saw_focus_key && create_panel)
595 focused = false; 616 focused = false;
596 617
597 if (focused) 618 if (focused)
598 new_window->window()->Show(); 619 new_window->window()->Show();
599 else 620 else
600 new_window->window()->ShowInactive(); 621 new_window->window()->ShowInactive();
601 622
623 WindowController* controller = new_window->extension_window_controller();
624
625 // TODO(limasdf): Minimize() should be removed after DesktopWindowTreeHostX11
tapted 2015/04/16 00:31:03 put this in #if defined(OS_LINUX) && !defined(OS
626 // is able to create new window with minimized state.
627 // See http://crbug.com/473228
628 if (create_params.initial_show_state == ui::SHOW_STATE_MINIMIZED) {
629 new_window->window()->Minimize();
630 } else if (create_params.initial_show_state == ui::SHOW_STATE_FULLSCREEN) {
631 controller->SetFullscreenMode(true, extension()->url());
632 }
633
602 if (new_window->profile()->IsOffTheRecord() && 634 if (new_window->profile()->IsOffTheRecord() &&
603 !GetProfile()->IsOffTheRecord() && !include_incognito()) { 635 !GetProfile()->IsOffTheRecord() && !include_incognito()) {
604 // Don't expose incognito windows if extension itself works in non-incognito 636 // Don't expose incognito windows if extension itself works in non-incognito
605 // profile and CanCrossIncognito isn't allowed. 637 // profile and CanCrossIncognito isn't allowed.
606 SetResult(base::Value::CreateNullValue()); 638 SetResult(base::Value::CreateNullValue());
607 } else { 639 } else {
608 SetResult( 640 SetResult(controller->CreateWindowValueWithTabs(extension()));
609 new_window->extension_window_controller()->CreateWindowValueWithTabs(
610 extension()));
611 } 641 }
612 642
613 return true; 643 return true;
614 } 644 }
615 645
616 bool WindowsUpdateFunction::RunSync() { 646 bool WindowsUpdateFunction::RunSync() {
617 scoped_ptr<windows::Update::Params> params( 647 scoped_ptr<windows::Update::Params> params(
618 windows::Update::Params::Create(*args_)); 648 windows::Update::Params::Create(*args_));
619 EXTENSION_FUNCTION_VALIDATE(params); 649 EXTENSION_FUNCTION_VALIDATE(params);
620 650
621 WindowController* controller; 651 WindowController* controller;
622 if (!windows_util::GetWindowFromWindowID(this, params->window_id, 652 if (!windows_util::GetWindowFromWindowID(this, params->window_id,
623 &controller)) 653 &controller))
624 return false; 654 return false;
625 655
626 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 656 ui::WindowShowState show_state =
627 switch (params->update_info.state) { 657 ConvertToWindowShowState(params->update_info.state);
628 case windows::WINDOW_STATE_NORMAL:
629 show_state = ui::SHOW_STATE_NORMAL;
630 break;
631 case windows::WINDOW_STATE_MINIMIZED:
632 show_state = ui::SHOW_STATE_MINIMIZED;
633 break;
634 case windows::WINDOW_STATE_MAXIMIZED:
635 show_state = ui::SHOW_STATE_MAXIMIZED;
636 break;
637 case windows::WINDOW_STATE_FULLSCREEN:
638 show_state = ui::SHOW_STATE_FULLSCREEN;
639 break;
640 case windows::WINDOW_STATE_NONE:
641 break;
642 default:
643 error_ = keys::kInvalidWindowStateError;
644 return false;
645 }
646 658
647 if (show_state != ui::SHOW_STATE_FULLSCREEN && 659 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
648 show_state != ui::SHOW_STATE_DEFAULT) 660 show_state != ui::SHOW_STATE_DEFAULT)
649 controller->SetFullscreenMode(false, extension()->url()); 661 controller->SetFullscreenMode(false, extension()->url());
650 662
651 switch (show_state) { 663 switch (show_state) {
652 case ui::SHOW_STATE_MINIMIZED: 664 case ui::SHOW_STATE_MINIMIZED:
653 controller->window()->Minimize(); 665 controller->window()->Minimize();
654 break; 666 break;
655 case ui::SHOW_STATE_MAXIMIZED: 667 case ui::SHOW_STATE_MAXIMIZED:
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 1963 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
1952 zoom_settings.default_zoom_factor.reset(new double( 1964 zoom_settings.default_zoom_factor.reset(new double(
1953 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 1965 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
1954 1966
1955 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 1967 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
1956 SendResponse(true); 1968 SendResponse(true);
1957 return true; 1969 return true;
1958 } 1970 }
1959 1971
1960 } // namespace extensions 1972 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698