OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
6 | 6 |
7 #include "base/gfx/jpeg_codec.h" | 7 #include "base/gfx/jpeg_codec.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
12 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 12 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
13 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 13 #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
14 #include "chrome/browser/extensions/extensions_service.h" | 14 #include "chrome/browser/extensions/extensions_service.h" |
15 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
16 #include "chrome/browser/renderer_host/backing_store.h" | 16 #include "chrome/browser/renderer_host/backing_store.h" |
17 #include "chrome/browser/renderer_host/render_view_host.h" | 17 #include "chrome/browser/renderer_host/render_view_host.h" |
18 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 18 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
19 #include "chrome/browser/tab_contents/navigation_entry.h" | 19 #include "chrome/browser/tab_contents/navigation_entry.h" |
20 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
21 #include "chrome/browser/window_sizer.h" | 21 #include "chrome/browser/window_sizer.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_error_utils.h" | 23 #include "chrome/common/extensions/extension_error_utils.h" |
24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "net/base/base64.h" | 25 #include "net/base/base64.h" |
26 #include "skia/ext/image_operations.h" | 26 #include "skia/ext/image_operations.h" |
27 #include "skia/ext/platform_canvas.h" | 27 #include "skia/ext/platform_canvas.h" |
28 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
29 | 29 |
30 | |
31 namespace keys = extension_tabs_module_constants; | 30 namespace keys = extension_tabs_module_constants; |
32 | 31 |
33 // Forward declare static helper functions defined below. | 32 // Forward declare static helper functions defined below. |
34 | 33 |
35 // |error_message| can optionally be passed in a will be set with an appropriate | 34 // |error_message| can optionally be passed in a will be set with an appropriate |
36 // message if the window cannot be found by id. | 35 // message if the window cannot be found by id. |
37 static Browser* GetBrowserInProfileWithId(Profile* profile, | 36 static Browser* GetBrowserInProfileWithId(Profile* profile, |
38 const int window_id, | 37 const int window_id, |
39 std::string* error_message); | 38 std::string* error_message); |
40 | 39 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 result->SetInteger(keys::kWidthKey, bounds.width()); | 149 result->SetInteger(keys::kWidthKey, bounds.width()); |
151 result->SetInteger(keys::kHeightKey, bounds.height()); | 150 result->SetInteger(keys::kHeightKey, bounds.height()); |
152 | 151 |
153 if (populate_tabs) { | 152 if (populate_tabs) { |
154 result->Set(keys::kTabsKey, ExtensionTabUtil::CreateTabList(browser)); | 153 result->Set(keys::kTabsKey, ExtensionTabUtil::CreateTabList(browser)); |
155 } | 154 } |
156 | 155 |
157 return result; | 156 return result; |
158 } | 157 } |
159 | 158 |
| 159 bool ExtensionTabUtil::GetDefaultTab(Browser* browser, TabContents** contents, |
| 160 int* tab_id) { |
| 161 DCHECK(browser); |
| 162 DCHECK(contents); |
| 163 DCHECK(tab_id); |
| 164 |
| 165 *contents = browser->tabstrip_model()->GetSelectedTabContents(); |
| 166 if (*contents) { |
| 167 if (tab_id) |
| 168 *tab_id = ExtensionTabUtil::GetTabId(*contents); |
| 169 return true; |
| 170 } |
| 171 |
| 172 return false; |
| 173 } |
| 174 |
160 bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile, | 175 bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile, |
161 Browser** browser, | 176 Browser** browser, |
162 TabStripModel** tab_strip, | 177 TabStripModel** tab_strip, |
163 TabContents** contents, | 178 TabContents** contents, |
164 int* tab_index) { | 179 int* tab_index) { |
165 Browser* target_browser; | 180 Browser* target_browser; |
166 TabStripModel* target_tab_strip; | 181 TabStripModel* target_tab_strip; |
167 TabContents* target_contents; | 182 TabContents* target_contents; |
168 for (BrowserList::const_iterator iter = BrowserList::begin(); | 183 for (BrowserList::const_iterator iter = BrowserList::begin(); |
169 iter != BrowserList::end(); ++iter) { | 184 iter != BrowserList::end(); ++iter) { |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 } | 684 } |
670 | 685 |
671 // Perform a simple within-window move. | 686 // Perform a simple within-window move. |
672 // Clamp move location to the last position. | 687 // Clamp move location to the last position. |
673 // This is ">=" because the move must be to an existing location. | 688 // This is ">=" because the move must be to an existing location. |
674 if (new_index >= source_tab_strip->count()) | 689 if (new_index >= source_tab_strip->count()) |
675 new_index = source_tab_strip->count() - 1; | 690 new_index = source_tab_strip->count() - 1; |
676 | 691 |
677 if (new_index != tab_index) | 692 if (new_index != tab_index) |
678 source_tab_strip->MoveTabContentsAt(tab_index, new_index, false); | 693 source_tab_strip->MoveTabContentsAt(tab_index, new_index, false); |
679 | 694 |
680 if (has_callback()) | 695 if (has_callback()) |
681 result_.reset(ExtensionTabUtil::CreateTabValue(contents, source_tab_strip, | 696 result_.reset(ExtensionTabUtil::CreateTabValue(contents, source_tab_strip, |
682 new_index)); | 697 new_index)); |
683 return true; | 698 return true; |
684 } | 699 } |
685 | 700 |
686 | 701 |
687 bool RemoveTabFunction::RunImpl() { | 702 bool RemoveTabFunction::RunImpl() { |
688 int tab_id; | 703 int tab_id; |
689 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id)); | 704 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id)); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, | 883 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, |
869 contents, tab_index)) | 884 contents, tab_index)) |
870 return true; | 885 return true; |
871 | 886 |
872 if (error_message) | 887 if (error_message) |
873 *error_message = ExtensionErrorUtils::FormatErrorMessage( | 888 *error_message = ExtensionErrorUtils::FormatErrorMessage( |
874 keys::kTabNotFoundError, IntToString(tab_id)); | 889 keys::kTabNotFoundError, IntToString(tab_id)); |
875 | 890 |
876 return false; | 891 return false; |
877 } | 892 } |
OLD | NEW |