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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 #include "extensions/common/manifest_handlers/incognito_info.h" | 77 #include "extensions/common/manifest_handlers/incognito_info.h" |
78 #include "extensions/common/message_bundle.h" | 78 #include "extensions/common/message_bundle.h" |
79 #include "extensions/common/permissions/permissions_data.h" | 79 #include "extensions/common/permissions/permissions_data.h" |
80 #include "extensions/common/user_script.h" | 80 #include "extensions/common/user_script.h" |
81 #include "skia/ext/image_operations.h" | 81 #include "skia/ext/image_operations.h" |
82 #include "skia/ext/platform_canvas.h" | 82 #include "skia/ext/platform_canvas.h" |
83 #include "third_party/skia/include/core/SkBitmap.h" | 83 #include "third_party/skia/include/core/SkBitmap.h" |
84 #include "ui/base/models/list_selection_model.h" | 84 #include "ui/base/models/list_selection_model.h" |
85 #include "ui/base/ui_base_types.h" | 85 #include "ui/base/ui_base_types.h" |
86 | 86 |
87 #if defined(OS_WIN) | |
88 #include "win8/util/win8_util.h" | |
89 #endif // OS_WIN | |
90 | |
91 #if defined(USE_ASH) | 87 #if defined(USE_ASH) |
92 #include "apps/app_window_registry.h" | 88 #include "apps/app_window_registry.h" |
93 #include "ash/ash_switches.h" | 89 #include "ash/ash_switches.h" |
94 #include "chrome/browser/extensions/api/tabs/ash_panel_contents.h" | 90 #include "chrome/browser/extensions/api/tabs/ash_panel_contents.h" |
95 #endif | 91 #endif |
96 | 92 |
97 using apps::AppWindow; | 93 using apps::AppWindow; |
98 using content::BrowserThread; | 94 using content::BrowserThread; |
99 using content::NavigationController; | 95 using content::NavigationController; |
100 using content::NavigationEntry; | 96 using content::NavigationEntry; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return false; | 178 return false; |
183 } | 179 } |
184 | 180 |
185 // Returns true if either |boolean| is a null pointer, or if |*boolean| and | 181 // Returns true if either |boolean| is a null pointer, or if |*boolean| and |
186 // |value| are equal. This function is used to check if a tab's parameters match | 182 // |value| are equal. This function is used to check if a tab's parameters match |
187 // those of the browser. | 183 // those of the browser. |
188 bool MatchesBool(bool* boolean, bool value) { | 184 bool MatchesBool(bool* boolean, bool value) { |
189 return !boolean || *boolean == value; | 185 return !boolean || *boolean == value; |
190 } | 186 } |
191 | 187 |
192 Browser* CreateBrowserWindow(const Browser::CreateParams& params, | |
193 Profile* profile, | |
194 const std::string& extension_id) { | |
195 bool use_existing_browser_window = false; | |
196 | |
197 #if defined(OS_WIN) | |
198 // In windows 8 metro mode we don't allow windows to be created. | |
199 if (win8::IsSingleWindowMetroMode()) | |
200 use_existing_browser_window = true; | |
201 #endif // OS_WIN | |
202 | |
203 Browser* new_window = NULL; | |
204 if (use_existing_browser_window) | |
205 // The false parameter passed below is to ensure that we find a browser | |
206 // object matching the profile passed in, instead of the original profile | |
207 new_window = chrome::FindTabbedBrowser(profile, false, | |
208 params.host_desktop_type); | |
209 | |
210 if (!new_window) | |
211 new_window = new Browser(params); | |
212 return new_window; | |
213 } | |
214 | |
215 } // namespace | 188 } // namespace |
216 | 189 |
217 // Windows --------------------------------------------------------------------- | 190 // Windows --------------------------------------------------------------------- |
218 | 191 |
219 bool WindowsGetFunction::RunImpl() { | 192 bool WindowsGetFunction::RunImpl() { |
220 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); | 193 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); |
221 EXTENSION_FUNCTION_VALIDATE(params.get()); | 194 EXTENSION_FUNCTION_VALIDATE(params.get()); |
222 | 195 |
223 bool populate_tabs = false; | 196 bool populate_tabs = false; |
224 if (params->get_info.get() && params->get_info->populate.get()) | 197 if (params->get_info.get() && params->get_info->populate.get()) |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 create_params = Browser::CreateParams::CreateForApp( | 538 create_params = Browser::CreateParams::CreateForApp( |
566 web_app::GenerateApplicationNameFromExtensionId(extension_id), | 539 web_app::GenerateApplicationNameFromExtensionId(extension_id), |
567 false /* trusted_source */, | 540 false /* trusted_source */, |
568 window_bounds, | 541 window_bounds, |
569 window_profile, | 542 window_profile, |
570 host_desktop_type); | 543 host_desktop_type); |
571 } | 544 } |
572 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; | 545 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; |
573 create_params.host_desktop_type = chrome::GetActiveDesktop(); | 546 create_params.host_desktop_type = chrome::GetActiveDesktop(); |
574 | 547 |
575 Browser* new_window = CreateBrowserWindow(create_params, window_profile, | 548 Browser* new_window = new Browser(create_params); |
576 extension_id); | |
577 | 549 |
578 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { | 550 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { |
579 WebContents* tab = chrome::AddSelectedTabWithURL( | 551 WebContents* tab = chrome::AddSelectedTabWithURL( |
580 new_window, *i, content::PAGE_TRANSITION_LINK); | 552 new_window, *i, content::PAGE_TRANSITION_LINK); |
581 if (create_panel) { | 553 if (create_panel) { |
582 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id); | 554 TabHelper::FromWebContents(tab)->SetExtensionAppIconById(extension_id); |
583 } | 555 } |
584 } | 556 } |
585 | 557 |
586 WebContents* contents = NULL; | 558 WebContents* contents = NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 bool WindowsUpdateFunction::RunImpl() { | 601 bool WindowsUpdateFunction::RunImpl() { |
630 scoped_ptr<windows::Update::Params> params( | 602 scoped_ptr<windows::Update::Params> params( |
631 windows::Update::Params::Create(*args_)); | 603 windows::Update::Params::Create(*args_)); |
632 EXTENSION_FUNCTION_VALIDATE(params); | 604 EXTENSION_FUNCTION_VALIDATE(params); |
633 | 605 |
634 WindowController* controller; | 606 WindowController* controller; |
635 if (!windows_util::GetWindowFromWindowID(this, params->window_id, | 607 if (!windows_util::GetWindowFromWindowID(this, params->window_id, |
636 &controller)) | 608 &controller)) |
637 return false; | 609 return false; |
638 | 610 |
639 #if defined(OS_WIN) | |
640 // Silently ignore changes on the window for metro mode. | |
641 if (win8::IsSingleWindowMetroMode()) { | |
642 SetResult(controller->CreateWindowValue()); | |
643 return true; | |
644 } | |
645 #endif | |
646 | |
647 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. | 611 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; // No change. |
648 switch (params->update_info.state) { | 612 switch (params->update_info.state) { |
649 case windows::Update::Params::UpdateInfo::STATE_NORMAL: | 613 case windows::Update::Params::UpdateInfo::STATE_NORMAL: |
650 show_state = ui::SHOW_STATE_NORMAL; | 614 show_state = ui::SHOW_STATE_NORMAL; |
651 break; | 615 break; |
652 case windows::Update::Params::UpdateInfo::STATE_MINIMIZED: | 616 case windows::Update::Params::UpdateInfo::STATE_MINIMIZED: |
653 show_state = ui::SHOW_STATE_MINIMIZED; | 617 show_state = ui::SHOW_STATE_MINIMIZED; |
654 break; | 618 break; |
655 case windows::Update::Params::UpdateInfo::STATE_MAXIMIZED: | 619 case windows::Update::Params::UpdateInfo::STATE_MAXIMIZED: |
656 show_state = ui::SHOW_STATE_MAXIMIZED; | 620 show_state = ui::SHOW_STATE_MAXIMIZED; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 bool WindowsRemoveFunction::RunImpl() { | 721 bool WindowsRemoveFunction::RunImpl() { |
758 scoped_ptr<windows::Remove::Params> params( | 722 scoped_ptr<windows::Remove::Params> params( |
759 windows::Remove::Params::Create(*args_)); | 723 windows::Remove::Params::Create(*args_)); |
760 EXTENSION_FUNCTION_VALIDATE(params); | 724 EXTENSION_FUNCTION_VALIDATE(params); |
761 | 725 |
762 WindowController* controller; | 726 WindowController* controller; |
763 if (!windows_util::GetWindowFromWindowID(this, params->window_id, | 727 if (!windows_util::GetWindowFromWindowID(this, params->window_id, |
764 &controller)) | 728 &controller)) |
765 return false; | 729 return false; |
766 | 730 |
767 #if defined(OS_WIN) | |
768 // In Windows 8 metro mode, an existing Browser instance is reused for | |
769 // hosting the extension tab. We should not be closing it as we don't own it. | |
770 if (win8::IsSingleWindowMetroMode()) | |
771 return false; | |
772 #endif | |
773 | |
774 WindowController::Reason reason; | 731 WindowController::Reason reason; |
775 if (!controller->CanClose(&reason)) { | 732 if (!controller->CanClose(&reason)) { |
776 if (reason == WindowController::REASON_NOT_EDITABLE) | 733 if (reason == WindowController::REASON_NOT_EDITABLE) |
777 error_ = keys::kTabStripNotEditableError; | 734 error_ = keys::kTabStripNotEditableError; |
778 return false; | 735 return false; |
779 } | 736 } |
780 controller->window()->Close(); | 737 controller->window()->Close(); |
781 return true; | 738 return true; |
782 } | 739 } |
783 | 740 |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 execute_tab_id_ = tab_id; | 1871 execute_tab_id_ = tab_id; |
1915 details_ = details.Pass(); | 1872 details_ = details.Pass(); |
1916 return true; | 1873 return true; |
1917 } | 1874 } |
1918 | 1875 |
1919 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 1876 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
1920 return true; | 1877 return true; |
1921 } | 1878 } |
1922 | 1879 |
1923 } // namespace extensions | 1880 } // namespace extensions |
OLD | NEW |