| Index: chrome/browser/extensions/extension_tabs_module.cc
|
| diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
|
| index 7ce8624ab7398f40afc5bee1b5e40b420b028b98..0c43caaf1b40b0bac9614a81c75fdcb61c1c344b 100644
|
| --- a/chrome/browser/extensions/extension_tabs_module.cc
|
| +++ b/chrome/browser/extensions/extension_tabs_module.cc
|
| @@ -23,6 +23,7 @@
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_tab_util.h"
|
| #include "chrome/browser/extensions/extension_tabs_module_constants.h"
|
| +#include "chrome/browser/extensions/extension_window_wrapper.h"
|
| #include "chrome/browser/net/url_fixer_upper.h"
|
| #include "chrome/browser/prefs/incognito_mode_prefs.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -231,11 +232,13 @@ bool GetWindowFunction::RunImpl() {
|
| if (params->get_info.get() && params->get_info->populate.get())
|
| populate_tabs = *params->get_info->populate;
|
|
|
| - Browser* browser = NULL;
|
| - if (!GetBrowserFromWindowID(this, params->window_id, &browser))
|
| + ExtensionWindowWrapper* wrapper =
|
| + ExtensionWindowWrapperList::GetInstance()->FindWindowById(
|
| + profile(), include_incognito(), params->window_id);
|
| + if (!wrapper)
|
| return false;
|
|
|
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs));
|
| + result_.reset(wrapper->CreateWindowValue(populate_tabs));
|
| return true;
|
| }
|
|
|
| @@ -247,12 +250,17 @@ bool GetCurrentWindowFunction::RunImpl() {
|
| if (params->get_info.get() && params->get_info->populate.get())
|
| populate_tabs = *params->get_info->populate;
|
|
|
| - Browser* browser = GetCurrentBrowser();
|
| - if (!browser || !browser->window()) {
|
| - error_ = keys::kNoCurrentWindowError;
|
| - return false;
|
| + // If there is a Browser associated with this extension, use that.
|
| + ExtensionWindowWrapper* wrapper =
|
| + dispatcher()->delegate()->GetBrowser()->extension_window_wrapper();
|
| + if (!wrapper) {
|
| + // Otherwise get the focused or most recently added window.
|
| + wrapper = ExtensionWindowWrapperList::GetInstance()->CurrentWindow(
|
| + profile(), include_incognito());
|
| }
|
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs));
|
| + if (!wrapper)
|
| + return false;
|
| + result_.reset(wrapper->CreateWindowValue(populate_tabs));
|
| return true;
|
| }
|
|
|
| @@ -265,13 +273,14 @@ bool GetLastFocusedWindowFunction::RunImpl() {
|
| if (params->get_info.get() && params->get_info->populate.get())
|
| populate_tabs = *params->get_info->populate;
|
|
|
| - Browser* browser = BrowserList::FindAnyBrowser(
|
| - profile(), include_incognito());
|
| - if (!browser || !browser->window()) {
|
| + ExtensionWindowWrapper* wrapper =
|
| + ExtensionWindowWrapperList::GetInstance()->FocusedWindow(
|
| + profile(), include_incognito());
|
| + if (!wrapper) {
|
| error_ = keys::kNoLastFocusedWindowError;
|
| return false;
|
| }
|
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs));
|
| + result_.reset(wrapper->CreateWindowValue(populate_tabs));
|
| return true;
|
| }
|
|
|
| @@ -283,21 +292,16 @@ bool GetAllWindowsFunction::RunImpl() {
|
| if (params->get_info.get() && params->get_info->populate.get())
|
| populate_tabs = *params->get_info->populate;
|
|
|
| - result_.reset(new ListValue());
|
| - Profile* incognito_profile =
|
| - include_incognito() && profile()->HasOffTheRecordProfile() ?
|
| - profile()->GetOffTheRecordProfile() : NULL;
|
| - for (BrowserList::const_iterator browser = BrowserList::begin();
|
| - browser != BrowserList::end(); ++browser) {
|
| - // Only examine browsers in the current profile that have windows.
|
| - if (((*browser)->profile() == profile() ||
|
| - (*browser)->profile() == incognito_profile) &&
|
| - (*browser)->window()) {
|
| - static_cast<ListValue*>(result_.get())->
|
| - Append(ExtensionTabUtil::CreateWindowValue(*browser, populate_tabs));
|
| - }
|
| + ListValue* window_list = new ListValue();
|
| + const ExtensionWindowWrapperList::WindowList& windows =
|
| + ExtensionWindowWrapperList::GetInstance()->windows();
|
| + for (ExtensionWindowWrapperList::WindowList::const_iterator iter =
|
| + windows.begin();
|
| + iter != windows.end(); ++iter) {
|
| + if ((*iter)->MatchesProfile(profile(), include_incognito()))
|
| + window_list->Append((*iter)->CreateWindowValue(populate_tabs));
|
| }
|
| -
|
| + result_.reset(window_list);
|
| return true;
|
| }
|
|
|
| @@ -531,7 +535,7 @@ bool CreateWindowFunction::RunImpl() {
|
| }
|
|
|
| #if defined(USE_AURA)
|
| - // Aura Panels create a new PanelDOMView.
|
| + // Aura Panels create a new PanelViewAura.
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| ash::switches::kAuraPanelManager) &&
|
| window_type == Browser::TYPE_PANEL) {
|
| @@ -540,9 +544,8 @@ bool CreateWindowFunction::RunImpl() {
|
| web_app::GenerateApplicationNameFromExtensionId(extension_id);
|
| PanelViewAura* panel_view = new PanelViewAura(title);
|
| panel_view->Init(window_profile, urls[0], panel_bounds);
|
| - // TODO(stevenjb): Provide an interface enable handles for any view, not
|
| - // just browsers. See crbug.com/113412.
|
| - result_.reset(Value::CreateNullValue());
|
| + result_.reset(panel_view->extension_window_wrapper()->
|
| + CreateWindowValue(false /*populate_tabs*/));
|
| return true;
|
| }
|
| #endif
|
| @@ -583,7 +586,8 @@ bool CreateWindowFunction::RunImpl() {
|
| // Don't expose incognito windows if the extension isn't allowed.
|
| result_.reset(Value::CreateNullValue());
|
| } else {
|
| - result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, true));
|
| + result_.reset(new_window->extension_window_wrapper()->
|
| + CreateWindowValue(true /*populate_tabs*/));
|
| }
|
|
|
| return true;
|
| @@ -595,8 +599,10 @@ bool UpdateWindowFunction::RunImpl() {
|
| DictionaryValue* update_props;
|
| EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
|
|
|
| - Browser* browser = NULL;
|
| - if (!GetBrowserFromWindowID(this, window_id, &browser))
|
| + ExtensionWindowWrapper* wrapper =
|
| + ExtensionWindowWrapperList::GetInstance()->FindWindowById(
|
| + profile(), include_incognito(), window_id);
|
| + if (!wrapper)
|
| return false;
|
|
|
| ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
|
| @@ -618,19 +624,19 @@ bool UpdateWindowFunction::RunImpl() {
|
|
|
| switch (show_state) {
|
| case ui::SHOW_STATE_MINIMIZED:
|
| - browser->window()->Minimize();
|
| + wrapper->window()->Minimize();
|
| break;
|
| case ui::SHOW_STATE_MAXIMIZED:
|
| - browser->window()->Maximize();
|
| + wrapper->window()->Maximize();
|
| break;
|
| case ui::SHOW_STATE_NORMAL:
|
| - browser->window()->Restore();
|
| + wrapper->window()->Restore();
|
| break;
|
| default:
|
| break;
|
| }
|
|
|
| - gfx::Rect bounds = browser->window()->GetRestoredBounds();
|
| + gfx::Rect bounds = wrapper->window()->GetRestoredBounds();
|
| bool set_bounds = false;
|
|
|
| // Any part of the bounds can optionally be set by the caller.
|
| @@ -673,7 +679,7 @@ bool UpdateWindowFunction::RunImpl() {
|
| error_ = keys::kInvalidWindowStateError;
|
| return false;
|
| }
|
| - browser->window()->SetBounds(bounds);
|
| + wrapper->window()->SetBounds(bounds);
|
| }
|
|
|
| bool active_val = false;
|
| @@ -685,13 +691,13 @@ bool UpdateWindowFunction::RunImpl() {
|
| error_ = keys::kInvalidWindowStateError;
|
| return false;
|
| }
|
| - browser->window()->Activate();
|
| + wrapper->window()->Activate();
|
| } else {
|
| if (show_state == ui::SHOW_STATE_MAXIMIZED) {
|
| error_ = keys::kInvalidWindowStateError;
|
| return false;
|
| }
|
| - browser->window()->Deactivate();
|
| + wrapper->window()->Deactivate();
|
| }
|
| }
|
|
|
| @@ -699,10 +705,10 @@ bool UpdateWindowFunction::RunImpl() {
|
| if (update_props->HasKey(keys::kDrawAttentionKey)) {
|
| EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
|
| keys::kDrawAttentionKey, &draw_attention));
|
| - browser->window()->FlashFrame(draw_attention);
|
| + wrapper->window()->FlashFrame(draw_attention);
|
| }
|
|
|
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false));
|
| + result_.reset(wrapper->CreateWindowValue(false /*populate_tabs*/));
|
|
|
| return true;
|
| }
|
| @@ -711,20 +717,21 @@ bool RemoveWindowFunction::RunImpl() {
|
| int window_id = -1;
|
| EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
|
|
|
| - Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
|
| - include_incognito(), &error_);
|
| - if (!browser)
|
| + ExtensionWindowWrapper* wrapper =
|
| + ExtensionWindowWrapperList::GetInstance()->FindWindowById(
|
| + profile(), include_incognito(), window_id);
|
| + if (wrapper == NULL) {
|
| + error_ = ExtensionErrorUtils::FormatErrorMessage(
|
| + keys::kWindowNotFoundError, base::IntToString(window_id));
|
| return false;
|
| -
|
| - // Don't let the extension remove the window if the user is dragging tabs
|
| - // in that window.
|
| - if (!browser->IsTabStripEditable()) {
|
| - error_ = keys::kTabStripNotEditableError;
|
| + }
|
| + ExtensionWindowWrapper::Reason reason;
|
| + if (!wrapper->CanClose(&reason)) {
|
| + if (reason == ExtensionWindowWrapper::REASON_TAB_STRIP_NOT_EDITABLE)
|
| + error_ = keys::kTabStripNotEditableError;
|
| return false;
|
| }
|
| -
|
| - browser->CloseWindow();
|
| -
|
| + wrapper->window()->Close();
|
| return true;
|
| }
|
|
|
| @@ -1072,7 +1079,8 @@ bool HighlightTabsFunction::RunImpl() {
|
|
|
| selection.set_active(active_index);
|
| browser->tabstrip_model()->SetSelectionFromModel(selection);
|
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, true));
|
| + result_.reset(browser->extension_window_wrapper()->
|
| + CreateWindowValue(true /*populate_tabs*/));
|
| return true;
|
| }
|
|
|
|
|