1 // Copyright 2015 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 "base/values.h"
6 #include "chrome/browser/extensions/api/tabs/app_base_window.h"
7 #include "chrome/browser/extensions/api/tabs/app_window_controller.h"
8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
9 #include "chrome/browser/extensions/extension_tab_util.h"
10 #include "chrome/browser/extensions/window_controller.h"
11 #include "chrome/browser/extensions/window_controller_list.h"
12 #include "chrome/browser/sessions/session_tab_helper.h"
13 #include "chrome/common/url_constants.h"
14 #include "extensions/browser/app_window/app_window.h"
15 #include "extensions/browser/app_window/native_app_window.h"
16 #include "extensions/common/extension.h"
18 namespace extensions
{
20 AppWindowController::AppWindowController(AppWindow
* app_window
,
21 scoped_ptr
<AppBaseWindow
> base_window
,
23 : WindowController(base_window
.get(), profile
),
24 app_window_(app_window
),
25 base_window_(base_window
.Pass()) {
26 WindowControllerList::GetInstance()->AddExtensionWindow(this);
29 AppWindowController::~AppWindowController() {
30 WindowControllerList::GetInstance()->RemoveExtensionWindow(this);
33 int AppWindowController::GetWindowId() const {
34 return static_cast<int>(app_window_
->session_id().id());
37 std::string
AppWindowController::GetWindowTypeText() const {
38 if (app_window_
->window_type_is_panel())
39 return tabs_constants::kWindowTypeValuePanel
;
40 return tabs_constants::kWindowTypeValueApp
;
43 base::DictionaryValue
* AppWindowController::CreateWindowValueWithTabs(
44 const Extension
* extension
) const {
45 base::DictionaryValue
* result
= CreateWindowValue();
47 base::DictionaryValue
* tab_value
= CreateTabValue(extension
, 0);
51 base::ListValue
* tab_list
= new base::ListValue();
52 tab_list
->Append(tab_value
);
53 result
->Set(tabs_constants::kTabsKey
, tab_list
);
58 base::DictionaryValue
* AppWindowController::CreateTabValue(
59 const Extension
* extension
,
60 int tab_index
) const {
64 content::WebContents
* web_contents
= app_window_
->web_contents();
68 base::DictionaryValue
* tab_value
= new base::DictionaryValue();
69 tab_value
->SetInteger(tabs_constants::kIdKey
,
70 SessionTabHelper::IdForTab(web_contents
));
71 tab_value
->SetInteger(tabs_constants::kIndexKey
, 0);
72 tab_value
->SetInteger(
73 tabs_constants::kWindowIdKey
,
74 SessionTabHelper::IdForWindowContainingTab(web_contents
));
75 tab_value
->SetString(tabs_constants::kUrlKey
, web_contents
->GetURL().spec());
77 tabs_constants::kStatusKey
,
78 ExtensionTabUtil::GetTabStatusText(web_contents
->IsLoading()));
79 tab_value
->SetBoolean(tabs_constants::kActiveKey
,
80 app_window_
->GetBaseWindow()->IsActive());
81 tab_value
->SetBoolean(tabs_constants::kSelectedKey
, true);
82 tab_value
->SetBoolean(tabs_constants::kHighlightedKey
, true);
83 tab_value
->SetBoolean(tabs_constants::kPinnedKey
, false);
84 tab_value
->SetString(tabs_constants::kTitleKey
, web_contents
->GetTitle());
85 tab_value
->SetBoolean(tabs_constants::kIncognitoKey
,
86 app_window_
->GetBaseWindow()->IsActive());
88 gfx::Rect bounds
= app_window_
->GetBaseWindow()->GetBounds();
89 tab_value
->SetInteger(tabs_constants::kWidthKey
, bounds
.width());
90 tab_value
->SetInteger(tabs_constants::kHeightKey
, bounds
.height());
92 const Extension
* ext
= app_window_
->GetExtension();
94 std::string
icon_str(chrome::kChromeUIFaviconURL
);
95 icon_str
.append(app_window_
->GetExtension()->url().spec());
96 tab_value
->SetString(tabs_constants::kFaviconUrlKey
, icon_str
);
102 bool AppWindowController::CanClose(Reason
* reason
) const {
106 void AppWindowController::SetFullscreenMode(bool is_fullscreen
,
107 const GURL
& extension_url
) const {
108 // Do nothing. Panels cannot be fullscreen.
109 if (app_window_
->window_type_is_panel())
111 // TODO(llandwerlin): should we prevent changes in fullscreen mode
112 // when the fullscreen state is FULLSCREEN_TYPE_FORCED?
113 app_window_
->SetFullscreen(AppWindow::FULLSCREEN_TYPE_WINDOW_API
,
117 Browser
* AppWindowController::GetBrowser() const {
121 bool AppWindowController::IsVisibleToExtension(
122 const Extension
* extension
) const {
124 return extension
->id() == app_window_
->extension_id();
127 } // namespace extensions