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

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: mention crbug 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
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 #if defined(OS_LINUX) || defined(OS_CHROMEOS)
626 // On Desktop Linux, window managers may ignore hints until the X11 window is
627 // mapped, which happens in the blocking call to Show() above.
628 // DesktopWindowTreeHostX11 currently only checks for an attempt to maximize
629 // once mapped, but not minimize or fullscreen.
630 // For ChromeOS, manually Minimize(). Because minimzied window is not
631 // considered to create new window. See http://crbug.com/473228.
632 if (create_params.initial_show_state == ui::SHOW_STATE_MINIMIZED)
633 new_window->window()->Minimize();
634 #endif
635 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_WIN)
not at google - send to devlin 2015/04/17 16:49:47 it seems like the expression defined(OS_LINUX) &&
limasdf 2015/04/17 18:33:26 This #if guard should be enabled for Linux desktop
636 // On Desktop Linux and Windows managers don't handle fullscreen state to
637 // create window for now.
not at google - send to devlin 2015/04/17 16:49:47 is this something to do with aura? (btw, you migh
limasdf 2015/04/17 18:33:26 Yes, It's todo with aura, exactly DesktopWindowTre
638 if (create_params.initial_show_state == ui::SHOW_STATE_FULLSCREEN)
639 controller->SetFullscreenMode(true, extension()->url());
640 #endif
641
602 if (new_window->profile()->IsOffTheRecord() && 642 if (new_window->profile()->IsOffTheRecord() &&
603 !GetProfile()->IsOffTheRecord() && !include_incognito()) { 643 !GetProfile()->IsOffTheRecord() && !include_incognito()) {
604 // Don't expose incognito windows if extension itself works in non-incognito 644 // Don't expose incognito windows if extension itself works in non-incognito
605 // profile and CanCrossIncognito isn't allowed. 645 // profile and CanCrossIncognito isn't allowed.
606 SetResult(base::Value::CreateNullValue()); 646 SetResult(base::Value::CreateNullValue());
607 } else { 647 } else {
608 SetResult( 648 SetResult(controller->CreateWindowValueWithTabs(extension()));
609 new_window->extension_window_controller()->CreateWindowValueWithTabs(
610 extension()));
611 } 649 }
612 650
613 return true; 651 return true;
614 } 652 }
615 653
616 bool WindowsUpdateFunction::RunSync() { 654 bool WindowsUpdateFunction::RunSync() {
617 scoped_ptr<windows::Update::Params> params( 655 scoped_ptr<windows::Update::Params> params(
618 windows::Update::Params::Create(*args_)); 656 windows::Update::Params::Create(*args_));
619 EXTENSION_FUNCTION_VALIDATE(params); 657 EXTENSION_FUNCTION_VALIDATE(params);
620 658
621 WindowController* controller; 659 WindowController* controller;
622 if (!windows_util::GetWindowFromWindowID(this, params->window_id, 660 if (!windows_util::GetWindowFromWindowID(this, params->window_id,
623 &controller)) 661 &controller))
624 return false; 662 return false;
625 663
626 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 664 ui::WindowShowState show_state =
627 switch (params->update_info.state) { 665 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 666
647 if (show_state != ui::SHOW_STATE_FULLSCREEN && 667 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
648 show_state != ui::SHOW_STATE_DEFAULT) 668 show_state != ui::SHOW_STATE_DEFAULT)
649 controller->SetFullscreenMode(false, extension()->url()); 669 controller->SetFullscreenMode(false, extension()->url());
650 670
651 switch (show_state) { 671 switch (show_state) {
652 case ui::SHOW_STATE_MINIMIZED: 672 case ui::SHOW_STATE_MINIMIZED:
653 controller->window()->Minimize(); 673 controller->window()->Minimize();
654 break; 674 break;
655 case ui::SHOW_STATE_MAXIMIZED: 675 case ui::SHOW_STATE_MAXIMIZED:
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 1971 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
1952 zoom_settings.default_zoom_factor.reset(new double( 1972 zoom_settings.default_zoom_factor.reset(new double(
1953 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 1973 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
1954 1974
1955 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 1975 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
1956 SendResponse(true); 1976 SendResponse(true);
1957 return true; 1977 return true;
1958 } 1978 }
1959 1979
1960 } // namespace extensions 1980 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698