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/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 window_ids.insert(window_id); | 63 window_ids.insert(window_id); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 // Default to all windows. | 67 // Default to all windows. |
68 bool all_windows = (window_ids.size() == 0); | 68 bool all_windows = (window_ids.size() == 0); |
69 | 69 |
70 result_.reset(new ListValue()); | 70 result_.reset(new ListValue()); |
71 for (BrowserList::const_iterator browser = BrowserList::begin(); | 71 for (BrowserList::const_iterator browser = BrowserList::begin(); |
72 browser != BrowserList::end(); ++browser) { | 72 browser != BrowserList::end(); ++browser) { |
73 if (all_windows || (window_ids.find(ExtensionTabUtil::GetWindowId(*browser)) | 73 // Only examine browsers in the current profile. |
74 != window_ids.end())) { | 74 if ((*browser)->profile() == profile()) { |
75 static_cast<ListValue*>(result_.get())->Append( | 75 if (all_windows || (window_ids.find(ExtensionTabUtil:: |
| 76 GetWindowId(*browser)) != window_ids.end())) { |
| 77 static_cast<ListValue*>(result_.get())->Append( |
76 CreateWindowValue(*browser)); | 78 CreateWindowValue(*browser)); |
| 79 } |
77 } | 80 } |
78 } | 81 } |
79 | 82 |
80 return true; | 83 return true; |
81 } | 84 } |
82 | 85 |
83 bool CreateWindowFunction::RunImpl() { | 86 bool CreateWindowFunction::RunImpl() { |
84 scoped_ptr<GURL> url(new GURL()); | 87 scoped_ptr<GURL> url(new GURL()); |
85 | 88 |
86 // Look for optional url. | 89 // Look for optional url. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 new_window->window()->SetBounds(bounds); | 142 new_window->window()->SetBounds(bounds); |
140 new_window->window()->Show(); | 143 new_window->window()->Show(); |
141 | 144 |
142 // TODO(rafaelw): support |focused|, |zIndex| | 145 // TODO(rafaelw): support |focused|, |zIndex| |
143 | 146 |
144 result_.reset(CreateWindowValue(new_window)); | 147 result_.reset(CreateWindowValue(new_window)); |
145 | 148 |
146 return true; | 149 return true; |
147 } | 150 } |
148 | 151 |
| 152 bool RemoveWindowFunction::RunImpl() { |
| 153 if (!args_->IsType(Value::TYPE_INTEGER)) |
| 154 return false; |
| 155 |
| 156 int window_id; |
| 157 if (!args_->GetAsInteger(&window_id)) |
| 158 return false; |
| 159 |
| 160 Browser* target = NULL; |
| 161 for (BrowserList::const_iterator browser = BrowserList::begin(); |
| 162 browser != BrowserList::end(); ++browser) { |
| 163 // Only examine browsers in the current profile. |
| 164 if ((*browser)->profile() == profile()) { |
| 165 if (ExtensionTabUtil::GetWindowId(*browser) == window_id) { |
| 166 target = *browser; |
| 167 break; |
| 168 } |
| 169 } |
| 170 } |
| 171 |
| 172 if (target == NULL) { |
| 173 // TODO(rafaelw): need error message. |
| 174 return false; |
| 175 } |
| 176 |
| 177 target->CloseWindow(); |
| 178 |
| 179 return true; |
| 180 } |
| 181 |
| 182 |
149 bool GetTabsForWindowFunction::RunImpl() { | 183 bool GetTabsForWindowFunction::RunImpl() { |
150 if (!args_->IsType(Value::TYPE_NULL)) | 184 if (!args_->IsType(Value::TYPE_NULL)) |
151 return false; | 185 return false; |
152 | 186 |
153 Browser* browser = BrowserList::GetLastActive(); | 187 Browser* browser = dispatcher_->browser(); |
154 if (!browser) | 188 if (!browser) |
155 return false; | 189 return false; |
156 | 190 |
157 result_.reset(CreateTabList(browser)); | 191 result_.reset(CreateTabList(browser)); |
158 | 192 |
159 return true; | 193 return true; |
160 } | 194 } |
161 | 195 |
162 bool CreateTabFunction::RunImpl() { | 196 bool CreateTabFunction::RunImpl() { |
163 // TODO(aa): Do data-driven validation in JS. | 197 // TODO(aa): Do data-driven validation in JS. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 int* tab_index) { | 433 int* tab_index) { |
400 for (int i = 0; i < tab_strip->count(); ++i) { | 434 for (int i = 0; i < tab_strip->count(); ++i) { |
401 TabContents* tab_contents = tab_strip->GetTabContentsAt(i); | 435 TabContents* tab_contents = tab_strip->GetTabContentsAt(i); |
402 if (tab_contents->controller().session_id().id() == tab_id) { | 436 if (tab_contents->controller().session_id().id() == tab_id) { |
403 *tab_index = i; | 437 *tab_index = i; |
404 return true; | 438 return true; |
405 } | 439 } |
406 } | 440 } |
407 return false; | 441 return false; |
408 } | 442 } |
OLD | NEW |