| 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.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 bool populate_tabs = false; | 255 bool populate_tabs = false; |
| 256 if (params->get_info.get() && params->get_info->populate.get()) | 256 if (params->get_info.get() && params->get_info->populate.get()) |
| 257 populate_tabs = *params->get_info->populate; | 257 populate_tabs = *params->get_info->populate; |
| 258 | 258 |
| 259 ExtensionWindowController* controller; | 259 ExtensionWindowController* controller; |
| 260 if (!GetWindowFromWindowID(this, params->window_id, &controller)) | 260 if (!GetWindowFromWindowID(this, params->window_id, &controller)) |
| 261 return false; | 261 return false; |
| 262 | 262 |
| 263 if (populate_tabs) | 263 if (populate_tabs) |
| 264 result_.reset(controller->CreateWindowValueWithTabs()); | 264 SetResult(controller->CreateWindowValueWithTabs()); |
| 265 else | 265 else |
| 266 result_.reset(controller->CreateWindowValue()); | 266 SetResult(controller->CreateWindowValue()); |
| 267 return true; | 267 return true; |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool GetCurrentWindowFunction::RunImpl() { | 270 bool GetCurrentWindowFunction::RunImpl() { |
| 271 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); | 271 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); |
| 272 EXTENSION_FUNCTION_VALIDATE(params.get()); | 272 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 273 | 273 |
| 274 bool populate_tabs = false; | 274 bool populate_tabs = false; |
| 275 if (params->get_info.get() && params->get_info->populate.get()) | 275 if (params->get_info.get() && params->get_info->populate.get()) |
| 276 populate_tabs = *params->get_info->populate; | 276 populate_tabs = *params->get_info->populate; |
| 277 | 277 |
| 278 ExtensionWindowController* controller; | 278 ExtensionWindowController* controller; |
| 279 if (!GetWindowFromWindowID(this, | 279 if (!GetWindowFromWindowID(this, |
| 280 extension_misc::kCurrentWindowId, | 280 extension_misc::kCurrentWindowId, |
| 281 &controller)) { | 281 &controller)) { |
| 282 return false; | 282 return false; |
| 283 } | 283 } |
| 284 if (populate_tabs) | 284 if (populate_tabs) |
| 285 result_.reset(controller->CreateWindowValueWithTabs()); | 285 SetResult(controller->CreateWindowValueWithTabs()); |
| 286 else | 286 else |
| 287 result_.reset(controller->CreateWindowValue()); | 287 SetResult(controller->CreateWindowValue()); |
| 288 return true; | 288 return true; |
| 289 } | 289 } |
| 290 | 290 |
| 291 bool GetLastFocusedWindowFunction::RunImpl() { | 291 bool GetLastFocusedWindowFunction::RunImpl() { |
| 292 scoped_ptr<GetLastFocused::Params> params( | 292 scoped_ptr<GetLastFocused::Params> params( |
| 293 GetLastFocused::Params::Create(*args_)); | 293 GetLastFocused::Params::Create(*args_)); |
| 294 EXTENSION_FUNCTION_VALIDATE(params.get()); | 294 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 295 | 295 |
| 296 bool populate_tabs = false; | 296 bool populate_tabs = false; |
| 297 if (params->get_info.get() && params->get_info->populate.get()) | 297 if (params->get_info.get() && params->get_info->populate.get()) |
| 298 populate_tabs = *params->get_info->populate; | 298 populate_tabs = *params->get_info->populate; |
| 299 | 299 |
| 300 // Note: currently this returns the last active browser. If we decide to | 300 // Note: currently this returns the last active browser. If we decide to |
| 301 // include other window types (e.g. panels), we will need to add logic to | 301 // include other window types (e.g. panels), we will need to add logic to |
| 302 // ExtensionWindowList that mirrors the active behavior of BrowserList. | 302 // ExtensionWindowList that mirrors the active behavior of BrowserList. |
| 303 Browser* browser = browser::FindAnyBrowser( | 303 Browser* browser = browser::FindAnyBrowser( |
| 304 profile(), include_incognito()); | 304 profile(), include_incognito()); |
| 305 if (!browser || !browser->window()) { | 305 if (!browser || !browser->window()) { |
| 306 error_ = keys::kNoLastFocusedWindowError; | 306 error_ = keys::kNoLastFocusedWindowError; |
| 307 return false; | 307 return false; |
| 308 } | 308 } |
| 309 ExtensionWindowController* controller = | 309 ExtensionWindowController* controller = |
| 310 browser->extension_window_controller(); | 310 browser->extension_window_controller(); |
| 311 if (populate_tabs) | 311 if (populate_tabs) |
| 312 result_.reset(controller->CreateWindowValueWithTabs()); | 312 SetResult(controller->CreateWindowValueWithTabs()); |
| 313 else | 313 else |
| 314 result_.reset(controller->CreateWindowValue()); | 314 SetResult(controller->CreateWindowValue()); |
| 315 return true; | 315 return true; |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool GetAllWindowsFunction::RunImpl() { | 318 bool GetAllWindowsFunction::RunImpl() { |
| 319 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); | 319 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); |
| 320 EXTENSION_FUNCTION_VALIDATE(params.get()); | 320 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 321 | 321 |
| 322 bool populate_tabs = false; | 322 bool populate_tabs = false; |
| 323 if (params->get_info.get() && params->get_info->populate.get()) | 323 if (params->get_info.get() && params->get_info->populate.get()) |
| 324 populate_tabs = *params->get_info->populate; | 324 populate_tabs = *params->get_info->populate; |
| 325 | 325 |
| 326 ListValue* window_list = new ListValue(); | 326 ListValue* window_list = new ListValue(); |
| 327 const ExtensionWindowList::WindowList& windows = | 327 const ExtensionWindowList::WindowList& windows = |
| 328 ExtensionWindowList::GetInstance()->windows(); | 328 ExtensionWindowList::GetInstance()->windows(); |
| 329 for (ExtensionWindowList::WindowList::const_iterator iter = | 329 for (ExtensionWindowList::WindowList::const_iterator iter = |
| 330 windows.begin(); | 330 windows.begin(); |
| 331 iter != windows.end(); ++iter) { | 331 iter != windows.end(); ++iter) { |
| 332 if (!this->CanOperateOnWindow(*iter)) | 332 if (!this->CanOperateOnWindow(*iter)) |
| 333 continue; | 333 continue; |
| 334 if (populate_tabs) | 334 if (populate_tabs) |
| 335 window_list->Append((*iter)->CreateWindowValueWithTabs()); | 335 window_list->Append((*iter)->CreateWindowValueWithTabs()); |
| 336 else | 336 else |
| 337 window_list->Append((*iter)->CreateWindowValue()); | 337 window_list->Append((*iter)->CreateWindowValue()); |
| 338 } | 338 } |
| 339 result_.reset(window_list); | 339 SetResult(window_list); |
| 340 return true; | 340 return true; |
| 341 } | 341 } |
| 342 | 342 |
| 343 bool CreateWindowFunction::ShouldOpenIncognitoWindow( | 343 bool CreateWindowFunction::ShouldOpenIncognitoWindow( |
| 344 const base::DictionaryValue* args, | 344 const base::DictionaryValue* args, |
| 345 std::vector<GURL>* urls, | 345 std::vector<GURL>* urls, |
| 346 bool* is_error) { | 346 bool* is_error) { |
| 347 *is_error = false; | 347 *is_error = false; |
| 348 const IncognitoModePrefs::Availability incognito_availability = | 348 const IncognitoModePrefs::Availability incognito_availability = |
| 349 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); | 349 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // Note: Panels ignore all but the first url provided. | 577 // Note: Panels ignore all but the first url provided. |
| 578 Panel* panel = PanelManager::GetInstance()->CreatePanel( | 578 Panel* panel = PanelManager::GetInstance()->CreatePanel( |
| 579 title, window_profile, urls[0], panel_bounds.size()); | 579 title, window_profile, urls[0], panel_bounds.size()); |
| 580 | 580 |
| 581 // Unlike other window types, Panels do not take focus by default. | 581 // Unlike other window types, Panels do not take focus by default. |
| 582 if (!saw_focus_key || !focused) | 582 if (!saw_focus_key || !focused) |
| 583 panel->ShowInactive(); | 583 panel->ShowInactive(); |
| 584 else | 584 else |
| 585 panel->Show(); | 585 panel->Show(); |
| 586 | 586 |
| 587 result_.reset( | 587 SetResult( |
| 588 panel->extension_window_controller()->CreateWindowValueWithTabs()); | 588 panel->extension_window_controller()->CreateWindowValueWithTabs()); |
| 589 return true; | 589 return true; |
| 590 } | 590 } |
| 591 #endif | 591 #endif |
| 592 // else fall through to create BrowserWindow | 592 // else fall through to create BrowserWindow |
| 593 } | 593 } |
| 594 | 594 |
| 595 // Create a new BrowserWindow. | 595 // Create a new BrowserWindow. |
| 596 Browser::CreateParams create_params; | 596 Browser::CreateParams create_params; |
| 597 if (extension_id.empty()) { | 597 if (extension_id.empty()) { |
| 598 create_params = Browser::CreateParams(window_type, window_profile); | 598 create_params = Browser::CreateParams(window_type, window_profile); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 628 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) | 628 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) |
| 629 focused = false; | 629 focused = false; |
| 630 | 630 |
| 631 if (focused) | 631 if (focused) |
| 632 new_window->window()->Show(); | 632 new_window->window()->Show(); |
| 633 else | 633 else |
| 634 new_window->window()->ShowInactive(); | 634 new_window->window()->ShowInactive(); |
| 635 | 635 |
| 636 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { | 636 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { |
| 637 // Don't expose incognito windows if the extension isn't allowed. | 637 // Don't expose incognito windows if the extension isn't allowed. |
| 638 result_.reset(Value::CreateNullValue()); | 638 SetResult(Value::CreateNullValue()); |
| 639 } else { | 639 } else { |
| 640 result_.reset( | 640 SetResult( |
| 641 new_window->extension_window_controller()->CreateWindowValueWithTabs()); | 641 new_window->extension_window_controller()->CreateWindowValueWithTabs()); |
| 642 } | 642 } |
| 643 | 643 |
| 644 return true; | 644 return true; |
| 645 } | 645 } |
| 646 | 646 |
| 647 bool UpdateWindowFunction::RunImpl() { | 647 bool UpdateWindowFunction::RunImpl() { |
| 648 int window_id = extension_misc::kUnknownWindowId; | 648 int window_id = extension_misc::kUnknownWindowId; |
| 649 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 649 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 650 DictionaryValue* update_props; | 650 DictionaryValue* update_props; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 } | 768 } |
| 769 } | 769 } |
| 770 | 770 |
| 771 bool draw_attention = false; | 771 bool draw_attention = false; |
| 772 if (update_props->HasKey(keys::kDrawAttentionKey)) { | 772 if (update_props->HasKey(keys::kDrawAttentionKey)) { |
| 773 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 773 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 774 keys::kDrawAttentionKey, &draw_attention)); | 774 keys::kDrawAttentionKey, &draw_attention)); |
| 775 controller->window()->FlashFrame(draw_attention); | 775 controller->window()->FlashFrame(draw_attention); |
| 776 } | 776 } |
| 777 | 777 |
| 778 result_.reset(controller->CreateWindowValue()); | 778 SetResult(controller->CreateWindowValue()); |
| 779 | 779 |
| 780 return true; | 780 return true; |
| 781 } | 781 } |
| 782 | 782 |
| 783 bool RemoveWindowFunction::RunImpl() { | 783 bool RemoveWindowFunction::RunImpl() { |
| 784 int window_id = -1; | 784 int window_id = -1; |
| 785 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 785 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 786 | 786 |
| 787 ExtensionWindowController* controller; | 787 ExtensionWindowController* controller; |
| 788 if (!GetWindowFromWindowID(this, window_id, &controller)) | 788 if (!GetWindowFromWindowID(this, window_id, &controller)) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 810 Browser* browser = NULL; | 810 Browser* browser = NULL; |
| 811 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 811 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
| 812 return false; | 812 return false; |
| 813 | 813 |
| 814 TabStripModel* tab_strip = browser->tab_strip_model(); | 814 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 815 TabContents* contents = tab_strip->GetActiveTabContents(); | 815 TabContents* contents = tab_strip->GetActiveTabContents(); |
| 816 if (!contents) { | 816 if (!contents) { |
| 817 error_ = keys::kNoSelectedTabError; | 817 error_ = keys::kNoSelectedTabError; |
| 818 return false; | 818 return false; |
| 819 } | 819 } |
| 820 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 820 SetResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
| 821 tab_strip, | 821 tab_strip, |
| 822 tab_strip->active_index())); | 822 tab_strip->active_index())); |
| 823 return true; | 823 return true; |
| 824 } | 824 } |
| 825 | 825 |
| 826 bool GetAllTabsInWindowFunction::RunImpl() { | 826 bool GetAllTabsInWindowFunction::RunImpl() { |
| 827 // windowId defaults to "current" window. | 827 // windowId defaults to "current" window. |
| 828 int window_id = extension_misc::kCurrentWindowId; | 828 int window_id = extension_misc::kCurrentWindowId; |
| 829 if (HasOptionalArgument(0)) | 829 if (HasOptionalArgument(0)) |
| 830 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 830 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 831 | 831 |
| 832 Browser* browser = NULL; | 832 Browser* browser = NULL; |
| 833 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 833 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
| 834 return false; | 834 return false; |
| 835 | 835 |
| 836 result_.reset(ExtensionTabUtil::CreateTabList(browser)); | 836 SetResult(ExtensionTabUtil::CreateTabList(browser)); |
| 837 | 837 |
| 838 return true; | 838 return true; |
| 839 } | 839 } |
| 840 | 840 |
| 841 bool QueryTabsFunction::RunImpl() { | 841 bool QueryTabsFunction::RunImpl() { |
| 842 DictionaryValue* query = NULL; | 842 DictionaryValue* query = NULL; |
| 843 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query)); | 843 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query)); |
| 844 | 844 |
| 845 QueryArg active = ParseBoolQueryArg(query, keys::kActiveKey); | 845 QueryArg active = ParseBoolQueryArg(query, keys::kActiveKey); |
| 846 QueryArg pinned = ParseBoolQueryArg(query, keys::kPinnedKey); | 846 QueryArg pinned = ParseBoolQueryArg(query, keys::kPinnedKey); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 continue; | 941 continue; |
| 942 | 942 |
| 943 if (!MatchesQueryArg(loading, web_contents->IsLoading())) | 943 if (!MatchesQueryArg(loading, web_contents->IsLoading())) |
| 944 continue; | 944 continue; |
| 945 | 945 |
| 946 result->Append(ExtensionTabUtil::CreateTabValue( | 946 result->Append(ExtensionTabUtil::CreateTabValue( |
| 947 web_contents, tab_strip, i)); | 947 web_contents, tab_strip, i)); |
| 948 } | 948 } |
| 949 } | 949 } |
| 950 | 950 |
| 951 result_.reset(result); | 951 SetResult(result); |
| 952 return true; | 952 return true; |
| 953 } | 953 } |
| 954 | 954 |
| 955 bool CreateTabFunction::RunImpl() { | 955 bool CreateTabFunction::RunImpl() { |
| 956 DictionaryValue* args = NULL; | 956 DictionaryValue* args = NULL; |
| 957 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 957 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 958 | 958 |
| 959 // windowId defaults to "current" window. | 959 // windowId defaults to "current" window. |
| 960 int window_id = extension_misc::kCurrentWindowId; | 960 int window_id = extension_misc::kCurrentWindowId; |
| 961 if (args->HasKey(keys::kWindowIdKey)) | 961 if (args->HasKey(keys::kWindowIdKey)) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 tab_strip = params.browser->tab_strip_model(); | 1072 tab_strip = params.browser->tab_strip_model(); |
| 1073 int new_index = tab_strip->GetIndexOfTabContents(params.target_contents); | 1073 int new_index = tab_strip->GetIndexOfTabContents(params.target_contents); |
| 1074 if (opener) | 1074 if (opener) |
| 1075 tab_strip->SetOpenerOfTabContentsAt(new_index, opener); | 1075 tab_strip->SetOpenerOfTabContentsAt(new_index, opener); |
| 1076 | 1076 |
| 1077 if (active) | 1077 if (active) |
| 1078 params.target_contents->web_contents()->GetView()->SetInitialFocus(); | 1078 params.target_contents->web_contents()->GetView()->SetInitialFocus(); |
| 1079 | 1079 |
| 1080 // Return data about the newly created tab. | 1080 // Return data about the newly created tab. |
| 1081 if (has_callback()) { | 1081 if (has_callback()) { |
| 1082 result_.reset(ExtensionTabUtil::CreateTabValue( | 1082 SetResult(ExtensionTabUtil::CreateTabValue( |
| 1083 params.target_contents->web_contents(), | 1083 params.target_contents->web_contents(), |
| 1084 tab_strip, new_index)); | 1084 tab_strip, new_index)); |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 return true; | 1087 return true; |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 bool GetTabFunction::RunImpl() { | 1090 bool GetTabFunction::RunImpl() { |
| 1091 int tab_id = -1; | 1091 int tab_id = -1; |
| 1092 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1092 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1093 | 1093 |
| 1094 TabStripModel* tab_strip = NULL; | 1094 TabStripModel* tab_strip = NULL; |
| 1095 TabContents* contents = NULL; | 1095 TabContents* contents = NULL; |
| 1096 int tab_index = -1; | 1096 int tab_index = -1; |
| 1097 if (!GetTabById(tab_id, profile(), include_incognito(), | 1097 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1098 NULL, &tab_strip, &contents, &tab_index, &error_)) | 1098 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 1099 return false; | 1099 return false; |
| 1100 | 1100 |
| 1101 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 1101 SetResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
| 1102 tab_strip, | 1102 tab_strip, |
| 1103 tab_index)); | 1103 tab_index)); |
| 1104 return true; | 1104 return true; |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 bool GetCurrentTabFunction::RunImpl() { | 1107 bool GetCurrentTabFunction::RunImpl() { |
| 1108 DCHECK(dispatcher()); | 1108 DCHECK(dispatcher()); |
| 1109 | 1109 |
| 1110 WebContents* contents = dispatcher()->delegate()->GetAssociatedWebContents(); | 1110 WebContents* contents = dispatcher()->delegate()->GetAssociatedWebContents(); |
| 1111 if (contents) | 1111 if (contents) |
| 1112 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); | 1112 SetResult(ExtensionTabUtil::CreateTabValue(contents)); |
| 1113 | 1113 |
| 1114 return true; | 1114 return true; |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 bool HighlightTabsFunction::RunImpl() { | 1117 bool HighlightTabsFunction::RunImpl() { |
| 1118 DictionaryValue* info = NULL; | 1118 DictionaryValue* info = NULL; |
| 1119 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &info)); | 1119 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &info)); |
| 1120 | 1120 |
| 1121 // Get the window id from the params; default to current window if omitted. | 1121 // Get the window id from the params; default to current window if omitted. |
| 1122 int window_id = extension_misc::kCurrentWindowId; | 1122 int window_id = extension_misc::kCurrentWindowId; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 // Make sure they actually specified tabs to select. | 1160 // Make sure they actually specified tabs to select. |
| 1161 if (selection.empty()) { | 1161 if (selection.empty()) { |
| 1162 error_ = keys::kNoHighlightedTabError; | 1162 error_ = keys::kNoHighlightedTabError; |
| 1163 return false; | 1163 return false; |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 selection.set_active(active_index); | 1166 selection.set_active(active_index); |
| 1167 browser->tab_strip_model()->SetSelectionFromModel(selection); | 1167 browser->tab_strip_model()->SetSelectionFromModel(selection); |
| 1168 result_.reset( | 1168 SetResult( |
| 1169 browser->extension_window_controller()->CreateWindowValueWithTabs()); | 1169 browser->extension_window_controller()->CreateWindowValueWithTabs()); |
| 1170 return true; | 1170 return true; |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 UpdateTabFunction::UpdateTabFunction() : tab_contents_(NULL) { | 1173 UpdateTabFunction::UpdateTabFunction() : tab_contents_(NULL) { |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 bool UpdateTabFunction::RunImpl() { | 1176 bool UpdateTabFunction::RunImpl() { |
| 1177 DictionaryValue* update_props = NULL; | 1177 DictionaryValue* update_props = NULL; |
| 1178 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1178 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 DCHECK_EQ(url.spec(), tab_contents_->web_contents()->GetURL().spec()); | 1332 DCHECK_EQ(url.spec(), tab_contents_->web_contents()->GetURL().spec()); |
| 1333 | 1333 |
| 1334 return true; | 1334 return true; |
| 1335 } | 1335 } |
| 1336 | 1336 |
| 1337 void UpdateTabFunction::PopulateResult() { | 1337 void UpdateTabFunction::PopulateResult() { |
| 1338 if (!has_callback()) | 1338 if (!has_callback()) |
| 1339 return; | 1339 return; |
| 1340 | 1340 |
| 1341 if (GetExtension()->HasAPIPermission(extensions::APIPermission::kTab)) { | 1341 if (GetExtension()->HasAPIPermission(extensions::APIPermission::kTab)) { |
| 1342 result_.reset( | 1342 SetResult(ExtensionTabUtil::CreateTabValue(tab_contents_->web_contents())); |
| 1343 ExtensionTabUtil::CreateTabValue(tab_contents_->web_contents())); | |
| 1344 } else { | 1343 } else { |
| 1345 result_.reset(Value::CreateNullValue()); | 1344 SetResult(Value::CreateNullValue()); |
| 1346 } | 1345 } |
| 1347 } | 1346 } |
| 1348 | 1347 |
| 1349 void UpdateTabFunction::OnExecuteCodeFinished(bool success, | 1348 void UpdateTabFunction::OnExecuteCodeFinished(bool success, |
| 1350 int32 page_id, | 1349 int32 page_id, |
| 1351 const std::string& error) { | 1350 const std::string& error) { |
| 1352 if (!error.empty()) { | 1351 if (!error.empty()) { |
| 1353 CHECK(!success); | 1352 CHECK(!success); |
| 1354 error_ = error; | 1353 error_ = error; |
| 1355 } | 1354 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 if (has_callback()) | 1457 if (has_callback()) |
| 1459 tab_values.Append(ExtensionTabUtil::CreateTabValue( | 1458 tab_values.Append(ExtensionTabUtil::CreateTabValue( |
| 1460 contents->web_contents(), source_tab_strip, new_index)); | 1459 contents->web_contents(), source_tab_strip, new_index)); |
| 1461 } | 1460 } |
| 1462 | 1461 |
| 1463 if (!has_callback()) | 1462 if (!has_callback()) |
| 1464 return true; | 1463 return true; |
| 1465 | 1464 |
| 1466 // Only return the results as an array if there are multiple tabs. | 1465 // Only return the results as an array if there are multiple tabs. |
| 1467 if (tab_ids.size() > 1) { | 1466 if (tab_ids.size() > 1) { |
| 1468 result_.reset(tab_values.DeepCopy()); | 1467 SetResult(tab_values.DeepCopy()); |
| 1469 } else if (tab_ids.size() == 1) { | 1468 } else if (tab_ids.size() == 1) { |
| 1470 Value* value = NULL; | 1469 Value* value = NULL; |
| 1471 CHECK(tab_values.Get(0, &value)); | 1470 CHECK(tab_values.Get(0, &value)); |
| 1472 result_.reset(value->DeepCopy()); | 1471 SetResult(value->DeepCopy()); |
| 1473 } | 1472 } |
| 1474 return true; | 1473 return true; |
| 1475 } | 1474 } |
| 1476 | 1475 |
| 1477 bool ReloadTabFunction::RunImpl() { | 1476 bool ReloadTabFunction::RunImpl() { |
| 1478 bool bypass_cache = false; | 1477 bool bypass_cache = false; |
| 1479 if (HasOptionalArgument(1)) { | 1478 if (HasOptionalArgument(1)) { |
| 1480 DictionaryValue* reload_props = NULL; | 1479 DictionaryValue* reload_props = NULL; |
| 1481 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &reload_props)); | 1480 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &reload_props)); |
| 1482 | 1481 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 return; | 1728 return; |
| 1730 } | 1729 } |
| 1731 | 1730 |
| 1732 std::string base64_result; | 1731 std::string base64_result; |
| 1733 base::StringPiece stream_as_string( | 1732 base::StringPiece stream_as_string( |
| 1734 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 1733 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
| 1735 | 1734 |
| 1736 base::Base64Encode(stream_as_string, &base64_result); | 1735 base::Base64Encode(stream_as_string, &base64_result); |
| 1737 base64_result.insert(0, base::StringPrintf("data:%s;base64,", | 1736 base64_result.insert(0, base::StringPrintf("data:%s;base64,", |
| 1738 mime_type.c_str())); | 1737 mime_type.c_str())); |
| 1739 result_.reset(new StringValue(base64_result)); | 1738 SetResult(new StringValue(base64_result)); |
| 1740 SendResponse(true); | 1739 SendResponse(true); |
| 1741 } | 1740 } |
| 1742 | 1741 |
| 1743 bool DetectTabLanguageFunction::RunImpl() { | 1742 bool DetectTabLanguageFunction::RunImpl() { |
| 1744 int tab_id = 0; | 1743 int tab_id = 0; |
| 1745 Browser* browser = NULL; | 1744 Browser* browser = NULL; |
| 1746 TabContents* contents = NULL; | 1745 TabContents* contents = NULL; |
| 1747 | 1746 |
| 1748 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1747 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
| 1749 // in the current window. | 1748 // in the current window. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1805 language = *content::Details<std::string>(details).ptr(); | 1804 language = *content::Details<std::string>(details).ptr(); |
| 1806 | 1805 |
| 1807 registrar_.RemoveAll(); | 1806 registrar_.RemoveAll(); |
| 1808 | 1807 |
| 1809 // Call GotLanguage in all cases as we want to guarantee the callback is | 1808 // Call GotLanguage in all cases as we want to guarantee the callback is |
| 1810 // called for every API call the extension made. | 1809 // called for every API call the extension made. |
| 1811 GotLanguage(language); | 1810 GotLanguage(language); |
| 1812 } | 1811 } |
| 1813 | 1812 |
| 1814 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1813 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1815 result_.reset(Value::CreateStringValue(language.c_str())); | 1814 SetResult(Value::CreateStringValue(language.c_str())); |
| 1816 SendResponse(true); | 1815 SendResponse(true); |
| 1817 | 1816 |
| 1818 Release(); // Balanced in Run() | 1817 Release(); // Balanced in Run() |
| 1819 } | 1818 } |
| OLD | NEW |