| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 if (!GetTabById(tab_id, profile(), include_incognito(), | 615 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 616 NULL, &tab_strip, &contents, &tab_index, &error_)) | 616 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 617 return false; | 617 return false; |
| 618 | 618 |
| 619 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, | 619 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, |
| 620 tab_index)); | 620 tab_index)); |
| 621 return true; | 621 return true; |
| 622 } | 622 } |
| 623 | 623 |
| 624 bool GetCurrentTabFunction::RunImpl() { | 624 bool GetCurrentTabFunction::RunImpl() { |
| 625 DCHECK(dispatcher() && dispatcher()->render_view_host()); | 625 DCHECK(dispatcher()); |
| 626 | 626 |
| 627 RenderViewHostDelegate* rvh_delegate = | 627 TabContents* contents = dispatcher()->delegate()->associated_tab_contents(); |
| 628 dispatcher()->render_view_host()->delegate(); | 628 if (contents) |
| 629 | |
| 630 TabContents* contents = rvh_delegate->GetAsTabContents(); | |
| 631 if (contents) { | |
| 632 // Caller is running inside a TabContents. | |
| 633 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); | 629 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); |
| 634 return true; | |
| 635 } | |
| 636 | |
| 637 ExtensionHost* host = reinterpret_cast<ExtensionHost*>(rvh_delegate); | |
| 638 Browser* browser = GetCurrentBrowser(); | |
| 639 if (browser && ViewType::EXTENSION_INFOBAR == host->extension_host_type()) { | |
| 640 // Unfortunately, now we have to iterate over each TabContents and each | |
| 641 // Infobar to try to find the one corresponding to this ExtensionHost. | |
| 642 TabStripModel* tab_strip = browser->tabstrip_model(); | |
| 643 int tab_count = tab_strip->count(); | |
| 644 for (int tab_index = 0; tab_index < tab_count; ++tab_index) { | |
| 645 contents = tab_strip->GetTabContentsAt(tab_index); | |
| 646 int infobar_count = contents->infobar_delegate_count(); | |
| 647 for (int infobar_index = 0; infobar_index < infobar_count; | |
| 648 ++infobar_index) { | |
| 649 ExtensionInfoBarDelegate* infobar_delegate = | |
| 650 contents->GetInfoBarDelegateAt(infobar_index) | |
| 651 ->AsExtensionInfoBarDelegate(); | |
| 652 if (infobar_delegate && infobar_delegate->extension_host() == host) { | |
| 653 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); | |
| 654 return true; | |
| 655 } | |
| 656 } | |
| 657 } | |
| 658 } | |
| 659 | 630 |
| 660 return true; | 631 return true; |
| 661 } | 632 } |
| 662 | 633 |
| 663 bool UpdateTabFunction::RunImpl() { | 634 bool UpdateTabFunction::RunImpl() { |
| 664 int tab_id; | 635 int tab_id; |
| 665 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); | 636 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); |
| 666 const ListValue* args = args_as_list(); | 637 const ListValue* args = args_as_list(); |
| 667 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); | 638 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); |
| 668 DictionaryValue* update_props; | 639 DictionaryValue* update_props; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 // caller. | 1131 // caller. |
| 1161 use_type = url.is_valid() && (url != resolved_url) ? | 1132 use_type = url.is_valid() && (url != resolved_url) ? |
| 1162 RELATIVE_URL_RESOLUTIONS_DIFFER : RELATIVE_URL_RESOLUTIONS_AGREE; | 1133 RELATIVE_URL_RESOLUTIONS_DIFFER : RELATIVE_URL_RESOLUTIONS_AGREE; |
| 1163 } | 1134 } |
| 1164 | 1135 |
| 1165 UMA_HISTOGRAM_ENUMERATION("Extensions.APIUse_RelativeURL", use_type, | 1136 UMA_HISTOGRAM_ENUMERATION("Extensions.APIUse_RelativeURL", use_type, |
| 1166 EXTENSION_API_RELATIVE_URL_USE_MAX_VALUE); | 1137 EXTENSION_API_RELATIVE_URL_USE_MAX_VALUE); |
| 1167 | 1138 |
| 1168 return url; | 1139 return url; |
| 1169 } | 1140 } |
| OLD | NEW |