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

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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 using content::BrowserThread; 103 using content::BrowserThread;
104 using content::NavigationController; 104 using content::NavigationController;
105 using content::NavigationEntry; 105 using content::NavigationEntry;
106 using content::OpenURLParams; 106 using content::OpenURLParams;
107 using content::Referrer; 107 using content::Referrer;
108 using content::RenderViewHost; 108 using content::RenderViewHost;
109 using content::WebContents; 109 using content::WebContents;
110 110
111 namespace extensions { 111 namespace extensions {
112 112
113 namespace Get = api::windows::Get; 113 namespace windows = api::windows;
114 namespace GetAll = api::windows::GetAll;
115 namespace GetCurrent = api::windows::GetCurrent;
116 namespace GetLastFocused = api::windows::GetLastFocused;
117 namespace errors = extension_manifest_errors; 114 namespace errors = extension_manifest_errors;
118 namespace keys = tabs_constants; 115 namespace keys = tabs_constants;
119 namespace tabs = api::tabs; 116 namespace tabs = api::tabs;
120 typedef tabs::CaptureVisibleTab::Params::Options FormatEnum; 117 typedef tabs::CaptureVisibleTab::Params::Options FormatEnum;
121 118
122 using api::tabs::InjectDetails; 119 using api::tabs::InjectDetails;
123 120
124 const int TabsCaptureVisibleTabFunction::kDefaultQuality = 90; 121 const int TabsCaptureVisibleTabFunction::kDefaultQuality = 90;
125 122
126 namespace { 123 namespace {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if (!new_window) 217 if (!new_window)
221 new_window = new Browser(params); 218 new_window = new Browser(params);
222 return new_window; 219 return new_window;
223 } 220 }
224 221
225 } // namespace 222 } // namespace
226 223
227 // Windows --------------------------------------------------------------------- 224 // Windows ---------------------------------------------------------------------
228 225
229 bool WindowsGetFunction::RunImpl() { 226 bool WindowsGetFunction::RunImpl() {
230 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); 227 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_));
231 EXTENSION_FUNCTION_VALIDATE(params.get()); 228 EXTENSION_FUNCTION_VALIDATE(params.get());
232 229
233 bool populate_tabs = false; 230 bool populate_tabs = false;
234 if (params->get_info.get() && params->get_info->populate.get()) 231 if (params->get_info.get() && params->get_info->populate.get())
235 populate_tabs = *params->get_info->populate; 232 populate_tabs = *params->get_info->populate;
236 233
237 WindowController* controller; 234 WindowController* controller;
238 if (!windows_util::GetWindowFromWindowID(this, 235 if (!windows_util::GetWindowFromWindowID(this,
239 params->window_id, 236 params->window_id,
240 &controller)) { 237 &controller)) {
241 return false; 238 return false;
242 } 239 }
243 240
244 if (populate_tabs) 241 if (populate_tabs)
245 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); 242 SetResult(controller->CreateWindowValueWithTabs(GetExtension()));
246 else 243 else
247 SetResult(controller->CreateWindowValue()); 244 SetResult(controller->CreateWindowValue());
248 return true; 245 return true;
249 } 246 }
250 247
251 bool WindowsGetCurrentFunction::RunImpl() { 248 bool WindowsGetCurrentFunction::RunImpl() {
252 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); 249 scoped_ptr<windows::GetCurrent::Params> params(
250 windows::GetCurrent::Params::Create(*args_));
253 EXTENSION_FUNCTION_VALIDATE(params.get()); 251 EXTENSION_FUNCTION_VALIDATE(params.get());
254 252
255 bool populate_tabs = false; 253 bool populate_tabs = false;
256 if (params->get_info.get() && params->get_info->populate.get()) 254 if (params->get_info.get() && params->get_info->populate.get())
257 populate_tabs = *params->get_info->populate; 255 populate_tabs = *params->get_info->populate;
258 256
259 WindowController* controller; 257 WindowController* controller;
260 if (!windows_util::GetWindowFromWindowID(this, 258 if (!windows_util::GetWindowFromWindowID(this,
261 extension_misc::kCurrentWindowId, 259 extension_misc::kCurrentWindowId,
262 &controller)) { 260 &controller)) {
263 return false; 261 return false;
264 } 262 }
265 if (populate_tabs) 263 if (populate_tabs)
266 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); 264 SetResult(controller->CreateWindowValueWithTabs(GetExtension()));
267 else 265 else
268 SetResult(controller->CreateWindowValue()); 266 SetResult(controller->CreateWindowValue());
269 return true; 267 return true;
270 } 268 }
271 269
272 bool WindowsGetLastFocusedFunction::RunImpl() { 270 bool WindowsGetLastFocusedFunction::RunImpl() {
273 scoped_ptr<GetLastFocused::Params> params( 271 scoped_ptr<windows::GetLastFocused::Params> params(
274 GetLastFocused::Params::Create(*args_)); 272 windows::GetLastFocused::Params::Create(*args_));
275 EXTENSION_FUNCTION_VALIDATE(params.get()); 273 EXTENSION_FUNCTION_VALIDATE(params.get());
276 274
277 bool populate_tabs = false; 275 bool populate_tabs = false;
278 if (params->get_info.get() && params->get_info->populate.get()) 276 if (params->get_info.get() && params->get_info->populate.get())
279 populate_tabs = *params->get_info->populate; 277 populate_tabs = *params->get_info->populate;
280 278
281 // Note: currently this returns the last active browser. If we decide to 279 // Note: currently this returns the last active browser. If we decide to
282 // include other window types (e.g. panels), we will need to add logic to 280 // include other window types (e.g. panels), we will need to add logic to
283 // WindowControllerList that mirrors the active behavior of BrowserList. 281 // WindowControllerList that mirrors the active behavior of BrowserList.
284 Browser* browser = chrome::FindAnyBrowser( 282 Browser* browser = chrome::FindAnyBrowser(
285 profile(), include_incognito(), chrome::GetActiveDesktop()); 283 profile(), include_incognito(), chrome::GetActiveDesktop());
286 if (!browser || !browser->window()) { 284 if (!browser || !browser->window()) {
287 error_ = keys::kNoLastFocusedWindowError; 285 error_ = keys::kNoLastFocusedWindowError;
288 return false; 286 return false;
289 } 287 }
290 WindowController* controller = 288 WindowController* controller =
291 browser->extension_window_controller(); 289 browser->extension_window_controller();
292 if (populate_tabs) 290 if (populate_tabs)
293 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); 291 SetResult(controller->CreateWindowValueWithTabs(GetExtension()));
294 else 292 else
295 SetResult(controller->CreateWindowValue()); 293 SetResult(controller->CreateWindowValue());
296 return true; 294 return true;
297 } 295 }
298 296
299 bool WindowsGetAllFunction::RunImpl() { 297 bool WindowsGetAllFunction::RunImpl() {
300 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); 298 scoped_ptr<windows::GetAll::Params> params(
299 windows::GetAll::Params::Create(*args_));
301 EXTENSION_FUNCTION_VALIDATE(params.get()); 300 EXTENSION_FUNCTION_VALIDATE(params.get());
302 301
303 bool populate_tabs = false; 302 bool populate_tabs = false;
304 if (params->get_info.get() && params->get_info->populate.get()) 303 if (params->get_info.get() && params->get_info->populate.get())
305 populate_tabs = *params->get_info->populate; 304 populate_tabs = *params->get_info->populate;
306 305
307 base::ListValue* window_list = new base::ListValue(); 306 base::ListValue* window_list = new base::ListValue();
308 const WindowControllerList::ControllerList& windows = 307 const WindowControllerList::ControllerList& windows =
309 WindowControllerList::GetInstance()->windows(); 308 WindowControllerList::GetInstance()->windows();
310 for (WindowControllerList::ControllerList::const_iterator iter = 309 for (WindowControllerList::ControllerList::const_iterator iter =
311 windows.begin(); 310 windows.begin();
312 iter != windows.end(); ++iter) { 311 iter != windows.end(); ++iter) {
313 if (!this->CanOperateOnWindow(*iter)) 312 if (!this->CanOperateOnWindow(*iter))
314 continue; 313 continue;
315 if (populate_tabs) 314 if (populate_tabs)
316 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension())); 315 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension()));
317 else 316 else
318 window_list->Append((*iter)->CreateWindowValue()); 317 window_list->Append((*iter)->CreateWindowValue());
319 } 318 }
320 SetResult(window_list); 319 SetResult(window_list);
321 return true; 320 return true;
322 } 321 }
323 322
324 bool WindowsCreateFunction::ShouldOpenIncognitoWindow( 323 bool WindowsCreateFunction::ShouldOpenIncognitoWindow(
325 const base::DictionaryValue* args, 324 const windows::Create::Params::CreateData* create_data,
326 std::vector<GURL>* urls, 325 std::vector<GURL>* urls, bool* is_error) {
327 bool* is_error) {
328 *is_error = false; 326 *is_error = false;
329 const IncognitoModePrefs::Availability incognito_availability = 327 const IncognitoModePrefs::Availability incognito_availability =
330 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); 328 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
331 bool incognito = false; 329 bool incognito = false;
332 if (args && args->HasKey(keys::kIncognitoKey)) { 330 if (create_data && create_data->incognito) {
333 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, 331 incognito = *create_data->incognito;
334 &incognito));
335 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) { 332 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) {
336 error_ = keys::kIncognitoModeIsDisabled; 333 error_ = keys::kIncognitoModeIsDisabled;
337 *is_error = true; 334 *is_error = true;
338 return false; 335 return false;
339 } 336 }
340 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) { 337 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) {
341 error_ = keys::kIncognitoModeIsForced; 338 error_ = keys::kIncognitoModeIsForced;
342 *is_error = true; 339 *is_error = true;
343 return false; 340 return false;
344 } 341 }
(...skipping 20 matching lines...) Expand all
365 error_ = ErrorUtils::FormatErrorMessage( 362 error_ = ErrorUtils::FormatErrorMessage(
366 keys::kURLsNotAllowedInIncognitoError, first_url_erased); 363 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
367 *is_error = true; 364 *is_error = true;
368 return false; 365 return false;
369 } 366 }
370 } 367 }
371 return incognito; 368 return incognito;
372 } 369 }
373 370
374 bool WindowsCreateFunction::RunImpl() { 371 bool WindowsCreateFunction::RunImpl() {
375 base::DictionaryValue* args = NULL; 372 scoped_ptr<windows::Create::Params> params(
373 windows::Create::Params::Create(*args_));
374 EXTENSION_FUNCTION_VALIDATE(params);
376 std::vector<GURL> urls; 375 std::vector<GURL> urls;
377 TabStripModel* source_tab_strip = NULL; 376 TabStripModel* source_tab_strip = NULL;
378 int tab_index = -1; 377 int tab_index = -1;
379 378
380 if (HasOptionalArgument(0)) 379 windows::Create::Params::CreateData* create_data = params->create_data.get();
381 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
382 380
383 // Look for optional url. 381 // Look for optional url.
384 if (args) { 382 if (create_data && create_data->url) {
385 if (args->HasKey(keys::kUrlKey)) { 383 std::vector<std::string> url_strings;
386 Value* url_value; 384 // First, get all the URLs the client wants to open.
387 std::vector<std::string> url_strings; 385 if (create_data->url->as_string)
388 args->Get(keys::kUrlKey, &url_value); 386 url_strings.push_back(*create_data->url->as_string);
387 else if (create_data->url->as_strings)
388 url_strings.swap(*create_data->url->as_strings);
389 389
390 // First, get all the URLs the client wants to open. 390 // Second, resolve, validate and convert them to GURLs.
391 if (url_value->IsType(Value::TYPE_STRING)) { 391 for (std::vector<std::string>::iterator i = url_strings.begin();
392 std::string url_string; 392 i != url_strings.end(); ++i) {
393 url_value->GetAsString(&url_string); 393 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
394 url_strings.push_back(url_string); 394 *i, GetExtension());
395 } else if (url_value->IsType(Value::TYPE_LIST)) { 395 if (!url.is_valid()) {
396 const base::ListValue* url_list = 396 error_ = ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, *i);
397 static_cast<const base::ListValue*>(url_value); 397 return false;
398 for (size_t i = 0; i < url_list->GetSize(); ++i) {
399 std::string url_string;
400 EXTENSION_FUNCTION_VALIDATE(url_list->GetString(i, &url_string));
401 url_strings.push_back(url_string);
402 }
403 } 398 }
404 399 // Don't let the extension crash the browser or renderers.
405 // Second, resolve, validate and convert them to GURLs. 400 if (ExtensionTabUtil::IsCrashURL(url)) {
406 for (std::vector<std::string>::iterator i = url_strings.begin(); 401 error_ = keys::kNoCrashBrowserError;
407 i != url_strings.end(); ++i) { 402 return false;
408 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
409 *i, GetExtension());
410 if (!url.is_valid()) {
411 error_ = ErrorUtils::FormatErrorMessage(
412 keys::kInvalidUrlError, *i);
413 return false;
414 }
415 // Don't let the extension crash the browser or renderers.
416 if (ExtensionTabUtil::IsCrashURL(url)) {
417 error_ = keys::kNoCrashBrowserError;
418 return false;
419 }
420 urls.push_back(url);
421 } 403 }
404 urls.push_back(url);
422 } 405 }
423 } 406 }
424 407
425 // Look for optional tab id. 408 // Look for optional tab id.
426 if (args) { 409 if (create_data && create_data->tab_id) {
427 int tab_id = -1; 410 // Find the tab. |source_tab_strip| and |tab_index| will later be used to
428 if (args->HasKey(keys::kTabIdKey)) { 411 // move the tab into the created window.
429 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id)); 412 if (!GetTabById(*create_data->tab_id, profile(), include_incognito(), NULL,
430 413 &source_tab_strip, NULL, &tab_index, &error_))
431 // Find the tab. |source_tab_strip| and |tab_index| will later be used to 414 return false;
432 // move the tab into the created window.
433 if (!GetTabById(tab_id, profile(), include_incognito(),
434 NULL, &source_tab_strip,
435 NULL, &tab_index, &error_))
436 return false;
437 }
438 } 415 }
439 416
440 Profile* window_profile = profile(); 417 Profile* window_profile = profile();
441 Browser::Type window_type = Browser::TYPE_TABBED; 418 Browser::Type window_type = Browser::TYPE_TABBED;
442 bool create_panel = false; 419 bool create_panel = false;
443 420
444 // panel_create_mode only applies if create_panel = true 421 // panel_create_mode only applies if create_panel = true
445 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; 422 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED;
446 423
447 gfx::Rect window_bounds; 424 gfx::Rect window_bounds;
448 bool focused = true; 425 bool focused = true;
449 bool saw_focus_key = false; 426 bool saw_focus_key = false;
450 std::string extension_id; 427 std::string extension_id;
451 428
452 // Decide whether we are opening a normal window or an incognito window. 429 // Decide whether we are opening a normal window or an incognito window.
453 bool is_error = true; 430 bool is_error = true;
454 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, 431 bool open_incognito_window = ShouldOpenIncognitoWindow(create_data, &urls,
455 &is_error); 432 &is_error);
456 if (is_error) { 433 if (is_error) {
457 // error_ member variable is set inside of ShouldOpenIncognitoWindow. 434 // error_ member variable is set inside of ShouldOpenIncognitoWindow.
458 return false; 435 return false;
459 } 436 }
460 if (open_incognito_window) { 437 if (open_incognito_window) {
461 window_profile = window_profile->GetOffTheRecordProfile(); 438 window_profile = window_profile->GetOffTheRecordProfile();
462 } 439 }
463 440
464 if (args) { 441 if (create_data) {
465 // Figure out window type before figuring out bounds so that default 442 // Figure out window type before figuring out bounds so that default
466 // bounds can be set according to the window type. 443 // bounds can be set according to the window type.
467 std::string type_str; 444 switch (create_data->type) {
468 if (args->HasKey(keys::kWindowTypeKey)) { 445 case windows::Create::Params::CreateData::TYPE_POPUP:
469 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey,
470 &type_str));
471 if (type_str == keys::kWindowTypeValuePopup) {
472 window_type = Browser::TYPE_POPUP; 446 window_type = Browser::TYPE_POPUP;
473 extension_id = GetExtension()->id(); 447 extension_id = GetExtension()->id();
474 } else if (type_str == keys::kWindowTypeValuePanel || 448 break;
475 type_str == keys::kWindowTypeValueDetachedPanel) { 449 case windows::Create::Params::CreateData::TYPE_PANEL:
450 case windows::Create::Params::CreateData::TYPE_DETACHED_PANEL: {
476 extension_id = GetExtension()->id(); 451 extension_id = GetExtension()->id();
477 bool use_panels = false; 452 bool use_panels = false;
478 #if !defined(OS_ANDROID) 453 #if !defined(OS_ANDROID)
479 use_panels = PanelManager::ShouldUsePanels(extension_id); 454 use_panels = PanelManager::ShouldUsePanels(extension_id);
480 #endif 455 #endif
481 if (use_panels) { 456 if (use_panels) {
482 create_panel = true; 457 create_panel = true;
483 #if !defined(OS_CHROMEOS) 458 #if !defined(OS_CHROMEOS)
484 // Non-ChromeOS has both docked and detached panel types. 459 // Non-ChromeOS has both docked and detached panel types.
485 if (type_str == keys::kWindowTypeValueDetachedPanel) 460 if (create_data->type ==
461 windows::Create::Params::CreateData::TYPE_DETACHED_PANEL) {
486 panel_create_mode = PanelManager::CREATE_AS_DETACHED; 462 panel_create_mode = PanelManager::CREATE_AS_DETACHED;
463 }
487 #endif 464 #endif
488 } else { 465 } else {
489 window_type = Browser::TYPE_POPUP; 466 window_type = Browser::TYPE_POPUP;
490 } 467 }
491 } else if (type_str != keys::kWindowTypeValueNormal) { 468 break;
469 }
470 case windows::Create::Params::CreateData::TYPE_NONE:
471 case windows::Create::Params::CreateData::TYPE_NORMAL:
472 break;
473 default:
492 error_ = keys::kInvalidWindowTypeError; 474 error_ = keys::kInvalidWindowTypeError;
493 return false; 475 return false;
494 }
495 } 476 }
496 477
497 // Initialize default window bounds according to window type. 478 // Initialize default window bounds according to window type.
498 if (window_type == Browser::TYPE_TABBED || 479 if (window_type == Browser::TYPE_TABBED ||
499 window_type == Browser::TYPE_POPUP || 480 window_type == Browser::TYPE_POPUP ||
500 create_panel) { 481 create_panel) {
501 // Try to position the new browser relative to its originating 482 // Try to position the new browser relative to its originating
502 // browser window. The call offsets the bounds by kWindowTilePixels 483 // browser window. The call offsets the bounds by kWindowTilePixels
503 // (defined in WindowSizer to be 10). 484 // (defined in WindowSizer to be 10).
504 // 485 //
505 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here. 486 // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here.
506 // GetBrowserWindowBounds will default to saved "default" values for 487 // GetBrowserWindowBounds will default to saved "default" values for
507 // the app. 488 // the app.
508 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; 489 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
509 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(), 490 WindowSizer::GetBrowserWindowBoundsAndShowState(std::string(),
510 gfx::Rect(), 491 gfx::Rect(),
511 GetCurrentBrowser(), 492 GetCurrentBrowser(),
512 &window_bounds, 493 &window_bounds,
513 &show_state); 494 &show_state);
514 } 495 }
515 496
516 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) { 497 if (create_panel && PanelManager::CREATE_AS_DETACHED == panel_create_mode) {
517 window_bounds.set_origin( 498 window_bounds.set_origin(
518 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin()); 499 PanelManager::GetInstance()->GetDefaultDetachedPanelOrigin());
519 } 500 }
520 501
521 // Any part of the bounds can optionally be set by the caller. 502 // Any part of the bounds can optionally be set by the caller.
522 int bounds_val = -1; 503 if (create_data->left)
523 if (args->HasKey(keys::kLeftKey)) { 504 window_bounds.set_x(*create_data->left);
524 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey,
525 &bounds_val));
526 window_bounds.set_x(bounds_val);
527 }
528 505
529 if (args->HasKey(keys::kTopKey)) { 506 if (create_data->top)
530 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, 507 window_bounds.set_y(*create_data->top);
531 &bounds_val));
532 window_bounds.set_y(bounds_val);
533 }
534 508
535 if (args->HasKey(keys::kWidthKey)) { 509 if (create_data->width)
536 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kWidthKey, 510 window_bounds.set_width(*create_data->width);
537 &bounds_val));
538 window_bounds.set_width(bounds_val);
539 }
540 511
541 if (args->HasKey(keys::kHeightKey)) { 512 if (create_data->height)
542 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 513 window_bounds.set_height(*create_data->height);
543 &bounds_val));
544 window_bounds.set_height(bounds_val);
545 }
546 514
547 if (args->HasKey(keys::kFocusedKey)) { 515 if (create_data->focused) {
548 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 516 focused = *create_data->focused;
549 &focused));
550 saw_focus_key = true; 517 saw_focus_key = true;
551 } 518 }
552 } 519 }
553 520
554 if (create_panel) { 521 if (create_panel) {
555 if (urls.empty()) 522 if (urls.empty())
556 urls.push_back(GURL(chrome::kChromeUINewTabURL)); 523 urls.push_back(GURL(chrome::kChromeUINewTabURL));
557 524
558 #if defined(OS_CHROMEOS) 525 #if defined(OS_CHROMEOS)
559 if (PanelManager::ShouldUsePanels(extension_id)) { 526 if (PanelManager::ShouldUsePanels(extension_id)) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } else { 622 } else {
656 SetResult( 623 SetResult(
657 new_window->extension_window_controller()->CreateWindowValueWithTabs( 624 new_window->extension_window_controller()->CreateWindowValueWithTabs(
658 GetExtension())); 625 GetExtension()));
659 } 626 }
660 627
661 return true; 628 return true;
662 } 629 }
663 630
664 bool WindowsUpdateFunction::RunImpl() { 631 bool WindowsUpdateFunction::RunImpl() {
665 int window_id = extension_misc::kUnknownWindowId; 632 scoped_ptr<windows::Update::Params> params(
666 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 633 windows::Update::Params::Create(*args_));
667 base::DictionaryValue* update_props; 634 EXTENSION_FUNCTION_VALIDATE(params);
668 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
669 635
670 WindowController* controller; 636 WindowController* controller;
671 if (!windows_util::GetWindowFromWindowID(this, window_id, &controller)) 637 if (!windows_util::GetWindowFromWindowID(this, params->window_id,
638 &controller))
672 return false; 639 return false;
673 640
674 #if defined(OS_WIN) 641 #if defined(OS_WIN)
675 // Silently ignore changes on the window for metro mode. 642 // Silently ignore changes on the window for metro mode.
676 if (win8::IsSingleWindowMetroMode()) { 643 if (win8::IsSingleWindowMetroMode()) {
677 SetResult(controller->CreateWindowValue()); 644 SetResult(controller->CreateWindowValue());
678 return true; 645 return true;
679 } 646 }
680 #endif 647 #endif
681 648
682 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. 649 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change.
683 std::string state_str; 650 switch (params->update_info.state) {
684 if (update_props->HasKey(keys::kShowStateKey)) { 651 case windows::Update::Params::UpdateInfo::STATE_NORMAL:
685 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(keys::kShowStateKey,
686 &state_str));
687 if (state_str == keys::kShowStateValueNormal) {
688 show_state = ui::SHOW_STATE_NORMAL; 652 show_state = ui::SHOW_STATE_NORMAL;
689 } else if (state_str == keys::kShowStateValueMinimized) { 653 break;
654 case windows::Update::Params::UpdateInfo::STATE_MINIMIZED:
690 show_state = ui::SHOW_STATE_MINIMIZED; 655 show_state = ui::SHOW_STATE_MINIMIZED;
691 } else if (state_str == keys::kShowStateValueMaximized) { 656 break;
657 case windows::Update::Params::UpdateInfo::STATE_MAXIMIZED:
692 show_state = ui::SHOW_STATE_MAXIMIZED; 658 show_state = ui::SHOW_STATE_MAXIMIZED;
693 } else if (state_str == keys::kShowStateValueFullscreen) { 659 break;
660 case windows::Update::Params::UpdateInfo::STATE_FULLSCREEN:
694 show_state = ui::SHOW_STATE_FULLSCREEN; 661 show_state = ui::SHOW_STATE_FULLSCREEN;
695 } else { 662 break;
663 case windows::Update::Params::UpdateInfo::STATE_NONE:
664 break;
665 default:
696 error_ = keys::kInvalidWindowStateError; 666 error_ = keys::kInvalidWindowStateError;
697 return false; 667 return false;
698 }
699 } 668 }
700 669
701 if (show_state != ui::SHOW_STATE_FULLSCREEN && 670 if (show_state != ui::SHOW_STATE_FULLSCREEN &&
702 show_state != ui::SHOW_STATE_DEFAULT) 671 show_state != ui::SHOW_STATE_DEFAULT)
703 controller->SetFullscreenMode(false, GetExtension()->url()); 672 controller->SetFullscreenMode(false, GetExtension()->url());
704 673
705 switch (show_state) { 674 switch (show_state) {
706 case ui::SHOW_STATE_MINIMIZED: 675 case ui::SHOW_STATE_MINIMIZED:
707 controller->window()->Minimize(); 676 controller->window()->Minimize();
708 break; 677 break;
(...skipping 14 matching lines...) Expand all
723 } 692 }
724 693
725 gfx::Rect bounds; 694 gfx::Rect bounds;
726 if (controller->window()->IsMinimized()) 695 if (controller->window()->IsMinimized())
727 bounds = controller->window()->GetRestoredBounds(); 696 bounds = controller->window()->GetRestoredBounds();
728 else 697 else
729 bounds = controller->window()->GetBounds(); 698 bounds = controller->window()->GetBounds();
730 bool set_bounds = false; 699 bool set_bounds = false;
731 700
732 // Any part of the bounds can optionally be set by the caller. 701 // Any part of the bounds can optionally be set by the caller.
733 int bounds_val; 702 if (params->update_info.left) {
734 if (update_props->HasKey(keys::kLeftKey)) { 703 bounds.set_x(*params->update_info.left);
735 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
736 keys::kLeftKey,
737 &bounds_val));
738 bounds.set_x(bounds_val);
739 set_bounds = true; 704 set_bounds = true;
740 } 705 }
741 706
742 if (update_props->HasKey(keys::kTopKey)) { 707 if (params->update_info.top) {
743 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 708 bounds.set_y(*params->update_info.top);
744 keys::kTopKey,
745 &bounds_val));
746 bounds.set_y(bounds_val);
747 set_bounds = true; 709 set_bounds = true;
748 } 710 }
749 711
750 if (update_props->HasKey(keys::kWidthKey)) { 712 if (params->update_info.width) {
751 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 713 bounds.set_width(*params->update_info.width);
752 keys::kWidthKey,
753 &bounds_val));
754 bounds.set_width(bounds_val);
755 set_bounds = true; 714 set_bounds = true;
756 } 715 }
757 716
758 if (update_props->HasKey(keys::kHeightKey)) { 717 if (params->update_info.height) {
759 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 718 bounds.set_height(*params->update_info.height);
760 keys::kHeightKey,
761 &bounds_val));
762 bounds.set_height(bounds_val);
763 set_bounds = true; 719 set_bounds = true;
764 } 720 }
765 721
766 if (set_bounds) { 722 if (set_bounds) {
767 if (show_state == ui::SHOW_STATE_MINIMIZED || 723 if (show_state == ui::SHOW_STATE_MINIMIZED ||
768 show_state == ui::SHOW_STATE_MAXIMIZED || 724 show_state == ui::SHOW_STATE_MAXIMIZED ||
769 show_state == ui::SHOW_STATE_FULLSCREEN) { 725 show_state == ui::SHOW_STATE_FULLSCREEN) {
770 error_ = keys::kInvalidWindowStateError; 726 error_ = keys::kInvalidWindowStateError;
771 return false; 727 return false;
772 } 728 }
773 // TODO(varkha): Updating bounds during a drag can cause problems and a more 729 // TODO(varkha): Updating bounds during a drag can cause problems and a more
774 // general solution is needed. See http://crbug.com/251813 . 730 // general solution is needed. See http://crbug.com/251813 .
775 controller->window()->SetBounds(bounds); 731 controller->window()->SetBounds(bounds);
776 } 732 }
777 733
778 bool active_val = false; 734 if (params->update_info.focused) {
779 if (update_props->HasKey(keys::kFocusedKey)) { 735 if (*params->update_info.focused) {
780 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
781 keys::kFocusedKey, &active_val));
782 if (active_val) {
783 if (show_state == ui::SHOW_STATE_MINIMIZED) { 736 if (show_state == ui::SHOW_STATE_MINIMIZED) {
784 error_ = keys::kInvalidWindowStateError; 737 error_ = keys::kInvalidWindowStateError;
785 return false; 738 return false;
786 } 739 }
787 controller->window()->Activate(); 740 controller->window()->Activate();
788 } else { 741 } else {
789 if (show_state == ui::SHOW_STATE_MAXIMIZED || 742 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
790 show_state == ui::SHOW_STATE_FULLSCREEN) { 743 show_state == ui::SHOW_STATE_FULLSCREEN) {
791 error_ = keys::kInvalidWindowStateError; 744 error_ = keys::kInvalidWindowStateError;
792 return false; 745 return false;
793 } 746 }
794 controller->window()->Deactivate(); 747 controller->window()->Deactivate();
795 } 748 }
796 } 749 }
797 750
798 bool draw_attention = false; 751 if (params->update_info.draw_attention)
799 if (update_props->HasKey(keys::kDrawAttentionKey)) { 752 controller->window()->FlashFrame(*params->update_info.draw_attention);
800 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
801 keys::kDrawAttentionKey, &draw_attention));
802 controller->window()->FlashFrame(draw_attention);
803 }
804 753
805 SetResult(controller->CreateWindowValue()); 754 SetResult(controller->CreateWindowValue());
806 755
807 return true; 756 return true;
808 } 757 }
809 758
810 bool WindowsRemoveFunction::RunImpl() { 759 bool WindowsRemoveFunction::RunImpl() {
811 int window_id = -1; 760 scoped_ptr<windows::Remove::Params> params(
812 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 761 windows::Remove::Params::Create(*args_));
762 EXTENSION_FUNCTION_VALIDATE(params);
813 763
814 WindowController* controller; 764 WindowController* controller;
815 if (!windows_util::GetWindowFromWindowID(this, window_id, &controller)) 765 if (!windows_util::GetWindowFromWindowID(this, params->window_id,
766 &controller))
816 return false; 767 return false;
817 768
818 #if defined(OS_WIN) 769 #if defined(OS_WIN)
819 // In Windows 8 metro mode, an existing Browser instance is reused for 770 // In Windows 8 metro mode, an existing Browser instance is reused for
820 // hosting the extension tab. We should not be closing it as we don't own it. 771 // hosting the extension tab. We should not be closing it as we don't own it.
821 if (win8::IsSingleWindowMetroMode()) 772 if (win8::IsSingleWindowMetroMode())
822 return false; 773 return false;
823 #endif 774 #endif
824 775
825 WindowController::Reason reason; 776 WindowController::Reason reason;
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2039 execute_tab_id_ = tab_id; 1990 execute_tab_id_ = tab_id;
2040 details_ = details.Pass(); 1991 details_ = details.Pass();
2041 return true; 1992 return true;
2042 } 1993 }
2043 1994
2044 bool TabsInsertCSSFunction::ShouldInsertCSS() const { 1995 bool TabsInsertCSSFunction::ShouldInsertCSS() const {
2045 return true; 1996 return true;
2046 } 1997 }
2047 1998
2048 } // namespace extensions 1999 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | chrome/browser/extensions/api/tabs/tabs_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698