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

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: Rebase Created 8 years, 9 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 ExtensionWindowController::ProfileMatchType ProfileMatchType(
132 bool include_incognito) {
133 return include_incognito ?
134 ExtensionWindowController::MATCH_INCOGNITO
135 : ExtensionWindowController::MATCH_NORMAL_ONLY;
136 }
137
138 bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
139 int window_id,
140 ExtensionWindowController** controller) {
141 if (window_id == extension_misc::kCurrentWindowId) {
142 Browser* browser = function->dispatcher()->delegate()->GetBrowser();
143 // If there is a windowed browser associated with this extension, use that.
144 if (browser && browser->extension_window_controller()) {
145 *controller = browser->extension_window_controller();
146 } else {
147 // Otherwise get the focused or most recently added window.
148 *controller = ExtensionWindowList::GetInstance()->CurrentWindow(
149 function->profile(),
150 ProfileMatchType(function->include_incognito()));
151 }
152 if (!(*controller)) {
153 function->SetError(keys::kNoCurrentWindowError);
154 return false;
155 }
156 } else {
157 *controller = ExtensionWindowList::GetInstance()->FindWindowById(
158 function->profile(),
159 ProfileMatchType(function->include_incognito()),
160 window_id);
161 if (!(*controller)) {
162 function->SetError(ExtensionErrorUtils::FormatErrorMessage(
163 keys::kWindowNotFoundError, base::IntToString(window_id)));
164 return false;
165 }
166 }
167 return true;
168 }
129 // |error_message| can optionally be passed in and will be set with an 169 // |error_message| can optionally be passed in and will be set with an
130 // appropriate message if the tab cannot be found by id. 170 // appropriate message if the tab cannot be found by id.
131 bool GetTabById(int tab_id, 171 bool GetTabById(int tab_id,
132 Profile* profile, 172 Profile* profile,
133 bool include_incognito, 173 bool include_incognito,
134 Browser** browser, 174 Browser** browser,
135 TabStripModel** tab_strip, 175 TabStripModel** tab_strip,
136 TabContentsWrapper** contents, 176 TabContentsWrapper** contents,
137 int* tab_index, 177 int* tab_index,
138 std::string* error_message) { 178 std::string* error_message) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // Windows --------------------------------------------------------------------- 264 // Windows ---------------------------------------------------------------------
225 265
226 bool GetWindowFunction::RunImpl() { 266 bool GetWindowFunction::RunImpl() {
227 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); 267 scoped_ptr<Get::Params> params(Get::Params::Create(*args_));
228 EXTENSION_FUNCTION_VALIDATE(params.get()); 268 EXTENSION_FUNCTION_VALIDATE(params.get());
229 269
230 bool populate_tabs = false; 270 bool populate_tabs = false;
231 if (params->get_info.get() && params->get_info->populate.get()) 271 if (params->get_info.get() && params->get_info->populate.get())
232 populate_tabs = *params->get_info->populate; 272 populate_tabs = *params->get_info->populate;
233 273
234 Browser* browser = NULL; 274 ExtensionWindowController* controller;
235 if (!GetBrowserFromWindowID(this, params->window_id, &browser)) 275 if (!GetWindowFromWindowID(this, params->window_id, &controller))
236 return false; 276 return false;
237 277
238 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 278 if (populate_tabs)
279 result_.reset(controller->CreateWindowValueWithTabs());
280 else
281 result_.reset(controller->CreateWindowValue());
239 return true; 282 return true;
240 } 283 }
241 284
242 bool GetCurrentWindowFunction::RunImpl() { 285 bool GetCurrentWindowFunction::RunImpl() {
243 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); 286 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_));
244 EXTENSION_FUNCTION_VALIDATE(params.get()); 287 EXTENSION_FUNCTION_VALIDATE(params.get());
245 288
246 bool populate_tabs = false; 289 bool populate_tabs = false;
247 if (params->get_info.get() && params->get_info->populate.get()) 290 if (params->get_info.get() && params->get_info->populate.get())
248 populate_tabs = *params->get_info->populate; 291 populate_tabs = *params->get_info->populate;
249 292
250 Browser* browser = GetCurrentBrowser(); 293 ExtensionWindowController* controller;
251 if (!browser || !browser->window()) { 294 if (!GetWindowFromWindowID(this,
252 error_ = keys::kNoCurrentWindowError; 295 extension_misc::kCurrentWindowId,
296 &controller)) {
253 return false; 297 return false;
254 } 298 }
255 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 299 if (populate_tabs)
300 result_.reset(controller->CreateWindowValueWithTabs());
301 else
302 result_.reset(controller->CreateWindowValue());
256 return true; 303 return true;
257 } 304 }
258 305
259 bool GetLastFocusedWindowFunction::RunImpl() { 306 bool GetLastFocusedWindowFunction::RunImpl() {
260 scoped_ptr<GetLastFocused::Params> params( 307 scoped_ptr<GetLastFocused::Params> params(
261 GetLastFocused::Params::Create(*args_)); 308 GetLastFocused::Params::Create(*args_));
262 EXTENSION_FUNCTION_VALIDATE(params.get()); 309 EXTENSION_FUNCTION_VALIDATE(params.get());
263 310
264 bool populate_tabs = false; 311 bool populate_tabs = false;
265 if (params->get_info.get() && params->get_info->populate.get()) 312 if (params->get_info.get() && params->get_info->populate.get())
266 populate_tabs = *params->get_info->populate; 313 populate_tabs = *params->get_info->populate;
267 314
315 // Note: currently this returns the last active browser. If we decide to
316 // include other window types (e.g. panels), we will need to add logic to
317 // ExtensionWindowList that mirrors the active behavior of BrowserList.
268 Browser* browser = BrowserList::FindAnyBrowser( 318 Browser* browser = BrowserList::FindAnyBrowser(
269 profile(), include_incognito()); 319 profile(), include_incognito());
270 if (!browser || !browser->window()) { 320 if (!browser || !browser->window()) {
271 error_ = keys::kNoLastFocusedWindowError; 321 error_ = keys::kNoLastFocusedWindowError;
272 return false; 322 return false;
273 } 323 }
274 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 324 ExtensionWindowController* controller =
325 browser->extension_window_controller();
326 if (populate_tabs)
327 result_.reset(controller->CreateWindowValueWithTabs());
328 else
329 result_.reset(controller->CreateWindowValue());
275 return true; 330 return true;
276 } 331 }
277 332
278 bool GetAllWindowsFunction::RunImpl() { 333 bool GetAllWindowsFunction::RunImpl() {
279 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); 334 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_));
280 EXTENSION_FUNCTION_VALIDATE(params.get()); 335 EXTENSION_FUNCTION_VALIDATE(params.get());
281 336
282 bool populate_tabs = false; 337 bool populate_tabs = false;
283 if (params->get_info.get() && params->get_info->populate.get()) 338 if (params->get_info.get() && params->get_info->populate.get())
284 populate_tabs = *params->get_info->populate; 339 populate_tabs = *params->get_info->populate;
285 340
286 result_.reset(new ListValue()); 341 ListValue* window_list = new ListValue();
287 Profile* incognito_profile = 342 const ExtensionWindowList::WindowList& windows =
288 include_incognito() && profile()->HasOffTheRecordProfile() ? 343 ExtensionWindowList::GetInstance()->windows();
289 profile()->GetOffTheRecordProfile() : NULL; 344 for (ExtensionWindowList::WindowList::const_iterator iter =
290 for (BrowserList::const_iterator browser = BrowserList::begin(); 345 windows.begin();
291 browser != BrowserList::end(); ++browser) { 346 iter != windows.end(); ++iter) {
292 // Only examine browsers in the current profile that have windows. 347 if (!(*iter)->MatchesProfile(
293 if (((*browser)->profile() == profile() || 348 profile(), ProfileMatchType(include_incognito())))
294 (*browser)->profile() == incognito_profile) && 349 continue;
295 (*browser)->window()) { 350 if (populate_tabs)
296 static_cast<ListValue*>(result_.get())-> 351 window_list->Append((*iter)->CreateWindowValueWithTabs());
297 Append(ExtensionTabUtil::CreateWindowValue(*browser, populate_tabs)); 352 else
298 } 353 window_list->Append((*iter)->CreateWindowValue());
299 } 354 }
300 355 result_.reset(window_list);
301 return true; 356 return true;
302 } 357 }
303 358
304 bool CreateWindowFunction::ShouldOpenIncognitoWindow( 359 bool CreateWindowFunction::ShouldOpenIncognitoWindow(
305 const base::DictionaryValue* args, 360 const base::DictionaryValue* args,
306 std::vector<GURL>* urls, 361 std::vector<GURL>* urls,
307 bool* is_error) { 362 bool* is_error) {
308 *is_error = false; 363 *is_error = false;
309 const IncognitoModePrefs::Availability incognito_availability = 364 const IncognitoModePrefs::Availability incognito_availability =
310 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); 365 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 else 579 else
525 window_type = Browser::TYPE_POPUP; 580 window_type = Browser::TYPE_POPUP;
526 } else if (type_str != keys::kWindowTypeValueNormal) { 581 } else if (type_str != keys::kWindowTypeValueNormal) {
527 error_ = keys::kInvalidWindowTypeError; 582 error_ = keys::kInvalidWindowTypeError;
528 return false; 583 return false;
529 } 584 }
530 } 585 }
531 } 586 }
532 587
533 #if defined(USE_AURA) 588 #if defined(USE_AURA)
534 // Aura Panels create a new PanelDOMView. 589 // Aura Panels create a new PanelViewAura.
535 if (CommandLine::ForCurrentProcess()->HasSwitch( 590 if (CommandLine::ForCurrentProcess()->HasSwitch(
536 ash::switches::kAuraPanelManager) && 591 ash::switches::kAuraPanelManager) &&
537 window_type == Browser::TYPE_PANEL) { 592 window_type == Browser::TYPE_PANEL) {
538 // Note: Panels ignore all but the first url provided. 593 // Note: Panels ignore all but the first url provided.
539 std::string title = 594 std::string title =
540 web_app::GenerateApplicationNameFromExtensionId(extension_id); 595 web_app::GenerateApplicationNameFromExtensionId(extension_id);
541 PanelViewAura* panel_view = new PanelViewAura(title); 596 PanelViewAura* panel_view = new PanelViewAura(title);
542 panel_view->Init(window_profile, urls[0], panel_bounds); 597 panel_view->Init(window_profile, urls[0], panel_bounds);
543 // TODO(stevenjb): Provide an interface enable handles for any view, not 598 result_.reset(
544 // just browsers. See crbug.com/113412. 599 panel_view->extension_window_controller()->CreateWindowValueWithTabs());
545 result_.reset(Value::CreateNullValue());
546 return true; 600 return true;
547 } 601 }
548 #endif 602 #endif
549 603
550 // Create a new BrowserWindow. 604 // Create a new BrowserWindow.
551 Browser* new_window; 605 Browser* new_window;
552 if (extension_id.empty()) { 606 if (extension_id.empty()) {
553 new_window = Browser::CreateForType(window_type, window_profile); 607 new_window = Browser::CreateForType(window_type, window_profile);
554 new_window->window()->SetBounds(window_bounds); 608 new_window->window()->SetBounds(window_bounds);
555 } else { 609 } else {
(...skipping 20 matching lines...) Expand all
576 630
577 if (focused) 631 if (focused)
578 new_window->window()->Show(); 632 new_window->window()->Show();
579 else 633 else
580 new_window->window()->ShowInactive(); 634 new_window->window()->ShowInactive();
581 635
582 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { 636 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) {
583 // Don't expose incognito windows if the extension isn't allowed. 637 // Don't expose incognito windows if the extension isn't allowed.
584 result_.reset(Value::CreateNullValue()); 638 result_.reset(Value::CreateNullValue());
585 } else { 639 } else {
586 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, true)); 640 result_.reset(
641 new_window->extension_window_controller()->CreateWindowValueWithTabs());
587 } 642 }
588 643
589 return true; 644 return true;
590 } 645 }
591 646
592 bool UpdateWindowFunction::RunImpl() { 647 bool UpdateWindowFunction::RunImpl() {
593 int window_id = extension_misc::kUnknownWindowId; 648 int window_id = extension_misc::kUnknownWindowId;
594 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 649 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
595 DictionaryValue* update_props; 650 DictionaryValue* update_props;
596 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 651 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
597 652
598 Browser* browser = NULL; 653 ExtensionWindowController* controller;
599 if (!GetBrowserFromWindowID(this, window_id, &browser)) 654 if (!GetWindowFromWindowID(this, window_id, &controller))
600 return false; 655 return false;
601 656
602 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 657 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
603 std::string state_str; 658 std::string state_str;
604 if (update_props->HasKey(keys::kShowStateKey)) { 659 if (update_props->HasKey(keys::kShowStateKey)) {
605 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey, 660 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
606 &state_str)); 661 &state_str));
607 if (state_str == keys::kShowStateValueNormal) { 662 if (state_str == keys::kShowStateValueNormal) {
608 show_state = ui::SHOW_STATE_NORMAL; 663 show_state = ui::SHOW_STATE_NORMAL;
609 } else if (state_str == keys::kShowStateValueMinimized) { 664 } else if (state_str == keys::kShowStateValueMinimized) {
610 show_state = ui::SHOW_STATE_MINIMIZED; 665 show_state = ui::SHOW_STATE_MINIMIZED;
611 } else if (state_str == keys::kShowStateValueMaximized) { 666 } else if (state_str == keys::kShowStateValueMaximized) {
612 show_state = ui::SHOW_STATE_MAXIMIZED; 667 show_state = ui::SHOW_STATE_MAXIMIZED;
613 } else if (state_str == keys::kShowStateValueFullscreen) { 668 } else if (state_str == keys::kShowStateValueFullscreen) {
614 show_state = ui::SHOW_STATE_FULLSCREEN; 669 show_state = ui::SHOW_STATE_FULLSCREEN;
615 } else { 670 } else {
616 error_ = keys::kInvalidWindowStateError; 671 error_ = keys::kInvalidWindowStateError;
617 return false; 672 return false;
618 } 673 }
619 } 674 }
620 675
621 if (browser->window()->IsFullscreen() && 676 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
622 show_state != ui::SHOW_STATE_FULLSCREEN &&
623 show_state != ui::SHOW_STATE_DEFAULT) 677 show_state != ui::SHOW_STATE_DEFAULT)
624 browser->ToggleFullscreenModeWithExtension(*GetExtension()); 678 controller->SetFullscreenMode(false, GetExtension()->url());
625 679
626 switch (show_state) { 680 switch (show_state) {
627 case ui::SHOW_STATE_MINIMIZED: 681 case ui::SHOW_STATE_MINIMIZED:
628 browser->window()->Minimize(); 682 controller->window()->Minimize();
629 break; 683 break;
630 case ui::SHOW_STATE_MAXIMIZED: 684 case ui::SHOW_STATE_MAXIMIZED:
631 browser->window()->Maximize(); 685 controller->window()->Maximize();
632 break; 686 break;
633 case ui::SHOW_STATE_FULLSCREEN: 687 case ui::SHOW_STATE_FULLSCREEN:
634 if (browser->window()->IsMinimized() || browser->window()->IsMaximized()) 688 if (controller->window()->IsMinimized() ||
635 browser->window()->Restore(); 689 controller->window()->IsMaximized())
636 if (!browser->window()->IsFullscreen()) 690 controller->window()->Restore();
637 browser->ToggleFullscreenModeWithExtension(*GetExtension()); 691 controller->SetFullscreenMode(true, GetExtension()->url());
638 break; 692 break;
639 case ui::SHOW_STATE_NORMAL: 693 case ui::SHOW_STATE_NORMAL:
640 browser->window()->Restore(); 694 controller->window()->Restore();
641 break; 695 break;
642 default: 696 default:
643 break; 697 break;
644 } 698 }
645 699
646 gfx::Rect bounds = browser->window()->GetRestoredBounds(); 700 gfx::Rect bounds;
701 if (controller->window()->IsMinimized())
702 bounds = controller->window()->GetRestoredBounds();
703 else
704 bounds = controller->window()->GetBounds();
647 bool set_bounds = false; 705 bool set_bounds = false;
648 706
649 // Any part of the bounds can optionally be set by the caller. 707 // Any part of the bounds can optionally be set by the caller.
650 int bounds_val; 708 int bounds_val;
651 if (update_props->HasKey(keys::kLeftKey)) { 709 if (update_props->HasKey(keys::kLeftKey)) {
652 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 710 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
653 keys::kLeftKey, 711 keys::kLeftKey,
654 &bounds_val)); 712 &bounds_val));
655 bounds.set_x(bounds_val); 713 bounds.set_x(bounds_val);
656 set_bounds = true; 714 set_bounds = true;
(...skipping 23 matching lines...) Expand all
680 set_bounds = true; 738 set_bounds = true;
681 } 739 }
682 740
683 if (set_bounds) { 741 if (set_bounds) {
684 if (show_state == ui::SHOW_STATE_MINIMIZED || 742 if (show_state == ui::SHOW_STATE_MINIMIZED ||
685 show_state == ui::SHOW_STATE_MAXIMIZED || 743 show_state == ui::SHOW_STATE_MAXIMIZED ||
686 show_state == ui::SHOW_STATE_FULLSCREEN) { 744 show_state == ui::SHOW_STATE_FULLSCREEN) {
687 error_ = keys::kInvalidWindowStateError; 745 error_ = keys::kInvalidWindowStateError;
688 return false; 746 return false;
689 } 747 }
690 browser->window()->SetBounds(bounds); 748 controller->window()->SetBounds(bounds);
691 } 749 }
692 750
693 bool active_val = false; 751 bool active_val = false;
694 if (update_props->HasKey(keys::kFocusedKey)) { 752 if (update_props->HasKey(keys::kFocusedKey)) {
695 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 753 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
696 keys::kFocusedKey, &active_val)); 754 keys::kFocusedKey, &active_val));
697 if (active_val) { 755 if (active_val) {
698 if (show_state == ui::SHOW_STATE_MINIMIZED) { 756 if (show_state == ui::SHOW_STATE_MINIMIZED) {
699 error_ = keys::kInvalidWindowStateError; 757 error_ = keys::kInvalidWindowStateError;
700 return false; 758 return false;
701 } 759 }
702 browser->window()->Activate(); 760 controller->window()->Activate();
703 } else { 761 } else {
704 if (show_state == ui::SHOW_STATE_MAXIMIZED || 762 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
705 show_state == ui::SHOW_STATE_FULLSCREEN) { 763 show_state == ui::SHOW_STATE_FULLSCREEN) {
706 error_ = keys::kInvalidWindowStateError; 764 error_ = keys::kInvalidWindowStateError;
707 return false; 765 return false;
708 } 766 }
709 browser->window()->Deactivate(); 767 controller->window()->Deactivate();
710 } 768 }
711 } 769 }
712 770
713 bool draw_attention = false; 771 bool draw_attention = false;
714 if (update_props->HasKey(keys::kDrawAttentionKey)) { 772 if (update_props->HasKey(keys::kDrawAttentionKey)) {
715 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 773 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
716 keys::kDrawAttentionKey, &draw_attention)); 774 keys::kDrawAttentionKey, &draw_attention));
717 browser->window()->FlashFrame(draw_attention); 775 controller->window()->FlashFrame(draw_attention);
718 } 776 }
719 777
720 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); 778 result_.reset(controller->CreateWindowValue());
721 779
722 return true; 780 return true;
723 } 781 }
724 782
725 bool RemoveWindowFunction::RunImpl() { 783 bool RemoveWindowFunction::RunImpl() {
726 int window_id = -1; 784 int window_id = -1;
727 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 785 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
728 786
729 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, 787 ExtensionWindowController* controller;
730 include_incognito(), &error_); 788 if (!GetWindowFromWindowID(this, window_id, &controller))
731 if (!browser)
732 return false; 789 return false;
733 790
734 // Don't let the extension remove the window if the user is dragging tabs 791 ExtensionWindowController::Reason reason;
735 // in that window. 792 if (!controller->CanClose(&reason)) {
736 if (!browser->IsTabStripEditable()) { 793 if (reason == ExtensionWindowController::REASON_TAB_STRIP_NOT_EDITABLE)
737 error_ = keys::kTabStripNotEditableError; 794 error_ = keys::kTabStripNotEditableError;
738 return false; 795 return false;
739 } 796 }
740 797 controller->window()->Close();
741 browser->CloseWindow();
742
743 return true; 798 return true;
744 } 799 }
745 800
746 // Tabs ------------------------------------------------------------------------ 801 // Tabs ------------------------------------------------------------------------
747 802
748 bool GetSelectedTabFunction::RunImpl() { 803 bool GetSelectedTabFunction::RunImpl() {
749 // windowId defaults to "current" window. 804 // windowId defaults to "current" window.
750 int window_id = extension_misc::kCurrentWindowId; 805 int window_id = extension_misc::kCurrentWindowId;
751 806
752 if (HasOptionalArgument(0)) 807 if (HasOptionalArgument(0))
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 } 1142 }
1088 1143
1089 // Make sure they actually specified tabs to select. 1144 // Make sure they actually specified tabs to select.
1090 if (selection.empty()) { 1145 if (selection.empty()) {
1091 error_ = keys::kNoHighlightedTabError; 1146 error_ = keys::kNoHighlightedTabError;
1092 return false; 1147 return false;
1093 } 1148 }
1094 1149
1095 selection.set_active(active_index); 1150 selection.set_active(active_index);
1096 browser->tabstrip_model()->SetSelectionFromModel(selection); 1151 browser->tabstrip_model()->SetSelectionFromModel(selection);
1097 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, true)); 1152 result_.reset(
1153 browser->extension_window_controller()->CreateWindowValueWithTabs());
1098 return true; 1154 return true;
1099 } 1155 }
1100 1156
1101 UpdateTabFunction::UpdateTabFunction() : web_contents_(NULL) { 1157 UpdateTabFunction::UpdateTabFunction() : web_contents_(NULL) {
1102 } 1158 }
1103 1159
1104 bool UpdateTabFunction::RunImpl() { 1160 bool UpdateTabFunction::RunImpl() {
1105 DictionaryValue* update_props = NULL; 1161 DictionaryValue* update_props = NULL;
1106 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 1162 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
1107 1163
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 // called for every API call the extension made. 1801 // called for every API call the extension made.
1746 GotLanguage(language); 1802 GotLanguage(language);
1747 } 1803 }
1748 1804
1749 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1805 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1750 result_.reset(Value::CreateStringValue(language.c_str())); 1806 result_.reset(Value::CreateStringValue(language.c_str()));
1751 SendResponse(true); 1807 SendResponse(true);
1752 1808
1753 Release(); // Balanced in Run() 1809 Release(); // Balanced in Run()
1754 } 1810 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.cc ('k') | chrome/browser/extensions/extension_tabs_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698