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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 23377002: Clean up windows API implementations to use JSON compiler generated code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/api/tabs/tabs_api.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 using content::BrowserThread; 102 using content::BrowserThread;
103 using content::NavigationController; 103 using content::NavigationController;
104 using content::NavigationEntry; 104 using content::NavigationEntry;
105 using content::OpenURLParams; 105 using content::OpenURLParams;
106 using content::Referrer; 106 using content::Referrer;
107 using content::RenderViewHost; 107 using content::RenderViewHost;
108 using content::WebContents; 108 using content::WebContents;
109 109
110 namespace extensions { 110 namespace extensions {
111 111
112 namespace Create = api::windows::Create;
113 namespace CreateData = Create::Params::CreateData;
112 namespace Get = api::windows::Get; 114 namespace Get = api::windows::Get;
113 namespace GetAll = api::windows::GetAll; 115 namespace GetAll = api::windows::GetAll;
114 namespace GetCurrent = api::windows::GetCurrent; 116 namespace GetCurrent = api::windows::GetCurrent;
115 namespace GetLastFocused = api::windows::GetLastFocused; 117 namespace GetLastFocused = api::windows::GetLastFocused;
118 namespace Remove = api::windows::Remove;
119 namespace Update = api::windows::Update;
120 namespace UpdateInfo = Update::Params::UpdateInfo;
not at google - send to devlin 2013/08/21 15:04:36 i really don't like all of these typedefs. Create,
pals 2013/08/22 08:54:28 Done.
116 namespace errors = extension_manifest_errors; 121 namespace errors = extension_manifest_errors;
117 namespace keys = tabs_constants; 122 namespace keys = tabs_constants;
118 namespace tabs = api::tabs; 123 namespace tabs = api::tabs;
119 typedef tabs::CaptureVisibleTab::Params::Options FormatEnum; 124 typedef tabs::CaptureVisibleTab::Params::Options FormatEnum;
120 125
121 using api::tabs::InjectDetails; 126 using api::tabs::InjectDetails;
122 127
123 const int TabsCaptureVisibleTabFunction::kDefaultQuality = 90; 128 const int TabsCaptureVisibleTabFunction::kDefaultQuality = 90;
124 129
125 namespace { 130 namespace {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 if (populate_tabs) 346 if (populate_tabs)
342 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension())); 347 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension()));
343 else 348 else
344 window_list->Append((*iter)->CreateWindowValue()); 349 window_list->Append((*iter)->CreateWindowValue());
345 } 350 }
346 SetResult(window_list); 351 SetResult(window_list);
347 return true; 352 return true;
348 } 353 }
349 354
350 bool WindowsCreateFunction::ShouldOpenIncognitoWindow( 355 bool WindowsCreateFunction::ShouldOpenIncognitoWindow(
351 const base::DictionaryValue* args, 356 const Create::Params* args,
352 std::vector<GURL>* urls, 357 std::vector<GURL>* urls,
353 bool* is_error) { 358 bool* is_error) {
354 *is_error = false; 359 *is_error = false;
355 const IncognitoModePrefs::Availability incognito_availability = 360 const IncognitoModePrefs::Availability incognito_availability =
356 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); 361 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
357 bool incognito = false; 362 bool incognito = false;
358 if (args && args->HasKey(keys::kIncognitoKey)) { 363 if (args && args->create_data->incognito) {
359 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, 364 incognito = *args->create_data->incognito;
360 &incognito));
361 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) { 365 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) {
362 error_ = keys::kIncognitoModeIsDisabled; 366 error_ = keys::kIncognitoModeIsDisabled;
363 *is_error = true; 367 *is_error = true;
364 return false; 368 return false;
365 } 369 }
366 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) { 370 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) {
367 error_ = keys::kIncognitoModeIsForced; 371 error_ = keys::kIncognitoModeIsForced;
368 *is_error = true; 372 *is_error = true;
369 return false; 373 return false;
370 } 374 }
(...skipping 20 matching lines...) Expand all
391 error_ = ErrorUtils::FormatErrorMessage( 395 error_ = ErrorUtils::FormatErrorMessage(
392 keys::kURLsNotAllowedInIncognitoError, first_url_erased); 396 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
393 *is_error = true; 397 *is_error = true;
394 return false; 398 return false;
395 } 399 }
396 } 400 }
397 return incognito; 401 return incognito;
398 } 402 }
399 403
400 bool WindowsCreateFunction::RunImpl() { 404 bool WindowsCreateFunction::RunImpl() {
401 base::DictionaryValue* args = NULL; 405 scoped_ptr<Create::Params> args(Create::Params::Create(*args_));
not at google - send to devlin 2013/08/21 15:04:36 args can't be null. the schema compilation should
pals 2013/08/22 08:54:28 Done.
402 std::vector<GURL> urls; 406 std::vector<GURL> urls;
403 TabStripModel* source_tab_strip = NULL; 407 TabStripModel* source_tab_strip = NULL;
404 int tab_index = -1; 408 int tab_index = -1;
405 409
406 if (HasOptionalArgument(0)) 410 if (HasOptionalArgument(0))
407 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 411 EXTENSION_FUNCTION_VALIDATE(args);
408 412
409 // Look for optional url. 413 // Look for optional url.
410 if (args) { 414 if (args) {
411 if (args->HasKey(keys::kUrlKey)) { 415 if (args->create_data->url) {
412 Value* url_value;
413 std::vector<std::string> url_strings; 416 std::vector<std::string> url_strings;
414 args->Get(keys::kUrlKey, &url_value);
415
416 // First, get all the URLs the client wants to open. 417 // First, get all the URLs the client wants to open.
417 if (url_value->IsType(Value::TYPE_STRING)) { 418 if (args->create_data->url->as_string) {
418 std::string url_string; 419 url_strings.push_back(*args->create_data->url->as_string);
419 url_value->GetAsString(&url_string); 420 } else if (args->create_data->url->as_strings) {
420 url_strings.push_back(url_string); 421 url_strings = *args->create_data->url->as_strings;
421 } else if (url_value->IsType(Value::TYPE_LIST)) {
422 const base::ListValue* url_list =
423 static_cast<const base::ListValue*>(url_value);
424 for (size_t i = 0; i < url_list->GetSize(); ++i) {
425 std::string url_string;
426 EXTENSION_FUNCTION_VALIDATE(url_list->GetString(i, &url_string));
427 url_strings.push_back(url_string);
428 }
429 } 422 }
430
431 // Second, resolve, validate and convert them to GURLs. 423 // Second, resolve, validate and convert them to GURLs.
432 for (std::vector<std::string>::iterator i = url_strings.begin(); 424 for (std::vector<std::string>::iterator i = url_strings.begin();
433 i != url_strings.end(); ++i) { 425 i != url_strings.end(); ++i) {
434 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( 426 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
435 *i, GetExtension()); 427 *i, GetExtension());
436 if (!url.is_valid()) { 428 if (!url.is_valid()) {
437 error_ = ErrorUtils::FormatErrorMessage( 429 error_ = ErrorUtils::FormatErrorMessage(
438 keys::kInvalidUrlError, *i); 430 keys::kInvalidUrlError, *i);
439 return false; 431 return false;
440 } 432 }
441 // Don't let the extension crash the browser or renderers. 433 // Don't let the extension crash the browser or renderers.
442 if (ExtensionTabUtil::IsCrashURL(url)) { 434 if (ExtensionTabUtil::IsCrashURL(url)) {
443 error_ = keys::kNoCrashBrowserError; 435 error_ = keys::kNoCrashBrowserError;
444 return false; 436 return false;
445 } 437 }
446 urls.push_back(url); 438 urls.push_back(url);
447 } 439 }
448 } 440 }
449 } 441 }
450 442
451 // Look for optional tab id. 443 // Look for optional tab id.
452 if (args) { 444 if (args) {
453 int tab_id = -1; 445 if (args->create_data->tab_id) {
454 if (args->HasKey(keys::kTabIdKey)) {
455 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id));
456
457 // Find the tab. |source_tab_strip| and |tab_index| will later be used to 446 // Find the tab. |source_tab_strip| and |tab_index| will later be used to
458 // move the tab into the created window. 447 // move the tab into the created window.
459 if (!GetTabById(tab_id, profile(), include_incognito(), 448 if (!GetTabById(*args->create_data->tab_id, profile(),
449 include_incognito(),
460 NULL, &source_tab_strip, 450 NULL, &source_tab_strip,
461 NULL, &tab_index, &error_)) 451 NULL, &tab_index, &error_))
462 return false; 452 return false;
463 } 453 }
464 } 454 }
465 455
466 Profile* window_profile = profile(); 456 Profile* window_profile = profile();
467 Browser::Type window_type = Browser::TYPE_TABBED; 457 Browser::Type window_type = Browser::TYPE_TABBED;
468 bool create_panel = false; 458 bool create_panel = false;
469 459
470 // panel_create_mode only applies if create_panel = true 460 // panel_create_mode only applies if create_panel = true
471 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; 461 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED;
472 462
473 gfx::Rect window_bounds; 463 gfx::Rect window_bounds;
474 bool focused = true; 464 bool focused = true;
475 bool saw_focus_key = false; 465 bool saw_focus_key = false;
476 std::string extension_id; 466 std::string extension_id;
477 467
478 // Decide whether we are opening a normal window or an incognito window. 468 // Decide whether we are opening a normal window or an incognito window.
479 bool is_error = true; 469 bool is_error = true;
480 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, 470 bool open_incognito_window = ShouldOpenIncognitoWindow(args.get(), &urls,
481 &is_error); 471 &is_error);
482 if (is_error) { 472 if (is_error) {
483 // error_ member variable is set inside of ShouldOpenIncognitoWindow. 473 // error_ member variable is set inside of ShouldOpenIncognitoWindow.
484 return false; 474 return false;
485 } 475 }
486 if (open_incognito_window) { 476 if (open_incognito_window) {
487 window_profile = window_profile->GetOffTheRecordProfile(); 477 window_profile = window_profile->GetOffTheRecordProfile();
488 } 478 }
489 479
490 if (args) { 480 if (args) {
491 // Figure out window type before figuring out bounds so that default 481 // Figure out window type before figuring out bounds so that default
492 // bounds can be set according to the window type. 482 // bounds can be set according to the window type.
493 std::string type_str; 483 if (args->create_data->type != CreateData::TYPE_NONE) {
not at google - send to devlin 2013/08/21 15:04:36 could you restructure this to use switch()?
pals 2013/08/22 08:54:28 Done.
494 if (args->HasKey(keys::kWindowTypeKey)) { 484 if (args->create_data->type == CreateData::TYPE_POPUP) {
495 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey,
496 &type_str));
497 if (type_str == keys::kWindowTypeValuePopup) {
498 window_type = Browser::TYPE_POPUP; 485 window_type = Browser::TYPE_POPUP;
499 extension_id = GetExtension()->id(); 486 extension_id = GetExtension()->id();
500 } else if (type_str == keys::kWindowTypeValuePanel || 487 } else if (args->create_data->type == CreateData::TYPE_PANEL ||
501 type_str == keys::kWindowTypeValueDetachedPanel) { 488 args->create_data->type == CreateData::TYPE_DETACHED_PANEL) {
502 extension_id = GetExtension()->id(); 489 extension_id = GetExtension()->id();
503 bool use_panels = false; 490 bool use_panels = false;
504 #if !defined(OS_ANDROID) 491 #if !defined(OS_ANDROID)
505 use_panels = PanelManager::ShouldUsePanels(extension_id); 492 use_panels = PanelManager::ShouldUsePanels(extension_id);
506 #endif 493 #endif
507 if (use_panels) { 494 if (use_panels) {
508 create_panel = true; 495 create_panel = true;
509 #if !defined(OS_CHROMEOS) 496 #if !defined(OS_CHROMEOS)
510 // Non-ChromeOS has both docked and detached panel types. 497 // Non-ChromeOS has both docked and detached panel types.
511 if (type_str == keys::kWindowTypeValueDetachedPanel) 498 if (args->create_data->type == CreateData::TYPE_DETACHED_PANEL)
512 panel_create_mode = PanelManager::CREATE_AS_DETACHED; 499 panel_create_mode = PanelManager::CREATE_AS_DETACHED;
513 #endif 500 #endif
514 } else { 501 } else {
515 window_type = Browser::TYPE_POPUP; 502 window_type = Browser::TYPE_POPUP;
516 } 503 }
517 } else if (type_str != keys::kWindowTypeValueNormal) { 504 } else if (args->create_data->type != CreateData::TYPE_NORMAL) {
518 error_ = keys::kInvalidWindowTypeError; 505 error_ = keys::kInvalidWindowTypeError;
519 return false; 506 return false;
520 } 507 }
521 } 508 }
522 509
523 // Initialize default window bounds according to window type. 510 // Initialize default window bounds according to window type.
524 if (window_type == Browser::TYPE_TABBED || 511 if (window_type == Browser::TYPE_TABBED ||
525 window_type == Browser::TYPE_POPUP || 512 window_type == Browser::TYPE_POPUP ||
526 create_panel) { 513 create_panel) {
527 // Try to position the new browser relative to its originating 514 // Try to position the new browser relative to its originating
(...skipping 10 matching lines...) Expand all
538 &window_bounds, 525 &window_bounds,
539 &show_state); 526 &show_state);
540 } 527 }
541 528
542 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) { 529 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) {
543 window_bounds.set_origin( 530 window_bounds.set_origin(
544 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin()); 531 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin());
545 } 532 }
546 533
547 // Any part of the bounds can optionally be set by the caller. 534 // Any part of the bounds can optionally be set by the caller.
548 int bounds_val = -1; 535 if (args->create_data->left)
549 if (args->HasKey(keys::kLeftKey)) { 536 window_bounds.set_x(*args->create_data->left);
550 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey,
551 &bounds_val));
552 window_bounds.set_x(bounds_val);
553 }
554 537
555 if (args->HasKey(keys::kTopKey)) { 538 if (args->create_data->top)
556 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, 539 window_bounds.set_y(*args->create_data->top);
557 &bounds_val));
558 window_bounds.set_y(bounds_val);
559 }
560 540
561 if (args->HasKey(keys::kWidthKey)) { 541 if (args->create_data->width)
562 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kWidthKey, 542 window_bounds.set_width(*args->create_data->width);
563 &bounds_val));
564 window_bounds.set_width(bounds_val);
565 }
566 543
567 if (args->HasKey(keys::kHeightKey)) { 544 if (args->create_data->height)
568 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 545 window_bounds.set_height(*args->create_data->height);
569 &bounds_val));
570 window_bounds.set_height(bounds_val);
571 }
572 546
573 if (args->HasKey(keys::kFocusedKey)) { 547 if (args->create_data->focused)
574 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 548 saw_focus_key = *args->create_data->focused;
575 &focused));
576 saw_focus_key = true;
577 }
578 } 549 }
579 550
580 if (create_panel) { 551 if (create_panel) {
581 if (urls.empty()) 552 if (urls.empty())
582 urls.push_back(GURL(chrome::kChromeUINewTabURL)); 553 urls.push_back(GURL(chrome::kChromeUINewTabURL));
583 554
584 #if defined(OS_CHROMEOS) 555 #if defined(OS_CHROMEOS)
585 if (PanelManager::ShouldUsePanels(extension_id)) { 556 if (PanelManager::ShouldUsePanels(extension_id)) {
586 ShellWindow::CreateParams create_params; 557 ShellWindow::CreateParams create_params;
587 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL; 558 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } else { 652 } else {
682 SetResult( 653 SetResult(
683 new_window->extension_window_controller()->CreateWindowValueWithTabs( 654 new_window->extension_window_controller()->CreateWindowValueWithTabs(
684 GetExtension())); 655 GetExtension()));
685 } 656 }
686 657
687 return true; 658 return true;
688 } 659 }
689 660
690 bool WindowsUpdateFunction::RunImpl() { 661 bool WindowsUpdateFunction::RunImpl() {
691 int window_id = extension_misc::kUnknownWindowId; 662 scoped_ptr<Update::Params> params(Update::Params::Create(*args_));
692 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 663 EXTENSION_FUNCTION_VALIDATE(params);
693 base::DictionaryValue* update_props;
694 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
695 664
696 WindowController* controller; 665 WindowController* controller;
697 if (!GetWindowFromWindowID(this, window_id, &controller)) 666 if (!GetWindowFromWindowID(this, params->window_id, &controller))
698 return false; 667 return false;
699 668
700 #if defined(OS_WIN) 669 #if defined(OS_WIN)
701 // Silently ignore changes on the window for metro mode. 670 // Silently ignore changes on the window for metro mode.
702 if (win8::IsSingleWindowMetroMode()) { 671 if (win8::IsSingleWindowMetroMode()) {
703 SetResult(controller->CreateWindowValue()); 672 SetResult(controller->CreateWindowValue());
704 return true; 673 return true;
705 } 674 }
706 #endif 675 #endif
707 676
708 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 677 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
709 std::string state_str; 678 if (params->update_info.state != UpdateInfo::STATE_NONE) {
710 if (update_props->HasKey(keys::kShowStateKey)) { 679 if (params->update_info.state == UpdateInfo::STATE_NORMAL) {
711 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
712 &state_str));
713 if (state_str == keys::kShowStateValueNormal) {
714 show_state = ui::SHOW_STATE_NORMAL; 680 show_state = ui::SHOW_STATE_NORMAL;
715 } else if (state_str == keys::kShowStateValueMinimized) { 681 } else if (params->update_info.state == UpdateInfo::STATE_MINIMIZED) {
716 show_state = ui::SHOW_STATE_MINIMIZED; 682 show_state = ui::SHOW_STATE_MINIMIZED;
717 } else if (state_str == keys::kShowStateValueMaximized) { 683 } else if (params->update_info.state == UpdateInfo::STATE_MAXIMIZED) {
718 show_state = ui::SHOW_STATE_MAXIMIZED; 684 show_state = ui::SHOW_STATE_MAXIMIZED;
719 } else if (state_str == keys::kShowStateValueFullscreen) { 685 } else if (params->update_info.state == UpdateInfo::STATE_FULLSCREEN) {
720 show_state = ui::SHOW_STATE_FULLSCREEN; 686 show_state = ui::SHOW_STATE_FULLSCREEN;
721 } else { 687 } else {
722 error_ = keys::kInvalidWindowStateError; 688 error_ = keys::kInvalidWindowStateError;
723 return false; 689 return false;
724 } 690 }
725 } 691 }
726 692
727 if (show_state != ui::SHOW_STATE_FULLSCREEN && 693 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
728 show_state != ui::SHOW_STATE_DEFAULT) 694 show_state != ui::SHOW_STATE_DEFAULT)
729 controller->SetFullscreenMode(false, GetExtension()->url()); 695 controller->SetFullscreenMode(false, GetExtension()->url());
(...skipping 19 matching lines...) Expand all
749 } 715 }
750 716
751 gfx::Rect bounds; 717 gfx::Rect bounds;
752 if (controller->window()->IsMinimized()) 718 if (controller->window()->IsMinimized())
753 bounds = controller->window()->GetRestoredBounds(); 719 bounds = controller->window()->GetRestoredBounds();
754 else 720 else
755 bounds = controller->window()->GetBounds(); 721 bounds = controller->window()->GetBounds();
756 bool set_bounds = false; 722 bool set_bounds = false;
757 723
758 // Any part of the bounds can optionally be set by the caller. 724 // Any part of the bounds can optionally be set by the caller.
759 int bounds_val; 725 if (params->update_info.left) {
760 if (update_props->HasKey(keys::kLeftKey)) { 726 bounds.set_x(*params->update_info.left);
761 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
762 keys::kLeftKey,
763 &bounds_val));
764 bounds.set_x(bounds_val);
765 set_bounds = true; 727 set_bounds = true;
766 } 728 }
767 729
768 if (update_props->HasKey(keys::kTopKey)) { 730 if (params->update_info.top) {
769 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 731 bounds.set_y(*params->update_info.top);
770 keys::kTopKey,
771 &bounds_val));
772 bounds.set_y(bounds_val);
773 set_bounds = true; 732 set_bounds = true;
774 } 733 }
775 734
776 if (update_props->HasKey(keys::kWidthKey)) { 735 if (params->update_info.width) {
777 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 736 bounds.set_width(*params->update_info.width);
778 keys::kWidthKey,
779 &bounds_val));
780 bounds.set_width(bounds_val);
781 set_bounds = true; 737 set_bounds = true;
782 } 738 }
783 739
784 if (update_props->HasKey(keys::kHeightKey)) { 740 if (params->update_info.height) {
785 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 741 bounds.set_height(*params->update_info.height);
786 keys::kHeightKey,
787 &bounds_val));
788 bounds.set_height(bounds_val);
789 set_bounds = true; 742 set_bounds = true;
790 } 743 }
791 744
792 if (set_bounds) { 745 if (set_bounds) {
793 if (show_state == ui::SHOW_STATE_MINIMIZED || 746 if (show_state == ui::SHOW_STATE_MINIMIZED ||
794 show_state == ui::SHOW_STATE_MAXIMIZED || 747 show_state == ui::SHOW_STATE_MAXIMIZED ||
795 show_state == ui::SHOW_STATE_FULLSCREEN) { 748 show_state == ui::SHOW_STATE_FULLSCREEN) {
796 error_ = keys::kInvalidWindowStateError; 749 error_ = keys::kInvalidWindowStateError;
797 return false; 750 return false;
798 } 751 }
799 // TODO(varkha): Updating bounds during a drag can cause problems and a more 752 // TODO(varkha): Updating bounds during a drag can cause problems and a more
800 // general solution is needed. See http://crbug.com/251813 . 753 // general solution is needed. See http://crbug.com/251813 .
801 controller->window()->SetBounds(bounds); 754 controller->window()->SetBounds(bounds);
802 } 755 }
803 756
804 bool active_val = false; 757 if (params->update_info.focused) {
805 if (update_props->HasKey(keys::kFocusedKey)) { 758 if (*params->update_info.focused) {
806 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
807 keys::kFocusedKey, &active_val));
808 if (active_val) {
809 if (show_state == ui::SHOW_STATE_MINIMIZED) { 759 if (show_state == ui::SHOW_STATE_MINIMIZED) {
810 error_ = keys::kInvalidWindowStateError; 760 error_ = keys::kInvalidWindowStateError;
811 return false; 761 return false;
812 } 762 }
813 controller->window()->Activate(); 763 controller->window()->Activate();
814 } else { 764 } else {
815 if (show_state == ui::SHOW_STATE_MAXIMIZED || 765 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
816 show_state == ui::SHOW_STATE_FULLSCREEN) { 766 show_state == ui::SHOW_STATE_FULLSCREEN) {
817 error_ = keys::kInvalidWindowStateError; 767 error_ = keys::kInvalidWindowStateError;
818 return false; 768 return false;
819 } 769 }
820 controller->window()->Deactivate(); 770 controller->window()->Deactivate();
821 } 771 }
822 } 772 }
823 773
824 bool draw_attention = false; 774 if (params->update_info.draw_attention)
825 if (update_props->HasKey(keys::kDrawAttentionKey)) { 775 controller->window()->FlashFrame(*params->update_info.draw_attention);
826 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
827 keys::kDrawAttentionKey, &draw_attention));
828 controller->window()->FlashFrame(draw_attention);
829 }
830 776
831 SetResult(controller->CreateWindowValue()); 777 SetResult(controller->CreateWindowValue());
832 778
833 return true; 779 return true;
834 } 780 }
835 781
836 bool WindowsRemoveFunction::RunImpl() { 782 bool WindowsRemoveFunction::RunImpl() {
837 int window_id = -1; 783 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_));
838 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 784 EXTENSION_FUNCTION_VALIDATE(params);
839 785
840 WindowController* controller; 786 WindowController* controller;
841 if (!GetWindowFromWindowID(this, window_id, &controller)) 787 if (!GetWindowFromWindowID(this, params->window_id, &controller))
842 return false; 788 return false;
843 789
844 #if defined(OS_WIN) 790 #if defined(OS_WIN)
845 // In Windows 8 metro mode, an existing Browser instance is reused for 791 // In Windows 8 metro mode, an existing Browser instance is reused for
846 // hosting the extension tab. We should not be closing it as we don't own it. 792 // hosting the extension tab. We should not be closing it as we don't own it.
847 if (win8::IsSingleWindowMetroMode()) 793 if (win8::IsSingleWindowMetroMode())
848 return false; 794 return false;
849 #endif 795 #endif
850 796
851 WindowController::Reason reason; 797 WindowController::Reason reason;
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 execute_tab_id_ = tab_id; 2011 execute_tab_id_ = tab_id;
2066 details_ = details.Pass(); 2012 details_ = details.Pass();
2067 return true; 2013 return true;
2068 } 2014 }
2069 2015
2070 bool TabsInsertCSSFunction::ShouldInsertCSS() const { 2016 bool TabsInsertCSSFunction::ShouldInsertCSS() const {
2071 return true; 2017 return true;
2072 } 2018 }
2073 2019
2074 } // namespace extensions 2020 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698