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

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
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) {
not at google - send to devlin 2013/08/22 15:12:11 check to see how many constants like kIncognitoKey
pals 2013/08/23 11:29:40 Done.
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) {
411 if (args->HasKey(keys::kUrlKey)) { 409 if (create_data->url) {
not at google - send to devlin 2013/08/22 15:12:11 save a level of indentation here by making the con
pals 2013/08/23 11:29:40 Done.
412 Value* url_value;
413 std::vector<std::string> url_strings; 410 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. 411 // First, get all the URLs the client wants to open.
417 if (url_value->IsType(Value::TYPE_STRING)) { 412 if (create_data->url->as_string) {
418 std::string url_string; 413 url_strings.push_back(*create_data->url->as_string);
419 url_value->GetAsString(&url_string); 414 } else if (create_data->url->as_strings) {
420 url_strings.push_back(url_string); 415 url_strings = *create_data->url->as_strings;
not at google - send to devlin 2013/08/22 15:12:11 since as_strings isn't used again we can .swap() h
pals 2013/08/23 11:29:40 Done.
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 } 416 }
not at google - send to devlin 2013/08/22 15:12:11 no need for the {}s here, just if (...) url_str
pals 2013/08/23 11:29:40 Done.
430
431 // Second, resolve, validate and convert them to GURLs. 417 // Second, resolve, validate and convert them to GURLs.
432 for (std::vector<std::string>::iterator i = url_strings.begin(); 418 for (std::vector<std::string>::iterator i = url_strings.begin();
433 i != url_strings.end(); ++i) { 419 i != url_strings.end(); ++i) {
434 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( 420 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
435 *i, GetExtension()); 421 *i, GetExtension());
436 if (!url.is_valid()) { 422 if (!url.is_valid()) {
437 error_ = ErrorUtils::FormatErrorMessage( 423 error_ = ErrorUtils::FormatErrorMessage(
438 keys::kInvalidUrlError, *i); 424 keys::kInvalidUrlError, *i);
439 return false; 425 return false;
440 } 426 }
441 // Don't let the extension crash the browser or renderers. 427 // Don't let the extension crash the browser or renderers.
442 if (ExtensionTabUtil::IsCrashURL(url)) { 428 if (ExtensionTabUtil::IsCrashURL(url)) {
443 error_ = keys::kNoCrashBrowserError; 429 error_ = keys::kNoCrashBrowserError;
444 return false; 430 return false;
445 } 431 }
446 urls.push_back(url); 432 urls.push_back(url);
447 } 433 }
448 } 434 }
449 } 435 }
450 436
451 // Look for optional tab id. 437 // Look for optional tab id.
452 if (args) { 438 if (create_data) {
not at google - send to devlin 2013/08/22 15:12:11 if (create_data && create_data->tab_id) { ... }
pals 2013/08/23 11:29:40 Done.
453 int tab_id = -1; 439 if (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 440 // Find the tab. |source_tab_strip| and |tab_index| will later be used to
458 // move the tab into the created window. 441 // move the tab into the created window.
459 if (!GetTabById(tab_id, profile(), include_incognito(), 442 if (!GetTabById(*create_data->tab_id, profile(), include_incognito(),
460 NULL, &source_tab_strip, 443 NULL, &source_tab_strip, NULL, &tab_index, &error_))
461 NULL, &tab_index, &error_))
462 return false; 444 return false;
463 } 445 }
464 } 446 }
465 447
466 Profile* window_profile = profile(); 448 Profile* window_profile = profile();
467 Browser::Type window_type = Browser::TYPE_TABBED; 449 Browser::Type window_type = Browser::TYPE_TABBED;
468 bool create_panel = false; 450 bool create_panel = false;
469 451
470 // panel_create_mode only applies if create_panel = true 452 // panel_create_mode only applies if create_panel = true
471 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; 453 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED;
472 454
473 gfx::Rect window_bounds; 455 gfx::Rect window_bounds;
474 bool focused = true; 456 bool focused = true;
475 bool saw_focus_key = false; 457 bool saw_focus_key = false;
476 std::string extension_id; 458 std::string extension_id;
477 459
478 // Decide whether we are opening a normal window or an incognito window. 460 // Decide whether we are opening a normal window or an incognito window.
479 bool is_error = true; 461 bool is_error = true;
480 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, 462 bool open_incognito_window = ShouldOpenIncognitoWindow(create_data, &urls,
481 &is_error); 463 &is_error);
482 if (is_error) { 464 if (is_error) {
483 // error_ member variable is set inside of ShouldOpenIncognitoWindow. 465 // error_ member variable is set inside of ShouldOpenIncognitoWindow.
484 return false; 466 return false;
485 } 467 }
486 if (open_incognito_window) { 468 if (open_incognito_window) {
487 window_profile = window_profile->GetOffTheRecordProfile(); 469 window_profile = window_profile->GetOffTheRecordProfile();
488 } 470 }
489 471
490 if (args) { 472 if (create_data) {
491 // Figure out window type before figuring out bounds so that default 473 // Figure out window type before figuring out bounds so that default
492 // bounds can be set according to the window type. 474 // bounds can be set according to the window type.
493 std::string type_str; 475 bool use_panels = false;
494 if (args->HasKey(keys::kWindowTypeKey)) { 476 switch (create_data->type) {
495 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey, 477 case windows::Create::Params::CreateData::TYPE_POPUP:
496 &type_str));
497 if (type_str == keys::kWindowTypeValuePopup) {
498 window_type = Browser::TYPE_POPUP; 478 window_type = Browser::TYPE_POPUP;
499 extension_id = GetExtension()->id(); 479 extension_id = GetExtension()->id();
500 } else if (type_str == keys::kWindowTypeValuePanel || 480 break;
501 type_str == keys::kWindowTypeValueDetachedPanel) { 481 case windows::Create::Params::CreateData::TYPE_PANEL:
482 case windows::Create::Params::CreateData::TYPE_DETACHED_PANEL:
502 extension_id = GetExtension()->id(); 483 extension_id = GetExtension()->id();
503 bool use_panels = false;
504 #if !defined(OS_ANDROID) 484 #if !defined(OS_ANDROID)
505 use_panels = PanelManager::ShouldUsePanels(extension_id); 485 use_panels = PanelManager::ShouldUsePanels(extension_id);
506 #endif 486 #endif
507 if (use_panels) { 487 if (use_panels) {
508 create_panel = true; 488 create_panel = true;
509 #if !defined(OS_CHROMEOS) 489 #if !defined(OS_CHROMEOS)
510 // Non-ChromeOS has both docked and detached panel types. 490 // Non-ChromeOS has both docked and detached panel types.
511 if (type_str == keys::kWindowTypeValueDetachedPanel) 491 if (create_data->type ==
492 windows::Create::Params::CreateData::TYPE_DETACHED_PANEL)
512 panel_create_mode = PanelManager::CREATE_AS_DETACHED; 493 panel_create_mode = PanelManager::CREATE_AS_DETACHED;
not at google - send to devlin 2013/08/22 15:12:11 has a 2-line condition so needs {} now.
pals 2013/08/23 11:29:40 Done.
513 #endif 494 #endif
514 } else { 495 } else {
515 window_type = Browser::TYPE_POPUP; 496 window_type = Browser::TYPE_POPUP;
516 } 497 }
517 } else if (type_str != keys::kWindowTypeValueNormal) { 498 break;
499 case windows::Create::Params::CreateData::TYPE_NONE:
500 case windows::Create::Params::CreateData::TYPE_NORMAL:
501 break;
502 default:
518 error_ = keys::kInvalidWindowTypeError; 503 error_ = keys::kInvalidWindowTypeError;
519 return false; 504 return false;
520 }
521 } 505 }
522 506
523 // Initialize default window bounds according to window type. 507 // Initialize default window bounds according to window type.
524 if (window_type == Browser::TYPE_TABBED || 508 if (window_type == Browser::TYPE_TABBED ||
525 window_type == Browser::TYPE_POPUP || 509 window_type == Browser::TYPE_POPUP ||
526 create_panel) { 510 create_panel) {
527 // Try to position the new browser relative to its originating 511 // Try to position the new browser relative to its originating
528 // browser window. The call offsets the bounds by kWindowTilePixels 512 // browser window. The call offsets the bounds by kWindowTilePixels
529 // (defined in WindowSizer to be 10). 513 // (defined in WindowSizer to be 10).
530 // 514 //
531 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here. 515 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here.
532 // GetBrowserWindowBounds will default to saved "default" values for 516 // GetBrowserWindowBounds will default to saved "default" values for
533 // the app. 517 // the app.
534 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; 518 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
535 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(), 519 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(),
536 gfx::Rect(), 520 gfx::Rect(),
537 GetCurrentBrowser(), 521 GetCurrentBrowser(),
538 &window_bounds, 522 &window_bounds,
539 &show_state); 523 &show_state);
540 } 524 }
541 525
542 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) { 526 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) {
543 window_bounds.set_origin( 527 window_bounds.set_origin(
544 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin()); 528 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin());
545 } 529 }
546 530
547 // Any part of the bounds can optionally be set by the caller. 531 // Any part of the bounds can optionally be set by the caller.
548 int bounds_val = -1; 532 if (create_data->left)
549 if (args->HasKey(keys::kLeftKey)) { 533 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 534
555 if (args->HasKey(keys::kTopKey)) { 535 if (create_data->top)
556 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, 536 window_bounds.set_y(*create_data->top);
557 &bounds_val));
558 window_bounds.set_y(bounds_val);
559 }
560 537
561 if (args->HasKey(keys::kWidthKey)) { 538 if (create_data->width)
562 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kWidthKey, 539 window_bounds.set_width(*create_data->width);
563 &bounds_val));
564 window_bounds.set_width(bounds_val);
565 }
566 540
567 if (args->HasKey(keys::kHeightKey)) { 541 if (create_data->height)
568 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 542 window_bounds.set_height(*create_data->height);
569 &bounds_val));
570 window_bounds.set_height(bounds_val);
571 }
572 543
573 if (args->HasKey(keys::kFocusedKey)) { 544 if (create_data->focused)
574 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 545 saw_focus_key = *create_data->focused;
575 &focused));
576 saw_focus_key = true;
577 }
578 } 546 }
579 547
580 if (create_panel) { 548 if (create_panel) {
581 if (urls.empty()) 549 if (urls.empty())
582 urls.push_back(GURL(chrome::kChromeUINewTabURL)); 550 urls.push_back(GURL(chrome::kChromeUINewTabURL));
583 551
584 #if defined(OS_CHROMEOS) 552 #if defined(OS_CHROMEOS)
585 if (PanelManager::ShouldUsePanels(extension_id)) { 553 if (PanelManager::ShouldUsePanels(extension_id)) {
586 ShellWindow::CreateParams create_params; 554 ShellWindow::CreateParams create_params;
587 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL; 555 create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } else { 649 } else {
682 SetResult( 650 SetResult(
683 new_window->extension_window_controller()->CreateWindowValueWithTabs( 651 new_window->extension_window_controller()->CreateWindowValueWithTabs(
684 GetExtension())); 652 GetExtension()));
685 } 653 }
686 654
687 return true; 655 return true;
688 } 656 }
689 657
690 bool WindowsUpdateFunction::RunImpl() { 658 bool WindowsUpdateFunction::RunImpl() {
691 int window_id = extension_misc::kUnknownWindowId; 659 scoped_ptr<windows::Update::Params> params(
692 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 660 windows::Update::Params::Create(*args_));
693 base::DictionaryValue* update_props; 661 EXTENSION_FUNCTION_VALIDATE(params);
694 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
695 662
696 WindowController* controller; 663 WindowController* controller;
697 if (!GetWindowFromWindowID(this, window_id, &controller)) 664 if (!GetWindowFromWindowID(this, params->window_id, &controller))
698 return false; 665 return false;
699 666
700 #if defined(OS_WIN) 667 #if defined(OS_WIN)
701 // Silently ignore changes on the window for metro mode. 668 // Silently ignore changes on the window for metro mode.
702 if (win8::IsSingleWindowMetroMode()) { 669 if (win8::IsSingleWindowMetroMode()) {
703 SetResult(controller->CreateWindowValue()); 670 SetResult(controller->CreateWindowValue());
704 return true; 671 return true;
705 } 672 }
706 #endif 673 #endif
707 674
708 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 675 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
709 std::string state_str; 676 switch (params->update_info.state) {
710 if (update_props->HasKey(keys::kShowStateKey)) { 677 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; 678 show_state = ui::SHOW_STATE_NORMAL;
715 } else if (state_str == keys::kShowStateValueMinimized) { 679 break;
680 case windows::Update::Params::UpdateInfo::STATE_MINIMIZED:
716 show_state = ui::SHOW_STATE_MINIMIZED; 681 show_state = ui::SHOW_STATE_MINIMIZED;
717 } else if (state_str == keys::kShowStateValueMaximized) { 682 break;
683 case windows::Update::Params::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 break;
686 case windows::Update::Params::UpdateInfo::STATE_FULLSCREEN:
720 show_state = ui::SHOW_STATE_FULLSCREEN; 687 show_state = ui::SHOW_STATE_FULLSCREEN;
721 } else { 688 break;
689 case windows::Update::Params::UpdateInfo::STATE_NONE:
690 break;
691 default:
722 error_ = keys::kInvalidWindowStateError; 692 error_ = keys::kInvalidWindowStateError;
723 return false; 693 return false;
724 }
725 } 694 }
726 695
727 if (show_state != ui::SHOW_STATE_FULLSCREEN && 696 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
728 show_state != ui::SHOW_STATE_DEFAULT) 697 show_state != ui::SHOW_STATE_DEFAULT)
729 controller->SetFullscreenMode(false, GetExtension()->url()); 698 controller->SetFullscreenMode(false, GetExtension()->url());
730 699
731 switch (show_state) { 700 switch (show_state) {
732 case ui::SHOW_STATE_MINIMIZED: 701 case ui::SHOW_STATE_MINIMIZED:
733 controller->window()->Minimize(); 702 controller->window()->Minimize();
734 break; 703 break;
(...skipping 14 matching lines...) Expand all
749 } 718 }
750 719
751 gfx::Rect bounds; 720 gfx::Rect bounds;
752 if (controller->window()->IsMinimized()) 721 if (controller->window()->IsMinimized())
753 bounds = controller->window()->GetRestoredBounds(); 722 bounds = controller->window()->GetRestoredBounds();
754 else 723 else
755 bounds = controller->window()->GetBounds(); 724 bounds = controller->window()->GetBounds();
756 bool set_bounds = false; 725 bool set_bounds = false;
757 726
758 // Any part of the bounds can optionally be set by the caller. 727 // Any part of the bounds can optionally be set by the caller.
759 int bounds_val; 728 if (params->update_info.left) {
760 if (update_props->HasKey(keys::kLeftKey)) { 729 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; 730 set_bounds = true;
766 } 731 }
767 732
768 if (update_props->HasKey(keys::kTopKey)) { 733 if (params->update_info.top) {
769 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 734 bounds.set_y(*params->update_info.top);
770 keys::kTopKey,
771 &bounds_val));
772 bounds.set_y(bounds_val);
773 set_bounds = true; 735 set_bounds = true;
774 } 736 }
775 737
776 if (update_props->HasKey(keys::kWidthKey)) { 738 if (params->update_info.width) {
777 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 739 bounds.set_width(*params->update_info.width);
778 keys::kWidthKey,
779 &bounds_val));
780 bounds.set_width(bounds_val);
781 set_bounds = true; 740 set_bounds = true;
782 } 741 }
783 742
784 if (update_props->HasKey(keys::kHeightKey)) { 743 if (params->update_info.height) {
785 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 744 bounds.set_height(*params->update_info.height);
786 keys::kHeightKey,
787 &bounds_val));
788 bounds.set_height(bounds_val);
789 set_bounds = true; 745 set_bounds = true;
790 } 746 }
791 747
792 if (set_bounds) { 748 if (set_bounds) {
793 if (show_state == ui::SHOW_STATE_MINIMIZED || 749 if (show_state == ui::SHOW_STATE_MINIMIZED ||
794 show_state == ui::SHOW_STATE_MAXIMIZED || 750 show_state == ui::SHOW_STATE_MAXIMIZED ||
795 show_state == ui::SHOW_STATE_FULLSCREEN) { 751 show_state == ui::SHOW_STATE_FULLSCREEN) {
796 error_ = keys::kInvalidWindowStateError; 752 error_ = keys::kInvalidWindowStateError;
797 return false; 753 return false;
798 } 754 }
799 // TODO(varkha): Updating bounds during a drag can cause problems and a more 755 // TODO(varkha): Updating bounds during a drag can cause problems and a more
800 // general solution is needed. See http://crbug.com/251813 . 756 // general solution is needed. See http://crbug.com/251813 .
801 controller->window()->SetBounds(bounds); 757 controller->window()->SetBounds(bounds);
802 } 758 }
803 759
804 bool active_val = false; 760 if (params->update_info.focused) {
805 if (update_props->HasKey(keys::kFocusedKey)) { 761 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) { 762 if (show_state == ui::SHOW_STATE_MINIMIZED) {
810 error_ = keys::kInvalidWindowStateError; 763 error_ = keys::kInvalidWindowStateError;
811 return false; 764 return false;
812 } 765 }
813 controller->window()->Activate(); 766 controller->window()->Activate();
814 } else { 767 } else {
815 if (show_state == ui::SHOW_STATE_MAXIMIZED || 768 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
816 show_state == ui::SHOW_STATE_FULLSCREEN) { 769 show_state == ui::SHOW_STATE_FULLSCREEN) {
817 error_ = keys::kInvalidWindowStateError; 770 error_ = keys::kInvalidWindowStateError;
818 return false; 771 return false;
819 } 772 }
820 controller->window()->Deactivate(); 773 controller->window()->Deactivate();
821 } 774 }
822 } 775 }
823 776
824 bool draw_attention = false; 777 if (params->update_info.draw_attention)
825 if (update_props->HasKey(keys::kDrawAttentionKey)) { 778 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 779
831 SetResult(controller->CreateWindowValue()); 780 SetResult(controller->CreateWindowValue());
832 781
833 return true; 782 return true;
834 } 783 }
835 784
836 bool WindowsRemoveFunction::RunImpl() { 785 bool WindowsRemoveFunction::RunImpl() {
837 int window_id = -1; 786 scoped_ptr<windows::Remove::Params> params(
838 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 787 windows::Remove::Params::Create(*args_));
788 EXTENSION_FUNCTION_VALIDATE(params);
839 789
840 WindowController* controller; 790 WindowController* controller;
841 if (!GetWindowFromWindowID(this, window_id, &controller)) 791 if (!GetWindowFromWindowID(this, params->window_id, &controller))
842 return false; 792 return false;
843 793
844 #if defined(OS_WIN) 794 #if defined(OS_WIN)
845 // In Windows 8 metro mode, an existing Browser instance is reused for 795 // 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. 796 // hosting the extension tab. We should not be closing it as we don't own it.
847 if (win8::IsSingleWindowMetroMode()) 797 if (win8::IsSingleWindowMetroMode())
848 return false; 798 return false;
849 #endif 799 #endif
850 800
851 WindowController::Reason reason; 801 WindowController::Reason reason;
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 execute_tab_id_ = tab_id; 2015 execute_tab_id_ = tab_id;
2066 details_ = details.Pass(); 2016 details_ = details.Pass();
2067 return true; 2017 return true;
2068 } 2018 }
2069 2019
2070 bool TabsInsertCSSFunction::ShouldInsertCSS() const { 2020 bool TabsInsertCSSFunction::ShouldInsertCSS() const {
2071 return true; 2021 return true;
2072 } 2022 }
2073 2023
2074 } // namespace extensions 2024 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698