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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/browser_extension_window_controller.h"
7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
8 #include "chrome/browser/extensions/extension_tab_util.h"
9 #include "chrome/browser/extensions/window_controller_list.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sessions/session_id.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "extensions/common/extension.h"
17 BrowserExtensionWindowController::BrowserExtensionWindowController(
19 : extensions::WindowController(browser
->window(), browser
->profile()),
21 extensions::WindowControllerList::GetInstance()->AddExtensionWindow(this);
24 BrowserExtensionWindowController::~BrowserExtensionWindowController() {
25 extensions::WindowControllerList::GetInstance()->RemoveExtensionWindow(this);
28 int BrowserExtensionWindowController::GetWindowId() const {
29 return static_cast<int>(browser_
->session_id().id());
32 namespace keys
= extensions::tabs_constants
;
34 std::string
BrowserExtensionWindowController::GetWindowTypeText() const {
35 if (browser_
->is_type_popup())
36 return keys::kWindowTypeValuePopup
;
37 if (browser_
->is_app())
38 return keys::kWindowTypeValueApp
;
39 return keys::kWindowTypeValueNormal
;
42 base::DictionaryValue
*
43 BrowserExtensionWindowController::CreateWindowValue() const {
44 base::DictionaryValue
* result
=
45 extensions::WindowController::CreateWindowValue();
49 base::DictionaryValue
*
50 BrowserExtensionWindowController::CreateWindowValueWithTabs(
51 const extensions::Extension
* extension
) const {
52 base::DictionaryValue
* result
= CreateWindowValue();
54 result
->Set(keys::kTabsKey
,
55 extensions::ExtensionTabUtil::CreateTabList(browser_
, extension
));
60 base::DictionaryValue
* BrowserExtensionWindowController::CreateTabValue(
61 const extensions::Extension
* extension
, int tab_index
) const {
62 TabStripModel
* tab_strip
= browser_
->tab_strip_model();
63 base::DictionaryValue
* result
= extensions::ExtensionTabUtil::CreateTabValue(
64 tab_strip
->GetWebContentsAt(tab_index
), tab_strip
, tab_index
);
68 bool BrowserExtensionWindowController::CanClose(Reason
* reason
) const {
69 // Don't let an extension remove the window if the user is dragging tabs
71 if (!browser_
->window()->IsTabStripEditable()) {
72 *reason
= extensions::WindowController::REASON_NOT_EDITABLE
;
78 void BrowserExtensionWindowController::SetFullscreenMode(
80 const GURL
& extension_url
) const {
81 if (browser_
->window()->IsFullscreen() != is_fullscreen
)
82 browser_
->ToggleFullscreenModeWithExtension(extension_url
);
85 Browser
* BrowserExtensionWindowController::GetBrowser() const {
89 bool BrowserExtensionWindowController::IsVisibleToExtension(
90 const extensions::Extension
* extension
) const {
91 // Platform apps can only see their own windows.
92 return !extension
->is_platform_app();