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

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, 3 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/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 Get = api::windows::Get; 112 namespace windows = api::windows;
113 namespace GetAll = api::windows::GetAll;
114 namespace GetCurrent = api::windows::GetCurrent;
115 namespace GetLastFocused = api::windows::GetLastFocused;
116 namespace errors = extension_manifest_errors; 113 namespace errors = extension_manifest_errors;
117 namespace keys = tabs_constants; 114 namespace keys = tabs_constants;
118 namespace tabs = api::tabs; 115 namespace tabs = api::tabs;
119 typedef tabs::CaptureVisibleTab::Params::Options FormatEnum; 116 typedef tabs::CaptureVisibleTab::Params::Options FormatEnum;
120 117
121 using api::tabs::InjectDetails; 118 using api::tabs::InjectDetails;
122 119
123 const int TabsCaptureVisibleTabFunction::kDefaultQuality = 90; 120 const int TabsCaptureVisibleTabFunction::kDefaultQuality = 90;
124 121
125 namespace { 122 namespace {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (!new_window) 246 if (!new_window)
250 new_window = new Browser(params); 247 new_window = new Browser(params);
251 return new_window; 248 return new_window;
252 } 249 }
253 250
254 } // namespace 251 } // namespace
255 252
256 // Windows --------------------------------------------------------------------- 253 // Windows ---------------------------------------------------------------------
257 254
258 bool WindowsGetFunction::RunImpl() { 255 bool WindowsGetFunction::RunImpl() {
259 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); 256 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_));
260 EXTENSION_FUNCTION_VALIDATE(params.get()); 257 EXTENSION_FUNCTION_VALIDATE(params.get());
261 258
262 bool populate_tabs = false; 259 bool populate_tabs = false;
263 if (params->get_info.get() && params->get_info->populate.get()) 260 if (params->get_info.get() && params->get_info->populate.get())
264 populate_tabs = *params->get_info->populate; 261 populate_tabs = *params->get_info->populate;
265 262
266 WindowController* controller; 263 WindowController* controller;
267 if (!GetWindowFromWindowID(this, params->window_id, &controller)) 264 if (!GetWindowFromWindowID(this, params->window_id, &controller))
268 return false; 265 return false;
269 266
270 if (populate_tabs) 267 if (populate_tabs)
271 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); 268 SetResult(controller->CreateWindowValueWithTabs(GetExtension()));
272 else 269 else
273 SetResult(controller->CreateWindowValue()); 270 SetResult(controller->CreateWindowValue());
274 return true; 271 return true;
275 } 272 }
276 273
277 bool WindowsGetCurrentFunction::RunImpl() { 274 bool WindowsGetCurrentFunction::RunImpl() {
278 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); 275 scoped_ptr<windows::GetCurrent::Params> params(
276 windows::GetCurrent::Params::Create(*args_));
279 EXTENSION_FUNCTION_VALIDATE(params.get()); 277 EXTENSION_FUNCTION_VALIDATE(params.get());
280 278
281 bool populate_tabs = false; 279 bool populate_tabs = false;
282 if (params->get_info.get() && params->get_info->populate.get()) 280 if (params->get_info.get() && params->get_info->populate.get())
283 populate_tabs = *params->get_info->populate; 281 populate_tabs = *params->get_info->populate;
284 282
285 WindowController* controller; 283 WindowController* controller;
286 if (!GetWindowFromWindowID(this, 284 if (!GetWindowFromWindowID(this,
287 extension_misc::kCurrentWindowId, 285 extension_misc::kCurrentWindowId,
288 &controller)) { 286 &controller)) {
289 return false; 287 return false;
290 } 288 }
291 if (populate_tabs) 289 if (populate_tabs)
292 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); 290 SetResult(controller->CreateWindowValueWithTabs(GetExtension()));
293 else 291 else
294 SetResult(controller->CreateWindowValue()); 292 SetResult(controller->CreateWindowValue());
295 return true; 293 return true;
296 } 294 }
297 295
298 bool WindowsGetLastFocusedFunction::RunImpl() { 296 bool WindowsGetLastFocusedFunction::RunImpl() {
299 scoped_ptr<GetLastFocused::Params> params( 297 scoped_ptr<windows::GetLastFocused::Params> params(
300 GetLastFocused::Params::Create(*args_)); 298 windows::GetLastFocused::Params::Create(*args_));
301 EXTENSION_FUNCTION_VALIDATE(params.get()); 299 EXTENSION_FUNCTION_VALIDATE(params.get());
302 300
303 bool populate_tabs = false; 301 bool populate_tabs = false;
304 if (params->get_info.get() && params->get_info->populate.get()) 302 if (params->get_info.get() && params->get_info->populate.get())
305 populate_tabs = *params->get_info->populate; 303 populate_tabs = *params->get_info->populate;
306 304
307 // Note: currently this returns the last active browser. If we decide to 305 // Note: currently this returns the last active browser. If we decide to
308 // include other window types (e.g. panels), we will need to add logic to 306 // include other window types (e.g. panels), we will need to add logic to
309 // WindowControllerList that mirrors the active behavior of BrowserList. 307 // WindowControllerList that mirrors the active behavior of BrowserList.
310 Browser* browser = chrome::FindAnyBrowser( 308 Browser* browser = chrome::FindAnyBrowser(
311 profile(), include_incognito(), chrome::GetActiveDesktop()); 309 profile(), include_incognito(), chrome::GetActiveDesktop());
312 if (!browser || !browser->window()) { 310 if (!browser || !browser->window()) {
313 error_ = keys::kNoLastFocusedWindowError; 311 error_ = keys::kNoLastFocusedWindowError;
314 return false; 312 return false;
315 } 313 }
316 WindowController* controller = 314 WindowController* controller =
317 browser->extension_window_controller(); 315 browser->extension_window_controller();
318 if (populate_tabs) 316 if (populate_tabs)
319 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); 317 SetResult(controller->CreateWindowValueWithTabs(GetExtension()));
320 else 318 else
321 SetResult(controller->CreateWindowValue()); 319 SetResult(controller->CreateWindowValue());
322 return true; 320 return true;
323 } 321 }
324 322
325 bool WindowsGetAllFunction::RunImpl() { 323 bool WindowsGetAllFunction::RunImpl() {
326 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); 324 scoped_ptr<windows::GetAll::Params> params(
325 windows::GetAll::Params::Create(*args_));
327 EXTENSION_FUNCTION_VALIDATE(params.get()); 326 EXTENSION_FUNCTION_VALIDATE(params.get());
328 327
329 bool populate_tabs = false; 328 bool populate_tabs = false;
330 if (params->get_info.get() && params->get_info->populate.get()) 329 if (params->get_info.get() && params->get_info->populate.get())
331 populate_tabs = *params->get_info->populate; 330 populate_tabs = *params->get_info->populate;
332 331
333 base::ListValue* window_list = new base::ListValue(); 332 base::ListValue* window_list = new base::ListValue();
334 const WindowControllerList::ControllerList& windows = 333 const WindowControllerList::ControllerList& windows =
335 WindowControllerList::GetInstance()->windows(); 334 WindowControllerList::GetInstance()->windows();
336 for (WindowControllerList::ControllerList::const_iterator iter = 335 for (WindowControllerList::ControllerList::const_iterator iter =
337 windows.begin(); 336 windows.begin();
338 iter != windows.end(); ++iter) { 337 iter != windows.end(); ++iter) {
339 if (!this->CanOperateOnWindow(*iter)) 338 if (!this->CanOperateOnWindow(*iter))
340 continue; 339 continue;
341 if (populate_tabs) 340 if (populate_tabs)
342 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension())); 341 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension()));
343 else 342 else
344 window_list->Append((*iter)->CreateWindowValue()); 343 window_list->Append((*iter)->CreateWindowValue());
345 } 344 }
346 SetResult(window_list); 345 SetResult(window_list);
347 return true; 346 return true;
348 } 347 }
349 348
350 bool WindowsCreateFunction::ShouldOpenIncognitoWindow( 349 bool WindowsCreateFunction::ShouldOpenIncognitoWindow(
351 const base::DictionaryValue* args, 350 const windows::Create::Params::CreateData* create_data,
352 std::vector<GURL>* urls, 351 std::vector<GURL>* urls, bool* is_error) {
353 bool* is_error) {
354 *is_error = false; 352 *is_error = false;
355 const IncognitoModePrefs::Availability incognito_availability = 353 const IncognitoModePrefs::Availability incognito_availability =
356 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); 354 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
357 bool incognito = false; 355 bool incognito = false;
358 if (args && args->HasKey(keys::kIncognitoKey)) { 356 if (create_data && create_data->incognito) {
359 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, 357 incognito = *create_data->incognito;
360 &incognito));
361 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) { 358 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) {
362 error_ = keys::kIncognitoModeIsDisabled; 359 error_ = keys::kIncognitoModeIsDisabled;
363 *is_error = true; 360 *is_error = true;
364 return false; 361 return false;
365 } 362 }
366 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) { 363 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) {
367 error_ = keys::kIncognitoModeIsForced; 364 error_ = keys::kIncognitoModeIsForced;
368 *is_error = true; 365 *is_error = true;
369 return false; 366 return false;
370 } 367 }
(...skipping 20 matching lines...) Expand all
391 error_ = ErrorUtils::FormatErrorMessage( 388 error_ = ErrorUtils::FormatErrorMessage(
392 keys::kURLsNotAllowedInIncognitoError, first_url_erased); 389 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
393 *is_error = true; 390 *is_error = true;
394 return false; 391 return false;
395 } 392 }
396 } 393 }
397 return incognito; 394 return incognito;
398 } 395 }
399 396
400 bool WindowsCreateFunction::RunImpl() { 397 bool WindowsCreateFunction::RunImpl() {
401 base::DictionaryValue* args = NULL; 398 scoped_ptr<windows::Create::Params> params(
399 windows::Create::Params::Create(*args_));
400 EXTENSION_FUNCTION_VALIDATE(params);
402 std::vector<GURL> urls; 401 std::vector<GURL> urls;
403 TabStripModel* source_tab_strip = NULL; 402 TabStripModel* source_tab_strip = NULL;
404 int tab_index = -1; 403 int tab_index = -1;
405 404
406 if (HasOptionalArgument(0)) 405 windows::Create::Params::CreateData* create_data = params->create_data.get();
407 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
408 406
409 // Look for optional url. 407 // Look for optional url.
410 if (args) { 408 if (create_data && create_data->url) {
411 if (args->HasKey(keys::kUrlKey)) { 409 std::vector<std::string> url_strings;
412 Value* url_value; 410 // First, get all the URLs the client wants to open.
413 std::vector<std::string> url_strings; 411 if (create_data->url->as_string)
414 args->Get(keys::kUrlKey, &url_value); 412 url_strings.push_back(*create_data->url->as_string);
413 else if (create_data->url->as_strings)
414 url_strings.swap(*create_data->url->as_strings);
415 415
416 // First, get all the URLs the client wants to open. 416 // Second, resolve, validate and convert them to GURLs.
417 if (url_value->IsType(Value::TYPE_STRING)) { 417 for (std::vector<std::string>::iterator i = url_strings.begin();
418 std::string url_string; 418 i != url_strings.end(); ++i) {
419 url_value->GetAsString(&url_string); 419 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
420 url_strings.push_back(url_string); 420 *i, GetExtension());
421 } else if (url_value->IsType(Value::TYPE_LIST)) { 421 if (!url.is_valid()) {
422 const base::ListValue* url_list = 422 error_ = ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, *i);
423 static_cast<const base::ListValue*>(url_value); 423 return false;
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 } 424 }
430 425 // Don't let the extension crash the browser or renderers.
431 // Second, resolve, validate and convert them to GURLs. 426 if (ExtensionTabUtil::IsCrashURL(url)) {
432 for (std::vector<std::string>::iterator i = url_strings.begin(); 427 error_ = keys::kNoCrashBrowserError;
433 i != url_strings.end(); ++i) { 428 return false;
434 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
435 *i, GetExtension());
436 if (!url.is_valid()) {
437 error_ = ErrorUtils::FormatErrorMessage(
438 keys::kInvalidUrlError, *i);
439 return false;
440 }
441 // Don't let the extension crash the browser or renderers.
442 if (ExtensionTabUtil::IsCrashURL(url)) {
443 error_ = keys::kNoCrashBrowserError;
444 return false;
445 }
446 urls.push_back(url);
447 } 429 }
430 urls.push_back(url);
448 } 431 }
449 } 432 }
450 433
451 // Look for optional tab id. 434 // Look for optional tab id.
452 if (args) { 435 if (create_data && create_data->tab_id) {
453 int tab_id = -1; 436 // Find the tab. |source_tab_strip| and |tab_index| will later be used to
454 if (args->HasKey(keys::kTabIdKey)) { 437 // move the tab into the created window.
455 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id)); 438 if (!GetTabById(*create_data->tab_id, profile(), include_incognito(), NULL,
456 439 &source_tab_strip, NULL, &tab_index, &error_))
457 // Find the tab. |source_tab_strip| and |tab_index| will later be used to 440 return false;
458 // move the tab into the created window.
459 if (!GetTabById(tab_id, profile(), include_incognito(),
460 NULL, &source_tab_strip,
461 NULL, &tab_index, &error_))
462 return false;
463 }
464 } 441 }
465 442
466 Profile* window_profile = profile(); 443 Profile* window_profile = profile();
467 Browser::Type window_type = Browser::TYPE_TABBED; 444 Browser::Type window_type = Browser::TYPE_TABBED;
468 bool create_panel = false; 445 bool create_panel = false;
469 446
470 // panel_create_mode only applies if create_panel = true 447 // panel_create_mode only applies if create_panel = true
471 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; 448 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED;
472 449
473 gfx::Rect window_bounds; 450 gfx::Rect window_bounds;
474 bool focused = true; 451 bool focused = true;
475 bool saw_focus_key = false; 452 bool saw_focus_key = false;
476 std::string extension_id; 453 std::string extension_id;
477 454
478 // Decide whether we are opening a normal window or an incognito window. 455 // Decide whether we are opening a normal window or an incognito window.
479 bool is_error = true; 456 bool is_error = true;
480 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, 457 bool open_incognito_window = ShouldOpenIncognitoWindow(create_data, &urls,
481 &is_error); 458 &is_error);
482 if (is_error) { 459 if (is_error) {
483 // error_ member variable is set inside of ShouldOpenIncognitoWindow. 460 // error_ member variable is set inside of ShouldOpenIncognitoWindow.
484 return false; 461 return false;
485 } 462 }
486 if (open_incognito_window) { 463 if (open_incognito_window) {
487 window_profile = window_profile->GetOffTheRecordProfile(); 464 window_profile = window_profile->GetOffTheRecordProfile();
488 } 465 }
489 466
490 if (args) { 467 if (create_data) {
491 // Figure out window type before figuring out bounds so that default 468 // Figure out window type before figuring out bounds so that default
492 // bounds can be set according to the window type. 469 // bounds can be set according to the window type.
493 std::string type_str; 470 bool use_panels = false;
not at google - send to devlin 2013/08/23 14:50:55 only declare this when it's used, you can put {}s
494 if (args->HasKey(keys::kWindowTypeKey)) { 471 switch (create_data->type) {
495 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey, 472 case windows::Create::Params::CreateData::TYPE_POPUP:
496 &type_str));
497 if (type_str == keys::kWindowTypeValuePopup) {
498 window_type = Browser::TYPE_POPUP; 473 window_type = Browser::TYPE_POPUP;
499 extension_id = GetExtension()->id(); 474 extension_id = GetExtension()->id();
500 } else if (type_str == keys::kWindowTypeValuePanel || 475 break;
501 type_str == keys::kWindowTypeValueDetachedPanel) { 476 case windows::Create::Params::CreateData::TYPE_PANEL:
477 case windows::Create::Params::CreateData::TYPE_DETACHED_PANEL:
502 extension_id = GetExtension()->id(); 478 extension_id = GetExtension()->id();
503 bool use_panels = false;
504 #if !defined(OS_ANDROID) 479 #if !defined(OS_ANDROID)
505 use_panels = PanelManager::ShouldUsePanels(extension_id); 480 use_panels = PanelManager::ShouldUsePanels(extension_id);
506 #endif 481 #endif
507 if (use_panels) { 482 if (use_panels) {
508 create_panel = true; 483 create_panel = true;
509 #if !defined(OS_CHROMEOS) 484 #if !defined(OS_CHROMEOS)
510 // Non-ChromeOS has both docked and detached panel types. 485 // Non-ChromeOS has both docked and detached panel types.
511 if (type_str == keys::kWindowTypeValueDetachedPanel) 486 if (create_data->type ==
487 windows::Create::Params::CreateData::TYPE_DETACHED_PANEL) {
512 panel_create_mode = PanelManager::CREATE_AS_DETACHED; 488 panel_create_mode = PanelManager::CREATE_AS_DETACHED;
489 }
513 #endif 490 #endif
514 } else { 491 } else {
515 window_type = Browser::TYPE_POPUP; 492 window_type = Browser::TYPE_POPUP;
516 } 493 }
517 } else if (type_str != keys::kWindowTypeValueNormal) { 494 break;
495 case windows::Create::Params::CreateData::TYPE_NONE:
496 case windows::Create::Params::CreateData::TYPE_NORMAL:
497 break;
498 default:
518 error_ = keys::kInvalidWindowTypeError; 499 error_ = keys::kInvalidWindowTypeError;
519 return false; 500 return false;
520 }
521 } 501 }
522 502
523 // Initialize default window bounds according to window type. 503 // Initialize default window bounds according to window type.
524 if (window_type == Browser::TYPE_TABBED || 504 if (window_type == Browser::TYPE_TABBED ||
525 window_type == Browser::TYPE_POPUP || 505 window_type == Browser::TYPE_POPUP ||
526 create_panel) { 506 create_panel) {
527 // Try to position the new browser relative to its originating 507 // Try to position the new browser relative to its originating
528 // browser window. The call offsets the bounds by kWindowTilePixels 508 // browser window. The call offsets the bounds by kWindowTilePixels
529 // (defined in WindowSizer to be 10). 509 // (defined in WindowSizer to be 10).
530 // 510 //
531 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here. 511 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here.
532 // GetBrowserWindowBounds will default to saved "default" values for 512 // GetBrowserWindowBounds will default to saved "default" values for
533 // the app. 513 // the app.
534 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; 514 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
535 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(), 515 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(),
536 gfx::Rect(), 516 gfx::Rect(),
537 GetCurrentBrowser(), 517 GetCurrentBrowser(),
538 &window_bounds, 518 &window_bounds,
539 &show_state); 519 &show_state);
540 } 520 }
541 521
542 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) { 522 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) {
543 window_bounds.set_origin( 523 window_bounds.set_origin(
544 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin()); 524 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin());
545 } 525 }
546 526
547 // Any part of the bounds can optionally be set by the caller. 527 // Any part of the bounds can optionally be set by the caller.
548 int bounds_val = -1; 528 if (create_data->left)
549 if (args->HasKey(keys::kLeftKey)) { 529 window_bounds.set_x(*create_data->left);
550 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey,
551 &bounds_val));
552 window_bounds.set_x(bounds_val);
553 }
554 530
555 if (args->HasKey(keys::kTopKey)) { 531 if (create_data->top)
556 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, 532 window_bounds.set_y(*create_data->top);
557 &bounds_val));
558 window_bounds.set_y(bounds_val);
559 }
560 533
561 if (args->HasKey(keys::kWidthKey)) { 534 if (create_data->width)
562 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kWidthKey, 535 window_bounds.set_width(*create_data->width);
563 &bounds_val));
564 window_bounds.set_width(bounds_val);
565 }
566 536
567 if (args->HasKey(keys::kHeightKey)) { 537 if (create_data->height)
568 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 538 window_bounds.set_height(*create_data->height);
569 &bounds_val));
570 window_bounds.set_height(bounds_val);
571 }
572 539
573 if (args->HasKey(keys::kFocusedKey)) { 540 if (create_data->focused)
574 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 541 saw_focus_key = *create_data->focused;
575 &focused));
576 saw_focus_key = true;
577 }
578 } 542 }
579 543
580 if (create_panel) { 544 if (create_panel) {
581 if (urls.empty()) 545 if (urls.empty())
582 urls.push_back(GURL(chrome::kChromeUINewTabURL)); 546 urls.push_back(GURL(chrome::kChromeUINewTabURL));
583 547
584 #if defined(OS_CHROMEOS) 548 #if defined(OS_CHROMEOS)
585 if (PanelManager::ShouldUsePanels(extension_id)) { 549 if (PanelManager::ShouldUsePanels(extension_id)) {
586 ShellWindow::CreateParams create_params; 550 ShellWindow::CreateParams create_params;
587 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL; 551 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } else { 645 } else {
682 SetResult( 646 SetResult(
683 new_window->extension_window_controller()->CreateWindowValueWithTabs( 647 new_window->extension_window_controller()->CreateWindowValueWithTabs(
684 GetExtension())); 648 GetExtension()));
685 } 649 }
686 650
687 return true; 651 return true;
688 } 652 }
689 653
690 bool WindowsUpdateFunction::RunImpl() { 654 bool WindowsUpdateFunction::RunImpl() {
691 int window_id = extension_misc::kUnknownWindowId; 655 scoped_ptr<windows::Update::Params> params(
692 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 656 windows::Update::Params::Create(*args_));
693 base::DictionaryValue* update_props; 657 EXTENSION_FUNCTION_VALIDATE(params);
694 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
695 658
696 WindowController* controller; 659 WindowController* controller;
697 if (!GetWindowFromWindowID(this, window_id, &controller)) 660 if (!GetWindowFromWindowID(this, params->window_id, &controller))
698 return false; 661 return false;
699 662
700 #if defined(OS_WIN) 663 #if defined(OS_WIN)
701 // Silently ignore changes on the window for metro mode. 664 // Silently ignore changes on the window for metro mode.
702 if (win8::IsSingleWindowMetroMode()) { 665 if (win8::IsSingleWindowMetroMode()) {
703 SetResult(controller->CreateWindowValue()); 666 SetResult(controller->CreateWindowValue());
704 return true; 667 return true;
705 } 668 }
706 #endif 669 #endif
707 670
708 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 671 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
709 std::string state_str; 672 switch (params->update_info.state) {
710 if (update_props->HasKey(keys::kShowStateKey)) { 673 case windows::Update::Params::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; 674 show_state = ui::SHOW_STATE_NORMAL;
715 } else if (state_str == keys::kShowStateValueMinimized) { 675 break;
676 case windows::Update::Params::UpdateInfo::STATE_MINIMIZED:
716 show_state = ui::SHOW_STATE_MINIMIZED; 677 show_state = ui::SHOW_STATE_MINIMIZED;
717 } else if (state_str == keys::kShowStateValueMaximized) { 678 break;
679 case windows::Update::Params::UpdateInfo::STATE_MAXIMIZED:
718 show_state = ui::SHOW_STATE_MAXIMIZED; 680 show_state = ui::SHOW_STATE_MAXIMIZED;
719 } else if (state_str == keys::kShowStateValueFullscreen) { 681 break;
682 case windows::Update::Params::UpdateInfo::STATE_FULLSCREEN:
720 show_state = ui::SHOW_STATE_FULLSCREEN; 683 show_state = ui::SHOW_STATE_FULLSCREEN;
721 } else { 684 break;
685 case windows::Update::Params::UpdateInfo::STATE_NONE:
686 break;
687 default:
722 error_ = keys::kInvalidWindowStateError; 688 error_ = keys::kInvalidWindowStateError;
723 return false; 689 return false;
724 }
725 } 690 }
726 691
727 if (show_state != ui::SHOW_STATE_FULLSCREEN && 692 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
728 show_state != ui::SHOW_STATE_DEFAULT) 693 show_state != ui::SHOW_STATE_DEFAULT)
729 controller->SetFullscreenMode(false, GetExtension()->url()); 694 controller->SetFullscreenMode(false, GetExtension()->url());
730 695
731 switch (show_state) { 696 switch (show_state) {
732 case ui::SHOW_STATE_MINIMIZED: 697 case ui::SHOW_STATE_MINIMIZED:
733 controller->window()->Minimize(); 698 controller->window()->Minimize();
734 break; 699 break;
(...skipping 14 matching lines...) Expand all
749 } 714 }
750 715
751 gfx::Rect bounds; 716 gfx::Rect bounds;
752 if (controller->window()->IsMinimized()) 717 if (controller->window()->IsMinimized())
753 bounds = controller->window()->GetRestoredBounds(); 718 bounds = controller->window()->GetRestoredBounds();
754 else 719 else
755 bounds = controller->window()->GetBounds(); 720 bounds = controller->window()->GetBounds();
756 bool set_bounds = false; 721 bool set_bounds = false;
757 722
758 // Any part of the bounds can optionally be set by the caller. 723 // Any part of the bounds can optionally be set by the caller.
759 int bounds_val; 724 if (params->update_info.left) {
760 if (update_props->HasKey(keys::kLeftKey)) { 725 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; 726 set_bounds = true;
766 } 727 }
767 728
768 if (update_props->HasKey(keys::kTopKey)) { 729 if (params->update_info.top) {
769 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 730 bounds.set_y(*params->update_info.top);
770 keys::kTopKey,
771 &bounds_val));
772 bounds.set_y(bounds_val);
773 set_bounds = true; 731 set_bounds = true;
774 } 732 }
775 733
776 if (update_props->HasKey(keys::kWidthKey)) { 734 if (params->update_info.width) {
777 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 735 bounds.set_width(*params->update_info.width);
778 keys::kWidthKey,
779 &bounds_val));
780 bounds.set_width(bounds_val);
781 set_bounds = true; 736 set_bounds = true;
782 } 737 }
783 738
784 if (update_props->HasKey(keys::kHeightKey)) { 739 if (params->update_info.height) {
785 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 740 bounds.set_height(*params->update_info.height);
786 keys::kHeightKey,
787 &bounds_val));
788 bounds.set_height(bounds_val);
789 set_bounds = true; 741 set_bounds = true;
790 } 742 }
791 743
792 if (set_bounds) { 744 if (set_bounds) {
793 if (show_state == ui::SHOW_STATE_MINIMIZED || 745 if (show_state == ui::SHOW_STATE_MINIMIZED ||
794 show_state == ui::SHOW_STATE_MAXIMIZED || 746 show_state == ui::SHOW_STATE_MAXIMIZED ||
795 show_state == ui::SHOW_STATE_FULLSCREEN) { 747 show_state == ui::SHOW_STATE_FULLSCREEN) {
796 error_ = keys::kInvalidWindowStateError; 748 error_ = keys::kInvalidWindowStateError;
797 return false; 749 return false;
798 } 750 }
799 // TODO(varkha): Updating bounds during a drag can cause problems and a more 751 // TODO(varkha): Updating bounds during a drag can cause problems and a more
800 // general solution is needed. See http://crbug.com/251813 . 752 // general solution is needed. See http://crbug.com/251813 .
801 controller->window()->SetBounds(bounds); 753 controller->window()->SetBounds(bounds);
802 } 754 }
803 755
804 bool active_val = false; 756 if (params->update_info.focused) {
805 if (update_props->HasKey(keys::kFocusedKey)) { 757 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) { 758 if (show_state == ui::SHOW_STATE_MINIMIZED) {
810 error_ = keys::kInvalidWindowStateError; 759 error_ = keys::kInvalidWindowStateError;
811 return false; 760 return false;
812 } 761 }
813 controller->window()->Activate(); 762 controller->window()->Activate();
814 } else { 763 } else {
815 if (show_state == ui::SHOW_STATE_MAXIMIZED || 764 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
816 show_state == ui::SHOW_STATE_FULLSCREEN) { 765 show_state == ui::SHOW_STATE_FULLSCREEN) {
817 error_ = keys::kInvalidWindowStateError; 766 error_ = keys::kInvalidWindowStateError;
818 return false; 767 return false;
819 } 768 }
820 controller->window()->Deactivate(); 769 controller->window()->Deactivate();
821 } 770 }
822 } 771 }
823 772
824 bool draw_attention = false; 773 if (params->update_info.draw_attention)
825 if (update_props->HasKey(keys::kDrawAttentionKey)) { 774 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 775
831 SetResult(controller->CreateWindowValue()); 776 SetResult(controller->CreateWindowValue());
832 777
833 return true; 778 return true;
834 } 779 }
835 780
836 bool WindowsRemoveFunction::RunImpl() { 781 bool WindowsRemoveFunction::RunImpl() {
837 int window_id = -1; 782 scoped_ptr<windows::Remove::Params> params(
838 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 783 windows::Remove::Params::Create(*args_));
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

Powered by Google App Engine
This is Rietveld 408576698