[sessions]: Componentize TabRestore code
[chromium-blink-merge.git] / chrome / browser / extensions / browser_extension_window_controller.cc
blobb88c2511879fd36072206fae3663c7e05b44e87b
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/ui/browser.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "components/sessions/session_id.h"
15 #include "extensions/common/extension.h"
17 BrowserExtensionWindowController::BrowserExtensionWindowController(
18 Browser* browser)
19 : extensions::WindowController(browser->window(), browser->profile()),
20 browser_(browser) {
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_devtools())
36 return keys::kWindowTypeValueDevTools;
37 if (browser_->is_type_popup())
38 return keys::kWindowTypeValuePopup;
39 if (browser_->is_app())
40 return keys::kWindowTypeValueApp;
41 return keys::kWindowTypeValueNormal;
44 base::DictionaryValue*
45 BrowserExtensionWindowController::CreateWindowValue() const {
46 base::DictionaryValue* result =
47 extensions::WindowController::CreateWindowValue();
48 return result;
51 base::DictionaryValue*
52 BrowserExtensionWindowController::CreateWindowValueWithTabs(
53 const extensions::Extension* extension) const {
54 base::DictionaryValue* result = CreateWindowValue();
56 result->Set(keys::kTabsKey,
57 extensions::ExtensionTabUtil::CreateTabList(browser_, extension));
59 return result;
62 base::DictionaryValue* BrowserExtensionWindowController::CreateTabValue(
63 const extensions::Extension* extension, int tab_index) const {
64 TabStripModel* tab_strip = browser_->tab_strip_model();
65 base::DictionaryValue* result = extensions::ExtensionTabUtil::CreateTabValue(
66 tab_strip->GetWebContentsAt(tab_index), tab_strip, tab_index);
67 return result;
70 bool BrowserExtensionWindowController::CanClose(Reason* reason) const {
71 // Don't let an extension remove the window if the user is dragging tabs
72 // in that window.
73 if (!browser_->window()->IsTabStripEditable()) {
74 *reason = extensions::WindowController::REASON_NOT_EDITABLE;
75 return false;
77 return true;
80 void BrowserExtensionWindowController::SetFullscreenMode(
81 bool is_fullscreen,
82 const GURL& extension_url) const {
83 if (browser_->window()->IsFullscreen() != is_fullscreen)
84 browser_->ToggleFullscreenModeWithExtension(extension_url);
87 Browser* BrowserExtensionWindowController::GetBrowser() const {
88 return browser_;
91 bool BrowserExtensionWindowController::IsVisibleToExtension(
92 const extensions::Extension* extension) const {
93 DCHECK(extension);
94 // Platform apps can only see their own windows.
95 return !browser_->is_devtools() && !extension->is_platform_app();