Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 9428018: Create BaseWindow and ExtensionWindowWrapper for extension API access to Panels (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments, rename -> ExtensionWindowController Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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** 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.
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.
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
137 if (browser && browser->extension_window_controller()) {
138 *wrapper = browser->extension_window_controller();
139 } else {
140 // Otherwise get the focused or most recently added window.
141 *wrapper = ExtensionWindowList::GetInstance()->CurrentWindow(
142 function->profile(), function->include_incognito());
143 }
144 if (!(*wrapper)) {
145 function->SetError(keys::kNoCurrentWindowError);
146 return false;
147 }
148 } else {
149 *wrapper = ExtensionWindowList::GetInstance()->FindWindowById(
150 function->profile(), function->include_incognito(), window_id);
151 if (!wrapper) {
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
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* wrapper;
235 if (!GetBrowserFromWindowID(this, params->window_id, &browser)) 265 if (!GetWindowFromWindowID(this, params->window_id, &wrapper))
236 return false; 266 return false;
237 267
238 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 268 if (populate_tabs)
269 result_.reset(wrapper->CreateWindowValueWithTabs());
270 else
271 result_.reset(wrapper->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* wrapper;
251 if (!browser || !browser->window()) { 284 if (!GetWindowFromWindowID(this, extension_misc::kCurrentWindowId, &wrapper))
252 error_ = keys::kNoCurrentWindowError;
253 return false; 285 return false;
254 } 286
255 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 287 if (populate_tabs)
288 result_.reset(wrapper->CreateWindowValueWithTabs());
289 else
290 result_.reset(wrapper->CreateWindowValue());
256 return true; 291 return true;
257 } 292 }
258 293
259 bool GetLastFocusedWindowFunction::RunImpl() { 294 bool GetLastFocusedWindowFunction::RunImpl() {
260 scoped_ptr<GetLastFocused::Params> params( 295 scoped_ptr<GetLastFocused::Params> params(
261 GetLastFocused::Params::Create(*args_)); 296 GetLastFocused::Params::Create(*args_));
262 EXTENSION_FUNCTION_VALIDATE(params.get()); 297 EXTENSION_FUNCTION_VALIDATE(params.get());
263 298
264 bool populate_tabs = false; 299 bool populate_tabs = false;
265 if (params->get_info.get() && params->get_info->populate.get()) 300 if (params->get_info.get() && params->get_info->populate.get())
266 populate_tabs = *params->get_info->populate; 301 populate_tabs = *params->get_info->populate;
267 302
268 Browser* browser = BrowserList::FindAnyBrowser( 303 ExtensionWindowController* wrapper =
269 profile(), include_incognito()); 304 ExtensionWindowList::GetInstance()->FocusedWindow(
270 if (!browser || !browser->window()) { 305 profile(), include_incognito());
306 if (!wrapper) {
271 error_ = keys::kNoLastFocusedWindowError; 307 error_ = keys::kNoLastFocusedWindowError;
272 return false; 308 return false;
273 } 309 }
274 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 310 if (populate_tabs)
311 result_.reset(wrapper->CreateWindowValueWithTabs());
312 else
313 result_.reset(wrapper->CreateWindowValue());
275 return true; 314 return true;
276 } 315 }
277 316
278 bool GetAllWindowsFunction::RunImpl() { 317 bool GetAllWindowsFunction::RunImpl() {
279 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); 318 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_));
280 EXTENSION_FUNCTION_VALIDATE(params.get()); 319 EXTENSION_FUNCTION_VALIDATE(params.get());
281 320
282 bool populate_tabs = false; 321 bool populate_tabs = false;
283 if (params->get_info.get() && params->get_info->populate.get()) 322 if (params->get_info.get() && params->get_info->populate.get())
284 populate_tabs = *params->get_info->populate; 323 populate_tabs = *params->get_info->populate;
285 324
286 result_.reset(new ListValue()); 325 ListValue* window_list = new ListValue();
287 Profile* incognito_profile = 326 const ExtensionWindowList::WindowList& windows =
288 include_incognito() && profile()->HasOffTheRecordProfile() ? 327 ExtensionWindowList::GetInstance()->windows();
289 profile()->GetOffTheRecordProfile() : NULL; 328 for (ExtensionWindowList::WindowList::const_iterator iter =
290 for (BrowserList::const_iterator browser = BrowserList::begin(); 329 windows.begin();
291 browser != BrowserList::end(); ++browser) { 330 iter != windows.end(); ++iter) {
292 // Only examine browsers in the current profile that have windows. 331 if ((*iter)->MatchesProfile(profile(), include_incognito())) {
293 if (((*browser)->profile() == profile() || 332 if (populate_tabs)
294 (*browser)->profile() == incognito_profile) && 333 window_list->Append((*iter)->CreateWindowValueWithTabs());
295 (*browser)->window()) { 334 else
296 static_cast<ListValue*>(result_.get())-> 335 window_list->Append((*iter)->CreateWindowValue());
297 Append(ExtensionTabUtil::CreateWindowValue(*browser, populate_tabs)); 336 }
298 }
299 } 337 }
300 338 result_.reset(window_list);
301 return true; 339 return true;
302 } 340 }
303 341
304 bool CreateWindowFunction::ShouldOpenIncognitoWindow( 342 bool CreateWindowFunction::ShouldOpenIncognitoWindow(
305 const base::DictionaryValue* args, 343 const base::DictionaryValue* args,
306 std::vector<GURL>* urls, 344 std::vector<GURL>* urls,
307 bool* is_error) { 345 bool* is_error) {
308 *is_error = false; 346 *is_error = false;
309 const IncognitoModePrefs::Availability incognito_availability = 347 const IncognitoModePrefs::Availability incognito_availability =
310 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); 348 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 else 562 else
525 window_type = Browser::TYPE_POPUP; 563 window_type = Browser::TYPE_POPUP;
526 } else if (type_str != keys::kWindowTypeValueNormal) { 564 } else if (type_str != keys::kWindowTypeValueNormal) {
527 error_ = keys::kInvalidWindowTypeError; 565 error_ = keys::kInvalidWindowTypeError;
528 return false; 566 return false;
529 } 567 }
530 } 568 }
531 } 569 }
532 570
533 #if defined(USE_AURA) 571 #if defined(USE_AURA)
534 // Aura Panels create a new PanelDOMView. 572 // Aura Panels create a new PanelViewAura.
535 if (CommandLine::ForCurrentProcess()->HasSwitch( 573 if (CommandLine::ForCurrentProcess()->HasSwitch(
536 ash::switches::kAuraPanelManager) && 574 ash::switches::kAuraPanelManager) &&
537 window_type == Browser::TYPE_PANEL) { 575 window_type == Browser::TYPE_PANEL) {
538 // Note: Panels ignore all but the first url provided. 576 // Note: Panels ignore all but the first url provided.
539 std::string title = 577 std::string title =
540 web_app::GenerateApplicationNameFromExtensionId(extension_id); 578 web_app::GenerateApplicationNameFromExtensionId(extension_id);
541 PanelViewAura* panel_view = new PanelViewAura(title); 579 PanelViewAura* panel_view = new PanelViewAura(title);
542 panel_view->Init(window_profile, urls[0], panel_bounds); 580 panel_view->Init(window_profile, urls[0], panel_bounds);
543 // TODO(stevenjb): Provide an interface enable handles for any view, not 581 result_.reset(
544 // just browsers. See crbug.com/113412. 582 panel_view->extension_window_controller()->CreateWindowValue());
545 result_.reset(Value::CreateNullValue());
546 return true; 583 return true;
547 } 584 }
548 #endif 585 #endif
549 586
550 // Create a new BrowserWindow. 587 // Create a new BrowserWindow.
551 Browser* new_window; 588 Browser* new_window;
552 if (extension_id.empty()) { 589 if (extension_id.empty()) {
553 new_window = Browser::CreateForType(window_type, window_profile); 590 new_window = Browser::CreateForType(window_type, window_profile);
554 new_window->window()->SetBounds(window_bounds); 591 new_window->window()->SetBounds(window_bounds);
555 } else { 592 } else {
(...skipping 20 matching lines...) Expand all
576 613
577 if (focused) 614 if (focused)
578 new_window->window()->Show(); 615 new_window->window()->Show();
579 else 616 else
580 new_window->window()->ShowInactive(); 617 new_window->window()->ShowInactive();
581 618
582 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { 619 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) {
583 // Don't expose incognito windows if the extension isn't allowed. 620 // Don't expose incognito windows if the extension isn't allowed.
584 result_.reset(Value::CreateNullValue()); 621 result_.reset(Value::CreateNullValue());
585 } else { 622 } else {
586 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, true)); 623 result_.reset(
624 new_window->extension_window_controller()->CreateWindowValueWithTabs());
587 } 625 }
588 626
589 return true; 627 return true;
590 } 628 }
591 629
592 bool UpdateWindowFunction::RunImpl() { 630 bool UpdateWindowFunction::RunImpl() {
593 int window_id = extension_misc::kUnknownWindowId; 631 int window_id = extension_misc::kUnknownWindowId;
594 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 632 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
595 DictionaryValue* update_props; 633 DictionaryValue* update_props;
596 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 634 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
597 635
598 Browser* browser = NULL; 636 ExtensionWindowController* wrapper;
599 if (!GetBrowserFromWindowID(this, window_id, &browser)) 637 if (!GetWindowFromWindowID(this, window_id, &wrapper))
600 return false; 638 return false;
601 639
602 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 640 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
603 std::string state_str; 641 std::string state_str;
604 if (update_props->HasKey(keys::kShowStateKey)) { 642 if (update_props->HasKey(keys::kShowStateKey)) {
605 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey, 643 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
606 &state_str)); 644 &state_str));
607 if (state_str == keys::kShowStateValueNormal) { 645 if (state_str == keys::kShowStateValueNormal) {
608 show_state = ui::SHOW_STATE_NORMAL; 646 show_state = ui::SHOW_STATE_NORMAL;
609 } else if (state_str == keys::kShowStateValueMinimized) { 647 } else if (state_str == keys::kShowStateValueMinimized) {
610 show_state = ui::SHOW_STATE_MINIMIZED; 648 show_state = ui::SHOW_STATE_MINIMIZED;
611 } else if (state_str == keys::kShowStateValueMaximized) { 649 } else if (state_str == keys::kShowStateValueMaximized) {
612 show_state = ui::SHOW_STATE_MAXIMIZED; 650 show_state = ui::SHOW_STATE_MAXIMIZED;
613 } else if (state_str == keys::kShowStateValueFullscreen) { 651 } else if (state_str == keys::kShowStateValueFullscreen) {
614 show_state = ui::SHOW_STATE_FULLSCREEN; 652 show_state = ui::SHOW_STATE_FULLSCREEN;
615 } else { 653 } else {
616 error_ = keys::kInvalidWindowStateError; 654 error_ = keys::kInvalidWindowStateError;
617 return false; 655 return false;
618 } 656 }
619 } 657 }
620 658
621 if (browser->window()->IsFullscreen() && 659 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
622 show_state != ui::SHOW_STATE_FULLSCREEN &&
623 show_state != ui::SHOW_STATE_DEFAULT) 660 show_state != ui::SHOW_STATE_DEFAULT)
624 browser->ToggleFullscreenModeWithExtension(*GetExtension()); 661 wrapper->SetFullscreenMode(false, GetExtension()->url());
625 662
626 switch (show_state) { 663 switch (show_state) {
627 case ui::SHOW_STATE_MINIMIZED: 664 case ui::SHOW_STATE_MINIMIZED:
628 browser->window()->Minimize(); 665 wrapper->window()->Minimize();
629 break; 666 break;
630 case ui::SHOW_STATE_MAXIMIZED: 667 case ui::SHOW_STATE_MAXIMIZED:
631 browser->window()->Maximize(); 668 wrapper->window()->Maximize();
632 break; 669 break;
633 case ui::SHOW_STATE_FULLSCREEN: 670 case ui::SHOW_STATE_FULLSCREEN:
634 if (browser->window()->IsMinimized() || browser->window()->IsMaximized()) 671 if (wrapper->window()->IsMinimized() || wrapper->window()->IsMaximized())
635 browser->window()->Restore(); 672 wrapper->window()->Restore();
636 if (!browser->window()->IsFullscreen()) 673 wrapper->SetFullscreenMode(true, GetExtension()->url());
637 browser->ToggleFullscreenModeWithExtension(*GetExtension());
638 break; 674 break;
639 case ui::SHOW_STATE_NORMAL: 675 case ui::SHOW_STATE_NORMAL:
640 browser->window()->Restore(); 676 wrapper->window()->Restore();
641 break; 677 break;
642 default: 678 default:
643 break; 679 break;
644 } 680 }
645 681
646 gfx::Rect bounds = browser->window()->GetRestoredBounds(); 682 gfx::Rect bounds = wrapper->window()->GetRestoredBounds();
647 bool set_bounds = false; 683 bool set_bounds = false;
648 684
649 // Any part of the bounds can optionally be set by the caller. 685 // Any part of the bounds can optionally be set by the caller.
650 int bounds_val; 686 int bounds_val;
651 if (update_props->HasKey(keys::kLeftKey)) { 687 if (update_props->HasKey(keys::kLeftKey)) {
652 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 688 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
653 keys::kLeftKey, 689 keys::kLeftKey,
654 &bounds_val)); 690 &bounds_val));
655 bounds.set_x(bounds_val); 691 bounds.set_x(bounds_val);
656 set_bounds = true; 692 set_bounds = true;
(...skipping 23 matching lines...) Expand all
680 set_bounds = true; 716 set_bounds = true;
681 } 717 }
682 718
683 if (set_bounds) { 719 if (set_bounds) {
684 if (show_state == ui::SHOW_STATE_MINIMIZED || 720 if (show_state == ui::SHOW_STATE_MINIMIZED ||
685 show_state == ui::SHOW_STATE_MAXIMIZED || 721 show_state == ui::SHOW_STATE_MAXIMIZED ||
686 show_state == ui::SHOW_STATE_FULLSCREEN) { 722 show_state == ui::SHOW_STATE_FULLSCREEN) {
687 error_ = keys::kInvalidWindowStateError; 723 error_ = keys::kInvalidWindowStateError;
688 return false; 724 return false;
689 } 725 }
690 browser->window()->SetBounds(bounds); 726 wrapper->window()->SetBounds(bounds);
691 } 727 }
692 728
693 bool active_val = false; 729 bool active_val = false;
694 if (update_props->HasKey(keys::kFocusedKey)) { 730 if (update_props->HasKey(keys::kFocusedKey)) {
695 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 731 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
696 keys::kFocusedKey, &active_val)); 732 keys::kFocusedKey, &active_val));
697 if (active_val) { 733 if (active_val) {
698 if (show_state == ui::SHOW_STATE_MINIMIZED) { 734 if (show_state == ui::SHOW_STATE_MINIMIZED) {
699 error_ = keys::kInvalidWindowStateError; 735 error_ = keys::kInvalidWindowStateError;
700 return false; 736 return false;
701 } 737 }
702 browser->window()->Activate(); 738 wrapper->window()->Activate();
703 } else { 739 } else {
704 if (show_state == ui::SHOW_STATE_MAXIMIZED || 740 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
705 show_state == ui::SHOW_STATE_FULLSCREEN) { 741 show_state == ui::SHOW_STATE_FULLSCREEN) {
706 error_ = keys::kInvalidWindowStateError; 742 error_ = keys::kInvalidWindowStateError;
707 return false; 743 return false;
708 } 744 }
709 browser->window()->Deactivate(); 745 wrapper->window()->Deactivate();
710 } 746 }
711 } 747 }
712 748
713 bool draw_attention = false; 749 bool draw_attention = false;
714 if (update_props->HasKey(keys::kDrawAttentionKey)) { 750 if (update_props->HasKey(keys::kDrawAttentionKey)) {
715 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 751 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
716 keys::kDrawAttentionKey, &draw_attention)); 752 keys::kDrawAttentionKey, &draw_attention));
717 browser->window()->FlashFrame(draw_attention); 753 wrapper->window()->FlashFrame(draw_attention);
718 } 754 }
719 755
720 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); 756 result_.reset(wrapper->CreateWindowValue());
721 757
722 return true; 758 return true;
723 } 759 }
724 760
725 bool RemoveWindowFunction::RunImpl() { 761 bool RemoveWindowFunction::RunImpl() {
726 int window_id = -1; 762 int window_id = -1;
727 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 763 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
728 764
729 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, 765 ExtensionWindowController* wrapper;
730 include_incognito(), &error_); 766 if (!GetWindowFromWindowID(this, window_id, &wrapper))
731 if (!browser)
732 return false; 767 return false;
733 768
734 // Don't let the extension remove the window if the user is dragging tabs 769 ExtensionWindowController::Reason reason;
735 // in that window. 770 if (!wrapper->CanClose(&reason)) {
736 if (!browser->IsTabStripEditable()) { 771 if (reason == ExtensionWindowController::REASON_TAB_STRIP_NOT_EDITABLE)
737 error_ = keys::kTabStripNotEditableError; 772 error_ = keys::kTabStripNotEditableError;
738 return false; 773 return false;
739 } 774 }
740 775 wrapper->window()->Close();
741 browser->CloseWindow();
742
743 return true; 776 return true;
744 } 777 }
745 778
746 // Tabs ------------------------------------------------------------------------ 779 // Tabs ------------------------------------------------------------------------
747 780
748 bool GetSelectedTabFunction::RunImpl() { 781 bool GetSelectedTabFunction::RunImpl() {
749 // windowId defaults to "current" window. 782 // windowId defaults to "current" window.
750 int window_id = extension_misc::kCurrentWindowId; 783 int window_id = extension_misc::kCurrentWindowId;
751 784
752 if (HasOptionalArgument(0)) 785 if (HasOptionalArgument(0))
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 } 1113 }
1081 1114
1082 // Make sure they actually specified tabs to select. 1115 // Make sure they actually specified tabs to select.
1083 if (selection.empty()) { 1116 if (selection.empty()) {
1084 error_ = keys::kNoHighlightedTabError; 1117 error_ = keys::kNoHighlightedTabError;
1085 return false; 1118 return false;
1086 } 1119 }
1087 1120
1088 selection.set_active(active_index); 1121 selection.set_active(active_index);
1089 browser->tabstrip_model()->SetSelectionFromModel(selection); 1122 browser->tabstrip_model()->SetSelectionFromModel(selection);
1090 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, true)); 1123 result_.reset(
1124 browser->extension_window_controller()->CreateWindowValueWithTabs());
1091 return true; 1125 return true;
1092 } 1126 }
1093 1127
1094 UpdateTabFunction::UpdateTabFunction() : web_contents_(NULL) { 1128 UpdateTabFunction::UpdateTabFunction() : web_contents_(NULL) {
1095 } 1129 }
1096 1130
1097 bool UpdateTabFunction::RunImpl() { 1131 bool UpdateTabFunction::RunImpl() {
1098 DictionaryValue* update_props = NULL; 1132 DictionaryValue* update_props = NULL;
1099 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 1133 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
1100 1134
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 // called for every API call the extension made. 1772 // called for every API call the extension made.
1739 GotLanguage(language); 1773 GotLanguage(language);
1740 } 1774 }
1741 1775
1742 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1776 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1743 result_.reset(Value::CreateStringValue(language.c_str())); 1777 result_.reset(Value::CreateStringValue(language.c_str()));
1744 SendResponse(true); 1778 SendResponse(true);
1745 1779
1746 Release(); // Balanced in Run() 1780 Release(); // Balanced in Run()
1747 } 1781 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698