| 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/offscreen_tabs/offscreen_tabs_api.h" | 5 #include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" | 
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 506     parent_tab = new ParentTab(); | 506     parent_tab = new ParentTab(); | 
| 507     parent_tab->Init(web_contents, extension_id()); | 507     parent_tab->Init(web_contents, extension_id()); | 
| 508   } | 508   } | 
| 509 | 509 | 
| 510   const OffscreenTab& offscreen_tab = GetMap()->CreateOffscreenTab( | 510   const OffscreenTab& offscreen_tab = GetMap()->CreateOffscreenTab( | 
| 511       parent_tab, url, width, height, extension_id()); | 511       parent_tab, url, width, height, extension_id()); | 
| 512 | 512 | 
| 513   // TODO(alexbost): Maybe the callback is called too soon. It should probably | 513   // TODO(alexbost): Maybe the callback is called too soon. It should probably | 
| 514   // be called once we have navigated to the url. | 514   // be called once we have navigated to the url. | 
| 515   if (has_callback()) { | 515   if (has_callback()) { | 
| 516     result_.reset(offscreen_tab.CreateValue()); | 516     SetResult(offscreen_tab.CreateValue()); | 
| 517     SendResponse(true); | 517     SendResponse(true); | 
| 518   } | 518   } | 
| 519 | 519 | 
| 520   return true; | 520   return true; | 
| 521 } | 521 } | 
| 522 | 522 | 
| 523 GetOffscreenTabFunction::GetOffscreenTabFunction() {} | 523 GetOffscreenTabFunction::GetOffscreenTabFunction() {} | 
| 524 GetOffscreenTabFunction::~GetOffscreenTabFunction() {} | 524 GetOffscreenTabFunction::~GetOffscreenTabFunction() {} | 
| 525 | 525 | 
| 526 bool GetOffscreenTabFunction::RunImpl() { | 526 bool GetOffscreenTabFunction::RunImpl() { | 
| 527   int offscreen_tab_id; | 527   int offscreen_tab_id; | 
| 528   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &offscreen_tab_id)); | 528   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &offscreen_tab_id)); | 
| 529 | 529 | 
| 530   OffscreenTab* offscreen_tab = NULL; | 530   OffscreenTab* offscreen_tab = NULL; | 
| 531   if (!GetMap()->GetOffscreenTab( | 531   if (!GetMap()->GetOffscreenTab( | 
| 532           offscreen_tab_id, this, &offscreen_tab, &error_)) { | 532           offscreen_tab_id, this, &offscreen_tab, &error_)) { | 
| 533     error_ = ExtensionErrorUtils::FormatErrorMessage( | 533     error_ = ExtensionErrorUtils::FormatErrorMessage( | 
| 534         keys::kOffscreenTabNotFoundError, base::IntToString(offscreen_tab_id)); | 534         keys::kOffscreenTabNotFoundError, base::IntToString(offscreen_tab_id)); | 
| 535     return false; | 535     return false; | 
| 536   } | 536   } | 
| 537 | 537 | 
| 538   result_.reset(offscreen_tab->CreateValue()); | 538   SetResult(offscreen_tab->CreateValue()); | 
| 539   return true; | 539   return true; | 
| 540 } | 540 } | 
| 541 | 541 | 
| 542 GetAllOffscreenTabFunction::GetAllOffscreenTabFunction() {} | 542 GetAllOffscreenTabFunction::GetAllOffscreenTabFunction() {} | 
| 543 GetAllOffscreenTabFunction::~GetAllOffscreenTabFunction() {} | 543 GetAllOffscreenTabFunction::~GetAllOffscreenTabFunction() {} | 
| 544 | 544 | 
| 545 bool GetAllOffscreenTabFunction::RunImpl() { | 545 bool GetAllOffscreenTabFunction::RunImpl() { | 
| 546   WebContents* web_contents = GetCurrentWebContents(this, &error_); | 546   WebContents* web_contents = GetCurrentWebContents(this, &error_); | 
| 547   if (!web_contents) | 547   if (!web_contents) | 
| 548     return false; | 548     return false; | 
| 549 | 549 | 
| 550   ParentTab* parent_tab = GetMap()->GetParentTab(web_contents, extension_id()); | 550   ParentTab* parent_tab = GetMap()->GetParentTab(web_contents, extension_id()); | 
| 551   ListValue* tab_list = new ListValue(); | 551   ListValue* tab_list = new ListValue(); | 
| 552   if (parent_tab) { | 552   if (parent_tab) { | 
| 553     for (OffscreenTabs::const_iterator i = parent_tab->offscreen_tabs().begin(); | 553     for (OffscreenTabs::const_iterator i = parent_tab->offscreen_tabs().begin(); | 
| 554          i != parent_tab->offscreen_tabs().end(); ++i) | 554          i != parent_tab->offscreen_tabs().end(); ++i) | 
| 555       tab_list->Append((*i)->CreateValue()); | 555       tab_list->Append((*i)->CreateValue()); | 
| 556   } | 556   } | 
| 557 | 557 | 
| 558   result_.reset(tab_list); | 558   SetResult(tab_list); | 
| 559   return true; | 559   return true; | 
| 560 } | 560 } | 
| 561 | 561 | 
| 562 RemoveOffscreenTabFunction::RemoveOffscreenTabFunction() {} | 562 RemoveOffscreenTabFunction::RemoveOffscreenTabFunction() {} | 
| 563 RemoveOffscreenTabFunction::~RemoveOffscreenTabFunction() {} | 563 RemoveOffscreenTabFunction::~RemoveOffscreenTabFunction() {} | 
| 564 | 564 | 
| 565 bool RemoveOffscreenTabFunction::RunImpl() { | 565 bool RemoveOffscreenTabFunction::RunImpl() { | 
| 566   int offscreen_tab_id; | 566   int offscreen_tab_id; | 
| 567   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &offscreen_tab_id)); | 567   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &offscreen_tab_id)); | 
| 568 | 568 | 
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 832   // async case (when a "javascript": URL is sent to a tab). | 832   // async case (when a "javascript": URL is sent to a tab). | 
| 833   if (!is_async) | 833   if (!is_async) | 
| 834     SendResponse(true); | 834     SendResponse(true); | 
| 835 | 835 | 
| 836   return true; | 836   return true; | 
| 837 } | 837 } | 
| 838 | 838 | 
| 839 void UpdateOffscreenTabFunction::PopulateResult() { | 839 void UpdateOffscreenTabFunction::PopulateResult() { | 
| 840   // There's no result associated with this callback. | 840   // There's no result associated with this callback. | 
| 841 } | 841 } | 
| OLD | NEW | 
|---|