OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 #include "extensions/common/message_bundle.h" | 88 #include "extensions/common/message_bundle.h" |
89 #include "extensions/common/permissions/permissions_data.h" | 89 #include "extensions/common/permissions/permissions_data.h" |
90 #include "extensions/common/user_script.h" | 90 #include "extensions/common/user_script.h" |
91 #include "net/base/escape.h" | 91 #include "net/base/escape.h" |
92 #include "skia/ext/image_operations.h" | 92 #include "skia/ext/image_operations.h" |
93 #include "skia/ext/platform_canvas.h" | 93 #include "skia/ext/platform_canvas.h" |
94 #include "third_party/skia/include/core/SkBitmap.h" | 94 #include "third_party/skia/include/core/SkBitmap.h" |
95 #include "ui/base/models/list_selection_model.h" | 95 #include "ui/base/models/list_selection_model.h" |
96 #include "ui/base/ui_base_types.h" | 96 #include "ui/base/ui_base_types.h" |
97 | 97 |
98 #if defined(USE_ASH) | |
99 #include "chrome/browser/extensions/api/tabs/ash_panel_contents.h" // nogncheck | |
100 #include "extensions/browser/app_window/app_window_registry.h" // nogncheck | |
101 #endif | |
102 | |
103 using content::BrowserThread; | 98 using content::BrowserThread; |
104 using content::NavigationController; | 99 using content::NavigationController; |
105 using content::NavigationEntry; | 100 using content::NavigationEntry; |
106 using content::OpenURLParams; | 101 using content::OpenURLParams; |
107 using content::Referrer; | 102 using content::Referrer; |
108 using content::WebContents; | 103 using content::WebContents; |
109 using zoom::ZoomController; | 104 using zoom::ZoomController; |
110 | 105 |
111 namespace extensions { | 106 namespace extensions { |
112 | 107 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 if (source_browser->profile() != window_profile) | 474 if (source_browser->profile() != window_profile) |
480 return RespondNow(Error(keys::kCanOnlyMoveTabsWithinSameProfileError)); | 475 return RespondNow(Error(keys::kCanOnlyMoveTabsWithinSameProfileError)); |
481 } | 476 } |
482 | 477 |
483 if (!IsValidStateForWindowsCreateFunction(create_data)) | 478 if (!IsValidStateForWindowsCreateFunction(create_data)) |
484 return RespondNow(Error(keys::kInvalidWindowStateError)); | 479 return RespondNow(Error(keys::kInvalidWindowStateError)); |
485 | 480 |
486 Browser::Type window_type = Browser::TYPE_TABBED; | 481 Browser::Type window_type = Browser::TYPE_TABBED; |
487 | 482 |
488 #if defined(USE_ASH) | 483 #if defined(USE_ASH) |
489 bool create_ash_panel = false; | |
490 bool saw_focus_key = false; | 484 bool saw_focus_key = false; |
491 #endif // defined(USE_ASH) | 485 #endif // defined(USE_ASH) |
492 | 486 |
493 gfx::Rect window_bounds; | 487 gfx::Rect window_bounds; |
494 bool focused = true; | 488 bool focused = true; |
495 std::string extension_id; | 489 std::string extension_id; |
496 | 490 |
497 if (create_data) { | 491 if (create_data) { |
498 // Report UMA stats to decide when to remove the deprecated "docked" windows | 492 // Report UMA stats to decide when to remove the deprecated "docked" windows |
499 // state (crbug.com/703733). | 493 // state (crbug.com/703733). |
500 ReportRequestedWindowState(create_data->state); | 494 ReportRequestedWindowState(create_data->state); |
501 | 495 |
502 // Figure out window type before figuring out bounds so that default | 496 // Figure out window type before figuring out bounds so that default |
503 // bounds can be set according to the window type. | 497 // bounds can be set according to the window type. |
504 switch (create_data->type) { | 498 switch (create_data->type) { |
505 case windows::CREATE_TYPE_POPUP: | 499 case windows::CREATE_TYPE_POPUP: |
506 window_type = Browser::TYPE_POPUP; | 500 window_type = Browser::TYPE_POPUP; |
507 extension_id = extension()->id(); | 501 extension_id = extension()->id(); |
508 break; | 502 break; |
509 | 503 |
510 case windows::CREATE_TYPE_PANEL: { | 504 case windows::CREATE_TYPE_PANEL: { |
511 extension_id = extension()->id(); | 505 extension_id = extension()->id(); |
512 #if defined(USE_ASH) | |
513 // Only ChromeOS' version of chrome.windows.create would create a panel | |
514 // window. It is whitelisted to Hangouts extension for limited time until | |
515 // it transitioned to other types of windows. | |
516 for (const char* id : extension_misc::kHangoutsExtensionIds) { | |
517 if (extension_id == id) { | |
518 create_ash_panel = true; | |
519 break; | |
520 } | |
521 } | |
522 #endif // defined(USE_ASH) | |
523 // Everything else gets POPUP instead of PANEL. | |
524 // TODO(dimich): Eventually, remove the 'panel' values form valid | 506 // TODO(dimich): Eventually, remove the 'panel' values form valid |
525 // window.create parameters. However, this is a more breaking change, so | 507 // window.create parameters. However, this is a more breaking change, so |
526 // for now simply treat it as a POPUP. | 508 // for now simply treat it as a POPUP. |
527 window_type = Browser::TYPE_POPUP; | 509 window_type = Browser::TYPE_POPUP; |
528 break; | 510 break; |
529 } | 511 } |
530 | 512 |
531 case windows::CREATE_TYPE_NONE: | 513 case windows::CREATE_TYPE_NONE: |
532 case windows::CREATE_TYPE_NORMAL: | 514 case windows::CREATE_TYPE_NORMAL: |
533 break; | 515 break; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 window_bounds.set_height(*create_data->height); | 548 window_bounds.set_height(*create_data->height); |
567 | 549 |
568 if (create_data->focused) { | 550 if (create_data->focused) { |
569 focused = *create_data->focused; | 551 focused = *create_data->focused; |
570 #if defined(USE_ASH) | 552 #if defined(USE_ASH) |
571 saw_focus_key = true; | 553 saw_focus_key = true; |
572 #endif | 554 #endif |
573 } | 555 } |
574 } | 556 } |
575 | 557 |
576 #if defined(USE_ASH) | |
577 if (create_ash_panel) { | |
578 if (urls.empty()) | |
579 urls.push_back(GURL(chrome::kChromeUINewTabURL)); | |
580 | |
581 AppWindow::CreateParams create_params; | |
582 create_params.window_type = AppWindow::WINDOW_TYPE_V1_PANEL; | |
583 create_params.window_key = extension_id; | |
584 create_params.window_spec.bounds = window_bounds; | |
585 create_params.focused = saw_focus_key && focused; | |
586 AppWindow* app_window = | |
587 new AppWindow(window_profile, new ChromeAppDelegate(true), extension()); | |
588 AshPanelContents* ash_panel_contents = new AshPanelContents(app_window); | |
589 app_window->Init(urls[0], ash_panel_contents, render_frame_host(), | |
590 create_params); | |
591 WindowController* window_controller = | |
592 WindowControllerList::GetInstance()->FindWindowById( | |
593 app_window->session_id().id()); | |
594 if (!window_controller) | |
595 return RespondNow(Error(kUnknownErrorDoNotUse)); | |
596 return RespondNow( | |
597 OneArgument(window_controller->CreateWindowValueWithTabs(extension()))); | |
598 } | |
599 #endif // defined(USE_ASH) | |
600 | |
601 // Create a new BrowserWindow. | 558 // Create a new BrowserWindow. |
602 Browser::CreateParams create_params(window_type, window_profile, | 559 Browser::CreateParams create_params(window_type, window_profile, |
603 user_gesture()); | 560 user_gesture()); |
604 if (extension_id.empty()) { | 561 if (extension_id.empty()) { |
605 create_params.initial_bounds = window_bounds; | 562 create_params.initial_bounds = window_bounds; |
606 } else { | 563 } else { |
607 create_params = Browser::CreateParams::CreateForApp( | 564 create_params = Browser::CreateParams::CreateForApp( |
608 web_app::GenerateApplicationNameFromExtensionId(extension_id), | 565 web_app::GenerateApplicationNameFromExtensionId(extension_id), |
609 false /* trusted_source */, window_bounds, window_profile, | 566 false /* trusted_source */, window_bounds, window_profile, |
610 user_gesture()); | 567 user_gesture()); |
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 params->tab_id | 2106 params->tab_id |
2150 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, | 2107 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, |
2151 base::IntToString(*params->tab_id)) | 2108 base::IntToString(*params->tab_id)) |
2152 : keys::kCannotFindTabToDiscard)); | 2109 : keys::kCannotFindTabToDiscard)); |
2153 } | 2110 } |
2154 | 2111 |
2155 TabsDiscardFunction::TabsDiscardFunction() {} | 2112 TabsDiscardFunction::TabsDiscardFunction() {} |
2156 TabsDiscardFunction::~TabsDiscardFunction() {} | 2113 TabsDiscardFunction::~TabsDiscardFunction() {} |
2157 | 2114 |
2158 } // namespace extensions | 2115 } // namespace extensions |
OLD | NEW |