Home | History | Annotate | Download | only in extensions
      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.
      4 
      5 #include "chrome/browser/extensions/browser_extension_window_controller.h"
      6 
      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"
     16 
     17 BrowserExtensionWindowController::BrowserExtensionWindowController(
     18     Browser* browser)
     19     : extensions::WindowController(browser->window(), browser->profile()),
     20       browser_(browser) {
     21   extensions::WindowControllerList::GetInstance()->AddExtensionWindow(this);
     22 }
     23 
     24 BrowserExtensionWindowController::~BrowserExtensionWindowController() {
     25   extensions::WindowControllerList::GetInstance()->RemoveExtensionWindow(this);
     26 }
     27 
     28 int BrowserExtensionWindowController::GetWindowId() const {
     29   return static_cast<int>(browser_->session_id().id());
     30 }
     31 
     32 namespace keys = extensions::tabs_constants;
     33 
     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;
     40 }
     41 
     42 base::DictionaryValue*
     43 BrowserExtensionWindowController::CreateWindowValue() const {
     44   DictionaryValue* result = extensions::WindowController::CreateWindowValue();
     45   return result;
     46 }
     47 
     48 base::DictionaryValue*
     49 BrowserExtensionWindowController::CreateWindowValueWithTabs(
     50     const extensions::Extension* extension) const {
     51   DictionaryValue* result = CreateWindowValue();
     52 
     53   result->Set(keys::kTabsKey,
     54               extensions::ExtensionTabUtil::CreateTabList(browser_, extension));
     55 
     56   return result;
     57 }
     58 
     59 base::DictionaryValue* BrowserExtensionWindowController::CreateTabValue(
     60     const extensions::Extension* extension, int tab_index) const {
     61   TabStripModel* tab_strip = browser_->tab_strip_model();
     62   DictionaryValue* result = extensions::ExtensionTabUtil::CreateTabValue(
     63       tab_strip->GetWebContentsAt(tab_index), tab_strip, tab_index);
     64   return result;
     65 }
     66 
     67 bool BrowserExtensionWindowController::CanClose(Reason* reason) const {
     68   // Don't let an extension remove the window if the user is dragging tabs
     69   // in that window.
     70   if (!browser_->window()->IsTabStripEditable()) {
     71     *reason = extensions::WindowController::REASON_NOT_EDITABLE;
     72     return false;
     73   }
     74   return true;
     75 }
     76 
     77 void BrowserExtensionWindowController::SetFullscreenMode(
     78     bool is_fullscreen,
     79     const GURL& extension_url) const {
     80   if (browser_->window()->IsFullscreen() != is_fullscreen)
     81     browser_->ToggleFullscreenModeWithExtension(extension_url);
     82 }
     83 
     84 Browser* BrowserExtensionWindowController::GetBrowser() const {
     85   return browser_;
     86 }
     87 
     88 bool BrowserExtensionWindowController::IsVisibleToExtension(
     89     const extensions::Extension* extension) const {
     90   // Platform apps can only see their own windows.
     91   return !extension->is_platform_app();
     92 }
     93