| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 21 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 22 #include "chrome/browser/extensions/extension_host.h" | 22 #include "chrome/browser/extensions/extension_host.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_tab_util.h" | 24 #include "chrome/browser/extensions/extension_tab_util.h" |
| 25 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 25 #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
| 26 #include "chrome/browser/extensions/extension_window_controller.h" |
| 27 #include "chrome/browser/extensions/extension_window_list.h" |
| 26 #include "chrome/browser/net/url_fixer_upper.h" | 28 #include "chrome/browser/net/url_fixer_upper.h" |
| 27 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 29 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/sessions/restore_tab_helper.h" | 31 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 30 #include "chrome/browser/tabs/tab_strip_model.h" | 32 #include "chrome/browser/tabs/tab_strip_model.h" |
| 31 #include "chrome/browser/translate/translate_tab_helper.h" | 33 #include "chrome/browser/translate/translate_tab_helper.h" |
| 32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_list.h" | 35 #include "chrome/browser/ui/browser_list.h" |
| 34 #include "chrome/browser/ui/browser_navigator.h" | 36 #include "chrome/browser/ui/browser_navigator.h" |
| 35 #include "chrome/browser/ui/browser_window.h" | 37 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 *browser = GetBrowserInProfileWithId( | 121 *browser = GetBrowserInProfileWithId( |
| 120 function->profile(), window_id, function->include_incognito(), &error); | 122 function->profile(), window_id, function->include_incognito(), &error); |
| 121 if (!*browser) { | 123 if (!*browser) { |
| 122 function->SetError(error); | 124 function->SetError(error); |
| 123 return false; | 125 return false; |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 return true; | 128 return true; |
| 127 } | 129 } |
| 128 | 130 |
| 131 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, |
| 132 int window_id, |
| 133 ExtensionWindowController** controller) { |
| 134 if (window_id == extension_misc::kCurrentWindowId) { |
| 135 Browser* browser = function->dispatcher()->delegate()->GetBrowser(); |
| 136 // If there is a windowed browser associated with this extension, use that. |
| 137 if (browser && browser->extension_window_controller()) { |
| 138 *controller = browser->extension_window_controller(); |
| 139 } else { |
| 140 // Otherwise get the focused or most recently added window. |
| 141 *controller = ExtensionWindowList::GetInstance()->CurrentWindow( |
| 142 function->profile(), function->include_incognito()); |
| 143 } |
| 144 if (!(*controller)) { |
| 145 function->SetError(keys::kNoCurrentWindowError); |
| 146 return false; |
| 147 } |
| 148 } else { |
| 149 *controller = ExtensionWindowList::GetInstance()->FindWindowById( |
| 150 function->profile(), function->include_incognito(), window_id); |
| 151 if (!(*controller)) { |
| 152 function->SetError(ExtensionErrorUtils::FormatErrorMessage( |
| 153 keys::kWindowNotFoundError, base::IntToString(window_id))); |
| 154 return false; |
| 155 } |
| 156 } |
| 157 return true; |
| 158 } |
| 129 // |error_message| can optionally be passed in and will be set with an | 159 // |error_message| can optionally be passed in and will be set with an |
| 130 // appropriate message if the tab cannot be found by id. | 160 // appropriate message if the tab cannot be found by id. |
| 131 bool GetTabById(int tab_id, | 161 bool GetTabById(int tab_id, |
| 132 Profile* profile, | 162 Profile* profile, |
| 133 bool include_incognito, | 163 bool include_incognito, |
| 134 Browser** browser, | 164 Browser** browser, |
| 135 TabStripModel** tab_strip, | 165 TabStripModel** tab_strip, |
| 136 TabContentsWrapper** contents, | 166 TabContentsWrapper** contents, |
| 137 int* tab_index, | 167 int* tab_index, |
| 138 std::string* error_message) { | 168 std::string* error_message) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // Windows --------------------------------------------------------------------- | 254 // Windows --------------------------------------------------------------------- |
| 225 | 255 |
| 226 bool GetWindowFunction::RunImpl() { | 256 bool GetWindowFunction::RunImpl() { |
| 227 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); | 257 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); |
| 228 EXTENSION_FUNCTION_VALIDATE(params.get()); | 258 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 229 | 259 |
| 230 bool populate_tabs = false; | 260 bool populate_tabs = false; |
| 231 if (params->get_info.get() && params->get_info->populate.get()) | 261 if (params->get_info.get() && params->get_info->populate.get()) |
| 232 populate_tabs = *params->get_info->populate; | 262 populate_tabs = *params->get_info->populate; |
| 233 | 263 |
| 234 Browser* browser = NULL; | 264 ExtensionWindowController* controller; |
| 235 if (!GetBrowserFromWindowID(this, params->window_id, &browser)) | 265 if (!GetWindowFromWindowID(this, params->window_id, &controller)) |
| 236 return false; | 266 return false; |
| 237 | 267 |
| 238 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); | 268 if (populate_tabs) |
| 269 result_.reset(controller->CreateWindowValueWithTabs()); |
| 270 else |
| 271 result_.reset(controller->CreateWindowValue()); |
| 239 return true; | 272 return true; |
| 240 } | 273 } |
| 241 | 274 |
| 242 bool GetCurrentWindowFunction::RunImpl() { | 275 bool GetCurrentWindowFunction::RunImpl() { |
| 243 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); | 276 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); |
| 244 EXTENSION_FUNCTION_VALIDATE(params.get()); | 277 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 245 | 278 |
| 246 bool populate_tabs = false; | 279 bool populate_tabs = false; |
| 247 if (params->get_info.get() && params->get_info->populate.get()) | 280 if (params->get_info.get() && params->get_info->populate.get()) |
| 248 populate_tabs = *params->get_info->populate; | 281 populate_tabs = *params->get_info->populate; |
| 249 | 282 |
| 250 Browser* browser = GetCurrentBrowser(); | 283 ExtensionWindowController* controller; |
| 251 if (!browser || !browser->window()) { | 284 if (!GetWindowFromWindowID(this, |
| 252 error_ = keys::kNoCurrentWindowError; | 285 extension_misc::kCurrentWindowId, |
| 286 &controller)) { |
| 253 return false; | 287 return false; |
| 254 } | 288 } |
| 255 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); | 289 if (populate_tabs) |
| 290 result_.reset(controller->CreateWindowValueWithTabs()); |
| 291 else |
| 292 result_.reset(controller->CreateWindowValue()); |
| 256 return true; | 293 return true; |
| 257 } | 294 } |
| 258 | 295 |
| 259 bool GetLastFocusedWindowFunction::RunImpl() { | 296 bool GetLastFocusedWindowFunction::RunImpl() { |
| 260 scoped_ptr<GetLastFocused::Params> params( | 297 scoped_ptr<GetLastFocused::Params> params( |
| 261 GetLastFocused::Params::Create(*args_)); | 298 GetLastFocused::Params::Create(*args_)); |
| 262 EXTENSION_FUNCTION_VALIDATE(params.get()); | 299 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 263 | 300 |
| 264 bool populate_tabs = false; | 301 bool populate_tabs = false; |
| 265 if (params->get_info.get() && params->get_info->populate.get()) | 302 if (params->get_info.get() && params->get_info->populate.get()) |
| 266 populate_tabs = *params->get_info->populate; | 303 populate_tabs = *params->get_info->populate; |
| 267 | 304 |
| 268 Browser* browser = BrowserList::FindAnyBrowser( | 305 ExtensionWindowController* controller = |
| 269 profile(), include_incognito()); | 306 ExtensionWindowList::GetInstance()->FocusedWindow( |
| 270 if (!browser || !browser->window()) { | 307 profile(), include_incognito()); |
| 308 if (!controller) { |
| 271 error_ = keys::kNoLastFocusedWindowError; | 309 error_ = keys::kNoLastFocusedWindowError; |
| 272 return false; | 310 return false; |
| 273 } | 311 } |
| 274 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); | 312 if (populate_tabs) |
| 313 result_.reset(controller->CreateWindowValueWithTabs()); |
| 314 else |
| 315 result_.reset(controller->CreateWindowValue()); |
| 275 return true; | 316 return true; |
| 276 } | 317 } |
| 277 | 318 |
| 278 bool GetAllWindowsFunction::RunImpl() { | 319 bool GetAllWindowsFunction::RunImpl() { |
| 279 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); | 320 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); |
| 280 EXTENSION_FUNCTION_VALIDATE(params.get()); | 321 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 281 | 322 |
| 282 bool populate_tabs = false; | 323 bool populate_tabs = false; |
| 283 if (params->get_info.get() && params->get_info->populate.get()) | 324 if (params->get_info.get() && params->get_info->populate.get()) |
| 284 populate_tabs = *params->get_info->populate; | 325 populate_tabs = *params->get_info->populate; |
| 285 | 326 |
| 286 result_.reset(new ListValue()); | 327 ListValue* window_list = new ListValue(); |
| 287 Profile* incognito_profile = | 328 const ExtensionWindowList::WindowList& windows = |
| 288 include_incognito() && profile()->HasOffTheRecordProfile() ? | 329 ExtensionWindowList::GetInstance()->windows(); |
| 289 profile()->GetOffTheRecordProfile() : NULL; | 330 for (ExtensionWindowList::WindowList::const_iterator iter = |
| 290 for (BrowserList::const_iterator browser = BrowserList::begin(); | 331 windows.begin(); |
| 291 browser != BrowserList::end(); ++browser) { | 332 iter != windows.end(); ++iter) { |
| 292 // Only examine browsers in the current profile that have windows. | 333 if ((*iter)->MatchesProfile(profile(), include_incognito())) { |
| 293 if (((*browser)->profile() == profile() || | 334 if (populate_tabs) |
| 294 (*browser)->profile() == incognito_profile) && | 335 window_list->Append((*iter)->CreateWindowValueWithTabs()); |
| 295 (*browser)->window()) { | 336 else |
| 296 static_cast<ListValue*>(result_.get())-> | 337 window_list->Append((*iter)->CreateWindowValue()); |
| 297 Append(ExtensionTabUtil::CreateWindowValue(*browser, populate_tabs)); | 338 } |
| 298 } | |
| 299 } | 339 } |
| 300 | 340 result_.reset(window_list); |
| 301 return true; | 341 return true; |
| 302 } | 342 } |
| 303 | 343 |
| 304 bool CreateWindowFunction::ShouldOpenIncognitoWindow( | 344 bool CreateWindowFunction::ShouldOpenIncognitoWindow( |
| 305 const base::DictionaryValue* args, | 345 const base::DictionaryValue* args, |
| 306 std::vector<GURL>* urls, | 346 std::vector<GURL>* urls, |
| 307 bool* is_error) { | 347 bool* is_error) { |
| 308 *is_error = false; | 348 *is_error = false; |
| 309 const IncognitoModePrefs::Availability incognito_availability = | 349 const IncognitoModePrefs::Availability incognito_availability = |
| 310 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); | 350 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 else | 564 else |
| 525 window_type = Browser::TYPE_POPUP; | 565 window_type = Browser::TYPE_POPUP; |
| 526 } else if (type_str != keys::kWindowTypeValueNormal) { | 566 } else if (type_str != keys::kWindowTypeValueNormal) { |
| 527 error_ = keys::kInvalidWindowTypeError; | 567 error_ = keys::kInvalidWindowTypeError; |
| 528 return false; | 568 return false; |
| 529 } | 569 } |
| 530 } | 570 } |
| 531 } | 571 } |
| 532 | 572 |
| 533 #if defined(USE_AURA) | 573 #if defined(USE_AURA) |
| 534 // Aura Panels create a new PanelDOMView. | 574 // Aura Panels create a new PanelViewAura. |
| 535 if (CommandLine::ForCurrentProcess()->HasSwitch( | 575 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 536 ash::switches::kAuraPanelManager) && | 576 ash::switches::kAuraPanelManager) && |
| 537 window_type == Browser::TYPE_PANEL) { | 577 window_type == Browser::TYPE_PANEL) { |
| 538 // Note: Panels ignore all but the first url provided. | 578 // Note: Panels ignore all but the first url provided. |
| 539 std::string title = | 579 std::string title = |
| 540 web_app::GenerateApplicationNameFromExtensionId(extension_id); | 580 web_app::GenerateApplicationNameFromExtensionId(extension_id); |
| 541 PanelViewAura* panel_view = new PanelViewAura(title); | 581 PanelViewAura* panel_view = new PanelViewAura(title); |
| 542 panel_view->Init(window_profile, urls[0], panel_bounds); | 582 panel_view->Init(window_profile, urls[0], panel_bounds); |
| 543 // TODO(stevenjb): Provide an interface enable handles for any view, not | 583 result_.reset( |
| 544 // just browsers. See crbug.com/113412. | 584 panel_view->extension_window_controller()->CreateWindowValueWithTabs()); |
| 545 result_.reset(Value::CreateNullValue()); | |
| 546 return true; | 585 return true; |
| 547 } | 586 } |
| 548 #endif | 587 #endif |
| 549 | 588 |
| 550 // Create a new BrowserWindow. | 589 // Create a new BrowserWindow. |
| 551 Browser* new_window; | 590 Browser* new_window; |
| 552 if (extension_id.empty()) { | 591 if (extension_id.empty()) { |
| 553 new_window = Browser::CreateForType(window_type, window_profile); | 592 new_window = Browser::CreateForType(window_type, window_profile); |
| 554 new_window->window()->SetBounds(window_bounds); | 593 new_window->window()->SetBounds(window_bounds); |
| 555 } else { | 594 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 576 | 615 |
| 577 if (focused) | 616 if (focused) |
| 578 new_window->window()->Show(); | 617 new_window->window()->Show(); |
| 579 else | 618 else |
| 580 new_window->window()->ShowInactive(); | 619 new_window->window()->ShowInactive(); |
| 581 | 620 |
| 582 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { | 621 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { |
| 583 // Don't expose incognito windows if the extension isn't allowed. | 622 // Don't expose incognito windows if the extension isn't allowed. |
| 584 result_.reset(Value::CreateNullValue()); | 623 result_.reset(Value::CreateNullValue()); |
| 585 } else { | 624 } else { |
| 586 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, true)); | 625 result_.reset( |
| 626 new_window->extension_window_controller()->CreateWindowValueWithTabs()); |
| 587 } | 627 } |
| 588 | 628 |
| 589 return true; | 629 return true; |
| 590 } | 630 } |
| 591 | 631 |
| 592 bool UpdateWindowFunction::RunImpl() { | 632 bool UpdateWindowFunction::RunImpl() { |
| 593 int window_id = extension_misc::kUnknownWindowId; | 633 int window_id = extension_misc::kUnknownWindowId; |
| 594 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 634 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 595 DictionaryValue* update_props; | 635 DictionaryValue* update_props; |
| 596 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 636 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 597 | 637 |
| 598 Browser* browser = NULL; | 638 ExtensionWindowController* controller; |
| 599 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 639 if (!GetWindowFromWindowID(this, window_id, &controller)) |
| 600 return false; | 640 return false; |
| 601 | 641 |
| 602 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. | 642 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. |
| 603 std::string state_str; | 643 std::string state_str; |
| 604 if (update_props->HasKey(keys::kShowStateKey)) { | 644 if (update_props->HasKey(keys::kShowStateKey)) { |
| 605 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey, | 645 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey, |
| 606 &state_str)); | 646 &state_str)); |
| 607 if (state_str == keys::kShowStateValueNormal) { | 647 if (state_str == keys::kShowStateValueNormal) { |
| 608 show_state = ui::SHOW_STATE_NORMAL; | 648 show_state = ui::SHOW_STATE_NORMAL; |
| 609 } else if (state_str == keys::kShowStateValueMinimized) { | 649 } else if (state_str == keys::kShowStateValueMinimized) { |
| 610 show_state = ui::SHOW_STATE_MINIMIZED; | 650 show_state = ui::SHOW_STATE_MINIMIZED; |
| 611 } else if (state_str == keys::kShowStateValueMaximized) { | 651 } else if (state_str == keys::kShowStateValueMaximized) { |
| 612 show_state = ui::SHOW_STATE_MAXIMIZED; | 652 show_state = ui::SHOW_STATE_MAXIMIZED; |
| 613 } else if (state_str == keys::kShowStateValueFullscreen) { | 653 } else if (state_str == keys::kShowStateValueFullscreen) { |
| 614 show_state = ui::SHOW_STATE_FULLSCREEN; | 654 show_state = ui::SHOW_STATE_FULLSCREEN; |
| 615 } else { | 655 } else { |
| 616 error_ = keys::kInvalidWindowStateError; | 656 error_ = keys::kInvalidWindowStateError; |
| 617 return false; | 657 return false; |
| 618 } | 658 } |
| 619 } | 659 } |
| 620 | 660 |
| 621 if (browser->window()->IsFullscreen() && | 661 if (show_state != ui::SHOW_STATE_FULLSCREEN && |
| 622 show_state != ui::SHOW_STATE_FULLSCREEN && | |
| 623 show_state != ui::SHOW_STATE_DEFAULT) | 662 show_state != ui::SHOW_STATE_DEFAULT) |
| 624 browser->ToggleFullscreenModeWithExtension(*GetExtension()); | 663 controller->SetFullscreenMode(false, GetExtension()->url()); |
| 625 | 664 |
| 626 switch (show_state) { | 665 switch (show_state) { |
| 627 case ui::SHOW_STATE_MINIMIZED: | 666 case ui::SHOW_STATE_MINIMIZED: |
| 628 browser->window()->Minimize(); | 667 controller->window()->Minimize(); |
| 629 break; | 668 break; |
| 630 case ui::SHOW_STATE_MAXIMIZED: | 669 case ui::SHOW_STATE_MAXIMIZED: |
| 631 browser->window()->Maximize(); | 670 controller->window()->Maximize(); |
| 632 break; | 671 break; |
| 633 case ui::SHOW_STATE_FULLSCREEN: | 672 case ui::SHOW_STATE_FULLSCREEN: |
| 634 if (browser->window()->IsMinimized() || browser->window()->IsMaximized()) | 673 if (controller->window()->IsMinimized() || |
| 635 browser->window()->Restore(); | 674 controller->window()->IsMaximized()) |
| 636 if (!browser->window()->IsFullscreen()) | 675 controller->window()->Restore(); |
| 637 browser->ToggleFullscreenModeWithExtension(*GetExtension()); | 676 controller->SetFullscreenMode(true, GetExtension()->url()); |
| 638 break; | 677 break; |
| 639 case ui::SHOW_STATE_NORMAL: | 678 case ui::SHOW_STATE_NORMAL: |
| 640 browser->window()->Restore(); | 679 controller->window()->Restore(); |
| 641 break; | 680 break; |
| 642 default: | 681 default: |
| 643 break; | 682 break; |
| 644 } | 683 } |
| 645 | 684 |
| 646 gfx::Rect bounds = browser->window()->GetRestoredBounds(); | 685 gfx::Rect bounds = controller->window()->GetRestoredBounds(); |
| 647 bool set_bounds = false; | 686 bool set_bounds = false; |
| 648 | 687 |
| 649 // Any part of the bounds can optionally be set by the caller. | 688 // Any part of the bounds can optionally be set by the caller. |
| 650 int bounds_val; | 689 int bounds_val; |
| 651 if (update_props->HasKey(keys::kLeftKey)) { | 690 if (update_props->HasKey(keys::kLeftKey)) { |
| 652 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 691 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 653 keys::kLeftKey, | 692 keys::kLeftKey, |
| 654 &bounds_val)); | 693 &bounds_val)); |
| 655 bounds.set_x(bounds_val); | 694 bounds.set_x(bounds_val); |
| 656 set_bounds = true; | 695 set_bounds = true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 680 set_bounds = true; | 719 set_bounds = true; |
| 681 } | 720 } |
| 682 | 721 |
| 683 if (set_bounds) { | 722 if (set_bounds) { |
| 684 if (show_state == ui::SHOW_STATE_MINIMIZED || | 723 if (show_state == ui::SHOW_STATE_MINIMIZED || |
| 685 show_state == ui::SHOW_STATE_MAXIMIZED || | 724 show_state == ui::SHOW_STATE_MAXIMIZED || |
| 686 show_state == ui::SHOW_STATE_FULLSCREEN) { | 725 show_state == ui::SHOW_STATE_FULLSCREEN) { |
| 687 error_ = keys::kInvalidWindowStateError; | 726 error_ = keys::kInvalidWindowStateError; |
| 688 return false; | 727 return false; |
| 689 } | 728 } |
| 690 browser->window()->SetBounds(bounds); | 729 controller->window()->SetBounds(bounds); |
| 691 } | 730 } |
| 692 | 731 |
| 693 bool active_val = false; | 732 bool active_val = false; |
| 694 if (update_props->HasKey(keys::kFocusedKey)) { | 733 if (update_props->HasKey(keys::kFocusedKey)) { |
| 695 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 734 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 696 keys::kFocusedKey, &active_val)); | 735 keys::kFocusedKey, &active_val)); |
| 697 if (active_val) { | 736 if (active_val) { |
| 698 if (show_state == ui::SHOW_STATE_MINIMIZED) { | 737 if (show_state == ui::SHOW_STATE_MINIMIZED) { |
| 699 error_ = keys::kInvalidWindowStateError; | 738 error_ = keys::kInvalidWindowStateError; |
| 700 return false; | 739 return false; |
| 701 } | 740 } |
| 702 browser->window()->Activate(); | 741 controller->window()->Activate(); |
| 703 } else { | 742 } else { |
| 704 if (show_state == ui::SHOW_STATE_MAXIMIZED || | 743 if (show_state == ui::SHOW_STATE_MAXIMIZED || |
| 705 show_state == ui::SHOW_STATE_FULLSCREEN) { | 744 show_state == ui::SHOW_STATE_FULLSCREEN) { |
| 706 error_ = keys::kInvalidWindowStateError; | 745 error_ = keys::kInvalidWindowStateError; |
| 707 return false; | 746 return false; |
| 708 } | 747 } |
| 709 browser->window()->Deactivate(); | 748 controller->window()->Deactivate(); |
| 710 } | 749 } |
| 711 } | 750 } |
| 712 | 751 |
| 713 bool draw_attention = false; | 752 bool draw_attention = false; |
| 714 if (update_props->HasKey(keys::kDrawAttentionKey)) { | 753 if (update_props->HasKey(keys::kDrawAttentionKey)) { |
| 715 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 754 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 716 keys::kDrawAttentionKey, &draw_attention)); | 755 keys::kDrawAttentionKey, &draw_attention)); |
| 717 browser->window()->FlashFrame(draw_attention); | 756 controller->window()->FlashFrame(draw_attention); |
| 718 } | 757 } |
| 719 | 758 |
| 720 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 759 result_.reset(controller->CreateWindowValue()); |
| 721 | 760 |
| 722 return true; | 761 return true; |
| 723 } | 762 } |
| 724 | 763 |
| 725 bool RemoveWindowFunction::RunImpl() { | 764 bool RemoveWindowFunction::RunImpl() { |
| 726 int window_id = -1; | 765 int window_id = -1; |
| 727 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 766 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 728 | 767 |
| 729 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, | 768 ExtensionWindowController* controller; |
| 730 include_incognito(), &error_); | 769 if (!GetWindowFromWindowID(this, window_id, &controller)) |
| 731 if (!browser) | |
| 732 return false; | 770 return false; |
| 733 | 771 |
| 734 // Don't let the extension remove the window if the user is dragging tabs | 772 ExtensionWindowController::Reason reason; |
| 735 // in that window. | 773 if (!controller->CanClose(&reason)) { |
| 736 if (!browser->IsTabStripEditable()) { | 774 if (reason == ExtensionWindowController::REASON_TAB_STRIP_NOT_EDITABLE) |
| 737 error_ = keys::kTabStripNotEditableError; | 775 error_ = keys::kTabStripNotEditableError; |
| 738 return false; | 776 return false; |
| 739 } | 777 } |
| 740 | 778 controller->window()->Close(); |
| 741 browser->CloseWindow(); | |
| 742 | |
| 743 return true; | 779 return true; |
| 744 } | 780 } |
| 745 | 781 |
| 746 // Tabs ------------------------------------------------------------------------ | 782 // Tabs ------------------------------------------------------------------------ |
| 747 | 783 |
| 748 bool GetSelectedTabFunction::RunImpl() { | 784 bool GetSelectedTabFunction::RunImpl() { |
| 749 // windowId defaults to "current" window. | 785 // windowId defaults to "current" window. |
| 750 int window_id = extension_misc::kCurrentWindowId; | 786 int window_id = extension_misc::kCurrentWindowId; |
| 751 | 787 |
| 752 if (HasOptionalArgument(0)) | 788 if (HasOptionalArgument(0)) |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 } | 1116 } |
| 1081 | 1117 |
| 1082 // Make sure they actually specified tabs to select. | 1118 // Make sure they actually specified tabs to select. |
| 1083 if (selection.empty()) { | 1119 if (selection.empty()) { |
| 1084 error_ = keys::kNoHighlightedTabError; | 1120 error_ = keys::kNoHighlightedTabError; |
| 1085 return false; | 1121 return false; |
| 1086 } | 1122 } |
| 1087 | 1123 |
| 1088 selection.set_active(active_index); | 1124 selection.set_active(active_index); |
| 1089 browser->tabstrip_model()->SetSelectionFromModel(selection); | 1125 browser->tabstrip_model()->SetSelectionFromModel(selection); |
| 1090 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, true)); | 1126 result_.reset( |
| 1127 browser->extension_window_controller()->CreateWindowValueWithTabs()); |
| 1091 return true; | 1128 return true; |
| 1092 } | 1129 } |
| 1093 | 1130 |
| 1094 UpdateTabFunction::UpdateTabFunction() : web_contents_(NULL) { | 1131 UpdateTabFunction::UpdateTabFunction() : web_contents_(NULL) { |
| 1095 } | 1132 } |
| 1096 | 1133 |
| 1097 bool UpdateTabFunction::RunImpl() { | 1134 bool UpdateTabFunction::RunImpl() { |
| 1098 DictionaryValue* update_props = NULL; | 1135 DictionaryValue* update_props = NULL; |
| 1099 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1136 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 1100 | 1137 |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1738 // called for every API call the extension made. | 1775 // called for every API call the extension made. |
| 1739 GotLanguage(language); | 1776 GotLanguage(language); |
| 1740 } | 1777 } |
| 1741 | 1778 |
| 1742 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1779 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1743 result_.reset(Value::CreateStringValue(language.c_str())); | 1780 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1744 SendResponse(true); | 1781 SendResponse(true); |
| 1745 | 1782 |
| 1746 Release(); // Balanced in Run() | 1783 Release(); // Balanced in Run() |
| 1747 } | 1784 } |
| OLD | NEW |