Chromium Code Reviews| 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 cfbadf443de9b49ef5067bf45988c05c3ca939b7..dc0d034347c5fcc33c53fc7327d7715f9d2e4bc3 100644 |
| --- a/chrome/browser/extensions/extension_tabs_module.cc |
| +++ b/chrome/browser/extensions/extension_tabs_module.cc |
| @@ -23,6 +23,8 @@ |
| #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_controller.h" |
| +#include "chrome/browser/extensions/extension_window_list.h" |
| #include "chrome/browser/net/url_fixer_upper.h" |
| #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -126,6 +128,34 @@ bool GetBrowserFromWindowID( |
| return true; |
| } |
| +bool GetWindowFromWindowID(UIThreadExtensionFunction* function, |
| + int window_id, |
| + ExtensionWindowController** wrapper) { |
|
Mihai Parparita -not on Chrome
2012/02/23 02:35:36
Nit: calling these variables "controller" instead
stevenjb
2012/02/23 19:57:51
Yeah, missed that, thanks. Done.
|
| + if (window_id == extension_misc::kCurrentWindowId) { |
| + Browser* browser = function->dispatcher()->delegate()->GetBrowser(); |
| + // If there is a windowed browser associated with this extension, use that. |
|
Mihai Parparita -not on Chrome
2012/02/23 02:35:36
When does this have different behavior from Extens
stevenjb
2012/02/23 19:57:51
When function->dispatcher()->delegate()->GetBrowse
|
| + if (browser && browser->extension_window_controller()) { |
| + *wrapper = browser->extension_window_controller(); |
| + } else { |
| + // Otherwise get the focused or most recently added window. |
| + *wrapper = ExtensionWindowList::GetInstance()->CurrentWindow( |
| + function->profile(), function->include_incognito()); |
| + } |
| + if (!(*wrapper)) { |
| + function->SetError(keys::kNoCurrentWindowError); |
| + return false; |
| + } |
| + } else { |
| + *wrapper = ExtensionWindowList::GetInstance()->FindWindowById( |
| + function->profile(), function->include_incognito(), window_id); |
| + if (!wrapper) { |
| + function->SetError(ExtensionErrorUtils::FormatErrorMessage( |
| + keys::kWindowNotFoundError, base::IntToString(window_id))); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| // |error_message| can optionally be passed in and will be set with an |
| // appropriate message if the tab cannot be found by id. |
| bool GetTabById(int tab_id, |
| @@ -231,11 +261,14 @@ 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)) |
| + ExtensionWindowController* wrapper; |
| + if (!GetWindowFromWindowID(this, params->window_id, &wrapper)) |
| return false; |
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| + if (populate_tabs) |
| + result_.reset(wrapper->CreateWindowValueWithTabs()); |
| + else |
| + result_.reset(wrapper->CreateWindowValue()); |
| return true; |
| } |
| @@ -247,12 +280,14 @@ 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; |
| + ExtensionWindowController* wrapper; |
| + if (!GetWindowFromWindowID(this, extension_misc::kCurrentWindowId, &wrapper)) |
| return false; |
| - } |
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| + |
| + if (populate_tabs) |
| + result_.reset(wrapper->CreateWindowValueWithTabs()); |
| + else |
| + result_.reset(wrapper->CreateWindowValue()); |
| return true; |
| } |
| @@ -265,13 +300,17 @@ 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()) { |
| + ExtensionWindowController* wrapper = |
| + ExtensionWindowList::GetInstance()->FocusedWindow( |
| + profile(), include_incognito()); |
| + if (!wrapper) { |
| error_ = keys::kNoLastFocusedWindowError; |
| return false; |
| } |
| - result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| + if (populate_tabs) |
| + result_.reset(wrapper->CreateWindowValueWithTabs()); |
| + else |
| + result_.reset(wrapper->CreateWindowValue()); |
| return true; |
| } |
| @@ -283,21 +322,20 @@ 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 ExtensionWindowList::WindowList& windows = |
| + ExtensionWindowList::GetInstance()->windows(); |
| + for (ExtensionWindowList::WindowList::const_iterator iter = |
| + windows.begin(); |
| + iter != windows.end(); ++iter) { |
| + if ((*iter)->MatchesProfile(profile(), include_incognito())) { |
| + if (populate_tabs) |
| + window_list->Append((*iter)->CreateWindowValueWithTabs()); |
| + else |
| + window_list->Append((*iter)->CreateWindowValue()); |
| + } |
| } |
| - |
| + result_.reset(window_list); |
| return true; |
| } |
| @@ -531,7 +569,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 +578,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_controller()->CreateWindowValue()); |
| return true; |
| } |
| #endif |
| @@ -583,7 +620,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_controller()->CreateWindowValueWithTabs()); |
| } |
| return true; |
| @@ -595,8 +633,8 @@ bool UpdateWindowFunction::RunImpl() { |
| DictionaryValue* update_props; |
| EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| - Browser* browser = NULL; |
| - if (!GetBrowserFromWindowID(this, window_id, &browser)) |
| + ExtensionWindowController* wrapper; |
| + if (!GetWindowFromWindowID(this, window_id, &wrapper)) |
| return false; |
| ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. |
| @@ -618,32 +656,30 @@ bool UpdateWindowFunction::RunImpl() { |
| } |
| } |
| - if (browser->window()->IsFullscreen() && |
| - show_state != ui::SHOW_STATE_FULLSCREEN && |
| + if (show_state != ui::SHOW_STATE_FULLSCREEN && |
| show_state != ui::SHOW_STATE_DEFAULT) |
| - browser->ToggleFullscreenModeWithExtension(*GetExtension()); |
| + wrapper->SetFullscreenMode(false, GetExtension()->url()); |
| 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_FULLSCREEN: |
| - if (browser->window()->IsMinimized() || browser->window()->IsMaximized()) |
| - browser->window()->Restore(); |
| - if (!browser->window()->IsFullscreen()) |
| - browser->ToggleFullscreenModeWithExtension(*GetExtension()); |
| + if (wrapper->window()->IsMinimized() || wrapper->window()->IsMaximized()) |
| + wrapper->window()->Restore(); |
| + wrapper->SetFullscreenMode(true, GetExtension()->url()); |
| 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. |
| @@ -687,7 +723,7 @@ bool UpdateWindowFunction::RunImpl() { |
| error_ = keys::kInvalidWindowStateError; |
| return false; |
| } |
| - browser->window()->SetBounds(bounds); |
| + wrapper->window()->SetBounds(bounds); |
| } |
| bool active_val = false; |
| @@ -699,14 +735,14 @@ bool UpdateWindowFunction::RunImpl() { |
| error_ = keys::kInvalidWindowStateError; |
| return false; |
| } |
| - browser->window()->Activate(); |
| + wrapper->window()->Activate(); |
| } else { |
| if (show_state == ui::SHOW_STATE_MAXIMIZED || |
| show_state == ui::SHOW_STATE_FULLSCREEN) { |
| error_ = keys::kInvalidWindowStateError; |
| return false; |
| } |
| - browser->window()->Deactivate(); |
| + wrapper->window()->Deactivate(); |
| } |
| } |
| @@ -714,10 +750,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()); |
| return true; |
| } |
| @@ -726,20 +762,17 @@ 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) |
| + ExtensionWindowController* wrapper; |
| + if (!GetWindowFromWindowID(this, window_id, &wrapper)) |
| 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; |
| + ExtensionWindowController::Reason reason; |
| + if (!wrapper->CanClose(&reason)) { |
| + if (reason == ExtensionWindowController::REASON_TAB_STRIP_NOT_EDITABLE) |
| + error_ = keys::kTabStripNotEditableError; |
| return false; |
| } |
| - |
| - browser->CloseWindow(); |
| - |
| + wrapper->window()->Close(); |
| return true; |
| } |
| @@ -1087,7 +1120,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_controller()->CreateWindowValueWithTabs()); |
| return true; |
| } |